Browse code

- updated TODO - more bloat into via_parse.c

Andrei Pelinescu-Onciul authored on 06/11/2001 00:11:56
Showing 2 changed files
... ...
@@ -6,10 +6,11 @@ $Id$
6 6
  ipv6 addresses ([fec0:aa::01]).
7 7
 - fix format string vulnerability in log()
8 8
 - fix alignement access problems (warning on Sun)
9
+- add request header bitmap field for the modules
9 10
 
10 11
 High priority:
11 12
 x if () {} else {}
12
-- plugin interface
13
+x plugin interface
13 14
 - ipv6 support
14 15
 - reply ("response line")
15 16
 - drop ACKs for our replies
... ...
@@ -22,9 +22,12 @@ enum{	         F_HOST,    P_HOST,
22 22
 		L_PARAM, F_PARAM,   P_PARAM,
23 23
 		L_VIA,   F_VIA,
24 24
 		         F_COMMENT, P_COMMENT,
25
+				 F_IP6HOST, P_IP6HOST,
25 26
 				 F_CRLF,
26 27
 				 F_LF
27 28
 	};
29
+enum{
30
+	};
28 31
 
29 32
 #define LOG(lev, fmt, args...) fprintf(stderr, fmt, ## args)
30 33
 
... ...
@@ -51,12 +54,123 @@ int main(int argc, char** argv)
51 54
 			exit(-1);
52 55
 	}
53 56
 	
54
-	
57
+	/* parse start of via ( SIP/2.0/UDP    )*/
58
+	state=F_SIP;
59
+	for(tmp=argv[1];*tmp;tmp++){
60
+		switch(*tmp){
61
+			case ' ':
62
+			case'\t':
63
+				switch(state){
64
+					case L_SIP: /*eat space*/
65
+					case L_SLASH1:
66
+					case L_SLASH2:
67
+					case L_VER:
68
+					case L_PROTO:
69
+					case F_SIP:
70
+					case F_VER:
71
+					case F_PROTO:
72
+						break;
73
+					case P_PROTO:
74
+						*tmp=0;
75
+						state=F_HOST;
76
+						break;
77
+					case F_LF:
78
+					case F_CRLF:
79
+					case F_CR:
80
+						state=saved_state;
81
+						break;
82
+					default:
83
+						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
84
+								" state %d\n", *tmp, state);
85
+						goto error;
86
+				}
87
+				break;
88
+			case '\n':
89
+				switch(state){
90
+					case L_SIP:
91
+					case L_SLASH1:
92
+					case L_SLASH2:
93
+					case L_VER:
94
+					case F_SIP:
95
+					case F_VER:
96
+					case F_PROTO:
97
+						saved_state=state;
98
+						state=F_LF;
99
+						break;
100
+					case P_PROTO:
101
+						*tmp=0;
102
+						state=F_LF;
103
+						saved_state=;
104
+						break;
105
+					case F_CR:
106
+						state=F_CRLF;
107
+						break;
108
+					case F_LF:
109
+					case F_CRLF:
110
+						state=saved_state;
111
+						goto endofheader;
112
+					default:
113
+						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
114
+								" state %d\n", *tmp, state);
115
+						goto error;
116
+				}
117
+				break;
118
+			case '\r':
119
+				switch(state){
120
+					case L_SIP:
121
+					case L_SLASH1:
122
+					case L_SLASH2:
123
+					case L_VER:
124
+					case F_SIP:
125
+					case F_VER:
126
+					case F_PROTO:
127
+						saved_state=state;
128
+						state=F_CR;
129
+						break;
130
+					case P_PROTO:
131
+						*tmp=0;
132
+						state=F_CR;
133
+						saved_state=;
134
+						break;
135
+					case F_LF: /*end of line ?next header?*/
136
+					case F_CR:
137
+					case F_CRLF:
138
+						state=saved_state;
139
+						goto endofheader;
140
+					default:
141
+						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
142
+								" state %d\n", *tmp, state);
143
+						goto error;
144
+				}
145
+				break;
146
+			
147
+			case '\\':
148
+				switch(state){
149
+					case L_VER:
150
+						*tmp=0;
151
+						state=F_VER;
152
+						break;
153
+					case L_PROTO:
154
+						*tmp=0;
155
+						state=F_PROTO;
156
+						break;
157
+					case L_
158
+
159
+
160
+						
161
+				
162
+								
163
+								
164
+
165
+			
166
+	}
167
+
55 168
 	c_nest=0;
56 169
 	state=F_HOST;
