ngx_str_set() and ngx_str_null()

This commit is contained in:
Igor Sysoev 2010-05-14 09:56:37 +00:00
parent 328df7a5cc
commit 05b1a8f1e3
37 changed files with 133 additions and 278 deletions

View File

@ -859,14 +859,11 @@ ngx_process_options(ngx_cycle_t *cycle)
#else #else
#ifdef NGX_CONF_PREFIX #ifdef NGX_CONF_PREFIX
cycle->conf_prefix.len = sizeof(NGX_CONF_PREFIX) - 1; ngx_str_set(&cycle->conf_prefix, NGX_CONF_PREFIX);
cycle->conf_prefix.data = (u_char *) NGX_CONF_PREFIX;
#else #else
cycle->conf_prefix.len = sizeof(NGX_PREFIX) - 1; ngx_str_set(&cycle->conf_prefix, NGX_PREFIX);
cycle->conf_prefix.data = (u_char *) NGX_PREFIX;
#endif #endif
cycle->prefix.len = sizeof(NGX_PREFIX) - 1; ngx_str_set(&cycle->prefix, NGX_PREFIX);
cycle->prefix.data = (u_char *) NGX_PREFIX;
#endif #endif
} }
@ -876,8 +873,7 @@ ngx_process_options(ngx_cycle_t *cycle)
cycle->conf_file.data = ngx_conf_file; cycle->conf_file.data = ngx_conf_file;
} else { } else {
cycle->conf_file.len = sizeof(NGX_CONF_PATH) - 1; ngx_str_set(&cycle->conf_file, NGX_CONF_PATH);
cycle->conf_file.data = (u_char *) NGX_CONF_PATH;
} }
if (ngx_conf_full_name(cycle, &cycle->conf_file, 0) != NGX_OK) { if (ngx_conf_full_name(cycle, &cycle->conf_file, 0) != NGX_OK) {
@ -993,8 +989,7 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
if (ccf->pid.len == 0) { if (ccf->pid.len == 0) {
ccf->pid.len = sizeof(NGX_PID_PATH) - 1; ngx_str_set(&ccf->pid, NGX_PID_PATH);
ccf->pid.data = (u_char *) NGX_PID_PATH;
} }
if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) { if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) {
@ -1042,8 +1037,7 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
if (ccf->lock_file.len == 0) { if (ccf->lock_file.len == 0) {
ccf->lock_file.len = sizeof(NGX_LOCK_PATH) - 1; ngx_str_set(&ccf->lock_file, NGX_LOCK_PATH);
ccf->lock_file.data = (u_char *) NGX_LOCK_PATH;
} }
if (ngx_conf_full_name(cycle, &ccf->lock_file, 0) != NGX_OK) { if (ngx_conf_full_name(cycle, &ccf->lock_file, 0) != NGX_OK) {

View File

@ -903,8 +903,7 @@ ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
ngx_open_file_t *file; ngx_open_file_t *file;
#if (NGX_SUPPRESS_WARN) #if (NGX_SUPPRESS_WARN)
full.len = 0; ngx_str_null(&full);
full.data = NULL;
#endif #endif
if (name->len) { if (name->len) {

View File

@ -825,8 +825,7 @@ ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree)
ngx_str_t file, buf; ngx_str_t file, buf;
ngx_dir_t dir; ngx_dir_t dir;
buf.len = 0; ngx_str_null(&buf);
buf.data = NULL;
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,
"walk tree \"%V\"", tree); "walk tree \"%V\"", tree);

View File

@ -429,8 +429,7 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
value = cf->args->elts; value = cf->args->elts;
if (ngx_strcmp(value[1].data, "stderr") == 0) { if (ngx_strcmp(value[1].data, "stderr") == 0) {
name.len = 0; ngx_str_null(&name);
name.data = NULL;
} else { } else {
name = value[1]; name = value[1];

View File

@ -38,6 +38,9 @@ typedef struct {
#define ngx_string(str) { sizeof(str) - 1, (u_char *) str } #define ngx_string(str) { sizeof(str) - 1, (u_char *) str }
#define ngx_null_string { 0, NULL } #define ngx_null_string { 0, NULL }
#define ngx_str_set(str, text) \
(str)->len = sizeof(text) - 1; (str)->data = (u_char *) text
#define ngx_str_null(str) (str)->len = 0; (str)->data = NULL
#define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c) #define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)

View File

@ -2234,21 +2234,17 @@ ngx_ssl_get_client_verify(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
X509 *cert; X509 *cert;
if (SSL_get_verify_result(c->ssl->connection) != X509_V_OK) { if (SSL_get_verify_result(c->ssl->connection) != X509_V_OK) {
s->len = sizeof("FAILED") - 1; ngx_str_set(s, "FAILED");
s->data = (u_char *) "FAILED";
return NGX_OK; return NGX_OK;
} }
cert = SSL_get_peer_certificate(c->ssl->connection); cert = SSL_get_peer_certificate(c->ssl->connection);
if (cert) { if (cert) {
s->len = sizeof("SUCCESS") - 1; ngx_str_set(s, "SUCCESS");
s->data = (u_char *) "SUCCESS";
} else { } else {
s->len = sizeof("NONE") - 1; ngx_str_set(s, "NONE");
s->data = (u_char *) "NONE";
} }
X509_free(cert); X509_free(cert);

View File

@ -348,8 +348,7 @@ ngx_http_auth_basic_set_realm(ngx_http_request_t *r, ngx_str_t *realm)
} }
r->headers_out.www_authenticate->hash = 1; r->headers_out.www_authenticate->hash = 1;
r->headers_out.www_authenticate->key.len = sizeof("WWW-Authenticate") - 1; ngx_str_set(&r->headers_out.www_authenticate->key, "WWW-Authenticate");
r->headers_out.www_authenticate->key.data = (u_char *) "WWW-Authenticate";
r->headers_out.www_authenticate->value = *realm; r->headers_out.www_authenticate->value = *realm;
return NGX_HTTP_UNAUTHORIZED; return NGX_HTTP_UNAUTHORIZED;
@ -425,9 +424,7 @@ ngx_http_auth_basic(ngx_conf_t *cf, void *post, void *data)
u_char *basic, *p; u_char *basic, *p;
if (ngx_strcmp(realm->data, "off") == 0) { if (ngx_strcmp(realm->data, "off") == 0) {
realm->len = 0; ngx_str_set(realm, "");
realm->data = (u_char *) "";
return NGX_CONF_OK; return NGX_CONF_OK;
} }

View File

@ -235,8 +235,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
r->headers_out.status = NGX_HTTP_OK; r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_type_len = sizeof("text/html") - 1; r->headers_out.content_type_len = sizeof("text/html") - 1;
r->headers_out.content_type.len = sizeof("text/html") - 1; ngx_str_set(&r->headers_out.content_type, "text/html");
r->headers_out.content_type.data = (u_char *) "text/html";
rc = ngx_http_send_header(r); rc = ngx_http_send_header(r);

View File

@ -123,8 +123,7 @@ ngx_http_empty_gif_handler(ngx_http_request_t *r)
} }
r->headers_out.content_type_len = sizeof("image/gif") - 1; r->headers_out.content_type_len = sizeof("image/gif") - 1;
r->headers_out.content_type.len = sizeof("image/gif") - 1; ngx_str_set(&r->headers_out.content_type, "image/gif");
r->headers_out.content_type.data = (u_char *) "image/gif";
if (r->method == NGX_HTTP_HEAD) { if (r->method == NGX_HTTP_HEAD) {
r->headers_out.status = NGX_HTTP_OK; r->headers_out.status = NGX_HTTP_OK;

View File

@ -589,9 +589,7 @@ ngx_http_fastcgi_handler(ngx_http_request_t *r)
u = r->upstream; u = r->upstream;
u->schema.len = sizeof("fastcgi://") - 1; ngx_str_set(&u->schema, "fastcgi://");
u->schema.data = (u_char *) "fastcgi://";
u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module; u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module;
u->conf = &flcf->upstream; u->conf = &flcf->upstream;
@ -1449,15 +1447,12 @@ ngx_http_fastcgi_process_header(ngx_http_request_t *r)
} else if (u->headers_in.location) { } else if (u->headers_in.location) {
u->headers_in.status_n = 302; u->headers_in.status_n = 302;
u->headers_in.status_line.len = ngx_str_set(&u->headers_in.status_line,
sizeof("302 Moved Temporarily") - 1; "302 Moved Temporarily");
u->headers_in.status_line.data =
(u_char *) "302 Moved Temporarily";
} else { } else {
u->headers_in.status_n = 200; u->headers_in.status_n = 200;
u->headers_in.status_line.len = sizeof("200 OK") - 1; ngx_str_set(&u->headers_in.status_line, "200 OK");
u->headers_in.status_line.data = (u_char *) "200 OK";
} }
if (u->state) { if (u->state) {
@ -1922,8 +1917,7 @@ ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
* conf->upstream.store_lengths = NULL; * conf->upstream.store_lengths = NULL;
* conf->upstream.store_values = NULL; * conf->upstream.store_values = NULL;
* *
* conf->index.len = 0; * conf->index.len = { 0, NULL };
* conf->index.data = NULL;
*/ */
conf->upstream.store = NGX_CONF_UNSET; conf->upstream.store = NGX_CONF_UNSET;

View File

@ -285,11 +285,8 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
} }
h->hash = 1; h->hash = 1;
h->key.len = sizeof("Content-Encoding") - 1; ngx_str_set(&h->key, "Content-Encoding");
h->key.data = (u_char *) "Content-Encoding"; ngx_str_set(&h->value, "gzip");
h->value.len = sizeof("gzip") - 1;
h->value.data = (u_char *) "gzip";
r->headers_out.content_encoding = h; r->headers_out.content_encoding = h;
r->main_filter_need_in_memory = 1; r->main_filter_need_in_memory = 1;

View File

@ -212,12 +212,10 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
} }
h->hash = 1; h->hash = 1;
h->key.len = sizeof("Content-Encoding") - 1; ngx_str_set(&h->key, "Content-Encoding");
h->key.data = (u_char *) "Content-Encoding"; ngx_str_set(&h->value, "gzip");
h->value.len = sizeof("gzip") - 1;
h->value.data = (u_char *) "gzip";
r->headers_out.content_encoding = h; r->headers_out.content_encoding = h;
r->ignore_content_encoding = 1; r->ignore_content_encoding = 1;
/* we need to allocate all before the header would be sent */ /* we need to allocate all before the header would be sent */

View File

@ -196,8 +196,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
r->headers_out.expires = expires; r->headers_out.expires = expires;
expires->hash = 1; expires->hash = 1;
expires->key.len = sizeof("Expires") - 1; ngx_str_set(&expires->key, "Expires");
expires->key.data = (u_char *) "Expires";
} }
len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT"); len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT");
@ -225,9 +224,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
} }
cc->hash = 1; cc->hash = 1;
cc->key.len = sizeof("Cache-Control") - 1; ngx_str_set(&cc->key, "Cache-Control");
cc->key.data = (u_char *) "Cache-Control";
*ccp = cc; *ccp = cc;
} else { } else {
@ -240,20 +237,14 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
if (conf->expires == NGX_HTTP_EXPIRES_EPOCH) { if (conf->expires == NGX_HTTP_EXPIRES_EPOCH) {
expires->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT"; expires->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT";
ngx_str_set(&cc->value, "no-cache");
cc->value.len = sizeof("no-cache") - 1;
cc->value.data = (u_char *) "no-cache";
return NGX_OK; return NGX_OK;
} }
if (conf->expires == NGX_HTTP_EXPIRES_MAX) { if (conf->expires == NGX_HTTP_EXPIRES_MAX) {
expires->value.data = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT"; expires->value.data = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT";
/* 10 years */ /* 10 years */
cc->value.len = sizeof("max-age=315360000") - 1; ngx_str_set(&cc->value, "max-age=315360000");
cc->value.data = (u_char *) "max-age=315360000";
return NGX_OK; return NGX_OK;
} }
@ -265,10 +256,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
if (conf->expires_time == 0) { if (conf->expires_time == 0) {
ngx_memcpy(expires->value.data, ngx_cached_http_time.data, ngx_memcpy(expires->value.data, ngx_cached_http_time.data,
ngx_cached_http_time.len + 1); ngx_cached_http_time.len + 1);
ngx_str_set(&cc->value, "max-age=0");
cc->value.len = sizeof("max-age=0") - 1;
cc->value.data = (u_char *) "max-age=0";
return NGX_OK; return NGX_OK;
} }
@ -292,9 +280,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
ngx_http_time(expires->value.data, expires_time); ngx_http_time(expires->value.data, expires_time);
if (conf->expires_time < 0 || max_age < 0) { if (conf->expires_time < 0 || max_age < 0) {
cc->value.len = sizeof("no-cache") - 1; ngx_str_set(&cc->value, "no-cache");
cc->value.data = (u_char *) "no-cache";
return NGX_OK; return NGX_OK;
} }
@ -361,8 +347,7 @@ ngx_http_add_cache_control(ngx_http_request_t *r, ngx_http_header_val_t *hv,
} }
cc->hash = 1; cc->hash = 1;
cc->key.len = sizeof("Cache-Control") - 1; ngx_str_set(&cc->key, "Cache-Control");
cc->key.data = (u_char *) "Cache-Control";
cc->value = *value; cc->value = *value;
*ccp = cc; *ccp = cc;

