util.c revision 44c46ef733836b32585d135d2d90856e7cfd9929
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz/* ====================================================================
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Redistribution and use in source and binary forms, with or without
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * modification, are permitted provided that the following conditions
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 1. Redistributions of source code must retain the above copyright
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * notice, this list of conditions and the following disclaimer.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 2. Redistributions in binary form must reproduce the above copyright
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * notice, this list of conditions and the following disclaimer in
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * the documentation and/or other materials provided with the
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * distribution.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 3. All advertising materials mentioning features or use of this
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * software must display the following acknowledgment:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * "This product includes software developed by the Apache Group
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * for use in the Apache HTTP server project (http://www.apache.org/)."
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 4. The names "Apache Server" and "Apache Group" must not be used to
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * endorse or promote products derived from this software without
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * prior written permission. For written permission, please contact
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * apache@apache.org.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 5. Products derived from this software may not be called "Apache"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * nor may "Apache" appear in their names without prior written
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * permission of the Apache Group.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 6. Redistributions of any form whatsoever must retain the following
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * acknowledgment:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * "This product includes software developed by the Apache Group
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * for use in the Apache HTTP server project (http://www.apache.org/)."
5c0419d51818eb02045cf923a9fe456127a44c60wrowe * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * OF THE POSSIBILITY OF SUCH DAMAGE.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * ====================================================================
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * This software consists of voluntary contributions made by many
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * individuals on behalf of the Apache Group and was originally based
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * on public domain software written at the National Center for
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Supercomputing Applications, University of Illinois, Urbana-Champaign.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * For more information on the Apache Group and the Apache HTTP server
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * project, please see <http://www.apache.org/>.
0568280364eb026393be492ebc732795c4934643jorton * util.c: string utility things
0568280364eb026393be492ebc732795c4934643jorton * 3/21/93 Rob McCool
0568280364eb026393be492ebc732795c4934643jorton * 1995-96 Many changes by the Apache Group
0568280364eb026393be492ebc732795c4934643jorton/* Debugging aid:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * #define DEBUG to trace all cfg_open*()/cfg_closefile() calls
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * #define DEBUG_CFG_LINES to trace every line read from the config files
796e4a7141265d8ed7036e4628161c6eafb2a789jorton/* stdio.h has been read in ap_config.h already. Add missing prototypes here: */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* A bunch of functions in util.c scan strings looking for certain characters.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * To make that more efficient we encode a lookup table. The test_char_table
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * is generated automatically by gen_test_char.c.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* we assume the folks using this ensure 0 <= c < 256... which means
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * you need a cast to (unsigned char) first, you can't just plug a
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * char in here and get it to work, because if char is signed then it
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * will first be sign extended.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define TEST_CHAR(c, f) (test_char_table[(unsigned)(c)] & (f))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Examine a field value (such as a media-/content-type) string and return
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * it sans any parameters; e.g., strip off any ';charset=foo' and the like.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_field_noparam(ap_context_t *p, const char *intype)
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe const char *semi;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_ht_time(ap_context_t *p, ap_time_t *t, const char *fmt, int gmt)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Convert %Z to "GMT" and %z to "+0000";
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * on hosts that do not have a time zone string in struct tm,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * strftime must assume its argument is local time.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *f;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for(strp = tf, f = fmt; strp < tf + sizeof(tf) - 6 && (*strp = *f)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (*f != '%') continue;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes switch (f[1]) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* check return code? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* What a pain in the ass. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Assume we are never more than 24 hours away. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes gmt = *gmtime(&tt); /* remember gmtime/localtime return ptr to static */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes hours = ((days < -1 ? 24 : 1 < days ? -24 : days * 24)
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe/* Roy owes Rob beer. */
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe/* Rob owes Roy dinner. */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin/* These legacy comments would make a lot more sense if Roy hadn't
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * replaced the old later_than() routine with util_date.c.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * Well, okay, they still wouldn't make any sense.
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes/* Match = 0, NoMatch = 1, Abort = -1
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * Based loosely on sections of wildmat.c by Rich Salz
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * Hmmm... shouldn't this really go component by component?
54d22ed1c429b903b029bbd62621f11a9e286137minfrinAPI_EXPORT(int) ap_strcmp_match(const char *str, const char *exp)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (x = 0, y = 0; exp[y]; ++y, ++x) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (str[x]) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((ret = ap_strcmp_match(&str[x++], &exp[y])) != 1)
54d22ed1c429b903b029bbd62621f11a9e286137minfrinAPI_EXPORT(int) ap_strcasecmp_match(const char *str, const char *exp)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (x = 0, y = 0; exp[y]; ++y, ++x) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (str[x]) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((ret = ap_strcasecmp_match(&str[x++], &exp[y])) != 1)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else if ((exp[y] != '?') && (ap_tolower(str[x]) != ap_tolower(exp[y])))
54d22ed1c429b903b029bbd62621f11a9e286137minfrin register int x;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin for (x = 0; str[x]; x++)
81965264d92dd8c9ca21d058420f6f6da34b3032minfrin * Here's a pool-based interface to POSIX regex's regcomp().
e1cc1ac970d0aa2910027f1f20445a16207a6deeminfrin * Note that we return regex_t instead of being passed one.
e1cc1ac970d0aa2910027f1f20445a16207a6deeminfrin * The reason is that if you use an already-used regex_t structure,
e1cc1ac970d0aa2910027f1f20445a16207a6deeminfrin * the memory that you've already allocated gets forgotten, and
e1cc1ac970d0aa2910027f1f20445a16207a6deeminfrin * regfree() doesn't clear it. So we don't allow it.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(regex_t *) ap_pregcomp(ap_context_t *p, const char *pattern,
7add8f7fb048534390571801b7794f71cd9e127abnicholes ap_register_cleanup(p, (void *) preg, regex_cleanup, regex_cleanup);
7add8f7fb048534390571801b7794f71cd9e127abnicholesAPI_EXPORT(void) ap_pregfree(ap_context_t *p, regex_t * reg)
7add8f7fb048534390571801b7794f71cd9e127abnicholes * Apache stub function for the regex libraries regexec() to make sure the
7add8f7fb048534390571801b7794f71cd9e127abnicholes * whole regex(3) API is available through the Apache (exported) namespace.
7add8f7fb048534390571801b7794f71cd9e127abnicholes * This is especially important for the DSO situations of modules.
7add8f7fb048534390571801b7794f71cd9e127abnicholes * DO NOT MAKE A MACRO OUT OF THIS FUNCTION!
7add8f7fb048534390571801b7794f71cd9e127abnicholesAPI_EXPORT(int) ap_regexec(const regex_t *preg, const char *string,
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes return regexec(preg, string, nmatch, pmatch, eflags);
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholesAPI_EXPORT(size_t) ap_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes return regerror(errcode, preg, errbuf, errbuf_size);
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes/* This function substitutes for $0-$9, filling in regular expression
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * submatches. Pass it the same nmatch and pmatch arguments that you
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * passed ap_regexec(). pmatch should not be greater than the maximum number
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * of subexpressions - i.e. one more than the re_nsub member of regex_t.
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * input should be the string with the $-expressions, source should be the
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * string that was matched against.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * It returns the substituted string, or NULL on error.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Parts of this code are based on Henry Spencer's regsub(), from his
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * AT&T V8 regexp package.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_pregsub(ap_context_t *p, const char *input, const char *source,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* First pass, find the size */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (c == '&')
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else if (no < nmatch && pmatch[no].rm_so < pmatch[no].rm_eo) {
8a03cd420b800a2428f49f4617293de9b2387b20jorton /* Now actually fill in the string */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (c == '&')
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else if (no < nmatch && pmatch[no].rm_so < pmatch[no].rm_eo) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Parse .. so we don't compromise security
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* Four paseses, as per RFC 1808 */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* a) remove ./ path segments */
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe if (name[l] == '.' && name[l + 1] == '/' && (l == 0 || name[l - 1] == '/'))
560fd0658902ab57754616c172d8953e69fc4722bnicholes /* b) remove trailing . path, segment */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes else if (w > 1 && name[w - 1] == '.' && name[w - 2] == '/')
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* c) remove all xx/../ segments. (including leading ../ and /../) */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe if (name[l] == '.' && name[l + 1] == '.' && name[l + 2] == '/' &&
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes register int m = l + 3, n;
560fd0658902ab57754616c172d8953e69fc4722bnicholes if (l >= 0) {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* d) remove trailing xx/.. segment. */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe else if (l > 2 && name[l - 1] == '.' && name[l - 2] == '.' && name[l - 3] == '/') {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (l >= 0) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *d, *s;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Check for UNC names. Leave leading two slashes. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *d++ = *s++;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe while (*s) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((*d++ = *s) == '/') {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes } while (*s == '/');
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * copy at most n leading directories of s into d
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * d should be at least as large as s plus 1 extra byte
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * assumes n > 0
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * the return value is the ever useful pointer to the trailing \0 of d
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * /a/b, 1 ==> /
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * /a/b, 2 ==> /a/
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * /a/b, 3 ==> /a/b/
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * /a/b, 4 ==> /a/b/
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_make_dirstr_prefix(char *d, const char *s, int n)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *d++ = *s++;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * return the parent directory name including trailing / of the file s
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_make_dirstr_parent(ap_context_t *p, const char *s)
560fd0658902ab57754616c172d8953e69fc4722bnicholes /* XXX: well this is really broken if this happens */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * This function is deprecated. Use one of the preceeding two functions
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * which are faster.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_make_dirstr(ap_context_t *p, const char *s, int n)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes register int x, f;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (x = 0, f = 0; s[x]; x++) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (s[x] == '/')
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((++f) == n) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return ap_pstrdup(p, s);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes register int x, n;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (x = 0, n = 0; path[x]; x++)
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe const char *x;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* XXX: well, this is a silly function, no method of reporting an
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * error... ah well. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_getword_nc(ap_context_t *atrans, char **line, char stop)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return ap_getword(atrans, (const char **) line, stop);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_getword(ap_context_t *atrans, const char **line, char stop)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_getword_white_nc(ap_context_t *atrans, char **line)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return ap_getword_white(atrans, (const char **) line);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_getword_white(ap_context_t *atrans, const char **line)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (x = 0; (*line)[x]; x++) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_getword_nulls_nc(ap_context_t *atrans, char **line, char stop)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return ap_getword_nulls(atrans, (const char **) line, stop);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_getword_nulls(ap_context_t *atrans, const char **line, char stop)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Get a word, (new) config-file style --- quoted strings and backslashes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * all honored
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic char *substring_conf(ap_context_t *p, const char *start, int len, char quote)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (i = 0; i < len; ++i) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_getword_conf_nc(ap_context_t *p, char **line)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_getword_conf(ap_context_t *p, const char **line)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (*strend == '\\' && strend[1] && strend[1] == quote)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes res = substring_conf(p, str + 1, strend - str - 1, quote);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(int) ap_cfg_closefile(configfile_t *cfp)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return (cfp->close == NULL) ? 0 : cfp->close(cfp->param);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return (int)EOF;
bb07ee33bce1a448bcc60ca43720b1ab1c413f87minfrinstatic void *cfg_getstr(void *buf, size_t bufsiz, void *param)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Open a configfile_t as FILE, return open configfile_t struct pointer */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(ap_status_t) ap_pcfg_openfile(configfile_t **ret_cfg, ap_context_t *p, const char *name)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Internal error: pcfg_openfile() called with NULL filename");
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, NULL,
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe "Access to config file %s denied: not a valid filename",
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe stat = ap_open(&file, name, APR_READ | APR_BUFFERED, APR_OS_DEFAULT, p);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Opening config file %s (%s)",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes name, (stat != APR_SUCCESS) ? strerror(errno) : "successful");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes strcasecmp(name + strlen(name) - 4, "/nul") == 0))) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif /* WIN32 || OS2 */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Access to file %s denied by server: not a regular file",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes new_cfg->getstr = (void *(*)(void *, size_t, void *)) cfg_getstr;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Allocate a configfile_t handle with user defined functions and params */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(configfile_t *) ap_pcfg_open_custom(ap_context_t *p, const char *descr,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes void *(*getstr) (void *buf, size_t bufsiz, void *param),
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes configfile_t *new_cfg = ap_palloc(p, sizeof(*new_cfg));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, NULL, "Opening config handler %s", descr);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Read one character from a configfile_t */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe/* Read one line from open configfile_t, strip LF, increase line number */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe/* If custom handler does not define a getstr() function, read char by char */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwroweAPI_EXPORT(int) ap_cfg_getline(char *buf, size_t bufsize, configfile_t *cfp)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* If a "get string" function is defined, use it */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe while (1) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (cfp->getstr(cbuf, cbufsize, cfp->param) == NULL)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * check for line continuation,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * i.e. match [^\\]\\[\r]\n only
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * line continuation requested -
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * then remove backslash and continue
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * no real continuation because escaped -
bb07ee33bce1a448bcc60ca43720b1ab1c413f87minfrin * then just remove escape character
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Leading and trailing white space is eliminated completely
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* blast trailing whitespace */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Zap leading whitespace by shifting */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL, "Read config: %s", buf);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* No "get string" function defined; read character by character */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes register int c;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes register size_t i = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* skip leading whitespace */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* too small, assume caller is crazy */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (c == CR) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* silently ignore CR (_assume_ that a LF follows) */
bb07ee33bce1a448bcc60ca43720b1ab1c413f87minfrin if (c == LF) {
bb07ee33bce1a448bcc60ca43720b1ab1c413f87minfrin /* increase line number and return on LF */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (c == EOF || c == 0x4 || c == LF || i >= (bufsize - 2)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * check for line continuation
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* line is continued */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* else nothing needs be done because
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * then the backslash is escaped and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * we just strip to a single one
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* blast trailing whitespace */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL, "Read config: %s", buf);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Size an HTTP header field list item, as separated by a comma.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * The return value is a pointer to the beginning of the non-empty list item
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * within the original string (or NULL if there is none) and the address
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * of field is shifted to the next non-comma, non-whitespace character.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * len is the length of the item excluding any beginning whitespace.
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwroweAPI_EXPORT(const char *) ap_size_list_item(const char **field, int *len)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const unsigned char *ptr = (const unsigned char *)*field;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const unsigned char *token;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Find first non-comma, non-whitespace byte */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Find the end of this item, skipping over dead bits */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *ptr && (in_qpair || in_qstr || in_com || *ptr != ',');
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe switch (*ptr) {
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes default : break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Advance field pointer to the next non-comma, non-white byte */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return (const char *)token;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe/* Retrieve an HTTP header field list item, as separated by a comma,
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * while stripping insignificant whitespace and lowercasing anything not in
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * a quoted string or comment. The return value is a new string containing
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * the converted list item (or NULL if none) and the address pointed to by
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes * field is shifted to the next non-comma, non-whitespace.
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholesAPI_EXPORT(char *) ap_get_list_item(ap_context_t *p, const char **field)
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe const char *tok_start;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe const unsigned char *ptr;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe unsigned char *pos;
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes int addspace = 0, in_qpair = 0, in_qstr = 0, in_com = 0, tok_len = 0;
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* Find the beginning and maximum length of the list item so that
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * we can allocate a buffer for the new string and reset the field.
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes if ((tok_start = ap_size_list_item(field, &tok_len)) == NULL) {
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* Scan the token again, but this time copy only the good bytes.
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * We skip extra whitespace and any whitespace around a '=', '/',
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * or ';' and lowercase normal characters not within a comment,
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * quoted-string or quoted-pair.
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes for (ptr = (const unsigned char *)tok_start, pos = (unsigned char *)token;
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes *ptr && (in_qpair || in_qstr || in_com || *ptr != ',');
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes switch (*ptr) {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe/* Find an item in canonical form (lowercase, no extra spaces) within
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * an HTTP field value list. Returns 1 if found, 0 if not found.
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes * This would be much more efficient if we stored header fields as
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * an array of list items as they are received instead of a plain string.
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholesAPI_EXPORT(int) ap_find_list_item(ap_context_t *p, const char *line, const char *tok)
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes const unsigned char *pos;
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes const unsigned char *ptr = (const unsigned char *)line;
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes int good = 0, addspace = 0, in_qpair = 0, in_qstr = 0, in_com = 0;
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes do { /* loop for each item in line's list */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* Find first non-comma, non-whitespace byte */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes break; /* no items left and nothing good found */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* We skip extra whitespace and any whitespace around a '=', '/',
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * or ';' and lowercase normal characters not within a comment,
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * quoted-string or quoted-pair.
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes *ptr && (in_qpair || in_qstr || in_com || *ptr != ',');
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes switch (*ptr) {
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes default : if (!good)
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes good = 0; /* not good if only a prefix was matched */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes/* Retrieve a token, spacing over it and returning a pointer to
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * the first non-white byte afterwards. Note that these tokens
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * are delimited by semis and commas; and can also be delimited
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * by whitespace at the caller's option.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_get_token(ap_context_t *p, const char **accept_line, int accept_white)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Find first non-white byte */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* find token end, skipping over quoted strings.
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe * (comments are already gone).
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (*ptr && (accept_white || !ap_isspace(*ptr))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Advance accept_line pointer to the next non-white byte */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* find http tokens, see the definition of token from RFC2068 */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(int) ap_find_token(ap_context_t *p, const char *line, const char *tok)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const unsigned char *start_token;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const unsigned char *s;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes s = (const unsigned char *)line;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* find start of token, skip all stop characters, note NUL
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * isn't a token stop, so we don't need to test for it
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* find end of the token */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strncasecmp((const char *)start_token, (const char *)tok, s - start_token)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(int) ap_find_last_token(ap_context_t *p, const char *line, const char *tok)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((lidx < 0) ||
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ((lidx > 0) && !(ap_isspace(line[lidx - 1]) || line[lidx - 1] == ',')))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(char *) ap_escape_shell_cmd(ap_context_t *p, const char *str)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes unsigned char *d;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const unsigned char *s;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe cmd = ap_palloc(p, 2 * strlen(str) + 1); /* Be safe */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe d = (unsigned char *)cmd;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes s = (const unsigned char *)str;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (; *s; ++s) {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* Don't allow '&' in parameters under OS/2. */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* This can be used to send commands to the shell. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (*s == '&') {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *d++ = '\\';
54d22ed1c429b903b029bbd62621f11a9e286137minfrin register char digit;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin digit = ((what[0] >= 'A') ? ((what[0] & 0xdf) - 'A') + 10 : (what[0] - '0'));
54d22ed1c429b903b029bbd62621f11a9e286137minfrin digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A') + 10 : (what[1] - '0'));
54d22ed1c429b903b029bbd62621f11a9e286137minfrin#else /*CHARSET_EBCDIC*/
54d22ed1c429b903b029bbd62621f11a9e286137minfrin#endif /*CHARSET_EBCDIC*/
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * Unescapes a URL.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * Returns 0 on success, non-zero on error
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * Failure is due to
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * bad % escape returns BAD_REQUEST
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * decoding %00 -> \0
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * decoding %2f -> / (a special character)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * returns NOT_FOUND
54d22ed1c429b903b029bbd62621f11a9e286137minfrin char *x, *y;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* Initial scan for first '%'. Don't bother writing values before
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * seeing a '%' */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (y == NULL) {
09338db7fdcf82ecc189195347da3a3ed5d0287abnicholes for (x = y; *y; ++x, ++y) {
09338db7fdcf82ecc189195347da3a3ed5d0287abnicholes if (*y != '%')
09338db7fdcf82ecc189195347da3a3ed5d0287abnicholes if (!ap_isxdigit(*(y + 1)) || !ap_isxdigit(*(y + 2))) {
09338db7fdcf82ecc189195347da3a3ed5d0287abnicholesAPI_EXPORT(char *) ap_construct_server(ap_context_t *p, const char *hostname,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin/* c2x takes an unsigned, and expects the caller has guaranteed that
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * 0 <= what < 256... which usually means that you have to cast to
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * unsigned char first, because (unsigned)(char)(x) fist goes through
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * signed extension to an int before the unsigned cast.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * The reason for this assumption is to assist gcc code generation --
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * the unsigned char -> unsigned extension is already done earlier in
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * both uses of this code, so there's no need to waste time doing it
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowestatic ap_inline unsigned char *c2x(unsigned what, unsigned char *where)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * escape_path_segment() escapes a path segment, as defined in RFC 1808. This
5aa455d45abacfa675c88d4ff53fbe97c44ce545bnicholes * routine is (should be) OS independent.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * os_escape_path() converts an OS path to a URL, in an OS dependent way. In all
d5cff0d8e871bf2528aadd8736fb50dc044b1e6dbnicholes * cases if a ':' occurs before the first '/' in the URL, the URL should be
5aa455d45abacfa675c88d4ff53fbe97c44ce545bnicholes * prefixed with "./" (or the ':' escaped). In the case of Unix, this means
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * leaving '/' alone, but otherwise doing what escape_path_segment() does. For
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * efficiency reasons, we don't use escape_path_segment(), which is provided for
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * reference. Again, RFC 1808 is where this stuff is defined.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * If partial is set, os_escape_path() assumes that the path will be appended to
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * something with a '/' in it (and thus does not prefix "./").
54d22ed1c429b903b029bbd62621f11a9e286137minfrinAPI_EXPORT(char *) ap_escape_path_segment(ap_context_t *p, const char *segment)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin const unsigned char *s = (const unsigned char *)segment;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin unsigned char *d = (unsigned char *)copy;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin unsigned c;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin while ((c = *s)) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrinAPI_EXPORT(char *) ap_os_escape_path(ap_context_t *p, const char *path, int partial)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin const unsigned char *s = (const unsigned char *)path;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin unsigned char *d = (unsigned char *)copy;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin unsigned c;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin *d++ = '.';
54d22ed1c429b903b029bbd62621f11a9e286137minfrin *d++ = '/';
54d22ed1c429b903b029bbd62621f11a9e286137minfrin while ((c = *s)) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin/* ap_escape_uri is now a macro for os_escape_path */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwroweAPI_EXPORT(char *) ap_escape_html(ap_context_t *p, const char *s)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* first, count the number of extra characters */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin for (i = 0, j = 0; s[i] != '\0'; i++)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else if (s[i] == '&')
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return ap_pstrndup(p, s, i);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin for (i = 0, j = 0; s[i] != '\0'; i++, j++)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (s[i] == '<') {
09338db7fdcf82ecc189195347da3a3ed5d0287abnicholes else if (s[i] == '>') {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else if (s[i] == '&') {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin x[j] = s[i];
54d22ed1c429b903b029bbd62621f11a9e286137minfrin x[j] = '\0';
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return 0; /* in error condition, just return no */
54d22ed1c429b903b029bbd62621f11a9e286137minfrinAPI_EXPORT(char *) ap_make_full_path(ap_context_t *a, const char *src1,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin const char *src2)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin register int x;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (x == 0)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * Check for an absoluteURI syntax (see section 3.2 in RFC2068).
54d22ed1c429b903b029bbd62621f11a9e286137minfrin register int x;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (x = 0; u[x] != ':'; x++) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if ((!u[x]) ||
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return (x ? 1 : 0); /* If the first character is ':', it's broken, too */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Ouch! Out of memory in our strdup()!");
54d22ed1c429b903b029bbd62621f11a9e286137minfrin/* The following two routines were donated for SVR4 by Andreas Vogel */
54d22ed1c429b903b029bbd62621f11a9e286137minfrinint strcasecmp(const char *a, const char *b)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin const char *p = a;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin const char *q = b;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe for (p = a, q = b; *p && *q; p++, q++) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return 0; /* Exact match */
141e1368614dc7564e1627671361b01b4869b491bnicholesint strncasecmp(const char *a, const char *b, int n)
141e1368614dc7564e1627671361b01b4869b491bnicholes const char *p = a;
141e1368614dc7564e1627671361b01b4869b491bnicholes const char *q = b;
141e1368614dc7564e1627671361b01b4869b491bnicholes for (p = a, q = b; /*NOTHING */ ; p++, q++) {
141e1368614dc7564e1627671361b01b4869b491bnicholes if (p == a + n)
141e1368614dc7564e1627671361b01b4869b491bnicholes return 0; /* Match up to n characters */
141e1368614dc7564e1627671361b01b4869b491bnicholes if (!(*p && *q))
141e1368614dc7564e1627671361b01b4869b491bnicholes return *p - *q;
141e1368614dc7564e1627671361b01b4869b491bnicholes /*NOTREACHED */
0894cd17fe3f614bf01dbf84f1414756bd5a34c3bnicholes/* The following routine was donated for UTS21 by dwd@bell-labs.com */
0894cd17fe3f614bf01dbf84f1414756bd5a34c3bnicholes /* an empty s2 */
1c9fe70e77b36d36ae34997fe25fe47beacf8709bnicholes /* found first character of s2, see if the rest matches */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* both strings ended together */
1c9fe70e77b36d36ae34997fe25fe47beacf8709bnicholes /* second string ended, a match */
0894cd17fe3f614bf01dbf84f1414756bd5a34c3bnicholes /* didn't find a match here, try starting at next character in s1 */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#if defined(QNX) || defined(MPE) || defined(BEOS) || defined(_OSD_POSIX) || defined(TPF) || defined(__TANDEM)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* QNX, MPE and BeOS do not appear to support supplementary groups. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#else /* ndef QNX */
141e1368614dc7564e1627671361b01b4869b491bnicholes while (index < NGROUPS_MAX && ((g = getgrent()) != NULL))
54d22ed1c429b903b029bbd62621f11a9e286137minfrin#endif /* def QNX */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin#endif /* def NEED_INITGROUPS */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin/* From ikluft@amdahl.com
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * this is not ideal but it works for SVR3 variants
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * Modified by dwd@bell-labs.com to call wait3 instead of wait because
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * apache started to use the WNOHANG option.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (((tmp_pid = wait3(statusp, options, 0)) != pid) &&
54d22ed1c429b903b029bbd62621f11a9e286137minfrin register int x;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (x = 0; s[x]; x++)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (s[x] == c)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes register int x;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (s[x] == c)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad user name %s", ap_server_argv0, name);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad group name %s", ap_server_argv0, name);
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe * Parses a host of the form <address>[:port]
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe * :port is permitted if 'port' is not NULL
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesunsigned long ap_get_virthost_addr(char *w, unsigned short *ports)
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton unsigned long my_addr;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((!hep) || (hep->h_addrtype != AF_INET || !hep->h_addr_list[0])) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Cannot resolve host name %s --- exiting!", w);
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Host %s has multiple addresses ---", w);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "you must choose one explicitly for use as");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "a virtual host. Exiting!!!");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return ((struct in_addr *) (hep->h_addr))->s_addr;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic char *find_fqdn(ap_context_t *a, struct hostent *p)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin for (x = 0; p->h_aliases[x]; ++x) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin (!strncasecmp(p->h_aliases[x], p->h_name, strlen(p->h_name))))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((!(p = gethostbyname(str))) || (!(server_hostname = find_fqdn(a, p)))) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "%s: cannot determine local host name.",
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe "Use the ServerName directive to set it manually.");
af6d8b02b2fd4ea9a0f6bfb95940d6075030e9a7minfrin/* simple 'pool' alloc()ing glue to ap_base64.c
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwroweAPI_EXPORT(char *) ap_pbase64decode(ap_context_t *p, const char *bufcoded)
e025b9c2dbc3e2873142a775c37336a75ead222bjorton decoded = (char *) ap_palloc(p, 1 + ap_base64decode_len(bufcoded));
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe decoded[l] = '\0'; /* make binary sequence into string */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwroweAPI_EXPORT(char *) ap_pbase64encode(ap_context_t *p, char *string)
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe encoded = (char *) ap_palloc(p, 1 + ap_base64encode_len(l));
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe encoded[l] = '\0'; /* make binary sequence into string */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe/* deprecated names for the above two functions, here for compatibility
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwroweAPI_EXPORT(char *) ap_uudecode(ap_context_t *p, const char *bufcoded)
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwroweAPI_EXPORT(char *) ap_uuencode(ap_context_t *p, char *string)
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe for (loop = 0; loop < (strlen(path) + 1) && loop < sizeof(newpath) - 1; loop++) {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe offset = offset + 1;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe newpath[offset] = '\\';
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* Debugging code */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* fprintf(stderr, "%s \n", newpath); */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe/* quotes in the string are doubled up.
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe * Used to escape quotes in args passed to OS/2's cmd.exe
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes quote_doubled_str = ap_palloc(p, len + num_quotes + 1);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes extern char *const sys_errlist[];
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe return (p);
char *semi;
if (semi) {
while (*str) {
++str;
if (semi) {
int newlen = 0;
newlen++;
newlen++;
inchr++;
newlen++;
inchr++;
return outstring;