Browse code

- added NO_DEBUG & NO_LOG - fixed socket listen

Andrei Pelinescu-Onciul authored on 08/11/2001 05:16:56
Showing 4 changed files
... ...
@@ -21,9 +21,9 @@ NAME=ser
21 21
 # MACROEATER replaces frequently called parser helper functions
22 22
 # with macros
23 23
 # recommanded: on (speed-up)
24
-# STATS allows to print out number of packets processed on CTRL-C; implementation
25
-#  still nasty and reports per-process
26
-DEFS=-DNOCR -DMACROEATER -DSTATS
24
+# STATS allows to print out number of packets processed on CTRL-C; 
25
+# implementation still nasty and reports per-process
26
+DEFS=-DNOCR -DMACROEATER -DSTATS #-DNO_DEBUG #-DNO_LOG
27 27
 
28 28
 # platform dependent settings
29 29
 
... ...
@@ -32,7 +32,7 @@ ARCH = $(shell uname -s)
32 32
 #common
33 33
 CC=gcc
34 34
 LD=gcc
35
-CFLAGS=-O2 -Wcast-align #-Wmissing-prototypes 
35
+CFLAGS=-O3 -Wcast-align #-Wmissing-prototypes 
36 36
 LDFLAGS=-Wl,-O2 -Wl,-E
37 37
 LEX=flex
38 38
 YACC=bison
... ...
@@ -46,9 +46,15 @@ void dprint (char* format, ...);
46 46
 
47 47
 #endif
48 48
 
49
+#ifndef NO_DEBUG
50
+	#undef NO_LOG
51
+#endif
49 52
 
53
+#ifdef NO_LOG
54
+	#define LOG(lev, fmt, args...)
55
+#else
50 56
 
51
-#define LOG(lev, fmt, args...) \
57
+	#define LOG(lev, fmt, args...) \
52 58
 			do { \
53 59
 				if (debug>=(lev)){ \
54 60
 					if (log_stderr) dprint (fmt, ## args); \
... ...
@@ -79,7 +85,13 @@ void dprint (char* format, ...);
79 79
 					} \
80 80
 				} \
81 81
 			}while(0)
82
+#endif
83
+
82 84
 
83
-#define DBG(fmt, args...) LOG(L_DBG, fmt, ## args)
85
+#ifdef NO_DEBUG
86
+	#define DBG(fmt, args...)
87
+#else
88
+	#define DBG(fmt, args...) LOG(L_DBG, fmt, ## args)
89
+#endif
84 90
 
85 91
 #endif /* ifndef dprint_h */
... ...
@@ -34,7 +34,7 @@
34 34
 
35 35
 
36 36
 static char id[]="@(#) $Id$";
37
-static char version[]="ser 0.8.3";
37
+static char version[]="ser 0.8.3.1";
38 38
 static char flags[]="NOCR:"
39 39
 #ifdef NOCR
40 40
 "On"
... ...
@@ -169,12 +169,10 @@ int daemonize(char*  name)
169 169
 	}
170 170
 	
171 171
 	/* close any open file descriptors */
172
-	
173 172
 	for (r=0;r<MAX_FD; r++){
174 173
 		if ((r==3) && log_stderr)  continue;
175 174
 		close(r);
176 175
 	}
177
-	
178 176
 	return  0;
179 177
 
180 178
 error:
... ...
@@ -191,6 +189,7 @@ int main_loop()
191 191
 
192 192
 	/* one "main" process and n children handling i/o */
193 193
 
