int ngx_max_module;
+void *ctx_conf;
int ngx_connection_counter;
}
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;
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,
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);
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;
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)
{
#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,
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)
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) {
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;
}
+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;
* 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
typedef struct {
- int index;
void *ctx;
+ int index;
ngx_command_t *commands;
int type;
int (*init_module)(ngx_pool_t *p);
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);
#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;
ngx_module_t *ngx_modules[] = {
+ /* events */
+
+ &ngx_events_module,
+ &ngx_event_module,
+
+ /* http */
+
&ngx_http_module,
&ngx_http_core_module,
#include <ngx_connection.h>
#include <ngx_event.h>
#include <ngx_event_timer.h>
+#include <ngx_conf_file.h>
#include <ngx_kqueue_module.h>
#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;
/* */
+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;
#include <ngx_listen.h>
#include <ngx_connection.h>
#include <ngx_event.h>
+#include <ngx_conf_file.h>
#include <ngx_select_module.h>
#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;
#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;
}
}
+
void ngx_worker(ngx_log_t *log)
{
for ( ;; ) {
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;
+}
#endif
+#define NGX_EVENT_MODULE_TYPE 0x544E5645 /* "EVNT" */
+
+#define NGX_EVENT_CONF 0x00200000
+
+
+
void ngx_event_accept(ngx_event_t *ev);
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 */
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;
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;
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) {
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);
}
}
- 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;
typedef struct {
+ void **main_conf;
void **srv_conf;
void **loc_conf;
} ngx_http_conf_ctx_t;
#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);
{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"),
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 */
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;
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);
} ngx_http_listen_t;
+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_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 */
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 */
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 */