diff src/http/ngx_http_parse.c @ 2415:d311b7f6a403

ngx_http_arg()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 22 Dec 2008 12:02:05 +0000
parents 8c17cfe63d2c
children c7bdd722532f
line wrap: on
line diff
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -1481,3 +1481,45 @@ ngx_http_parse_multi_header_lines(ngx_ar
 
     return NGX_DECLINED;
 }
+
+
+ngx_int_t
+ngx_http_arg(ngx_http_request_t *r, u_char *name, size_t len, ngx_str_t *value)
+{
+    u_char  *p;
+
+    if (r->args.len == 0) {
+        return NGX_DECLINED;
+    }
+
+    for (p = r->args.data; *p && *p != ' '; p++) {
+
+        /*
+         * although r->args.data is not null-terminated by itself,
+         * however, there is null in the end of request line
+         */
+
+        p = ngx_strcasestrn(p, (char *) name, len - 1);
+
+        if (p == NULL) {
+            return NGX_DECLINED;
+        }
+
+        if ((p == r->args.data || *(p - 1) == '&') && *(p + len) == '=') {
+
+            value->data = p + len + 1;
+
+            p = (u_char *) ngx_strchr(p, '&');
+
+            if (p == NULL) {
+                p = r->args.data + r->args.len;
+            }
+
+            value->len = p - value->data;
+
+            return NGX_OK;
+        }
+    }
+
+    return NGX_DECLINED;
+}