Browse code

TM callbacks, acc, flags

Jiri Kuthan authored on 13/05/2002 01:15:40
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1779 +0,0 @@
1
-/*
2
- * $Id$ 
3
- *
4
- * via parsing automaton
5
- * 
6
- */
7
-
8
-/* parsing:           compact form:
9
- */
10
-
11
-/* 
12
- * still TODO/test:
13
- *  x parse next via
14
- *  - return a list of header structs
15
- *  - return list of params
16
- */
17
-
18
-
19
-
20
-#include <stdlib.h>
21
-#include <string.h>
22
-#include "dprint.h"
23
-#include "msg_parser.h"
24
-#include "ut.h"
25
-#include "mem/mem.h"
26
-
27
-
28
-
29
-/* main via states (uri:port ...) */
30
-enum{	         F_HOST,    P_HOST,
31
-		L_PORT,  F_PORT,    P_PORT,
32
-		L_PARAM, F_PARAM,   P_PARAM,
33
-		L_VIA,   F_VIA,
34
-		         F_COMMENT, P_COMMENT,
35
-				 F_IP6HOST, P_IP6HOST,
36
-				 F_CRLF,
37
-				 F_LF,
38
-				 F_CR,
39
-				 END_OF_HEADER
40
-	};
41
-
42
-/* first via part state */
43
-enum{	         F_SIP=100,
44
-		SIP1, SIP2, FIN_SIP,
45
-		L_VER, F_VER,
46
-		VER1, VER2, FIN_VER,
47
-		L_PROTO, F_PROTO, P_PROTO
48
-	};
49
-
50
-/* param related states
51
- * WARNING: keep the FIN*, GEN_PARAM & PARAM_ERROR in sync w/ PARAM_* from
52
- * msg_parser.h !*/
53
-enum{	L_VALUE=200,   F_VALUE, P_VALUE, P_STRING,
54
-		HIDDEN1,   HIDDEN2,   HIDDEN3,   HIDDEN4,   HIDDEN5,
55
-		TTL1,      TTL2,
56
-		BRANCH1,   BRANCH2,   BRANCH3,   BRANCH4,   BRANCH5,
57
-		MADDR1,    MADDR2,    MADDR3,    MADDR4,
58
-		RECEIVED1, RECEIVED2, RECEIVED3, RECEIVED4, RECEIVED5, RECEIVED6,
59
-		RECEIVED7,
60
-		/* fin states (227-...)*/
61
-		FIN_HIDDEN=230, FIN_TTL, FIN_BRANCH, FIN_MADDR, FIN_RECEIVED,
62
-		/*GEN_PARAM,
63
-		PARAM_ERROR*/ /* declared in msg_parser.h*/
64
-	};
65
-
66
-
67
-
68
-/* entry state must be F_PARAM, or saved_state=F_PARAM and
69
- * state=F_{LF,CR,CRLF}!
70
- * output state = L_PARAM or F_PARAM or END_OF_HEADER
71
- * (and saved_state= last state); everything else => error */
72
-char* parse_via_param(	char* p, char* end, int* pstate, 
73
-								int* psaved_state, struct via_param* param)
74
-{
75
-	char* tmp;
76
-	register int state;
77
-	int saved_state;
78
-
79
-	state=*pstate;
80
-	saved_state=*psaved_state;
81
-	param->type=PARAM_ERROR;
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
-						param->name.len=tmp-param->name.s;
92
-						state=L_PARAM;
93
-						goto endofparam;
94
-					case FIN_BRANCH:
95
-					case FIN_TTL:
96
-					case FIN_MADDR:
97
-					case FIN_RECEIVED:
98
-						*tmp=0;
99
-						param->type=state;
100
-						param->name.len=tmp-param->name.s;
101
-						state=L_VALUE;
102
-						goto find_value;
103
-					case F_PARAM:
104
-						break;
105
-					case F_LF:
106
-					case F_CR:
107
-					case F_CRLF:
108
-						state=saved_state;
109
-						break;
110
-					case GEN_PARAM:
111
-					default:
112
-						*tmp=0;
113
-						param->type=GEN_PARAM;
114
-						param->name.len=tmp-param->name.s;
115
-						state=L_VALUE;
116
-						goto find_value;
117
-				}
118
-				break;
119
-			/* \n and \r*/
120
-			case '\n':
121
-				switch(state){
122
-					case FIN_HIDDEN:
123
-						*tmp=0;
124
-						param->type=state;
125
-						param->name.len=tmp-param->name.s;
126
-						saved_state=L_PARAM;
127
-						state=F_LF;
128
-						goto endofparam;
129
-					case FIN_BRANCH:
130
-					case FIN_TTL:
131
-					case FIN_MADDR:
132
-					case FIN_RECEIVED:
133
-						*tmp=0;
134
-						param->type=state;
135
-						param->name.len=tmp-param->name.s;
136
-						saved_state=L_VALUE;
137
-						state=F_LF;
138
-						goto find_value;
139
-					case F_PARAM:
140
-						saved_state=state;
141
-						state=F_LF;
142
-						break;
143
-					case F_LF:
144
-					case F_CRLF:
145
-						state=END_OF_HEADER;
146
-						goto end_via;
147
-					case F_CR:
148
-						state=F_CRLF;
149
-						break;
150
-					case GEN_PARAM:
151
-					default:
152
-						*tmp=0;
153
-						param->type=GEN_PARAM;
154
-						saved_state=L_VALUE;
155
-						param->name.len=tmp-param->name.s;
156
-						state=F_LF;
157
-						goto find_value;
158
-				}
159
-				break;
160
-			case '\r':
161
-				switch(state){
162
-					case FIN_HIDDEN:
163
-						*tmp=0;
164
-						param->type=state;
165
-						param->name.len=tmp-param->name.s;
166
-						saved_state=L_PARAM;
167
-						state=F_CR;
168
-						goto endofparam;
169
-					case FIN_BRANCH:
170
-					case FIN_TTL:
171
-					case FIN_MADDR:
172
-					case FIN_RECEIVED:
173
-						*tmp=0;
174
-						param->type=state;
175
-						param->name.len=tmp-param->name.s;
176
-						saved_state=L_VALUE;
177
-						state=F_CR;
178
-						goto find_value;
179
-					case F_PARAM:
180
-						saved_state=state;
181
-						state=F_CR;
182
-						break;
183
-					case F_CR:
184
-					case F_CRLF:
185
-						state=END_OF_HEADER;
186
-						goto end_via;
187
-					case GEN_PARAM:
188
-					default:
189
-						*tmp=0;
190
-						param->type=GEN_PARAM;
191
-						param->name.len=tmp-param->name.s;
192
-						saved_state=L_VALUE;
193
-						state=F_CR;
194
-						goto find_value;
195
-				}
196
-				break;
197
-
198
-			case '=':
199
-				switch(state){
200
-					case FIN_BRANCH:
201
-					case FIN_TTL:
202
-					case FIN_MADDR:
203
-					case FIN_RECEIVED:
204
-						*tmp=0;
205
-						param->type=state;
206
-						param->name.len=tmp-param->name.s;
207
-						state=F_VALUE;
208
-						goto find_value;
209
-					case F_PARAM:
210
-					case FIN_HIDDEN:
211
-						LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
212
-								" state %d\n", *tmp, state);
213
-						goto error;
214
-					case F_CR:
215
-					case F_LF:
216
-					case F_CRLF:
217
-						state=END_OF_HEADER;
218
-						goto end_via;
219
-					case GEN_PARAM:
220
-					default:
221
-						*tmp=0;
222
-						param->type=GEN_PARAM;
223
-						param->name.len=tmp-param->name.s;
224
-						state=F_VALUE;
225
-						goto find_value;
226
-				}
227
-				break;
228
-			case ';':
229
-				switch(state){
230
-					case FIN_HIDDEN:
231
-						*tmp=0;
232
-						param->type=state;
233
-						param->name.len=tmp-param->name.s;
234
-						state=F_PARAM;
235
-						goto endofparam;
236
-					case FIN_BRANCH:
237
-					case FIN_MADDR:
238
-					case FIN_TTL:
239
-					case FIN_RECEIVED:
240
-						LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
241
-								" state %d\n", *tmp, state);
242
-						goto error;
243
-					case F_CR:
244
-					case F_LF:
245
-					case F_CRLF:
246
-						state=END_OF_HEADER;
247
-						goto end_via;
248
-					case GEN_PARAM:
249
-					default:
250
-						*tmp=0;
251
-						param->type=GEN_PARAM;
252
-						param->name.len=tmp-param->name.s;
253
-						state=F_PARAM;
254
-						goto endofparam;
255
-				}
256
-				break;
257
-			case ',':
258
-				switch(state){
259
-					case FIN_HIDDEN:
260
-						*tmp=0;
261
-						param->type=state;
262
-						param->name.len=tmp-param->name.s;
263
-						state=F_VIA;
264
-						goto endofvalue;
265
-					case FIN_BRANCH:
266
-					case FIN_MADDR:
267
-					case FIN_TTL:
268
-					case FIN_RECEIVED:
269
-						LOG(L_ERR, "ERROR: parse_via_param: new via found" 
270
-								"(',') when '=' expected (state %d=)\n",
271
-								state);
272
-						goto error; /* or we could ignore this bad param*/
273
-					case F_CR:
274
-					case F_LF:
275
-					case F_CRLF:
276
-						state=END_OF_HEADER;
277
-						goto end_via;
278
-					case GEN_PARAM:
279
-					default:
280
-						*tmp=0;
281
-						param->type=GEN_PARAM;
282
-						param->name.len=tmp-param->name.s;
283
-						state=F_VIA;
284
-						goto endofvalue;
285
-				}
286
-				break; 
287
-
288
-				/* param names */
289
-			case 'h':
290
-			case 'H':
291
-				switch(state){
292
-					case F_PARAM:
293
-						state=HIDDEN1;
294
-						param->name.s=tmp;
295
-						break;
296
-					case BRANCH5:
297
-						state=FIN_BRANCH;
298
-						break;
299
-					case GEN_PARAM:
300
-						break;
301
-					case F_CR:
302
-					case F_LF:
303
-					case F_CRLF:
304
-						state=END_OF_HEADER;
305
-						goto end_via;
306
-					default:
307
-						state=GEN_PARAM;
308
-				}
309
-				break;
310
-			case 'i':
311
-			case 'I':
312
-				switch(state){
313
-					case F_PARAM:
314
-						state=GEN_PARAM;
315
-						param->name.s=tmp;
316
-						break;
317
-					case HIDDEN1:
318
-						state=HIDDEN2;
319
-						break;
320
-					case RECEIVED4:
321
-						state=RECEIVED5;
322
-						break;
323
-					case GEN_PARAM:
324
-						break;
325
-					case F_CR:
326
-					case F_LF:
327
-					case F_CRLF:
328
-						state=END_OF_HEADER;
329
-						goto end_via;
330
-					default:
331
-						state=GEN_PARAM;
332
-				}
333
-				break;
334
-			case 'd':
335
-			case 'D':
336
-				switch(state){
337
-					case F_PARAM:
338
-						state=GEN_PARAM;
339
-						param->name.s=tmp;
340
-						break;
341
-					case HIDDEN2:
342
-						state=HIDDEN3;
343
-						break;
344
-					case HIDDEN3:
345
-						state=HIDDEN4;
346
-						break;
347
-					case MADDR2:
348
-						state=MADDR3;
349
-						break;
350
-					case MADDR3:
351
-						state=MADDR4;
352
-						break;
353
-					case RECEIVED7:
354
-						state=FIN_RECEIVED;
355
-						break;
356
-					case GEN_PARAM:
357
-						break;
358
-					case F_CR:
359
-					case F_LF:
360
-					case F_CRLF:
361
-						state=END_OF_HEADER;
362
-						goto end_via;
363
-					default:
364
-						state=GEN_PARAM;
365
-				}
366
-				break;
367
-			case 'e':
368
-			case 'E':
369
-				switch(state){
370
-					case F_PARAM:
371
-						state=GEN_PARAM;
372
-						param->name.s=tmp;
373
-						break;
374
-					case HIDDEN4:
375
-						state=HIDDEN5;
376
-						break;
377
-					case RECEIVED1:
378
-						state=RECEIVED2;
379
-						break;
380
-					case RECEIVED3:
381
-						state=RECEIVED4;
382
-						break;
383
-					case RECEIVED6:
384
-						state=RECEIVED7;
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 'n':
398
-			case 'N':
399
-				switch(state){
400
-					case F_PARAM:
401
-						state=GEN_PARAM;
402
-						param->name.s=tmp;
403
-						break;
404
-					case HIDDEN5:
405
-						state=FIN_HIDDEN;
406
-						break;
407
-					case BRANCH3:
408
-						state=BRANCH4;
409
-						break;
410
-					case GEN_PARAM:
411
-						break;
412
-					case F_CR:
413
-					case F_LF:
414
-					case F_CRLF:
415
-						state=END_OF_HEADER;
416
-						goto end_via;
417
-					default:
418
-						state=GEN_PARAM;
419
-				}
420
-				break;
421
-			case 't':
422
-			case 'T':
423
-				switch(state){
424
-					case F_PARAM:
425
-						state=TTL1;
426
-						param->name.s=tmp;
427
-						break;
428
-					case TTL1:
429
-						state=TTL2;
430
-						break;
431
-					case GEN_PARAM:
432
-						break;
433
-					case F_CR:
434
-					case F_LF:
435
-					case F_CRLF:
436
-						state=END_OF_HEADER;
437
-						goto end_via;
438
-					default:
439
-						state=GEN_PARAM;
440
-				}
441
-				break;
442
-			case 'l':
443
-			case 'L':
444
-				switch(state){
445
-					case F_PARAM:
446
-						state=GEN_PARAM;
447
-						param->name.s=tmp;
448
-						break;
449
-					case TTL2:
450
-						state=FIN_TTL;
451
-						break;
452
-					case GEN_PARAM:
453
-						break;
454
-					case F_CR:
455
-					case F_LF:
456
-					case F_CRLF:
457
-						state=END_OF_HEADER;
458
-						goto end_via;
459
-					default:
460
-						state=GEN_PARAM;
461
-				}
462
-				break;
463
-			case 'm':
464
-			case 'M':
465
-				switch(state){
466
-					case F_PARAM:
467
-						state=MADDR1;
468
-						param->name.s=tmp;
469
-						break;
470
-					case GEN_PARAM:
471
-						break;
472
-					case F_CR:
473
-					case F_LF:
474
-					case F_CRLF:
475
-						state=END_OF_HEADER;
476
-						goto end_via;
477
-					default:
478
-						state=GEN_PARAM;
479
-				}
480
-				break;
481
-			case 'a':
482
-			case 'A':
483
-				switch(state){
484
-					case F_PARAM:
485
-						state=GEN_PARAM;
486
-						param->name.s=tmp;
487
-						break;
488
-					case MADDR1:
489
-						state=MADDR2;
490
-						break;
491
-					case BRANCH2:
492
-						state=BRANCH3;
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_via;
501
-					default:
502
-						state=GEN_PARAM;
503
-				}
504
-				break;
505
-			case 'r':
506
-			case 'R':
507
-				switch(state){
508
-					case MADDR4:
509
-						state=FIN_MADDR;
510
-						break;
511
-					case F_PARAM:
512
-						state=RECEIVED1;
513
-						param->name.s=tmp;
514
-						break;
515
-					case BRANCH1:
516
-						state=BRANCH2;
517
-						break;
518
-					case GEN_PARAM:
519
-						break;
520
-					case F_CR:
521
-					case F_LF:
522
-					case F_CRLF:
523
-						state=END_OF_HEADER;
524
-						goto end_via;
525
-					default:
526
-						state=GEN_PARAM;
527
-				}
528
-				break;
529
-			case 'c':
530
-			case 'C':
531
-				switch(state){
532
-					case F_PARAM:
533
-						state=GEN_PARAM;
534
-						param->name.s=tmp;
535
-						break;
536
-					case RECEIVED2:
537
-						state=RECEIVED3;
538
-						break;
539
-					case BRANCH4:
540
-						state=BRANCH5;
541
-						break;
542
-					case GEN_PARAM:
543
-						break;
544
-					case F_CR:
545
-					case F_LF:
546
-					case F_CRLF:
547
-						state=END_OF_HEADER;
548
-						goto end_via;
549
-					default:
550
-						state=GEN_PARAM;
551
-				}
552
-				break;
553
-			case 'v':
554
-			case 'V':
555
-				switch(state){
556
-					case F_PARAM:
557
-						state=GEN_PARAM;
558
-						param->name.s=tmp;
559
-						break;
560
-					case RECEIVED5:
561
-						state=RECEIVED6;
562
-						break;
563
-					case GEN_PARAM:
564
-						break;
565
-					case F_CR:
566
-					case F_LF:
567
-					case F_CRLF:
568
-						state=END_OF_HEADER;
569
-						goto end_via;
570
-					default:
571
-						state=GEN_PARAM;
572
-				}
573
-				break;
574
-			case 'b':
575
-			case 'B':
576
-				switch(state){
577
-					case F_PARAM:
578
-						state=BRANCH1;
579
-						param->name.s=tmp;
580
-						break;
581
-					case GEN_PARAM:
582
-						break;
583
-					case F_CR:
584
-					case F_LF:
585
-					case F_CRLF:
586
-						state=END_OF_HEADER;
587
-						goto end_via;
588
-					default:
589
-						state=GEN_PARAM;
590
-				}
591
-				break;
592
-
593
-			default:
594
-				switch(state){
595
-					case F_PARAM:
596
-						state=GEN_PARAM;
597
-						param->name.s=tmp;
598
-						break;
599
-					case  GEN_PARAM:
600
-						break;
601
-					case F_CR:
602
-					case F_LF:
603
-					case F_CRLF:
604
-						state=END_OF_HEADER;
605
-						goto end_via;
606
-					default:
607
-						state=GEN_PARAM;
608
-				}
609
-		}
610
-	}/* for tmp*/
611
-
612
-/* end of packet? => error, no cr/lf,',' found!!!*/
613
-saved_state=state;
614
-state=END_OF_HEADER;
615
-goto error;
616
-
617
-find_value:
618
-	tmp++;
619
-	for(;*tmp;tmp++){
620
-		switch(*tmp){
621
-			case ' ':
622
-			case '\t':
623
-				switch(state){
624
-					case L_VALUE:
625
-					case F_VALUE: /*eat space*/
626
-						break; 
627
-					case P_VALUE:
628
-						*tmp=0;
629
-						state=L_PARAM;
630
-						param->value.len=tmp-param->value.s;
631
-						goto endofvalue;
632
-					case P_STRING:
633
-						break;
634
-					case F_CR:
635
-					case F_LF:
636
-					case F_CRLF:
637
-						state=saved_state;
638
-						break;
639
-					default:
640
-						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
641
-								" in state %d\n", *tmp, state);
642
-						goto error;
643
-				}
644
-				break;
645
-			case '\n':
646
-				switch(state){
647
-					case L_VALUE:
648
-					case F_VALUE: /*eat space*/
649
-					case P_STRING:
650
-						saved_state=state;
651
-						state=F_LF;
652
-						break;
653
-					case P_VALUE:
654
-						*tmp=0;
655
-						saved_state=L_PARAM;
656
-						state=F_LF;
657
-						param->value.len=tmp-param->value.s;
658
-						goto endofvalue;
659
-					case F_LF:
660
-					case F_CRLF:
661
-						state=END_OF_HEADER;
662
-						goto end_via;
663
-					case F_CR:
664
-						state=F_CRLF;
665
-						break;
666
-					default:
667
-						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
668
-								" in state %d\n", *tmp, state);
669
-						goto error;
670
-				}
671
-				break;
672
-			case '\r':
673
-				switch(state){
674
-					case L_VALUE:
675
-					case F_VALUE: /*eat space*/
676
-					case P_STRING:
677
-						saved_state=state;
678
-						state=F_CR;
679
-						break;
680
-					case P_VALUE:
681
-						*tmp=0;
682
-						param->value.len=tmp-param->value.s;
683
-						saved_state=L_PARAM;
684
-						state=F_CR;
685
-						goto endofvalue;
686
-					case F_LF:
687
-					case F_CR:
688
-					case F_CRLF:
689
-						state=END_OF_HEADER;
690
-						goto end_via;
691
-					default:
692
-						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
693
-								" in state %d\n", *tmp, state);
694
-						goto error;
695
-				}
696
-				break;
697
-
698
-			case '=':
699
-				switch(state){
700
-					case L_VALUE:
701
-						state=F_VALUE;
702
-						break;
703
-					case P_STRING:
704
-						break;
705
-					case F_LF:
706
-					case F_CR:
707
-					case F_CRLF:
708
-						state=END_OF_HEADER;
709
-						goto end_via;
710
-					default:
711
-						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
712
-								" in state %d\n", *tmp, state);
713
-						goto error;
714
-				}
715
-				break;
716
-			case ';':
717
-				switch(state){
718
-					case P_VALUE:
719
-						*tmp=0;
720
-						param->value.len=tmp-param->value.s;
721
-						state=F_PARAM;
722
-						goto endofvalue;
723
-					case P_STRING:
724
-						break; /* what to do? */
725
-					case F_LF:
726
-					case F_CR:
727
-					case F_CRLF:
728
-						state=END_OF_HEADER;
729
-						goto end_via;
730
-					default:
731
-						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
732
-								" in state %d\n", *tmp, state);
733
-						goto error;
734
-				}
735
-				break;
736
-			case ',':
737
-				switch(state){
738
-					case P_VALUE:
739
-						*tmp=0;
740
-						param->value.len=tmp-param->value.s;
741
-						state=F_VIA;
742
-						goto endofvalue;
743
-					case P_STRING:
744
-						case F_LF:
745
-					case F_CR:
746
-					case F_CRLF:
747
-						state=END_OF_HEADER;
748
-						goto end_via;
749
-					default:
750
-						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
751
-								" in state %d\n", *tmp, state);
752
-						goto error;
753
-				}
754
-				break; /* what to do? */
755
-			case '"':
756
-				switch(state){
757
-					case F_VALUE:
758
-						state=P_STRING;
759
-						param->value.s=tmp+1;
760
-						break;
761
-					case P_STRING:
762
-						*tmp=0;
763
-						state=L_PARAM;
764
-						param->value.len=tmp-param->value.s;
765
-						goto endofvalue;
766
-					case F_LF:
767
-					case F_CR:
768
-					case F_CRLF:
769
-						state=END_OF_HEADER;
770
-						goto end_via;
771
-					default:
772
-						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
773
-								" in state %d\n", *tmp, state);
774
-						goto error;
775
-				}
776
-				break;
777
-			default:
778
-				switch(state){
779
-					case F_VALUE:
780
-						state=P_VALUE;
781
-						param->value.s=tmp;
782
-						break;
783
-					case P_VALUE:
784
-					case P_STRING:
785
-						break;
786
-					case F_LF:
787
-					case F_CR:
788
-					case F_CRLF:
789
-						state=END_OF_HEADER;
790
-						goto end_via;
791
-					default:
792
-						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
793
-								" in state %d\n", *tmp, state);
794
-						goto error;
795
-				}
796
-		}
797
-	} /* for2 tmp*/
798
-
799
-	/* end of buff and no CR/LF =>error*/
800
-saved_state=state;
801
-state=END_OF_HEADER;
802
-goto error;
803
-
804
-endofparam:
805
-endofvalue:
806
-	param->size=tmp-p;
807
-	*pstate=state;
808
-	*psaved_state=saved_state;
809
-	DBG("Found param type %d, <%s> = <%s>; state=%d\n", param->type,
810
-			param->name.s, param->value.s, state);
811
-	return tmp;
812
-
813
-end_via:
814
-	/* if we are here we found an "unexpected" end of via
815
-	 *  (cr/lf). This is valid only if the param type is GEN_PARAM*/
816
-	if (param->type==GEN_PARAM){
817
-		saved_state=L_PARAM; /* change the saved_state, we have an unknown
818
-		                        param. w/o a value */
819
-		goto endofparam;
820
-	}
821
-	*pstate=state;
822
-	*psaved_state=saved_state;
823
-	DBG("Error on  param type %d, <%s>, state=%d, saved_state=%d\n",
824
-		param->type, param->name.s, state, saved_state);
825
-
826
-error:
827
-	LOG(L_ERR, "error: parse_via_param\n");
828
-	param->type=PARAM_ERROR;
829
-	*pstate=PARAM_ERROR;
830
-	*psaved_state=state;
831
-	return tmp;
832
-}
833
-
834
-
835
-
836
-char* parse_via(char* buffer, char* end, struct via_body *vb)
837
-{
838
-
839
-	char* tmp;
840
-	int state;
841
-	int saved_state;
842
-	int c_nest;
843
-	int err;
844
-
845
-	struct via_param* param;
846
-
847
-parse_again:
848
-	vb->error=VIA_PARSE_ERROR;
849
-	/* parse start of via ( SIP/2.0/UDP    )*/
850
-	state=F_SIP;
851
-	for(tmp=buffer;tmp<end;tmp++){
852
-		switch(*tmp){
853
-			case ' ':
854
-			case'\t':
855
-				switch(state){
856
-					case L_VER: /* eat space */
857
-					case L_PROTO:
858
-					case F_SIP:
859
-					case F_VER:
860
-					case F_PROTO:
861
-						break;
862
-					case P_PROTO:
863
-						*tmp=0;  /* finished proto parsing */
864
-						vb->transport.len=tmp-vb->transport.s;
865
-						state=F_HOST; /* start looking for host*/
866
-						goto main_via;
867
-					case FIN_SIP:
868
-						*tmp=0;
869
-						vb->name.len=tmp-vb->name.s;
870
-						state=L_VER;
871
-						break;
872
-					case FIN_VER:
873
-						*tmp=0;
874
-						vb->version.len=tmp-vb->version.s;
875
-						state=L_PROTO;
876
-						break;
877
-					case F_LF:
878
-					case F_CRLF:
879
-					case F_CR: /* header continues on this line */
880
-						state=saved_state;
881
-						break;
882
-					default:
883
-						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
884
-								" state %d\n", *tmp, state);
885
-						goto error;
886
-				}
887
-				break;
888
-			case '\n':
889
-				switch(state){
890
-					case L_VER:
891
-					case F_SIP:
892
-					case F_VER:
893
-					case F_PROTO:
894
-					case L_PROTO:
895
-						saved_state=state;
896
-						state=F_LF;
897
-						break;
898
-					case P_PROTO:
899
-						*tmp=0;
900
-						vb->transport.len=tmp-vb->transport.s;
901
-						state=F_LF;
902
-						saved_state=F_HOST; /* start looking for host*/
903
-						goto main_via;
904
-					case FIN_SIP:
905
-						*tmp=0;
906
-						vb->name.len=tmp-vb->name.s;
907
-						state=F_LF;
908
-						saved_state=L_VER;
909
-						break;
910
-					case FIN_VER: