From: Stefan Fritsch Date: Sat, 20 Aug 2011 18:29:02 +0000 (+0000) Subject: Simplify some overly complicated code using apr_brigade_putstrs and apr_pstrcat X-Git-Tag: 2.3.15~376 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be55d0f140b09342f5f0ea3d0d3f71ce22c449b8;p=apache Simplify some overly complicated code using apr_brigade_putstrs and apr_pstrcat Submitted by: Christophe Jaillet , Stefan Fritsch git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1159896 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/filters/mod_include.c b/modules/filters/mod_include.c index f4cf28331b..db3b2a2a4f 100644 --- a/modules/filters/mod_include.c +++ b/modules/filters/mod_include.c @@ -2680,36 +2680,18 @@ static apr_status_t handle_printenv(include_ctx_t *ctx, ap_filter_t *f, 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) { + if (val_text == LAZY_VALUE) val_text = add_include_vars_lazy(r, elts[i].key, ctx->time_str); - } val_text = ap_escape_html(ctx->dpool, val_text); - 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)); + + apr_brigade_putstrs(bb, NULL, NULL, key_text, "=", val_text, "\n", + NULL); } ctx->flush_now = 1; diff --git a/modules/http/http_filters.c b/modules/http/http_filters.c index fa832fa1cf..86b74e8d82 100644 --- a/modules/http/http_filters.c +++ b/modules/http/http_filters.c @@ -655,23 +655,10 @@ static int form_header_field(header_struct *h, #if APR_CHARSET_EBCDIC char *headfield; apr_size_t len; - apr_size_t name_len; - apr_size_t val_len; - char *next; - - name_len = strlen(fieldname); - val_len = strlen(fieldval); - len = name_len + val_len + 4; /* 4 for ": " plus CRLF */ - headfield = (char *)apr_palloc(h->pool, len + 1); - memcpy(headfield, fieldname, name_len); - next = headfield + name_len; - *next++ = ':'; - *next++ = ' '; - memcpy(next, fieldval, val_len); - next += val_len; - *next++ = CR; - *next++ = LF; - *next = 0; + + headfield = apr_pstrcat(h->pool, fieldname, ": ", fieldval, CRLF, NULL); + len = strlen(headfield); + ap_xlate_proto_to_ascii(headfield, len); apr_brigade_write(h->bb, NULL, NULL, headfield, len); #else