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