summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Querna <pquerna@apache.org>2008-12-05 08:36:26 +0000
committerPaul Querna <pquerna@apache.org>2008-12-05 08:36:26 +0000
commit03eb9179524d996e44c18b306027518fb751186d (patch)
treeb8687b32e3903884e9075bfc74280d84ee6ec1a7
parent81bc4a8a4e3f82eb0bdedf7beff23afdb5220e54 (diff)
downloadhttpd-03eb9179524d996e44c18b306027518fb751186d.tar.gz
New API, ap_body_to_table, a very ineffeicent and bad hack to remove an apreq dependency.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/wombat-integration@723652 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--include/httpd.h1
-rw-r--r--include/util_script.h2
-rw-r--r--server/util_script.c77
3 files changed, 80 insertions, 0 deletions
diff --git a/include/httpd.h b/include/httpd.h
index 0d708adfcf..876a5b1647 100644
--- a/include/httpd.h
+++ b/include/httpd.h
@@ -1005,6 +1005,7 @@ struct request_rec {
apr_thread_mutex_t *invoke_mtx;
+ apr_table_t *body_table;
/* Things placed at the end of the record to avoid breaking binary
* compatibility. It would be nice to remember to reorder the entire
* record to improve 64bit alignment the next time we need to break
diff --git a/include/util_script.h b/include/util_script.h
index d478aa658b..d7e7eae080 100644
--- a/include/util_script.h
+++ b/include/util_script.h
@@ -142,6 +142,8 @@ AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
AP_DECLARE(void) ap_args_to_table(request_rec *r, apr_table_t **table);
+AP_DECLARE(apr_status_t) ap_body_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 674a215b9c..0c764903ba 100644
--- a/server/util_script.c
+++ b/server/util_script.c
@@ -729,6 +729,10 @@ argstr_to_table(apr_pool_t *p, char *str, apr_table_t *parms)
char *key;
char *value;
char *strtok_state;
+
+ if (str == NULL) {
+ return;
+ }
key = apr_strtok(str, "&", &strtok_state);
while (key) {
@@ -758,4 +762,77 @@ AP_DECLARE(void) ap_args_to_table(request_rec *r, apr_table_t **table)
*table = t;
}
+AP_DECLARE(apr_status_t) ap_body_to_table(request_rec *r, apr_table_t **table)
+{
+ apr_bucket_brigade *bb;
+ apr_bucket_brigade *tmpbb;
+ apr_status_t rv = APR_SUCCESS;
+
+ if (r->body_table) {
+ *table = r->body_table;
+ return APR_SUCCESS;
+ }
+
+ *table = NULL;
+
+ bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
+ tmpbb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
+
+ do {
+ apr_off_t len;
+
+ rv = ap_get_brigade(r->input_filters, tmpbb, AP_MODE_READBYTES,
+ APR_BLOCK_READ, AP_IOBUFSIZE);
+ if (rv) {
+ break;
+ }
+
+ rv = apr_brigade_length(tmpbb, 1, &len);
+ if (rv) {
+ break;
+ }
+
+ if (len == 0) {
+ break;
+ }
+
+ APR_BRIGADE_CONCAT(bb, tmpbb);
+ } while(1);
+
+ if (!rv) {
+ r->body_table = apr_table_make(r->pool, 10);
+
+ if (!APR_BRIGADE_EMPTY(bb)) {
+ char *buffer;
+ apr_off_t len;
+ apr_pool_t *tpool;
+
+ apr_pool_create(&tpool, r->pool);
+
+ rv = apr_brigade_length(bb, 1, &len);
+
+ if (!rv) {
+ apr_size_t total;
+ buffer = apr_palloc(tpool, len+1);
+
+ total = len+1;
+
+ rv = apr_brigade_flatten(bb, buffer, &total);
+
+ buffer[total] = '\0';
+
+ argstr_to_table(r->pool, buffer, r->body_table);
+ }
+ apr_pool_destroy(tpool);
+ }
+ }
+
+ apr_brigade_destroy(bb);
+ apr_brigade_destroy(tmpbb);
+
+ *table = r->body_table;
+
+ return rv;
+}
+