diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-11-11 14:07:14 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-11-11 14:07:14 +0000 |
commit | 1b73583ba2c0e4b72d951218827e0c621427d389 (patch) | |
tree | 9e4d204e2cce91560d5cb8908b8a1a9f2c1d92ee /src/http | |
parent | d6f24959428caed68a509a19ca4fd866d978a69c (diff) | |
download | nginx-1b73583ba2c0e4b72d951218827e0c621427d389.tar.gz nginx-1b73583ba2c0e4b72d951218827e0c621427d389.zip |
nginx-0.1.5-RELEASE importrelease-0.1.5
*) Bugfix: on Solaris and Linux there may be too many "recvmsg()
returned not enough data" alerts.
*) Bugfix: there were the "writev() failed (22: Invalid argument)"
errors on Solaris in proxy mode without sendfile. On other platforms
that do not support sendfile at all the process got caught in an
endless loop.
*) Bugfix: segmentation fault on Solaris in proxy mode and using
sendfile.
*) Bugfix: segmentation fault on Solaris.
*) Bugfix: on-line upgrade did not work on Linux.
*) Bugfix: the ngx_http_autoindex_module module did not escape the
spaces, the quotes, and the percent signs in the directory listing.
*) Change: the decrease of the copy operations.
*) Feature: the userid_p3p directive.
Diffstat (limited to 'src/http')
29 files changed, 797 insertions, 642 deletions
diff --git a/src/http/modules/ngx_http_access_handler.c b/src/http/modules/ngx_http_access_handler.c index 3a323b149..9e5c43c4d 100644 --- a/src/http/modules/ngx_http_access_handler.c +++ b/src/http/modules/ngx_http_access_handler.c @@ -97,8 +97,9 @@ static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r) rule = alcf->rules->elts; for (i = 0; i < alcf->rules->nelts; i++) { -ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%08X %08X %08X", - addr_in->sin_addr.s_addr, rule[i].mask, rule[i].addr); + ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "%08XD %08XD %08XD", + addr_in->sin_addr.s_addr, rule[i].mask, rule[i].addr); if ((addr_in->sin_addr.s_addr & rule[i].mask) == rule[i].addr) { if (rule[i].deny) { @@ -157,8 +158,8 @@ static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd, } if (ngx_ptocidr(&value[1], &in_cidr) == NGX_ERROR) { - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid paramter \"%s\"", - value[1].data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid paramter \"%V\"", + &value[1]); return NGX_CONF_ERROR; } diff --git a/src/http/modules/ngx_http_autoindex_handler.c b/src/http/modules/ngx_http_autoindex_handler.c index 99aa35d88..c78d4e616 100644 --- a/src/http/modules/ngx_http_autoindex_handler.c +++ b/src/http/modules/ngx_http_autoindex_handler.c @@ -24,6 +24,7 @@ typedef struct { typedef struct { ngx_str_t name; + ngx_uint_t escape; ngx_uint_t dir; time_t mtime; off_t size; @@ -269,10 +270,13 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) } entry->name.len = len; + entry->escape = 2 * ngx_escape_uri(NULL, ngx_de_name(&dir), len, + NGX_ESCAPE_HTML); - if (!(entry->name.data = ngx_palloc(pool, len + 1))) { + if (!(entry->name.data = ngx_palloc(pool, len + entry->escape + 1))) { return ngx_http_autoindex_error(r, &dir, dname.data); } + ngx_cpystrn(entry->name.data, ngx_de_name(&dir), len + 1); entry->dir = ngx_de_is_dir(&dir); @@ -298,7 +302,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) for (i = 0; i < entries.nelts; i++) { len += sizeof("<a href=\"") - 1 + 1 /* 1 is for "/" */ - + entry[i].name.len + + entry[i].name.len + entry[i].escape + sizeof("\">") - 1 + NGX_HTTP_AUTOINDEX_NAME_LEN + sizeof("</a>") - 1 @@ -329,7 +333,17 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) for (i = 0; i < entries.nelts; i++) { b->last = ngx_cpymem(b->last, "<a href=\"", sizeof("<a href=\"") - 1); - b->last = ngx_cpymem(b->last, entry[i].name.data, entry[i].name.len); + + if (entry[i].escape) { + ngx_escape_uri(b->last, entry[i].name.data, entry[i].name.len, + NGX_ESCAPE_HTML); + + b->last += entry[i].name.len + entry[i].escape; + + } else { + b->last = ngx_cpymem(b->last, entry[i].name.data, + entry[i].name.len); + } if (entry[i].dir) { *b->last++ = '/'; @@ -375,7 +389,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) } else { length = entry[i].size; - if (length > 1024 * 1024 * 1024) { + if (length > 1024 * 1024 * 1024 - 1) { size = (ngx_int_t) (length / (1024 * 1024 * 1024)); if ((length % (1024 * 1024 * 1024)) > (1024 * 1024 * 1024 / 2 - 1)) @@ -384,7 +398,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) } scale = 'G'; - } else if (length > 1024 * 1024) { + } else if (length > 1024 * 1024 - 1) { size = (ngx_int_t) (length / (1024 * 1024)); if ((length % (1024 * 1024)) > (1024 * 1024 / 2 - 1)) { size++; diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c index f2e85e530..cf9d3d2be 100644 --- a/src/http/modules/ngx_http_charset_filter.c +++ b/src/http/modules/ngx_http_charset_filter.c @@ -125,7 +125,7 @@ ngx_module_t ngx_http_charset_filter_module = { ngx_http_charset_filter_commands, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_charset_filter_init, /* init module */ - NULL /* init child */ + NULL /* init process */ }; @@ -287,8 +287,7 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, if (src == dst) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "\"charset_map\" between the same charsets " - "\"%s\" and \"%s\"", - value[1].data, value[2].data); + "\"%V\" and \"%V\"", &value[1], &value[2]); return NGX_CONF_ERROR; } @@ -299,8 +298,7 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "duplicate \"charset_map\" between " - "\"%s\" and \"%s\"", - value[1].data, value[2].data); + "\"%V\" and \"%V\"", &value[1], &value[2]); return NGX_CONF_ERROR; } } @@ -357,14 +355,14 @@ static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) src = ngx_hextoi(value[0].data, value[0].len); if (src == NGX_ERROR || src > 255) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[0].data); + "invalid value \"%V\"", &value[0]); return NGX_CONF_ERROR; } dst = ngx_hextoi(value[1].data, value[1].len); if (dst == NGX_ERROR || dst > 255) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[1].data); + "invalid value \"%V\"", &value[1]); return NGX_CONF_ERROR; } @@ -525,8 +523,8 @@ static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf) ngx_log_error(NGX_LOG_EMERG, cf->log, 0, " no \"charset_map\" between the charsets " - "\"%s\" and \"%s\"", - charset[i].name.data, charset[n].name.data); + "\"%V\" and \"%V\"", + &charset[i].name, &charset[n].name); return NGX_CONF_ERROR; } } diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c index 7881248cc..929a7ed2c 100644 --- a/src/http/modules/ngx_http_chunked_filter.c +++ b/src/http/modules/ngx_http_chunked_filter.c @@ -32,7 +32,7 @@ ngx_module_t ngx_http_chunked_filter_module = { NULL, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_chunked_filter_init, /* init module */ - NULL /* init child */ + NULL /* init process */ }; @@ -84,7 +84,11 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r, size += ngx_buf_size(cl->buf); if (cl->buf->flush || ngx_buf_in_memory(cl->buf) || cl->buf->in_file) { - ngx_test_null(tl, ngx_alloc_chain_link(r->pool), NGX_ERROR); + + if (!(tl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + tl->buf = cl->buf; *ll = tl; ll = &tl->next; @@ -102,30 +106,22 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r, return NGX_ERROR; } - if (!(chunk = ngx_palloc(r->pool, 11))) { + if (!(chunk = ngx_palloc(r->pool, sizeof("00000000" CRLF) - 1))) { return NGX_ERROR; } b->temporary = 1; b->pos = chunk; - b->last = ngx_sprintf(chunk, "%uxS" CRLF, size); - - out.buf = b; -#if 0 - ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR); - len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size); - - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); - b->temporary = 1; - b->pos = chunk; - b->last = chunk + len; + b->last = ngx_sprintf(chunk, "%xz" CRLF, size); out.buf = b; -#endif } if (cl->buf->last_buf) { - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->memory = 1; b->last_buf = 1; b->pos = (u_char *) CRLF "0" CRLF CRLF; @@ -147,7 +143,10 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r, return ngx_http_next_body_filter(r, out.next); } - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->memory = 1; b->pos = (u_char *) CRLF; b->last = b->pos + 2; diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index bb3a1f0c6..f8980af52 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -80,7 +80,7 @@ static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size); 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 int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, uintptr_t data); @@ -507,7 +507,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, b->pos = gzheader; b->last = b->pos + 10; - ngx_alloc_link_and_set_buf(cl, b, r->pool, ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = b; + cl->next = NULL; ctx->out = cl; ctx->last_out = &cl->next; @@ -534,7 +538,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, && !ctx->redo) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "gzip in: " PTR_FMT, ctx->in); + "gzip in: %p", ctx->in); if (ctx->in == NULL) { break; @@ -547,7 +551,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos; ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "gzip in_buf:" PTR_FMT " ni:" PTR_FMT " ai:%d", + "gzip in_buf:%p ni:%p ai:%ud", ctx->in_buf, ctx->zstream.next_in, ctx->zstream.avail_in); @@ -608,10 +612,10 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, } ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "deflate in: ni:%X no:%X ai:%d ao:%d fl:%d redo:%d", - ctx->zstream.next_in, ctx->zstream.next_out, - ctx->zstream.avail_in, ctx->zstream.avail_out, - ctx->flush, ctx->redo); + "deflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d", + ctx->zstream.next_in, ctx->zstream.next_out, + ctx->zstream.avail_in, ctx->zstream.avail_out, + ctx->flush, ctx->redo); rc = deflate(&ctx->zstream, ctx->flush); @@ -622,13 +626,13 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, } ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "deflate out: ni:%X no:%X ai:%d ao:%d rc:%d", + "deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d", ctx->zstream.next_in, ctx->zstream.next_out, ctx->zstream.avail_in, ctx->zstream.avail_out, rc); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "gzip in_buf:" PTR_FMT " pos:" PTR_FMT, + "gzip in_buf:%p pos:%p", ctx->in_buf, ctx->in_buf->pos); @@ -646,8 +650,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, /* zlib wants to output some more gzipped data */ - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -663,8 +670,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, ctx->out_buf->flush = 0; ctx->flush = Z_NO_FLUSH; - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -686,8 +696,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_pfree(r->pool, ctx->preallocated); - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -703,8 +716,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, b->last_buf = 1; - ngx_alloc_link_and_set_buf(cl, b, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = b; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; trailer = (struct gztrailer *) b->pos; @@ -735,8 +751,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, } if (conf->no_buffer && ctx->in == NULL) { - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -782,10 +801,12 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size) ngx_uint_t alloc; alloc = items * size; + if (alloc % 512 != 0) { /* - * the zlib deflate_state allocation, it takes about 6K, we allocate 8K + * The zlib deflate_state allocation, it takes about 6K, + * we allocate 8K. Other allocations are divisible by 512. */ alloc = (alloc + ngx_pagesize - 1) & ~(ngx_pagesize - 1); @@ -797,14 +818,14 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size) ctx->allocated -= alloc; ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, - "gzip alloc: n:%d s:%d a:%d p:" PTR_FMT, + "gzip alloc: n:%ud s:%ud a:%ud p:%p", items, size, alloc, p); return p; } ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0, - "gzip filter failed to use preallocated memory: %d of %d", + "gzip filter failed to use preallocated memory: %ud of %ud", items * size, ctx->allocated); p = ngx_palloc(ctx->request->pool, items * size); @@ -819,7 +840,7 @@ static void ngx_http_gzip_filter_free(void *opaque, void *address) ngx_http_gzip_ctx_t *ctx = opaque; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, - "gzip free: %X", address); + "gzip free: %p", address); #endif } @@ -837,8 +858,6 @@ static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, return buf + 1; } - /* we prefer do not use the FPU */ - zint = (ngx_uint_t) (ctx->zin / ctx->zout); zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100); @@ -855,16 +874,10 @@ static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, } return ngx_sprintf(buf, "%ui.%02ui", zint, zfrac); - -#if 0 - return buf + ngx_snprintf((char *) buf, NGX_INT32_LEN + 4, - "%" NGX_UINT_T_FMT ".%02" NGX_UINT_T_FMT, - zint, zfrac); -#endif } -ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) +static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) { deflateEnd(&ctx->zstream); diff --git a/src/http/modules/ngx_http_headers_filter.c b/src/http/modules/ngx_http_headers_filter.c index faf81920a..e86f6ae63 100644 --- a/src/http/modules/ngx_http_headers_filter.c +++ b/src/http/modules/ngx_http_headers_filter.c @@ -138,12 +138,6 @@ static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r) conf->expires) - cc->value.data; -#if 0 - cc->value.len = ngx_snprintf((char *) cc->value.data, - sizeof("max-age=") + TIME_T_LEN, - "max-age=" TIME_T_FMT, - conf->expires); -#endif } } } diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c index 60b6c0185..013f62b46 100644 --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -143,7 +143,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) &r->uri, &crc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http index cache get: " PTR_FMT, ctx->cache); + "http index cache get: %p", ctx->cache); if (ctx->cache && !ctx->cache->expired) { @@ -251,7 +251,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) err = ngx_errno; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, err, - ngx_open_file_n " %s failed", name); + ngx_open_file_n " \"%s\" failed", name); if (err == NGX_ENOTDIR) { return ngx_http_index_error(r, ctx, err); @@ -275,7 +275,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) } ngx_log_error(NGX_LOG_ERR, log, err, - ngx_open_file_n " %s failed", name); + ngx_open_file_n " \"%s\" failed", name); return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -331,7 +331,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) ctx->redirect.len--; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http index cache alloc: " PTR_FMT, ctx->cache); + "http index cache alloc: %p", ctx->cache); if (ctx->cache) { ctx->cache->fd = NGX_INVALID_FILE; @@ -373,7 +373,7 @@ static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r, } ngx_log_error(NGX_LOG_CRIT, r->connection->log, err, - ngx_file_info_n " %s failed", ctx->path.data); + ngx_file_info_n " \"%s\" failed", ctx->path.data); return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -502,17 +502,17 @@ static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, if (value[1].data[0] == '/' && ilcf->indices.nelts == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "first index \"%s\" in \"%s\" directive " + "first index \"%V\" in \"%V\" directive " "must not be absolute", - value[1].data, cmd->name.data); + &value[1], &cmd->name); return NGX_CONF_ERROR; } for (i = 1; i < cf->args->nelts; i++) { if (value[i].len == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "index \"%s\" in \"%s\" directive is invalid", - value[1].data, cmd->name.data); + "index \"%V\" in \"%V\" directive is invalid", + &value[1], &cmd->name); return NGX_CONF_ERROR; } diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter.c index 04d1fde6b..24ea58d90 100644 --- a/src/http/modules/ngx_http_not_modified_filter.c +++ b/src/http/modules/ngx_http_not_modified_filter.c @@ -33,7 +33,7 @@ ngx_module_t ngx_http_not_modified_filter_module = { NULL, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_not_modified_filter_init, /* init module */ - NULL /* init child */ + NULL /* init process */ }; diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c index 082fd3c4a..f96456cef 100644 --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -107,11 +107,13 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter; static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) { - ngx_int_t rc; - ngx_uint_t boundary, suffix, i; u_char *p; size_t len; off_t start, end; + ngx_int_t rc; + uint32_t boundary; + ngx_uint_t suffix, i; + ngx_table_elt_t *content_range; ngx_http_range_t *range; ngx_http_range_filter_ctx_t *ctx; @@ -141,8 +143,11 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) return ngx_http_next_header_filter(r); } - ngx_init_array(r->headers_out.ranges, r->pool, 5, sizeof(ngx_http_range_t), - NGX_ERROR); + if (ngx_array_init(&r->headers_out.ranges, r->pool, 5, + sizeof(ngx_http_range_t)) == NGX_ERROR) + { + return NGX_ERROR; + } rc = 0; range = NULL; @@ -180,8 +185,10 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) while (*p == ' ') { p++; } if (*p == ',' || *p == '\0') { - ngx_test_null(range, ngx_push_array(&r->headers_out.ranges), - NGX_ERROR); + if (!(range = ngx_array_push(&r->headers_out.ranges))) { + return NGX_ERROR; + } + range->start = start; range->end = r->headers_out.content_length_n; @@ -223,7 +230,10 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) break; } - ngx_test_null(range, ngx_push_array(&r->headers_out.ranges), NGX_ERROR); + if (!(range = ngx_array_push(&r->headers_out.ranges))) { + return NGX_ERROR; + } + range->start = start; if (end >= r->headers_out.content_length_n) { @@ -249,29 +259,26 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) r->headers_out.status = rc; r->headers_out.ranges.nelts = 0; - r->headers_out.content_range = ngx_list_push(&r->headers_out.headers); - if (r->headers_out.content_range == NULL) { + if (!(content_range = ngx_list_push(&r->headers_out.headers))) { return NGX_ERROR; } - r->headers_out.content_range->key.len = sizeof("Content-Range") - 1; - r->headers_out.content_range->key.data = (u_char *) "Content-Range"; + r->headers_out.content_range = content_range; - r->headers_out.content_range->value.data = - ngx_palloc(r->pool, 8 + 20 + 1); - if (r->headers_out.content_range->value.data == NULL) { + content_range->key.len = sizeof("Content-Range") - 1; + content_range->key.data = (u_char *) "Content-Range"; + + content_range->value.data = + ngx_palloc(r->pool, sizeof("bytes */") - 1 + NGX_OFF_T_LEN); + + if (content_range->value.data == NULL) { return NGX_ERROR; } - r->headers_out.content_range->value.len = - ngx_sprintf(r->headers_out.content_range->value.data, - "bytes */%O", r->headers_out.content_length_n) - - r->headers_out.content_range->value.data; -#if 0 - ngx_snprintf((char *) r->headers_out.content_range->value.data, - 8 + 20 + 1, "bytes */" OFF_T_FMT, - r->headers_out.content_length_n); -#endif + content_range->value.len = ngx_sprintf(content_range->value.data, + "bytes */%O", + r->headers_out.content_length_n) + - content_range->value.data; r->headers_out.content_length_n = -1; if (r->headers_out.content_length) { @@ -280,177 +287,135 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) } return rc; + } - } else { - r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; + r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; - if (r->headers_out.ranges.nelts == 1) { + if (r->headers_out.ranges.nelts == 1) { - r->headers_out.content_range = - ngx_list_push(&r->headers_out.headers); - if (r->headers_out.content_range == NULL) { - return NGX_ERROR; - } + if (!(content_range = ngx_list_push(&r->headers_out.headers))) { + return NGX_ERROR; + } - r->headers_out.content_range->key.len = sizeof("Content-Range") - 1; - r->headers_out.content_range->key.data = (u_char *) "Content-Range"; + r->headers_out.content_range = content_range; - ngx_test_null(r->headers_out.content_range->value.data, - ngx_palloc(r->pool, 6 + 20 + 1 + 20 + 1 + 20 + 1), - NGX_ERROR); + content_range->key.len = sizeof("Content-Range") - 1; + content_range->key.data = (u_char *) "Content-Range"; - /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ + content_range->value.data = + ngx_palloc(r->pool, sizeof("bytes -/") - 1 + 3 * NGX_OFF_T_LEN); + if (content_range->value.data == NULL) { + return NGX_ERROR; + } - r->headers_out.content_range->value.len = - ngx_sprintf(r->headers_out.content_range->value.data, - "bytes %O-%O/%O", - range->start, range->end - 1, - r->headers_out.content_length_n) - - r->headers_out.content_range->value.data; + /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ -#if 0 - ngx_snprintf((char *) - r->headers_out.content_range->value.data, - 6 + 20 + 1 + 20 + 1 + 20 + 1, - "bytes " OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT, - range->start, range->end - 1, - r->headers_out.content_length_n); -#endif + content_range->value.len = ngx_sprintf(content_range->value.data, + "bytes %O-%O/%O", + range->start, range->end - 1, + r->headers_out.content_length_n) + - content_range->value.data; - r->headers_out.content_length_n = range->end - range->start; + r->headers_out.content_length_n = range->end - range->start; - } else { + return ngx_http_next_header_filter(r); + } -#if 0 - /* TODO: what if no content_type ?? */ - if (!(r->headers_out.content_type = - ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) - { - return NGX_ERROR; - } -#endif + /* TODO: what if no content_type ?? */ - ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module, - sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR); + ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module, + sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR); - len = 4 + 10 + 2 + 14 + r->headers_out.content_type->value.len - + 2 + 21 + 1; - if (r->headers_out.charset.len) { - len += 10 + r->headers_out.charset.len; - } + len = sizeof(CRLF "--0123456789" CRLF "Content-Type: ") - 1 + + r->headers_out.content_type->value.len + + sizeof(CRLF "Content-Range: bytes ") - 1; - ngx_test_null(ctx->boundary_header.data, ngx_palloc(r->pool, len), - NGX_ERROR); + if (r->headers_out.charset.len) { + len += sizeof("; charset=") - 1 + r->headers_out.charset.len; + } - boundary = ngx_next_temp_number(0); + if (!(ctx->boundary_header.data = ngx_palloc(r->pool, len))) { + return NGX_ERROR; + } - /* - * The boundary header of the range: - * CRLF - * "--0123456789" CRLF - * "Content-Type: image/jpeg" CRLF - * "Content-Range: bytes " - */ + boundary = ngx_next_temp_number(0); - if (r->headers_out.charset.len) { - ctx->boundary_header.len = - ngx_sprintf(ctx->boundary_header.data, - CRLF "--%010ui" CRLF - "Content-Type: %s; charset=%s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data, - r->headers_out.charset.data) - - ctx->boundary_header.data; -#if 0 - ngx_snprintf((char *) ctx->boundary_header.data, len, - CRLF "--%010" NGX_UINT_T_FMT CRLF - "Content-Type: %s; charset=%s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data, - r->headers_out.charset.data); -#endif - - r->headers_out.charset.len = 0; - - } else { - ctx->boundary_header.len = - ngx_sprintf(ctx->boundary_header.data, - CRLF "--%010ui" CRLF - "Content-Type: %s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data) - - ctx->boundary_header.data; - -#if 0 - ngx_snprintf((char *) ctx->boundary_header.data, len, - CRLF "--%010" NGX_UINT_T_FMT CRLF - "Content-Type: %s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data); - -#endif - } + /* + * The boundary header of the range: + * CRLF + * "--0123456789" CRLF + * "Content-Type: image/jpeg" CRLF + * "Content-Range: bytes " + */ - ngx_test_null(r->headers_out.content_type->value.data, - ngx_palloc(r->pool, 31 + 10 + 1), - NGX_ERROR); - - /* "Content-Type: multipart/byteranges; boundary=0123456789" */ - - r->headers_out.content_type->value.len = - ngx_sprintf(r->headers_out.content_type->value.data, - "multipart/byteranges; boundary=%010ui", - boundary) - - r->headers_out.content_type->value.data; -#if 0 - ngx_snprintf((char *) - r->headers_out.content_type->value.data, - 31 + 10 + 1, - "multipart/byteranges; boundary=%010" - NGX_UINT_T_FMT, - boundary); -#endif - - /* the size of the last boundary CRLF "--0123456789--" CRLF */ - len = 4 + 10 + 4; - - range = r->headers_out.ranges.elts; - for (i = 0; i < r->headers_out.ranges.nelts; i++) { - ngx_test_null(range[i].content_range.data, - ngx_palloc(r->pool, 20 + 1 + 20 + 1 + 20 + 5), - NGX_ERROR); - - /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ - - range[i].content_range.len = - ngx_sprintf(range[i].content_range.data, - "%O-%O/%O" CRLF CRLF, - range[i].start, range[i].end - 1, - r->headers_out.content_length_n) - - range[i].content_range.data; -#if 0 - ngx_snprintf((char *) range[i].content_range.data, - 20 + 1 + 20 + 1 + 20 + 5, - OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT CRLF CRLF, - range[i].start, range[i].end - 1, - r->headers_out.content_length_n); -#endif - - len += ctx->boundary_header.len + range[i].content_range.len - + (size_t) (range[i].end - range[i].start); - } + if (r->headers_out.charset.len) { + ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, + CRLF "--%010ud" CRLF + "Content-Type: %V; charset=%V" CRLF + "Content-Range: bytes ", + boundary, + &r->headers_out.content_type->value, + &r->headers_out.charset) + - ctx->boundary_header.data; - r->headers_out.content_length_n = len; - r->headers_out.content_length = NULL; + r->headers_out.charset.len = 0; + + } else { + ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, + CRLF "--%010ud" CRLF + "Content-Type: %V" CRLF + "Content-Range: bytes ", + boundary, + &r->headers_out.content_type->value) + - ctx->boundary_header.data; + } + + r->headers_out.content_type->value.data = + ngx_palloc(r->pool, sizeof("Content-Type: multipart/byteranges; " + "boundary=0123456789") - 1); + + if (r->headers_out.content_type->value.data == NULL) { + return NGX_ERROR; + } + + /* "Content-Type: multipart/byteranges; boundary=0123456789" */ + + r->headers_out.content_type->value.len = + ngx_sprintf(r->headers_out.content_type->value.data, + "multipart/byteranges; boundary=%010ud", + boundary) + - r->headers_out.content_type->value.data; + + /* the size of the last boundary CRLF "--0123456789--" CRLF */ + len = sizeof(CRLF "--0123456789--" CRLF) - 1; + + range = r->headers_out.ranges.elts; + for (i = 0; i < r->headers_out.ranges.nelts; i++) { + + /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ + + range[i].content_range.data = + ngx_palloc(r->pool, 3 * NGX_OFF_T_LEN + 2 + 4); + + if (range[i].content_range.data == NULL) { + return NGX_ERROR; } + + range[i].content_range.len = ngx_sprintf(range[i].content_range.data, + "%O-%O/%O" CRLF CRLF, + range[i].start, range[i].end - 1, + r->headers_out.content_length_n) + - range[i].content_range.data; + + len += ctx->boundary_header.len + range[i].content_range.len + + (size_t) (range[i].end - range[i].start); } + r->headers_out.content_length_n = len; + r->headers_out.content_length = NULL; + return ngx_http_next_header_filter(r); } @@ -496,33 +461,54 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, * "Content-Range: bytes " */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->memory = 1; b->pos = ctx->boundary_header.data; b->last = ctx->boundary_header.data + ctx->boundary_header.len; - ngx_test_null(hcl, ngx_alloc_chain_link(r->pool), NGX_ERROR); + if (!(hcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + hcl->buf = b; + /* "SSSS-EEEE/TTTT" CRLF CRLF */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->temporary = 1; b->pos = range[i].content_range.data; b->last = range[i].content_range.data + range[i].content_range.len; - ngx_test_null(rcl, ngx_alloc_chain_link(r->pool), NGX_ERROR); + if (!(rcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + rcl->buf = b; + /* the range data */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->in_file = 1; b->file_pos = range[i].start; b->file_last = range[i].end; b->file = in->buf->file; - ngx_alloc_link_and_set_buf(dcl, b, r->pool, NGX_ERROR); + if (!(dcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + + dcl->buf = b; *ll = hcl; hcl->next = rcl; @@ -532,15 +518,29 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, /* the last boundary CRLF "--0123456789--" CRLF */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->temporary = 1; b->last_buf = 1; - ngx_test_null(b->pos, ngx_palloc(r->pool, 4 + 10 + 4), NGX_ERROR); + + b->pos = ngx_palloc(r->pool, sizeof(CRLF "--0123456789--" CRLF) - 1); + if (b->pos == NULL) { + return NGX_ERROR; + } + b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, 4 + 10); *b->last++ = '-'; *b->last++ = '-'; *b->last++ = CR; *b->last++ = LF; - ngx_alloc_link_and_set_buf(hcl, b, r->pool, NGX_ERROR); + if (!(hcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + + hcl->buf = b; + hcl->next = NULL; + *ll = hcl; return ngx_http_next_body_filter(r, out); diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_handler.c index aa3a65648..0973ef087 100644 --- a/src/http/modules/ngx_http_rewrite_handler.c +++ b/src/http/modules/ngx_http_rewrite_handler.c @@ -146,8 +146,8 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) if (rc == NGX_DECLINED) { if (scf->log) { ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, - "\"%s\" does not match \"%s\"", - rule[i].re_name.data, r->uri.data); + "\"%V\" does not match \"%V\"", + &rule[i].re_name, &r->uri); } continue; @@ -156,15 +156,15 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) if (rc < 0) { ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, ngx_regex_exec_n - " failed: %d on \"%s\" using \"%s\"", - rc, r->uri.data, rule[i].re_name.data); + " failed: %d on \"%V\" using \"%V\"", + rc, &r->uri, &rule[i].re_name); return NGX_HTTP_INTERNAL_SERVER_ERROR; } if (scf->log) { ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, - "\"%s\" matches \"%s\"", - rule[i].re_name.data, r->uri.data); + "\"%V\" matches \"%V\"", + &rule[i].re_name, &r->uri); } if (rule[i].status) { @@ -177,7 +177,7 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) uri.len += matches[2 * n + 1] - matches[2 * n]; } - if (!(uri.data = ngx_palloc(r->pool, uri.len + 1))) { + if (!(uri.data = ngx_palloc(r->pool, uri.len))) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -203,11 +203,9 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) } } - *p = '\0'; - if (scf->log) { ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, - "rewritten uri: \"%s\"", uri.data); + "rewritten uri: \"%V\"", &uri); } r->uri = uri; @@ -353,7 +351,7 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd, } ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid parameter \"%s\"", value[3].data); + "invalid parameter \"%V\"", &value[3]); return NGX_CONF_ERROR; } @@ -427,7 +425,7 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd, } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid parameter \"%s\"", value[3].data); + "invalid parameter \"%V\"", &value[3]); return NGX_CONF_ERROR; } } diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c index c4ffde3b2..12cf5b39d 100644 --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -197,7 +197,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) &name, &file_crc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http open file cache get: " PTR_FMT, file); + "http open file cache get: %p", file); if (file && !file->expired) { r->cache = file; @@ -216,7 +216,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) &name, &redirect_crc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http redirect cache get: " PTR_FMT, redirect); + "http redirect cache get: %p", redirect); if (redirect && !redirect->expired) { @@ -247,7 +247,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) /* open file */ -#if (WIN9X) +#if (NGX_WIN9X) /* TODO: redirect cache */ @@ -276,7 +276,8 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) } if (ngx_is_dir(&fi)) { - ngx_log_debug(log, "HTTP DIR: '%s'" _ name.data); + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, + "HTTP DIR: \"%s\"", name.data); if (!(r->headers_out.location = ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) @@ -384,7 +385,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) location.len--; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http redirect cache alloc: " PTR_FMT, redirect); + "http redirect cache alloc: %p", redirect); if (redirect) { redirect->fd = NGX_INVALID_FILE; @@ -403,11 +404,11 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) return NGX_HTTP_MOVED_PERMANENTLY; } -#if !(WIN32) /* the not regular files are probably Unix specific */ +#if !(NGX_WIN32) /* the not regular files are probably Unix specific */ if (!ngx_is_file(&fi)) { ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, - "%s is not a regular file", name.data); + "\"%s\" is not a regular file", name.data); if (ngx_close_file(fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, @@ -459,7 +460,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) #endif ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http open file cache alloc: " PTR_FMT, file); + "http open file cache alloc: %p", file); if (file) { file->fd = fd; diff --git a/src/http/modules/ngx_http_status_handler.c b/src/http/modules/ngx_http_status_handler.c index 357affff4..ce49ae426 100644 --- a/src/http/modules/ngx_http_status_handler.c +++ b/src/http/modules/ngx_http_status_handler.c @@ -171,10 +171,7 @@ static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx) return NGX_ERROR; } - b->last += ngx_snprintf((char *) b->last, - /* STUB: should be NGX_PID_T_LEN */ - NGX_INT64_LEN + NGX_INT32_LEN, - PID_T_FMT " %4u", ngx_pid, i); + b->last = ngx_sprintf(b->last, "%P %5ui", ngx_pid, i); switch (r->http_state) { case NGX_HTTP_INITING_REQUEST_STATE: @@ -250,10 +247,7 @@ static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx) return NGX_ERROR; } - b->last += ngx_snprintf((char *) b->last, - /* STUB: should be NGX_PID_T_LEN */ - NGX_INT64_LEN + NGX_INT32_LEN, - PID_T_FMT " %4u", ngx_pid, i); + b->last = ngx_sprintf(b->last, "%P %5ui", ngx_pid, i); *(b->last++) = ' '; *(b->last++) = 's'; diff --git a/src/http/modules/ngx_http_userid_filter.c b/src/http/modules/ngx_http_userid_filter.c index bafdea884..2385ceed2 100644 --- a/src/http/modules/ngx_http_userid_filter.c +++ b/src/http/modules/ngx_http_userid_filter.c @@ -27,15 +27,13 @@ typedef struct { ngx_str_t domain; ngx_str_t path; time_t expires; - - ngx_int_t p3p; - ngx_str_t p3p_string; + ngx_str_t p3p; } ngx_http_userid_conf_t; typedef struct { - uint32_t uid_got[4]; - uint32_t uid_set[4]; + uint32_t uid_got[4]; + uint32_t uid_set[4]; } ngx_http_userid_ctx_t; @@ -56,8 +54,10 @@ static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf); static void *ngx_http_userid_create_conf(ngx_conf_t *cf); static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, void *child); -char *ngx_conf_check_domain(ngx_conf_t *cf, void *post, void *data); +char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); +char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data); char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data); static uint32_t sequencer_v1 = 1; @@ -79,8 +79,11 @@ static ngx_conf_enum_t ngx_http_userid_state[] = { }; -static ngx_conf_post_handler_pt ngx_conf_check_domain_p = - ngx_conf_check_domain; +static ngx_conf_post_handler_pt ngx_http_userid_domain_p = + ngx_http_userid_domain; + +static ngx_conf_post_handler_pt ngx_http_userid_path_p = ngx_http_userid_path; +static ngx_conf_post_handler_pt ngx_http_userid_p3p_p = ngx_http_userid_p3p; static ngx_command_t ngx_http_userid_commands[] = { @@ -111,14 +114,14 @@ static ngx_command_t ngx_http_userid_commands[] = { ngx_conf_set_str_slot, NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_userid_conf_t, domain), - &ngx_conf_check_domain_p }, + &ngx_http_userid_domain_p }, { ngx_string("userid_path"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_str_slot, NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_userid_conf_t, path), - NULL }, + &ngx_http_userid_path_p }, { ngx_string("userid_expires"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, @@ -127,6 +130,13 @@ static ngx_command_t ngx_http_userid_commands[] = { 0, NULL }, + { ngx_string("userid_p3p"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_str_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_userid_conf_t, p3p), + &ngx_http_userid_p3p_p }, + ngx_null_command }; @@ -210,40 +220,44 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, for (i = 0; i < r->headers_in.cookies.nelts; i++) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "cookie: \"%s\"", cookies[i]->value.data); + "cookie: \"%V\"", &cookies[i]->value); + if (conf->name.len >= cookies[i]->value.len) { + continue; + } + + start = cookies[i]->value.data; end = cookies[i]->value.data + cookies[i]->value.len; - for (start = cookies[i]->value.data; start < end; /* void */) { + while (start < end) { - if (conf->name.len >= cookies[i]->value.len - || ngx_strncmp(start, conf->name.data, conf->name.len) != 0) - { - start += conf->name.len; - while (start < end && *start++ != ';') { /* void */ } + if (ngx_strncmp(start, conf->name.data, conf->name.len) != 0) { - for (/* void */; start < end && *start == ' '; start++) { /**/ } + while (start < end && *start++ != ';') { /* void */ } + while (start < end && *start == ' ') { start++; } continue; } - for (start += conf->name.len; start < end && *start == ' '; start++) - { - /* void */ - } + start += conf->name.len; - if (*start != '=') { + while (start < end && *start == ' ') { start++; } + + if (start == end || *start++ != '=') { + /* the invalid "Cookie" header */ break; } - for (start++; start < end && *start == ' '; start++) { /* void */ } + while (start < end && *start == ' ') { start++; } + + last = start; - for (last = start; last < end && *last != ';'; last++) { /**/ } + while (last < end && *last++ != ';') { /* void */ } if (last - start < 22) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "client sent too short userid cookie \"%s\"", - cookies[i]->value.data); + "client sent too short userid cookie \"%V\"", + &cookies[i]->value); break; } @@ -259,13 +273,13 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, if (ngx_decode_base64(&dst, &src) == NGX_ERROR) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "client sent invalid userid cookie \"%s\"", - cookies[i]->value.data); + "client sent invalid userid cookie \"%V\"", + &cookies[i]->value); break; } ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "uid: %08X%08X%08X%08X", + "uid: %08XD%08XD%08XD%08XD", ctx->uid_got[0], ctx->uid_got[1], ctx->uid_got[2], ctx->uid_got[3]); @@ -280,14 +294,13 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf) - { u_char *cookie, *p; size_t len; socklen_t slen; struct sockaddr_in addr_in; ngx_str_t src, dst; - ngx_table_elt_t *set_cookie; + ngx_table_elt_t *set_cookie, *p3p; /* TODO: mutex for sequencers */ @@ -333,18 +346,14 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, } } - len = conf->name.len + 1 + ngx_base64_encoded_length(16) + 1; + len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len; if (conf->expires) { len += sizeof(expires) - 1 + 2; } if (conf->domain.len > 1) { - len += sizeof("; domain=") - 1 + conf->domain.len; - } - - if (conf->path.len) { - len += sizeof("; path=") - 1 + conf->path.len; + len += conf->domain.len; } if (!(cookie = ngx_palloc(r->pool, len))) { @@ -371,19 +380,10 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, } if (conf->domain.len > 1) { - p = ngx_cpymem(p, "; domain=", sizeof("; domain=") - 1); p = ngx_cpymem(p, conf->domain.data, conf->domain.len); } - if (conf->path.len) { - p = ngx_cpymem(p, "; path=", sizeof("; path=") - 1); - p = ngx_cpymem(p, conf->path.data, conf->path.len); - } - - *p = '\0'; - - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "uid cookie: \"%s\"", cookie); + p = ngx_cpymem(p, conf->path.data, conf->path.len); if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) { return NGX_ERROR; @@ -394,6 +394,21 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, set_cookie->value.len = p - cookie; set_cookie->value.data = cookie; + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "uid cookie: \"%V\"", &set_cookie->value); + + if (conf->p3p.len == 1) { + return NGX_OK; + } + + if (!(p3p = ngx_list_push(&r->headers_out.headers))) { + return NGX_ERROR; + } + + p3p->key.len = sizeof("P3P") - 1; + p3p->key.data = (u_char *) "P3P"; + p3p->value = conf->p3p; + return NGX_OK; } @@ -425,9 +440,9 @@ static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, *buf++ = '='; - return buf + ngx_snprintf((char *) buf, 33, "%08X%08X%08X%08X", - ctx->uid_got[0], ctx->uid_got[1], - ctx->uid_got[2], ctx->uid_got[3]); + return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", + ctx->uid_got[0], ctx->uid_got[1], + ctx->uid_got[2], ctx->uid_got[3]); } @@ -458,9 +473,9 @@ static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, *buf++ = '='; - return buf + ngx_snprintf((char *) buf, 33, "%08X%08X%08X%08X", - ctx->uid_set[0], ctx->uid_set[1], - ctx->uid_set[2], ctx->uid_set[3]); + return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", + ctx->uid_set[0], ctx->uid_set[1], + ctx->uid_set[2], ctx->uid_set[3]); } @@ -510,6 +525,8 @@ static void *ngx_http_userid_create_conf(ngx_conf_t *cf) conf->domain.date = NULL; conf->path.len = 0; conf->path.date = NULL; + conf->p3p.len = 0; + conf->p3p.date = NULL; */ @@ -531,7 +548,8 @@ static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, ngx_conf_merge_str_value(conf->name, prev->name, "uid"); ngx_conf_merge_str_value(conf->domain, prev->domain, "."); - ngx_conf_merge_str_value(conf->path, prev->path, "/"); + ngx_conf_merge_str_value(conf->path, prev->path, "; path=/"); + ngx_conf_merge_str_value(conf->p3p, prev->p3p, "."); ngx_conf_merge_value(conf->service, prev->service, NGX_CONF_UNSET); ngx_conf_merge_sec_value(conf->expires, prev->expires, 0); @@ -540,15 +558,49 @@ static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, } -char *ngx_conf_check_domain(ngx_conf_t *cf, void *post, void *data) +char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data) { ngx_str_t *domain = data; + u_char *p, *new; + if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) { domain->len = 1; domain->data = (u_char *) "."; + + return NGX_CONF_OK; + } + + if (!(new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len))) { + return NGX_CONF_ERROR; + } + + p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1); + p = ngx_cpymem(p, domain->data, domain->len); + + domain->len += sizeof("; domain=") - 1; + domain->data = new; + + return NGX_CONF_OK; +} + + +char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data) +{ + ngx_str_t *path = data; + + u_char *p, *new; + + if (!(new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len))) { + return NGX_CONF_ERROR; } + p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1); + p = ngx_cpymem(p, path->data, path->len); + + path->len += sizeof("; path=") - 1; + path->data = new; + return NGX_CONF_OK; } @@ -586,3 +638,16 @@ char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_OK; } + + +char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data) +{ + ngx_str_t *p3p = data; + + if (p3p->len == 4 && ngx_strcmp(p3p->data, "none") == 0) { + p3p->len = 1; + p3p->data = (u_char *) "."; + } + + return NGX_CONF_OK; +} diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c index 0a2a20025..f0b56f548 100644 --- a/src/http/modules/proxy/ngx_http_proxy_cache.c +++ b/src/http/modules/proxy/ngx_http_proxy_cache.c @@ -173,8 +173,8 @@ static int ngx_http_proxy_process_cached_header(ngx_http_proxy_ctx_t *p) ngx_cpystrn(c->status_line.data, p->status_start, c->status_line.len + 1); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http cache status %d \"%s\"", - c->status, c->status_line.data); + "http cache status %ui \"%V\"", + c->status, &c->status_line); /* TODO: ngx_init_table */ c->headers_in.headers = ngx_create_table(r->pool, 20); @@ -219,8 +219,7 @@ static int ngx_http_proxy_process_cached_header(ngx_http_proxy_ctx_t *p) } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http cache header: \"%s: %s\"", - h->key.data, h->value.data); + "http cache header: \"%V: %V\"", &h->key, &h->value); continue; @@ -614,7 +613,7 @@ int ngx_http_proxy_update_cache(ngx_http_proxy_ctx_t *p) ep = p->upstream->event_pipe; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, - "http cache update len: " OFF_T_FMT ":" OFF_T_FMT, + "http cache update len: %O:%O", p->cache->ctx.length, ep->read_length); if (p->cache->ctx.length == -1) { diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index 64f7c0794..915d378e6 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -710,26 +710,75 @@ void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p) } -size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len) +u_char *ngx_http_proxy_log_error(void *data, u_char *buf, size_t len) { ngx_http_proxy_log_ctx_t *ctx = data; - ngx_http_request_t *r; - ngx_peer_connection_t *peer; + u_char *p; + ngx_int_t escape; + ngx_str_t uri; + ngx_http_request_t *r; + ngx_peer_connection_t *peer; + ngx_http_proxy_upstream_conf_t *uc; r = ctx->proxy->request; + uc = ctx->proxy->lcf->upstream; peer = &ctx->proxy->upstream->peer; - return ngx_snprintf(buf, len, - " while %s, client: %s, URL: %s, upstream: %s%s%s%s%s", - ctx->proxy->action, - r->connection->addr_text.data, - r->unparsed_uri.data, - peer->peers->peers[peer->cur_peer].addr_port_text.data, - ctx->proxy->lcf->upstream->uri.data, - r->uri.data + ctx->proxy->lcf->upstream->location->len, - r->args.len ? "?" : "", - r->args.len ? r->args.data : (u_char *) ""); + p = ngx_snprintf(buf, len, + " while %s, client: %V, URL: %V, upstream: %V%V", + ctx->proxy->action, + &r->connection->addr_text, + &r->unparsed_uri, + &peer->peers->peers[peer->cur_peer].addr_port_text, + &ctx->proxy->lcf->upstream->uri); + len -= p - buf; + buf = p; + + if (r->quoted_uri) { + escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, + NGX_ESCAPE_URI); + } else { + escape = 0; + } + + if (escape) { + if (len >= r->uri.len - uc->location->len + escape) { + + ngx_escape_uri(buf, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, NGX_ESCAPE_URI); + + buf += r->uri.len - uc->location->len + escape; + + if (r->args.len == 0) { + return buf; + } + + len -= r->uri.len - uc->location->len + escape; + + return ngx_snprintf(buf, len, "?%V", &r->args); + } + + p = ngx_palloc(r->pool, r->uri.len - uc->location->len + escape); + if (p == NULL) { + return buf; + } + + ngx_escape_uri(p, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, NGX_ESCAPE_URI); + + uri.len = r->uri.len - uc->location->len + escape; + uri.data = p; + + } else { + uri.len = r->uri.len - uc->location->len; + uri.data = r->uri.data + uc->location->len; + + } + + return ngx_snprintf(buf, len, "%V%s%V", + &uri, r->args.len ? "?" : "", &r->args); } @@ -759,8 +808,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, TIME_T_LEN, - TIME_T_FMT, p->state->expired); + buf = ngx_sprintf(buf, "%T", p->state->expired); } *buf++ = '/'; @@ -769,8 +817,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, TIME_T_LEN, - TIME_T_FMT, p->state->bl_time); + buf = ngx_sprintf(buf, "%T", p->state->bl_time); } *buf++ = '/'; @@ -783,8 +830,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, 4, "%" NGX_UINT_T_FMT, - p->state->status); + buf = ngx_sprintf(buf, "%ui", p->state->status); } *buf++ = '/'; @@ -803,8 +849,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, TIME_T_LEN, - TIME_T_FMT, p->state->expires); + buf = ngx_sprintf(buf, "%T", p->state->expires); } *buf++ = ' '; @@ -1166,7 +1211,7 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, lcf->peers->peers[i].addr = *(in_addr_t *)(h->h_addr_list[i]); lcf->peers->peers[i].port = lcf->upstream->port; - len = INET_ADDRSTRLEN + lcf->upstream->port_text.len + 1; + len = INET_ADDRSTRLEN - 1 + 1 + lcf->upstream->port_text.len; lcf->peers->peers[i].addr_port_text.data = ngx_palloc(cf->pool, len); @@ -1181,12 +1226,12 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, lcf->peers->peers[i].addr_port_text.data[len++] = ':'; - ngx_cpystrn(lcf->peers->peers[i].addr_port_text.data + len, - lcf->upstream->port_text.data, - lcf->upstream->port_text.len + 1); + ngx_memcpy(lcf->peers->peers[i].addr_port_text.data + len, + lcf->upstream->port_text.data, + lcf->upstream->port_text.len); lcf->peers->peers[i].addr_port_text.len = - len + lcf->upstream->port_text.len + 1; + len + lcf->upstream->port_text.len; } } else { @@ -1204,10 +1249,11 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, lcf->peers->peers[0].addr = addr; lcf->peers->peers[0].port = lcf->upstream->port; - len = lcf->upstream->host.len + lcf->upstream->port_text.len + 1; + len = lcf->upstream->host.len + 1 + lcf->upstream->port_text.len; + + lcf->peers->peers[0].addr_port_text.len = len; - lcf->peers->peers[0].addr_port_text.data = - ngx_palloc(cf->pool, len + 1); + lcf->peers->peers[0].addr_port_text.data = ngx_palloc(cf->pool, len); if (lcf->peers->peers[0].addr_port_text.data == NULL) { return NGX_CONF_ERROR; } @@ -1219,9 +1265,9 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, lcf->peers->peers[0].addr_port_text.data[len++] = ':'; - ngx_cpystrn(lcf->peers->peers[0].addr_port_text.data + len, - lcf->upstream->port_text.data, - lcf->upstream->port_text.len + 1); + ngx_memcpy(lcf->peers->peers[0].addr_port_text.data + len, + lcf->upstream->port_text.data, + lcf->upstream->port_text.len); } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index 76db65282..094ee3bd1 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -245,7 +245,7 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev); void ngx_http_proxy_busy_lock_handler(ngx_event_t *rev); void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p); -size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len); +u_char *ngx_http_proxy_log_error(void *data, u_char *buf, size_t len); void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc); void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p); diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index 9b3d8847e..0852a426f 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -25,7 +25,8 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev); static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *); static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p); static void ngx_http_proxy_process_body(ngx_event_t *ev); -static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type); +static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, + ngx_uint_t ft_type); static ngx_str_t http_methods[] = { @@ -137,7 +138,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) if (r->quoted_uri) { escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, - r->uri.len - uc->location->len); + r->uri.len - uc->location->len, + NGX_ESCAPE_URI); } else { escape = 0; } @@ -246,7 +248,7 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) if (escape) { ngx_escape_uri(b->last, r->uri.data + uc->location->len, - r->uri.len - uc->location->len); + r->uri.len - uc->location->len, NGX_ESCAPE_URI); b->last += r->uri.len - uc->location->len + escape; } else { @@ -409,8 +411,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) *(b->last++) = CR; *(b->last++) = LF; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http proxy header: \"%s: %s\"", - header[i].key.data, header[i].value.data); + "http proxy header: \"%V: %V\"", + &header[i].key, &header[i].value); } /* add "\r\n" at the header end */ @@ -670,7 +672,7 @@ void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p) static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) { - int rc; + ngx_int_t rc; ngx_connection_t *c; ngx_http_request_t *r; ngx_output_chain_ctx_t *output; @@ -683,7 +685,7 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) rc = ngx_event_connect_peer(&p->upstream->peer); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, - "http proxy connect: %d", rc); + "http proxy connect: %i", rc); if (rc == NGX_ERROR) { ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); @@ -705,6 +707,8 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) c->write->event_handler = ngx_http_proxy_send_request_handler; c->read->event_handler = ngx_http_proxy_process_upstream_status_line; + c->sendfile = r->connection->sendfile; + c->pool = r->pool; c->read->log = c->write->log = c->log = r->connection->log; @@ -1028,8 +1032,8 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev) p->upstream->status_line.len + 1); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0, - "http proxy status %d \"%s\"", - p->upstream->status, p->upstream->status_line.data); + "http proxy status %ui \"%V\"", + p->upstream->status, &p->upstream->status_line); /* init or reinit the p->upstream->headers_in.headers table */ @@ -1143,8 +1147,7 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev) } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http proxy header: \"%s: %s\"", - h->key.data, h->value.data); + "http proxy header: \"%V: %V\"", &h->key, &h->value); continue; @@ -1467,7 +1470,7 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev) if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0, - "http proxy upstream exit: " PTR_FMT, ep->out); + "http proxy upstream exit: %p", ep->out); ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); ngx_http_proxy_finalize_request(p, 0); return; @@ -1484,12 +1487,13 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev) } -static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type) +static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, + ngx_uint_t ft_type) { - int status; + ngx_uint_t status; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, - "http proxy next upstream: %d", ft_type); + "http proxy next upstream: %ui", ft_type); ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index 90bbbe2f5..a550acb1d 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -83,7 +83,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_http_core_srv_conf_t **cscfp, *cscf; ngx_http_core_loc_conf_t *clcf; ngx_http_core_main_conf_t *cmcf; -#if (WIN32) +#if (NGX_WIN32) ngx_iocp_conf_t *iocpcf; #endif @@ -343,9 +343,8 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (in_addr[a].default_server) { ngx_log_error(NGX_LOG_ERR, cf->log, 0, - "the duplicate default server in %s:%d", - lscf[l].file_name.data, - lscf[l].line); + "the duplicate default server in %V:%d", + &lscf[l].file_name, lscf[l].line); return NGX_CONF_ERROR; } @@ -516,7 +515,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index]; ls->log = clcf->err_log; -#if (WIN32) +#if (NGX_WIN32) iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module); if (iocpcf->acceptex_read) { ls->post_accept_buffer_size = cscf->client_header_buffer_size; @@ -582,18 +581,18 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) in_port = in_ports.elts; for (p = 0; p < in_ports.nelts; p++) { ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0, - "port: %d %08x", in_port[p].port, &in_port[p]); + "port: %d %p", in_port[p].port, &in_port[p]); in_addr = in_port[p].addrs.elts; for (a = 0; a < in_port[p].addrs.nelts; a++) { ngx_inet_ntop(AF_INET, &in_addr[a].addr, address, 20); ngx_log_debug3(NGX_LOG_DEBUG_HTTP, cf->log, 0, - "%s:%d %08x", + "%s:%d %p", address, in_port[p].port, in_addr[a].core_srv_conf); s_name = in_addr[a].names.elts; for (n = 0; n < in_addr[a].names.nelts; n++) { ngx_log_debug4(NGX_LOG_DEBUG_HTTP, cf->log, 0, - "%s:%d %s %08x", - address, in_port[p].port, s_name[n].name.data, + "%s:%d %V %p", + address, in_port[p].port, &s_name[n].name, s_name[n].core_srv_conf); } } @@ -671,7 +670,7 @@ static ngx_int_t ngx_http_add_names(ngx_conf_t *cf, for (i = 0; i < cscf->server_names.nelts; i++) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, - "name: %s", server_names[i].name.data); + "name: %V", &server_names[i].name); /* TODO: duplicate names can be checked here */ diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h index 303a4daef..46194f34d 100644 --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -33,7 +33,7 @@ typedef struct ngx_http_cleanup_s ngx_http_cleanup_t; typedef struct { - u_int connection; + u_int connection; /* * we declare "action" as "char *" because the actions are usually @@ -41,9 +41,9 @@ typedef struct { * all the time their types */ - char *action; - u_char *client; - u_char *url; + char *action; + ngx_str_t *client; + ngx_http_request_t *request; } ngx_http_log_ctx_t; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 8f101bad8..7e8cf6903 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -10,7 +10,7 @@ #include <ngx_http.h> #include <nginx.h> -/* STUB */ + #define NGX_HTTP_LOCATION_EXACT 1 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2 #define NGX_HTTP_LOCATION_REGEX 3 @@ -329,12 +329,12 @@ ngx_module_t ngx_http_core_module = { void ngx_http_handler(ngx_http_request_t *r) { - ngx_http_log_ctx_t *lcx; + ngx_http_log_ctx_t *ctx; r->connection->unexpected_eof = 0; - lcx = r->connection->log->data; - lcx->action = NULL; + ctx = r->connection->log->data; + ctx->action = NULL; switch (r->headers_in.connection_type) { case 0: @@ -526,17 +526,15 @@ ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r) ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http cl: " SIZE_T_FMT " max: " SIZE_T_FMT, - r->headers_in.content_length_n, - clcf->client_max_body_size); + "http cl:%z max:%uz", + r->headers_in.content_length_n, clcf->client_max_body_size); if (r->headers_in.content_length_n != -1 && clcf->client_max_body_size && clcf->client_max_body_size < (size_t) r->headers_in.content_length_n) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "client intented to send too large body: " - SIZE_T_FMT " bytes", + "client intented to send too large body: %z bytes", r->headers_in.content_length_n); return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE; @@ -583,9 +581,8 @@ static ngx_int_t ngx_http_find_location(ngx_http_request_t *r, #endif ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "find location: %s\"%s\"", - clcfp[i]->exact_match ? "= " : "", - clcfp[i]->name.data); + "find location: %s\"%V\"", + clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name); if (clcfp[i]->auto_redirect && r->uri.len == clcfp[i]->name.len - 1 @@ -649,8 +646,7 @@ static ngx_int_t ngx_http_find_location(ngx_http_request_t *r, } ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "find location: ~ \"%s\"", - clcfp[i]->name.data); + "find location: ~ \"%V\"", &clcfp[i]->name); n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0); @@ -661,8 +657,8 @@ static ngx_int_t ngx_http_find_location(ngx_http_request_t *r, if (n < 0) { ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, ngx_regex_exec_n - " failed: %d on \"%s\" using \"%s\"", - n, r->uri.data, clcfp[i]->name.data); + " failed: %d on \"%V\" using \"%V\"", + n, &r->uri, &clcfp[i]->name); return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -809,14 +805,12 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, ngx_str_t *uri, ngx_str_t *args) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "internal redirect: \"%s\"", uri->data); + "internal redirect: \"%V\"", uri); - r->uri.len = uri->len; - r->uri.data = uri->data; + r->uri = *uri; if (args) { - r->args.len = args->len; - r->args.data = args->data; + r->args = *args; } if (ngx_http_set_exten(r) != NGX_OK) { @@ -1092,16 +1086,14 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) clcf->name = value[2]; #else ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "the using of the regex \"%s\" " - "requires PCRE library", - value[2].data); + "the using of the regex \"%V\" " + "requires PCRE library", &value[2]); return NGX_CONF_ERROR; #endif } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid location modifier \"%s\"", - value[1].data); + "invalid location modifier \"%V\"", &value[1]); return NGX_CONF_ERROR; } @@ -1123,9 +1115,9 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) if (pclcf->exact_match) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "location \"%s\" could not be inside " - "the exact location \"%s\"", - clcf->name.data, pclcf->name.data); + "location \"%V\" could not be inside " + "the exact location \"%V\"", + &clcf->name, &pclcf->name); return NGX_CONF_ERROR; } @@ -1139,8 +1131,8 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) #endif { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "location \"%s\" is outside location \"%s\"", - clcf->name.data, pclcf->name.data); + "location \"%V\" is outside location \"%V\"", + &clcf->name, &pclcf->name); return NGX_CONF_ERROR; } @@ -1301,7 +1293,7 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, if (conf->listen.nelts == 0) { ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR); l->addr = INADDR_ANY; -#if (WIN32) +#if (NGX_WIN32) l->port = 80; #else /* STUB: getuid() should be cached */ @@ -1561,9 +1553,9 @@ static char *ngx_http_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) || (port < 1 || port > 65536)) { /* "listen 99999" */ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid port \"%s\" in \"%s\" directive, " + "invalid port \"%s\" in \"%V\" directive, " "it must be a number between 1 and 65535", - &addr[p], cmd->name.data); + &addr[p], &cmd->name); return NGX_CONF_ERROR; @@ -1583,7 +1575,7 @@ static char *ngx_http_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (h == NULL || h->h_addr_list[0] == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "can not resolve host \"%s\" " - "in \"%s\" directive", addr, cmd->name.data); + "in \"%V\" directive", addr, &cmd->name); return NGX_CONF_ERROR; } @@ -1612,9 +1604,9 @@ static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) for (i = 1; i < cf->args->nelts; i++) { if (value[i].len == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "server name \"%s\" is invalid " - "in \"%s\" directive", - value[i].data, cmd->name.data); + "server name \"%V\" is invalid " + "in \"%V\" directive", + &value[i], &cmd->name); return NGX_CONF_ERROR; } @@ -1659,13 +1651,13 @@ static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if ((ngx_uint_t) lcf->alias == alias) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "\"%s\" directive is duplicate", - cmd->name.data); + "\"%V\" directive is duplicate", + &cmd->name); } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "\"%s\" directive is duplicate, " + "\"%V\" directive is duplicate, " "\"%s\" directive is specified before", - cmd->name.data, lcf->alias ? "alias" : "root"); + &cmd->name, lcf->alias ? "alias" : "root"); } return NGX_CONF_ERROR; @@ -1708,7 +1700,7 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (value[i].data[0] == '=') { if (i == 1) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[i].data); + "invalid value \"%V\"", &value[i]); return NGX_CONF_ERROR; } @@ -1716,7 +1708,7 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) if (overwrite == NGX_ERROR) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[i].data); + "invalid value \"%V\"", value[i]); return NGX_CONF_ERROR; } @@ -1735,14 +1727,14 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) err->status = ngx_atoi(value[i].data, value[i].len); if (err->status == NGX_ERROR) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[i].data); + "invalid value \"%V\"", &value[i]); return NGX_CONF_ERROR; } if (err->status < 400 || err->status > 599) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "value \"%s\" must be between 400 and 599", - value[i].data); + "value \"%V\" must be between 400 and 599", + &value[i]); return NGX_CONF_ERROR; } diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c index acd8dbd3b..8f920d240 100644 --- a/src/http/ngx_http_file_cache.c +++ b/src/http/ngx_http_file_cache.c @@ -168,7 +168,7 @@ int ngx_http_cache_update_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx, err = ngx_errno; -#if (WIN32) +#if (NGX_WIN32) if (err == NGX_EEXIST) { if (ngx_win32_rename_file(temp_file, &ctx->file.name, r->pool) == NGX_ERROR) diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c index 595dd59e3..3fa11086d 100644 --- a/src/http/ngx_http_header_filter.c +++ b/src/http/ngx_http_header_filter.c @@ -319,13 +319,6 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) if (r->headers_out.content_length_n >= 0) { b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF, r->headers_out.content_length_n); - -#if 0 - b->last += ngx_snprintf((char *) b->last, - sizeof("Content-Length: ") + NGX_OFF_T_LEN + 2, - "Content-Length: " OFF_T_FMT CRLF, - r->headers_out.content_length_n); -#endif } } @@ -396,12 +389,6 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) { b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF, clcf->keepalive_header); -#if 0 - b->last += ngx_snprintf((char *) b->last, - sizeof("Keep-Alive: timeout=") + TIME_T_LEN + 2, - "Keep-Alive: timeout=" TIME_T_FMT CRLF, - clcf->keepalive_header); -#endif } } else { diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c index 9a1389d13..581a1ce65 100644 --- a/src/http/ngx_http_log_handler.c +++ b/src/http/ngx_http_log_handler.c @@ -133,7 +133,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_request_t *r) ngx_http_log_t *log; ngx_http_log_op_t *op; ngx_http_log_loc_conf_t *lcf; -#if (WIN32) +#if (NGX_WIN32) u_long written; #endif @@ -160,7 +160,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_request_t *r) } } -#if (WIN32) +#if (NGX_WIN32) len += 2; #else len++; @@ -186,7 +186,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_request_t *r) } } -#if (WIN32) +#if (NGX_WIN32) *p++ = CR; *p++ = LF; WriteFile(log[l].file->fd, line, p - line, &written, NULL); #else @@ -211,12 +211,6 @@ static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, uintptr_t data) { return ngx_sprintf(buf, "%ui", r->connection->number); - -#if 0 - return buf + ngx_snprintf((char *) buf, NGX_INT_T_LEN + 1, - "%" NGX_UINT_T_FMT, - r->connection->number); -#endif } @@ -249,11 +243,6 @@ static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, ngx_gettimeofday(&tv); return ngx_sprintf(buf, "%l.%03l", tv.tv_sec, tv.tv_usec / 1000); - -#if 0 - return buf + ngx_snprintf((char *) buf, TIME_T_LEN + 5, "%ld.%03ld", - tv.tv_sec, tv.tv_usec / 1000); -#endif } @@ -274,11 +263,6 @@ static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, { return ngx_sprintf(buf, "%ui", r->err_status ? r->err_status : r->headers_out.status); - -#if 0 - return buf + ngx_snprintf((char *) buf, 4, "%" NGX_UINT_T_FMT, - r->err_status ? r->err_status : r->headers_out.status); -#endif } @@ -286,11 +270,6 @@ static u_char *ngx_http_log_length(ngx_http_request_t *r, u_char *buf, uintptr_t data) { return ngx_sprintf(buf, "%O", r->connection->sent); - -#if 0 - return buf + ngx_snprintf((char *) buf, NGX_OFF_T_LEN + 1, OFF_T_FMT, - r->connection->sent); -#endif } @@ -298,10 +277,6 @@ static u_char *ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf, uintptr_t data) { return ngx_sprintf(buf, "%O", r->connection->sent - r->header_size); -#if 0 - return buf + ngx_snprintf((char *) buf, NGX_OFF_T_LEN + 1, OFF_T_FMT, - r->connection->sent - r->header_size); -#endif } @@ -470,9 +445,7 @@ static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf, if (buf == NULL) { return (u_char *) NGX_OFF_T_LEN; } - return buf + ngx_snprintf((char *) buf, - NGX_OFF_T_LEN + 2, OFF_T_FMT, - r->headers_out.content_length_n); + return ngx_sprintf(buf, "%O", r->headers_out.content_length_n); } if (data == offsetof(ngx_http_headers_out_t, last_modified)) { diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c index e70a6ea93..bfe5efb17 100644 --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c @@ -199,7 +199,7 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) } break; - /* check "/.", "//", and "%" in URI */ + /* check "/.", "//", "%", and "\" (Win32) in URI */ case sw_after_slash_in_uri: switch (ch) { case CR: @@ -224,6 +224,11 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) r->quoted_uri = 1; state = sw_uri; break; +#if (NGX_WIN32) + case '\\': + r->complex_uri = 1; + break; +#endif case '/': r->complex_uri = 1; break; @@ -237,7 +242,7 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) } break; - /* check "/" and "%" in URI */ + /* check "/", "%" and "\" (Win32) in URI */ case sw_check_uri: switch (ch) { case CR: @@ -257,6 +262,12 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) case '.': r->uri_ext = p; break; +#if (NGX_WIN32) + case '\\': + r->complex_uri = 1; + state = sw_after_slash_in_uri; + break; +#endif case '/': r->uri_ext = NULL; state = sw_after_slash_in_uri; @@ -657,7 +668,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) sw_slash, sw_dot, sw_dot_dot, -#if (WIN32) +#if (NGX_WIN32) sw_dot_dot_dot, #endif sw_quoted, @@ -671,17 +682,42 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) p = r->uri_start; u = r->uri.data; r->uri_ext = NULL; + r->args_start = NULL; ch = *p++; - while (p < r->uri_start + r->uri.len + 1) { + while (p < r->uri_start + r->uri.len + 1 && r->args_start == NULL) { + + /* + * we use "ch = *p++" inside the cycle but this operation is safe + * because after the URI there is always at least one charcter: + * the line feed + */ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "s:%d in:'%x:%c', out:'%c'", state, ch, ch, *u); + "s:%d in:'%Xd:%c', out:'%c'", state, ch, ch, *u); switch (state) { case sw_usual: switch(ch) { +#if (NGX_WIN32) + case '\\': + r->uri_ext = NULL; + + if (p == r->uri_start + r->uri.len) { + + /* + * we omit the last "\" to cause redirect because + * the browsers do not treat "\" as "/" in relative URL path + */ + + break; + } + + state = sw_slash; + *u++ = '/'; + break; +#endif case '/': r->uri_ext = NULL; state = sw_slash; @@ -691,6 +727,9 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) quoted_state = state; state = sw_quoted; break; + case '?': + r->args_start = p; + break; case '.': r->uri_ext = u + 1; default: @@ -702,6 +741,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) case sw_slash: switch(ch) { +#if (NGX_WIN32) + case '\\': + break; +#endif case '/': break; case '.': @@ -722,6 +765,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) case sw_dot: switch(ch) { +#if (NGX_WIN32) + case '\\': + /* fall through */ +#endif case '/': state = sw_slash; u--; @@ -744,6 +791,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) case sw_dot_dot: switch(ch) { +#if (NGX_WIN32) + case '\\': + /* fall through */ +#endif case '/': state = sw_slash; u -= 4; @@ -758,7 +809,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) quoted_state = state; state = sw_quoted; break; -#if (WIN32) +#if (NGX_WIN32) case '.': state = sw_dot_dot_dot; *u++ = ch; @@ -772,9 +823,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) ch = *p++; break; -#if (WIN32) +#if (NGX_WIN32) case sw_dot_dot_dot: switch(ch) { + case '\\': case '/': state = sw_slash; u -= 5; @@ -857,12 +909,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) if (r->uri_ext) { r->exten.len = u - r->uri_ext; - - if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } - - ngx_cpystrn(r->exten.data, r->uri_ext, r->exten.len + 1); + r->exten.data = r->uri_ext; } r->uri_ext = NULL; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index d78a779ca..a2cf1a025 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -34,24 +34,22 @@ static void ngx_http_lingering_close_handler(ngx_event_t *ev); static void ngx_http_client_error(ngx_http_request_t *r, int client_error, int error); -static size_t ngx_http_log_error(void *data, char *buf, size_t len); +static u_char *ngx_http_log_error(void *data, u_char *buf, size_t len); /* NGX_HTTP_PARSE_... errors */ static char *client_header_errors[] = { - "client %s sent invalid method", - "client %s sent invalid request", - "client %s sent too long URI", - "client %s sent invalid method in HTTP/0.9 request", - - "client %s sent invalid header, URL: %s", - "client %s sent too long header line, URL: %s", - "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", - "client %s sent invalid \"Content-Length\" header, URL: %s", - "client %s sent POST method without \"Content-Length\" header, URL: %s", - "client %s sent plain HTTP request to HTTPS port, URL: %s", - "client %s sent invalid \"Host\" header \"%s\", URL: %s" + "client %V sent invalid method \"%V\"", + "client %V sent invalid request \"%V\"", + "client %V sent too long URI in request \"%V\"", + "client %V sent invalid method in HTTP/0.9 request \"%V\"", + + "client %V sent invalid header, URL: \"%V\"", + "client %V sent too long header line, URL: \"%V\"", + "client %V sent HTTP/1.1 request without \"Host\" header, URL: \"%V\"", + "client %V sent invalid \"Content-Length\" header, URL: \"%V\"", + "client %V sent POST method without \"Content-Length\" header, URL: \"%V\"", }; @@ -105,14 +103,15 @@ void ngx_http_init_connection(ngx_connection_t *c) ngx_event_t *rev; ngx_http_log_ctx_t *ctx; - if (!(ctx = ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t)))) { + if (!(ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)))) { ngx_http_close_connection(c); return; } ctx->connection = c->number; - ctx->client = c->addr_text.data; + ctx->client = &c->addr_text; ctx->action = "reading client request line"; + ctx->request = NULL; c->log->data = ctx; c->log->handler = ngx_http_log_error; c->log_error = NGX_ERROR_INFO; @@ -278,7 +277,7 @@ static void ngx_http_init_request(ngx_event_t *rev) * AcceptEx() already gave this address. */ -#if (WIN32) +#if (NGX_WIN32) if (c->local_sockaddr) { r->in_addr = ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; @@ -295,7 +294,7 @@ static void ngx_http_init_request(ngx_event_t *rev) r->in_addr = addr_in.sin_addr.s_addr; -#if (WIN32) +#if (NGX_WIN32) } #endif @@ -428,9 +427,9 @@ static void ngx_http_init_request(ngx_event_t *rev) static void ngx_http_ssl_handshake(ngx_event_t *rev) { - int n; - ngx_int_t rc; u_char buf[1]; + ssize_t n; + ngx_int_t rc; ngx_connection_t *c; ngx_http_request_t *r; @@ -454,7 +453,7 @@ static void ngx_http_ssl_handshake(ngx_event_t *rev) if (n == 1) { if (buf[0] == 0x80 /* SSLv2 */ || buf[0] == 0x16 /* SSLv3/TLSv1 */) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, - "https ssl handshake: 0x%X", buf[0]); + "https ssl handshake: 0x%02Xd", buf[0]); c->recv = ngx_ssl_recv; c->send_chain = ngx_ssl_send_chain; @@ -488,7 +487,6 @@ static void ngx_http_ssl_handshake(ngx_event_t *rev) static void ngx_http_process_request_line(ngx_event_t *rev) { - u_char *p; ssize_t n; ngx_int_t rc, rv; ngx_connection_t *c; @@ -524,21 +522,9 @@ static void ngx_http_process_request_line(ngx_event_t *rev) /* the request line has been parsed successfully */ - /* copy unparsed URI */ - - r->unparsed_uri.len = r->uri_end - r->uri_start; - r->unparsed_uri.data = ngx_palloc(r->pool, r->unparsed_uri.len + 1); - if (r->unparsed_uri.data == NULL) { - ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - ngx_http_close_connection(c); - return; - } - - ngx_cpystrn(r->unparsed_uri.data, r->uri_start, - r->unparsed_uri.len + 1); - + r->request_line.len = r->request_end - r->request_start; + r->request_line.data = r->request_start; - /* copy URI */ if (r->args_start) { r->uri.len = r->args_start - 1 - r->uri_start; @@ -546,13 +532,14 @@ static void ngx_http_process_request_line(ngx_event_t *rev) r->uri.len = r->uri_end - r->uri_start; } - if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) { - ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - ngx_http_close_connection(c); - return; - } - if (r->complex_uri || r->quoted_uri) { + + if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) { + ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); + ngx_http_close_connection(c); + return; + } + rc = ngx_http_parse_complex_uri(r); if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { @@ -562,74 +549,55 @@ static void ngx_http_process_request_line(ngx_event_t *rev) } if (rc != NGX_OK) { - r->request_line.len = r->request_end - r->request_start; - r->request_line.data = r->request_start; - ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST); return; } } else { - ngx_cpystrn(r->uri.data, r->uri_start, r->uri.len + 1); + r->uri.data = r->uri_start; } + r->unparsed_uri.len = r->uri_end - r->uri_start; + r->unparsed_uri.data = r->uri_start; - r->request_line.len = r->request_end - r->request_start; - r->request_line.data = r->request_start; - r->request_line.data[r->request_line.len] = '\0'; if (r->method == 0) { r->method_name.len = r->method_end - r->request_start + 1; r->method_name.data = r->request_line.data; } - if (r->uri_ext) { - - /* copy URI extention */ + if (r->uri_ext) { if (r->args_start) { r->exten.len = r->args_start - 1 - r->uri_ext; } else { r->exten.len = r->uri_end - r->uri_ext; } - if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) { - ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - ngx_http_close_connection(c); - return; - } - - ngx_cpystrn(r->exten.data, r->uri_ext, r->exten.len + 1); + r->exten.data = r->uri_ext; } - if (r->args_start && r->uri_end > r->args_start) { - - /* copy URI arguments */ + if (r->args_start && r->uri_end > r->args_start) { r->args.len = r->uri_end - r->args_start; - - if (!(r->args.data = ngx_palloc(r->pool, r->args.len + 1))) { - ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - ngx_http_close_connection(c); - return; - } - - ngx_cpystrn(r->args.data, r->args_start, r->args.len + 1); + r->args.data = r->args_start; } + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http request line: \"%s\"", r->request_line.data); + "http request line: \"%V\"", &r->request_line); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http uri: \"%s\"", r->uri.data); + "http uri: \"%V\"", &r->uri); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http args: \"%s\"", - r->args.data ? r->args.data : (u_char *) ""); + "http args: \"%V\"", &r->args); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http exten: \"%s\"", - r->exten.data ? r->exten.data : (u_char *) ""); + "http exten: \"%V\"", &r->exten); + + ctx = c->log->data; + ctx->request = r; if (r->http_version < NGX_HTTP_VERSION_10) { rev->event_handler = ngx_http_block_read; @@ -655,10 +623,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev) return; } - - ctx = c->log->data; ctx->action = "reading client request headers"; - ctx->url = r->unparsed_uri.data; rev->event_handler = ngx_http_process_request_headers; ngx_http_process_request_headers(rev); @@ -669,6 +634,9 @@ static void ngx_http_process_request_line(ngx_event_t *rev) /* there was error while a request line parsing */ + ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST); + +#if 0 for (p = r->request_start; p < r->header_in->last; p++) { if (*p == CR || *p == LF) { break; @@ -686,6 +654,8 @@ static void ngx_http_process_request_line(ngx_event_t *rev) (rc == NGX_HTTP_PARSE_INVALID_METHOD) ? NGX_HTTP_NOT_IMPLEMENTED: NGX_HTTP_BAD_REQUEST); +#endif + return; } @@ -811,8 +781,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev) } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http header: \"%s: %s\"", - h->key.data, h->value.data); + "http header: \"%V: %V\"", + &h->key, &h->value); continue; @@ -973,7 +943,7 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, b = hc->free[--hc->nfree]; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http large header free: " PTR_FMT " " SIZE_T_FMT, + "http large header free: %p %uz", b->pos, b->end - b->last); } else if (hc->nbusy < cscf->large_client_header_buffers.num) { @@ -993,7 +963,7 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http large header alloc: " PTR_FMT " " SIZE_T_FMT, + "http large header alloc: %p %uz", b->pos, b->end - b->last); } else { @@ -1095,7 +1065,7 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r) for (i = 0; i < r->virtual_names->nelts; i++) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "server name: %s", name[i].name.data); + "server name: %V", &name[i].name); if (name[i].wildcard) { if (r->headers_in.host_name_len <= name[i].name.len) { @@ -1579,7 +1549,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r) ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler"); - ctx = (ngx_http_log_ctx_t *) c->log->data; + ctx = c->log->data; ctx->action = "closing request"; hc = r->http_connection; @@ -1677,7 +1647,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r) b->last = b->start; } - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: " PTR_FMT " %d", + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: %p %d", hc->free, hc->nfree); if (hc->free) { @@ -1689,7 +1659,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r) hc->nfree = 0; } - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: " PTR_FMT " %d", + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: %p %d", hc->busy, hc->nbusy); if (hc->busy) { @@ -1785,8 +1755,9 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev) if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { if (rev->pending_eof) { + rev->log->handler = NULL; ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno, - "kevent() reported that client %s closed " + "kevent() reported that client %V closed " "keepalive connection", ctx->client); ngx_http_close_connection(c); return; @@ -1841,7 +1812,7 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev) if (n == 0) { ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno, - "client %s closed keepalive connection", ctx->client); + "client %V closed keepalive connection", ctx->client); ngx_http_close_connection(c); return; } @@ -2055,7 +2026,7 @@ void ngx_http_close_request(ngx_http_request_t *r, int error) if (r->file.fd != NGX_INVALID_FILE) { if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, - ngx_close_file_n " \"%s\" failed", r->file.name.data); + ngx_close_file_n " \"%V\" failed", &r->file.name); } } @@ -2067,8 +2038,8 @@ void ngx_http_close_request(ngx_http_request_t *r, int error) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, - ngx_close_file_n " deleted file \"%s\" failed", - r->request_body->temp_file->file.name.data); + ngx_close_file_n " deleted file \"%V\" failed", + &r->request_body->temp_file->file.name); } } @@ -2088,9 +2059,9 @@ void ngx_http_close_request(ngx_http_request_t *r, int error) } } - /* ctx->url was allocated from r->pool */ + /* the variuos request strings were allocated from r->pool */ ctx = log->data; - ctx->url = NULL; + ctx->request = NULL; r->request_line.len = 0; @@ -2148,6 +2119,7 @@ void ngx_http_close_connection(ngx_connection_t *c) static void ngx_http_client_error(ngx_http_request_t *r, int client_error, int error) { + u_char *p; ngx_http_log_ctx_t *ctx; ngx_http_core_srv_conf_t *cscf; @@ -2164,13 +2136,15 @@ static void ngx_http_client_error(ngx_http_request_t *r, r->connection->log->handler = NULL; - if (ctx->url) { + if (ctx->request) { + switch (client_error) { case NGX_HTTP_PARSE_INVALID_HOST: ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], - ctx->client, r->headers_in.host->value.data, ctx->url); + "client %V sent invalid \"Host\" header \"%V\", URL: \"%V\"", + ctx->client, &r->headers_in.host->value, + &ctx->request->unparsed_uri); error = NGX_HTTP_INVALID_HOST; @@ -2186,24 +2160,49 @@ static void ngx_http_client_error(ngx_http_request_t *r, case NGX_HTTP_PARSE_HTTP_TO_HTTPS: error = NGX_HTTP_TO_HTTPS; + if (ctx->request->headers_in.referer) { + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "client %V sent plain HTTP request to HTTPS port, " + "URL: \"%V\", referrer \"%V\"", + ctx->client, &ctx->request->unparsed_uri, + &ctx->request->headers_in.referer->value); - /* fall through */ + } else { + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "client %V sent plain HTTP request to HTTPS port, " + "URL: \"%V\"", ctx->client, &ctx->request->unparsed_uri); + } + + break; default: ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], - ctx->client, ctx->url); + ctx->client, &ctx->request->unparsed_uri); } } else { + if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) { r->request_line.len = r->header_in->end - r->request_start; r->request_line.data = r->request_start; + + } else { + if (r->request_line.data == NULL) { + for (p = r->request_start; p < r->header_in->last; p++) { + if (*p == CR || *p == LF) { + break; + } + } + + r->request_line.len = p - r->request_start; + r->request_line.data = r->request_start; + } } ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], - ctx->client); + ctx->client, &r->request_line); } r->connection->log->handler = ngx_http_log_error; @@ -2212,20 +2211,35 @@ static void ngx_http_client_error(ngx_http_request_t *r, } -static size_t ngx_http_log_error(void *data, char *buf, size_t len) +static u_char *ngx_http_log_error(void *data, u_char *buf, size_t len) { ngx_http_log_ctx_t *ctx = data; - if (ctx->action && ctx->url) { - return ngx_snprintf(buf, len, " while %s, client: %s, URL: %s", - ctx->action, ctx->client, ctx->url); + u_char *p; - } else if (ctx->action == NULL && ctx->url) { - return ngx_snprintf(buf, len, ", client: %s, URL: %s", - ctx->client, ctx->url); + p = buf; - } else { - return ngx_snprintf(buf, len, " while %s, client: %s", - ctx->action, ctx->client); + if (ctx->action) { + p = ngx_snprintf(p, len, " while %s", ctx->action); + len -= p - buf; } + + p = ngx_snprintf(p, len, ", client: %V", ctx->client); + + if (ctx->request == NULL) { + return p; + } + + len -= p - buf; + + p = ngx_snprintf(p, len, ", URL: \"%V\"", &ctx->request->unparsed_uri); + + if (ctx->request->headers_in.referer == NULL) { + return p; + } + + len -= p - buf; + + return ngx_snprintf(p, len, ", referrer: \"%V\"", + &ctx->request->headers_in.referer->value); } diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index f1b957b6f..31b1187b0 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -41,8 +41,9 @@ #define NGX_HTTP_PARSE_NO_HOST_HEADER 16 #define NGX_HTTP_PARSE_INVALID_CL_HEADER 17 #define NGX_HTTP_PARSE_POST_WO_CL_HEADER 18 -#define NGX_HTTP_PARSE_HTTP_TO_HTTPS 19 -#define NGX_HTTP_PARSE_INVALID_HOST 20 + +#define NGX_HTTP_PARSE_INVALID_HOST 19 +#define NGX_HTTP_PARSE_HTTP_TO_HTTPS 20 #define NGX_HTTP_OK 200 diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c index ee8e3685b..c9ec6fa07 100644 --- a/src/http/ngx_http_request_body.c +++ b/src/http/ngx_http_request_body.c @@ -148,7 +148,7 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r) n = c->recv(c, r->request_body->buf->last, size); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http client request body recv " SIZE_T_FMT, n); + "http client request body recv %z", n); if (n == NGX_AGAIN) { clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); @@ -184,7 +184,7 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r) } ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http client request body rest " SIZE_T_FMT, + "http client request body rest %uz", r->request_body->rest); if (r->request_body->rest) { diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c index 3a26d65de..51a1b47e2 100644 --- a/src/http/ngx_http_script.c +++ b/src/http/ngx_http_script.c @@ -40,15 +40,11 @@ char *ngx_http_script_request_line(ngx_http_request_t *r, char *p, size_t len) char *ngx_http_script_status(ngx_http_request_t *r, char *p, size_t len) { - p += ngx_snprintf(p, len, "%d", r->headers_out.status); - - return p; + return ngx_snprintf(p, len, "%d", r->headers_out.status); } char *ngx_http_script_sent(ngx_http_request_t *r, char *p, size_t len) { - p += ngx_snprintf(p, len, OFF_FMT, r->connection->sent); - - return p; + return ngx_sprintf(p, "%O", r->connection->sent); } diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c index 37e0f3fab..67f686267 100644 --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -69,6 +69,12 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) for (cl = ctx->out; cl; cl = cl->next) { ll = &cl->next; +#if 1 + if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { + ngx_debug_point(); + } +#endif + size += ngx_buf_size(cl->buf); if (cl->buf->flush || cl->buf->recycled) { @@ -83,10 +89,20 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) /* add the new chain to the existent one */ for (ln = in; ln; ln = ln->next) { - ngx_alloc_link_and_set_buf(cl, ln->buf, r->pool, NGX_ERROR); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + + cl->buf = ln->buf; *ll = cl; ll = &cl->next; +#if 1 + if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { + ngx_debug_point(); + } +#endif + size += ngx_buf_size(cl->buf); if (cl->buf->flush || cl->buf->recycled) { @@ -98,11 +114,12 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) } } + *ll = NULL; + c = r->connection; ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http write filter: l:%d f:" OFF_T_FMT " s:" OFF_T_FMT, - last, flush, size); + "http write filter: l:%d f:%O s:%O", last, flush, size); clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r, ngx_http_core_module); @@ -125,6 +142,9 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) if (!last) { ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, "the http output chain is empty"); + + ngx_debug_point(); + return NGX_ERROR; } return NGX_OK; @@ -136,7 +156,7 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) clcf->limit_rate ? clcf->limit_rate: OFF_T_MAX_VALUE); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http write filter %X", chain); + "http write filter %p", chain); if (clcf->limit_rate) { sent = c->sent - sent; |