* [Indent] Ran Source Through indent

I re-indented the source code using indent with the following options:

indent -kr -bad -bap -nut -i8 -l80 -psl -sob -ss -ncs

There are now _no_ tabs in the source files, and all indentation is
eight spaces.  Lines are 80 characters long, and the procedure type is
on it's own line.  Read the indent manual for more information about
what each option means.
This commit is contained in:
Robert James Kaes 2005-08-15 03:54:31 +00:00
parent 38f0b3a103
commit c0299e1868
41 changed files with 4064 additions and 3850 deletions

View File

@ -1,4 +1,4 @@
/* $Id: acl.c,v 1.21 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: acl.c,v 1.22 2005-08-15 03:54:31 rjkaes Exp $
*
* This system handles Access Control for use of this daemon. A list of
* domains, or IP addresses (including IP blocks) are stored in a list
@ -119,7 +119,8 @@ insert_acl(char *location, acl_access_t access_type)
if (mask >= ((i + 1) * 8))
acl.address.ip.mask[i] = 0xff;
else
acl.address.ip.mask[i] = 0xff << (8 - (mask - i * 8));
acl.address.ip.mask[i] =
0xff << (8 - (mask - i * 8));
}
} else {
/* In all likelihood a string */
@ -138,7 +139,6 @@ insert_acl(char *location, acl_access_t access_type)
return ret;
}
/*
* This function is called whenever a "string" access control is found in
* the ACL. From here we do both a text based string comparison, along with
@ -150,8 +150,7 @@ insert_acl(char *location, acl_access_t access_type)
*/
static int
acl_string_processing(struct acl_s *acl,
const char* ip_address,
const char* string_address)
const char *ip_address, const char *string_address)
{
int match;
struct addrinfo hints, *res, *ressave;
@ -206,7 +205,9 @@ STRING_TEST:
if (test_length < match_length)
return -1;
if (strcasecmp(string_address + (test_length - match_length), acl->address.string) == 0) {
if (strcasecmp
(string_address + (test_length - match_length),
acl->address.string) == 0) {
if (acl->access == ACL_DENY)
return 0;
else
@ -234,7 +235,8 @@ check_numeric_acl(const struct acl_s* acl, const char* ip)
assert(acl && acl->type == ACL_NUMERIC);
assert(ip && strlen(ip) > 0);
if (full_inet_pton(ip, &addr) <= 0) return -1;
if (full_inet_pton(ip, &addr) <= 0)
return -1;
for (i = 0; i != IPV6_LEN; ++i) {
x = addr[i] & acl->address.ip.mask[i];
@ -249,7 +251,6 @@ check_numeric_acl(const struct acl_s* acl, const char* ip)
return (acl->access == ACL_ALLOW);
}
/*
* Checks whether file descriptor is allowed.
*
@ -271,7 +272,8 @@ check_acl(int fd, const char* ip, const char* host)
/*
* If there is no access list allow everything.
*/
if (!access_list) return 1;
if (!access_list)
return 1;
for (i = 0; i != vector_length(access_list); ++i) {
acl = vector_getentry(access_list, i, NULL);
@ -281,7 +283,8 @@ check_acl(int fd, const char* ip, const char* host)
break;
case ACL_NUMERIC:
if (ip[0] == '\0') continue;
if (ip[0] == '\0')
continue;
perm = check_numeric_acl(acl, ip);
break;
}

View File

@ -1,4 +1,4 @@
/* $Id: acl.h,v 1.4 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: acl.h,v 1.5 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'acl.c' for detailed information.
*
@ -21,6 +21,7 @@
typedef enum { ACL_ALLOW, ACL_DENY } acl_access_t;
extern int insert_acl(char *location, acl_access_t access_type);
extern int check_acl(int fd, const char* ip_address, const char* string_address);
extern int check_acl(int fd, const char *ip_address,
const char *string_address);
#endif

View File

@ -1,4 +1,4 @@
/* $Id: anonymous.c,v 1.15 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: anonymous.c,v 1.16 2005-08-15 03:54:31 rjkaes Exp $
*
* Handles insertion and searches for headers which should be let through when
* the anonymous feature is turned on.

View File

@ -1,4 +1,4 @@
/* $Id: buffer.c,v 1.24 2004-02-13 21:27:42 rjkaes Exp $
/* $Id: buffer.c,v 1.25 2005-08-15 03:54:31 rjkaes Exp $
*
* The buffer used in each connection is a linked list of lines. As the lines
* are read in and written out the buffer expands and contracts. Basically,
@ -140,7 +140,8 @@ delete_buffer(struct buffer_s *buffptr)
/*
* Return the current size of the buffer.
*/
size_t buffer_size(struct buffer_s *buffptr)
size_t
buffer_size(struct buffer_s *buffptr)
{
return buffptr->size;
}
@ -279,7 +280,8 @@ write_buffer(int fd, struct buffer_s * buffptr)
line = BUFFER_HEAD(buffptr);
bytessent =
send(fd, line->string + line->pos, line->length - line->pos, MSG_NOSIGNAL);
send(fd, line->string + line->pos, line->length - line->pos,
MSG_NOSIGNAL);
if (bytessent >= 0) {
/* bytes sent, adjust buffer */

View File

@ -1,4 +1,4 @@
/* $Id: buffer.h,v 1.9 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: buffer.h,v 1.10 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'buffer.c' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: child.c,v 1.17 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: child.c,v 1.18 2005-08-15 03:54:31 rjkaes Exp $
*
* Handles the creation/destruction of the various children required for
* processing incoming connections.
@ -189,9 +189,11 @@ child_main(struct child_s* ptr)
if (getenv("TINYPROXY_DEBUG")) {
/* Pause for 10 seconds to allow us to connect debugger */
fprintf(stderr,
"Process has accepted connection: %ld\n", (long int)ptr->tid);
"Process has accepted connection: %ld\n",
(long int)ptr->tid);
sleep(10);
fprintf(stderr, "Continuing process: %ld\n", (long int)ptr->tid);
fprintf(stderr, "Continuing process: %ld\n",
(long int)ptr->tid);
}
#endif
@ -199,7 +201,9 @@ child_main(struct child_s* ptr)
* Make sure no error occurred...
*/
if (connfd < 0) {
log_message(LOG_ERR, "Accept returned an error (%s) ... retrying.", strerror(errno));
log_message(LOG_ERR,
"Accept returned an error (%s) ... retrying.",
strerror(errno));
continue;
}
@ -229,7 +233,8 @@ child_main(struct child_s* ptr)
*/
log_message(LOG_NOTICE,
"Waiting servers (%d) exceeds MaxSpareServers (%d). Killing child.",
*servers_waiting, child_config.maxspareservers);
*servers_waiting,
child_config.maxspareservers);
SERVER_COUNT_UNLOCK();
break;
@ -302,7 +307,8 @@ child_pool_create(void)
servers_waiting = malloc_shared_memory(sizeof(unsigned int));
if (servers_waiting == MAP_FAILED) {
log_message(LOG_ERR, "Could not allocate memory for child counting.");
log_message(LOG_ERR,
"Could not allocate memory for child counting.");
return -1;
}
*servers_waiting = 0;
@ -326,7 +332,8 @@ child_pool_create(void)
}
for (i = 0; i != child_config.startservers; i++) {
DEBUG2("Trying to create child %d of %d", i + 1, child_config.startservers);
DEBUG2("Trying to create child %d of %d", i + 1,
child_config.startservers);
child_ptr[i].status = T_WAITING;
child_ptr[i].tid = child_make(&child_ptr[i]);
@ -367,14 +374,16 @@ child_main_loop(void)
if (*servers_waiting < child_config.minspareservers) {
log_message(LOG_NOTICE,
"Waiting servers (%d) is less than MinSpareServers (%d). Creating new child.",
*servers_waiting, child_config.minspareservers);
*servers_waiting,
child_config.minspareservers);
SERVER_COUNT_UNLOCK();
for (i = 0; i != child_config.maxclients; i++) {
if (child_ptr[i].status == T_EMPTY) {
child_ptr[i].status = T_WAITING;
child_ptr[i].tid = child_make(&child_ptr[i]);
child_ptr[i].tid =
child_make(&child_ptr[i]);
if (child_ptr[i].tid < 0) {
log_message(LOG_NOTICE,
"Could not create child");

View File

@ -1,4 +1,4 @@
/* $Id: child.h,v 1.3 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: child.h,v 1.4 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'child.c' for more information.
*

View File

@ -1,4 +1,4 @@
/* $Id: common.h,v 1.8 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: common.h,v 1.9 2005-08-15 03:54:31 rjkaes Exp $
*
* This file groups all the headers required throughout the tinyproxy
* system. All this information use to be in the "tinyproxy.h" header,

View File

@ -1,4 +1,4 @@
/* $Id: conffile.c,v 1.4 2004-08-24 16:34:22 rjkaes Exp $
/* $Id: conffile.c,v 1.5 2005-08-15 03:54:31 rjkaes Exp $
*
* Parses the configuration file and sets up the config_s structure for
* use by the application. This file replaces the old grammar.y and
@ -57,7 +57,6 @@
*/
#define RE_MAX_MATCHES 16
/*
* All configuration handling functions are REQUIRED to be defined
* with the same function template as below.
@ -77,12 +76,16 @@ typedef int (*CONFFILE_HANDLER)(struct config_s*, const char*, regmatch_t[]);
*/
#define HANDLE_FUNC(func) int func(struct config_s* conf, const char* line, regmatch_t match[])
/*
* List all the handling functions. These are defined later, but they need
* to be in-scope before the big structure below.
*/
static HANDLE_FUNC(handle_nop) { return 0; } /* do nothing function */
static
HANDLE_FUNC(handle_nop)
{
return 0;
} /* do nothing function */
static HANDLE_FUNC(handle_allow);
static HANDLE_FUNC(handle_anonymous);
static HANDLE_FUNC(handle_bind);
@ -115,12 +118,12 @@ static HANDLE_FUNC(handle_statfile);
static HANDLE_FUNC(handle_stathost);
static HANDLE_FUNC(handle_syslog);
static HANDLE_FUNC(handle_timeout);
//static HANDLE_FUNC(handle_upstream);
static HANDLE_FUNC(handle_user);
static HANDLE_FUNC(handle_viaproxyname);
static HANDLE_FUNC(handle_xtinyproxy);
/*
* This macro can be used to make standard directives in the form:
* directive arguments [arguments ...]
@ -134,7 +137,6 @@ static HANDLE_FUNC(handle_xtinyproxy);
*/
#define STDCONF(d, re, func) { BEGIN "(" d ")" WS re END, func, NULL }
/*
* Holds the regular expression used to match the configuration directive,
* the function pointer to the routine to handle the directive, and
@ -147,11 +149,11 @@ struct {
regex_t *cre;
} directives[] = {
/* comments */
{ BEGIN "#", handle_nop },
{
BEGIN "#", handle_nop},
/* blank lines */
{ "^[[:space:]]+$", handle_nop },
{
"^[[:space:]]+$", handle_nop},
/* string arguments */
STDCONF("logfile", STR, handle_logfile),
STDCONF("pidfile", STR, handle_pidfile),
@ -161,11 +163,9 @@ struct {
STDCONF("statfile", STR, handle_statfile),
STDCONF("stathost", STR, handle_stathost),
STDCONF("xtinyproxy", STR, handle_xtinyproxy),
/* boolean arguments */
STDCONF("syslog", BOOL, handle_syslog),
STDCONF("bindsame", BOOL, handle_bindsame),
/* integer arguments */
STDCONF("port", INT, handle_port),
STDCONF("maxclients", INT, handle_maxclients),
@ -175,39 +175,33 @@ struct {
STDCONF("maxrequestsperchild", INT, handle_maxrequestsperchild),
STDCONF("timeout", INT, handle_timeout),
STDCONF("connectport", INT, handle_connectport),
/* alphanumeric arguments */
STDCONF("user", ALNUM, handle_user),
STDCONF("group", ALNUM, handle_group),
/* ip arguments */
STDCONF("listen", IP, handle_listen),
STDCONF("allow", "(" IPMASK "|" ALNUM ")", handle_allow),
STDCONF("deny", "(" IPMASK "|" ALNUM ")", handle_deny),
STDCONF("bind", IP, handle_bind),
/* error files */
STDCONF("errorfile", INT WS STR, handle_errorfile),
/* filtering */
STDCONF("filter", STR, handle_filter),
STDCONF("filterurls", BOOL, handle_filterurls),
STDCONF("filterextended", BOOL, handle_filterextended),
STDCONF("filterdefaultdeny", BOOL, handle_filterdefaultdeny),
STDCONF("filtercasesensitive", BOOL, handle_filtercasesensitive),
/* Reverse proxy arguments */
STDCONF("reversebaseurl", STR, handle_reversebaseurl),
STDCONF("reverseonly", BOOL, handle_reverseonly),
STDCONF("reversemagic", BOOL, handle_reversemagic),
STDCONF("reversepath", STR WS "(" STR ")?", handle_reversepath),
/* upstream is rather complicated */
// { BEGIN "no" WS "upstream" WS STR END, handle_no_upstream },
// { BEGIN "upstream" WS IP ":" INT "(" WS STR ")" END, handle_upstream },
/* loglevel */
STDCONF("loglevel", "(critical|error|warning|notice|connect|info)", handle_loglevel)
STDCONF("loglevel", "(critical|error|warning|notice|connect|info)",
handle_loglevel)
};
const unsigned int ndirectives = sizeof(directives) / sizeof(directives[0]);
@ -233,12 +227,12 @@ config_compile(void)
r = regcomp(directives[i].cre,
directives[i].re,
REG_EXTENDED | REG_ICASE | REG_NEWLINE);
if (r) return r;
if (r)
return r;
}
return 0;
}
/*
* Attempt to match the supplied line with any of the configuration
* regexes defined above. If a match is found, call the handler
@ -283,7 +277,6 @@ config_parse(struct config_s* conf, FILE* f)
return 0;
}
/***********************************************************************
*
* The following are basic data extraction building blocks that can
@ -313,6 +306,7 @@ static int
set_string_arg(char **var, const char *line, regmatch_t * match)
{
char *arg = get_string_arg(line, match);
if (!arg)
return -1;
*var = safestrdup(arg);
@ -365,7 +359,6 @@ set_int_arg(int long* var, const char* line, regmatch_t* match)
return 0;
}
/***********************************************************************
*
* Below are all the directive handling functions. You will notice
@ -384,17 +377,23 @@ set_int_arg(int long* var, const char* line, regmatch_t* match)
*
***********************************************************************/
static HANDLE_FUNC(handle_logfile)
static
HANDLE_FUNC(handle_logfile)
{
return set_string_arg(&conf->logf_name, line, &match[2]);
}
static HANDLE_FUNC(handle_pidfile)
static
HANDLE_FUNC(handle_pidfile)
{
return set_string_arg(&conf->pidpath, line, &match[2]);
}
static HANDLE_FUNC(handle_anonymous)
static
HANDLE_FUNC(handle_anonymous)
{
char *arg = get_string_arg(line, &match[2]);
if (!arg)
return -1;
@ -402,33 +401,44 @@ static HANDLE_FUNC(handle_anonymous)
safefree(arg);
return 0;
}
static HANDLE_FUNC(handle_viaproxyname)
static
HANDLE_FUNC(handle_viaproxyname)
{
int r = set_string_arg(&conf->via_proxy_name, line, &match[2]);
if (r) return r;
if (r)
return r;
log_message(LOG_INFO,
"Setting \"Via\" header proxy to %s",
conf->via_proxy_name);
"Setting \"Via\" header proxy to %s", conf->via_proxy_name);
return 0;
}
static HANDLE_FUNC(handle_defaulterrorfile)
static
HANDLE_FUNC(handle_defaulterrorfile)
{
return set_string_arg(&conf->errorpage_undef, line, &match[2]);
}
static HANDLE_FUNC(handle_statfile)
static
HANDLE_FUNC(handle_statfile)
{
return set_string_arg(&conf->statpage, line, &match[2]);
}
static HANDLE_FUNC(handle_stathost)
static
HANDLE_FUNC(handle_stathost)
{
int r = set_string_arg(&conf->stathost, line, &match[2]);
if (r) return r;
log_message(LOG_INFO,
"Stathost set to \"%s\"",
conf->stathost);
if (r)
return r;
log_message(LOG_INFO, "Stathost set to \"%s\"", conf->stathost);
return 0;
}
static HANDLE_FUNC(handle_xtinyproxy)
static
HANDLE_FUNC(handle_xtinyproxy)
{
#ifdef XTINYPROXY_ENABLE
return set_string_arg(&conf->my_domain, line, &match[2]);
@ -438,91 +448,126 @@ static HANDLE_FUNC(handle_xtinyproxy)
return 1;
#endif
}
static HANDLE_FUNC(handle_syslog)
static
HANDLE_FUNC(handle_syslog)
{
#ifdef HAVE_SYSLOG_H
return set_bool_arg(&conf->syslog, line, &match[2]);
#else
fprintf(stderr,
"Syslog support not compiled in executable.\n");
fprintf(stderr, "Syslog support not compiled in executable.\n");
return 1;
#endif
}
static HANDLE_FUNC(handle_bindsame)
static
HANDLE_FUNC(handle_bindsame)
{
int r = set_bool_arg(&conf->bindsame, line, &match[2]);
if (r) return r;
if (r)
return r;
log_message(LOG_INFO, "Binding outgoing connection to incoming IP");
return 0;
}
static HANDLE_FUNC(handle_port)
static
HANDLE_FUNC(handle_port)
{
return set_int_arg((long int *)&conf->port, line, &match[2]);
}
static HANDLE_FUNC(handle_maxclients)
static
HANDLE_FUNC(handle_maxclients)
{
child_configure(CHILD_MAXCLIENTS, get_int_arg(line, &match[2]));
return 0;
}
static HANDLE_FUNC(handle_maxspareservers)
static
HANDLE_FUNC(handle_maxspareservers)
{
child_configure(CHILD_MAXSPARESERVERS, get_int_arg(line, &match[2]));
return 0;
}
static HANDLE_FUNC(handle_minspareservers)
static
HANDLE_FUNC(handle_minspareservers)
{
child_configure(CHILD_MINSPARESERVERS, get_int_arg(line, &match[2]));
return 0;
}
static HANDLE_FUNC(handle_startservers)
static
HANDLE_FUNC(handle_startservers)
{
child_configure(CHILD_STARTSERVERS, get_int_arg(line, &match[2]));
return 0;
}
static HANDLE_FUNC(handle_maxrequestsperchild)
static
HANDLE_FUNC(handle_maxrequestsperchild)
{
child_configure(CHILD_MAXREQUESTSPERCHILD, get_int_arg(line, &match[2]));
child_configure(CHILD_MAXREQUESTSPERCHILD,
get_int_arg(line, &match[2]));
return 0;
}
static HANDLE_FUNC(handle_timeout)
static
HANDLE_FUNC(handle_timeout)
{
return set_int_arg((long int *)&conf->idletimeout, line, &match[2]);
}
static HANDLE_FUNC(handle_connectport)
static
HANDLE_FUNC(handle_connectport)
{
add_connect_port_allowed(get_int_arg(line, &match[2]));
return 0;
}
static HANDLE_FUNC(handle_user)
static
HANDLE_FUNC(handle_user)
{
return set_string_arg(&conf->username, line, &match[2]);
}
static HANDLE_FUNC(handle_group)
static
HANDLE_FUNC(handle_group)
{
return set_string_arg(&conf->group, line, &match[2]);
}
static HANDLE_FUNC(handle_allow)
static
HANDLE_FUNC(handle_allow)
{
char *arg = get_string_arg(line, &match[2]);
insert_acl(arg, ACL_ALLOW);
safefree(arg);
return 0;
}
static HANDLE_FUNC(handle_deny)
static
HANDLE_FUNC(handle_deny)
{
char *arg = get_string_arg(line, &match[2]);
insert_acl(arg, ACL_DENY);
safefree(arg);
return 0;
}
static HANDLE_FUNC(handle_bind)
static
HANDLE_FUNC(handle_bind)
{
#ifndef TRANSPARENT_PROXY
int r = set_string_arg(&conf->bind_address, line, &match[2]);
if (r) return r;
if (r)
return r;
log_message(LOG_INFO,
"Outgoing connections bound to IP %s",
conf->bind_address);
"Outgoing connections bound to IP %s", conf->bind_address);
return 0;
#else
fprintf(stderr,
@ -530,14 +575,20 @@ static HANDLE_FUNC(handle_bind)
return 1;
#endif
}
static HANDLE_FUNC(handle_listen)
static
HANDLE_FUNC(handle_listen)
{
int r = set_string_arg(&conf->ipAddr, line, &match[2]);
if (r) return r;
if (r)
return r;
log_message(LOG_INFO, "Listing on IP %s", conf->ipAddr);
return 0;
}
static HANDLE_FUNC(handle_errorfile)
static
HANDLE_FUNC(handle_errorfile)
{
/*
* Because an integer is defined as ((0x)?[[:digit:]]+) _two_
@ -548,6 +599,7 @@ static HANDLE_FUNC(handle_errorfile)
*/
long int err = get_int_arg(line, &match[2]);
char *page = get_string_arg(line, &match[4]);
add_new_errorpage(page, err);
safefree(page);
return 0;
@ -569,12 +621,15 @@ static struct log_levels_s log_levels[] = {
{"info", LOG_INFO}
};
static HANDLE_FUNC(handle_loglevel)
static
HANDLE_FUNC(handle_loglevel)
{
static const unsigned int nlevels = sizeof(log_levels)/sizeof(log_levels[0]);
static const unsigned int nlevels =
sizeof(log_levels) / sizeof(log_levels[0]);
unsigned int i;
char *arg = get_string_arg(line, &match[2]);
for (i = 0; i != nlevels; ++i) {
if (!strcasecmp(arg, log_levels[i].string)) {
set_log_level(log_levels[i].level);
@ -584,21 +639,27 @@ static HANDLE_FUNC(handle_loglevel)
return -1;
}
#ifdef FILTER_ENABLE
static HANDLE_FUNC(handle_filter)
static
HANDLE_FUNC(handle_filter)
{
return set_string_arg(&conf->filter, line, &match[2]);
}
static HANDLE_FUNC(handle_filterurls)
static
HANDLE_FUNC(handle_filterurls)
{
return set_bool_arg(&conf->filter_url, line, &match[2]);
}
static HANDLE_FUNC(handle_filterextended)
static
HANDLE_FUNC(handle_filterextended)
{
return set_bool_arg(&conf->filter_extended, line, &match[2]);
}
static HANDLE_FUNC(handle_filterdefaultdeny)
static
HANDLE_FUNC(handle_filterdefaultdeny)
{
assert(match[2].rm_so != -1);
@ -606,7 +667,9 @@ static HANDLE_FUNC(handle_filterdefaultdeny)
filter_set_default_policy(FILTER_DEFAULT_DENY);
return 0;
}
static HANDLE_FUNC(handle_filtercasesensitive)
static
HANDLE_FUNC(handle_filtercasesensitive)
{
return set_bool_arg(&conf->filter_casesensitive, line, &match[2]);
}
@ -618,29 +681,59 @@ no_filter_support(void)
return -1;
}
static HANDLE_FUNC(handle_filter) { return no_filter_support(); }
static HANDLE_FUNC(handle_filtercasesensitive) { return no_filter_support(); }
static HANDLE_FUNC(handle_filterdefaultdeny) { return no_filter_support(); }
static HANDLE_FUNC(handle_filterextended) { return no_filter_support(); }
static HANDLE_FUNC(handle_filterurls) { return no_filter_support(); }
static
HANDLE_FUNC(handle_filter)
{
return no_filter_support();
}
static
HANDLE_FUNC(handle_filtercasesensitive)
{
return no_filter_support();
}
static
HANDLE_FUNC(handle_filterdefaultdeny)
{
return no_filter_support();
}
static
HANDLE_FUNC(handle_filterextended)
{
return no_filter_support();
}
static
HANDLE_FUNC(handle_filterurls)
{
return no_filter_support();
}
#endif
#ifdef REVERSE_SUPPORT
static HANDLE_FUNC(handle_reverseonly)
static
HANDLE_FUNC(handle_reverseonly)
{
return set_bool_arg(&conf->reverseonly, line, &match[2]);
}
static HANDLE_FUNC(handle_reversemagic)
static
HANDLE_FUNC(handle_reversemagic)
{
return set_bool_arg(&conf->reversemagic, line, &match[2]);
}
static HANDLE_FUNC(handle_reversebaseurl)
static
HANDLE_FUNC(handle_reversebaseurl)
{
return set_string_arg(&conf->reversebaseurl, line, &match[2]);
}
static HANDLE_FUNC(handle_reversepath)
static
HANDLE_FUNC(handle_reversepath)
{
/*
* The second string argument is optional.
@ -648,7 +741,8 @@ static HANDLE_FUNC(handle_reversepath)
char *arg1, *arg2;
arg1 = get_string_arg(line, &match[2]);
if (!arg1) return -1;
if (!arg1)
return -1;
if (match[3].rm_so != -1) {
arg2 = get_string_arg(line, &match[3]);
@ -674,9 +768,28 @@ no_reverse_support(void)
return -1;
}
static HANDLE_FUNC(handle_reversebaseurl) { return no_reverse_support(); }
static HANDLE_FUNC(handle_reversemagic) { return no_reverse_support(); }
static HANDLE_FUNC(handle_reverseonly) { return no_reverse_support(); }
static HANDLE_FUNC(handle_reversepath) { return no_reverse_support(); }
static
HANDLE_FUNC(handle_reversebaseurl)
{
return no_reverse_support();
}
static
HANDLE_FUNC(handle_reversemagic)
{
return no_reverse_support();
}
static
HANDLE_FUNC(handle_reverseonly)
{
return no_reverse_support();
}
static
HANDLE_FUNC(handle_reversepath)
{
return no_reverse_support();
}
#endif

View File

@ -1,4 +1,4 @@
/* $Id: conffile.h,v 1.1 2004-08-13 20:19:50 rjkaes Exp $
/* $Id: conffile.h,v 1.2 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'conffile.c' for more details.
*

View File

@ -1,4 +1,4 @@
/* $Id: conns.c,v 1.24 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: conns.c,v 1.25 2005-08-15 03:54:31 rjkaes Exp $
*
* Create and free the connection structure. One day there could be
* other connection related tasks put here, but for now the header

View File

@ -1,4 +1,4 @@
/* $Id: conns.h,v 1.19 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: conns.h,v 1.20 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'conns.c' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: daemon.c,v 1.4 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: daemon.c,v 1.5 2005-08-15 03:54:31 rjkaes Exp $
*
* This file contains functions which are useful when writing a
* daemon process. The functions include a "makedaemon" function and

View File

@ -1,4 +1,4 @@
/* $Id: daemon.h,v 1.2 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: daemon.h,v 1.3 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'daemon.c' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: filter.c,v 1.21 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: filter.c,v 1.22 2005-08-15 03:54:31 rjkaes Exp $
*
* Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca)
* Copyright (c) 2002 James E. Flemer (jflemer@acm.jhu.edu)
@ -69,14 +69,16 @@ filter_init(void)
*/
s = buf;
while (*s) {
if (isspace((unsigned char)*s)) break;
if (isspace((unsigned char)*s))
break;
if (*s == '#') {
/*
* If the '#' char is preceeded by
* an escape, it's not a comment
* string.
*/
if (s == buf || *(s - 1) != '\\')
if (s == buf
|| *(s - 1) != '\\')
break;
}
++s;
@ -107,7 +109,8 @@ filter_init(void)
p->pat = safestrdup(s);
p->cpat = safemalloc(sizeof(regex_t));
if ((err = regcomp(p->cpat, p->pat, cflags)) != 0) {
if ((err =
regcomp(p->cpat, p->pat, cflags)) != 0) {
fprintf(stderr, "Bad regex in %s: %s\n",
config.filter, p->pat);
exit(EX_DATAERR);
@ -154,7 +157,8 @@ filter_domain(const char *host)
goto COMMON_EXIT;
for (p = fl; p; p = p->next) {
result = regexec(p->cpat, host, (size_t) 0, (regmatch_t *) 0, 0);
result =
regexec(p->cpat, host, (size_t) 0, (regmatch_t *) 0, 0);
if (result == 0) {
if (default_policy == FILTER_DEFAULT_ALLOW)

View File

@ -1,4 +1,4 @@
/* $Id: filter.h,v 1.5 2002-06-07 18:36:21 rjkaes Exp $
/* $Id: filter.h,v 1.6 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'filter.c' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: hashmap.c,v 1.16 2005-07-12 17:39:43 rjkaes Exp $
/* $Id: hashmap.c,v 1.17 2005-08-15 03:54:31 rjkaes Exp $
*
* A hashmap implementation. The keys are case-insensitive NULL terminated
* strings, and the data is arbitrary lumps of data. Copies of both the
@ -76,8 +76,8 @@ hashfunc(const char *key, unsigned int size)
return -ERANGE;
for (hash = tolower(*key++); *key != '\0'; key++) {
uint32_t bit =
(hash & 1) ? (1 << (sizeof(uint32_t) - 1)) : 0;
uint32_t bit = (hash & 1) ? (1 << (sizeof(uint32_t) - 1)) : 0;
hash >>= 1;
hash += tolower(*key) + bit;
@ -186,8 +186,7 @@ hashmap_delete(hashmap_t map)
* negative number if there are errors
*/
int
hashmap_insert(hashmap_t map, const char *key,
const void *data, size_t len)
hashmap_insert(hashmap_t map, const char *key, const void *data, size_t len)
{
struct hashentry_s *ptr;
int hash;
@ -343,8 +342,7 @@ hashmap_find(hashmap_t map, const char* key)
* negative upon error
*/
ssize_t
hashmap_return_entry(hashmap_t map, hashmap_iter iter,
char** key, void** data)
hashmap_return_entry(hashmap_t map, hashmap_iter iter, char **key, void **data)
{
unsigned int i;
struct hashentry_s *ptr;

View File

@ -1,4 +1,4 @@
/* $Id: hashmap.h,v 1.3 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: hashmap.h,v 1.4 2005-08-15 03:54:31 rjkaes Exp $
*
* A hashmap implementation. The keys are case-insensitive NULL terminated
* strings, and the data is arbitrary lumps of data. Copies of both the
@ -104,7 +104,8 @@ extern ssize_t hashmap_return_entry(hashmap_t map, hashmap_iter iter,
* zero if no entry is found
* length of data for the entry
*/
extern ssize_t hashmap_entry_by_key(hashmap_t map, const char* key, void** data);
extern ssize_t hashmap_entry_by_key(hashmap_t map, const char *key,
void **data);
/*
* Searches for _any_ occurrances of "key" within the hashmap and returns the
@ -129,5 +130,4 @@ extern ssize_t hashmap_remove(hashmap_t map, const char *key);
#if defined(__cplusplus)
}
#endif /* C++ */
#endif /* _HASHMAP_H */

View File

@ -1,4 +1,4 @@
/* $Id: heap.c,v 1.9 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: heap.c,v 1.10 2005-08-15 03:54:31 rjkaes Exp $
*
* Debugging versions of various heap related functions are combined
* here. The debugging versions include assertions and also print
@ -146,4 +146,3 @@ calloc_shared_memory(size_t nmemb, size_t size)
return ptr;
}

View File

@ -1,4 +1,4 @@
/* $Id: heap.h,v 1.5 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: heap.h,v 1.6 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'heap.c' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: htmlerror.c,v 1.7 2003-08-01 00:14:34 rjkaes Exp $
/* $Id: htmlerror.c,v 1.8 2005-08-15 03:54:31 rjkaes Exp $
*
* This file contains source code for the handling and display of
* HTML error pages with variable substitution.
@ -33,7 +33,8 @@
#define ERRPAGES_BUCKETCOUNT 16
int
add_new_errorpage(char *filepath, unsigned int errornum) {
add_new_errorpage(char *filepath, unsigned int errornum)
{
char errornbuf[ERRORNUM_BUFSIZE];
config.errorpages = hashmap_create(ERRPAGES_BUCKETCOUNT);
@ -53,7 +54,8 @@ add_new_errorpage(char *filepath, unsigned int errornum) {
* Get the file appropriate for a given error.
*/
static char *
get_html_file(unsigned int errornum) {
get_html_file(unsigned int errornum)
{
hashmap_iter result_iter;
char errornbuf[ERRORNUM_BUFSIZE];
char *key;
@ -61,7 +63,8 @@ get_html_file(unsigned int errornum) {
assert(errornum >= 100 && errornum < 1000);
if (!config.errorpages) return(config.errorpage_undef);
if (!config.errorpages)
return (config.errorpage_undef);
snprintf(errornbuf, ERRORNUM_BUFSIZE, "%u", errornum);
@ -81,7 +84,8 @@ get_html_file(unsigned int errornum) {
* Look up the value for a variable.
*/
static char *
lookup_variable(struct conn_s *connptr, char *varname) {
lookup_variable(struct conn_s *connptr, char *varname)
{
hashmap_iter result_iter;
char *key;
static char *data;
@ -104,7 +108,8 @@ lookup_variable(struct conn_s *connptr, char *varname) {
* Send an already-opened file to the client with variable substitution.
*/
int
send_html_file(FILE *infile, struct conn_s *connptr) {
send_html_file(FILE * infile, struct conn_s *connptr)
{
char inbuf[HTML_BUFSIZE], *varstart = NULL, *p;
char *varval;
int in_variable = 0, writeret;
@ -115,15 +120,23 @@ send_html_file(FILE *infile, struct conn_s *connptr) {
case '}':
if (in_variable) {
*p = '\0';
if(!(varval = lookup_variable(connptr, varstart)))
if (!
(varval =
lookup_variable(connptr,
varstart)))
varval = "(unknown)";
writeret = write_message(connptr->client_fd, "%s",
varval);
if(writeret) return(writeret);
writeret =
write_message(connptr->client_fd,
"%s", varval);
if (writeret)
return (writeret);
in_variable = 0;
} else {
writeret = write_message(connptr->client_fd, "%c", *p);
if (writeret) return(writeret);
writeret =
write_message(connptr->client_fd,
"%c", *p);
if (writeret)
return (writeret);
}
break;
case '{':
@ -140,9 +153,11 @@ send_html_file(FILE *infile, struct conn_s *connptr) {
in_variable = 0;
default:
if (!in_variable) {
writeret = write_message(connptr->client_fd, "%c",
*p);
if(writeret) return(writeret);
writeret =
write_message(connptr->client_fd,
"%c", *p);
if (writeret)
return (writeret);
}
}
@ -153,17 +168,15 @@ send_html_file(FILE *infile, struct conn_s *connptr) {
}
int
send_http_headers(struct conn_s *connptr, int code, char *message) {
char *headers = \
"HTTP/1.0 %d %s\r\n" \
"Server: %s/%s\r\n" \
"Content-Type: text/html\r\n" \
"Connection: close\r\n" \
"\r\n";
send_http_headers(struct conn_s *connptr, int code, char *message)
{
char *headers =
"HTTP/1.0 %d %s\r\n"
"Server: %s/%s\r\n"
"Content-Type: text/html\r\n" "Connection: close\r\n" "\r\n";
return (write_message(connptr->client_fd, headers,
code, message,
PACKAGE, VERSION));
code, message, PACKAGE, VERSION));
}
/*
@ -175,18 +188,17 @@ send_http_error_message(struct conn_s *connptr)
char *error_file;
FILE *infile;
int ret;
char *fallback_error = \
"<html><head><title>%s</title></head>" \
"<body><blockquote><i>%s %s</i><br>" \
"The page you requested was unavailable. The error code is listed " \
"below. In addition, the HTML file which has been configured as the " \
"page to be displayed when an error of this type was unavailable, " \
"with the error code %d (%s). Please contact your administrator." \
"<center>%s</center>" \
"</body></html>" \
"\r\n";
char *fallback_error =
"<html><head><title>%s</title></head>"
"<body><blockquote><i>%s %s</i><br>"
"The page you requested was unavailable. The error code is listed "
"below. In addition, the HTML file which has been configured as the "
"page to be displayed when an error of this type was unavailable, "
"with the error code %d (%s). Please contact your administrator."
"<center>%s</center>" "</body></html>" "\r\n";
send_http_headers(connptr, connptr->error_number, connptr->error_string);
send_http_headers(connptr, connptr->error_number,
connptr->error_string);
error_file = get_html_file(connptr->error_number);
if (!(infile = fopen(error_file, "r")))
@ -211,7 +223,9 @@ int
add_error_variable(struct conn_s *connptr, char *key, char *val)
{
if (!connptr->error_variables)
if (!(connptr->error_variables = hashmap_create(ERRVAR_BUCKETCOUNT)))
if (!
(connptr->error_variables =
hashmap_create(ERRVAR_BUCKETCOUNT)))
return (-1);
if (hashmap_insert(connptr->error_variables, key, val,
@ -227,7 +241,8 @@ add_error_variable(struct conn_s *connptr, char *key, char *val)
* Set some standard variables used by all HTML pages
*/
int
add_standard_vars(struct conn_s *connptr) {
add_standard_vars(struct conn_s *connptr)
{
char timebuf[30];
time_t global_time = time(NULL);
@ -257,6 +272,7 @@ indicate_http_error(struct conn_s* connptr, int number, char *message, ...)
while ((key = va_arg(ap, char *))) {
val = va_arg(ap, char *);
if (add_error_variable(connptr, key, val) == -1) {
va_end(ap);
return (-1);

View File

@ -1,4 +1,4 @@
/* $Id: htmlerror.h,v 1.2 2003-03-14 22:45:59 rjkaes Exp $
/* $Id: htmlerror.h,v 1.3 2005-08-15 03:54:31 rjkaes Exp $
*
* Contains header declarations for the HTML error functions in
* htmlerror.c
@ -24,7 +24,8 @@ struct conn_s;
extern int add_new_errorpage(char *filepath, unsigned int errornum);
extern int send_http_error_message(struct conn_s *connptr);
extern int indicate_http_error(struct conn_s *connptr, int number, char *message, ...);
extern int indicate_http_error(struct conn_s *connptr, int number,
char *message, ...);
extern int add_error_variable(struct conn_s *connptr, char *key, char *val);
extern int send_html_file(FILE * infile, struct conn_s *connptr);
extern int send_http_headers(struct conn_s *connptr, int code, char *message);

View File

@ -1,4 +1,4 @@
/* $Id: http_message.c,v 1.5 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: http_message.c,v 1.6 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'http_message.h' for a detailed description.
*
@ -60,10 +60,14 @@ struct http_message_s {
static int
is_http_message_valid(http_message_t msg)
{
if (msg == NULL) return 0;
if (msg->headers.strings == NULL) return 0;
if (msg->response.string == NULL) return 0;
if (msg->response.code < 1 || msg->response.code > 999) return 0;
if (msg == NULL)
return 0;
if (msg->headers.strings == NULL)
return 0;
if (msg->response.string == NULL)
return 0;
if (msg->response.code < 1 || msg->response.code > 999)
return 0;
return 1;
}
@ -116,7 +120,8 @@ http_message_destroy(http_message_t msg)
assert(msg->headers.strings != NULL);
/* Check for valid arguments */
if (msg == NULL) return -EFAULT;
if (msg == NULL)
return -EFAULT;
if (msg->headers.strings != NULL)
safefree(msg->headers.strings);
@ -130,14 +135,17 @@ http_message_destroy(http_message_t msg)
*/
int
http_message_set_response(http_message_t msg,
int response_code,
const char* response_string)
int response_code, const char *response_string)
{
/* Check for valid arguments */
if (msg == NULL) return -EFAULT;
if (response_code < 1 || response_code > 999) return -EINVAL;
if (response_string == NULL) return -EINVAL;
if (strlen(response_string) == 0) return -EINVAL;
if (msg == NULL)
return -EFAULT;
if (response_code < 1 || response_code > 999)
return -EINVAL;
if (response_string == NULL)
return -EINVAL;
if (strlen(response_string) == 0)
return -EINVAL;
msg->response.code = response_code;
msg->response.string = response_string;
@ -152,9 +160,12 @@ int
http_message_set_body(http_message_t msg, const char *body, size_t len)
{
/* Check for valid arguments */
if (msg == NULL) return -EFAULT;
if (body == NULL) return -EINVAL;
if (len == 0) return -EINVAL;
if (msg == NULL)
return -EFAULT;
if (body == NULL)
return -EINVAL;
if (len == 0)
return -EINVAL;
msg->body.text = body;
msg->body.length = len;
@ -166,16 +177,18 @@ http_message_set_body(http_message_t msg, const char* body, size_t len)
* Add headers to the structure.
*/
int
http_message_add_headers(http_message_t msg, char** headers,
int num_headers)
http_message_add_headers(http_message_t msg, char **headers, int num_headers)
{
char **new_headers;
int i;
/* Check for valid arguments */
if (msg == NULL) return -EFAULT;
if (headers == NULL) return -EINVAL;
if (num_headers < 1) return -EINVAL;
if (msg == NULL)
return -EFAULT;
if (headers == NULL)
return -EINVAL;
if (num_headers < 1)
return -EINVAL;
/*
* If the number of headers to add is greater than the space
@ -220,9 +233,12 @@ http_message_send(http_message_t msg, int fd)
assert(is_http_message_valid(msg));
/* Check for valid arguments */
if (msg == NULL) return -EFAULT;
if (fd < 1) return -EBADF;
if (!is_http_message_valid(msg)) return -EINVAL;
if (msg == NULL)
return -EFAULT;
if (fd < 1)
return -EBADF;
if (!is_http_message_valid(msg))
return -EINVAL;
/* Write the response line */
write_message(fd, "HTTP/1.0 %d %s\r\n",

View File

@ -1,4 +1,4 @@
/* $Id: http_message.h,v 1.2 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: http_message.h,v 1.3 2005-08-15 03:54:31 rjkaes Exp $
*
* HTTP Message API
* ----------------
@ -84,7 +84,6 @@ extern int http_message_set_response(http_message_t msg,
* sent.
*/
extern int http_message_add_headers(http_message_t msg,
char** headers,
int num_headers);
char **headers, int num_headers);
#endif /* _TINYPROXY_HTTP_MESSAGE_H_ */

View File

@ -1,4 +1,4 @@
/* $Id: log.c,v 1.30 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: log.c,v 1.31 2005-08-15 03:54:31 rjkaes Exp $
*
* Logs the various messages which tinyproxy produces to either a log file or
* the syslog daemon. Not much to it...
@ -155,7 +155,6 @@ log_message(int level, char *fmt, ...)
return;
}
#ifdef HAVE_SYSLOG_H
if (config.syslog) {
# ifdef HAVE_VSYSLOG_H
@ -171,8 +170,8 @@ log_message(int level, char *fmt, ...)
strftime(time_string, TIME_LENGTH, "%b %d %H:%M:%S",
localtime(&nowtime));
snprintf(str, STRING_LENGTH, "%-9s %s [%ld]: ", syslog_level[level],
time_string, (long int) getpid());
snprintf(str, STRING_LENGTH, "%-9s %s [%ld]: ",
syslog_level[level], time_string, (long int)getpid());
assert(log_file_fd >= 0);

View File

@ -1,4 +1,4 @@
/* $Id: log.h,v 1.12 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: log.h,v 1.13 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'log.c' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: network.c,v 1.4 2004-02-18 20:17:18 rjkaes Exp $
/* $Id: network.c,v 1.5 2005-08-15 03:54:31 rjkaes Exp $
*
* The functions found here are used for communicating across a
* network. They include both safe reading and writing (which are
@ -252,11 +252,13 @@ get_ip_string(struct sockaddr* sa, char* buf, size_t buflen)
switch (sa->sa_family) {
case AF_INET:{
struct sockaddr_in *sa_in = (struct sockaddr_in *)sa;
inet_ntop(AF_INET, &sa_in->sin_addr, buf, buflen);
break;
}
case AF_INET6:{
struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)sa;
inet_ntop(AF_INET6, &sa_in6->sin6_addr, buf, buflen);
break;
}

View File

@ -1,4 +1,4 @@
/* $Id: network.h,v 1.2 2004-02-18 20:17:18 rjkaes Exp $
/* $Id: network.h,v 1.3 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'network.c' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: reqs.c,v 1.119 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: reqs.c,v 1.120 2005-08-15 03:54:31 rjkaes Exp $
*
* This is where all the work in tinyproxy is actually done. Incoming
* connections have a new child created for them. The child then
@ -97,12 +97,14 @@ add_connect_port_allowed(int port)
if (!ports_allowed_by_connect) {
ports_allowed_by_connect = vector_create();
if (!ports_allowed_by_connect) {
log_message(LOG_WARNING, "Could not create a list of allowed CONNECT ports");
log_message(LOG_WARNING,
"Could not create a list of allowed CONNECT ports");
return;
}
}
log_message(LOG_INFO, "Adding Port [%d] to the list allowed by CONNECT", port);
log_message(LOG_INFO, "Adding Port [%d] to the list allowed by CONNECT",
port);
vector_append(ports_allowed_by_connect, (void **)&port, sizeof(port));
}
@ -343,7 +345,8 @@ upstream_add(const char *host, int port, const char *domain)
struct upstream *up = safemalloc(sizeof(struct upstream));
if (!up) {
log_message(LOG_ERR, "Unable to allocate memory in upstream_add()");
log_message(LOG_ERR,
"Unable to allocate memory in upstream_add()");
return;
}
@ -352,17 +355,20 @@ upstream_add(const char *host, int port, const char *domain)
if (domain == NULL) {
if (!host || host[0] == '\0' || port < 1) {
log_message(LOG_WARNING, "Nonsense upstream rule: invalid host or port");
log_message(LOG_WARNING,
"Nonsense upstream rule: invalid host or port");
goto upstream_cleanup;
}
up->host = safestrdup(host);
up->port = port;
log_message(LOG_INFO, "Added upstream %s:%d for [default]", host, port);
log_message(LOG_INFO, "Added upstream %s:%d for [default]",
host, port);
} else if (host == NULL) {
if (!domain || domain[0] == '\0') {
log_message(LOG_WARNING, "Nonsense no-upstream rule: empty domain");
log_message(LOG_WARNING,
"Nonsense no-upstream rule: empty domain");
goto upstream_cleanup;
}
@ -377,9 +383,11 @@ upstream_add(const char *host, int port, const char *domain)
if (strchr(ptr, '.')) {
if (inet_aton(ptr, &addrstruct) != 0)
up->mask = ntohl(addrstruct.s_addr);
up->mask =
ntohl(addrstruct.s_addr);
} else {
up->mask = ~((1 << (32 - atoi(ptr))) - 1);
up->mask =
~((1 << (32 - atoi(ptr))) - 1);
}
}
} else {
@ -388,8 +396,10 @@ upstream_add(const char *host, int port, const char *domain)
log_message(LOG_INFO, "Added no-upstream for %s", domain);
} else {
if (!host || host[0] == '\0' || port < 1 || !domain || domain == '\0') {
log_message(LOG_WARNING, "Nonsense upstream rule: invalid parameters");
if (!host || host[0] == '\0' || port < 1 || !domain
|| domain == '\0') {
log_message(LOG_WARNING,
"Nonsense upstream rule: invalid parameters");
goto upstream_cleanup;
}
@ -497,29 +507,35 @@ reversepath_add(const char *path, const char *url)
struct reversepath *reverse;
if (url == NULL) {
log_message(LOG_WARNING, "Illegal reverse proxy rule: missing url");
log_message(LOG_WARNING,
"Illegal reverse proxy rule: missing url");
return;
}
if (!strstr(url, "://")) {
log_message(LOG_WARNING,
"Skipping reverse proxy rule: '%s' is not a valid url", url);
"Skipping reverse proxy rule: '%s' is not a valid url",
url);
return;
}
if (path && *path != '/') {
log_message(LOG_WARNING,
"Skipping reverse proxy rule: path '%s' doesn't start with a /", path);
"Skipping reverse proxy rule: path '%s' doesn't start with a /",
path);
return;
}
if (!(reverse = safemalloc(sizeof(struct reversepath)))) {
log_message(LOG_ERR, "Unable to allocate memory in reversepath_add()");
log_message(LOG_ERR,
"Unable to allocate memory in reversepath_add()");
return;
}
if (!path) reverse->path = safestrdup("/");
else reverse->path = safestrdup(path);
if (!path)
reverse->path = safestrdup("/");
else
reverse->path = safestrdup(path);
reverse->url = safestrdup(url);
@ -527,7 +543,8 @@ reversepath_add(const char *path, const char *url)
config.reversepath_list = reverse;
log_message(LOG_INFO,
"Added reverse proxy rule: %s -> %s", reverse->path, reverse->url);
"Added reverse proxy rule: %s -> %s", reverse->path,
reverse->url);
}
/*
@ -564,8 +581,8 @@ establish_http_connection(struct conn_s *connptr, struct request_s *request)
portbuff[0] = '\0';
return write_message(connptr->server_fd,
"%s %s HTTP/1.0\r\n" \
"Host: %s%s\r\n" \
"%s %s HTTP/1.0\r\n"
"Host: %s%s\r\n"
"Connection: close\r\n",
request->method, request->path,
request->host, portbuff);
@ -585,10 +602,9 @@ static inline int
send_ssl_response(struct conn_s *connptr)
{
return write_message(connptr->client_fd,
"%s\r\n" \
"%s\r\n" \
"\r\n",
SSL_CONNECTION_RESPONSE, PROXY_AGENT);
"%s\r\n"
"%s\r\n"
"\r\n", SSL_CONNECTION_RESPONSE, PROXY_AGENT);
}
/*
@ -660,8 +676,7 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
connptr->client_fd);
indicate_http_error(connptr, 400, "Bad Request",
"detail", "Request has an invalid format",
"url", url,
NULL);
"url", url, NULL);
safefree(url);
free_request_struct(request);
@ -675,15 +690,13 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
connptr->client_fd);
indicate_http_error(connptr, 400, "Bad Request",
"detail", "Request has an empty URL",
"url", url,
NULL);
"url", url, NULL);
safefree(url);
free_request_struct(request);
return NULL;
}
#ifdef REVERSE_SUPPORT
/*
* Reverse proxy URL rewriting.
@ -695,20 +708,29 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
reverse = reversepath_get(url);
if (reverse) {
rewrite_url = safemalloc(strlen(url) +
strlen(reverse->url) + 1);
strlen(reverse->url) +
1);
strcpy(rewrite_url, reverse->url);
strcat(rewrite_url, url + strlen(reverse->path));
} else if (config.reversemagic &&
hashmap_entry_by_key(hashofheaders, "cookie",
(void **)&cookie) > 0) {
strcat(rewrite_url,
url + strlen(reverse->path));
} else if (config.reversemagic
&& hashmap_entry_by_key(hashofheaders,
"cookie",
(void **)&cookie) >
0) {
/* No match - try the magical tracking cookie next */
if ((cookieval = strstr(cookie, REVERSE_COOKIE "=")) &&
(reverse = reversepath_get(cookieval +
strlen(REVERSE_COOKIE) + 1))) {
if ((cookieval =
strstr(cookie, REVERSE_COOKIE "="))
&& (reverse =
reversepath_get(cookieval +
strlen(REVERSE_COOKIE) +
1))) {
rewrite_url = safemalloc(strlen(url) +
strlen(reverse->url) + 1);
strlen
(reverse->
url) + 1);
strcpy(rewrite_url, reverse->url);
strcat(rewrite_url, url + 1);
@ -723,9 +745,9 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
if (config.reverseonly && !rewrite_url) {
log_message(LOG_ERR, "Bad request");
indicate_http_error(connptr, 400, "Bad Request",
"detail", "Request has an invalid URL",
"url", url,
NULL);
"detail",
"Request has an invalid URL", "url",
url, NULL);
safefree(url);
free_request_struct(request);
@ -740,7 +762,8 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
url = rewrite_url;
/* Store reverse path so that the magical tracking cookie can be set */
if (config.reversemagic) connptr->reversepath = safestrdup(reverse->path);
if (config.reversemagic)
connptr->reversepath = safestrdup(reverse->path);
}
#endif
@ -751,8 +774,7 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
if (extract_http_url(skipped_type, request) < 0) {
indicate_http_error(connptr, 400, "Bad Request",
"detail", "Could not parse URL",
"url", url,
NULL);
"url", url, NULL);
safefree(url);
free_request_struct(request);
@ -763,8 +785,7 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
if (extract_ssl_url(url, request) < 0) {
indicate_http_error(connptr, 400, "Bad Request",
"detail", "Could not parse URL",
"url", url,
NULL);
"url", url, NULL);
safefree(url);
free_request_struct(request);
@ -775,11 +796,12 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
/* Verify that the port in the CONNECT method is allowed */
if (!check_allowed_connect_ports(request->port)) {
indicate_http_error(connptr, 403, "Access violation",
"detail", "The CONNECT method not allowed " \
"detail",
"The CONNECT method not allowed "
"with the port you tried to use.",
"url", url,
NULL);
log_message(LOG_INFO, "Refused CONNECT method on port %d",
"url", url, NULL);
log_message(LOG_INFO,
"Refused CONNECT method on port %d",
request->port);
safefree(url);
@ -801,18 +823,22 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
*/
int length;
char *data;
length = hashmap_entry_by_key(hashofheaders, "host", (void **)&data);
length =
hashmap_entry_by_key(hashofheaders, "host", (void **)&data);
if (length <= 0) {
struct sockaddr_in dest_addr;
if (getsockname(connptr->client_fd, (struct sockaddr *)&dest_addr, &length) < 0) {
if (getsockname
(connptr->client_fd, (struct sockaddr *)&dest_addr,
&length) < 0) {
log_message(LOG_ERR,
"process_request: cannot get destination IP for %d",
connptr->client_fd);
indicate_http_error(connptr, 400, "Bad Request",
"detail", "Unknown destination",
"url", url,
NULL);
"detail",
"Unknown destination",
"url", url, NULL);
safefree(url);
free_request_struct(request);
return NULL;
@ -823,33 +849,36 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
request->path = safemalloc(strlen(url) + 1);
strcpy(request->path, url);
safefree(url);
build_url(&url, request->host, request->port, request->path);
build_url(&url, request->host, request->port,
request->path);
log_message(LOG_INFO,
"process_request: trans IP %s %s for %d",
request->method, url, connptr->client_fd);
} else {
request->host = safemalloc(length + 1);
if (sscanf(data, "%[^:]:%hu", request->host, &request->port) != 2) {
if (sscanf
(data, "%[^:]:%hu", request->host,
&request->port) != 2) {
strcpy(request->host, data);
request->port = HTTP_PORT;
}
request->path = safemalloc(strlen(url) + 1);
strcpy(request->path, url);
safefree(url);
build_url(&url, request->host, request->port, request->path);
build_url(&url, request->host, request->port,
request->path);
log_message(LOG_INFO,
"process_request: trans Host %s %s for %d",
request->method, url, connptr->client_fd);
}
if (config.ipAddr &&
strcmp(request->host, config.ipAddr) == 0) {
if (config.ipAddr && strcmp(request->host, config.ipAddr) == 0) {
log_message(LOG_ERR,
"process_request: destination IP is localhost %d",
connptr->client_fd);
indicate_http_error(connptr, 400, "Bad Request",
"detail", "You tried to connect to the machine the proxy is running on",
"url", url,
NULL);
"detail",
"You tried to connect to the machine the proxy is running on",
"url", url, NULL);
safefree(url);
free_request_struct(request);
return NULL;
@ -860,8 +889,7 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
connptr->client_fd);
indicate_http_error(connptr, 400, "Bad Request",
"detail", "Unknown URL type",
"url", url,
NULL);
"url", url, NULL);
safefree(url);
free_request_struct(request);
@ -893,9 +921,9 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
request->host);
indicate_http_error(connptr, 403, "Filtered",
"detail", "The request you made has been filtered",
"url", url,
NULL);
"detail",
"The request you made has been filtered",
"url", url, NULL);
safefree(url);
free_request_struct(request);
@ -985,8 +1013,7 @@ add_xtinyproxy_header(struct conn_s *connptr)
{
assert(connptr && connptr->server_fd >= 0);
return write_message(connptr->server_fd,
"X-Tinyproxy: %s\r\n",
connptr->client_ip_addr);
"X-Tinyproxy: %s\r\n", connptr->client_ip_addr);
}
#endif /* XTINYPROXY */
@ -1064,7 +1091,8 @@ get_all_headers(int fd, hashmap_t hashofheaders)
}
if (!double_cgi
&& add_header_to_connection(hashofheaders, header, len) < 0) {
&& add_header_to_connection(hashofheaders, header,
len) < 0) {
safefree(header);
return -1;
}
@ -1092,7 +1120,9 @@ remove_connection_headers(hashmap_t hashofheaders)
for (i = 0; i != (sizeof(headers) / sizeof(char *)); ++i) {
/* Look for the connection header. If it's not found, return. */
len = hashmap_entry_by_key(hashofheaders, headers[i], (void **)&data);
len =
hashmap_entry_by_key(hashofheaders, headers[i],
(void **)&data);
if (len <= 0)
return 0;
@ -1136,7 +1166,9 @@ get_content_length(hashmap_t hashofheaders)
char *data;
long content_length = -1;
len = hashmap_entry_by_key(hashofheaders, "content-length", (void **)&data);
len =
hashmap_entry_by_key(hashofheaders, "content-length",
(void **)&data);
if (len > 0)
content_length = atol(data);
@ -1174,15 +1206,13 @@ write_via_header(int fd, hashmap_t hashofheaders,
ret = write_message(fd,
"Via: %s, %hu.%hu %s (%s/%s)\r\n",
data,
major, minor,
hostname, PACKAGE, VERSION);
major, minor, hostname, PACKAGE, VERSION);
hashmap_remove(hashofheaders, "via");
} else {
ret = write_message(fd,
"Via: %hu.%hu %s (%s/%s)\r\n",
major, minor,
hostname, PACKAGE, VERSION);
major, minor, hostname, PACKAGE, VERSION);
}
return ret;
@ -1224,7 +1254,8 @@ process_client_headers(struct conn_s *connptr, hashmap_t hashofheaders)
*/
if (connptr->server_fd == -1 || connptr->show_stats
|| (connptr->connect_method && (connptr->upstream_proxy == NULL))) {
log_message(LOG_INFO, "Not sending client headers to remote machine");
log_message(LOG_INFO,
"Not sending client headers to remote machine");
return 0;
}
@ -1254,7 +1285,8 @@ process_client_headers(struct conn_s *connptr, hashmap_t hashofheaders)
if (ret < 0) {
indicate_http_error(connptr, 503,
"Could not send data to remote server",
"detail", "A network error occurred while trying to write data to the remote web server.",
"detail",
"A network error occurred while trying to write data to the remote web server.",
NULL);
goto PULL_CLIENT_DATA;
}
@ -1266,25 +1298,24 @@ process_client_headers(struct conn_s *connptr, hashmap_t hashofheaders)
if (iter >= 0) {
for (; !hashmap_is_end(hashofheaders, iter); ++iter) {
hashmap_return_entry(hashofheaders,
iter,
&data,
(void**)&header);
iter, &data, (void **)&header);
if (!is_anonymous_enabled() || anonymous_search(data) > 0) {
ret = write_message(connptr->server_fd,
"%s: %s\r\n",
data, header);
if (!is_anonymous_enabled()
|| anonymous_search(data) > 0) {
ret =
write_message(connptr->server_fd,
"%s: %s\r\n", data, header);
if (ret < 0) {
indicate_http_error(connptr, 503,
"Could not send data to remote server",
"detail", "A network error occurred while trying to write data to the remote web server.",
"detail",
"A network error occurred while trying to write data to the remote web server.",
NULL);
goto PULL_CLIENT_DATA;
}
}
}
}
#if defined(XTINYPROXY_ENABLE)
if (config.my_domain)
add_xtinyproxy_header(connptr);
@ -1362,12 +1393,16 @@ process_server_headers(struct conn_s *connptr)
* Get all the headers from the remote server in a big hash
*/
if (get_all_headers(connptr->server_fd, hashofheaders) < 0) {
log_message(LOG_WARNING, "Could not retrieve all the headers from the remote server.");
log_message(LOG_WARNING,
"Could not retrieve all the headers from the remote server.");
hashmap_delete(hashofheaders);
safefree(response_line);
indicate_http_error(connptr, 503, "Could not retrieve all the headers",
"detail", PACKAGE " was unable to retrieve and process headers from the remote web server.",
indicate_http_error(connptr, 503,
"Could not retrieve all the headers",
"detail",
PACKAGE
" was unable to retrieve and process headers from the remote web server.",
NULL);
return -1;
}
@ -1384,7 +1419,6 @@ process_server_headers(struct conn_s *connptr)
return 0;
}
/* Send the saved response line first */
ret = write_message(connptr->client_fd, "%s\r\n", response_line);
safefree(response_line);
@ -1421,32 +1455,39 @@ process_server_headers(struct conn_s *connptr)
/* Write tracking cookie for the magical reverse proxy path hack */
if (config.reversemagic && connptr->reversepath) {
ret = write_message(connptr->client_fd,
"Set-Cookie: " REVERSE_COOKIE "=%s; path=/\r\n",
connptr->reversepath);
if (ret < 0) goto ERROR_EXIT;
"Set-Cookie: " REVERSE_COOKIE
"=%s; path=/\r\n", connptr->reversepath);
if (ret < 0)
goto ERROR_EXIT;
}
/* Rewrite the HTTP redirect if needed */
if (config.reversebaseurl &&
hashmap_entry_by_key(hashofheaders, "location", (void **)&header) > 0) {
hashmap_entry_by_key(hashofheaders, "location",
(void **)&header) > 0) {
/* Look for a matching entry in the reversepath list */
while (reverse) {
if (strncasecmp(header,
reverse->url,
(len = strlen(reverse->url))) == 0) break;
(len = strlen(reverse->url))) == 0)
break;
reverse = reverse->next;
}
if (reverse) {
ret = write_message(connptr->client_fd, "Location: %s%s%s\r\n",
config.reversebaseurl, (reverse->path + 1),
(header + len));
if (ret < 0) goto ERROR_EXIT;
ret =
write_message(connptr->client_fd,
"Location: %s%s%s\r\n",
config.reversebaseurl,
(reverse->path + 1), (header + len));
if (ret < 0)
goto ERROR_EXIT;
log_message(LOG_INFO,
"Rewriting HTTP redirect: %s -> %s%s%s", header,
config.reversebaseurl, (reverse->path + 1), (header + len));
"Rewriting HTTP redirect: %s -> %s%s%s",
header, config.reversebaseurl,
(reverse->path + 1), (header + len));
hashmap_remove(hashofheaders, "location");
}
}
@ -1459,13 +1500,10 @@ process_server_headers(struct conn_s *connptr)
if (iter >= 0) {
for (; !hashmap_is_end(hashofheaders, iter); ++iter) {
hashmap_return_entry(hashofheaders,
iter,
&data,
(void **)&header);
iter, &data, (void **)&header);
ret = write_message(connptr->client_fd,
"%s: %s\r\n",
data, header);
"%s: %s\r\n", data, header);
if (ret < 0)
goto ERROR_EXIT;
}
@ -1550,7 +1588,8 @@ relay_connection(struct conn_s *connptr)
}
if (FD_ISSET(connptr->server_fd, &rset)) {
bytes_received = read_buffer(connptr->server_fd, connptr->sbuffer);
bytes_received =
read_buffer(connptr->server_fd, connptr->sbuffer);
if (bytes_received < 0)
break;
@ -1612,22 +1651,26 @@ connect_to_upstream(struct conn_s *connptr, struct request_s *request)
int len;
struct upstream *cur_upstream = connptr->upstream_proxy;
if (!cur_upstream) {
log_message(LOG_WARNING,
"No upstream proxy defined for %s.",
request->host);
indicate_http_error(connptr, 404, "Unable to connect to upstream proxy.");
"No upstream proxy defined for %s.", request->host);
indicate_http_error(connptr, 404,
"Unable to connect to upstream proxy.");
return -1;
}
connptr->server_fd =
opensock(cur_upstream->host, cur_upstream->port, connptr->server_ip_addr);
opensock(cur_upstream->host, cur_upstream->port,
connptr->server_ip_addr);
if (connptr->server_fd < 0) {
log_message(LOG_WARNING,
"Could not connect to upstream proxy.");
indicate_http_error(connptr, 404, "Unable to connect to upstream proxy",
"detail", "A network error occurred while trying to connect to the upstream web proxy.",
indicate_http_error(connptr, 404,
"Unable to connect to upstream proxy",
"detail",
"A network error occurred while trying to connect to the upstream web proxy.",
NULL);
return -1;
}
@ -1710,7 +1753,8 @@ handle_connection(int fd)
if (check_acl(fd, peer_ipaddr, peer_string) <= 0) {
update_stats(STAT_DENIED);
indicate_http_error(connptr, 403, "Access denied",
"detail", "The administrator of this proxy has not configured it to service requests from your host.",
"detail",
"The administrator of this proxy has not configured it to service requests from your host.",
NULL);
send_http_error_message(connptr);
destroy_conn(connptr);
@ -1720,7 +1764,8 @@ handle_connection(int fd)
if (read_request_line(connptr) < 0) {
update_stats(STAT_BADCONN);
indicate_http_error(connptr, 408, "Timeout",
"detail", "Server timeout waiting for the HTTP request from the client.",
"detail",
"Server timeout waiting for the HTTP request from the client.",
NULL);
send_http_error_message(connptr);
destroy_conn(connptr);
@ -1733,7 +1778,8 @@ handle_connection(int fd)
if (!(hashofheaders = hashmap_create(HEADER_BUCKETS))) {
update_stats(STAT_BADCONN);
indicate_http_error(connptr, 503, "Internal error",
"detail", "An internal server error occurred while processing your request. Please contact the administrator.",
"detail",
"An internal server error occurred while processing your request. Please contact the administrator.",
NULL);
send_http_error_message(connptr);
destroy_conn(connptr);
@ -1744,7 +1790,8 @@ handle_connection(int fd)
* Get all the headers from the client in a big hash.
*/
if (get_all_headers(connptr->client_fd, hashofheaders) < 0) {
log_message(LOG_WARNING, "Could not retrieve all the headers from the client");
log_message(LOG_WARNING,
"Could not retrieve all the headers from the client");
hashmap_delete(hashofheaders);
update_stats(STAT_BADCONN);
destroy_conn(connptr);
@ -1772,9 +1819,10 @@ handle_connection(int fd)
connptr->server_ip_addr);
if (connptr->server_fd < 0) {
indicate_http_error(connptr, 500, "Unable to connect",
"detail", PACKAGE " was unable to connect to the remote web server.",
"error", strerror(errno),
NULL);
"detail",
PACKAGE
" was unable to connect to the remote web server.",
"error", strerror(errno), NULL);
goto send_error;
}
@ -1830,7 +1878,8 @@ handle_connection(int fd)
relay_connection(connptr);
log_message(LOG_INFO, "Closed connection between local client (fd:%d) and remote client (fd:%d)",
log_message(LOG_INFO,
"Closed connection between local client (fd:%d) and remote client (fd:%d)",
connptr->client_fd, connptr->server_fd);
/*

View File

@ -1,4 +1,4 @@
/* $Id: sock.c,v 1.42 2005-07-12 20:34:26 rjkaes Exp $
/* $Id: sock.c,v 1.43 2005-08-15 03:54:31 rjkaes Exp $
*
* Sockets are created and destroyed here. When a new connection comes in from
* a client, we need to copy the socket and the create a second socket to the
@ -95,7 +95,8 @@ opensock(const char* host, int port, const char* bind_to)
ressave = res;
do {
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
sockfd =
socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sockfd < 0)
continue; /* ignore this one */
@ -187,13 +188,15 @@ listen_sock(uint16_t port, socklen_t* addrlen)
}
if (bind(listenfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
log_message(LOG_ERR, "Unable to bind listening socket because of %s",
log_message(LOG_ERR,
"Unable to bind listening socket because of %s",
strerror(errno));
return -1;
}
if (listen(listenfd, MAXLISTEN) < 0) {
log_message(LOG_ERR, "Unable to start listening socket because of %s",
log_message(LOG_ERR,
"Unable to start listening socket because of %s",
strerror(errno));
return -1;
}
@ -252,6 +255,5 @@ getpeer_information(int fd, char* ipaddr, char* string_addr)
/* Get the full host name */
return getnameinfo((struct sockaddr *)&sa, salen,
string_addr, HOSTNAME_LENGTH,
NULL, 0, 0);
string_addr, HOSTNAME_LENGTH, NULL, 0, 0);
}

View File

@ -1,4 +1,4 @@
/* $Id: sock.h,v 1.13 2004-04-27 18:53:14 rjkaes Exp $
/* $Id: sock.h,v 1.14 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'sock.c' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: stats.c,v 1.17 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: stats.c,v 1.18 2005-08-15 03:54:31 rjkaes Exp $
*
* This module handles the statistics for tinyproxy. There are only two
* public API functions. The reason for the functions, rather than just a
@ -89,7 +89,8 @@ showstats(struct conn_s *connptr)
PACKAGE, VERSION, PACKAGE, VERSION,
stats->num_open,
stats->num_reqs,
stats->num_badcons, stats->num_denied, stats->num_refused);
stats->num_badcons, stats->num_denied,
stats->num_refused);
if (send_http_message(connptr, 200, "OK", message_buffer) < 0) {
safefree(message_buffer);

View File

@ -1,4 +1,4 @@
/* $Id: stats.h,v 1.5 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: stats.h,v 1.6 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'stats.h' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: text.c,v 1.4 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: text.c,v 1.5 2005-08-15 03:54:31 rjkaes Exp $
*
* The functions included here are useful for text manipulation. They
* replace or augment the standard C string library. These functions
@ -87,8 +87,10 @@ chomp(char *buffer, size_t length)
assert(length > 0);
/* Make sure the arguments are valid */
if (buffer == NULL) return -EFAULT;
if (length < 1) return -ERANGE;
if (buffer == NULL)
return -EFAULT;
if (length < 1)
return -ERANGE;
chars = 0;
@ -98,7 +100,8 @@ chomp(char *buffer, size_t length)
chars++;
/* Stop once we get to zero to prevent wrap-around */
if (length-- == 0) break;
if (length-- == 0)
break;
}
return chars;

View File

@ -1,4 +1,4 @@
/* $Id: text.h,v 1.3 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: text.h,v 1.4 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'text.c' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: tinyproxy.c,v 1.51 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: tinyproxy.c,v 1.52 2005-08-15 03:54:31 rjkaes Exp $
*
* The initialize routine. Basically sets up all the initial stuff (logfile,
* listening socket, config options, etc.) and then sits there and loops
@ -66,8 +66,7 @@ takesig(int sig)
break;
case SIGCHLD:
while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
;
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) ;
break;
}
@ -232,8 +231,7 @@ main(int argc, char **argv)
if (config.logf_name) {
if (open_log_file(config.logf_name) < 0) {
fprintf(stderr,
"%s: Could not create log file.\n",
argv[0]);
"%s: Could not create log file.\n", argv[0]);
exit(EX_SOFTWARE);
}
config.syslog = FALSE; /* disable syslog */
@ -271,7 +269,8 @@ main(int argc, char **argv)
"You SHOULD set a UserName in the configuration file. Using current user instead.");
}
if (config.idletimeout == 0) {
log_message(LOG_WARNING, "Invalid idle time setting. Only values greater than zero allowed; therefore setting idle timeout to %u seconds.",
log_message(LOG_WARNING,
"Invalid idle time setting. Only values greater than zero allowed; therefore setting idle timeout to %u seconds.",
MAX_IDLE_TIME);
config.idletimeout = MAX_IDLE_TIME;
}
@ -306,7 +305,6 @@ main(int argc, char **argv)
argv[0]);
exit(EX_OSERR);
}
#ifdef FILTER_ENABLE
if (config.filter)
filter_init();
@ -410,7 +408,6 @@ main(int argc, char **argv)
"Could not remove PID file \"%s\": %s.",
config.pidpath, strerror(errno));
}
#ifdef FILTER_ENABLE
if (config.filter)
filter_destroy();

View File

@ -1,4 +1,4 @@
/* $Id: tinyproxy.h,v 1.46 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: tinyproxy.h,v 1.47 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'tinyproxy.c' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.39 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: utils.c,v 1.40 2005-08-15 03:54:31 rjkaes Exp $
*
* Misc. routines which are used by the various functions to handle strings
* and memory allocation and pretty much anything else we can think of. Also,

View File

@ -1,4 +1,4 @@
/* $Id: utils.h,v 1.24 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: utils.h,v 1.25 2005-08-15 03:54:31 rjkaes Exp $
*
* See 'utils.h' for a detailed description.
*

View File

@ -1,4 +1,4 @@
/* $Id: vector.c,v 1.12 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: vector.c,v 1.13 2005-08-15 03:54:31 rjkaes Exp $
*
* A vector implementation. The vector can be of an arbitrary length, and
* the data for each entry is an lump of data (the size is stored in the

View File

@ -1,4 +1,4 @@
/* $Id: vector.h,v 1.6 2005-07-12 17:39:44 rjkaes Exp $
/* $Id: vector.h,v 1.7 2005-08-15 03:54:31 rjkaes Exp $
*
* A vector implementation. The vector can be of an arbritrary length, and
* the data for each entry is an lump of data (the size is stored in the
@ -70,7 +70,8 @@ extern int vector_prepend(vector_t vector, void *data, ssize_t len);
* Returns: NULL on error
* valid pointer to data
*/
extern void* vector_getentry(vector_t vector, size_t pos, size_t* size);
extern void *vector_getentry(vector_t vector, size_t pos,
size_t * size);
/*
* Returns the number of enteries (or the length) of the vector.
@ -83,5 +84,4 @@ extern ssize_t vector_length(vector_t vector);
#if defined(__cplusplus)
}
#endif /* C++ */
#endif /* _VECTOR_H */