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 116
 
111 117
    The database url.
112 118
 
119
+   If set, the module is a fully operational presence server.
120
+   Otherwise, it is used as a 'library', for its exported
121
+   functions.
122
+
113 123
    Default value is "NULL". 
114 124
 
115 125
    Example 1-1. Set db_url parameter
... ...
@@ -325,6 +335,7 @@ typedef struct ev
325 335
         str* param;         // required param
326 336
         str stored_name;
327 337
         str content_type;
338
+        int default_expires; /* the package default expires*/
328 339
         int type;
329 340
 /*      it can be: PUBL_TYPE or WINFO_TYPE */
330 341
         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 74
 		<para>
71 75
 		The database url.
72 76
 		</para>
77
+		<para>If set, the module is a fully operational
78
+		presence server. Otherwise, it is used as a 'library', for 
79
+		its exported functions.
80
+		</para>
73 81
 		<para>
74 82
 		<emphasis>	Default value is <quote>NULL</quote>.	
75 83
 		</emphasis>
... ...
@@ -219,27 +227,28 @@ modparam("presence", "expires_offset", 10)
219 227
 ...
220 228
 </programlisting>
221 229
 		</example>
222
-	</section>
223 230
 
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">
231
+</section>
232
+       <section>
233
+               <title><varname>max_expires</varname> (int)</title>
234
+               <para>
235
+               The the maximum admissible expires value for PUBLISH/SUBSCRIBE
236
+               message.
237
+               </para>
238
+               <para>
239
+               <emphasis>Default value is <quote>3600</quote>.
240
+               </emphasis>
241
+               </para>
242
+               <example>
243
+               <title>Set <varname>max_expires</varname> parameter</title>
244
+               <programlisting format="linespecific">
237 245
 ...
238 246
 modparam("presence", "max_expires", 3600)
239 247
 ...
240 248
 </programlisting>
241
-		</example>
242
-	</section>
249
+               </example>
250
+       </section>
251
+
243 252
 <section>
244 253
 		<title><varname>server_address</varname> (str)</title>
245 254
 		<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 111
 	ev->content_type.len= event->content_type.len;
110 112
 	memcpy(ev->content_type.s, event->content_type.s, event->content_type.len);
111 113
 	size+= ev->content_type.len;
112
-	
114
+
113 115
 	sep= strchr(event->name.s, '.');
114 116
 
115 117
 	if(sep && strncmp(sep+1, "winfo", 5)== 0)
... ...
@@ -140,6 +142,8 @@ int add_event(ev_t* event)
140 142
 	ev->evs_publ_handl= event->evs_publ_handl;
141 143
 	ev->etag_not_new= event->etag_not_new;
142 144
 	ev->free_body= event->free_body;
145
+	ev->default_expires= event->default_expires;
146
+
143 147
 	ev->next= EvList->events;
144 148
 	EvList->events= ev;
145 149
 	EvList->ev_count++;
... ...
@@ -196,6 +200,62 @@ ev_t* contains_event(str* name, str* param)
196 200
 	return NULL;	
197 201
 }
198 202
 
203
+ev_t* get_sname_event(str* stored_name)
204
+{
205
+	ev_t* event;
206
+	event= EvList->events;
207
+
208
+	while(event)
209
+	{
210
+		if(stored_name->len== event->stored_name.len && 
211
+			strncmp(stored_name->s,event->stored_name.s,stored_name->len)==0)
212
+			return event;
213
+		event= event->next;
214
+	}
215
+	return NULL;
216
+}
217
+int get_event_list(str** ev_list)
218
+{	
219
+	ev_t* ev= EvList->events;
220
+	int i;
221
+	str* list;
222
+	*ev_list= NULL;
223
+	
224
+	if(EvList->ev_count== 0)
225
+		return 0;
226
+	
227
+	list= (str*)pkg_malloc(sizeof(str));
228
+	if(list== NULL)
229
+	{
230
+		LOG(L_ERR, "PRESENCE: get_event_list: ERROR No more memory\n");
231
+		return -1;
232
+	}
233
+	memset(list, 0, sizeof(str));
234
+	list->s= (char*)pkg_malloc(EvList->ev_count* MAX_EVNAME_SIZE);
235
+	if(list->s== NULL)
236
+	{
237
+		LOG(L_ERR, "PRESENCE: get_event_list: ERROR No more memory\n");
238
+		pkg_free(list);
239
+		return -1;
240
+	}
241
+	list->s[0]= '\0';
242
+	
243
+	for(i= 0; i< EvList->ev_count; i++)
244
+	{
245
+		if(i> 0)
246
+		{
247
+			memcpy(list->s+ list->len, ", ", 2);
248
+			list->len+= 2;
249
+		}	
250
+		memcpy(list->s+ list->len, ev->stored_name.s, ev->stored_name.len );
251
+		list->len+= ev->stored_name.len ;
252
+		ev= ev->next;
253
+	}
254
+	
255
+	*ev_list= list;
256
+	return 0;
257
+}
258
+
199 259
 void destroy_evlist()
