]> git.kaiwu.me - nginx.git/commitdiff
nginx-0.0.1-2003-11-10-20:17:31 import
authorIgor Sysoev <igor@sysoev.ru>
Mon, 10 Nov 2003 17:17:31 +0000 (17:17 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 10 Nov 2003 17:17:31 +0000 (17:17 +0000)
20 files changed:
src/core/ngx_conf_file.c
src/http/modules/ngx_http_charset_filter.c
src/http/modules/ngx_http_chunked_filter.c
src/http/modules/ngx_http_gzip_filter.c
src/http/modules/ngx_http_index_handler.c
src/http/modules/ngx_http_not_modified_filter.c
src/http/modules/ngx_http_range_filter.c
src/http/modules/ngx_http_static_handler.c
src/http/modules/proxy/ngx_http_proxy_cache.c
src/http/modules/proxy/ngx_http_proxy_handler.c
src/http/modules/proxy/ngx_http_proxy_upstream.c
src/http/ngx_http.c
src/http/ngx_http_config.h
src/http/ngx_http_core_module.c
src/http/ngx_http_header_filter.c
src/http/ngx_http_log_handler.c
src/http/ngx_http_log_handler.h
src/http/ngx_http_output_filter.c
src/http/ngx_http_write_filter.c
src/os/unix/ngx_freebsd_config.h

index 24aa096fdd97a7a85c83c075c128f26853a89b9a..5c83afc8198a4225b308fc8ac6b5e19e09d9d047 100644 (file)
@@ -368,6 +368,11 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
                 return NGX_OK;
             }
 
+            ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+                          "unexpected '%c' in %s:%d",
+                          ch, cf->conf_file->file.name.data,
+                          cf->conf_file->line);
+
             return NGX_ERROR;
         }
 
