Browse code

- Restructured the module to handle PUBLISH and SUBSCRIBE messages and generates NOTIFY messages in a general, event independentway. It allows registering events to it from other OpenSER modules. presence_xml module adds events: presence, presence.winfo, dialog;sla.

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

Anca Vamanu authored on 23/04/2007 07:28:35
Showing 18 changed files
... ...
@@ -16,35 +16,41 @@ Anca-Maria Vamanu
16 16
    1. User's Guide
17 17
 
18 18
         1.1. Overview
19
-        1.2. To-do
20
-        1.3. Dependencies
19
+        1.2. Dependencies
21 20
 
22
-              1.3.1. OpenSER Modules
23
-              1.3.2. External Libraries or Applications
21
+              1.2.1. OpenSER Modules
22
+              1.2.2. External Libraries or Applications
24 23
 
25
-        1.4. Exported Parameters
24
+        1.3. Exported Parameters
26 25
 
27
-              1.4.1. db_url(str)
28
-              1.4.2. presentity_table(str)
29
-              1.4.3. active_watchers_table(str)
30
-              1.4.4. watchers_table(str)
31
-              1.4.5. xcap_table(str)
32
-              1.4.6. clean_period (int)
33
-              1.4.7. to_tag_pref (str)
34
-              1.4.8. lock_set_size (int)
35
-              1.4.9. expires_offset (int)
36
-              1.4.10. force_active (int)
37
-              1.4.11. max_expires (int)
38
-              1.4.12. server_address (str)
26
+              1.3.1. db_url(str)
27
+              1.3.2. presentity_table(str)
28
+              1.3.3. active_watchers_table(str)
29
+              1.3.4. watchers_table(str)
30
+              1.3.5. clean_period (int)
31
+              1.3.6. to_tag_pref (str)
32
+              1.3.7. lock_set_size (int)
33
+              1.3.8. expires_offset (int)
34
+              1.3.9. max_expires (int)
35
+              1.3.10. server_address (str)
39 36
 
40
-        1.5. Exported Functions
37
+        1.4. Exported Functions
41 38
 
42
-              1.5.1. handle_publish(char* sender_uri)
43
-              1.5.2. handle_subscribe()
39
+              1.4.1. handle_publish(char* sender_uri)
40
+              1.4.2. handle_subscribe()
44 41
 
45
-        1.6. Installation
42
+        1.5. Installation
46 43
 
47 44
    2. Developer's Guide
45
+
46
+        2.1. bind_presence(event_api_t* api)
47
+        2.2. add_event(ev_t* event)
48
+        2.3. apply_auth_nbody
49
+        2.4. is_watcher_allowed
50
+        2.5. agg_nbody
51
+        2.6. evs_publ_handl
52
+        2.7. evs_subs_handl
53
+
48 54
    3. Frequently Asked Questions
49 55
 
50 56
    List of Examples
... ...
@@ -52,48 +58,38 @@ Anca-Maria Vamanu
52 52
    1-2. Set presentity_table parameter
53 53
    1-3. Set active_watchers_table parameter
54 54
    1-4. Set watchers_table parameter
55
-   1-5. Set xcap_table parameter
56
-   1-6. Set clean_period parameter
57
-   1-7. Set to_tag_pref parameter
58
-   1-8. Set lock_set_size parameter
59
-   1-9. Set expires_offset parameter
60
-   1-10. Set force_active parameter
61
-   1-11. Set max_expires parameter
62
-   1-12. Set server_address parameter
63
-   1-13. handle_publish usage
64
-   1-14. handle_subscribe usage
65
-   1-15. PRESENCE tables
55
+   1-5. Set clean_period parameter
56
+   1-6. Set to_tag_pref parameter
57
+   1-7. Set lock_set_size parameter
58
+   1-8. Set expires_offset parameter
59
+   1-9. Set max_expires parameter
60
+   1-10. Set server_address parameter
61
+   1-11. handle_publish usage
62
+   1-12. handle_subscribe usage
63
+   1-13. PRESENCE tables
64
+   2-1. event_api_t structure
66 65
      _________________________________________________________
67 66
 
68 67
 Chapter 1. User's Guide
69 68
 
70 69
 1.1. Overview
71 70
 
72
-   The modules implements a presence server. It handles PUBLISH
73
-   and SUBSCRIBE messages and generates NOTIFY messages. It
74
-   offers support for aggregation of published presence
75
-   information for the same presentity using more devices. It can
76
-   also filter the information provided to watchers according to
77
-   privacy rules.
71
+   The modules handles PUBLISH and SUBSCRIBE messages and
72
+   generates NOTIFY messages in a general, event independent way.
73
+   It allows registering events to it from other OpenSER modules.
74
+   Events that can currently be added to it are: presence,
75
+   presence.winfo, dialog;sla from presence_xml module.
78 76
 
79 77
    The modules works with database storage. It stores published
80 78
    information and Subscribe -Notify dialog characteristics.
81
-   There is also an extra table which stores xcap documents with
82
-   permission rules.
83 79
 
84 80
    The server follows the specifications in: RFC3265, RFC3856,
85 81
    RFC3857, RFC3858.
86 82
      _________________________________________________________
87 83
 
88
-1.2. To-do
89
-
90
-   Provide support for clients which implement end-to-end
91
-   presence.
92
-     _________________________________________________________
93
-
94
-1.3. Dependencies
84
+1.2. Dependencies
95 85
 
96
-1.3.1. OpenSER Modules
86
+1.2.1. OpenSER Modules
97 87
 
98 88
    The following modules must be loaded before this module:
99 89
 
... ...
@@ -102,17 +98,14 @@ Chapter 1. User's Guide
102 102
      * tm.
103 103
      _________________________________________________________
104 104
 
105
-1.3.2. External Libraries or Applications
106
-
107
-   The following libraries or applications must be installed
108
-   before running OpenSER with this module loaded:
105
+1.2.2. External Libraries or Applications
109 106
 
110
-     * libxml.
107
+   None.
111 108
      _________________________________________________________
112 109
 
113
-1.4. Exported Parameters
110
+1.3. Exported Parameters
114 111
 
115
-1.4.1. db_url(str)
112
+1.3.1. db_url(str)
116 113
 
117 114
    The database url.
118 115
 