View File

@ -529,8 +529,7 @@ ngx_http_image_json(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
ngx_http_clean_header(r); ngx_http_clean_header(r);
r->headers_out.status = NGX_HTTP_OK; r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_type.len = sizeof("text/plain") - 1; ngx_str_set(&r->headers_out.content_type, "text/plain");
r->headers_out.content_type.data = (u_char *) "text/plain";
r->headers_out.content_type_lowcase = NULL; r->headers_out.content_type_lowcase = NULL;
if (ctx == NULL) { if (ctx == NULL) {

View File

@ -747,8 +747,7 @@ ngx_http_log_create_main_conf(ngx_conf_t *cf)
return NULL; return NULL;
} }
fmt->name.len = sizeof("combined") - 1; ngx_str_set(&fmt->name, "combined");
fmt->name.data = (u_char *) "combined";
fmt->flushes = NULL; fmt->flushes = NULL;
@ -922,8 +921,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
} }
} else { } else {
name.len = sizeof("combined") - 1; ngx_str_set(&name, "combined");
name.data = (u_char *) "combined";
lmcf->combined_used = 1; lmcf->combined_used = 1;
} }

View File

@ -189,9 +189,7 @@ ngx_http_memcached_handler(ngx_http_request_t *r)
u = r->upstream; u = r->upstream;
u->schema.len = sizeof("memcached://") - 1; ngx_str_set(&u->schema, "memcached://");
u->schema.data = (u_char *) "memcached://";
u->output.tag = (ngx_buf_tag_t) &ngx_http_memcached_module; u->output.tag = (ngx_buf_tag_t) &ngx_http_memcached_module;
mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module); mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module);

