Commit 2ded650a authored by Paul Querna's avatar Paul Querna
Browse files

Add new api, ap_args_to_table, to parse a request's arguments into a table.

parent 69015904
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
+38 −0
Original line number Diff line number Diff line
@@ -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;
}