Browse code

*** empty log message ***

Andrei Pelinescu-Onciul authored on 23/11/2001 09:15:13
Showing 9 changed files
... ...
@@ -41,5 +41,8 @@
41 41
 #define RECEIVED ";received="
42 42
 #define RECEIVED_LEN 10
43 43
 
44
+/*used only if PKG_MALLOC is defined*/
45
+#define PKG_MEM_POOL_SIZE 1024*1024
46
+
44 47
 
45 48
 #endif
... ...
@@ -23,7 +23,7 @@ struct lump* append_new_lump(struct lump** list, char* new_hdr,
23 23
 	
24 24
 	for (t=list;*t;t=&((*t)->next));
25 25
 
26
-	tmp=malloc(sizeof(struct lump));
26
+	tmp=pkg_malloc(sizeof(struct lump));
27 27
 	if (tmp==0){
28 28
 		LOG(L_ERR, "ERROR: append_new_lump: out of memory\n");
29 29
 		return 0;
... ...
@@ -47,7 +47,7 @@ struct lump* insert_new_lump(struct lump** list, char* new_hdr,
47 47
 {
48 48
 	struct lump* tmp;
49 49
 
50
-	tmp=malloc(sizeof(struct lump));
50
+	tmp=pkg_malloc(sizeof(struct lump));
51 51
 	if (tmp==0){
52 52
 		LOG(L_ERR, "ERROR: insert_new_lump: out of memory\n");
53 53
 		return 0;
... ...
@@ -71,7 +71,7 @@ struct lump* insert_new_lump_after( struct lump* after, char* new_hdr,
71 71
 {
72 72
 	struct lump* tmp;
73 73
 
74
-	tmp=malloc(sizeof(struct lump));
74
+	tmp=pkg_malloc(sizeof(struct lump));
75 75
 	if (tmp==0){
76 76
 		LOG(L_ERR, "ERROR: insert_new_lump_after: out of memory\n");
77 77
 		return 0;
... ...
@@ -95,7 +95,7 @@ struct lump* insert_new_lump_before( struct lump* before, char* new_hdr,
95 95
 {
96 96
 	struct lump* tmp;
97 97
 
98
-	tmp=malloc(sizeof(struct lump));
98
+	tmp=pkg_malloc(sizeof(struct lump));
99 99
 	if (tmp==0){
100 100
 		LOG(L_ERR,"ERROR: insert_new_lump_before: out of memory\n");
101 101
 		return 0;
... ...
@@ -118,7 +118,7 @@ struct lump* del_lump(struct lump** list, int offset, int len, int type)
118 118
 	struct lump* tmp;
119 119
 	struct lump* prev, *t;
120 120
 
121
-	tmp=malloc(sizeof(struct lump));
121
+	tmp=pkg_malloc(sizeof(struct lump));
122 122
 	if (tmp==0){
123 123
 		LOG(L_ERR, "ERROR: insert_new_lump_before: out of memory\n");
124 124
 		return 0;
... ...
@@ -148,7 +148,7 @@ struct lump* anchor_lump(struct lump** list, int offset, int len, int type)
148 148
 	struct lump* tmp;
149 149
 	struct lump* prev, *t;
150 150
 
151
-	tmp=malloc(sizeof(struct lump));
151
+	tmp=pkg_malloc(sizeof(struct lump));
152 152
 	if (tmp==0){
153 153
 		LOG(L_ERR, "ERROR: insert_new_lump_before: out of memory\n");
154 154
 		return 0;
... ...
@@ -176,7 +176,7 @@ struct lump* anchor_lump(struct lump** list, int offset, int len, int type)
176 176
 void free_lump(struct lump* lmp)
177 177
 {
178 178
 	if (lmp && (lmp->op==LUMP_ADD)){
179
-		if (lmp->u.value) free(lmp->u.value);
179
+		if (lmp->u.value) pkg_free(lmp->u.value);
180 180
 		lmp->u.value=0;
181 181
 		lmp->len=0;
182 182
 	}
... ...
@@ -200,18 +200,18 @@ void free_lump_list(struct lump* l)
200 200
 		r=crt->before;
201 201
 		while(r){
202 202
 			foo=r; r=r->before;
203
-			free_lump(foo);
204
-			free(foo);
203
+			pkg_free_lump(foo);
204
+			pkg_free(foo);
205 205
 		}
206 206
 		r=crt->after;
207 207
 		while(r){
208 208
 			foo=r; r=r->after;
209
-			free_lump(foo);
210
-			free(foo);
209
+			pkg_free_lump(foo);
210
+			pkg_free(foo);
211 211
 		}
212 212
 		
213 213
 		/*clean current elem*/
214
-		free_lump(crt);
215
-		free(crt);
214
+		pkg_free_lump(crt);
215
+		pkg_free(crt);
216 216
 	}
217 217
 }
... ...
@@ -23,6 +23,8 @@
23 23
 #include "route.h"
24 24
 #include "udp_server.h"
25 25
 #include "globals.h"
26
+#include "mem.h"
27
+
26 28
 
27 29
 #include <signal.h>
28 30
 
... ...
@@ -502,11 +504,21 @@ int main(int argc, char** argv)
502 502
 	if (init_stats(  dont_fork ? 1 : children_no  )==-1) goto error;
503 503
 #endif
504 504
 
505
+	
505 506
 	/* init_daemon? */
506 507
 	if (!dont_fork){
507 508
 		if ( daemonize(argv[0]) <0 ) goto error;
508 509
 	}
509
-		
510
+
511
+#ifdef PKG_MALLOC
512
+	/*init mem*/
513
+	mem_block=qm_malloc_init(mem_pool, MEM_POOL_SIZE);
514
+	if (mem_block==0){
515
+		LOG(L_CRIT, "could not initialize memory pool\n");
516
+		goto error;
517
+	}
518
+#endif
519
+
510 520
 	
511 521
 	return main_loop();
512 522
 
... ...
@@ -184,23 +184,7 @@ error1:
184 184
 }
185 185
 
186 186
 
187
-#ifdef OLD_PARSER
188
-/* returns integer field name type */
189
-int field_name(char *s, int l)
190
-{
191
-	if (l<1) return HDR_OTHER;
192
-	else if ((l==1) && ((*s=='v')||(*s=='V')))
193
-		return HDR_VIA;
194
-	else if (strcasecmp(s, "Via")==0)
195
-		return  HDR_VIA;
196
-/*	if ((strcmp(s, "To")==0)||(strcmp(s,"t")==0))
197
-		return HDR_TO;*/
198
-	return HDR_OTHER;
199
-}
200
-#endif
201 187
 
202
-
203
-#ifndef OLD_PARSER
204 188
 /* returns pointer to next header line, and fill hdr_f ;
205 189
  * if at end of header returns pointer to the last crlf  (always buf)*/
206 190
 char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
... ...
@@ -225,7 +209,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
225 225
 	}
226 226
 	switch(hdr->type){
227 227
 		case HDR_VIA:
228
-			vb=malloc(sizeof(struct via_body));
228
+			vb=pkg_malloc(sizeof(struct via_body));
229 229
 			if (vb==0){
230 230
 				LOG(L_ERR, "get_hdr_field: out of memory\n");
231 231
 				goto error;
... ...
@@ -236,7 +220,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
236 236
 			tmp=parse_via(tmp, end, vb);
237 237
 			if (vb->error==VIA_PARSE_ERROR){
238 238
 				LOG(L_ERR, "ERROR: get_hdr_field: bad via\n");
239
-				free(vb);
239
+				pkg_free(vb);
240 240
 				goto error;
241 241
 			}
242 242
 			hdr->parsed=vb;
... ...
@@ -245,7 +229,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
245 245
 			hdr->body.len=tmp-hdr->body.s;
246 246
 			break;
247 247
 		case HDR_CSEQ:
248
-			cseq_b=malloc(sizeof(struct cseq_body));
248
+			cseq_b=pkg_malloc(sizeof(struct cseq_body));
249 249
 			if (cseq_b==0){
250 250
 				LOG(L_ERR, "get_hdr_field: out of memory\n");
251 251
 				goto error;
... ...
@@ -255,7 +239,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
255 255
 			tmp=parse_cseq(tmp, end, cseq_b);
256 256
 			if (cseq_b->error==PARSE_ERROR){
257 257
 				LOG(L_ERR, "ERROR: get_hdr_field: bad cseq\n");
258
-				free(cseq_b);
258
+				pkg_free(cseq_b);
259 259
 				goto error;
260 260
 			}
261 261
 			hdr->parsed=cseq_b;
... ...
@@ -277,13 +261,6 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
277 277
 				match=q_memchr(tmp, '\n', end-tmp);
278 278
 				if (match){
279 279
 					match++;
280
-				#if 0
281
-					/* null terminate*/
282
-					*match=0;
283
-					hdr->body.len=match-tmp;
284
-					match++; /*skip*/
285
-					tmp=match;
286
-				#endif
287 280
 				}else {
288 281
 					tmp=end;
289 282
 					LOG(L_ERR,
... ...
@@ -309,91 +286,6 @@ error:
309 309
 	return tmp;
310 310
 }
311 311
 
312
-#else
313
-/* returns pointer to next header line, and fill hdr_f */
314
-char* get_hdr_field(char *buffer, unsigned int len, struct hdr_field*  hdr_f)
315
-{
316
-	/* grammar (rfc822):
317
-		field = field-name ":" field-body CRLF
318
-		field-body = text [ CRLF SP field-body ]
319
-	   (CRLF in the field body must be removed)
320
-	*/
321
-
322
-	char* tmp, *tmp2;
323
-	char* nl;
324
-	char* body;
325
-	int offset;
326
-	int l;
327
-
328
-	
329
-	/* init content to the empty string */
330
-	hdr_f->name.s="";
331
-	hdr_f->name.len=0;
332
-	hdr_f->body.s="";
333
-	hdr_f->body.len=0;
334
-	
335
-	if ((*buffer=='\n')||(*buffer=='\r')){
336
-		/* double crlf */
337
-		tmp=eat_line(buffer,len);
338
-		hdr_f->type=HDR_EOH;
339
-		return tmp;
340
-	}
341
-#if 0	
342
-	tmp=eat_token2_end(buffer, buffer+len, ':');
343
-	if ((tmp==buffer) || (tmp-buffer==len) ||
344
-		(is_empty_end(buffer, tmp))|| (*tmp!=':')){
345
-		hdr_f->type=HDR_ERROR;
346
-		goto error;
347
-	}
348
-	*tmp=0;
349
-	/* take care of possible spaces (e.g: "Via  :") */
350
-	tmp2=eat_token_end(buffer, tmp);
351
-	/* in the worst case tmp2=buffer+tmp-buffer=tmp */
352
-	*tmp2=0;
353
-	l=tmp2-buffer;
354
-	if (tmp2<tmp){
355
-		tmp2++;
356
-		/* catch things like: "Via foo bar:" */
357
-		tmp2=eat_space_end(tmp2, tmp);
358
-		if (tmp2!=tmp){
359
-			hdr_f->type=HDR_ERROR;
360
-			goto error;
361
-		}
362
-	}
363
-#endif
364
-
365
-	tmp=parse_hname(buffer, buffer+len, hdr_f);
366
-	if (hdr_f->type==HDR_ERROR){
367
-		LOG(L_ERR, "ERROR: get_hdr_field: bad header\n");
368
-		goto error;
369
-	}
370
-	
371
-#if 0
372
-	hdr_f->type=field_name(buffer, l);
373
-	body= ++tmp;
374
-	hdr_f->name.s=buffer;
375
-	hdr_f->name.len=l;
376
-#endif
377
-	offset=tmp-buffer;
378
-	/* get all the lines in this field  body */
379
-	do{
380
-		nl=eat_line(tmp, len-offset);
381
-		offset+=nl-tmp;
382
-		tmp=nl;
383
-	
384
-	}while( (*tmp==' ' ||  *tmp=='\t') && (offset<len) );
385
-	if (offset==len){
386
-		hdr_f->type=HDR_ERROR;
387
-		LOG(L_INFO, "ERROR: get_hdr_field: field body too  long\n");
388
-		goto error;
389
-	}
390
-	*(tmp-1)=0; /* should be an LF */
391
-	hdr_f->body.s=body;
392
-	hdr_f->body.len=tmp-1-body;
393
-error:
394
-	return tmp;
395
-}
396
-#endif
397 312
 
398 313
 
399 314
 char* parse_hostport(char* buf, str* host, short int* port)
... ...
@@ -511,7 +403,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
511 511
 		if (passwd==0){
512 512
 			/* no ':' found => no password */
513 513
 			uri->passwd.s=0;
514
-			uri->user.s=(char*)malloc(next-user+1);
514
+			uri->user.s=(char*)pkg_malloc(next-user+1);
515 515
 			if (uri->user.s==0){
516 516
 				LOG(L_ERR,"ERROR:parse_uri: memory allocation failure\n");
517 517
 				ret=E_OUT_OF_MEM;
... ...
@@ -522,7 +414,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
522 522
 			uri->user.s[next-user]=0; /* null terminate it, 
523 523
 									   usefull for easy printing*/
524 524
 		}else{
525
-			uri->user.s=(char*)malloc(passwd-user+1);
525
+			uri->user.s=(char*)pkg_malloc(passwd-user+1);
526 526
 			if (uri->user.s==0){
527 527
 				LOG(L_ERR,"ERROR:parse_uri: memory allocation failure\n");
528 528
 				ret=E_OUT_OF_MEM;
... ...
@@ -532,7 +424,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
532 532
 			uri->user.len=passwd-user;
533 533
 			uri->user.s[passwd-user]=0;
534 534
 			passwd++; /*skip ':' */
535
-			uri->passwd.s=(char*)malloc(next-passwd+1);
535
+			uri->passwd.s=(char*)pkg_malloc(next-passwd+1);
536 536
 			if (uri->passwd.s==0){
537 537
 				LOG(L_ERR,"ERROR:parse_uri: memory allocation failure\n");
538 538
 				ret=E_OUT_OF_MEM;
... ...
@@ -555,7 +447,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
555 555
 	port=q_memchr(host,':',end-host);
556 556
 	host_len=(port)?port-host:(params)?params-host:(headers)?headers-host:end-host;
557 557
 	/* get host */
558
-	uri->host.s=malloc(host_len+1);
558
+	uri->host.s=pkg_malloc(host_len+1);
559 559
 	if (uri->host.s==0){
560 560
 		LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
561 561
 		ret=E_OUT_OF_MEM;
... ...
@@ -574,7 +466,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
574 574
 			goto error;
575 575
 		}
576 576
 		port_len=(params)?params-port:(headers)?headers-port:end-port;
577
-		uri->port.s=malloc(port_len+1);
577
+		uri->port.s=pkg_malloc(port_len+1);
578 578
 		if (uri->port.s==0){
579 579
 			LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
580 580
 			ret=E_OUT_OF_MEM;
... ...
@@ -594,7 +486,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
594 594
 			goto error;
595 595
 		}
596 596
 		params_len=(headers)?headers-params:end-params;
597
-		uri->params.s=malloc(params_len+1);
597
+		uri->params.s=pkg_malloc(params_len+1);
598 598
 		if (uri->params.s==0){
599 599
 			LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
600 600
 			ret=E_OUT_OF_MEM;
... ...
@@ -608,7 +500,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
608 608
 	if ((headers)&&(headers+1<end)){
609 609
 		headers++;
610 610
 		headers_len=end-headers;
611
-		uri->headers.s=malloc(headers_len+1);
611
+		uri->headers.s=pkg_malloc(headers_len+1);
612 612
 		if(uri->headers.s==0){
613 613
 			LOG(L_ERR, "ERROR: parse_uri: memory allocation error\n");
614 614
 			ret=E_OUT_OF_MEM;
... ...
@@ -791,7 +683,7 @@ int parse_headers(struct sip_msg* msg, int flags)
791 791
 	
792 792
 	DBG("parse_headers: flags=%d\n", flags);
793 793
 	while( tmp<end && (flags & msg->parsed_flag) != flags){
794
-		hf=malloc(sizeof(struct hdr_field));
794
+		hf=pkg_malloc(sizeof(struct hdr_field));
795 795
 		memset(hf,0, sizeof(struct hdr_field));
796 796
 		if (hf==0){
797 797
 			LOG(L_ERR, "ERROR:parse_headers: memory allocation error\n");
... ...
@@ -870,7 +762,7 @@ skip:
870 870
 	return 0;
871 871
 	
872 872
 error:
873
-	if (hf) free(hf);
873
+	if (hf) pkg_free(hf);
874 874
 	return -1;
875 875
 }
876 876
 
... ...
@@ -887,23 +779,9 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
887 887
 	char* first_via;
888 888
 	char* second_via;
889 889
 	struct msg_start *fl;
890
-	struct hdr_field* hf;
891
-	struct via_body *vb1, *vb2;
892 890
 	int offset;
893 891
 	int flags;
894 892
 
895
-#ifdef OLD_PARSER
896
-	/* init vb1 & vb2 to the null string */
897
-	/*memset(&vb1,0, sizeof(struct via_body));
898
-	memset(&vb2,0, sizeof(struct via_body));*/
899
-	vb1=&(msg->via1);
900
-	vb2=&(msg->via2);
901
-	vb1->error=VIA_PARSE_ERROR;
902
-	vb2->error=VIA_PARSE_ERROR;
903
-#else
904
-	vb1=vb2=0;
905
-	hf=0;
906
-#endif
907 893
 	/* eat crlf from the beginning */
908 894
 	for (tmp=buf; (*tmp=='\n' || *tmp=='\r')&&
909 895
 			tmp-buf < len ; tmp++);
... ...
@@ -951,27 +829,17 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
951 951
 		if (msg->via1->comment.s) DBG(" <%s>", msg->via1->comment.s);
952 952
 		DBG ("\n");
953 953
 	}
954
-#ifdef OLD_PARSER
955 954
 	if (msg->via2){
956
-		DBG(" second via: <%s/%s/%s> <%s:%d>",
957
-				vb2->name.s, vb2->version.s, vb2->transport.s, vb2->host.s,
958
-				vb2->port);
959
-		if (vb2->params.s)  DBG(";<%s>", vb2->params.s);
960
-		if (vb2->comment.s) DBG(" <%s>", vb2->comment.s);
961
-		DBG("\n");
955
+		DBG(" first  via: <%s/%s/%s> <%s:%s(%d)>",
956
+			msg->via2->name.s, msg->via2->version.s,
957
+			msg->via2->transport.s, msg->via2->host.s,
958
+			msg->via2->port_str, msg->via2->port);
959
+		if (msg->via2->params.s)  DBG(";<%s>", msg->via2->params.s);
960
+		if (msg->via2->comment.s) DBG(" <%s>", msg->via2->comment.s);
961
+		DBG ("\n");
962 962
 	}
963 963
 #endif
964
-#endif
965 964
 	
966
-	/* copy data into msg */
967
-#if 0
968
-#ifndef OLD_PARSER
969
-	memcpy(&(msg->via1), vb1, sizeof(struct via_body));
970
-	if (second_via) memcpy(&(msg->via2), vb2, sizeof(struct via_body));
971
-	if (vb1) free(vb1);
972
-	if (vb2) free(vb1);
973
-#endif
974
-#endif
975 965
 
976 966
 #ifdef DEBUG
977 967
 	DBG("exiting parse_msg\n");
... ...
@@ -980,11 +848,6 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
980 980
 	return 0;
981 981
 	
982 982
 error:
983
-	if (hf) free(hf);
984
-#ifndef OLD_PARSER
985
-	if (vb1) free(vb1);
986
-	if (vb2) free(vb1);
987
-#endif
988 983
 	return -1;
989 984
 }
990 985
 
... ...
@@ -993,12 +856,12 @@ error:
993 993
 void free_uri(struct sip_uri* u)
994 994
 {
995 995
 	if (u){
996
-		if (u->user.s) free(u->user.s);
997
-		if (u->passwd.s) free(u->passwd.s);
998
-		if (u->host.s) free(u->host.s);
999
-		if (u->port.s) free(u->port.s);
1000
-		if (u->params.s) free(u->params.s);
1001
-		if (u->headers.s) free(u->headers.s);
996
+		if (u->user.s)    pkg_free(u->user.s);
997
+		if (u->passwd.s)  pkg_free(u->passwd.s);
998
+		if (u->host.s)    pkg_free(u->host.s);
999
+		if (u->port.s)    pkg_free(u->port.s);
1000
+		if (u->params.s)  pkg_free(u->params.s);
1001
+		if (u->headers.s) pkg_free(u->headers.s);
1002 1002
 	}
1003 1003
 }
1004 1004
 
... ...
@@ -1010,7 +873,7 @@ void free_via_list(struct via_body* vb)
1010 1010
 	while(vb){
1011 1011
 		foo=vb;
1012 1012
 		vb=vb->next;
1013
-		free(foo);
1013
+		pkg_free(foo);
1014 1014
 	}
1015 1015
 }
1016 1016
 
... ...
@@ -1025,7 +888,7 @@ void clean_hdr_field(struct hdr_field* hf)
1025 1025
 				free_via_list(hf->parsed);
1026 1026
 				break;
1027 1027
 			case HDR_CSEQ:
1028
-				free(hf->parsed);
1028
+				pkg_free(hf->parsed);
1029 1029
 				break;
1030 1030
 			default:
1031 1031
 				LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
... ...
@@ -1046,6 +909,23 @@ void free_hdr_field_lst(struct hdr_field* hf)
1046 1046
 		foo=hf;
1047 1047
 		hf=hf->next;
1048 1048
 		clean_hdr_field(foo);
1049
-		free(foo);
1049
+		pkg_free(foo);
1050 1050
 	}
1051 1051
 }
1052
+
1053
+
1054
+
1055
+/*only the content*/
1056
+void free_sip_msg(struct sip_msg* msg)
1057
+{
1058
+	if (msg->new_uri.s) { pkg_free(msg->new_uri.s); msg->new_uri.len=0; }
1059
+	if (msg->headers) 	  free_hdr_field_lst(msg->headers);
1060
+	if (msg->add_rm)      free_lump_list(msg->add_rm);
1061
+	if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm);
1062
+	free(msg->orig);
1063
+	free(msg->buf);
1064
+}
1065
+
1066
+
1067
+
1068
+}
... ...
@@ -181,6 +181,7 @@ char* parse_cseq(char* buffer, char* end, struct cseq_body *cb);
181 181
 void free_via_list(struct via_body *vb);
182 182
 void clean_hdr_field(struct hdr_field* hf);
183 183
 void free_hdr_field_lst(struct hdr_field* hf);
184
+void free_sip_msg(struct sip_msg* msg);
184 185
 
185 186
 
186 187
 #endif
187 188
new file mode 100644
... ...
@@ -0,0 +1,468 @@
0
+/*
1
+ * $Id�
2
+ *
3
+ * header name parsing automaton:
4
+
5
+ * parsing:           compact form:
6
+ * Via:               v:
7
+ * From:              f:
8
+ * To:                t:
9
+ * Cseq:              n/a
10
+ * Call-ID:           i:
11
+ * Contact:           m:
12
+ * Max-Forwards:      n/a
13
+ * Route:             n/a
14
+ */
15
+
16
+
17
+#include "msg_parser.h"
18
+#include "dprint.h"
19
+
20
+enum { INITIAL=0,
21
+		VIA1, VIA2,
22
+		FROM1, FROM2, FROM3,
23
+		TO1,
24
+		C_START, CSEQ2, CSEQ3,
25
+		         CALLID2, CALLID3, CALLID4, CALLID5, CALLID6,
26
+		         CONTACT2, CONTACT3, CONTACT4, CONTACT5, CONTACT6,
27
+		M_START,      MAXFORWARDS2, MAXFORWARDS3, MAXFORWARDS4, MAXFORWARDS5,
28
+		MAXFORWARDS6, MAXFORWARDS7, MAXFORWARDS8, MAXFORWARDS9, MAXFORWARDS10,
29
+		MAXFORWARDS11,
30
+		ROUTE1, ROUTE2, ROUTE3, ROUTE4,
31
+		/* final states*/
32
+		F_VIA=1000, F_FROM, F_TO, F_CSEQ, F_CALLID, F_CONTACT, F_MAXFORWARDS,
33
+		F_ROUTE,
34
+		I_START,
35
+
36
+		UNKNOWN_HEADER=200,
37
+		BODY=220,
38
+		LF=25000,
39
+	};
40
+
41
+
42
+/* returns end or pointer to next elem*/
43
+char* parse_hname(char* p, char* end, struct hdr_field* hdr)
44
+{
45
+
46
+	char* t;
47
+	register int state;
48
+	int i;
49
+	int err;
50
+	err=0;
51
+
52
+	state=INITIAL;
53
+		
54
+	for(t=p;t<end;t++){
55
+		switch(*t){
56
+			case 'V':
57
+			case 'v':
58
+					switch(state){
59
+						case INITIAL:
60
+							state=VIA1;
61
+							hdr->name.s=t;
62
+							break;
63
+						case UNKNOWN_HEADER: break;
64
+						default:
65
+							state=UNKNOWN_HEADER;
66
+					}
67
+					break;
68
+			case 'I':
69
+			case 'i':
70
+					switch(state){
71
+						case VIA1:
72
+							state=VIA2;
73
+							break;
74
+						case CALLID5:
75
+							state=CALLID6;
76
+							break;
77
+						case INITIAL:
78
+							state=I_START;
79
+							hdr->name.s=t;
80
+							break;
81
+						case UNKNOWN_HEADER: break;
82
+						default:
83
+							state=UNKNOWN_HEADER;
84
+					}
85
+					break;
86
+			case 'A':
87
+			case 'a':
88
+					switch(state){
89
+						case VIA2:
90
+								state=F_VIA;
91
+								break;
92
+						case C_START:  /*CALLID1*/
93
+								state=CALLID2;
94
+								break;
95
+						case CONTACT4:
96
+								state=CONTACT5;
97
+								break;
98
+						case M_START:
99
+								state=MAXFORWARDS2;
100
+								break;
101
+						case MAXFORWARDS8:
102
+								state=MAXFORWARDS9;
103
+								break;
104
+						case UNKNOWN_HEADER: break;
105
+						default:
106
+								state=UNKNOWN_HEADER;
107
+					}
108
+					break;
109
+			case 'F':
110
+			case 'f':
111
+					switch(state){
112
+						case INITIAL:
113
+								state=FROM1;
114
+								hdr->name.s=t;
115
+								break;
116
+						case MAXFORWARDS4:
117
+								state=MAXFORWARDS5;
118
+								break;
119
+						case UNKNOWN_HEADER: break;
120
+						default:
121
+								state=UNKNOWN_HEADER;
122
+					}
123
+					break;
124
+			case 'R':
125
+			case 'r':
126
+					switch(state){
127
+						case INITIAL:
128
+							state=ROUTE1;
129
+							hdr->name.s=t;
130
+							break;
131
+						case FROM1:
132
+							state=FROM2;
133
+							break;
134
+						case MAXFORWARDS6:
135
+							state=MAXFORWARDS7;
136
+							break;
137
+						case MAXFORWARDS9:
138
+							state=MAXFORWARDS10;
139
+							break;
140
+						case UNKNOWN_HEADER: break;
141
+						default:
142
+							state=UNKNOWN_HEADER;
143
+					}
144
+					break;
145
+			case 'O':
146
+			case 'o':
147
+					switch(state){
148
+						case FROM2:
149
+							state=FROM3;
150
+							break;
151
+						case TO1:
152
+							state=F_TO;
153
+							break;
154
+						case C_START: /*CONTACT1 */
155
+							state=CONTACT2;
156
+							break;
157
+						case ROUTE1:
158
+							state=ROUTE2;
159
+							break;
160
+						case MAXFORWARDS5:
161
+							state=MAXFORWARDS6;
162
+							break;
163
+						case UNKNOWN_HEADER: break;
164
+						default:
165
+							state=UNKNOWN_HEADER;
166
+					}
167
+					break;
168
+			case 'M':
169
+			case 'm':
170
+						switch(state){
171
+							case INITIAL:
172
+								state=M_START;
173
+								hdr->name.s=t;
174
+								break;
175
+							case FROM3:
176
+								state=F_FROM;
177
+								break;
178
+							case UNKNOWN_HEADER: break;
179
+							default:
180
+								state=UNKNOWN_HEADER;
181
+						}
182
+						break;
183
+			case 'T':
184
+			case 't':
185
+						switch(state){
186
+							case INITIAL:
187
+								state=TO1;
188
+								hdr->name.s=t;
189
+								break;
190
+							case CONTACT3:
191
+								state=CONTACT4;
192
+								break;
193
+							case CONTACT6:
194
+								state=F_CONTACT;
195
+								break;
196
+							case ROUTE3:
197
+								state=ROUTE4;
198
+								break;
199
+							case UNKNOWN_HEADER: break;
200
+							default:
201
+								state=UNKNOWN_HEADER;
202
+						}
203
+						break;
204
+			case 'C':
205
+			case 'c':
206
+						switch(state){
207
+							case INITIAL:
208
+								state=C_START;
209
+								hdr->name.s=t;
210
+								break;
211
+							case CONTACT5:
212
+								state=CONTACT6;
213
+								break;
214
+							case UNKNOWN_HEADER: break;
215
+							default:
216
+								state=UNKNOWN_HEADER;
217
+						}
218
+						break;
219
+			case 'S':
220
+			case 's':
221
+						switch(state){
222
+							case C_START:
223
+								state=CSEQ2;
224
+								break;
225
+							case MAXFORWARDS11:
226
+								state=F_MAXFORWARDS;
227
+								break;
228
+							case UNKNOWN_HEADER: break;
229
+							default:
230
+								state=UNKNOWN_HEADER;
231
+						}
232
+						break;
233
+			case 'E':
234
+			case 'e':
235
+						switch(state){
236
+							case CSEQ2:
237
+								state=CSEQ3;
238
+								break;
239
+							case ROUTE4:
240
+								state=F_ROUTE;
241
+								break;
242
+							case UNKNOWN_HEADER: break;
243
+							default:
244
+								state=UNKNOWN_HEADER;
245
+						}
246
+						break;
247
+			case 'Q':
248
+			case 'q':
249
+						switch(state){
250
+							case CSEQ3:
251
+								state=F_CSEQ;
252
+								break;
253
+							case UNKNOWN_HEADER: break;
254
+							default:
255
+								state=UNKNOWN_HEADER;
256
+						}
257
+						break;
258
+			case 'L':
259
+			case 'l':
260
+						switch(state){
261
+							case CALLID2:
262
+								state=CALLID3;
263
+								break;
264
+							case CALLID3:
265
+								state=CALLID4;
266
+								break;
267
+							case UNKNOWN_HEADER: break;
268
+							default:
269
+								state=UNKNOWN_HEADER;
270
+						}
271
+						break;
272
+			case 'D':
273
+			case 'd':
274
+						switch(state){
275
+							case CALLID6:
276
+								state=F_CALLID;
277
+								break;
278
+							case MAXFORWARDS10:
279
+								state=MAXFORWARDS11;
280
+								break;
281
+							case UNKNOWN_HEADER: break;
282
+							default:
283
+								state=UNKNOWN_HEADER;
284
+						}
285
+						break;
286
+			case 'N':
287
+			case 'n':
288
+						switch(state){
289
+							case CONTACT2:
290
+								state=CONTACT3;
291
+								break;
292
+							case UNKNOWN_HEADER: break;
293
+							default:
294
+								state=UNKNOWN_HEADER;
295
+						}
296
+						break;
297
+			case 'X':
298
+			case 'x':
299
+						switch(state){
300
+							case MAXFORWARDS2:
301
+								state=MAXFORWARDS3;
302
+								break;
303
+							case UNKNOWN_HEADER: break;
304
+							default:
305
+								state=UNKNOWN_HEADER;
306
+						}
307
+						break;
308
+			case '-':
309
+						switch(state){
310
+							case CALLID4:
311
+								state=CALLID5;
312
+								break;
313
+							case MAXFORWARDS3:
314
+								state=MAXFORWARDS4;
315
+								break;
316
+							case UNKNOWN_HEADER: break;
317
+							default:
318
+								state=UNKNOWN_HEADER;
319
+						}
320
+						break;
321
+			case 'W':
322
+			case 'w':
323
+						switch(state){
324
+							case MAXFORWARDS7:
325
+								state=MAXFORWARDS8;
326
+								break;
327
+							case UNKNOWN_HEADER: break;
328
+							default:
329
+								state=UNKNOWN_HEADER;
330
+						}
331
+						break;
332
+			case 'U':
333
+			case 'u':
334
+						switch(state){
335
+							case ROUTE2:
336
+								state=ROUTE3;
337
+								break;
338
+							case UNKNOWN_HEADER: break;
339
+							default:
340
+								state=UNKNOWN_HEADER;
341
+						}
342
+						break;
343
+			case ' ':
344
+						switch(state){
345
+							case INITIAL:
346
+								break; /*eat space */
347
+							case F_VIA:
348
+							case F_FROM:
349
+							case F_TO:
350
+							case F_CSEQ:
351
+							case F_CALLID:
352
+							case F_CONTACT:
353
+							case F_MAXFORWARDS:
354
+							case F_ROUTE:
355
+								break; /* eat trailing space*/
356
+							case VIA1:
357
+								/*compact form: v: */
358
+								state=F_VIA;
359
+								break;
360
+							case FROM1:
361
+								/*compact form f:*/
362
+								state=F_FROM;
363
+								break;
364
+							case TO1:
365
+								/*compact form t:*/
366
+								state=F_TO;
367
+								break;
368
+							case I_START:
369
+								/*compact form i: (Call-ID)*/
370
+								state=F_CALLID;
371
+								break;
372
+							case M_START:
373
+								/*compact form m: (Contact)*/
374
+								state=F_CONTACT;
375
+								break;
376
+							case UNKNOWN_HEADER: break;
377
+							default:
378
+								state=UNKNOWN_HEADER;
379
+						}
380
+						break;
381
+			case ':':
382
+						switch(state){
383
+							case F_VIA:
384
+							case VIA1: /* compact form*/
385
+								*t=0;
386
+								hdr->name.len=t-hdr->name.s;
387
+								hdr->type=HDR_VIA;
388
+								goto skip;
389
+							case F_FROM:
390
+							case FROM1: /*compact form*/
391
+								*t=0;
392
+								hdr->name.len=t-hdr->name.s;
393
+								hdr->type=HDR_FROM;
394
+								goto skip;
395
+							case F_TO:
396
+							case TO1: /*compact form*/
397
+								*t=0;
398
+								hdr->name.len=t-hdr->name.s;
399
+								hdr->type=HDR_TO;
400
+								goto skip;
401
+							case F_CSEQ:
402
+								*t=0;
403
+								hdr->name.len=t-hdr->name.s;
404
+								hdr->type=HDR_CSEQ;
405
+								goto skip;
406
+							case F_CALLID:
407
+							case I_START: /*compact form*/
408
+								*t=0;
409
+								hdr->name.len=t-hdr->name.s;
410
+								hdr->type=HDR_CALLID;
411
+								goto skip;
412
+							case F_CONTACT:
413
+							case M_START: /*compact form*/
414
+								*t=0;
415
+								hdr->name.len=t-hdr->name.s;
416
+								hdr->type=HDR_CONTACT;
417
+								goto skip;
418
+							case F_MAXFORWARDS:
419
+								*t=0;
420
+								hdr->name.len=t-hdr->name.s;
421
+								hdr->type=HDR_MAXFORWARDS;
422
+								goto skip;
423
+							case F_ROUTE:
424
+								*t=0;
425
+								hdr->name.len=t-hdr->name.s;
426
+								hdr->type=HDR_ROUTE;
427
+								goto skip;
428
+							case UNKNOWN_HEADER:
429
+								*t=0;
430
+								hdr->name.len=t-hdr->name.s;
431
+								hdr->type=HDR_OTHER;
432
+								goto skip;
433
+							default:
434
+								/*printf("found unkown header, state=%d\n", 
435
+											state);*/
436
+								LOG(L_ERR, "ERROR : bug?: parse_hname:"
437
+										" on char <%c> state %d\n",
438
+										*t, state);
439
+								goto error;
440
+						}
441
+						break;
442
+			default:
443
+					switch(state){
444
+						case INITIAL:
445
+							hdr->name.s=t;
446
+							state=UNKNOWN_HEADER;
447
+							break;
448
+						case UNKNOWN_HEADER:
449
+							break;
450
+						default:
451
+							state=UNKNOWN_HEADER;
452
+					}
453
+		}
454
+	}
455
+/* if we are here => we didn't find ':' => error*/
456
+	
457
+error:
458
+	hdr->type=HDR_ERROR;
459
+	return t;
460
+
461
+skip:
462
+	DBG("end of header name found, state=%d\n", state);
463
+	t++;
464
+	return t;
465
+
466
+}
467
+
0 468
new file mode 100644
... ...
@@ -0,0 +1,1646 @@
0
+/* 
1
+ * $Id$ 
2
+ *
3
+ * via parsing automaton
4
+ * 
5
+ */
6
+
7
+/* parsing:           compact form:
8
+ */
9
+
10
+/* 
11
+ * still TODO/test:
12
+ *  - parse next via
13
+ *  - return a list of header structs
14
+ *  - return list of params
15
+ */
16
+
17
+
18
+#ifndef OLD_PARSER
19
+
20
+#include <stdlib.h>
21
+#include "dprint.h"
22
+#include "msg_parser.h"
23
+#include "ut.h"
24
+
25
+
26
+
27
+/* main via states (uri:port ...) */
28
+enum{	         F_HOST,    P_HOST,
29
+		L_PORT,  F_PORT,    P_PORT,
30
+		L_PARAM, F_PARAM,   P_PARAM,
31
+		L_VIA,   F_VIA,
32
+		         F_COMMENT, P_COMMENT,
33
+				 F_IP6HOST, P_IP6HOST,
34
+				 F_CRLF,
35
+				 F_LF,
36
+				 F_CR,
37
+				 END_OF_HEADER
38
+	};
39
+
40
+/* first via part state */
41
+enum{	         F_SIP=100,
42
+		SIP1, SIP2, FIN_SIP,
43
+		L_VER, F_VER,
44
+		VER1, VER2, FIN_VER,
45
+		L_PROTO, F_PROTO, P_PROTO
46
+	};
47
+
48
+/* param realated states */
49
+enum{	L_VALUE=200,   F_VALUE, P_VALUE, P_STRING,
50
+		HIDDEN1,   HIDDEN2,   HIDDEN3,   HIDDEN4,   HIDDEN5,
51
+		TTL1,      TTL2,
52
+		BRANCH1,   BRANCH2,   BRANCH3,   BRANCH4,   BRANCH5,
53
+		MADDR1,    MADDR2,    MADDR3,    MADDR4,
54
+		RECEIVED1, RECEIVED2, RECEIVED3, RECEIVED4, RECEIVED5, RECEIVED6,
55
+		RECEIVED7,
56
+		/* fin states (227-...)*/
57
+		FIN_HIDDEN, FIN_TTL, FIN_BRANCH, FIN_MADDR, FIN_RECEIVED,
58
+		GEN_PARAM
59
+	};
60
+
61
+
62
+
63
+/* entry state must be F_PARAM, or saved_state=F_PARAM and 
64
+ * state=F_{LF,CR,CRLF}!
65
+ * output state = L_PARAM or F_PARAM or END_OF_HEADER 
66
+ * (and saved_state= last state); everything else => error */
67
+__inline char* parse_via_param(	char* p, char* end, int* pstate, 
68
+								int* psaved_state)
69
+{
70
+	char* tmp;
71
+	register int state;
72
+	int saved_state;
73
+	int param_type;
74
+	char* param_name;
75
+	char* param_value;
76
+	
77
+	state=*pstate;
78
+	saved_state=*psaved_state;
79
+	param_name=param_value=0;
80
+	param_type=0;
81
+	
82
+	for (tmp=p;tmp<end;tmp++){
83
+		switch(*tmp){
84
+			case ' ':
85
+			case '\t':
86
+				switch(state){
87
+					case FIN_HIDDEN:
88
+						*tmp=0;
89
+						param_type=state;
90
+						state=L_PARAM;
91
+						goto endofparam;
92
+					case FIN_BRANCH:
93
+					case FIN_TTL:
94
+					case FIN_MADDR:
95
+					case FIN_RECEIVED:
96
+						*tmp=0;
97
+						param_type=state;
98
+						state=L_VALUE;
99
+						goto find_value;
100
+					case F_PARAM:
101
+						break;
102
+					case F_LF:
103
+					case F_CR:
104
+					case F_CRLF:
105
+						state=saved_state;
106
+						break;
107
+					case GEN_PARAM:
108
+					default:
109
+						*tmp=0;
110
+						param_type=GEN_PARAM;
111
+						state=L_VALUE;
112
+						goto find_value;
113
+				}
114
+				break;
115
+			/* \n and \r*/
116
+			case '\n':
117
+				switch(state){
118
+					case FIN_HIDDEN:
119
+						*tmp=0;
120
+						param_type=state;
121
+						saved_state=L_PARAM;
122
+						state=F_LF;
123
+						goto endofparam;
124
+					case FIN_BRANCH:
125
+					case FIN_TTL:
126
+					case FIN_MADDR:
127
+					case FIN_RECEIVED:
128
+						*tmp=0;
129
+						param_type=state;
130
+						saved_state=L_VALUE;
131
+						state=F_LF;
132
+						goto find_value;
133
+					case F_PARAM:
134
+						saved_state=state;
135
+						state=F_LF;
136
+						break;
137
+					case F_LF:
138
+					case F_CRLF:
139
+						state=END_OF_HEADER;
140
+						goto end_via;
141
+					case F_CR:
142
+						state=F_CRLF;
143
+						break;
144
+					case GEN_PARAM:
145
+					default:
146
+						*tmp=0;
147
+						param_type=GEN_PARAM;
148
+						saved_state=L_VALUE;
149
+						state=F_LF;
150
+						goto find_value;
151
+				}
152
+				break;
153
+			case '\r':
154
+				switch(state){
155
+					case FIN_HIDDEN:
156
+						*tmp=0;
157
+						param_type=state;
158
+						saved_state=L_PARAM;
159
+						state=F_CR;
160
+						goto endofparam;
161
+					case FIN_BRANCH:
162
+					case FIN_TTL:
163
+					case FIN_MADDR:
164
+					case FIN_RECEIVED:
165
+						*tmp=0;
166
+						param_type=state;
167
+						saved_state=L_VALUE;
168
+						state=F_CR;
169
+						goto find_value;
170
+					case F_PARAM:
171
+						saved_state=state;
172
+						state=F_CR;
173
+						break;
174
+					case F_CR:
175
+					case F_CRLF:
176
+						state=END_OF_HEADER;
177
+						goto end_via;
178
+					case GEN_PARAM:
179
+					default:
180
+						*tmp=0;
181
+						param_type=GEN_PARAM;
182
+						saved_state=L_VALUE;
183
+						state=F_CR;
184
+						goto find_value;
185
+				}
186
+				break;
187
+
188
+			case '=':
189
+				switch(state){
190
+					case FIN_BRANCH:
191
+					case FIN_TTL:
192
+					case FIN_MADDR:
193
+					case FIN_RECEIVED:
194
+						*tmp=0;
195
+						param_type=state;
196
+						state=F_VALUE;
197
+						goto find_value;
198
+					case F_PARAM:
199
+					case FIN_HIDDEN:
200
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
201
+								" state %d\n");
202
+						goto error;
203
+					case F_CR:
204
+					case F_LF:
205
+					case F_CRLF:
206
+						state=END_OF_HEADER;
207
+						goto end_via;
208
+					case GEN_PARAM:
209
+					default:
210
+						*tmp=0;
211
+						param_type=GEN_PARAM;
212
+						state=F_VALUE;
213
+						goto find_value;
214
+				}
215
+				break;
216
+			case ';':
217
+				switch(state){
218
+					case FIN_HIDDEN:
219
+						*tmp=0;
220
+						param_type=state;
221
+						state=F_PARAM;
222
+						goto endofparam;
223
+					case FIN_BRANCH:
224
+					case FIN_MADDR:
225
+					case FIN_TTL:
226
+					case FIN_RECEIVED:
227
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
228
+								" state %d\n");
229
+						goto error;
230
+					case F_CR:
231
+					case F_LF:
232
+					case F_CRLF:
233
+						state=END_OF_HEADER;
234
+						goto end_via;
235
+					case GEN_PARAM:
236
+					default:
237
+						*tmp=0;
238
+						param_type=GEN_PARAM;
239
+						state=F_PARAM;
240
+						goto endofparam;
241
+				}
242
+				break;
243
+				
244
+				/* param names */
245
+			case 'h':
246
+			case 'H':
247
+				switch(state){
248
+					case F_PARAM:
249
+						state=HIDDEN1;
250
+						param_name=tmp;
251
+						break;
252
+					case GEN_PARAM:
253
+						break;
254
+					case F_CR:
255
+					case F_LF:
256
+					case F_CRLF:
257
+						state=END_OF_HEADER;
258
+						goto end_via;
259
+					default:
260
+						state=GEN_PARAM;
261
+				}
262
+				break;
263
+			case 'i':
264
+			case 'I':
265
+				switch(state){
266
+					case HIDDEN1:
267
+						state=HIDDEN2;
268
+						break;
269
+					case RECEIVED4:
270
+						state=RECEIVED5;
271
+						break;
272
+					case GEN_PARAM:
273
+						break;
274
+					case F_CR:
275
+					case F_LF:
276
+					case F_CRLF:
277
+						state=END_OF_HEADER;
278
+						goto end_via;
279
+					default:
280
+						state=GEN_PARAM;
281
+				}
282
+				break;
283
+			case 'd':
284
+			case 'D':
285
+				switch(state){
286
+					case HIDDEN2:
287
+						state=HIDDEN3;
288
+						break;
289
+					case HIDDEN3:
290
+						state=HIDDEN4;
291
+						break;
292
+					case MADDR2:
293
+						state=MADDR3;
294
+						break;
295
+					case MADDR3:
296
+						state=MADDR4;
297
+						break;
298
+					case RECEIVED7:
299
+						state=FIN_RECEIVED;
300
+						break;
301
+					case GEN_PARAM:
302
+						break;
303
+					case F_CR:
304
+					case F_LF:
305
+					case F_CRLF:
306
+						state=END_OF_HEADER;
307
+						goto end_via;
308
+					default:
309
+						state=GEN_PARAM;
310
+				}
311
+				break;
312
+			case 'e':
313
+			case 'E':
314
+				switch(state){
315
+					case HIDDEN4:
316
+						state=HIDDEN5;
317
+						break;
318
+					case RECEIVED1:
319
+						state=RECEIVED2;
320
+						break;
321
+					case RECEIVED3:
322
+						state=RECEIVED4;
323
+						break;
324
+					case RECEIVED6:
325
+						state=RECEIVED7;
326
+						break;
327
+					case GEN_PARAM:
328
+						break;
329
+					case F_CR:
330
+					case F_LF:
331
+					case F_CRLF:
332
+						state=END_OF_HEADER;
333
+						goto end_via;
334
+					default:
335
+						state=GEN_PARAM;
336
+				}
337
+				break;
338
+			case 'n':
339
+			case 'N':
340
+				switch(state){
341
+					case HIDDEN5:
342
+						state=FIN_HIDDEN;
343
+						break;
344
+					case BRANCH3:
345
+						state=BRANCH4;
346
+						break;
347
+					case GEN_PARAM:
348
+						break;
349
+					case F_CR:
350
+					case F_LF:
351
+					case F_CRLF:
352
+						state=END_OF_HEADER;
353
+						goto end_via;
354
+					default:
355
+						state=GEN_PARAM;
356
+				}
357
+				break;
358
+			case 't':
359
+			case 'T':
360
+				switch(state){
361
+					case F_PARAM:
362
+						state=TTL1;
363
+						param_name=tmp;
364
+						break;
365
+					case TTL1:
366
+						state=TTL2;
367
+						break;
368
+					case GEN_PARAM:
369
+						break;
370
+					case F_CR:
371
+					case F_LF:
372
+					case F_CRLF:
373
+						state=END_OF_HEADER;
374
+						goto end_via;
375
+					default:
376
+						state=GEN_PARAM;
377
+				}
378
+				break;
379
+			case 'l':
380
+			case 'L':
381
+				switch(state){
382
+					case TTL2:
383
+						state=FIN_TTL;
384
+						break;
385
+					case GEN_PARAM:
386
+						break;
387
+					case F_CR:
388
+					case F_LF:
389
+					case F_CRLF:
390
+						state=END_OF_HEADER;
391
+						goto end_via;
392
+					default:
393
+						state=GEN_PARAM;
394
+				}
395
+				break;
396
+			case 'm':
397
+			case 'M':
398
+				switch(state){
399
+					case F_PARAM:
400
+						state=MADDR1;
401
+						param_name=tmp;
402
+						break;
403
+					case GEN_PARAM:
404
+						break;
405
+					case F_CR:
406
+					case F_LF:
407
+					case F_CRLF:
408
+						state=END_OF_HEADER;
409
+						goto end_via;
410
+					default:
411
+						state=GEN_PARAM;
412
+				}
413
+				break;
414
+			case 'a':
415
+			case 'A':
416
+				switch(state){
417
+					case MADDR1:
418
+						state=MADDR2;
419
+						break;
420
+					case BRANCH2:
421
+						state=BRANCH3;
422
+						break;
423
+					case GEN_PARAM:
424
+						break;
425
+					case F_CR:
426
+					case F_LF:
427
+					case F_CRLF:
428
+						state=END_OF_HEADER;
429
+						goto end_via;
430
+					default:
431
+						state=GEN_PARAM;
432
+				}
433
+				break;
434
+			case 'r':
435
+			case 'R':
436
+				switch(state){
437
+					case MADDR4:
438
+						state=FIN_MADDR;
439
+						break;
440
+					case F_PARAM:
441
+						state=RECEIVED1;
442
+						param_name=tmp;
443
+						break;
444
+					case BRANCH1:
445
+						state=BRANCH2;
446
+						break;
447
+					case GEN_PARAM:
448
+						break;
449
+					case F_CR:
<