Browse code

- corrected taking presentity uri from Request-URI (reported by Juha Heinanen) - changed active_watchers table - added 2 more columns

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

Anca Vamanu authored on 10/05/2007 15:11:11
Showing 7 changed files
... ...
@@ -306,6 +306,8 @@ CREATE TABLE `presentity` (
306 306
 
307 307
 CREATE TABLE `active_watchers` (
308 308
   `id` int(10) NOT NULL auto_increment,
309
+  `pres_user` varchar(64) NOT NULL,
310
+  `pres_domain` varchar(128) NOT NULL,
309 311
   `to_user` varchar(64) NOT NULL,
310 312
   `to_domain` varchar(128) NOT NULL,
311 313
   `from_user` varchar(64) NOT NULL,
... ...
@@ -16,6 +16,8 @@ CREATE TABLE `presentity` (
16 16
 
17 17
 CREATE TABLE `active_watchers` (
18 18
   `id` int(10) NOT NULL auto_increment,
19
+  `pres_user` varchar(64) NOT NULL,
20
+  `pres_domain` varchar(128) NOT NULL,
19 21
   `to_user` varchar(64) NOT NULL,
20 22
   `to_domain` varchar(128) NOT NULL,
21 23
   `from_user` varchar(64) NOT NULL,
... ...
@@ -51,7 +51,10 @@ c_back_param* shm_dup_subs(subs_t* subs, str to_tag);
51 51
 void p_tm_callback( struct cell *t, int type, struct tmcb_params *ps);
52 52
 
53 53
 void printf_subs(subs_t* subs)
54
-{
54
+{	
55
+	DBG("\n\tpres_user= %.*s - len: %d\tpres_domain= %.*s - len: %d", 
56
+			subs->pres_user.len,  subs->pres_user.s, subs->pres_user.len,
57
+			subs->pres_domain.len,  subs->pres_domain.s, subs->pres_domain.len);
55 58
 	DBG("\n\t[p_user]= %.*s  [p_domain]= %.*s\n\t[w_user]= %.*s "  
56 59
 			"[w_domain]= %.*s\n",
57 60
 			subs->to_user.len, subs->to_user.s, subs->to_domain.len,
... ...
@@ -63,7 +66,8 @@ void printf_subs(subs_t* subs)
63 63
 			subs->expires );
64 64
 	DBG("[to_tag]= %.*s\n\t[from_tag]= %.*s\n",
65 65
 			subs->to_tag.len, subs->to_tag.s,	subs->from_tag.len, subs->from_tag.s);
66
-
66
+	DBG("[contact]= %.*s\n",
67
+			subs->contact.len, subs->contact.s);
67 68
 }
68 69
 str* create_winfo_xml(watcher_t* watchers,int n, char* version,char* resource, int STATE_FLAG );
69 70
 
... ...
@@ -247,18 +251,18 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs)
247 247
 		return notify_body;
248 248
 	}
249 249
 
250
-	query_cols[n_query_cols] = "to_user";
250
+	query_cols[n_query_cols] = "pres_user";
251 251
 	query_ops[n_query_cols] = OP_EQ;
252 252
 	query_vals[n_query_cols].type = DB_STR;
253 253
 	query_vals[n_query_cols].nul = 0;
254
-	query_vals[n_query_cols].val.str_val= subs->to_user;
254
+	query_vals[n_query_cols].val.str_val= subs->pres_user;
255 255
 	n_query_cols++;
256 256
 
257
-	query_cols[n_query_cols] = "to_domain";
257
+	query_cols[n_query_cols] = "pres_domain";
258 258
 	query_ops[n_query_cols] = OP_EQ;
259 259
 	query_vals[n_query_cols].type = DB_STR;
260 260
 	query_vals[n_query_cols].nul = 0;
261
-	query_vals[n_query_cols].val.str_val = subs->to_domain;
261
+	query_vals[n_query_cols].val.str_val = subs->pres_domain;
262 262
 	n_query_cols++;
263 263
 
264 264
 	
... ...
@@ -663,16 +667,18 @@ int get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender,
663 663
 	db_key_t query_cols[7];
664 664
 	db_op_t  query_ops[7];
665 665
 	db_val_t query_vals[7];
666
-	db_key_t result_cols[16];
666
+	db_key_t result_cols[18];
667 667
 	int n_result_cols = 0, n_query_cols = 0;
668 668
 	db_row_t *row ;	
669 669
 	db_val_t *row_vals ;
670 670
 	db_res_t *result = NULL;
671 671
 	int size= 0;
672
-	str from_user, from_domain, to_tag, from_tag;
672
+	str from_user, from_domain, from_tag;
673
+	str to_user, to_domain, to_tag;
673 674
 	str event_id, callid, record_route, contact, status;
674 675
 	str sockinfo_str, local_contact;
675
-	int from_user_col, from_domain_col, to_tag_col, from_tag_col;
676
+	int from_user_col, from_domain_col, from_tag_col;
677
+	int to_user_col, to_domain_col, to_tag_col;
676 678
 	int expires_col= 0,callid_col, cseq_col, i, status_col =0, event_id_col = 0;
677 679
 	int version_col= 0, record_route_col = 0, contact_col = 0;
678 680
 	int sockinfo_col= 0, local_contact_col= 0;
... ...
@@ -685,7 +691,7 @@ int get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender,
685 685
 	}
686 686
 
687 687
 	DBG("PRESENCE:get_subs_dialog:querying database table = active_watchers\n");
688
-	query_cols[n_query_cols] = "to_domain";
688
+	query_cols[n_query_cols] = "pres_domain";
689 689
 	query_ops[n_query_cols] = OP_EQ;
690 690
 	query_vals[n_query_cols].type = DB_STR;
691 691
 	query_vals[n_query_cols].nul = 0;
... ...
@@ -693,7 +699,7 @@ int get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender,
693 693
 	query_vals[n_query_cols].val.str_val.len = p_domain->len;
694 694
 	n_query_cols++;
695 695
 
696
-	query_cols[n_query_cols] = "to_user";
696
+	query_cols[n_query_cols] = "pres_user";
697 697
 	query_ops[n_query_cols] = OP_EQ;
698 698
 	query_vals[n_query_cols].type = DB_STR;
699 699
 	query_vals[n_query_cols].nul = 0;
... ...
@@ -721,7 +727,8 @@ int get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender,
721 721
 		query_vals[n_query_cols].val.str_val.len = sender->len;
722 722
 		n_query_cols++;
723 723
 	}
724
-
724
+	result_cols[to_user_col=n_result_cols++] = "to_user" ;
725
+	result_cols[to_domain_col=n_result_cols++] = "to_domain" ;
725 726
 	result_cols[from_user_col=n_result_cols++] = "from_user" ;
726 727
 	result_cols[from_domain_col=n_result_cols++] = "from_domain" ;
727 728
 	result_cols[event_id_col=n_result_cols++] = "event_id";
... ...
@@ -779,6 +786,11 @@ int get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender,
779 779
 		row_vals = ROW_VALUES(row);		
780 780
 	
781 781
 		memset(&status, 0, sizeof(str));
782
+		to_user.s= (char*)row_vals[to_user_col].val.string_val;
783
+		to_user.len= 	strlen(to_user.s);
784
+		to_domain.s= (char*)row_vals[to_domain_col].val.string_val;
785
+		to_domain.len= strlen(to_domain.s);
786
+
782 787
 		from_user.s= (char*)row_vals[from_user_col].val.string_val;
783 788
 		from_user.len= 	strlen(from_user.s);
784 789
 		from_domain.s= (char*)row_vals[from_domain_col].val.string_val;
... ...
@@ -814,10 +826,11 @@ int get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender,
814 814
 		local_contact.s = (char*)row_vals[local_contact_col].val.string_val;
815 815
 		local_contact.len = local_contact.s?strlen (local_contact.s):0;
816 816
 		
817
-		size= sizeof(subs_t)+ (p_user->len+ p_domain->len+ from_user.len+ 
818
-				from_domain.len+ event_id.len+ to_tag.len+ status.len+
819
-				from_tag.len+ callid.len+ record_route.len+ contact.len+
820
-				sockinfo_str.len+ local_contact.len)* sizeof(char);
817
+		size= sizeof(subs_t)+ (p_user->len+ p_domain->len+ to_user.len+
818
+				to_domain.len+ from_user.len+ from_domain.len+ event_id.len+
819
+				to_tag.len+ status.len+ from_tag.len+ callid.len+ 
820
+				record_route.len+ contact.len+ sockinfo_str.len+ 
821
+				local_contact.len)* sizeof(char);
821 822
 
822 823
 		subs= (subs_t*)pkg_malloc(size);
823 824
 		if(subs ==NULL)
... ...
@@ -829,16 +842,26 @@ int get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender,
829 829
 		memset(subs, 0, size);
830 830
 		size= sizeof(subs_t);
831 831
 
832
-		subs->to_user.s= (char*)subs+ size;
833
-		memcpy(subs->to_user.s, p_user->s, p_user->len);
834
-		subs->to_user.len = p_user->len;
832
+		subs->pres_user.s= (char*)subs+ size;
833
+		memcpy(subs->pres_user.s, p_user->s, p_user->len);
834
+		subs->pres_user.len = p_user->len;
835 835
 		size+= p_user->len;
836 836
 
837
-		subs->to_domain.s= (char*)subs+ size;
838
-		memcpy(subs->to_domain.s, p_domain->s, p_domain->len);
839
-		subs->to_domain.len = p_domain->len;
837
+		subs->pres_domain.s= (char*)subs+ size;
838
+		memcpy(subs->pres_domain.s, p_domain->s, p_domain->len);
839
+		subs->pres_domain.len = p_domain->len;
840 840
 		size+= p_domain->len;
841 841
 	
842
+		subs->to_user.s= (char*)subs+ size;
843
+		memcpy(subs->to_user.s, to_user.s, to_user.len);
844
+		subs->to_user.len = to_user.len;
845
+		size+= to_user.len;
846
+
847
+		subs->to_domain.s= (char*)subs+ size;
848
+		memcpy(subs->to_domain.s, to_domain.s, to_domain.len);
849
+		subs->to_domain.len = to_domain.len;
850
+		size+= to_domain.len;
851
+
842 852
 		subs->event= event;
843 853
 
844 854
 		subs->from_user.s= (char*)subs+ size;
... ...
@@ -1097,7 +1120,7 @@ error:
1097 1097
 	return -1;
1098 1098
 }
