diff src/core/ngx_string.c @ 206:3866d57d9cfd NGINX_0_3_50

nginx 0.3.50 *) Change: the "proxy_redirect_errors" and "fastcgi_redirect_errors" directives was renamed to the "proxy_intercept_errors" and "fastcgi_intercept_errors" directives. *) Feature: the ngx_http_charset_module supports the recoding from the single byte encodings to the UTF-8 encoding and back. *) Feature: the "X-Accel-Charset" response header line is supported in proxy and FastCGI mode. *) Bugfix: the "\" escape symbol in the "\"" and "\'" pairs in the SSI command was removed only if the command also has the "$" symbol. *) Bugfix: the "<!--" string might be added on some conditions in the SSI after inclusion. *) Bugfix: if the "Content-Length: 0" header line was in response, then in nonbuffered proxying mode the client connection was not closed.
author Igor Sysoev <http://sysoev.ru>
date Wed, 28 Jun 2006 00:00:00 +0400
parents 6be073125f2e
children fbf2b2f66c9f
line wrap: on
line diff
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -750,16 +750,82 @@ ngx_decode_base64(ngx_str_t *dst, ngx_st
 }
 
 
+/*
+ * ngx_utf_decode() decodes two and more bytes UTF sequences only
+ * the return values:
+ *    0x80 - 0x10ffff         valid character
+ *    0x10ffff - 0xfffffffd   invalid sequence
+ *    0xfffffffe              incomplete sequence
+ *    0xffffffff              error
+ */
+
+uint32_t
+ngx_utf_decode(u_char **p, size_t n)
+{
+    size_t    len;
+    uint32_t  u, i, valid;
+
+    u = **p;
+
+    if (u > 0xf0) {
+
+        u &= 0x07;
+        valid = 0xffff;
+        len = 3;
+
+    } else if (u > 0xe0) {
+
+        u &= 0x0f;
+        valid = 0x7ff;
+        len = 2;
+
+    } else if (u > 0xc0) {
+
+        u &= 0x1f;
+        valid = 0x7f;
+        len = 1;
+
+    } else {
+        (*p)++;
+        return 0xffffffff;
+    }
+
+    if (n - 1 < len) {
+        return 0xfffffffe;
+    }
+
+    (*p)++;
+
+    while (len) {
+        i = *(*p)++;
+
+        if (i < 0x80) {
+            return 0xffffffff;
+        }
+
+        u = (u << 6) | (i & 0x3f);
+
+        len--;
+    }
+
+    if (u > valid) {
+        return u;
+    }
+
+    return 0xffffffff;
+}
+
+
 size_t
-ngx_utf_length(ngx_str_t *utf)
+ngx_utf_length(u_char *p, size_t n)
 {
     u_char      c;
     size_t      len;
     ngx_uint_t  i;
 
-    for (len = 0, i = 0; i < utf->len; len++, i++) {
+    for (len = 0, i = 0; i < n; len++, i++) {
 
-        c = utf->data[i];
+        c = p[i];
 
         if (c < 0x80) {
             continue;
@@ -775,7 +841,7 @@ ngx_utf_length(ngx_str_t *utf)
 
         /* invalid utf */
 
-        return utf->len;
+        return n;
     }
 
     return len;