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 66
 			subs->expires );
64 67
 	DBG("[to_tag]= %.*s\n\t[from_tag]= %.*s\n",
65 68
 			subs->to_tag.len, subs->to_tag.s,	subs->from_tag.len, subs->from_tag.s);
66
-
69
+	DBG("[contact]= %.*s\n",
70
+			subs->contact.len, subs->contact.s);
67 71
 }
68 72
 str* create_winfo_xml(watcher_t* watchers,int n, char* version,char* resource, int STATE_FLAG );
69 73
 
... ...
@@ -247,18 +251,18 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs)
247 251
 		return notify_body;
248 252
 	}
249 253
 
250
-	query_cols[n_query_cols] = "to_user";
254
+	query_cols[n_query_cols] = "pres_user";
251 255
 	query_ops[n_query_cols] = OP_EQ;
252 256
 	query_vals[n_query_cols].type = DB_STR;
253 257
 	query_vals[n_query_cols].nul = 0;
254
-	query_vals[n_query_cols].val.str_val= subs->to_user;
258
+	query_vals[n_query_cols].val.str_val= subs->pres_user;
255 259
 	n_query_cols++;
256 260
 
257
-	query_cols[n_query_cols] = "to_domain";
261
+	query_cols[n_query_cols] = "pres_domain";
258 262
 	query_ops[n_query_cols] = OP_EQ;
259 263
 	query_vals[n_query_cols].type = DB_STR;
260 264
 	query_vals[n_query_cols].nul = 0;
261
-	query_vals[n_query_cols].val.str_val = subs->to_domain;
265
+	query_vals[n_query_cols].val.str_val = subs->pres_domain;
262 266
 	n_query_cols++;
263 267
 
264 268
 	
... ...
@@ -663,16 +667,18 @@ int get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender,
663 667
 	db_key_t query_cols[7];
664 668
 	db_op_t  query_ops[7];
665 669
 	db_val_t query_vals[7];
666
-	db_key_t result_cols[16];
670
+	db_key_t result_cols[18];
667 671
 	int n_result_cols = 0, n_query_cols = 0;
668 672
 	db_row_t *row ;	
669 673
 	db_val_t *row_vals ;
670 674
 	db_res_t *result = NULL;
671 675
 	int size= 0;
672
-	str from_user, from_domain, to_tag, from_tag;
676
+	str from_user, from_domain, from_tag;
677
+	str to_user, to_domain, to_tag;
673 678
 	str event_id, callid, record_route, contact, status;
674 679
 	str sockinfo_str, local_contact;
675
-	int from_user_col, from_domain_col, to_tag_col, from_tag_col;
680
+	int from_user_col, from_domain_col, from_tag_col;
681
+	int to_user_col, to_domain_col, to_tag_col;
676 682
 	int expires_col= 0,callid_col, cseq_col, i, status_col =0, event_id_col = 0;
677 683
 	int version_col= 0, record_route_col = 0, contact_col = 0;
678 684
 	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 691
 	}
686 692
 
687 693
 	DBG("PRESENCE:get_subs_dialog:querying database table = active_watchers\n");
688
-	query_cols[n_query_cols] = "to_domain";
694
+	query_cols[n_query_cols] = "pres_domain";
689 695
 	query_ops[n_query_cols] = OP_EQ;
690 696
 	query_vals[n_query_cols].type = DB_STR;
691 697
 	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 699
 	query_vals[n_query_cols].val.str_val.len = p_domain->len;
694 700
 	n_query_cols++;
695 701
 
696
-	query_cols[n_query_cols] = "to_user";
702
+	query_cols[n_query_cols] = "pres_user";
697 703
 	query_ops[n_query_cols] = OP_EQ;
698 704
 	query_vals[n_query_cols].type = DB_STR;
699 705
 	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 727
 		query_vals[n_query_cols].val.str_val.len = sender->len;
722 728
 		n_query_cols++;
723 729
 	}
724
-
730
+	result_cols[to_user_col=n_result_cols++] = "to_user" ;
731
+	result_cols[to_domain_col=n_result_cols++] = "to_domain" ;
725 732
 	result_cols[from_user_col=n_result_cols++] = "from_user" ;
726 733
 	result_cols[from_domain_col=n_result_cols++] = "from_domain" ;
727 734
 	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 786
 		row_vals = ROW_VALUES(row);		
780 787
 	
781 788
 		memset(&status, 0, sizeof(str));
789
+		to_user.s= (char*)row_vals[to_user_col].val.string_val;
790
+		to_user.len= 	strlen(to_user.s);
791
+		to_domain.s= (char*)row_vals[to_domain_col].val.string_val;
792
+		to_domain.len= strlen(to_domain.s);
793
+
782 794
 		from_user.s= (char*)row_vals[from_user_col].val.string_val;
783 795
 		from_user.len= 	strlen(from_user.s);
784 796
 		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 826
 		local_contact.s = (char*)row_vals[local_contact_col].val.string_val;
815 827
 		local_contact.len = local_contact.s?strlen (local_contact.s):0;
816 828
 		
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);
829
+		size= sizeof(subs_t)+ (p_user->len+ p_domain->len+ to_user.len+
830
+				to_domain.len+ from_user.len+ from_domain.len+ event_id.len+
831
+				to_tag.len+ status.len+ from_tag.len+ callid.len+ 
832
+				record_route.len+ contact.len+ sockinfo_str.len+ 
833
+				local_contact.len)* sizeof(char);
821 834
 
822 835
 		subs= (subs_t*)pkg_malloc(size);
823 836
 		if(subs ==NULL)
... ...
@@ -829,16 +842,26 @@ int get_subs_dialog(str* p_user, str* p_domain, ev_t* event,str* sender,
829 842
 		memset(subs, 0, size);
830 843
 		size= sizeof(subs_t);
831 844
 
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;
845
+		subs->pres_user.s= (char*)subs+ size;
846
+		memcpy(subs->pres_user.s, p_user->s, p_user->len);
847
+		subs->pres_user.len = p_user->len;
835 848
 		size+= p_user->len;
836 849
 
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;
850
+		subs->pres_domain.s= (char*)subs+ size;
851
+		memcpy(subs->pres_domain.s, p_domain->s, p_domain->len);
852
+		subs->pres_domain.len = p_domain->len;
840 853
 		size+= p_domain->len;
841 854
 	
855
+		subs->to_user.s= (char*)subs+ size;
856
+		memcpy(subs->to_user.s, to_user.s, to_user.len);
857
+		subs->to_user.len = to_user.len;
858
+		size+= to_user.len;
859
+
860
+		subs->to_domain.s= (char*)subs+ size;
861
+		memcpy(subs->to_domain.s, to_domain.s, to_domain.len);
862
+		subs->to_domain.len = to_domain.len;
863
+		size+= to_domain.len;
864
+
842 865
 		subs->event= event;
843 866
 
844 867
 		subs->from_user.s= (char*)subs+ size;
... ...
@@ -1097,7 +1120,7 @@ error:
1097 1120
 	return -1;
1098 1121
 }
1099 1122
 
1100
-int notify(subs_t* subs, subs_t * watcher_subs, str* n_body, int force_null_body )
1123
+int notify(subs_t* subs, subs_t * watcher_subs,str* n_body,int force_null_body)
1101 1124
 {
1102 1125
 
1103 1126
 	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 1182
 			}
1160 1183
 			else
