[PATCH] Style: use ngx_str_set()

Piotr Sikora piotr at cloudflare.com
Tue Aug 5 08:52:59 UTC 2014


# HG changeset patch
# User Piotr Sikora <piotr at cloudflare.com>
# Date 1407228679 25200
#      Tue Aug 05 01:51:19 2014 -0700
# Node ID 42d455aafd7fc9c3ab204c6bf7f60a8aafb5179c
# Parent  f8764e20fcd7f87d98fe97f82b2a8d0a77ed9097
Style: use ngx_str_set().

Signed-off-by: Piotr Sikora <piotr at cloudflare.com>

diff -r f8764e20fcd7 -r 42d455aafd7f src/core/nginx.c
--- a/src/core/nginx.c	Fri Aug 01 20:39:22 2014 -0700
+++ b/src/core/nginx.c	Tue Aug 05 01:51:19 2014 -0700
@@ -493,8 +493,7 @@ ngx_set_environment(ngx_cycle_t *cycle, 
         return NULL;
     }
 
-    var->len = 2;
-    var->data = (u_char *) "TZ";
+    ngx_str_set(var, "TZ");
 
     var = ccf->env.elts;
 
diff -r f8764e20fcd7 -r 42d455aafd7f src/event/ngx_event.c
--- a/src/event/ngx_event.c	Fri Aug 01 20:39:22 2014 -0700
+++ b/src/event/ngx_event.c	Tue Aug 05 01:51:19 2014 -0700
@@ -518,8 +518,7 @@ ngx_event_module_init(ngx_cycle_t *cycle
 #endif
 
     shm.size = size;
-    shm.name.len = sizeof("nginx_shared_zone");
-    shm.name.data = (u_char *) "nginx_shared_zone";
+    ngx_str_set(&shm.name, "nginx_shared_zone");
     shm.log = cycle->log;
 
     if (ngx_shm_alloc(&shm) != NGX_OK) {
diff -r f8764e20fcd7 -r 42d455aafd7f src/http/modules/ngx_http_auth_request_module.c
--- a/src/http/modules/ngx_http_auth_request_module.c	Fri Aug 01 20:39:22 2014 -0700
+++ b/src/http/modules/ngx_http_auth_request_module.c	Tue Aug 05 01:51:19 2014 -0700
@@ -367,9 +367,7 @@ ngx_http_auth_request(ngx_conf_t *cf, ng
     value = cf->args->elts;
 
     if (ngx_strcmp(value[1].data, "off") == 0) {
-        arcf->uri.len = 0;
-        arcf->uri.data = (u_char *) "";
-
+        ngx_str_set(&arcf->uri, "");
         return NGX_CONF_OK;
     }
 
diff -r f8764e20fcd7 -r 42d455aafd7f src/http/modules/ngx_http_headers_filter_module.c
--- a/src/http/modules/ngx_http_headers_filter_module.c	Fri Aug 01 20:39:22 2014 -0700
+++ b/src/http/modules/ngx_http_headers_filter_module.c	Tue Aug 05 01:51:19 2014 -0700
@@ -194,7 +194,6 @@ ngx_http_headers_filter(ngx_http_request
 static ngx_int_t
 ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
 {
-    size_t            len;
     time_t            now, expires_time, max_age;
     ngx_uint_t        i;
     ngx_table_elt_t  *expires, *cc, **ccp;
@@ -214,9 +213,6 @@ ngx_http_set_expires(ngx_http_request_t 
         ngx_str_set(&expires->key, "Expires");
     }
 
-    len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT");
-    expires->value.len = len - 1;
-
     ccp = r->headers_out.cache_control.elts;
 
     if (ccp == NULL) {
@@ -251,19 +247,21 @@ ngx_http_set_expires(ngx_http_request_t 
     }
 
     if (conf->expires == NGX_HTTP_EXPIRES_EPOCH) {
-        expires->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT";
+        ngx_str_set(&expires->value, "Thu, 01 Jan 1970 00:00:01 GMT");
         ngx_str_set(&cc->value, "no-cache");
         return NGX_OK;
     }
 
     if (conf->expires == NGX_HTTP_EXPIRES_MAX) {
-        expires->value.data = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT";
+        ngx_str_set(&expires->value, "Thu, 31 Dec 2037 23:55:55 GMT");
         /* 10 years */
         ngx_str_set(&cc->value, "max-age=315360000");
         return NGX_OK;
     }
 
-    expires->value.data = ngx_pnalloc(r->pool, len);
+    expires->value.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1;
+
+    expires->value.data = ngx_pnalloc(r->pool, expires->value.len + 1);
     if (expires->value.data == NULL) {
         return NGX_ERROR;
     }
diff -r f8764e20fcd7 -r 42d455aafd7f src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c	Fri Aug 01 20:39:22 2014 -0700
+++ b/src/http/ngx_http_core_module.c	Tue Aug 05 01:51:19 2014 -0700
@@ -2093,7 +2093,7 @@ ngx_http_auth_basic_user(ngx_http_reques
     }
 
     if (r->headers_in.authorization == NULL) {
-        r->headers_in.user.data = (u_char *) "";
+        ngx_str_set(&r->headers_in.user, "");
         return NGX_DECLINED;
     }
 
@@ -2104,7 +2104,7 @@ ngx_http_auth_basic_user(ngx_http_reques
                            sizeof("Basic ") - 1)
            != 0)
     {
-        r->headers_in.user.data = (u_char *) "";
+        ngx_str_set(&r->headers_in.user, "");
         return NGX_DECLINED;
     }
 
@@ -2117,7 +2117,7 @@ ngx_http_auth_basic_user(ngx_http_reques
     }
 
     if (encoded.len == 0) {
-        r->headers_in.user.data = (u_char *) "";
+        ngx_str_set(&r->headers_in.user, "");
         return NGX_DECLINED;
     }
 
@@ -2128,7 +2128,7 @@ ngx_http_auth_basic_user(ngx_http_reques
     }
 
     if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
-        r->headers_in.user.data = (u_char *) "";
+        ngx_str_set(&r->headers_in.user, "");
         return NGX_DECLINED;
     }
 
@@ -2141,7 +2141,7 @@ ngx_http_auth_basic_user(ngx_http_reques
     }
 
     if (len == 0 || len == auth.len) {
-        r->headers_in.user.data = (u_char *) "";
+        ngx_str_set(&r->headers_in.user, "");
         return NGX_DECLINED;
     }
 
diff -r f8764e20fcd7 -r 42d455aafd7f src/http/ngx_http_script.c
--- a/src/http/ngx_http_script.c	Fri Aug 01 20:39:22 2014 -0700
+++ b/src/http/ngx_http_script.c	Tue Aug 05 01:51:19 2014 -0700
@@ -601,8 +601,7 @@ ngx_http_script_done(ngx_http_script_com
 
     if (sc->zero) {
 
-        zero.len = 1;
-        zero.data = (u_char *) "\0";
+        ngx_str_set(&zero, "\0");
 
         if (ngx_http_script_add_copy_code(sc, &zero, 0) != NGX_OK) {
             return NGX_ERROR;



More information about the nginx-devel mailing list