diff options
author | Jim Jagielski <jim@apache.org> | 2015-12-30 13:03:01 +0100 |
---|---|---|
committer | Jim Jagielski <jim@apache.org> | 2015-12-30 13:03:01 +0100 |
commit | f970bc8d999588741a832f8de0ef84e37cb61de8 (patch) | |
tree | 53dcd918ff0ef21f459ac1084d5f5ef1ee4828df | |
parent | Better check (diff) | |
download | apache2-f970bc8d999588741a832f8de0ef84e37cb61de8.tar.xz apache2-f970bc8d999588741a832f8de0ef84e37cb61de8.zip |
New support function: ap_getword_conf2[_nc] which acts
just like ap_getword_conf[_nc] but allows for {} to be
used as word quotes. That is:
{Hello World} Foo Bar
"Hello World" Foo Bar
are equiv.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1722321 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | include/ap_mmn.h | 3 | ||||
-rw-r--r-- | include/httpd.h | 19 | ||||
-rw-r--r-- | server/util.c | 54 |
3 files changed, 75 insertions, 1 deletions
diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 7e05d86582..53e2f1e1b2 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -496,6 +496,7 @@ * conn_rec. * 20150222.6 (2.5.0-dev) Add async_filter to conn_rec. * 20150222.7 (2.5.0-dev) Add ap_casecmpstr[n](); + * 20150222.8 (2.5.0-dev) Add ap_getword_conf2[_nc](); */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ @@ -503,7 +504,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20150222 #endif -#define MODULE_MAGIC_NUMBER_MINOR 7 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 8 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/httpd.h b/include/httpd.h index 1ac9a23f2e..a3dcf4cec2 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -1533,6 +1533,25 @@ AP_DECLARE(char *) ap_getword_conf(apr_pool_t *p, const char **line); AP_DECLARE(char *) ap_getword_conf_nc(apr_pool_t *p, char **line); /** + * Get the second word in the string paying attention to quoting, + * with {...} supported as well as "..." and '...' + * @param p The pool to allocate from + * @param line The line to traverse + * @return A copy of the string + */ +AP_DECLARE(char *) ap_getword_conf2(apr_pool_t *p, const char **line); + +/** + * Get the second word in the string paying attention to quoting, + * with {...} supported as well as "..." and '...' + * @param p The pool to allocate from + * @param line The line to traverse + * @return A copy of the string + * @note The same as ap_getword_conf2(), except it doesn't use const char **. + */ +AP_DECLARE(char *) ap_getword_conf2_nc(apr_pool_t *p, char **line); + +/** * Check a string for any config define or environment variable construct * and replace each of them by the value of that variable, if it exists. * The default syntax of the constructs is ${ENV} but can be changed by diff --git a/server/util.c b/server/util.c index 62299f7c30..f628d78a56 100644 --- a/server/util.c +++ b/server/util.c @@ -821,6 +821,60 @@ AP_DECLARE(char *) ap_getword_conf(apr_pool_t *p, const char **line) return res; } +AP_DECLARE(char *) ap_getword_conf2_nc(apr_pool_t *p, char **line) +{ + return ap_getword_conf2(p, (const char **) line); +} + +AP_DECLARE(char *) ap_getword_conf2(apr_pool_t *p, const char **line) +{ + const char *str = *line, *strend; + char *res; + char quote; + int count = 1; + + while (apr_isspace(*str)) + ++str; + + if (!*str) { + *line = str; + return ""; + } + + if ((quote = *str) == '"' || quote == '\'') + return ap_getword_conf(p, line); + + if (quote == '{') { + strend = str + 1; + while (*strend) { + if (*strend == '}' && !--count) + break; + if (*strend == '{') + ++count; + if (*strend == '\\' && strend[1] && strend[1] == '\\') { + ++strend; + } + ++strend; + } + res = substring_conf(p, str + 1, strend - str - 1, 0); + + if (*strend == '}') + ++strend; + } + else { + strend = str; + while (*strend && !apr_isspace(*strend)) + ++strend; + + res = substring_conf(p, str, strend - str, 0); + } + + while (apr_isspace(*strend)) + ++strend; + *line = strend; + return res; +} + AP_DECLARE(int) ap_cfg_closefile(ap_configfile_t *cfp) { #ifdef DEBUG |