View File

@ -1568,10 +1568,8 @@ ngx_http_proxy_process_header(ngx_http_request_t *r)
h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash( h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash(
ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r'); ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r');
h->key.len = sizeof("Server") - 1; ngx_str_set(&h->key, "Server");
h->key.data = (u_char *) "Server"; ngx_str_null(&h->value);
h->value.len = 0;
h->value.data = NULL;
h->lowcase_key = (u_char *) "server"; h->lowcase_key = (u_char *) "server";
} }
@ -1583,10 +1581,8 @@ ngx_http_proxy_process_header(ngx_http_request_t *r)
h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e'); h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e');
h->key.len = sizeof("Date") - 1; ngx_str_set(&h->key, "Date");
h->key.data = (u_char *) "Date"; ngx_str_null(&h->value);
h->value.len = 0;
h->value.data = NULL;
h->lowcase_key = (u_char *) "date"; h->lowcase_key = (u_char *) "date";
} }
@ -2222,8 +2218,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
pr->replacement.text = conf->location; pr->replacement.text = conf->location;
} else { } else {
pr->replacement.text.len = 0; ngx_str_null(&pr->replacement.text);
pr->replacement.text.data = NULL;
} }
} }
} }
@ -2311,10 +2306,8 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
s->key.len = sizeof("Content-Length") - 1; ngx_str_set(&s->key, "Content-Length");
s->key.data = (u_char *) "Content-Length"; ngx_str_set(&s->value, "$proxy_internal_body_length");
s->value.len = sizeof("$proxy_internal_body_length") - 1;
s->value.data = (u_char *) "$proxy_internal_body_length";
} }
if (ngx_http_proxy_merge_headers(cf, conf, prev) != NGX_OK) { if (ngx_http_proxy_merge_headers(cf, conf, prev) != NGX_OK) {
@ -2777,8 +2770,7 @@ ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
pr->replacement.text = plcf->location; pr->replacement.text = plcf->location;
} else { } else {
pr->replacement.text.len = 0; ngx_str_null(&pr->replacement.text);
pr->replacement.text.data = NULL;
} }
return NGX_CONF_OK; return NGX_CONF_OK;
@ -3038,12 +3030,10 @@ ngx_http_proxy_set_vars(ngx_url_t *u, ngx_http_proxy_vars_t *v)
v->host_header = u->host; v->host_header = u->host;
if (u->default_port == 80) { if (u->default_port == 80) {
v->port.len = sizeof("80") - 1; ngx_str_set(&v->port, "80");
v->port.data = (u_char *) "80";
} else { } else {
v->port.len = sizeof("443") - 1; ngx_str_set(&v->port, "443");
v->port.data = (u_char *) "443";
} }
} else { } else {
@ -3055,10 +3045,8 @@ ngx_http_proxy_set_vars(ngx_url_t *u, ngx_http_proxy_vars_t *v)
v->key_start.len += v->host_header.len; v->key_start.len += v->host_header.len;
} else { } else {
v->host_header.len = sizeof("localhost") - 1; ngx_str_set(&v->host_header, "localhost");
v->host_header.data = (u_char *) "localhost"; ngx_str_null(&v->port);
v->port.len = 0;
v->port.data = (u_char *) "";
v->key_start.len += sizeof("unix:") - 1 + u->host.len + 1; v->key_start.len += sizeof("unix:") - 1 + u->host.len + 1;
} }

View File

