Browse code

Update to the new event parser in the sip-router core.

List of changes:
* Variable parsed in the event structure has been renamed to type
* Variable text in the event structure has been renamed to name
* Linked list of parameters is now in event->params.list
* There is a new macro EVENT_DIALOG_SLA in util_func.h
* Use macro EVENT_DIALOG_SLA to if the Event header contains
"dialog;sla"

Jan Janak authored on 17/03/2009 17:46:13
Showing 7 changed files
... ...
@@ -61,15 +61,15 @@ event_t* shm_copy_event(event_t* e)
61 61
 	}
62 62
 	memset(ev, 0, sizeof(event_t));
63 63
 
64
-	ev->text.s= (char*)shm_malloc(e->text.len* sizeof(char));
65
-	if(ev->text.s== NULL)
64
+	ev->name.s= (char*)shm_malloc(e->name.len* sizeof(char));
65
+	if(ev->name.s== NULL)
66 66
 	{
67 67
 		ERR_MEM(SHARE_MEM);
68 68
 	}
69
-	memcpy(ev->text.s, e->text.s, e->text.len);
70
-	ev->text.len= e->text.len;
69
+	memcpy(ev->name.s, e->name.s, e->name.len);
70
+	ev->name.len= e->name.len;
71 71
 
72
-	p1= e->params;
72
+	p1= e->params.list;
73 73
 	while(p1)
74 74
 	{
75 75
 		size= sizeof(param_t)+ (p1->name.len+ p1->body.len)* sizeof(char);
... ...
@@ -84,11 +84,11 @@ event_t* shm_copy_event(event_t* e)
84 84
 		CONT_COPY(p2, p2->name, p1->name);
85 85
 		if(p1->body.s && p1->body.len)
86 86
 			CONT_COPY(p2, p2->body, p1->body);
87
-		p2->next= ev->params;
88
-		ev->params= p2;
87
+		p2->next= ev->params.list;
88
+		ev->params.list= p2;
89 89
 		p1= p1->next;
90 90
 	}
91
-	ev->parsed= e->parsed;
91
+	ev->type= e->type;
92 92
 
93 93
 	return ev;
94 94
 
... ...
@@ -102,10 +102,10 @@ void shm_free_event(event_t* ev)
102 102
 	if(ev== NULL)
103 103
 		return;
104 104
 	
105
-	if(ev->text.s)
106
-		shm_free(ev->text.s);
105
+	if(ev->name.s)
106
+		shm_free(ev->name.s);
107 107
 
108
-	free_event_params(ev->params, SHM_MEM_TYPE);
108
+	free_event_params(ev->params.list, SHM_MEM_TYPE);
109 109
 
110 110
 	shm_free(ev);
111 111
 }
... ...
@@ -141,14 +141,14 @@ int add_event(pres_ev_t* event)
141 141
 		ev= (pres_ev_t*)shm_malloc(sizeof(pres_ev_t));
142 142
 		if(ev== NULL)
143 143
 		{
144
-			free_event_params(parsed_event.params, PKG_MEM_TYPE);
144
+			free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
145 145
 			ERR_MEM(SHARE_MEM);
146 146
 		}
147 147
 		memset(ev, 0, sizeof(pres_ev_t));
148 148
 		ev->name.s= (char*)shm_malloc(event->name.len* sizeof(char));
149 149
 		if(ev->name.s== NULL)
150 150
 		{
151
-			free_event_params(parsed_event.params, PKG_MEM_TYPE);
151
+			free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
152 152
 			ERR_MEM(SHARE_MEM);
153 153
 		}
154 154
 		memcpy(ev->name.s, event->name.s, event->name.len);
... ...
@@ -158,14 +158,14 @@ int add_event(pres_ev_t* event)
158 158
 		if(ev->evp== NULL)
159 159
 		{
160 160
 			LM_ERR("copying event_t structure\n");
161
-			free_event_params(parsed_event.params, PKG_MEM_TYPE);
161
+			free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
162 162
 			goto error;
163 163
 		}
164
-		free_event_params(parsed_event.params, PKG_MEM_TYPE);
164
+		free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
165 165
 	}