... ...
@@ -125,7 +118,7 @@ modparam("presence", "db_url",
125 125
 ...
126 126
      _________________________________________________________
127 127
 
128
-1.4.2. presentity_table(str)
128
+1.3.2. presentity_table(str)
129 129
 
130 130
    The name of the db table where Publish information are stored.
131 131
 
... ...
@@ -137,7 +130,7 @@ modparam("presence", "presentity_table", "presentity");
137 137
 ...
138 138
      _________________________________________________________
139 139
 
140
-1.4.3. active_watchers_table(str)
140
+1.3.3. active_watchers_table(str)
141 141
 
142 142
    The name of the db table where active subscription information
143 143
    are stored.
... ...
@@ -150,7 +143,7 @@ modparam("presence", "active_watchers_table", "active_watchers")
150 150
 ...
151 151
      _________________________________________________________
152 152
 
153
-1.4.4. watchers_table(str)
153
+1.3.4. watchers_table(str)
154 154
 
155 155
    The name of the db table where subscription states are stored.
156 156
 
... ...
@@ -162,58 +155,46 @@ modparam("presence", "watchers_table", "watchers")
162 162
 ...
163 163
      _________________________________________________________
164 164
 
165
-1.4.5. xcap_table(str)
166
-
167
-   The name of the db table where XCAP XMLs are stored.
168
-
169
-   Default value is "scap_xml". 
170
-
171
-   Example 1-5. Set xcap_table parameter
172
-...
173
-modparam("presence", "xcap_table", "xcaps")
174
-...
175
-     _________________________________________________________
176
-
177
-1.4.6. clean_period (int)
165
+1.3.5. clean_period (int)
178 166
 
179 167
    The period at which to verify if there are expired messages
180 168
    stored in database.
181 169
 
182 170
    Default value is "100". 
183 171
 
184
-   Example 1-6. Set clean_period parameter
172
+   Example 1-5. Set clean_period parameter
185 173
 ...
186 174
 modparam("presence", "clean_period", 100)
187 175
 ...
188 176
      _________________________________________________________
189 177
 
190
-1.4.7. to_tag_pref (str)
178
+1.3.6. to_tag_pref (str)
191 179
 
192 180
    The prefix used when generating to_tag when sending replies
193 181
    for SUBSCRIBE requests.
194 182
 
195 183
    Default value is "10". 
196 184
 
197
-   Example 1-7. Set to_tag_pref parameter
185
+   Example 1-6. Set to_tag_pref parameter
198 186
 ...
199 187
 modparam("presence", "to_tag_pref", 'a')
200 188
 ...
201 189
      _________________________________________________________
202 190
 
203
-1.4.8. lock_set_size (int)
191
+1.3.7. lock_set_size (int)
204 192
 
205 193
    The size of the lock used for synchronizing updating
206 194
    information from database.
207 195
 
208 196
    Default value is "8". 
209 197
 
210
-   Example 1-8. Set lock_set_size parameter
198
+   Example 1-7. Set lock_set_size parameter
211 199
 ...
212 200
 modparam("presence", "lock_set_size", 8)
213 201
 ...
214 202
      _________________________________________________________
215 203
 
216
-1.4.9. expires_offset (int)
204
+1.3.8. expires_offset (int)
217 205
 
218 206
    The value that should be subtracted from the expires value
219 207
    when sending a 200OK for a publish. It is used for forcing the
... ...
@@ -221,75 +202,56 @@ modparam("presence", "lock_set_size", 8)
221 221
 
222 222
    Default value is "0". 
223 223
 
224
-   Example 1-9. Set expires_offset parameter
224
+   Example 1-8. Set expires_offset parameter
225 225
 ...
226 226
 modparam("presence", "expires_offset", 10)
227 227
 ...
228 228
      _________________________________________________________
229 229
 
230
-1.4.10. force_active (int)
231
-
232
-   This parameter is used for permissions when handling Subscribe
233
-   messages. If set to 1, subscription state is considered active
234
-   and the presentity is not queried for permissions. Otherwise,
235
-   the xcap_table is queried and the state is extracted from
236
-   there. If no record exists, the subscriptions remains in
237
-   pending state and the watcher receives Notify messages with no
238
-   body. ( If not using an xcap server, you should set this
239
-   parameter to 1).
240
-
241
-   Default value is "0". 
242
-
243
-   Example 1-10. Set force_active parameter
244
-...
245
-modparam("presence", "force_active", 1)
246
-...
247
-     _________________________________________________________
248
-
249
-1.4.11. max_expires (int)
230
+1.3.9. max_expires (int)
250 231
 
251 232
    The the maximum admissible expires value for PUBLISH/SUBSCRIBE
252 233
    message.
253 234
 
254 235
    Default value is "3600". 
255 236
 
256
-   Example 1-11. Set max_expires parameter
237
+   Example 1-9. Set max_expires parameter
257 238
 ...
258 239
 modparam("presence", "max_expires", 3600)
259 240
 ...
260 241
      _________________________________________________________
261 242
 
262
-1.4.12. server_address (str)
243
+1.3.10. server_address (str)
263 244
 
264 245
    The presence server address which will become the value of
265 246
    Contact header filed for 200OK replyes to Subscribe and
266 247
    Publish and in Notify messages.
267 248
 
268
-   Example 1-12. Set server_address parameter
249
+   Example 1-10. Set server_address parameter
269 250
 ...
270 251
 modparam("presence", "server_address", "sip:10.10.10.10:5060")
271 252
 ...
272 253
      _________________________________________________________
273 254
 
274
-1.5. Exported Functions
255
+1.4. Exported Functions
275 256
 
276
-1.5.1. handle_publish(char* sender_uri)
257
+1.4.1. handle_publish(char* sender_uri)
277 258
 
278 259
    The function handles PUBLISH requests. It stores and updates
279
-   presence information in database and calls functions to send
280
-   NOTIFY messages when changes in presence information occur. It
281
-   takes one argument -> sender_uri. The parameter was added for
282
-   enabling BLA implementation. If present, Notification of a
283
-   change in presence state is not sent to the respective uri
284
-   even though a subscription exists. It should be taken from the
285
-   Sender header. It was left at the decision of the
286
-   administrator whether or not to transmit the content of this
287
-   header as parameter for handle_publish, to prevent security
288
-   problems.
260
+   published information in database and calls functions to send
261
+   NOTIFY messages when changes in the published information
262
+   occur. It takes one argument -> sender_uri. The parameter was
263
+   added for enabling BLA implementation. If present,
264
+   Notification of a change in published state is not sent to the
265
+   respective uri even though a subscription exists. It should be
266
+   taken from the Sender header. It was left at the decision of
267
+   the administrator whether or not to transmit the content of
268
+   this header as parameter for handle_publish, to prevent
269
+   security problems.
289 270
 
290 271
    This function can be used from REQUEST_ROUTE.
291 272
 
292
-   Example 1-13. handle_publish usage
273
+   Example 1-11. handle_publish usage
293 274
 ...
294 275
         if(is_method("PUBLISH"))
295 276
         {
... ...
@@ -302,7 +264,7 @@ modparam("presence", "server_address", "sip:10.10.10.10:5060")
302 302
 ...
303 303
      _________________________________________________________
304 304
 
305
-1.5.2. handle_subscribe()
305
+1.4.2. handle_subscribe()
306 306
 
307 307
    The function which handles SUBSCRIBE requests. It stores or
308 308
    updates information in database and calls functions to send
... ...
@@ -311,19 +273,19 @@ modparam("presence", "server_address", "sip:10.10.10.10:5060")
311 311
 
312 312
    This function can be used from REQUEST_ROUTE.
313 313
 
314
-   Example 1-14. handle_subscribe usage
314
+   Example 1-12. handle_subscribe usage
315 315
 ...
316 316
 if(method=="SUBSCRIBE")
317 317
     handle_subscribe();
318 318
 ...
319 319
      _________________________________________________________
320 320
 
321
-1.6. Installation
321
+1.5. Installation
322 322
 
323
-   The module requires 4 table in OpenSER database. Next SQL
323
+   The module requires 3 table in OpenSER database. Next SQL
324 324
    statements shows the syntax to create them.
325 325
 
326
-   Example 1-15. PRESENCE tables
326
+   Example 1-13. PRESENCE tables
327 327
 ...
328 328
 
329 329
 use openser;
... ...
@@ -381,24 +343,121 @@ CREATE TABLE `watchers` (
381 381
 ) ENGINE=MyISAM;
382 382
 
383 383
 
384
+...
385
+     _________________________________________________________
384 386
 
385
-CREATE TABLE `xcap_xml` (
386
-  `id` int(10) NOT NULL auto_increment,
387
-  `username` varchar(66) NOT NULL,
388
-  `domain` varchar(128) NOT NULL,
389
-  `xcap` text NOT NULL,
390
-  `doc_type` int(11) NOT NULL,
391
-  UNIQUE KEY udd_xcap (`username`,`domain`,`doc_type`),
392
-  PRIMARY KEY (id)
393
-) ENGINE=MyISAM;
387
+Chapter 2. Developer's Guide
388
+
389
+   The module provides the following functions that can be used
390
+   in other OpenSER modules.
391
+     _________________________________________________________
392
+
393
+2.1. bind_presence(event_api_t* api)
394
+
395
+   This function binds the presence modules and fills the
396
+   structure with one exported function -> add_event, which when
397
+   called adds a new event to be handled by presence.
394 398
 
399
+   Example 2-1. event_api_t structure
400
+...
401
+typedef struct event_api {
402
+        add_event_t add_event;
403
+} event_api_t;
395 404
 ...
396 405
      _________________________________________________________
397 406
 
398
-Chapter 2. Developer's Guide
407
+2.2. add_event(ev_t* event)
408
+
409
+   This function receives as a parameter a structure with event
410
+   specific information and adds it to presence list.
411
+
412
+   The structure received as a parameter:
413
+...
414
+typedef struct ev
415
+{
416
+        str name;
417
+        str* param;         // required param
418
+        str stored_name;
419
+        str content_type;
420
+        int type;
421
+/*      it can be: PUBL_TYPE or WINFO_TYPE */
422
+        int req_auth;
423
+/* flag to mark if the event requires authorization*/
424
+        apply_auth_t*  apply_auth_nbody;
425
+        is_allowed_t*  is_watcher_allowed;
426
+
427
+        agg_nbody_t* agg_nbody;
428
+        publ_handling_t  * evs_publ_handl;
429
+        subs_handling_t  * evs_subs_handl;
430
+
431
+/* this two should not be filed when the structure is given as a
432
+        parmeter for add_event function */
433
+        struct ev* wipeer;
434
+        struct ev* next;
435
+
436
+}ev_t;
437
+...
438
+     _________________________________________________________
439
+
440
+2.3. apply_auth_nbody
441
+
442
+   This parameter should be a function to be calledfor an event
443
+   that requires authorization, when constructing final body. It
444
+   is called only if the req_auth field is not 0.
445
+
446
+   Filed type:
447
+...
448
+typedef int (apply_auth_t)(str* , struct subscription*, str* );
449
+..
450
+     _________________________________________________________
451
+
452
+2.4. is_watcher_allowed
453
+
454
+   This filed is a function to be called for a subscription
455
+   request to return the state for that subscription according to
456
+   authorization rules. It is called only if the req_auth field
457
+   is not 0.
458
+
459
+   Filed type:
460
+...
461
+typedef int (is_allowed_t)(struct subscription* subs);
462
+..
463
+     _________________________________________________________
464
+
465
+2.5. agg_nbody
466
+
467
+   If present, this field marks that the events requires
468
+   aggregation of states. This function receives a body array and
469
+   should return the final body. If not present, it is considered
470
+   that the event does not require aggregation and the most
471
+   recent published information is used when constructing
472
+   Notifies.
473
+
474
+   Filed type:
475
+...
476
+typedef str* (agg_nbody_t)(str** body_array, int n, int off_index);
477
+..
478
+     _________________________________________________________
479
+
480
+2.6. evs_publ_handl
399 481
 
400
-   The module does not provide any API to use in other OpenSER
401
-   modules.
482
+   This function is called when handling Publish requests. Most
483
+   contain body correctitude check.
484
+
485
+...
486
+typedef int (publ_handling_t)(struct sip_msg*);
487
+..
488
+     _________________________________________________________
489
+
490
+2.7. evs_subs_handl
491
+
492
+   It is not compulsory. Should contain event specific handling
493
+   for Subscription requests.
494
+
495
+   Filed type:
496
+...
497
+typedef int (subs_handling_t)(struct sip_msg*);
498
+..
402 499
      _________________________________________________________
403 500
 
404 501
 Chapter 3. Frequently Asked Questions
405 502
new file mode 100644
... ...
@@ -0,0 +1,48 @@
0
+/*
1
+ * $Id: bind_presence.c 1979 2007-04-06 13:24:12Z anca_vamanu $
2
+ *
3
+ * presence module - presence server implementation
4
+ *
5
+ * Copyright (C) 2006 Voice Sistem S.R.L.
6
+ *
7
+ * This file is part of openser, a free SIP server.
8
+ *
9
+ * openser is free software; you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation; either version 2 of the License, or
12
+ * (at your option) any later version
13
+ *
14
+ * openser is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License 
20
+ * along with this program; if not, write to the Free Software 
21
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
+ *
23
+ * History:
24
+ * --------
25
+ *  2007-04-17  initial version (anca)
26
+ */
27
+#include "bind_presence.h"
28
+#include "../../dprint.h"
29
+#include "../../sr_module.h"
30
+
31
+int bind_presence(event_api_t* api)
32
+{
33
+	if (!api) {
34
+		LOG(L_ERR, "NOTIFIER:bind_notifier: Invalid parameter value\n");
35
+		return -1;
36
+	}
37
+	api->add_event = (add_event_t )find_export("add_event", 1, 0);
38
+	if(!api->add_event)
39
+	{
40
+		LOG(L_ERR, "NOTIFIER:bind_notifier: Can't bind add_event\n");
41
+		return -1;
42
+	}
43
+
44
+	return 0;
45
+}
46
+
47
+
0 48
new file mode 100644
... ...
@@ -0,0 +1,43 @@
0
+/*
1
+ * $Id: bind_presence.h 1979 2007-04-06 13:24:12Z anca_vamanu $
2
+ *
3
+ * presence module - presence server implementation
4
+ *
5
+ * Copyright (C) 2007 Voice Sistem S.R.L.
6
+ *
7
+ * This file is part of openser, a free SIP server.
8
+ *
9
+ * openser is free software; you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation; either version 2 of the License, or
12
+ * (at your option) any later version
13
+ *
14
+ * openser is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License 
20
+ * along with this program; if not, write to the Free Software 
21
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
+ *
23
+ * History:
24
+ * --------
25
+ *  2007-04-17  initial version (anca)
26
+ */
27
+
28
+#ifndef _PRES_BIND_H_
29
+#define _PRES_BIND_H_
30
+
31
+#include "event_list.h"
32
+
33
+typedef struct event_api {
34
+	add_event_t add_event;
35
+} event_api_t;
36
+
37
+int bind_presence(event_api_t* api);
38
+
39
+typedef int (*bind_presence_t)(event_api_t* api);
40
+
41
+#endif
42
+
... ...
@@ -53,14 +53,3 @@ CREATE TABLE `watchers` (
53 53
   PRIMARY KEY (id)
54 54
 ) ENGINE=MyISAM;
55 55
 
56
-
57
-
58
-CREATE TABLE `xcap_xml` (
59
-  `id` int(10) NOT NULL auto_increment,
60
-  `username` varchar(66) NOT NULL,
61
-  `domain` varchar(128) NOT NULL,
62
-  `xcap` text NOT NULL,
63
-  `doc_type` int(11) NOT NULL,
64
-  UNIQUE KEY udd_xcap (`username`,`domain`,`doc_type`),
65
-  PRIMARY KEY (id)
66
-) ENGINE=MyISAM;
... ...
@@ -11,8 +11,164 @@
11 11
     </chapterinfo>
12 12
     <title>Developer's Guide</title>
13 13
     <para>
14
-	The module does not provide any <acronym>API</acronym> to use in other &ser; modules.
15
-    </para>
14
+		The module provides the following functions that can be used
15
+		in other &ser; modules.
16
+   </para>
17
+ 		<section>
18
+				<title>
19
+				<function moreinfo="none">bind_presence(event_api_t* api)</function>
20
+				</title>
21
+			<para>
22
+				This function binds the presence modules and fills the structure 
23
+				with one exported function -> add_event, which when called adds a 
24
+				new event to be handled by presence.
25
+			</para>
26
+		<example>
27
+		<title><function>event_api_t</function> structure</title>
28
+	<programlisting format="linespecific">
29
+...
30
+typedef struct event_api {
31
+	add_event_t add_event;
32
+} event_api_t;
33
+...
34
+</programlisting>
35
+		</example>
36
+
37
+		</section>
38
+	
39
+	<section>
40
+			<title>
41
+			<function moreinfo="none">add_event(ev_t* event)</function>
42
+			</title>
43
+		<para>
44
+			This function receives as a parameter a structure with event specific
45
+			information and adds it to presence list.
46
+		</para>
47
+		<para>
48
+		The structure received as a parameter:
49
+	<programlisting format="linespecific">
50
+...
51
+typedef struct ev
52
+{
53
+	str name;
54
+	str* param;         // required param 
55
+	str stored_name;
56
+	str content_type;
57
+	int type;
58
+/*	it can be: PUBL_TYPE or WINFO_TYPE */
59
+	int req_auth;
60
+/* flag to mark if the event requires authorization*/	
61
+	apply_auth_t*  apply_auth_nbody;
62
+	is_allowed_t*  is_watcher_allowed;
63
+	
64
+	agg_nbody_t* agg_nbody;
65
+	publ_handling_t  * evs_publ_handl;
66
+	subs_handling_t  * evs_subs_handl;
67
+
68
+/* this two should not be filed when the structure is given as a
69
+	parmeter for add_event function */
70
+	struct ev* wipeer;			
71
+	struct ev* next;
72
+	
73
+}ev_t;
74
+...
75
+</programlisting>
76
+		</section>
77
+
78
+<section>
79
+		<title>
80
+			<function moreinfo="none">apply_auth_nbody</function>
81
+		</title>
82
+		<para>
83
+			This parameter should be a function to be calledfor an event that requires
84
+			authorization, when constructing final body. It is called only if the
85
+			req_auth field is not 0.
86
+		</para>
87
+		<para>
88
+			Filed type:
89
+			<programlisting format="linespecific">
90
+...
91
+typedef int (apply_auth_t)(str* , struct subscription*, str* );
92
+..
93
+			</programlisting>
94
+			</para>
95
+</section>			
96
+
97
+<section>
98
+		<title>
99
+			<function moreinfo="none">is_watcher_allowed</function>
100
+		</title>
101
+		<para>
102
+			This filed is a function to be called for a subscription request to
103
+			return the state for that subscription according to authorization rules.
104
+			It is called only if the req_auth field is not 0.
105
+		</para>
106
+		<para>
107
+			Filed type:
108
+			<programlisting format="linespecific">
109
+...
110
+typedef int (is_allowed_t)(struct subscription* subs);
111
+..
112
+			</programlisting>
113
+			</para>
114
+</section>	
115
+
116
+<section>
117
+		<title>
118
+			<function moreinfo="none">agg_nbody</function>
119
+		</title>
120
+		<para>
121
+			If present, this field marks that the events requires aggregation of states.
122
+			This function receives a body array and should return the final body.
123
+			If not present, it is considered that the event does not require aggregation and
124
+			the most recent published information is used when constructing Notifies.
125
+		</para>
126
+		<para>
127
+		Filed type:
128
+			<programlisting format="linespecific">
129
+...
130
+typedef str* (agg_nbody_t)(str** body_array, int n, int off_index);
131
+..
132
+			</programlisting>
133
+			</para>
134
+</section>	
135
+
136
+<section>
137
+		<title>
138
+			<function moreinfo="none">evs_publ_handl</function>
139
+		</title>
140
+		<para>
141
+		This function is called when handling Publish requests. Most contain 
142
+		body correctitude check.
143
+		</para>
144
+		<para>
145
+			<programlisting format="linespecific">
146
+...
147
+typedef int (publ_handling_t)(struct sip_msg*);
148
+..
149
+			</programlisting>
150
+			</para>
151
+</section>	
152
+
153
+<section>
154
+		<title>
155
+			<function moreinfo="none">evs_subs_handl</function>
156
+		</title>
157
+		<para>
158
+		It is not compulsory. Should contain event specific handling for
159
+		Subscription requests.
160
+		</para>
161
+		<para>
162
+		Filed type:
163
+			<programlisting format="linespecific">
164
+...
165
+typedef int (subs_handling_t)(struct sip_msg*);
166
+..
167
+			</programlisting>
168
+			</para>
169
+</section>	
170
+
171
+
16 172
 </chapter>
17 173
 
18 174
 <!-- Keep this element at the end of the file
... ...
@@ -13,17 +13,14 @@
13 13
 	
14 14
 	<section>
15 15
 	<title>Overview</title>
16
-	<para> The modules implements a presence server. It handles PUBLISH
17
-	and SUBSCRIBE messages and generates NOTIFY messages. It
18
-	offers support for aggregation of published presence
19
-	information for the same presentity using more devices. It can
20
-	also filter the information provided to watchers according to
21
-	privacy rules.
16
+	<para> The modules handles PUBLISH and SUBSCRIBE messages and generates
17
+	NOTIFY messages in a general, event independent way. It allows registering 
18
+	events to it from other &ser modules. Events that can currently be added to
19
+	it are: presence, presence.winfo, dialog;sla from presence_xml module.
22 20
 	</para>
23 21
 	<para>
24 22
 	The modules works with database storage. It stores published information 
25
-	and Subscribe -Notify dialog characteristics. There is also an extra table
26
-	which stores xcap documents with permission rules. 
23
+	and Subscribe -Notify dialog characteristics.
27 24
 	</para>
28 25
 	<para>
29 26
 	The server follows the specifications in: RFC3265, RFC3856, RFC3857, 
... ...
@@ -32,14 +29,6 @@
32 32
 	</section>
33 33
 
34 34
 	<section>
35
-	<title>To-do</title>
36
-		<para>
37
-		Provide support for clients which implement 
38
-		end-to-end presence. 
39
-		</para>
40
-	</section>
41
-	
42
-	<section>
43 35
 	<title>Dependencies</title>
44 36
 	<section>
45 37
 		<title>&ser; Modules</title>
... ...
@@ -68,15 +57,7 @@
68 68
 	<section>
69 69
 		<title>External Libraries or Applications</title>
70 70
 		<para>
71
-		The following libraries or applications must be installed before running
72
-		&ser; with this module loaded:
73
-			<itemizedlist>
74
-			<listitem>
75
-			<para>
76
-				<emphasis>libxml</emphasis>.
77
-			</para>
78
-			</listitem>
79
-			</itemizedlist>
71
+			None.
80 72
 		</para>
81 73
 	</section>
82 74
 	</section>
... ...
@@ -157,24 +138,6 @@ modparam("presence", "watchers_table", "watchers")
157 157
 </programlisting>
158 158
 		</example>
159 159
 	</section>
160
-	<section>
161
-		<title><varname>xcap_table</varname>(str)</title>
162
-		<para>
163
-		The name of the db table where XCAP XMLs are stored.
164
-		</para>
165
-		<para>
166
-		<emphasis>	Default value is <quote>scap_xml</quote>.
167
-		</emphasis>
168
-		</para>
169
-		<example>
170
-		<title>Set <varname>xcap_table</varname> parameter</title>
171
-		<programlisting format="linespecific">
172
-...
173
-modparam("presence", "xcap_table", "xcaps")
174
-...
175
-</programlisting>
176
-		</example>
177
-	</section>
178 160
 
179 161
 	<section>
180 162
 		<title><varname>clean_period</varname> (int)</title>
... ...
@@ -258,30 +221,6 @@ modparam("presence", "expires_offset", 10)
258 258
 	</section>
259 259
 
260 260
 	<section>
261
-		<title><varname>force_active</varname> (int)</title>
262
-		<para>
263
-		This parameter is used for permissions when handling Subscribe messages.
264
-		If set to 1, subscription state is considered active and the presentity
265
-		is not queried for permissions. 
266
-		Otherwise, the xcap_table is queried and the state is extracted
267
-		from there. If no record exists, the subscriptions remains in pending
268
-		state and the watcher receives Notify messages with no body.
269
-		( If not using an xcap server, you should set this parameter to 1).
270
-		</para>
271
-		<para>
272
-		<emphasis>Default value is <quote>0</quote>.
273
-		</emphasis>
274
-		</para>
275
-		<example>
276
-		<title>Set <varname>force_active</varname> parameter</title>
277
-		<programlisting format="linespecific">
278
-...
279
-modparam("presence", "force_active", 1)
280
-...
281
-</programlisting>
282
-		</example>
283
-	</section>
284
-	<section>
285 261
 		<title><varname>max_expires</varname> (int)</title>
286 262
 		<para>
287 263
 		The the maximum admissible expires value for PUBLISH/SUBSCRIBE 
... ...
@@ -327,11 +266,11 @@ modparam("presence", "server_address", "sip:10.10.10.10:5060")
327 327
 		</title>
328 328
 		<para>
329 329
 		The function handles PUBLISH requests. It stores and updates 
330
-		presence information in database and calls functions to send 
331
-		NOTIFY messages when changes in presence information occur.
330
+		published information in database and calls functions to send 
331
+		NOTIFY messages when changes in the published information occur.
332 332
 		It takes one argument -> sender_uri. The parameter was added 
333 333
 		for enabling BLA implementation. If present, Notification of
334
-		a change in presence state is not sent to the respective uri
334
+		a change in published state is not sent to the respective uri
335 335
 		even though a subscription exists.
336 336
 		It should be taken from the Sender header. It was left at the
337 337
 		decision of the administrator whether or not to transmit the 
... ...
@@ -385,7 +324,7 @@ if(method=="SUBSCRIBE")
385 385
 <section>
386 386
 	<title>Installation</title>
387 387
 	<para>
388
-	The module requires 4 table in OpenSER database. Next SQL statements
388
+	The module requires 3 table in OpenSER database. Next SQL statements
389 389
 	shows the syntax to create them.
390 390
 	</para>
391 391
 	<example>
... ...
@@ -33,45 +33,39 @@
33 33
 #include "../../dprint.h"
34 34
 #include "../../mem/shm_mem.h" 
35 35
 #include "event_list.h"
36
-#include "presence.h"
36
+//#include "presence.h"
37 37
 
38
-int add_event(char* name, char* param, char* content_type, int agg_body)
38
+int add_event(ev_t* event)
39 39
 {
40 40
 	ev_t* ev= NULL;
41 41
 	int size;
42
-	str str_name;
43
-	str* str_param= NULL;
44 42
 	char* sep= NULL;
45 43
 	str wipeer_name;
46 44
 	char buf[50];
47 45
 	int ret_code= 1;
48 46
 
49
-	str_name.s= name;
50
-	str_name.len= strlen(name);
47
+	if(event->name.s== NULL || event->name.len== 0)
48
+	{
49
+		LOG(L_ERR, "PRESENCE: add_event: NULL event name\n");
50
+		return -1;
51
+	}
51 52
 
52
-	if(param)
53
+	if(event->content_type.s== NULL || event->content_type.len== 0)
53 54
 	{
54
-		str_param= (str*)pkg_malloc(sizeof(str));
55
-		if(str_param== NULL)
56
-		{
57
-			LOG(L_ERR, "PRESENCE: add_event: ERROR No more memory\n");
58
-			return -1;
59
-		}
60
-		str_param->s= param;
61
-		str_param->len= strlen(param);
55
+		LOG(L_ERR, "PRESENCE: add_event: NULL content_type param\n");
56
+		return -1;
62 57
 	}
63 58
 
64
-	if(contains_event(&str_name, str_param))
59
+	if(contains_event(&event->name, event->param))
65 60
 	{
66 61
 		DBG("PRESENCE: add_event: Found prevoius record for event\n");
67 62
 		ret_code= -1;
68 63
 		goto done;
69 64
 	}	
70
-	size= sizeof(ev_t)+ (str_name.len+ strlen(content_type))
71
-		*sizeof(char);
65
+	size= sizeof(ev_t)+ (event->name.len+ event->content_type.len)*sizeof(char);
72 66
 
73
-	if(param)
74
-		size+= sizeof(str)+ ( 2*strlen(param) + str_name.len+ 1)* sizeof(char);
67
+	if(event->param)
68
+		size+= sizeof(str)+ ( 2*event->param->len + event->name.len+ 1)* sizeof(char);
75 69
 
76 70
 	ev= (ev_t*)shm_malloc(size);
77 71
 	if(ev== NULL)
... ...
@@ -84,26 +78,26 @@ int add_event(char* name, char* param, char* content_type, int agg_body)
84 84
 
85 85
 	size= sizeof(ev_t);
86 86
 	ev->name.s= (char*)ev+ size;
87
-	ev->name.len= str_name.len;
88
-	memcpy(ev->name.s, name, str_name.len);
89
-	size+= str_name.len;
87
+	ev->name.len= event->name.len;
88
+	memcpy(ev->name.s, event->name.s, event->name.len);
89
+	size+= event->name.len;
90 90
 
91
-	if(str_param)
91
+	if(event->param)
92 92
 	{	
93 93
 		ev->param= (str*)((char*)ev+ size);
94 94
 		size+= sizeof(str);
95 95
 		ev->param->s= (char*)ev+ size;
96
-		memcpy(ev->param->s, str_param->s, str_param->len);
97
-		ev->param->len= str_param->len;
98
-		size+= str_param->len;
99
-
96
+		memcpy(ev->param->s, event->param->s, event->param->len);
97
+		ev->param->len= event->param->len;
98
+		size+= event->param->len;
99
+	
100 100
 		ev->stored_name.s= (char*)ev+ size;
101
-		memcpy(ev->stored_name.s, name, str_name.len);
102
-		ev->stored_name.len= str_name.len;
101
+		memcpy(ev->stored_name.s, event->name.s, event->name.len);
102
+		ev->stored_name.len= event->name.len;
103 103
 		memcpy(ev->stored_name.s+ ev->stored_name.len, ";", 1);
104 104
 		ev->stored_name.len+= 1;
105
-		memcpy(ev->stored_name.s+ ev->stored_name.len, str_param->s, str_param->len);
106
-		ev->stored_name.len+= str_param->len;
105
+		memcpy(ev->stored_name.s+ ev->stored_name.len, event->param->s, event->param->len);
106
+		ev->stored_name.len+= event->param->len;
107 107
 		size+= ev->stored_name.len;
108 108
 	}
109 109
 	else
... ...
@@ -113,20 +107,18 @@ int add_event(char* name, char* param, char* content_type, int agg_body)
113 113
 	}	
114 114
 
115 115
 	ev->content_type.s= (char*)ev+ size;
116
-	ev->content_type.len= strlen(content_type);
117
-	memcpy(ev->content_type.s, content_type, ev->content_type.len);
116
+	ev->content_type.len= event->content_type.len;
117
+	memcpy(ev->content_type.s, event->content_type.s, event->content_type.len);
118 118
 	size+= ev->content_type.len;
119 119
 	
120
-	ev->agg_body= agg_body;
121
-	
122
-	sep= strchr(name, '.');
120
+	sep= strchr(event->name.s, '.');
123 121
 	if(sep)
124 122
 	{
125 123
 		if(strncmp(sep+1, "winfo", 5)== 0)
126 124
 		{	
127 125
 			ev->type= WINFO_TYPE;
128
-			wipeer_name.s= name;
129
-			wipeer_name.len= sep - name;
126
+			wipeer_name.s= event->name.s;
127
+			wipeer_name.len= sep - event->name.s;
130 128
 			
131 129
 			ev->wipeer= contains_event(&wipeer_name, ev->param );
132 130
 		}
... ...
@@ -134,7 +126,8 @@ int add_event(char* name, char* param, char* content_type, int agg_body)
134 134
 		{	
135 135
 			ev->type= PUBL_TYPE;
136 136
 			wipeer_name.s= buf;
137
-			wipeer_name.len= sprintf(wipeer_name.s, "%s", name);
137
+			memcpy(wipeer_name.s, event->name.s, event->name.len);
138
+			wipeer_name.len= event->name.len;
138 139
 			memcpy(wipeer_name.s+ wipeer_name.len, ".winfo", 5);
139 140
 			wipeer_name.len+= 5;
140 141
 			ev->wipeer= contains_event(&wipeer_name, ev->param);
... ...
@@ -144,13 +137,19 @@ int add_event(char* name, char* param, char* content_type, int agg_body)
144 144
 	else
145 145
 		ev->type= PUBL_TYPE;
146 146
 
147
+	ev->req_auth= event->req_auth;
148
+	ev->agg_nbody= event->agg_nbody;
149
+	ev->apply_auth_nbody= event->apply_auth_nbody;
150
+	ev->is_watcher_allowed= event->is_watcher_allowed;
151
+	ev->evs_publ_handl= event->evs_publ_handl;
152
+
147 153
 	ev->next= EvList->events;
148 154
 	EvList->events= ev;
149 155
 	EvList->ev_count++;
150 156
 
151 157
 done:
152
-	if(str_param)
153
-		pkg_free(str_param);
158
+	DBG("\n\n\nPRESENCE: add_event: SUCCESFULLY ADDED EVENT: %.*s\n\n", 
159
+			ev->stored_name.len, ev->stored_name.s);
154 160
 	return ret_code; 
155 161
 }
156 162
 
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- * $Id: event_list.c 1953 2007-04-04 08:50:33Z anca_vamanu $
2
+ * $Id: event_list.h 1953 2007-04-04 08:50:33Z anca_vamanu $
3 3
  *
4 4
  * presence module - presence server implementation
5 5
  *
... ...
@@ -26,28 +26,71 @@
26 26
  *  2007-04-05  initial version (anca)
27 27
  */
28 28
 
29
-#ifndef _PRES_EV_LST_
30
-#define  _PRES_EV_LST_
29
+#ifndef _PRES_EV_LST_H
30
+#define  _PRES_EV_LST_H
31 31
 
32
+#include "../../parser/msg_parser.h"
32 33
 #include "../../str.h"
34
+#include "subscribe.h"
33 35
 
34 36
 #define WINFO_TYPE			1<< 0
35 37
 #define PUBL_TYPE		    1<< 1
36 38
 
37
-typedef struct ev
39
+struct subscription;
40
+
41
+typedef int (apply_auth_t)(str* , struct subscription*, str* );
42
+
43
+typedef int (publ_handling_t)(struct sip_msg*);
44
+
45
+typedef int (subs_handling_t)(struct sip_msg*);
46
+
47
+typedef str* (agg_nbody_t)(str** body_array, int n, int off_index);
48
+/* params for agg_body_t 
49
+ *	body_array= an array with all the bodies stored for that resource
50
+ *	n= the number of bodies
51
+ *	off_index= the index of the registration(etag) for which a Publish
52
+ *				with Expires: 0 has just been received
53
+ *	*/
54
+typedef int (is_allowed_t)(struct subscription* subs);
55
+/* return code rules for is_allowed_t
56
+ *	< 0  if error occured
57
+ *	=0	 if no change in status(if no xcap document exists)
58
+ *	>0   if change in status
59
+ *	*/
60
+
61
+struct ev
38 62
 {
39 63
 	str name;
40 64
 	str* param;         // required param 
41 65
 	/* to do: transform it in a list ( for multimple param)*/
42 66
 	str stored_name;
43 67
 	str content_type;
44
-	int agg_body;
45 68
 	int type;
69
+
70
+	/* fileds that deal with authorization rules*/
71
+	/*
72
+	 *  req_auth -> flag 0  - if not require 
73
+	 *  is_watcher_allowed  - get subscription state from xcap rules
74
+	 *  apply_auth_nbody    - alter the body according to authorization rules
75
+	 */
46 76
 	int req_auth;
47
-	struct ev* wipeer; /* can be NULL or the name of teh winfo event */
77
+	apply_auth_t*  apply_auth_nbody;
78
+	is_allowed_t*  is_watcher_allowed;
79
+	
80
+	/* an agg_body_t function should be registered if the event permits having
81
+	 * multiple published states and requires an aggregation of the information
82
+	 * otherwise, this field should be NULL and the last published state is taken 
83
+	 * when constructing Notify msg 
84
+	 * */
85
+	agg_nbody_t* agg_nbody;
86
+	publ_handling_t  * evs_publ_handl;
87
+	subs_handling_t  * evs_subs_handl;
88
+
89
+	struct ev* wipeer;			
48 90
 	struct ev* next;
49 91
 	
50
-}ev_t;
92
+};
93
+typedef struct ev ev_t;
51 94
 
52 95
 typedef struct evlist
53 96
 {
... ...
@@ -57,10 +100,14 @@ typedef struct evlist
57 57
 
58 58
 evlist_t* init_evlist();
59 59
 
60
-int add_event(char* name, char* param, char* content_type, int agg_body);
60
+int add_event(ev_t* event);
61
+
62
+typedef int (*add_event_t)(ev_t* event);
61 63
 
62 64
 ev_t* contains_event(str* name, str* param);
63 65
 
64 66
 void destroy_evlist();
65 67
 
68
+extern evlist_t* EvList;
69
+
66 70
 #endif
... ...
@@ -29,6 +29,7 @@
29 29
 #include <stdio.h>
30 30
 #include <stdlib.h>
31 31
 #include <string.h>
32
+#include <libxml/parser.h>
32 33
 
33 34
 #include "../../trim.h"
34 35
 #include "../../ut.h"
... ...
@@ -42,7 +43,6 @@
42 42
 
43 43
 #include "presence.h"
44 44
 #include "notify.h"
45
-#include "pidf.h"
46 45
 #include "utils_func.h"
47 46
 
48 47
 extern struct tm_binds tmb;
... ...
@@ -65,6 +65,7 @@ void printf_subs(subs_t* subs)
65 65
 			subs->to_tag.len, subs->to_tag.s,	subs->from_tag.len, subs->from_tag.s);
66 66
 
67 67
 }
68
+str* create_winfo_xml(watcher_t* watchers,int n, char* version,char* resource, int STATE_FLAG );
68 69
 
69 70
 str* build_str_hdr(ev_t* event, str event_id, str status, int expires_t,
70 71
 		str reason,str* local_contact)
... ...
@@ -390,7 +391,7 @@ error:
390 390
 	return NULL;
391 391
 
392 392
 }