194
+
194 195
 	if (dont_fork){
195 196
 		/* only one address */
196 197
 		if (udp_init(addresses[0],port_no)==-1) goto error;
... ...
@@ -198,6 +197,8 @@ int main_loop()
198 198
 		udp_rcv_loop();
199 199
 	}else{
200 200
 		for(r=0;r<addresses_no;r++){
201
+			/* create the listening socket (for each address)*/
202
+			if (udp_init(addresses[r], port_no)==-1) goto error;
201 203
 			for(i=0;i<children_no;i++){
202 204
 				if ((pid=fork())<0){
203 205
 					LOG(L_CRIT,  "main_loop: Cannot fork\n");
... ...
@@ -205,16 +206,17 @@ int main_loop()
205 205
 				}
206 206
 				if (pid==0){
207 207
 					/* child */
208
-					if (udp_init(addresses[r], port_no)==-1) goto error;
209 208
 					return udp_rcv_loop();
210 209
 				}
211 210
 			}
211
+			close(udp_sock); /*parent*/
212 212
 		}
213 213
 	}
214 214
 		
215 215
 	for(;;){
216
-		/* debug:  instead of select */
217
-		sleep(1);
216
+		/* debug:  instead of doing something usefull */
217
+		/* (placeholder for timers, etc.) */
218
+		sleep(10);
218 219
 	}
219 220
 	
220 221
 	return 0;
... ...
@@ -26,7 +26,8 @@ enum{	         F_HOST,    P_HOST,
26 26
 				 F_IP6HOST, P_IP6HOST,
27 27
 				 F_CRLF,
28 28
 				 F_LF,
29
-				 F_CR
29
+				 F_CR,
30
+				 END_OF_HEADER
30 31
 	};
31 32
 
32 33
 /* first via part state */
... ...
@@ -37,13 +38,690 @@ enum{	         F_SIP=100,
37 37
 		L_PROTO, F_PROTO, P_PROTO
38 38
 	};
39 39
 
40
+/* param realated states */
41
+enum{	L_VALUE=200,   F_VALUE, P_VALUE, P_STRING,
42
+		HIDDEN1,   HIDDEN2,   HIDDEN3,   HIDDEN4,   HIDDEN5,
43
+		TTL1,      TTL2,
44
+		BRANCH1,   BRANCH2,   BRANCH3,   BRANCH4,   BRANCH5,
45
+		MADDR1,    MADDR2,    MADDR3,    MADDR4,
46
+		RECEIVED1, RECEIVED2, RECEIVED3, RECEIVED4, RECEIVED5, RECEIVED6,
47
+		RECEIVED7,
48
+		/* fin states (227-...)*/
49
+		FIN_HIDDEN, FIN_TTL, FIN_BRANCH, FIN_MADDR, FIN_RECEIVED,
50
+		GEN_PARAM
51
+	};
52
+
40 53
 #define LOG(lev, fmt, args...) fprintf(stderr, fmt, ## args)
41 54
 
