modules/ims_qos: added patch for flow-description bug when request originates from...
[sip-router] / src / core / parser / parse_via.c
1 /*
2  * via parsing automaton
3  * 
4  * Copyright (C) 2001-2003 FhG Fokus
5  *
6  * This file is part of Kamailio, a free SIP server.
7  *
8  * Kamailio is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * Kamailio is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License 
19  * along with this program; if not, write to the Free Software 
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 /** @file
24  * @brief Parser :: Via parsing automation
25  *
26  * @ingroup parser
27  */
28
29 #include "../comp_defs.h"
30 #include <stdlib.h>
31 #include <string.h>
32 #include "../dprint.h"
33 #include "../ut.h"
34 #include "../mem/mem.h"
35 #include "../ip_addr.h"
36 #include "parse_via.h"
37 #include "parse_def.h"
38 #include "msg_parser.h"
39
40
41
42 /** \brief main via states (uri:port ...) */
43 enum {           
44         F_HOST, P_HOST,
45         L_PORT, F_PORT, P_PORT,
46         L_PARAM, F_PARAM, P_PARAM,
47         L_VIA, F_VIA,
48         F_COMMENT, P_COMMENT,
49         F_IP6HOST, P_IP6HOST, 
50         F_CRLF,
51         F_LF,
52         F_CR,
53         END_OF_HEADER
54 };
55
56
57 /** \brief first via part state */
58 enum {
59         F_SIP = 100,
60         SIP1, SIP2, FIN_SIP,
61         L_VER, F_VER,
62         VER1, VER2, FIN_VER,
63         UDP1, UDP2, FIN_UDP,
64         TCP_TLS1, TCP2, FIN_TCP,
65                   TLS2, FIN_TLS,
66         SCTP1, SCTP2, SCTP3, FIN_SCTP,
67         WS_WSS1, WS_WSS2, FIN_WSS,
68         OTHER_PROTO,
69         L_PROTO, F_PROTO
70 };
71
72
73 /** \brief param related states
74  * WARNING: keep in sync with parse_via.h, PARAM_HIDDEN, ...
75  */
76 enum {  
77         L_VALUE = 200, F_VALUE, P_VALUE, P_STRING,
78         HIDDEN1, HIDDEN2, HIDDEN3, HIDDEN4, HIDDEN5,
79         TTL1, TTL2,
80         BRANCH1, BRANCH2, BRANCH3, BRANCH4, BRANCH5,
81         MADDR1, MADDR2, MADDR3, MADDR4,
82         RECEIVED1, RECEIVED2, RECEIVED3, RECEIVED4, RECEIVED5, RECEIVED6,
83         RECEIVED7,
84         RPORT1, RPORT2, RPORT3,
85         ALIAS1, ALIAS2, ALIAS3, ALIAS4,
86 #ifdef USE_COMP
87         COMP1, COMP2, COMP3, 
88         /* values */
89         L_COMP_VALUE, F_COMP_VALUE,
90         V_COMP_S, V_SIGCOMP_I, V_SIGCOMP_G, V_SIGCOMP_C, V_SIGCOMP_O, V_SIGCOMP_M,
91         FIN_V_SIGCOMP_P,
92         V_SERGZ_E, V_SERGZ_R, V_SERGZ_G, FIN_V_SERGZ_Z,
93 #endif
94              /* fin states (227-...)*/
95         FIN_HIDDEN = 230, FIN_TTL, FIN_BRANCH,
96         FIN_MADDR, FIN_RECEIVED, FIN_RPORT, FIN_I, FIN_ALIAS
97 #ifdef USE_COMP
98         , FIN_COMP
99 #endif
100              /*GEN_PARAM,
101                PARAM_ERROR*/ /* declared in msg_parser.h*/
102 };
103
104
105 /* entry state must be F_PARAM, or saved_state=F_PARAM and
106  * state=F_{LF,CR,CRLF}!
107  * output state = L_PARAM or F_PARAM or END_OF_HEADER
108  * (and saved_state= last state); everything else => error 
109  * WARNING: param->start must be filled before, it's used in param->size 
110  * computation.
111  */
112 static /*inline*/ char* parse_via_param(char* const p, const char* const end,
113                                                                         unsigned char* const pstate, 
114                                                                         unsigned char* const psaved_state,
115                                                                         struct via_param* const param,
116                                                                         const struct via_body* vb)
117 {
118         char* tmp;
119         register unsigned char state;
120         unsigned char saved_state;
121
122 #define value_case(c, C, oldstate, newstate, start_of_value) \
123                         case (c): \
124                         case (C): \
125                                 switch(state){ \
126                                         case (oldstate): \
127                                                 state=(newstate); \
128                                                 if ((start_of_value))  param->value.s=tmp; \
129                                                 break; \
130                                         default_value_cases \
131                                 } \
132                                 break
133
134 #define value_case_double(c, C, oldstate1, newstate1, oldstate2, newstate2) \
135                         case (c): \
136                         case (C): \
137                                 switch(state){ \
138                                         case (oldstate1): \
139                                                 state=(newstate1); \
140                                                 break; \
141                                         case (oldstate2): \
142                                                 state=(newstate2); \
143                                                 break; \
144                                         default_value_cases \
145                                 } \
146                                 break
147
148 #define default_value_cases \
149                                         case F_VALUE: \
150                                                 state=P_VALUE; \
151                                                 param->value.s=tmp; \
152                                                 break; \
153                                         case P_VALUE: \
154                                         case P_STRING: \
155                                                 break; \
156                                         case F_LF: \
157                                         case F_CR:  \
158                                         case F_CRLF: \
159                                                 state=END_OF_HEADER; \
160                                                 goto end_via; \
161                                         default: \
162                                                 switch(state){ \
163                                                         case F_COMP_VALUE: \
164                                                                 comp_unexpected_char; \
165                                                                 state=P_VALUE; \
166                                                                 param->value.s=tmp; \
167                                                                 break; \
168                                                         comp_states_cases \
169                                                         comp_fin_states_cases \
170                                                                 comp_unexpected_char; \
171                                                                 state=P_VALUE; \
172                                                                 break; \
173                                                         default: \
174                                                                 LOG(L_ERR, "ERROR: parse_via_param: invalid " \
175                                                                         "char <%c> in state %d\n", *tmp, state); \
176                                                                 goto error; \
177                                                 }
178
179 #define comp_states_cases \
180                                         case V_COMP_S: \
181                                         case V_SIGCOMP_I: \
182                                         case V_SIGCOMP_G: \
183                                         case V_SIGCOMP_C: \
184                                         case V_SIGCOMP_O: \
185                                         case V_SIGCOMP_M: \
186                                         case V_SERGZ_E: \
187                                         case V_SERGZ_R: \
188                                         case V_SERGZ_G: 
189
190 #define comp_fin_states_cases \
191                                         case FIN_V_SIGCOMP_P: \
192                                         case FIN_V_SERGZ_Z:
193
194
195 /* if unrecognized/bad comp, don't return error, just ignore comp */
196 #define comp_unexpected_char \
197                                                         LOG(L_ERR, "parse_via_param: bad/unrecognized" \
198                                                                         " comp method\n"); \
199                                                         vb->comp_no=0
200                                                                 
201
202
203         state=*pstate;
204         saved_state=*psaved_state;
205         param->type=PARAM_ERROR;
206
207         for (tmp=p;tmp<end;tmp++){
208                 switch(*tmp){
209                         case ' ':
210                         case '\t':
211                                 switch(state){
212                                         case FIN_HIDDEN:
213                                         case FIN_ALIAS:
214                                                 param->type=state;
215                                                 param->name.len=tmp-param->name.s;
216                                                 state=L_PARAM;
217                                                 goto endofparam;
218                                         case FIN_BRANCH:
219                                         case FIN_TTL:
220                                         case FIN_MADDR:
221                                         case FIN_RECEIVED:
222                                         case FIN_RPORT:
223                                         case FIN_I:
224                                                 param->type=state;
225                                                 param->name.len=tmp-param->name.s;
226                                                 state=L_VALUE;
227                                                 goto find_value;
228 #ifdef USE_COMP
229                                         case FIN_COMP:
230                                                 param->type=state;
231                                                 param->name.len=tmp-param->name.s;
232                                                 state=L_COMP_VALUE;
233                                                 goto find_value;
234 #endif
235                                         case F_PARAM:
236                                                 break;
237                                         case F_LF:
238                                         case F_CR:
239                                         case F_CRLF:
240                                                 state=saved_state;
241                                                 break;
242                                         case GEN_PARAM:
243                                         default:
244                                                 param->type=GEN_PARAM;
245                                                 param->name.len=tmp-param->name.s;
246                                                 state=L_VALUE;
247                                                 goto find_value;
248                                 }
249                                 break;
250                         /* \n and \r*/
251                         case '\n':
252                                 switch(state){
253                                         case FIN_HIDDEN:
254                                         case FIN_ALIAS:
255                                                 param->type=state;
256                                                 param->name.len=tmp-param->name.s;
257                                                 param->size=tmp-param->start; 
258                                                 saved_state=L_PARAM;
259                                                 state=F_LF;
260                                                 goto endofparam;
261                                         case FIN_BRANCH:
262                                         case FIN_TTL:
263                                         case FIN_MADDR:
264                                         case FIN_RECEIVED:
265                                         case FIN_I:
266                                         case FIN_RPORT:
267                                                 param->type=state;
268                                                 param->name.len=tmp-param->name.s;
269                                                 param->size=tmp-param->start; 
270                                                 saved_state=L_VALUE;
271                                                 state=F_LF;
272                                                 goto find_value;
273 #ifdef USE_COMP
274                                         case FIN_COMP:
275                                                 param->type=state;
276                                                 param->name.len=tmp-param->name.s;
277                                                 param->size=tmp-param->start; 
278                                                 saved_state=L_COMP_VALUE;
279                                                 state=F_LF;
280                                                 goto find_value;
281 #endif
282                                         case F_PARAM:
283                                                 saved_state=state;
284                                                 state=F_LF;
285                                                 break;
286                                         case F_LF:
287                                         case F_CRLF:
288                                                 state=END_OF_HEADER;
289                                                 goto end_via;
290                                         case F_CR:
291                                                 state=F_CRLF;
292                                                 break;
293                                         case GEN_PARAM:
294                                         default:
295                                                 param->type=GEN_PARAM;
296                                                 saved_state=L_VALUE;
297                                                 param->name.len=tmp-param->name.s;
298                                                 param->size=tmp-param->start; 
299                                                 state=F_LF;
300                                                 goto find_value;
301                                 }
302                                 break;
303                         case '\r':
304                                 switch(state){
305                                         case FIN_HIDDEN:
306                                         case FIN_ALIAS:
307                                                 param->type=state;
308                                                 param->name.len=tmp-param->name.s;
309                                                 param->size=tmp-param->start; 
310                                                 saved_state=L_PARAM;
311                                                 state=F_CR;
312                                                 goto endofparam;
313                                         case FIN_BRANCH:
314                                         case FIN_TTL:
315                                         case FIN_MADDR:
316                                         case FIN_RECEIVED:
317                                         case FIN_I:
318                                         case FIN_RPORT:
319                                                 param->type=state;
320                                                 param->name.len=tmp-param->name.s;
321                                                 param->size=tmp-param->start; 
322                                                 saved_state=L_VALUE;
323                                                 state=F_CR;
324                                                 goto find_value;
325 #ifdef USE_COMP
326                                         case FIN_COMP:
327                                                 param->type=state;
328                                                 param->name.len=tmp-param->name.s;
329                                                 param->size=tmp-param->start; 
330                                                 saved_state=L_COMP_VALUE;
331                                                 state=F_LF;
332                                                 goto find_value;
333 #endif
334                                         case F_PARAM:
335                                                 saved_state=state;
336                                                 state=F_CR;
337                                                 break;
338                                         case F_CR:
339                                         case F_CRLF:
340                                                 state=END_OF_HEADER;
341                                                 goto end_via;
342                                         case GEN_PARAM:
343                                         default:
344                                                 param->type=GEN_PARAM;
345                                                 param->name.len=tmp-param->name.s;
346                                                 param->size=tmp-param->start; 
347                                                 saved_state=L_VALUE;
348                                                 state=F_CR;
349                                                 goto find_value;
350                                 }
351                                 break;
352
353                         case '=':
354                                 switch(state){
355                                         case FIN_BRANCH:
356                                         case FIN_TTL:
357                                         case FIN_MADDR:
358                                         case FIN_RECEIVED:
359                                         case FIN_RPORT:
360                                         case FIN_I:
361                                                 param->type=state;
362                                                 param->name.len=tmp-param->name.s;
363                                                 state=F_VALUE;
364                                                 goto find_value;
365 #ifdef USE_COMP
366                                         case FIN_COMP:
367                                                 param->type=state;
368                                                 param->name.len=tmp-param->name.s;
369                                                 state=F_COMP_VALUE;
370                                                 goto find_value;
371 #endif
372                                         case F_PARAM:
373                                         case FIN_HIDDEN:
374                                         case FIN_ALIAS:
375                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
376                                                                 " state %d\n", *tmp, state);
377                                                 goto error;
378                                         case F_CR:
379                                         case F_LF:
380                                         case F_CRLF:
381                                                 state=END_OF_HEADER;
382                                                 goto end_via;
383                                         case GEN_PARAM:
384                                         default:
385                                                 param->type=GEN_PARAM;
386                                                 param->name.len=tmp-param->name.s;
387                                                 state=F_VALUE;
388                                                 goto find_value;
389                                 }
390                                 break;
391                         case ';':
392                                 switch(state){
393                                         case FIN_HIDDEN:
394                                         case FIN_RPORT: /* rport can appear w/o a value */
395                                         case FIN_ALIAS:
396                                                 param->type=state;
397                                                 param->name.len=tmp-param->name.s;
398                                                 state=F_PARAM;
399                                                 goto endofparam;
400                                         case FIN_BRANCH:
401                                         case FIN_MADDR:
402                                         case FIN_TTL:
403                                         case FIN_RECEIVED:
404                                         case FIN_I:
405 #ifdef USE_COMP
406                                         case FIN_COMP:
407 #endif
408                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
409                                                                 " state %d\n", *tmp, state);
410                                                 goto error;
411                                         case F_CR:
412                                         case F_LF:
413                                         case F_CRLF:
414                                                 state=END_OF_HEADER;
415                                                 goto end_via;
416                                         case GEN_PARAM:
417                                         default:
418                                                 param->type=GEN_PARAM;
419                                                 param->name.len=tmp-param->name.s;
420                                                 state=F_PARAM;
421                                                 goto endofparam;
422                                 }
423                                 break;
424                         case ',':
425                                 switch(state){
426                                         case FIN_HIDDEN:
427                                         case FIN_RPORT:
428                                         case FIN_ALIAS:
429                                                 param->type=state;
430                                                 param->name.len=tmp-param->name.s;
431                                                 state=F_VIA;
432                                                 goto endofvalue;
433                                         case FIN_BRANCH:
434                                         case FIN_MADDR:
435                                         case FIN_TTL:
436                                         case FIN_RECEIVED:
437                                         case FIN_I:
438 #ifdef USE_COMP
439                                         case FIN_COMP:
440 #endif
441                                                 LOG(L_ERR, "ERROR: parse_via_param: new via found" 
442                                                                 "(',') when '=' expected (state %d=)\n",
443                                                                 state);
444                                                 goto error; /* or we could ignore this bad param*/
445                                         case F_CR:
446                                         case F_LF:
447                                         case F_CRLF:
448                                                 state=END_OF_HEADER;
449                                                 goto end_via;
450                                         case GEN_PARAM:
451                                         default:
452                                                 param->type=GEN_PARAM;
453                                                 param->name.len=tmp-param->name.s;
454                                                 state=F_VIA;
455                                                 goto endofvalue;
456                                 }
457                                 break; 
458
459                                 /* param names */
460                         case 'h':
461                         case 'H':
462                                 switch(state){
463                                         case F_PARAM:
464                                                 state=HIDDEN1;
465                                                 param->name.s=tmp;
466                                                 break;
467                                         case BRANCH5:
468                                                 state=FIN_BRANCH;
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 'i':
482                         case 'I':
483                                 switch(state){
484                                         case F_PARAM:
485                                                 state=FIN_I;
486                                                 param->name.s=tmp;
487                                                 break;
488                                         case HIDDEN1:
489                                                 state=HIDDEN2;
490                                                 break;
491                                         case RECEIVED4:
492                                                 state=RECEIVED5;
493                                                 break;
494                                         case ALIAS2:
495                                                 state=ALIAS3;
496                                                 break;
497                                         case GEN_PARAM:
498                                                 break;
499                                         case F_CR:
500                                         case F_LF:
501                                         case F_CRLF:
502                                                 state=END_OF_HEADER;
503                                                 goto end_via;
504                                         default:
505                                                 state=GEN_PARAM;
506                                 }
507                                 break;
508                         case 'd':
509                         case 'D':
510                                 switch(state){
511                                         case F_PARAM:
512                                                 state=GEN_PARAM;
513                                                 param->name.s=tmp;
514                                                 break;
515                                         case HIDDEN2:
516                                                 state=HIDDEN3;
517                                                 break;
518                                         case HIDDEN3:
519                                                 state=HIDDEN4;
520                                                 break;
521                                         case MADDR2:
522                                                 state=MADDR3;
523                                                 break;
524                                         case MADDR3:
525                                                 state=MADDR4;
526                                                 break;
527                                         case RECEIVED7:
528                                                 state=FIN_RECEIVED;
529                                                 break;
530                                         case GEN_PARAM:
531                                                 break;
532                                         case F_CR:
533                                         case F_LF:
534                                         case F_CRLF:
535                                                 state=END_OF_HEADER;
536                                                 goto end_via;
537                                         default:
538                                                 state=GEN_PARAM;
539                                 }
540                                 break;
541                         case 'e':
542                         case 'E':
543                                 switch(state){
544                                         case F_PARAM:
545                                                 state=GEN_PARAM;
546                                                 param->name.s=tmp;
547                                                 break;
548                                         case HIDDEN4:
549                                                 state=HIDDEN5;
550                                                 break;
551                                         case RECEIVED1:
552                                                 state=RECEIVED2;
553                                                 break;
554                                         case RECEIVED3:
555                                                 state=RECEIVED4;
556                                                 break;
557                                         case RECEIVED6:
558                                                 state=RECEIVED7;
559                                                 break;
560                                         case GEN_PARAM:
561                                                 break;
562                                         case F_CR:
563                                         case F_LF:
564                                         case F_CRLF:
565                                                 state=END_OF_HEADER;
566                                                 goto end_via;
567                                         default:
568                                                 state=GEN_PARAM;
569                                 }
570                                 break;
571                         case 'n':
572                         case 'N':
573                                 switch(state){
574                                         case F_PARAM:
575                                                 state=GEN_PARAM;
576                                                 param->name.s=tmp;
577                                                 break;
578                                         case HIDDEN5:
579                                                 state=FIN_HIDDEN;
580                                                 break;
581                                         case BRANCH3:
582                                                 state=BRANCH4;
583                                                 break;
584                                         case GEN_PARAM:
585                                                 break;
586                                         case F_CR:
587                                         case F_LF:
588                                         case F_CRLF:
589                                                 state=END_OF_HEADER;
590                                                 goto end_via;
591                                         default:
592                                                 state=GEN_PARAM;
593                                 }
594                                 break;
595                         case 't':
596                         case 'T':
597                                 switch(state){
598                                         case F_PARAM:
599                                                 state=TTL1;
600                                                 param->name.s=tmp;
601                                                 break;
602                                         case TTL1:
603                                                 state=TTL2;
604                                                 break;
605                                         case RPORT3:
606                                                 state=FIN_RPORT;
607                                                 break;
608                                         case GEN_PARAM:
609                                                 break;
610                                         case F_CR:
611                                         case F_LF:
612                                         case F_CRLF:
613                                                 state=END_OF_HEADER;
614                                                 goto end_via;
615                                         default:
616                                                 state=GEN_PARAM;
617                                 }
618                                 break;
619                         case 'l':
620                         case 'L':
621                                 switch(state){
622                                         case F_PARAM:
623                                                 state=GEN_PARAM;
624                                                 param->name.s=tmp;
625                                                 break;
626                                         case TTL2:
627                                                 state=FIN_TTL;
628                                                 break;
629                                         case ALIAS1:
630                                                 state=ALIAS2;
631                                                 break;
632                                         case GEN_PARAM:
633                                                 break;
634                                         case F_CR:
635                                         case F_LF:
636                                         case F_CRLF:
637                                                 state=END_OF_HEADER;
638                                                 goto end_via;
639                                         default:
640                                                 state=GEN_PARAM;
641                                 }
642                                 break;
643                         case 'm':
644                         case 'M':
645                                 switch(state){
646                                         case F_PARAM:
647                                                 state=MADDR1;
648                                                 param->name.s=tmp;
649                                                 break;
650 #ifdef USE_COMP
651                                         case COMP2:
652                                                 state=COMP3;
653                                                 break;
654 #endif
655                                         case GEN_PARAM:
656                                                 break;
657                                         case F_CR:
658                                         case F_LF:
659                                         case F_CRLF:
660                                                 state=END_OF_HEADER;
661                                                 goto end_via;
662                                         default:
663                                                 state=GEN_PARAM;
664                                 }
665                                 break;
666                         case 'a':
667                         case 'A':
668                                 switch(state){
669                                         case F_PARAM:
670                                                 state=ALIAS1;
671                                                 param->name.s=tmp;
672                                                 break;
673                                         case MADDR1:
674                                                 state=MADDR2;
675                                                 break;
676                                         case BRANCH2:
677                                                 state=BRANCH3;
678                                                 break;
679                                         case ALIAS3:
680                                                 state=ALIAS4;
681                                                 break;
682                                         case GEN_PARAM:
683                                                 break;
684                                         case F_CR:
685                                         case F_LF:
686                                         case F_CRLF:
687                                                 state=END_OF_HEADER;
688                                                 goto end_via;
689                                         default:
690                                                 state=GEN_PARAM;
691                                 }
692                                 break;
693                         case 'r':
694                         case 'R':
695                                 switch(state){
696                                         case MADDR4:
697                                                 state=FIN_MADDR;
698                                                 break;
699                                         case F_PARAM:
700                                                 state=RECEIVED1;
701                                                 param->name.s=tmp;
702                                                 break;
703                                         case BRANCH1:
704                                                 state=BRANCH2;
705                                                 break;
706                                         case RPORT2:
707                                                 state=RPORT3;
708                                                 break;
709                                         case GEN_PARAM:
710                                                 break;
711                                         case F_CR:
712                                         case F_LF:
713                                         case F_CRLF:
714                                                 state=END_OF_HEADER;
715                                                 goto end_via;
716                                         default:
717                                                 state=GEN_PARAM;
718                                 }
719                                 break;
720                         case 'c':
721                         case 'C':
722                                 switch(state){
723                                         case F_PARAM:
724 #ifdef USE_COMP
725                                                 state=COMP1;
726 #else
727                                                 state=GEN_PARAM;
728 #endif
729                                                 param->name.s=tmp;
730                                                 break;
731                                         case RECEIVED2:
732                                                 state=RECEIVED3;
733                                                 break;
734                                         case BRANCH4:
735                                                 state=BRANCH5;
736                                                 break;
737                                         case GEN_PARAM:
738                                                 break;
739                                         case F_CR:
740                                         case F_LF:
741                                         case F_CRLF:
742                                                 state=END_OF_HEADER;
743                                                 goto end_via;
744                                         default:
745                                                 state=GEN_PARAM;
746                                 }
747                                 break;
748                         case 'v':
749                         case 'V':
750                                 switch(state){
751                                         case F_PARAM:
752                                                 state=GEN_PARAM;
753                                                 param->name.s=tmp;
754                                                 break;
755                                         case RECEIVED5:
756                                                 state=RECEIVED6;
757                                                 break;
758                                         case GEN_PARAM:
759                                                 break;
760                                         case F_CR:
761                                         case F_LF:
762                                         case F_CRLF:
763                                                 state=END_OF_HEADER;
764                                                 goto end_via;
765                                         default:
766                                                 state=GEN_PARAM;
767                                 }
768                                 break;
769                         case 'b':
770                         case 'B':
771                                 switch(state){
772                                         case F_PARAM:
773                                                 state=BRANCH1;
774                                                 param->name.s=tmp;
775                                                 break;
776                                         case GEN_PARAM:
777                                                 break;
778                                         case F_CR:
779                                         case F_LF:
780                                         case F_CRLF:
781                                                 state=END_OF_HEADER;
782                                                 goto end_via;
783                                         default:
784                                                 state=GEN_PARAM;
785                                 }
786                                 break;
787                         case 'p':
788                         case 'P':
789                                 switch(state){
790                                         case F_PARAM:
791                                                 state=GEN_PARAM;
792                                                 param->name.s=tmp;
793                                                 break;
794                                         case RECEIVED1:
795                                                 state=RPORT1;
796                                                 break;
797 #ifdef USE_COMP
798                                         case COMP3:
799                                                 state=FIN_COMP;
800                                                 break;
801 #endif
802                                         case F_CR:
803                                         case F_LF:
804                                         case F_CRLF:
805                                                 state=END_OF_HEADER;
806                                                 goto end_via;
807                                         default:
808                                                 state=GEN_PARAM;
809                                 }
810                                 break;
811                         case 'o':
812                         case 'O':
813                                 switch(state){
814                                         case F_PARAM:
815                                                 state=GEN_PARAM;
816                                                 param->name.s=tmp;
817                                                 break;
818                                         case RPORT1:
819                                                 state=RPORT2;
820                                                 break;
821 #ifdef USE_COMP
822                                         case COMP1:
823                                                 state=COMP2;
824                                                 break;
825 #endif
826                                         case F_CR:
827                                         case F_LF:
828                                         case F_CRLF:
829                                                 state=END_OF_HEADER;
830                                                 goto end_via;
831                                         default:
832                                                 state=GEN_PARAM;
833                                 }
834                                 break;
835                         case 's':
836                         case 'S':
837                                 switch(state){
838                                         case F_PARAM:
839                                                 state=GEN_PARAM;
840                                                 param->name.s=tmp;
841                                                 break;
842                                         case ALIAS4:
843                                                 state=FIN_ALIAS;
844                                                 break;
845                                         case F_CR:
846                                         case F_LF:
847                                         case F_CRLF:
848                                                 state=END_OF_HEADER;
849                                                 goto end_via;
850                                         default:
851                                                 state=GEN_PARAM;
852                                 }
853                                 break;
854                         default:
855                                 switch(state){
856                                         case F_PARAM:
857                                                 state=GEN_PARAM;
858                                                 param->name.s=tmp;
859                                                 break;
860                                         case GEN_PARAM:
861                                                 break;
862                                         case F_CR:
863                                         case F_LF:
864                                         case F_CRLF:
865                                                 state=END_OF_HEADER;
866                                                 goto end_via;
867                                         default:
868                                                 state=GEN_PARAM;
869                                 }
870                 }
871         }/* for tmp*/
872
873         /* end of packet? => error, no cr/lf,',' found!!!*/
874         saved_state=state;
875         state=END_OF_HEADER;
876         goto error;
877         
878  find_value:
879         tmp++;
880         for(;*tmp;tmp++){
881                 switch(*tmp){
882                         case ' ':
883                         case '\t':
884                                 switch(state){
885                                         case L_VALUE:
886                                         case F_VALUE: /*eat space*/
887                                                 break; 
888                                         case P_VALUE:
889                                                 state=L_PARAM;
890                                                 param->value.len=tmp-param->value.s;
891                                                 goto endofvalue;
892 #ifdef USE_COMP
893                                         case L_COMP_VALUE:
894                                         case F_COMP_VALUE:
895                                                 break; /* eat space */
896                                         case FIN_V_SIGCOMP_P:
897                                                 state=L_PARAM;
898                                                 param->value.len=tmp-param->value.s;
899                                                 vb->comp_no=COMP_SIGCOMP;
900                                                 goto endofvalue;
901                                         case FIN_V_SERGZ_Z:
902                                                 state=L_PARAM;
903                                                 param->value.len=tmp-param->value.s;
904                                                 vb->comp_no=COMP_SIGCOMP;
905                                                 goto endofvalue;
906                                         comp_states_cases
907                                                 state=L_PARAM;
908                                                 param->value.len=tmp-param->value.s;
909                                                 comp_unexpected_char;
910                                                 goto endofvalue;
911 #endif
912                                         case P_STRING:
913                                                 break;
914                                         case F_CR:
915                                         case F_LF:
916                                         case F_CRLF:
917                                                 state=saved_state;
918                                                 break;
919                                         default:
920                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
921                                                                 " in state %d\n", *tmp, state);
922                                                 goto error;
923                                 }
924                                 break;
925                         case '\n':
926                                 switch(state){
927                                         case L_VALUE:
928                                         case F_VALUE: /*eat space*/
929 #ifdef USE_COMP
930                                         case L_COMP_VALUE:
931                                         case F_COMP_VALUE:
932 #endif
933                                         case P_STRING:
934                                                 saved_state=state;
935                                                 param->size=tmp-param->start;
936                                                 state=F_LF;
937                                                 break;
938                                         case P_VALUE:
939                                                 saved_state=L_PARAM;
940                                                 state=F_LF;
941                                                 param->value.len=tmp-param->value.s;
942                                                 goto endofvalue;
943 #ifdef USE_COMP
944                                         case FIN_V_SIGCOMP_P:
945                                                 saved_state=L_PARAM;
946                                                 state=F_LF;
947                                                 param->value.len=tmp-param->value.s;
948                                                 vb->comp_no=COMP_SIGCOMP;
949                                                 goto endofvalue;
950                                         case FIN_V_SERGZ_Z:
951                                                 saved_state=L_PARAM;
952                                                 state=F_LF;
953                                                 param->value.len=tmp-param->value.s;
954                                                 vb->comp_no=COMP_SIGCOMP;
955                                                 goto endofvalue;
956                                         comp_states_cases
957                                                 saved_state=L_PARAM;
958                                                 state=F_LF;
959                                                 param->value.len=tmp-param->value.s;
960                                                 comp_unexpected_char;
961                                                 goto endofvalue;
962 #endif
963                                         case F_LF:
964                                         case F_CRLF:
965                                                 state=END_OF_HEADER;
966                                                 goto end_via;
967                                         case F_CR:
968                                                 state=F_CRLF;
969                                                 break;
970                                         default:
971                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
972                                                                 " in state %d\n", *tmp, state);
973                                                 goto error;
974                                 }
975                                 break;
976                         case '\r':
977                                 switch(state){
978                                         case L_VALUE:
979                                         case F_VALUE: /*eat space*/
980 #ifdef USE_COMP
981                                         case L_COMP_VALUE:
982                                         case F_COMP_VALUE:
983 #endif
984                                         case P_STRING:
985                                                 saved_state=state;
986                                                 param->size=tmp-param->start;
987                                                 state=F_CR;
988                                                 break;
989                                         case P_VALUE:
990                                                 param->value.len=tmp-param->value.s;
991                                                 saved_state=L_PARAM;
992                                                 state=F_CR;
993                                                 goto endofvalue;
994 #ifdef USE_COMP
995                                         case FIN_V_SIGCOMP_P:
996                                                 saved_state=L_PARAM;
997                                                 state=F_CR;
998                                                 param->value.len=tmp-param->value.s;
999                                                 vb->comp_no=COMP_SIGCOMP;
1000                                                 goto endofvalue;
1001                                         case FIN_V_SERGZ_Z:
1002                                                 saved_state=L_PARAM;
1003                                                 state=F_CR;
1004                                                 param->value.len=tmp-param->value.s;
1005                                                 vb->comp_no=COMP_SIGCOMP;
1006                                                 goto endofvalue;
1007                                         comp_states_cases
1008                                                 saved_state=L_PARAM;
1009                                                 state=F_CR;
1010                                                 param->value.len=tmp-param->value.s;
1011                                                 comp_unexpected_char;
1012                                                 goto endofvalue;
1013 #endif
1014                                         case F_LF:
1015                                         case F_CR:
1016                                         case F_CRLF:
1017                                                 state=END_OF_HEADER;
1018                                                 goto end_via;
1019                                         default:
1020                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
1021                                                                 " in state %d\n", *tmp, state);
1022                                                 goto error;
1023                                 }
1024                                 break;
1025
1026                         case '=':
1027                                 switch(state){
1028                                         case L_VALUE:
1029                                                 state=F_VALUE;
1030                                                 break;
1031 #ifdef USE_COMP
1032                                         case L_COMP_VALUE:
1033                                                 state=F_COMP_VALUE;
1034                                                 break;
1035                                         /* '=' in any other COMP value state is an error,
1036                                          * and it will be catched by the default branch */
1037 #endif
1038                                         case P_STRING:
1039                                                 break;
1040                                         case F_LF:
1041                                         case F_CR:
1042                                         case F_CRLF:
1043                                                 state=END_OF_HEADER;
1044                                                 goto end_via;
1045                                         default:
1046                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
1047                                                                 " in state %d\n", *tmp, state);
1048                                                 goto error;
1049                                 }
1050                                 break;
1051                         case ';':
1052                                 switch(state){
1053                                         case P_VALUE:
1054                                                 param->value.len=tmp-param->value.s;
1055                                                 state=F_PARAM;
1056                                                 goto endofvalue;
1057                                         case F_VALUE:
1058                                                 param->value.len=0;
1059                                                 state=F_PARAM;
1060                                                 goto endofvalue;
1061                                         case P_STRING:
1062                                                 break; /* what to do? */
1063                                         case F_LF:
1064                                         case F_CR:
1065                                         case F_CRLF:
1066                                                 state=END_OF_HEADER;
1067                                                 goto end_via;
1068 #ifdef USE_COMP
1069                                         case L_COMP_VALUE:
1070                                                 comp_unexpected_char;
1071                                                 /* we want to contine with no comp */
1072                                                 state=F_PARAM;
1073                                                 param->value.len=0;
1074                                                 param->value.s=0;
1075                                                 goto endofvalue;
1076                                         case F_COMP_VALUE:
1077                                                 comp_unexpected_char;
1078                                                 param->value.len=0;
1079                                                 state=F_PARAM;
1080                                                 goto endofvalue;
1081                                         comp_states_cases
1082                                                 comp_unexpected_char;
1083                                                 param->value.len=tmp-param->value.s;
1084                                                 state=F_PARAM;
1085                                                 goto endofvalue;
1086                                         case FIN_V_SIGCOMP_P:
1087                                                 vb->comp_no=COMP_SIGCOMP;
1088                                                 param->value.len=tmp-param->value.s;
1089                                                 state=F_PARAM;
1090                                                 goto endofvalue;
1091                                         case FIN_V_SERGZ_Z:
1092                                                 vb->comp_no=COMP_SIGCOMP;
1093                                                 param->value.len=tmp-param->value.s;
1094                                                 state=F_PARAM;
1095                                                 goto endofvalue;
1096 #endif
1097                                         case L_VALUE:
1098                                                 param->value.len=0;
1099                                                 param->value.s=0; /* null value */
1100                                                 state=F_PARAM;
1101                                                 goto endofvalue;
1102                                         default:
1103                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
1104                                                                 " in state %d\n", *tmp, state);
1105                                                 goto error;
1106                                 }
1107                                 break;
1108                         case ',':
1109                                 switch(state){
1110                                         case P_VALUE:
1111                                                 param->value.len=tmp-param->value.s;
1112                                                 state=F_VIA;
1113                                                 goto endofvalue;
1114                                         case P_STRING:
1115                                         case F_LF:
1116                                         case F_CR:
1117                                         case F_CRLF:
1118                                                 state=END_OF_HEADER;
1119                                                 goto end_via;
1120 #ifdef USE_COMP
1121                                         case L_COMP_VALUE:
1122                                                 comp_unexpected_char;
1123                                                 /* we want to contine with no comp */
1124                                                 state=F_VIA;
1125                                                 param->value.len=0;
1126                                                 param->value.s=0;
1127                                                 goto endofvalue;
1128                                         case F_COMP_VALUE:
1129                                                 comp_unexpected_char;
1130                                                 param->value.len=0;
1131                                                 state=F_VIA;
1132                                                 goto endofvalue;
1133                                         comp_states_cases
1134                                                 comp_unexpected_char;
1135                                                 param->value.len=tmp-param->value.s;
1136                                                 state=F_VIA;
1137                                                 goto endofvalue;
1138                                         case FIN_V_SIGCOMP_P:
1139                                                 vb->comp_no=COMP_SIGCOMP;
1140                                                 param->value.len=tmp-param->value.s;
1141                                                 state=F_VIA;
1142                                                 goto endofvalue;
1143                                         case FIN_V_SERGZ_Z:
1144                                                 vb->comp_no=COMP_SIGCOMP;
1145                                                 param->value.len=tmp-param->value.s;
1146                                                 state=F_VIA;
1147                                                 goto endofvalue;
1148 #endif
1149                                         case L_VALUE:
1150                                                 if (param->type==FIN_RPORT){
1151                                                         param->value.len=0;
1152                                                         param->value.s=0; /* null value */
1153                                                         state=F_VIA;
1154                                                         goto endofvalue;
1155                                                 };
1156                                                 /* no break */
1157                                         default:
1158                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
1159                                                                 " in state %d\n", *tmp, state);
1160                                                 goto error;
1161                                 }
1162                                 break; /* what to do? */
1163                         case '"':
1164                                 switch(state){
1165                                         case F_VALUE:
1166                                                 state=P_STRING;
1167                                                 param->value.s=tmp+1;
1168                                                 break;
1169                                         case P_STRING:
1170                                                 state=L_PARAM;
1171                                                 param->value.len=tmp-param->value.s;
1172                                                 goto endofvalue;
1173                                         case F_LF:
1174                                         case F_CR:
1175                                         case F_CRLF:
1176                                                 state=END_OF_HEADER;
1177                                                 goto end_via;
1178                                         default:
1179                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
1180                                                                 " in state %d\n", *tmp, state);
1181                                                 goto error;
1182                                 }
1183                                 break;
1184 #ifdef USE_COMP
1185                         value_case('s', 'S', F_COMP_VALUE, V_COMP_S, 1);
1186                         value_case('i', 'I', V_COMP_S, V_SIGCOMP_I, 0);
1187                         value_case_double('g', 'G', V_SIGCOMP_I, V_SIGCOMP_G,
1188                                                             V_SERGZ_R,   V_SERGZ_G);
1189                         value_case('c', 'C', V_SIGCOMP_G, V_SIGCOMP_C, 0);
1190                         value_case('o', 'O', V_SIGCOMP_C, V_SIGCOMP_O, 0);
1191                         value_case('m', 'M', V_SIGCOMP_O, V_SIGCOMP_M, 0);
1192                         value_case('p', 'P', V_SIGCOMP_M, FIN_V_SIGCOMP_P, 0);
1193                         
1194                         value_case('e', 'E', V_COMP_S, V_SERGZ_E, 0);
1195                         value_case('r', 'R', V_SERGZ_E, V_SERGZ_R, 0);
1196                         value_case('z', 'Z', V_SERGZ_G, FIN_V_SERGZ_Z, 0);
1197 #endif /* USE_COMP */
1198                                 
1199                         default:
1200                                 switch(state){
1201                                         case F_VALUE:
1202                                                 state=P_VALUE;
1203                                                 param->value.s=tmp;
1204                                                 break;
1205                                         case P_VALUE:
1206                                         case P_STRING:
1207                                                 break;
1208                                         case F_LF:
1209                                         case F_CR:
1210                                         case F_CRLF:
1211                                                 state=END_OF_HEADER;
1212                                                 goto end_via;
1213                                         default:
1214 #ifdef USE_COMP
1215                                                 switch(state){
1216                                                         case F_COMP_VALUE:
1217                                                                 comp_unexpected_char;
1218                                                                 state=P_VALUE;
1219                                                                 param->value.s=tmp;
1220                                                                 break;
1221                                                         comp_states_cases
1222                                                         comp_fin_states_cases
1223                                                                 comp_unexpected_char;
1224                                                                 state=P_VALUE;
1225                                                                 break;
1226                                                         default:
1227                                                                 LOG(L_ERR, "ERROR: parse_via_param: invalid "
1228                                                                         "char <%c> in state %d\n", *tmp, state);
1229                                                                 goto error;
1230                                                 }
1231 #else
1232                                                 LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
1233                                                                 " in state %d\n", *tmp, state);
1234                                                 goto error;
1235 #endif /* USE_COMP */
1236                                 }
1237                 }
1238         } /* for2 tmp*/
1239
1240         /* end of buff and no CR/LF =>error*/
1241         saved_state=state;
1242         state=END_OF_HEADER;
1243         goto error;
1244         
1245  endofparam:
1246  endofvalue:
1247         param->size=tmp-param->start;
1248 normal_exit:
1249         *pstate=state;
1250         *psaved_state=saved_state;
1251         DBG("Found param type %d, <%.*s> = <%.*s>; state=%d\n", param->type,
1252                         param->name.len, ZSW(param->name.s), 
1253                         (param->value.len?param->value.len:3),
1254                         (param->value.len?param->value.s:"n/a"), state);
1255         return tmp;
1256         
1257  end_via:
1258              /* if we are here we found an "unexpected" end of via
1259               *  (cr/lf). This is valid only if the param type is GEN_PARAM or
1260                   *  RPORT (the only ones which can miss the value; HIDDEN is a 
1261                   *  special case )*/
1262         if ((param->type==GEN_PARAM)||(param->type==PARAM_RPORT)){
1263                 saved_state=L_PARAM; /* change the saved_state, we have an unknown
1264                                         param. w/o a value */
1265                 /* param->size should be computed before */
1266                 goto normal_exit;
1267         }
1268         *pstate=state;
1269         *psaved_state=saved_state;
1270         DBG("Error on  param type %d, <%.*s>, state=%d, saved_state=%d\n",
1271                 param->type, param->name.len, ZSW(param->name.s), state, saved_state);
1272
1273  error:
1274         LOG(L_ERR, "error: parse_via_param\n");
1275         param->type=PARAM_ERROR;
1276         *pstate=PARAM_ERROR;
1277         *psaved_state=state;
1278         return tmp;
1279 }
1280
1281
1282
1283 /*
1284  * call it with a vb initialized to 0
1285  * returns: pointer after the parsed parts and sets vb->error
1286  * WARNING: don't forget to cleanup on error with free_via_list(vb)!
1287  */
1288 char* parse_via(char* buffer, const char* const end, struct via_body* const vbody)
1289 {
1290         char* tmp;
1291         char* param_start;
1292         unsigned char state;
1293         unsigned char saved_state;
1294         int c_nest;
1295         int err;
1296         struct via_body* vb;
1297         struct via_param* param;
1298
1299         vb=vbody; /* keep orignal vbody value, needed to set the error member
1300                                  in case of multiple via bodies in the same header */
1301 parse_again:
1302         vb->error=PARSE_ERROR;
1303         /* parse start of via ( SIP/2.0/UDP    )*/
1304         state=F_SIP;
1305         saved_state=F_SIP; /* fixes gcc 4.0 warning */
1306         param_start=0;
1307         for(tmp=buffer;tmp<end;tmp++){
1308                 switch(*tmp){
1309                         case ' ':
1310                         case'\t':
1311                                 switch(state){
1312                                         case L_VER: /* eat space */
1313                                         case L_PROTO:
1314                                         case F_SIP:
1315                                         case F_VER:
1316                                         case F_PROTO:
1317                                                 break;
1318                                         case FIN_UDP:
1319                                                 vb->transport.len=tmp-vb->transport.s;
1320                                                 vb->proto=PROTO_UDP;
1321                                                 state=F_HOST; /* start looking for host*/
1322                                                 goto main_via;
1323                                         case FIN_TCP:
1324                                                 /* finished proto parsing */
1325                                                 vb->transport.len=tmp-vb->transport.s;
1326                                                 vb->proto=PROTO_TCP;
1327                                                 state=F_HOST; /* start looking for host*/
1328                                                 goto main_via;
1329                                         case FIN_TLS:
1330                                                 /* finished proto parsing */
1331                                                 vb->transport.len=tmp-vb->transport.s;
1332                                                 vb->proto=PROTO_TLS;
1333                                                 state=F_HOST; /* start looking for host*/
1334                                                 goto main_via;
1335                                         case FIN_SCTP:
1336                                                 /* finished proto parsing */
1337                                                 vb->transport.len=tmp-vb->transport.s;
1338                                                 vb->proto=PROTO_SCTP;
1339                                                 state=F_HOST; /* start looking for host*/
1340                                                 goto main_via;
1341                                         case WS_WSS2:
1342                                                 /* finished proto parsing */
1343                                                 vb->transport.len=tmp-vb->transport.s;
1344                                                 vb->proto=PROTO_WS;
1345                                                 state=F_HOST; /* start looking for host*/
1346                                                 goto main_via;
1347                                         case FIN_WSS:
1348                                                 /* finished proto parsing */
1349                                                 vb->transport.len=tmp-vb->transport.s;
1350                                                 vb->proto=PROTO_WSS;
1351                                                 state=F_HOST; /* start looking for host*/
1352                                                 goto main_via;
1353                                         case OTHER_PROTO:
1354                                                 /* finished proto parsing */
1355                                                 vb->transport.len=tmp-vb->transport.s;
1356                                                 vb->proto=PROTO_OTHER;
1357                                                 state=F_HOST; /* start looking for host*/
1358                                                 goto main_via;
1359                                         case UDP1:
1360                                         case UDP2:
1361                                         case TCP_TLS1:
1362                                         case TCP2:
1363                                         case TLS2:
1364                                         case SCTP1:
1365                                         case SCTP2:
1366                                         case SCTP3:
1367                                         case WS_WSS1:
1368                                                 /* finished proto parsing */
1369                                                 vb->transport.len=tmp-vb->transport.s;
1370                                                 vb->proto=PROTO_OTHER;
1371                                                 state=F_HOST; /* start looking for host*/
1372                                                 goto main_via;
1373                                         case FIN_SIP:
1374                                                 vb->name.len=tmp-vb->name.s;
1375                                                 state=L_VER;
1376                                                 break;
1377                                         case FIN_VER:
1378                                                 vb->version.len=tmp-vb->version.s;
1379                                                 state=L_PROTO;
1380                                                 break;
1381                                         case F_LF:
1382                                         case F_CRLF:
1383                                         case F_CR: /* header continues on this line */
1384                                                 state=saved_state;
1385                                                 break;
1386                                         default:
1387                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1388                                                                 " state %d\n", *tmp, state);
1389                                                 goto error;
1390                                 }
1391                                 break;
1392                         case '\n':
1393                                 switch(state){
1394                                         case L_VER:
1395                                         case F_SIP:
1396                                         case F_VER:
1397                                         case F_PROTO:
1398                                         case L_PROTO:
1399                                                 saved_state=state;
1400                                                 state=F_LF;
1401                                                 break;
1402                                         case FIN_UDP:
1403                                                 vb->transport.len=tmp-vb->transport.s;
1404                                                 vb->proto=PROTO_UDP;
1405                                                 state=F_LF;
1406                                                 saved_state=F_HOST; /* start looking for host*/
1407                                                 goto main_via;
1408                                         case FIN_TCP:
1409                                                 vb->transport.len=tmp-vb->transport.s;
1410                                                 vb->proto=PROTO_TCP;
1411                                                 state=F_LF;
1412                                                 saved_state=F_HOST; /* start looking for host*/
1413                                                 goto main_via;
1414                                         case FIN_TLS:
1415                                                 vb->transport.len=tmp-vb->transport.s;
1416                                                 vb->proto=PROTO_TLS;
1417                                                 state=F_LF;
1418                                                 saved_state=F_HOST; /* start looking for host*/
1419                                                 goto main_via;
1420                                         case FIN_SCTP:
1421                                                 /* finished proto parsing */
1422                                                 vb->transport.len=tmp-vb->transport.s;
1423                                                 vb->proto=PROTO_SCTP;
1424                                                 state=F_LF;
1425                                                 saved_state=F_HOST; /* start looking for host*/
1426                                                 goto main_via;
1427                                         case WS_WSS2:
1428                                                 /* finished proto parsing */
1429                                                 vb->transport.len=tmp-vb->transport.s;
1430                                                 vb->proto=PROTO_WS;
1431                                                 state=F_LF;
1432                                                 saved_state=F_HOST; /* start looking for host*/
1433                                                 goto main_via;
1434                                         case FIN_WSS:
1435                                                 /* finished proto parsing */
1436                                                 vb->transport.len=tmp-vb->transport.s;
1437                                                 vb->proto=PROTO_WSS;
1438                                                 state=F_LF;
1439                                                 saved_state=F_HOST; /* start looking for host*/
1440                                                 goto main_via;
1441                                         case OTHER_PROTO:
1442                                                 /* finished proto parsing */
1443                                                 vb->transport.len=tmp-vb->transport.s;
1444                                                 vb->proto=PROTO_OTHER;
1445                                                 state=F_LF;
1446                                                 saved_state=F_HOST; /* start looking for host*/
1447                                                 goto main_via;
1448                                         case UDP1:
1449                                         case UDP2:
1450                                         case TCP_TLS1:
1451                                         case TCP2:
1452                                         case TLS2:
1453                                         case SCTP1:
1454                                         case SCTP2:
1455                                         case SCTP3:
1456                                         case WS_WSS1:
1457                                                 /* finished proto parsing */
1458                                                 vb->transport.len=tmp-vb->transport.s;
1459                                                 vb->proto=PROTO_OTHER;
1460                                                 state=F_LF;
1461                                                 saved_state=F_HOST; /* start looking for host*/
1462                                                 goto main_via;
1463                                         case FIN_SIP:
1464                                                 vb->name.len=tmp-vb->name.s;
1465                                                 state=F_LF;
1466                                                 saved_state=L_VER;
1467                                                 break;
1468                                         case FIN_VER:
1469                                                 vb->version.len=tmp-vb->version.s;
1470                                                 state=F_LF;
1471                                                 saved_state=L_PROTO;
1472                                                 break;
1473                                         case F_CR:
1474                                                 state=F_CRLF;
1475                                                 break;
1476                                         case F_LF:
1477                                         case F_CRLF:
1478                                                 state=saved_state;
1479                                                 goto endofheader;
1480                                         default:
1481                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1482                                                                 " state %d\n", *tmp, state);
1483                                                 goto error;
1484                                 }
1485                                 break;
1486                         case '\r':
1487                                 switch(state){
1488                                         case L_VER:
1489                                         case F_SIP:
1490                                         case F_VER:
1491                                         case F_PROTO:
1492                                         case L_PROTO:
1493                                                 saved_state=state;
1494                                                 state=F_CR;
1495                                                 break;
1496                                         case FIN_UDP:
1497                                                 vb->transport.len=tmp-vb->transport.s;
1498                                                 vb->proto=PROTO_UDP;
1499                                                 state=F_CR;
1500                                                 saved_state=F_HOST;
1501                                                 goto main_via;
1502                                         case FIN_TCP:
1503                                                 vb->transport.len=tmp-vb->transport.s;
1504                                                 vb->proto=PROTO_TCP;
1505                                                 state=F_CR;
1506                                                 saved_state=F_HOST;
1507                                                 goto main_via;
1508                                         case FIN_TLS:
1509                                                 vb->transport.len=tmp-vb->transport.s;
1510                                                 vb->proto=PROTO_TLS;
1511                                                 state=F_CR;
1512                                                 saved_state=F_HOST;
1513                                                 goto main_via;
1514                                         case FIN_SCTP:
1515                                                 vb->transport.len=tmp-vb->transport.s;
1516                                                 vb->proto=PROTO_SCTP;
1517                                                 state=F_CR;
1518                                                 saved_state=F_HOST;
1519                                                 goto main_via;
1520                                         case WS_WSS2:
1521                                                 vb->transport.len=tmp-vb->transport.s;
1522                                                 vb->proto=PROTO_WS;
1523                                                 state=F_CR;
1524                                                 saved_state=F_HOST;
1525                                                 goto main_via;
1526                                         case FIN_WSS:
1527                                                 vb->transport.len=tmp-vb->transport.s;
1528                                                 vb->proto=PROTO_WSS;
1529                                                 state=F_CR;
1530                                                 saved_state=F_HOST;
1531                                                 goto main_via;
1532                                         case OTHER_PROTO:
1533                                                 vb->transport.len=tmp-vb->transport.s;
1534                                                 vb->proto=PROTO_OTHER;
1535                                                 state=F_CR;
1536                                                 saved_state=F_HOST;
1537                                                 goto main_via;
1538                                         case UDP1:
1539                                         case UDP2:
1540                                         case TCP_TLS1:
1541                                         case TCP2:
1542                                         case TLS2:
1543                                         case SCTP1:
1544                                         case SCTP2:
1545                                         case SCTP3:
1546                                         case WS_WSS1:
1547                                                 /* finished proto parsing */
1548                                                 vb->transport.len=tmp-vb->transport.s;
1549                                                 vb->proto=PROTO_OTHER;
1550                                                 state=F_CR;
1551                                                 saved_state=F_HOST;
1552                                                 goto main_via;
1553                                         case FIN_SIP:
1554                                                 vb->name.len=tmp-vb->name.s;
1555                                                 state=F_CR;
1556                                                 saved_state=L_VER;
1557                                                 break;
1558                                         case FIN_VER:
1559                                                 vb->version.len=tmp-vb->version.s;
1560                                                 state=F_CR;
1561                                                 saved_state=L_PROTO;
1562                                                 break;
1563                                         case F_LF: /*end of line ?next header?*/
1564                                         case F_CR:
1565                                         case F_CRLF:
1566                                                 state=saved_state;
1567                                                 goto endofheader;
1568                                         default:
1569                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1570                                                                 " state %d\n", *tmp, state);
1571                                                 goto error;
1572                                 }
1573                                 break;
1574                         
1575                         case '/':
1576                                 switch(state){
1577                                         case FIN_SIP:
1578                                                 vb->name.len=tmp-vb->name.s;
1579                                                 state=F_VER;
1580                                                 break;
1581                                         case FIN_VER:
1582                                                 vb->version.len=tmp-vb->version.s;
1583                                                 state=F_PROTO;
1584                                                 break;
1585                                         case L_VER:
1586                                                 state=F_VER;
1587                                                 break;
1588                                         case L_PROTO:
1589                                                 state=F_PROTO;
1590                                                 break;
1591                                         default:
1592                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1593                                                                 " state %d\n", *tmp, state);
1594                                                 goto error;
1595                                 }
1596                                 break;
1597                                 /* match SIP*/
1598                         case 'S':
1599                         case 's':
1600                                 switch(state){
1601                                         case F_SIP:
1602                                                 state=SIP1;
1603                                                 vb->name.s=tmp;
1604                                                 break;
1605                                         case TLS2:
1606                                                 state=FIN_TLS;
1607                                                 break;
1608                                         case WS_WSS1:
1609                                                 state=WS_WSS2;
1610                                                 break;
1611                                         case WS_WSS2:
1612                                                 state=FIN_WSS;
1613                                                 break;
1614                                         case F_PROTO:
1615                                                 state=SCTP1;
1616                                                 vb->transport.s=tmp;
1617                                                 break;
1618                                         case OTHER_PROTO:
1619                                                 break;
1620                                         case UDP1:
1621                                         case UDP2:
1622                                         case FIN_UDP:
1623                                         case TCP_TLS1:
1624                                         case TCP2:
1625                                         case FIN_TCP:
1626                                         case FIN_TLS:
1627                                         case SCTP1:
1628                                         case SCTP2:
1629                                         case SCTP3:
1630                                         case FIN_WSS:
1631                                         case FIN_SCTP:
1632                                                 state=OTHER_PROTO;
1633                                                 break;
1634                                         default:
1635                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1636                                                                 " state %d\n", *tmp, state);
1637                                                 goto error;
1638                                 }
1639                                 break;
1640                         case 'I':
1641                         case 'i':
1642                                 switch(state){
1643                                         case SIP1:
1644                                                 state=SIP2;
1645                                                 break;
1646                                         case OTHER_PROTO:
1647                                                 break;
1648                                         case UDP1:
1649                                         case UDP2:
1650                                         case FIN_UDP:
1651                                         case TCP_TLS1:
1652                                         case TCP2:
1653                                         case FIN_TCP:
1654                                         case TLS2:
1655                                         case FIN_TLS:
1656                                         case SCTP1:
1657                                         case SCTP2:
1658                                         case SCTP3:
1659                                         case FIN_SCTP:
1660                                         case WS_WSS1:
1661                                         case WS_WSS2:
1662                                         case FIN_WSS:
1663                                                 state=OTHER_PROTO;
1664                                                 break;
1665                                         default:
1666                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1667                                                                 " state %d\n", *tmp, state);
1668                                                 goto error;
1669                                 }
1670                                 break;
1671                         case 'p':
1672                         case 'P':
1673                                 switch(state){
1674                                         case SIP2:
1675                                                 state=FIN_SIP;
1676                                                 break;
1677                                         /* allow p in PROTO */
1678                                         case UDP2:
1679                                                 state=FIN_UDP;
1680                                                 break;
1681                                         case TCP2:
1682                                                 state=FIN_TCP;
1683                                                 break;
1684                                         case SCTP3:
1685                                                 state=FIN_SCTP;
1686                                                 break;
1687                                         case OTHER_PROTO:
1688                                                 break;
1689                                         case UDP1:
1690                                         case FIN_UDP:
1691                                         case TCP_TLS1:
1692                                         case FIN_TCP:
1693                                         case TLS2:
1694                                         case FIN_TLS:
1695                                         case SCTP1:
1696                                         case SCTP2:
1697                                         case FIN_SCTP:
1698                                         case WS_WSS1:
1699                                         case WS_WSS2:
1700                                         case FIN_WSS:
1701                                                 state=OTHER_PROTO;
1702                                                 break;
1703                                         default:
1704                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1705                                                                 " state %d\n", *tmp, state);
1706                                                 goto error;
1707                                 }
1708                                 break;
1709                         case 'U':
1710                         case 'u':
1711                                 switch(state){
1712                                         case F_PROTO:
1713                                                 state=UDP1;
1714                                                 vb->transport.s=tmp;
1715                                                 break;
1716                                         case OTHER_PROTO:
1717                                                 break;
1718                                         case UDP1:
1719                                         case UDP2:
1720                                         case FIN_UDP:
1721                                         case TCP_TLS1:
1722                                         case TCP2:
1723                                         case FIN_TCP:
1724                                         case TLS2:
1725                                         case FIN_TLS:
1726                                         case SCTP1:
1727                                         case SCTP2:
1728                                         case SCTP3:
1729                                         case FIN_SCTP:
1730                                         case WS_WSS1:
1731                                         case WS_WSS2:
1732                                         case FIN_WSS:
1733                                                 state=OTHER_PROTO;
1734                                                 break;
1735                                         default:
1736                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1737                                                                 " state %d\n", *tmp, state);
1738                                                 goto error;
1739                                 }
1740                                 break;
1741                         case 'D':
1742                         case 'd':
1743                                 switch(state){
1744                                         case UDP1:
1745                                                 state=UDP2;
1746                                                 break;
1747                                         case OTHER_PROTO:
1748                                                 break;
1749                                         case UDP2:
1750                                         case FIN_UDP:
1751                                         case TCP_TLS1:
1752                                         case TCP2:
1753                                         case FIN_TCP:
1754                                         case TLS2:
1755                                         case FIN_TLS:
1756                                         case SCTP1:
1757                                         case SCTP2:
1758                                         case SCTP3:
1759                                         case FIN_SCTP:
1760                                         case WS_WSS1:
1761                                         case WS_WSS2:
1762                                         case FIN_WSS:
1763                                                 state=OTHER_PROTO;
1764                                                 break;
1765                                         default:
1766                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1767                                                                 " state %d\n", *tmp, state);
1768                                                 goto error;
1769                                 }
1770                                 break;
1771                         case 'T':
1772                         case 't':
1773                                 switch(state){
1774                                         case F_PROTO:
1775                                                 state=TCP_TLS1;
1776                                                 vb->transport.s=tmp;
1777                                                 break;
1778                                         case SCTP2:
1779                                                 state=SCTP3;
1780                                                 break;
1781                                         case OTHER_PROTO:
1782                                                 break;
1783                                         case UDP1:
1784                                         case UDP2:
1785                                         case FIN_UDP:
1786                                         case TCP_TLS1:
1787                                         case TCP2:
1788                                         case FIN_TCP:
1789                                         case TLS2:
1790                                         case FIN_TLS:
1791                                         case SCTP1:
1792                                         case SCTP3:
1793                                         case FIN_SCTP:
1794                                         case WS_WSS1:
1795                                         case WS_WSS2:
1796                                         case FIN_WSS:
1797                                                 state=OTHER_PROTO;
1798                                                 break;
1799                                         default:
1800                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1801                                                                 " state %d\n", *tmp, state);
1802                                                 goto error;
1803                                 }
1804                                 break;
1805                         case 'C':
1806                         case 'c':
1807                                 switch(state){
1808                                         case TCP_TLS1:
1809                                                 state=TCP2;
1810                                                 break;
1811                                         case SCTP1:
1812                                                 state=SCTP2;
1813                                                 break;
1814                                         case OTHER_PROTO:
1815                                                 break;
1816                                         case UDP1:
1817                                         case UDP2:
1818                                         case FIN_UDP:
1819                                         case TCP2:
1820                                         case FIN_TCP:
1821                                         case TLS2:
1822                                         case FIN_TLS:
1823                                         case SCTP2:
1824                                         case SCTP3:
1825                                         case FIN_SCTP:
1826                                         case WS_WSS1:
1827                                         case WS_WSS2:
1828                                         case FIN_WSS:
1829                                                 state=OTHER_PROTO;
1830                                                 break;
1831                                         default:
1832                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1833                                                                 " state %d\n", *tmp, state);
1834                                                 goto error;
1835                                 }
1836                                 break;
1837                         case 'L':
1838                         case 'l':
1839                                 switch(state){
1840                                         case TCP_TLS1:
1841                                                 state=TLS2;
1842                                                 break;
1843                                         case OTHER_PROTO:
1844                                                 break;
1845                                         case UDP1:
1846                                         case UDP2:
1847                                         case FIN_UDP:
1848                                         case TCP2:
1849                                         case FIN_TCP:
1850                                         case TLS2:
1851                                         case FIN_TLS:
1852                                         case SCTP1:
1853                                         case SCTP2:
1854                                         case SCTP3:
1855                                         case FIN_SCTP:
1856                                         case WS_WSS1:
1857                                         case WS_WSS2:
1858                                         case FIN_WSS:
1859                                                 state=OTHER_PROTO;
1860                                                 break;
1861                                         default:
1862                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1863                                                                 " state %d\n", *tmp, state);
1864                                                 goto error;
1865                                 }
1866                                 break;
1867                         case 'W':
1868                         case 'w':
1869                                 switch(state){
1870                                         case F_PROTO:
1871                                                 state=WS_WSS1;
1872                                                 vb->transport.s=tmp;
1873                                                 break;
1874                                         case OTHER_PROTO:
1875                                                 break;
1876                                         case UDP1:
1877                                         case UDP2:
1878                                         case FIN_UDP:
1879                                         case TCP_TLS1:
1880                                         case TCP2:
1881                                         case FIN_TCP:
1882                                         case TLS2:
1883                                         case FIN_TLS:
1884                                         case SCTP1:
1885                                         case SCTP2:
1886                                         case SCTP3:
1887                                         case FIN_SCTP:
1888                                         case WS_WSS1:
1889                                         case WS_WSS2:
1890                                         case FIN_WSS:
1891                                                 state=OTHER_PROTO;
1892                                                 break;
1893                                         default:
1894                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1895                                                                 " state %d\n", *tmp, state);
1896                                                 goto error;
1897                                 }
1898                                 break;
1899                         /*match 2.0*/
1900                         case '2':
1901                                 switch(state){
1902                                         case F_VER:
1903                                                 state=VER1;
1904                                                 vb->version.s=tmp;
1905                                                 break;
1906                                         case OTHER_PROTO:
1907                                                 break;
1908                                         case UDP1:
1909                                         case UDP2:
1910                                         case FIN_UDP:
1911                                         case TCP_TLS1:
1912                                         case TCP2:
1913                                         case FIN_TCP:
1914                                         case TLS2:
1915                                         case FIN_TLS:
1916                                         case SCTP1:
1917                                         case SCTP2:
1918                                         case SCTP3:
1919                                         case FIN_SCTP:
1920                                         case WS_WSS1:
1921                                         case WS_WSS2:
1922                                         case FIN_WSS:
1923                                                 state=OTHER_PROTO;
1924                                                 break;
1925                                         default:
1926                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1927                                                                 " state %d\n", *tmp, state);
1928                                                 goto error;
1929                                 }
1930                                 break;
1931                         case '.':
1932                                 switch(state){
1933                                         case VER1:
1934                                                 state=VER2;
1935                                                 break;
1936                                         case OTHER_PROTO:
1937                                                 break;
1938                                         case UDP1:
1939                                         case UDP2:
1940                                         case FIN_UDP:
1941                                         case TCP_TLS1:
1942                                         case TCP2:
1943                                         case FIN_TCP:
1944                                         case TLS2:
1945                                         case FIN_TLS:
1946                                         case SCTP1:
1947                                         case SCTP2:
1948                                         case SCTP3:
1949                                         case FIN_SCTP:
1950                                         case WS_WSS1:
1951                                         case WS_WSS2:
1952                                         case FIN_WSS:
1953                                                 state=OTHER_PROTO;
1954                                                 break;
1955                                         default:
1956                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1957                                                                 " state %d\n", *tmp, state);
1958                                                 goto error;
1959                                 }
1960                                  break;
1961                         case '0':
1962                                 switch(state){
1963                                         case VER2:
1964                                                 state=FIN_VER;
1965                                                 break;
1966                                         case OTHER_PROTO:
1967                                                 break;
1968                                         case UDP1:
1969                                         case UDP2:
1970                                         case FIN_UDP:
1971                                         case TCP_TLS1:
1972                                         case TCP2:
1973                                         case FIN_TCP:
1974                                         case TLS2:
1975                                         case FIN_TLS:
1976                                         case SCTP1:
1977                                         case SCTP2:
1978                                         case SCTP3:
1979                                         case FIN_SCTP:
1980                                         case WS_WSS1:
1981                                         case WS_WSS2:
1982                                         case FIN_WSS:
1983                                                 state=OTHER_PROTO;
1984                                                 break;
1985                                         default:
1986                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
1987                                                                 " state %d\n", *tmp, state);
1988                                                 goto error;
1989                                 }
1990                                 break;
1991                         default:
1992                                 switch(state){
1993                                         case F_PROTO:
1994                                                 state=OTHER_PROTO;
1995                                                 vb->transport.s=tmp;
1996                                                 break;
1997                                         case OTHER_PROTO:
1998                                                 break;
1999                                         case UDP1:
2000                                         case UDP2:
2001                                         case FIN_UDP:
2002                                         case TCP_TLS1:
2003                                         case TCP2:
2004                                         case FIN_TCP:
2005                                         case TLS2:
2006                                         case FIN_TLS:
2007                                         case SCTP1:
2008                                         case SCTP2:
2009                                         case SCTP3:
2010                                         case FIN_SCTP:
2011                                         case WS_WSS1:
2012                                         case WS_WSS2:
2013                                         case FIN_WSS:
2014                                                 state=OTHER_PROTO;
2015                                                 break;
2016                                         default:
2017                                                 LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
2018                                                 " state %d\n", *tmp, state);
2019                                                 goto error;
2020                                 }
2021                                 break;
2022                 }
2023         } /* for tmp*/
2024
2025         /* we should not be here! if everything is ok > main_via*/
2026         LOG(L_ERR, "ERROR: parse_via: bad via: end of packet on state=%d\n",
2027                         state);
2028         goto error;
2029
2030  main_via:
2031         /* inc tmp to point to the next char*/
2032         tmp++;
2033         c_nest=0;
2034         /*state should always be F_HOST here*/;
2035         for(;*tmp;tmp++){
2036                 switch(*tmp){
2037                 case ' ':
2038                 case '\t':
2039                         switch(state){
2040                                         case F_HOST:/*eat the spaces*/
2041                                                 break;
2042                                         case P_HOST:
2043                                                  /*mark end of host*/
2044                                                  vb->host.len=tmp-vb->host.s;
2045                                                  state=L_PORT;
2046                                                  break;
2047                                         case L_PORT: /*eat the spaces*/
2048                                         case F_PORT:
2049                                                 break;
2050                                         case P_PORT:
2051                                                 /*end of port */
2052                                                 vb->port_str.len=tmp-vb->port_str.s;
2053                                                 state=L_PARAM;
2054                                                 break;
2055                                         case L_PARAM: /* eat the space */
2056                                         case F_PARAM:
2057                                                 break;
2058                                         case P_PARAM:
2059                                         /*      *tmp=0;*/ /*!?end of param*/
2060                                                 state=L_PARAM;
2061                                                 break;
2062                                         case L_VIA:
2063                                         case F_VIA: /* eat the space */
2064                                                 break;
2065                                         case F_COMMENT:
2066                                         case P_COMMENT:
2067                                                 break;
2068                                         case F_IP6HOST: /*no spaces allowed*/
2069                                         case P_IP6HOST:
2070                                                 LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
2071                                                 goto error;
2072                                         case F_CRLF:
2073                                         case F_LF:
2074                                         case F_CR:
2075                                                 /*previous=crlf and now =' '*/
2076                                                 state=saved_state;
2077                                                 break;
2078                                         default:
2079                                                 LOG(L_CRIT,"BUG: parse_via"
2080                                                         " on <%c>, state=%d\n",*tmp, state);
2081                                                 goto  error;
2082                                 }
2083                         break;
2084                         case '\n':
2085                                 switch(state){
2086                                         case F_HOST:/*eat the spaces*/
2087                                         case L_PORT: /*eat the spaces*/
2088                                         case F_PORT:
2089                                         case L_PARAM: /* eat the space */
2090                                         case F_PARAM:
2091                                         case F_VIA: /* eat the space */
2092                                         case L_VIA:
2093                                         case F_COMMENT:
2094                                         case P_COMMENT:
2095                                         case F_IP6HOST:
2096                                         case P_IP6HOST:
2097                                                 saved_state=state;
2098                                                 state=F_LF;
2099                                                 break;
2100                                         case P_HOST:
2101                                                  /*mark end of host*/
2102                                                  vb->host.len=tmp-vb->host.s;
2103                                                  saved_state=L_PORT;
2104                                                  state=F_LF;
2105                                                  break;
2106                                         case P_PORT:
2107                                                 /*end of port */
2108                                                 vb->port_str.len=tmp-vb->port_str.s;
2109                                                 saved_state=L_PARAM;
2110                                                 state=F_LF;
2111                                                 break;
2112                                         case P_PARAM:
2113                                         /*      *tmp=0;*/ /*!?end of param*/
2114                                                 saved_state=L_PARAM;
2115                                                 state=F_LF;
2116                                                 break;
2117                                         case F_CR:
2118                                                 state=F_CRLF;
2119                                                 break;
2120                                         case F_CRLF:
2121                                         case F_LF:
2122                                                 state=saved_state;
2123                                                 goto endofheader;
2124                                         default:
2125                                                 LOG(L_CRIT,"BUG: parse_via"
2126                                                         " on <%c>\n",*tmp);
2127                                                 goto  error;
2128                                 }
2129                         break;
2130                 case '\r':
2131                                 switch(state){
2132                                         case F_HOST:/*eat the spaces*/
2133                                         case L_PORT: /*eat the spaces*/
2134                                         case F_PORT:
2135                                         case L_PARAM: /* eat the space */
2136                                         case F_PARAM:
2137                                         case F_VIA: /* eat the space */
2138                                         case L_VIA:
2139                                         case F_COMMENT:
2140                                         case P_COMMENT:
2141                                         case F_IP6HOST:
2142                                         case P_IP6HOST:
2143                                                 saved_state=state;
2144                                                 state=F_CR;
2145                                                 break;
2146                                         case P_HOST:
2147                                                  /*mark end of host*/
2148                                                  vb->host.len=tmp-vb->host.s;
2149                                                  saved_state=L_PORT;
2150                                                  state=F_CR;
2151                                                  break;
2152                                         case P_PORT:
2153                                                 /*end of port */
2154                                                 vb->port_str.len=tmp-vb->port_str.s;
2155                                                 saved_state=L_PARAM;
2156                                                 state=F_CR;
2157                                                 break;
2158                                         case P_PARAM:
2159                                         /*      *tmp=0;*/ /*!?end of param*/
2160                                                 saved_state=L_PARAM;
2161                                                 state=F_CR;
2162                                                 break;
2163                                         case F_CRLF:
2164                                         case F_CR:
2165                                         case F_LF:
2166                                                 state=saved_state;
2167                                                 goto endofheader;
2168                                         default: