Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3C676200C34 for ; Mon, 27 Feb 2017 12:19:23 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3B05A160B6C; Mon, 27 Feb 2017 11:19:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5D283160B60 for ; Mon, 27 Feb 2017 12:19:22 +0100 (CET) Received: (qmail 85835 invoked by uid 500); 27 Feb 2017 11:19:21 -0000 Mailing-List: contact dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list dev@httpd.apache.org Received: (qmail 85824 invoked by uid 99); 27 Feb 2017 11:19:21 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Feb 2017 11:19:21 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id E05011A061C for ; Mon, 27 Feb 2017 11:19:20 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -7.221 X-Spam-Level: X-Spam-Status: No, score=-7.221 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id hQPGP0B-Xr10 for ; Mon, 27 Feb 2017 11:19:18 +0000 (UTC) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id EEC705F1C2 for ; Mon, 27 Feb 2017 11:19:17 +0000 (UTC) Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E202D3E9 for ; Mon, 27 Feb 2017 11:19:17 +0000 (UTC) Received: from iberis (ovpn-120-99.rdu2.redhat.com [10.10.120.99] (may be forged)) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RBJGE5019905 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 27 Feb 2017 06:19:17 -0500 Received: from jorton by iberis with local (Exim 4.87) (envelope-from ) id 1ciJKl-0005hz-99 for dev@httpd.apache.org; Mon, 27 Feb 2017 11:19:15 +0000 Date: Mon, 27 Feb 2017 11:19:15 +0000 From: Joe Orton To: dev@httpd.apache.org Subject: Re: [RFC] ? Message-ID: <20170227111915.GA7774@redhat.com> Mail-Followup-To: dev@httpd.apache.org References: <20170221215809.GA13579@redhat.com> <1fd376ac-ebd9-a388-245b-f88c07387865@gmail.com> <20170222104702.GA6992@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="1yeeQ81UyVL57Vl7" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.1 (2016-10-04) Organization: Registered in England and Wales under Company Registration No. 03798903 Directors: Michael Cunningham (US), Michael O'Neill (Ireland), Paul Argiry (US) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 27 Feb 2017 11:19:17 +0000 (UTC) archived-at: Mon, 27 Feb 2017 11:19:23 -0000 --1yeeQ81UyVL57Vl7 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On Wed, Feb 22, 2017 at 10:00:08PM +0100, Yann Ylavic wrote: > On Wed, Feb 22, 2017 at 11:47 AM, Joe Orton wrote: > > (b) for match both "foo" and " > I'd vote for this, it's very unlikely that some day we want to add a > directive called VirtualHost or If (w/o the leading '<') which may > conflict here, so it shouldn't hurt. I'm fine with that, I'll commit like this unless anybody else has strong opinions. Regards, Joe --1yeeQ81UyVL57Vl7 Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="ap_ifdirective.diff" Index: server/config.c =================================================================== --- server/config.c (revision 1784534) +++ server/config.c (working copy) @@ -2668,6 +2668,24 @@ printf(" %s\n", ap_loaded_modules[n]->name); } +AP_DECLARE(int) ap_exists_directive(apr_pool_t *p, const char *name) +{ + char *lname; + + if (!ap_config_hash) + return 0; + + lname = apr_pstrdup(p, name); + ap_str_tolower(lname); + + if (apr_hash_get(ap_config_hash, lname, APR_HASH_KEY_STRING) != NULL) + return 1; + + /* Try '<'-prefixed form. */ + return apr_hash_get(ap_config_hash, apr_pstrcat(p, "<", lname, NULL), + APR_HASH_KEY_STRING) != NULL; + } + AP_DECLARE(void *) ap_retained_data_get(const char *key) { void *retained; Index: include/http_config.h =================================================================== --- include/http_config.h (revision 1784534) +++ include/http_config.h (working copy) @@ -992,6 +992,15 @@ AP_DECLARE(void) ap_show_directives(void); /** + * Returns non-zero if a configuration directive of the given name has + * been registered by a module at the time of calling. + * @param p Temporary pool + * @param name Directive name to match, case-insensitively, either + * directly or against '<'-prefixed container form. + */ +AP_DECLARE(int) ap_exists_directive(apr_pool_t *p, const char *name); + +/** * Show the preloaded module names. Used for httpd -l. */ AP_DECLARE(void) ap_show_modules(void); Index: server/core.c =================================================================== --- server/core.c (revision 1784534) +++ server/core.c (working copy) @@ -2894,6 +2894,46 @@ } } + +static const char *start_ifdirective(cmd_parms *cmd, void *dummy, const char *arg) +{ + const char *endp; + int defined; + int not = 0; + + endp = ap_strrchr_c(arg, '>'); + if (endp == NULL) { + return unclosed_directive(cmd); + } + + arg = apr_pstrmemdup(cmd->temp_pool, arg, endp - arg); + + if (arg[0] == '!') { + not = 1; + arg++; + } + + if (!arg[0]) { + return missing_container_arg(cmd); + } + + defined = ap_exists_directive(cmd->temp_pool, arg); + if ((!not && defined) || (not && !defined)) { + ap_directive_t *parent = NULL; + ap_directive_t *current = NULL; + const char *retval; + + retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd, + ¤t, &parent, " business */ static const char *virtualhost_section(cmd_parms *cmd, void *dummy, @@ -4509,6 +4549,8 @@ "Container for directives based on existence of command line defines"), AP_INIT_TAKE1("