200 260
 {
201 261
     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 94
 	publ_handling_t  * evs_publ_handl;
94 95
 	subs_handling_t  * evs_subs_handl;
95 96
 	free_body_t* free_body;
96
-	int default_expires;
97 97
 	struct ev* wipeer;			
98 98
 	struct ev* next;
99 99
 	
... ...
@@ -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 125
 	{ "to_tag_pref",			STR_PARAM, &to_tag_pref },
127 126
 	{ "totag_avpid",			INT_PARAM, &reply_tag_avp_id },
128 127
 	{ "expires_offset",			INT_PARAM, &expires_offset },
129
-	{ "max_expires",			INT_PARAM, &max_expires  },
128
+	{ "max_expires",			INT_PARAM, &max_expires },
130 129
 	{ "server_address",         STR_PARAM, &server_address.s},
131 130
 	{0,0,0}
132 131
 };
... ...
@@ -162,6 +161,21 @@ static int mod_init(void)
162 161
 
163 162
 	DBG("PRESENCE: initializing module ...\n");
164 163
 
164
+	if(db_url.s== NULL)
165
+	{
166
+		use_db= 0;
167
+		DBG("PRESENCE:mod_init: presence module used for library"
168
+				" purpose only\n");
169
+		EvList= init_evlist();
170
+		if(!EvList)
171
+		{
172
+			LOG(L_ERR,"PRESENCE:mod_init: ERROR while initializing event list\n");
173
+			return -1;
174
+		}
175
+		return 0;
176
+
177
+	}
178
+
165 179
 	if(expires_offset<0)
166 180
 		expires_offset = 0;
167 181
 	
... ...
@@ -291,6 +305,12 @@ static int mod_init(void)
291 305
 static int child_init(int rank)
292 306
 {
293 307
 	DBG("PRESENCE: init_child [%d]  pid [%d]\n", rank, getpid());
308
+	
309
+	pid = my_pid();
310
+	
311
+	if(use_db== 0)
312
+		return 0;
313
+
294 314
 	if (pa_dbf.init==0)
295 315
 	{
296 316
 		LOG(L_CRIT, "BUG: PRESENCE: child_init: database not bound\n");
... ...
@@ -323,7 +343,6 @@ static int child_init(int rank)
323 343
 
324 344
 		DBG("PRESENCE: child %d: Database connection opened successfully\n", rank);
325 345
 	}
326
-	pid = my_pid();
327 346
 	return 0;
328 347
 }
329 348
 
... ...
@@ -357,6 +376,7 @@ static int fixup_presence(void** param, int param_no)
357 376
  	LOG(L_ERR, "PRESENCE:fixup_presence: ERROR null format\n");
358 377
  	return E_UNSPEC;
359 378
 }
379
+
360 380
 /* 
361 381
  *  mi cmd: refreshWatchers
362 382
  *			<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 401
 	else 
405 402
 	{
406 403
 		DBG("PRESENCE: handle_publish: 'expires' not found; default=%d\n",
407
-				default_expires);
408
-		lexpire = default_expires;
404
+				event->default_expires);
405
+		lexpire = event->default_expires;
409 406
 	}
410 407
 	if(lexpire > max_expires)
411 408
 		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;