393
-str* get_p_notify_body(str user, str host, str* etag, ev_t* event)
393
+str* get_p_notify_body(str user, str host, str* etag, ev_t* event, subs_t* subs)
394 394
 {
395 395
 	db_key_t query_cols[6];
396 396
 	db_op_t  query_ops[6];
... ...
@@ -467,16 +468,10 @@ str* get_p_notify_body(str user, str host, str* etag, ev_t* event)
467 467
 	else
468 468
 	{
469 469
 		n= result->n;
470
-		if(!event->agg_body )
470
+		if(event->agg_nbody== NULL )
471 471
 		{
472 472
 			int len;
473
-		/*	if(n>1)
474
-			{
475
-				LOG(L_ERR, "PRESENCE:get_p_notify_body: ERROR multiple published" 
476
-					" dialog states stored for the same BLA AOR\n");
477
-				goto error;
478
-			}
479
-		*/
473
+			DBG("PRESENCE:get_p_notify_body: Event does not require aggregation\n");
480 474
 			row = &result->rows[0];
481 475
 			row_vals = ROW_VALUES(row);
482 476
 			if(row_vals[body_col].val.string_val== NULL)
... ...
@@ -510,6 +505,8 @@ str* get_p_notify_body(str user, str host, str* etag, ev_t* event)
510 510
 			goto done;
511 511
 		}
512 512
 		
513
+		DBG("PRESENCE:get_p_notify_body: Event requires aggregation\n");
514
+
513 515
 		body_array =(str**)pkg_malloc( (result->n)*sizeof(str*));
514 516
 		if(body_array == NULL)
515 517
 		{
... ...
@@ -537,17 +534,8 @@ str* get_p_notify_body(str user, str host, str* etag, ev_t* event)
537 537
 				{
538 538
 					DBG("PRESENCE:get_p_notify_body found etag  \n");
539 539
 					build_off_n= i;
540
-					
541
-					body_array[build_off_n]= offline_nbody(&row_vals[body_col].val.str_val);
542
-					if(body_array[i] == NULL)
543
-					{
544
-						DBG("PRESENCE: get_p_notify_body:The users's"
545
-								"status was already offline\n");
546
-						goto error;
547
-					}
548
-				}
549
-				else
550
-					body_array[i] =&row_vals[body_col].val.str_val;
540
+				}	
541
+				body_array[i] =&row_vals[body_col].val.str_val;
551 542
 			}
552 543
 		}	
