]> granicus.if.org Git - apache/commitdiff
Another one in the department of fairly useless patches which
authorDirk-Willem van Gulik <dirkx@apache.org>
Tue, 14 Mar 2000 14:09:52 +0000 (14:09 +0000)
committerDirk-Willem van Gulik <dirkx@apache.org>
Tue, 14 Mar 2000 14:09:52 +0000 (14:09 +0000)
are best described as feature creep. Allows ${ENV} constructs
in the config file. This avoids the need for mod_perl or
m4 cleverness whilst mainting some of the usefullness. It
does not do (of course) multiline things or anything that clever.

Feel free to flame me.

PR:
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@84765 13f79535-47bb-0310-9956-ffa450edef68

include/httpd.h
server/config.c
server/util.c

index 3c33893dd45ae587354130731fa4a7e143cfd668..23eef47205bb1532cd4de4f5b549c33979b2b2a2 100644 (file)
@@ -918,6 +918,7 @@ API_EXPORT(char *) ap_getword_nulls(ap_context_t *p, const char **line, char sto
 API_EXPORT(char *) ap_getword_nulls_nc(ap_context_t *p, char **line, char stop);
 API_EXPORT(char *) ap_getword_conf(ap_context_t *p, const char **line);
 API_EXPORT(char *) ap_getword_conf_nc(ap_context_t *p, char **line);
+API_EXPORT(char *) ap_resolve_env(ap_context_t *p, const char * word); 
 
 API_EXPORT(const char *) ap_size_list_item(const char **field, int *len);
 API_EXPORT(char *) ap_get_list_item(ap_context_t *p, const char **field);
index 4ab643767128cded1a00378afd129b3e06795ca2..cc1d0f244b40749295c20ec34d31aa74ab583a80 100644 (file)
@@ -636,6 +636,9 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
 
     switch (cmd->args_how) {
     case RAW_ARGS:
+#ifdef RESOLVE_ENV_PER_TOKEN
+       args = ap_resolve_env(parms->pool,args);
+#endif
        return ((const char *(*)(cmd_parms *, void *, const char *))
                (cmd->func)) (parms, mconfig, args);
 
@@ -829,6 +832,7 @@ CORE_EXPORT(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module
     return mconfig;
 }
 
+
 CORE_EXPORT(const char *) ap_handle_command(cmd_parms *parms, void *config, const char *l)
 {
     void *oldconfig;
@@ -839,7 +843,11 @@ CORE_EXPORT(const char *) ap_handle_command(cmd_parms *parms, void *config, cons
     if ((l[0] == '#') || (!l[0]))
        return NULL;
 
+#if RESOLVE_ENV_PER_TOKEN
     args = l;
+#else
+    args = ap_resolve_env(parms->temp_pool,l); 
+#endif
     cmd_name = ap_getword_conf(parms->temp_pool, &args);
     if (*cmd_name == '\0')
        return NULL;
index 063359f01da0bfa0181ee5b57ebff05e44121039..2260af249c63b2ba19f9efcbc71d66f98c772a1f 100644 (file)
@@ -706,7 +706,11 @@ static char *substring_conf(ap_context_t *p, const char *start, int len, char qu
     }
 
     *resp++ = '\0';
+#if RESOLVE_ENV_PER_TOKEN
+    return ap_resolve_env(p,result);
+#else
     return result;
+#endif
 }
 
 API_EXPORT(char *) ap_getword_conf_nc(ap_context_t *p, char **line)
@@ -755,6 +759,41 @@ API_EXPORT(char *) ap_getword_conf(ap_context_t *p, const char **line)
     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.
+ */
+API_EXPORT(char *) ap_resolve_env(ap_context_t *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,'}'))) {
+                       *e = '\0';
+                       word = e + 1;
+                       e = getenv(s+2);
+                       strcat(tmp,e ? e : "");
+               } else {
+                       /* ignore invalid strings */
+                       word = s+1;
+                       strcat(tmp,"$");
+               };
+       } while ((s=strchr(word,'$')));
+       strcat(tmp,word);
+
+       return ap_pstrdup(p,tmp);
+}
 API_EXPORT(int) ap_cfg_closefile(configfile_t *cfp)
 {
 #ifdef DEBUG