comparison src/http/ngx_http_parse.c @ 21:df7fb216a149

nginx-0.0.1-2002-12-04-19:29:40 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 04 Dec 2002 16:29:40 +0000
parents 72ad26c77d2d
children f540a63026c9
comparison
equal deleted inserted replaced
20:a649c0a0adb3 21:df7fb216a149
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 #include <ngx_http.h> 4 #include <ngx_http.h>
5 5
6 int ngx_read_http_request_line(ngx_http_request_t *r) 6 int ngx_read_http_request_line(ngx_http_request_t *r)
7 { 7 {
8 char ch; 8 char ch;
9 char *p = r->header_in->pos.mem; 9 char *p;
10 enum { 10 enum {
11 sw_start = 0, 11 sw_start = 0,
12 sw_space_after_method, 12 sw_space_after_method,
13 sw_spaces_before_uri, 13 sw_spaces_before_uri,
14 sw_after_slash_in_uri, 14 sw_after_slash_in_uri,
20 sw_major_digit, 20 sw_major_digit,
21 sw_first_minor_digit, 21 sw_first_minor_digit,
22 sw_minor_digit, 22 sw_minor_digit,
23 sw_almost_done, 23 sw_almost_done,
24 sw_done 24 sw_done
25 } state = r->state; 25 } state;
26
27 state = r->state;
28 p = r->header_in->pos.mem;
26 29
27 while (p < r->header_in->last.mem && state < sw_done) { 30 while (p < r->header_in->last.mem && state < sw_done) {
28 ch = *p++; 31 ch = *p++;
29 32
30 /* 33 /*
212 default: 215 default:
213 return NGX_HTTP_PARSE_INVALID_REQUEST; 216 return NGX_HTTP_PARSE_INVALID_REQUEST;
214 } 217 }
215 break; 218 break;
216 219
217 /* TTP/ */ 220 /* "TTP/" */
218 case sw_http_version: 221 case sw_http_version:
219 if (p + 2 >= r->header_in->last.mem) { 222 if (p + 2 >= r->header_in->last.mem) {
220 r->state = sw_http_version; 223 r->state = sw_http_version;
221 r->header_in->pos.mem = p - 1; 224 r->header_in->pos.mem = p - 1;
222 return NGX_AGAIN; 225 return NGX_AGAIN;
307 r->state = state; 310 r->state = state;
308 return NGX_AGAIN; 311 return NGX_AGAIN;
309 } 312 }
310 } 313 }
311 314
315 #if 0
316 int ngx_read_http_response_line(ngx_http_request_t *r)
317 {
318 char c, ch;
319 char *p;
320 enum {
321 sw_start = 0,
322 sw_done
323 } state;
324
325 state = r->state;
326 p = r->header_in->pos.mem;
327
328 while (p < r->header_in->last.mem && state < sw_done) {
329 ch = *p++;
330
331 /*
332 printf("\nstate: %d, pos: %x, end: %x, char: '%c' buf: %s",
333 state, p, r->header_in->last, ch, p);
334 */
335
336 switch (state) {
337
338 /* "HTTP/" */
339 case sw_start:
340 if (p + 3 >= r->header_in->last.mem)
341 return NGX_AGAIN;
342
343 if (ch != 'H' || *p != 'T' || *(p + 1) != 'T' || *(p + 2) != 'P'
344 || *(p + 3) != '/')
345 return NGX_HTTP_PARSE_NO_HEADER;
346
347 p += 4;
348 state = sw_first_major_digit;
349 break;
350
351 /* first digit of major HTTP version */
352 case sw_first_major_digit:
353 if (ch < '1' || ch > '9')
354 return NGX_HTTP_PARSE_NO_HEADER;
355
356 state = sw_major_digit;
357 break;
358
359 /* major HTTP version or dot */
360 case sw_major_digit:
361 if (ch == '.') {
362 state = sw_first_minor_digit;
363 break;
364 }
365
366 if (ch < '0' || ch > '9')
367 return NGX_HTTP_PARSE_NO_HEADER;
368
369 break;
370
371 /* first digit of minor HTTP version */
372 case sw_first_minor_digit:
373 if (ch < '0' || ch > '9')
374 return NGX_HTTP_PARSE_NO_HEADER;
375
376 state = sw_minor_digit;
377 break;
378
379 /* minor HTTP version or end of request line */
380 case sw_minor_digit:
381 if (ch == ' ') {
382 state = sw_code;
383 break;
384 }
385
386 if (ch < '0' || ch > '9')
387 return NGX_HTTP_PARSE_NO_HEADER;
388
389 break;
390 }
391 }
392 }
393 #endif
394
312 int ngx_read_http_header_line(ngx_http_request_t *r) 395 int ngx_read_http_header_line(ngx_http_request_t *r)
313 { 396 {
314 char c, ch; 397 char c, ch;
315 char *p = r->header_in->pos.mem; 398 char *p;
316 enum { 399 enum {
317 sw_start = 0, 400 sw_start = 0,
318 sw_name, 401 sw_name,
319 sw_space_before_value, 402 sw_space_before_value,
320 sw_value, 403 sw_value,
321 sw_space_after_value, 404 sw_space_after_value,
322 sw_almost_done, 405 sw_almost_done,
323 sw_header_almost_done, 406 sw_header_almost_done,
324 sw_done, 407 sw_done,
325 sw_header_done 408 sw_header_done
326 } state = r->state; 409 } state;
410
411 state = r->state;
412 p = r->header_in->pos.mem;
327 413
328 while (p < r->header_in->last.mem && state < sw_done) { 414 while (p < r->header_in->last.mem && state < sw_done) {
329 ch = *p++; 415 ch = *p++;
330 416
331 /* 417 /*