nginx-0.0.1-2002-10-04-21:58:04 import

This commit is contained in:
Igor Sysoev 2002-10-04 17:58:04 +00:00
parent 509a02e478
commit 0b83568133
7 changed files with 92 additions and 12 deletions

View File

@ -14,9 +14,13 @@ typedef struct ngx_connection_s ngx_connection_t;
#endif
struct ngx_connection_s {
ngx_socket_t fd;
ngx_socket_t fd;
void *data;
/* STUB */
ngx_array_t *requests;
int requests_len;
#ifdef NGX_EVENT
ngx_event_t *read;
ngx_event_t *write;

View File

@ -2,10 +2,6 @@
* Copyright (C) 2002 Igor Sysoev, http://sysoev.ru
*/
/*
NEED ? : unify change_list and event_list:
event_list = change_list;
*/
#include <ngx_config.h>
#include <ngx_core.h>
@ -66,6 +62,17 @@ int ngx_kqueue_add_event(ngx_event_t *ev, int event, u_int flags)
int ngx_kqueue_del_event(ngx_event_t *ev, int event)
{
ngx_event_t *e;
if (ev->index <= nchanges && change_list[ev->index].udata == ev) {
change_list[ev->index] = change_list[nchanges];
e = (ngx_event_t *) change_list[ev->index].udata;
e->index = ev->index;
nchanges--;
return NGX_OK;
}
return ngx_kqueue_set_event(ev, event, EV_DELETE);
}
@ -94,6 +101,10 @@ int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags)
change_list[nchanges].fflags = 0;
change_list[nchanges].data = 0;
change_list[nchanges].udata = ev;
if (flags == EV_ADD)
ev->index = nchanges;
nchanges++;
return NGX_OK;

View File

@ -21,7 +21,7 @@ ngx_event_t *ngx_read_events, *ngx_write_events;
#if !(USE_KQUEUE)
#if 1
#if 0
ngx_event_type_e ngx_event_type = NGX_SELECT_EVENT;
#else
ngx_event_type_e ngx_event_type = NGX_KQUEUE_EVENT;

View File

@ -31,8 +31,8 @@ int ngx_http_init(ngx_pool_t *pool, ngx_log_t *log)
#if (WIN32)
ngx_http_server.doc_root = "html";
#else
ngx_http_server.doc_root = "/home/is/dox/";
ngx_http_server.doc_root = "/home/is/work/xml/site-1.0.0/html";
ngx_http_server.doc_root = "/home/is/dox/";
#endif
ngx_http_server.doc_root_len = strlen(ngx_http_server.doc_root) + 1;

View File

