diff src/core/ngx_string.c @ 34:aab2ea7c0458 NGINX_0_1_17

nginx 0.1.17 *) Change: the ngx_http_rewrite_module was rewritten from the scratch. Now it is possible to redirect, to return the error codes, to check the variables and referrers. The directives can be used inside locations. The redirect directive was canceled. *) Feature: the ngx_http_geo_module. *) Feature: the proxy_set_x_var and fastcgi_set_var directives. *) Bugfix: the location configuration with "=" modifier may be used in another location. *) Bugfix: the correct content type was set only for requests that use small caps letters in extension. *) Bugfix: if the proxy_pass or fastcgi_pass directives were set in the location, and access was denied, and the error was redirected to a static page, then the segmentation fault occurred. *) Bugfix: if in a proxied "Location" header was a relative URL, then a host name and a slash were added to them; bug appeared in 0.1.14. *) Bugfix: the system error message was not logged on Linux.
author Igor Sysoev <http://sysoev.ru>
date Thu, 03 Feb 2005 00:00:00 +0300
parents 7ca9bdc82b3f
children 41ccba1aba45
line wrap: on
line diff
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -28,6 +28,20 @@ u_char *ngx_cpystrn(u_char *dst, u_char 
 }
 
 
+u_char *ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src)
+{
+    u_char  *dst;
+
+    if (!(dst = ngx_palloc(pool, src->len))) {
+        return NULL;
+    }
+
+    ngx_memcpy(dst, src->data, src->len);
+
+    return dst;
+}
+
+
 /*
  * supported formats:
  *    %[0][width][x][X]O        off_t
@@ -602,13 +616,14 @@ ngx_int_t ngx_decode_base64(ngx_str_t *d
 }
 
 
-ngx_uint_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
-                          ngx_uint_t type)
+uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
 {
     ngx_uint_t        i, n;
     uint32_t         *escape;
     static u_char     hex[] = "0123456789abcdef";
 
+                      /* " ", "%", "?", %00-%1F, %7F-%FF */
+
     static uint32_t   uri[] =
         { 0xffffffff, /* 1111 1111 1111 1111  1111 1111 1111 1111 */
 
@@ -626,6 +641,27 @@ ngx_uint_t ngx_escape_uri(u_char *dst, u
           0xffffffff, /* 1111 1111 1111 1111  1111 1111 1111 1111 */
           0xffffffff  /* 1111 1111 1111 1111  1111 1111 1111 1111 */ };
 
+                      /* " ", "%", "+", "?", %00-%1F, %7F-%FF */
+
+    static uint32_t   args[] =
+        { 0xffffffff, /* 1111 1111 1111 1111  1111 1111 1111 1111 */
+
+                      /* ?>=< ;:98 7654 3210  /.-, +*)( '&%$ #"!  */
+          0x80000821, /* 1000 0000 0000 0000  0000 1000 0010 0001 */
+
+                      /* _^]\ [ZYX WVUT SRQP  ONML KJIH GFED CBA@ */
+          0x00000000, /* 0000 0000 0000 0000  0000 0000 0000 0000 */
+
+                      /*  ~}| {zyx wvut srqp  onml kjih gfed cba` */
+          0x80000000, /* 1000 0000 0000 0000  0000 0000 0000 0000 */
+
+          0xffffffff, /* 1111 1111 1111 1111  1111 1111 1111 1111 */
+          0xffffffff, /* 1111 1111 1111 1111  1111 1111 1111 1111 */
+          0xffffffff, /* 1111 1111 1111 1111  1111 1111 1111 1111 */
+          0xffffffff  /* 1111 1111 1111 1111  1111 1111 1111 1111 */ };
+
+                      /* " ", """, "%", "'", %00-%1F, %7F-%FF */
+
     static uint32_t   html[] =
         { 0xffffffff, /* 1111 1111 1111 1111  1111 1111 1111 1111 */
 
@@ -644,11 +680,16 @@ ngx_uint_t ngx_escape_uri(u_char *dst, u
           0xffffffff  /* 1111 1111 1111 1111  1111 1111 1111 1111 */ };
 
 
-    if (type == NGX_ESCAPE_HTML) {
+    switch (type) {
+    case NGX_ESCAPE_HTML:
         escape = html;
-
-    } else {
+        break;
+    case NGX_ESCAPE_ARGS:
+        escape = args;
+        break;
+    default:
         escape = uri;
+        break;
     }
 
     if (dst == NULL) {
@@ -664,7 +705,7 @@ ngx_uint_t ngx_escape_uri(u_char *dst, u
             src++;
         }
 
-        return n;
+        return (uintptr_t) n;
     }
 
     for (i = 0; i < size; i++) {
@@ -679,5 +720,5 @@ ngx_uint_t ngx_escape_uri(u_char *dst, u
         }
     }
 
-    return 0;
+    return (uintptr_t) dst;
 }