553 544
 		else
... ...
@@ -559,20 +547,13 @@ str* get_p_notify_body(str user, str host, str* etag, ev_t* event)
559 559
 				body_array[i] =&row_vals[body_col].val.str_val;
560 560
 			}			
561 561
 		}
562
-		notify_body = agregate_xmls(body_array, result->n);
562
+	
563
+		notify_body = event->agg_nbody(body_array, result->n, build_off_n);
563 564
 	}
565
+
564 566
 done:	
565 567
 	if(result!=NULL)
566 568
 		pa_dbf.free_result(pa_db, result);
567
-	if(build_off_n >= 0)
568
-	{
569
-		if(body_array[build_off_n])
570
-		{
571
-			if(body_array[build_off_n]->s)
572
-				xmlFree(body_array[build_off_n]->s);
573
-			pkg_free(body_array[build_off_n]);
574
-		}
575
-	}	
576 569
 	if(body_array!=NULL)
577 570
 		pkg_free(body_array);
578 571
 	return notify_body;
... ...
@@ -580,15 +561,6 @@ done:
580 580
 error:
581 581
 	if(result!=NULL)
582 582
 		pa_dbf.free_result(pa_db, result);
583
-	if(build_off_n > 0)
584
-	{
585
-		if(body_array[build_off_n])
586
-		{
587
-			if(body_array[build_off_n]->s)
588
-				xmlFree(body_array[build_off_n]->s);
589
-			pkg_free(body_array[build_off_n]);
590
-		}
591
-	}	
592 583
 