166 166
 	else
167 167
 	{
168
-		free_event_params(parsed_event.params, PKG_MEM_TYPE);
168
+		free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
169 169
 		if(ev->content_type.s)
170 170
 		{
171 171
 			LM_DBG("Event already registered\n");
... ...
@@ -296,7 +296,7 @@ pres_ev_t* contains_event(str* sname, event_t* parsed_event)
296 296
 		*parsed_event= event;
297 297
 	else
298 298
 	{
299
-		free_event_params(event.params, PKG_MEM_TYPE);
299
+		free_event_params(event.params.list, PKG_MEM_TYPE);
300 300
 	}
301 301
 	e= search_event(&event);
302 302
 
... ...
@@ -325,13 +325,13 @@ pres_ev_t* search_event(event_t* event)
325 325
 	pres_ev_t* pres_ev;
326 326
 	pres_ev= EvList->events;
327 327
 
328
-	LM_DBG("start event= [%.*s]\n", event->text.len, event->text.s);
328
+	LM_DBG("start event= [%.*s]\n", event->name.len, event->name.s);
329 329
 
330 330
 	while(pres_ev)
331 331
 	{
332
-		if(pres_ev->evp->parsed== event->parsed)
332
+		if(pres_ev->evp->type== event->type)
333 333
 		{
334
-			if(event->params== NULL && pres_ev->evp->params== NULL)
334
+			if(event->params.list== NULL && pres_ev->evp->params.list== NULL)
335 335
 			{
336 336
 				return pres_ev;
337 337
 			}
... ...
@@ -357,11 +357,11 @@ int search_event_params(event_t* ev, event_t* searched_ev)
357 357
 	param_t* ps, *p;
358 358
 	int found;
359 359
 
360
-	ps= ev->params;
360
+	ps= ev->params.list;
361 361
 
362 362
 	while(ps)
363 363
 	{
364
-		p= searched_ev->params;
364
+		p= searched_ev->params.list;
365 365
 		found= 0;
366 366
 	
367 367
 		while(p)
... ...
@@ -598,7 +598,7 @@ int update_phtable(presentity_t* presentity, str pres_uri, str body)
598 598
 	
599 599
 	lock_get(&pres_htable[hash_code].lock);
600 600
 
601
-	p= search_phtable(&pres_uri, presentity->event->evp->parsed, hash_code);
601
+	p= search_phtable(&pres_uri, presentity->event->evp->type, hash_code);
602 602
 	if(p== NULL)
603 603
 	{
604 604
 		lock_release(&pres_htable[hash_code].lock);
... ...
@@ -638,7 +638,7 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag,
638 638
 
639 639
 	/* search in hash table if any record exists */
640 640
 	hash_code= core_hash(&pres_uri, NULL, phtable_size);
641
-	if(search_phtable(&pres_uri, event->evp->parsed, hash_code)== NULL)
641
+	if(search_phtable(&pres_uri, event->evp->type, hash_code)== NULL)
642 642
 	{
643 643
 		LM_DBG("No record exists in hash_table\n");
644 644
 		if(fallback2db)
... ...
@@ -726,8 +726,7 @@ db_query:
726 726
 			
727 727
 			/* if event BLA - check if sender is the same as contact */
728 728
 			/* if so, send an empty dialog info document */
729
-			if( event->evp->parsed == EVENT_DIALOG_SLA && contact )
730
-			{
729
+			if( EVENT_DIALOG_SLA(event->evp) && contact ) {
731 730
 				sender.s = (char*)row_vals[sender_col].val.string_val;
732 731
 				if(sender.s== NULL || strlen(sender.s)==0)
733 732
 					goto after_sender_check;
... ...
@@ -340,7 +340,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
340 340
 	{
341 341
 		/* insert new record in hash_table */
342 342
 	
343
-		if(insert_phtable(&pres_uri, presentity->event->evp->parsed, sphere)< 0)
343
+		if(insert_phtable(&pres_uri, presentity->event->evp->type, sphere)< 0)
344 344
 		{
345 345
 			LM_ERR("inserting record in hash table\n");
346 346
 			goto error;
... ...
@@ -417,7 +417,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
417 417
 		if (result->n > 0)
418 418
 		{
419 419
 
420
-			if(presentity->event->evp->parsed == EVENT_DIALOG_SLA)
420
+			if(EVENT_DIALOG_SLA(presentity->event->evp))
421 421
 			{
422 422
 				/* analize if previous body has a dialog */
423 423
 				row = &result->rows[0];
... ...
@@ -489,7 +489,7 @@ after_dialog_check:
489 489
 
490 490
 				/* delete from hash table */
491 491
 	
492
-				if(delete_phtable(&pres_uri, presentity->event->evp->parsed)< 0)
492
+				if(delete_phtable(&pres_uri, presentity->event->evp->type)< 0)
493 493
 				{
494 494
 					LM_ERR("deleting record from hash table\n");
495 495
 					goto error;
... ...
@@ -500,7 +500,7 @@ after_dialog_check:
500 500
 			n_update_cols= 0;
501 501
 			/* if event dialog and is_dialog -> if sender not the same as
502 502
 			 * old sender do not overwrite */
503
-			if( (presentity->event->evp->parsed == EVENT_DIALOG_SLA) &&  bla_update_publish==0)
503
+			if( EVENT_DIALOG_SLA(presentity->event->evp) &&  bla_update_publish==0)
504 504
 			{
505 505
 				LM_DBG("drop Publish for BLA from a different sender that"
506 506
 						" wants to overwrite an existing dialog\n");
... ...
@@ -582,7 +582,7 @@ after_dialog_check:
582 582
 
583 583
 				/* updated stored sphere */
584 584
 				if(sphere_enable && 
585
-						presentity->event->evp->parsed== EVENT_PRESENCE)
585
+						presentity->event->evp->type== EVENT_PRESENCE)
586 586
 				{
587 587
 					if(update_phtable(presentity, pres_uri, *body)< 0)
588 588
 					{
... ...
@@ -742,11 +742,11 @@ int pres_htable_restore(void)
742 742
 		if(event_parser(ev_str.s, ev_str.len, &ev)< 0)
743 743
 		{
744 744
 			LM_ERR("parsing event\n");
745
-			free_event_params(ev.params, PKG_MEM_TYPE);
745
+			free_event_params(ev.params.list, PKG_MEM_TYPE);
746 746
 			goto error;
747 747
 		}
748
-		event= ev.parsed;
749
-		free_event_params(ev.params, PKG_MEM_TYPE);
748
+		event= ev.type;
749
+		free_event_params(ev.params.list, PKG_MEM_TYPE);
750 750
 
751 751
 		if(uandd_to_uri(user, domain, &uri)< 0)
752 752
 		{
... ...
@@ -177,7 +177,7 @@ void msg_presentity_clean(unsigned int ticks,void *param)
177 177
 		if(pres->event== NULL)
178 178
 		{
179 179
 			LM_ERR("event not found\n");
180
-			free_event_params(ev.params, PKG_MEM_TYPE);
180
+			free_event_params(ev.params.list, PKG_MEM_TYPE);
181 181
 			goto error;
182 182
 		}	
183 183
 	
... ...
@@ -185,18 +185,18 @@ void msg_presentity_clean(unsigned int ticks,void *param)
185 185
 		if(uandd_to_uri(user, domain, &p[i].uri)< 0)
186 186
 		{
187 187
 			LM_ERR("constructing uri\n");
188
-			free_event_params(ev.params, PKG_MEM_TYPE);
188
+			free_event_params(ev.params.list, PKG_MEM_TYPE);
189 189
 			goto error;
190 190
 		}
191 191
 		
192 192
 		/* delete from hash table */
193
-		if(delete_phtable(&p[i].uri, ev.parsed)< 0)
193
+		if(delete_phtable(&p[i].uri, ev.type)< 0)
194 194
 		{
195 195
 			LM_ERR("deleting from pres hash table\n");
196
-			free_event_params(ev.params, PKG_MEM_TYPE);
196
+			free_event_params(ev.params.list, PKG_MEM_TYPE);
197 197
 			goto error;
198 198
 		}
199
-		free_event_params(ev.params, PKG_MEM_TYPE);
199
+		free_event_params(ev.params.list, PKG_MEM_TYPE);
200 200
 
201 201
 	}
202 202
 	pa_dbf.free_result(pa_db, result);
... ...
@@ -325,7 +325,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
325 325
 			reply_str= pu_400a_rpl;
326 326
 			goto error;
327 327
 		}
328
-		if(((event_t*)msg->event->parsed)->parsed == EVENT_OTHER)
328
+		if(((event_t*)msg->event->parsed)->type == EVENT_OTHER)
329 329
 		{	
330 330
 			goto unsupported_event;
331 331
 		}
... ...
@@ -334,7 +334,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
334 334
 		goto unsupported_event;
335 335
 
336 336
 	/* search event in the list */
337
-	event= search_event((event_t*)msg->event->parsed);
337
+	event= search_event((event_t*)msg->event->type);
338 338
 	if(event== NULL)
339 339
 	{
340 340
 		goto unsupported_event;
... ...
@@ -441,7 +441,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
441 441
 		}
442 442
 		body.len= get_content_length( msg );
443 443
 
444
-		if(sphere_enable && event->evp->parsed == EVENT_PRESENCE &&
444
+		if(sphere_enable && event->evp->type == EVENT_PRESENCE &&
445 445
 				get_content_type(msg)== SUBTYPE_PIDFXML)
446 446
 		{
447 447
 			sphere= extract_sphere(body);			
... ...
@@ -541,7 +541,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
541 541
 			reply_str= pu_400_rpl;
542 542
 			goto error;
543 543
 		}
544
-		if(((event_t*)msg->event->parsed)->parsed == EVENT_OTHER)
544
+		if(((event_t*)msg->event->parsed)->type == EVENT_OTHER)
545 545
 		{	
546 546
 			goto bad_event;
547 547
 		}
... ...
@@ -559,7 +559,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
559 559
 	subs.event= event;
560 560
 	
561 561
 	/* extract the id if any*/
562
-	ev_param= parsed_event->params;
562
+	ev_param= parsed_event->params.list;
563 563
 	while(ev_param)
564 564
 	{
565 565
 		if(ev_param->name.len== 2 && strncmp(ev_param->name.s, "id", 2)== 0)
... ...
@@ -580,7 +580,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
580 580
 	/* getting presentity uri from Request-URI if initial subscribe - or else from database*/
581 581
 	if(to_tag_gen)
582 582
 	{
583
-		if(parsed_event->parsed!= EVENT_DIALOG_SLA)
583
+		if (!EVENT_DIALOG_SLA(parsed_event))
584 584
 		{
585 585
 			if( parse_sip_msg_uri(msg)< 0)
586 586
 			{
... ...
@@ -711,8 +711,8 @@ bad_event:
711 711
 
712 712
 	LM_ERR("Missing or unsupported event header field value\n");
713 713
 		
714
-	if(parsed_event && parsed_event->text.s)
715
-		LM_ERR("\tevent= %.*s\n",parsed_event->text.len,parsed_event->text.s);
714
+	if(parsed_event && parsed_event->name.s)
715
+		LM_ERR("\tevent= %.*s\n",parsed_event->name.len,parsed_event->name.s);
716 716
 	
717 717
 	reply_code= BAD_EVENT_CODE;
718 718
 	reply_str= pu_489_rpl;
... ...
@@ -918,7 +918,7 @@ int extract_sdialog_info(subs_t* subs,struct sip_msg* msg, int mexp,
918 918
 	LM_DBG("subs->contact= %.*s - len = %d\n",subs->contact.len,
919 919
 			subs->contact.s, subs->contact.len);	
920 920
 
921
-    if(subs->event->evp->parsed== EVENT_DIALOG_SLA)
921
+	if (EVENT_DIALOG_SLA(subs->event->evp))
922 922
     {
923 923
         /* user_contact@from_domain */
924 924
         if(parse_uri(subs->contact.s, subs->contact.len, &uri)< 0)
... ...
@@ -1027,7 +1027,7 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* reply_code,
1027 1027
 	{
1028 1028
 		lock_get(&subs_htable[i].lock);
1029 1029
 		s= search_shtable(subs_htable, subs->callid,subs->to_tag,subs->from_tag, i);
1030
-		if(s && s->event->evp->parsed!= EVENT_DIALOG_SLA)
1030
+		if (s && !EVENT_DIALOG_SLA(s->event->evp))
1031 1031
 		{
1032 1032
 			pres_uri.s= (char*)pkg_malloc(s->pres_uri.len* sizeof(char));
1033 1033
 			if(pres_uri.s== NULL)
... ...
@@ -1059,7 +1059,7 @@ found_rec:
1059 1059
 	
1060 1060
 	LM_DBG("Record found in hash_table\n");
1061 1061
 	
1062
-	if(s->event->evp->parsed!= EVENT_DIALOG_SLA)
1062
+	if(!EVENT_DIALOG_SLA(s->event->evp))
1063 1063
 		subs->pres_uri= pres_uri;
1064 1064
 	
1065 1065
 	subs->version = s->version;
... ...
@@ -1260,7 +1260,7 @@ int get_database_info(struct sip_msg* msg, subs_t* subs, int* reply_code, str* r
1260 1260
 	subs->local_cseq= row_vals[local_cseq_col].val.int_val;
1261 1261
 	subs->version= row_vals[version_col].val.int_val;
1262 1262
 
1263
-	if(subs->event->evp->parsed!= EVENT_DIALOG_SLA)
1263
+	if(!EVENT_DIALOG_SLA(subs->event->evp))
1264 1264
 	{
1265 1265
 		pres_uri.s= (char*)row_vals[pres_uri_col].val.string_val;
1266 1266
 		pres_uri.len= strlen(pres_uri.s);
... ...
@@ -1739,14 +1739,14 @@ int restore_db_subs(void)
1739 1739
 			event= (pres_ev_t*)shm_malloc(sizeof(pres_ev_t));
1740 1740
 			if(event== NULL)
1741 1741
 			{
1742
-				free_event_params(parsed_event.params, PKG_MEM_TYPE);
1742
+				free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
1743 1743
 				ERR_MEM(SHM_MEM_STR);
1744 1744
 			}
1745 1745
 			memset(event, 0, sizeof(pres_ev_t));
1746 1746
 			event->name.s= (char*)shm_malloc(ev_sname.len* sizeof(char));
1747 1747
 			if(event->name.s== NULL)
1748 1748
 			{
1749
-				free_event_params(parsed_event.params, PKG_MEM_TYPE);
1749
+				free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
1750 1750
 				ERR_MEM(SHM_MEM_STR);
1751 1751
 			}
1752 1752
 			memcpy(event->name.s,ev_sname.s, ev_sname.len);
... ...
@@ -1756,14 +1756,14 @@ int restore_db_subs(void)
1756 1756
 			if(event->evp== NULL)
1757 1757
 			{
1758 1758
 				LM_ERR("ERROR copying event_t structure\n");
1759
-				free_event_params(parsed_event.params, PKG_MEM_TYPE);
1759
+				free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
1760 1760
 				goto error;
1761 1761
 			}
1762 1762
 			event->next= EvList->events;
1763 1763
 			EvList->events= event;
1764 1764
 		}
1765 1765
 			
1766
-		free_event_params(parsed_event.params, PKG_MEM_TYPE);
1766
+		free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
1767 1767
 
1768 1768
 		s.event= event;
1769 1769
 
... ...
@@ -43,10 +43,16 @@
43 43
 #include "../../dprint.h"
44 44
 #include "../../str.h"
45 45
 #include "../../parser/msg_parser.h"
46
+#include "../../parser/parse_event.h"
46 47
 
47 48
 #define LCONTACT_BUF_SIZE 1024
48 49
 #define BAD_EVENT_CODE 489
49 50
 
51
+
52
+#define EVENT_DIALOG_SLA(ev) \
53
+	((ev)->type == EVENT_DIALOG && (ev)->params.dialog.sla)
54
+
55
+
50 56
 static inline int uandd_to_uri(str user,  str domain, str *out)
51 57
 {
52 58
 	int size;