Browse code

modules_k/rls: Updated rls_handle_subscribe() so that an optional parameter can be used to specify watcher URI

- This is useful when you want to use a URI from another SIP header
(for example, P-Asserted-Identity:) as the watcher URI.
- When the parameter is not used the From: URI is used as the
watcher URI.

Peter Dunkley authored on 19/04/2012 17:03:54
Showing 10 changed files
... ...
@@ -51,7 +51,7 @@ Anca-Maria Vamanu
51 51
 
52 52
         4. Functions
53 53
 
54
-              4.1. rls_handle_subscribe()
54
+              4.1. rls_handle_subscribe([watcher_uri])
55 55
               4.2. rls_handle_notify()
56 56
               4.3. rls_update_subs(uri, event)
57 57
 
... ...
@@ -130,7 +130,7 @@ Chapter 1. Admin Guide
130 130
 
131 131
    4. Functions
132 132
 
133
-        4.1. rls_handle_subscribe()
133
+        4.1. rls_handle_subscribe([watcher_uri])
134 134
         4.2. rls_handle_notify()
135 135
         4.3. rls_update_subs(uri, event)
136 136
 
... ...
@@ -550,17 +550,22 @@ modparam("rls", "max_backend_subs", 30)
550 550
 
551 551
 4. Functions
552 552
 
553
-   4.1. rls_handle_subscribe()
553
+   4.1. rls_handle_subscribe([watcher_uri])
554 554
    4.2. rls_handle_notify()
555 555
    4.3. rls_update_subs(uri, event)
556 556
 
557
-4.1.  rls_handle_subscribe()
557
+4.1.  rls_handle_subscribe([watcher_uri])
558 558
 
559 559
    This function detects if a Subscribe message should be handled by RLS.
560 560
    If not it replies with the configured to_presence_code. If it is, it
561 561
    extracts the dialog info and sends aggregate Notify requests with
562 562
    information for the list.
563 563
 
564
+   By default this function uses the From: URI from the SUBSCRIBE request
565
+   as the Watcher URI. The optional watcher_uri parameter can be used to
566
+   specify a different Watcher URI, possibly taken from a SIP header like
567
+   P-Asserted-Identity:.
568
+
564 569
    This function can be used from REQUEST_ROUTE.
565 570
 
566 571
    Example 1.26. rls_handle_subscribe usage
... ...
@@ -2,11 +2,13 @@
2 2
 #define RLS_API_H
3 3
 #include "../../str.h"
4 4
 
5
-typedef int (*rls_handle_subscribe_t)(struct sip_msg*, char*, char*);
5
+typedef int (*rls_handle_subscribe_t)(struct sip_msg*, str, str);
6
+typedef int (*rls_handle_subscribe0_t)(struct sip_msg*);
6 7
 typedef int (*rls_handle_notify_t)(struct sip_msg*, char*, char*);
7 8
 
8 9
 typedef struct rls_binds {
9 10
 	rls_handle_subscribe_t rls_handle_subscribe;
11
+	rls_handle_subscribe0_t rls_handle_subscribe0;
10 12
 	rls_handle_notify_t rls_handle_notify;
11 13
 } rls_api_t;
12 14
 
... ...
@@ -642,7 +642,7 @@ modparam("rls", "max_backend_subs", 30)
642 642
 	<title>Functions</title>
643 643
 	<section>
644 644
 		<title>
645
-		<function moreinfo="none">rls_handle_subscribe()</function>
645
+		<function moreinfo="none">rls_handle_subscribe([watcher_uri])</function>
646 646
 		</title>
647 647
 		<para>
648 648
 		This function detects if a Subscribe message should be
... ...
@@ -651,6 +651,12 @@ modparam("rls", "max_backend_subs", 30)
651 651
 		aggregate Notify requests with information for the list.	
652 652
 		</para>
653 653
 		<para>
654
+		By default this function uses the From: URI from the SUBSCRIBE
655
+		request as the Watcher URI.  The optional watcher_uri parameter
656
+		can be used to specify a different Watcher URI, possibly taken
657
+		from a SIP header like P-Asserted-Identity:.
658
+		</para>
659
+		<para>
654 660
 		This function can be used from REQUEST_ROUTE.
655 661
 		</para>
656 662
 		<example>
