You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by sf...@apache.org on 2011/01/20 19:37:47 UTC

svn commit: r1061444 - in /httpd/httpd/trunk/server: core.c util.c

Author: sf
Date: Thu Jan 20 18:37:47 2011
New Revision: 1061444

URL: http://svn.apache.org/viewvc?rev=1061444&view=rev
Log:
Move ap_resolve_env to core.c, in preparation for adding mod_define-like
variable support.

Modified:
    httpd/httpd/trunk/server/core.c
    httpd/httpd/trunk/server/util.c

Modified: httpd/httpd/trunk/server/core.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/core.c?rev=1061444&r1=1061443&r2=1061444&view=diff
==============================================================================
--- httpd/httpd/trunk/server/core.c (original)
+++ httpd/httpd/trunk/server/core.c Thu Jan 20 18:37:47 2011
@@ -1087,6 +1087,95 @@ static const char *set_access_name(cmd_p
     return NULL;
 }
 
+/* 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, leave the ${ENV}
+ * construct alone; it means something else.
+ */
+AP_DECLARE(const char *) ap_resolve_env(apr_pool_t *p, const char * word)
+{
+# define SMALL_EXPANSION 5
+    struct sll {
+        struct sll *next;
+        const char *string;
+        apr_size_t len;
+    } *result, *current, sresult[SMALL_EXPANSION];
+    char *res_buf, *cp;
+    const char *s, *e, *ep;
+    unsigned spc;
+    apr_size_t outlen;
+
+    s = ap_strchr_c(word, '$');
+    if (!s) {
+        return word;
+    }
+
+    /* well, actually something to do */
+    ep = word + strlen(word);
+    spc = 0;
+    result = current = &(sresult[spc++]);
+    current->next = NULL;
+    current->string = word;
+    current->len = s - word;
+    outlen = current->len;
+
+    do {
+        /* prepare next entry */
+        if (current->len) {
+            current->next = (spc < SMALL_EXPANSION)
+                            ? &(sresult[spc++])
+                            : (struct sll *)apr_palloc(p,
+                                                       sizeof(*current->next));
+            current = current->next;
+            current->next = NULL;
+            current->len = 0;
+        }
+
+        if (*s == '$') {
+            if (s[1] == '{' && (e = ap_strchr_c(s, '}'))) {
+                word = getenv(apr_pstrndup(p, s+2, e-s-2));
+                if (word) {
+                    current->string = word;
+                    current->len = strlen(word);
+                    outlen += current->len;
+                }
+                else {
+                    current->string = s;
+                    current->len = e - s + 1;
+                    outlen += current->len;
+                }
+                s = e + 1;
+            }
+            else {
+                current->string = s++;
+                current->len = 1;
+                ++outlen;
+            }
+        }
+        else {
+            word = s;
+            s = ap_strchr_c(s, '$');
+            current->string = word;
+            current->len = s ? s - word : ep - word;
+            outlen += current->len;
+        }
+    } while (s && *s);
+
+    /* assemble result */
+    res_buf = cp = apr_palloc(p, outlen + 1);
+    do {
+        if (result->len) {
+            memcpy(cp, result->string, result->len);
+            cp += result->len;
+        }
+        result = result->next;
+    } while (result);
+    res_buf[outlen] = '\0';
+
+    return res_buf;
+}
+
 static int reset_config_defines(void *dummy)
 {
     ap_server_config_defines = saved_server_config_defines;

Modified: httpd/httpd/trunk/server/util.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util.c?rev=1061444&r1=1061443&r2=1061444&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util.c (original)
+++ httpd/httpd/trunk/server/util.c Thu Jan 20 18:37:47 2011
@@ -755,95 +755,6 @@ AP_DECLARE(char *) ap_getword_conf(apr_p
     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, leave the ${ENV}
- * construct alone; it means something else.
- */
-AP_DECLARE(const char *) ap_resolve_env(apr_pool_t *p, const char * word)
-{
-# define SMALL_EXPANSION 5
-    struct sll {
-        struct sll *next;
-        const char *string;
-        apr_size_t len;
-    } *result, *current, sresult[SMALL_EXPANSION];
-    char *res_buf, *cp;
-    const char *s, *e, *ep;
-    unsigned spc;
-    apr_size_t outlen;
-
-    s = ap_strchr_c(word, '$');
-    if (!s) {
-        return word;
-    }
-
-    /* well, actually something to do */
-    ep = word + strlen(word);
-    spc = 0;
-    result = current = &(sresult[spc++]);
-    current->next = NULL;
-    current->string = word;
-    current->len = s - word;
-    outlen = current->len;
-
-    do {
-        /* prepare next entry */
-        if (current->len) {
-            current->next = (spc < SMALL_EXPANSION)
-                            ? &(sresult[spc++])
-                            : (struct sll *)apr_palloc(p,
-                                                       sizeof(*current->next));
-            current = current->next;
-            current->next = NULL;
-            current->len = 0;
-        }
-
-        if (*s == '$') {
-            if (s[1] == '{' && (e = ap_strchr_c(s, '}'))) {
-                word = getenv(apr_pstrndup(p, s+2, e-s-2));
-                if (word) {
-                    current->string = word;
-                    current->len = strlen(word);
-                    outlen += current->len;
-                }
-                else {
-                    current->string = s;
-                    current->len = e - s + 1;
-                    outlen += current->len;
-                }
-                s = e + 1;
-            }
-            else {
-                current->string = s++;
-                current->len = 1;
-                ++outlen;
-            }
-        }
-        else {
-            word = s;
-            s = ap_strchr_c(s, '$');
-            current->string = word;
-            current->len = s ? s - word : ep - word;
-            outlen += current->len;
-        }
-    } while (s && *s);
-
-    /* assemble result */
-    res_buf = cp = apr_palloc(p, outlen + 1);
-    do {
-        if (result->len) {
-            memcpy(cp, result->string, result->len);
-            cp += result->len;
-        }
-        result = result->next;
-    } while (result);
-    res_buf[outlen] = '\0';
-
-    return res_buf;
-}
-
 AP_DECLARE(int) ap_cfg_closefile(ap_configfile_t *cfp)
 {
 #ifdef DEBUG