* [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
@ -40,7 +40,7 @@ struct acl_s {
acl_access_t access;
enum acl_type type;
union {
char* string;
char *string;
struct {
unsigned char octet[IPV6_LEN];
unsigned char mask[IPV6_LEN];
@ -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
@ -149,9 +149,8 @@ insert_acl(char *location, acl_access_t access_type)
* -1 if no tests match, so skip
*/
static int
acl_string_processing(struct acl_s* acl,
const char* ip_address,
const char* string_address)
acl_string_processing(struct acl_s *acl,
const char *ip_address, const char *string_address)
{
int match;
struct addrinfo hints, *res, *ressave;
@ -195,7 +194,7 @@ acl_string_processing(struct acl_s* acl,
}
}
STRING_TEST:
STRING_TEST:
test_length = strlen(string_address);
match_length = strlen(acl->address.string);
@ -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
@ -226,7 +227,7 @@ STRING_TEST:
* -1 neither allowed nor denied.
*/
static int
check_numeric_acl(const struct acl_s* acl, const char* ip)
check_numeric_acl(const struct acl_s *acl, const char *ip)
{
uint8_t addr[IPV6_LEN], x, y;
int i;
@ -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.
*
@ -258,9 +259,9 @@ check_numeric_acl(const struct acl_s* acl, const char* ip)
* 0 if denied
*/
int
check_acl(int fd, const char* ip, const char* host)
check_acl(int fd, const char *ip, const char *host)
{
struct acl_s* acl;
struct acl_s *acl;
int perm;
int i;
@ -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.
@ -51,7 +51,7 @@ static struct child_config_s {
int maxspareservers, minspareservers, startservers;
} child_config;
static unsigned int* servers_waiting; /* servers waiting for a connection */
static unsigned int *servers_waiting; /* servers waiting for a connection */
/*
* Lock/Unlock the "servers_waiting" variable so that two children cannot
@ -159,7 +159,7 @@ child_configure(child_config_t type, int val)
* This is the main (per child) loop.
*/
static void
child_main(struct child_s* ptr)
child_main(struct child_s *ptr)
{
int connfd;
struct sockaddr *cliaddr;
@ -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;
@ -251,7 +256,7 @@ child_main(struct child_s* ptr)
* child_main() function.
*/
static pid_t
child_make(struct child_s* ptr)
child_make(struct child_s *ptr)
{
pid_t pid;
@ -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,12 +57,11 @@
*/
#define RE_MAX_MATCHES 16
/*
* All configuration handling functions are REQUIRED to be defined
* with the same function template as below.
*/
typedef int (*CONFFILE_HANDLER)(struct config_s*, const char*, regmatch_t[]);
typedef int (*CONFFILE_HANDLER) (struct config_s *, const char *, regmatch_t[]);
/*
* Define the pattern used by any directive handling function. The
@ -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
@ -142,16 +144,16 @@ static HANDLE_FUNC(handle_xtinyproxy);
* to be compiled one.
*/
struct {
const char* re;
const char *re;
CONFFILE_HANDLER handler;
regex_t* cre;
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,41 +175,35 @@ 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]);
const unsigned int ndirectives = sizeof(directives) / sizeof(directives[0]);
/*
* Compiles the regular expressions used by the configuration file. This
@ -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
@ -248,7 +242,7 @@ config_compile(void)
* a negative number is returned.
*/
static int
check_match(struct config_s* conf, const char* line)
check_match(struct config_s *conf, const char *line)
{
regmatch_t match[RE_MAX_MATCHES];
unsigned int i;
@ -258,7 +252,7 @@ check_match(struct config_s* conf, const char* line)
for (i = 0; i != ndirectives; ++i) {
assert(directives[i].cre);
if (!regexec(directives[i].cre, line, RE_MAX_MATCHES, match, 0))
return (*directives[i].handler)(conf, line, match);
return (*directives[i].handler) (conf, line, match);
}
return -1;
@ -268,7 +262,7 @@ check_match(struct config_s* conf, const char* line)
* Parse the previously opened configuration stream.
*/
int
config_parse(struct config_s* conf, FILE* f)
config_parse(struct config_s *conf, FILE * f)
{
char buffer[1024]; /* 1KB lines should be plenty */
unsigned long lineno = 1;
@ -283,7 +277,6 @@ config_parse(struct config_s* conf, FILE* f)
return 0;
}
/***********************************************************************
*
* The following are basic data extraction building blocks that can
@ -291,8 +284,8 @@ config_parse(struct config_s* conf, FILE* f)
*
***********************************************************************/
static char*
get_string_arg(const char* line, regmatch_t* match)
static char *
get_string_arg(const char *line, regmatch_t * match)
{
char *p;
const unsigned int len = match->rm_eo - match->rm_so;
@ -310,9 +303,10 @@ get_string_arg(const char* line, regmatch_t* match)
}
static int
set_string_arg(char** var, const char* line, regmatch_t* match)
set_string_arg(char **var, const char *line, regmatch_t * match)
{
char* arg = get_string_arg(line, match);
char *arg = get_string_arg(line, match);
if (!arg)
return -1;
*var = safestrdup(arg);
@ -321,9 +315,9 @@ set_string_arg(char** var, const char* line, regmatch_t* match)
}
static int
get_bool_arg(const char* line, regmatch_t* match)
get_bool_arg(const char *line, regmatch_t * match)
{
const char* p = line + match->rm_so;
const char *p = line + match->rm_so;
assert(line);
assert(match && match->rm_so != -1);
@ -336,7 +330,7 @@ get_bool_arg(const char* line, regmatch_t* match)
}
static int
set_bool_arg(unsigned int* var, const char* line, regmatch_t* match)
set_bool_arg(unsigned int *var, const char *line, regmatch_t * match)
{
assert(var);
assert(line);
@ -347,7 +341,7 @@ set_bool_arg(unsigned int* var, const char* line, regmatch_t* match)
}
static inline long int
get_int_arg(const char* line, regmatch_t* match)
get_int_arg(const char *line, regmatch_t * match)
{
assert(line);
assert(match && match->rm_so != -1);
@ -355,7 +349,7 @@ get_int_arg(const char* line, regmatch_t* match)
return strtol(line + match->rm_so, NULL, 0);
}
static int
set_int_arg(int long* var, const char* line, regmatch_t* match)
set_int_arg(int long *var, const char *line, regmatch_t * match)
{
assert(var);
assert(line);
@ -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]);
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]);
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]);
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;
@ -557,24 +609,27 @@ static HANDLE_FUNC(handle_errorfile)
* Log level's strings.
*/
struct log_levels_s {
const char* string;
const char *string;
int level;
};
static struct log_levels_s log_levels[] = {
{ "critical", LOG_CRIT },
{ "error", LOG_ERR },
{ "warning", LOG_WARNING },
{ "notice", LOG_NOTICE },
{ "connect", LOG_CONN },
{ "info", LOG_INFO }
{"critical", LOG_CRIT},
{"error", LOG_ERR},
{"warning", LOG_WARNING},
{"notice", LOG_NOTICE},
{"connect", LOG_CONN},
{"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.
*
@ -19,6 +19,6 @@
#define TINYPROXY_CONFFILE_H
extern int config_compile(void);
extern int config_parse(struct config_s* conf, FILE* f);
extern int config_parse(struct config_s *conf, FILE * f);
#endif

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
@ -27,8 +27,8 @@
#include "stats.h"
struct conn_s *
initialize_conn(int client_fd, const char* ipaddr, const char* string_addr,
const char* sock_ipaddr)
initialize_conn(int client_fd, const char *ipaddr, const char *string_addr,
const char *sock_ipaddr)
{
struct conn_s *connptr;
struct buffer_s *cbuffer, *sbuffer;
@ -86,7 +86,7 @@ initialize_conn(int client_fd, const char* ipaddr, const char* string_addr,
return connptr;
error_exit:
error_exit:
/*
* If we got here, there was a problem allocating memory
*/

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.
*
@ -56,13 +56,13 @@ struct conn_s {
/*
* Store the server's IP (for BindSame)
*/
char* server_ip_addr;
char *server_ip_addr;
/*
* Store the client's IP and hostname information
*/
char* client_ip_addr;
char* client_string_addr;
char *client_ip_addr;
char *client_string_addr;
/*
* Store the incoming request's HTTP protocol.
@ -76,7 +76,7 @@ struct conn_s {
/*
* Place to store the current per-connection reverse proxy path
*/
char* reversepath;
char *reversepath;
#endif
/*
@ -88,9 +88,9 @@ struct conn_s {
/*
* Functions for the creation and destruction of a connection structure.
*/
extern struct conn_s* initialize_conn(int client_fd, const char* ipaddr,
const char* string_addr,
const char* sock_ipaddr);
extern struct conn_s *initialize_conn(int client_fd, const char *ipaddr,
const char *string_addr,
const char *sock_ipaddr);
extern void destroy_conn(struct conn_s *connptr);
#endif

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
@ -56,7 +56,7 @@ makedaemon(void)
* to handle signals sent to the process.
*/
signal_func *
set_signal_handler(int signo, signal_func *func)
set_signal_handler(int signo, signal_func * func)
{
struct sigaction act, oact;

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.
*
@ -23,7 +23,7 @@ typedef void signal_func(int);
/*
* Pass a singal integer and a function to handle the signal.
*/
extern signal_func *set_signal_handler(int signo, signal_func *func);
extern signal_func *set_signal_handler(int signo, signal_func * func);
/*
* Make a program a daemon process

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;
@ -97,7 +97,7 @@ hashfunc(const char *key, unsigned int size)
hashmap_t
hashmap_create(unsigned int nbuckets)
{
struct hashmap_s* ptr;
struct hashmap_s *ptr;
if (nbuckets == 0)
return NULL;
@ -127,7 +127,7 @@ hashmap_create(unsigned int nbuckets)
* negative number is returned if "entry" was NULL
*/
static inline int
delete_hashbucket(struct hashbucket_s* bucket)
delete_hashbucket(struct hashbucket_s *bucket)
{
struct hashentry_s *nextptr;
struct hashentry_s *ptr;
@ -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;
@ -303,11 +302,11 @@ hashmap_is_end(hashmap_t map, hashmap_iter iter)
* an "end-iterator" if the key wasn't found
*/
hashmap_iter
hashmap_find(hashmap_t map, const char* key)
hashmap_find(hashmap_t map, const char *key)
{
unsigned int i;
hashmap_iter iter = 0;
struct hashentry_s* ptr;
struct hashentry_s *ptr;
assert(map != NULL);
assert(key != NULL);
@ -343,11 +342,10 @@ 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;
struct hashentry_s *ptr;
hashmap_iter count = 0;
assert(map != NULL);
@ -388,7 +386,7 @@ ssize_t
hashmap_search(hashmap_t map, const char *key)
{
int hash;
struct hashentry_s* ptr;
struct hashentry_s *ptr;
ssize_t count = 0;
if (map == NULL || key == NULL)
@ -421,10 +419,10 @@ hashmap_search(hashmap_t map, const char *key)
* length of data for the entry
*/
ssize_t
hashmap_entry_by_key(hashmap_t map, const char* key, void** data)
hashmap_entry_by_key(hashmap_t map, const char *key, void **data)
{
int hash;
struct hashentry_s* ptr;
struct hashentry_s *ptr;
if (!map || !key || !data)
return -EINVAL;

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
@ -38,15 +38,15 @@ extern "C" {
* hash map. Sure, it's a pointer, but the struct is hidden in the C file.
* So, just use the hashmap_t like it's a cookie. :)
*/
typedef struct hashmap_s* hashmap_t;
typedef int hashmap_iter;
typedef struct hashmap_s *hashmap_t;
typedef int hashmap_iter;
/*
* hashmap_create() takes one argument, which is the number of buckets to
* use internally. hashmap_delete() is self explanatory.
*/
extern hashmap_t hashmap_create(unsigned int nbuckets);
extern int hashmap_delete(hashmap_t map);
extern hashmap_t hashmap_create(unsigned int nbuckets);
extern int hashmap_delete(hashmap_t map);
/*
* When the you insert a key/data pair into the hashmap it will the key
@ -57,7 +57,7 @@ extern int hashmap_delete(hashmap_t map);
* Returns: negative on error
* 0 upon successful insert
*/
extern int hashmap_insert(hashmap_t map, const char *key,
extern int hashmap_insert(hashmap_t map, const char *key,
const void *data, size_t len);
/*
@ -65,7 +65,7 @@ extern int hashmap_insert(hashmap_t map, const char *key,
*
* Returns: an negative value upon error.
*/
extern hashmap_iter hashmap_first(hashmap_t map);
extern hashmap_iter hashmap_first(hashmap_t map);
/*
* Checks to see if the iterator is pointing at the "end" of the entries.
@ -73,7 +73,7 @@ extern hashmap_iter hashmap_first(hashmap_t map);
* Returns: 1 if it is the end
* 0 otherwise
*/
extern int hashmap_is_end(hashmap_t map, hashmap_iter iter);
extern int hashmap_is_end(hashmap_t map, hashmap_iter iter);
/*
* Return a "pointer" to the first instance of the particular key. It can
@ -83,7 +83,7 @@ extern int hashmap_is_end(hashmap_t map, hashmap_iter iter);
* an "iterator" pointing at the first key
* an "end-iterator" if the key wasn't found
*/
extern hashmap_iter hashmap_find(hashmap_t map, const char* key);
extern hashmap_iter hashmap_find(hashmap_t map, const char *key);
/*
* Retrieve the key/data associated with a particular iterator.
@ -93,8 +93,8 @@ extern hashmap_iter hashmap_find(hashmap_t map, const char* key);
* Returns: the length of the data block upon success
* negative upon error
*/
extern ssize_t hashmap_return_entry(hashmap_t map, hashmap_iter iter,
char** key, void** data);
extern ssize_t hashmap_return_entry(hashmap_t map, hashmap_iter iter,
char **key, void **data);
/*
* Get the first entry (assuming there is more than one) for a particular
@ -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
@ -114,7 +115,7 @@ extern ssize_t hashmap_entry_by_key(hashmap_t map, const char* key, void** data)
* zero if no key is found
* count found (positive value)
*/
extern ssize_t hashmap_search(hashmap_t map, const char *key);
extern ssize_t hashmap_search(hashmap_t map, const char *key);
/*
* Go through the hashmap and remove the particular key.
@ -124,10 +125,9 @@ extern ssize_t hashmap_search(hashmap_t map, const char *key);
* 0 if the key was not found
* positive count of entries deleted
*/
extern ssize_t hashmap_remove(hashmap_t map, const char *key);
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
@ -73,10 +73,10 @@ debugging_free(void *ptr, const char *file, unsigned long line)
return;
}
char*
debugging_strdup(const char* s, const char* file, unsigned long line)
char *
debugging_strdup(const char *s, const char *file, unsigned long line)
{
char* ptr;
char *ptr;
size_t len;
assert(s != NULL);
@ -99,14 +99,14 @@ debugging_strdup(const char* s, const char* file, unsigned long line)
* want to look into something like MM (Shared Memory Library) for a better
* solution.
*/
void*
void *
malloc_shared_memory(size_t size)
{
int fd;
void* ptr;
void *ptr;
char buffer[32];
static char* shared_file = "/tmp/tinyproxy.shared.XXXXXX";
static char *shared_file = "/tmp/tinyproxy.shared.XXXXXX";
assert(size > 0);
@ -118,7 +118,7 @@ malloc_shared_memory(size_t size)
if (ftruncate(fd, size) == -1)
return MAP_FAILED;
ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
return ptr;
}
@ -127,10 +127,10 @@ malloc_shared_memory(size_t size)
* Allocate a block of memory from the "shared" region an initialize it to
* zero.
*/
void*
void *
calloc_shared_memory(size_t nmemb, size_t size)
{
void* ptr;
void *ptr;
long length;
assert(nmemb > 0);
@ -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.
*
@ -30,7 +30,7 @@ extern void *debugging_malloc(size_t size, const char *file,
extern void debugging_free(void *ptr, const char *file, unsigned long line);
extern void *debugging_realloc(void *ptr, size_t size, const char *file,
unsigned long line);
extern char *debugging_strdup(const char* s, const char* file,
extern char *debugging_strdup(const char *s, const char *file,
unsigned long line);
# define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
@ -57,7 +57,7 @@ free(*__safefree_tmp); \
/*
* Allocate memory from the "shared" region of memory.
*/
extern void* malloc_shared_memory(size_t size);
extern void* calloc_shared_memory(size_t nmemb, size_t size);
extern void *malloc_shared_memory(size_t size);
extern void *calloc_shared_memory(size_t nmemb, size_t size);
#endif

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,27 +33,29 @@
#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);
if (!config.errorpages)
return(-1);
return (-1);
snprintf(errornbuf, ERRORNUM_BUFSIZE, "%u", errornum);
if (hashmap_insert(config.errorpages, errornbuf,
filepath, strlen(filepath) + 1) < 0)
return(-1);
return (-1);
return(0);
return (0);
}
/*
* Get the file appropriate for a given error.
*/
static char*
get_html_file(unsigned int errornum) {
static char *
get_html_file(unsigned int errornum)
{
hashmap_iter result_iter;
char errornbuf[ERRORNUM_BUFSIZE];
char *key;
@ -61,27 +63,29 @@ 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);
result_iter = hashmap_find(config.errorpages, errornbuf);
if (hashmap_is_end(config.errorpages, result_iter))
return(config.errorpage_undef);
return (config.errorpage_undef);
if (hashmap_return_entry(config.errorpages, result_iter,
&key, (void **)&val) < 0)
return(config.errorpage_undef);
return (config.errorpage_undef);
return(val);
return (val);
}
/*
* Look up the value for a variable.
*/
static char*
lookup_variable(struct conn_s *connptr, char *varname) {
static char *
lookup_variable(struct conn_s *connptr, char *varname)
{
hashmap_iter result_iter;
char *key;
static char *data;
@ -89,13 +93,13 @@ lookup_variable(struct conn_s *connptr, char *varname) {
result_iter = hashmap_find(connptr->error_variables, varname);
if (hashmap_is_end(connptr->error_variables, result_iter))
return(NULL);
return (NULL);
if (hashmap_return_entry(connptr->error_variables, result_iter,
&key, (void **)&data) < 0)
return(NULL);
return (NULL);
return(data);
return (data);
}
#define HTML_BUFSIZE 4096
@ -104,26 +108,35 @@ 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;
while(fgets(inbuf, HTML_BUFSIZE, infile) != NULL) {
while (fgets(inbuf, HTML_BUFSIZE, infile) != NULL) {
for (p = inbuf; *p; p++) {
switch(*p) {
switch (*p) {
case '}':
if(in_variable) {
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 '{':
@ -133,37 +146,37 @@ send_html_file(FILE *infile, struct conn_s *connptr) {
* this code will fallthrough to the code that
* just dumps a character to the client fd.
*/
if(!in_variable) {
varstart = p+1;
if (!in_variable) {
varstart = p + 1;
in_variable++;
} else
in_variable = 0;
default:
if(!in_variable) {
writeret = write_message(connptr->client_fd, "%c",
*p);
if(writeret) return(writeret);
if (!in_variable) {
writeret =
write_message(connptr->client_fd,
"%c", *p);
if (writeret)
return (writeret);
}
}
}
in_variable = 0;
}
return(0);
return (0);
}
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));
return (write_message(connptr->client_fd, headers,
code, message, PACKAGE, VERSION));
}
/*
@ -175,22 +188,21 @@ 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")))
return(write_message(connptr->client_fd, fallback_error,
if (!(infile = fopen(error_file, "r")))
return (write_message(connptr->client_fd, fallback_error,
connptr->error_string,
PACKAGE, VERSION,
errno, strerror(errno),
@ -198,7 +210,7 @@ send_http_error_message(struct conn_s *connptr)
ret = send_html_file(infile, connptr);
fclose(infile);
return(ret);
return (ret);
}
/*
@ -210,15 +222,17 @@ send_http_error_message(struct conn_s *connptr)
int
add_error_variable(struct conn_s *connptr, char *key, char *val)
{
if(!connptr->error_variables)
if (!(connptr->error_variables = hashmap_create(ERRVAR_BUCKETCOUNT)))
return(-1);
if (!connptr->error_variables)
if (!
(connptr->error_variables =
hashmap_create(ERRVAR_BUCKETCOUNT)))
return (-1);
if (hashmap_insert(connptr->error_variables, key, val,
strlen(val) + 1) < 0)
return(-1);
return (-1);
return(0);
return (0);
}
#define ADD_VAR_RET(x, y) if(y) { if(add_error_variable(connptr, x, y) == -1) return(-1); }
@ -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);
@ -241,25 +256,26 @@ add_standard_vars(struct conn_s *connptr) {
ADD_VAR_RET("version", VERSION);
ADD_VAR_RET("package", PACKAGE);
ADD_VAR_RET("date", timebuf);
return(0);
return (0);
}
/*
* Add the error information to the conn structure.
*/
int
indicate_http_error(struct conn_s* connptr, int number, char *message, ...)
indicate_http_error(struct conn_s *connptr, int number, char *message, ...)
{
va_list ap;
char *key, *val;
va_start(ap, message);
while((key = va_arg(ap, char *))) {
while ((key = va_arg(ap, char *))) {
val = va_arg(ap, char *);
if(add_error_variable(connptr, key, val) == -1) {
if (add_error_variable(connptr, key, val) == -1) {
va_end(ap);
return(-1);
return (-1);
}
}
@ -268,5 +284,5 @@ indicate_http_error(struct conn_s* connptr, int number, char *message, ...)
va_end(ap);
return(add_standard_vars(connptr));
return (add_standard_vars(connptr));
}

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,9 +24,10 @@ 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_html_file(FILE * infile, struct conn_s *connptr);
extern int send_http_headers(struct conn_s *connptr, int code, char *message);
extern int add_standard_vars(struct conn_s *connptr);

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.
*
@ -30,7 +30,7 @@
struct http_message_s {
/* Response string and code supplied on the HTTP status line */
struct {
const char* string;
const char *string;
int code;
} response;
@ -40,14 +40,14 @@ struct http_message_s {
* I might change this to a vector in the future.
*/
struct {
char** strings;
char **strings;
unsigned int total;
unsigned int used;
} headers;
/* Body of the message (most likely an HTML message) */
struct {
const char* text;
const char *text;
size_t length;
} body;
};
@ -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;
}
@ -76,7 +80,7 @@ is_http_message_valid(http_message_t msg)
* If memory could not be allocated, return a NULL.
*/
http_message_t
http_message_create(int response_code, const char* response_string)
http_message_create(int response_code, const char *response_string)
{
http_message_t msg;
int ret;
@ -85,7 +89,7 @@ http_message_create(int response_code, const char* response_string)
if (msg == NULL)
return NULL;
msg->headers.strings = safecalloc(NUMBER_OF_HEADERS, sizeof(char*));
msg->headers.strings = safecalloc(NUMBER_OF_HEADERS, sizeof(char *));
if (msg->headers.strings == NULL) {
safefree(msg);
return NULL;
@ -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;
@ -149,12 +157,15 @@ http_message_set_response(http_message_t msg,
* Set the HTTP message body.
*/
int
http_message_set_body(http_message_t msg, const char* body, size_t len)
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;
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
@ -183,7 +196,7 @@ http_message_add_headers(http_message_t msg, char** headers,
*/
if (msg->headers.used + num_headers > msg->headers.total) {
new_headers = safecalloc(msg->headers.total * 2,
sizeof(char*));
sizeof(char *));
if (new_headers == NULL)
return -ENOMEM;
@ -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
* ----------------
@ -55,7 +55,7 @@ typedef struct http_message_s *http_message_t;
/* Initialize the internal structure of the HTTP message */
extern http_message_t http_message_create(int response_code,
const char* response_string);
const char *response_string);
/* Free up an _internal_ resources */
extern int http_message_destroy(http_message_t msg);
@ -72,10 +72,10 @@ extern int http_message_send(http_message_t msg, int fd);
* add a new set of headers.
*/
extern int http_message_set_body(http_message_t msg,
const char* body, size_t len);
const char *body, size_t len);
extern int http_message_set_response(http_message_t msg,
int response_code,
const char* response_string);
const char *response_string);
/*
* Set the headers for this HTTP message. Each string must be NUL ('\0')
@ -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...
@ -61,7 +61,7 @@ static vector_t log_message_storage;
* Open the log file and store the file descriptor in a global location.
*/
int
open_log_file(const char* log_file_name)
open_log_file(const char *log_file_name)
{
log_file_fd = create_file_safely(log_file_name, FALSE);
return log_file_fd;
@ -133,7 +133,7 @@ log_message(int level, char *fmt, ...)
* the messages for later processing.
*/
if (!processed_config_file) {
char* entry_buffer;
char *entry_buffer;
if (!log_message_storage) {
log_message_storage = vector_create();
@ -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.
*
@ -99,7 +99,7 @@
# define DEBUG2(x, y...) do { } while(0)
#endif
extern int open_log_file(const char* file);
extern int open_log_file(const char *file);
extern void close_log_file(void);
extern void truncate_log_file(void);

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
@ -241,8 +241,8 @@ readline(int fd, char **whole_buffer)
* Convert the network address into either a dotted-decimal or an IPv6
* hex string.
*/
char*
get_ip_string(struct sockaddr* sa, char* buf, size_t buflen)
char *
get_ip_string(struct sockaddr *sa, char *buf, size_t buflen)
{
assert(sa != NULL);
assert(buf != NULL);
@ -250,13 +250,15 @@ get_ip_string(struct sockaddr* sa, char* buf, size_t buflen)
buf[0] = '\0'; /* start with an empty string */
switch (sa->sa_family) {
case AF_INET: {
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: {
case AF_INET6:{
struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)sa;
inet_ntop(AF_INET6, &sa_in6->sin6_addr, buf, buflen);
break;
}
@ -276,7 +278,7 @@ get_ip_string(struct sockaddr* sa, char* buf, size_t buflen)
* Returns the same as inet_pton().
*/
int
full_inet_pton(const char* ip, void* dst)
full_inet_pton(const char *ip, void *dst)
{
char buf[24], tmp[24]; /* IPv4->IPv6 = ::FFFF:xxx.xxx.xxx.xxx\0 */
int n;
@ -289,7 +291,7 @@ full_inet_pton(const char* ip, void* dst)
* older inet_aton() call since it handles more IPv4 numeric
* address formats.
*/
n = inet_aton(ip, (struct in_addr*)dst);
n = inet_aton(ip, (struct in_addr *)dst);
if (n == 0) {
/*
* Simple case: "ip" wasn't an IPv4 numeric address, so

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.
*
@ -24,7 +24,7 @@ extern ssize_t safe_read(int fd, char *buffer, size_t count);
extern int write_message(int fd, const char *fmt, ...);
extern ssize_t readline(int fd, char **whole_buffer);
extern char* get_ip_string(struct sockaddr* sa, char* buf, size_t len);
extern int full_inet_pton(const char* ip, void* dst);
extern char *get_ip_string(struct sockaddr *sa, char *buf, size_t len);
extern int full_inet_pton(const char *ip, void *dst);
#endif

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));
}
@ -198,7 +200,7 @@ free_request_struct(struct request_s *request)
* it off.
*/
static void
strip_username_password(char* host)
strip_username_password(char *host)
{
char *p;
@ -223,7 +225,7 @@ strip_username_password(char* host)
* it off and set proper port variable i.e. for www.host.com:8001
*/
static int
strip_return_port(char* host)
strip_return_port(char *host)
{
char *ptr1;
int port;
@ -340,10 +342,11 @@ void
upstream_add(const char *host, int port, const char *domain)
{
char *ptr;
struct upstream *up = safemalloc(sizeof (struct upstream));
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;
}
@ -426,7 +436,7 @@ upstream_add(const char *host, int port, const char *domain)
return;
upstream_cleanup:
upstream_cleanup:
safefree(up->host);
safefree(up->domain);
safefree(up);
@ -456,7 +466,7 @@ upstream_get(char *host)
break; /* local host matches "." */
while (dot && strcasecmp(dot, up->domain))
dot = strchr(dot+1, '.');
dot = strchr(dot + 1, '.');
if (dot)
break; /* subdomain match */
@ -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()");
if (!(reverse = safemalloc(sizeof(struct reversepath)))) {
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) {
request->host = safemalloc(length + 1);
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;
}
@ -1080,19 +1108,21 @@ get_all_headers(int fd, hashmap_t hashofheaders)
static int
remove_connection_headers(hashmap_t hashofheaders)
{
static char* headers[] = {
static char *headers[] = {
"connection",
"proxy-connection"
};
char *data;
char* ptr;
char *ptr;
ssize_t len;
int i;
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;
}
@ -1264,27 +1296,26 @@ process_client_headers(struct conn_s *connptr, hashmap_t hashofheaders)
*/
iter = hashmap_first(hashofheaders);
if (iter >= 0) {
for ( ; !hashmap_is_end(hashofheaders, iter); ++iter) {
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");
}
}
@ -1457,15 +1498,12 @@ process_server_headers(struct conn_s *connptr)
*/
iter = hashmap_first(hashofheaders);
if (iter >= 0) {
for ( ; !hashmap_is_end(hashofheaders, iter); ++iter) {
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) {
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
@ -35,7 +35,7 @@
* to indicate an error.
*/
static int
bind_socket(int sockfd, const char* addr)
bind_socket(int sockfd, const char *addr)
{
struct addrinfo hints, *res, *ressave;
@ -71,7 +71,7 @@ bind_socket(int sockfd, const char* addr)
* independent implementation (mostly for IPv4 and IPv6 addresses.)
*/
int
opensock(const char* host, int port, const char* bind_to)
opensock(const char *host, int port, const char *bind_to)
{
int sockfd, n;
struct addrinfo hints, *res, *ressave;
@ -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 */
@ -164,7 +165,7 @@ socket_blocking(int sock)
* - rjkaes
*/
int
listen_sock(uint16_t port, socklen_t* addrlen)
listen_sock(uint16_t port, socklen_t * addrlen)
{
int listenfd;
const int on = 1;
@ -186,14 +187,16 @@ listen_sock(uint16_t port, socklen_t* addrlen)
addr.sin_addr.s_addr = inet_addr("0.0.0.0");
}
if (bind(listenfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
log_message(LOG_ERR, "Unable to bind listening socket because of %s",
if (bind(listenfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
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;
}
@ -207,14 +210,14 @@ listen_sock(uint16_t port, socklen_t* addrlen)
* Takes a socket descriptor and returns the socket's IP address.
*/
int
getsock_ip(int fd, char* ipaddr)
getsock_ip(int fd, char *ipaddr)
{
struct sockaddr_storage name;
socklen_t namelen = sizeof(name);
assert(fd >= 0);
if (getsockname(fd, (struct sockaddr *) &name, &namelen) != 0) {
if (getsockname(fd, (struct sockaddr *)&name, &namelen) != 0) {
log_message(LOG_ERR, "getsock_ip: getsockname() error: %s",
strerror(errno));
return -1;
@ -230,7 +233,7 @@ getsock_ip(int fd, char* ipaddr)
* Return the peer's socket information.
*/
int
getpeer_information(int fd, char* ipaddr, char* string_addr)
getpeer_information(int fd, char *ipaddr, char *string_addr)
{
struct sockaddr_storage sa;
size_t salen = sizeof(sa);
@ -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.
*
@ -25,13 +25,13 @@
#define MAXLINE (1024 * 4)
extern int opensock(const char* host, int port, const char* bind_to);
extern int listen_sock(uint16_t port, socklen_t* addrlen);
extern int opensock(const char *host, int port, const char *bind_to);
extern int listen_sock(uint16_t port, socklen_t * addrlen);
extern int socket_nonblocking(int sock);
extern int socket_blocking(int sock);
extern int getsock_ip(int fd, char* ipaddr);
extern int getpeer_information(int fd, char* ipaddr, char* string_addr);
extern int getsock_ip(int fd, char *ipaddr);
extern int getpeer_information(int fd, char *ipaddr, char *string_addr);
#endif

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;
}
@ -153,7 +152,7 @@ main(int argc, char **argv)
unsigned int godaemon = TRUE; /* boolean */
struct passwd *thisuser = NULL;
struct group *thisgroup = NULL;
FILE* config_file;
FILE *config_file;
/*
* Disable the creation of CORE files right up front.
@ -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.
*
@ -81,13 +81,13 @@ struct config_s {
#endif /* UPSTREAM_SUPPORT */
char *pidpath;
unsigned int idletimeout;
char* bind_address;
char *bind_address;
unsigned int bindsame;
/*
* The configured name to use in the HTTP "Via" header field.
*/
char* via_proxy_name;
char *via_proxy_name;
/*
* Error page support. Map error numbers to file paths.

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,
@ -33,7 +33,7 @@ int
send_http_message(struct conn_s *connptr, int http_code,
const char *error_title, const char *message)
{
static char* headers[] = {
static char *headers[] = {
"Server: " PACKAGE "/" VERSION,
"Content-type: text/html",
"Connection: close"
@ -198,7 +198,7 @@ pidfile_create(const char *filename)
return -EIO;
}
fprintf(fd, "%ld\n", (long) getpid());
fprintf(fd, "%ld\n", (long)getpid());
fclose(fd);
return 0;
}

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
@ -175,7 +175,7 @@ vector_prepend(vector_t vector, void *data, ssize_t len)
* length of data if position is valid
*/
void *
vector_getentry(vector_t vector, size_t pos, size_t* size)
vector_getentry(vector_t vector, size_t pos, size_t * size)
{
struct vectorentry_s *ptr;
size_t loc;

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
@ -34,14 +34,14 @@ extern "C" {
* vector. Sure, it's a pointer, but the struct is hidden in the C file.
* So, just use the vector_t like it's a cookie. :)
*/
typedef struct vector_s *vector_t;
typedef struct vector_s *vector_t;
/*
* vector_create() takes no arguments.
* vector_delete() is self explanatory.
*/
extern vector_t vector_create(void);
extern int vector_delete(vector_t vector);
extern vector_t vector_create(void);
extern int vector_delete(vector_t vector);
/*
* When you insert a piece of data into the vector, the data will be
@ -51,8 +51,8 @@ extern int vector_delete(vector_t vector);
* Returns: negative on error
* 0 upon successful insert.
*/
extern int vector_append(vector_t vector, void *data, ssize_t len);
extern int vector_prepend(vector_t vector, void *data, ssize_t len);
extern int vector_append(vector_t vector, void *data, ssize_t len);
extern int vector_prepend(vector_t vector, void *data, ssize_t len);
/*
* A pointer to the data at position "pos" (zero based) is returned and 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.
@ -78,10 +79,9 @@ extern void* vector_getentry(vector_t vector, size_t pos, size_t* size);
* Returns: negative if vector is not valid
* positive length of vector otherwise
*/
extern ssize_t vector_length(vector_t vector);
extern ssize_t vector_length(vector_t vector);
#if defined(__cplusplus)
}
#endif /* C++ */
#endif /* _VECTOR_H */