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,