Browse code

pua: use parameter default_expires instead of 3600 constant

- GH #2994

Daniel-Constantin Mierla authored on 05/01/2022 17:44:41
Showing 1 changed files
... ...
@@ -668,7 +668,7 @@ send_publish:
668 668
 
669 669
 	if(publ->flag & UPDATE_TYPE)
670 670
 		LM_DBG("etag:%.*s\n", etag.len, etag.s);
671
-	str_hdr = publ_build_hdr((publ->expires< 0)?3600:publ->expires, ev, &publ->content_type,
671
+	str_hdr = publ_build_hdr((publ->expires< 0)?pua_default_expires:publ->expires, ev, &publ->content_type,
672 672
 				(publ->flag & UPDATE_TYPE)?&etag:NULL, publ->extra_headers, (body)?1:0);
673 673
 
674 674
 	if(str_hdr == NULL)
Browse code

pua: fix send_publish() behavior on PUA_DB_ONLY

* dialog PUBLISH was missing SIP-If-Mach
* pua was inserting a new record for every dialog state

fixes #2414

Victor Seva authored on 30/07/2020 10:19:45
Showing 1 changed files
... ...
@@ -516,14 +516,11 @@ int send_publish( publ_info_t* publ )
516 516
 
517 517
 	if (dbmode==PUA_DB_ONLY)
518 518
 	{
519
-		if (publ->etag) {
520
-			memset(&dbpres, 0, sizeof(dbpres));
521
-			dbpres.pres_uri = &pres_uri;
522
-			dbpres.watcher_uri = &watcher_uri;
523
-			dbpres.extra_headers = &extra_headers;
524
-			presentity = get_record_puadb(publ->id, publ->etag,
525
-						      &dbpres, &res);
526
-		}
519
+		memset(&dbpres, 0, sizeof(dbpres));
520
+		dbpres.pres_uri = &pres_uri;
521
+		dbpres.watcher_uri = &watcher_uri;
522
+		dbpres.extra_headers = &extra_headers;
523
+		presentity = get_record_puadb(publ->id, publ->etag, &dbpres, &res);
527 524
 	}
528 525
 	else
529 526
 	{
Browse code

pua: convert to PKG/SHM memory logging helper functions

* remove trailing spaces

Victor Seva authored on 29/07/2020 08:53:48
Showing 1 changed files
... ...
@@ -59,7 +59,7 @@ str* publ_build_hdr(int expires, pua_event_t* ev, str* content_type, str* etag,
59 59
 	str_hdr =(str*)pkg_malloc(sizeof(str));
60 60
 	if(str_hdr== NULL)
61 61
 	{
62
-		LM_ERR("no more memory\n");
62
+		PKG_MEM_ERROR;
63 63
 		return NULL;
64 64
 	}
65 65
 	memset(str_hdr, 0 , sizeof(str));
... ...
@@ -79,12 +79,12 @@ str* publ_build_hdr(int expires, pua_event_t* ev, str* content_type, str* etag,
79 79
 	str_hdr->len+= ev->name.len;
80 80
 	memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
81 81
 	str_hdr->len += CRLF_LEN;
82
-	
82
+
83 83
 
84 84
 	memcpy(str_hdr->s+str_hdr->len ,"Expires: ", 9);
85 85
 	str_hdr->len += 9;
86 86
 
87
-	t= expires; 
87
+	t= expires;
88 88
 
89 89
 	if( t<=0 )
90 90
 	{
... ...
@@ -100,7 +100,7 @@ str* publ_build_hdr(int expires, pua_event_t* ev, str* content_type, str* etag,
100 100
 	str_hdr->len+= len;
101 101
 	memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
102 102
 	str_hdr->len += CRLF_LEN;
103
-	
103
+
104 104
 	if(etag)
105 105
 	{
106 106
 		LM_DBG("UPDATE_TYPE [etag]= %.*s\n", etag->len, etag->s);
... ...
@@ -112,13 +112,13 @@ str* publ_build_hdr(int expires, pua_event_t* ev, str* content_type, str* etag,
112 112
 		str_hdr->len += CRLF_LEN;
113 113
 	}
114 114
 	if(is_body)
115
-	{	
115
+	{
116 116
 		if(content_type== NULL || content_type->s== NULL || content_type->len== 0)
117 117
 		{
118
-			ctype= ev->content_type; /* use event default value */ 
118
+			ctype= ev->content_type; /* use event default value */
119 119
 		}
120 120
 		else
121
-		{	
121
+		{
122 122
 			ctype.s=   content_type->s;
123 123
 			ctype.len= content_type->len;
124 124
 		}
... ...
@@ -135,9 +135,9 @@ str* publ_build_hdr(int expires, pua_event_t* ev, str* content_type, str* etag,
135 135
 	{
136 136
 		memcpy(str_hdr->s+str_hdr->len,extra_headers->s , extra_headers->len);
137 137
 		str_hdr->len += extra_headers->len;
138
-	}	
138
+	}
139 139
 	str_hdr->s[str_hdr->len] = '\0';
140
-	
140
+
141 141
 	return str_hdr;
142 142
 
143 143
 }
... ...
@@ -194,7 +194,7 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
194 194
 	struct hdr_field* hdr= NULL;
195 195
 	struct sip_msg* msg= NULL;
196 196
 	ua_pres_t* presentity= NULL;
197
-	ua_pres_t* db_presentity= NULL; 
197
+	ua_pres_t* db_presentity= NULL;
198 198
 	ua_pres_t* hentity= NULL;
199 199
 	int found = 0;
200 200
 	int size= 0;
... ...
@@ -233,7 +233,7 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
233 233
 		LM_ERR("no reply message found\n ");
234 234
 		goto error;
235 235
 	}
236
-	
236
+
237 237
 
238 238
 	if(msg== FAKED_REPLY)
239 239
 	{
... ...
@@ -255,9 +255,9 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
255 255
 			LM_DBG("received a 412 reply- try again to send PUBLISH\n");
256 256
 			publ_info_t publ;
257 257
 			memset(&publ, 0, sizeof(publ_info_t));
258
-			publ.pres_uri= hentity->pres_uri; 
258
+			publ.pres_uri= hentity->pres_uri;
259 259
 			publ.body= hentity->body;
260
-			
260
+
261 261
 			if(hentity->desired_expires== 0)
262 262
 				publ.expires= -1;
263 263
 			else
... ...
@@ -268,7 +268,7 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
268 268
 
269 269
 			publ.source_flag|= hentity->flag;
270 270
 			publ.event|= hentity->event;
271
-			publ.content_type= hentity->content_type;	
271
+			publ.content_type= hentity->content_type;
272 272
 			publ.id= hentity->id;
273 273
 			publ.extra_headers= hentity->extra_headers;
274 274
 			publ.outbound_proxy = hentity->outbound_proxy;
... ...
@@ -293,18 +293,18 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
293 293
 		}
294 294
 		goto done;
295 295
 	} /* code >= 300 */
296
-	
296
+
297 297
 	if( parse_headers(msg,HDR_EOH_F, 0)==-1 )
298 298
 	{
299 299
 		LM_ERR("parsing headers\n");
300 300
 		goto error;
301
-	}	
301
+	}
302 302
 	if(msg->expires== NULL || msg->expires->body.len<= 0)
303 303
 	{
304 304
 			LM_ERR("No Expires header found\n");
305 305
 			goto error;
306
-	}	
307
-	
306
+	}
307
+
308 308
 	if (!msg->expires->parsed && (parse_expires(msg->expires) < 0))
309 309
 	{
310 310
 		LM_ERR("cannot parse Expires header\n");
... ...
@@ -312,7 +312,7 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
312 312
 	}
313 313
 	lexpire = ((exp_body_t*)msg->expires->parsed)->val;
314 314
 	LM_DBG("lexpire= %u\n", lexpire);
315
-		
315
+
316 316
 	hdr = msg->headers;
317 317
 	while (hdr!= NULL)
318 318
 	{
... ...
@@ -324,12 +324,12 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
324 324
 		hdr = hdr->next;
325 325
 	}
326 326
 	if(found== 0) /* must find SIP-Etag header field in 200 OK msg*/
327
-	{	
327
+	{
328 328
 		LM_ERR("no SIP-ETag header field found\n");
329 329
 		goto error;
330 330
 	}
331 331
 	etag= hdr->body;
332
-		
332
+
333 333
 	LM_DBG("completed with status %d [contact:%.*s]\n",
334 334
 	       ps->code, hentity->pres_uri->len, hentity->pres_uri->s);
335 335
 
... ...
@@ -354,8 +354,8 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
354 354
 		}
355 355
 	}
356 356
 
357
-	size= sizeof(ua_pres_t)+ sizeof(str)+ 
358
-		(hentity->pres_uri->len+ hentity->tuple_id.len + 
357
+	size= sizeof(ua_pres_t)+ sizeof(str)+
358
+		(hentity->pres_uri->len+ hentity->tuple_id.len +
359 359
 		 hentity->id.len)* sizeof(char);
360 360
 	if(hentity->extra_headers)
361 361
 		size+= sizeof(str)+ hentity->extra_headers->len* sizeof(char);
... ...
@@ -363,9 +363,9 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
363 363
 	presentity= (ua_pres_t*)shm_malloc(size);
364 364
 	if(presentity== NULL)
365 365
 	{
366
-		LM_ERR("no more share memory\n");
366
+		SHM_MEM_ERROR;
367 367
 		goto error;
368
-	}	
368
+	}
369 369
 	memset(presentity, 0, size);
370 370
 
371 371
 	size= sizeof(ua_pres_t);
... ...
@@ -373,11 +373,11 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
373 373
 	size+= sizeof(str);
374 374
 
375 375
 	presentity->pres_uri->s= (char*)presentity+ size;
376
-	memcpy(presentity->pres_uri->s, hentity->pres_uri->s, 
376
+	memcpy(presentity->pres_uri->s, hentity->pres_uri->s,
377 377
 			hentity->pres_uri->len);
378 378
 	presentity->pres_uri->len= hentity->pres_uri->len;
379 379
 	size+= hentity->pres_uri->len;
380
-	
380
+
381 381
 	presentity->tuple_id.s= (char*)presentity+ size;
382 382
 	memcpy(presentity->tuple_id.s, hentity->tuple_id.s,
383 383
 			hentity->tuple_id.len);
... ...
@@ -385,17 +385,17 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
385 385
 	size+= presentity->tuple_id.len;
386 386
 
387 387
 	presentity->id.s=(char*)presentity+ size;
388
-	memcpy(presentity->id.s, hentity->id.s, 
388
+	memcpy(presentity->id.s, hentity->id.s,
389 389
 			hentity->id.len);
390
-	presentity->id.len= hentity->id.len; 
390
+	presentity->id.len= hentity->id.len;
391 391
 	size+= presentity->id.len;
392
-		
392
+
393 393
 	if(hentity->extra_headers)
394 394
 	{
395 395
 		presentity->extra_headers= (str*)((char*)presentity+ size);
396 396
 		size+= sizeof(str);
397 397
 		presentity->extra_headers->s= (char*)presentity+ size;
398
-		memcpy(presentity->extra_headers->s, hentity->extra_headers->s, 
398
+		memcpy(presentity->extra_headers->s, hentity->extra_headers->s,
399 399
 				hentity->extra_headers->len);
400 400
 		presentity->extra_headers->len= hentity->extra_headers->len;
401 401
 		size+= hentity->extra_headers->len;
... ...
@@ -409,7 +409,7 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
409 409
 	presentity->etag.s= (char*)shm_malloc(etag.len* sizeof(char));
410 410
 	if(presentity->etag.s== NULL)
411 411
 	{
412
-		LM_ERR("No more share memory\n");
412
+		SHM_MEM_ERROR;
413 413
 		goto error;
414 414
 	}
415 415
 	memcpy(presentity->etag.s, etag.s, etag.len);
... ...
@@ -473,7 +473,7 @@ error:
473 473
 	}
474 474
 
475 475
 	return;
476
-}	
476
+}
477 477
 
478 478
 int send_publish( publ_info_t* publ )
479 479
 {
... ...
@@ -491,12 +491,12 @@ int send_publish( publ_info_t* publ )
491 491
 	pua_event_t* ev= NULL;
492 492
 	uac_req_t uac_r;
493 493
 	db1_res_t *res=NULL;
494
-	ua_pres_t dbpres; 
494
+	ua_pres_t dbpres;
495 495
 	str pres_uri={0,0}, watcher_uri={0,0}, extra_headers={0,0};
496 496
 	int ret = -1;
497 497
 
498 498
 	LM_DBG("pres_uri=%.*s\n", publ->pres_uri->len, publ->pres_uri->s );
499
-	
499
+
500 500
 	if (dbmode == PUA_DB_ONLY && pua_dbf.start_transaction)
501 501
 	{
502 502
 		if (pua_dbf.start_transaction(pua_db, db_table_lock) < 0)
... ...
@@ -512,7 +512,7 @@ int send_publish( publ_info_t* publ )
512 512
 	{
513 513
 		LM_ERR("event not found in list\n");
514 514
 		goto error;
515
-	}	
515
+	}
516 516
 
517 517
 	if (dbmode==PUA_DB_ONLY)
518 518
 	{
... ...
@@ -544,7 +544,7 @@ int send_publish( publ_info_t* publ )
544 544
 
545 545
 	if(publ->etag && presentity== NULL)
546 546
 	{
547
-		if (dbmode!=PUA_DB_ONLY) 
547
+		if (dbmode!=PUA_DB_ONLY)
548 548
 			lock_release(&HashT->p_records[hash_code].lock);
549 549
 		ret = 418;
550 550
 		goto error;
... ...
@@ -555,14 +555,14 @@ int send_publish( publ_info_t* publ )
555 555
 		LM_DBG("Insert flag set\n");
556 556
 		goto insert;
557 557
 	}
558
-	
558
+
559 559
 	if(presentity== NULL)
560 560
 	{
561
-insert:	
562
-		if (dbmode!=PUA_DB_ONLY) 
561
+insert:
562
+		if (dbmode!=PUA_DB_ONLY)
563 563
 			lock_release(&HashT->p_records[hash_code].lock);
564
-		LM_DBG("insert type\n"); 
565
-		
564
+		LM_DBG("insert type\n");
565
+
566 566
 		if(publ->flag & UPDATE_TYPE )
567 567
 		{
568 568
 			LM_DBG("UPDATE_TYPE and no record found \n");
... ...
@@ -573,7 +573,7 @@ insert:
573 573
 			LM_DBG("request for a publish with expires 0 and"
574 574
 					" no record found\n");
575 575
 			goto done;
576
-			
576
+
577 577
 		}
578 578
 		if(publ->body== NULL)
579 579
 		{
... ...
@@ -589,8 +589,8 @@ insert:
589 589
 		etag.s= (char*)pkg_malloc(presentity->etag.len* sizeof(char));
590 590
 		if(etag.s== NULL)
591 591
 		{
592
-			LM_ERR("while allocating memory\n");
593
-			if (dbmode!=PUA_DB_ONLY) 
592
+			PKG_MEM_ERROR;
593
+			if (dbmode!=PUA_DB_ONLY)
594 594
 				lock_release(&HashT->p_records[hash_code].lock);
595 595
 			goto error;
596 596
 		}
... ...
@@ -598,24 +598,24 @@ insert:
598 598
 		etag.len= presentity->etag.len;
599 599
 
600 600
 		if(presentity->tuple_id.s && presentity->tuple_id.len)
601
-		{	
601
+		{
602 602
 			/* get tuple_id*/
603 603
 			tuple_id=(str*)pkg_malloc(sizeof(str));
604 604
 			if(tuple_id== NULL)
605 605
 			{
606
-				LM_ERR("No more memory\n");
607
-				if (dbmode!=PUA_DB_ONLY) 
606
+				PKG_MEM_ERROR;
607
+				if (dbmode!=PUA_DB_ONLY)
608 608
 					lock_release(&HashT->p_records[hash_code].lock);
609 609
 				goto error;
610
-			}	
610
+			}
611 611
 			tuple_id->s= (char*)pkg_malloc(presentity->tuple_id.len* sizeof(char));
612 612
 			if(tuple_id->s== NULL)
613 613
 			{
614
-				LM_ERR("No more memory\n");
615
-				if (dbmode!=PUA_DB_ONLY) 
614
+				PKG_MEM_ERROR;
615
+				if (dbmode!=PUA_DB_ONLY)
616 616
 					lock_release(&HashT->p_records[hash_code].lock);
617 617
 				goto error;
618
-			}	
618
+			}
619 619
 			memcpy(tuple_id->s, presentity->tuple_id.s, presentity->tuple_id.len);
620 620
 			tuple_id->len= presentity->tuple_id.len;
621 621
 		}
... ...
@@ -623,16 +623,16 @@ insert:
623 623
 		if(publ->expires== 0)
624 624
 		{
625 625
 			LM_DBG("expires= 0- delete from hash table\n");
626
-			if (dbmode!=PUA_DB_ONLY) 
626
+			if (dbmode!=PUA_DB_ONLY)
627 627
 				lock_release(&HashT->p_records[hash_code].lock);
628 628
 			goto send_publish;
629 629
 		}
630 630
 
631
-		presentity->version++; 
631
+		presentity->version++;
632 632
 		ver= presentity->version;
633 633
 
634 634
 		if (dbmode==PUA_DB_ONLY)
635
-		{ 
635
+		{
636 636
 			update_version_puadb(presentity);
637 637
 		}
638 638
 		else
... ...
@@ -655,9 +655,9 @@ insert:
655 655
 	}
656 656
 	if(tuple_id)
657 657
 		LM_DBG("tuple_id= %.*s\n", tuple_id->len, tuple_id->s  );
658
-	
658
+
659 659
 send_publish:
660
-	
660
+
661 661
 	/* construct the callback parameter */
662 662
 	if(etag.s && etag.len)
663 663
 		publ->etag = &etag;
... ...
@@ -671,7 +671,7 @@ send_publish:
671 671
 
672 672
 	if(publ->flag & UPDATE_TYPE)
673 673
 		LM_DBG("etag:%.*s\n", etag.len, etag.s);
674
-	str_hdr = publ_build_hdr((publ->expires< 0)?3600:publ->expires, ev, &publ->content_type, 
674
+	str_hdr = publ_build_hdr((publ->expires< 0)?3600:publ->expires, ev, &publ->content_type,
675 675
 				(publ->flag & UPDATE_TYPE)?&etag:NULL, publ->extra_headers, (body)?1:0);
676 676
 
677 677
 	if(str_hdr == NULL)
... ...
@@ -733,7 +733,7 @@ finish:
733 733
 		if(body->s)
734 734
 			xmlFree(body->s);
735 735
 		pkg_free(body);
736
-	}	
736
+	}
737 737
 	if(str_hdr)
738 738
 		pkg_free(str_hdr);
739 739
 	if(tuple_id)
... ...
@@ -753,7 +753,7 @@ ua_pres_t* publish_cbparam(publ_info_t* publ,str* body,str* tuple_id,
753 753
 	int size;
754 754
 	ua_pres_t* cb_param= NULL;
755 755
 
756
-	size= sizeof(ua_pres_t)+ sizeof(str)+ (publ->pres_uri->len+ 
756
+	size= sizeof(ua_pres_t)+ sizeof(str)+ (publ->pres_uri->len+
757 757
 		+ publ->content_type.len+ publ->id.len+ 1)*sizeof(char);
758 758
 
759 759
 	if(publ->outbound_proxy)
... ...
@@ -770,12 +770,11 @@ ua_pres_t* publish_cbparam(publ_info_t* publ,str* body,str* tuple_id,
770 770
 	cb_param= (ua_pres_t*)shm_malloc(size);
771 771
 	if(cb_param== NULL)
772 772
 	{
773
-		LM_ERR("ERROR no more share memory while allocating cb_param"
774
-				" - size= %d\n", size);
773
+		SHM_MEM_ERROR;
775 774
 		return NULL;
776 775
 	}
777 776
 	memset(cb_param, 0, size);
778
-	
777
+
779 778
 	size =  sizeof(ua_pres_t);
780 779
 
781 780
 	cb_param->pres_uri = (str*)((char*)cb_param + size);
... ...
@@ -787,7 +786,7 @@ ua_pres_t* publish_cbparam(publ_info_t* publ,str* body,str* tuple_id,
787 786
 	size+= publ->pres_uri->len;
788 787
 
789 788
 	if(publ->id.s && publ->id.len)
790
-	{	
789
+	{
791 790
 		cb_param->id.s = ((char*)cb_param+ size);
792 791
 		memcpy(cb_param->id.s, publ->id.s, publ->id.len);
793 792
 		cb_param->id.len= publ->id.len;
... ...
@@ -798,7 +797,7 @@ ua_pres_t* publish_cbparam(publ_info_t* publ,str* body,str* tuple_id,
798 797
 	{
799 798
 		cb_param->body = (str*)((char*)cb_param  + size);
800 799
 		size+= sizeof(str);
801
-		
800
+
802 801
 		cb_param->body->s = (char*)cb_param + size;
803 802
 		memcpy(cb_param->body->s, body->s ,
804 803
 			body->len ) ;
... ...
@@ -822,7 +821,7 @@ ua_pres_t* publish_cbparam(publ_info_t* publ,str* body,str* tuple_id,
822 821
 			publ->extra_headers->len ) ;
823 822
 		cb_param->extra_headers->len= publ->extra_headers->len;
824 823
 		size+= publ->extra_headers->len;
825
-	}	
824
+	}
826 825
 	if(publ->outbound_proxy)
827 826
 	{
828 827
 		cb_param->outbound_proxy = (str*)((char*)cb_param + size);
... ...
@@ -832,7 +831,7 @@ ua_pres_t* publish_cbparam(publ_info_t* publ,str* body,str* tuple_id,
832 831
 		       publ->outbound_proxy->len);
833 832
 		cb_param->outbound_proxy->len = publ->outbound_proxy->len;
834 833
 		size+= publ->outbound_proxy->len;
835
-	}	
834
+	}
836 835
 
837 836
 	if(publ->content_type.s && publ->content_type.len)
838 837
 	{
... ...
@@ -840,9 +839,9 @@ ua_pres_t* publish_cbparam(publ_info_t* publ,str* body,str* tuple_id,
840 839
 		memcpy(cb_param->content_type.s, publ->content_type.s, publ->content_type.len);
841 840
 		cb_param->content_type.len= publ->content_type.len;
842 841
 		size+=  publ->content_type.len;
843
-	}	
842
+	}
844 843
 	if(tuple_id)
845
-	{	
844
+	{
846 845
 		cb_param->tuple_id.s = (char*)cb_param+ size;
847 846
 		memcpy(cb_param->tuple_id.s, tuple_id->s ,tuple_id->len);
848 847
 		cb_param->tuple_id.len= tuple_id->len;
Browse code

pua: renamed MI flags to reflect use of RPC

Daniel-Constantin Mierla authored on 12/12/2017 08:48:45
Showing 1 changed files
... ...
@@ -247,8 +247,8 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
247 247
 	{
248 248
 		find_and_delete_record(hentity, hash_code);
249 249
 
250
-		if(ps->code== 412 && hentity->body && hentity->flag!= MI_PUBLISH
251
-				&& hentity->flag!= MI_ASYN_PUBLISH)
250
+		if(ps->code== 412 && hentity->body && hentity->flag!= RPC_PUBLISH
251
+				&& hentity->flag!= RPC_ASYN_PUBLISH)
252 252
 		{
253 253
 			/* sent a PUBLISH within a dialog that no longer exists
254 254
 			 * send again an intial PUBLISH */
Browse code

pua: free in case of errors

Daniel-Constantin Mierla authored on 31/07/2017 13:53:27
Showing 1 changed files
... ...
@@ -457,7 +457,7 @@ done:
457 457
 	return;
458 458
 
459 459
 error:
460
-	if(*ps->param)
460
+	if(ps->param && *ps->param)
461 461
 	{
462 462
 		shm_free(*ps->param);
463 463
 		*ps->param= NULL;
Browse code

core, lib, modules: updated include paths for header files

Daniel-Constantin Mierla authored on 07/12/2016 11:07:22
Showing 1 changed files
... ...
@@ -28,14 +28,14 @@
28 28
 #include <libxml/parser.h>
29 29
 #include <time.h>
30 30
 
31
-#include "../../mem/mem.h"
32
-#include "../../dprint.h"
33
-#include "../../parser/parse_expires.h"
34
-#include "../../dprint.h"
35
-#include "../../mem/shm_mem.h"
36
-#include "../../parser/msg_parser.h"
37
-#include "../../strutils.h"
38
-#include "../../hashes.h"
31
+#include "../../core/mem/mem.h"
32
+#include "../../core/dprint.h"
33
+#include "../../core/parser/parse_expires.h"
34
+#include "../../core/dprint.h"
35
+#include "../../core/mem/shm_mem.h"
36
+#include "../../core/parser/msg_parser.h"
37
+#include "../../core/strutils.h"
38
+#include "../../core/hashes.h"
39 39
 #include "../../modules/tm/tm_load.h"
40 40
 #include "pua.h"
41 41
 #include "hash.h"
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,863 @@
1
+/*
2
+ * pua module - presence user agent module
3
+ *
4
+ * Copyright (C) 2006 Voice Sistem S.R.L.
5
+ *
6
+ * This file is part of Kamailio, a free SIP server.
7
+ *
8
+ * Kamailio is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * Kamailio is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
+ *
22
+ */
23
+
24
+
25
+#include <stdio.h>
26
+#include <stdlib.h>
27
+#include <string.h>
28
+#include <libxml/parser.h>
29
+#include <time.h>
30
+
31
+#include "../../mem/mem.h"
32
+#include "../../dprint.h"
33
+#include "../../parser/parse_expires.h"
34
+#include "../../dprint.h"
35
+#include "../../mem/shm_mem.h"
36
+#include "../../parser/msg_parser.h"
37
+#include "../../strutils.h"
38
+#include "../../hashes.h"
39
+#include "../../modules/tm/tm_load.h"
40
+#include "pua.h"
41
+#include "hash.h"
42
+#include "send_publish.h"
43
+#include "pua_callback.h"
44
+#include "event_list.h"
45
+#include "pua_db.h"
46
+
47
+extern db_locking_t db_table_lock;
48
+
49
+str* publ_build_hdr(int expires, pua_event_t* ev, str* content_type, str* etag,
50
+		str* extra_headers, int is_body)
51
+{
52
+	static char buf[3000];
53
+	str* str_hdr = NULL;
54
+	char* expires_s = NULL;
55
+	int len = 0;
56
+	int t= 0;
57
+	str ctype;
58
+
59
+	str_hdr =(str*)pkg_malloc(sizeof(str));
60
+	if(str_hdr== NULL)
61
+	{
62
+		LM_ERR("no more memory\n");
63
+		return NULL;
64
+	}
65
+	memset(str_hdr, 0 , sizeof(str));
66
+	memset(buf, 0, 2999);
67
+	str_hdr->s = buf;
68
+	str_hdr->len= 0;
69
+
70
+	memcpy(str_hdr->s ,"Max-Forwards: ", 14);
71
+	str_hdr->len = 14;
72
+	str_hdr->len+= sprintf(str_hdr->s+ str_hdr->len,"%d", MAX_FORWARD);
73
+	memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
74
+	str_hdr->len += CRLF_LEN;
75
+
76
+	memcpy(str_hdr->s+ str_hdr->len ,"Event: ", 7);
77
+	str_hdr->len+= 7;
78
+	memcpy(str_hdr->s+ str_hdr->len, ev->name.s, ev->name.len);
79
+	str_hdr->len+= ev->name.len;
80
+	memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
81
+	str_hdr->len += CRLF_LEN;
82
+	
83
+
84
+	memcpy(str_hdr->s+str_hdr->len ,"Expires: ", 9);
85
+	str_hdr->len += 9;
86
+
87
+	t= expires; 
88
+
89
+	if( t<=0 )
90
+	{
91
+		t= min_expires;
92
+	}
93
+	else
94
+	{
95
+		t++;
96
+	}
97
+	expires_s = int2str(t, &len);
98
+
99
+	memcpy(str_hdr->s+str_hdr->len, expires_s, len);
100
+	str_hdr->len+= len;
101
+	memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
102
+	str_hdr->len += CRLF_LEN;
103
+	
104
+	if(etag)
105
+	{
106
+		LM_DBG("UPDATE_TYPE [etag]= %.*s\n", etag->len, etag->s);
107
+		memcpy(str_hdr->s+str_hdr->len,"SIP-If-Match: ", 14);
108
+		str_hdr->len += 14;
109
+		memcpy(str_hdr->s+str_hdr->len, etag->s, etag->len);
110
+		str_hdr->len += etag->len;
111
+		memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
112
+		str_hdr->len += CRLF_LEN;
113
+	}
114
+	if(is_body)
115
+	{	
116
+		if(content_type== NULL || content_type->s== NULL || content_type->len== 0)
117
+		{
118
+			ctype= ev->content_type; /* use event default value */ 
119
+		}
120
+		else
121
+		{	
122
+			ctype.s=   content_type->s;
123
+			ctype.len= content_type->len;
124
+		}
125
+
126
+		memcpy(str_hdr->s+str_hdr->len,"Content-Type: ", 14);
127
+		str_hdr->len += 14;
128
+		memcpy(str_hdr->s+str_hdr->len, ctype.s, ctype.len);
129
+		str_hdr->len += ctype.len;
130
+		memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
131
+		str_hdr->len += CRLF_LEN;
132
+	}
133
+
134
+	if(extra_headers && extra_headers->s && extra_headers->len)
135
+	{
136
+		memcpy(str_hdr->s+str_hdr->len,extra_headers->s , extra_headers->len);
137
+		str_hdr->len += extra_headers->len;
138
+	}	
139
+	str_hdr->s[str_hdr->len] = '\0';
140
+	
141
+	return str_hdr;
142
+
143
+}
144
+
145
+static void find_and_delete_record(ua_pres_t *dialog, int hash_code)
146
+{
147
+	ua_pres_t *presentity;
148
+
149
+	if (dbmode == PUA_DB_ONLY)
150
+	{
151
+		delete_record_puadb(dialog);
152
+	}
153
+	else
154
+	{
155
+		lock_get(&HashT->p_records[hash_code].lock);
156
+		presentity = search_htable(dialog, hash_code);
157
+		if (presentity == NULL)
158
+		{
159
+			LM_DBG("Record found in table and deleted\n");
160
+			lock_release(&HashT->p_records[hash_code].lock);
161
+			return;
162
+		}
163
+		delete_htable(presentity, hash_code);
164
+		lock_release(&HashT->p_records[hash_code].lock);
165
+	}
166
+}
167
+
168
+static int find_and_update_record(ua_pres_t *dialog, int hash_code, int lexpire, str *etag)
169
+{
170
+	ua_pres_t *presentity;
171
+
172
+	if(dbmode==PUA_DB_ONLY)
173
+	{
174
+		return update_record_puadb(dialog, lexpire, etag);
175
+	}
176
+	else
177
+	{
178
+		lock_get(&HashT->p_records[hash_code].lock);
179
+		presentity = search_htable(dialog, hash_code);
180
+		if (presentity == NULL)
181
+		{
182
+			LM_DBG("Record found in table and deleted\n");
183
+			lock_release(&HashT->p_records[hash_code].lock);
184
+			return 0;
185
+		}
186
+		update_htable(presentity, dialog->desired_expires, lexpire, etag, hash_code, NULL);
187
+		lock_release(&HashT->p_records[hash_code].lock);
188
+		return 1;
189
+	}
190
+}
191
+
192
+void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
193
+{
194
+	struct hdr_field* hdr= NULL;
195
+	struct sip_msg* msg= NULL;
196
+	ua_pres_t* presentity= NULL;
197
+	ua_pres_t* db_presentity= NULL; 
198
+	ua_pres_t* hentity= NULL;
199
+	int found = 0;
200
+	int size= 0;
201
+	unsigned int lexpire= 0;
202
+	str etag;
203
+	unsigned int hash_code;
204
+	db1_res_t *res=NULL;
205
+	ua_pres_t dbpres;
206
+	str pres_uri={0,0}, watcher_uri={0,0}, extra_headers={0,0};
207
+	int end_transaction = 1;
208
+
209
+	memset(&dbpres, 0, sizeof(dbpres));
210
+	dbpres.pres_uri = &pres_uri;
211
+	dbpres.watcher_uri = &watcher_uri;
212
+	dbpres.extra_headers = &extra_headers;
213
+
214
+	if (dbmode == PUA_DB_ONLY && pua_dbf.start_transaction)
215
+	{
216
+		if (pua_dbf.start_transaction(pua_db, db_table_lock) < 0)
217
+		{
218
+			LM_ERR("in start_transaction\n");
219
+			goto error;
220
+		}
221
+	}
222
+
223
+	if(ps->param== NULL|| *ps->param== NULL)
224
+	{
225
+		LM_ERR("NULL callback parameter\n");
226
+		goto error;
227
+	}
228
+	hentity= (ua_pres_t*)(*ps->param);
229
+
230
+	msg= ps->rpl;
231
+	if(msg == NULL)
232
+	{
233
+		LM_ERR("no reply message found\n ");
234
+		goto error;
235
+	}
236
+	
237
+
238
+	if(msg== FAKED_REPLY)
239
+	{
240
+		LM_DBG("FAKED_REPLY\n");
241
+		goto done;
242
+	}
243
+
244
+	hash_code= core_hash(hentity->pres_uri, NULL, HASH_SIZE);
245
+
246
+	if( ps->code>= 300 )
247
+	{
248
+		find_and_delete_record(hentity, hash_code);
249
+
250
+		if(ps->code== 412 && hentity->body && hentity->flag!= MI_PUBLISH
251
+				&& hentity->flag!= MI_ASYN_PUBLISH)
252
+		{
253
+			/* sent a PUBLISH within a dialog that no longer exists
254
+			 * send again an intial PUBLISH */
255
+			LM_DBG("received a 412 reply- try again to send PUBLISH\n");
256
+			publ_info_t publ;
257
+			memset(&publ, 0, sizeof(publ_info_t));
258
+			publ.pres_uri= hentity->pres_uri; 
259
+			publ.body= hentity->body;
260
+			
261
+			if(hentity->desired_expires== 0)
262
+				publ.expires= -1;
263
+			else
264
+			if(hentity->desired_expires<= (int)time(NULL))
265
+				publ.expires= 0;
266
+			else
267
+				publ.expires= hentity->desired_expires- (int)time(NULL)+ 3;
268
+
269
+			publ.source_flag|= hentity->flag;
270
+			publ.event|= hentity->event;
271
+			publ.content_type= hentity->content_type;	
272
+			publ.id= hentity->id;
273
+			publ.extra_headers= hentity->extra_headers;
274
+			publ.outbound_proxy = hentity->outbound_proxy;
275
+			publ.cb_param= hentity->cb_param;
276
+
277
+			if (dbmode == PUA_DB_ONLY && pua_dbf.end_transaction)
278
+			{
279
+				if (pua_dbf.end_transaction(pua_db) < 0)
280
+				{
281
+					LM_ERR("in end_transaction\n");
282
+					goto error;
283
+				}
284
+			}
285
+
286
+			end_transaction = 0;
287
+
288
+			if(send_publish(&publ)< 0)
289
+			{
290
+				LM_ERR("when trying to send PUBLISH\n");
291
+				goto error;
292
+			}
293
+		}
294
+		goto done;
295
+	} /* code >= 300 */
296
+	
297
+	if( parse_headers(msg,HDR_EOH_F, 0)==-1 )
298
+	{
299
+		LM_ERR("parsing headers\n");
300
+		goto error;
301
+	}	
302
+	if(msg->expires== NULL || msg->expires->body.len<= 0)
303
+	{
304
+			LM_ERR("No Expires header found\n");
305
+			goto error;
306
+	}	
307
+	
308
+	if (!msg->expires->parsed && (parse_expires(msg->expires) < 0))
309
+	{
310
+		LM_ERR("cannot parse Expires header\n");
311
+		goto error;
312
+	}
313
+	lexpire = ((exp_body_t*)msg->expires->parsed)->val;
314
+	LM_DBG("lexpire= %u\n", lexpire);
315
+		
316
+	hdr = msg->headers;
317
+	while (hdr!= NULL)
318
+	{
319
+		if(cmp_hdrname_strzn(&hdr->name, "SIP-ETag",8)==0 )
320
+		{
321
+			found = 1;
322
+			break;
323
+		}
324
+		hdr = hdr->next;
325
+	}
326
+	if(found== 0) /* must find SIP-Etag header field in 200 OK msg*/
327
+	{	
328
+		LM_ERR("no SIP-ETag header field found\n");
329
+		goto error;
330
+	}
331
+	etag= hdr->body;
332
+		
333
+	LM_DBG("completed with status %d [contact:%.*s]\n",
334
+	       ps->code, hentity->pres_uri->len, hentity->pres_uri->s);
335
+
336
+	if (lexpire == 0)
337
+	{
338
+		find_and_delete_record(hentity, hash_code);
339
+		goto done;
340
+	}
341
+
342
+	if (hentity->etag.s) {
343
+		if (pua_dbf.affected_rows != NULL || dbmode != PUA_DB_ONLY) {
344
+			if (find_and_update_record(hentity, hash_code,
345
+						   lexpire, &etag) > 0)
346
+				goto done;
347
+		}
348
+		else if ((db_presentity =
349
+			  get_record_puadb(hentity->id, &hentity->etag,
350
+					   &dbpres, &res)) != NULL)
351
+		{
352
+			update_record_puadb(hentity, lexpire, &etag);
353
+			goto done;
354
+		}
355
+	}
356
+
357
+	size= sizeof(ua_pres_t)+ sizeof(str)+ 
358
+		(hentity->pres_uri->len+ hentity->tuple_id.len + 
359
+		 hentity->id.len)* sizeof(char);
360
+	if(hentity->extra_headers)
361
+		size+= sizeof(str)+ hentity->extra_headers->len* sizeof(char);
362
+
363
+	presentity= (ua_pres_t*)shm_malloc(size);
364
+	if(presentity== NULL)
365
+	{
366
+		LM_ERR("no more share memory\n");
367
+		goto error;
368
+	}	
369
+	memset(presentity, 0, size);
370
+
371
+	size= sizeof(ua_pres_t);
372
+	presentity->pres_uri= (str*)((char*)presentity+ size);
373
+	size+= sizeof(str);
374
+
375
+	presentity->pres_uri->s= (char*)presentity+ size;
376
+	memcpy(presentity->pres_uri->s, hentity->pres_uri->s, 
377
+			hentity->pres_uri->len);
378
+	presentity->pres_uri->len= hentity->pres_uri->len;
379
+	size+= hentity->pres_uri->len;
380
+	
381
+	presentity->tuple_id.s= (char*)presentity+ size;
382
+	memcpy(presentity->tuple_id.s, hentity->tuple_id.s,
383
+			hentity->tuple_id.len);
384
+	presentity->tuple_id.len= hentity->tuple_id.len;
385
+	size+= presentity->tuple_id.len;
386
+
387
+	presentity->id.s=(char*)presentity+ size;