From: Paul Querna Date: Fri, 5 Dec 2008 07:15:22 +0000 (+0000) Subject: Add new api, ap_args_to_table, to parse a request's arguments into a table. X-Git-Tag: 2.3.0~14^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba87dcea6aaebf414aa0ad6dc915f09d91203194;p=apache Add new api, ap_args_to_table, to parse a request's arguments into a table. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/wombat-integration@723627 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/util_script.h b/include/util_script.h index 44ea7f3df8..d478aa658b 100644 --- a/include/util_script.h +++ b/include/util_script.h @@ -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 diff --git a/server/util_script.c b/server/util_script.c index e13334a118..674a215b9c 100644 --- a/server/util_script.c +++ b/server/util_script.c @@ -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; +} + +