GPLization banner introduced to *.[hc] files
[sip-router] / test / auto.c
1
2 /* test program -> switch speed */
3 /*
4  *
5  * Copyright (C) 2001-2003 Fhg Fokus
6  *
7  * This file is part of ser, a free SIP server.
8  *
9  * ser is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version
13  *
14  * For a license to use the ser software under conditions
15  * other than those described here, or to purchase support for this
16  * software, please contact iptel.org by e-mail at the following addresses:
17  *    info@iptel.org
18  *
19  * ser is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License 
25  * along with this program; if not, write to the Free Software 
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27  */
28
29
30
31 /* parsing:           compact form:
32  * Via:               v:
33  * From:              f:
34  * To:                t:
35  * Cseq:              n/a
36  * Call-ID:           i:
37  * Contact:           m:
38  * Max-Forwards:      n/a
39  * Route:             n/a
40  */
41
42 enum { INITIAL=0,
43                 VIA1, VIA2,
44                 FROM1, FROM2, FROM3,
45                 TO1,
46                 C_START, CSEQ2, CSEQ3,
47                          CALLID2, CALLID3, CALLID4, CALLID5, CALLID6,
48                          CONTACT2, CONTACT3, CONTACT4, CONTACT5, CONTACT6,
49                 M_START,      MAXFORWARDS2, MAXFORWARDS3, MAXFORWARDS4, MAXFORWARDS5,
50                 MAXFORWARDS6, MAXFORWARDS7, MAXFORWARDS8, MAXFORWARDS9, MAXFORWARDS10,
51                 MAXFORWARDS11,
52                 ROUTE1, ROUTE2, ROUTE3, ROUTE4,
53                 /* final states*/
54                 F_VIA=1000, F_FROM, F_TO, F_CSEQ, F_CALLID, F_CONTACT, F_MAXFORWARDS,
55                 F_ROUTE,
56                 I_START,
57
58                 UNKNOWN_HEADER=200,
59                 BODY=220,
60                 LF=25000,
61         };
62
63 #include <stdio.h>
64
65 int main(int argc, char** argv)
66 {
67
68         char* t;
69         register int state;
70         int i;
71         int err;
72         err=0;
73
74         state=INITIAL;
75         printf(" %s (%d)\n", argv[0], argc);
76         if (argc<2){
77                         fprintf(stderr, " no parameters\n");
78                         exit(-1);
79         }
80         
81         for (i=0;i<10000000;i++){
82                 
83         for(t=argv[1];*t;t++){
84                 switch(*t){
85                         case 'V':
86                         case 'v':
87                                         switch(state){
88                                                 case INITIAL:
89                                                         state=VIA1;
90                                                         break;
91                                                 case UNKNOWN_HEADER: break;
92                                                 default:
93                                                         state=UNKNOWN_HEADER;
94                                         }
95                                         break;
96                         case 'I':
97                         case 'i':
98                                         switch(state){
99                                                 case VIA1:
100                                                         state=VIA2;
101                                                         break;
102                                                 case CALLID5:
103                                                         state=CALLID6;
104                                                         break;
105                                                 case INITIAL:
106                                                         state=I_START;
107                                                         break;
108                                                 case UNKNOWN_HEADER: break;
109                                                 default:
110                                                         state=UNKNOWN_HEADER;
111                                         }
112                                         break;
113                         case 'A':
114                         case 'a':
115                                         switch(state){
116                                                 case VIA2:
117                                                                 state=F_VIA;
118                                                                 break;
119                                                 case C_START:  /*CALLID1*/
120                                                                 state=CALLID2;
121                                                                 break;
122                                                 case CONTACT4:
123                                                                 state=CONTACT5;
124                                                                 break;
125                                                 case M_START:
126                                                                 state=MAXFORWARDS2;
127                                                                 break;
128                                                 case MAXFORWARDS8:
129                                                                 state=MAXFORWARDS9;
130                                                                 break;
131                                                 case UNKNOWN_HEADER: break;
132                                                 default:
133                                                                 state=UNKNOWN_HEADER;
134                                         }
135                                         break;
136                         case 'F':
137                         case 'f':
138                                         switch(state){
139                                                 case INITIAL:
140                                                                 state=FROM1;
141                                                                 break;
142                                                 case MAXFORWARDS4:
143                                                                 state=MAXFORWARDS5;
144                                                                 break;
145                                                 case UNKNOWN_HEADER: break;
146                                                 default:
147                                                                 state=UNKNOWN_HEADER;
148                                         }
149                                         break;
150                         case 'R':
151                         case 'r':
152                                         switch(state){
153                                                 case INITIAL:
154                                                         state=ROUTE1;
155                                                         break;
156                                                 case FROM1:
157                                                         state=FROM2;
158                                                         break;
159                                                 case MAXFORWARDS6:
160                                                         state=MAXFORWARDS7;
161                                                         break;
162                                                 case MAXFORWARDS9:
163                                                         state=MAXFORWARDS10;
164                                                         break;
165                                                 case UNKNOWN_HEADER: break;
166                                                 default:
167                                                         state=UNKNOWN_HEADER;
168                                         }
169                                         break;
170                         case 'O':
171                         case 'o':
172                                         switch(state){
173                                                 case FROM2:
174                                                         state=FROM3;
175                                                         break;
176                                                 case TO1:
177                                                         state=F_TO;
178                                                         break;
179                                                 case C_START: /*CONTACT1 */
180                                                         state=CONTACT2;
181                                                         break;
182                                                 case ROUTE1:
183                                                         state=ROUTE2;
184                                                         break;
185                                                 case MAXFORWARDS5:
186                                                         state=MAXFORWARDS6;
187                                                         break;
188                                                 case UNKNOWN_HEADER: break;
189                                                 default:
190                                                         state=UNKNOWN_HEADER;
191                                         }
192                                         break;
193                         case 'M':
194                         case 'm':
195                                                 switch(state){
196                                                         case INITIAL:
197                                                                 state=M_START;
198                                                                 break;
199                                                         case FROM3:
200                                                                 state=F_FROM;
201                                                                 break;
202                                                         case UNKNOWN_HEADER: break;
203                                                         default:
204                                                                 state=UNKNOWN_HEADER;
205                                                 }
206                                                 break;
207                         case 'T':
208                         case 't':
209                                                 switch(state){
210                                                         case INITIAL:
211                                                                 state=TO1;
212                                                                 break;
213                                                         case CONTACT3:
214                                                                 state=CONTACT4;
215                                                                 break;
216                                                         case CONTACT6:
217                                                                 state=F_CONTACT;
218                                                                 break;
219                                                         case ROUTE3:
220                                                                 state=ROUTE4;
221                                                                 break;
222                                                         case UNKNOWN_HEADER: break;
223                                                         default:
224                                                                 state=UNKNOWN_HEADER;
225                                                 }
226                                                 break;
227                         case 'C':
228                         case 'c':
229                                                 switch(state){
230                                                         case INITIAL:
231                                                                 state=C_START;
232                                                                 break;
233                                                         case CONTACT5:
234                                                                 state=CONTACT6;
235                                                                 break;
236                                                         case UNKNOWN_HEADER: break;
237                                                         default:
238                                                                 state=UNKNOWN_HEADER;
239                                                 }
240                                                 break;
241                         case 'S':
242                         case 's':
243                                                 switch(state){
244                                                         case C_START:
245                                                                 state=CSEQ2;
246                                                                 break;
247                                                         case MAXFORWARDS11:
248                                                                 state=F_MAXFORWARDS;
249                                                                 break;
250                                                         case UNKNOWN_HEADER: break;
251                                                         default:
252                                                                 state=UNKNOWN_HEADER;
253                                                 }
254                                                 break;
255                         case 'E':
256                         case 'e':
257                                                 switch(state){
258                                                         case CSEQ2:
259                                                                 state=CSEQ3;
260                                                                 break;
261                                                         case ROUTE4:
262                                                                 state=F_ROUTE;
263                                                                 break;
264                                                         case UNKNOWN_HEADER: break;
265                                                         default:
266                                                                 state=UNKNOWN_HEADER;
267                                                 }
268                                                 break;
269                         case 'Q':
270                         case 'q':
271                                                 switch(state){
272                                                         case CSEQ3:
273                                                                 state=F_CSEQ;
274                                                                 break;
275                                                         case UNKNOWN_HEADER: break;
276                                                         default:
277                                                                 state=UNKNOWN_HEADER;
278                                                 }
279                                                 break;
280                         case 'L':
281                         case 'l':
282                                                 switch(state){
283                                                         case CALLID2:
284                                                                 state=CALLID3;
285                                                                 break;
286                                                         case CALLID3:
287                                                                 state=CALLID4;
288                                                                 break;
289                                                         case UNKNOWN_HEADER: break;
290                                                         default:
291                                                                 state=UNKNOWN_HEADER;
292                                                 }
293                                                 break;
294                         case 'D':
295                         case 'd':
296                                                 switch(state){
297                                                         case CALLID6:
298                                                                 state=F_CALLID;
299                                                                 break;
300                                                         case MAXFORWARDS10:
301                                                                 state=MAXFORWARDS11;
302                                                                 break;
303                                                         case UNKNOWN_HEADER: break;
304                                                         default:
305                                                                 state=UNKNOWN_HEADER;
306                                                 }
307                                                 break;
308                         case 'N':
309                         case 'n':
310                                                 switch(state){
311                                                         case CONTACT2:
312                                                                 state=CONTACT3;
313                                                                 break;
314                                                         case UNKNOWN_HEADER: break;
315                                                         default:
316                                                                 state=UNKNOWN_HEADER;
317                                                 }
318                                                 break;
319                         case 'X':
320                         case 'x':
321                                                 switch(state){
322                                                         case MAXFORWARDS2:
323                                                                 state=MAXFORWARDS3;
324                                                                 break;
325                                                         case UNKNOWN_HEADER: break;
326                                                         default:
327                                                                 state=UNKNOWN_HEADER;
328                                                 }
329                                                 break;
330                         case '-':
331                                                 switch(state){
332                                                         case CALLID4:
333                                                                 state=CALLID5;
334                                                                 break;
335                                                         case MAXFORWARDS3:
336                                                                 state=MAXFORWARDS4;
337                                                                 break;
338                                                         case UNKNOWN_HEADER: break;
339                                                         default:
340                                                                 state=UNKNOWN_HEADER;
341                                                 }
342                                                 break;
343                         case 'W':
344                         case 'w':
345                                                 switch(state){
346                                                         case MAXFORWARDS7:
347                                                                 state=MAXFORWARDS8;
348                                                                 break;
349                                                         case UNKNOWN_HEADER: break;
350                                                         default:
351                                                                 state=UNKNOWN_HEADER;
352                                                 }
353                                                 break;
354                         case 'U':
355                         case 'u':
356                                                 switch(state){
357                                                         case ROUTE2:
358                                                                 state=ROUTE3;
359                                                                 break;
360                                                         case UNKNOWN_HEADER: break;
361                                                         default:
362                                                                 state=UNKNOWN_HEADER;
363                                                 }
364                                                 break;
365                         case ' ':
366                                                 switch(state){
367                                                         case INITIAL:
368                                                                 break; /*eat space */
369                                                         case F_VIA:
370                                                         case F_FROM:
371                                                         case F_TO:
372                                                         case F_CSEQ:
373                                                         case F_CALLID:
374                                                         case F_CONTACT:
375                                                         case F_MAXFORWARDS:
376                                                         case F_ROUTE:
377                                                                 break; /* eat trailing space*/
378                                                         case VIA1:
379                                                                 /*compact form: v: */
380                                                                 state=F_VIA;
381                                                                 break;
382                                                         case FROM1:
383                                                                 /*compact form f:*/
384                                                                 state=F_FROM;
385                                                                 break;
386                                                         case TO1:
387                                                                 /*compact form t:*/
388                                                                 state=F_TO;
389                                                                 break;
390                                                         case I_START:
391                                                                 /*compact form i: (Call-ID)*/
392                                                                 state=F_CALLID;
393                                                                 break;
394                                                         case M_START:
395                                                                 /*compact form m: (Contact)*/
396                                                                 state=F_CONTACT;
397                                                                 break;
398                                                         case UNKNOWN_HEADER: break;
399                                                         default:
400                                                                 state=UNKNOWN_HEADER;
401                                                 }
402                                                 break;
403                         case ':':
404                                                 switch(state){
405                                                         case F_VIA:
406                                                         case VIA1: /* compact form*/
407                                                         case F_FROM:
408                                                         case FROM1: /*compact form*/
409                                                         case F_TO:
410                                                         case TO1: /*compact form*/
411                                                         case F_CSEQ:
412                                                         case F_CALLID:
413                                                         case I_START: /*compact form*/
414                                                         case F_CONTACT:
415                                                         case M_START: /*compact form*/
416                                                         case F_MAXFORWARDS:
417                                                         case F_ROUTE:
418                                                         //      printf("found header, state=%d\n", state);
419                                                                 state=INITIAL; /* reset to test*/
420                                                                 break;
421                                                         case UNKNOWN_HEADER:
422                                                         default:
423                                                                 /*printf("found unkown header, state=%d\n", 
424                                                                                         state);*/
425                                                                 err=1;
426                                                                 state=INITIAL;
427                                                 }
428                                                 break;
429                         default:
430                                         /*fprintf(stderr, "Unexpected char <%c> encountered"
431                                                                                 " state=%d\n", *t, state);
432                                                 exit(-1);*/
433                                         state=UNKNOWN_HEADER;
434                 }
435         }
436
437         } //for i
438         if (err) printf("Error unknown header\n");
439         printf("final state=%d\n", state);
440
441         exit(0);
442
443 }
444