comparison src/http/ngx_http_parse.c @ 67:5a7d1aaa1618

nginx-0.0.1-2003-03-11-23:38:13 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 11 Mar 2003 20:38:13 +0000
parents 4222c496acb3
children 59229033ae93
comparison
equal deleted inserted replaced
66:4876cd4a36bb 67:5a7d1aaa1618
23 sw_almost_done, 23 sw_almost_done,
24 sw_done 24 sw_done
25 } state; 25 } state;
26 26
27 state = r->state; 27 state = r->state;
28 p = r->header_in->pos.mem; 28 p = r->header_in->pos;
29 29
30 while (p < r->header_in->last.mem && state < sw_done) { 30 while (p < r->header_in->last && state < sw_done) {
31 ch = *p++; 31 ch = *p++;
32
33 /*
34 printf("\nstate: %d, pos: %x, end: %x, char: '%c' buf: %s",
35 state, p, r->header_in->last, ch, p);
36 */
37 32
38 /* GCC 2.95.2 and VC 6.0 compile this switch as jump table */ 33 /* GCC 2.95.2 and VC 6.0 compile this switch as jump table */
39 34
40 switch (state) { 35 switch (state) {
41 36
43 case sw_start: 38 case sw_start:
44 r->request_start = p - 1; 39 r->request_start = p - 1;
45 40
46 switch (ch) { 41 switch (ch) {
47 case 'G': 42 case 'G':
48 if (p + 1 >= r->header_in->last.mem) { 43 if (p + 1 >= r->header_in->last) {
49 return NGX_AGAIN; 44 return NGX_AGAIN;
50 } 45 }
51 46
52 if (*p != 'E' || *(p + 1) != 'T') { 47 if (*p != 'E' || *(p + 1) != 'T') {
53 return NGX_HTTP_PARSE_INVALID_METHOD; 48 return NGX_HTTP_PARSE_INVALID_METHOD;
56 r->method = NGX_HTTP_GET; 51 r->method = NGX_HTTP_GET;
57 p += 2; 52 p += 2;
58 break; 53 break;
59 54
60 case 'H': 55 case 'H':
61 if (p + 2 >= r->header_in->last.mem) { 56 if (p + 2 >= r->header_in->last) {
62 return NGX_AGAIN; 57 return NGX_AGAIN;
63 } 58 }
64 59
65 if (*p != 'E' || *(p + 1) != 'A' || *(p + 2) != 'D') { 60 if (*p != 'E' || *(p + 1) != 'A' || *(p + 2) != 'D') {
66 return NGX_HTTP_PARSE_INVALID_METHOD; 61 return NGX_HTTP_PARSE_INVALID_METHOD;
69 r->method = NGX_HTTP_HEAD; 64 r->method = NGX_HTTP_HEAD;
70 p += 3; 65 p += 3;
71 break; 66 break;
72 67
73 case 'P': 68 case 'P':
74 if (p + 2 >= r->header_in->last.mem) { 69 if (p + 2 >= r->header_in->last) {
75 return NGX_AGAIN; 70 return NGX_AGAIN;
76 } 71 }
77 72
78 if (*p != 'O' || *(p + 1) != 'S' || *(p + 2) != 'T') { 73 if (*p != 'O' || *(p + 1) != 'S' || *(p + 2) != 'T') {
79 return NGX_HTTP_PARSE_INVALID_METHOD; 74 return NGX_HTTP_PARSE_INVALID_METHOD;
226 } 221 }
227 break; 222 break;
228 223
229 /* "TTP/" */ 224 /* "TTP/" */
230 case sw_http_version: 225 case sw_http_version:
231 if (p + 2 >= r->header_in->last.mem) { 226 if (p + 2 >= r->header_in->last) {
232 r->state = sw_http_version; 227 r->state = sw_http_version;
233 r->header_in->pos.mem = p - 1; 228 r->header_in->pos = p - 1;
234 return NGX_AGAIN; 229 return NGX_AGAIN;
235 } 230 }
236 231
237 if (ch != 'T' || *p != 'T' || *(p + 1) != 'P' || *(p + 2) != '/') { 232 if (ch != 'T' || *p != 'T' || *(p + 1) != 'P' || *(p + 2) != '/') {
238 return NGX_HTTP_PARSE_INVALID_REQUEST; 233 return NGX_HTTP_PARSE_INVALID_REQUEST;
307 } 302 }
308 break; 303 break;
309 } 304 }
310 } 305 }
311 306
312 r->header_in->pos.mem = p; 307 r->header_in->pos = p;
313 308
314 if (state == sw_done) { 309 if (state == sw_done) {
315 if (r->request_end == NULL) { 310 if (r->request_end == NULL) {
316 r->request_end = p - 1; 311 r->request_end = p - 1;
317 } 312 }
346 sw_done, 341 sw_done,
347 sw_header_done 342 sw_header_done
348 } state; 343 } state;
349 344
350 state = r->state; 345 state = r->state;
351 p = h->pos.mem; 346 p = h->pos;
352 347
353 while (p < h->last.mem && state < sw_done) { 348 while (p < h->last && state < sw_done) {
354 ch = *p++; 349 ch = *p++;
355
356 /*
357 printf("\nstate: %d, pos: %x, end: %x, char: '%c' buf: %s",
358 state, p, h->last.mem, ch, p);
359 */
360 350
361 switch (state) { 351 switch (state) {
362 352
363 /* first char */ 353 /* first char */
364 case sw_start: 354 case sw_start:
493 } 483 }
494 break; 484 break;
495 } 485 }
496 } 486 }
497 487
498 h->pos.mem = p; 488 h->pos = p;
499 489
500 if (state == sw_done) { 490 if (state == sw_done) {
501 r->state = sw_start; 491 r->state = sw_start;
502 return NGX_OK; 492 return NGX_OK;
503 493