55
+
56
+/* entry state must be F_PARAM, or saved_state=F_PARAM and 
57
+ * state=F_{LF,CR,CRLF}!
58
+ * output state = L_PARAM or F_PARAM or END_OF_HEADER 
59
+ * (and saved_state= last state); everything else => error */
60
+__inline char* parse_via_param(char* p, int* pstate, int* psaved_state)
61
+{
62
+	char* tmp;
63
+	register int state;
64
+	int saved_state;
65
+	int param_type;
66
+	char* param_name;
67
+	char* param_value;
68
+	
69
+	state=*pstate;
70
+	saved_state=*psaved_state;
71
+	param_name=param_value=0;
72
+	param_type=0;
73
+	
74
+	for (tmp=p;*tmp;tmp++){
75
+		switch(*tmp){
76
+			case ' ':
77
+			case '\t':
78
+				switch(state){
79
+					case FIN_HIDDEN:
80
+						*tmp=0;
81
+						param_type=state;
82
+						state=L_PARAM;
83
+						goto endofparam;
84
+					case FIN_BRANCH:
85
+					case FIN_TTL:
86
+					case FIN_MADDR:
87
+					case FIN_RECEIVED:
88
+						*tmp=0;
89
+						param_type=state;
90
+						state=L_VALUE;
91
+						goto find_value;
92
+					case F_PARAM:
93
+						break;
94
+					case F_LF:
95
+					case F_CR:
96
+					case F_CRLF:
97
+						state=saved_state;
98
+						break;
99
+					case GEN_PARAM:
100
+					default:
101
+						*tmp=0;
102
+						param_type=GEN_PARAM;
103
+						state=L_VALUE;
104
+						goto find_value;
105
+				}
106
+				break;
107
+			/* \n and \r*/
108
+			case '\n':
109
+				switch(state){
110
+					case FIN_HIDDEN:
111
+						*tmp=0;
112
+						param_type=state;
113
+						saved_state=L_PARAM;
114
+						state=F_LF;
115
+						goto endofparam;
116
+					case FIN_BRANCH:
117
+					case FIN_TTL:
118
+					case FIN_MADDR:
119
+					case FIN_RECEIVED:
120
+						*tmp=0;
121
+						param_type=state;
122
+						saved_state=L_VALUE;
123
+						state=F_LF;
124
+						goto find_value;
125
+					case F_PARAM:
126
+						saved_state=state;
127
+						state=F_LF;
128
+						break;
129
+					case F_LF:
130
+					case F_CRLF:
131
+						state=END_OF_HEADER;
132
+						goto end;
133
+					case F_CR:
134
+						state=F_CRLF;
135
+						break;
136
+					case GEN_PARAM:
137
+					default:
138
+						*tmp=0;
139
+						param_type=GEN_PARAM;
140
+						saved_state=L_VALUE;
141
+						state=F_LF;
142
+						goto find_value;
143
+				}
144
+				break;
145
+			case '\r':
146
+				switch(state){
147
+					case FIN_HIDDEN:
148
+						*tmp=0;
149
+						param_type=state;
150
+						saved_state=L_PARAM;
151
+						state=F_CR;
152
+						goto endofparam;
153
+					case FIN_BRANCH:
154
+					case FIN_TTL:
155
+					case FIN_MADDR:
156
+					case FIN_RECEIVED:
157
+						*tmp=0;
158
+						param_type=state;
159
+						saved_state=L_VALUE;
160
+						state=F_CR;
161
+						goto find_value;
162
+					case F_PARAM:
163
+						saved_state=state;
164
+						state=F_CR;
165
+						break;
166
+					case F_CR:
167
+					case F_CRLF:
168
+						state=END_OF_HEADER;
169
+						goto end;
170
+					case GEN_PARAM:
171
+					default:
172
+						*tmp=0;
173
+						param_type=GEN_PARAM;
174
+						saved_state=L_VALUE;
175
+						state=F_CR;
176
+						goto find_value;
177
+				}
178
+				break;
179
+
180
+			case '=':
181
+				switch(state){
182
+					case FIN_BRANCH:
183
+					case FIN_TTL:
184
+					case FIN_MADDR:
185
+					case FIN_RECEIVED:
186
+						*tmp=0;
187
+						param_type=state;
188
+						state=F_VALUE;
189
+						goto find_value;
190
+					case F_PARAM:
191
+					case FIN_HIDDEN:
192
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
193
+								" state %d\n");
194
+						goto error;
195
+					case F_CR:
196
+					case F_LF:
197
+					case F_CRLF:
198
+						state=END_OF_HEADER;
199
+						goto end;
200
+					case GEN_PARAM:
201
+					default:
202
+						*tmp=0;
203
+						param_type=GEN_PARAM;
204
+						state=F_VALUE;
205
+						goto find_value;
206
+				}
207
+				break;
208
+			case ';':
209
+				switch(state){
210
+					case FIN_HIDDEN:
211
+						*tmp=0;
212
+						param_type=state;
213
+						state=F_PARAM;
214
+						goto endofparam;
215
+					case FIN_BRANCH:
216
+					case FIN_MADDR:
217
+					case FIN_TTL:
218
+					case FIN_RECEIVED:
219
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
220
+								" state %d\n");
221
+						goto error;
222
+					case F_CR:
223
+					case F_LF:
224
+					case F_CRLF:
225
+						state=END_OF_HEADER;
226
+						goto end;
227
+					case GEN_PARAM:
228
+					default:
229
+						*tmp=0;
230
+						param_type=GEN_PARAM;
231
+						state=F_PARAM;
232
+						goto endofparam;
233
+				}
234
+				break;
235
+				
236
+				/* param names */
237
+			case 'h':
238
+			case 'H':
239
+				switch(state){
240
+					case F_PARAM:
241
+						state=HIDDEN1;
242
+						param_name=tmp;
243
+						break;
244
+					case GEN_PARAM:
245
+						break;
246
+					case F_CR:
247
+					case F_LF:
248
+					case F_CRLF:
249
+						state=END_OF_HEADER;
250
+						goto end;
251
+					default:
252
+						state=GEN_PARAM;
253
+				}
254
+				break;
255
+			case 'i':
256
+			case 'I':
257
+				switch(state){
258
+					case HIDDEN1:
259
+						state=HIDDEN2;
260
+						break;
261
+					case RECEIVED4:
262
+						state=RECEIVED5;
263
+						break;
264
+					case GEN_PARAM:
265
+						break;
266
+					case F_CR:
267
+					case F_LF:
268
+					case F_CRLF:
269
+						state=END_OF_HEADER;
270
+						goto end;
271
+					default:
272
+						state=GEN_PARAM;
273
+				}
274
+				break;
275
+			case 'd':
276
+			case 'D':
277
+				switch(state){
278
+					case HIDDEN2:
279
+						state=HIDDEN3;
280
+						break;
281
+					case HIDDEN3:
282
+						state=HIDDEN4;
283
+						break;
284
+					case MADDR2:
285
+						state=MADDR3;
286
+						break;
287
+					case MADDR3:
288
+						state=MADDR4;
289
+						break;
290
+					case RECEIVED7:
291
+						state=FIN_RECEIVED;
292
+						break;
293
+					case GEN_PARAM:
294
+						break;
295
+					case F_CR:
296
+					case F_LF:
297
+					case F_CRLF:
298
+						state=END_OF_HEADER;
299
+						goto end;
300
+					default:
301
+						state=GEN_PARAM;
302
+				}
303
+				break;
304
+			case 'e':
305
+			case 'E':
306
+				switch(state){
307
+					case HIDDEN4:
308
+						state=HIDDEN5;
309
+						break;
310
+					case RECEIVED1:
311
+						state=RECEIVED2;
312
+						break;
313
+					case RECEIVED3:
314
+						state=RECEIVED4;
315
+						break;
316
+					case RECEIVED6:
317
+						state=RECEIVED7;
318
+						break;
319
+					case GEN_PARAM:
320
+						break;
321
+					case F_CR:
322
+					case F_LF:
323
+					case F_CRLF:
324
+						state=END_OF_HEADER;
325
+						goto end;
326
+					default:
327
+						state=GEN_PARAM;
328
+				}
329
+				break;
330
+			case 'n':
331
+			case 'N':
332
+				switch(state){
333
+					case HIDDEN5:
334
+						state=FIN_HIDDEN;
335
+						break;
336
+					case BRANCH3:
337
+						state=BRANCH4;
338
+						break;
339
+					case GEN_PARAM:
340
+						break;
341
+					case F_CR:
342
+					case F_LF:
343
+					case F_CRLF:
344
+						state=END_OF_HEADER;
345
+						goto end;
346
+					default:
347
+						state=GEN_PARAM;
348
+				}
349
+				break;
350
+			case 't':
351
+			case 'T':
352
+				switch(state){
353
+					case F_PARAM:
354
+						state=TTL1;
355
+						param_name=tmp;
356
+						break;
357
+					case TTL1:
358
+						state=TTL2;
359
+						break;
360
+					case GEN_PARAM:
361
+						break;
362
+					case F_CR:
363
+					case F_LF:
364
+					case F_CRLF:
365
+						state=END_OF_HEADER;
366
+						goto end;
367
+					default:
368
+						state=GEN_PARAM;
369
+				}
370
+				break;
371
+			case 'l':
372
+			case 'L':
373
+				switch(state){
374
+					case TTL2:
375
+						state=FIN_TTL;
376
+						break;
377
+					case GEN_PARAM:
378
+						break;
379
+					case F_CR:
380
+					case F_LF:
381
+					case F_CRLF:
382
+						state=END_OF_HEADER;
383
+						goto end;
384
+					default:
385
+						state=GEN_PARAM;
386
+				}
387
+				break;
388
+			case 'm':
389
+			case 'M':
390
+				switch(state){
391
+					case F_PARAM:
392
+						state=MADDR1;
393
+						param_name=tmp;
394
+						break;
395
+					case GEN_PARAM:
396
+						break;
397
+					case F_CR:
398
+					case F_LF:
399
+					case F_CRLF:
400
+						state=END_OF_HEADER;
401
+						goto end;
402
+					default:
403
+						state=GEN_PARAM;
404
+				}
405
+				break;
406
+			case 'a':
407
+			case 'A':
408
+				switch(state){
409
+					case MADDR1:
410
+						state=MADDR2;
411
+						break;
412
+					case BRANCH2:
413
+						state=BRANCH3;
414
+						break;
415
+					case GEN_PARAM:
416
+						break;
417
+					case F_CR:
418
+					case F_LF:
419
+					case F_CRLF:
420
+						state=END_OF_HEADER;
421
+						goto end;
422
+					default:
423
+						state=GEN_PARAM;
424
+				}
425
+				break;
426
+			case 'r':
427
+			case 'R':
428
+				switch(state){
429
+					case MADDR4:
430
+						state=FIN_MADDR;
431
+						break;
432
+					case F_PARAM:
433
+						state=RECEIVED1;
434
+						param_name=tmp;
435
+						break;
436
+					case BRANCH1:
437
+						state=BRANCH2;
438
+						break;
439
+					case GEN_PARAM:
440
+						break;
441
+					case F_CR:
442
+					case F_LF:
443
+					case F_CRLF:
444
+						state=END_OF_HEADER;
445
+						goto end;
446
+					default:
447
+						state=GEN_PARAM;
448
+				}
449
+				break;
450
+			case 'c':
451
+			case 'C':
452
+				switch(state){
453
+					case RECEIVED2:
454
+						state=RECEIVED3;
455
+						break;
456
+					case BRANCH4:
457
+						state=BRANCH5;
458
+						break;
459
+					case GEN_PARAM:
460
+						break;
461
+					case F_CR:
462
+					case F_LF:
463
+					case F_CRLF:
464
+						state=END_OF_HEADER;
465
+						goto end;
466
+					default:
467
+						state=GEN_PARAM;
468
+				}
469
+				break;
470
+			case 'v':
471
+			case 'V':
472
+				switch(state){
473
+					case RECEIVED5:
474
+						state=RECEIVED6;
475
+						break;
476
+					case GEN_PARAM:
477
+						break;
478
+					case F_CR:
479
+					case F_LF:
480
+					case F_CRLF:
481
+						state=END_OF_HEADER;
482
+						goto end;
483
+					default:
484
+						state=GEN_PARAM;
485
+				}
486
+				break;
487
+			case 'b':
488
+			case 'B':
489
+				switch(state){
490
+					case F_PARAM:
491
+						state=BRANCH1;
492
+						param_name=tmp;
493
+						break;
494
+					case GEN_PARAM:
495
+						break;
496
+					case F_CR:
497
+					case F_LF:
498
+					case F_CRLF:
499
+						state=END_OF_HEADER;
500
+						goto end;
501
+					default:
502
+						state=GEN_PARAM;
503
+				}
504
+				break;
505
+
506
+			default:
507
+				switch(state){
508
+					case F_PARAM:
509
+						state=GEN_PARAM;
510
+						param_name=tmp;
511
+						break;
512
+					case  GEN_PARAM:
513
+						break;
514
+					case F_CR:
515
+					case F_LF:
516
+					case F_CRLF:
517
+						state=END_OF_HEADER;
518
+						goto end;
519
+					default:
520
+						state=GEN_PARAM;
521
+				}
522
+		}
523
+	}/* for tmp*/
524
+
525
+/* end of packet?*/
526
+saved_state=state;
527
+param_type=state;
528
+state=END_OF_HEADER;
529
+goto end;
530
+
531
+find_value:
532
+	tmp++;
533
+	for(tmp;*tmp;tmp++){
534
+		switch(*tmp){
535
+			case ' ':
536
+			case '\t':
537
+				switch(state){
538
+					case L_VALUE:
539
+					case F_VALUE: /*eat space*/
540
+						break; 
541
+					case P_VALUE:
542
+						*tmp=0;
543
+						state=L_PARAM;
544
+						goto endofvalue;
545
+					case P_STRING:
546
+						break;
547
+					case F_CR:
548
+					case F_LF:
549
+					case F_CRLF:
550
+						state=saved_state;
551
+						break;
552
+					default:
553
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
554
+								" in state %d\n", state);
555
+						goto error;
556
+				}
557
+				break;
558
+			case '\n':
559
+				switch(state){
560
+					case L_VALUE:
561
+					case F_VALUE: /*eat space*/
562
+					case P_STRING:
563
+						saved_state=state;
564
+						state=F_LF;
565
+						break; 
566
+					case P_VALUE:
567
+						*tmp=0;
568
+						saved_state=L_PARAM;
569
+						state=F_LF;
570
+						goto endofvalue;
571
+					case F_LF:
572
+					case F_CRLF:
573
+						state=END_OF_HEADER;
574
+						goto end;
575
+					case F_CR:
576
+						state=F_CRLF;
577
+						break;
578
+					default:
579
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
580
+								" in state %d\n", state);
581
+						goto error;
582
+				}
583
+				break;
584
+			case '\r':
585
+				switch(state){
586
+					case L_VALUE:
587
+					case F_VALUE: /*eat space*/
588
+					case P_STRING:
589
+						saved_state=state;
590
+						state=F_CR;
591
+						break; 
592
+					case P_VALUE:
593
+						*tmp=0;
594
+						saved_state=L_PARAM;
595
+						state=F_CR;
596
+						goto endofvalue;
597
+					case F_LF:
598
+					case F_CR:
599
+					case F_CRLF:
600
+						state=END_OF_HEADER;
601
+						goto end;
602
+					default:
603
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
604
+								" in state %d\n", state);
605
+						goto error;
606
+				}
607
+				break;
608
+
609
+			case '=':
610
+				switch(state){
611
+					case L_VALUE:
612
+						state=F_VALUE;
613
+						break;
614
+					case P_STRING:
615
+						break;
616
+					case F_LF:
617
+					case F_CR:
618
+					case F_CRLF:
619
+						state=END_OF_HEADER;
620
+						goto end;
621
+					default:
622
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
623
+								" in state %d\n", state);
624
+						goto error;
625
+				}
626
+				break;
627
+			case ';':
628
+				switch(state){
629
+					case P_VALUE:
630
+						*tmp=0;
631
+						state=F_PARAM;
632
+						goto endofvalue;
633
+					case P_STRING:
634
+						break; /* what to do? */
635
+					case F_LF:
636
+					case F_CR:
637
+					case F_CRLF:
638
+						state=END_OF_HEADER;
639
+						goto end;
640
+					default:
641
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
642
+								" in state %d\n", state);
643
+						goto error;
644
+				}
645
+				break;
646
+			
647
+			case '"':
648
+				switch(state){
649
+					case F_VALUE:
650
+						state=P_STRING;
651
+						param_value=tmp+1;
652
+						break;
653
+					case P_STRING:
654
+						*tmp=0;
655
+						state=L_PARAM;
656
+						goto endofvalue;
657
+					case F_LF:
658
+					case F_CR:
659
+					case F_CRLF:
660
+						state=END_OF_HEADER;
661
+						goto end;
662
+					default:
663
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
664
+								" in state %d\n", state);
665
+						goto error;
666
+				}
667
+				break;
668
+			default:
669
+				switch(state){
670
+					case F_VALUE:
671
+						state=P_VALUE;
672
+						param_value=tmp;
673
+						break;
674
+					case P_VALUE:
675
+					case P_STRING:
676
+						break;
677
+					case F_LF:
678
+					case F_CR:
679
+					case F_CRLF:
680
+						state=END_OF_HEADER;
681
+						goto end;
682
+					default:
683
+						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
684
+								" in state %d\n", state);
685
+						goto error;
686
+				}
687
+		}
688
+	} /* for2 tmp*/
689
+
690
+	/* if generic_param => it can have no value */
691
+	if ((state==L_VALUE)&&(param_type==GEN_PARAM)) state=L_PARAM;
692
+	saved_state=state;
693
+	state=END_OF_HEADER;
694
+	goto end;
695
+
696
+endofparam:
697
+endofvalue:
698
+	printf("end, tmp=%x, <%c>\n", tmp, *tmp);
699
+	//tmp++;
700
+end:
701
+	*pstate=state;
702
+	*psaved_state=saved_state;
703
+	printf("Found param type %d, <%s> = <%s>\n", param_type, param_name,
704
+			param_value);
705
+	return tmp;
706
+
707
+error:
708
+	fprintf(stderr,"error: via_parse_param\n");
709
+	*pstate=state;
710
+	*psaved_state=saved_state;
711
+	return tmp;
712
+}
713
+
714
+
715
+
716
+
717
+
718
+
42 719
 int main(int argc, char** argv)
43 720
 {
44 721
 
45 722
 	char* tmp;
46
-	register int state;
723
+	int state;
47 724
 	int saved_state;
48 725
 	int c_nest;
49 726
 	int i;
... ...
@@ -779,8 +1457,25 @@ main_via:
779 779
 						/*check if number?*/
780 780
 						break;
781 781
 					case F_PARAM:
782
-						state=P_PARAM;
782
+						/*state=P_PARAM*/;
783 783
 						param=tmp;
784
+						tmp=parse_via_param(tmp, &state, &saved_state);
785
+						switch(state){
786
+							case L_PARAM:
787
+							case F_PARAM:
788
+							case F_LF:
789
+							case F_CR:
790
+								break;
791
+							case END_OF_HEADER:
792
+								state=saved_state;
793
+								goto endofheader;
794
+							default:
795
+								LOG(L_ERR, "ERROR: parse_via after"
796
+										" parse_via_param: invalid"
797
+										" char <%c> on state %d\n",
798
+										*tmp, state);
799
+								goto error;
800
+						}
784 801
 						break;
785 802
 					case P_PARAM:
786 803
 						break;
... ...
@@ -839,6 +1534,9 @@ endofpacket:
839 839
 		case P_PORT:
840 840
 		case L_PARAM:
841 841
 		case P_PARAM:
842
+		case P_VALUE:
843
+		case GEN_PARAM:
844
+		case FIN_HIDDEN:
842 845
 		case L_VIA:
843 846
 			break;
844 847
 		default:
... ...
@@ -848,7 +1546,7 @@ endofpacket:
848 848
 	}
849 849
 		
850 850
 nextvia:
851
-	if (proto) printf("<SIP/2.0/%s<\n", proto);
851
+	if (proto) printf("<SIP/2.0/%s>\n", proto);
852 852
 	if (host) printf("host= <%s>\n", host);
853 853
 	if (port_str) printf("port= <%s>\n", port_str);
854 854
 	if (param) printf("params= <%s>\n", param);