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 51
 			exit(-1);
52 52
 	}
53 53
 	
54
-	
54
+	/* parse start of via ( SIP/2.0/UDP    )*/
55
+	state=F_SIP;
56
+	for(tmp=argv[1];*tmp;tmp++){
57
+		switch(*tmp){
58
+			case ' ':
59
+			case'\t':
60
+				switch(state){
61
+					case L_SIP: /*eat space*/
62
+					case L_SLASH1:
63
+					case L_SLASH2:
64
+					case L_VER:
65
+					case L_PROTO:
66
+					case F_SIP:
67
+					case F_VER:
68
+					case F_PROTO:
69
+						break;
70
+					case P_PROTO:
71
+						*tmp=0;
72
+						state=F_HOST;
73
+						break;
74
+					case F_LF:
75
+					case F_CRLF:
76
+					case F_CR:
77
+						state=saved_state;
78
+						break;
79
+					default:
80
+						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
81
+								" state %d\n", *tmp, state);
82
+						goto error;
83
+				}
84
+				break;
85
+			case '\n':
86
+				switch(state){
87
+					case L_SIP:
88
+					case L_SLASH1:
89
+					case L_SLASH2:
90
+					case L_VER:
91
+					case F_SIP:
92
+					case F_VER:
93
+					case F_PROTO:
94
+						saved_state=state;
95
+						state=F_LF;
96
+						break;
97
+					case P_PROTO:
98
+						*tmp=0;
99
+						state=F_LF;
100
+						saved_state=;
101
+						break;
102
+					case F_CR:
103
+						state=F_CRLF;
104
+						break;
105
+					case F_LF:
106
+					case F_CRLF:
107
+						state=saved_state;
108
+						goto endofheader;
109
+					default:
110
+						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
111
+								" state %d\n", *tmp, state);
112
+						goto error;
113
+				}
114
+				break;
115
+			case '\r':
116
+				switch(state){
117
+					case L_SIP:
118
+					case L_SLASH1:
119
+					case L_SLASH2:
120
+					case L_VER:
121
+					case F_SIP:
122
+					case F_VER:
123
+					case F_PROTO:
124
+						saved_state=state;
125
+						state=F_CR;
126
+						break;
127
+					case P_PROTO:
128
+						*tmp=0;
129
+						state=F_CR;
130
+						saved_state=;
131
+						break;
132
+					case F_LF: /*end of line ?next header?*/
133
+					case F_CR:
134
+					case F_CRLF:
135
+						state=saved_state;
136
+						goto endofheader;
137
+					default:
138
+						LOG(L_ERR, "ERROR: parse_via: bad char <%c> on"
139
+								" state %d\n", *tmp, state);
140
+						goto error;
141
+				}
142
+				break;
143
+			
144
+			case '\\':
145
+				switch(state){
146
+					case L_VER:
147
+						*tmp=0;
148
+						state=F_VER;
149
+						break;
150
+					case L_PROTO:
151
+						*tmp=0;
152
+						state=F_PROTO;
153
+						break;
154
+					case L_
155
+
156
+
157
+						
158
+				
159
+								
160
+								
161
+
162
+			
163
+	}
164
+
55 165
 	c_nest=0;
56 166
 	state=F_HOST;
57
-	for(tmp=argv[1];*tmp;tmp++){
167
+	for(;*tmp;tmp++){
58 168
 		switch(*tmp){
59 169
 			case ' ':
170
+			case '\t':
60 171
 				switch(state){
61 172
 					case F_HOST:/*eat the spaces*/
62 173
 						break;
... ...
@@ -84,14 +198,21 @@ int main(int argc, char** argv)
84 84
 					case F_COMMENT:
85 85
 					case P_COMMENT:
86 86
 						break;
87
+					case F_IP6HOST: /*eat the spaces*/
88
+						break;
89
+					case P_IP6HOST:
90
+						*tmp=0; /*mark end of host*/
91
+						state=L_PORT; 
92
+						break;
87 93
 					case F_CRLF:
88 94
 					case F_LF:
95
+					case F_CR:
89 96
 						/*previous=crlf and now =' '*/
90 97
 						state=saved_state;
91 98
 						break;
92 99
 					default:
93 100
 						LOG(L_CRIT,"BUG: parse_via"
94
-							" on <%c>\n",*tmp);
101
+							" on <%c>, state=%d\n",*tmp, state);
95 102
 						goto  error;
96 103
 				}
97 104
 			break;
... ...
@@ -106,6 +227,8 @@ int main(int argc, char** argv)
106 106
 					case L_VIA:
107 107
 					case F_COMMENT:
108 108
 					case P_COMMENT:
109
+					case F_IP6HOST:
110
+					case P_IP6HOST:
109 111
 						saved_state=state;
110 112
 						state=F_LF;
111 113
 						break;
... ...
@@ -124,18 +247,72 @@ int main(int argc, char** argv)
124 124
 						saved_state=L_PARAM;
125 125
 						state=F_LF;
126 126
 						break;
127
+					case F_CR:
128
+						state=F_CRLF;
129
+						break;
130
+					case F_CRLF:
131
+					case F_LF:
132
+						state=saved_state;
133
+						goto endofheader;
127 134
 					default:
128 135
 						LOG(L_CRIT,"BUG: parse_via"
129 136
 							" on <%c>\n",*tmp);
130 137
 						goto  error;
131 138
 				}
132 139
 			break;
140
+		case '\r':
141
+				switch(state){
142
+					case F_HOST:/*eat the spaces*/
143
+					case L_PORT: /*eat the spaces*/
144
+					case F_PORT:
145
+					case L_PARAM: /* eat the space */
146
+					case F_PARAM:
147
+					case F_VIA: /* eat the space */
148
+					case L_VIA:
149
+					case F_COMMENT:
150
+					case P_COMMENT:
151
+					case F_IP6HOST:
152
+					case P_IP6HOST:
153
+						saved_state=state;
154
+						state=F_CR;
155
+						break;
156
+					case P_HOST:
157
+						 *tmp=0;/*mark end of host*/
158
+						 saved_state=L_PORT;
159
+						 state=F_CR;
160
+						 break;
161
+					case P_PORT:
162
+						*tmp=0; /*end of port */
163
+						saved_state=L_PARAM;
164
+						state=F_CR;
165
+						break;
166
+					case P_PARAM:
167
+					/*	*tmp=0;*/ /*!?end of param*/
168
+						saved_state=L_PARAM;
169
+						state=F_CR;
170
+						break;
171
+					case F_CRLF:
172
+					case F_CR:
173
+					case F_LF:
174
+						state=saved_state;
175
+						goto endofheader;
176
+					default:
177
+						LOG(L_CRIT,"BUG: parse_via"
178
+							" on <%c>\n",*tmp);
179
+						goto  error;
180
+				}
181
+			break;
182
+			
133 183
 			case ':':
134 184
 				switch(state){
135 185
 					case F_HOST:
186
+					case F_IP6HOST:
136 187
 						LOG(L_ERR,"ERROR:parse_via:"
137 188
 							" no host found\n");
138 189
 						goto error;
190
+					case P_IP6HOST:
191
+						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
192
+						goto error;
139 193
 					case P_HOST:
140 194
 						*tmp=0; /*mark  end of host*/
141 195
 						state=F_PORT;
... ...
@@ -163,8 +340,12 @@ int main(int argc, char** argv)
163 163
 						goto error;
164 164
 					case F_CRLF:
165 165
 					case F_LF:
166
+					case F_CR:
166 167
 						/*previous=crlf and now !=' '*/
167 168
 						goto endofheader;
169
+					case F_COMMENT:
170
+					case P_COMMENT: /*everything is allowed in a comment*/
171
+						break;
168 172
 					default:
169 173
 						LOG(L_CRIT,"BUG: parse_via"
170 174
 							" on <%c> state %d\n",
... ...
@@ -175,9 +356,13 @@ int main(int argc, char** argv)
175 175
 			case ';':
176 176
 				switch(state){
177 177
 					case F_HOST:
178
+					case F_IP6HOST:
178 179
 						LOG(L_ERR,"ERROR:parse_via:"
179 180
 							" no host found\n");
180 181
 						goto error;
182
+					case P_IP6HOST:
183
+						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
184
+						goto error;
181 185
 					case P_HOST:
182 186
 					case P_PORT:
183 187
 						*tmp=0; /*mark the end*/
... ...
@@ -208,8 +393,12 @@ int main(int argc, char** argv)
208 208
 						goto error;
209 209
 					case F_CRLF:
210 210
 					case F_LF:
211
+					case F_CR:
211 212
 						/*previous=crlf and now !=' '*/
212 213
 						goto endofheader;
214
+					case F_COMMENT:
215
+					case P_COMMENT: /*everything is allowed in a comment*/
216
+						break;
213 217
 					
214 218
 					default:
215 219
 						LOG(L_CRIT,"BUG: parse_via"
... ...
@@ -221,9 +410,13 @@ int main(int argc, char** argv)
221 221
 			case ',':
222 222
 				switch(state){
223 223
 					case F_HOST:
224
+					case F_IP6HOST:
224 225
 						LOG(L_ERR,"ERROR:parse_via:"
225 226
 							" no host found\n");
226 227
 						goto error;
228
+					case P_IP6HOST:
229
+						LOG(L_ERR, "ERROR:parse_via: bad ipv6 reference\n");
230
+						goto error;
227 231
 					case P_HOST:
228 232
 					case P_PORT:
229 233
 						*tmp=0; /*mark the end*/
... ...
@@ -246,8 +439,12 @@ int main(int argc, char** argv)
246 246
 						break;	
247 247
 					case F_CRLF:
248 248
 					case F_LF:
249
+					case F_CR:
249 250
 						/*previous=crlf and now !=' '*/
250 251
 						goto endofheader;
252
+					case F_COMMENT:
253
+					case P_COMMENT: /*everything is allowed in a comment*/
254
+						break;
251 255
 					default:
252 256
 						LOG(L_CRIT,"BUG: parse_via"
253 257
 							" on <%c> state %d\n",
... ...
@@ -261,6 +458,8 @@ int main(int argc, char** argv)
261 261
 					case F_PORT:
262 262
 					case F_PARAM:
263 263
 					case F_VIA:
264
+					case F_IP6HOST:
265
+					case P_IP6HOST: /*must be terminated in ']'*/
264 266
 						LOG(_ERR,"ERROR:parse_via"
265 267
 							" on <%c> state %d\n",
266 268
 							*tmp, state);
... ...
@@ -284,6 +483,7 @@ int main(int argc, char** argv)
284 284
 						break;
285 285
 					case F_CRLF:
286 286
 					case F_LF:
287
+					case F_CR:
287 288
 						/*previous=crlf and now !=' '*/
288 289
 						goto endofheader;
289 290
 					default:
... ...
@@ -324,12 +524,15 @@ int main(int argc, char** argv)
324 324
 					case L_PORT:
325 325
 					case L_PARAM:
326 326
 					case L_VIA:
327
+					case F_IP6HOST:
328
+					case P_IP6HOST:
327 329
 						LOG(L_ERR,"ERROR:parse_via"
328 330
 							" on <%c> state %d\n",
329 331
 							*tmp, state);
330 332
 						goto  error;
331 333
 					case F_CRLF:
332 334
 					case F_LF:
335
+					case F_CR:
333 336
 						/*previous=crlf and now !=' '*/
334 337
 						goto endofheader;
335 338
 					default:
... ...
@@ -339,6 +542,45 @@ int main(int argc, char** argv)
339 339
 						goto  error;
340 340
 				}
341 341
 				break;
342
+			case '[':
343
+				switch(state){
344
+					case F_HOST:
345
+						state=F_IP6HOST;
346
+						break;
347
+					case F_COMMENT:
348
+					case P_COMMENT:
349
+						break;
350
+					case F_CRLF:
351
+					case F_LF:
352
+					case F_CR:
353
+						/*previous=crlf and now !=' '*/
354
+						goto endofheader;
355
+					default:
356
+						LOG(L_ERR,"ERROR:parse_via"
357
+							" on <%c> state %d\n",
358
+							*tmp, state);
359
+						goto  error;
360
+				}
361
+				break;
362
+			case ']':
363
+				switch(state){
364
+					case P_IP6HOST:
365
+						*tmp=0; /*mark the end*/
366
+						state=L_PORT;
367
+						break;
368
+					case F_CRLF:
369
+					case F_LF:
370
+					case F_CR:
371
+						/*previous=crlf and now !=' '*/
372
+						goto endofheader;
373
+					default:
374
+						LOG(L_ERR,"ERROR:parse_via"
375
+							" on <%c> state %d\n",
376
+							*tmp, state);
377
+						goto  error;
378
+				}
379
+				break;
380
+						
342 381
 			default:
343 382
 				switch(state){
344 383
 					case F_HOST:
... ...
@@ -378,8 +620,15 @@ int main(int argc, char** argv)
378 378
 						break;
379 379
 					case P_COMMENT:
380 380
 						break;
381
+					case F_IP6HOST:
382
+						state=P_IP6HOST;
383
+						host=tmp;
384
+						break;
385
+					case P_IP6HOST:
386
+						break;
381 387
 					case F_CRLF:
382 388
 					case F_LF:
389
+					case F_CR:
383 390
 						/*previous=crlf and now !=' '*/
384 391
 						goto endofheader;
385 392
 					default: