Browse code

- enabled a 'library' like functioning mode - if the db_url module parameter is not set, no messages are processed and the exported functions can be used by other modules.' - added a event specific parameter 'default expires' - exported 2 new event list handling functions

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2577 689a6050-402a-0410-94f2-e92a70836424

Anca Vamanu authored on 07/08/2007 12:17:09
Showing 12 changed files
... ...
@@ -81,8 +81,14 @@ Chapter 1. User's Guide
81 81
    presence.winfo, dialog;sla from presence_xml module and
82 82
    message-summary from presence_mwi module.
83 83
 
84
-   The modules works with database storage. It stores published
85
-   information and Subscribe -Notify dialog characteristics.
84
+   The presence server works with database storage. It stores
85
+   published information and Subscribe -Notify dialog
86
+   characteristics.
87
+
88
+   It can also work only with the functionality of a library,
89
+   with no message processing and generation, but used only for
90
+   the exported functions. This mode of operation is enabled if
91
+   the db_url parameter is not set to any value.
86 92
 
87 93
    The server follows the specifications in: RFC3265, RFC3856,
88 94
    RFC3857, RFC3858.
... ...
@@ -110,6 +116,10 @@ Chapter 1. User's Guide
110 110
 
111 111
    The database url.
112 112
 
113
+   If set, the module is a fully operational presence server.
114
+   Otherwise, it is used as a 'library', for its exported
115
+   functions.
116
+
113 117
    Default value is "NULL". 
114 118
 
115 119
    Example 1-1. Set db_url parameter
... ...
@@ -325,6 +335,7 @@ typedef struct ev
325 325
         str* param;         // required param
326 326
         str stored_name;
327 327
         str content_type;
328
+        int default_expires; /* the package default expires*/
328 329
         int type;
329 330
 /*      it can be: PUBL_TYPE or WINFO_TYPE */
330 331
         int req_auth;
... ...
@@ -32,13 +32,14 @@
32 32
 int bind_presence(event_api_t* api)
33 33
 {
34 34
 	if (!api) {
35
-		LOG(L_ERR, "NOTIFIER:bind_notifier: Invalid parameter value\n");
35
+		LOG(L_ERR, "PRESENCE:bind_notifier: Invalid parameter value\n");
36 36
 		return -1;
37 37
 	}
38 38
 	
39 39
 	api->add_event = add_event;
40 40
 	api->contains_event= contains_event;
41
-
41
+	api->get_sname_event= get_sname_event;
42
+	api->get_event_list= get_event_list;
42 43
 	return 0;
43 44
 }
44 45
 
... ...
@@ -34,6 +34,8 @@
34 34
 typedef struct event_api {
35 35
 	add_event_t add_event;
36 36
 	contains_event_t contains_event;
37
+	get_sname_event_t get_sname_event;
38
+	get_event_list_t get_event_list;
37 39
 } event_api_t;
38 40
 
39 41
 int bind_presence(event_api_t* api);
... ...
@@ -54,6 +54,7 @@ typedef struct ev
54 54
 	str* param;         // required param 
55 55
 	str stored_name;
56 56
 	str content_type;
57
+	int default_expires; /* the package default expires*/
57 58
 	int type;
58 59
 /*	it can be: PUBL_TYPE or WINFO_TYPE */
59 60
 	int req_auth;
... ...
@@ -20,9 +20,13 @@
20 20
 	module and message-summary from presence_mwi module.
21 21
 	</para>
22 22
 	<para>
23
-	The modules works with database storage. It stores published information 
23
+	The presence server works with database storage. It stores published information 
24 24
 	and Subscribe -Notify dialog characteristics.
25 25
 	</para>
26
+	<para>It can also work only with the functionality of a library, with no message 
27
+	processing and generation, but used only for the exported functions.
28
+	This mode of operation is enabled if the db_url parameter is not set to any value.
29
+	</para>
26 30
 	<para>
27 31
 	The server follows the specifications in: RFC3265, RFC3856, RFC3857, 
28 32
 	RFC3858.
... ...
@@ -70,6 +74,10 @@
70 70
 		<para>
