]> granicus.if.org Git - apache/commitdiff
Add new api, ap_args_to_table, to parse a request's arguments into a table.
authorPaul Querna <pquerna@apache.org>
Fri, 5 Dec 2008 07:15:22 +0000 (07:15 +0000)
committerPaul Querna <pquerna@apache.org>
Fri, 5 Dec 2008 07:15:22 +0000 (07:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/wombat-integration@723627 13f79535-47bb-0310-9956-ffa450edef68

include/util_script.h
server/util_script.c

index 44ea7f3df8ab62b5705a2930f6b9c018074ab3ae..d478aa658bff44c0c6ddf604e4dc14c8dac0b4bf 100644 (file)
@@ -140,6 +140,8 @@ AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
                                       int (*getsfunc) (char *, int, void *),
                                       void *getsfunc_data);
 
+AP_DECLARE(void) ap_args_to_table(request_rec *r, apr_table_t **table);
+
 #ifdef __cplusplus
 }
 #endif
index e13334a118998c0ca586ecbc6cd31d83cc11feb5..674a215b9c85ac6871f7b056d41a48b4dc50e188 100644 (file)
@@ -721,3 +721,41 @@ AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r,
     va_end(strs.args);
     return res;
 }
+
+
+static void
+argstr_to_table(apr_pool_t *p, char *str, apr_table_t *parms)
+{
+    char *key;
+    char *value;
+    char *strtok_state;
+    
+    key = apr_strtok(str, "&", &strtok_state);
+    while (key) {
+        value = strchr(key, '=');
+        if (value) {
+            *value = '\0';      /* Split the string in two */
+            value++;            /* Skip passed the = */
+        }
+        else {
+            value = "1";
+        }
+        ap_unescape_url(key);
+        ap_unescape_url(value);
+        apr_table_set(parms, key, value);
+        /*
+         ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
+         "Found query arg: %s = %s", key, value);
+         */
+        key = apr_strtok(NULL, "&", &strtok_state);
+    }
+}
+
+AP_DECLARE(void) ap_args_to_table(request_rec *r, apr_table_t **table)
+{
+    apr_table_t *t = apr_table_make(r->pool, 10);
+    argstr_to_table(r->pool, r->args, t);
+    *table = t;
+}
+
+