index dd48f0bb1c5007bbfb7866783384405418bad5a1..a545eafa184e56dc855835b015c5033fa5fee68c 100644 (file)
@@ -29,6 +29,8 @@ static ngx_command_t  ngx_http_charset_filter_commands[] = {
 
 
 static ngx_http_module_t  ngx_http_charset_filter_module_ctx = {
+    NULL,                                  /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
index 20a5d0d2ddb9536a88b8a8f1195297dacb5dba55..5e7bd28be1ffd1d353739261d0ac05818cb5bb3e 100644 (file)
@@ -8,6 +8,8 @@ static int ngx_http_chunked_filter_init(ngx_cycle_t *cycle);
 
 
 static ngx_http_module_t  ngx_http_chunked_filter_module_ctx = {
+    NULL,                                  /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
index 5a091b475b9f683ffee94635d90f0f2c7a6bdbe2..09980eff3832611300ae234303019de7d370d01f 100644 (file)
@@ -34,6 +34,10 @@ typedef struct {
 
     unsigned             flush:4;
     unsigned             redo:1;
+    unsigned             done:1;
+
+    size_t               zin;
+    size_t               zout;
 
     u_int                crc32;
     z_stream             zstream;
@@ -46,6 +50,11 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items,
 static void ngx_http_gzip_filter_free(void *opaque, void *address);
 
 ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx);
+
+static char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, char *buf,
+                                     uintptr_t data);
+
+static int ngx_http_gzip_pre_conf(ngx_conf_t *cf);
 static int ngx_http_gzip_filter_init(ngx_cycle_t *cycle);
 static void *ngx_http_gzip_create_conf(ngx_conf_t *cf);
 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
@@ -114,6 +123,8 @@ static ngx_command_t  ngx_http_gzip_filter_commands[] = {
 
 
 static ngx_http_module_t  ngx_http_gzip_filter_module_ctx = {
+    ngx_http_gzip_pre_conf,                /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
@@ -135,6 +146,13 @@ ngx_module_t  ngx_http_gzip_filter_module = {
 };
 
 
+static ngx_http_log_op_name_t ngx_http_gzip_log_fmt_ops[] = {
+    { ngx_string("gzip_ratio"), NGX_INT32_LEN + 3, ngx_http_gzip_log_ratio },
+    { ngx_null_string, 0, NULL }
+};
+
+
+
 static u_char  gzheader[10] = { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 };
 
 #if (HAVE_LITTLE_ENDIAN)
@@ -215,7 +233,7 @@ static int ngx_http_gzip_header_filter(ngx_http_request_t *r)
 
 static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 {
-    int                    rc, wbits, memlevel, zin, zout, last;
+    int                    rc, wbits, memlevel, last;
     struct gztrailer      *trailer;
     ngx_hunk_t            *h;
     ngx_chain_t           *cl;
@@ -226,6 +244,10 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
         return ngx_http_next_body_filter(r, in);
     }
 
+    if (ctx->done) {
+        return ngx_http_next_body_filter(r, in);
+    }
+
     conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
 
     if (ctx->preallocated == NULL) {
@@ -400,8 +422,8 @@ ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _
 
                     /* rc == Z_STREAM_END */
 
-                    zin = ctx->zstream.total_in;
-                    zout = 10 + ctx->zstream.total_out + 8;
+                    ctx->zin = ctx->zstream.total_in;
+                    ctx->zout = 10 + ctx->zstream.total_out + 8;
 
                     rc = deflateEnd(&ctx->zstream);
                     if (rc != Z_OK) {
@@ -441,7 +463,7 @@ ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _
 
 #if (HAVE_LITTLE_ENDIAN)
                     trailer->crc32 = ctx->crc32;
-                    trailer->zlen = zin;
+                    trailer->zlen = ctx->zin;
 #else
                     /* STUB */
 #endif
@@ -449,7 +471,11 @@ ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _
                     ctx->zstream.avail_in = 0;
                     ctx->zstream.avail_out = 0;
 
+                    ctx->done = 1;
+
+#if 0
                     ngx_http_delete_ctx(r, ngx_http_gzip_filter_module);
+#endif
 
                     break;
 
@@ -531,6 +557,40 @@ static void ngx_http_gzip_filter_free(void *opaque, void *address)
 }
 
 
+static char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, char *buf,
+                                     uintptr_t data)
+{
+    int                   zint, zfrac;
+    ngx_http_gzip_ctx_t  *ctx;
+
+    ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module);
+
+    if (ctx == NULL || ctx->zout == 0) {
+        *buf = '-';
+        return buf + 1;
+    }
+
+#if 0
+    return buf + ngx_snprintf(buf, NGX_INT32_LEN + 4, "%.2f",
+                              (float) ctx->zin / ctx->zout);
+#endif
+
+    /* we prefer do not use FPU */
+
+    zint = ctx->zin / ctx->zout;
+    zfrac = (ctx->zin * 100 / ctx->zout) % 100;
+
+    if ((ctx->zin * 1000 / ctx->zout) %10 > 4) {
+        if (++zfrac > 99) {
+            zint++;
+            zfrac = 0;
+        }
+    }
+
+    return buf + ngx_snprintf(buf, NGX_INT32_LEN + 4, "%d.%02d", zint, zfrac);
+}
+
+
 ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx)
 {
     deflateEnd(&ctx->zstream);
@@ -544,6 +604,27 @@ ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx)
 }
 
 
+static int ngx_http_gzip_pre_conf(ngx_conf_t *cf)
+{
+    ngx_http_log_op_name_t  *op;
+
+    for (op = ngx_http_gzip_log_fmt_ops; op->name.len; op++) { /* void */ }
+    op->op = NULL;
+
+    op = ngx_http_log_fmt_ops;
+
+    for (op = ngx_http_log_fmt_ops; op->op; op++) {
+        if (op->name.len == 0) {
+            op = (ngx_http_log_op_name_t *) op->op;
+        }
+    }
+
+    op->op = (ngx_http_log_op_pt) ngx_http_gzip_log_fmt_ops;
+
+    return NGX_OK;
+}
+
+
 static int ngx_http_gzip_filter_init(ngx_cycle_t *cycle)
 {
     ngx_http_next_header_filter = ngx_http_top_header_filter;
index 9ec932517ddf38e45b5c641703b8809a6e363616..f4c7157ac9b8598c8de991fd2f87f477fe40b790 100644 (file)
@@ -46,6 +46,8 @@ static ngx_command_t ngx_http_index_commands[] = {
 
 
 ngx_http_module_t  ngx_http_index_module_ctx = {
+    NULL,                                  /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
index b00e2ff76170d969c905cb342b49393bf2e248fe..c6237525332e570a75d60dc81e34068b9f87d2d0 100644 (file)
@@ -9,6 +9,8 @@ static int ngx_http_not_modified_filter_init(ngx_cycle_t *cycle);
 
 
 static ngx_http_module_t  ngx_http_not_modified_filter_module_ctx = {
+    NULL,                                  /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
index 850235a38d975c711631e28ce4822564e2ff3c73..11b7d0f13ea2436f913833ffb29c846362e72f2f 100644 (file)
@@ -48,6 +48,8 @@ static int ngx_http_range_filter_init(ngx_cycle_t *cycle);
 
 
 static ngx_http_module_t  ngx_http_range_filter_module_ctx = {
+    NULL,                                  /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
index 9849dbf34366fb8da8a890fcd03ba2fbb1b00d46..33d293aac310d277ef400fde326788228afba339 100644 (file)
@@ -16,6 +16,8 @@ static ngx_command_t  ngx_http_static_commands[] = {
 
 
 ngx_http_module_t  ngx_http_static_module_ctx = {
+    NULL,                                  /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
     
index 0f56686b80fc009974e026b21440fa125b94920f..3c4f5cad38b34c34d98bc269a3bd1c67eeb61031 100644 (file)
@@ -302,6 +302,7 @@ void ngx_http_proxy_cache_busy_lock(ngx_http_proxy_ctx_t *p)
         return;
     }
     
+    p->state->status = NGX_HTTP_SERVICE_UNAVAILABLE;
     ngx_http_proxy_finalize_request(p, NGX_HTTP_SERVICE_UNAVAILABLE);
 }
 
@@ -468,7 +469,7 @@ int ngx_http_proxy_send_cached_response(ngx_http_proxy_ctx_t *p)
 
 int ngx_http_proxy_is_cachable(ngx_http_proxy_ctx_t *p)
 {
-    time_t                        date, last_modified, expires;
+    time_t                        date, last_modified, expires, t;
     ngx_http_proxy_headers_in_t  *h;
 
     switch (p->upstream->status) {
@@ -509,6 +510,7 @@ int ngx_http_proxy_is_cachable(ngx_http_proxy_ctx_t *p)
                            h->x_accel_expires->value.len);
         if (expires != NGX_ERROR) {
             p->state->reason = NGX_HTTP_PROXY_CACHE_XAE;
+            p->state->expires = expires;
             p->cache->ctx.expires = date + expires;
             return (expires > 0);
         }
@@ -523,6 +525,7 @@ int ngx_http_proxy_is_cachable(ngx_http_proxy_ctx_t *p)
                                           h->expires->value.len);
             if (expires != NGX_ERROR) {
                 p->state->reason = NGX_HTTP_PROXY_CACHE_EXP;
+                p->state->expires = expires - date;
                 p->cache->ctx.expires = expires;
                 return (date < expires);
             }
@@ -531,6 +534,7 @@ int ngx_http_proxy_is_cachable(ngx_http_proxy_ctx_t *p)
 
     if (p->upstream->status == NGX_HTTP_MOVED_PERMANENTLY) {
         p->state->reason = NGX_HTTP_PROXY_CACHE_MVD;
+        p->state->expires = /* STUB: 1 hour */ 60 * 60;
         p->cache->ctx.expires = /* STUB: 1 hour */ 60 * 60;
         return 1;
     }
@@ -544,14 +548,17 @@ int ngx_http_proxy_is_cachable(ngx_http_proxy_ctx_t *p)
         /* FIXME: time_t == int_64_t, we can use fpu */ 
 
         p->state->reason = NGX_HTTP_PROXY_CACHE_LMF;
-        p->cache->ctx.expires = (time_t) (ngx_time()
-             + (((int64_t) (date - last_modified)) * p->lcf->lm_factor) / 100);
+        t = (time_t)
+              ((((int64_t) (date - last_modified)) * p->lcf->lm_factor) / 100);
+        p->state->expires = t;
+        p->cache->ctx.expires = ngx_time() + t;
         return 1;
     }
 
     if (p->lcf->default_expires > 0) {
         p->state->reason = NGX_HTTP_PROXY_CACHE_PDE;
-        p->cache->ctx.expires = p->lcf->default_expires;
+        p->state->expires = p->lcf->default_expires;
+        p->cache->ctx.expires = ngx_time() + p->lcf->default_expires;
         return 1;
     }
 
index 4a48250e39e32ba492bfb70cd34148ce199b058c..ad719ca11e7b9eb110d2a5942b7c7cbc2caf1a6b 100644 (file)
@@ -7,7 +7,14 @@
 
 static int ngx_http_proxy_handler(ngx_http_request_t *r);
 
-static int ngx_http_proxy_init(ngx_cycle_t *cycle);
+static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf,
+                                            uintptr_t data);
+static char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, char *buf,
+                                            uintptr_t data);
+static char *ngx_http_proxy_log_reason(ngx_http_request_t *r, char *buf,
+                                       uintptr_t data);
+
+static int ngx_http_proxy_pre_conf(ngx_conf_t *cf);
 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf,
                                            void *parent, void *child);
@@ -194,6 +201,8 @@ static ngx_command_t  ngx_http_proxy_commands[] = {
 
 
 ngx_http_module_t  ngx_http_proxy_module_ctx = {
+    ngx_http_proxy_pre_conf,               /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
@@ -215,6 +224,19 @@ ngx_module_t  ngx_http_proxy_module = {
 };
 
 
+
+static ngx_http_log_op_name_t ngx_http_proxy_log_fmt_ops[] = {
+    { ngx_string("proxy"), /* STUB */ 100,
+                           ngx_http_proxy_log_proxy_state },
+    { ngx_string("proxy_cache_state"), sizeof("BYPASS") - 1,
+                                       ngx_http_proxy_log_cache_state },
+    { ngx_string("proxy_reason"), sizeof("BPS") - 1,
+                                  ngx_http_proxy_log_reason },
+    { ngx_null_string, 0, NULL }
+};
+
+
+
 ngx_http_header_t ngx_http_proxy_headers_in[] = {
     { ngx_string("Date"), offsetof(ngx_http_proxy_headers_in_t, date) },
     { ngx_string("Server"), offsetof(ngx_http_proxy_headers_in_t, server) },
@@ -252,7 +274,7 @@ static ngx_str_t cache_states[] = {
 };
 
 
-static ngx_str_t cache_reason[] = {
+static ngx_str_t cache_reasons[] = {
     ngx_string("BPS"),
     ngx_string("XAE"),
     ngx_string("CTL"),
@@ -453,12 +475,6 @@ void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p)
 }
 
 
-size_t ngx_http_proxy_log_state(void *data, char *buf, size_t len)
-{
-    return 0;
-}
-
-
 size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len)
 {
     ngx_http_proxy_ctx_t *p = data;
@@ -482,6 +498,121 @@ size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len)
 }
 
 
+static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf,
+                                            uintptr_t data)
+{
+    ngx_http_proxy_ctx_t  *p;
+
+    p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+
+    if (p == NULL) {
+        *buf = '-';
+        return buf + 1;
+    }
+
+    if (p->state->cache_state == 0) {
+        *buf++ = '-';
+
+    } else {
+        buf = ngx_cpymem(buf, cache_states[p->state->cache_state - 1].data,
+                         cache_states[p->state->cache_state - 1].len);
+    }
+
+    *buf++ = '/';
+
+    *buf++ = 'X';
+
+    *buf++ = '/';
+
+    *buf++ = 'X';
+
+    *buf++ = ' ';
+
+    if (p->state->status == 0) {
+        *buf++ = '-';
+
+    } else {
+        buf += ngx_snprintf(buf, 4, "%d", p->state->status);
+    }
+
+    *buf++ = '/';
+
+    if (p->state->reason == 0) {
+        *buf++ = '-';
+
+    } else {
+        buf = ngx_cpymem(buf, cache_reasons[p->state->reason - 1].data,
+                         cache_reasons[p->state->reason - 1].len);
+    }
+
+    *buf++ = '/';
+
+    if (p->state->reason >= NGX_HTTP_PROXY_CACHE_XAE) {
+        *buf++ = '-';
+
+    } else {
+        buf += ngx_snprintf(buf, NGX_TIME_LEN, TIME_FMT, p->state->expires);
+    }
+
+    return buf;
+}
+
+
+static char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, char *buf,
+                                            uintptr_t data)
+{
+    ngx_http_proxy_ctx_t  *p;
+
+    p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+
+    if (p == NULL || p->state->cache_state == 0) {
+        *buf = '-';
+        return buf + 1;
+    }
+
+    return ngx_cpymem(buf, cache_states[p->state->cache_state - 1].data,
+                      cache_states[p->state->cache_state - 1].len);
+}
+
+
+static char *ngx_http_proxy_log_reason(ngx_http_request_t *r, char *buf,
+                                       uintptr_t data)
+{
+    ngx_http_proxy_ctx_t  *p;
+
+    p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+
+    if (p == NULL || p->state->reason == 0) {
+        *buf = '-';
+        return buf + 1;
+    }
+
+    return ngx_cpymem(buf, cache_reasons[p->state->reason - 1].data,
+                      cache_reasons[p->state->reason - 1].len);
+}
+
+
+static int ngx_http_proxy_pre_conf(ngx_conf_t *cf)
+{
+    ngx_http_log_op_name_t  *op;
+
+    for (op = ngx_http_proxy_log_fmt_ops; op->name.len; op++) { /* void */ }
+    op->op = NULL;
+
+    op = ngx_http_log_fmt_ops;
+
+    for (op = ngx_http_log_fmt_ops; op->op; op++) {
+        if (op->name.len == 0) {
+            op = (ngx_http_log_op_name_t *) op->op;
+        }
+    }
+
+    op->op = (ngx_http_log_op_pt) ngx_http_proxy_log_fmt_ops;
+
+    return NGX_OK;
+}
+
+
 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
 {
     ngx_http_proxy_loc_conf_t  *conf;
index 0ec2fee486df26baba7d4e8ac54a3d94c02c3d04..d4049935df482370a0088b5ab281c50d6777a68f 100644 (file)
@@ -305,6 +305,13 @@ static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p)
         }
     }
 
