diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-03-16 07:10:12 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-03-16 07:10:12 +0000 |
commit | 10a543a810ac78eb5d754302b001debf9cd420c4 (patch) | |
tree | a4a4f43835bed4549007b82db516d460fc86c555 /src/http | |
parent | 5596ede94ed311bb9d16ee11f6f68c97eb46d836 (diff) | |
download | nginx-10a543a810ac78eb5d754302b001debf9cd420c4.tar.gz nginx-10a543a810ac78eb5d754302b001debf9cd420c4.zip |
nginx-0.0.2-2004-03-16-10:10:12 import
Diffstat (limited to 'src/http')
28 files changed, 473 insertions, 380 deletions
diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c index ed7b460c1..21e2f5b7c 100644 --- a/src/http/modules/ngx_http_chunked_filter.c +++ b/src/http/modules/ngx_http_chunked_filter.c @@ -56,7 +56,7 @@ static int ngx_http_chunked_header_filter(ngx_http_request_t *r) static int ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { - char *chunk; + u_char *chunk; size_t size, len; ngx_hunk_t *h; ngx_chain_t *out, *cl, *tl, **ll; @@ -87,7 +87,7 @@ static int ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in) } ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR); - len = ngx_snprintf(chunk, 11, SIZE_T_X_FMT CRLF, size); + len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size); ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index 18ad074fc..57177b509 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -7,12 +7,14 @@ typedef struct { - int enable; + ngx_flag_t enable; + ngx_flag_t no_buffer; + ngx_bufs_t bufs; + int level; - ssize_t wbits; - ssize_t memlevel; - int no_buffer; + int wbits; + int memlevel; } ngx_http_gzip_conf_t; @@ -39,7 +41,7 @@ typedef struct { size_t zin; size_t zout; - u_int crc32; + uint32_t crc32; z_stream zstream; ngx_http_request_t *request; } ngx_http_gzip_ctx_t; @@ -51,8 +53,8 @@ static void ngx_http_gzip_filter_free(void *opaque, void *address); ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); -static char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, char *buf, - uintptr_t data); +static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, + uintptr_t data); static int ngx_http_gzip_pre_conf(ngx_conf_t *cf); static int ngx_http_gzip_filter_init(ngx_cycle_t *cycle); @@ -158,15 +160,15 @@ static u_char gzheader[10] = { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 }; #if (HAVE_LITTLE_ENDIAN) struct gztrailer { - u_int crc32; - u_int zlen; + uint32_t crc32; + uint32_t zlen; }; #else /* HAVE_BIG_ENDIAN */ struct gztrailer { - u_char crc32[4]; - u_char zlen[4]; + u_char crc32[4]; + u_char zlen[4]; }; #endif @@ -296,7 +298,7 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ngx_test_null(h, ngx_calloc_hunk(r->pool), ngx_http_gzip_error(ctx)); h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; - h->pos = (char *) gzheader; + h->pos = gzheader; h->last = h->pos + 10; ngx_alloc_link_and_set_hunk(cl, h, r->pool, ngx_http_gzip_error(ctx)); @@ -396,8 +398,8 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ctx->zstream.avail_in, ctx->zstream.avail_out, rc); - ctx->in_hunk->pos = (char *) ctx->zstream.next_in; - ctx->out_hunk->last = (char *) ctx->zstream.next_out; + ctx->in_hunk->pos = ctx->zstream.next_in; + ctx->out_hunk->last = ctx->zstream.next_out; if (ctx->zstream.avail_out == 0) { ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, @@ -558,10 +560,10 @@ static void ngx_http_gzip_filter_free(void *opaque, void *address) } -static char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { - u_int zint, zfrac; + ngx_uint_t zint, zfrac; ngx_http_gzip_ctx_t *ctx; ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module); @@ -572,14 +574,14 @@ static char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, char *buf, } #if 0 - return buf + ngx_snprintf(buf, NGX_INT32_LEN + 4, "%.2f", + return buf + ngx_snprintf((char *) buf, NGX_INT32_LEN + 4, "%.2f", (float) ctx->zin / ctx->zout); #endif /* we prefer do not use FPU */ - zint = ctx->zin / ctx->zout; - zfrac = (ctx->zin * 100 / ctx->zout) % 100; + zint = (ngx_uint_t) (ctx->zin / ctx->zout); + zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100); if ((ctx->zin * 1000 / ctx->zout) %10 > 4) { if (++zfrac > 99) { @@ -588,7 +590,8 @@ static char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, char *buf, } } - return buf + ngx_snprintf(buf, NGX_INT32_LEN + 4, "%d.%02d", zint, zfrac); + return buf + ngx_snprintf((char *) buf, NGX_INT32_LEN + 4, + "%d.%02d", zint, zfrac); } @@ -647,8 +650,10 @@ static void *ngx_http_gzip_create_conf(ngx_conf_t *cf) NGX_CONF_ERROR); conf->enable = NGX_CONF_UNSET; - /* conf->bufs.num = 0; */ conf->no_buffer = NGX_CONF_UNSET; + + /* conf->bufs.num = 0; */ + conf->level = NGX_CONF_UNSET; conf->wbits = NGX_CONF_UNSET; conf->memlevel = NGX_CONF_UNSET; @@ -667,9 +672,8 @@ static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf, ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, /* STUB: PAGE_SIZE */ 4096); ngx_conf_merge_value(conf->level, prev->level, 1); - ngx_conf_merge_size_value(conf->wbits, prev->wbits, MAX_WBITS); - ngx_conf_merge_size_value(conf->memlevel, prev->memlevel, - MAX_MEM_LEVEL - 1); + ngx_conf_merge_value(conf->wbits, prev->wbits, MAX_WBITS); + ngx_conf_merge_value(conf->memlevel, prev->memlevel, MAX_MEM_LEVEL - 1); ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0); return NGX_CONF_OK; diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c index bec9d653f..dd965d0cc 100644 --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -12,8 +12,8 @@ typedef struct { typedef struct { - ngx_int_t index; - char *last; + ngx_uint_t index; + u_char *last; ngx_str_t path; ngx_str_t redirect; ngx_http_cache_t *cache; @@ -97,7 +97,7 @@ ngx_module_t ngx_http_index_module = { int ngx_http_index_handler(ngx_http_request_t *r) { - char *name; + u_char *name; size_t len; ngx_fd_t fd; ngx_int_t rc; @@ -161,13 +161,13 @@ int ngx_http_index_handler(ngx_http_request_t *r) #endif - len = clcf->doc_root.len + r->uri.len + ilcf->max_index_len; + len = clcf->root.len + r->uri.len + ilcf->max_index_len; if (!(ctx->path.data = ngx_palloc(r->pool, len))) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } - ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->doc_root.data, - clcf->doc_root.len); + ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data, + clcf->root.len); ctx->last = ngx_cpystrn(ctx->redirect.data, r->uri.data, r->uri.len + 1); ctx->path.len = ctx->last - ctx->path.data; @@ -237,7 +237,7 @@ int ngx_http_index_handler(ngx_http_request_t *r) } else { ctx->redirect.len = r->uri.len + index[ctx->index].len; - r->file.name.len = clcf->doc_root.len + r->uri.len + r->file.name.len = clcf->root.len + r->uri.len + index[ctx->index].len; } @@ -387,7 +387,7 @@ static char *ngx_http_index_merge_loc_conf(ngx_conf_t *cf, ngx_http_index_loc_conf_t *prev = parent; ngx_http_index_loc_conf_t *conf = child; - int i; + ngx_uint_t i; ngx_str_t *index, *prev_index; if (conf->max_index_len == 0) { @@ -434,7 +434,7 @@ static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, { ngx_http_index_loc_conf_t *ilcf = conf; - int i; + ngx_uint_t i; ngx_str_t *index, *value; value = cf->args->elts; diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c index 676a9780f..3f3a6a3f1 100644 --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -44,7 +44,7 @@ typedef struct { } ngx_http_range_filter_ctx_t; -static int ngx_http_range_filter_init(ngx_cycle_t *cycle); +static ngx_int_t ngx_http_range_filter_init(ngx_cycle_t *cycle); static ngx_http_module_t ngx_http_range_filter_module_ctx = { @@ -75,10 +75,12 @@ static ngx_http_output_header_filter_pt ngx_http_next_header_filter; static ngx_http_output_body_filter_pt ngx_http_next_body_filter; -static int ngx_http_range_header_filter(ngx_http_request_t *r) +static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) { - ngx_int_t rc, boundary, suffix, len, i; - char *p; + ngx_int_t rc; + ngx_uint_t boundary, suffix, i; + u_char *p; + size_t len; off_t start, end; ngx_http_range_t *range; ngx_http_range_filter_ctx_t *ctx; @@ -235,9 +237,9 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) NGX_ERROR); r->headers_out.content_range->value.len = - ngx_snprintf(r->headers_out.content_range->value.data, - 8 + 20 + 1, "bytes */" OFF_T_FMT, - r->headers_out.content_length_n); + ngx_snprintf((char *) r->headers_out.content_range->value.data, + 8 + 20 + 1, "bytes */" OFF_T_FMT, + r->headers_out.content_length_n); r->headers_out.content_length_n = -1; if (r->headers_out.content_length) { @@ -268,7 +270,8 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ r->headers_out.content_range->value.len = - ngx_snprintf(r->headers_out.content_range->value.data, + 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, @@ -313,7 +316,7 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) if (r->headers_out.charset.len) { ctx->boundary_header.len = - ngx_snprintf(ctx->boundary_header.data, len, + ngx_snprintf((char *) ctx->boundary_header.data, len, CRLF "--%010u" CRLF "Content-Type: %s; charset=%s" CRLF "Content-Range: bytes ", @@ -325,7 +328,7 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) } else { ctx->boundary_header.len = - ngx_snprintf(ctx->boundary_header.data, len, + ngx_snprintf((char *) ctx->boundary_header.data, len, CRLF "--%010u" CRLF "Content-Type: %s" CRLF "Content-Range: bytes ", @@ -340,7 +343,8 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) /* "Content-Type: multipart/byteranges; boundary=0123456789" */ r->headers_out.content_type->value.len = - ngx_snprintf(r->headers_out.content_type->value.data, + ngx_snprintf((char *) + r->headers_out.content_type->value.data, 31 + 10 + 1, "multipart/byteranges; boundary=%010u", boundary); @@ -357,7 +361,7 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ range[i].content_range.len = - ngx_snprintf(range[i].content_range.data, + 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, @@ -376,9 +380,10 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r) } -static int ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in) +static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, + ngx_chain_t *in) { - int i; + ngx_uint_t i; ngx_hunk_t *h; ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; ngx_http_range_t *range; @@ -475,7 +480,7 @@ static int ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in) } -static int ngx_http_range_filter_init(ngx_cycle_t *cycle) +static ngx_int_t ngx_http_range_filter_init(ngx_cycle_t *cycle) { ngx_http_next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_range_header_filter; diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_handler.c index e06b54bf3..88c6a335f 100644 --- a/src/http/modules/ngx_http_rewrite_handler.c +++ b/src/http/modules/ngx_http_rewrite_handler.c @@ -82,10 +82,11 @@ ngx_module_t ngx_http_rewrite_module = { static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) { int *matches; - char *p; + u_char *p; size_t len; uintptr_t data; - ngx_int_t rc, i, n, m; + ngx_int_t rc; + ngx_uint_t i, m, n; ngx_str_t uri; ngx_http_rewrite_op_t *op; ngx_http_rewrite_rule_t *rule; @@ -134,7 +135,7 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) uri.len = rule[i].size; - for (n = 1; n < rc; n++) { + for (n = 1; n < (ngx_uint_t) rc; n++) { uri.len += matches[2 * n + 1] - matches[2 * n]; } @@ -150,7 +151,7 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) len = op[n].len; data = op[n].data; while (len--) { - *p++ = data & 0xff; + *p++ = (char) (data & 0xff); data >>= 8; } @@ -208,13 +209,13 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd, { ngx_http_rewrite_srv_conf_t *scf = conf; - char *data, *p; + u_char *data, *p; size_t len; ngx_str_t *value, err; ngx_uint_t i; ngx_http_rewrite_op_t *op; ngx_http_rewrite_rule_t *rule; - char errstr[NGX_MAX_CONF_ERRSTR]; + u_char errstr[NGX_MAX_CONF_ERRSTR]; if (!(rule = ngx_push_array(&scf->rules))) { return NGX_CONF_ERROR; diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter.c index 65ce128b9..f4ddb318e 100644 --- a/src/http/modules/ngx_http_ssi_filter.c +++ b/src/http/modules/ngx_http_ssi_filter.c @@ -15,8 +15,8 @@ typedef struct { - int enable; - ssize_t value_len; + ngx_flag_t enable; + size_t value_len; } ngx_http_ssi_conf_t; @@ -28,9 +28,9 @@ typedef struct { typedef struct { ngx_hunk_t *buf; - char *start; - char *last; - char *pos; + u_char *start; + u_char *last; + u_char *pos; ngx_str_t command; ngx_array_t params; @@ -41,7 +41,7 @@ typedef struct { ngx_chain_t **last_out; ngx_chain_t *busy; - int state; + ngx_uint_t state; size_t saved; } ngx_http_ssi_ctx_t; @@ -839,7 +839,7 @@ static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r, break; default: - if ((ssize_t) ctx->param->value.len >= conf->value_len) { + if (ctx->param->value.len >= conf->value_len) { ctx->last = last; ctx->pos = p; ctx->state = ssi_error_state; @@ -853,7 +853,7 @@ static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r, break; case ssi_double_quoted_value_quote_state: - if ((ssize_t) ctx->param->value.len >= conf->value_len) { + if (ctx->param->value.len >= conf->value_len) { ctx->last = last; ctx->pos = p; ctx->state = ssi_error_state; @@ -877,7 +877,7 @@ static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r, break; default: - if ((ssize_t) ctx->param->value.len >= conf->value_len) { + if (ctx->param->value.len >= conf->value_len) { ctx->last = last; ctx->pos = p; ctx->state = ssi_error_state; @@ -891,7 +891,7 @@ static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r, break; case ssi_quoted_value_quote_state: - if ((ssize_t) ctx->param->value.len >= conf->value_len) { + if (ctx->param->value.len >= conf->value_len) { ctx->last = last; ctx->pos = p; ctx->state = ssi_error_state; @@ -1006,7 +1006,7 @@ static void *ngx_http_ssi_create_conf(ngx_conf_t *cf) } conf->enable = NGX_CONF_UNSET; - conf->value_len = NGX_CONF_UNSET; + conf->value_len = NGX_CONF_UNSET_SIZE; return conf; } diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c index 7876d2a24..0576255eb 100644 --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -60,7 +60,7 @@ ngx_module_t ngx_http_static_module = { static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) { - char *last; + u_char *last; ngx_fd_t fd; ngx_int_t rc; ngx_uint_t level; @@ -115,14 +115,31 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) * in a possible redirect and for the last '\0' */ - name.data = ngx_palloc(r->pool, clcf->doc_root.len + r->uri.len + 2); + name.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len + 2 + - clcf->alias * clcf->name.len); if (name.data == NULL) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } - location.data = ngx_cpymem(name.data, clcf->doc_root.data, - clcf->doc_root.len); - last = ngx_cpystrn(location.data, r->uri.data, r->uri.len + 1); + location.data = ngx_cpymem(name.data, clcf->root.data, clcf->root.len); + + if (clcf->alias) { + last = ngx_cpystrn(location.data, r->uri.data + clcf->name.len, + r->uri.len + 1 - clcf->name.len); + + /* + * aliases usually have trailling "/", + * set it in the start of the possible redirect + */ + + if (*location.data != '/') { + location.data--; + } + + } else { + last = ngx_cpystrn(location.data, r->uri.data, r->uri.len + 1); + } + name.len = last - name.data; location.len = last - location.data + 1; diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index e382f05e2..d36867dba 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -7,12 +7,12 @@ static int ngx_http_proxy_handler(ngx_http_request_t *r); -static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, - uintptr_t data); -static char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, char *buf, - uintptr_t data); -static char *ngx_http_proxy_log_reason(ngx_http_request_t *r, char *buf, - uintptr_t data); +static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, + u_char *buf, uintptr_t data); +static u_char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, + u_char *buf, uintptr_t data); +static u_char *ngx_http_proxy_log_reason(ngx_http_request_t *r, u_char *buf, + uintptr_t data); static int ngx_http_proxy_pre_conf(ngx_conf_t *cf); static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf); @@ -146,7 +146,7 @@ static ngx_command_t ngx_http_proxy_commands[] = { ngx_conf_set_path_slot, NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_proxy_loc_conf_t, temp_path), - ngx_garbage_collector_temp_handler }, + (void *) ngx_garbage_collector_temp_handler }, { ngx_string("proxy_temp_file_write_size"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, @@ -591,7 +591,7 @@ void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p) ngx_close_socket_n " failed"); } - c->fd = -1; + c->fd = (ngx_socket_t) -1; } @@ -614,12 +614,12 @@ size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len) ctx->proxy->lcf->upstream->uri.data, r->uri.data + ctx->proxy->lcf->upstream->location->len, r->args.len ? "?" : "", - r->args.len ? r->args.data : ""); + r->args.len ? r->args.data : (u_char *) ""); } -static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, + u_char *buf, uintptr_t data) { ngx_http_proxy_ctx_t *p; @@ -644,7 +644,8 @@ static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, *buf++ = '-'; } else { - buf += ngx_snprintf(buf, NGX_TIME_T_LEN, TIME_T_FMT, p->state->expired); + buf += ngx_snprintf((char *) buf, NGX_TIME_T_LEN, + TIME_T_FMT, p->state->expired); } *buf++ = '/'; @@ -653,7 +654,8 @@ static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, *buf++ = '-'; } else { - buf += ngx_snprintf(buf, NGX_TIME_T_LEN, TIME_T_FMT, p->state->bl_time); + buf += ngx_snprintf((char *) buf, NGX_TIME_T_LEN, + TIME_T_FMT, p->state->bl_time); } *buf++ = '/'; @@ -666,7 +668,7 @@ static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, *buf++ = '-'; } else { - buf += ngx_snprintf(buf, 4, "%d", p->state->status); + buf += ngx_snprintf((char *) buf, 4, "%d", p->state->status); } *buf++ = '/'; @@ -685,7 +687,8 @@ static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, *buf++ = '-'; } else { - buf += ngx_snprintf(buf, NGX_TIME_T_LEN, TIME_T_FMT, p->state->expires); + buf += ngx_snprintf((char *) buf, NGX_TIME_T_LEN, + TIME_T_FMT, p->state->expires); } *buf++ = ' '; @@ -695,8 +698,8 @@ static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, } -static char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, + u_char *buf, uintptr_t data) { ngx_http_proxy_ctx_t *p; @@ -712,8 +715,8 @@ static char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, char *buf, } -static char *ngx_http_proxy_log_reason(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_proxy_log_reason(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { ngx_http_proxy_ctx_t *p; @@ -777,17 +780,17 @@ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) */ - conf->request_buffer_size = NGX_CONF_UNSET; - conf->connect_timeout = NGX_CONF_UNSET; - conf->send_timeout = NGX_CONF_UNSET; + conf->request_buffer_size = NGX_CONF_UNSET_SIZE; + conf->connect_timeout = NGX_CONF_UNSET_MSEC; + conf->send_timeout = NGX_CONF_UNSET_MSEC; conf->preserve_host = NGX_CONF_UNSET; conf->set_x_real_ip = NGX_CONF_UNSET; conf->add_x_forwarded_for = NGX_CONF_UNSET; - conf->header_buffer_size = NGX_CONF_UNSET; - conf->read_timeout = NGX_CONF_UNSET; - conf->busy_buffers_size = NGX_CONF_UNSET; + conf->header_buffer_size = NGX_CONF_UNSET_SIZE; + conf->read_timeout = NGX_CONF_UNSET_MSEC; + conf->busy_buffers_size = NGX_CONF_UNSET_SIZE; /* * "proxy_max_temp_file_size" is hardcoded to 1G for reverse proxy, @@ -795,7 +798,7 @@ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) */ conf->max_temp_file_size = 1024 * 1024 * 1024; - conf->temp_file_write_size = NGX_CONF_UNSET; + conf->temp_file_write_size = NGX_CONF_UNSET_SIZE; /* "proxy_cyclic_temp_file" is disabled */ conf->cyclic_temp_file = 0; @@ -906,8 +909,9 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, { ngx_http_proxy_loc_conf_t *lcf = conf; - int i, len; - char *err, *host; + ngx_uint_t i, len; + char *err; + u_char *host; in_addr_t addr; ngx_str_t *value; struct hostent *h; @@ -946,10 +950,10 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, /* AF_INET only */ - addr = inet_addr(host); + addr = inet_addr((char *) host); if (addr == INADDR_NONE) { - h = gethostbyname(host); + h = gethostbyname((char *) host); if (h == NULL || h->h_addr_list[0] == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "host %s not found", host); @@ -980,7 +984,7 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, NGX_CONF_ERROR); len = ngx_inet_ntop(AF_INET, - (char *) &lcf->peers->peers[i].addr, + (u_char *) &lcf->peers->peers[i].addr, lcf->peers->peers[i].addr_port_text.data, len); diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index dd9cd15fc..2e6cb8473 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -40,40 +40,40 @@ typedef struct { ngx_str_t host_header; ngx_str_t port_text; ngx_str_t *location; - int port; + + ngx_int_t port; + unsigned default_port:1; } ngx_http_proxy_upstream_conf_t; typedef struct { - ssize_t request_buffer_size; + size_t request_buffer_size; + size_t header_buffer_size; + size_t busy_buffers_size; + size_t max_temp_file_size; + size_t temp_file_write_size; + ngx_msec_t connect_timeout; ngx_msec_t send_timeout; - ssize_t header_buffer_size; ngx_msec_t read_timeout; + time_t default_expires; + + ngx_int_t lm_factor; + + ngx_uint_t next_upstream; + ngx_uint_t use_stale; ngx_bufs_t bufs; - ssize_t busy_buffers_size; - ssize_t max_temp_file_size; - ssize_t temp_file_write_size; ngx_flag_t cyclic_temp_file; - ngx_flag_t cache; - ngx_flag_t preserve_host; ngx_flag_t set_x_real_ip; ngx_flag_t add_x_forwarded_for; - ngx_flag_t pass_server; ngx_flag_t pass_x_accel_expires; - ngx_flag_t ignore_expires; - int lm_factor; - time_t default_expires; - - u_int next_upstream; - u_int use_stale; ngx_path_t *cache_path; ngx_path_t *temp_path; @@ -96,9 +96,9 @@ typedef struct { ngx_http_proxy_state_e cache_state; time_t expired; time_t bl_time; - int bl_state; + ngx_uint_t bl_state; - int status; + ngx_uint_t status; ngx_http_proxy_reason_e reason; time_t time; time_t expires; @@ -130,7 +130,7 @@ typedef struct { typedef struct { ngx_http_cache_ctx_t ctx; - int status; + ngx_uint_t status; ngx_str_t status_line; ngx_http_proxy_headers_in_t headers_in; @@ -139,9 +139,9 @@ typedef struct { typedef struct { ngx_peer_connection_t peer; - int status; + ngx_uint_t status; ngx_str_t status_line; - int method; + ngx_uint_t method; ngx_output_chain_ctx_t *output_chain_ctx; ngx_event_pipe_t *event_pipe; @@ -175,23 +175,23 @@ struct ngx_http_proxy_ctx_s { /* used to parse an upstream HTTP header */ - int status; - char *status_start; - char *status_end; - int status_count; - int parse_state; + ngx_uint_t status; + u_char *status_start; + u_char *status_end; + ngx_uint_t status_count; + ngx_uint_t parse_state; ngx_http_proxy_state_t *state; ngx_array_t states; /* of ngx_http_proxy_state_t */ - char *action; + u_char *action; ngx_http_log_ctx_t *saved_ctx; ngx_log_handler_pt saved_handler; }; typedef struct { - u_int connection; + ngx_uint_t connection; ngx_http_proxy_ctx_t *proxy; } ngx_http_proxy_log_ctx_t; diff --git a/src/http/modules/proxy/ngx_http_proxy_header.c b/src/http/modules/proxy/ngx_http_proxy_header.c index 0c44a5248..66a6bfe01 100644 --- a/src/http/modules/proxy/ngx_http_proxy_header.c +++ b/src/http/modules/proxy/ngx_http_proxy_header.c @@ -11,7 +11,7 @@ static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p, int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p, ngx_http_proxy_headers_in_t *headers_in) { - int i; + ngx_uint_t i; ngx_table_elt_t *ho, *h; ngx_http_request_t *r; @@ -97,7 +97,7 @@ int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p, static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p, ngx_table_elt_t *loc) { - char *last; + u_char *last; ngx_http_request_t *r; ngx_http_proxy_upstream_conf_t *uc; diff --git a/src/http/modules/proxy/ngx_http_proxy_parse.c b/src/http/modules/proxy/ngx_http_proxy_parse.c index a69795850..5e76dc043 100644 --- a/src/http/modules/proxy/ngx_http_proxy_parse.c +++ b/src/http/modules/proxy/ngx_http_proxy_parse.c @@ -7,8 +7,8 @@ int ngx_http_proxy_parse_status_line(ngx_http_proxy_ctx_t *p) { - char ch; - char *pos; + u_char ch; + u_char *pos; enum { sw_start = 0, sw_H, diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index dc55050bf..7704cb1ce 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -98,8 +98,8 @@ int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p) static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) { - int i; size_t len; + ngx_uint_t i; ngx_hunk_t *h; ngx_chain_t *chain; ngx_table_elt_t *header; diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index 234992d58..9d53d8861 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -46,8 +46,8 @@ ngx_module_t ngx_http_module = { static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - int mi, m, s, l, p, a, n; - int port_found, addr_found, virtual_names; + ngx_uint_t mi, m, s, l, p, a, n; + ngx_uint_t port_found, addr_found, virtual_names; char *rv; struct sockaddr_in *addr_in; ngx_conf_t pcf; @@ -304,10 +304,8 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) * serves this address:port */ - if (lscf[l].flags & NGX_HTTP_DEFAULT_SERVER) { - if (in_addr[a].flags - & NGX_HTTP_DEFAULT_SERVER) { - + if (lscf[l].default_server) { + if (in_addr[a].default_server) { ngx_log_error(NGX_LOG_ERR, cf->log, 0, "duplicate default server in %s:%d", lscf[l].file_name.data, @@ -316,8 +314,8 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_ERROR; } - in_addr[a].flags |= NGX_HTTP_DEFAULT_SERVER; in_addr[a].core_srv_conf = cscfp[s]; + in_addr[a].default_server = 1; } addr_found = 1; @@ -340,7 +338,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) sizeof(ngx_http_in_addr_t)); in_addr[a].addr = lscf[l].addr; - in_addr[a].flags = lscf[l].flags; + in_addr[a].default_server = lscf[l].default_server; in_addr[a].core_srv_conf = cscfp[s]; /* @@ -370,7 +368,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) NGX_CONF_ERROR); inaddr->addr = lscf[l].addr; - inaddr->flags = lscf[l].flags; + inaddr->default_server = lscf[l].default_server; inaddr->core_srv_conf = cscfp[s]; /* @@ -397,7 +395,8 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_test_null(in_port->port_name.data, ngx_palloc(cf->pool, 7), NGX_CONF_ERROR); - in_port->port_name.len = ngx_snprintf(in_port->port_name.data, + in_port->port_name.len = ngx_snprintf((char *) + in_port->port_name.data, 7, ":%d", in_port->port); @@ -413,7 +412,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) /* ... and add the address to this list */ inaddr->addr = lscf[l].addr; - inaddr->flags = lscf[l].flags; + inaddr->default_server = lscf[l].default_server; inaddr->core_srv_conf = cscfp[s]; /* @@ -495,14 +494,15 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) NGX_CONF_ERROR); ls->addr_text.len = - ngx_snprintf(ls->addr_text.data + ngx_snprintf((char *) ls->addr_text.data + ngx_inet_ntop(AF_INET, - (char *) &in_addr[a].addr, + (u_char *) + &in_addr[a].addr, ls->addr_text.data, INET_ADDRSTRLEN), 6, ":%d", in_port[p].port); - ls->fd = -1; + ls->fd = (ngx_socket_t) -1; ls->family = AF_INET; ls->type = SOCK_STREAM; ls->protocol = IPPROTO_IP; @@ -596,8 +596,8 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) "port: %d %08x", in_port[p].port, &in_port[p]); in_addr = in_port[p].addrs.elts; for (a = 0; a < in_port[p].addrs.nelts; a++) { - char ip[20]; - ngx_inet_ntop(AF_INET, (char *) &in_addr[a].addr, ip, 20); + u_char ip[20]; + ngx_inet_ntop(AF_INET, (u_char *) &in_addr[a].addr, ip, 20); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0, "%s %08x", ip, in_addr[a].core_srv_conf); s_name = in_addr[a].names.elts; diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h index ff4bc2b4c..35879d41c 100644 --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -22,10 +22,10 @@ typedef struct ngx_http_cleanup_s ngx_http_cleanup_t; typedef struct { - u_int connection; - char *action; - char *client; - char *url; + u_int connection; + u_char *action; + u_char *client; + u_char *url; } ngx_http_log_ctx_t; @@ -69,14 +69,14 @@ void ngx_http_close_request(ngx_http_request_t *r, int error); void ngx_http_close_connection(ngx_connection_t *c); -int ngx_http_read_client_request_body(ngx_http_request_t *r, - int request_buffer_size); +ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r, + size_t request_buffer_size); int ngx_http_send_header(ngx_http_request_t *r); int ngx_http_special_response_handler(ngx_http_request_t *r, int error); -time_t ngx_http_parse_time(char *value, size_t len); +time_t ngx_http_parse_time(u_char *value, size_t len); size_t ngx_http_get_time(char *buf, time_t t); ngx_table_elt_t *ngx_http_add_header(void *header, ngx_http_header_t *http_headers); diff --git a/src/http/ngx_http_busy_lock.c b/src/http/ngx_http_busy_lock.c index dac6f59e9..4bef15a60 100644 --- a/src/http/ngx_http_busy_lock.c +++ b/src/http/ngx_http_busy_lock.c @@ -190,7 +190,7 @@ char *ngx_http_set_busy_lock_slot(ngx_conf_t *cf, ngx_command_t *cmd, { char *p = conf; - int i, dup, invalid; + ngx_uint_t i, dup, invalid; ngx_str_t *value, line; ngx_http_busy_lock_t *bl, **blp; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index ebec1d23c..d95e8f15d 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -28,6 +28,7 @@ static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -129,9 +130,16 @@ static ngx_command_t ngx_http_core_commands[] = { { ngx_string("root"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, - ngx_conf_set_str_slot, + ngx_set_root, + NGX_HTTP_LOC_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("alias"), + NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_set_root, NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_core_loc_conf_t, doc_root), + 0, NULL }, { ngx_string("client_body_timeout"), @@ -382,12 +390,12 @@ static void ngx_http_run_phases(ngx_http_request_t *r) clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - if (!(path = ngx_palloc(r->pool, clcf->doc_root.len + r->uri.len))) { + if (!(path = ngx_palloc(r->pool, clcf->root.len + r->uri.len))) { ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); return; } - ngx_cpystrn(ngx_cpymem(path, clcf->doc_root.data, clcf->doc_root.len), + ngx_cpystrn(ngx_cpymem(path, clcf->root.data, clcf->root.len), r->uri.data, r->uri.len + 1); ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, @@ -406,7 +414,8 @@ static void ngx_http_run_phases(ngx_http_request_t *r) int ngx_http_find_location_config(ngx_http_request_t *r) { - ngx_int_t i, rc, exact; + int rc; + ngx_uint_t i, exact; ngx_str_t *auto_redirect; ngx_http_core_loc_conf_t *clcf, **clcfp; ngx_http_core_srv_conf_t *cscf; @@ -544,7 +553,7 @@ int ngx_http_find_location_config(ngx_http_request_t *r) ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r) { uint32_t key; - ngx_int_t i; + ngx_uint_t i; ngx_http_type_t *type; ngx_http_core_loc_conf_t *clcf; @@ -856,7 +865,7 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) ngx_http_core_loc_conf_t *clcf, **clcfp; #if (HAVE_PCRE) ngx_str_t err; - char errstr[NGX_MAX_CONF_ERRSTR]; + u_char errstr[NGX_MAX_CONF_ERRSTR]; #endif if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) { @@ -973,7 +982,8 @@ static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) { ngx_http_core_loc_conf_t *lcf = conf; - int i, key; + uint32_t key; + ngx_uint_t i; ngx_str_t *args; ngx_http_type_t *type; @@ -1021,9 +1031,11 @@ static void *ngx_http_core_create_main_conf(ngx_conf_t *cf) static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) { +#if 0 ngx_http_core_main_conf_t *cmcf = conf; /* TODO: remove it if no directives */ +#endif return NGX_CONF_OK; } @@ -1044,11 +1056,11 @@ static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf) ngx_init_array(cscf->server_names, cf->pool, 5, sizeof(ngx_http_server_name_t), NGX_CONF_ERROR); - cscf->connection_pool_size = NGX_CONF_UNSET; - cscf->post_accept_timeout = NGX_CONF_UNSET; - cscf->request_pool_size = NGX_CONF_UNSET; - cscf->client_header_timeout = NGX_CONF_UNSET; - cscf->client_header_buffer_size = NGX_CONF_UNSET; + cscf->connection_pool_size = NGX_CONF_UNSET_SIZE; + cscf->post_accept_timeout = NGX_CONF_UNSET_MSEC; + cscf->request_pool_size = NGX_CONF_UNSET_SIZE; + cscf->client_header_timeout = NGX_CONF_UNSET_MSEC; + cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE; cscf->large_client_header = NGX_CONF_UNSET; return cscf; @@ -1083,7 +1095,7 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, ngx_test_null(n->name.data, ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN), NGX_CONF_ERROR); - if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) { + if (gethostname((char *) n->name.data, NGX_MAXHOSTNAMELEN) == -1) { ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, "gethostname() failed"); return NGX_CONF_ERROR; @@ -1120,8 +1132,8 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) /* set by ngx_pcalloc(): - lcf->doc_root.len = 0; - lcf->doc_root.data = NULL; + lcf->root.len = 0; + lcf->root.data = NULL; lcf->types = NULL; lcf->default_type.len = 0; lcf->default_type.data = NULL; @@ -1131,18 +1143,19 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) lcf->regex = NULL; lcf->exact_match = 0; lcf->auto_redirect = 0; + lcf->alias = 0; */ - lcf->client_body_timeout = NGX_CONF_UNSET; + lcf->client_body_timeout = NGX_CONF_UNSET_MSEC; lcf->sendfile = NGX_CONF_UNSET; lcf->tcp_nopush = NGX_CONF_UNSET; - lcf->send_timeout = NGX_CONF_UNSET; - lcf->send_lowat = NGX_CONF_UNSET; - lcf->discarded_buffer_size = NGX_CONF_UNSET; - lcf->keepalive_timeout = NGX_CONF_UNSET; - lcf->lingering_time = NGX_CONF_UNSET; - lcf->lingering_timeout = NGX_CONF_UNSET; + lcf->send_timeout = NGX_CONF_UNSET_MSEC; + lcf->send_lowat = NGX_CONF_UNSET_SIZE; + lcf->discarded_buffer_size = NGX_CONF_UNSET_SIZE; + lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; + lcf->lingering_time = NGX_CONF_UNSET_MSEC; + lcf->lingering_timeout = NGX_CONF_UNSET_MSEC; lcf->msie_padding = NGX_CONF_UNSET; @@ -1167,7 +1180,7 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, int i, key; ngx_http_type_t *t; - ngx_conf_merge_str_value(conf->doc_root, prev->doc_root, "html"); + ngx_conf_merge_str_value(conf->root, prev->root, "html"); if (conf->types == NULL) { if (prev->types) { @@ -1241,7 +1254,7 @@ static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_srv_conf_t *scf = conf; - char *addr; + u_char *addr; u_int p; struct hostent *h; ngx_str_t *args; @@ -1255,7 +1268,7 @@ static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) /* AF_INET only */ ls->family = AF_INET; - ls->flags = 0; + ls->default_server = 0; ls->file_name = cf->conf_file->file.name; ls->line = cf->conf_file->line; @@ -1295,9 +1308,9 @@ static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_OK; } - ls->addr = inet_addr(addr); + ls->addr = inet_addr((const char *) addr); if (ls->addr == INADDR_NONE) { - h = gethostbyname(addr); + h = gethostbyname((const char *) addr); if (h == NULL || h->h_addr_list[0] == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, @@ -1317,7 +1330,7 @@ static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_srv_conf_t *scf = conf; - int i; + ngx_uint_t i; ngx_str_t *value; ngx_http_server_name_t *sn; @@ -1346,11 +1359,44 @@ static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } +static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_http_core_loc_conf_t *lcf = conf; + + ngx_uint_t alias; + ngx_str_t *value; + + alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0; + + if (lcf->root.data) { + if (lcf->alias == alias) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"%s\" directive is duplicate", + cmd->name.data); + } else { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"%s\" directive is duplicate, " + "\"%s\" directive is specified before", + cmd->name.data, lcf->alias ? "alias" : "root"); + } + + return NGX_CONF_ERROR; + } + + value = cf->args->elts; + + lcf->alias = alias; + lcf->root = value[1]; + + return NGX_CONF_OK; +} + + static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *lcf = conf; - int i; + ngx_uint_t i; ngx_str_t *value; ngx_http_err_page_t *err; @@ -1403,7 +1449,7 @@ static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data) { #if (HAVE_LOWAT_EVENT) - int *np = data; + ssize_t *np = data; if (*np >= ngx_freebsd_net_inet_tcp_sendspace) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index a6738e699..e4c624d59 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -11,9 +11,10 @@ typedef struct { in_addr_t addr; int port; int family; - int flags; /* 'default' */ ngx_str_t file_name; int line; + + unsigned default_server:1; } ngx_http_listen_t; @@ -27,7 +28,7 @@ typedef enum { typedef struct { ngx_array_t handlers; - int type; /* NGX_OK, NGX_DECLINED */ + ngx_int_t type; /* NGX_OK, NGX_DECLINED */ } ngx_http_phase_t; @@ -50,12 +51,14 @@ typedef struct { ngx_http_conf_ctx_t *ctx; /* server ctx */ + size_t connection_pool_size; + size_t request_pool_size; + size_t client_header_buffer_size; + ngx_msec_t post_accept_timeout; - ssize_t connection_pool_size; - ssize_t request_pool_size; ngx_msec_t client_header_timeout; - ssize_t client_header_buffer_size; - int large_client_header; + + ngx_flag_t large_client_header; } ngx_http_core_srv_conf_t; @@ -73,11 +76,9 @@ typedef struct { ngx_array_t names; /* array of ngx_http_server_name_t */ ngx_http_core_srv_conf_t *core_srv_conf; /* default server conf for this address:port */ - int flags; -} ngx_http_in_addr_t; -/* ngx_http_in_addr_t's flags */ -#define NGX_HTTP_DEFAULT_SERVER 1 + unsigned default_server:1; +} ngx_http_in_addr_t; typedef struct { @@ -115,22 +116,24 @@ typedef struct { int (*handler) (ngx_http_request_t *r); - ngx_str_t doc_root; /* root */ + ngx_str_t root; /* root, alias */ ngx_array_t *types; ngx_str_t default_type; + size_t send_lowat; /* send_lowat */ + size_t discarded_buffer_size; /* discarded_buffer_size */ + ngx_msec_t client_body_timeout; /* client_body_timeout */ - int sendfile; /* sendfile */ - int tcp_nopush; /* tcp_nopush */ ngx_msec_t send_timeout; /* send_timeout */ - ssize_t send_lowat; /* send_lowat */ - ssize_t discarded_buffer_size; /* discarded_buffer_size */ ngx_msec_t keepalive_timeout; /* keepalive_timeout */ ngx_msec_t lingering_time; /* lingering_time */ ngx_msec_t lingering_timeout; /* lingering_timeout */ - int msie_padding; /* msie_padding */ + ngx_flag_t sendfile; /* sendfile */ + ngx_flag_t tcp_nopush; /* tcp_nopush */ + ngx_flag_t msie_padding; /* msie_padding */ + ngx_array_t *error_pages; /* error_page */ ngx_http_cache_hash_t *open_files; @@ -141,6 +144,7 @@ typedef struct { unsigned exact_match:1; unsigned auto_redirect:1; + unsigned alias:1; ngx_log_t *err_log; } ngx_http_core_loc_conf_t; diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c index 801ab993e..d399daae1 100644 --- a/src/http/ngx_http_header_filter.c +++ b/src/http/ngx_http_header_filter.c @@ -92,8 +92,9 @@ static ngx_str_t http_codes[] = { static int ngx_http_header_filter(ngx_http_request_t *r) { - int len, status, i; - char *p; + u_char *p; + size_t len; + ngx_uint_t status, i; ngx_hunk_t *h; ngx_chain_t *ln; ngx_table_elt_t *header; @@ -246,7 +247,7 @@ static int ngx_http_header_filter(ngx_http_request_t *r) if (r->headers_out.content_length == NULL) { if (r->headers_out.content_length_n >= 0) { - h->last += ngx_snprintf(h->last, + h->last += ngx_snprintf((char *) h->last, sizeof("Content-Length: ") + NGX_OFF_T_LEN + 2, "Content-Length: " OFF_T_FMT CRLF, r->headers_out.content_length_n); diff --git a/src/http/ngx_http_headers.c b/src/http/ngx_http_headers.c index 83fcae5cb..900323a96 100644 --- a/src/http/ngx_http_headers.c +++ b/src/http/ngx_http_headers.c @@ -60,8 +60,8 @@ ngx_http_header_t ngx_http_headers_out[] = { ngx_table_elt_t *ngx_http_add_header(void *header, ngx_http_header_t *http_headers) { - int i, j; char *prev; + ngx_uint_t i, j; ngx_table_t *headers; ngx_table_elt_t *h, *new; diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c index f2ac5a33b..c46b119f5 100644 --- a/src/http/ngx_http_log_handler.c +++ b/src/http/ngx_http_log_handler.c @@ -5,35 +5,35 @@ #include <nginx.h> -static char *ngx_http_log_addr(ngx_http_request_t *r, char *buf, - uintptr_t data); -static char *ngx_http_log_connection(ngx_http_request_t *r, char *buf, - uintptr_t data); -static char *ngx_http_log_pipe(ngx_http_request_t *r, char *buf, - uintptr_t data); -static char *ngx_http_log_time(ngx_http_request_t *r, char *buf, - uintptr_t data); -static char *ngx_http_log_request(ngx_http_request_t *r, char *buf, - uintptr_t data); -static char *ngx_http_log_status(ngx_http_request_t *r, char *buf, +static u_char *ngx_http_log_addr(ngx_http_request_t *r, u_char *buf, uintptr_t data); -static char *ngx_http_log_length(ngx_http_request_t *r, char *buf, +static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, + uintptr_t data); +static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, uintptr_t data); -static char *ngx_http_log_apache_length(ngx_http_request_t *r, char *buf, - uintptr_t data); -static char *ngx_http_log_header_in(ngx_http_request_t *r, char *buf, +static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, + uintptr_t data); +static u_char *ngx_http_log_request(ngx_http_request_t *r, u_char *buf, uintptr_t data); -static char *ngx_http_log_connection_header_out(ngx_http_request_t *r, - char *buf, uintptr_t data); -static char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, - char *buf, - uintptr_t data); -static char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, char *buf, - uintptr_t data); -static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf, - uintptr_t data); -static char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, char *buf, - uintptr_t data); +static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, + uintptr_t data); +static u_char *ngx_http_log_length(ngx_http_request_t *r, u_char *buf, + uintptr_t data); +static u_char *ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf, + uintptr_t data); +static u_char *ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf, + uintptr_t data); +static u_char *ngx_http_log_connection_header_out(ngx_http_request_t *r, + u_char *buf, uintptr_t data); +static u_char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, + u_char *buf, + uintptr_t data); +static u_char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, + u_char *buf, uintptr_t data); +static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf, + uintptr_t data); +static u_char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, u_char *buf, + uintptr_t data); static int ngx_http_log_pre_conf(ngx_conf_t *cf); static void *ngx_http_log_create_main_conf(ngx_conf_t *cf); @@ -118,9 +118,9 @@ ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = { int ngx_http_log_handler(ngx_http_request_t *r) { - int i, l; - u_int data; - char *line, *p; + ngx_uint_t i, l; + uintptr_t data; + u_char *line, *p; size_t len; ngx_http_log_t *log; ngx_http_log_op_t *op; @@ -162,7 +162,7 @@ int ngx_http_log_handler(ngx_http_request_t *r) len = op[i].len; data = op[i].data; while (len--) { - *p++ = data & 0xff; + *p++ = (char) (data & 0xff); data >>= 8; } @@ -187,22 +187,24 @@ int ngx_http_log_handler(ngx_http_request_t *r) } -static char *ngx_http_log_addr(ngx_http_request_t *r, char *buf, uintptr_t data) +static u_char *ngx_http_log_addr(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { return ngx_cpymem(buf, r->connection->addr_text.data, r->connection->addr_text.len); } -static char *ngx_http_log_connection(ngx_http_request_t *r, char *buf, +static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, uintptr_t data) { - return buf + ngx_snprintf(buf, NGX_INT32_LEN + 1, "%u", + return buf + ngx_snprintf((char *) buf, NGX_INT32_LEN + 1, "%u", r->connection->number); } -static char *ngx_http_log_pipe(ngx_http_request_t *r, char *buf, uintptr_t data) +static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { if (r->pipeline) { *buf = 'p'; @@ -214,53 +216,54 @@ static char *ngx_http_log_pipe(ngx_http_request_t *r, char *buf, uintptr_t data) } -static char *ngx_http_log_time(ngx_http_request_t *r, char *buf, uintptr_t data) +static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { return ngx_cpymem(buf, ngx_cached_http_log_time.data, ngx_cached_http_log_time.len); } -static char *ngx_http_log_request(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_log_request(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { if (buf == NULL) { /* find the request line length */ - return (char *) r->request_line.len; + return (u_char *) r->request_line.len; } return ngx_cpymem(buf, r->request_line.data, r->request_line.len); } -static char *ngx_http_log_status(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { - return buf + ngx_snprintf(buf, 4, "%d", + return buf + ngx_snprintf((char *) buf, 4, "%d", r->err_status ? r->err_status : r->headers_out.status); } -static char *ngx_http_log_length(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_log_length(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { - return buf + ngx_snprintf(buf, NGX_OFF_T_LEN + 1, OFF_T_FMT, + return buf + ngx_snprintf((char *) buf, NGX_OFF_T_LEN + 1, OFF_T_FMT, r->connection->sent); } -static char *ngx_http_log_apache_length(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { - return buf + ngx_snprintf(buf, NGX_OFF_T_LEN + 1, OFF_T_FMT, + return buf + ngx_snprintf((char *) buf, NGX_OFF_T_LEN + 1, OFF_T_FMT, r->connection->sent - r->header_size); } -static char *ngx_http_log_header_in(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { - int i; + ngx_uint_t i; ngx_str_t *s; ngx_table_elt_t *h; ngx_http_log_op_t *op; @@ -281,7 +284,7 @@ static char *ngx_http_log_header_in(ngx_http_request_t *r, char *buf, if (buf == NULL) { /* find the header length */ - return (char *) h->value.len; + return (u_char *) h->value.len; } return ngx_cpymem(buf, h->value.data, h->value.len); @@ -315,10 +318,10 @@ static char *ngx_http_log_header_in(ngx_http_request_t *r, char *buf, } -static char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, + u_char *buf, uintptr_t data) { - int i; + ngx_uint_t i; ngx_str_t *s; ngx_table_elt_t *h; @@ -333,7 +336,7 @@ static char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, char *buf, if (ngx_strncasecmp(h[i].key.data, s->data, s->len) == 0) { if (buf == NULL) { /* find the header length */ - return (char *) h[i].value.len; + return (u_char *) h[i].value.len; } return ngx_cpymem(buf, h[i].value.data, h[i].value.len); @@ -350,10 +353,10 @@ static char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, char *buf, } -static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf, + uintptr_t data) { - int i; + ngx_uint_t i; ngx_str_t *s; ngx_table_elt_t *h; ngx_http_log_op_t *op; @@ -384,7 +387,7 @@ static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf, if (data == offsetof(ngx_http_headers_out_t, date)) { if (buf == NULL) { - return (char *) ngx_cached_http_time.len; + return (u_char *) ngx_cached_http_time.len; } return ngx_cpymem(buf, ngx_cached_http_time.data, ngx_cached_http_time.len); @@ -392,7 +395,7 @@ static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf, if (data == offsetof(ngx_http_headers_out_t, server)) { if (buf == NULL) { - return (char *) (sizeof(NGINX_VER) - 1); + return (u_char *) (sizeof(NGINX_VER) - 1); } return ngx_cpymem(buf, NGINX_VER, sizeof(NGINX_VER) - 1); } @@ -406,9 +409,10 @@ static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf, } if (buf == NULL) { - return (char *) NGX_OFF_T_LEN; + return (u_char *) NGX_OFF_T_LEN; } - return buf + ngx_snprintf(buf, NGX_OFF_T_LEN + 2, OFF_T_FMT, + return buf + ngx_snprintf((char *) buf, + NGX_OFF_T_LEN + 2, OFF_T_FMT, r->headers_out.content_length_n); } @@ -421,7 +425,8 @@ static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf, } if (buf == NULL) { - return (char *) sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1; + return (u_char *) + sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1; } return buf + ngx_http_time(buf, r->headers_out.last_modified_time); @@ -436,7 +441,7 @@ static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf, if (buf == NULL) { /* find the header length */ - return (char *) h->value.len; + return (u_char *) h->value.len; } return ngx_cpymem(buf, h->value.data, h->value.len); @@ -485,12 +490,12 @@ static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf, } -static char *ngx_http_log_connection_header_out(ngx_http_request_t *r, - char *buf, uintptr_t data) +static u_char *ngx_http_log_connection_header_out(ngx_http_request_t *r, + u_char *buf, uintptr_t data) { if (buf == NULL) { - return (char *) ((r->keepalive) ? sizeof("keep-alive") - 1: - sizeof("close") - 1); + return (u_char *) ((r->keepalive) ? sizeof("keep-alive") - 1: + sizeof("close") - 1); } if (r->keepalive) { @@ -502,12 +507,12 @@ static char *ngx_http_log_connection_header_out(ngx_http_request_t *r, } -static char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, - char *buf, - uintptr_t data) +static u_char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, + u_char *buf, + uintptr_t data) { if (buf == NULL) { - return (char *) ((r->chunked) ? sizeof("chunked") - 1 : 1); + return (u_char *) ((r->chunked) ? sizeof("chunked") - 1 : 1); } if (r->chunked) { @@ -520,10 +525,11 @@ static char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, } -static char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, char *buf, - uintptr_t data) +static u_char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, + u_char *buf, + uintptr_t data) { - int i; + ngx_uint_t i; ngx_str_t *s; ngx_table_elt_t *h; @@ -538,7 +544,7 @@ static char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, char *buf, if (ngx_strncasecmp(h[i].key.data, s->data, s->len) == 0) { if (buf == NULL) { /* find the header length */ - return (char *) h[i].value.len; + return (u_char *) h[i].value.len; } return ngx_cpymem(buf, h[i].value.data, h[i].value.len); @@ -665,7 +671,7 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, { ngx_http_log_loc_conf_t *llcf = conf; - int i; + ngx_uint_t i; ngx_str_t *value, name; ngx_http_log_t *log; ngx_http_log_fmt_t *fmt; @@ -715,8 +721,8 @@ static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, { ngx_http_log_main_conf_t *lmcf = conf; - int s, f, invalid; - char *data, *p, *fname; + ngx_uint_t s, f, invalid; + u_char *data, *p, *fname; size_t i, len, fname_len; ngx_str_t *value, arg, *a; ngx_http_log_op_t *op; @@ -843,7 +849,7 @@ static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, } *a = arg; - name->op(NULL, (char *) op, (uintptr_t) a); + name->op(NULL, (u_char *) op, (uintptr_t) a); break; } diff --git a/src/http/ngx_http_log_handler.h b/src/http/ngx_http_log_handler.h index c67a01b6f..2ffc61ae2 100644 --- a/src/http/ngx_http_log_handler.h +++ b/src/http/ngx_http_log_handler.h @@ -7,8 +7,8 @@ #include <ngx_http.h> -typedef char *(*ngx_http_log_op_pt) (ngx_http_request_t *r, char *buf, - uintptr_t data); +typedef u_char *(*ngx_http_log_op_pt) (ngx_http_request_t *r, u_char *buf, + uintptr_t data); #define NGX_HTTP_LOG_COPY_SHORT (ngx_http_log_op_pt) 0 #define NGX_HTTP_LOG_COPY_LONG (ngx_http_log_op_pt) -1 diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c index ad9dac085..c86024539 100644 --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c @@ -5,7 +5,7 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r) { - char ch, *p; + u_char ch, *p; enum { sw_start = 0, sw_G, @@ -421,7 +421,7 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r) ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_hunk_t *h) { - char c, ch, *p; + u_char c, ch, *p; enum { sw_start = 0, sw_name, @@ -458,7 +458,7 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_hunk_t *h) state = sw_name; r->header_name_start = p - 1; - c = ch | 0x20; + c = (char) (ch | 0x20); if (c >= 'a' && c <= 'z') { break; } @@ -478,7 +478,7 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_hunk_t *h) /* header name */ case sw_name: - c = ch | 0x20; + c = (u_char) (ch | 0x20); if (c >= 'a' && c <= 'z') { break; } @@ -623,7 +623,7 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_hunk_t *h) ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) { - char c, ch, decoded, *p, *u; + u_char c, ch, decoded, *p, *u; enum { sw_usual = 0, sw_slash, @@ -778,15 +778,15 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) case sw_quoted: if (ch >= '0' && ch <= '9') { - decoded = ch - '0'; + decoded = (char) (ch - '0'); state = sw_quoted_second; ch = *p++; break; } - c = ch | 0x20; + c = (char) (ch | 0x20); if (c >= 'a' && c <= 'f') { - decoded = c - 'a' + 10; + decoded = (char) (c - 'a' + 10); state = sw_quoted_second; ch = *p++; break; @@ -796,7 +796,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) case sw_quoted_second: if (ch >= '0' && ch <= '9') { - ch = (decoded << 4) + ch - '0'; + ch = (char) ((decoded << 4) + ch - '0'); if (ch == '%') { state = sw_usual; *u++ = ch; @@ -807,9 +807,9 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) break; } - c = ch | 0x20; + c = (char) (ch | 0x20); if (c >= 'a' && c <= 'f') { - ch = (decoded << 4) + c - 'a' + 10; + ch = (char) ((decoded << 4) + c - 'a' + 10); if (ch == '%') { state = sw_usual; *u++ = ch; diff --git a/src/http/ngx_http_parse_time.c b/src/http/ngx_http_parse_time.c index 6b98bad43..ea2a22474 100644 --- a/src/http/ngx_http_parse_time.c +++ b/src/http/ngx_http_parse_time.c @@ -6,10 +6,10 @@ static int mday[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; -time_t ngx_http_parse_time(char *value, size_t len) +time_t ngx_http_parse_time(u_char *value, size_t len) { - char *p, *end; - int day, month, year, hour, min, sec; + u_char *p, *end; + int day, month, year, hour, min, sec; enum { no = 0, rfc822, /* Tue 10 Nov 2002 23:50:13 */ diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index f79dc2af2..4113279c1 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -115,7 +115,7 @@ void ngx_http_init_connection(ngx_connection_t *c) static void ngx_http_init_request(ngx_event_t *rev) { - ngx_int_t i; + ngx_uint_t i; socklen_t len; struct sockaddr_in addr_in; ngx_connection_t *c; @@ -182,12 +182,13 @@ static void ngx_http_init_request(ngx_event_t *rev) ngx_http_close_connection(c); return; } + + r->in_addr = addr_in.sin_addr.s_addr; + #if (WIN32) } #endif - r->in_addr = addr_in.sin_addr.s_addr; - /* the last in_port->addrs address is "*" */ for ( /* void */ ; i < in_port->addrs.nelts - 1; i++) { @@ -279,7 +280,7 @@ static void ngx_http_init_request(ngx_event_t *rev) static void ngx_http_process_request_line(ngx_event_t *rev) { - char *p; + u_char *p; ssize_t n; ngx_int_t rc, offset; ngx_connection_t *c; @@ -453,11 +454,12 @@ static void ngx_http_process_request_line(ngx_event_t *rev) "http uri: \"%s\"", r->uri.data); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http args: \"%s\"", r->args.data ? r->args.data : ""); + "http args: \"%s\"", + r->args.data ? r->args.data : (u_char *) ""); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http exten: \"%s\"", - r->exten.data ? r->exten.data : ""); + r->exten.data ? r->exten.data : (u_char *) ""); if (r->http_version < NGX_HTTP_VERSION_10) { rev->event_handler = ngx_http_block_read; @@ -681,7 +683,7 @@ static void ngx_http_process_request_headers(ngx_event_t *rev) #if (NGX_LOG_DEBUG) if (rc == NGX_HTTP_PARSE_INVALID_HEADER) { - char *p; + u_char *p; for (p = r->header_name_start; p < r->header_in->last - 1; p++) @@ -794,7 +796,7 @@ static ssize_t ngx_http_read_request_header(ngx_http_request_t *r) static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r) { size_t len; - ngx_int_t i; + ngx_uint_t i; ngx_http_server_name_t *name; ngx_http_core_loc_conf_t *clcf; @@ -1133,8 +1135,8 @@ static int ngx_http_read_discarded_body(ngx_http_request_t *r) size = r->headers_in.content_length_n; - if (size > clcf->discarded_buffer_size) { - size = clcf->discarded_buffer_size; + if (size > (ssize_t) clcf->discarded_buffer_size) { + size = (ssize_t) clcf->discarded_buffer_size; } n = ngx_recv(r->connection, r->discarded_buffer, size); @@ -1396,7 +1398,8 @@ static void ngx_http_lingering_close_handler(ngx_event_t *rev) instead of r->header_in->last */ if (r->header_in->end - r->header_in->last - >= clcf->discarded_buffer_size) { + >= (ssize_t) clcf->discarded_buffer_size) + { r->discarded_buffer = r->header_in->last; } else { @@ -1458,7 +1461,7 @@ int ngx_http_send_last(ngx_http_request_t *r) void ngx_http_close_request(ngx_http_request_t *r, int error) { - ngx_int_t i; + ngx_uint_t i; ngx_log_t *log; ngx_http_log_ctx_t *ctx; ngx_http_cleanup_t *cleanup; @@ -1559,7 +1562,7 @@ void ngx_http_close_connection(ngx_connection_t *c) ngx_close_socket_n " failed"); } - c->fd = -1; + c->fd = (ngx_socket_t) -1; c->data = NULL; ngx_destroy_pool(c->pool); diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index 770221210..68ab7cb14 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -2,34 +2,34 @@ #define _NGX_HTTP_REQUEST_H_INCLUDED_ -#define NGX_HTTP_VERSION_9 9 -#define NGX_HTTP_VERSION_10 1000 -#define NGX_HTTP_VERSION_11 1001 +#define NGX_HTTP_VERSION_9 9 +#define NGX_HTTP_VERSION_10 1000 +#define NGX_HTTP_VERSION_11 1001 -#define NGX_HTTP_GET 1 -#define NGX_HTTP_HEAD 2 -#define NGX_HTTP_POST 3 +#define NGX_HTTP_GET 1 +#define NGX_HTTP_HEAD 2 +#define NGX_HTTP_POST 3 -#define NGX_HTTP_CONNECTION_CLOSE 1 -#define NGX_HTTP_CONNECTION_KEEP_ALIVE 2 +#define NGX_HTTP_CONNECTION_CLOSE 1 +#define NGX_HTTP_CONNECTION_KEEP_ALIVE 2 -#define NGX_NONE 1 +#define NGX_NONE 1 -#define NGX_HTTP_PARSE_HEADER_DONE 1 +#define NGX_HTTP_PARSE_HEADER_DONE 1 -#define NGX_HTTP_CLIENT_ERROR 10 -#define NGX_HTTP_PARSE_INVALID_METHOD 10 -#define NGX_HTTP_PARSE_INVALID_REQUEST 11 -#define NGX_HTTP_PARSE_TOO_LONG_URI 12 -#define NGX_HTTP_PARSE_INVALID_09_METHOD 13 +#define NGX_HTTP_CLIENT_ERROR 10 +#define NGX_HTTP_PARSE_INVALID_METHOD 10 +#define NGX_HTTP_PARSE_INVALID_REQUEST 11 +#define NGX_HTTP_PARSE_TOO_LONG_URI 12 +#define NGX_HTTP_PARSE_INVALID_09_METHOD 13 -#define NGX_HTTP_PARSE_HEADER_ERROR 14 -#define NGX_HTTP_PARSE_INVALID_HEADER 14 -#define NGX_HTTP_PARSE_TOO_LONG_HEADER 15 -#define NGX_HTTP_PARSE_NO_HOST_HEADER 16 -#define NGX_HTTP_PARSE_INVALID_CL_HEADER 17 +#define NGX_HTTP_PARSE_HEADER_ERROR 14 +#define NGX_HTTP_PARSE_INVALID_HEADER 14 +#define NGX_HTTP_PARSE_TOO_LONG_HEADER 15 +#define NGX_HTTP_PARSE_NO_HOST_HEADER 16 +#define NGX_HTTP_PARSE_INVALID_CL_HEADER 17 #define NGX_HTTP_OK 200 @@ -80,8 +80,8 @@ typedef enum { typedef struct { - ngx_str_t name; - int offset; + ngx_str_t name; + ngx_uint_t offset; } ngx_http_header_t; @@ -124,14 +124,14 @@ typedef struct { ngx_file_t temp_file; ngx_path_t *temp_path; off_t offset; - char *header_in_pos; + u_char *header_in_pos; } ngx_http_request_body_t; typedef struct { - off_t start; - off_t end; - ngx_str_t content_range; + off_t start; + off_t end; + ngx_str_t content_range; } ngx_http_range_t; @@ -155,7 +155,7 @@ typedef struct { ngx_array_t ranges; off_t content_length_n; - char *etag; + u_char *etag; time_t date_time; time_t last_modified_time; } ngx_http_headers_out_t; @@ -165,7 +165,7 @@ struct ngx_http_cleanup_s { union { struct { ngx_fd_t fd; - char *name; + u_char *name; } file; struct { @@ -202,10 +202,10 @@ struct ngx_http_request_s { time_t lingering_time; - int method; - int http_version; - int http_major; - int http_minor; + ngx_uint_t method; + ngx_uint_t http_version; + ngx_uint_t http_major; + ngx_uint_t http_minor; ngx_str_t request_line; ngx_str_t uri; @@ -215,20 +215,20 @@ struct ngx_http_request_s { ngx_http_request_t *main; - u_int in_addr; - int port; + uint32_t in_addr; + ngx_uint_t port; ngx_str_t *port_name; /* ":80" */ ngx_str_t *server_name; ngx_array_t *virtual_names; - int phase; - int phase_handler; + ngx_uint_t phase; + ngx_int_t phase_handler; ngx_http_handler_pt content_handler; ngx_temp_file_t *temp_file; ngx_chain_t *request_hunks; ngx_hunk_t *request_body_hunk; - int request_body_len; + size_t request_body_len; void (*request_body_handler) (void *data); void *data; @@ -236,9 +236,9 @@ struct ngx_http_request_s { size_t header_size; - char *discarded_buffer; + u_char *discarded_buffer; void **err_ctx; - int err_status; + ngx_uint_t err_status; unsigned http_state:4; @@ -268,21 +268,21 @@ struct ngx_http_request_s { unsigned closed:1; #endif - /* TODO: use filter or bits ???? */ - int filter; + /* TODO: use the filter flags or the separate bits ???? */ + u_int filter; /* used to parse HTTP headers */ - int state; - char *uri_start; - char *uri_end; - char *uri_ext; - char *args_start; - char *request_start; - char *request_end; - char *header_name_start; - char *header_name_end; - char *header_start; - char *header_end; + ngx_int_t state; + u_char *uri_start; + u_char *uri_end; + u_char *uri_ext; + u_char *args_start; + u_char *request_start; + u_char *request_end; + u_char *header_name_start; + u_char *header_name_end; + u_char *header_start; + u_char *header_end; }; diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c index a337c3a95..404e45f0d 100644 --- a/src/http/ngx_http_request_body.c +++ b/src/http/ngx_http_request_body.c @@ -8,8 +8,8 @@ static void ngx_http_read_client_request_body_handler(ngx_event_t *rev); -int ngx_http_read_client_request_body(ngx_http_request_t *r, - int request_buffer_size) +ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r, + size_t request_buffer_size) { ssize_t size; ngx_hunk_t *h; @@ -73,7 +73,8 @@ int ngx_http_read_client_request_body(ngx_http_request_t *r, static void ngx_http_read_client_request_body_handler(ngx_event_t *rev) { - ssize_t n, size; + size_t size; + ssize_t n; ngx_hunk_t *h; ngx_connection_t *c; ngx_http_request_t *r; diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c index 51ebd0959..f27177bec 100644 --- a/src/http/ngx_http_special_response.c +++ b/src/http/ngx_http_special_response.c @@ -5,14 +5,14 @@ #include <nginx.h> -static char error_tail[] = +static u_char error_tail[] = "<hr><center>" NGINX_VER "</center>" CRLF "</body>" CRLF "</html>" CRLF ; -static char msie_stub[] = +static u_char msie_stub[] = "<!-- The padding to disable MSIE's friendly error page -->" CRLF "<!-- The padding to disable MSIE's friendly error page -->" CRLF "<!-- The padding to disable MSIE's friendly error page -->" CRLF @@ -176,7 +176,8 @@ static ngx_str_t error_pages[] = { int ngx_http_special_response_handler(ngx_http_request_t *r, int error) { - int err, rc, i; + ngx_int_t rc; + ngx_uint_t err, i; ngx_hunk_t *h; ngx_chain_t *out, **ll, *cl; ngx_http_err_page_t *err_page; diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c index 37e8abe88..1091d75be 100644 --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -6,7 +6,7 @@ typedef struct { - ssize_t postpone_output; + size_t postpone_output; } ngx_http_write_filter_conf_t; @@ -171,7 +171,7 @@ static void *ngx_http_write_filter_create_conf(ngx_conf_t *cf) ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)), NULL); - conf->postpone_output = NGX_CONF_UNSET; + conf->postpone_output = NGX_CONF_UNSET_SIZE; return conf; } |