From: André Malo Date: Fri, 22 Aug 2003 23:03:35 +0000 (+0000) Subject: cleanup handle_printenv function X-Git-Tag: pre_ajp_proxy~1234 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbc1a65d92fffc9da8c2213f2d42eaf7d4d4ec05;p=apache cleanup handle_printenv function git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@101068 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/filters/mod_include.c b/modules/filters/mod_include.c index 8fd2ea9eb0..eeafe57633 100644 --- a/modules/filters/mod_include.c +++ b/modules/filters/mod_include.c @@ -2428,59 +2428,72 @@ static apr_status_t handle_set(include_ctx_t *ctx, ap_filter_t *f, return APR_SUCCESS; } +/* + * + */ static apr_status_t handle_printenv(include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb) { - char *tag = NULL; - char *tag_val = NULL; - apr_bucket *tmp_buck; request_rec *r = f->r; + const apr_array_header_t *arr; + const apr_table_entry_t *elts; + int i; - if (ctx->flags & SSI_FLAG_PRINTING) { - ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, SSI_VALUE_DECODED); - if (!tag && !tag_val) { - const apr_array_header_t *arr = apr_table_elts(r->subprocess_env); - const apr_table_entry_t *elts = (const apr_table_entry_t *)arr->elts; - int i; - const char *key_text, *val_text; - char *key_val, *next; - apr_size_t k_len, v_len, kv_length; - - for (i = 0; i < arr->nelts; ++i) { - key_text = ap_escape_html(r->pool, elts[i].key); - val_text = elts[i].val; - if (val_text == LAZY_VALUE) { - val_text = add_include_vars_lazy(r, elts[i].key); - } - val_text = ap_escape_html(r->pool, elts[i].val); - k_len = strlen(key_text); - v_len = strlen(val_text); - kv_length = k_len + v_len + sizeof("=\n"); - key_val = apr_palloc(r->pool, kv_length); - next = key_val; - memcpy(next, key_text, k_len); - next += k_len; - *next++ = '='; - memcpy(next, val_text, v_len); - next += v_len; - *next++ = '\n'; - *next = 0; - tmp_buck = apr_bucket_pool_create(key_val, kv_length - 1, - r->pool, - r->connection->bucket_alloc); - APR_BRIGADE_INSERT_TAIL(bb, tmp_buck); - } - return APR_SUCCESS; - } - else { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, - "printenv directive does not take tags in %s", - r->filename); - SSI_CREATE_ERROR_BUCKET(ctx, f, bb); - return APR_SUCCESS; + if (ctx->argc) { + ap_log_rerror(APLOG_MARK, + (ctx->flags & SSI_FLAG_PRINTING) + ? APLOG_ERR : APLOG_WARNING, + 0, r, "printenv directive does not take tags in %s", + r->filename); + } + + if (!(ctx->flags & SSI_FLAG_PRINTING)) { + return APR_SUCCESS; + } + + if (ctx->argc) { + SSI_CREATE_ERROR_BUCKET(ctx, f, bb); + return APR_SUCCESS; + } + + arr = apr_table_elts(r->subprocess_env); + elts = (apr_table_entry_t *)arr->elts; + + for (i = 0; i < arr->nelts; ++i) { + const char *key_text, *val_text; + char *key_val, *next; + apr_size_t k_len, v_len, kv_length; + + /* get key */ + key_text = ap_escape_html(ctx->dpool, elts[i].key); + k_len = strlen(key_text); + + /* get value */ + val_text = elts[i].val; + if (val_text == LAZY_VALUE) { + val_text = add_include_vars_lazy(r, elts[i].key); } + val_text = ap_escape_html(ctx->dpool, elts[i].val); + v_len = strlen(val_text); + + /* assemble result */ + kv_length = k_len + v_len + sizeof("=\n"); + key_val = apr_palloc(ctx->pool, kv_length); + next = key_val; + + memcpy(next, key_text, k_len); + next += k_len; + *next++ = '='; + memcpy(next, val_text, v_len); + next += v_len; + *next++ = '\n'; + *next = 0; + + APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pool_create(key_val, kv_length-1, + ctx->pool, f->c->bucket_alloc)); } + ctx->flush_now = 1; return APR_SUCCESS; }