util.c revision 1ccd992d37d62c8cb2056126f2234f64ec189bfd
ab4ab2edaac480f68b476dc19e015c54cd4f1978Lubos Kosco/* ====================================================================
ab4ab2edaac480f68b476dc19e015c54cd4f1978Lubos Kosco * The Apache Software License, Version 1.1
ab4ab2edaac480f68b476dc19e015c54cd4f1978Lubos Kosco * Copyright (c) 2000 The Apache Software Foundation. All rights
9661674ed58ba62a40e43d1a4b38d5e77c3c6545Knut Anders Hatlen * Redistribution and use in source and binary forms, with or without
551b849ce88d596dc52dda2f78229a932b339c78Lubos Kosco * modification, are permitted provided that the following conditions
e7b21c8124ec55ffacc49c1e28a8685834715484Lubos Kosco * 1. Redistributions of source code must retain the above copyright
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * notice, this list of conditions and the following disclaimer.
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * 2. Redistributions in binary form must reproduce the above copyright
477c09a2656e6a2c1075425ad81e61d594164fa9Lubos Kosco * notice, this list of conditions and the following disclaimer in
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * the documentation and/or other materials provided with the
bcae302a5f4b516d2f3c05f657df054e1a0efde7Knut Anders Hatlen * distribution.
98774b0b90e4da0f3f2c5e4856bcbbf366ed0fe0Knut Anders Hatlen * 3. The end-user documentation included with the redistribution,
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * if any, must include the following acknowledgment:
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * "This product includes software developed by the
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * Apache Software Foundation (http://www.apache.org/)."
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * Alternately, this acknowledgment may appear in the software itself,
afb218f076cae538126a5f931299a82a114a075aKnut Anders Hatlen * if and wherever such third-party acknowledgments normally appear.
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * 4. The names "Apache" and "Apache Software Foundation" must
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * not be used to endorse or promote products derived from this
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * software without prior written permission. For written
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * permission, please contact apache@apache.org.
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * 5. Products derived from this software may not be called "Apache",
c0550b01024b910b8c1468811c0ea663b10b1372Trond Norbye * nor may "Apache" appear in their name, without prior written
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * permission of the Apache Software Foundation.
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
9661674ed58ba62a40e43d1a4b38d5e77c3c6545Knut Anders Hatlen * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
bbb39d08c0e5b73c89ba813a7c1789842c60f961Lubos Kosco * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2ba599c0d79caf59996d8b54a0490bb968442134Knut Anders Hatlen * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
67b14513c549ae0027ba7590e736b3dd3281db7cLubos Kosco * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * SUCH DAMAGE.
85fb1b4846faa28d393e65ba466b7931478d7d6aLubos Kosco * ====================================================================
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * This software consists of voluntary contributions made by many
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * individuals on behalf of the Apache Software Foundation. For more
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * information on the Apache Software Foundation, please see
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * Portions of this software are based upon public domain software
f9fd2b96d1c5ea62664f74da0e34a04b6511a8ffLubos Kosco * originally written at the National Center for Supercomputing Applications,
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * University of Illinois, Urbana-Champaign.
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * util.c: string utility things
bbb39d08c0e5b73c89ba813a7c1789842c60f961Lubos Kosco * 3/21/93 Rob McCool
2ba599c0d79caf59996d8b54a0490bb968442134Knut Anders Hatlen * 1995-96 Many changes by the Apache Software Foundation
425278cfacbc73f1e955ab6016f206fc5ed93ccbVladimir Kotal/* Debugging aid:
425278cfacbc73f1e955ab6016f206fc5ed93ccbVladimir Kotal * #define DEBUG to trace all cfg_open*()/cfg_closefile() calls
425278cfacbc73f1e955ab6016f206fc5ed93ccbVladimir Kotal * #define DEBUG_CFG_LINES to trace every line read from the config files
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye/* A bunch of functions in util.c scan strings looking for certain characters.
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * To make that more efficient we encode a lookup table. The test_char_table
25fddb6fbc2130e3847315ff2b0b6819ff3feccaLubos Kosco * is generated automatically by gen_test_char.c.
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye/* we assume the folks using this ensure 0 <= c < 256... which means
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * you need a cast to (unsigned char) first, you can't just plug a
a1318a82916028f363b3c5b52e7fd7256b632497Trond Norbye * char in here and get it to work, because if char is signed then it
* Examine a field value (such as a media-/content-type) string and return
const char *semi;
semi--;
if (gmt) {
char *strp;
; f++, strp++) {
*++strp = *++f;
* replaced the old later_than() routine with util_date.c.
* Based loosely on sections of wildmat.c by Rich Salz
for (x = 0, y = 0; exp[y]; ++y, ++x) {
if (!exp[y])
while (str[x]) {
int ret;
return ret;
for (x = 0, y = 0; exp[y]; ++y, ++x) {
if (!exp[y])
while (str[x]) {
int ret;
return ret;
for (x = 0; str[x]; x++)
return APR_SUCCESS;
int cflags)
return NULL;
return preg;
return((char *)s1);
return((char *)s1);
s1++;
return((char *)s1);
int len;
if (!source)
return NULL;
if (!nmatch)
len = 0;
no = 0;
c = *src++;
len++;
no = 0;
c = *src++;
*dst++ = c;
return dest;
s = d = name;
#ifdef WIN32
memcpy(d, s, l);
char *res;
return res;
return apr_pstrdup(p, s);
for (x = 0, n = 0; path[x]; x++)
if (x == NULL) {
char *res;
if (!pos) {
return res;
++pos;
return res;
char *res;
for (x = 0; (*line)[x]; x++) {
pos = x;
return res;
++pos;
return res;
char *res;
if (!pos) {
return res;
++pos;
return res;
for (i = 0; i < len; ++i) {
return result;
char *res;
char quote;
++str;
if (!*str) {
++strend;
++strend;
++strend;
++strend;
return res;
return word;
const char *e2 = e;
#ifdef DEBUG
char ch;
return ch;
return (int)EOF;
return buf;
return NULL;
#ifdef DEBUG
return APR_EBADF;
name);
return APR_EACCES;
#ifdef DEBUG
return status;
return status;
name);
return APR_EBADF;
return APR_SUCCESS;
void *param,
#ifdef DEBUG
return new_cfg;
return ch;
char *cp;
cp++;
cp--;
cp--;
cp--;
++src;
#ifdef DEBUG_CFG_LINES
register size_t i = 0;
if (c == EOF)
if (c == CR) {
if (c == LF) {
#ifdef DEBUG_CFG_LINES
buf[i] = c;
const unsigned char *token;
++ptr;
++ptr) {
if (in_qpair) {
in_qpair = 0;
switch (*ptr) {
++in_com;
--in_com;
return NULL;
++ptr;
return (const char *)token;
const char *tok_start;
const unsigned char *ptr;
unsigned char *pos;
char *token;
return NULL;
++ptr) {
if (in_qpair) {
in_qpair = 0;
switch (*ptr) {
addspace = 0;
addspace = 0;
++in_com;
addspace = 0;
--in_com;
addspace = 0;
addspace = 0;
return token;
const unsigned char *pos;
++ptr;
if (*ptr)
++ptr) {
if (in_qpair) {
in_qpair = 0;
if (good)
switch (*ptr) {
addspace = 0;
addspace = 0;
++in_com;
addspace = 0;
--in_com;
addspace = 0;
default : if (!good)
addspace = 0;
return good;
const char *tok_start;
char *token;
int tok_len;
++ptr;
while (*ptr)
++ptr;
return token;
const unsigned char *start_token;
if (!line)
s = (const unsigned char *)line;
start_token = s;
if (!line)
if ((lidx < 0) ||
char *cmd;
d = (unsigned char *)cmd;
s = (const unsigned char *)str;
return cmd;
register char digit;
#ifndef CHARSET_EBCDIC
return (digit);
badesc = 0;
badpath = 0;
if (y == NULL) {
return OK;
if (badesc)
return HTTP_BAD_REQUEST;
else if (badpath)
return HTTP_NOT_FOUND;
return OK;
#ifdef CHARSET_EBCDIC
return where;
const unsigned char *s = (const unsigned char *)segment;
unsigned char *d = (unsigned char *)copy;
d = c2x(c, d);
return copy;
const unsigned char *s = (const unsigned char *)path;
unsigned char *d = (unsigned char *)copy;
if (!partial) {
d = c2x(c, d);
return copy;
return apr_pstrndup(p, s, i);
const char *src2)
#ifndef HAVE_INITGROUPS
#if defined(QNX) || defined(MPE) || defined(BEOS) || defined(_OSD_POSIX) || defined(TPF) || defined(__TANDEM) || defined(OS2) || defined(WIN32)
struct group *g;
int index = 0;
setgrent();
char **names;
endgrent();
while (*str) {
++str;
#ifdef WIN32
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad user name %s", ap_server_argv0, name);
#ifdef WIN32
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad group name %s", ap_server_argv0, name);
unsigned long my_addr;
*ports = 0;
if (p != NULL)
if (p != NULL)
if (p != NULL)
return my_addr;
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Cannot resolve host name %s --- exiting!", w);
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Host %s has multiple addresses ---", w);
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "you must choose one explicitly for use as");
if (p != NULL)
for (x = 0; p->h_aliases[x]; ++x) {
return NULL;
#ifndef MAXHOSTNAMELEN
struct hostent *p;
#ifdef BEOS
return server_hostname;
if (!server_hostname)
return server_hostname;
/* simple 'pool' alloc()ing glue to ap_base64.c
char *decoded;
return decoded;
char *encoded;
return encoded;
char *semi;
if (semi) {
while (*str) {
++str;
if (semi) {
int newlen = 0;
newlen++;
newlen++;
inchr++;
newlen++;
inchr++;
return outstring;