* by the ap_filter_ring_t 'pending_filters' in struct
* conn_rec, and add ring entry 'pending' in struct
* ap_filter_t
+ * 20180711.2 (2.5.1-dev) Add ap_reuse_brigade_from_pool()
*/
#define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20180711
#endif
-#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */
/**
* Determine if the server's current MODULE_MAGIC_NUMBER is at least a
*/
AP_DECLARE(int) ap_request_tainted(request_rec *r, int flags);
+/**
+ * Reuse a brigade from a pool, or create it on the given pool/alloc and
+ * associate it with the given key for further reuse.
+ *
+ * @param key the key/id of the brigade
+ * @param pool the pool to cache and create the brigade from
+ * @param alloc the bucket allocator to be used by the brigade
+ * @return the reused and cleaned up brigade, or a new one
+ */
+AP_DECLARE(apr_bucket_brigade *) ap_reuse_brigade_from_pool(const char *key,
+ apr_pool_t *pool,
+ apr_bucket_alloc_t *alloc);
+
/**
* Cleanup a string (mainly to be filesystem safe)
* We only allow '_' and alphanumeric chars. Non-printable
return rv;
}
-#define RETRIEVE_BRIGADE_FROM_POOL(bb, key, pool, allocator) do { \
- apr_pool_userdata_get((void **)&bb, key, pool); \
- if (bb == NULL) { \
- bb = apr_brigade_create(pool, allocator); \
- apr_pool_userdata_setn((const void *)bb, key, NULL, pool); \
- } \
- else { \
- apr_brigade_cleanup(bb); \
- } \
-} while(0)
-
AP_DECLARE(void) ap_process_request_after_handler(request_rec *r)
{
apr_bucket_brigade *bb;
* this bucket is destroyed, the request will be logged and
* its pool will be freed
*/
- RETRIEVE_BRIGADE_FROM_POOL(bb, "ap_process_request_after_handler_brigade",
- c->pool, c->bucket_alloc);
+ bb = ap_reuse_brigade_from_pool("ap_prah_bb", c->pool, c->bucket_alloc);
b = ap_bucket_eor_create(c->bucket_alloc, r);
APR_BRIGADE_INSERT_HEAD(bb, b);
ap_process_async_request(r);
if (!c->data_in_input_filters || ap_run_input_pending(c) != OK) {
- RETRIEVE_BRIGADE_FROM_POOL(bb, "ap_process_request_brigade",
- c->pool, c->bucket_alloc);
+ bb = ap_reuse_brigade_from_pool("ap_pr_bb", c->pool, c->bucket_alloc);
b = apr_bucket_flush_create(c->bucket_alloc);
APR_BRIGADE_INSERT_HEAD(bb, b);
rv = ap_pass_brigade(c->output_filters, bb);
}
if (!tmp_bb) {
- const char *tmp_bb_key = "ap_request_core_filter_bb";
- tmp_bb = (void *)apr_table_get(f->c->notes, tmp_bb_key);
- if (!tmp_bb) {
- tmp_bb = apr_brigade_create(f->c->pool, f->c->bucket_alloc);
- apr_table_setn(f->c->notes, tmp_bb_key, (void *)tmp_bb);
- }
- f->ctx = tmp_bb;
+ f->ctx = tmp_bb = ap_reuse_brigade_from_pool("ap_rcf_bb", f->c->pool,
+ f->c->bucket_alloc);
}
/* Reinstate any buffered content */
}
status = ap_pass_brigade(f->next, tmp_bb);
+ apr_brigade_cleanup(tmp_bb);
+
if (seen_eor || (status != APR_SUCCESS &&
!APR_STATUS_IS_EOF(status))) {
- apr_brigade_cleanup(tmp_bb);
return status;
}
-
- apr_brigade_cleanup(tmp_bb);
}
return ap_filter_setaside_brigade(f, bb);
return APR_SUCCESS;
}
+AP_DECLARE(apr_bucket_brigade *) ap_reuse_brigade_from_pool(const char *key,
+ apr_pool_t *pool,
+ apr_bucket_alloc_t *alloc)
+{
+ apr_bucket_brigade *bb = NULL;
+ apr_pool_userdata_get((void **)&bb, key, pool);
+ if (bb == NULL) {
+ bb = apr_brigade_create(pool, alloc);
+ apr_pool_userdata_set(bb, key, NULL, pool);
+ }
+ else {
+ apr_brigade_cleanup(bb);
+ }
+ return bb;
+}
+
AP_DECLARE(apr_status_t) ap_str2_alnum(const char *src, char *dest) {
for ( ; *src; src++, dest++)