71 71
 		The database url.
72 72
 		</para>
73
+		<para>If set, the module is a fully operational
74
+		presence server. Otherwise, it is used as a 'library', for 
75
+		its exported functions.
76
+		</para>
73 77
 		<para>
74 78
 		<emphasis>	Default value is <quote>NULL</quote>.	
75 79
 		</emphasis>
... ...
@@ -219,27 +227,28 @@ modparam("presence", "expires_offset", 10)
219 219
 ...
220 220
 </programlisting>
221 221
 		</example>
222
-	</section>
223 222
 
224
-	<section>
225
-		<title><varname>max_expires</varname> (int)</title>
226
-		<para>
227
-		The the maximum admissible expires value for PUBLISH/SUBSCRIBE 
228
-		message.
229
-		</para>
230
-		<para>
231
-		<emphasis>Default value is <quote>3600</quote>.
232
-		</emphasis>
233
-		</para>
234
-		<example>
235
-		<title>Set <varname>max_expires</varname> parameter</title>
236
-		<programlisting format="linespecific">
223
+</section>
224
+       <section>
225
+               <title><varname>max_expires</varname> (int)</title>
226
+               <para>
227
+               The the maximum admissible expires value for PUBLISH/SUBSCRIBE
228
+               message.
229
+               </para>
230
+               <para>
231
+               <emphasis>Default value is <quote>3600</quote>.
232
+               </emphasis>
233
+               </para>
234
+               <example>
235
+               <title>Set <varname>max_expires</varname> parameter</title>
236
+               <programlisting format="linespecific">
237 237
 ...
238 238
 modparam("presence", "max_expires", 3600)
239 239
 ...
240 240
 </programlisting>
241
-		</example>
242
-	</section>
241
+               </example>
242
+       </section>
243
+
243 244
 <section>
244 245
 		<title><varname>server_address</varname> (str)</title>
245 246
 		<para>
... ...
@@ -34,6 +34,8 @@
34 34
 #include "../../mem/shm_mem.h" 
35 35
 #include "event_list.h"
36 36
 
37
+#define MAX_EVNAME_SIZE 20
38
+
37 39
 int add_event(ev_t* event)
38 40
 {
39 41
 	ev_t* ev= NULL;
... ...
@@ -109,7 +111,7 @@ int add_event(ev_t* event)
109 109
 	ev->content_type.len= event->content_type.len;
110 110
 	memcpy(ev->content_type.s, event->content_type.s, event->content_type.len);
111 111
 	size+= ev->content_type.len;
112
-	
112
+
113 113
 	sep= strchr(event->name.s, '.');
114 114
 
115 115
 	if(sep && strncmp(sep+1, "winfo", 5)== 0)
... ...
@@ -140,6 +142,8 @@ int add_event(ev_t* event)
140 140
 	ev->evs_publ_handl= event->evs_publ_handl;
141 141
 	ev->etag_not_new= event->etag_not_new;
142 142
 	ev->free_body= event->free_body;
143
+	ev->default_expires= event->default_expires;
144
+
143 145
 	ev->next= EvList->events;
144 146
 	EvList->events= ev;
145 147
 	EvList->ev_count++;
... ...
@@ -196,6 +200,62 @@ ev_t* contains_event(str* name, str* param)
196 196
 	return NULL;	
197 197
 }
198 198
 
