util.c revision 42df154a9b4c440ec42879d9e215be1b0468f47d
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * The Apache Software License, Version 1.1
b99dbaab171d91e1b664397cc40e039d0c087c65fielding * Copyright (c) 2000 The Apache Software Foundation. All rights
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * reserved.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Redistribution and use in source and binary forms, with or without
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * modification, are permitted provided that the following conditions
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 1. Redistributions of source code must retain the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 2. Redistributions in binary form must reproduce the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer in
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * the documentation and/or other materials provided with the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * distribution.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 3. The end-user documentation included with the redistribution,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if any, must include the following acknowledgment:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * "This product includes software developed by the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Apache Software Foundation (http://www.apache.org/)."
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Alternately, this acknowledgment may appear in the software itself,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if and wherever such third-party acknowledgments normally appear.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 4. The names "Apache" and "Apache Software Foundation" must
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * not be used to endorse or promote products derived from this
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * software without prior written permission. For written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission, please contact apache@apache.org.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 5. Products derived from this software may not be called "Apache",
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * nor may "Apache" appear in their name, without prior written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission of the Apache Software Foundation.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SUCH DAMAGE.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * This software consists of voluntary contributions made by many
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * individuals on behalf of the Apache Software Foundation. For more
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * information on the Apache Software Foundation, please see
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Portions of this software are based upon public domain software
f4c310fd2555c6faca1f980f00b161eadb089023gstein * originally written at the National Center for Supercomputing Applications,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * University of Illinois, Urbana-Champaign.
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * util.c: string utility things
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * 3/21/93 Rob McCool
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * 1995-96 Many changes by the Apache Software Foundation
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Debugging aid:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * #define DEBUG to trace all cfg_open*()/cfg_closefile() calls
f4c310fd2555c6faca1f980f00b161eadb089023gstein * #define DEBUG_CFG_LINES to trace every line read from the config files
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* A bunch of functions in util.c scan strings looking for certain characters.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * To make that more efficient we encode a lookup table. The test_char_table
f4c310fd2555c6faca1f980f00b161eadb089023gstein * is generated automatically by gen_test_char.c.
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* we assume the folks using this ensure 0 <= c < 256... which means
f4c310fd2555c6faca1f980f00b161eadb089023gstein * you need a cast to (unsigned char) first, you can't just plug a
f4c310fd2555c6faca1f980f00b161eadb089023gstein * char in here and get it to work, because if char is signed then it
f4c310fd2555c6faca1f980f00b161eadb089023gstein * will first be sign extended.
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define TEST_CHAR(c, f) (test_char_table[(unsigned)(c)] & (f))
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Examine a field value (such as a media-/content-type) string and return
f4c310fd2555c6faca1f980f00b161eadb089023gstein * it sans any parameters; e.g., strip off any ';charset=foo' and the like.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_field_noparam(apr_pool_t *p, const char *intype)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *semi;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_ht_time(apr_pool_t *p, apr_time_t t, const char *fmt, int gmt)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *f;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Convert %Z to "GMT" and %z to "+0000";
f4c310fd2555c6faca1f980f00b161eadb089023gstein * on hosts that do not have a time zone string in struct tm,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * strftime must assume its argument is local time.
f4c310fd2555c6faca1f980f00b161eadb089023gstein for(strp = tf, f = fmt; strp < tf + sizeof(tf) - 6 && (*strp = *f)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ; f++, strp++) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (*f != '%') continue;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe switch (f[1]) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* check return code? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_strftime(ts, &retcode, MAX_STRING_LEN, fmt, &xt);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Roy owes Rob beer. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Rob owes Roy dinner. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* These legacy comments would make a lot more sense if Roy hadn't
f4c310fd2555c6faca1f980f00b161eadb089023gstein * replaced the old later_than() routine with util_date.c.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Well, okay, they still wouldn't make any sense.
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Match = 0, NoMatch = 1, Abort = -1
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Based loosely on sections of wildmat.c by Rich Salz
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Hmmm... shouldn't this really go component by component?
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_strcmp_match(const char *str, const char *exp)
48f35e10f195dd594d75738fc536bb885eda537cgstein for (x = 0, y = 0; exp[y]; ++y, ++x) {
48f35e10f195dd594d75738fc536bb885eda537cgstein while (str[x]) {
48f35e10f195dd594d75738fc536bb885eda537cgstein if ((ret = ap_strcmp_match(&str[x++], &exp[y])) != 1)
48f35e10f195dd594d75738fc536bb885eda537cgsteinAP_DECLARE(int) ap_strcasecmp_match(const char *str, const char *exp)
48f35e10f195dd594d75738fc536bb885eda537cgstein for (x = 0, y = 0; exp[y]; ++y, ++x) {
48f35e10f195dd594d75738fc536bb885eda537cgstein while (str[x]) {
48f35e10f195dd594d75738fc536bb885eda537cgstein if ((ret = ap_strcasecmp_match(&str[x++], &exp[y])) != 1)
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if ((exp[y] != '?') && (apr_tolower(str[x]) != apr_tolower(exp[y])))
f4c310fd2555c6faca1f980f00b161eadb089023gstein register int x;
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (x = 0; str[x]; x++)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * Here's a pool-based interface to POSIX regex's regcomp().
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Note that we return regex_t instead of being passed one.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * The reason is that if you use an already-used regex_t structure,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the memory that you've already allocated gets forgotten, and
f4c310fd2555c6faca1f980f00b161eadb089023gstein * regfree() doesn't clear it. So we don't allow it.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(regex_t *) ap_pregcomp(apr_pool_t *p, const char *pattern,
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_register_cleanup(p, (void *) preg, regex_cleanup, regex_cleanup);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(void) ap_pregfree(apr_pool_t *p, regex_t * reg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Similar to standard strstr() but we ignore case in this version.
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein * Based on the strstr() implementation further below.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_strcasestr(const char *s1, const char *s2)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* an empty s2 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return((char *)s1);
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein for ( ; (*s1 != '\0') && (apr_tolower(*s1) != apr_tolower(*s2)); s1++);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* found first character of s2, see if the rest matches */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* both strings ended together */
f39230a531b23d94f86a087963299bbe2e431a4agstein return((char *)s1);
f39230a531b23d94f86a087963299bbe2e431a4agstein /* second string ended, a match */
f39230a531b23d94f86a087963299bbe2e431a4agstein /* didn't find a match here, try starting at next character in s1 */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein return((char *)s1);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * Returns an offsetted pointer in bigstring immediately after
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * prefix. Returns bigstring if bigstring doesn't start with
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * prefix or if prefix is longer than bigstring while still matching.
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * NOTE: pointer returned is relative to bigstring, so we
f39230a531b23d94f86a087963299bbe2e431a4agstein * can use standard pointer comparisons in the calling function
f39230a531b23d94f86a087963299bbe2e431a4agstein * (eg: test if ap_stripprefix(a,b) == a)
f39230a531b23d94f86a087963299bbe2e431a4agsteinAP_DECLARE(const char *) ap_stripprefix(const char *bigstring,
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein const char *prefix)
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein const char *p1;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein /* hit the end of bigstring! */
f39230a531b23d94f86a087963299bbe2e431a4agstein * Apache stub function for the regex libraries regexec() to make sure the
f39230a531b23d94f86a087963299bbe2e431a4agstein * whole regex(3) API is available through the Apache (exported) namespace.
f39230a531b23d94f86a087963299bbe2e431a4agstein * This is especially important for the DSO situations of modules.
f39230a531b23d94f86a087963299bbe2e431a4agstein * DO NOT MAKE A MACRO OUT OF THIS FUNCTION!
f39230a531b23d94f86a087963299bbe2e431a4agsteinAP_DECLARE(int) ap_regexec(regex_t *preg, const char *string,
f39230a531b23d94f86a087963299bbe2e431a4agstein return regexec(preg, string, nmatch, pmatch, eflags);
f39230a531b23d94f86a087963299bbe2e431a4agsteinAP_DECLARE(size_t) ap_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
f39230a531b23d94f86a087963299bbe2e431a4agstein/* This function substitutes for $0-$9, filling in regular expression
f39230a531b23d94f86a087963299bbe2e431a4agstein * submatches. Pass it the same nmatch and pmatch arguments that you
f39230a531b23d94f86a087963299bbe2e431a4agstein * passed ap_regexec(). pmatch should not be greater than the maximum number
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * of subexpressions - i.e. one more than the re_nsub member of regex_t.
f39230a531b23d94f86a087963299bbe2e431a4agstein * input should be the string with the $-expressions, source should be the
f39230a531b23d94f86a087963299bbe2e431a4agstein * string that was matched against.
f39230a531b23d94f86a087963299bbe2e431a4agstein * It returns the substituted string, or NULL on error.
f39230a531b23d94f86a087963299bbe2e431a4agstein * Parts of this code are based on Henry Spencer's regsub(), from his
f39230a531b23d94f86a087963299bbe2e431a4agstein * AT&T V8 regexp package.
f39230a531b23d94f86a087963299bbe2e431a4agsteinAP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input, const char *source,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* First pass, find the size */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (c == '&')
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (no < nmatch && pmatch[no].rm_so < pmatch[no].rm_eo) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Now actually fill in the string */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (c == '&')
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (no < nmatch && pmatch[no].rm_so < pmatch[no].rm_eo) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Parse .. so we don't compromise security
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* Four paseses, as per RFC 1808 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* a) remove ./ path segments */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (name[l] == '.' && name[l + 1] == '/' && (l == 0 || name[l - 1] == '/'))
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* b) remove trailing . path, segment */
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (w > 1 && name[w - 1] == '.' && name[w - 2] == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* c) remove all xx/../ segments. (including leading ../ and /../) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (name[l] == '.' && name[l + 1] == '.' && name[l + 2] == '/' &&
f4c310fd2555c6faca1f980f00b161eadb089023gstein register int m = l + 3, n;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (l >= 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein (++n, ++m);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* d) remove trailing xx/.. segment. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (l > 2 && name[l - 1] == '.' && name[l - 2] == '.' && name[l - 3] == '/') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (l >= 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *d, *s;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Check for UNC names. Leave leading two slashes. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein *d++ = *s++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (*s) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((*d++ = *s) == '/') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein } while (*s == '/');
f4c310fd2555c6faca1f980f00b161eadb089023gstein * copy at most n leading directories of s into d
f4c310fd2555c6faca1f980f00b161eadb089023gstein * d should be at least as large as s plus 1 extra byte
f4c310fd2555c6faca1f980f00b161eadb089023gstein * assumes n > 0
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the return value is the ever useful pointer to the trailing \0 of d
f4c310fd2555c6faca1f980f00b161eadb089023gstein * MODIFIED FOR HAVE_DRIVE_LETTERS and NETWARE environments,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * so that if n == 0, "/" is returned in d with n == 1
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and s == "e:/test.html", "e:/" is returned in d
f4c310fd2555c6faca1f980f00b161eadb089023gstein * *** See also directory_walk in src/main/http_request.c
f4c310fd2555c6faca1f980f00b161eadb089023gstein * examples:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * /a/b, 0 ==> / (true for all platforms)
f4c310fd2555c6faca1f980f00b161eadb089023gstein * /a/b, 1 ==> /
f4c310fd2555c6faca1f980f00b161eadb089023gstein * /a/b, 2 ==> /a/
f4c310fd2555c6faca1f980f00b161eadb089023gstein * /a/b, 3 ==> /a/b/
f4c310fd2555c6faca1f980f00b161eadb089023gstein * /a/b, 4 ==> /a/b/
f4c310fd2555c6faca1f980f00b161eadb089023gstein * c:/a/b 0 ==> /
f4c310fd2555c6faca1f980f00b161eadb089023gstein * c:/a/b 1 ==> c:/
f4c310fd2555c6faca1f980f00b161eadb089023gstein * c:/a/b 2 ==> c:/a/
f4c310fd2555c6faca1f980f00b161eadb089023gstein * c:/a/b 3 ==> c:/a/b
f4c310fd2555c6faca1f980f00b161eadb089023gstein * c:/a/b 4 ==> c:/a/b
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_make_dirstr_prefix(char *d, const char *s, int n)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (n < 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein *++d = '\0';
f4c310fd2555c6faca1f980f00b161eadb089023gstein return (d);
f4c310fd2555c6faca1f980f00b161eadb089023gstein *d++ = *s++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return (d);
f4c310fd2555c6faca1f980f00b161eadb089023gstein * return the parent directory name including trailing / of the file s
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_make_dirstr_parent(apr_pool_t *p, const char *s)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: well this is really broken if this happens */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return (d);
f4c310fd2555c6faca1f980f00b161eadb089023gstein register int x, n;
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (x = 0, n = 0; path[x]; x++)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *x;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (x == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: well, this is a silly function, no method of reporting an
f4c310fd2555c6faca1f980f00b161eadb089023gstein * error... ah well. */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_getword_nc(apr_pool_t *atrans, char **line, char stop)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_getword(atrans, (const char **) line, stop);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_getword(apr_pool_t *atrans, const char **line, char stop)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_getword_white_nc(apr_pool_t *atrans, char **line)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_getword_white(atrans, (const char **) line);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_getword_white(apr_pool_t *atrans, const char **line)
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (x = 0; (*line)[x]; x++) {
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_getword_nulls_nc(apr_pool_t *atrans, char **line, char stop)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_getword_nulls(atrans, (const char **) line, stop);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_getword_nulls(apr_pool_t *atrans, const char **line, char stop)
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Get a word, (new) config-file style --- quoted strings and backslashes
f4c310fd2555c6faca1f980f00b161eadb089023gstein * all honored
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic char *substring_conf(apr_pool_t *p, const char *start, int len, char quote)
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < len; ++i) {
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_getword_conf_nc(apr_pool_t *p, char **line)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_getword_conf(apr_pool_t *p, const char **line)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (*strend == '\\' && strend[1] && strend[1] == quote)
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = substring_conf(p, str + 1, strend - str - 1, quote);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Check a string for any ${ENV} environment variable
f4c310fd2555c6faca1f980f00b161eadb089023gstein * construct and replace each them by the value of
f4c310fd2555c6faca1f980f00b161eadb089023gstein * that environment variable, if it exists. If the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * environment value does not exist, leave the ${ENV}
f4c310fd2555c6faca1f980f00b161eadb089023gstein * construct alone; it means something else.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(const char *) ap_resolve_env(apr_pool_t *p, const char * word)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *s, *e;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX - relies on strncat() to add '\0'
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *e2 = e;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ignore invalid strings */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein return (cfp->close == NULL) ? 0 : cfp->close(cfp->param);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return (int)EOF;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void *cfg_getstr(void *buf, size_t bufsiz, void *param)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv == APR_SUCCESS || (rv == APR_EOF && strcmp(buf, "")))
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Open a configfile_t as FILE, return open configfile_t struct pointer */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(apr_status_t) ap_pcfg_openfile(configfile_t **ret_cfg, apr_pool_t *p, const char *name)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Internal error: pcfg_openfile() called with NULL filename");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### We no longer need the test ap_os_is_filename_valid() here
f4c310fd2555c6faca1f980f00b161eadb089023gstein * The directory was already walked on a segment by segment basis,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * so we should never be called with a bad path element, and device
f4c310fd2555c6faca1f980f00b161eadb089023gstein * names as access file names never posed as security threats, since
f4c310fd2555c6faca1f980f00b161eadb089023gstein * it was the admin's choice to assign the .htaccess file's name.
f4c310fd2555c6faca1f980f00b161eadb089023gstein status = apr_open(&file, name, APR_READ | APR_BUFFERED, APR_OS_DEFAULT, p);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Opening config file %s (%s)",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_strerror(status, buf, sizeof(buf)) : "successful");
f4c310fd2555c6faca1f980f00b161eadb089023gstein strcasecmp(name + strlen(name) - 4, "/nul") == 0))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* WIN32 || OS2 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Access to file %s denied by server: not a regular file",
f4c310fd2555c6faca1f980f00b161eadb089023gstein new_cfg->getstr = (void *(*)(void *, size_t, void *)) cfg_getstr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Allocate a configfile_t handle with user defined functions and params */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(configfile_t *) ap_pcfg_open_custom(apr_pool_t *p, const char *descr,
f4c310fd2555c6faca1f980f00b161eadb089023gstein void *(*getstr) (void *buf, size_t bufsiz, void *param),
f4c310fd2555c6faca1f980f00b161eadb089023gstein configfile_t *new_cfg = apr_palloc(p, sizeof(*new_cfg));
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, NULL, "Opening config handler %s", descr);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Read one character from a configfile_t */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Read one line from open configfile_t, strip LF, increase line number */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* If custom handler does not define a getstr() function, read char by char */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_cfg_getline(char *buf, size_t bufsize, configfile_t *cfp)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If a "get string" function is defined, use it */
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein * check for line continuation,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * i.e. match [^\\]\\[\r]\n only
f4c310fd2555c6faca1f980f00b161eadb089023gstein * line continuation requested -
f4c310fd2555c6faca1f980f00b161eadb089023gstein * then remove backslash and continue
f4c310fd2555c6faca1f980f00b161eadb089023gstein * no real continuation because escaped -
f4c310fd2555c6faca1f980f00b161eadb089023gstein * then just remove escape character
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Leading and trailing white space is eliminated completely
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* blast trailing whitespace */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Zap leading whitespace by shifting */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, NULL, "Read config: %s", buf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* No "get string" function defined; read character by character */
f4c310fd2555c6faca1f980f00b161eadb089023gstein register int c;
f4c310fd2555c6faca1f980f00b161eadb089023gstein register size_t i = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* skip leading whitespace */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* too small, assume caller is crazy */
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (c == CR) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* silently ignore CR (_assume_ that a LF follows) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (c == LF) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* increase line number and return on LF */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (c == EOF || c == 0x4 || c == LF || i >= (bufsize - 2)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein * check for line continuation
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* line is continued */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* else nothing needs be done because
f4c310fd2555c6faca1f980f00b161eadb089023gstein * then the backslash is escaped and
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we just strip to a single one
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* blast trailing whitespace */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, NULL, "Read config: %s", buf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Size an HTTP header field list item, as separated by a comma.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * The return value is a pointer to the beginning of the non-empty list item
f4c310fd2555c6faca1f980f00b161eadb089023gstein * within the original string (or NULL if there is none) and the address
f4c310fd2555c6faca1f980f00b161eadb089023gstein * of field is shifted to the next non-comma, non-whitespace character.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * len is the length of the item excluding any beginning whitespace.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(const char *) ap_size_list_item(const char **field, int *len)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const unsigned char *ptr = (const unsigned char *)*field;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const unsigned char *token;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Find first non-comma, non-whitespace byte */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Find the end of this item, skipping over dead bits */
f4c310fd2555c6faca1f980f00b161eadb089023gstein *ptr && (in_qpair || in_qstr || in_com || *ptr != ',');
f4c310fd2555c6faca1f980f00b161eadb089023gstein switch (*ptr) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein default : break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Advance field pointer to the next non-comma, non-white byte */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return (const char *)token;
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Retrieve an HTTP header field list item, as separated by a comma,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * while stripping insignificant whitespace and lowercasing anything not in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a quoted string or comment. The return value is a new string containing
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the converted list item (or NULL if none) and the address pointed to by
f4c310fd2555c6faca1f980f00b161eadb089023gstein * field is shifted to the next non-comma, non-whitespace.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_get_list_item(apr_pool_t *p, const char **field)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *tok_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const unsigned char *ptr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned char *pos;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int addspace = 0, in_qpair = 0, in_qstr = 0, in_com = 0, tok_len = 0;
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein /* Find the beginning and maximum length of the list item so that
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein * we can allocate a buffer for the new string and reset the field.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((tok_start = ap_size_list_item(field, &tok_len)) == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Scan the token again, but this time copy only the good bytes.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * We skip extra whitespace and any whitespace around a '=', '/',
f4c310fd2555c6faca1f980f00b161eadb089023gstein * or ';' and lowercase normal characters not within a comment,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * quoted-string or quoted-pair.
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (ptr = (const unsigned char *)tok_start, pos = (unsigned char *)token;
f4c310fd2555c6faca1f980f00b161eadb089023gstein *ptr && (in_qpair || in_qstr || in_com || *ptr != ',');
f4c310fd2555c6faca1f980f00b161eadb089023gstein switch (*ptr) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Find an item in canonical form (lowercase, no extra spaces) within
f4c310fd2555c6faca1f980f00b161eadb089023gstein * an HTTP field value list. Returns 1 if found, 0 if not found.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * This would be much more efficient if we stored header fields as
f4c310fd2555c6faca1f980f00b161eadb089023gstein * an array of list items as they are received instead of a plain string.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_find_list_item(apr_pool_t *p, const char *line, const char *tok)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const unsigned char *pos;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const unsigned char *ptr = (const unsigned char *)line;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int good = 0, addspace = 0, in_qpair = 0, in_qstr = 0, in_com = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein do { /* loop for each item in line's list */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Find first non-comma, non-whitespace byte */
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein break; /* no items left and nothing good found */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We skip extra whitespace and any whitespace around a '=', '/',
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein * or ';' and lowercase normal characters not within a comment,
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein * quoted-string or quoted-pair.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *ptr && (in_qpair || in_qstr || in_com || *ptr != ',');
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein switch (*ptr) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein default : if (!good)
f4c310fd2555c6faca1f980f00b161eadb089023gstein good = 0; /* not good if only a prefix was matched */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Retrieve a token, spacing over it and returning a pointer to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the first non-white byte afterwards. Note that these tokens
f4c310fd2555c6faca1f980f00b161eadb089023gstein * are delimited by semis and commas; and can also be delimited
f4c310fd2555c6faca1f980f00b161eadb089023gstein * by whitespace at the caller's option.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_get_token(apr_pool_t *p, const char **accept_line, int accept_white)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *tok_start;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* Find first non-white byte */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* find token end, skipping over quoted strings.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * (comments are already gone).
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Advance accept_line pointer to the next non-white byte */
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein/* find http tokens, see the definition of token from RFC2068 */
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gsteinAP_DECLARE(int) ap_find_token(apr_pool_t *p, const char *line, const char *tok)
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein const unsigned char *start_token;
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein const unsigned char *s;
f4c310fd2555c6faca1f980f00b161eadb089023gstein s = (const unsigned char *)line;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* find start of token, skip all stop characters, note NUL
f4c310fd2555c6faca1f980f00b161eadb089023gstein * isn't a token stop, so we don't need to test for it
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* find end of the token */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!strncasecmp((const char *)start_token, (const char *)tok, s - start_token)) {
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_find_last_token(apr_pool_t *p, const char *line, const char *tok)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((lidx < 0) ||
f4c310fd2555c6faca1f980f00b161eadb089023gstein ((lidx > 0) && !(apr_isspace(line[lidx - 1]) || line[lidx - 1] == ',')))
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_escape_shell_cmd(apr_pool_t *p, const char *str)
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned char *d;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const unsigned char *s;
f4c310fd2555c6faca1f980f00b161eadb089023gstein cmd = apr_palloc(p, 2 * strlen(str) + 1); /* Be safe */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm d = (unsigned char *)cmd;
f4c310fd2555c6faca1f980f00b161eadb089023gstein s = (const unsigned char *)str;
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (; *s; ++s) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Don't allow '&' in parameters under OS/2. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This can be used to send commands to the shell. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (*s == '&') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein *d++ = ' ';
f4c310fd2555c6faca1f980f00b161eadb089023gstein *d++ = '\\';
f4c310fd2555c6faca1f980f00b161eadb089023gstein register char digit;
f4c310fd2555c6faca1f980f00b161eadb089023gstein digit = ((what[0] >= 'A') ? ((what[0] & 0xdf) - 'A') + 10 : (what[0] - '0'));
f4c310fd2555c6faca1f980f00b161eadb089023gstein digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A') + 10 : (what[1] - '0'));
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else /*CHARSET_EBCDIC*/
f4c310fd2555c6faca1f980f00b161eadb089023gstein digit = apr_xlate_conv_byte(ap_hdrs_from_ascii, 0xFF & strtol(xstr, NULL, 16));
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /*CHARSET_EBCDIC*/
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Unescapes a URL.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * Returns 0 on success, non-zero on error
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Failure is due to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * bad % escape returns HTTP_BAD_REQUEST
f4c310fd2555c6faca1f980f00b161eadb089023gstein * decoding %00 -> \0
f4c310fd2555c6faca1f980f00b161eadb089023gstein * decoding %2f -> / (a special character)
f4c310fd2555c6faca1f980f00b161eadb089023gstein * returns HTTP_NOT_FOUND
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *x, *y;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Initial scan for first '%'. Don't bother writing values before
f4c310fd2555c6faca1f980f00b161eadb089023gstein * seeing a '%' */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (y == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (x = y; *y; ++x, ++y) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (*y != '%')
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!apr_isxdigit(*(y + 1)) || !apr_isxdigit(*(y + 2))) {
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_construct_server(apr_pool_t *p, const char *hostname,
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* c2x takes an unsigned, and expects the caller has guaranteed that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 0 <= what < 256... which usually means that you have to cast to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * unsigned char first, because (unsigned)(char)(x) first goes through
f4c310fd2555c6faca1f980f00b161eadb089023gstein * signed extension to an int before the unsigned cast.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * The reason for this assumption is to assist gcc code generation --
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the unsigned char -> unsigned extension is already done earlier in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * both uses of this code, so there's no need to waste time doing it
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_inline unsigned char *c2x(unsigned what, unsigned char *where)
f4c310fd2555c6faca1f980f00b161eadb089023gstein what = apr_xlate_conv_byte(ap_hdrs_to_ascii, (unsigned char)what);
f39230a531b23d94f86a087963299bbe2e431a4agstein#endif /*CHARSET_EBCDIC*/
50bd75672ef114fb839dd9643c192b432fdf344cgstein * escape_path_segment() escapes a path segment, as defined in RFC 1808. This
50bd75672ef114fb839dd9643c192b432fdf344cgstein * routine is (should be) OS independent.
50bd75672ef114fb839dd9643c192b432fdf344cgstein * os_escape_path() converts an OS path to a URL, in an OS dependent way. In all
50bd75672ef114fb839dd9643c192b432fdf344cgstein * cases if a ':' occurs before the first '/' in the URL, the URL should be
50bd75672ef114fb839dd9643c192b432fdf344cgstein * prefixed with "./" (or the ':' escaped). In the case of Unix, this means
50bd75672ef114fb839dd9643c192b432fdf344cgstein * leaving '/' alone, but otherwise doing what escape_path_segment() does. For
50bd75672ef114fb839dd9643c192b432fdf344cgstein * efficiency reasons, we don't use escape_path_segment(), which is provided for
50bd75672ef114fb839dd9643c192b432fdf344cgstein * reference. Again, RFC 1808 is where this stuff is defined.
50bd75672ef114fb839dd9643c192b432fdf344cgstein * If partial is set, os_escape_path() assumes that the path will be appended to
50bd75672ef114fb839dd9643c192b432fdf344cgstein * something with a '/' in it (and thus does not prefix "./").
50bd75672ef114fb839dd9643c192b432fdf344cgsteinAP_DECLARE(char *) ap_escape_path_segment(apr_pool_t *p, const char *segment)
f39230a531b23d94f86a087963299bbe2e431a4agstein const unsigned char *s = (const unsigned char *)segment;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein unsigned char *d = (unsigned char *)copy;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein unsigned c;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein while ((c = *s)) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gsteinAP_DECLARE(char *) ap_os_escape_path(apr_pool_t *p, const char *path, int partial)
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein const unsigned char *s = (const unsigned char *)path;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein unsigned char *d = (unsigned char *)copy;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein unsigned c;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein *d++ = '.';
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein *d++ = '/';
f4c310fd2555c6faca1f980f00b161eadb089023gstein while ((c = *s)) {
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein/* ap_escape_uri is now a macro for os_escape_path */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gsteinAP_DECLARE(char *) ap_escape_html(apr_pool_t *p, const char *s)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein /* first, count the number of extra characters */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein for (i = 0, j = 0; s[i] != '\0'; i++)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein else if (s[i] == '&')
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein if (j == 0)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein return apr_pstrndup(p, s, i);
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein for (i = 0, j = 0; s[i] != '\0'; i++, j++)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein if (s[i] == '<') {
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein else if (s[i] == '>') {
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein else if (s[i] == '&') {
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein x[j] = s[i];
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein x[j] = '\0';
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein return 0; /* in error condition, just return no */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0; /* in error condition, just return no */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gsteinAP_DECLARE(char *) ap_make_full_path(apr_pool_t *a, const char *src1,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *src2)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein register int x;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (x == 0)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * Check for an absoluteURI syntax (see section 3.2 in RFC2068).
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein register int x;
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (x = 0; u[x] != ':'; x++) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if ((!u[x]) ||
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein return (x ? 1 : 0); /* If the first character is ':', it's broken, too */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein#if defined(QNX) || defined(MPE) || defined(BEOS) || defined(_OSD_POSIX) || defined(TPF) || defined(__TANDEM) || defined(OS2) || defined(WIN32)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein/* QNX, MPE and BeOS do not appear to support supplementary groups. */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein#else /* ndef QNX */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein while (index < NGROUPS_MAX && ((g = getgrent()) != NULL))
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein#endif /* def QNX */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein#endif /* def NEED_INITGROUPS */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein register int x;
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein for (x = 0; s[x]; x++)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein if (s[x] == c)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein register int x;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if (s[x] == c)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein return (1);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad user name %s", ap_server_argv0, name);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein return (1);
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad group name %s", ap_server_argv0, name);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic char *find_fqdn(apr_pool_t *a, struct hostent *p)
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein for (x = 0; p->h_aliases[x]; ++x) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein (!strncasecmp(p->h_aliases[x], p->h_name, strlen(p->h_name))))
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_WARNING, 0, NULL,
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein "%s: gethostname() failed to determine ServerName",
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein /* Recovery - return the default servername by IP: */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein apr_snprintf(str, sizeof(str), "%pA", p->h_addr_list[0]);
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein /* We will drop through to report the IP-named server */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Since we found a fdqn, return it with no logged message. */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO|APLOG_STARTUP, 0, NULL,
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein "%s: Could not determine the server's fully qualified "
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein "domain name, using %s for ServerName",
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein/* simple 'pool' alloc()ing glue to ap_base64.c
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gsteinAP_DECLARE(char *) ap_pbase64decode(apr_pool_t *p, const char *bufcoded)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein decoded = (char *) apr_palloc(p, 1 + ap_base64decode_len(bufcoded));
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein decoded[l] = '\0'; /* make binary sequence into string */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(char *) ap_pbase64encode(apr_pool_t *p, char *string)
f4c310fd2555c6faca1f980f00b161eadb089023gstein encoded = (char *) apr_palloc(p, 1 + ap_base64encode_len(l));
f4c310fd2555c6faca1f980f00b161eadb089023gstein encoded[l] = '\0'; /* make binary sequence into string */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein/* we want to downcase the type/subtype for comparison purposes
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * but nothing else because ;parameter=foo values are case sensitive.
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * XXX: in truth we want to downcase parameter names... but really,
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * apache has never handled parameters and such correctly. You
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * also need to compress spaces and such to be able to compare
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * properly. -djg
int newlen = 0;
newlen++;
newlen++;
inchr++;
newlen++;
inchr++;
return outstring;