+    /* add one more state */
+
+    if (!(p->state = ngx_push_array(&p->states))) {
+        ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
+        return;
+    }
+
     p->status = 0;
     p->status_count = 0;
 }
@@ -344,6 +351,7 @@ void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p)
         return;
     }
 
+    p->state->status = NGX_HTTP_SERVICE_UNAVAILABLE;
     ngx_http_proxy_finalize_request(p, NGX_HTTP_SERVICE_UNAVAILABLE);
 }
 
@@ -407,11 +415,6 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
 
     p->request_sent = 0;
 
-    if (!(p->state = ngx_push_array(&p->states))) {
-        ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
-        return;
-    }
-
     if (rc == NGX_AGAIN) {
         ngx_add_timer(c->write, p->lcf->connect_timeout);
         return;
@@ -636,6 +639,7 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev)
     /* rc == NGX_OK */
 
     p->upstream->status = p->status;
+    p->state->status = p->status;
 
     if (p->status == NGX_HTTP_INTERNAL_SERVER_ERROR) {
 
index 5f561f71386f6c6eb131d1562855d8a3beae5552..9fa8f6213623aca9e6b42fd4a0c81a7c0ee3df89 100644 (file)
@@ -107,6 +107,12 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
         module = ngx_modules[m]->ctx;
         mi = ngx_modules[m]->ctx_index;
 
+        if (module->pre_conf) {
+            if (module->pre_conf(cf) != NGX_OK) {
+                return NGX_CONF_ERROR;
+            }
+        }
+
         if (module->create_main_conf) {
             ngx_test_null(ctx->main_conf[mi], module->create_main_conf(cf),
                           NGX_CONF_ERROR);
@@ -157,6 +163,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
         if (module->init_main_conf) {
             rv = module->init_main_conf(cf, ctx->main_conf[mi]);
             if (rv != NGX_CONF_OK) {
+                *cf = pcf;
                 return rv;
             }
         }
@@ -170,6 +177,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
                                             ctx->srv_conf[mi],
                                             cscfp[s]->ctx->srv_conf[mi]);
                 if (rv != NGX_CONF_OK) {
+                    *cf = pcf;
                     return rv;
                 }
             }
