Commit f6c93f27 authored by Yann Ylavic's avatar Yann Ylavic
Browse files

core: Add ap_reuse_brigade_from_pool().

Current RETRIEVE_BRIGADE_FROM_POOL macro from "http_request.c" is turned into
a helper and used in ap_request_core_filter().

We will need it in a subsequent commit in "util_filter.c" too.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1836018 13f79535-47bb-0310-9956-ffa450edef68
parent 93bab76a
Loading
Loading
Loading
Loading
+2 −1
Changes for include/ap_mmn.h: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -580,6 +580,7 @@
 *                         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" */
@@ -587,7 +588,7 @@
#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
+13 −0
Changes for include/httpd.h: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2193,6 +2193,19 @@ AP_DECLARE(int) ap_request_has_body(request_rec *r);
 */
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
+2 −15
Changes for modules/http/http_request.c: 2 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -345,17 +345,6 @@ AP_DECLARE(apr_status_t) ap_check_pipeline(conn_rec *c, apr_bucket_brigade *bb,
    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;
@@ -368,8 +357,7 @@ AP_DECLARE(void) ap_process_request_after_handler(request_rec *r)
     * 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);

@@ -507,8 +495,7 @@ AP_DECLARE(void) ap_process_request(request_rec *r)
    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);
+4 −10
Changes for server/request.c: 4 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -2081,13 +2081,8 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_request_core_filter(ap_filter_t *f,
    }

    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 */
@@ -2137,13 +2132,12 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_request_core_filter(ap_filter_t *f,
        }

        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);
+16 −0
Changes for server/util.c: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2675,6 +2675,22 @@ AP_DECLARE_NONSTD(apr_status_t) ap_pool_cleanup_set_null(void *data_)
    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++)