joes 2004/09/12 12:21:33
Modified: src apreq_params.h apreq_parsers.c
t parsers.c
Log:
Add apreq_hook_discard_brigade
Revision Changes Path
1.40 +7 -0 httpd-apreq-2/src/apreq_params.h
Index: apreq_params.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_params.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- apreq_params.h 10 Sep 2004 23:54:08 -0000 1.39
+++ apreq_params.h 12 Sep 2004 19:21:32 -0000 1.40
@@ -290,6 +290,7 @@
* bucket brigade. The hook may modify the brigade if necessary.
* Once all hooks have completed, the contents of the brigade will
* be added to the parameter's bb attribute.
+ * @return APR_SUCCESS on success. All other values represent errors.
*/
#define APREQ_RUN_HOOK(h,env,param,bb) (h)->hook(h,env,param,bb)
@@ -411,6 +412,12 @@
*
*/
APREQ_DECLARE_HOOK(apreq_hook_disable_uploads);
+
+/**
+ * Calls apr_brigade_cleanup on the incoming brigade
+ * after passing the brigade to any subsequent hooks.
+ */
+APREQ_DECLARE_HOOK(apreq_hook_discard_brigade);
#ifdef __cplusplus
}
1.65 +17 -2 httpd-apreq-2/src/apreq_parsers.c
Index: apreq_parsers.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_parsers.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- apreq_parsers.c 12 Sep 2004 06:16:43 -0000 1.64
+++ apreq_parsers.c 12 Sep 2004 19:21:32 -0000 1.65
@@ -1135,7 +1135,7 @@
case APR_INCOMPLETE:
if (parser->hook) {
s = APREQ_RUN_HOOK(parser->hook, env, param, ctx->bb);
- if (s != APR_INCOMPLETE && s != APR_SUCCESS) {
+ if (s != APR_SUCCESS) {
ctx->status = MFD_ERROR;
return s;
}
@@ -1206,6 +1206,15 @@
return APR_EGENERAL;
}
+APREQ_DECLARE_HOOK(apreq_hook_discard_brigade)
+{
+ apr_status_t s = APR_SUCCESS;
+ if (hook->next)
+ s = APREQ_RUN_HOOK(hook->next, env, param, bb);
+ apr_brigade_cleanup(bb);
+ return s;
+}
+
/* generic parser */
@@ -1310,6 +1319,8 @@
s = apr_xml_parser_done(ctx->xml_parser, &ctx->doc);
if (s == APR_SUCCESS) {
ctx->status = XML_COMPLETE;
+ if (hook->next)
+ s = APREQ_RUN_HOOK(hook->next, env, param, bb);
}
else {
ctx->status = XML_ERROR;
@@ -1342,5 +1353,9 @@
}
- return APR_INCOMPLETE;
+ if (hook->next)
+ return APREQ_RUN_HOOK(hook->next, env, param, bb);
+
+ return APR_SUCCESS;
}
+
1.24 +30 -0 httpd-apreq-2/t/parsers.c
Index: parsers.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/t/parsers.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- parsers.c 12 Sep 2004 06:16:43 -0000 1.23
+++ parsers.c 12 Sep 2004 19:21:33 -0000 1.24
@@ -283,6 +283,35 @@
CuAssertStrNEquals(tc, xml_data, val, vlen);
}
+static void hook_discard(CuTest *tc)
+{
+ apr_status_t rv;
+ apreq_param_t *dummy;
+ apreq_request_t *req = apreq_request(APREQ_XML_ENCTYPE, "");
+ apr_bucket_brigade *bb = apr_brigade_create(p,
+ apr_bucket_alloc_create(p));
+ apr_bucket *e = apr_bucket_immortal_create(xml_data,
+ strlen(xml_data),
+ bb->bucket_alloc);
+
+ CuAssertPtrNotNull(tc, req);
+ APR_BRIGADE_INSERT_HEAD(bb, e);
+ APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_eos_create(bb->bucket_alloc));
+
+ req->body = NULL;
+ req->parser = apreq_make_parser(p, APREQ_XML_ENCTYPE,
+ apreq_parse_generic,
+ apreq_make_hook(p,
apreq_hook_discard_brigade,
+ NULL,NULL), NULL);
+ rv = apreq_parse_request(req,bb);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ dummy = *(apreq_param_t **)req->parser->ctx;
+ CuAssertPtrNotNull(tc, dummy);
+ CuAssertPtrNotNull(tc, dummy->bb);
+ CuAssertTrue(tc, APR_BRIGADE_EMPTY(dummy->bb));
+
+}
+
static void parse_related(CuTest *tc)
{
@@ -417,6 +446,7 @@
SUITE_ADD_TEST(suite, parse_generic);
SUITE_ADD_TEST(suite, parse_related);
SUITE_ADD_TEST(suite, parse_mixed);
+ SUITE_ADD_TEST(suite, hook_discard);
return suite;
}