@@ -182,6 +190,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
                                             ctx->loc_conf[mi],
                                             cscfp[s]->ctx->loc_conf[mi]);
                 if (rv != NGX_CONF_OK) {
+                    *cf = pcf;
                     return rv;
                 }
 
@@ -194,6 +203,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
                                                 cscfp[s]->ctx->loc_conf[mi],
                                                 clcfp[l]->loc_conf[mi]);
                     if (rv != NGX_CONF_OK) {
+                        *cf = pcf;
                         return rv;
                     }
                 }
@@ -201,6 +211,8 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
         }
     }
 
+    /* we needed "http"'s cf->ctx while merging configuration */
+    *cf = pcf;
 
     /* init lists of the handlers */
 
@@ -557,6 +569,5 @@ ngx_log_debug(cf->log, "%s %08x" _ s_name[n].name.data _
     }
     /**/
 
-    *cf = pcf;
     return NGX_CONF_OK;
 }
index d12dfca94d1efc5c0936f815a6f8f16791e8214e..ab5b47724ad1311bbcb9bd6fe20cee4c8d3485ea 100644 (file)
@@ -20,6 +20,8 @@ typedef struct {
 
 
 typedef struct {
+    int    (*pre_conf)(ngx_conf_t *cf);
+
     void  *(*create_main_conf)(ngx_conf_t *cf);
     char  *(*init_main_conf)(ngx_conf_t *cf, void *conf);
 
index d7b4fac2bd21825eace81e843b553932fa0261cb..a5f5c38ca024712007c1df6dbb9764e334d41501 100644 (file)
@@ -212,6 +212,8 @@ static ngx_command_t  ngx_http_core_commands[] = {
 
 
 ngx_http_module_t  ngx_http_core_module_ctx = {
+    NULL,                                  /* pre conf */
+
     ngx_http_core_create_main_conf,        /* create main configuration */
     ngx_http_core_init_main_conf,          /* init main configuration */
 
index 3f56563d0be7d55d640cac8f9995117d22b806fb..64cf4bbce17ca26886710a67578be574018f637d 100644 (file)
@@ -10,6 +10,8 @@ static int ngx_http_header_filter(ngx_http_request_t *r);
 
 
 static ngx_http_module_t  ngx_http_header_filter_module_ctx = {
+    NULL,                                  /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
index b4811c8e948e3229f476bcf50e308cdefcb02dae..7a2bf9e9c5bc9e6329c3242d5b04cca093f78d44 100644 (file)
@@ -28,6 +28,7 @@ static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf,
 static char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, char *buf,
                                              uintptr_t data);
 
+static int ngx_http_log_pre_conf(ngx_conf_t *cf);
 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf);
 static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent,
@@ -61,6 +62,8 @@ static ngx_command_t  ngx_http_log_commands[] = {
 
 
 ngx_http_module_t  ngx_http_log_module_ctx = {
+    ngx_http_log_pre_conf,                 /* pre conf */
+
     ngx_http_log_create_main_conf,         /* create main configuration */
     NULL,                                  /* init main configuration */
 
@@ -93,7 +96,7 @@ static ngx_str_t ngx_http_combined_fmt =
                "\"%{Referer}i\" %{User-Agent}i\"");
 
 
-static ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = {
+ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = {
     { ngx_string("addr"), INET_ADDRSTRLEN - 1, ngx_http_log_addr },
     { ngx_string("conn"), NGX_INT32_LEN, ngx_http_log_connection },
     { ngx_string("pipe"), 1, ngx_http_log_pipe },
@@ -439,6 +442,17 @@ static char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, char *buf,
 }
 
 
+static int ngx_http_log_pre_conf(ngx_conf_t *cf)
+{
+    ngx_http_log_op_name_t  *op;
+
+    for (op = ngx_http_log_fmt_ops; op->name.len; op++) { /* void */ }
+    op->op = NULL;
+
+    return NGX_OK;
+}
+
+
 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf)
 {
     ngx_http_log_main_conf_t  *conf;
@@ -474,7 +488,7 @@ static void *ngx_http_log_create_main_conf(ngx_conf_t *cf)
 
     rc = ngx_http_log_set_format(cf, NULL, conf);
     if (rc != NGX_CONF_OK) {
-        return rc;
+        return NULL;
     }
 
     return conf;
@@ -597,9 +611,6 @@ static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
     ngx_http_log_op_name_t     *name;
 
     value = cf->args->elts;
-#if 0
-    lmcf = ngx_http_conf_module_main_conf(cf, ngx_http_log_module);
-#endif
 
     fmt = lmcf->formats.elts;
     for (f = 0; f < lmcf->formats.nelts; f++) {
@@ -669,8 +680,8 @@ static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
                 fname = &value[s].data[i];
 
                 while (i < value[s].len
-                       && value[s].data[i] >= 'a'
-                       && value[s].data[i] <= 'z')
+                       && ((value[s].data[i] >= 'a' && value[s].data[i] <= 'z')
+                           || value[s].data[i] == '_'))
                 {
                     i++;
                 }
@@ -682,7 +693,11 @@ static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
                     break;
                 }
 
-                for (name = ngx_http_log_fmt_ops; name->name.len; name++) {
+                for (name = ngx_http_log_fmt_ops; name->op; name++) {
+                    if (name->name.len == 0) {
+                        name = (ngx_http_log_op_name_t *) name->op;
+                    }
+
                     if (name->name.len == fname_len
                         && ngx_strncmp(name->name.data, fname, fname_len) == 0)
                     {
index ba301aebf3eead540d9028217ba743f737cc4bf3..40e70dfe3a1163bec15101d6b2892854cec246d3 100644 (file)
@@ -17,6 +17,7 @@ typedef char *(*ngx_http_log_op_pt) (ngx_http_request_t *r, char *buf,
 
 /* STUB */
 #define NGX_INT32_LEN      sizeof("4294967296") - 1
+#define NGX_TIME_LEN       sizeof("4294967296") - 1
 #define NGX_OFF_LEN        sizeof("18446744073709551616") - 1
 
 
@@ -56,4 +57,7 @@ typedef struct {
 } ngx_http_log_loc_conf_t;
 
 
+extern ngx_http_log_op_name_t ngx_http_log_fmt_ops[];
+
+
 #endif /* _NGX_HTTP_LOG_HANDLER_H_INCLUDED_ */
index b8ce33202bfec51764e15762e2bbe83b65341058..f6cc85d12c474babf79a435f7a11302506601faa 100644 (file)
@@ -28,6 +28,8 @@ static ngx_command_t  ngx_http_output_filter_commands[] = {
 
 
 static ngx_http_module_t  ngx_http_output_filter_module_ctx = {
+    NULL,                                  /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
index 143f38c7d63361a63292c846b8ad7693f3b45cb6..50f7f93768c25365806ecd1b9f69d4238e853edd 100644 (file)
@@ -35,6 +35,8 @@ static ngx_command_t  ngx_http_write_filter_commands[] = {
 
 
 ngx_http_module_t  ngx_http_write_filter_module_ctx = {
+    NULL,                                  /* pre conf */
+
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
index 637c921e26e83f122c288cfaa0178a109ed922ad..890d6cc1cf02be49f72174de6e71f48ba7c5b4b7 100644 (file)
 #define OFF_FMT    "%lld"
 #define SIZE_FMT   "%d"
 #define SIZEX_FMT  "%x"
+#define TIME_FMT   "%lu"
 
 #else  /* amd64, alpha, sparc64, ia64 */
 
 #define OFF_FMT    "%ld"
 #define SIZE_FMT   "%ld"
 #define SIZEX_FMT  "%lx"
+#define TIME_FMT   "%lu"
 
 #endif