@ -224,10 +224,8 @@ next_filter:
} }
r->headers_out.accept_ranges->hash = 1; r->headers_out.accept_ranges->hash = 1;
r->headers_out.accept_ranges->key.len = sizeof("Accept-Ranges") - 1; ngx_str_set(&r->headers_out.accept_ranges->key, "Accept-Ranges");
r->headers_out.accept_ranges->key.data = (u_char *) "Accept-Ranges"; ngx_str_set(&r->headers_out.accept_ranges->value, "bytes");
r->headers_out.accept_ranges->value.len = sizeof("bytes") - 1;
r->headers_out.accept_ranges->value.data = (u_char *) "bytes";
return ngx_http_next_header_filter(r); return ngx_http_next_header_filter(r);
} }
@ -355,8 +353,7 @@ ngx_http_range_singlepart_header(ngx_http_request_t *r,
r->headers_out.content_range = content_range; r->headers_out.content_range = content_range;
content_range->hash = 1; content_range->hash = 1;
content_range->key.len = sizeof("Content-Range") - 1; ngx_str_set(&content_range->key, "Content-Range");
content_range->key.data = (u_char *) "Content-Range";
content_range->value.data = ngx_pnalloc(r->pool, content_range->value.data = ngx_pnalloc(r->pool,
sizeof("bytes -/") - 1 + 3 * NGX_OFF_T_LEN); sizeof("bytes -/") - 1 + 3 * NGX_OFF_T_LEN);
@ -520,8 +517,7 @@ ngx_http_range_not_satisfiable(ngx_http_request_t *r)
r->headers_out.content_range = content_range; r->headers_out.content_range = content_range;
content_range->hash = 1; content_range->hash = 1;
content_range->key.len = sizeof("Content-Range") - 1; ngx_str_set(&content_range->key, "Content-Range");
content_range->key.data = (u_char *) "Content-Range";
content_range->value.data = ngx_pnalloc(r->pool, content_range->value.data = ngx_pnalloc(r->pool,
sizeof("bytes */") - 1 + NGX_OFF_T_LEN); sizeof("bytes */") - 1 + NGX_OFF_T_LEN);

View File

@ -363,8 +363,7 @@ ngx_http_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_http_server_name_t *sn; ngx_http_server_name_t *sn;
ngx_http_core_srv_conf_t *cscf; ngx_http_core_srv_conf_t *cscf;
name.len = sizeof("invalid_referer") - 1; ngx_str_set(&name, "invalid_referer");
name.data = (u_char *) "invalid_referer";
var = ngx_http_add_variable(cf, &name, var = ngx_http_add_variable(cf, &name,
NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOHASH); NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOHASH);
@ -407,8 +406,7 @@ ngx_http_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
continue; continue;
} }
uri.len = 0; ngx_str_null(&uri);
uri.data = NULL;
if (ngx_strcmp(value[i].data, "server_names") == 0) { if (ngx_strcmp(value[i].data, "server_names") == 0) {

View File

@ -346,13 +346,9 @@ ngx_http_ssi_header_filter(ngx_http_request_t *r)
ctx->params.nalloc = NGX_HTTP_SSI_PARAMS_N; ctx->params.nalloc = NGX_HTTP_SSI_PARAMS_N;
ctx->params.pool = r->pool; ctx->params.pool = r->pool;
ctx->timefmt.len = sizeof("%A, %d-%b-%Y %H:%M:%S %Z") - 1; ngx_str_set(&ctx->timefmt, "%A, %d-%b-%Y %H:%M:%S %Z");
ctx->timefmt.data = (u_char *) "%A, %d-%b-%Y %H:%M:%S %Z"; ngx_str_set(&ctx->errmsg,
"[an error occurred while processing the directive]");
ctx->errmsg.len =
sizeof("[an error occurred while processing the directive]") - 1;
ctx->errmsg.data = (u_char *)
"[an error occurred while processing the directive]";
r->filter_need_in_memory = 1; r->filter_need_in_memory = 1;
@ -1904,8 +1900,7 @@ ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"ssi include: \"%V\"", uri); "ssi include: \"%V\"", uri);
args.len = 0; ngx_str_null(&args);
args.data = NULL;
flags = NGX_HTTP_LOG_UNSAFE; flags = NGX_HTTP_LOG_UNSAFE;
if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) { if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) {

View File

@ -314,8 +314,7 @@ ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
* sscf->dhparam = { 0, NULL }; * sscf->dhparam = { 0, NULL };
* sscf->client_certificate = { 0, NULL }; * sscf->client_certificate = { 0, NULL };
* sscf->crl = { 0, NULL }; * sscf->crl = { 0, NULL };
* sscf->ciphers.len = 0; * sscf->ciphers = { 0, NULL };
* sscf->ciphers.data = NULL;
* sscf->shm_zone = NULL; * sscf->shm_zone = NULL;
*/ */

View File

@ -75,8 +75,7 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
return rc; return rc;
} }
r->headers_out.content_type.len = sizeof("text/plain") - 1; ngx_str_set(&r->headers_out.content_type, "text/plain");
r->headers_out.content_type.data = (u_char *) "text/plain";
if (r->method == NGX_HTTP_HEAD) { if (r->method == NGX_HTTP_HEAD) {
r->headers_out.status = NGX_HTTP_OK; r->headers_out.status = NGX_HTTP_OK;

View File

@ -493,8 +493,7 @@ ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
} }
set_cookie->hash = 1; set_cookie->hash = 1;
set_cookie->key.len = sizeof("Set-Cookie") - 1; ngx_str_set(&set_cookie->key, "Set-Cookie");
set_cookie->key.data = (u_char *) "Set-Cookie";
set_cookie->value.len = p - cookie; set_cookie->value.len = p - cookie;
set_cookie->value.data = cookie; set_cookie->value.data = cookie;
@ -511,8 +510,7 @@ ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
} }
p3p->hash = 1; p3p->hash = 1;
p3p->key.len = sizeof("P3P") - 1; ngx_str_set(&p3p->key, "P3P");
p3p->key.data = (u_char *) "P3P";
p3p->value = conf->p3p; p3p->value = conf->p3p;
return NGX_OK; return NGX_OK;
@ -576,14 +574,10 @@ ngx_http_userid_create_conf(ngx_conf_t *cf)
/* /*
* set by ngx_pcalloc(): * set by ngx_pcalloc():
* *
* conf->name.len = 0; * conf->name = { 0, NULL };
* conf->name.date = NULL; * conf->domain = { 0, NULL };
* conf->domain.len = 0; * conf->path = { 0, NULL };
* conf->domain.date = NULL; * conf->p3p = { 0, NULL };
* conf->path.len = 0;
* conf->path.date = NULL;
* conf->p3p.len = 0;
* conf->p3p.date = NULL;
*/ */
conf->enable = NGX_CONF_UNSET_UINT; conf->enable = NGX_CONF_UNSET_UINT;
@ -642,9 +636,7 @@ ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
u_char *p, *new; u_char *p, *new;
if (ngx_strcmp(domain->data, "none") == 0) { if (ngx_strcmp(domain->data, "none") == 0) {
domain->len = 0; ngx_str_set(domain, "");
domain->data = (u_char *) "";
return NGX_CONF_OK; return NGX_CONF_OK;
} }
@ -727,8 +719,7 @@ ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data)
ngx_str_t *p3p = data; ngx_str_t *p3p = data;
if (ngx_strcmp(p3p->data, "none") == 0) { if (ngx_strcmp(p3p->data, "none") == 0) {
p3p->len = 0; ngx_str_set(p3p, "");
p3p->data = (u_char *) "";
} }
return NGX_CONF_OK; return NGX_CONF_OK;

View File

