util.c revision 9ede6357edc9aff1fb2f7edebefab473673298aa
/* ====================================================================
* Copyright (c) 1995-1999 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Group and was originally based
* on public domain software written at the National Center for
* Supercomputing Applications, University of Illinois, Urbana-Champaign.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
/*
* util.c: string utility things
*
* 3/21/93 Rob McCool
* 1995-96 Many changes by the Apache Group
*
*/
/* Debugging aid:
* #define DEBUG to trace all cfg_open*()/cfg_closefile() calls
* #define DEBUG_CFG_LINES to trace every line read from the config files
*/
#include "httpd.h"
#include "http_main.h"
#include "http_log.h"
#include "http_protocol.h"
#if defined(SUNOS4)
/* stdio.h has been read in ap_config.h already. Add missing prototypes here: */
#endif
/* A bunch of functions in util.c scan strings looking for certain characters.
* To make that more efficient we encode a lookup table. The test_char_table
* is generated automatically by gen_test_char.c.
*/
#include "test_char.h"
/* we assume the folks using this ensure 0 <= c < 256... which means
* you need a cast to (unsigned char) first, you can't just plug a
* char in here and get it to work, because if char is signed then it
* will first be sign extended.
*/
#define TEST_CHAR(c, f) (test_char_table[(unsigned)(c)] & (f))
API_EXPORT(char *) ap_get_time()
{
char *time_string = NULL;
ap_make_time(&t, NULL);
ap_current_time(t);
return (time_string);
}
/*
* Examine a field value (such as a media-/content-type) string and return
* it sans any parameters; e.g., strip off any ';charset=foo' and the like.
*/
{
const char *semi;
return ap_pstrdup(p, intype);
}
else {
semi--;
}
}
}
{
char ts[MAX_STRING_LEN];
char tf[MAX_STRING_LEN];
if (gmt) {
}
else {
}
if(gmt) {
/* Convert %Z to "GMT" and %z to "+0000";
* on hosts that do not have a time zone string in struct tm,
* strftime must assume its argument is local time.
*/
const char *f;
char *strp;
; f++, strp++) {
if (*f != '%') continue;
switch (f[1]) {
case '%':
*++strp = *++f;
break;
case 'Z':
*strp++ = 'G';
*strp++ = 'M';
*strp = 'T';
f++;
break;
case 'z': /* common extension */
*strp++ = '+';
*strp++ = '0';
*strp++ = '0';
*strp++ = '0';
*strp = '0';
f++;
break;
}
}
*strp = '\0';
}
/* check return code? */
return ap_pstrdup(p, ts);
}
/* Roy owes Rob beer. */
/* Rob owes Roy dinner. */
/* These legacy comments would make a lot more sense if Roy hadn't
* replaced the old later_than() routine with util_date.c.
*
* Well, okay, they still wouldn't make any sense.
*/
/* Match = 0, NoMatch = 1, Abort = -1
* Based loosely on sections of wildmat.c by Rich Salz
* Hmmm... shouldn't this really go component by component?
*/
{
int x, y;
for (x = 0, y = 0; exp[y]; ++y, ++x) {
return -1;
if (exp[y] == '*') {
while (exp[++y] == '*');
if (!exp[y])
return 0;
while (str[x]) {
int ret;
return ret;
}
return -1;
}
return 1;
}
return (str[x] != '\0');
}
{
int x, y;
for (x = 0, y = 0; exp[y]; ++y, ++x) {
return -1;
if (exp[y] == '*') {
while (exp[++y] == '*');
if (!exp[y])
return 0;
while (str[x]) {
int ret;
return ret;
}
return -1;
}
return 1;
}
return (str[x] != '\0');
}
{
register int x;
for (x = 0; str[x]; x++)
return 1;
return 0;
}
/*
* Here's a pool-based interface to POSIX regex's regcomp().
* Note that we return regex_t instead of being passed one.
* The reason is that if you use an already-used regex_t structure,
* the memory that you've already allocated gets forgotten, and
* regfree() doesn't clear it. So we don't allow it.
*/
{
return APR_SUCCESS;
}
int cflags)
{
return NULL;
}
return preg;
}
{
}
/*
* Apache stub function for the regex libraries regexec() to make sure the
* whole regex(3) API is available through the Apache (exported) namespace.
* This is especially important for the DSO situations of modules.
* DO NOT MAKE A MACRO OUT OF THIS FUNCTION!
*/
{
}
{
}
/* This function substitutes for $0-$9, filling in regular expression
* submatches. Pass it the same nmatch and pmatch arguments that you
* passed ap_regexec(). pmatch should not be greater than the maximum number
* of subexpressions - i.e. one more than the re_nsub member of regex_t.
*
* input should be the string with the $-expressions, source should be the
* string that was matched against.
*
* It returns the substituted string, or NULL on error.
*
* Parts of this code are based on Henry Spencer's regsub(), from his
* AT&T V8 regexp package.
*/
{
char c;
int len;
if (!source)
return NULL;
if (!nmatch)
return ap_pstrdup(p, src);
/* First pass, find the size */
len = 0;
while ((c = *src++) != '\0') {
if (c == '&')
no = 0;
else
no = 10;
c = *src++;
len++;
}
}
}
/* Now actually fill in the string */
while ((c = *src++) != '\0') {
if (c == '&')
no = 0;
else
no = 10;
c = *src++;
*dst++ = c;
}
}
}
*dst = '\0';
return dest;
}
/*
* Parse .. so we don't compromise security
*/
{
int l, w;
/* Four paseses, as per RFC 1808 */
/* a) remove ./ path segments */
for (l = 0, w = 0; name[l] != '\0';) {
l += 2;
else
}
/* b) remove trailing . path, segment */
w--;
w--;
name[w] = '\0';
/* c) remove all xx/../ segments. (including leading ../ and /../) */
l = 0;
while (name[l] != '\0') {
register int m = l + 3, n;
l = l - 2;
if (l >= 0) {
while (l >= 0 && name[l] != '/')
l--;
l++;
}
else
l = 0;
n = l;
(++n, ++m);
}
else
++l;
}
/* d) remove trailing xx/.. segment. */
name[0] = '\0';
l = l - 4;
if (l >= 0) {
while (l >= 0 && name[l] != '/')
l--;
l++;
}
else
l = 0;
name[l] = '\0';
}
}
{
char *d, *s;
s = d = name;
#ifdef WIN32
/* Check for UNC names. Leave leading two slashes. */
if (s[0] == '/' && s[1] == '/')
*d++ = *s++;
#endif
while (*s) {
if ((*d++ = *s) == '/') {
do {
++s;
} while (*s == '/');
}
else {
++s;
}
}
*d = '\0';
}
/*
* copy at most n leading directories of s into d
* d should be at least as large as s plus 1 extra byte
* assumes n > 0
* the return value is the ever useful pointer to the trailing \0 of d
*
* examples:
* /a/b, 1 ==> /
* /a/b, 2 ==> /a/
* /a/b, 3 ==> /a/b/
* /a/b, 4 ==> /a/b/
*/
API_EXPORT(char *) ap_make_dirstr_prefix(char *d, const char *s, int n)
{
for (;;) {
if (*s == '\0' || (*s == '/' && (--n) == 0)) {
*d = '/';
break;
}
*d++ = *s++;
}
*++d = 0;
return (d);
}
/*
* return the parent directory name including trailing / of the file s
*/
{
char *d;
int l;
if (last_slash == NULL) {
/* XXX: well this is really broken if this happens */
return (ap_pstrdup(p, "/"));
}
l = (last_slash - s) + 1;
d = ap_palloc(p, l + 1);
memcpy(d, s, l);
d[l] = 0;
return (d);
}
/*
* This function is deprecated. Use one of the preceeding two functions
* which are faster.
*/
{
register int x, f;
char *res;
for (x = 0, f = 0; s[x]; x++) {
if (s[x] == '/')
if ((++f) == n) {
res[x] = '/';
return res;
}
}
return ap_pstrdup(p, s);
else
}
{
register int x, n;
for (x = 0, n = 0; path[x]; x++)
if (path[x] == '/')
n++;
return n;
}
{
const char *x;
char buf[HUGE_STRING_LEN];
if (x == NULL) {
}
}
/* XXX: well, this is a silly function, no method of reporting an
* error... ah well. */
}
{
}
{
char *res;
if (!pos) {
return res;
}
++pos;
}
return res;
}
{
}
{
int pos = -1, x;
char *res;
for (x = 0; (*line)[x]; x++) {
if (ap_isspace((*line)[x])) {
pos = x;
break;
}
}
if (pos == -1) {
return res;
}
++pos;
return res;
}
{
}
{
char *res;
if (!pos) {
return res;
}
++pos;
return res;
}
/* Get a word, (new) config-file style --- quoted strings and backslashes
* all honored
*/
{
int i;
for (i = 0; i < len; ++i) {
else
}
*resp++ = '\0';
return result;
}
{
return ap_getword_conf(p, (const char **) line);
}
{
char *res;
char quote;
++str;
if (!*str) {
return "";
}
strend += 2;
else
++strend;
}
++strend;
}
else {
++strend;
}
++strend;
return res;
}
{
#ifdef DEBUG
#endif
}
{
}
{
char ch;
return ch;
return (int)EOF;
}
{
return buf;
return NULL;
}
/* Open a configfile_t as FILE, return open configfile_t struct pointer */
{
"Internal error: pcfg_openfile() called with NULL filename");
return APR_EBADF;
}
if (!ap_os_is_filename_valid(name)) {
"Access to config file %s denied: not a valid filename",
name);
return APR_EACCES;
}
#ifdef DEBUG
"Opening config file %s (%s)",
#endif
if (stat != APR_SUCCESS)
return stat;
if (stat != APR_SUCCESS)
return stat;
#else
#endif /* WIN32 || OS2 */
"Access to file %s denied by server: not a regular file",
name);
return APR_EBADF;
}
new_cfg->line_number = 0;
return APR_SUCCESS;
}
/* Allocate a configfile_t handle with user defined functions and params */
void *param,
int(*close_func)(void *param))
{
#ifdef DEBUG
#endif
new_cfg->line_number = 0;
return new_cfg;
}
/* Read one character from a configfile_t */
{
++cfp->line_number;
return ch;
}
/* Read one line from open configfile_t, strip LF, increase line number */
/* If custom handler does not define a getstr() function, read char by char */
{
/* If a "get string" function is defined, use it */
char *cp;
while (1) {
++cfp->line_number;
return 1;
/*
* check for line continuation,
* i.e. match [^\\]\\[\r]\n only
*/
cp++;
cp--;
cp--;
cp--;
/*
* line continuation requested -
* then remove backslash and continue
*/
continue;
}
else {
/*
* no real continuation because escaped -
* then just remove escape character
*/
}
}
}
break;
}
/*
* Leading and trailing white space is eliminated completely
*/
while (ap_isspace(*src))
++src;
/* blast trailing whitespace */
*dst = '\0';
/* Zap leading whitespace by shifting */
;
#ifdef DEBUG_CFG_LINES
#endif
return 0;
} else {
/* No "get string" function defined; read character by character */
register int c;
register size_t i = 0;
buf[0] = '\0';
/* skip leading whitespace */
do {
} while (c == '\t' || c == ' ');
if (c == EOF)
return 1;
if(bufsize < 2) {
/* too small, assume caller is crazy */
return 1;
}
while (1) {
if ((c == '\t') || (c == ' ')) {
buf[i++] = ' ';
while ((c == '\t') || (c == ' '))
}
if (c == CR) {
/* silently ignore CR (_assume_ that a LF follows) */
}
if (c == LF) {
/* increase line number and return on LF */
++cfp->line_number;
}
/*
* check for line continuation
*/
i--;
/* line is continued */
continue;
}
/* else nothing needs be done because
* then the backslash is escaped and
* we just strip to a single one
*/
}
/* blast trailing whitespace */
--i;
buf[i] = '\0';
#ifdef DEBUG_CFG_LINES
#endif
return 0;
}
buf[i] = c;
++i;
}
}
}
/* Size an HTTP header field list item, as separated by a comma.
* The return value is a pointer to the beginning of the non-empty list item
* within the original string (or NULL if there is none) and the address
* of field is shifted to the next non-comma, non-whitespace character.
* len is the length of the item excluding any beginning whitespace.
*/
{
const unsigned char *token;
/* Find first non-comma, non-whitespace byte */
++ptr;
/* Find the end of this item, skipping over dead bits */
++ptr) {
if (in_qpair) {
in_qpair = 0;
}
else {
switch (*ptr) {
break;
break;
++in_com;
break;
--in_com;
break;
default : break;
}
}
}
return NULL;
}
/* Advance field pointer to the next non-comma, non-white byte */
++ptr;
return (const char *)token;
}
/* Retrieve an HTTP header field list item, as separated by a comma,
* while stripping insignificant whitespace and lowercasing anything not in
* a quoted string or comment. The return value is a new string containing
* the converted list item (or NULL if none) and the address pointed to by
* field is shifted to the next non-comma, non-whitespace.
*/
{
const char *tok_start;
const unsigned char *ptr;
unsigned char *pos;
char *token;
/* Find the beginning and maximum length of the list item so that
* we can allocate a buffer for the new string and reset the field.
*/
return NULL;
}
/* Scan the token again, but this time copy only the good bytes.
* We skip extra whitespace and any whitespace around a '=', '/',
* or ';' and lowercase normal characters not within a comment,
* quoted-string or quoted-pair.
*/
++ptr) {
if (in_qpair) {
in_qpair = 0;
}
else {
switch (*ptr) {
if (addspace == 1)
*pos++ = ' ';
addspace = 0;
break;
case '"' : if (!in_com)
if (addspace == 1)
*pos++ = ' ';
addspace = 0;
break;
case '(' : if (!in_qstr)
++in_com;
if (addspace == 1)
*pos++ = ' ';
addspace = 0;
break;
case ')' : if (in_com)
--in_com;
addspace = 0;
break;
case ' ' :
case '\t': if (addspace)
break;
else
addspace = 1;
break;
case '=' :
case '/' :
addspace = -1;
break;
default : if (addspace == 1)
*pos++ = ' ';
: ap_tolower(*ptr);
addspace = 0;
break;
}
}
}
*pos = '\0';
return token;
}
/* Find an item in canonical form (lowercase, no extra spaces) within
* an HTTP field value list. Returns 1 if found, 0 if not found.
* This would be much more efficient if we stored header fields as
* an array of list items as they are received instead of a plain string.
*/
{
const unsigned char *pos;
return 0;
do { /* loop for each item in line's list */
/* Find first non-comma, non-whitespace byte */
++ptr;
if (*ptr)
else
break; /* no items left and nothing good found */
/* We skip extra whitespace and any whitespace around a '=', '/',
* or ';' and lowercase normal characters not within a comment,
* quoted-string or quoted-pair.
*/
++ptr) {
if (in_qpair) {
in_qpair = 0;
if (good)
}
else {
switch (*ptr) {
if (addspace == 1)
addspace = 0;
break;
case '"' : if (!in_com)
if (addspace == 1)
addspace = 0;
break;
case '(' : if (!in_qstr)
++in_com;
if (addspace == 1)
addspace = 0;
break;
case ')' : if (in_com)
--in_com;
addspace = 0;
break;
case ' ' :
break;
else
addspace = 1;
break;
case '=' :
case '/' :
addspace = -1;
break;
default : if (!good)
break;
if (addspace == 1)
else
addspace = 0;
break;
}
}
}
good = 0; /* not good if only a prefix was matched */
return good;
}
/* Retrieve a token, spacing over it and returning a pointer to
* the first non-white byte afterwards. Note that these tokens
* are delimited by semis and commas; and can also be delimited
* by whitespace at the caller's option.
*/
{
const char *ptr = *accept_line;
const char *tok_start;
char *token;
int tok_len;
/* Find first non-white byte */
++ptr;
/* find token end, skipping over quoted strings.
* (comments are already gone).
*/
if (*ptr++ == '"')
while (*ptr)
if (*ptr++ == '"')
break;
}
/* Advance accept_line pointer to the next non-white byte */
++ptr;
*accept_line = ptr;
return token;
}
/* find http tokens, see the definition of token from RFC2068 */
{
const unsigned char *start_token;
const unsigned char *s;
if (!line)
return 0;
s = (const unsigned char *)line;
for (;;) {
/* find start of token, skip all stop characters, note NUL
* isn't a token stop, so we don't need to test for it
*/
while (TEST_CHAR(*s, T_HTTP_TOKEN_STOP)) {
++s;
}
if (!*s) {
return 0;
}
start_token = s;
/* find end of the token */
while (*s && !TEST_CHAR(*s, T_HTTP_TOKEN_STOP)) {
++s;
}
return 1;
}
if (!*s) {
return 0;
}
}
}
{
if (!line)
return 0;
if ((lidx < 0) ||
return 0;
}
{
char *cmd;
unsigned char *d;
const unsigned char *s;
d = (unsigned char *)cmd;
s = (const unsigned char *)str;
for (; *s; ++s) {
/* Don't allow '&' in parameters under OS/2. */
/* This can be used to send commands to the shell. */
if (*s == '&') {
*d++ = ' ';
continue;
}
#endif
if (TEST_CHAR(*s, T_ESCAPE_SHELL_CMD)) {
*d++ = '\\';
}
*d++ = *s;
}
*d = '\0';
return cmd;
}
{
register char digit;
#ifndef CHARSET_EBCDIC
digit *= 16;
#else /*CHARSET_EBCDIC*/
char xstr[5];
xstr[0]='0';
#endif /*CHARSET_EBCDIC*/
return (digit);
}
/*
* Unescapes a URL.
* Returns 0 on success, non-zero on error
* Failure is due to
* bad % escape returns BAD_REQUEST
*
* decoding %00 -> \0
* decoding %2f -> / (a special character)
* returns NOT_FOUND
*/
{
char *x, *y;
badesc = 0;
badpath = 0;
/* Initial scan for first '%'. Don't bother writing values before
* seeing a '%' */
if (y == NULL) {
return OK;
}
for (x = y; *y; ++x, ++y) {
if (*y != '%')
*x = *y;
else {
badesc = 1;
*x = '%';
}
else {
*x = x2c(y + 1);
y += 2;
if (*x == '/' || *x == '\0')
badpath = 1;
}
}
}
*x = '\0';
if (badesc)
return BAD_REQUEST;
else if (badpath)
return NOT_FOUND;
else
return OK;
}
unsigned port, const request_rec *r)
{
if (ap_is_default_port(port, r))
return ap_pstrdup(p, hostname);
else {
}
}
/* c2x takes an unsigned, and expects the caller has guaranteed that
* 0 <= what < 256... which usually means that you have to cast to
* unsigned char first, because (unsigned)(char)(x) fist goes through
* signed extension to an int before the unsigned cast.
*
* The reason for this assumption is to assist gcc code generation --
* the unsigned char -> unsigned extension is already done earlier in
* both uses of this code, so there's no need to waste time doing it
* again.
*/
static const char c2x_table[] = "0123456789abcdef";
{
*where++ = '%';
return where;
}
/*
* escape_path_segment() escapes a path segment, as defined in RFC 1808. This
* routine is (should be) OS independent.
*
* os_escape_path() converts an OS path to a URL, in an OS dependent way. In all
* cases if a ':' occurs before the first '/' in the URL, the URL should be
* prefixed with "./" (or the ':' escaped). In the case of Unix, this means
* leaving '/' alone, but otherwise doing what escape_path_segment() does. For
* efficiency reasons, we don't use escape_path_segment(), which is provided for
* reference. Again, RFC 1808 is where this stuff is defined.
*
* If partial is set, os_escape_path() assumes that the path will be appended to
* something with a '/' in it (and thus does not prefix "./").
*/
{
const unsigned char *s = (const unsigned char *)segment;
unsigned char *d = (unsigned char *)copy;
unsigned c;
while ((c = *s)) {
if (TEST_CHAR(c, T_ESCAPE_PATH_SEGMENT)) {
d = c2x(c, d);
}
else {
*d++ = c;
}
++s;
}
*d = '\0';
return copy;
}
{
const unsigned char *s = (const unsigned char *)path;
unsigned char *d = (unsigned char *)copy;
unsigned c;
if (!partial) {
*d++ = '.';
*d++ = '/';
}
}
while ((c = *s)) {
if (TEST_CHAR(c, T_OS_ESCAPE_PATH)) {
d = c2x(c, d);
}
else {
*d++ = c;
}
++s;
}
*d = '\0';
return copy;
}
/* ap_escape_uri is now a macro for os_escape_path */
{
int i, j;
char *x;
/* first, count the number of extra characters */
for (i = 0, j = 0; s[i] != '\0'; i++)
if (s[i] == '<' || s[i] == '>')
j += 3;
else if (s[i] == '&')
j += 4;
if (j == 0)
return ap_pstrndup(p, s, i);
x = ap_palloc(p, i + j + 1);
for (i = 0, j = 0; s[i] != '\0'; i++, j++)
if (s[i] == '<') {
j += 3;
}
else if (s[i] == '>') {
j += 3;
}
else if (s[i] == '&') {
j += 4;
}
else
x[j] = s[i];
x[j] = '\0';
return x;
}
{
return 0; /* in error condition, just return no */
}
const char *src2)
{
register int x;
if (x == 0)
else
}
/*
* Check for an absoluteURI syntax (see section 3.2 in RFC2068).
*/
API_EXPORT(int) ap_is_url(const char *u)
{
register int x;
for (x = 0; u[x] != ':'; x++) {
if ((!u[x]) ||
((!ap_isalpha(u[x])) && (!ap_isdigit(u[x])) &&
(u[x] != '+') && (u[x] != '-') && (u[x] != '.'))) {
return 0;
}
}
return (x ? 1 : 0); /* If the first character is ':', it's broken, too */
}
#ifndef HAVE_STRDUP
{
char *sdup;
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Ouch! Out of memory in our strdup()!");
return NULL;
}
return sdup;
}
#endif
/* The following two routines were donated for SVR4 by Andreas Vogel */
#ifndef HAVE_STRCASECMP
int strcasecmp(const char *a, const char *b)
{
const char *p = a;
const char *q = b;
for (p = a, q = b; *p && *q; p++, q++) {
if (diff)
return diff;
}
if (*p)
return 1; /* p was longer than q */
if (*q)
return -1; /* p was shorter than q */
return 0; /* Exact match */
}
#endif
#ifndef HAVE_STRNCASECMP
int strncasecmp(const char *a, const char *b, int n)
{
const char *p = a;
const char *q = b;
for (p = a, q = b; /*NOTHING */ ; p++, q++) {
int diff;
if (p == a + n)
return 0; /* Match up to n characters */
if (!(*p && *q))
return *p - *q;
if (diff)
return diff;
}
/*NOTREACHED */
}
#endif
/* The following routine was donated for UTS21 by dwd@bell-labs.com */
#ifndef HAVE_STRSTR
{
if (*s2 == '\0') {
/* an empty s2 */
return(s1);
}
/* found first character of s2, see if the rest matches */
if (*p1 == '\0') {
/* both strings ended together */
return(s1);
}
}
if (*p2 == '\0') {
/* second string ended, a match */
break;
}
/* didn't find a match here, try starting at next character in s1 */
s1++;
}
return(s1);
}
#endif
#ifndef HAVE_INITGROUPS
{
#if defined(QNX) || defined(MPE) || defined(BEOS) || defined(_OSD_POSIX) || defined(TPF) || defined(__TANDEM)
/* QNX, MPE and BeOS do not appear to support supplementary groups. */
return 0;
#else /* ndef QNX */
struct group *g;
int index = 0;
setgrent();
char **names;
}
endgrent();
#endif /* def QNX */
}
#endif /* def NEED_INITGROUPS */
#ifndef HAVE_WAITPID
/* From ikluft@amdahl.com
* this is not ideal but it works for SVR3 variants
* Modified by dwd@bell-labs.com to call wait3 instead of wait because
* apache started to use the WNOHANG option.
*/
{
int tmp_pid;
return -1;
}
;
return tmp_pid;
}
#endif
API_EXPORT(int) ap_ind(const char *s, char c)
{
register int x;
for (x = 0; s[x]; x++)
if (s[x] == c)
return x;
return -1;
}
API_EXPORT(int) ap_rind(const char *s, char c)
{
register int x;
if (s[x] == c)
return x;
return -1;
}
{
while (*str) {
++str;
}
}
{
#ifdef WIN32
return (1);
#else
if (name[0] == '#')
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad user name %s", ap_server_argv0, name);
exit(1);
}
#endif
}
{
#ifdef WIN32
return (1);
#else
if (name[0] == '#')
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad group name %s", ap_server_argv0, name);
exit(1);
}
#endif
}
/*
* Parses a host of the form <address>[:port]
* :port is permitted if 'port' is not NULL
*/
unsigned long ap_get_virthost_addr(char *w, unsigned short *ports)
{
unsigned long my_addr;
char *p;
p = strchr(w, ':');
*ports = 0;
}
if (p != NULL)
*p = '\0';
if (strcmp(w, "*") == 0) {
if (p != NULL)
*p = ':';
return htonl(INADDR_ANY);
}
my_addr = ap_inet_addr((char *)w);
if (my_addr != INADDR_NONE) {
if (p != NULL)
*p = ':';
return my_addr;
}
hep = gethostbyname(w);
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Cannot resolve host name %s --- exiting!", w);
exit(1);
}
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");
exit(1);
}
if (p != NULL)
*p = ':';
}
{
int x;
for (x = 0; p->h_aliases[x]; ++x) {
return ap_pstrdup(a, p->h_aliases[x]);
}
return NULL;
}
return ap_pstrdup(a, (void *) p->h_name);
}
char *ap_get_local_host(ap_context_t *a)
{
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif
char *server_hostname;
struct hostent *p;
#ifdef BEOS
#else
#endif
{
perror("Unable to gethostname");
exit(1);
}
"%s: cannot determine local host name.",
"Use the ServerName directive to set it manually.");
exit(1);
}
return server_hostname;
}
/* simple 'pool' alloc()ing glue to ap_base64.c
*/
{
char *decoded;
int l;
return decoded;
}
{
char *encoded;
return encoded;
}
/* deprecated names for the above two functions, here for compatibility
*/
{
return ap_pbase64decode(p, bufcoded);
}
{
return ap_pbase64encode(p, string);
}
#ifdef OS2
void os2pathname(char *path)
{
char newpath[MAX_STRING_LEN];
int loop;
int offset;
offset = 0;
/*
offset = offset + 1;
newpath[offset] = '\\';
*/
}
else
};
/* Debugging code */
/* fprintf(stderr, "%s \n", newpath); */
};
/* quotes in the string are doubled up.
* Used to escape quotes in args passed to OS/2's cmd.exe
*/
{
int num_quotes = 0;
int len = 0;
char *quote_doubled_str, *dest;
}
while (*str) {
if (*str == '\"')
*(dest++) = '\"';
}
*dest = 0;
return quote_doubled_str;
}
#endif
#ifndef HAVE_STRERROR
char *
{
char *p;
extern char *const sys_errlist[];
p = sys_errlist[err];
return (p);
}
#endif
* but nothing else because ;parameter=foo values are case sensitive.
* XXX: in truth we want to downcase parameter names... but really,
* apache has never handled parameters and such correctly. You
* also need to compress spaces and such to be able to compare
* properly. -djg
*/
{
char *semi;
if (semi) {
*semi = '\0';
}
while (*str) {
++str;
}
if (semi) {
*semi = ';';
}
}
/*
* Given a string, replace any bare " with \" .
*/
{
int newlen = 0;
/*
* Look through the input string, jogging the length of the output
* string up by an extra byte each time we find an unescaped ".
*/
while (*inchr != '\0') {
newlen++;
if (*inchr == '"') {
newlen++;
}
/*
* If we find a slosh, and it's not the last byte in the string,
* it's escaping something - advance past both bytes.
*/
inchr++;
newlen++;
}
inchr++;
}
/*
* Now copy the input string to the output string, inserting a slosh
* in front of every " that doesn't already have one.
*/
while (*inchr != '\0') {
}
if (*inchr == '"') {
*outchr++ = '\\';
}
if (*inchr != '\0') {
}
}
*outchr = '\0';
return outstring;
}