mirror of
https://github.com/nginx/nginx.git
synced 2025-01-19 01:42:58 +08:00
nginx-0.0.1-2003-11-10-20:17:31 import
This commit is contained in:
parent
74e95c224a
commit
7832933eed
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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_ */
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -29,12 +29,14 @@
|
||||
#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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user