@ -837,8 +837,7 @@ ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
} else if (doc_type == XML_HTML_DOCUMENT_NODE) { } else if (doc_type == XML_HTML_DOCUMENT_NODE) {
r->headers_out.content_type_len = sizeof("text/html") - 1; r->headers_out.content_type_len = sizeof("text/html") - 1;
r->headers_out.content_type.len = sizeof("text/html") - 1; ngx_str_set(&r->headers_out.content_type, "text/html");
r->headers_out.content_type.data = (u_char *) "text/html";
} }
r->headers_out.content_type_lowcase = NULL; r->headers_out.content_type_lowcase = NULL;

View File

@ -481,8 +481,7 @@ ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf)
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
m->len = sizeof(NGX_PERL_MODULES) - 1; ngx_str_set(m, NGX_PERL_MODULES);
m->data = NGX_PERL_MODULES;
} }
#endif #endif

View File

@ -1685,8 +1685,7 @@ ngx_http_set_exten(ngx_http_request_t *r)
{ {
ngx_int_t i; ngx_int_t i;
r->exten.len = 0; ngx_str_null(&r->exten);
r->exten.data = NULL;
for (i = r->uri.len - 1; i > 1; i--) { for (i = r->uri.len - 1; i > 1; i--) {
if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') { if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
@ -2187,8 +2186,7 @@ ngx_http_internal_redirect(ngx_http_request_t *r,
r->args = *args; r->args = *args;
} else { } else {
r->args.len = 0; ngx_str_null(&r->args);
r->args.data = NULL;
} }
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@ -3032,8 +3030,7 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->root_values = prev->root_values; conf->root_values = prev->root_values;
if (prev->root.data == NULL) { if (prev->root.data == NULL) {
conf->root.len = sizeof("html") - 1; ngx_str_set(&conf->root, "html");
conf->root.data = (u_char *) "html";
if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) { if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) {
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
@ -3891,8 +3888,7 @@ ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
args.len = 0; ngx_str_null(&args);
args.data = NULL;
if (cv.lengths == NULL && uri.data[0] == '/') { if (cv.lengths == NULL && uri.data[0] == '/') {
p = (u_char *) ngx_strchr(uri.data, '?'); p = (u_char *) ngx_strchr(uri.data, '?');

View File

@ -218,8 +218,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
if (status == NGX_HTTP_NO_CONTENT) { if (status == NGX_HTTP_NO_CONTENT) {
r->header_only = 1; r->header_only = 1;
r->headers_out.content_type.len = 0; ngx_str_null(&r->headers_out.content_type);
r->headers_out.content_type.data = NULL;
r->headers_out.last_modified_time = -1; r->headers_out.last_modified_time = -1;
r->headers_out.last_modified = NULL; r->headers_out.last_modified = NULL;
r->headers_out.content_length = NULL; r->headers_out.content_length = NULL;
@ -371,8 +370,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
} }
} else { } else {
host.len = 0; ngx_str_null(&host);
host.data = NULL;
port = 0; port = 0;
} }
@ -539,8 +537,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
r->headers_out.location->value.len = b->last - p; r->headers_out.location->value.len = b->last - p;
r->headers_out.location->value.data = p; r->headers_out.location->value.data = p;
r->headers_out.location->key.len = sizeof("Location") - 1; ngx_str_set(&r->headers_out.location->key, "Location");
r->headers_out.location->key.data = (u_char *) "Location";
*b->last++ = CR; *b->last++ = LF; *b->last++ = CR; *b->last++ = LF;
} }

View File

@ -1008,8 +1008,7 @@ ngx_http_script_regex_end_code(ngx_http_script_engine_t *e)
} }
r->headers_out.location->hash = 1; r->headers_out.location->hash = 1;
r->headers_out.location->key.len = sizeof("Location") - 1; ngx_str_set(&r->headers_out.location->key, "Location");
r->headers_out.location->key.data = (u_char *) "Location";
r->headers_out.location->value = e->buf; r->headers_out.location->value = e->buf;
e->ip += sizeof(ngx_http_script_regex_end_code_t); e->ip += sizeof(ngx_http_script_regex_end_code_t);

View File

@ -553,8 +553,7 @@ ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
r->err_status = NGX_HTTP_MOVED_TEMPORARILY; r->err_status = NGX_HTTP_MOVED_TEMPORARILY;
location->hash = 1; location->hash = 1;
location->key.len = sizeof("Location") - 1; ngx_str_set(&location->key, "Location");
location->key.data = (u_char *) "Location";
location->value = uri; location->value = uri;
r->headers_out.location = location; r->headers_out.location = location;
@ -608,8 +607,7 @@ ngx_http_send_special_response(ngx_http_request_t *r,
} }
r->headers_out.content_type_len = sizeof("text/html") - 1; r->headers_out.content_type_len = sizeof("text/html") - 1;
r->headers_out.content_type.len = sizeof("text/html") - 1; ngx_str_set(&r->headers_out.content_type, "text/html");
r->headers_out.content_type.data = (u_char *) "text/html";
r->headers_out.content_type_lowcase = NULL; r->headers_out.content_type_lowcase = NULL;
} else { } else {
@ -711,8 +709,7 @@ ngx_http_send_refresh(ngx_http_request_t *r)
r->err_status = NGX_HTTP_OK; r->err_status = NGX_HTTP_OK;
r->headers_out.content_type_len = sizeof("text/html") - 1; r->headers_out.content_type_len = sizeof("text/html") - 1;
r->headers_out.content_type.len = sizeof("text/html") - 1; ngx_str_set(&r->headers_out.content_type, "text/html");
r->headers_out.content_type.data = (u_char *) "text/html";
r->headers_out.content_type_lowcase = NULL; r->headers_out.content_type_lowcase = NULL;
r->headers_out.location->hash = 0; r->headers_out.location->hash = 0;

View File

@ -1800,8 +1800,7 @@ ngx_http_upstream_process_headers(ngx_http_request_t *r, ngx_http_upstream_t *u)
} }
uri = &u->headers_in.x_accel_redirect->value; uri = &u->headers_in.x_accel_redirect->value;
args.len = 0; ngx_str_null(&args);
args.data = NULL;
flags = NGX_HTTP_LOG_UNSAFE; flags = NGX_HTTP_LOG_UNSAFE;
if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) { if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) {

View File

@ -1390,8 +1390,7 @@ ngx_http_variable_sent_location(ngx_http_request_t *r,
return NGX_OK; return NGX_OK;
} }
name.len = sizeof("sent_http_location") - 1; ngx_str_set(&name, "sent_http_location");
name.data = (u_char *) "sent_http_location";
return ngx_http_variable_unknown_header(v, &name, return ngx_http_variable_unknown_header(v, &name,
&r->headers_out.headers.part, &r->headers_out.headers.part,

View File

@ -1409,15 +1409,13 @@ ngx_mail_auth_http(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ahcf->host_header = u.host; ahcf->host_header = u.host;
} else { } else {
ahcf->host_header.len = sizeof("localhost") - 1; ngx_str_set(&ahcf->host_header, "localhost");
ahcf->host_header.data = (u_char *) "localhost";
} }
ahcf->uri = u.uri; ahcf->uri = u.uri;
if (ahcf->uri.len == 0) { if (ahcf->uri.len == 0) {
ahcf->uri.len = sizeof("/") - 1; ngx_str_set(&ahcf->uri, "/");
ahcf->uri.data = (u_char *) "/";
} }
return NGX_CONF_OK; return NGX_CONF_OK;

View File

@ -39,8 +39,7 @@ ngx_mail_imap_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
s->out.len = sizeof(imap_greeting) - 1; ngx_str_set(&s->out, imap_greeting);
s->out.data = imap_greeting;
c->read->handler = ngx_mail_imap_init_protocol; c->read->handler = ngx_mail_imap_init_protocol;
@ -136,8 +135,7 @@ ngx_mail_imap_auth_state(ngx_event_t *rev)
tag = 1; tag = 1;
s->text.len = 0; s->text.len = 0;
s->out.len = sizeof(imap_ok) - 1; ngx_str_set(&s->out, imap_ok);
s->out.data = imap_ok;
if (rc == NGX_OK) { if (rc == NGX_OK) {
@ -186,8 +184,7 @@ ngx_mail_imap_auth_state(ngx_event_t *rev)
case NGX_IMAP_LOGOUT: case NGX_IMAP_LOGOUT:
s->quit = 1; s->quit = 1;
s->text.len = sizeof(imap_bye) - 1; ngx_str_set(&s->text, imap_bye);
s->text.data = imap_bye;
break; break;
case NGX_IMAP_NOOP: case NGX_IMAP_NOOP:
@ -208,8 +205,7 @@ ngx_mail_imap_auth_state(ngx_event_t *rev)
rc = ngx_mail_auth_login_username(s, c, 0); rc = ngx_mail_auth_login_username(s, c, 0);
tag = 0; tag = 0;
s->out.len = sizeof(imap_password) - 1; ngx_str_set(&s->out, imap_password);
s->out.data = imap_password;
s->mail_state = ngx_imap_auth_login_password; s->mail_state = ngx_imap_auth_login_password;
break; break;
@ -229,8 +225,7 @@ ngx_mail_imap_auth_state(ngx_event_t *rev)
} else if (rc == NGX_IMAP_NEXT) { } else if (rc == NGX_IMAP_NEXT) {
tag = 0; tag = 0;
s->out.len = sizeof(imap_next) - 1; ngx_str_set(&s->out, imap_next);
s->out.data = imap_next;
} }
switch (rc) { switch (rc) {
@ -245,16 +240,14 @@ ngx_mail_imap_auth_state(ngx_event_t *rev)
case NGX_MAIL_PARSE_INVALID_COMMAND: case NGX_MAIL_PARSE_INVALID_COMMAND:
s->state = 0; s->state = 0;
s->out.len = sizeof(imap_invalid_command) - 1; ngx_str_set(&s->out, imap_invalid_command);
s->out.data = imap_invalid_command;
s->mail_state = ngx_imap_start; s->mail_state = ngx_imap_start;
break; break;
} }
if (tag) { if (tag) {
if (s->tag.len == 0) { if (s->tag.len == 0) {
s->tag.len = sizeof(imap_star) - 1; ngx_str_set(&s->tag, imap_star);
s->tag.data = (u_char *) imap_star;
} }
if (s->tagged_line.len < s->tag.len + s->text.len + s->out.len) { if (s->tagged_line.len < s->tag.len + s->text.len + s->out.len) {
@ -364,24 +357,21 @@ ngx_mail_imap_authenticate(ngx_mail_session_t *s, ngx_connection_t *c)
case NGX_MAIL_AUTH_LOGIN: case NGX_MAIL_AUTH_LOGIN:
s->out.len = sizeof(imap_username) - 1; ngx_str_set(&s->out, imap_username);
s->out.data = imap_username;
s->mail_state = ngx_imap_auth_login_username; s->mail_state = ngx_imap_auth_login_username;
return NGX_OK; return NGX_OK;
case NGX_MAIL_AUTH_LOGIN_USERNAME: case NGX_MAIL_AUTH_LOGIN_USERNAME:
s->out.len = sizeof(imap_password) - 1; ngx_str_set(&s->out, imap_password);
s->out.data = imap_password;
s->mail_state = ngx_imap_auth_login_password; s->mail_state = ngx_imap_auth_login_password;
return ngx_mail_auth_login_username(s, c, 1); return ngx_mail_auth_login_username(s, c, 1);
case NGX_MAIL_AUTH_PLAIN: case NGX_MAIL_AUTH_PLAIN:
s->out.len = sizeof(imap_plain_next) - 1; ngx_str_set(&s->out, imap_plain_next);
s->out.data = imap_plain_next;
s->mail_state = ngx_imap_auth_plain; s->mail_state = ngx_imap_auth_plain;
return NGX_OK; return NGX_OK;

View File

@ -59,8 +59,7 @@ ngx_mail_pop3_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
s->out.len = p - s->out.data; s->out.len = p - s->out.data;
} else { } else {
s->out.len = sizeof(pop3_greeting) - 1; ngx_str_set(&s->out, pop3_greeting);
s->out.data = pop3_greeting;
} }
c->read->handler = ngx_mail_pop3_init_protocol; c->read->handler = ngx_mail_pop3_init_protocol;
@ -149,8 +148,7 @@ ngx_mail_pop3_auth_state(ngx_event_t *rev)
return; return;
} }
s->out.len = sizeof(pop3_ok) - 1; ngx_str_set(&s->out, pop3_ok);
s->out.data = pop3_ok;
if (rc == NGX_OK) { if (rc == NGX_OK) {
switch (s->mail_state) { switch (s->mail_state) {
@ -226,8 +224,7 @@ ngx_mail_pop3_auth_state(ngx_event_t *rev)
case ngx_pop3_auth_login_username: case ngx_pop3_auth_login_username:
rc = ngx_mail_auth_login_username(s, c, 0); rc = ngx_mail_auth_login_username(s, c, 0);
s->out.len = sizeof(pop3_password) - 1; ngx_str_set(&s->out, pop3_password);
s->out.data = pop3_password;
s->mail_state = ngx_pop3_auth_login_password; s->mail_state = ngx_pop3_auth_login_password;
break; break;
@ -259,8 +256,7 @@ ngx_mail_pop3_auth_state(ngx_event_t *rev)
s->mail_state = ngx_pop3_start; s->mail_state = ngx_pop3_start;
s->state = 0; s->state = 0;
s->out.len = sizeof(pop3_invalid_command) - 1; ngx_str_set(&s->out, pop3_invalid_command);
s->out.data = pop3_invalid_command;
/* fall through */ /* fall through */
@ -466,24 +462,21 @@ ngx_mail_pop3_auth(ngx_mail_session_t *s, ngx_connection_t *c)
case NGX_MAIL_AUTH_LOGIN: case NGX_MAIL_AUTH_LOGIN:
s->out.len = sizeof(pop3_username) - 1; ngx_str_set(&s->out, pop3_username);
s->out.data = pop3_username;
s->mail_state = ngx_pop3_auth_login_username; s->mail_state = ngx_pop3_auth_login_username;
return NGX_OK; return NGX_OK;
case NGX_MAIL_AUTH_LOGIN_USERNAME: case NGX_MAIL_AUTH_LOGIN_USERNAME:
s->out.len = sizeof(pop3_password) - 1; ngx_str_set(&s->out, pop3_password);
s->out.data = pop3_password;
s->mail_state = ngx_pop3_auth_login_password; s->mail_state = ngx_pop3_auth_login_password;
return ngx_mail_auth_login_username(s, c, 1); return ngx_mail_auth_login_username(s, c, 1);
case NGX_MAIL_AUTH_PLAIN: case NGX_MAIL_AUTH_PLAIN:
s->out.len = sizeof(pop3_next) - 1; ngx_str_set(&s->out, pop3_next);
s->out.data = pop3_next;
s->mail_state = ngx_pop3_auth_plain; s->mail_state = ngx_pop3_auth_plain;
return NGX_OK; return NGX_OK;

View File

@ -304,8 +304,7 @@ ngx_mail_proxy_pop3_handler(ngx_event_t *rev)
default: default:
#if (NGX_SUPPRESS_WARN) #if (NGX_SUPPRESS_WARN)
line.len = 0; ngx_str_null(&line);
line.data = NULL;
#endif #endif
break; break;
} }
@ -439,8 +438,7 @@ ngx_mail_proxy_imap_handler(ngx_event_t *rev)
default: default:
#if (NGX_SUPPRESS_WARN) #if (NGX_SUPPRESS_WARN)
line.len = 0; ngx_str_null(&line);
line.data = NULL;
#endif #endif
break; break;
} }
@ -664,8 +662,7 @@ ngx_mail_proxy_smtp_handler(ngx_event_t *rev)
default: default:
#if (NGX_SUPPRESS_WARN) #if (NGX_SUPPRESS_WARN)
line.len = 0; ngx_str_null(&line);
line.data = NULL;
#endif #endif
break; break;
} }

