nginx-0.0.1-2003-05-16-19:27:48 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 4a22e58..ad0cd57 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -38,6 +38,7 @@
int ngx_max_module;
+void *ctx_conf;
int ngx_connection_counter;
@@ -81,8 +82,14 @@
}
ngx_memzero(&conf, sizeof(ngx_conf_t));
- ngx_test_null(conf.args,
- ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)), 1);
+
+ ngx_test_null(conf.args, ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)),
+ 1);
+
+ ngx_test_null(conf.ctx,
+ ngx_pcalloc(ngx_pool, ngx_max_module * sizeof(void *)),
+ 1);
+
conf.pool = ngx_pool;
conf.log = &ngx_log;
conf.module_type = NGX_CORE_MODULE_TYPE;
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 5e1f173..3d93f02 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -27,6 +27,8 @@
if (filename) {
+ /* open configuration file */
+
fd = ngx_open_file(filename->data, NGX_FILE_RDONLY);
if (fd == NGX_INVALID_FILE) {
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
@@ -60,7 +62,8 @@
for ( ;; ) {
rc = ngx_conf_read_token(cf);
- /* NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */
+ /* ngx_conf_read_token() returns NGX_OK, NGX_ERROR,
+ NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE */
#if 0
ngx_log_debug(cf->log, "token %d" _ rc);
@@ -76,6 +79,8 @@
if (cf->handler) {
+ /* custom handler, i.e. used in http "types { ... }" directive */
+
rv = (*cf->handler)(cf, NULL, cf->handler_conf);
if (rv == NGX_CONF_OK) {
continue;
@@ -97,6 +102,9 @@
found = 0;
for (i = 0; !found && ngx_modules[i]; i++) {
+
+ /* look up the directive in the appropriate modules */
+
if (ngx_modules[i]->type != NGX_CONF_MODULE_TYPE
&& ngx_modules[i]->type != cf->module_type)
{
@@ -116,6 +124,7 @@
#if 0
ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data);
#endif
+ /* is the directive's location right ? */
if ((cmd->type & cf->cmd_type) == 0) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
@@ -127,6 +136,8 @@
return NGX_CONF_ERROR;
}
+ /* is the directive's argument count right ? */
+
if (!(cmd->type & NGX_CONF_ANY)
&& ((cmd->type & NGX_CONF_FLAG && cf->args->nelts != 2)
|| (!(cmd->type & NGX_CONF_FLAG)
@@ -145,8 +156,14 @@
return NGX_CONF_ERROR;
}
+ /* set up the directive's configuration context */
+
conf = NULL;
- if (cf->ctx) {
+
+ if (cf->module_type == NGX_CORE_MODULE_TYPE) {
+ conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
+
+ } else if (cf->ctx) {
pconf = *(void **) ((char *) cf->ctx + cmd->conf);
if (pconf) {
@@ -197,7 +214,7 @@
cf->conf_file = prev;
if (ngx_close_file(fd) == NGX_FILE_ERROR) {
- ngx_log_error(NGX_LOG_ERR, cf->log, ngx_errno,
+ ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
ngx_close_file_n " %s failed",
cf->conf_file->file.name.data);
return NGX_CONF_ERROR;
@@ -450,6 +467,26 @@
}
+char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
+{
+ int num, len;
+ ngx_str_t *value;
+
+ value = (ngx_str_t *) cf->args->elts;
+
+ len = value[1].len;
+
+ num = ngx_atoi(value[1].data, len);
+ if (num == NGX_ERROR) {
+ return "invalid value";
+ }
+
+ *(int *) (conf + cmd->offset) = num;
+
+ return NGX_CONF_OK;
+}
+
+
char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
{
int size, len, scale;
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index 195424f..a632625 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -17,18 +17,17 @@
* AAAA number of agruments
* FF command flags
* TT command type, i.e. HTTP "location" or "server" command
- * 00
*/
-#define NGX_CONF_NOARGS 0x0000000001
-#define NGX_CONF_TAKE1 0x0000000002
-#define NGX_CONF_TAKE2 0x0000000004
-#define NGX_CONF_ARGS_NUMBER 0x000000ffff
-#define NGX_CONF_ANY 0x0000010000
-#define NGX_CONF_BLOCK 0x0000020000
-#define NGX_CONF_FLAG 0x0000040000
+#define NGX_CONF_NOARGS 0x00000001
+#define NGX_CONF_TAKE1 0x00000002
+#define NGX_CONF_TAKE2 0x00000004
+#define NGX_CONF_ARGS_NUMBER 0x0000ffff
+#define NGX_CONF_ANY 0x00010000
+#define NGX_CONF_BLOCK 0x00020000
+#define NGX_CONF_FLAG 0x00040000
-#define NGX_MAIN_CONF 0x0001000000
+#define NGX_MAIN_CONF 0x01000000
@@ -61,8 +60,8 @@
typedef struct {
- int index;
void *ctx;
+ int index;
ngx_command_t *commands;
int type;
int (*init_module)(ngx_pool_t *p);
@@ -121,6 +120,7 @@
char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf);
char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf);
+char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf);
char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf);
char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf);
char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf);
diff --git a/src/core/ngx_modules.c b/src/core/ngx_modules.c
index a6b56c5..273c555 100644
--- a/src/core/ngx_modules.c
+++ b/src/core/ngx_modules.c
@@ -4,6 +4,10 @@
#include <ngx_conf_file.h>
+extern ngx_module_t ngx_events_module;
+extern ngx_module_t ngx_event_module;
+
+
extern ngx_module_t ngx_http_module;
extern ngx_module_t ngx_http_core_module;
@@ -17,6 +21,13 @@
ngx_module_t *ngx_modules[] = {
+ /* events */
+
+ &ngx_events_module,
+ &ngx_event_module,
+
+ /* http */
+
&ngx_http_module,
&ngx_http_core_module,
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c
index 917fe2c..8cc7190 100644
--- a/src/event/modules/ngx_kqueue_module.c
+++ b/src/event/modules/ngx_kqueue_module.c
@@ -10,6 +10,7 @@
#include <ngx_connection.h>
#include <ngx_event.h>
#include <ngx_event_timer.h>
+#include <ngx_conf_file.h>
#include <ngx_kqueue_module.h>
@@ -18,6 +19,10 @@
#define KQUEUE_NEVENTS 512
+static int ngx_kqueue_changes;
+static int ngx_kqueue_events;
+
+
/* should be per-thread if threads are used without thread pool */
#if 1
int kq;
@@ -32,6 +37,37 @@
/* */
+static ngx_str_t kqueue_name = ngx_string("kqueue");
+
+static ngx_command_t ngx_kqueue_commands[] = {
+
+ {ngx_string("kqueue_changes"),
+ NGX_EVENT_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ 0,
+ addressof(ngx_kqueue_changes),
+ NULL},
+
+ {ngx_string("kqueue_events"),
+ NGX_EVENT_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ 0,
+ addressof(ngx_kqueue_events),
+ NULL},
+
+ {ngx_string(""), 0, NULL, 0, 0, NULL}
+};
+
+ngx_module_t ngx_kqueue_module = {
+ &kqueue_name, /* module context */
+ 0, /* module index */
+ ngx_kqueue_commands, /* module directives */
+ NGX_EVENT_MODULE_TYPE, /* module type */
+ NULL /* init module */
+};
+
+
+
int ngx_kqueue_init(int max_connections, ngx_log_t *log)
{
int change_size, event_size;
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index d3acb4f..a3b12d0 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -9,6 +9,7 @@
#include <ngx_listen.h>
#include <ngx_connection.h>
#include <ngx_event.h>
+#include <ngx_conf_file.h>
#include <ngx_select_module.h>
@@ -34,6 +35,9 @@
#endif
+static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy);
+
+
ngx_connection_t *ngx_connections;
ngx_event_t *ngx_read_events, *ngx_write_events;
@@ -68,6 +72,66 @@
#endif /* USE_KQUEUE */
+static int ngx_event_connections;
+
+
+static ngx_str_t events_name = ngx_string("events");
+
+static ngx_command_t ngx_events_commands[] = {
+
+ {ngx_string("events"),
+ NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
+ ngx_events_block,
+ 0,
+ 0,
+ NULL},
+
+ {ngx_string(""), 0, NULL, 0, 0, NULL}
+};
+
+
+ngx_module_t ngx_events_module = {
+ &events_name, /* module context */
+ 0, /* module index */
+ ngx_events_commands, /* module directives */
+ NGX_CORE_MODULE_TYPE, /* module type */
+ NULL /* init module */
+};
+
+
+
+static ngx_command_t ngx_event_commands[] = {
+
+ {ngx_string("connections"),
+ NGX_EVENT_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ 0,
+ addressof(ngx_event_connections),
+ NULL},
+
+#if 0
+ {ngx_string("type"),
+ NGX_EVENT_CONF|NGX_CONF_TAKE1,
+ ngx_event_set_type,
+ 0,
+ 0,
+ NULL},
+#endif
+
+ {ngx_string(""), 0, NULL, 0, 0, NULL}
+};
+
+
+ngx_module_t ngx_event_module = {
+ NULL, /* module context */
+ 0, /* module index */
+ ngx_events_commands, /* module directives */
+ NGX_EVENT_MODULE_TYPE, /* module type */
+ NULL /* init module */
+};
+
+
+
void ngx_pre_thread(ngx_array_t *ls, ngx_pool_t *pool, ngx_log_t *log)
{
int i, fd;
@@ -173,6 +237,7 @@
}
}
+
void ngx_worker(ngx_log_t *log)
{
for ( ;; ) {
@@ -181,3 +246,44 @@
ngx_process_events(log);
}
}
+
+
+static char *ngx_events_init(ngx_pool_t *pool)
+{
+ ngx_event_connections = -1;
+ ngx_event_type = -1;
+
+ return NGX_CONF_OK;
+}
+
+
+static char *ngx_events_postconf(ngx_pool_t *pool)
+{
+ if (ngx_event_connections == -1) {
+ ngx_event_connections = 512;
+ }
+
+ return NGX_CONF_OK;
+}
+
+
+static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
+{
+ char *rv;
+ ngx_conf_t pcf;
+
+#if 0
+ *(ngx_events_conf_ctx_t **) conf = ctx;
+#endif
+
+ pcf = *cf;
+ cf->module_type = NGX_EVENT_MODULE_TYPE;
+ cf->cmd_type = NGX_EVENT_CONF;
+ rv = ngx_conf_parse(cf, NULL);
+ *cf = pcf;
+
+ if (rv != NGX_CONF_OK)
+ return rv;
+
+ return NGX_CONF_OK;
+}
diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h
index 72f4ba9..c976e17 100644
--- a/src/event/ngx_event.h
+++ b/src/event/ngx_event.h
@@ -298,6 +298,12 @@
#endif
+#define NGX_EVENT_MODULE_TYPE 0x544E5645 /* "EVNT" */
+
+#define NGX_EVENT_CONF 0x00200000
+
+
+
void ngx_event_accept(ngx_event_t *ev);
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index 4af3c94..2a236ee 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -47,8 +47,8 @@
ngx_module_t ngx_http_index_module = {
- 0, /* module index */
&ngx_http_index_module_ctx, /* module context */
+ 0, /* module index */
ngx_http_index_commands, /* module directives */
NGX_HTTP_MODULE_TYPE, /* module type */
ngx_http_index_init /* init module */
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 95a7459..17c3da5 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -53,15 +53,15 @@
ngx_module_t ngx_http_module = {
- 0, /* module index */
&http_name, /* module context */
+ 0, /* module index */
ngx_http_commands, /* module directives */
NGX_CORE_MODULE_TYPE, /* module type */
NULL /* init module */
};
-static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
+static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
{
int i, s, l, p, a, n, start;
int port_found, addr_found, virtual_names;
@@ -70,7 +70,7 @@
ngx_array_t in_ports;
ngx_listen_t *ls;
ngx_http_module_t *module;
- ngx_conf_t prev;
+ ngx_conf_t pcf;
ngx_http_conf_ctx_t *ctx;
ngx_http_in_port_t *in_port, *inport;
ngx_http_in_addr_t *in_addr, *inaddr;
@@ -85,6 +85,8 @@
ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
NGX_CONF_ERROR);
+ *(ngx_http_conf_ctx_t **) conf = ctx;
+
ngx_http_max_module = 0;
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) {
@@ -96,7 +98,20 @@
module->index = ngx_http_max_module++;
}
- /* null loc_conf */
+ /* TODO: http main_conf */
+
+ ngx_test_null(ctx->main_conf,
+ ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
+ NGX_CONF_ERROR);
+
+ /* TODO: http srv_conf */
+
+ ngx_test_null(ctx->srv_conf,
+ ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
+ NGX_CONF_ERROR);
+
+ /* http null loc_conf */
+
ngx_test_null(ctx->loc_conf,
ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
NGX_CONF_ERROR);
@@ -115,12 +130,12 @@
}
}
- prev = *cf;
+ pcf = *cf;
cf->ctx = ctx;
cf->module_type = NGX_HTTP_MODULE_TYPE;
cf->cmd_type = NGX_HTTP_MAIN_CONF;
rv = ngx_conf_parse(cf, NULL);
- *cf = prev;
+ *cf = pcf;
if (rv != NGX_CONF_OK)
return rv;
diff --git a/src/http/ngx_http_config.h b/src/http/ngx_http_config.h
index 34890f9..370b7db 100644
--- a/src/http/ngx_http_config.h
+++ b/src/http/ngx_http_config.h
@@ -7,6 +7,7 @@
typedef struct {
+ void **main_conf;
void **srv_conf;
void **loc_conf;
} ngx_http_conf_ctx_t;
@@ -38,20 +39,19 @@
#define NGX_HTTP_LOC_CONF 0x8000000
-#define NGX_HTTP_SRV_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, srv_conf)
-#define NGX_HTTP_LOC_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, loc_conf)
+#define NGX_HTTP_MAIN_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, main_conf)
+#define NGX_HTTP_SRV_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, srv_conf)
+#define NGX_HTTP_LOC_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, loc_conf)
-#define ngx_http_get_module_srv_conf(r, module) r->srv_conf[module.index]
-#define ngx_http_get_module_loc_conf(r, module) r->loc_conf[module.index]
+#define ngx_http_get_module_main_conf(r, ctx) r->main_conf[ctx.index]
+#define ngx_http_get_module_srv_conf(r, ctx) r->srv_conf[ctx.index]
+#define ngx_http_get_module_loc_conf(r, ctx) r->loc_conf[ctx.index]
int ngx_http_config_modules(ngx_pool_t *pool, ngx_module_t **modules);
-extern ngx_module_t ngx_http_module;
-
-
extern int (*ngx_http_top_header_filter) (ngx_http_request_t *r);
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index d80567b..19bafda 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -74,8 +74,8 @@
{ngx_string("client_header_buffer_size"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
- 0,
- addressof(ngx_http_client_header_buffer_size),
+ NGX_HTTP_MAIN_CONF_OFFSET,
+ offsetof(ngx_http_core_main_conf_t, client_header_buffer_size),
NULL},
{ngx_string("large_client_header"),
@@ -157,8 +157,8 @@
ngx_module_t ngx_http_core_module = {
- 0, /* module index */
&ngx_http_core_module_ctx, /* module context */
+ 0, /* module index */
ngx_http_core_commands, /* module directives */
NGX_HTTP_MODULE_TYPE, /* module type */
ngx_http_core_init /* init module */
@@ -615,7 +615,7 @@
char *rv;
ngx_http_module_t *module;
ngx_conf_t pcf;
- ngx_http_conf_ctx_t *ctx, *pctx;
+ ngx_http_conf_ctx_t *ctx, *tctx, *pctx;
ngx_http_core_srv_conf_t *scf;
ngx_http_core_loc_conf_t **plcf;
@@ -623,12 +623,17 @@
ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
NGX_CONF_ERROR);
- /* server config */
+ tctx = (ngx_http_conf_ctx_t *) cf->ctx;
+ ctx->main_conf = tctx->main_conf;
+
+ /* server configuration */
+
ngx_test_null(ctx->srv_conf,
ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
NGX_CONF_ERROR);
- /* server location config */
+ /* server location configuration */
+
ngx_test_null(ctx->loc_conf,
ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
NGX_CONF_ERROR);
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 48de146..d44a86c 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -18,6 +18,12 @@
typedef struct {
+ int request_pool_size;
+ int client_header_buffer_size;
+} ngx_http_core_main_conf_t;
+
+
+typedef struct {
ngx_array_t locations; /* array of ngx_http_core_loc_conf_t */
ngx_array_t listen; /* 'listen', array of ngx_http_listen_t */
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index 1b83fc4..926a286 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -30,8 +30,8 @@
ngx_module_t ngx_http_header_filter_module = {
- 0, /* module index */
&ngx_http_header_filter_module_ctx, /* module context */
+ 0, /* module index */
NULL, /* module directives */
NGX_HTTP_MODULE_TYPE, /* module type */
ngx_http_header_filter_init /* init module */
diff --git a/src/http/ngx_http_output_filter.c b/src/http/ngx_http_output_filter.c
index 2a7ada7..738c383 100644
--- a/src/http/ngx_http_output_filter.c
+++ b/src/http/ngx_http_output_filter.c
@@ -45,8 +45,8 @@
ngx_module_t ngx_http_output_filter_module = {
- 0, /* module index */
&ngx_http_output_filter_module_ctx, /* module context */
+ 0, /* module index */
ngx_http_output_filter_commands, /* module directives */
NGX_HTTP_MODULE_TYPE, /* module type */
NULL /* init module */
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index 752a932..31303d4 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -44,8 +44,8 @@
ngx_module_t ngx_http_write_filter_module = {
- 0, /* module index */
&ngx_http_write_filter_module_ctx, /* module context */
+ 0, /* module index */
ngx_http_write_filter_commands, /* module directives */
NGX_HTTP_MODULE_TYPE, /* module type */
ngx_http_write_filter_init /* init module */