593 584
 	if(body_array!=NULL)
594 585
 		pkg_free(body_array);
... ...
@@ -838,7 +810,8 @@ subs_t** get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender, in
838 838
 	{
839 839
 		row = &result->rows[i];
840 840
 		row_vals = ROW_VALUES(row);		
841
-		
841
+	
842
+		memset(&status, 0, sizeof(str));
842 843
 		from_user.s= (char*)row_vals[from_user_col].val.string_val;
843 844
 		from_user.len= 	strlen(from_user.s);
844 845
 		from_domain.s= (char*)row_vals[from_domain_col].val.string_val;
... ...
@@ -865,17 +838,9 @@ subs_t** get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender, in
865 865
 		contact.s= (char*)row_vals[contact_col].val.string_val;
866 866
 		contact.len= strlen(contact.s);
867 867
 		
868
-		if(!force_active && row_vals[status_col].val.string_val)
869
-		{
870
-			status.s=  (char*)row_vals[status_col].val.string_val;
871
-			status.len= strlen(status.s);
872
-		}
873
-		else
874
-		{
875
-			status.s= NULL;
876
-			status.len= 0;
877
-		}
878
-		
868
+		status.s=  (char*)row_vals[status_col].val.string_val;
869
+		status.len= strlen(status.s);
870
+			
879 871
 		sockinfo_str.s = (char*)row_vals[sockinfo_col].val.string_val;
880 872
 		sockinfo_str.len = sockinfo_str.s?strlen (sockinfo_str.s):0;
881 873
 
... ...
@@ -884,15 +849,10 @@ subs_t** get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender, in
884 884
 		
885 885
 
886 886
 		size= sizeof(subs_t)+ (p_user->len+ p_domain->len+ from_user.len+ 
887
-				from_domain.len+ event_id.len+ to_tag.len+ 
887
+				from_domain.len+ event_id.len+ to_tag.len+ status.len+
888 888
 				from_tag.len+ callid.len+ record_route.len+ contact.len+
889 889
 				sockinfo_str.len+ local_contact.len)* sizeof(char);
890 890
 
891
-		if(force_active== 0)
892
-			size+= status.len* sizeof(char);
893
-		else
894
-			size+= 6;
895
-
896 891
 		subs= (subs_t*)pkg_malloc(size);
897 892
 		if(subs ==NULL)
898 893
 		{
... ...
@@ -913,7 +873,6 @@ subs_t** get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender, in
913 913
 		subs->to_domain.len = p_domain->len;
914 914
 		size+= p_domain->len;
915 915
 	
916
-
917 916
 		subs->event= event;
918 917
 
919 918
 		subs->from_user.s= (char*)subs+ size;
... ...
@@ -961,25 +920,12 @@ subs_t** get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender, in
961 961
 		memcpy(subs->contact.s, contact.s, contact.len);
962 962
 		subs->contact.len = contact.len;
963 963
 		size+= contact.len;
964
+	
965
+		subs->status.s= (char*)subs+ size;
966
+		memcpy(subs->status.s, status.s, status.len);
967
+		subs->status.len = status.len;
968
+		size+= status.len;
964 969
 		
965
-		if(force_active!=0)
966
-		{
967
-			subs->status.s=(char*)subs+ size;
968
-			memcpy(subs->status.s, "active", 6);
969
-			subs->status.len = 6;
970
-			size+= 6;
971
-		}
972
-		else
973
-		{
974
-			if(status.s && status.len)
975
-			{
976
-				subs->status.s= (char*)subs+ size;
977
-				memcpy(subs->status.s, status.s, status.len);
978
-				subs->status.len = status.len;
979
-				size+= status.len;
980
-			}
981
-		}
982
-
983 970
 		subs->sockinfo_str.s =(char*)subs+ size;
984 971
 		memcpy(subs->sockinfo_str.s, sockinfo_str.s, sockinfo_str.len);
985 972
 		subs->sockinfo_str.len = sockinfo_str.len;
... ...
@@ -1036,7 +982,7 @@ int query_db_notify(str* p_user, str* p_domain, ev_t* event,
1036 1036
 	
1037 1037
 	if(event->type & PUBL_TYPE)
1038 1038
 	{
1039
-		notify_body = get_p_notify_body(*p_user, *p_domain, etag, event);
1039
+		notify_body = get_p_notify_body(*p_user, *p_domain, etag, event, NULL);
1040 1040
 		if(notify_body == NULL)
1041 1041
 		{
1042 1042
 			DBG( "PRESENCE:query_db_notify: Could not get the"
... ...
@@ -1091,328 +1037,6 @@ error:
1091 1091
 	return -1;
1092 1092
 }
1093 1093
 
1094
-xmlNodePtr is_watcher_allowed( subs_t* subs, xmlDocPtr xcap_tree )
1095
-{
1096
-	xmlNodePtr ruleset_node = NULL, node1= NULL, node2= NULL;
1097
-	xmlNodePtr cond_node = NULL, except_node = NULL, actions_node = NULL;
1098
-	xmlNodePtr identity_node = NULL, validity_node =NULL, sphere_node = NULL;
1099
-	xmlNodePtr sub_handling_node = NULL;
1100
-	int apply_rule = -1;
1101
-	char* id = NULL, *domain = NULL;
1102
-	str w_uri;
1103
-	char* sub_handling = NULL;
1104
-
1105
-	if(xcap_tree == NULL)
1106
-	{
1107
-		LOG(L_ERR, "PRESENCE: is_watcher_allowed: The authorization document"
1108
-				" is NULL\n");
1109
-		return NULL;
1110
-	}
1111
-	
1112
-	uandd_to_uri(subs->from_user, subs->from_domain, &w_uri);
1113
-	if(w_uri.s == NULL)
1114
-	{
1115
-		LOG(L_ERR, "PRESENCE: is_watcher_allowed:Error while creating uri\n");
1116
-		return NULL;
1117
-	}
1118
-	ruleset_node = xmlDocGetNodeByName(xcap_tree, "ruleset", NULL);
1119
-	if(ruleset_node == NULL)
1120
-	{
1121
-		DBG( "PRESENCE:is_watcher_allowed: ruleset_node NULL\n");
1122
-		goto error;
1123
-
1124
-	}