199
+ev_t* get_sname_event(str* stored_name)
200
+{
201
+	ev_t* event;
202
+	event= EvList->events;
203
+
204
+	while(event)
205
+	{
206
+		if(stored_name->len== event->stored_name.len && 
207
+			strncmp(stored_name->s,event->stored_name.s,stored_name->len)==0)
208
+			return event;
209
+		event= event->next;
210
+	}
211
+	return NULL;
212
+}
213
+int get_event_list(str** ev_list)
214
+{	
215
+	ev_t* ev= EvList->events;
216
+	int i;
217
+	str* list;
218
+	*ev_list= NULL;
219
+	
220
+	if(EvList->ev_count== 0)
221
+		return 0;
222
+	
223
+	list= (str*)pkg_malloc(sizeof(str));
224
+	if(list== NULL)
225
+	{
226
+		LOG(L_ERR, "PRESENCE: get_event_list: ERROR No more memory\n");
227
+		return -1;
228
+	}
229
+	memset(list, 0, sizeof(str));
230
+	list->s= (char*)pkg_malloc(EvList->ev_count* MAX_EVNAME_SIZE);
231
+	if(list->s== NULL)
232
+	{
233
+		LOG(L_ERR, "PRESENCE: get_event_list: ERROR No more memory\n");
234
+		pkg_free(list);
235
+		return -1;
236
+	}
237
+	list->s[0]= '\0';
238
+	
239
+	for(i= 0; i< EvList->ev_count; i++)
240
+	{
241
+		if(i> 0)
242
+		{
243
+			memcpy(list->s+ list->len, ", ", 2);
244
+			list->len+= 2;
245
+		}	
246
+		memcpy(list->s+ list->len, ev->stored_name.s, ev->stored_name.len );
247
+		list->len+= ev->stored_name.len ;
248
+		ev= ev->next;
249
+	}
250
+	
251
+	*ev_list= list;
252
+	return 0;
253
+}
254
+
199 255
 void destroy_evlist()
