nginx-0.0.1-2002-08-29-20:59:54 import
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index 6bfab9b..5ab42ac 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -1,47 +1,47 @@
#include <ngx_config.h>
+#include <ngx_core.h>
#include <ngx_http.h>
int ngx_read_http_request_line(ngx_http_request_t *r)
{
char ch;
- char *buff = r->buff->buff;
- char *p = r->buff->pos;
+ char *p = r->header_in->pos.mem;
enum {
- rl_start = 0,
- rl_space_after_method,
- rl_spaces_before_uri,
- rl_after_slash_in_uri,
- rl_check_uri,
- rl_uri,
- rl_http_09,
- rl_http_version,
- rl_first_major_digit,
- rl_major_digit,
- rl_first_minor_digit,
- rl_minor_digit,
- rl_almost_done,
- rl_done
+ sw_start = 0,
+ sw_space_after_method,
+ sw_spaces_before_uri,
+ sw_after_slash_in_uri,
+ sw_check_uri,
+ sw_uri,
+ sw_http_09,
+ sw_http_version,
+ sw_first_major_digit,
+ sw_major_digit,
+ sw_first_minor_digit,
+ sw_minor_digit,
+ sw_almost_done,
+ sw_done
} state = r->state;
- while (p < r->buff->last && state < rl_done) {
+ while (p < r->header_in->last.mem && state < sw_done) {
ch = *p++;
/*
printf("\nstate: %d, pos: %x, end: %x, char: '%c' buf: %s",
- state, p, r->buff->last, ch, p);
+ state, p, r->header_in->last, ch, p);
*/
- /* GCC complie it as jump table */
+ /* GCC compiles switch as jump table */
switch (state) {
/* HTTP methods: GET, HEAD, POST */
- case rl_start:
+ case sw_start:
switch (ch) {
case 'G':
- if (p + 1 >= r->buff->last)
- return 0;
+ if (p + 1 >= r->header_in->last.mem)
+ return NGX_AGAIN;
if (*p != 'E' || *(p + 1) != 'T')
return NGX_HTTP_INVALID_METHOD;
@@ -51,8 +51,8 @@
break;
case 'H':
- if (p + 2 >= r->buff->last)
- return 0;
+ if (p + 2 >= r->header_in->last.mem)
+ return NGX_AGAIN;
if (*p != 'E' || *(p + 1) != 'A' || *(p + 2) != 'D')
return NGX_HTTP_INVALID_METHOD;
@@ -62,8 +62,8 @@
break;
case 'P':
- if (p + 2 >= r->buff->last)
- return 0;
+ if (p + 2 >= r->header_in->last.mem)
+ return NGX_AGAIN;
if (*p != 'O' || *(p + 1) != 'S' || *(p + 2) != 'T')
return NGX_HTTP_INVALID_METHOD;
@@ -76,14 +76,14 @@
return NGX_HTTP_INVALID_METHOD;
}
- state = rl_space_after_method;
+ state = sw_space_after_method;
break;
/* single space after method */
- case rl_space_after_method:
+ case sw_space_after_method:
switch (ch) {
case ' ':
- state = rl_spaces_before_uri;
+ state = sw_spaces_before_uri;
break;
default:
return NGX_HTTP_INVALID_METHOD;
@@ -91,123 +91,123 @@
break;
/* space* before URI */
- case rl_spaces_before_uri:
+ case sw_spaces_before_uri:
switch (ch) {
case '/':
r->uri_start = p - 1;
- state = rl_after_slash_in_uri;
+ state = sw_after_slash_in_uri;
break;
case ' ':
break;
default:
r->unusual_uri = 1;
r->uri_start = p - 1;
- state = rl_uri;
+ state = sw_uri;
break;
}
break;
/* check dot after slash */
- case rl_after_slash_in_uri:
+ case sw_after_slash_in_uri:
switch (ch) {
case CR:
r->uri_end = p - 1;
r->http_minor = 9;
- state = rl_almost_done;
+ state = sw_almost_done;
break;
case LF:
r->uri_end = p - 1;
r->http_minor = 9;
- state = rl_done;
+ state = sw_done;
break;
case ' ':
r->uri_end = p - 1;
- state = rl_http_09;
+ state = sw_http_09;
break;
case '.':
r->complex_uri = 1;
- state = rl_uri;
+ state = sw_uri;
break;
case '/':
r->complex_uri = 1;
- state = rl_uri;
+ state = sw_uri;
break;
case '?':
r->args_start = p;
- state = rl_uri;
+ state = sw_uri;
break;
default:
- state = rl_check_uri;
+ state = sw_check_uri;
break;
}
break;
/* check slash in URI */
- case rl_check_uri:
+ case sw_check_uri:
switch (ch) {
case CR:
r->uri_end = p - 1;
r->http_minor = 9;
- state = rl_almost_done;
+ state = sw_almost_done;
break;
case LF:
r->uri_end = p - 1;
r->http_minor = 9;
- state = rl_done;
+ state = sw_done;
break;
case ' ':
r->uri_end = p - 1;
- state = rl_http_09;
+ state = sw_http_09;
break;
case '.':
r->uri_ext = p;
break;
case '/':
r->uri_ext = NULL;
- state = rl_after_slash_in_uri;
+ state = sw_after_slash_in_uri;
break;
case '?':
r->args_start = p;
- state = rl_uri;
+ state = sw_uri;
break;
}
break;
/* URI */
- case rl_uri:
+ case sw_uri:
switch (ch) {
case CR:
r->uri_end = p - 1;
r->http_minor = 9;
- state = rl_almost_done;
+ state = sw_almost_done;
break;
case LF:
r->uri_end = p - 1;
r->http_minor = 9;
- state = rl_done;
+ state = sw_done;
break;
case ' ':
r->uri_end = p - 1;
- state = rl_http_09;
+ state = sw_http_09;
break;
}
break;
/* space+ after URI */
- case rl_http_09:
+ case sw_http_09:
switch (ch) {
case ' ':
break;
case CR:
r->http_minor = 9;
- state = rl_almost_done;
+ state = sw_almost_done;
break;
case LF:
r->http_minor = 9;
- state = rl_done;
+ state = sw_done;
break;
case 'H':
- state = rl_http_version;
+ state = sw_http_version;
break;
default:
return NGX_HTTP_INVALID_REQUEST;
@@ -215,33 +215,33 @@
break;
/* TTP/ */
- case rl_http_version:
- if (p + 2 >= r->buff->last) {
- r->state = rl_http_version;
- r->buff->pos = p - 1;
- return 0;
+ case sw_http_version:
+ if (p + 2 >= r->header_in->last.mem) {
+ r->state = sw_http_version;
+ r->header_in->pos.mem = p - 1;
+ return NGX_AGAIN;
}
if (ch != 'T' || *p != 'T' || *(p + 1) != 'P' || *(p + 2) != '/')
return NGX_HTTP_INVALID_REQUEST;
p += 3;
- state = rl_first_major_digit;
+ state = sw_first_major_digit;
break;
/* first digit of major HTTP version */
- case rl_first_major_digit:
+ case sw_first_major_digit:
if (ch < '1' || ch > '9')
return NGX_HTTP_INVALID_REQUEST;
r->http_major = ch - '0';
- state = rl_major_digit;
+ state = sw_major_digit;
break;
/* major HTTP version or dot */
- case rl_major_digit:
+ case sw_major_digit:
if (ch == '.') {
- state = rl_first_minor_digit;
+ state = sw_first_minor_digit;
break;
}
@@ -252,24 +252,24 @@
break;
/* first digit of minor HTTP version */
- case rl_first_minor_digit:
+ case sw_first_minor_digit:
if (ch < '0' || ch > '9')
return NGX_HTTP_INVALID_REQUEST;
r->http_minor = ch - '0';
- state = rl_minor_digit;
+ state = sw_minor_digit;
break;
/* minor HTTP version or end of request line */
- case rl_minor_digit:
+ case sw_minor_digit:
if (ch == CR) {
- state = rl_almost_done;
+ state = sw_almost_done;
break;
}
if (ch == LF) {
- state = rl_done;
+ state = sw_done;
break;
}
@@ -280,70 +280,72 @@
break;
/* end of request line */
- case rl_almost_done:
+ case sw_almost_done:
switch (ch) {
case LF:
- state = rl_done;
+ state = sw_done;
break;
default:
- return NGX_HTTP_INVALID_METHOD;
+ return NGX_HTTP_INVALID_REQUEST;
}
break;
}
}
- r->buff->pos = p;
+ r->header_in->pos.mem = p;
- if (state == rl_done) {
+ if (state == sw_done) {
r->http_version = r->http_major * 1000 + r->http_minor;
- r->state = rl_start;
- return 1;
+ r->state = sw_start;
+ if (r->http_version == 9 && r->method == NGX_HTTP_HEAD)
+ return NGX_HTTP_INVALID_HEAD;
+ else
+ return NGX_OK;
} else {
r->state = state;
- return 0;
+ return NGX_AGAIN;
}
}
int ngx_read_http_header_line(ngx_http_request_t *r)
{
char c, ch;
- char *buff = r->buff->buff;
- char *p = r->buff->pos;
+ char *p = r->header_in->pos.mem;
enum {
- hl_start = 0,
- hl_name,
- hl_space_before_value,
- hl_value,
- hl_space_after_value,
- hl_almost_done,
- header_almost_done,
- hl_done,
- header_done
+ sw_start = 0,
+ sw_name,
+ sw_space_before_value,
+ sw_value,
+ sw_space_after_value,
+ sw_almost_done,
+ sw_header_almost_done,
+ sw_done,
+ sw_header_done
} state = r->state;
- while (p < r->buff->last && state < hl_done) {
+ while (p < r->header_in->last.mem && state < sw_done) {
ch = *p++;
/*
printf("\nstate: %d, pos: %x, end: %x, char: '%c' buf: %s",
- state, p, r->buff->last, ch, p);
+ state, p, r->header_in->last.mem, ch, p);
*/
switch (state) {
/* first char */
- case hl_start:
+ case sw_start:
switch (ch) {
case CR:
r->header_end = p - 1;
- state = header_almost_done;
+ state = sw_header_almost_done;
break;
case LF:
r->header_end = p - 1;
- state = header_done;
+ state = sw_header_done;
break;
default:
- state = hl_name;
+ state = sw_name;
r->header_name_start = p - 1;
c = ch | 0x20;
@@ -362,14 +364,14 @@
break;
/* header name */
- case hl_name:
+ case sw_name:
c = ch | 0x20;
if (c >= 'a' && c <= 'z')
break;
if (ch == ':') {
r->header_name_end = p - 1;
- state = hl_space_before_value;
+ state = sw_space_before_value;
break;
}
@@ -382,65 +384,65 @@
return NGX_HTTP_INVALID_HEADER;
/* space* before header value */
- case hl_space_before_value:
+ case sw_space_before_value:
switch (ch) {
case ' ':
break;
case CR:
r->header_start = r->header_end = p - 1;
- state = hl_almost_done;
+ state = sw_almost_done;
break;
case LF:
r->header_start = r->header_end = p - 1;
- state = hl_done;
+ state = sw_done;
break;
default:
r->header_start = p - 1;
- state = hl_value;
+ state = sw_value;
break;
}
break;
/* header value */
- case hl_value:
+ case sw_value:
switch (ch) {
case ' ':
r->header_end = p - 1;
- state = hl_space_after_value;
+ state = sw_space_after_value;
break;
case CR:
r->header_end = p - 1;
- state = hl_almost_done;
+ state = sw_almost_done;
break;
case LF:
r->header_end = p - 1;
- state = hl_done;
+ state = sw_done;
break;
}
break;
/* space* before end of header line */
- case hl_space_after_value:
+ case sw_space_after_value:
switch (ch) {
case ' ':
break;
case CR:
- state = hl_almost_done;
+ state = sw_almost_done;
break;
case LF:
- state = hl_done;
+ state = sw_done;
break;
default:
- state = hl_value;
+ state = sw_value;
break;
}
break;
/* end of header line */
- case hl_almost_done:
+ case sw_almost_done:
switch (ch) {
case LF:
- state = hl_done;
+ state = sw_done;
break;
default:
return NGX_HTTP_INVALID_HEADER;
@@ -448,10 +450,10 @@
break;
/* end of header */
- case header_almost_done:
+ case sw_header_almost_done:
switch (ch) {
case LF:
- state = header_done;
+ state = sw_header_done;
break;
default:
return NGX_HTTP_INVALID_HEADER;
@@ -460,16 +462,16 @@
}
}
- r->buff->pos = p;
+ r->header_in->pos.mem = p;
- if (state == hl_done) {
- r->state = hl_start;
- return 1;
- } else if (state == header_done) {
- r->state = hl_start;
- return 2;
+ if (state == sw_done) {
+ r->state = sw_start;
+ return NGX_OK;
+ } else if (state == sw_header_done) {
+ r->state = sw_start;
+ return NGX_HTTP_HEADER_DONE;
} else {
r->state = state;
- return 0;
+ return NGX_AGAIN;
}
}