View File

@ -319,8 +319,7 @@ ngx_mail_smtp_invalid_pipelining(ngx_event_t *rev)
return; return;
} }
s->out.len = sizeof(smtp_invalid_pipelining) - 1; ngx_str_set(&s->out, smtp_invalid_pipelining);
s->out.data = smtp_invalid_pipelining;
} }
ngx_mail_send(c->write); ngx_mail_send(c->write);
@ -414,8 +413,7 @@ ngx_mail_smtp_auth_state(ngx_event_t *rev)
return; return;
} }
s->out.len = sizeof(smtp_ok) - 1; ngx_str_set(&s->out, smtp_ok);
s->out.data = smtp_ok;
if (rc == NGX_OK) { if (rc == NGX_OK) {
switch (s->mail_state) { switch (s->mail_state) {
@ -435,8 +433,7 @@ ngx_mail_smtp_auth_state(ngx_event_t *rev)
case NGX_SMTP_QUIT: case NGX_SMTP_QUIT:
s->quit = 1; s->quit = 1;
s->out.len = sizeof(smtp_bye) - 1; ngx_str_set(&s->out, smtp_bye);
s->out.data = smtp_bye;
break; break;
case NGX_SMTP_MAIL: case NGX_SMTP_MAIL:
@ -456,8 +453,7 @@ ngx_mail_smtp_auth_state(ngx_event_t *rev)
case NGX_SMTP_STARTTLS: case NGX_SMTP_STARTTLS:
rc = ngx_mail_smtp_starttls(s, c); rc = ngx_mail_smtp_starttls(s, c);
s->out.len = sizeof(smtp_starttls) - 1; ngx_str_set(&s->out, smtp_starttls);
s->out.data = smtp_starttls;
break; break;
default: default:
@ -470,8 +466,7 @@ ngx_mail_smtp_auth_state(ngx_event_t *rev)
case ngx_smtp_auth_login_username: case ngx_smtp_auth_login_username:
rc = ngx_mail_auth_login_username(s, c, 0); rc = ngx_mail_auth_login_username(s, c, 0);
s->out.len = sizeof(smtp_password) - 1; ngx_str_set(&s->out, smtp_password);
s->out.data = smtp_password;
s->mail_state = ngx_smtp_auth_login_password; s->mail_state = ngx_smtp_auth_login_password;
break; break;
@ -502,9 +497,7 @@ ngx_mail_smtp_auth_state(ngx_event_t *rev)
case NGX_MAIL_PARSE_INVALID_COMMAND: case NGX_MAIL_PARSE_INVALID_COMMAND:
s->mail_state = ngx_smtp_start; s->mail_state = ngx_smtp_start;
s->state = 0; s->state = 0;
ngx_str_set(&s->out, smtp_invalid_command);
s->out.len = sizeof(smtp_invalid_command) - 1;
s->out.data = smtp_invalid_command;
/* fall through */ /* fall through */
@ -529,8 +522,7 @@ ngx_mail_smtp_helo(ngx_mail_session_t *s, ngx_connection_t *c)
ngx_mail_smtp_srv_conf_t *sscf; ngx_mail_smtp_srv_conf_t *sscf;
if (s->args.nelts != 1) { if (s->args.nelts != 1) {
s->out.len = sizeof(smtp_invalid_argument) - 1; ngx_str_set(&s->out, smtp_invalid_argument);
s->out.data = smtp_invalid_argument;
s->state = 0; s->state = 0;
return NGX_OK; return NGX_OK;
} }
@ -546,10 +538,8 @@ ngx_mail_smtp_helo(ngx_mail_session_t *s, ngx_connection_t *c)
ngx_memcpy(s->smtp_helo.data, arg[0].data, arg[0].len); ngx_memcpy(s->smtp_helo.data, arg[0].data, arg[0].len);
s->smtp_from.len = 0; ngx_str_null(&s->smtp_from);
s->smtp_from.data = NULL; ngx_str_null(&s->smtp_to);
s->smtp_to.len = 0;
s->smtp_to.data = NULL;
sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module); sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
@ -599,8 +589,7 @@ ngx_mail_smtp_auth(ngx_mail_session_t *s, ngx_connection_t *c)
#endif #endif
if (s->args.nelts == 0) { if (s->args.nelts == 0) {
s->out.len = sizeof(smtp_invalid_argument) - 1; ngx_str_set(&s->out, smtp_invalid_argument);
s->out.data = smtp_invalid_argument;
s->state = 0; s->state = 0;
return NGX_OK; return NGX_OK;
} }
@ -611,24 +600,21 @@ ngx_mail_smtp_auth(ngx_mail_session_t *s, ngx_connection_t *c)
case NGX_MAIL_AUTH_LOGIN: case NGX_MAIL_AUTH_LOGIN:
s->out.len = sizeof(smtp_username) - 1; ngx_str_set(&s->out, smtp_username);
s->out.data = smtp_username;
s->mail_state = ngx_smtp_auth_login_username; s->mail_state = ngx_smtp_auth_login_username;
return NGX_OK; return NGX_OK;
case NGX_MAIL_AUTH_LOGIN_USERNAME: case NGX_MAIL_AUTH_LOGIN_USERNAME:
s->out.len = sizeof(smtp_password) - 1; ngx_str_set(&s->out, smtp_password);
s->out.data = smtp_password;
s->mail_state = ngx_smtp_auth_login_password; s->mail_state = ngx_smtp_auth_login_password;
return ngx_mail_auth_login_username(s, c, 1); return ngx_mail_auth_login_username(s, c, 1);
case NGX_MAIL_AUTH_PLAIN: case NGX_MAIL_AUTH_PLAIN:
s->out.len = sizeof(smtp_next) - 1; ngx_str_set(&s->out, smtp_next);
s->out.data = smtp_next;
s->mail_state = ngx_smtp_auth_plain; s->mail_state = ngx_smtp_auth_plain;
return NGX_OK; return NGX_OK;
@ -673,18 +659,14 @@ ngx_mail_smtp_mail(ngx_mail_session_t *s, ngx_connection_t *c)
if (!(sscf->auth_methods & NGX_MAIL_AUTH_NONE_ENABLED)) { if (!(sscf->auth_methods & NGX_MAIL_AUTH_NONE_ENABLED)) {
ngx_mail_smtp_log_rejected_command(s, c, "client was rejected: \"%V\""); ngx_mail_smtp_log_rejected_command(s, c, "client was rejected: \"%V\"");
ngx_str_set(&s->out, smtp_auth_required);
s->out.len = sizeof(smtp_auth_required) - 1;
s->out.data = smtp_auth_required;
return NGX_OK; return NGX_OK;
} }
/* auth none */ /* auth none */
if (s->smtp_from.len) { if (s->smtp_from.len) {
s->out.len = sizeof(smtp_bad_sequence) - 1; ngx_str_set(&s->out, smtp_bad_sequence);
s->out.data = smtp_bad_sequence;
return NGX_OK; return NGX_OK;
} }
@ -723,8 +705,7 @@ ngx_mail_smtp_mail(ngx_mail_session_t *s, ngx_connection_t *c)
ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
"smtp mail from:\"%V\"", &s->smtp_from); "smtp mail from:\"%V\"", &s->smtp_from);
s->out.len = sizeof(smtp_ok) - 1; ngx_str_set(&s->out, smtp_ok);
s->out.data = smtp_ok;
return NGX_OK; return NGX_OK;
} }
@ -738,8 +719,7 @@ ngx_mail_smtp_rcpt(ngx_mail_session_t *s, ngx_connection_t *c)
ngx_uint_t i; ngx_uint_t i;
if (s->smtp_from.len == 0) { if (s->smtp_from.len == 0) {
s->out.len = sizeof(smtp_bad_sequence) - 1; ngx_str_set(&s->out, smtp_bad_sequence);
s->out.data = smtp_bad_sequence;
return NGX_OK; return NGX_OK;
} }
@ -787,13 +767,9 @@ ngx_mail_smtp_rcpt(ngx_mail_session_t *s, ngx_connection_t *c)
static ngx_int_t static ngx_int_t
ngx_mail_smtp_rset(ngx_mail_session_t *s, ngx_connection_t *c) ngx_mail_smtp_rset(ngx_mail_session_t *s, ngx_connection_t *c)
{ {
s->smtp_from.len = 0; ngx_str_null(&s->smtp_from);
s->smtp_from.data = NULL; ngx_str_null(&s->smtp_to);
s->smtp_to.len = 0; ngx_str_set(&s->out, smtp_ok);
s->smtp_to.data = NULL;
s->out.len = sizeof(smtp_ok) - 1;
s->out.data = smtp_ok;
return NGX_OK; return NGX_OK;
} }
@ -814,12 +790,9 @@ ngx_mail_smtp_starttls(ngx_mail_session_t *s, ngx_connection_t *c)
* obtained from client before STARTTLS. * obtained from client before STARTTLS.
*/ */
s->smtp_helo.len = 0; ngx_str_null(&s->smtp_helo);
s->smtp_helo.data = NULL; ngx_str_null(&s->smtp_from);
s->smtp_from.len = 0; ngx_str_null(&s->smtp_to);
s->smtp_from.data = NULL;
s->smtp_to.len = 0;
s->smtp_to.data = NULL;
c->read->handler = ngx_mail_starttls_handler; c->read->handler = ngx_mail_starttls_handler;
return NGX_OK; return NGX_OK;

View File

@ -163,8 +163,7 @@ ngx_mail_ssl_create_conf(ngx_conf_t *cf)
* scf->certificate = { 0, NULL }; * scf->certificate = { 0, NULL };
* scf->certificate_key = { 0, NULL }; * scf->certificate_key = { 0, NULL };
* scf->dhparam = { 0, NULL }; * scf->dhparam = { 0, NULL };
* scf->ciphers.len = 0; * scf->ciphers = { 0, NULL };
* scf->ciphers.data = NULL;
* scf->shm_zone = NULL; * scf->shm_zone = NULL;
*/ */