200 256
 {
201 257
     ev_t* e1, *e2;
... ...
@@ -68,6 +68,7 @@ struct ev
68 68
 	/* to do: transform it in a list ( for multimple param)*/
69 69
 	str stored_name;
70 70
 	str content_type;
71
+	int default_expires;
71 72
 	int type;
72 73
 	int etag_not_new;
73 74
 	/*
... ...
@@ -93,7 +94,6 @@ struct ev
93 93
 	publ_handling_t  * evs_publ_handl;
94 94
 	subs_handling_t  * evs_subs_handl;
95 95
 	free_body_t* free_body;
96
-	int default_expires;
97 96
 	struct ev* wipeer;			
98 97
 	struct ev* next;
99 98
 	
... ...
@@ -116,6 +116,14 @@ ev_t* contains_event(str* name, str* param);
116 116
 
117 117
 typedef ev_t* (*contains_event_t) (str* name, str* param);
118 118
 
119
+ev_t* get_sname_event(str* stored_name);
120
+
121
+typedef ev_t* (*get_sname_event_t)(str* stored_name);
122
+
123
+int get_event_list(str** ev_list);
124
+
125
+typedef int (*get_event_list_t) (str** ev_list);
126
+
119 127
 void destroy_evlist();
120 128
 
121 129
 extern evlist_t* EvList;
... ...
@@ -105,8 +105,7 @@ char prefix='a';
105 105
 int startup_time=0;
106 106
 str db_url = {0, 0};
107 107
 int expires_offset = 0;
108
-int default_expires = 3600;
109
-int max_expires = 3600;
108
+int max_expires= 3600;
110 109
 
111 110
 static cmd_export_t cmds[]=
112 111
 {
... ...
@@ -126,7 +125,7 @@ static param_export_t params[]={
126 126
 	{ "to_tag_pref",			STR_PARAM, &to_tag_pref },
127 127
 	{ "totag_avpid",			INT_PARAM, &reply_tag_avp_id },
128 128
 	{ "expires_offset",			INT_PARAM, &expires_offset },
129
-	{ "max_expires",			INT_PARAM, &max_expires  },
129
+	{ "max_expires",			INT_PARAM, &max_expires },
130 130
 	{ "server_address",         STR_PARAM, &server_address.s},
131 131
 	{0,0,0}
132 132
 };
... ...
@@ -162,6 +161,21 @@ static int mod_init(void)
162 162
 
163 163
 	DBG("PRESENCE: initializing module ...\n");
164 164
 
165
+	if(db_url.s== NULL)
166
+	{
167
+		use_db= 0;
168
+		DBG("PRESENCE:mod_init: presence module used for library"
169
+				" purpose only\n");
170
+		EvList= init_evlist();
171
+		if(!EvList)
172
+		{
173
+			LOG(L_ERR,"PRESENCE:mod_init: ERROR while initializing event list\n");
174
+			return -1;
175
+		}
176
+		return 0;
177
+
178
+	}
179
+
165 180
 	if(expires_offset<0)
166 181
 		expires_offset = 0;
167 182
 	
... ...
@@ -291,6 +305,12 @@ static int mod_init(void)
291 291
 static int child_init(int rank)
292 292
 {
293 293
 	DBG("PRESENCE: init_child [%d]  pid [%d]\n", rank, getpid());
294
+	
295
+	pid = my_pid();
296
+	
297
+	if(use_db== 0)
298
+		return 0;
299
+
294 300
 	if (pa_dbf.init==0)
295 301
 	{
296 302
 		LOG(L_CRIT, "BUG: PRESENCE: child_init: database not bound\n");
... ...
@@ -323,7 +343,6 @@ static int child_init(int rank)
323 323
 
324 324
 		DBG("PRESENCE: child %d: Database connection opened successfully\n", rank);
325 325
 	}
326
-	pid = my_pid();
327 326
 	return 0;
328 327
 }
329 328
 
... ...
@@ -357,6 +376,7 @@ static int fixup_presence(void** param, int param_no)
357 357
  	LOG(L_ERR, "PRESENCE:fixup_presence: ERROR null format\n");
358 358
  	return E_UNSPEC;
359 359
 }
360
+
360 361
 /* 
361 362
  *  mi cmd: refreshWatchers
362 363
  *			<presentity_uri> 
... ...
@@ -56,10 +56,9 @@ extern int startup_time;
56 56
 extern int reply_tag_avp_id;
57 57
 extern char *to_tag_pref;
58 58
 extern int expires_offset;
59
-extern int default_expires;
60 59
 extern int lock_set_size;
61
-extern int max_expires;
62 60
 extern struct sl_binds slb;
63 61
 extern str server_address;
62
+extern int max_expires;
64 63
 
65 64
 #endif /* PA_MOD_H */
... ...
@@ -379,10 +379,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
379 379
 	else
380 380
 	{
381 381
 		DBG("PRESENCE:handle_publish: SIP-If-Match found\n");
382
-
383
-		etag.s = hdr->body.s;
384
-		etag.len = hdr->body.len;
385
-		etag.s[ etag.len] = '\0';
382
+		etag = hdr->body;
386 383
 		DBG("PRESENCE:handle_publish: existing etag  = %.*s \n", etag.len,
387 384
 				etag.s);
388 385
 	}
... ...
@@ -404,8 +401,8 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
404 404
 	else 
405 405
 	{
406 406
 		DBG("PRESENCE: handle_publish: 'expires' not found; default=%d\n",
407
-				default_expires);
408
-		lexpire = default_expires;
407
+				event->default_expires);
408
+		lexpire = event->default_expires;
409 409
 	}
410 410
 	if(lexpire > max_expires)
411 411
 		lexpire = max_expires;
... ...
@@ -421,7 +421,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
421 421
 			goto error;
422 422
 		}
423 423
 		
424
-		if(subs->event->wipeer)
424
+		if(subs->expires!= 0 && subs->event->wipeer)
425 425
 		{	
426 426
 			DBG("PRESENCE:update_subscription: send Notify with winfo\n");
427 427
 			if(query_db_notify(&subs->pres_user,&subs->pres_domain, subs->event->wipeer,
... ...
@@ -989,8 +989,8 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
989 989
 	else 
990 990
 	{
991 991
 		DBG("PRESENCE: handle_subscribe: 'expires' not found; default=%d\n",
992
-				default_expires);
993
-		lexpire = default_expires;
992
+				event->default_expires);
993
+		lexpire = event->default_expires;
994 994
 	}
995 995
 	if(lexpire > max_expires)
996 996
 		lexpire = max_expires;
... ...
@@ -54,7 +54,7 @@ struct subscription
54 54
 	unsigned int cseq; 
55 55
 	str contact;
56 56
 	str record_route;
57
-	int expires;
57
+	unsigned int expires;
58 58
 	str status;
59 59
 	str reason;
60 60
 	int version;