Browse code

- added via_param list to via_body

Andrei Pelinescu-Onciul authored on 26/11/2001 19:13:23
Showing 3 changed files
... ...
@@ -28,7 +28,7 @@ NAME=ser
28 28
 # DEBUG compiles in some extra debugging code
29 29
 # OLD_PARSER uses the old and stable parser (from ser 8.3.2)
30 30
 # DNS_IP_HACK faster ip address resolver for ip strings (e.g "127.0.0.1")
31
-DEFS=-DNOCR -DMACROEATER -DDNS_IP_HACK -DPKG_MALLOC -DNO_DEBUG#-DSTATS -DNO_DEBUG 
31
+DEFS=-DNOCR -DMACROEATER -DDNS_IP_HACK -DPKG_MALLOC #-DNO_DEBUG#-DSTATS -DNO_DEBUG 
32 32
 #-DNO_LOG
33 33
 
34 34
 PROFILE=  # -pg #set this if you want profiling
... ...
@@ -29,6 +29,16 @@
29 29
 #define HDR_ROUTE        256
30 30
 #define HDR_OTHER       65536 /*unknown header type*/
31 31
 
32
+/* via param types
33
+ * WARNING: keep in sync w/ FIN_*, GEN_PARAM and PARAM_ERROR from via_parse.c*/
34
+enum{
35
+		PARAM_HIDDEN=230, PARAM_TTL, PARAM_BRANCH, PARAM_MADDR, PARAM_RECEIVED,
36
+		GEN_PARAM,
37
+		PARAM_ERROR
38
+};
39
+
40
+
41
+
32 42
 #define INVITE_LEN	6
33 43
 #define ACK_LEN		3
34 44
 #define CANCEL_LEN	6
... ...
@@ -81,6 +91,16 @@ struct hdr_field{   /* format: name':' body */
81 91
 	struct hdr_field* next;
82 92
 };
83 93
 
