You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dirk-Willem van Gulik <di...@webweaving.org> on 1999/10/20 22:09:06 UTC
[PATCH] allow ENV var's in config file.
This let you do things lke
DocumentRoot ${DOCROOT}
or
TransferLog ${DIR}/${OPS_CLASS}_access.log
i.e simple environment variables in the various
config files in quite some places.
Any objections against commiting this _horrible_ hack right
now.. (because of course the all singing and dancing 2.0
series will be so clever it won't need this :-)).
Dw
Index: util.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/util.c,v
retrieving revision 1.160
diff -u -r1.160 util.c
--- util.c 1999/04/21 18:25:44 1.160
+++ util.c 1999/10/20 20:13:21
@@ -648,6 +648,36 @@
/* Get a word, (new) config-file style --- quoted strings and backslashes
* all honored
*/
+API_EXPORT(char *) ap_resolve_env(pool *p, const char * word)
+{
+ char tmp[ MAX_STRING_LEN ];
+ char * s, * e;
+ tmp[0] = '\0';
+
+ if (!(s=index(word,'$')))
+ return (char *)word;
+
+ do {
+ /* XXX - relies on strncat() to add '\0'
+ */
+ strncat(tmp,word,s - word);
+ if ((s[1] == '{') && (e=index(s,'}'))) {
+ *e = '\0';
+ word = e + 1;
+ e = getenv(s+2);
+#if 1
+ if (!e)
+ e="!unset!";
+#endif
+ strcat(tmp,e);
+ } else {
+ /* ignore invalid strings */
+ word = s+1;
+ };
+ } while (s=index(word,'$'));
+
+ return ap_pstrdup(p,tmp);
+}
static char *substring_conf(pool *p, const char *start, int len, char quote)
{
@@ -664,7 +694,7 @@
}
*resp++ = '\0';
- return result;
+ return ap_resolve_env(p, result);
}
API_EXPORT(char *) ap_getword_conf_nc(pool *p, char **line)
@@ -710,6 +740,8 @@
while (*strend && ap_isspace(*strend))
++strend;
*line = strend;
+
+
return res;
}
Re: [PATCH] allow ENV var's in config file.
Posted by Dirk-Willem van Gulik <di...@webweaving.org>.
On Wed, 20 Oct 1999, Greg Stein wrote:
> Should you use strchr() rather than index(). My Linux man pages say
> index() is BSD, while strchr() is POSIX.
> On Wed, 20 Oct 1999, Dirk-Willem van Gulik wrote:
> > This let you do things lke
> >
> > DocumentRoot ${DOCROOT}
> > or
> > TransferLog ${DIR}/${OPS_CLASS}_access.log
> >
> > i.e simple environment variables in the various
> > config files in quite some places.
> >
> > Any objections against commiting this _horrible_ hack right
> > now.. (because of course the all singing and dancing 2.0
> > series will be so clever it won't need this :-)).
>
> +0
Correct. Fixed this. Am now going through all modules, as we have a few
places, such as in mod_userdir.c where we do not use ap_getword_conf but
the normal ap_getword_(nc..). This I am now left wondering if I a/ should
fix all those and then b/ deceide not to use this at all and trap/do the
translation the moment we suck in the file. (Thus twarting any other
attemt at using the ${ENV} construct intelligently by higher up clients.)
Dw
Re: [PATCH] allow ENV var's in config file.
Posted by Greg Stein <gs...@lyra.org>.
On Wed, 20 Oct 1999, Dirk-Willem van Gulik wrote:
> This let you do things lke
>
> DocumentRoot ${DOCROOT}
> or
> TransferLog ${DIR}/${OPS_CLASS}_access.log
>
> i.e simple environment variables in the various
> config files in quite some places.
>
> Any objections against commiting this _horrible_ hack right
> now.. (because of course the all singing and dancing 2.0
> series will be so clever it won't need this :-)).
+0
Should you use strchr() rather than index(). My Linux man pages say
index() is BSD, while strchr() is POSIX.
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
Re: [PATCH] allow ENV var's in config file.
Posted by Dean Gaudet <dg...@arctic.org>.
ho hum.
m4.
perl.
insert dean's usual rant about growing a config language organically.
doesn't this break things like mod_rewrite which already use $ as a
special character in its command arguments?
Dean
On Wed, 20 Oct 1999, Dirk-Willem van Gulik wrote:
>
> This let you do things lke
>
> DocumentRoot ${DOCROOT}
> or
> TransferLog ${DIR}/${OPS_CLASS}_access.log
>
> i.e simple environment variables in the various
> config files in quite some places.
>
> Any objections against commiting this _horrible_ hack right
> now.. (because of course the all singing and dancing 2.0
> series will be so clever it won't need this :-)).
>
> Dw
>
> Index: util.c
> ===================================================================
> RCS file: /home/cvs/apache-1.3/src/main/util.c,v
> retrieving revision 1.160
> diff -u -r1.160 util.c
> --- util.c 1999/04/21 18:25:44 1.160
> +++ util.c 1999/10/20 20:13:21
> @@ -648,6 +648,36 @@
> /* Get a word, (new) config-file style --- quoted strings and backslashes
> * all honored
> */
> +API_EXPORT(char *) ap_resolve_env(pool *p, const char * word)
> +{
> + char tmp[ MAX_STRING_LEN ];
> + char * s, * e;
> + tmp[0] = '\0';
> +
> + if (!(s=index(word,'$')))
> + return (char *)word;
> +
> + do {
> + /* XXX - relies on strncat() to add '\0'
> + */
> + strncat(tmp,word,s - word);
> + if ((s[1] == '{') && (e=index(s,'}'))) {
> + *e = '\0';
> + word = e + 1;
> + e = getenv(s+2);
> +#if 1
> + if (!e)
> + e="!unset!";
> +#endif
> + strcat(tmp,e);
> + } else {
> + /* ignore invalid strings */
> + word = s+1;
> + };
> + } while (s=index(word,'$'));
> +
> + return ap_pstrdup(p,tmp);
> +}
>
> static char *substring_conf(pool *p, const char *start, int len, char quote)
> {
> @@ -664,7 +694,7 @@
> }
>
> *resp++ = '\0';
> - return result;
> + return ap_resolve_env(p, result);
> }
>
> API_EXPORT(char *) ap_getword_conf_nc(pool *p, char **line)
> @@ -710,6 +740,8 @@
> while (*strend && ap_isspace(*strend))
> ++strend;
> *line = strend;
> +
> +
> return res;
> }
>
>
>