2b078c8475871c34d5b0d6da80d0ad724490aa39
[sip-router] / test / via_parse.c
1
2 /* test program -> via parse */
3
4
5 /* parsing:           compact form:
6  */
7
8 /* 
9  * still TODO/test:
10  *  - parse next via
11  *  - return a list of header structs
12  *  - '[' ']' ipv6 parsing!
13  *  - return list of params
14  *  - test ^\s...'
15  *  - add support for parsing via front (SIP/2.0/UDP)
16  */
17
18 #include <stdio.h>
19
20 /* main via states (uri:port ...) */
21 enum{            F_HOST,    P_HOST,
22                 L_PORT,  F_PORT,    P_PORT,
23                 L_PARAM, F_PARAM,   P_PARAM,
24                 L_VIA,   F_VIA,
25                          F_COMMENT, P_COMMENT,
26                                  F_IP6HOST, P_IP6HOST,
27                                  F_CRLF,
28                                  F_LF,
29                                  F_CR,
30                                  END_OF_HEADER
31         };
32
33 /* first via part state */
34 enum{            F_SIP=100,
35                 SIP1, SIP2, FIN_SIP,
36                 L_VER, F_VER,
37                 VER1, VER2, FIN_VER,
38                 L_PROTO, F_PROTO, P_PROTO
39         };
40
41 /* param realated states */
42 enum{   L_VALUE=200,   F_VALUE, P_VALUE, P_STRING,
43                 HIDDEN1,   HIDDEN2,   HIDDEN3,   HIDDEN4,   HIDDEN5,
44                 TTL1,      TTL2,
45                 BRANCH1,   BRANCH2,   BRANCH3,   BRANCH4,   BRANCH5,
46                 MADDR1,    MADDR2,    MADDR3,    MADDR4,
47                 RECEIVED1, RECEIVED2, RECEIVED3, RECEIVED4, RECEIVED5, RECEIVED6,
48                 RECEIVED7,
49                 /* fin states (227-...)*/
50                 FIN_HIDDEN, FIN_TTL, FIN_BRANCH, FIN_MADDR, FIN_RECEIVED,
51                 GEN_PARAM
52         };
53
54 #define LOG(lev, fmt, args...) fprintf(stderr, fmt, ## args)
55
56
57 /* entry state must be F_PARAM, or saved_state=F_PARAM and 
58  * state=F_{LF,CR,CRLF}!
59  * output state = L_PARAM or F_PARAM or END_OF_HEADER 
60  * (and saved_state= last state); everything else => error */
61 __inline char* parse_via_param(char* p, int* pstate, int* psaved_state)
62 {
63         char* tmp;
64         register int state;
65         int saved_state;
66         int param_type;
67         char* param_name;
68         char* param_value;
69         
70         state=*pstate;
71         saved_state=*psaved_state;
72         param_name=param_value=0;
73         param_type=0;
74         
75         for (tmp=p;*tmp;tmp++){
76                 switch(*tmp){
77                         case ' ':
78                         case '\t':
79                                 switch(state){
80                                         case FIN_HIDDEN:
81                                                 *tmp=0;
82                                                 param_type=state;
83                                                 state=L_PARAM;
84                                                 goto endofparam;
85                                         case FIN_BRANCH:
86                                         case FIN_TTL:
87                                         case FIN_MADDR:
88                                         case FIN_RECEIVED:
89                                                 *tmp=0;
90                                                 param_type=state;
91                                                 state=L_VALUE;
92                                                 goto find_value;
93                                         case F_PARAM:
94                                                 break;
95                                         case F_LF:
96                                         case F_CR:
97                                         case F_CRLF:
98                                                 state=saved_state;
99                                                 break;
100                                         case GEN_PARAM:
101                                         default:
102                                                 *tmp=0;
103                                                 param_type=GEN_PARAM;
104                                                 state=L_VALUE;
105                                                 goto find_value;
106                                 }
107                                 break;
108                         /* \n and \r*/
109                         case '\n':
110                                 switch(state){
111                                         case FIN_HIDDEN:
112                                                 *tmp=0;
113                                                 param_type=state;
114                                                 saved_state=L_PARAM;
115                                                 state=F_LF;
116                                                 goto endofparam;
117                                         case FIN_BRANCH:
118                                         case FIN_TTL:
119                                         case FIN_MADDR:
120                                         case FIN_RECEIVED:
121                                                 *tmp=0;
122                                                 param_type=state;
123                                                 saved_state=L_VALUE;
124                                                 state=F_LF;
125                                                 goto find_value;
126                                         case F_PARAM:
127                                                 saved_state=state;
128                                                 state=F_LF;
129                                                 break;
130                                         case F_LF:
131                                         case F_CRLF:
132                                                 state=END_OF_HEADER;
133                                                 goto end;
134                                         case F_CR:
135                                                 state=F_CRLF;
136                                                 break;
137                                         case GEN_PARAM:
138                                         default:
139                                                 *tmp=0;
140                                                 param_type=GEN_PARAM;
141                                                 saved_state=L_VALUE;
142                                                 state=F_LF;
143                                                 goto find_value;
144                                 }
145                                 break;
146                         case '\r':
147                                 switch(state){
148                                         case FIN_HIDDEN:
149                                                 *tmp=0;
150                                                 param_type=state;
151                                                 saved_state=L_PARAM;
152                                                 state=F_CR;
153                                                 goto endofparam;
154                                         case FIN_BRANCH:
155                                         case FIN_TTL:
156                                         case FIN_MADDR:
157                                         case FIN_RECEIVED:
158                                                 *tmp=0;
159                                                 param_type=state;
160                                                 saved_state=L_VALUE;
161                                                 state=F_CR;
162                                                 goto find_value;
163                                         case F_PARAM:
164                                                 saved_state=state;
165                                                 state=F_CR;
166                                                 break;
167                                         case F_CR:
168                                         case F_CRLF:
169                                                 state=END_OF_HEADER;
170                                                 goto end;
171                                         case GEN_PARAM:
172                                         default:
173                                                 *tmp=0;
174                                                 param_type=GEN_PARAM;
175                                                 saved_state=L_VALUE;
176                                                 state=F_CR;
177                                                 goto find_value;
178                                 }
179                                 break;
180
181                         case '=':
182                                 switch(state){
183                                         case FIN_BRANCH:
184                                         case FIN_TTL:
185                                         case FIN_MADDR:
186                                         case FIN_RECEIVED:
187                                                 *tmp=0;
188                                                 param_type=state;
189                                                 state=F_VALUE;
190                                                 goto find_value;
191                                         case F_PARAM:
192                                         case FIN_HIDDEN:
193                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
194                                                                 " state %d\n");
195                                                 goto error;
196                                         case F_CR:
197                                         case F_LF:
198                                         case F_CRLF:
199                                                 state=END_OF_HEADER;
200                                                 goto end;
201                                         case GEN_PARAM:
202                                         default:
203                                                 *tmp=0;
204                                                 param_type=GEN_PARAM;
205                                                 state=F_VALUE;
206                                                 goto find_value;
207                                 }
208                                 break;
209                         case ';':
210                                 switch(state){
211                                         case FIN_HIDDEN:
212                                                 *tmp=0;
213                                                 param_type=state;
214                                                 state=F_PARAM;
215                                                 goto endofparam;
216                                         case FIN_BRANCH:
217                                         case FIN_MADDR:
218                                         case FIN_TTL:
219                                         case FIN_RECEIVED:
220                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
221                                                                 " state %d\n");
222                                                 goto error;
223                                         case F_CR:
224                                         case F_LF:
225                                         case F_CRLF:
226                                                 state=END_OF_HEADER;
227                                                 goto end;
228                                         case GEN_PARAM:
229                                         default:
230                                                 *tmp=0;
231                                                 param_type=GEN_PARAM;
232                                                 state=F_PARAM;
233                                                 goto endofparam;
234                                 }
235                                 break;
236                                 
237                                 /* param names */
238                         case 'h':
239                         case 'H':
240                                 switch(state){
241                                         case F_PARAM:
242                                                 state=HIDDEN1;
243                                                 param_name=tmp;
244                                                 break;
245                                         case GEN_PARAM:
246                                                 break;
247                                         case F_CR:
248                                         case F_LF:
249                                         case F_CRLF:
250                                                 state=END_OF_HEADER;
251                                                 goto end;
252                                         default:
253                                                 state=GEN_PARAM;
254                                 }
255                                 break;
256                         case 'i':
257                         case 'I':
258                                 switch(state){
259                                         case HIDDEN1:
260                                                 state=HIDDEN2;
261                                                 break;
262                                         case RECEIVED4:
263                                                 state=RECEIVED5;
264                                                 break;
265                                         case GEN_PARAM:
266                                                 break;
267                                         case F_CR:
268                                         case F_LF:
269                                         case F_CRLF:
270                                                 state=END_OF_HEADER;
271                                                 goto end;
272                                         default:
273                                                 state=GEN_PARAM;
274                                 }
275                                 break;
276                         case 'd':
277                         case 'D':
278                                 switch(state){
279                                         case HIDDEN2:
280                                                 state=HIDDEN3;
281                                                 break;
282                                         case HIDDEN3:
283                                                 state=HIDDEN4;
284                                                 break;
285                                         case MADDR2:
286                                                 state=MADDR3;
287                                                 break;
288                                         case MADDR3:
289                                                 state=MADDR4;
290                                                 break;
291                                         case RECEIVED7:
292                                                 state=FIN_RECEIVED;
293                                                 break;
294                                         case GEN_PARAM:
295                                                 break;
296                                         case F_CR:
297                                         case F_LF:
298                                         case F_CRLF:
299                                                 state=END_OF_HEADER;
300                                                 goto end;
301                                         default:
302                                                 state=GEN_PARAM;
303                                 }
304                                 break;
305                         case 'e':
306                         case 'E':
307                                 switch(state){
308                                         case HIDDEN4:
309                                                 state=HIDDEN5;
310                                                 break;
311                                         case RECEIVED1:
312                                                 state=RECEIVED2;
313                                                 break;
314                                         case RECEIVED3:
315                                                 state=RECEIVED4;
316                                                 break;
317                                         case RECEIVED6:
318                                                 state=RECEIVED7;
319                                                 break;
320                                         case GEN_PARAM:
321                                                 break;
322                                         case F_CR:
323                                         case F_LF:
324                                         case F_CRLF:
325                                                 state=END_OF_HEADER;
326                                                 goto end;
327                                         default:
328                                                 state=GEN_PARAM;
329                                 }
330                                 break;
331                         case 'n':
332                         case 'N':
333                                 switch(state){
334                                         case HIDDEN5:
335                                                 state=FIN_HIDDEN;
336                                                 break;
337                                         case BRANCH3:
338                                                 state=BRANCH4;
339                                                 break;
340                                         case GEN_PARAM:
341                                                 break;
342                                         case F_CR:
343                                         case F_LF:
344                                         case F_CRLF:
345                                                 state=END_OF_HEADER;
346                                                 goto end;
347                                         default:
348                                                 state=GEN_PARAM;
349                                 }
350                                 break;
351                         case 't':
352                         case 'T':
353                                 switch(state){
354                                         case F_PARAM:
355                                                 state=TTL1;
356                                                 param_name=tmp;
357                                                 break;
358                                         case TTL1:
359                                                 state=TTL2;
360                                                 break;
361                                         case GEN_PARAM:
362                                                 break;
363                                         case F_CR:
364                                         case F_LF:
365                                         case F_CRLF:
366                                                 state=END_OF_HEADER;
367                                                 goto end;
368                                         default:
369                                                 state=GEN_PARAM;
370                                 }
371                                 break;
372                         case 'l':
373                         case 'L':
374                                 switch(state){
375                                         case TTL2:
376                                                 state=FIN_TTL;
377                                                 break;
378                                         case GEN_PARAM:
379                                                 break;
380                                         case F_CR:
381                                         case F_LF:
382                                         case F_CRLF:
383                                                 state=END_OF_HEADER;
384                                                 goto end;
385                                         default:
386                                                 state=GEN_PARAM;
387                                 }
388                                 break;
389                         case 'm':
390                         case 'M':
391                                 switch(state){
392                                         case F_PARAM:
393                                                 state=MADDR1;
394                                                 param_name=tmp;
395                                                 break;
396                                         case GEN_PARAM:
397                                                 break;
398                                         case F_CR:
399                                         case F_LF:
400                                         case F_CRLF:
401                                                 state=END_OF_HEADER;
402                                                 goto end;
403                                         default:
404                                                 state=GEN_PARAM;
405                                 }
406                                 break;
407                         case 'a':
408                         case 'A':
409                                 switch(state){
410                                         case MADDR1:
411                                                 state=MADDR2;
412                                                 break;
413                                         case BRANCH2:
414                                                 state=BRANCH3;
415                                                 break;
416                                         case GEN_PARAM:
417                                                 break;
418                                         case F_CR:
419                                         case F_LF:
420                                         case F_CRLF:
421                                                 state=END_OF_HEADER;
422                                                 goto end;
423                                         default:
424                                                 state=GEN_PARAM;
425                                 }
426                                 break;
427                         case 'r':
428                         case 'R':
429                                 switch(state){
430                                         case MADDR4:
431                                                 state=FIN_MADDR;
432                                                 break;
433                                         case F_PARAM:
434                                                 state=RECEIVED1;
435                                                 param_name=tmp;
436                                                 break;
437                                         case BRANCH1:
438                                                 state=BRANCH2;
439                                                 break;
440                                         case GEN_PARAM:
441                                                 break;
442                                         case F_CR:
443                                         case F_LF:
444                                         case F_CRLF:
445                                                 state=END_OF_HEADER;
446                                                 goto end;
447                                         default:
448                                                 state=GEN_PARAM;
449                                 }
450                                 break;
451                         case 'c':
452                         case 'C':
453                                 switch(state){
454                                         case RECEIVED2:
455                                                 state=RECEIVED3;
456                                                 break;
457                                         case BRANCH4:
458                                                 state=BRANCH5;
459                                                 break;
460                                         case GEN_PARAM:
461                                                 break;
462                                         case F_CR:
463                                         case F_LF:
464                                         case F_CRLF:
465                                                 state=END_OF_HEADER;
466                                                 goto end;
467                                         default:
468                                                 state=GEN_PARAM;
469                                 }
470                                 break;
471                         case 'v':
472                         case 'V':
473                                 switch(state){
474                                         case RECEIVED5:
475                                                 state=RECEIVED6;
476                                                 break;
477                                         case GEN_PARAM:
478                                                 break;
479                                         case F_CR:
480                                         case F_LF:
481                                         case F_CRLF:
482                                                 state=END_OF_HEADER;
483                                                 goto end;
484                                         default:
485                                                 state=GEN_PARAM;
486                                 }
487                                 break;
488                         case 'b':
489                         case 'B':
490                                 switch(state){
491                                         case F_PARAM:
492                                                 state=BRANCH1;
493                                                 param_name=tmp;
494                                                 break;
495                                         case GEN_PARAM:
496                                                 break;
497                                         case F_CR:
498                                         case F_LF:
499                                         case F_CRLF:
500                                                 state=END_OF_HEADER;
501                                                 goto end;
502                                         default:
503                                                 state=GEN_PARAM;
504                                 }
505                                 break;
506
507                         default:
508                                 switch(state){
509                                         case F_PARAM:
510                                                 state=GEN_PARAM;
511                                                 param_name=tmp;
512                                                 break;
513                                         case  GEN_PARAM:
514                                                 break;
515                                         case F_CR:
516                                         case F_LF:
517                                         case F_CRLF:
518                                                 state=END_OF_HEADER;
519                                                 goto end;
520                                         default:
521                                                 state=GEN_PARAM;
522                                 }
523                 }
524         }/* for tmp*/
525
526 /* end of packet?*/
527 saved_state=state;
528 param_type=state;
529 state=END_OF_HEADER;
530 goto end;
531
532 find_value:
533         tmp++;
534         for(tmp;*tmp;tmp++){
535                 switch(*tmp){
536                         case ' ':
537                         case '\t':
538                                 switch(state){
539                                         case L_VALUE:
540                                         case F_VALUE: /*eat space*/
541                                                 break; 
542                                         case P_VALUE:
543                                                 *tmp=0;
544                                                 state=L_PARAM;
545                                                 goto endofvalue;
546                                         case P_STRING:
547                                                 break;
548                                         case F_CR:
549                                         case F_LF:
550                                         case F_CRLF:
551                                                 state=saved_state;
552                                                 break;
553                                         default:
554                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
555                                                                 " in state %d\n", state);
556                                                 goto error;
557                                 }
558                                 break;
559                         case '\n':
560                                 switch(state){
561                                         case L_VALUE:
562                                         case F_VALUE: /*eat space*/
563                                         case P_STRING:
564                                                 saved_state=state;
565                                                 state=F_LF;
566                                                 break; 
567                                         case P_VALUE:
568                                                 *tmp=0;
569                                                 saved_state=L_PARAM;
570                                                 state=F_LF;
571                                                 goto endofvalue;
572                                         case F_LF:
573                                         case F_CRLF:
574                                                 state=END_OF_HEADER;
575                                                 goto end;
576                                         case F_CR:
577                                                 state=F_CRLF;
578                                                 break;
579                                         default:
580                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
581                                                                 " in state %d\n", state);
582                                                 goto error;
583                                 }
584                                 break;
585                         case '\r':
586                                 switch(state){
587                                         case L_VALUE:
588                                         case F_VALUE: /*eat space*/
589                                         case P_STRING:
590                                                 saved_state=state;
591                                                 state=F_CR;
592                                                 break; 
593                                         case P_VALUE:
594                                                 *tmp=0;
595                                                 saved_state=L_PARAM;
596                                                 state=F_CR;
597                                                 goto endofvalue;
598                                         case F_LF:
599                                         case F_CR:
600                                         case F_CRLF:
601                                                 state=END_OF_HEADER;
602                                                 goto end;
603                                         default:
604                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
605                                                                 " in state %d\n", state);
606                                                 goto error;
607                                 }
608                                 break;
609
610                         case '=':
611                                 switch(state){
612                                         case L_VALUE:
613                                                 state=F_VALUE;
614                                                 break;
615                                         case P_STRING:
616                                                 break;
617                                         case F_LF:
618                                         case F_CR:
619                                         case F_CRLF:
620                                                 state=END_OF_HEADER;
621                                                 goto end;
622                                         default:
623                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
624                                                                 " in state %d\n", state);
625                                                 goto error;
626                                 }
627                                 break;
628                         case ';':
629                                 switch(state){
630                                         case P_VALUE:
631                                                 *tmp=0;
632                                                 state=F_PARAM;
633                                                 goto endofvalue;
634                                         case P_STRING:
635                                                 break; /* what to do? */
636                                         case F_LF:
637                                         case F_CR:
638                                         case F_CRLF:
639                                                 state=END_OF_HEADER;
640                                                 goto end;
641                                         default:
642                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
643                                                                 " in state %d\n", state);
644                                                 goto error;
645                                 }
646                                 break;
647                         
648                         case '"':
649                                 switch(state){
650                                         case F_VALUE:
651                                                 state=P_STRING;
652                                                 param_value=tmp+1;
653                                                 break;
654                                         case P_STRING:
655                                                 *tmp=0;
656                                                 state=L_PARAM;
657                                                 goto endofvalue;
658                                         case F_LF:
659                                         case F_CR:
660                                         case F_CRLF:
661                                                 state=END_OF_HEADER;
662                                                 goto end;
663                                         default:
664                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
665                                                                 " in state %d\n", state);
666                                                 goto error;
667                                 }
668                                 break;
669                         default:
670                                 switch(state){
671                                         case F_VALUE:
672                                                 state=P_VALUE;
673                                                 param_value=tmp;
674                                                 break;
675                                         case P_VALUE:
676                                         case P_STRING:
677                                                 break;
678                                         case F_LF:
679                                         case F_CR:
680                                         case F_CRLF:
681                                                 state=END_OF_HEADER;
682                                                 goto end;
683                                         default:
684                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
685                                                                 " in state %d\n", state);
686                                                 goto error;
687                                 }
688                 }
689         } /* for2 tmp*/
690
691         /* if generic_param => it can have no value */
692         if ((state==L_VALUE)&&(param_type==GEN_PARAM)) state=L_PARAM;
693         saved_state=state;
694         state=END_OF_HEADER;
695         goto end;
696
697 endofparam:
698 endofvalue:
699         printf("end, tmp=%x, <%c>\n", tmp, *tmp);
700         //tmp++;
701 end:
702         *pstate=state;
703         *psaved_state=saved_state;
704         printf("Found param type %d, <%s> = <%s>\n", param_type, param_name,
705                         param_value);
706         return tmp;
707
708 error:
709         fprintf(stderr,"error: via_parse_param\n");
710         *pstate=state;
711         *psaved_state=saved_state;
712         return tmp;
713 }
714
715
716
717
718
719
720 int main(int argc, char** argv)
721 {
722
723         char* tmp;
724         int state;
725         int saved_state;
726         int c_nest;
727         int i;
728         int port;
729         char* host;
730         char* port_str;
731         char* param;
732         char* comment;
733         char* next_via;
734         char *proto; /* in fact transport*/
735
736         host=port_str=param=comment=next_via=proto=0;
737
738         printf(" %s (%d)\n", argv[0], argc);
739         if (argc<2){
740                         fprintf(stderr, " no parameters\n");
741                         exit(-1);
742         }
743         
744         /* parse start of via ( SIP/2.0/UDP    )*/
745         state=F_SIP;
746         for(tmp=argv[1];*tmp;tmp++){
747                 switch(*tmp){
748                         case ' ':
749                         case'\t':
750                                 switch(state){
751                                         case L_VER: /* eat space */
752                                         case L_PROTO:
753                                         case F_SIP:
754                                         case F_VER:
755                                         case F_PROTO:
756                                                 break;
757                                         case P_PROTO:
758                                                 *tmp=0;  /* finished proto parsing */
759                                                 state=F_HOST; /* start looking for host*/
760                                                 goto main_via;
761                                         case FIN_SIP:
762                                                 *tmp=0;
763                                                 state=L_VER;
764                                                 break;
765                                         case FIN_VER:
766                                                 *tmp=0;
767                                                 state=L_PROTO;
768                                                 break;
769                                         case F_LF:
770                                         case F_CRLF:
771                                         case F_CR: /* header continues on this line */
772                                                 state=saved_state;
773                                                 break;
774                                         default:
775                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
776                                                                 " state %d\n", *tmp, state);
777                                                 goto error;
778                                 }
779                                 break;
780                         case '\n':
781                                 switch(state){
782                                         case L_VER:
783                                         case F_SIP:
784                                         case F_VER:
785                                         case F_PROTO:
786                                         case L_PROTO:
787                                                 saved_state=state;
788                                                 state=F_LF;
789                                                 break;
790                                         case P_PROTO:
791                                                 *tmp=0;
792                                                 state=F_LF;
793                                                 saved_state=F_HOST; /* start looking for host*/
794                                                 goto main_via;
795                                         case FIN_SIP:
796                                                 *tmp=0;
797                                                 state=F_LF;
798                                                 saved_state=L_VER;
799                                                 break;
800                                         case FIN_VER:
801                                                 *tmp=0;
802                                                 state=F_LF;
803                                                 saved_state=L_PROTO;
804                                                 break;
805                                         case F_CR:
806                                                 state=F_CRLF;
807                                                 break;
808                                         case F_LF:
809                                         case F_CRLF:
810                                                 state=saved_state;
811                                                 goto endofheader;
812                                         default:
813                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
814                                                                 " state %d\n", *tmp, state);
815                                                 goto error;
816                                 }
817                                 break;
818                         case '\r':
819                                 switch(state){
820                                         case L_VER:
821                                         case F_SIP:
822                                         case F_VER:
823                                         case F_PROTO:
824                                         case L_PROTO:
825                                                 saved_state=state;
826                                                 state=F_CR;
827                                                 break;
828                                         case P_PROTO:
829                                                 *tmp=0;
830                                                 state=F_CR;
831                                                 saved_state=F_HOST;
832                                                 goto main_via;
833                                         case FIN_SIP:
834                                                 *tmp=0;
835                                                 state=F_CR;
836                                                 saved_state=L_VER;
837                                                 break;
838                                         case FIN_VER:
839                                                 *tmp=0;
840                                                 state=F_CR;
841                                                 saved_state=L_PROTO;
842                                                 break;
843                                         case F_LF: /*end of line ?next header?*/
844                                         case F_CR:
845                                         case F_CRLF:
846                                                 state=saved_state;
847                                                 goto endofheader;
848                                         default:
849                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
850                                                                 " state %d\n", *tmp, state);
851                                                 goto error;
852                                 }
853                                 break;
854                         
855                         case '/':
856                                 switch(state){
857                                         case FIN_SIP:
858                                                 *tmp=0;
859                                                 state=F_VER;
860                                                 break;
861                                         case FIN_VER:
862                                                 *tmp=0;
863                                                 state=F_PROTO;
864                                                 break;
865                                         case L_VER:
866                                                 state=F_VER;
867                                                 break;
868                                         case L_PROTO:
869                                                 state=F_PROTO;
870                                                 break;
871                                         default:
872                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
873                                                                 " state %d\n", *tmp, state);
874                                                 goto error;
875                                 }
876                                 break;
877                                 /* match SIP*/
878                         case 'S':
879                         case 's':
880                                 switch(state){
881                                         case F_SIP:
882                                                 state=SIP1;
883                                                 break;
884                                         /* allow S in PROTO */
885                                         case F_PROTO:
886                                                 proto=tmp;
887                                                 state=P_PROTO;
888                                                 break;
889                                         case P_PROTO:
890                                                 break;
891                                         default:
892                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
893                                                                 " state %d\n", *tmp, state);
894                                                 goto error;
895                                 }
896                                 break;
897                         case 'I':
898                         case 'i':
899                                 switch(state){
900                                         case SIP1:
901                                                 state=SIP2;
902                                                 break;
903                                         /* allow i in PROTO */
904                                         case F_PROTO:
905                                                 proto=tmp;
906                                                 state=P_PROTO;
907                                                 break;
908                                         case P_PROTO:
909                                                 break;
910                                         default:
911                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
912                                                                 " state %d\n", *tmp, state);
913                                                 goto error;
914                                 }
915                                 break;
916                         case 'p':
917                         case 'P':
918                                 switch(state){
919                                         case SIP2:
920                                                 state=FIN_SIP;
921                                                 break;
922                                         /* allow p in PROTO */
923                                         case F_PROTO:
924                                                 proto=tmp;
925                                                 state=P_PROTO;
926                                                 break;
927                                         case P_PROTO:
928                                                 break;
929                                         default:
930                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
931                                                                 " state %d\n", *tmp, state);
932                                                 goto error;
933                                 }
934                                 break;
935                         /*match 2.0*/
936                         case '2':
937                                 switch(state){
938                                         case F_VER:
939                                                 state=VER1;
940                                                 break;
941                                         /* allow 2 in PROTO*/
942                                         case F_PROTO:
943                                                 proto=tmp;
944                                                 state=P_PROTO;
945                                                 break;
946                                         case P_PROTO:
947                                                 break;
948                                         default:
949                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
950                                                                 " state %d\n", *tmp, state);
951                                                 goto error;
952                                 }
953                                 break;
954                         case '.':
955                                 switch(state){
956                                         case VER1:
957                                                 state=VER2;
958                                                 break;
959                                         /* allow . in PROTO */
960                                         case F_PROTO:
961                                                 proto=tmp;
962                                                 state=P_PROTO;
963                                                 break;
964                                         case P_PROTO:
965                                                 break;
966                                         default:
967                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
968                                                                 " state %d\n", *tmp, state);
969                                                 goto error;
970                                 }
971                                  break;
972                         case '0':
973                                 switch(state){
974                                         case VER2:
975                                                 state=FIN_VER;
976                                                 break;
977                                         /* allow 0 in PROTO*/
978                                         case F_PROTO:
979                                                 proto=tmp;
980                                                 state=P_PROTO;
981                                                 break;
982                                         case P_PROTO:
983                                                 break;
984                                         default:
985                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
986                                                                 " state %d\n", *tmp, state);
987                                                 goto error;
988                                 }
989                                 break;
990                         
991                         default:
992                                 switch(state){
993                                         case F_PROTO:
994                                                 proto=tmp;
995                                                 state=P_PROTO;
996                                                 break;
997                                         case P_PROTO:
998                                                 break;
999                                         default:
1000                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1001                                                                 " state %d\n", *tmp, state);
1002                                                 goto error;
1003                                 }
1004                                 break;
1005                 }
1006         } /* for tmp*/
1007
1008 /* we should not be here! if everything is ok > main_via*/
1009         LOG(L_ERR, "ERROR: parse_via: bad via: end of packet on state=%d\n",
1010                         state);
1011         goto error;
1012
1013 main_via:
1014 /* inc tmp to point to the next char*/
1015         tmp++;
1016         c_nest=0;
1017         /*state should always be F_HOST here*/;
1018         for(;*tmp;tmp++){
1019                 switch(*tmp){
1020                         case ' ':
1021                         case '\t':
1022                                 switch(state){
1023                                         case F_HOST:/*eat the spaces*/
1024                                                 break;
1025                                         case P_HOST:
1026                                                  *tmp=0;/*mark end of host*/
1027                                                  state=L_PORT;
1028                                                  break;
1029                                         case L_PORT: /*eat the spaces*/
1030                                         case F_PORT:
1031                                                 break;
1032                                         case P_PORT:
1033                                                 *tmp=0; /*end of port */
1034                                                 state=L_PARAM;
1035                                                 break;
1036                                         case L_PARAM: /* eat the space */
1037                                         case F_PARAM:
1038                                                 break;
1039                                         case P_PARAM:
1040                                         /*      *tmp=0;*/ /*!?end of param*/
1041                                                 state=L_PARAM;
1042                                                 break;
1043                                         case L_VIA:
1044                                         case F_VIA: /* eat the space */
1045                                                 break;
1046                                         case F_COMMENT:
1047                                         case P_COMMENT:
1048                                                 break;
1049                                         case F_IP6HOST: /*eat the spaces*/
1050                                                 break;
1051                                         case P_IP6HOST:
1052                                                 *tmp=0; /*mark end of host*/
1053                                                 state=L_PORT; 
1054                                                 break;
1055                                         case F_CRLF:
1056                                         case F_LF:
1057                                         case F_CR:
1058                                                 /*previous=crlf and now =' '*/
1059                                                 state=saved_state;
1060                                                 break;
1061                                         default:
1062                                                 LOG(L_CRIT,"BUG: parse_via"
1063                                                         " on <%c>, state=%d\n",*tmp, state);
1064                                                 goto  error;
1065                                 }
1066                         break;
1067                         case '\n':
1068                                 switch(state){
1069                                         case F_HOST:/*eat the spaces*/
1070                                         case L_PORT: /*eat the spaces*/
1071                                         case F_PORT:
1072                                         case L_PARAM: /* eat the space */
1073                                         case F_PARAM:
1074                                         case F_VIA: /* eat the space */
1075                                         case L_VIA:
1076                                         case F_COMMENT:
1077                                         case P_COMMENT:
1078                                         case F_IP6HOST:
1079                                         case P_IP6HOST:
1080                                                 saved_state=state;
1081                                                 state=F_LF;
1082                                                 break;
1083                                         case P_HOST:
1084                                                  *tmp=0;/*mark end of host*/
1085                                                  saved_state=L_PORT;
1086                                                  state=F_LF;
1087                                                  break;
1088                                         case P_PORT:
1089                                                 *tmp=0; /*end of port */
1090                                                 saved_state=L_PARAM;
1091                                                 state=F_LF;
1092                                                 break;
1093                                         case P_PARAM:
1094                                         /*      *tmp=0;*/ /*!?end of param*/
1095                                                 saved_state=L_PARAM;
1096                                                 state=F_LF;
1097                                                 break;
1098                                         case F_CR:
1099                                                 state=F_CRLF;
1100                                                 break;
1101                                         case F_CRLF:
1102                                         case F_LF:
1103                                                 state=saved_state;
1104                                                 goto endofheader;
1105                                         default:
1106                                                 LOG(L_CRIT,"BUG: parse_via"
1107                                                         " on <%c>\n",*tmp);
1108                                                 goto  error;
1109                                 }
1110                         break;
1111                 case '\r':
1112                                 switch(state){
1113                                         case F_HOST:/*eat the spaces*/
1114                                         case L_PORT: /*eat the spaces*/
1115                                         case F_PORT:
1116                                         case L_PARAM: /* eat the space */
1117                                         case F_PARAM:
1118                                         case F_VIA: /* eat the space */
1119                                         case L_VIA:
1120                                         case F_COMMENT:
1121                                         case P_COMMENT:
1122                                         case F_IP6HOST:
1123                                         case P_IP6HOST:
1124                                                 saved_state=state;
1125                                                 state=F_CR;
1126                                                 break;
1127                                         case P_HOST:
1128                                                  *tmp=0;/*mark end of host*/
1129                                                  saved_state=L_PORT;
1130                                                  state=F_CR;
1131                                                  break;
1132                                         case P_PORT:
1133                                                 *tmp=0; /*end of port */
1134                                                 saved_state=L_PARAM;
1135                                                 state=F_CR;
1136                                                 break;
1137                                         case P_PARAM:
1138                                         /*      *tmp=0;*/ /*!?end of param*/
1139                                                 saved_state=L_PARAM;
1140                                                 state=F_CR;
1141                                                 break;
1142                                         case F_CRLF:
1143                                         case F_CR:
1144                                         case F_LF:
1145                                                 state=saved_state;
1146                                                 goto endofheader;
1147                                         default:
1148                                                 LOG(L_CRIT,"BUG: parse_via"
1149                                                         " on <%c>\n",*tmp);
1150                                                 goto  error;
1151                                 }
1152                         break;
1153                         
1154                         case ':':
1155                                 switch(state){
1156                                         case F_HOST:
1157                                         case F_IP6HOST:
1158                                                 LOG(L_ERR,"ERROR:parse_via:"
1159                                                         " no host found\n");
1160                                                 goto error;
1161                                         case P_IP6HOST:
1162                                                 LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
1163                                                 goto error;
1164                                         case P_HOST:
1165                                                 *tmp=0; /*mark  end of host*/
1166                                                 state=F_PORT;
1167                                                 break;
1168                                         case L_PORT:
1169                                                 state=F_PORT;
1170                                                 break;
1171                                         case P_PORT:
1172                                                 LOG(L_ERR, "ERROR:parse_via:"
1173                                                         " bad port\n");
1174                                                 goto error;
1175                                         case L_PARAM:
1176                                         case F_PARAM:
1177                                         case P_PARAM:
1178                                                 LOG(L_ERR, "ERROR:parse_via:"
1179                                                 " bad char <%c> in state %d\n",
1180                                                         *tmp,state);
1181                                                 goto error;
1182                                         case L_VIA:
1183                                         case F_VIA:
1184                                                 LOG(L_ERR, "ERROR:parse_via:"
1185                                                 " bad char in compact via\n");
1186                                                 goto error;
1187                                         case F_CRLF:
1188                                         case F_LF:
1189                                         case F_CR:
1190                                                 /*previous=crlf and now !=' '*/
1191                                                 goto endofheader;
1192                                         case F_COMMENT:/*everything is allowed in a comment*/
1193                                                 comment=tmp;
1194                                                 state=P_COMMENT;
1195                                                 break;
1196                                         case P_COMMENT: /*everything is allowed in a comment*/
1197                                                 break;
1198                                         default:
1199                                                 LOG(L_CRIT,"BUG: parse_via"
1200                                                         " on <%c> state %d\n",
1201                                                         *tmp, state);
1202                                                 goto error;
1203                                 }
1204                                 break;
1205                         case ';':
1206                                 switch(state){
1207                                         case F_HOST:
1208                                         case F_IP6HOST:
1209                                                 LOG(L_ERR,"ERROR:parse_via:"
1210                                                         " no host found\n");
1211                                                 goto error;
1212                                         case P_IP6HOST:
1213                                                 LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
1214                                                 goto error;
1215                                         case P_HOST:
1216                                         case P_PORT:
1217                                                 *tmp=0; /*mark the end*/
1218                                         case L_PORT:
1219                                         case L_PARAM:
1220                                                 state=F_PARAM;
1221                                                 break;
1222                                         case F_PORT:
1223                                                 LOG(L_ERR, "ERROR:parse_via:"
1224                                                 " bad char <%c> in state %d\n",
1225                                                         *tmp,state);
1226                                                 goto error;
1227                                         case F_PARAM:
1228                                                 LOG(L_ERR,  "ERROR:parse_via:"
1229                                                         " null param?\n");
1230                                                 goto error;
1231                                         case P_PARAM:
1232                                                 /*hmm next, param?*/
1233                                                 state=F_PARAM;
1234                                                 break;
1235                                         case L_VIA:
1236                                         case F_VIA:
1237                                                 LOG(L_ERR, "ERROR:parse_via:"
1238                                                 " bad char <%c> in next via\n",
1239                                                         *tmp);
1240                                                 goto error;
1241                                         case F_CRLF:
1242                                         case F_LF:
1243                                         case F_CR:
1244                                                 /*previous=crlf and now !=' '*/
1245                                                 goto endofheader;
1246                                         case F_COMMENT:/*everything is allowed in a comment*/
1247                                                 comment=tmp;
1248                                                 state=P_COMMENT;
1249                                                 break;
1250                                         case P_COMMENT: /*everything is allowed in a comment*/
1251                                                 break;
1252                                         
1253                                         default:
1254                                                 LOG(L_CRIT,"BUG: parse_via"
1255                                                         " on <%c> state %d\n",
1256                                                         *tmp, state);
1257                                                 goto  error;
1258                                 }
1259                         break;
1260                         case ',':
1261                                 switch(state){
1262                                         case F_HOST:
1263                                         case F_IP6HOST:
1264                                                 LOG(L_ERR,"ERROR:parse_via:"
1265                                                         " no host found\n");
1266                                                 goto error;
1267                                         case P_IP6HOST:
1268                                                 LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
1269                                                 goto error;
1270                                         case P_HOST:
1271                                         case P_PORT:
1272                                                 *tmp=0; /*mark the end*/
1273                                         case L_PORT:
1274                                         case L_PARAM:
1275                                         case P_PARAM:
1276                                         case L_VIA:
1277                                                 state=F_VIA;
1278                                                 break;
1279                                         case F_PORT:
1280                                         case F_PARAM:
1281                                                 LOG(L_ERR, "ERROR:parse_via:"
1282                                                 " invalid char <%c> in state"
1283                                                 " %d\n", *tmp,state);
1284                                                 goto error;
1285                                         case F_VIA:
1286                                                 /* do  nothing,  eat ","*/
1287                                                 break;  
1288                                         case F_CRLF:
1289                                         case F_LF:
1290                                         case F_CR:
1291                                                 /*previous=crlf and now !=' '*/
1292                                                 goto endofheader;
1293                                         case F_COMMENT:/*everything is allowed in a comment*/
1294                                                 comment=tmp;
1295                                                 state=P_COMMENT;
1296                                                 break;
1297                                         case P_COMMENT: /*everything is allowed in a comment*/
1298                                                 break;
1299                                         default:
1300                                                 LOG(L_CRIT,"BUG: parse_via"
1301                                                         " on <%c> state %d\n",
1302                                                         *tmp, state);
1303                                                 goto  error;
1304                                 }
1305                         break;
1306                         case '(':
1307                                 switch(state){
1308                                         case F_HOST:
1309                                         case F_PORT:
1310                                         case F_PARAM:
1311                                         case F_VIA:
1312                                         case F_IP6HOST:
1313                                         case P_IP6HOST: /*must be terminated in ']'*/
1314                                                 LOG(_ERR,"ERROR:parse_via"
1315                                                         " on <%c> state %d\n",
1316                                                         *tmp, state);
1317                                                 goto  error;
1318                                         case P_HOST:
1319                                         case P_PORT:
1320                                         case P_PARAM:
1321                                                 *tmp=0; /*mark the end*/
1322                                         case L_PORT:
1323                                         case L_PARAM:
1324                                         case L_VIA:
1325                                                 state=F_COMMENT;
1326                                                 c_nest++;
1327                                                 printf("found '(', state=%d, c_nest=%d\n",
1328                                                                 state, c_nest);
1329                                                 *tmp=0;
1330                                                 break;
1331                                         case P_COMMENT:
1332                                         case F_COMMENT:
1333                                                 c_nest++;
1334                                                 break;
1335                                         case F_CRLF:
1336                                         case F_LF:
1337                                         case F_CR:
1338                                                 /*previous=crlf and now !=' '*/
1339                                                 goto endofheader;
1340                                         default:
1341                                                 LOG(L_CRIT,"BUG: parse_via"
1342                                                         " on <%c> state %d\n",
1343                                                         *tmp, state);
1344                                                 goto  error;
1345                                 }
1346                         break;
1347                         case ')':
1348                                 switch(state){
1349                                         case F_COMMENT:
1350                                         case P_COMMENT:
1351                                                 if (c_nest){
1352                                                         c_nest--;
1353                                                         if(c_nest==0){
1354                                                                 state=L_VIA;
1355                                                                 *tmp=0;
1356                                                                 printf("out of comment\n");
1357                                                                 break;
1358                                                         }
1359                                                 }else{
1360                                                         LOG(L_ERR,"ERROR:"
1361                                                             "parse_via: "
1362                                                             "missing '(' - "
1363                                                             "nesting = %d\n",
1364                                                             c_nest);
1365                                                          goto error;
1366                                                 }
1367                                                 break;
1368                                         case F_HOST:
1369                                         case F_PORT:
1370                                         case F_PARAM:
1371                                         case F_VIA:
1372                                         case P_HOST:
1373                                         case P_PORT:
1374                                         case P_PARAM:
1375                                         case L_PORT:
1376                                         case L_PARAM:
1377                                         case L_VIA:
1378                                         case F_IP6HOST:
1379                                         case P_IP6HOST:
1380                                                 LOG(L_ERR,"ERROR:parse_via"
1381                                                         " on <%c> state %d\n",
1382                                                         *tmp, state);
1383                                                 goto  error;
1384                                         case F_CRLF:
1385                                         case F_LF:
1386                                         case F_CR:
1387                                                 /*previous=crlf and now !=' '*/
1388                                                 goto endofheader;
1389                                         default:
1390                                                 LOG(L_CRIT,"BUG: parse_via"
1391                                                         " on <%c> state %d\n",
1392                                                         *tmp, state);
1393                                                 goto  error;
1394                                 }
1395                                 break;
1396                         case '[':
1397                                 switch(state){
1398                                         case F_HOST:
1399                                                 state=F_IP6HOST;
1400                                                 break;
1401                                         case F_COMMENT:/*everything is allowed in a comment*/
1402                                                 comment=tmp;
1403                                                 state=P_COMMENT;
1404                                                 break;
1405                                         case P_COMMENT:
1406                                                 break;
1407                                         case F_CRLF:
1408                                         case F_LF:
1409                                         case F_CR:
1410                                                 /*previous=crlf and now !=' '*/
1411                                                 goto endofheader;
1412                                         default:
1413                                                 LOG(L_ERR,"ERROR:parse_via"
1414                                                         " on <%c> state %d\n",
1415                                                         *tmp, state);
1416                                                 goto  error;
1417                                 }
1418                                 break;
1419                         case ']':
1420                                 switch(state){
1421                                         case P_IP6HOST:
1422                                                 *tmp=0; /*mark the end*/
1423                                                 state=L_PORT;
1424                                                 break;
1425                                         case F_CRLF:
1426                                         case F_LF:
1427                                         case F_CR:
1428                                                 /*previous=crlf and now !=' '*/
1429                                                 goto endofheader;
1430                                         case F_COMMENT:/*everything is allowed in a comment*/
1431                                                 comment=tmp;
1432                                                 state=P_COMMENT;
1433                                                 break;
1434                                         case P_COMMENT:
1435                                                 break;
1436                                         default:
1437                                                 LOG(L_ERR,"ERROR:parse_via"
1438                                                         " on <%c> state %d\n",
1439                                                         *tmp, state);
1440                                                 goto  error;
1441                                 }
1442                                 break;
1443                                                 
1444                         default:
1445                                 switch(state){
1446                                         case F_HOST:
1447                                                 state=P_HOST;
1448                                                 host=tmp;
1449                                                 break;
1450                                         case P_HOST:
1451                                                 break;
1452                                         case F_PORT:
1453                                                 state=P_PORT;
1454                                                 port_str=tmp;
1455                                                 break;
1456                                         case P_PORT:
1457                                                 /*check if number?*/
1458                                                 break;
1459                                         case F_PARAM:
1460                                                 /*state=P_PARAM*/;
1461                                                 param=tmp;
1462                                                 tmp=parse_via_param(tmp, &state, &saved_state);
1463                                                 switch(state){
1464                                                         case L_PARAM:
1465                                                         case F_PARAM:
1466                                                         case F_LF:
1467                                                         case F_CR:
1468                                                                 break;
1469                                                         case END_OF_HEADER:
1470                                                                 state=saved_state;
1471                                                                 goto endofheader;
1472                                                         default:
1473                                                                 LOG(L_ERR, "ERROR: parse_via after"
1474                                                                                 " parse_via_param: invalid"
1475                                                                                 " char <%c> on state %d\n",
1476                                                                                 *tmp, state);
1477                                                                 goto error;
1478                                                 }
1479                                                 break;
1480                                         case P_PARAM:
1481                                                 break;
1482                                         case F_VIA:
1483                                                 next_via=tmp;
1484                                                 printf("found new via on <%c>\n", *tmp);
1485                                                 goto nextvia;
1486                                         case L_PORT:
1487                                         case L_PARAM:
1488                                         case L_VIA:
1489                                                 LOG(L_ERR,"ERROR:parse_via"
1490                                                         " on <%c> state %d (default)\n",
1491                                                         *tmp, state);
1492                                                 goto  error;
1493                                         case F_COMMENT:
1494                                                 printf("starting comment parsing on %c \n",*tmp);
1495                                                 state=P_COMMENT;
1496                                                 comment=tmp;
1497                                                 break;
1498                                         case P_COMMENT:
1499                                                 break;
1500                                         case F_IP6HOST:
1501                                                 state=P_IP6HOST;
1502                                                 host=tmp;
1503                                                 break;
1504                                         case P_IP6HOST:
1505                                                 break;
1506                                         case F_CRLF:
1507                                         case F_LF:
1508                                         case F_CR:
1509                                                 /*previous=crlf and now !=' '*/
1510                                                 goto endofheader;
1511                                         default:
1512                                                 LOG(L_ERR, "BUG:parse_via:"
1513                                                         " invalid char <%c>"
1514                                                         " in state %d\n",
1515                                                         *tmp, state);
1516                                                 goto error;
1517                                 }
1518                                 
1519                                         
1520                 }                       
1521         }
1522
1523         printf("end of packet reached, state=%d\n", state);
1524         goto endofpacket; /*end of packet, probably should be goto error*/
1525         
1526 endofheader:
1527         state=saved_state;
1528         printf("end of header reached, state=%d\n", state);
1529 endofpacket:
1530         /* check if error*/
1531         switch(state){
1532                 case P_HOST:
1533                 case L_PORT:
1534                 case P_PORT:
1535                 case L_PARAM:
1536                 case P_PARAM:
1537                 case P_VALUE:
1538                 case GEN_PARAM:
1539                 case FIN_HIDDEN:
1540                 case L_VIA:
1541                         break;
1542                 default:
1543                         LOG(L_ERR, "ERROR: parse_via: invalid via - end of header in"
1544                                         " state %d\n", state);
1545                         goto error;
1546         }
1547                 
1548 nextvia:
1549         if (proto) printf("<SIP/2.0/%s>\n", proto);
1550         if (host) printf("host= <%s>\n", host);
1551         if (port_str) printf("port= <%s>\n", port_str);
1552         if (param) printf("params= <%s>\n", param);
1553         if (comment) printf("comment= <%s>\n", comment);
1554         if(next_via) printf("next_via= <%s>\n", next_via);
1555         printf("rest=<%s>\n", tmp);
1556         
1557         exit(0);
1558
1559 error:
1560         fprintf(stderr, "via parse error\n");
1561         exit(-1);
1562 }
1563