@ -122,14 +122,15 @@ struct ngx_http_request_s {
unsigned logging:1;
unsigned header_only:1;
unsigned unusual_uri:1;
unsigned complex_uri:1;
unsigned unusual_uri:1; /* URI is not started with '/' - "GET http://" */
unsigned complex_uri:1; /* URI with "./" or with "//" */
int state;
char *uri_start;
char *uri_end;
char *uri_ext;
char *args_start;
char *request_end;
char *header_name_start;
char *header_name_end;
char *header_start;

View File

@ -47,6 +47,7 @@ static int ngx_http_redirect(ngx_http_request_t *r, int redirect);
static int ngx_http_error(ngx_http_request_t *r, int error);
static int ngx_http_close_request(ngx_http_request_t *r);
static int ngx_http_close_connection(ngx_event_t *ev);
static size_t ngx_http_log_error(void *data, char *buf, size_t len);
@ -69,12 +70,19 @@ int ngx_http_init_connection(ngx_connection_t *c)
ev = c->read;
ev->event_handler = ngx_http_init_request;
srv = (ngx_http_server_t *) c->server;
ngx_test_null(c->pool,
ngx_create_pool(srv->connection_pool_size, ev->log),
NGX_ERROR);
ngx_test_null(c->requests, ngx_create_array(c->pool, 10, sizeof(char *)),
NGX_ERROR);
ev->close_handler = ngx_http_close_connection;
c->write->close_handler = ngx_http_close_connection;
ngx_test_null(addr, ngx_palloc(c->pool, c->socklen), NGX_ERROR);
ngx_memcpy(addr, c->sockaddr, c->socklen);
c->sockaddr = addr;
@ -240,17 +248,35 @@ static int ngx_http_process_request(ngx_event_t *ev)
static int ngx_http_process_request_line(ngx_http_request_t *r)
{
int rc;
int rc, len;
char **request;
ngx_connection_t *c;
ngx_http_log_ctx_t *ctx;
rc = ngx_read_http_request_line(r);
c = r->connection;
if (rc == NGX_OK) {
ngx_test_null(r->uri,
ngx_palloc(r->pool, r->uri_end - r->uri_start + 1),
ngx_http_close_request(r));
ngx_cpystrn(r->uri, r->uri_start, r->uri_end - r->uri_start + 1);
ngx_test_null(request, ngx_push_array(c->requests),
ngx_http_close_request(r));
if (r->request_end)
len = r->request_end - r->header_in->start + 1;
else
len = 1;
c->requests_len += len;
ngx_test_null(*request, ngx_palloc(c->pool, len),
ngx_http_close_request(r));
ngx_cpystrn(*request, r->header_in->start, len);
ngx_log_debug(c->log, "REQ: '%s'" _ *request);
if (r->uri_ext) {
ngx_test_null(r->exten,
ngx_palloc(r->pool, r->uri_end - r->uri_ext + 1),
@ -862,6 +888,42 @@ static int ngx_http_close_request(ngx_http_request_t *r)
}
static int ngx_http_close_connection(ngx_event_t *ev)
{
int i, len;
char **requests, *requests_line, *prev, *new;
ngx_connection_t *c = (ngx_connection_t *) ev->data;
if (c->requests->nelts > 1) {
len = c->requests_len + c->requests->nelts * 2 - 1;
ngx_test_null(requests_line, ngx_palloc(c->pool, len),
ngx_event_close_connection(ev));
requests = (char **) c->requests->elts;
prev = requests_line;
new = ngx_cpystrn(prev, requests[0], len);
len -= new - prev;
prev = new;
for (i = 1; i < c->requests->nelts; i++) {
new = ngx_cpystrn(prev, ", ", len);
new = ngx_cpystrn(new, requests[i], len);
len -= new - prev;
prev = new;
}
} else {
requests_line = * (char **) c->requests->elts;
}
ngx_log_error(NGX_LOG_INFO, c->log, 0,
"REQUESTS: %d, '%s'", c->requests->nelts, requests_line);
return ngx_event_close_connection(ev);
}
static size_t ngx_http_log_error(void *data, char *buf, size_t len)
{
ngx_http_log_ctx_t *ctx = (ngx_http_log_ctx_t *) data;

View File

@ -32,7 +32,7 @@ printf("\nstate: %d, pos: %x, end: %x, char: '%c' buf: %s",
state, p, r->header_in->last, ch, p);
*/
/* GCC 2.95.2 and VC 6.0 compiles this switch as jump table */
/* GCC 2.95.2 and VC 6.0 compile this switch as jump table */
switch (state) {
@ -257,7 +257,6 @@ printf("\nstate: %d, pos: %x, end: %x, char: '%c' buf: %s",
return NGX_HTTP_PARSE_INVALID_REQUEST;
r->http_minor = ch - '0';
state = sw_minor_digit;
break;
@ -281,6 +280,7 @@ printf("\nstate: %d, pos: %x, end: %x, char: '%c' buf: %s",
/* end of request line */
case sw_almost_done:
r->request_end = p - 2;
switch (ch) {
case LF:
state = sw_done;
@ -295,6 +295,8 @@ printf("\nstate: %d, pos: %x, end: %x, char: '%c' buf: %s",
r->header_in->pos.mem = p;
if (state == sw_done) {
if (r->request_end == NULL)
r->request_end = p - 1;
r->http_version = r->http_major * 1000 + r->http_minor;
r->state = sw_start;
if (r->http_version == 9 && r->method == NGX_HTTP_HEAD)