... ...
@@ -161,7 +161,7 @@ int send_full_notify(subs_t* subs, xmlNodePtr rl_node, str* rl_uri,
161 161
 
162 162
 	/* Find all the uri's to which we are subscribed */
163 163
 	param.next = &uri_list_head;
164
-	if(process_list_and_exec(rl_node, subs->from_user, subs->from_domain, add_resource_to_list,(void*)(&param))< 0)
164
+	if(process_list_and_exec(rl_node, subs->watcher_user, subs->watcher_domain, add_resource_to_list,(void*)(&param))< 0)
165 165
 	{
166 166
 		LM_ERR("in process_list_and_exec function\n");
167 167
 		goto error;
... ...
@@ -842,7 +842,7 @@ error:
842 842
 
843 843
 static void timer_send_full_state_notifies(int round)
844 844
 {
845
-	db_key_t query_cols[1], result_cols[20], update_cols[1];
845
+	db_key_t query_cols[1], result_cols[22], update_cols[1];
846 846
 	db_val_t query_vals[1], update_vals[1], *values;
847 847
 	db_row_t *rows;
848 848
 	db1_res_t *result = NULL;
... ...
@@ -861,6 +861,8 @@ static void timer_send_full_state_notifies(int round)
861 861
 	result_cols[n_result_cols++] = &str_presentity_uri_col;
862 862
 	result_cols[n_result_cols++] = &str_to_user_col;
863 863
 	result_cols[n_result_cols++] = &str_to_domain_col;
864
+	result_cols[n_result_cols++] = &str_from_user_col;
865
+	result_cols[n_result_cols++] = &str_from_domain_col;
864 866
 	result_cols[n_result_cols++] = &str_watcher_username_col;
865 867
 	result_cols[n_result_cols++] = &str_watcher_domain_col;
866 868
 	result_cols[n_result_cols++] = &str_callid_col;
... ...
@@ -920,16 +922,18 @@ static void timer_send_full_state_notifies(int round)
920 922
 		EXTRACT_STRING(sub.to_domain, VAL_STRING(&values[2]));
921 923
 		EXTRACT_STRING(sub.from_user, VAL_STRING(&values[3]));
922 924
 		EXTRACT_STRING(sub.from_domain, VAL_STRING(&values[4]));
923
-		EXTRACT_STRING(sub.callid, VAL_STRING(&values[5]));
924
-		EXTRACT_STRING(sub.to_tag, VAL_STRING(&values[6]));
925
-		EXTRACT_STRING(sub.from_tag, VAL_STRING(&values[7]));
926
-		EXTRACT_STRING(sub.sockinfo_str, VAL_STRING(&values[8]));
927
-		EXTRACT_STRING(sub.local_contact, VAL_STRING(&values[9]));
928
-		EXTRACT_STRING(sub.contact, VAL_STRING(&values[10]));
929
-		EXTRACT_STRING(sub.record_route, VAL_STRING(&values[11]));
930
-		EXTRACT_STRING(sub.event_id, VAL_STRING(&values[12]));
931
-		EXTRACT_STRING(sub.reason, VAL_STRING(&values[13]));
932
-		EXTRACT_STRING(ev_sname, VAL_STRING(&values[14]));
925
+		EXTRACT_STRING(sub.watcher_user, VAL_STRING(&values[5]));
926
+		EXTRACT_STRING(sub.watcher_domain, VAL_STRING(&values[6]));
927
+		EXTRACT_STRING(sub.callid, VAL_STRING(&values[7]));
928
+		EXTRACT_STRING(sub.to_tag, VAL_STRING(&values[8]));
929
+		EXTRACT_STRING(sub.from_tag, VAL_STRING(&values[9]));
930
+		EXTRACT_STRING(sub.sockinfo_str, VAL_STRING(&values[10]));
931
+		EXTRACT_STRING(sub.local_contact, VAL_STRING(&values[11]));
932
+		EXTRACT_STRING(sub.contact, VAL_STRING(&values[12]));
933
+		EXTRACT_STRING(sub.record_route, VAL_STRING(&values[13]));
934
+		EXTRACT_STRING(sub.event_id, VAL_STRING(&values[14]));
935
+		EXTRACT_STRING(sub.reason, VAL_STRING(&values[15]));
936
+		EXTRACT_STRING(ev_sname, VAL_STRING(&values[16]));
933 937
 		sub.event = pres_contains_event(&ev_sname, &parsed_event);
934 938
 		if (sub.event == NULL)
935 939
 		{
... ...
@@ -937,15 +941,15 @@ static void timer_send_full_state_notifies(int round)
937 941
 			goto done;
938 942
 		}
939 943
 
940
-		sub.local_cseq = VAL_INT(&values[15]);
941
-		sub.remote_cseq = VAL_INT(&values[16]);
942
-		sub.status = VAL_INT(&values[17]);
943
-		sub.version = VAL_INT(&values[18]);
944
-		sub.expires = VAL_INT(&values[19]) - (int)time(NULL);
944
+		sub.local_cseq = VAL_INT(&values[17]);
945
+		sub.remote_cseq = VAL_INT(&values[18]);
946
+		sub.status = VAL_INT(&values[19]);
947
+		sub.version = VAL_INT(&values[20]);
948
+		sub.expires = VAL_INT(&values[21]) - (int)time(NULL);
945 949
 		if (sub.expires < 0) sub.expires = 0;
946 950
 		
947
-		if (rls_get_service_list(&sub.pres_uri, &sub.from_user,
948
-			&sub.from_domain, &service_node, &doc) < 0)
951
+		if (rls_get_service_list(&sub.pres_uri, &sub.watcher_user,
952
+			&sub.watcher_domain, &service_node, &doc) < 0)
949 953
 		{
950 954
 			LM_ERR("failed getting resource list\n");
951 955
 			goto done;
... ...
@@ -56,6 +56,8 @@
56 56
 #include "notify.h"
57 57
 #include "resource_notify.h"
58 58
 #include "api.h"
59
+#include "subscribe.h"
60
+#include "../../mod_fix.h"
59 61
 
60 62
 MODULE_VERSION
61 63
 
... ...
@@ -165,6 +167,8 @@ str str_event_col = str_init("event");
165 167
 str str_event_id_col = str_init("event_id");
166 168
 str str_to_user_col = str_init("to_user");
167 169
 str str_to_domain_col = str_init("to_domain");
170
+str str_from_user_col = str_init("from_user");
171
+str str_from_domain_col = str_init("from_domain");
168 172
 str str_watcher_username_col = str_init("watcher_username");
169 173
 str str_watcher_domain_col = str_init("watcher_domain");
170 174
 str str_callid_col = str_init("callid");
... ...
@@ -197,7 +201,6 @@ int rls_max_backend_subs = 0;
197 201
 
198 202
 static int mod_init(void);
199 203
 static int child_init(int);
200
-int rls_handle_subscribe(struct sip_msg*, char*, char*);
201 204
 static void destroy(void);
202 205
 int rlsubs_table_restore();
203 206
 void rlsubs_table_update(unsigned int ticks,void *param);
... ...
@@ -207,8 +210,10 @@ int fixup_update_subs(void** param, int param_no);
207 210
 
208 211
 static cmd_export_t cmds[]=
209 212
 {
210
-	{"rls_handle_subscribe",  (cmd_function)rls_handle_subscribe,   0,
213
+	{"rls_handle_subscribe",  (cmd_function)rls_handle_subscribe0,  0,
211 214
 			0, 0, REQUEST_ROUTE},
215
+	{"rls_handle_subscribe",  (cmd_function)w_rls_handle_subscribe, 1,
216
+			fixup_spve_null, 0, REQUEST_ROUTE},
212 217
 	{"rls_handle_notify",     (cmd_function)rls_handle_notify,      0,
213 218
 			0, 0, REQUEST_ROUTE},
214 219
 	{"rls_update_subs",       (cmd_function)rls_update_subs,	2,
... ...
@@ -837,7 +842,7 @@ void rlsubs_table_update(unsigned int ticks,void *param)
837 842
 
838 843
 int rls_restore_db_subs(void)
839 844
 {
840
-	db_key_t result_cols[22]; 
845
+	db_key_t result_cols[24]; 
841 846
 	db1_res_t *res= NULL;
842 847
 	db_row_t *row = NULL;	
843 848
 	db_val_t *row_vals= NULL;
... ...
@@ -847,6 +852,7 @@ int rls_restore_db_subs(void)
847 852
 	int callid_col,totag_col,fromtag_col,to_domain_col,sockinfo_col,reason_col;
848 853
 	int event_col,contact_col,record_route_col, event_id_col, status_col;
849 854
 	int remote_cseq_col, local_cseq_col, local_contact_col, version_col;
855
+	int watcher_user_col, watcher_domain_col;
850 856
 	subs_t s;
851 857
 	str ev_sname;
852 858
 	pres_ev_t* event= NULL;
... ...
@@ -860,8 +866,10 @@ int rls_restore_db_subs(void)
860 866
 	result_cols[event_id_col=n_result_cols++] = &str_event_id_col;
861 867
 	result_cols[to_user_col=n_result_cols++] = &str_to_user_col;
862 868
 	result_cols[to_domain_col=n_result_cols++] = &str_to_domain_col;
863
-	result_cols[from_user_col=n_result_cols++] = &str_watcher_username_col;
864
-	result_cols[from_domain_col=n_result_cols++] = &str_watcher_domain_col;
869
+	result_cols[watcher_user_col=n_result_cols++] = &str_watcher_username_col;
870
+	result_cols[watcher_domain_col=n_result_cols++] = &str_watcher_domain_col;
871
+	result_cols[from_user_col=n_result_cols++] = &str_from_user_col;
872
+	result_cols[from_domain_col=n_result_cols++] = &str_from_domain_col;
865 873
 	result_cols[callid_col=n_result_cols++] = &str_callid_col;
866 874
 	result_cols[totag_col=n_result_cols++] = &str_to_tag_col;
867 875
 	result_cols[fromtag_col=n_result_cols++] = &str_from_tag_col;
... ...
@@ -937,6 +945,13 @@ int rls_restore_db_subs(void)
937 945
 			s.from_domain.s=(char*)row_vals[from_domain_col].val.string_val;
938 946
 			s.from_domain.len= strlen(s.from_domain.s);
939 947
 
948
+			s.watcher_user.s=(char*)row_vals[watcher_user_col].val.string_val;
949
+			s.watcher_user.len= strlen(s.watcher_user.s);
950
+		
951
+			s.watcher_domain.s=(char*)row_vals[watcher_domain_col].val.string_val;
952
+			s.watcher_domain.len= strlen(s.watcher_domain.s);
953
+
954
+
940 955
 			s.to_tag.s=(char*)row_vals[totag_col].val.string_val;
941 956
 			s.to_tag.len= strlen(s.to_tag.s);
942 957
 
... ...
@@ -1044,6 +1059,7 @@ int bind_rls(struct rls_binds *pxb)
1044 1059
 		}
1045 1060
 
1046 1061
 		pxb->rls_handle_subscribe = rls_handle_subscribe;
1062
+		pxb->rls_handle_subscribe0 = rls_handle_subscribe0;
1047 1063
 		pxb->rls_handle_notify = rls_handle_notify;
1048 1064
 		return 0;
1049 1065
 }
... ...
@@ -162,7 +162,7 @@ extern int update_dialog_subscribe_rlsdb(subs_t *s);
162 162
 extern int insert_rlsdb(subs_t *s);
163 163
 extern int get_dialog_subscribe_rlsdb(subs_t *s);
164 164
 subs_t *get_dialog_notify_rlsdb(str callid, str to_tag, str from_tag);
165
-extern int update_all_subs_rlsdb(str *from_user, str *from_domain, str *evt);
165
+extern int update_all_subs_rlsdb(str *watcher_user, str *watcher_domain, str *evt);
166 166
 
167 167
 extern int rls_get_service_list(str *service_uri, str *user, str *domain,
168 168
 			xmlNodePtr *service_node, xmlDocPtr *rootdoc);
... ...
@@ -180,6 +180,8 @@ extern str str_event_col;
180 180
 extern str str_event_id_col;
181 181
 extern str str_to_user_col;
182 182
 extern str str_to_domain_col;
183
+extern str str_from_user_col;
184
+extern str str_from_domain_col;
183 185
 extern str str_watcher_username_col;
184 186
 extern str str_watcher_domain_col;
185 187
 extern str str_callid_col;
... ...
@@ -273,7 +273,7 @@ int update_dialog_notify_rlsdb(subs_t *subs)
273 273
 
274 274
 /******************************************************************************/
275 275
 
276
-int update_all_subs_rlsdb(str *from_user, str *from_domain, str *evt)
276
+int update_all_subs_rlsdb(str *watcher_user, str *watcher_domain, str *evt)
277 277
 {
278 278
 	db_key_t query_cols[3];
279 279
 	db_val_t query_vals[3];
... ...
@@ -303,13 +303,13 @@ int update_all_subs_rlsdb(str *from_user, str *from_domain, str *evt)
303 303
 	query_cols[n_query_cols] = &str_watcher_username_col;
304 304
 	query_vals[n_query_cols].type = DB1_STR;
305 305
 	query_vals[n_query_cols].nul = 0;
306
-	query_vals[n_query_cols].val.str_val= *from_user;
306
+	query_vals[n_query_cols].val.str_val= *watcher_user;
307 307
 	n_query_cols++;
308 308
 
309 309
 	query_cols[n_query_cols] = &str_watcher_domain_col;
310 310
 	query_vals[n_query_cols].type = DB1_STR;
311 311
 	query_vals[n_query_cols].nul = 0;
312
-	query_vals[n_query_cols].val.str_val= *from_domain;
312
+	query_vals[n_query_cols].val.str_val= *watcher_domain;
313 313
 	n_query_cols++;
314 314
 
315 315
 	query_cols[n_query_cols] = &str_event_col;
... ...
@@ -372,10 +372,10 @@ int update_all_subs_rlsdb(str *from_user, str *from_domain, str *evt)
372 372
 		}
373 373
 
374 374
 		dest->expires= VAL_INT(values+r_expires_col);
375
-		dest->from_user.s= from_user->s;
376
-		dest->from_user.len= from_user->len;
377
-		dest->from_domain.s= from_domain->s;
378
-		dest->from_domain.len= from_domain->len;
375
+		dest->watcher_user.s= watcher_user->s;
376
+		dest->watcher_user.len= watcher_user->len;
377
+		dest->watcher_domain.s= watcher_domain->s;
378
+		dest->watcher_domain.len= watcher_domain->len;
379 379
 
380 380
 		update_a_sub(dest);
381 381
 	}
... ...
@@ -460,8 +460,8 @@ int update_dialog_subscribe_rlsdb(subs_t *subs)
460 460
 int insert_rlsdb( subs_t *s )
461 461
 
462 462
 {
463
-	db_key_t data_cols[21];
464
-	db_val_t data_vals[21];
463
+	db_key_t data_cols[23];
464
+	db_val_t data_vals[23];
465 465
 	int n_data_cols = 0;
466 466
 
467 467
 	if (s==NULL) return(-1);
... ...
@@ -513,19 +513,31 @@ int insert_rlsdb( subs_t *s )
513 513
 	data_vals[n_data_cols].nul = 0;
514 514
 	data_vals[n_data_cols].val.str_val = s->to_domain;
515 515
 	n_data_cols++;
516
-	
517
-	data_cols[n_data_cols] = &str_watcher_username_col;
516
+
517
+	data_cols[n_data_cols] = &str_from_user_col;
518 518
 	data_vals[n_data_cols].type = DB1_STR;
519 519
 	data_vals[n_data_cols].nul = 0;
520 520
 	data_vals[n_data_cols].val.str_val = s->from_user;
521 521
 	n_data_cols++;
522 522
 
523
-	data_cols[n_data_cols] = &str_watcher_domain_col;
523
+	data_cols[n_data_cols] = &str_from_domain_col;
524 524
 	data_vals[n_data_cols].type = DB1_STR;
525 525
 	data_vals[n_data_cols].nul = 0;
526 526
 	data_vals[n_data_cols].val.str_val = s->from_domain;
527 527
 	n_data_cols++;
528 528
 
529
+	data_cols[n_data_cols] = &str_watcher_username_col;
530
+	data_vals[n_data_cols].type = DB1_STR;
531
+	data_vals[n_data_cols].nul = 0;
532
+	data_vals[n_data_cols].val.str_val = s->watcher_user;
533
+	n_data_cols++;
534
+
535
+	data_cols[n_data_cols] = &str_watcher_domain_col;
536
+	data_vals[n_data_cols].type = DB1_STR;
537
+	data_vals[n_data_cols].nul = 0;
538
+	data_vals[n_data_cols].val.str_val = s->watcher_domain;
539
+	n_data_cols++;
540
+
529 541
 	data_cols[n_data_cols] = &str_event_col;
530 542
 	data_vals[n_data_cols].type = DB1_STR;
531 543
 	data_vals[n_data_cols].nul = 0;
... ...
@@ -759,15 +771,15 @@ subs_t *get_dialog_notify_rlsdb(str callid, str to_tag, str from_tag)
759 771
 {
760 772
  	db_key_t query_cols[3];
761 773
 	db_val_t query_vals[3];
762
-	db_key_t result_cols[20];
774
+	db_key_t result_cols[22];
763 775
 	int n_query_cols = 0, n_result_cols=0;
764 776
 	int r_pres_uri_col,r_to_user_col,r_to_domain_col;
765 777
 	int r_from_user_col,r_from_domain_col,r_callid_col;
766 778
 	int r_to_tag_col,r_from_tag_col,r_socket_info_col;
767 779
 	int r_event_id_col,r_local_contact_col,r_contact_col;
768
-	int r_record_route_col, r_reason_col;
769
-	int r_event_col, r_local_cseq_col, r_remote_cseq_col;
770
-	int r_status_col, r_version_col;
780
+	int r_record_route_col, r_reason_col, r_event_col;
781
+	int r_local_cseq_col, r_remote_cseq_col, r_status_col;
782
+	int r_version_col, r_watcher_user_col, r_watcher_domain_col;
771 783
 	int r_expires_col;
772 784
 	db1_res_t *result= NULL;
773 785
  	db_val_t *values;
... ...
@@ -810,8 +822,10 @@ subs_t *get_dialog_notify_rlsdb(str callid, str to_tag, str from_tag)
810 822
 	result_cols[r_pres_uri_col=n_result_cols++] = &str_presentity_uri_col;
811 823
 	result_cols[r_to_user_col=n_result_cols++] = &str_to_user_col;
812 824
 	result_cols[r_to_domain_col=n_result_cols++] = &str_to_domain_col;
813
-	result_cols[r_from_user_col=n_result_cols++] = &str_watcher_username_col;
814
-	result_cols[r_from_domain_col=n_result_cols++] = &str_watcher_domain_col;
825
+	result_cols[r_from_user_col=n_result_cols++] = &str_from_user_col;
826
+	result_cols[r_from_domain_col=n_result_cols++] = &str_from_domain_col;
827
+	result_cols[r_watcher_user_col=n_result_cols++] = &str_watcher_username_col;
828
+	result_cols[r_watcher_domain_col=n_result_cols++] = &str_watcher_domain_col;
815 829
 	result_cols[r_callid_col=n_result_cols++] = &str_callid_col;
816 830
 	result_cols[r_to_tag_col=n_result_cols++] = &str_to_tag_col;
817 831
 	result_cols[r_from_tag_col=n_result_cols++] = &str_from_tag_col;
... ...
@@ -865,6 +879,8 @@ subs_t *get_dialog_notify_rlsdb(str callid, str to_tag, str from_tag)
865 879
 		+ strlen(VAL_STRING(values+r_to_domain_col))
866 880
 		+ strlen(VAL_STRING(values+r_from_user_col))
867 881
 		+ strlen(VAL_STRING(values+r_from_domain_col))
882
+		+ strlen(VAL_STRING(values+r_watcher_user_col))
883
+		+ strlen(VAL_STRING(values+r_watcher_domain_col))
868 884
 		+ strlen(VAL_STRING(values+r_to_tag_col))
869 885
 		+ strlen(VAL_STRING(values+r_from_tag_col))
870 886
 		+ strlen(VAL_STRING(values+r_callid_col))
... ...
@@ -891,6 +907,8 @@ subs_t *get_dialog_notify_rlsdb(str callid, str to_tag, str from_tag)
891 907
 	CONT_COPYDB(dest, dest->to_domain, VAL_STRING(values+r_to_domain_col))
892 908
 	CONT_COPYDB(dest, dest->from_user, VAL_STRING(values+r_from_user_col))
893 909
 	CONT_COPYDB(dest, dest->from_domain, VAL_STRING(values+r_from_domain_col))
910
+	CONT_COPYDB(dest, dest->watcher_user, VAL_STRING(values+r_watcher_user_col))
911
+	CONT_COPYDB(dest, dest->watcher_domain, VAL_STRING(values+r_watcher_domain_col))
894 912
 	CONT_COPYDB(dest, dest->to_tag, VAL_STRING(values+r_to_tag_col))
895 913
 	CONT_COPYDB(dest, dest->from_tag, VAL_STRING(values+r_from_tag_col))
896 914
 	CONT_COPYDB(dest, dest->callid, VAL_STRING(values+r_callid_col))
... ...
@@ -412,7 +412,47 @@ int reply_489(struct sip_msg * msg)
412 412
 /**
413 413
  * handle RLS subscription
414 414
  */
415
-int rls_handle_subscribe(struct sip_msg* msg, char* s1, char* s2)
415
+int rls_handle_subscribe0(struct sip_msg* msg)
416
+{
417
+	struct to_body *pfrom;
418
+
419
+	if (parse_from_uri(msg) < 0)
420
+	{
421
+		LM_ERR("failed to find From header\n");
422
+		if (slb.freply(msg, 400, &pu_400_rpl) < 0)
423
+		{
424
+			LM_ERR("while sending 400 reply\n");
425
+			return -1;
426
+		}
427
+		return 0;
428
+	}
429
+	pfrom = (struct to_body *) msg->from->parsed;
430
+	
431
+	return rls_handle_subscribe(msg, pfrom->parsed_uri.user,
432
+			pfrom->parsed_uri.host);
433
+}
434
+
435
+int w_rls_handle_subscribe(struct sip_msg* msg, char* watcher_uri)
436
+{
437
+	str wuri;
438
+	struct sip_uri parsed_wuri;
439
+	
440
+	if (fixup_get_svalue(msg, (gparam_p)watcher_uri, &wuri) != 0)
441
+	{
442
+		LM_ERR("invalid uri parameter\n");
443
+		return -1;
444
+	}
445
+
446
+	if (parse_uri(wuri.s, wuri.len, &parsed_wuri) < 0)
447
+	{
448
+		LM_ERR("failed to parse watcher URI\n");
449
+		return -1;
450
+	}
451
+
452
+	return rls_handle_subscribe(msg, parsed_wuri.user, parsed_wuri.host);
453
+}
454
+
455
+int rls_handle_subscribe(struct sip_msg* msg, str watcher_user, str watcher_domain)
416 456
 {
417 457
 	subs_t subs;
418 458
 	pres_ev_t* event = NULL;
... ...
@@ -511,7 +551,7 @@ int rls_handle_subscribe(struct sip_msg* msg, char* s1, char* s2)
511 551
 		goto bad_event;
512 552
 	}
513 553
 	subs.event= event;
514
-	
554
+
515 555
 	/* extract the id if any*/
516 556
 	ev_param= parsed_event->params.list;
517 557
 	while(ev_param)
... ...
@@ -526,7 +566,8 @@ int rls_handle_subscribe(struct sip_msg* msg, char* s1, char* s2)
526 566
 
527 567
 	/* extract dialog information from message headers */
528 568
 	if(pres_extract_sdialog_info(&subs, msg, rls_max_expires,
529
-				&to_tag_gen, rls_server_address)<0)
569
+				&to_tag_gen, rls_server_address,
570
+				watcher_user, watcher_domain)<0)
530 571
 	{
531 572
 		LM_ERR("bad subscribe request\n");
532 573
 		goto error;
... ...
@@ -550,8 +591,8 @@ int rls_handle_subscribe(struct sip_msg* msg, char* s1, char* s2)
550 591
 			LM_ERR("while constructing uri from user and domain\n");
551 592
 			goto error;
552 593
 		}
553
-		if(rls_get_service_list(&subs.pres_uri, &subs.from_user,
554
-					&subs.from_domain, &service_node, &doc)<0)
594
+		if(rls_get_service_list(&subs.pres_uri, &subs.watcher_user,
595
+					&subs.watcher_domain, &service_node, &doc)<0)
555 596
 		{
556 597
 			LM_ERR("while attepmting to get a resource list\n");
557 598
 			goto error;
... ...
@@ -596,8 +637,8 @@ int rls_handle_subscribe(struct sip_msg* msg, char* s1, char* s2)
596 637
 			if (rt <= 0)
597 638
 			{
598 639
 				LM_DBG("subscription dialog not found for <%.*s@%.*s>\n",
599
-						subs.from_user.len, subs.from_user.s,
600
-						subs.from_domain.len, subs.from_domain.s);
640
+						subs.watcher_user.len, subs.watcher_user.s,
641
+						subs.watcher_domain.len, subs.watcher_domain.s);
601 642
 				goto forpresence;
602 643
 			}
603 644
 			else if(rt>=400)
... ...
@@ -630,8 +671,8 @@ int rls_handle_subscribe(struct sip_msg* msg, char* s1, char* s2)
630 671
 			{
631 672
 				lock_release(&rls_table[hash_code].lock);
632 673
 				LM_DBG("subscription dialog not found for <%.*s@%.*s>\n",
633
-						subs.from_user.len, subs.from_user.s,
634
-						subs.from_domain.len, subs.from_domain.s);
674
+						subs.watcher_user.len, subs.watcher_user.s,
675
+						subs.watcher_domain.len, subs.watcher_domain.s);
635 676
 				goto forpresence;
636 677
 			}
637 678
 			lock_release(&rls_table[hash_code].lock);
... ...
@@ -660,8 +701,8 @@ int rls_handle_subscribe(struct sip_msg* msg, char* s1, char* s2)
660 701
 				return 0;
661 702
 			}
662 703
 		}	
663
-		if(rls_get_service_list(&subs.pres_uri, &subs.from_user,
664
-					&subs.from_domain, &service_node, &doc)<0)
704
+		if(rls_get_service_list(&subs.pres_uri, &subs.watcher_user,
705
+					&subs.watcher_domain, &service_node, &doc)<0)
665 706
 		{
666 707
 			LM_ERR("failed getting resource list\n");
667 708
 			goto error;
... ...
@@ -950,7 +991,7 @@ int resource_subscriptions(subs_t* subs, xmlNodePtr xmlnode)
950 991
 
951 992
 	memset(&s, 0, sizeof(subs_info_t));
952 993
 
953
-	if(uandd_to_uri(subs->from_user, subs->from_domain, &wuri)<0)
994
+	if(uandd_to_uri(subs->watcher_user, subs->watcher_domain, &wuri)<0)
954 995
 	{
955 996
 		LM_ERR("while constructing uri from user and domain\n");
956 997
 		goto error;
... ...
@@ -995,7 +1036,7 @@ int resource_subscriptions(subs_t* subs, xmlNodePtr xmlnode)
995 1036
 
996 1037
 	counter = 0;
997 1038
 	
998
-	if(process_list_and_exec(xmlnode, subs->from_user, subs->from_domain,
1039
+	if(process_list_and_exec(xmlnode, subs->watcher_user, subs->watcher_domain,
999 1040
 			send_resource_subs, (void*)(&s))<0)
1000 1041
 	{
1001 1042
 		LM_ERR("while processing list\n");
... ...
@@ -1073,8 +1114,8 @@ void update_a_sub(subs_t *subs_copy)
1073 1114
 		goto done;
1074 1115
 	}
1075 1116
 
1076
-	if(rls_get_service_list(&subs_copy->pres_uri, &subs_copy->from_user,
1077
-				&subs_copy->from_domain, &service_node, &doc)<0)
1117
+	if(rls_get_service_list(&subs_copy->pres_uri, &subs_copy->watcher_user,
1118
+				&subs_copy->watcher_domain, &service_node, &doc)<0)
1078 1119
 	{
1079 1120
 		LM_ERR("failed getting resource list for: %.*s\n",
1080 1121
 			subs_copy->pres_uri.len, subs_copy->pres_uri.s);
... ...
@@ -1179,10 +1220,10 @@ int rls_update_subs(struct sip_msg *msg, char *puri, char *pevent)
1179 1220
 
1180 1221
 		while (subs != NULL)
1181 1222
 		{
1182
-			if (subs->from_user.len == parsed_uri.user.len &&
1183
-				strncmp(subs->from_user.s, parsed_uri.user.s, parsed_uri.user.len) == 0 &&
1184
-				subs->from_domain.len == parsed_uri.host.len &&
1185
-				strncmp(subs->from_domain.s, parsed_uri.host.s, parsed_uri.host.len) == 0 &&
1223
+			if (subs->watcher_user.len == parsed_uri.user.len &&
1224
+				strncmp(subs->watcher_user.s, parsed_uri.user.s, parsed_uri.user.len) == 0 &&
1225
+				subs->watcher_domain.len == parsed_uri.host.len &&
1226
+				strncmp(subs->watcher_domain.s, parsed_uri.host.s, parsed_uri.host.len) == 0 &&
1186 1227
 				subs->event->evp->type == e.type)
1187 1228
 			{
1188 1229
 				subs_t *subs_copy = NULL;
... ...
@@ -32,6 +32,8 @@
32 32
 #include <libxml/parser.h>
33 33
 #include "../../parser/msg_parser.h"
34 34
 
35
-int rls_handle_subscribe(struct sip_msg* msg, char* s1, char* s2);
35
+int rls_handle_subscribe0(struct sip_msg* msg);
36
+int w_rls_handle_subscribe(struct sip_msg* msg, char* watcher_uri);
37
+int rls_handle_subscribe(struct sip_msg* msg, str watcher_user, str watcher_domain);
36 38
 
37 39
 #endif