util.c revision 5bfaaf573bacb45c1cf290ce85ecc676587e8a64
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* util.c: string utility things
*
* 3/21/93 Rob McCool
* 1995-96 Many changes by the Apache Software Foundation
*
*/
/* 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 "apr.h"
#include "apr_strings.h"
#include "apr_lib.h"
#define APR_WANT_STDIO
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include <unistd.h>
#endif
#include <process.h> /* for getpid() on Win32 */
#endif
#if APR_HAVE_NETDB_H
#include <netdb.h> /* for gethostbyname() */
#endif
#include "ap_config.h"
#include "apr_base64.h"
#include "httpd.h"
#include "http_main.h"
#include "http_log.h"
#include "http_protocol.h"
#include "http_config.h"
#include "http_core.h"
#include "util_ebcdic.h"
#include "util_varbuf.h"
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#ifdef HAVE_GRP_H
#include <grp.h>
#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))
* in ap_getparents() and ap_escape_url.
*/
#ifdef CASE_BLIND_FILESYSTEM
#define SLASHES "/\\"
#else
#define IS_SLASH(s) (s == '/')
#define SLASHES "/"
#endif
/* we know core's module_index is 0 */
/*
* 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 apr_pstrdup(p, intype);
}
else {
semi--;
}
}
}
int gmt)
{
char ts[MAX_STRING_LEN];
char tf[MAX_STRING_LEN];
if (gmt) {
const char *f;
char *strp;
apr_time_exp_gmt(&xt, t);
/* 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.
*/
; 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';
}
else {
apr_time_exp_lt(&xt, t);
}
/* check return code? */
return apr_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; expected[y]; ++y, ++x) {
return -1;
if (expected[y] == '*') {
while (expected[++y] == '*');
if (!expected[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; expected[y]; ++y, ++x) {
return -1;
if (expected[y] == '*') {
while (expected[++y] == '*');
if (!expected[y])
return 0;
while (str[x]) {
int ret;
return ret;
}
return -1;
}
else if (expected[y] != '?'
return 1;
}
return (str[x] != '\0');
}
/* We actually compare the canonical root to this root, (but we don't
* waste time checking the case), since every use of this function in
* httpd-2.1 tests if the path is 'proper', meaning we've already passed
* it through apr_filepath_merge, or we haven't.
*/
{
const char *newpath;
return 0;
}
return 1;
}
{
register int x;
for (x = 0; str[x]; x++)
return 1;
return 0;
}
/*
* Here's a pool-based interface to the POSIX-esque ap_regcomp().
* Note that we return ap_regex_t instead of being passed one.
* The reason is that if you use an already-used ap_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;
}
{
}
/*
* Similar to standard strstr() but we ignore case in this version.
* Based on the strstr() implementation further below.
*/
{
if (*s2 == '\0') {
/* an empty s2 */
return((char *)s1);
}
while(1) {
if (*s1 == '\0') {
return(NULL);
}
/* found first character of s2, see if the rest matches */
if (*p1 == '\0') {
/* both strings ended together */
return((char *)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((char *)s1);
}
/*
* Returns an offsetted pointer in bigstring immediately after
* prefix. Returns bigstring if bigstring doesn't start with
* prefix or if prefix is longer than bigstring while still matching.
* NOTE: pointer returned is relative to bigstring, so we
* can use standard pointer comparisons in the calling function
* (eg: test if ap_stripprefix(a,b) == a)
*/
const char *prefix)
{
const char *p1;
if (*prefix == '\0')
return bigstring;
return bigstring;
}
if (*prefix == '\0')
return p1;
/* hit the end of bigstring! */
return bigstring;
}
/* 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 ap_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 apr_pstrdup(p, src);
/* First pass, find the size */
len = 0;
while ((c = *src++) != '\0') {
else
no = 10;
if (c == '\\' && *src)
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
*/
{
char *next;
int l, w, first_dot;
/* Four paseses, as per RFC 1808 */
/* a) remove ./ path segments */
}
while (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 = first_dot;
while (name[l] != '\0') {
register int m = l + 3, n;
l = l - 2;
if (l >= 0) {
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) {
l--;
l++;
}
else
l = 0;
name[l] = '\0';
}
}
{
char *d, *s;
s = d = name;
#ifdef HAVE_UNC_PATHS
/* 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
*
* MODIFIED FOR HAVE_DRIVE_LETTERS and NETWARE environments,
* so that if n == 0, "/" is returned in d with n == 1
* and s == "e:/test.html", "e:/" is returned in d
* *** See also directory_walk in modules/http/http_request.c
* examples:
* /a/b, 0 ==> / (true for all platforms)
* /a/b, 1 ==> /
* /a/b, 2 ==> /a/
* /a/b, 3 ==> /a/b/
* /a/b, 4 ==> /a/b/
*
* c:/a/b 0 ==> /
* c:/a/b 1 ==> c:/
* c:/a/b 2 ==> c:/a/
* c:/a/b 3 ==> c:/a/b
* c:/a/b 4 ==> c:/a/b
*/
AP_DECLARE(char *) ap_make_dirstr_prefix(char *d, const char *s, int n)
{
if (n < 1) {
*d = '/';
*++d = '\0';
return (d);
}
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) {
return apr_pstrdup(p, "");
}
l = (last_slash - s) + 1;
d = apr_pstrmemdup(p, s, l);
return (d);
}
{
register int x, n;
for (x = 0, n = 0; path[x]; x++)
if (path[x] == '/')
n++;
return n;
}
{
}
{
int len;
char *res;
++pos;
}
if (stop) {
++pos;
}
}
return res;
}
{
}
{
int len;
char *res;
++pos;
}
while (apr_isspace(*pos)) {
++pos;
}
return res;
}
char stop)
{
}
char stop)
{
char *res;
if (!pos) {
return res;
}
++pos;
return res;
}
/* Get a word, (new) config-file style --- quoted strings and backslashes
* all honored
*/
char quote)
{
int i;
for (i = 0; i < len; ++i) {
else
}
*resp++ = '\0';
return (char *)ap_resolve_env(p,result);
#else
return result;
#endif
}
{
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
}
/* we can't use apr_file_* directly because of linking issues on Windows */
{
return apr_file_close(param);
}
{
}
{
}
/* Open a ap_configfile_t as FILE, return open ap_configfile_t struct pointer */
apr_pool_t *p, const char *name)
{
#ifdef DEBUG
char buf[120];
#endif
"Internal error: pcfg_openfile() called with NULL filename");
return APR_EBADF;
}
APR_OS_DEFAULT, p);
#ifdef DEBUG
"Opening config file %s (%s)",
#endif
if (status != APR_SUCCESS)
return status;
if (status != APR_SUCCESS)
return status;
#else
#endif /* WIN32 || OS2 */
"Access to file %s denied by server: not a regular file",
name);
return APR_EBADF;
}
#ifdef WIN32
/* Some twisted character [no pun intended] at MS decided that a
* zero width joiner as the lead wide character would be ideal for
* describing Unicode text files. This was further convoluted to
* another MSism that the same character mapped into utf-8, EF BB BF
* would signify utf-8 text files.
*
* Since MS configuration files are all protecting utf-8 encoded
* Unicode path, file and resource names, we already have the correct
* WinNT encoding. But at least eat the stupid three bytes up front.
*/
{
unsigned char buf[4];
}
}
#endif
new_cfg->line_number = 0;
return APR_SUCCESS;
}
/* Allocate a ap_configfile_t handle with user defined functions and params */
{
new_cfg->line_number = 0;
return new_cfg;
}
/* Read one character from a configfile_t */
{
++cfp->line_number;
return rc;
}
{
char buf[MAX_STRING_LEN];
if (rc == APR_SUCCESS)
return NULL;
return apr_psprintf(p, "Error reading %s at line %d: %s",
}
/* Read one line from open ap_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;
*cbuf = '\0';
break;
}
else {
return APR_EOF;
}
}
if (rc != APR_SUCCESS) {
return rc;
}
/*
* check for line continuation,
* i.e. match [^\\]\\[\r]\n only
*/
cp--;
cp--;
cp--;
/*
* line continuation requested -
* then remove backslash and continue
*/
continue;
}
}
return APR_ENOSPC;
}
break;
}
} else {
/* No "get string" function defined; read character by character */
size_t i = 0;
if (bufsize < 2) {
/* too small, assume caller is crazy */
return APR_EINVAL;
}
buf[0] = '\0';
while (1) {
char c;
if (i > 0)
break;
else
return APR_EOF;
}
if (rc != APR_SUCCESS)
return rc;
if (c == LF) {
++cfp->line_number;
/* check for line continuation */
i--;
continue;
}
else {
break;
}
}
else if (i >= bufsize - 2) {
return APR_ENOSPC;
}
buf[i] = c;
++i;
}
buf[i] = '\0';
}
return APR_SUCCESS;
}
static int cfg_trim_line(char *buf)
{
/*
* Leading and trailing white space is eliminated completely
*/
while (apr_isspace(*start))
++start;
/* blast trailing whitespace */
*end = '\0';
/* Zap leading whitespace by shifting */
#ifdef DEBUG_CFG_LINES
#endif
}
/* Read one line from open ap_configfile_t, strip LF, increase line number */
/* If custom handler does not define a getstr() function, read char by char */
{
if (rc == APR_SUCCESS)
return rc;
}
{
for (;;) {
if (rc != APR_ENOSPC)
break;
return APR_ENOSPC;
--cfp->line_number;
}
if (rc == APR_SUCCESS)
return rc;
}
/* 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++ = ' ';
: apr_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 char *tok)
{
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.
*/
int accept_white)
{
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;
}
s - start_token)) {
return 1;
}
if (!*s) {
return 0;
}
}
}
const char *tok)
{
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) {
/*
* Convert them to spaces since they are effectively white
* space to most applications
*/
if (*s == '\r' || *s == '\n') {
*d++ = ' ';
continue;
}
#endif
if (TEST_CHAR(*s, T_ESCAPE_SHELL_CMD)) {
*d++ = '\\';
}
*d++ = *s;
}
*d = '\0';
return cmd;
}
{
register char digit;
#if !APR_CHARSET_EBCDIC
: (what[0] - '0'));
digit *= 16;
#else /*APR_CHARSET_EBCDIC*/
char xstr[5];
xstr[0]='0';
#endif /*APR_CHARSET_EBCDIC*/
return (digit);
}
/*
* Unescapes a URL, leaving reserved characters intact.
* Returns 0 on success, non-zero on error
* Failure is due to
* bad % escape returns HTTP_BAD_REQUEST
*
* decoding %00 or a forbidden character returns HTTP_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 {
char decoded;
if ((decoded == '\0')
badpath = 1;
*x = decoded;
y += 2;
}
*x++ = *y++;
*x++ = *y++;
*x = *y;
}
else {
*x = decoded;
y += 2;
}
}
}
}
*x = '\0';
if (badesc) {
return HTTP_BAD_REQUEST;
}
else if (badpath) {
return HTTP_NOT_FOUND;
}
else {
return OK;
}
}
{
/* Traditional */
}
{
/* AllowEncodedSlashes (corrected) */
if (decode_slashes) {
/* no chars reserved */
} else {
/* reserve (do not decode) encoded slashes */
}
}
#ifdef NEW_APIS
/* IFDEF these out until they've been thought through.
* Just a germ of an API extension for now
*/
{
/* leave RFC1738 reserved characters intact, * so proxied URLs
* don't get mangled. Where does that leave encoded '&' ?
*/
}
{
}
#endif
{
if (ap_is_default_port(port, r)) {
return apr_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) first 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";
unsigned char *where)
{
#endif /*APR_CHARSET_EBCDIC*/
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;
else if (s[i] == '"')
j += 5;
else if (toasc && !apr_isascii(s[i]))
j += 5;
if (j == 0)
return apr_pstrmemdup(p, s, i);
x = apr_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 if (s[i] == '"') {
j += 5;
}
else if (toasc && !apr_isascii(s[i])) {
j += 5;
}
else
x[j] = s[i];
x[j] = '\0';
return x;
}
{
char *ret;
unsigned char *d;
const unsigned char *s;
if (!str) {
return NULL;
}
d = (unsigned char *)ret;
s = (const unsigned char *)str;
for (; *s; ++s) {
if (TEST_CHAR(*s, T_ESCAPE_LOGITEM)) {
*d++ = '\\';
switch(*s) {
case '\b':
*d++ = 'b';
break;
case '\n':
*d++ = 'n';
break;
case '\r':
*d++ = 'r';
break;
case '\t':
*d++ = 't';
break;
case '\v':
*d++ = 'v';
break;
case '\\':
case '"':
*d++ = *s;
break;
default:
c2x(*s, 'x', d);
d += 3;
}
}
else {
*d++ = *s;
}
}
*d = '\0';
return ret;
}
{
unsigned char *d, *ep;
const unsigned char *s;
return 0;
}
d = (unsigned char *)dest;
s = (const unsigned char *)source;
for (; d < ep && *s; ++s) {
if (TEST_CHAR(*s, T_ESCAPE_LOGITEM)) {
*d++ = '\\';
if (d >= ep) {
--d;
break;
}
switch(*s) {
case '\b':
*d++ = 'b';
break;
case '\n':
*d++ = 'n';
break;
case '\r':
*d++ = 'r';
break;
case '\t':
*d++ = 't';
break;
case '\v':
*d++ = 'v';
break;
case '\\':
*d++ = *s;
break;
case '"': /* no need for this in error log */
d[-1] = *s;
break;
default:
if (d >= ep - 2) {
ep = --d; /* break the for loop as well */
break;
}
c2x(*s, 'x', d);
d += 3;
}
}
else {
*d++ = *s;
}
}
*d = '\0';
return (d - (unsigned char *)dest);
}
{
return 0; /* in error condition, just return no */
}
{
return 0; /* in error condition, just return no */
}
const char *src2)
{
char *path;
/* allocate +3 for '/' delimiter, trailing NULL and overallocate
* one extra byte to allow the caller to add a trailing '/'
*/
if (len1 == 0) {
*path = '/';
}
else {
char *next;
*next++ = '/';
}
}
return path;
}
/*
* Check for an absoluteURI syntax (see section 3.2 in RFC2068).
*/
AP_DECLARE(int) ap_is_url(const char *u)
{
register int x;
for (x = 0; u[x] != ':'; x++) {
if ((!u[x]) ||
((!apr_isalpha(u[x])) && (!apr_isdigit(u[x])) &&
(u[x] != '+') && (u[x] != '-') && (u[x] != '.'))) {
return 0;
}
}
return (x ? 1 : 0); /* If the first character is ':', it's broken, too */
}
AP_DECLARE(int) ap_ind(const char *s, char c)
{
const char *p = ap_strchr_c(s, c);
if (p == NULL)
return -1;
return p - s;
}
AP_DECLARE(int) ap_rind(const char *s, char c)
{
const char *p = ap_strrchr_c(s, c);
if (p == NULL)
return -1;
return p - s;
}
{
while (*str) {
++str;
}
}
{
while (*str) {
++str;
}
}
/*
* We must return a FQDN
*/
char *ap_get_local_host(apr_pool_t *a)
{
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif
char *server_hostname = NULL;
char *hostname;
"%s: apr_gethostname() failed to determine ServerName",
} else {
return server_hostname;
} else {
}
} else {
"%s: apr_sockaddr_info_get() failed for %s",
}
}
if (!server_hostname)
"%s: Could not reliably determine the server's fully qualified "
"domain name, using %s. Set the 'ServerName' directive globally "
"to suppress this message",
return server_hostname;
}
/* simple 'pool' alloc()ing glue to apr_base64.c
*/
{
char *decoded;
int l;
return decoded;
}
{
char *encoded;
return encoded;
}
* 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';
}
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;
}
/*
* Given a string, append the PID deliminated by delim.
* Usually used to create a pid-appended filepath name
* a macro, to avoid unistd.h dependency
*/
const char *delim)
{
}
/**
* Parse a given timeout parameter string into an apr_interval_time_t value.
* The unit of the time interval is given as postfix string to the numeric
* string. Currently the following units are understood:
*
* ms : milliseconds
* s : seconds
* mi[n] : minutes
* h : hours
*
* If no unit is contained in the given timeout parameter the default_time_unit
* will be used instead.
* @param timeout_parameter The string containing the timeout parameter.
* @param timeout The timeout value to be returned.
* @param default_time_unit The default time unit to use if none is specified
* in timeout_parameter.
* @return Status value indicating whether the parsing was successful or not.
*/
const char *timeout_parameter,
const char *default_time_unit)
{
char *endp;
const char *time_str;
if (errno) {
return errno;
}
}
else {
}
switch (*time_str) {
/* Time is in seconds */
case 's':
break;
case 'h':
/* Time is in hours */
break;
case 'm':
switch (*(++time_str)) {
/* Time is in milliseconds */
case 's':
break;
/* Time is in minutes */
case 'i':
break;
default:
return APR_EGENERAL;
}
break;
default:
return APR_EGENERAL;
}
return APR_SUCCESS;
}
/**
* Determine if a request has a request body or not.
*
* @param r the request_rec of the request
* @return truth value
*/
{
char *estr;
const char *cls;
int has_body;
has_body = (!r->header_only
&& (r->kept_body
&& (!*estr)
&& (cl > 0) )
)
);
return has_body;
}
{
return APR_SUCCESS;
}
{
if (!apr_isprint(*src))
*dest = 'x';
else if (!apr_isalnum(*src))
*dest = '_';
else
}
*dest = '\0';
return APR_SUCCESS;
}
const char **dest)
{
if (!new)
return APR_ENOMEM;
}
/**
* Read the body and parse any form found, which must be of the
* type application/x-www-form-urlencoded.
*
* strings with a maximum length of HUGE_STRING_LEN, and the
* values as bucket brigades. This allows values to be arbitrarily
* large.
*
* All url-encoding is removed from both the names and the values
* on the fly. The names are interpreted as strings, while the
* values are interpreted as blocks of binary data, that may
* contain the 0 character.
*
* In order to ensure that resource limits are not exceeded, a
* maximum size must be provided. If the sum of the lengths of
* the names and the values exceed this size, this function
* will return HTTP_REQUEST_ENTITY_TOO_LARGE.
*
* An optional number of parameters can be provided, if the number
* of parameters provided exceeds this amount, this function will
* return HTTP_REQUEST_ENTITY_TOO_LARGE. If this value is negative,
* no limit is imposed, and the number of parameters is in turn
* constrained by the size parameter above.
*
* This function honours any kept_body configuration, and the
* original raw request body will be saved to the kept_body brigade
* if so configured, just as ap_discard_request_body does.
*
* NOTE: File upload is not yet supported, but can be without change
* to the function call.
*/
/* form parsing stuff */
typedef enum {
{
int seen_eos = 0;
const char *ct;
apr_size_t offset = 0;
char hi = 0;
char low = 0;
/* sanity check - we only support forms for now */
return ap_discard_request_body(r);
}
else
if (!f) {
f = r->input_filters;
}
do {
if (rv != APR_SUCCESS) {
}
const char *data;
if (last) {
}
if (APR_BUCKET_IS_EOS(bucket)) {
seen_eos = 1;
break;
}
continue;
}
if (rv != APR_SUCCESS) {
return HTTP_BAD_REQUEST;
}
char c = *data++;
if ('+' == c) {
c = ' ';
}
else if ('&' == c) {
}
if ('%' == c) {
continue;
}
if (FORM_PERCENTA == percent) {
if (c >= 'a') {
}
else if (c >= 'A') {
}
else if (c >= '0') {
hi = c - '0';
}
continue;
}
if (FORM_PERCENTB == percent) {
if (c >= 'a') {
}
else if (c >= 'A') {
}
else if (c >= '0') {
low = c - '0';
}
}
switch (state) {
case FORM_AMP:
if (pair) {
}
offset = 0;
num--;
break;
case FORM_NAME:
if (offset < HUGE_STRING_LEN) {
if ('=' == c) {
offset = 0;
state = FORM_VALUE;
}
else {
size--;
}
}
else {
state = FORM_ABORT;
}
break;
case FORM_VALUE:
if (offset >= HUGE_STRING_LEN) {
offset = 0;
}
size--;
break;
default:
break;
}
}
}
} while (!seen_eos);
return HTTP_REQUEST_ENTITY_TOO_LARGE;
}
}
return OK;
}
#define VARBUF_SMALL_SIZE 2048
APR_ALIGN_DEFAULT(sizeof(struct ap_varbuf_info)))
struct ap_varbuf_info {
struct apr_memnode_t *node;
};
{
return APR_SUCCESS;
}
{
}
{
struct ap_varbuf_info *new_info;
char *new;
return;
/* at least double the size, to avoid repeated reallocations */
}
else if (new_len > VARBUF_MAX_SIZE) {
return;
}
new_len++; /* add space for trailing \0 */
if (new_len <= VARBUF_SMALL_SIZE) {
/* We are lucky: the new memory lies directly after our old
* buffer, we can now use both.
*/
return;
}
else {
/* copy up to vb->strlen + 1 bytes */
}
}
else {
*new = '\0';
}
return;
}
/* The required block is rather larger. Use allocator directly so that
* the memory can be freed independently from the pool. */
if (new_len <= VARBUF_MAX_SIZE)
if (!new_node) {
return;
}
else
*new = '\0';
}
int len)
{
return;
}
}
}
{
}
}
#define OOM_MESSAGE "[crit] Memory allocation failed, " \
"aborting process." APR_EOL_STR
AP_DECLARE(void) ap_abort_on_oom()
{
abort();
}
{
return p;
}
{
return p;
}
{
return p;
}