57
-	for(tmp=argv[1];*tmp;tmp++){
170
+	for(;*tmp;tmp++){
58 171
 		switch(*tmp){
59 172
 			case ' ':
173
+			case '\t':
60 174
 				switch(state){
61 175
 					case F_HOST:/*eat the spaces*/
62 176
 						break;
... ...
@@ -84,14 +198,21 @@ int main(int argc, char** argv)
84 198
 					case F_COMMENT:
85 199
 					case P_COMMENT:
86 200
 						break;
201
+					case F_IP6HOST: /*eat the spaces*/
202
+						break;
203
+					case P_IP6HOST:
204
+						*tmp=0; /*mark end of host*/
205
+						state=L_PORT; 
206
+						break;
87 207
 					case F_CRLF:
88 208
 					case F_LF:
209
+					case F_CR:
89 210
 						/*previous=crlf and now =' '*/
90 211
 						state=saved_state;
91 212
 						break;
92 213
 					default:
93 214
 						LOG(L_CRIT,"BUG: parse_via"
94
-							" on <%c>\n",*tmp);
215
+							" on <%c>, state=%d\n",*tmp, state);
95 216
 						goto  error;
96 217
 				}
97 218
 			break;
... ...
@@ -106,6 +227,8 @@ int main(int argc, char** argv)
106 227
 					case L_VIA:
107 228
 					case F_COMMENT:
108 229
 					case P_COMMENT:
230
+					case F_IP6HOST:
231
+					case P_IP6HOST:
109 232
 						saved_state=state;
110 233
 						state=F_LF;
111 234
 						break;
... ...
@@ -124,18 +247,72 @@ int main(int argc, char** argv)
124 247
 						saved_state=L_PARAM;
125 248
 						state=F_LF;
126 249
 						break;
250
+					case F_CR:
251
+						state=F_CRLF;
252
+						break;
253
+					case F_CRLF:
254
+					case F_LF:
255
+						state=saved_state;
256
+						goto endofheader;
127 257
 					default:
128 258
 						LOG(L_CRIT,"BUG: parse_via"
129 259
 							" on <%c>\n",*tmp);
130 260
 						goto  error;
131 261
 				}
132 262
 			break;
263
+		case '\r':
264
+				switch(state){
265
+					case F_HOST:/*eat the spaces*/
266
+					case L_PORT: /*eat the spaces*/
267
+					case F_PORT:
268
+					case L_PARAM: /* eat the space */
269
+					case F_PARAM:
270
+					case F_VIA: /* eat the space */
271
+					case L_VIA:
272
+					case F_COMMENT:
273
+					case P_COMMENT:
274
+					case F_IP6HOST:
275
+					case P_IP6HOST:
276
+						saved_state=state;
277
+						state=F_CR;
278
+						break;
279
+					case P_HOST:
280
+						 *tmp=0;/*mark end of host*/
281
+						 saved_state=L_PORT;
282
+						 state=F_CR;
283
+						 break;
284
+					case P_PORT:
285
+						*tmp=0; /*end of port */
286
+						saved_state=L_PARAM;
287
+						state=F_CR;
288
+						break;
289
+					case P_PARAM:
290
+					/*	*tmp=0;*/ /*!?end of param*/
291
+						saved_state=L_PARAM;
292
+						state=F_CR;
293
+						break;
294
+					case F_CRLF:
295
+					case F_CR:
296
+					case F_LF:
297
+						state=saved_state;
298
+						goto endofheader;
299
+					default:
300
+						LOG(L_CRIT,"BUG: parse_via"
301
+							" on <%c>\n",*tmp);
302
+						goto  error;
303
+				}
304
+			break;
305
+			
133 306
 			case ':':
134 307
 				switch(state){
135 308
 					case F_HOST:
309
+					case F_IP6HOST:
136 310
 						LOG(L_ERR,"ERROR:parse_via:"
137 311
 							" no host found\n");
138 312
 						goto error;
313
+					case P_IP6HOST:
314
+						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
315
+						goto error;
139 316
 					case P_HOST:
140 317
 						*tmp=0; /*mark  end of host*/
141 318
 						state=F_PORT;
... ...
@@ -163,8 +340,12 @@ int main(int argc, char** argv)
163 340
 						goto error;
164 341
 					case F_CRLF:
165 342
 					case F_LF:
343
+					case F_CR:
166 344
 						/*previous=crlf and now !=' '*/
167 345
 						goto endofheader;
346
+					case F_COMMENT:
347
+					case P_COMMENT: /*everything is allowed in a comment*/
348
+						break;
168 349
 					default:
169 350
 						LOG(L_CRIT,"BUG: parse_via"
170 351
 							" on <%c> state %d\n",
... ...
@@ -175,9 +356,13 @@ int main(int argc, char** argv)
175 356
 			case ';':
176 357
 				switch(state){
177 358
 					case F_HOST:
359
+					case F_IP6HOST:
178 360
 						LOG(L_ERR,"ERROR:parse_via:"
179 361
 							" no host found\n");
180 362
 						goto error;
363
+					case P_IP6HOST:
364
+						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
365
+						goto error;
181 366
 					case P_HOST:
182 367
 					case P_PORT:
183 368
 						*tmp=0; /*mark the end*/
... ...
@@ -208,8 +393,12 @@ int main(int argc, char** argv)
208 393
 						goto error;
209 394
 					case F_CRLF:
210 395
 					case F_LF:
396
+					case F_CR:
211 397
 						/*previous=crlf and now !=' '*/
212 398
 						goto endofheader;
399
+					case F_COMMENT:
400
+					case P_COMMENT: /*everything is allowed in a comment*/
401
+						break;
213 402
 					
214 403
 					default:
215 404
 						LOG(L_CRIT,"BUG: parse_via"
... ...
@@ -221,9 +410,13 @@ int main(int argc, char** argv)
221 410
 			case ',':
222 411
 				switch(state){
223 412
 					case F_HOST:
413
+					case F_IP6HOST:
224 414
 						LOG(L_ERR,"ERROR:parse_via:"
225 415
 							" no host found\n");
226 416
 						goto error;
417
+					case P_IP6HOST:
418
+						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
419
+						goto error;
227 420
 					case P_HOST:
228 421
 					case P_PORT:
229 422
 						*tmp=0; /*mark the end*/
... ...
@@ -246,8 +439,12 @@ int main(int argc, char** argv)
246 439
 						break;	
247 440
 					case F_CRLF:
248 441
 					case F_LF:
442
+					case F_CR:
249 443
 						/*previous=crlf and now !=' '*/
250 444
 						goto endofheader;
445
+					case F_COMMENT:
446
+					case P_COMMENT: /*everything is allowed in a comment*/
447
+						break;
251 448
 					default:
252 449
 						LOG(L_CRIT,"BUG: parse_via"
253 450
 							" on <%c> state %d\n",
... ...
@@ -261,6 +458,8 @@ int main(int argc, char** argv)
261 458
 					case F_PORT:
262 459
 					case F_PARAM:
263 460
 					case F_VIA:
461
+					case F_IP6HOST:
462
+					case P_IP6HOST: /*must be terminated in ']'*/
264 463
 						LOG(_ERR,"ERROR:parse_via"
265 464
 							" on <%c> state %d\n",
266 465
 							*tmp, state);
... ...
@@ -284,6 +483,7 @@ int main(int argc, char** argv)
284 483
 						break;
285 484
 					case F_CRLF:
286 485
 					case F_LF:
486
+					case F_CR:
287 487
 						/*previous=crlf and now !=' '*/
288 488
 						goto endofheader;
289 489
 					default:
... ...
@@ -324,12 +524,15 @@ int main(int argc, char** argv)
324 524
 					case L_PORT:
325 525
 					case L_PARAM:
326 526
 					case L_VIA:
527
+					case F_IP6HOST:
528
+					case P_IP6HOST:
327 529
 						LOG(L_ERR,"ERROR:parse_via"
328 530
 							" on <%c> state %d\n",
329 531
 							*tmp, state);
330 532
 						goto  error;
331 533
 					case F_CRLF:
332 534
 					case F_LF:
535
+					case F_CR:
333 536
 						/*previous=crlf and now !=' '*/
334 537
 						goto endofheader;
335 538
 					default:
... ...
@@ -339,6 +542,45 @@ int main(int argc, char** argv)
339 542
 						goto  error;
340 543
 				}
341 544
 				break;
545
+			case '[':
546
+				switch(state){
547
+					case F_HOST:
548
+						state=F_IP6HOST;
549
+						break;
550
+					case F_COMMENT:
551
+					case P_COMMENT:
552
+						break;
553
+					case F_CRLF:
554
+					case F_LF:
555
+					case F_CR:
556
+						/*previous=crlf and now !=' '*/
557
+						goto endofheader;
558
+					default:
559
+						LOG(L_ERR,"ERROR:parse_via"
560
+							" on <%c> state %d\n",
561
+							*tmp, state);
562
+						goto  error;
563
+				}
564
+				break;
565
+			case ']':
566
+				switch(state){
567
+					case P_IP6HOST:
568
+						*tmp=0; /*mark the end*/
569
+						state=L_PORT;
570
+						break;
571
+					case F_CRLF:
572
+					case F_LF:
573
+					case F_CR:
574
+						/*previous=crlf and now !=' '*/
575
+						goto endofheader;
576
+					default:
577
+						LOG(L_ERR,"ERROR:parse_via"
578
+							" on <%c> state %d\n",
579
+							*tmp, state);
580
+						goto  error;
581
+				}
582
+				break;
583
+						
342 584
 			default:
343 585
 				switch(state){
344 586
 					case F_HOST:
... ...
@@ -378,8 +620,15 @@ int main(int argc, char** argv)
378 620
 						break;
379 621
 					case P_COMMENT:
380 622
 						break;
623
+					case F_IP6HOST:
624
+						state=P_IP6HOST;
625
+						host=tmp;
626
+						break;
627
+					case P_IP6HOST:
628
+						break;
381 629
 					case F_CRLF:
382 630
 					case F_LF:
631
+					case F_CR:
383 632
 						/*previous=crlf and now !=' '*/
384 633
 						goto endofheader;
385 634
 					default: