Browse code

- freed some query results

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

Anca Vamanu authored on 10/01/2007 16:47:01
Showing 7 changed files
... ...
@@ -93,7 +93,7 @@ error:
93 93
 }
94 94
 
95 95
 ua_pres_t* search_htable(str* pres_uri, str* watcher_uri, str id,
96
-		int FLAG, htable_t* H)
96
+		int FLAG, int event, htable_t* H)
97 97
 {
98 98
 	ua_pres_t* p= NULL,* L= NULL;
99 99
  
... ...
@@ -103,7 +103,7 @@ ua_pres_t* search_htable(str* pres_uri, str* watcher_uri, str id,
103 103
 
104 104
 	for(p= L->next; p; p=p->next)
105 105
 	{
106
-		if(p->flag & FLAG)
106
+		if((p->event== event) && (p->flag & FLAG))
107 107
 		{
108 108
 			DBG("PUA: search_htable:pres_uri= %.*s len= %d\n",
109 109
 					p->pres_uri->len, p->pres_uri->s, p->pres_uri->len);
... ...
@@ -113,6 +113,7 @@ ua_pres_t* search_htable(str* pres_uri, str* watcher_uri, str id,
113 113
 			if((p->pres_uri->len==pres_uri->len) &&
114 114
 					(strncmp(p->pres_uri->s, pres_uri->s,pres_uri->len)==0))
115 115
 			{	
116
+				DBG("PUA: search_htable:found pres_ur\n");
116 117
 				if(watcher_uri)
117 118
 				{	
118 119
 					if(p->watcher_uri->len==watcher_uri->len &&
... ...
@@ -125,7 +126,7 @@ ua_pres_t* search_htable(str* pres_uri, str* watcher_uri, str id,
125 126
 				}
126 127
 				else
127 128
 				{
128
-					if(id.s )
129
+					if(id.s)
129 130
 					{	
130 131
 						DBG("PUA: search_htable: compare id\n");
131 132
 						if(id.len== p->id.len &&
... ...
@@ -155,7 +156,7 @@ void hash_update(ua_pres_t* presentity, int expires, htable_t* H)
155 156
 	DBG("PUA:hash_update ..\n");
156 157
 
157 158
 	p= search_htable(presentity->pres_uri, presentity->watcher_uri,
158
-				presentity->id, presentity->flag, H);
159
+				presentity->id, presentity->flag,presentity->event, H);
159 160
 	if(p== NULL)
160 161
 	{
161 162
 		DBG("PUA:hash_update : no recod found\n");
... ...
@@ -188,7 +189,7 @@ void insert_htable(ua_pres_t* presentity , htable_t* H)
188 189
 	lock_get(&H->p_records[hash_code].lock);
189 190
 	
190 191
 	p= search_htable(presentity->pres_uri, presentity->watcher_uri,
191
-				presentity->id, presentity->flag, H);
192
+				presentity->id, presentity->flag, presentity->event, H);
192 193
 	if(p) 
193 194
 	{
194 195
 		lock_release(&H->p_records[hash_code].lock);
... ...
@@ -211,7 +212,7 @@ void delete_htable(ua_pres_t* presentity , htable_t* H)
211 212
 	DBG("PUA:delete_htable...\n");
212 213
 
213 214
 	p= search_htable(presentity->pres_uri, presentity->watcher_uri,
214
-			presentity->id, presentity->flag, H);
215
+			presentity->id, presentity->flag, presentity->event, H);
215 216
 	if(p== NULL)
216 217
 	{
217 218
 		return;
... ...
@@ -32,9 +32,17 @@
32 32
 #include "../../str.h"
33 33
 #include "../../lock_ops.h"
34 34
 
35
-#define UL_PUBLISH		1<<1
36
-#define MI_PUBLISH		1<<2
37
-#define MI_SUBSCRIBE	1<<3
35
+#define UL_PUBLISH			1<<0
36
+#define MI_PUBLISH			1<<1
37
+#define MI_SUBSCRIBE		1<<2
38
+#define END2END_PUBLISH		1<<3
39
+#define END2END_SUBSCRIBE   1<<4
40
+#define XMPP_PUBLISH		1<<5
41
+#define XMPP_SUBSCRIBE      1<<6
42
+
43
+#define PRESENCE_EVENT      1<<0
44
+#define PWINFO_EVENT        1<<1
45
+
38 46
 
39 47
 #define NO_UPDATEDB_FLAG	1<<0
40 48
 #define UPDATEDB_FLAG		1<<1
... ...
@@ -46,8 +54,9 @@ typedef struct hentity
46 54
 	str* watcher_uri;
47 55
 	str id;
48 56
 	str tuple_id;
57
+	int event;
49 58
 	int flag;
50
-	int expires;
59
+	int desired_expires;
51 60
 }hentity_t;
52 61
 
53 62
 typedef struct ua_pres{
... ...
@@ -55,7 +64,9 @@ typedef struct ua_pres{
55 64
     /* common*/
56 65
     str* pres_uri;
57 66
 	str id;
67
+	int event;
58 68
 	time_t expires;
69
+	time_t desired_expires;
59 70
 	int flag;
60 71
 	int db_flag;
61 72
 	struct ua_pres* next;
... ...
@@ -86,7 +97,7 @@ typedef struct htable{
86 97
 htable_t* new_htable();
87 98
 
88 99
 ua_pres_t* search_htable(str* pres_uri, str* watcher_uri, str id, 
89
-		int FLAG, htable_t* H);
100
+		int FLAG, int event, htable_t* H);
90 101
 
91 102
 void insert_htable(ua_pres_t* presentity , htable_t* H);
92 103
 
... ...
@@ -74,6 +74,8 @@ static void destroy(void);
74 74
 int send_subscribe(subs_info_t*);
75 75
 int send_publish(publ_info_t*);
76 76
 
77
+int update_pua(ua_pres_t* p);
78
+
77 79
 int db_store(htable_t* H);
78 80
 int db_restore(htable_t* H);
79 81
 void db_update(unsigned int ticks,void *param);
... ...
@@ -240,6 +242,9 @@ static void destroy(void)
240 242
 	if(HashT)
241 243
 		destroy_htable(HashT);
242 244
 
245
+	if(pua_db)
246
+		pua_dbf.close(pua_db);
247
+
243 248
 	return ;
244 249
 }
245 250
 
... ...
@@ -283,9 +288,17 @@ int db_restore(htable_t* H)
283 288
 	if(pua_dbf.query(pua_db,0, 0, 0, result_cols,0, 11, 0,&res)< 0)
284 289
 	{
285 290
 		LOG(L_ERR, "PUA: db_restore:ERROR while querrying table\n");
291
+		if(res)
292
+		{
293
+			pua_dbf.free_result(pua_db, res);
294
+			res = NULL;
295
+		}
286 296
 		return -1;
287 297
 	}
288
-	if(res && res->n<=0)
298
+	if(res== NULL)
299
+		return -1;
300
+
301
+	if(res->n<=0)
289 302
 	{
290 303
 		LOG(L_INFO, "PUA: db_restore:the query returned no result\n");
291 304
 		pua_dbf.free_result(pua_db, res);
... ...
@@ -446,18 +459,147 @@ void hashT_clean(unsigned int ticks,void *param)
446 459
 		p= HashT->p_records[i].entity->next;
447 460
 		while(p)
448 461
 		{	
449
-			if(p->expires< (int)(time)(NULL))
462
+			if(p->expires< (int)(time)(NULL)+10)
450 463
 			{
451
-				q= p->next;
452
-				delete_htable(p, HashT);
453
-				p= q;
464
+				if(p->desired_expires> p->expires+ 10)
465
+				{
466
+					if(update_pua(p)< 0)
467
+					{
468
+						LOG(L_ERR, "PUA: hashT_clean: Error while updating\n");
469
+						lock_release(&HashT->p_records[i].lock);
470
+						return;
471
+					}	
472
+				}
473
+				p= p->next;
454 474
 			}
455 475
 			else
456
-				p= p->next;
476
+				if(p->expires< (int)(time)(NULL))
477
+				{
478
+					q= p->next;
479
+					delete_htable(p, HashT);
480
+					p= q;
481
+				}
482
+				else
483
+					p= p->next;
457 484
 		}
458 485
 		lock_release(&HashT->p_records[i].lock);
459 486
 	}
460 487
 
488
+}
489
+int update_pua(ua_pres_t* p)
490
+{
491
+	int size= 0;
492
+	hentity_t* hentity= NULL;
493
+	str* str_hdr= NULL;
494
+
495
+	size= sizeof(hentity_t)+ sizeof(str)+ (p->pres_uri->len+ 1)*sizeof(char);
496
+	
497
+	if(p->watcher_uri)
498
+		size+= sizeof(str)+ p->watcher_uri->len;
499
+	else
500
+		size+=  p->id.len;
501
+
502
+	hentity= (hentity_t*)shm_malloc(size);
503
+	if(hentity== NULL)
504
+	{
505
+		LOG(L_ERR, "PUA: update_pua: ERROR no more share memory\n");
506
+		goto error;
507
+	}
508
+	memset(hentity, 0, size);
509
+
510
+	size =  sizeof(hentity_t);
511
+
512
+	hentity->pres_uri = (str*)((char*)hentity + size);
513
+	size+= sizeof(str);
514
+
515
+	hentity->pres_uri->s = (char*)hentity+ size;
516
+	memcpy(hentity->pres_uri->s, p->pres_uri->s ,
517
+			p->pres_uri->len ) ;
518
+	hentity->pres_uri->len= p->pres_uri->len;
519
+	size+= p->pres_uri->len;
520
+		
521
+	if(p->watcher_uri)
522
+	{
523
+		hentity->watcher_uri=(str*)((char*)hentity+ size);
524
+		size+= sizeof(str);
525
+		hentity->watcher_uri->s= (char*)hentity+ size;
526
+		memcpy(hentity->watcher_uri->s, p->watcher_uri->s,p->watcher_uri->len);
527
+		hentity->watcher_uri->len= p->watcher_uri->len;
528
+		size+= p->watcher_uri->len;
529
+	}	
530
+	else
531
+	{	
532
+		hentity->id.s = ((char*)hentity+ size);
533
+		memcpy(hentity->id.s, p->id.s, p->id.len);
534
+		hentity->id.len= p->id.len;
535
+		size+= p->id.len;
536
+	}
537
+
538
+	hentity->flag|= p->flag;
539
+	
540
+
541
+	if(p->watcher_uri== NULL)
542
+	{
543
+		str met= {"PUBLISH", 7};
544
+		str_hdr = publ_build_hdr(p->expires- (int)time(NULL), &p->etag);
545
+		if(str_hdr == NULL)
546
+		{
547
+			LOG(L_ERR, "PUA: update_pua: ERROR while building extra_headers\n");
548
+			goto error;
549
+		}
550
+		DBG("PUA: update_pua: str_hdr:\n%.*s\n ", str_hdr->len, str_hdr->s);
551
+	
552
+		tmb.t_request(&met,						/* Type of the message */
553
+				p->pres_uri,					/* Request-URI */
554
+				p->pres_uri,					/* To */
555
+				p->pres_uri,					/* From */
556
+				str_hdr,						/* Optional headers */
557
+				0,							/* Message body */
558
+				publ_cback_func,				/* Callback function */
559
+				(void*)hentity					/* Callback parameter */
560
+				);
561
+	}
562
+	else
563
+	{	
564
+		str met= {"SUBSCRIBE", 9};
565
+		dlg_t* td= NULL;
566
+		td= pua_build_dlg_t(p);
567
+		if(td== NULL)
568
+		{
569
+			LOG(L_ERR, "PUA:update_pua: Error while building tm dlg_t"
570
+					"structure");		
571
+			goto error;
572
+		}
573
+		str_hdr= subs_build_hdr(p->watcher_uri, p->expires- (int)time(NULL), p->event);
574
+		if(str_hdr== NULL || str_hdr->s== NULL)
575
+		{
576
+			LOG(L_ERR, "PUA:send_subscribe: Error while building extra headers\n");
577
+			return -1;
578
+		}
579
+
580
+		tmb.t_request_within
581
+		(&met,
582
+		str_hdr,                               
583
+		0,                           
584
+		td,					                  
585
+		subs_cback_func,				        
586
+		(void*)hentity	
587
+		);
588
+
589
+		pkg_free(td);
590
+		td= NULL;
591
+	}	
592
+
593
+	pkg_free(str_hdr);
594
+	return 0;
595
+
596
+error:
597
+	if(str_hdr)
598
+		pkg_free(str_hdr);
599
+	if(hentity)
600
+		pkg_free(hentity);
601
+	return -1;
602
+
461 603
 }
462 604
 
463 605
 void db_update(unsigned int ticks,void *param)
... ...
@@ -591,6 +733,8 @@ void db_update(unsigned int ticks,void *param)
591 733
 						LOG(L_ERR, "PUA: db_update:ERROR while querying"
592 734
 								" database");
593 735
 						lock_release(&HashT->p_records[i].lock);
736
+						if(res)
737
+							pua_dbf.free_result(pua_db, res);	
594 738
 						return ;
595 739
 					}
596 740
 					if(res && res->n> 0)
... ...
@@ -601,11 +745,21 @@ void db_update(unsigned int ticks,void *param)
601 745
 							LOG(L_ERR, "PUA: db_update: ERROR while updating"
602 746
 									" in database");
603 747
 							lock_release(&HashT->p_records[i].lock);	
748
+							pua_dbf.free_result(pua_db, res);
749
+							res= NULL;
604 750
 							return ;
605 751
 						}
752
+						pua_dbf.free_result(pua_db, res);
753
+						res= NULL;
754
+
606 755
 					}
607 756
 					else
608 757
 					{
758
+						if(res)
759
+						{	
760
+							pua_dbf.free_result(pua_db, res);
761
+							res= NULL;
762
+						}
609 763
 						DBG("PUA:db_update: UPDATEDB_FLAG and no record"
610 764
 								" found\n");
611 765
 					}	
... ...
@@ -23,19 +23,14 @@
23 23
  */
24 24
 
25 25
 
26
-#include <stdio.h>
27
-#include <stdlib.h>
28
-#include <string.h>
29
-
30
-#include "../../mem/mem.h"
31
-#include "../../dprint.h"
32
-
33 26
 #include <stdio.h>
34 27
 #include <stdlib.h>
35 28
 #include <string.h>
36 29
 #include <libxml/parser.h>
37 30
 #include <time.h>
38 31
 
32
+#include "../../mem/mem.h"
33
+#include "../../dprint.h"
39 34
 #include "../../parser/parse_expires.h"
40 35
 #include "../../dprint.h"
41 36
 #include "../../mem/shm_mem.h"
... ...
@@ -98,19 +93,19 @@ void print_hentity(hentity_t* h)
98 93
 		DBG("\ttuple_id: %.*s\n", h->tuple_id.len, h->tuple_id.s);
99 94
 }	
100 95
 
101
-static str* build_hdr(int expires, str* etag)
96
+str* publ_build_hdr(int expires, str* etag)
102 97
 {
103
-	char buf[3000];
98
+	static char buf[3000];
104 99
 	str* str_hdr = NULL;	
105 100
 	char* expires_s = NULL;
106 101
 	int len = 0;
107 102
 	int t= 0;
108 103
 
109
-	DBG("PUA: build_hdr ...\n");
104
+	DBG("PUA: publ_build_hdr ...\n");
110 105
 	str_hdr =(str*) pkg_malloc(sizeof(str));
111 106
 	if(!str_hdr)
112 107
 	{
113
-		LOG(L_ERR, "PUA: build_hdr:ERROR while allocating memory\n");
108
+		LOG(L_ERR, "PUA: publ_build_hdr:ERROR while allocating memory\n");
114 109
 		return NULL;
115 110
 	}
116 111
 
... ...
@@ -144,7 +139,7 @@ static str* build_hdr(int expires, str* etag)
144 139
 	
145 140
 	if( etag)
146 141
 	{
147
-		DBG("PUA:build_hdr: UPDATE_TYPE\n");
142
+		DBG("PUA:publ_build_hdr: UPDATE_TYPE\n");
148 143
 		memcpy(str_hdr->s+str_hdr->len,"SIP-If-Match: ", 14);
149 144
 		str_hdr->len += 14;
150 145
 		memcpy(str_hdr->s+str_hdr->len, etag->s, etag->len);
... ...
@@ -194,7 +189,8 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
194 189
 
195 190
 		presentity= search_htable(((hentity_t*)(*ps->param))->pres_uri, NULL,
196 191
 				((hentity_t*)(*ps->param))->id,
197
-				((hentity_t*)(*ps->param))->flag, HashT);
192
+				((hentity_t*)(*ps->param))->flag,
193
+				((hentity_t*)(*ps->param))->event,HashT);
198 194
 		if(presentity)
199 195
 		{
200 196
 			delete_htable(presentity, HashT);
... ...
@@ -253,7 +249,8 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
253 249
 
254 250
 	presentity= search_htable(((hentity_t*)(*ps->param))->pres_uri, NULL,
255 251
 				((hentity_t*)(*ps->param))->id,
256
-				((hentity_t*)(*ps->param))->flag, HashT);
252
+				((hentity_t*)(*ps->param))->flag,
253
+				((hentity_t*)(*ps->param))->event,HashT);
257 254
 	if(presentity)
258 255
 	{
259 256
 			DBG("PUA:publ_cback_func: update record\n");
... ...
@@ -333,7 +330,9 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
333 330
 	size+= presentity->id.len;
334 331
 		
335 332
 	presentity->expires= lexpire +(int)time(NULL);
333
+	presentity->desired_expires= ((hentity_t*)(*ps->param))->desired_expires;
336 334
 	presentity->flag|= ((hentity_t*)(*ps->param))->flag;
335
+	presentity->event= PRESENCE_EVENT;
337 336
 	presentity->db_flag|= INSERTDB_FLAG;
338 337
 
339 338
 	insert_htable( presentity, HashT);
... ...
@@ -374,7 +373,7 @@ int send_publish( publ_info_t* publ )
374 373
 	lock_get(&HashT->p_records[hash_code].lock);
375 374
 
376 375
 	presentity= search_htable( publ->pres_uri, NULL,
377
-				publ->id, publ->source_flag, HashT);
376
+				publ->id, publ->source_flag, PRESENCE_EVENT, HashT);
378 377
 	
379 378
 	
380 379
 	if(presentity== NULL)
... ...
@@ -454,6 +453,15 @@ int send_publish( publ_info_t* publ )
454 453
 				goto error;
455 454
 			}
456 455
 		}
456
+		else
457
+		{
458
+			strcpy(buf, tuple_id);
459
+			xmlFree(tuple_id);
460
+			tuple_id= buf;
461
+			tuple_id_len= strlen(tuple_id);
462
+		}	
463
+			
464
+
457 465
 		node= xmlNodeGetNodeByName(doc->children, "person", NULL);
458 466
 		if(node)
459 467
 		{
... ...
@@ -469,6 +477,8 @@ int send_publish( publ_info_t* publ )
469 477
 					goto error;
470 478
 				}
471 479
 			}
480
+			else
481
+				xmlFree(person_id);
472 482
 		}	
473 483
 		body= (str*)pkg_malloc(sizeof(str));
474 484
 		if(body== NULL)
... ...
@@ -514,24 +524,28 @@ int send_publish( publ_info_t* publ )
514 524
 	memcpy(hentity->id.s, publ->id.s, publ->id.len);
515 525
 	hentity->id.len= publ->id.len;
516 526
 	size+= publ->id.len;
517
-		
527
+	
528
+	hentity->event= PRESENCE_EVENT;
518 529
 	hentity->flag|= publ->source_flag;
519
-	hentity->expires= publ->expires + (int )time(NULL);
530
+	hentity->desired_expires= publ->expires + (int )time(NULL);
520 531
 
521 532
 send_publish:
522 533
 	
523 534
 	if(publ->flag & UPDATE_TYPE)
524
-		str_hdr = build_hdr(publ->expires, &etag);
535
+		str_hdr = publ_build_hdr(publ->expires, &etag);
525 536
 	else
526
-		str_hdr= build_hdr(publ->expires, NULL);
537
+		str_hdr= publ_build_hdr(publ->expires, NULL);
527 538
 
528 539
 	if(str_hdr == NULL)
529 540
 	{
530 541
 		LOG(L_ERR, "PUA:send_publish: ERROR while building extra_headers\n");
531 542
 		goto error;
532 543
 	}
533
-	DBG("PUA: send_publish: str_hdr:\n%.*s\n ", str_hdr->len, str_hdr->s);
534
-	
544
+
545
+	DBG("PUA: send_publish: publ->pres_uri:\n%.*s\n ", publ->pres_uri->len, publ->pres_uri->s);
546
+	DBG("PUA: send_publish: str_hdr:\n%.*s %d\n ", str_hdr->len, str_hdr->s, str_hdr->len);
547
+	DBG("PUA: send_publish: body:\n%.*s\n ", body->len, body->s);
548
+		
535 549
 
536 550
 	tmb.t_request(&met,						/* Type of the message */
537 551
 			publ->pres_uri,					/* Request-URI */
... ...
@@ -25,9 +25,9 @@
25 25
 
26 26
 #ifndef _PU_SEND_PUBLISH_
27 27
 #define _PU_SEND_PUBLISH_
28
-
29
-#include "../../str.h"
30 28
 #include <time.h>
29
+#include "../tm/tm_load.h"
30
+#include "../../str.h"
31 31
 #include "hash.h"
32 32
 
33 33
 
... ...
@@ -45,5 +45,7 @@ typedef struct publ_info
45 45
 typedef int (*send_publish_t)(publ_info_t* publ);
46 46
 int send_publish( publ_info_t* publ );
47 47
 void print_ua_pres(ua_pres_t* p);
48
+void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps);
49
+str* publ_build_hdr(int expires, str* etag);
48 50
 
49 51
 #endif
... ...
@@ -54,45 +54,54 @@ void print_subs(subs_info_t* subs)
54 54
 
55 55
 }
56 56
 
57
-static str* build_hdr(subs_info_t* subs)
57
+str* subs_build_hdr(str* watcher_uri, int expires, int event)
58 58
 {
59 59
 	str* str_hdr= NULL;
60
-	char buf[1000];
60
+	static char buf[3000];
61 61
 	char* subs_expires= NULL;
62 62
 	int len= 1;
63 63
 
64 64
 	str_hdr= (str*)pkg_malloc(sizeof(str));
65 65
 	if(str_hdr== NULL)
66 66
 	{
67
-		LOG(L_ERR, "PUA:build_hdr:ERROR while allocating memory\n");
67
+		LOG(L_ERR, "PUA:subs_build_hdr:ERROR while allocating memory\n");
68 68
 		return NULL;
69 69
 	}
70 70
 	str_hdr->s= buf;
71 71
 
72
-	memcpy(str_hdr->s ,"Event: presence", 15);
73
-	str_hdr->len = 15;
72
+	if(event& PRESENCE_EVENT)
73
+	{	
74
+		memcpy(str_hdr->s ,"Event: presence", 15);
75
+		str_hdr->len = 15;
76
+	}
77
+	else
78
+	{	
79
+		memcpy(str_hdr->s ,"Event: presence.winfo", 21);
80
+		str_hdr->len = 21;
81
+	}
82
+
74 83
 	memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
75 84
 	str_hdr->len += CRLF_LEN;
76 85
 	
77 86
 	memcpy(str_hdr->s+ str_hdr->len ,"Contact: ", 9);
78 87
 	str_hdr->len += 9;
79
-	memcpy(str_hdr->s +str_hdr->len, subs->watcher_uri->s, 
80
-			subs->watcher_uri->len);
81
-	str_hdr->len+= subs->watcher_uri->len;
88
+	memcpy(str_hdr->s +str_hdr->len, watcher_uri->s, 
89
+			watcher_uri->len);
90
+	str_hdr->len+= watcher_uri->len;
82 91
 	memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
83 92
 	str_hdr->len += CRLF_LEN;
84 93
 
85 94
 	memcpy(str_hdr->s+ str_hdr->len ,"Expires: ", 9);
86 95
 	str_hdr->len += 9;
87 96
 
88
-	if( subs->expires<= min_expires)
97
+	if( expires<= min_expires)
89 98
 		subs_expires= int2str(min_expires, &len);  
90 99
 	else
91
-		subs_expires= int2str(subs->expires+ 1, &len);
100
+		subs_expires= int2str(expires+ 1, &len);
92 101
 		
93 102
 	if(subs_expires == NULL || len == 0)
94 103
 	{
95
-		LOG(L_ERR, "PUA:build_hdr: ERROR while converting int "
104
+		LOG(L_ERR, "PUA:subs_build_hdr: ERROR while converting int "
96 105
 				" to str\n");
97 106
 		pkg_free(str_hdr);
98 107
 		return NULL;
... ...
@@ -107,7 +116,7 @@ static str* build_hdr(subs_info_t* subs)
107 116
 	return str_hdr;
108 117
 }	
109 118
 
110
-static dlg_t* build_dlg_t(ua_pres_t* presentity)	
119
+dlg_t* pua_build_dlg_t(ua_pres_t* presentity)	
111 120
 {
112 121
 	dlg_t* td =NULL;
113 122
 	int size;
... ...
@@ -119,7 +128,7 @@ static dlg_t* build_dlg_t(ua_pres_t* presentity)
119 128
 	td = (dlg_t*)pkg_malloc(size);
120 129
 	if(td == NULL)
121 130
 	{
122
-		LOG(L_ERR, "PUA:build_dlg_t: No memory left\n");
131
+		LOG(L_ERR, "PUA:pua_build_dlg_t: No memory left\n");
123 132
 		return NULL;
124 133
 	}
125 134
 	memset(td, 0, size);
... ...
@@ -167,11 +176,10 @@ static dlg_t* build_dlg_t(ua_pres_t* presentity)
167 176
 void subs_cback_func(struct cell *t, int type, struct tmcb_params *ps)
168 177
 {
169 178
 	struct sip_msg* msg= NULL;
170
-	int lexpire= 0, cseq;
179
+	int lexpire= 0;
180
+	unsigned int cseq;
171 181
 	ua_pres_t* presentity= NULL;
172 182
 	struct to_body *pto, *pfrom = NULL, TO;
173
-	struct cseq_body cseqb;
174
-	str cseq_nr;
175 183
 	int size= 0;
176 184
 	int hash_code;
177 185
 
... ...
@@ -199,7 +207,8 @@ void subs_cback_func(struct cell *t, int type, struct tmcb_params *ps)
199 207
 		presentity= search_htable(((hentity_t*)(*ps->param))->pres_uri, 
200 208
 				((hentity_t*)(*ps->param))->watcher_uri,
201 209
 				((hentity_t*)(*ps->param))->id	,
202
-				((hentity_t*)(*ps->param))->flag, HashT);
210
+				((hentity_t*)(*ps->param))->flag, 
211
+				((hentity_t*)(*ps->param))->event,HashT);
203 212
 
204 213
 		if(presentity)
205 214
 			delete_htable(presentity, HashT);
... ...
@@ -254,7 +263,8 @@ void subs_cback_func(struct cell *t, int type, struct tmcb_params *ps)
254 263
 	presentity= search_htable(((hentity_t*)(*ps->param))->pres_uri, 
255 264
 				((hentity_t*)(*ps->param))->watcher_uri,
256 265
 				((hentity_t*)(*ps->param))->id	,
257
-				((hentity_t*)(*ps->param))->flag, HashT);
266
+				((hentity_t*)(*ps->param))->flag,
267
+				((hentity_t*)(*ps->param))->event,HashT);
258 268
 
259 269
 	if(presentity)
260 270
 	{
... ...
@@ -295,20 +305,8 @@ void subs_cback_func(struct cell *t, int type, struct tmcb_params *ps)
295 305
 		" header\n");
296 306
 		goto done;
297 307
 	}
298
-	if(parse_cseq(msg->cseq->body.s, msg->cseq->body.s+
299
-				msg->cseq->body.len+2, &cseqb )< 0)
300
-	{
301
-		LOG(L_ERR, "PUA: subs_cback_func: ERROR while parsing cseq\n");
302
-		goto done;
303
-	}
304
-	cseq_nr= cseqb.number;
305
-	if(cseq_nr.s== NULL || cseq_nr.len== 0)
306
-	{
307
-		LOG(L_ERR, "PUA: subs_cback_func: ERROR while parsing cseq\n");
308
-		goto done;
309
-	}
310 308
 
311
-	if( str2int(&cseq_nr,(unsigned int*) &cseq)< 0)
309
+	if( str2int( &(get_cseq(msg)->number), &cseq)< 0)
312 310
 	{
313 311
 		LOG(L_ERR, "PUA: subs_cback_func: ERROR while converting str"
314 312
 					" to int\n");
... ...
@@ -413,10 +411,12 @@ void subs_cback_func(struct cell *t, int type, struct tmcb_params *ps)
413 411
 	presentity->from_tag.len= pfrom->tag_value.len;
414 412
 	size+= pfrom->tag_value.len;
415 413
 	
414
+	presentity->event|= ((hentity_t*)(*ps->param))->event;
416 415
 	presentity->flag|= ((hentity_t*)(*ps->param))->flag;
417 416
 	presentity->db_flag|= INSERTDB_FLAG;
418 417
 	presentity->etag.s= NULL;
419 418
 	presentity->cseq= cseq;
419
+	presentity->desired_expires= ((hentity_t*)(*ps->param))->desired_expires;
420 420
 	presentity->expires= lexpire+ (int)time(NULL);
421 421
 	insert_htable(presentity, HashT);
422 422
 	
... ...
@@ -471,10 +471,11 @@ hentity_t* build_cback_param(subs_info_t* subs)
471 471
 		subs->watcher_uri->len ) ;
472 472
 	hentity->watcher_uri->len= subs->watcher_uri->len;
473 473
 	size+= subs->watcher_uri->len;
474
-	
475
-	hentity->expires= subs->expires+ (int)time(NULL);
474
+
475
+	hentity->desired_expires= subs->expires+ (int)time(NULL);
476 476
 	hentity->flag|= subs->source_flag;
477
-	
477
+	hentity->event|= subs->event;
478
+
478 479
 	return hentity;
479 480
 
480 481
 }	
... ...
@@ -491,7 +492,7 @@ int send_subscribe(subs_info_t* subs)
491 492
 	DBG("send_subscribe... \n");
492 493
 	print_subs(subs);
493 494
 
494
-	str_hdr= build_hdr(subs);
495
+	str_hdr= subs_build_hdr(subs->watcher_uri, subs->expires, subs->event);
495 496
 	if(str_hdr== NULL || str_hdr->s== NULL)
496 497
 	{
497 498
 		LOG(L_ERR, "PUA:send_subscribe: Error while building extra headers\n");
... ...
@@ -503,7 +504,7 @@ int send_subscribe(subs_info_t* subs)
503 504
 	lock_get(&HashT->p_records[hash_code].lock);
504 505
  
505 506
 	presentity= search_htable(subs->pres_uri, subs->watcher_uri,
506
-				subs->id, subs->source_flag, HashT);
507
+				subs->id, subs->source_flag, subs->event, HashT);
507 508
 
508 509
 	if(presentity== NULL )
509 510
 	{
... ...
@@ -554,7 +555,7 @@ int send_subscribe(subs_info_t* subs)
554 555
 				goto done;
555 556
 			}
556 557
 		}
557
-		td= build_dlg_t(presentity);
558
+		td= pua_build_dlg_t(presentity);
558 559
 		lock_release(&HashT->p_records[hash_code].lock);
559 560
 	
560 561
 		if(td== NULL)
... ...
@@ -26,14 +26,18 @@
26 26
 #ifndef _PU_SEND_SUBSC_
27 27
 #define _PU_SEND_SUBSC_
28 28
 
29
-#include "../../str.h"
30 29
 #include <time.h>
31 30
 
31
+#include "../tm/tm_load.h"
32
+#include "../../str.h"
33
+#include "hash.h"
34
+
32 35
 typedef struct subs_info
33 36
 {
34 37
 	str id;
35 38
 	str* pres_uri;
36 39
 	str* watcher_uri;
40
+	int event;
37 41
 	time_t expires;
38 42
 	int flag;
39 43
 	int source_flag;
... ...
@@ -42,5 +46,8 @@ typedef struct subs_info
42 46
 
43 47
 typedef int (*send_subscribe_t)(subs_info_t* subs);
44 48
 int send_subscribe(subs_info_t* subs);
49
+void subs_cback_func(struct cell *t, int type, struct tmcb_params *ps);
50
+str* subs_build_hdr(str* watcher_uri, int expires, int event);
51
+dlg_t* pua_build_dlg_t(ua_pres_t* presentity);
45 52
 
46 53
 #endif