util.c revision 8a116e033795dd83754b68dfc970a524ea4a5779
4ef32fc8ca017f80aa0d8ff267722a335c9d7784nd/* Licensed to the Apache Software Foundation (ASF) under one or more
d8a47f7a3f857a43664484552cf83bf170e4629dnd * contributor license agreements. See the NOTICE file distributed with
4ef32fc8ca017f80aa0d8ff267722a335c9d7784nd * this work for additional information regarding copyright ownership.
641746f1699ae2f01e3ad9dee32f71a5b7dca344rbowen * The ASF licenses this file to You under the Apache License, Version 2.0
4ef32fc8ca017f80aa0d8ff267722a335c9d7784nd * (the "License"); you may not use this file except in compliance with
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd * the License. You may obtain a copy of the License at
031b91a62d25106ae69d4693475c79618dd5e884fielding * Unless required by applicable law or agreed to in writing, software
031b91a62d25106ae69d4693475c79618dd5e884fielding * distributed under the License is distributed on an "AS IS" BASIS,
031b91a62d25106ae69d4693475c79618dd5e884fielding * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd * See the License for the specific language governing permissions and
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd * limitations under the License.
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd * util.c: string utility things
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd * 3/21/93 Rob McCool
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd * 1995-96 Many changes by the Apache Software Foundation
4ef32fc8ca017f80aa0d8ff267722a335c9d7784nd/* Debugging aid:
4ef32fc8ca017f80aa0d8ff267722a335c9d7784nd * #define DEBUG to trace all cfg_open*()/cfg_closefile() calls
4ef32fc8ca017f80aa0d8ff267722a335c9d7784nd * #define DEBUG_CFG_LINES to trace every line read from the config files
#include <unistd.h>
#if APR_HAVE_NETDB_H
#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>
#ifdef HAVE_GRP_H
#include <grp.h>
#include "ap_mpm.h"
/* A bunch of functions in util.c scan strings looking for certain characters.
* is generated automatically by gen_test_char.c.
#include "test_char.h"
#ifdef CASE_BLIND_FILESYSTEM
* Examine a field value (such as a media-/content-type) string and return
const char *semi;
semi--;
int gmt)
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; expected[y]; ++y, ++x) {
if (!expected[y])
while (str[x]) {
int ret;
return ret;
for (x = 0, y = 0; expected[y]; ++y, ++x) {
if (!expected[y])
while (str[x]) {
int ret;
return ret;
const char *newpath;
for (x = 0; str[x]; x++)
return APR_SUCCESS;
int cflags)
if (err) {
return NULL;
return preg;
return((char *)s1);
return(NULL);
return((char *)s1);
s1++;
return((char *)s1);
const char *prefix)
const char *p1;
return bigstring;
return bigstring;
return p1;
return bigstring;
char *dst;
return APR_EINVAL;
if (!nmatch) {
return APR_ENOMEM;
if (!vb) {
return APR_SUCCESS;
return APR_SUCCESS;
src++;
len++;
return APR_ENOMEM;
return APR_ENOMEM;
if (!vb) {
c = *src++;
*dst++ = c;
return APR_SUCCESS;
#ifndef AP_PREGSUB_MAXLEN
char *result;
return result;
return rc;
char *next;
int l, w, first_dot;
l = first_dot;
s = d = name;
#ifdef HAVE_UNC_PATHS
* and s == "e:/test.html", "e:/" is returned in d
* *** See also directory_walk in modules/http/http_request.c
d = apr_pstrmemdup(p, s, l);
for (x = 0, n = 0; path[x]; x++)
int len;
char *res;
++pos;
if (stop) {
++pos;
return res;
int len;
char *res;
++pos;
++pos;
return res;
char stop)
char stop)
char *res;
if (!pos) {
return res;
++pos;
return res;
char quote)
for (i = 0; i < len; ++i) {
return result;
char *res;
char quote;
++str;
if (!*str) {
++strend;
++strend;
++strend;
++strend;
return res;
#ifdef DEBUG
#ifdef DEBUG
return APR_EBADF;
APR_OS_DEFAULT, p);
#ifdef DEBUG
return status;
return status;
name);
return APR_EBADF;
#ifdef WIN32
return APR_SUCCESS;
return new_cfg;
return rc;
return NULL;
char *cp;
return APR_EOF;
return rc;
cp--;
cp--;
cp--;
return APR_ENOSPC;
apr_size_t i = 0;
return APR_EINVAL;
return APR_EOF;
return rc;
if (c == LF) {
return APR_ENOSPC;
buf[i] = c;
return APR_SUCCESS;
++start;
#ifdef DEBUG_CFG_LINES
return rc;
return APR_ENOSPC;
return APR_ENOSPC;
return rc;
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 char *tok)
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;
int accept_white)
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;
s - start_token)) {
const char *tok)
if (!line)
if (lidx < 0 ||
char *cmd;
d = (unsigned char *)cmd;
s = (const unsigned char *)str;
return cmd;
register char digit;
#if !APR_CHARSET_EBCDIC
return (digit);
badesc = 0;
badpath = 0;
if (y == NULL) {
return OK;
char decoded;
*x = decoded;
*x = decoded;
if (badesc) {
return HTTP_BAD_REQUEST;
else if (badpath) {
return HTTP_NOT_FOUND;
return OK;
if (decode_slashes) {
#ifdef NEW_APIS
char *slider;
if (query) {
unsigned char *where)
return where;
const unsigned char *s = (const unsigned char *)segment;
unsigned char *d = (unsigned char *)copy;
return copy;
const unsigned char *s = (const unsigned char *)path;
unsigned char *d = (unsigned char *)copy;
if (!partial) {
return copy;
const unsigned char *s = (const unsigned char *)buffer;
unsigned char *d = (unsigned char *)copy;
return copy;
return apr_pstrmemdup(p, s, i);
char *ret;
if (!str) {
return NULL;
d = (unsigned char *)ret;
s = (const unsigned char *)str;
return ret;
unsigned char *d, *ep;
d = (unsigned char *)dest;
s = (const unsigned char *)source;
for (; d < ep && *s; ++s) {
if (d >= ep) {
return (d - (unsigned char *)dest);
const char *src2)
char *path;
if (len1 == 0) {
char *next;
return path;
const char *p = ap_strchr_c(s, c);
if (p == NULL)
const char *p = ap_strrchr_c(s, c);
if (p == NULL)
while (*str) {
++str;
while (*str) {
++str;
#ifndef MAXHOSTNAMELEN
char *hostname;
return server_hostname;
if (!server_hostname)
return server_hostname;
/* simple 'pool' alloc()ing glue to apr_base64.c
char *decoded;
return decoded;
char *encoded;
return encoded;
char *semi;
if (semi) {
if (semi) {
int newlen = 0;
newlen++;
newlen++;
inchr++;
newlen++;
inchr++;
return outstring;
* a macro, to avoid unistd.h dependency
const char *delim)
const char *timeout_parameter,
const char *default_time_unit)
char *endp;
const char *time_str;
if (errno) {
return errno;
switch (*time_str) {
switch (*(++time_str)) {
return APR_EGENERAL;
return APR_EGENERAL;
return APR_SUCCESS;
char *estr;
const char *cls;
int has_body;
&& (r->kept_body
&& (!*estr)
&& (cl > 0) )
return has_body;
return APR_SUCCESS;
return APR_SUCCESS;
const char **dest)
if (!new)
return APR_ENOMEM;
* type application/x-www-form-urlencoded.
int seen_eos = 0;
const char *ct;
char hi = 0;
char low = 0;
return ap_discard_request_body(r);
f = r->input_filters;
const char *data;
if (last) {
return HTTP_BAD_REQUEST;
char c = *data++;
switch (state) {
case FORM_AMP:
if (pair) {
offset = 0;
num--;
case FORM_NAME:
offset = 0;
size--;
case FORM_VALUE:
offset = 0;
size--;
} while (!seen_eos);
return HTTP_REQUEST_ENTITY_TOO_LARGE;
return OK;
struct ap_varbuf_info {
return APR_SUCCESS;
char *new;
if (!new_node) {
int len)
if (len == 0)
apr_size_t i = 0;
if (prepend) {
if (append) {
if (new_len)
*new_len = 0;
const char *input,
const char *source,
if (written > 0) {
abort();
int ready = 0;
int busy = 0;
int total;
for (i = 0; i < server_limit; i++) {
for (j = 0; j < thread_limit; j++) {
int res;
ready++;
busy++;
if (total) {
#if HAVE_GETLOADAVG
int num;
if (num > 0) {