In the department of scratching old itches - any strong objections to me
adding the following patch which allows one to do things like
# httpd.conf
ServerRoot ${HOME}/apache
Port ${PORT:=80}
ErrorDocument 500 "Please contact ${CUSTOMER}
and then
[EMAIL PROTECTED] PORT=1234 ./apachectl start
as few, if any, people use ${FOO} constructs in their configuration files
today - the change is rather harmless.
But I've found this useful (since 1.3.9 :-).
Objections ?
Dw
? http_main.c-with-mtext
Index: http_core.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/http_core.c,v
retrieving revision 1.316
diff -u -r1.316 http_core.c
--- http_core.c 21 Sep 2002 17:18:34 -0000 1.316
+++ http_core.c 26 Sep 2002 00:45:53 -0000
@@ -1258,6 +1258,8 @@
w, NULL);
}
+ line = ap_resolve_env(cmd->pool,line);
+
/* The entry should be ignored if it is a full URL for a 401 error */
if (error_number == 401 &&
Index: util.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/util.c,v
retrieving revision 1.206
diff -u -r1.206 util.c
--- util.c 18 Jun 2002 00:59:58 -0000 1.206
+++ util.c 26 Sep 2002 00:45:55 -0000
@@ -756,6 +756,49 @@
return res;
}
+/* Check a string for any ${ENV} environment variable
+ * construct and replace each them by the value of
+ * that environment variable, if it exists. If the
+ * environment value does not exist, replace by an
+ * empty string. Any unrecognized construct is not
+ * replaced and silently ignored. Apart from that
+ * simple ${ENV:=defaults} are also possible.
+ */
+API_EXPORT(char *) ap_resolve_env(pool *p, const char * word)
+{
+ char tmp[ MAX_STRING_LEN ];
+ char * s, * e;
+ tmp[0] = '\0';
+
+ if (!(s=strchr(word,'$')))
+ return (char *)word;
+
+ do {
+ /* XXX - relies on strncat() to add '\0'
+ */
+ strncat(tmp,word,s - word);
+
+ if ((s[1] == '{') && (e=strchr(s,'}'))) {
+ char * dfault = "";
+ *e = '\0';
+ if ((dfault = strchr(s,':')) && ((dfault[1] == '='))) {
+ *dfault = '\0';
+ dfault +=2;
+ }
+ word = e + 1;
+ e = getenv(s+2);
+ strcat(tmp,e ? e : dfault);
+ } else {
+ /* ignore invalid strings */
+ word = s+1;
+ strcat(tmp,"$");
+ };
+ } while ((s=strchr(word,'$')));
+ strcat(tmp,word);
+
+ return ap_pstrdup(p,tmp);
+}
+
/* Get a word, (new) config-file style --- quoted strings and backslashes
* all honored
*/
@@ -775,7 +818,7 @@
}
*resp++ = '\0';
- return result;
+ return ap_resolve_env(p, result);
}
API_EXPORT(char *) ap_getword_conf_nc(pool *p, char **line)