1099 1099
 
1100
-int notify(subs_t* subs, subs_t * watcher_subs, str* n_body, int force_null_body )
1100
+int notify(subs_t* subs, subs_t * watcher_subs,str* n_body,int force_null_body)
1101 1101
 {
1102 1102
 
1103 1103
 	str p_uri= {NULL, 0};
... ...
@@ -1159,8 +1182,8 @@ int notify(subs_t* subs, subs_t * watcher_subs, str* n_body, int force_null_body
1159 1159
 			}
1160 1160
 			else
1161 1161
 			{
1162
-				notify_body = get_p_notify_body(subs->to_user,
1163
-						subs->to_domain,subs->event, NULL, subs);
1162
+				notify_body = get_p_notify_body(subs->pres_user,
1163
+						subs->pres_domain, subs->event, NULL, subs);
1164 1164
 				if(notify_body == NULL || notify_body->s== NULL)
1165 1165
 				{
1166 1166
 					DBG("PRESENCE:notify: Could not get the notify_body\n");
... ...
@@ -1416,7 +1439,8 @@ c_back_param* shm_dup_subs(subs_t* subs, str to_tag)
1416 1416
 	{
1417 1417
 		size+= sizeof(subs_t) + (subs->to_user.len+ 
1418 1418
 			subs->to_domain.len+ subs->from_user.len+ subs->from_domain.len+
1419
-			+subs->event_id.len + subs->to_tag.len +
1419
+			subs->pres_user.len+ subs->pres_domain.len +
1420
+			subs->event_id.len + subs->to_tag.len +
1420 1421
 			subs->from_tag.len + subs->callid.len +subs->contact.len +
1421 1422
 			subs->record_route.len +subs->status.len + subs->reason.len+
1422 1423
 			subs->local_contact.len+ subs->sockinfo_str.len)* sizeof(char);
... ...
@@ -1450,6 +1474,16 @@ c_back_param* shm_dup_subs(subs_t* subs, str to_tag)
1450 1450
 	cb_param->wi_subs = (subs_t*)((char*)cb_param + size);
1451 1451
 	size+= sizeof(subs_t);
1452 1452
 
1453
+	cb_param->wi_subs->pres_user.s = (char*)cb_param + size;
1454
+	strncpy(cb_param->wi_subs->pres_user.s, subs->pres_user.s, subs->pres_user.len);
1455
+	cb_param->wi_subs->pres_user.len = subs->pres_user.len;
1456
+	size+= subs->pres_user.len;
1457
+
1458
+	cb_param->wi_subs->pres_domain.s = (char*)cb_param + size;
1459
+	strncpy(cb_param->wi_subs->pres_domain.s, subs->pres_domain.s, subs->pres_domain.len);
1460
+	cb_param->wi_subs->pres_domain.len = subs->pres_domain.len;
1461
+	size+= subs->pres_domain.len;
1462
+
1453 1463
 	cb_param->wi_subs->to_user.s = (char*)cb_param + size;
1454 1464
 	strncpy(cb_param->wi_subs->to_user.s, subs->to_user.s, subs->to_user.len);
1455 1465
 	cb_param->wi_subs->to_user.len = subs->to_user.len;
... ...
@@ -57,7 +57,7 @@
57 57
 MODULE_VERSION
58 58
 
59 59
 #define S_TABLE_VERSION 1
60
-#define ACTWATCH_TABLE_VERSION 3
60
+#define ACTWATCH_TABLE_VERSION 4
61 61
 
62 62
 char *log_buf = NULL;
63 63
 static int clean_period=100;
... ...
@@ -285,9 +285,8 @@ error:
285 285
  */
286 286
 int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
287 287
 {
288
-	struct sip_uri uri, puri;
288
+	struct sip_uri puri;
289 289
 	str body;
290
-	struct to_body *pto, TO;
291 290
 	int lexpire;
292 291
 	presentity_t* presentity = 0;
293 292
 	struct hdr_field* hdr;
... ...
@@ -300,6 +299,9 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
300 300
 	ev_t* event= NULL;
301 301
 	param_t* ev_param= NULL;
302 302
 	str ev_name;
303
+	str pres_user;
304
+	str pres_domain;
305
+	struct sip_uri pres_uri;
303 306
 
304 307
 	counter++;
305 308
 	if ( parse_headers(msg,HDR_EOH_F, 0)==-1 )
... ...
@@ -413,41 +415,15 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
413 413
 	if(lexpire > max_expires)
414 414
 		lexpire = max_expires;
415 415
 
416
-	if( msg->to==NULL || msg->to->body.s==NULL)
416
+	/* get pres_uri from Request-URI*/
417
+	if( parse_uri(msg->first_line.u.request.uri.s, 
418
+				msg->first_line.u.request.uri.len, &pres_uri)< 0)
417 419
 	{
418
-		LOG(L_ERR, "PRESENCE: handle_publish: ERROR cannot parse TO header\n");
419
-		goto error;
420
-	}
421
-
422
-	if(msg->to->parsed != NULL)
423
-	{
424
-		pto = (struct to_body*)msg->to->parsed;
425
-		DBG("PRESENCE: handle_publish: 'To' header ALREADY PARSED: <%.*s>\n",
426
-				pto->uri.len, pto->uri.s );	
427
-	}
428
-	else
429
-	{
430
-		memset( &TO , 0, sizeof(TO) );
431
-		if(!parse_to(msg->to->body.s,msg->to->body.s + msg->to->body.len + 1, &TO))
432
-		{
433
-			DBG("PRESENCE: handle_publish: 'To' header NOT parsed\n");
434
-			goto error;
435
-		}
436
-		pto = &TO;
437
-	}
438
-	
439
-	if(parse_uri(pto->uri.s, pto->uri.len, &uri)!=0)
440
-	{
441
-		LOG(L_ERR, "PRESENCE: handle_publish: bad R-URI!\n");
442
-		goto error;
443
-	}
444
-
445
-	if(uri.user.len<=0 || uri.user.s==NULL || uri.host.len<=0 ||
446
-			uri.host.s==NULL)
447
-	{
448
-		LOG(L_ERR, "PRESENCE: handle_publish: bad URI in To header!\n");
420
+		LOG(L_ERR, "PRESENCE: handle_publish:error parsing Request URI\n");
449 421
 		goto error;
450 422
 	}
423
+	pres_user= pres_uri.user;
424
+	pres_domain= pres_uri.host;
451 425
 
452 426
 	if (!msg->content_length) 
453 427
 	{
... ...
@@ -523,7 +499,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
523 523
 	/* now we have all the necessary values */
524 524
 	/* fill in the filds of the structure */
525 525
 
526
-	presentity= new_presentity(&uri.host, &uri.user, lexpire, event, &etag, sender);
526
+	presentity= new_presentity(&pres_domain, &pres_user, lexpire, event, &etag, sender);
527 527
 	if(presentity== NULL)
528 528
 	{
529 529
 		LOG(L_ERR,"PRESENCE: handle_publish: ERORR creating presentity\n");
... ...
@@ -136,8 +136,8 @@ error:
136 136
 int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
137 137
 		int to_tag_gen, ev_t* event)
138 138
 {	
139
-	db_key_t query_cols[19];
140
-	db_val_t query_vals[19], update_vals[5];
139
+	db_key_t query_cols[22];
140
+	db_val_t query_vals[22], update_vals[5];
141 141
 	db_key_t result_cols[4], update_keys[5];
142 142
 	db_res_t *result= NULL;
143 143
 	unsigned int remote_cseq, local_cseq;
... ...
@@ -152,6 +152,18 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
152 152
 	DBG("PRESENCE: update_subscription...\n");
153 153
 	printf_subs(subs);	
154 154
 	
155
+	query_cols[n_query_cols] = "pres_user";
156
+	query_vals[n_query_cols].type = DB_STR;
157
+	query_vals[n_query_cols].nul = 0;
158
+	query_vals[n_query_cols].val.str_val = subs->pres_user;
159
+	n_query_cols++;
160
+	
161
+	query_cols[n_query_cols] = "pres_domain";
162
+	query_vals[n_query_cols].type = DB_STR;
163
+	query_vals[n_query_cols].nul = 0;
164
+	query_vals[n_query_cols].val.str_val = subs->pres_domain;
165
+	n_query_cols++;
166
+
155 167
 	query_cols[n_query_cols] = "to_user";
156 168
 	query_vals[n_query_cols].type = DB_STR;
157 169
 	query_vals[n_query_cols].nul = 0;
... ...
@@ -302,7 +314,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
302 302
 				
303 303
 				if(event->wipeer)
304 304
 				{
305
-					if(query_db_notify(&subs->to_user,&subs->to_domain,
305
+					if(query_db_notify(&subs->pres_user,&subs->pres_domain,
306 306
 								event->wipeer, NULL)< 0)
307 307
 					{
308 308
 						LOG(L_ERR, "PRESENCE:update_subscription:Could not send"
... ...
@@ -360,7 +372,9 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
360 360
 			query_vals[n_query_cols].nul = 0;
361 361
 			query_vals[n_query_cols].val.str_val = subs->contact;
362 362
 			n_query_cols++;
363
-	
363
+			DBG("PRESENCE:update_subscription: subs->contact= %.*s-  len= %d\n",
364
+					subs->contact.len, subs->contact.s, subs->contact.len);
365
+
364 366
 			query_cols[n_query_cols] = "status";
365 367
 			query_vals[n_query_cols].type = DB_STR;
366 368
 			query_vals[n_query_cols].nul = 0;
... ...
@@ -430,8 +444,9 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
430 430
 			for(i = 0;i< n_query_cols; i++)
431 431
 			{
432 432
 				if(query_vals[i].type==DB_STR)
433
-				DBG("[%d] = %s %.*s\n",i, query_cols[i], 
434
-					query_vals[i].val.str_val.len,query_vals[i].val.str_val.s );
433
+				DBG("[%d] = %s %.*s-  len= %d\n",i, query_cols[i], 
434
+					query_vals[i].val.str_val.len,query_vals[i].val.str_val.s,
435
+					query_vals[i].val.str_val.len);
435 436
 				if(query_vals[i].type==DB_INT)
436 437
 					DBG("[%d] = %s %d\n",i, query_cols[i], 
437 438
 						query_vals[i].val.int_val);
... ...
@@ -440,14 +455,13 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
440 440
 			if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols) < 0) 
441 441
 			{
442 442
 				LOG(L_ERR, "PRESENCE:update_subscription: ERROR while storing"
443
-						" new subscribtion\n");
443
+						" new subscription\n");
444 444
 				goto error;
445 445
 			}
446 446
 		
447 447
 		}
448 448
 		/*otherwise there is a subscription outside a dialog with expires= 0 
449
-		 * no update in database, but
450
-		 * should try to send Notify */
449
+		 * no update in database, but should try to send Notify */
451 450
 		 
452 451
 	}
453 452
 
... ...
@@ -464,7 +478,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
464 464
 		
465 465
 		if(event->wipeer)
466 466
 		{	
467
-			if(query_db_notify(&subs->to_user,&subs->to_domain, event->wipeer,
467
+			if(query_db_notify(&subs->pres_user,&subs->pres_domain, event->wipeer,
468 468
 					subs )< 0)
469 469
 			{
470 470
 				LOG(L_ERR, "PRESENCE:update_subscription:Could not send"
... ...
@@ -583,6 +597,7 @@ void msg_active_watchers_clean(unsigned int ticks,void *param)
583 583
 	int n_result_cols = 0;
584 584
 	int from_user_col, from_domain_col, to_tag_col, from_tag_col;
585 585
 	int to_user_col, to_domain_col, event_col;
586
+	int pres_user_col, pres_domain_col;
586 587
 	int callid_col, cseq_col, i, event_id_col = 0;
587 588
 	int record_route_col = 0, contact_col, cseq;
588 589
 	int sockinfo_col = 0, local_contact_col= 0;
... ...
@@ -592,7 +607,7 @@ void msg_active_watchers_clean(unsigned int ticks,void *param)
592 592
 
593 593
 	str from_user, from_domain, to_tag, from_tag;
594 594
 	str to_user, to_domain, event, event_id, callid;
595
-	str record_route, contact;
595
+	str record_route, contact, pres_user, pres_domain;
596 596
 	str sockinfo_str, local_contact;
597 597
 	
598 598
 	DBG("PRESENCE: msg_active_watchers_clean:cleaning expired watcher information\n");
... ...
@@ -603,7 +618,8 @@ void msg_active_watchers_clean(unsigned int ticks,void *param)
603 603
 	db_vals[0].nul = 0;
604 604
 	db_vals[0].val.int_val = (int)time(NULL)- 10;
605 605
 	
606
-
606
+	result_cols[pres_user_col=n_result_cols++] = "pres_user" ;
607
+	result_cols[pres_domain_col=n_result_cols++] = "pres_domain" ;
607 608
 	result_cols[event_col=n_result_cols++] = "event";
608 609
 	result_cols[from_user_col=n_result_cols++] = "from_user" ;
609 610
 	result_cols[from_domain_col=n_result_cols++] = "from_domain" ;
... ...
@@ -657,6 +673,12 @@ void msg_active_watchers_clean(unsigned int ticks,void *param)
657 657
 		row = &result->rows[i];
658 658
 		row_vals = ROW_VALUES(row);		
659 659
 		
660
+		pres_user.s = (char*)row_vals[pres_user_col].val.string_val;
661
+		pres_user.len =strlen(pres_user.s);
662
+
663
+		pres_domain.s = (char*)row_vals[pres_domain_col].val.string_val;
664
+		pres_domain.len =strlen(pres_domain.s);
665
+		
660 666
 		to_user.s = (char*)row_vals[to_user_col].val.string_val;
661 667
 		to_user.len =strlen(to_user.s);
662 668
 
... ...
@@ -884,10 +906,10 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
884 884
 	str rec_route= {0, 0};
885 885
 	int error_ret = -1;
886 886
 	int rt  = 0;
887
-	db_key_t db_keys[8];
888
-	db_val_t db_vals[8];
889
-	db_key_t update_keys[3];
890
-	db_val_t update_vals[3];
887
+	db_key_t db_keys[10];
888
+	db_val_t db_vals[10];
889
+	db_key_t update_keys[5];
890
+	db_val_t update_vals[5];
891 891
 
892 892
 	int n_query_cols= 0; 
893 893
 	db_key_t result_cols[2];
... ...
@@ -901,7 +923,8 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
901 901
 	param_t* ev_param= NULL;
902 902
 	str ev_name;
903 903
 	int result_code, result_n;
904
-	
904
+	struct sip_uri pres_uri;
905
+
905 906
 	/* ??? rename to avoid collisions with other symbols */
906 907
 	counter ++;
907 908
 	contact_body_t *b;
... ...
@@ -920,7 +943,21 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
920 920
 		error_ret = 0;
921 921
 		goto error;
922 922
 	}
923
+	
924
+	/* getting presentity uri from Request-URI */
923 925
 
926
+	if( parse_uri(msg->first_line.u.request.uri.s, 
927
+				msg->first_line.u.request.uri.len, &pres_uri)< 0)
928
+	{
929
+		LOG(L_ERR, "PRESENCE: handle_subscribe:error parsing Request URI\n");
930
+		goto error;
931
+	}
932
+	subs.pres_user.s= pres_uri.user.s;
933
+	subs.pres_user.len= pres_uri.user.len;
934
+	
935
+	subs.pres_domain.s= pres_uri.host.s;
936
+	subs.pres_domain.len= pres_uri.host.len;
937
+	
924 938
 	/* inspecting the Event header field */
925 939
 	if(msg->event && msg->event->body.len > 0)
926 940
 	{
... ...
@@ -1145,8 +1182,11 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1145 1145
 	}
1146 1146
 	subs.contact.s = b->contacts->uri.s;
1147 1147
 	subs.contact.len = b->contacts->uri.len;
1148
-	
1149
-/*process record route and add it to a string*/
1148
+
1149
+	DBG("PRESENCE: handle_subscribe: subs.contact= %.*s - len = %d\n",
1150
+			subs.contact.len, subs.contact.s, subs.contact.len);	
1151
+
1152
+	/*process record route and add it to a string*/
1150 1153
 	if (msg->record_route!=NULL)
1151 1154
 	{
1152 1155
 		rt = print_rr_body(msg->record_route, &rec_route, 0);
... ...
@@ -1168,7 +1208,6 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1168 1168
 				" present\n");
1169 1169
 		goto error;
1170 1170
 	}
1171
-
1172 1171
 	subs.from_tag.s = pfrom->tag_value.s;
1173 1172
 	subs.from_tag.len = pfrom->tag_value.len;
1174 1173
 
... ...
@@ -1254,20 +1293,19 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1254 1254
 			goto error;
1255 1255
 		}
1256 1256
 	}	
1257
-
1258 1257
 	/* subscription status handling */
1259 1258
 	db_keys[n_query_cols] ="p_user";
1260 1259
 	db_vals[n_query_cols].type = DB_STR;
1261 1260
 	db_vals[n_query_cols].nul = 0;
1262
-	db_vals[n_query_cols].val.str_val= subs.to_user;
1261
+	db_vals[n_query_cols].val.str_val= subs.pres_user;
1263 1262
 	n_query_cols++;
1264 1263
 
1265 1264
 	db_keys[n_query_cols] ="p_domain";
1266 1265
 	db_vals[n_query_cols].type = DB_STR;
1267 1266
 	db_vals[n_query_cols].nul = 0;
1268
-	db_vals[n_query_cols].val.str_val = subs.to_domain;
1267
+	db_vals[n_query_cols].val.str_val = subs.pres_domain;
1269 1268
 	n_query_cols++;
1270
-
1269
+	
1271 1270
 	db_keys[n_query_cols] ="w_user";
1272 1271
 	db_vals[n_query_cols].type = DB_STR;
1273 1272
 	db_vals[n_query_cols].nul = 0;
... ...
@@ -1300,7 +1338,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1300 1300
 	}
1301 1301
 	if(result== NULL)
1302 1302
 		goto error;
1303
-		
1303
+	
1304 1304
 	result_n= result->n;
1305 1305
 	if(result_n> 0)
1306 1306
 	{	
... ...
@@ -1339,6 +1377,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1339 1339
 	subs.reason= reason;
1340 1340
 	
1341 1341
 	/* get subs.status */
1342
+
1342 1343
 	if(!event->req_auth)
1343 1344
 	{
1344 1345
 		subs.status.s = "active";
... ...
@@ -1373,7 +1412,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1373 1373
 			LOG(L_ERR, "PRESENCE: subscribe: ERROR in function event specific function"
1374 1374
 					" is_watcher_allowed\n");
1375 1375
 			goto error;
1376
-		}				
1376
+		}	
1377 1377
 		if(result_code!=0)	/* a change has ocured */
1378 1378
 		{
1379 1379
 			if(result_n <=0)
... ...
@@ -1468,6 +1507,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1468 1468
 			
1469 1469
 		}
1470 1470
 	}
1471
+	
1471 1472
 	printf_subs(&subs);	
1472 1473
 	if( update_subscription(msg, &subs, &rtag_value, to_tag_gen, event) <0 )
1473 1474
 	{	
... ...
@@ -38,6 +38,8 @@ struct ev;
38 38
 
39 39
 struct subscription
40 40
 {
41
+	str pres_user;
42
+	str pres_domain;
41 43
 	str to_user;
42 44
 	str to_domain;
43 45
 	str from_user;