Mon May 4 12:26:37 2020 UTC ()
Add expr suppoort in mod_subsitutre RHS, from upstream trunk
(manu)
diff -r1.89 -r1.90 pkgsrc/www/apache24/Makefile
diff -r1.42 -r1.43 pkgsrc/www/apache24/distinfo
diff -r0 -r1.1 pkgsrc/www/apache24/patches/patch-modules_filters_mod_substitute.c
--- pkgsrc/www/apache24/Makefile 2020/04/06 08:27:26 1.89
+++ pkgsrc/www/apache24/Makefile 2020/05/04 12:26:37 1.90
| @@ -1,22 +1,23 @@ | | | @@ -1,22 +1,23 @@ |
1 | # $NetBSD: Makefile,v 1.89 2020/04/06 08:27:26 wiz Exp $ | | 1 | # $NetBSD: Makefile,v 1.90 2020/05/04 12:26:37 manu Exp $ |
2 | # | | 2 | # |
3 | # When updating this package, make sure that no strings like | | 3 | # When updating this package, make sure that no strings like |
4 | # "PR 12345" are in the commit message. Upstream likes | | 4 | # "PR 12345" are in the commit message. Upstream likes |
5 | # to reference their own PRs this way, but this ends up | | 5 | # to reference their own PRs this way, but this ends up |
6 | # in NetBSD GNATS. | | 6 | # in NetBSD GNATS. |
7 | | | 7 | |
8 | DISTNAME= httpd-2.4.43 | | 8 | DISTNAME= httpd-2.4.43 |
9 | PKGNAME= ${DISTNAME:S/httpd/apache/} | | 9 | PKGNAME= ${DISTNAME:S/httpd/apache/} |
| | | 10 | PKGREVISION= 1 |
10 | CATEGORIES= www | | 11 | CATEGORIES= www |
11 | MASTER_SITES= ${MASTER_SITE_APACHE:=httpd/} | | 12 | MASTER_SITES= ${MASTER_SITE_APACHE:=httpd/} |
12 | MASTER_SITES+= http://archive.apache.org/dist/httpd/ | | 13 | MASTER_SITES+= http://archive.apache.org/dist/httpd/ |
13 | MASTER_SITES+= http://archive.eu.apache.org/dist/httpd/ | | 14 | MASTER_SITES+= http://archive.eu.apache.org/dist/httpd/ |
14 | EXTRACT_SUFX= .tar.bz2 | | 15 | EXTRACT_SUFX= .tar.bz2 |
15 | | | 16 | |
16 | MAINTAINER= ryoon@NetBSD.org | | 17 | MAINTAINER= ryoon@NetBSD.org |
17 | HOMEPAGE= http://httpd.apache.org/ | | 18 | HOMEPAGE= http://httpd.apache.org/ |
18 | COMMENT= Apache HTTP (Web) server, version 2.4 | | 19 | COMMENT= Apache HTTP (Web) server, version 2.4 |
19 | LICENSE= apache-2.0 | | 20 | LICENSE= apache-2.0 |
20 | | | 21 | |
21 | BUILD_DEFS+= IPV6_READY | | 22 | BUILD_DEFS+= IPV6_READY |
22 | BUILD_DEFS+= VARBASE | | 23 | BUILD_DEFS+= VARBASE |
--- pkgsrc/www/apache24/distinfo 2020/04/06 08:27:26 1.42
+++ pkgsrc/www/apache24/distinfo 2020/05/04 12:26:37 1.43
| @@ -1,17 +1,18 @@ | | | @@ -1,17 +1,18 @@ |
1 | $NetBSD: distinfo,v 1.42 2020/04/06 08:27:26 wiz Exp $ | | 1 | $NetBSD: distinfo,v 1.43 2020/05/04 12:26:37 manu Exp $ |
2 | | | 2 | |
3 | SHA1 (httpd-2.4.43.tar.bz2) = fc078df062503ffcf19319c4bf4e8cf27fe30cb4 | | 3 | SHA1 (httpd-2.4.43.tar.bz2) = fc078df062503ffcf19319c4bf4e8cf27fe30cb4 |
4 | RMD160 (httpd-2.4.43.tar.bz2) = 8ccc599b50478330e5505bf75780145d80f4f4ce | | 4 | RMD160 (httpd-2.4.43.tar.bz2) = 8ccc599b50478330e5505bf75780145d80f4f4ce |
5 | SHA512 (httpd-2.4.43.tar.bz2) = 16cfeecc8f6fab6eca478065a384bdf1872f7ac42206b0bc2bcac6c0d9c576f392c07107201f39e0601dec1bbafcb33d66153544de4d87d79b9a52094d334b64 | | 5 | SHA512 (httpd-2.4.43.tar.bz2) = 16cfeecc8f6fab6eca478065a384bdf1872f7ac42206b0bc2bcac6c0d9c576f392c07107201f39e0601dec1bbafcb33d66153544de4d87d79b9a52094d334b64 |
6 | Size (httpd-2.4.43.tar.bz2) = 7155865 bytes | | 6 | Size (httpd-2.4.43.tar.bz2) = 7155865 bytes |
7 | SHA1 (patch-aa) = 9a66685f1d2e4710ab464beda98cbaad632aebf9 | | 7 | SHA1 (patch-aa) = 9a66685f1d2e4710ab464beda98cbaad632aebf9 |
8 | SHA1 (patch-ab) = a3edcc20b7654e0446c7d442cda1510b23e5d324 | | 8 | SHA1 (patch-ab) = a3edcc20b7654e0446c7d442cda1510b23e5d324 |
9 | SHA1 (patch-ac) = 9f86d845df30316d22bce677a4b176f51007ba0d | | 9 | SHA1 (patch-ac) = 9f86d845df30316d22bce677a4b176f51007ba0d |
10 | SHA1 (patch-ad) = 4ba4a9c812951f533fa316e5dbf17eaab5494157 | | 10 | SHA1 (patch-ad) = 4ba4a9c812951f533fa316e5dbf17eaab5494157 |
11 | SHA1 (patch-ae) = 5bd3bf54e792bf8a2916d7e1b49b1702b02c6903 | | 11 | SHA1 (patch-ae) = 5bd3bf54e792bf8a2916d7e1b49b1702b02c6903 |
12 | SHA1 (patch-ag) = 50c7f0fab1cb90ac573f1c47f2d37f9c2a6247e1 | | 12 | SHA1 (patch-ag) = 50c7f0fab1cb90ac573f1c47f2d37f9c2a6247e1 |
13 | SHA1 (patch-ai) = d3870e46e41adc97c3fce86f9ffd224502ad6b0c | | 13 | SHA1 (patch-ai) = d3870e46e41adc97c3fce86f9ffd224502ad6b0c |
14 | SHA1 (patch-al) = 02d9ade5aac4270182063d5ad413970c832ee911 | | 14 | SHA1 (patch-al) = 02d9ade5aac4270182063d5ad413970c832ee911 |
15 | SHA1 (patch-am) = acdf7198ae8b4353cfc70c8015a0f09de036b777 | | 15 | SHA1 (patch-am) = acdf7198ae8b4353cfc70c8015a0f09de036b777 |
16 | SHA1 (patch-aw) = 43cd64df886853ef7b75b91ed20183f329fcc9df | | 16 | SHA1 (patch-aw) = 43cd64df886853ef7b75b91ed20183f329fcc9df |
17 | SHA1 (patch-include_ap__config.h) = 1d056e2d4db80ec97aaf755b6dd6aff69ed2cd96 | | 17 | SHA1 (patch-include_ap__config.h) = 1d056e2d4db80ec97aaf755b6dd6aff69ed2cd96 |
| | | 18 | SHA1 (patch-modules_filters_mod_substitute.c) = 730af0342b78de04fe51b7dcc3ed057b2b0c3a54 |
$NetBSD: patch-modules_filters_mod_substitute.c,v 1.1 2020/05/04 12:26:37 manu Exp $
expr= support in RHS, from upstream trunk
--- ./modules/filters/mod_substitute.c.orig
+++ ./modules/filters/mod_substitute.c
@@ -29,8 +29,9 @@
#include "util_filter.h"
#include "util_varbuf.h"
#include "apr_buckets.h"
#include "http_request.h"
+#include "ap_expr.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
/*
@@ -51,8 +52,9 @@
apr_size_t replen;
apr_size_t patlen;
int flatten;
const char *from;
+ ap_expr_info_t* expr_replacement;
} subst_pattern_t;
typedef struct {
apr_array_header_t *patterns;
@@ -68,8 +70,13 @@
apr_bucket_brigade *pattbb;
apr_pool_t *tpool;
} substitute_module_ctx;
+typedef struct {
+ const char **expcache;
+ int *expcache_len;
+} subst_req_t;
+
static void *create_substitute_dcfg(apr_pool_t *p, char *d)
{
subst_dir_conf *dcfg =
(subst_dir_conf *) apr_palloc(p, sizeof(subst_dir_conf));
@@ -96,9 +103,9 @@
* was to apply inherited subst patterns after locally scoped patterns.
* In later 2.2 and 2.4 versions, SubstituteInheritBefore may be toggled
* 'on' to follow the corrected/expected behavior, without violating POLS.
*/
- if (a->inherit_before == 1) {
+ if (a->inherit_before) {
a->patterns = apr_array_append(p, base->patterns,
over->patterns);
}
else {
@@ -136,13 +143,16 @@
const char *buff;
struct ap_varbuf vb;
apr_bucket *b;
apr_bucket *tmp_b;
+ subst_pattern_t *script;
subst_dir_conf *cfg =
(subst_dir_conf *) ap_get_module_config(f->r->per_dir_config,
&substitute_module);
- subst_pattern_t *script;
+ subst_req_t *rconf =
+ (subst_req_t*) ap_get_module_config(f->r->request_config,
+ &substitute_module);
APR_BRIGADE_INSERT_TAIL(mybb, inb);
ap_varbuf_init(pool, &vb, 0);
@@ -154,8 +164,18 @@
if (cfg->patterns->nelts == 1) {
force_quick = 1;
}
for (i = 0; i < cfg->patterns->nelts; i++) {
+ const char *replacement = script->replacement;
+ apr_size_t replen = script->replen;
+ if (script->expr_replacement) {
+ if (!rconf) {
+ rconf = apr_pcalloc(f->r->pool, sizeof(*rconf));
+ rconf->expcache = apr_pcalloc(f->r->pool, sizeof(const char*) * cfg->patterns->nelts);
+ rconf->expcache_len = apr_pcalloc(f->r->pool, sizeof(int) * cfg->patterns->nelts);
+ ap_set_module_config(f->r->request_config, &substitute_module, rconf);
+ }
+ }
for (b = APR_BRIGADE_FIRST(mybb);
b != APR_BRIGADE_SENTINEL(mybb);
b = APR_BUCKET_NEXT(b)) {
if (APR_BUCKET_IS_METADATA(b)) {
@@ -186,14 +206,28 @@
* space_left counts how many bytes we have left until the
* line length reaches max_line_length.
*/
apr_size_t space_left = cfg->max_line_length;
- apr_size_t repl_len = strlen(script->replacement);
while ((repl = apr_strmatch(script->pattern, buff, bytes)))
{
+
+ if (!have_match && script->expr_replacement) {
+ if (!rconf->expcache[i]) {
+ const char *err = NULL;
+ rconf->expcache[i] = ap_expr_str_exec(f->r, script->expr_replacement, &err);
+ if (err) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, "error evaluating expression: %s", err);
+ return APR_EINVAL;
+ }
+ rconf->expcache_len[i] = strlen(rconf->expcache[i]);
+ }
+ replacement = rconf->expcache[i];
+ replen = rconf->expcache_len[i];
+ }
+
ap_log_rerror(APLOG_MARK, APLOG_TRACE8, 0, f->r,
"Matching found, result: '%s'",
- script->replacement);
+ replacement);
have_match = 1;
/* get offset into buff for pattern */
len = (apr_size_t) (repl - buff);
if (script->flatten && !force_quick) {
@@ -204,23 +238,23 @@
* contain and use them. This is slow, since we
* are constanting allocing space and copying
* strings.
*/
- if (vb.strlen + len + repl_len > cfg->max_line_length)
+ if (vb.strlen + len + replen > cfg->max_line_length)
return APR_ENOMEM;
ap_varbuf_strmemcat(&vb, buff, len);
- ap_varbuf_strmemcat(&vb, script->replacement, repl_len);
+ ap_varbuf_strmemcat(&vb, replacement, replen);
}
else {
/*
* The string before the match but after the
* previous match (if any) has length 'len'.
* Check if we still have space for this string and
* the replacement string.
*/
- if (space_left < len + repl_len)
+ if (space_left < len + replen)
return APR_ENOMEM;
- space_left -= len + repl_len;
+ space_left -= len + replen;
/*
* We now split off the string before the match
* as its own bucket, then isolate the matched
* string and delete it.
@@ -229,10 +263,10 @@
/*
* Finally, we create a bucket that contains the
* replacement...
*/
- tmp_b = apr_bucket_transient_create(script->replacement,
- script->replen,
+ tmp_b = apr_bucket_transient_create(replacement,
+ replen,
f->r->connection->bucket_alloc);
/* ... and insert it */
APR_BUCKET_INSERT_BEFORE(b, tmp_b);
}
@@ -281,8 +315,22 @@
apr_size_t space_left = cfg->max_line_length;
while (!ap_regexec_len(script->regexp, pos, left,
AP_MAX_REG_MATCH, regm, 0)) {
apr_status_t rv;
+ if (!have_match && script->expr_replacement) {
+ if (!rconf->expcache[i]) {
+ const char *err = NULL;
+ rconf->expcache[i] = ap_expr_str_exec(f->r, script->expr_replacement, &err);
+ if (err) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, "error evaluating expression: %s", err);
+ return APR_EGENERAL;
+ }
+ rconf->expcache_len[i] = strlen(rconf->expcache[i]);
+ }
+ replacement = rconf->expcache[i];
+ replen = rconf->expcache_len[i];
+ }
+
ap_log_rerror(APLOG_MARK, APLOG_TRACE8, 0, f->r,
"Matching found");
have_match = 1;
if (script->flatten && !force_quick) {
@@ -295,9 +343,9 @@
/* copy bytes before the match */
if (regm[0].rm_so > 0)
ap_varbuf_strmemcat(&vb, pos, regm[0].rm_so);
/* add replacement string, last argument is unsigned! */
- rv = ap_varbuf_regsub(&vb, script->replacement, pos,
+ rv = ap_varbuf_regsub(&vb, replacement, pos,
AP_MAX_REG_MATCH, regm,
cfg->max_line_length - vb.strlen);
if (rv != APR_SUCCESS)
return rv;
@@ -310,9 +358,9 @@
if (space_left <= regm[0].rm_so)
return APR_ENOMEM;
space_left -= regm[0].rm_so;
rv = ap_pregsub_ex(pool, &repl,
- script->replacement, pos,
+ replacement, pos,
AP_MAX_REG_MATCH, regm,
space_left);
if (rv != APR_SUCCESS)
return rv;
@@ -462,8 +510,9 @@
apr_brigade_cleanup(ctx->linebb);
}
APR_BUCKET_REMOVE(b);
APR_BRIGADE_INSERT_TAIL(ctx->passbb, b);
+ ap_remove_output_filter(f);
}
/*
* No need to handle FLUSH buckets separately as we call
* ap_pass_brigade anyway at the end of the loop.
@@ -690,8 +739,20 @@
}
nscript->replacement = to;
nscript->replen = strlen(to);
+
+ if (!strncasecmp(to, "expr=", 5)) {
+ const char *err;
+ nscript->expr_replacement = ap_expr_parse_cmd(cmd, to+5,
+ AP_EXPR_FLAG_STRING_RESULT,
+ &err, NULL);
+ if (err) {
+ return apr_pstrcat(cmd->pool,
+ "Can't parse value expression : ", err, NULL);
+ }
+ }
+
nscript->flatten = flatten;
return NULL;
}