94
+
95
+
96
+struct via_param{
97
+	int type;
98
+	str name;
99
+	str value;
100
+	int size; /* total size*/
101
+	struct via_param* next;
102
+};
103
+
84 104
 struct via_body{  /* format: name/version/transport host:port;params comment */
85 105
 	int error;
86 106
 	str hdr;   /* contains "Via" or "v" */
... ...
@@ -92,6 +112,8 @@ struct via_body{  /* format: name/version/transport host:port;params comment */
92 112
 	str port_str;
93 113
 	str params;
94 114
 	str comment;
115
+	struct via_param* param_lst; /* list of parameters*/
116
+	struct via_param* last_param; /*last via parameter, internal use*/
95 117
 	int bsize;    /* body size, not including hdr */
96 118
 	struct via_body* next; /* pointer to next via body string if
97 119
 							  compact via or null */
... ...
@@ -99,6 +121,8 @@ struct via_body{  /* format: name/version/transport host:port;params comment */
99 121
 
100 122
 
101 123
 
124
+
125
+
102 126
 struct cseq_body{
103 127
 	int error;
104 128
 	str number;
... ...
@@ -47,7 +47,9 @@ enum{	         F_SIP=100,
47 47
 		L_PROTO, F_PROTO, P_PROTO
48 48
 	};
49 49
 
50
-/* param realated states */
50
+/* param related states
51
+ * WARNING: keep the FIN*, GEN_PARAM & PARAM_ERROR in sync w/ PARAM_* from
52
+ * msg_parser.h !*/
51 53
 enum{	L_VALUE=200,   F_VALUE, P_VALUE, P_STRING,
52 54
 		HIDDEN1,   HIDDEN2,   HIDDEN3,   HIDDEN4,   HIDDEN5,
53 55
 		TTL1,      TTL2,
... ...
@@ -56,8 +58,9 @@ enum{	L_VALUE=200,   F_VALUE, P_VALUE, P_STRING,
56 58
 		RECEIVED1, RECEIVED2, RECEIVED3, RECEIVED4, RECEIVED5, RECEIVED6,
57 59
 		RECEIVED7,
58 60
 		/* fin states (227-...)*/
59
-		FIN_HIDDEN, FIN_TTL, FIN_BRANCH, FIN_MADDR, FIN_RECEIVED,
60
-		GEN_PARAM
61
+		FIN_HIDDEN=230, FIN_TTL, FIN_BRANCH, FIN_MADDR, FIN_RECEIVED,
62
+		/*GEN_PARAM,
63
+		PARAM_ERROR*/ /* declared in msg_parser.h*/
61 64
 	};
62 65
 
63 66
 
... ...
@@ -67,19 +70,15 @@ enum{	L_VALUE=200,   F_VALUE, P_VALUE, P_STRING,
67 70
  * output state = L_PARAM or F_PARAM or END_OF_HEADER 
68 71
  * (and saved_state= last state); everything else => error */
69 72
 __inline char* parse_via_param(	char* p, char* end, int* pstate, 
70
-								int* psaved_state)
73
+								int* psaved_state, struct via_param* param)
71 74
 {
72 75
 	char* tmp;
73 76
 	register int state;
74 77
 	int saved_state;
75
-	int param_type;
76
-	char* param_name;
77
-	char* param_value;
78 78
 	
79 79
 	state=*pstate;
80 80
 	saved_state=*psaved_state;
81
-	param_name=param_value=0;
82
-	param_type=0;
81
+	param->type=PARAM_ERROR;
83 82
 	
84 83
 	for (tmp=p;tmp<end;tmp++){
85 84
 		switch(*tmp){
... ...
@@ -88,7 +87,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
88 87
 				switch(state){
89 88
 					case FIN_HIDDEN:
90 89
 						*tmp=0;
91
-						param_type=state;
90
+						param->type=state;
91
+						param->name.len=tmp-param->name.s;
92 92
 						state=L_PARAM;
93 93
 						goto endofparam;
94 94
 					case FIN_BRANCH:
... ...
@@ -96,7 +96,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
96 96
 					case FIN_MADDR:
97 97
 					case FIN_RECEIVED:
98 98
 						*tmp=0;
99
-						param_type=state;
99
+						param->type=state;
100
+						param->name.len=tmp-param->name.s;
100 101
 						state=L_VALUE;
101 102
 						goto find_value;
102 103
 					case F_PARAM:
... ...
@@ -109,7 +110,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
109 110
 					case GEN_PARAM:
110 111
 					default:
111 112
 						*tmp=0;
112
-						param_type=GEN_PARAM;
113
+						param->type=GEN_PARAM;
114
+						param->name.len=tmp-param->name.s;
113 115
 						state=L_VALUE;
114 116
 						goto find_value;
115 117
 				}
... ...
@@ -119,7 +121,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
119 121
 				switch(state){
120 122
 					case FIN_HIDDEN:
121 123
 						*tmp=0;
122
-						param_type=state;
124
+						param->type=state;
125
+						param->name.len=tmp-param->name.s;
123 126
 						saved_state=L_PARAM;
124 127
 						state=F_LF;
125 128
 						goto endofparam;
... ...
@@ -128,7 +131,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
128 131
 					case FIN_MADDR:
129 132
 					case FIN_RECEIVED:
130 133
 						*tmp=0;
131
-						param_type=state;
134
+						param->type=state;
135
+						param->name.len=tmp-param->name.s;
132 136
 						saved_state=L_VALUE;
133 137
 						state=F_LF;
134 138
 						goto find_value;
... ...
@@ -146,8 +150,9 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
146 150
 					case GEN_PARAM:
147 151
 					default:
148 152
 						*tmp=0;
149
-						param_type=GEN_PARAM;
153
+						param->type=GEN_PARAM;
150 154
 						saved_state=L_VALUE;
155
+						param->name.len=tmp-param->name.s;
151 156
 						state=F_LF;
152 157
 						goto find_value;
153 158
 				}
... ...
@@ -156,7 +161,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
156 161
 				switch(state){
157 162
 					case FIN_HIDDEN:
158 163
 						*tmp=0;
159
-						param_type=state;
164
+						param->type=state;
165
+						param->name.len=tmp-param->name.s;
160 166
 						saved_state=L_PARAM;
161 167
 						state=F_CR;
162 168
 						goto endofparam;
... ...
@@ -165,7 +171,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
165 171
 					case FIN_MADDR:
166 172
 					case FIN_RECEIVED:
167 173
 						*tmp=0;
168
-						param_type=state;
174
+						param->type=state;
175
+						param->name.len=tmp-param->name.s;
169 176
 						saved_state=L_VALUE;
170 177
 						state=F_CR;
171 178
 						goto find_value;
... ...
@@ -180,7 +187,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
180 187
 					case GEN_PARAM:
181 188
 					default:
182 189
 						*tmp=0;
183
-						param_type=GEN_PARAM;
190
+						param->type=GEN_PARAM;
191
+						param->name.len=tmp-param->name.s;
184 192
 						saved_state=L_VALUE;
185 193
 						state=F_CR;
186 194
 						goto find_value;
... ...
@@ -194,7 +202,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
194 202
 					case FIN_MADDR:
195 203
 					case FIN_RECEIVED:
196 204
 						*tmp=0;
197
-						param_type=state;
205
+						param->type=state;
206
+						param->name.len=tmp-param->name.s;
198 207
 						state=F_VALUE;
199 208
 						goto find_value;
200 209
 					case F_PARAM:
... ...
@@ -210,7 +219,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
210 219
 					case GEN_PARAM:
211 220
 					default:
212 221
 						*tmp=0;
213
-						param_type=GEN_PARAM;
222
+						param->type=GEN_PARAM;
223
+						param->name.len=tmp-param->name.s;
214 224
 						state=F_VALUE;
215 225
 						goto find_value;
216 226
 				}
... ...
@@ -219,7 +229,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
219 229
 				switch(state){
220 230
 					case FIN_HIDDEN:
221 231
 						*tmp=0;
222
-						param_type=state;
232
+						param->type=state;
233
+						param->name.len=tmp-param->name.s;
223 234
 						state=F_PARAM;
224 235
 						goto endofparam;
225 236
 					case FIN_BRANCH:
... ...
@@ -237,7 +248,8 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
237 248
 					case GEN_PARAM:
238 249
 					default:
239 250
 						*tmp=0;
240
-						param_type=GEN_PARAM;
251
+						param->type=GEN_PARAM;
252
+						param->name.len=tmp-param->name.s;
241 253
 						state=F_PARAM;
242 254
 						goto endofparam;
243 255
 				}
... ...
@@ -249,7 +261,7 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
249 261
 				switch(state){
250 262
 					case F_PARAM:
251 263
 						state=HIDDEN1;
252
-						param_name=tmp;
264
+						param->name.s=tmp;
253 265
 						break;
254 266
 					case GEN_PARAM:
255 267
 						break;
... ...
@@ -265,6 +277,10 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
265 277
 			case 'i':
266 278
 			case 'I':
267 279
 				switch(state){
280
+					case F_PARAM:
281
+						state=GEN_PARAM;
282
+						param->name.s=tmp;
283
+						break;
268 284
 					case HIDDEN1:
269 285
 						state=HIDDEN2;
270 286
 						break;
... ...
@@ -285,6 +301,10 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
285 301
 			case 'd':
286 302
 			case 'D':
287 303
 				switch(state){
304
+					case F_PARAM:
305
+						state=GEN_PARAM;
306
+						param->name.s=tmp;
307
+						break;
288 308
 					case HIDDEN2:
289 309
 						state=HIDDEN3;
290 310
 						break;
... ...
@@ -314,6 +334,10 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
314 334
 			case 'e':
315 335
 			case 'E':
316 336
 				switch(state){
337
+					case F_PARAM:
338
+						state=GEN_PARAM;
339
+						param->name.s=tmp;
340
+						break;
317 341
 					case HIDDEN4:
318 342
 						state=HIDDEN5;
319 343
 						break;
... ...
@@ -340,6 +364,10 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
340 364
 			case 'n':
341 365
 			case 'N':
342 366
 				switch(state){
367
+					case F_PARAM:
368
+						state=GEN_PARAM;
369
+						param->name.s=tmp;
370
+						break;
343 371
 					case HIDDEN5:
344 372
 						state=FIN_HIDDEN;
345 373
 						break;
... ...
@@ -362,7 +390,7 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
362 390
 				switch(state){
363 391
 					case F_PARAM:
364 392
 						state=TTL1;
365
-						param_name=tmp;
393
+						param->name.s=tmp;
366 394
 						break;
367 395
 					case TTL1:
368 396
 						state=TTL2;
... ...
@@ -381,6 +409,10 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
381 409
 			case 'l':
382 410
 			case 'L':
383 411
 				switch(state){
412
+					case F_PARAM:
413
+						state=GEN_PARAM;
414
+						param->name.s=tmp;
415
+						break;
384 416
 					case TTL2:
385 417
 						state=FIN_TTL;
386 418
 						break;
... ...
@@ -400,7 +432,7 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
400 432
 				switch(state){
401 433
 					case F_PARAM:
402 434
 						state=MADDR1;
403
-						param_name=tmp;
435
+						param->name.s=tmp;
404 436
 						break;
405 437
 					case GEN_PARAM:
406 438
 						break;
... ...
@@ -416,6 +448,10 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
416 448
 			case 'a':
417 449
 			case 'A':
418 450
 				switch(state){
451
+					case F_PARAM:
452
+						state=GEN_PARAM;
453
+						param->name.s=tmp;
454
+						break;
419 455
 					case MADDR1:
420 456
 						state=MADDR2;
421 457
 						break;
... ...
@@ -441,7 +477,7 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
441 477
 						break;
442 478
 					case F_PARAM:
443 479
 						state=RECEIVED1;
444
-						param_name=tmp;
480
+						param->name.s=tmp;
445 481
 						break;
446 482
 					case BRANCH1:
447 483
 						state=BRANCH2;
... ...
@@ -460,6 +496,10 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
460 496
 			case 'c':
461 497
 			case 'C':
462 498
 				switch(state){
499
+					case F_PARAM:
500
+						state=GEN_PARAM;
501
+						param->name.s=tmp;
502
+						break;
463 503
 					case RECEIVED2:
464 504
 						state=RECEIVED3;
465 505
 						break;
... ...
@@ -480,6 +520,10 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
480 520
 			case 'v':
481 521
 			case 'V':
482 522
 				switch(state){
523
+					case F_PARAM:
524
+						state=GEN_PARAM;
525
+						param->name.s=tmp;
526
+						break;
483 527
 					case RECEIVED5:
484 528
 						state=RECEIVED6;
485 529
 						break;
... ...
@@ -499,7 +543,7 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
499 543
 				switch(state){
500 544
 					case F_PARAM:
501 545
 						state=BRANCH1;
502
-						param_name=tmp;
546
+						param->name.s=tmp;
503 547
 						break;
504 548
 					case GEN_PARAM:
505 549
 						break;
... ...
@@ -517,7 +561,7 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
517 561
 				switch(state){
518 562
 					case F_PARAM:
519 563
 						state=GEN_PARAM;
520
-						param_name=tmp;
564
+						param->name.s=tmp;
521 565
 						break;
522 566
 					case  GEN_PARAM:
523 567
 						break;
... ...
@@ -532,11 +576,10 @@ __inline char* parse_via_param(	char* p, char* end, int* pstate,
532 576
 		}
533 577
 	}/* for tmp*/
534 578
 
535
-/* end of packet?*/
579
+/* end of packet? => error, no cr/lf,',' found!!!*/
536 580
 saved_state=state;
537
-param_type=state;
538 581
 state=END_OF_HEADER;
539
-goto end_via;
582
+goto error;
540 583
 
541 584
 find_value:
542 585
 	tmp++;
... ...
@@ -551,6 +594,7 @@ find_value:
551 594
 					case P_VALUE:
552 595
 						*tmp=0;
553 596
 						state=L_PARAM;
597
+						param->value.len=tmp-param->value.s;
554 598
 						goto endofvalue;
555 599
 					case P_STRING:
556 600
 						break;
... ...
@@ -577,6 +621,7 @@ find_value:
577 621
 						*tmp=0;
578 622
 						saved_state=L_PARAM;
579 623
 						state=F_LF;
624
+						param->value.len=tmp-param->value.s;
580 625
 						goto endofvalue;
581 626
 					case F_LF:
582 627
 					case F_CRLF:
... ...
@@ -601,6 +646,7 @@ find_value:
601 646
 						break; 
602 647
 					case P_VALUE:
603 648
 						*tmp=0;
649
+						param->value.len=tmp-param->value.s;
604 650
 						saved_state=L_PARAM;
605 651
 						state=F_CR;
606 652
 						goto endofvalue;
... ...
@@ -638,6 +684,7 @@ find_value:
638 684
 				switch(state){
639 685
 					case P_VALUE:
640 686
 						*tmp=0;
687
+						param->value.len=tmp-param->value.s;
641 688
 						state=F_PARAM;
642 689
 						goto endofvalue;
643 690
 					case P_STRING:
... ...
@@ -658,11 +705,12 @@ find_value:
658 705
 				switch(state){
659 706
 					case F_VALUE:
660 707
 						state=P_STRING;
661
-						param_value=tmp+1;
708
+						param->value.s=tmp+1;
662 709
 						break;
663 710
 					case P_STRING:
664 711
 						*tmp=0;
665 712
 						state=L_PARAM;
713
+						param->value.len=tmp-param->value.s;
666 714
 						goto endofvalue;
667 715
 					case F_LF:
668 716
 					case F_CR:
... ...
@@ -679,7 +727,7 @@ find_value:
679 727
 				switch(state){
680 728
 					case F_VALUE:
681 729
 						state=P_VALUE;
682
-						param_value=tmp;
730
+						param->value.s=tmp;
683 731
 						break;
684 732
 					case P_VALUE:
685 733
 					case P_STRING:
... ...
@@ -697,34 +745,39 @@ find_value:
697 745
 		}
698 746
 	} /* for2 tmp*/
699 747
 
700
-	/* if generic_param => it can have no value */
701
-	if ((state==L_VALUE)&&(param_type==GEN_PARAM)) state=L_PARAM;
702
-	saved_state=state;
703
-	state=END_OF_HEADER;
704
-	goto end_via;
748
+	/* end of buff and no CR/LF =>error*/
749
+saved_state=state;
750
+state=END_OF_HEADER;
751
+goto error;
705 752
 
706 753
 endofparam:
707 754
 endofvalue:
708
-
709
-end_via:
755
+	param->size=tmp-p;
710 756
 	*pstate=state;
711 757
 	*psaved_state=saved_state;
712
-	DBG("Found param type %d, <%s> = <%s>\n", param_type, param_name,
713
-			param_value);
758
+	DBG("Found param type %d, <%s> = <%s>; state=%d\n", param->type, 
759
+			param->name, param->value, state);
714 760
 	return tmp;
715
-
716
-error:
717
-	LOG(L_ERR, "error: via_parse_param\n");
761
+	
762
+end_via:
763
+	/* if we are here we found an "unexpected" end of via
764
+	 *  (cr/lf). This is valid only if the param type is GEN_PARAM*/
765
+	if (param->type==GEN_PARAM) goto endofparam;
718 766
 	*pstate=state;
719 767
 	*psaved_state=saved_state;
768
+	DBG("Error on  param type %d, <%s>, state=%d, saved_state=%d\n", 
769
+		param->type, param->name.s, state, saved_state);
770
+
771
+error:
772
+	LOG(L_ERR, "error: parse_via_param\n");
773
+	param->type=PARAM_ERROR;
774
+	*pstate=PARAM_ERROR;
775
+	*psaved_state=state;
720 776
 	return tmp;
721 777
 }
722 778
 
723 779
 
724 780
 
725
-
726
-
727
-
728 781
 char* parse_via(char* buffer, char* end, struct via_body *vb)
729 782
 {
730 783
 
... ...
@@ -736,6 +789,7 @@ char* parse_via(char* buffer, char* end, struct via_body *vb)
736 789
 	int err;
737 790
 
738 791
 	char* tmp_param;
792
+	struct via_param* param;
739 793
 
740 794
 
741 795
 parse_again:
... ...
@@ -1505,7 +1559,20 @@ main_via:
1505 1559
 					case F_PARAM:
1506 1560
 						/*state=P_PARAM*/;
1507 1561
 						if(vb->params.s==0) vb->params.s=tmp;
1508
-						tmp=parse_via_param(tmp, end, &state, &saved_state);
1562
+						param=pkg_malloc(sizeof(struct via_param));
1563
+						if (param==0){
1564
+							LOG(L_ERR, "ERROR:parse_via: mem. allocation"
1565
+									" error\n");
1566
+							goto error;
1567
+						}
1568
+						memset(param,0, sizeof(struct via_param));
1569
+						tmp=parse_via_param(tmp, end, &state, &saved_state,
1570
+											param);
1571
+						/*add param to the list*/
1572
+						if (vb->last_param)	vb->last_param->next=param;
1573
+						else				vb->param_lst=param;
1574
+						vb->last_param=param;
1575
+						
1509 1576
 						switch(state){
1510 1577
 							case L_PARAM:
1511 1578
 							case F_PARAM:
... ...
@@ -1520,6 +1587,8 @@ main_via:
1520 1587
 								vb->params.len=tmp-vb->params.s;
1521 1588
 								state=saved_state;
1522 1589
 								goto endofheader;
1590
+							case PARAM_ERROR:
1591
+								goto error;
1523 1592
 							default:
1524 1593
 								LOG(L_ERR, "ERROR: parse_via after"
1525 1594
 										" parse_via_param: invalid"