1161 1184
 			{
1162
-				notify_body = get_p_notify_body(subs->to_user,
1163
-						subs->to_domain,subs->event, NULL, subs);
1185
+				notify_body = get_p_notify_body(subs->pres_user,
1186
+						subs->pres_domain, subs->event, NULL, subs);
1164 1187
 				if(notify_body == NULL || notify_body->s== NULL)
1165 1188
 				{
1166 1189
 					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 1439
 	{
1417 1440
 		size+= sizeof(subs_t) + (subs->to_user.len+ 
1418 1441
 			subs->to_domain.len+ subs->from_user.len+ subs->from_domain.len+
1419
-			+subs->event_id.len + subs->to_tag.len +
1442
+			subs->pres_user.len+ subs->pres_domain.len +
1443
+			subs->event_id.len + subs->to_tag.len +
1420 1444
 			subs->from_tag.len + subs->callid.len +subs->contact.len +
1421 1445
 			subs->record_route.len +subs->status.len + subs->reason.len+
1422 1446
 			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 1474
 	cb_param->wi_subs = (subs_t*)((char*)cb_param + size);
1451 1475
 	size+= sizeof(subs_t);
1452 1476
 
1477
+	cb_param->wi_subs->pres_user.s = (char*)cb_param + size;
1478
+	strncpy(cb_param->wi_subs->pres_user.s, subs->pres_user.s, subs->pres_user.len);
1479
+	cb_param->wi_subs->pres_user.len = subs->pres_user.len;
1480
+	size+= subs->pres_user.len;
1481
+
1482
+	cb_param->wi_subs->pres_domain.s = (char*)cb_param + size;
1483
+	strncpy(cb_param->wi_subs->pres_domain.s, subs->pres_domain.s, subs->pres_domain.len);
1484
+	cb_param->wi_subs->pres_domain.len = subs->pres_domain.len;
1485
+	size+= subs->pres_domain.len;
1486
+
1453 1487
 	cb_param->wi_subs->to_user.s = (char*)cb_param + size;
1454 1488
 	strncpy(cb_param->wi_subs->to_user.s, subs->to_user.s, subs->to_user.len);
1455 1489
 	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 299
 	ev_t* event= NULL;
301 300
 	param_t* ev_param= NULL;
302 301
 	str ev_name;
302
+	str pres_user;
303
+	str pres_domain;
304
+	struct sip_uri pres_uri;
303 305
 
304 306
 	counter++;
305 307
 	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 415
 	if(lexpire > max_expires)
414 416
 		lexpire = max_expires;
415 417
 
416
-	if( msg->to==NULL || msg->to->body.s==NULL)
418
+	/* get pres_uri from Request-URI*/
419
+	if( parse_uri(msg->first_line.u.request.uri.s, 
420
+				msg->first_line.u.request.uri.len, &pres_uri)< 0)
417 421
 	{
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");
422
+		LOG(L_ERR, "PRESENCE: handle_publish:error parsing Request URI\n");
449 423
 		goto error;
450 424
 	}
425
+	pres_user= pres_uri.user;
426
+	pres_domain= pres_uri.host;
451 427
 
452 428
 	if (!msg->content_length) 
453 429
 	{
... ...
@@ -523,7 +499,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
523 499
 	/* now we have all the necessary values */
524 500
 	/* fill in the filds of the structure */
525 501
 
526
-	presentity= new_presentity(&uri.host, &uri.user, lexpire, event, &etag, sender);
502
+	presentity= new_presentity(&pres_domain, &pres_user, lexpire, event, &etag, sender);
527 503
 	if(presentity== NULL)
528 504
 	{
529 505
 		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 314
 				
303 315
 				if(event->wipeer)
304 316
 				{
305
-					if(query_db_notify(&subs->to_user,&subs->to_domain,
317
+					if(query_db_notify(&subs->pres_user,&subs->pres_domain,
306 318
 								event->wipeer, NULL)< 0)
307 319
 					{
308 320
 						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 372
 			query_vals[n_query_cols].nul = 0;
361 373
 			query_vals[n_query_cols].val.str_val = subs->contact;
362 374
 			n_query_cols++;
363
-	
375
+			DBG("PRESENCE:update_subscription: subs->contact= %.*s-  len= %d\n",
376
+					subs->contact.len, subs->contact.s, subs->contact.len);
377
+
364 378
 			query_cols[n_query_cols] = "status";
365 379
 			query_vals[n_query_cols].type = DB_STR;
366 380
 			query_vals[n_query_cols].nul = 0;
... ...
@@ -430,8 +444,9 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
430 444
 			for(i = 0;i< n_query_cols; i++)
431 445
 			{
432 446
 				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 );
447
+				DBG("[%d] = %s %.*s-  len= %d\n",i, query_cols[i], 
448
+					query_vals[i].val.str_val.len,query_vals[i].val.str_val.s,
449
+					query_vals[i].val.str_val.len);
435 450
 				if(query_vals[i].type==DB_INT)
436 451
 					DBG("[%d] = %s %d\n",i, query_cols[i], 
437 452
 						query_vals[i].val.int_val);
... ...
@@ -440,14 +455,13 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
440 455
 			if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols) < 0) 
441 456
 			{
442 457
 				LOG(L_ERR, "PRESENCE:update_subscription: ERROR while storing"
443
-						" new subscribtion\n");
458
+						" new subscription\n");
444 459
 				goto error;
445 460
 			}
446 461
 		
447 462
 		}
448 463
 		/*otherwise there is a subscription outside a dialog with expires= 0 
449
-		 * no update in database, but
450
-		 * should try to send Notify */
464
+		 * no update in database, but should try to send Notify */
451 465
 		 
452 466
 	}
453 467
 
... ...
@@ -464,7 +478,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
464 478
 		
465 479
 		if(event->wipeer)
466 480
 		{	
467
-			if(query_db_notify(&subs->to_user,&subs->to_domain, event->wipeer,
481
+			if(query_db_notify(&subs->pres_user,&subs->pres_domain, event->wipeer,
468 482
 					subs )< 0)
469 483
 			{
470 484
 				LOG(L_ERR, "PRESENCE:update_subscription:Could not send"
... ...
@@ -583,6 +597,7 @@ void msg_active_watchers_clean(unsigned int ticks,void *param)
583 597
 	int n_result_cols = 0;
584 598
 	int from_user_col, from_domain_col, to_tag_col, from_tag_col;
585 599
 	int to_user_col, to_domain_col, event_col;
600
+	int pres_user_col, pres_domain_col;
586 601
 	int callid_col, cseq_col, i, event_id_col = 0;
587 602
 	int record_route_col = 0, contact_col, cseq;
588 603
 	int sockinfo_col = 0, local_contact_col= 0;
... ...
@@ -592,7 +607,7 @@ void msg_active_watchers_clean(unsigned int ticks,void *param)
592 607
 
593 608
 	str from_user, from_domain, to_tag, from_tag;
594 609
 	str to_user, to_domain, event, event_id, callid;
595
-	str record_route, contact;
610
+	str record_route, contact, pres_user, pres_domain;
596 611
 	str sockinfo_str, local_contact;
597 612
 	
598 613
 	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 618
 	db_vals[0].nul = 0;
604 619
 	db_vals[0].val.int_val = (int)time(NULL)- 10;
605 620
 	
606
-
621
+	result_cols[pres_user_col=n_result_cols++] = "pres_user" ;
622
+	result_cols[pres_domain_col=n_result_cols++] = "pres_domain" ;
607 623
 	result_cols[event_col=n_result_cols++] = "event";
608 624
 	result_cols[from_user_col=n_result_cols++] = "from_user" ;
609 625
 	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 673
 		row = &result->rows[i];
658 674
 		row_vals = ROW_VALUES(row);		
659 675
 		
676
+		pres_user.s = (char*)row_vals[pres_user_col].val.string_val;
677
+		pres_user.len =strlen(pres_user.s);
678
+
679
+		pres_domain.s = (char*)row_vals[pres_domain_col].val.string_val;
680
+		pres_domain.len =strlen(pres_domain.s);
681
+		
660 682
 		to_user.s = (char*)row_vals[to_user_col].val.string_val;
661 683
 		to_user.len =strlen(to_user.s);
662 684
 
... ...
@@ -884,10 +906,10 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
884 906
 	str rec_route= {0, 0};
885 907
 	int error_ret = -1;
886 908
 	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];
909
+	db_key_t db_keys[10];
910
+	db_val_t db_vals[10];
911
+	db_key_t update_keys[5];
912
+	db_val_t update_vals[5];
891 913
 
892 914
 	int n_query_cols= 0; 
893 915
 	db_key_t result_cols[2];
... ...
@@ -901,7 +923,8 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
901 923
 	param_t* ev_param= NULL;
902 924
 	str ev_name;
903 925
 	int result_code, result_n;
904
-	
926
+	struct sip_uri pres_uri;
927
+
905 928
 	/* ??? rename to avoid collisions with other symbols */
906 929
 	counter ++;
907 930
 	contact_body_t *b;
... ...
@@ -920,7 +943,21 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
920 943
 		error_ret = 0;
921 944
 		goto error;
922 945
 	}
946
+	
947
+	/* getting presentity uri from Request-URI */
923 948
 
949
+	if( parse_uri(msg->first_line.u.request.uri.s, 
950
+				msg->first_line.u.request.uri.len, &pres_uri)< 0)
951
+	{
952
+		LOG(L_ERR, "PRESENCE: handle_subscribe:error parsing Request URI\n");
953
+		goto error;
954
+	}
955
+	subs.pres_user.s= pres_uri.user.s;
956
+	subs.pres_user.len= pres_uri.user.len;
957
+	
958
+	subs.pres_domain.s= pres_uri.host.s;
959
+	subs.pres_domain.len= pres_uri.host.len;
960
+	
924 961
 	/* inspecting the Event header field */
925 962
 	if(msg->event && msg->event->body.len > 0)
926 963
 	{
... ...
@@ -1145,8 +1182,11 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1145 1182
 	}
1146 1183
 	subs.contact.s = b->contacts->uri.s;
1147 1184
 	subs.contact.len = b->contacts->uri.len;
1148
-	
1149
-/*process record route and add it to a string*/
1185
+
1186
+	DBG("PRESENCE: handle_subscribe: subs.contact= %.*s - len = %d\n",
1187
+			subs.contact.len, subs.contact.s, subs.contact.len);	
1188
+
1189
+	/*process record route and add it to a string*/
1150 1190
 	if (msg->record_route!=NULL)
1151 1191
 	{
1152 1192
 		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 1208
 				" present\n");
1169 1209
 		goto error;
1170 1210
 	}
1171
-
1172 1211
 	subs.from_tag.s = pfrom->tag_value.s;
1173 1212
 	subs.from_tag.len = pfrom->tag_value.len;
1174 1213
 
... ...
@@ -1254,20 +1293,19 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1254 1293
 			goto error;
1255 1294
 		}
1256 1295
 	}	
1257
-
1258 1296
 	/* subscription status handling */
1259 1297
 	db_keys[n_query_cols] ="p_user";
1260 1298
 	db_vals[n_query_cols].type = DB_STR;
1261 1299
 	db_vals[n_query_cols].nul = 0;
1262
-	db_vals[n_query_cols].val.str_val= subs.to_user;
1300
+	db_vals[n_query_cols].val.str_val= subs.pres_user;
1263 1301
 	n_query_cols++;
1264 1302
 
1265 1303
 	db_keys[n_query_cols] ="p_domain";
1266 1304
 	db_vals[n_query_cols].type = DB_STR;
1267 1305
 	db_vals[n_query_cols].nul = 0;
1268
-	db_vals[n_query_cols].val.str_val = subs.to_domain;
1306
+	db_vals[n_query_cols].val.str_val = subs.pres_domain;
1269 1307
 	n_query_cols++;
1270
-
1308
+	
1271 1309
 	db_keys[n_query_cols] ="w_user";
1272 1310
 	db_vals[n_query_cols].type = DB_STR;
1273 1311
 	db_vals[n_query_cols].nul = 0;
... ...
@@ -1300,7 +1338,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1300 1338
 	}
1301 1339
 	if(result== NULL)
1302 1340
 		goto error;
1303
-		
1341
+	
1304 1342
 	result_n= result->n;
1305 1343
 	if(result_n> 0)
1306 1344
 	{	
... ...
@@ -1339,6 +1377,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1339 1377
 	subs.reason= reason;
1340 1378
 	
1341 1379
 	/* get subs.status */
1380
+
1342 1381
 	if(!event->req_auth)
1343 1382
 	{
1344 1383
 		subs.status.s = "active";
... ...
@@ -1373,7 +1412,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1373 1412
 			LOG(L_ERR, "PRESENCE: subscribe: ERROR in function event specific function"
1374 1413
 					" is_watcher_allowed\n");
1375 1414
 			goto error;
1376
-		}				
1415
+		}	
1377 1416
 		if(result_code!=0)	/* a change has ocured */
1378 1417
 		{
1379 1418
 			if(result_n <=0)
... ...
@@ -1468,6 +1507,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
1468 1507
 			
1469 1508
 		}
1470 1509
 	}
1510
+	
1471 1511
 	printf_subs(&subs);	
1472 1512
 	if( update_subscription(msg, &subs, &rtag_value, to_tag_gen, event) <0 )
1473 1513
 	{	
... ...
@@ -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;