Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4202928d35 | ||
|
|
2577811738 | ||
|
|
66012c4e8e | ||
|
|
c825db8d56 | ||
|
|
fc94a56f56 | ||
|
|
a328cefbf0 | ||
|
|
22bdb8123d | ||
|
|
c83c92a0d1 |
No files matched your search
@@ -1,3 +1,27 @@
|
||||
2001-08-30 Robert James Kaes <rjkaes@flarenet.com>
|
||||
|
||||
* src/dnscache.c: Removed the insert_data() function and replaced
|
||||
the "replace" logic in dns_insert() with a call to
|
||||
ternary_replace(). This fixes the segmentation fault problem which
|
||||
I introduced when I "tried" to fix the memory leak. Also changed
|
||||
the LOCKing be around the entire dnscache() again since I still
|
||||
need to work out how locking should be done when accessing the
|
||||
ternary tree.
|
||||
|
||||
* src/ternary.c (ternary_insert_replace): Renamed ternary_insert()
|
||||
to ternary_insert_replace() and added a extra argument. The
|
||||
function can now "replace" data already in the tree without
|
||||
causing a memory leak. Added two DEFINES to make coding easier:
|
||||
ternary_insert() and ternary_replace() which both call this
|
||||
function with the right arguments.
|
||||
|
||||
* src/utils.c: Removed xstrstr() since it was only used in once
|
||||
place, and could be safely replaced with strstr. I can't even
|
||||
remember why we had this function to begin with.
|
||||
|
||||
* src/reqs.c (compare_header): Removed the call to xstrstr() since
|
||||
it's been removed from the source.
|
||||
|
||||
2001-08-28 Robert James Kaes <rjkaes@flarenet.com>
|
||||
|
||||
* src/log.c (log_message): Handle a debug enabled compile better.
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
Thursday, August 30, 2001
|
||||
-------------------------
|
||||
|
||||
Maybe I just shouldn't be working on the code base this week. The
|
||||
memory fix I added in the last release contained a serious bug which
|
||||
would cause a segmentation fault. I actually fixed this by removing
|
||||
the code I added and just fixing the problem in ternary_insert()
|
||||
instead. I don't know why I didn't do this in the first place. I also
|
||||
removed the xstrstr() function since strstr() will do what tinyproxy
|
||||
needs. Removing code is _always_ a good idea. Less code, less chance
|
||||
of bugs.
|
||||
|
||||
-- Robert
|
||||
|
||||
|
||||
Wednesday, August 29, 2001
|
||||
--------------------------
|
||||
|
||||
@@ -22,4 +37,4 @@ needed.
|
||||
I would suggest that everyone upgrade to this version; especially
|
||||
anyone who is still running 1.4.0 or below.
|
||||
|
||||
-- Robert
|
||||
-- Robert
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
dnl $Id: configure.in,v 1.23 2001-08-29 15:29:29 rjkaes Exp $
|
||||
dnl $Id: configure.in,v 1.24 2001-08-30 16:54:04 rjkaes Exp $
|
||||
|
||||
dnl Devlopers, please strive to achieve this order:
|
||||
dnl
|
||||
@@ -19,7 +19,7 @@ AC_INIT()
|
||||
AC_CANONICAL_SYSTEM
|
||||
AC_DEFINE_UNQUOTED(TARGET_SYSTEM, "$target")
|
||||
|
||||
AM_INIT_AUTOMAKE(tinyproxy,1.4.2)
|
||||
AM_INIT_AUTOMAKE(tinyproxy,1.4.2.1)
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
|
||||
dnl
|
||||
|
||||
+14
-56
@@ -1,4 +1,4 @@
|
||||
/* $Id: dnscache.c,v 1.10 2001-08-29 03:57:51 rjkaes Exp $
|
||||
/* $Id: dnscache.c,v 1.11 2001-08-30 16:50:42 rjkaes Exp $
|
||||
*
|
||||
* This is a caching DNS system. When a host name is needed we look it up here
|
||||
* and see if there is already an answer for it. The domains are placed in a
|
||||
@@ -51,20 +51,6 @@ struct dnscache_s {
|
||||
|
||||
static TERNARY dns_tree = -1;
|
||||
|
||||
/*
|
||||
* Insert the data into the DNS tree.
|
||||
*/
|
||||
static int insert_data(char *domain, struct dnscache_s *newptr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
LOCK();
|
||||
ret = ternary_insert(dns_tree, domain, newptr);
|
||||
UNLOCK();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dns_lookup(struct in_addr *addr, char *domain)
|
||||
{
|
||||
int ret;
|
||||
@@ -73,17 +59,14 @@ static int dns_lookup(struct in_addr *addr, char *domain)
|
||||
assert(addr != NULL);
|
||||
assert(domain != NULL);
|
||||
|
||||
LOCK();
|
||||
ret = ternary_search(dns_tree, domain, (void *)&ptr);
|
||||
|
||||
if (TE_ISERROR(ret)
|
||||
|| difftime(time(NULL), ptr->expire) > DNSEXPIRE) {
|
||||
UNLOCK();
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(addr, &ptr->ipaddr, sizeof(struct in_addr));
|
||||
UNLOCK();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -91,7 +74,6 @@ static int dns_lookup(struct in_addr *addr, char *domain)
|
||||
static int dns_insert(struct in_addr *addr, char *domain)
|
||||
{
|
||||
struct dnscache_s *newptr;
|
||||
int ret;
|
||||
|
||||
assert(addr != NULL);
|
||||
assert(domain != NULL);
|
||||
@@ -105,37 +87,9 @@ static int dns_insert(struct in_addr *addr, char *domain)
|
||||
memcpy(&newptr->ipaddr, addr, sizeof(struct in_addr));
|
||||
newptr->expire = time(NULL);
|
||||
|
||||
ret = insert_data(domain, newptr);
|
||||
|
||||
if (TE_ISERROR(ret)) {
|
||||
if (ret == TE_EXISTS) {
|
||||
/*
|
||||
* The value already exists. First search for the
|
||||
* value and then delete the data before inserting
|
||||
* the new value.
|
||||
*/
|
||||
struct dnscache_s *existing;
|
||||
|
||||
DEBUG2("[%s] already exists in DNS cache", domain);
|
||||
|
||||
LOCK();
|
||||
ret = ternary_search(dns_tree, domain, (void *)&existing);
|
||||
UNLOCK();
|
||||
|
||||
if (TE_ISERROR(ret))
|
||||
goto INSERT_ERROR;
|
||||
|
||||
safefree(existing);
|
||||
|
||||
ret = insert_data(domain, newptr);
|
||||
|
||||
if (TE_ISERROR(ret))
|
||||
goto INSERT_ERROR;
|
||||
} else {
|
||||
INSERT_ERROR:
|
||||
safefree(newptr);
|
||||
return -1;
|
||||
}
|
||||
if (TE_ISERROR(ternary_replace(dns_tree, domain, newptr))) {
|
||||
safefree(newptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -148,30 +102,34 @@ int dnscache(struct in_addr *addr, char *domain)
|
||||
assert(addr != NULL);
|
||||
assert(domain != NULL);
|
||||
|
||||
/* If the DNS tree doesn't exist, build a new one */
|
||||
LOCK();
|
||||
|
||||
/* If the DNS tree doesn't exist, build a new one */
|
||||
if (dns_tree < 0)
|
||||
dns_tree = ternary_new();
|
||||
UNLOCK();
|
||||
|
||||
if (inet_aton(domain, (struct in_addr *)addr) != 0)
|
||||
if (inet_aton(domain, (struct in_addr *)addr) != 0) {
|
||||
UNLOCK();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Well, we're not dotted-decimal so we need to look it up */
|
||||
if (dns_lookup(addr, domain) == 0)
|
||||
if (dns_lookup(addr, domain) == 0) {
|
||||
UNLOCK();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Okay, so not in the list... need to actually look it up. */
|
||||
LOCK();
|
||||
if (!(resolv = gethostbyname(domain))) {
|
||||
UNLOCK();
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(addr, resolv->h_addr_list[0], (size_t)resolv->h_length);
|
||||
UNLOCK();
|
||||
|
||||
dns_insert(addr, domain);
|
||||
|
||||
UNLOCK();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
/* $Id: reqs.c,v 1.17 2001-08-28 04:32:14 rjkaes Exp $
|
||||
/* $Id: reqs.c,v 1.18 2001-08-30 16:51:10 rjkaes Exp $
|
||||
*
|
||||
* This is where all the work in tinyproxy is actually done. Incoming
|
||||
* connections have a new thread created for them. The thread then
|
||||
@@ -326,7 +326,7 @@ static int compare_header(char *line)
|
||||
char *ptr;
|
||||
int ret;
|
||||
|
||||
if ((ptr = xstrstr(line, ":", strlen(line), FALSE)) == NULL)
|
||||
if ((ptr = strstr(line, ":")) == NULL)
|
||||
return -1;
|
||||
|
||||
if ((buffer = malloc(ptr - line + 1)) == NULL)
|
||||
|
||||
+10
-3
@@ -1,4 +1,4 @@
|
||||
/* $Id: ternary.c,v 1.5 2001-05-23 17:59:53 rjkaes Exp $
|
||||
/* $Id: ternary.c,v 1.6 2001-08-30 16:52:09 rjkaes Exp $
|
||||
*
|
||||
* This module creates a Ternary Search Tree which can store both string
|
||||
* keys, and arbitrary data for each key. It works similar to a hash, and
|
||||
@@ -294,7 +294,8 @@ int ternary_destroy(TERNARY tno, void (*freeptr)(void *))
|
||||
* TE_TOOFULL tree is full, so no new elements can be added.
|
||||
* Exceptions: none
|
||||
*/
|
||||
int ternary_insert(TERNARY tno, const char *s, void *data)
|
||||
int ternary_insert_replace(TERNARY tno, const char *s, void *data,
|
||||
short int replace)
|
||||
{
|
||||
int cur; /* index of current tree */
|
||||
Ttree *tree; /* pointer to tree structure */
|
||||
@@ -314,7 +315,13 @@ int ternary_insert(TERNARY tno, const char *s, void *data)
|
||||
while ((pp = *p)) {
|
||||
if ((d = *s - pp->splitchar) == 0) {
|
||||
if (*s++ == 0) {
|
||||
return TE_EXISTS;
|
||||
if (!replace)
|
||||
return TE_EXISTS;
|
||||
else {
|
||||
free(pp->eqkid);
|
||||
pp->eqkid = (Tnode *)data;
|
||||
return TE_NONE;
|
||||
}
|
||||
}
|
||||
p = &(pp->eqkid);
|
||||
} else if (d < 0)
|
||||
|
||||
+6
-2
@@ -1,4 +1,4 @@
|
||||
/* $Id: ternary.h,v 1.2 2000-09-26 04:59:20 rjkaes Exp $
|
||||
/* $Id: ternary.h,v 1.3 2001-08-30 16:52:09 rjkaes Exp $
|
||||
*
|
||||
* See 'ternary.c' for a detailed description.
|
||||
*
|
||||
@@ -58,7 +58,11 @@ extern char te_errbuf[256];
|
||||
extern TERNARY ternary_new(void);
|
||||
extern int ternary_destroy(TERNARY tno, void (*freeptr)(void *));
|
||||
|
||||
extern int ternary_insert(TERNARY tno, const char *s, void *data);
|
||||
#define ternary_insert(x, y, z) ternary_insert_replace(x, y, z, 0)
|
||||
#define ternary_replace(x, y, z) ternary_insert_replace(x, y, z, 1)
|
||||
|
||||
extern int ternary_insert_replace(TERNARY tno, const char *s, void *data,
|
||||
short int replace);
|
||||
extern int ternary_search(TERNARY tno, const char *s, void **data);
|
||||
|
||||
#endif
|
||||
+1
-29
@@ -1,4 +1,4 @@
|
||||
/* $Id: utils.c,v 1.7 2001-08-28 04:33:54 rjkaes Exp $
|
||||
/* $Id: utils.c,v 1.8 2001-08-30 16:52:56 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,
|
||||
@@ -30,34 +30,6 @@
|
||||
#include "sock.h"
|
||||
#include "utils.h"
|
||||
|
||||
/*
|
||||
* Find the start of the needle in the haystack. Limits the search to less
|
||||
* than "length" characters. Returns NULL if the needle is not found.
|
||||
*/
|
||||
char *xstrstr(char *haystack, char *needle, size_t length,
|
||||
bool_t case_sensitive)
|
||||
{
|
||||
unsigned int i;
|
||||
/* Used to specify which function to use... need the decl. */
|
||||
int (*fn) (const char *s1, const char *s2, size_t n);
|
||||
|
||||
if (case_sensitive)
|
||||
fn = strncmp;
|
||||
else
|
||||
fn = strncasecmp;
|
||||
|
||||
if (strlen(needle) > length)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i <= length - strlen(needle); i++) {
|
||||
if ((*fn) (haystack + i, needle, strlen(needle)) == 0)
|
||||
return (haystack + i);
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Display an error to the client.
|
||||
*/
|
||||
|
||||
+1
-4
@@ -1,4 +1,4 @@
|
||||
/* $Id: utils.h,v 1.5 2001-08-27 03:45:34 rjkaes Exp $
|
||||
/* $Id: utils.h,v 1.6 2001-08-30 16:52:56 rjkaes Exp $
|
||||
*
|
||||
* See 'utils.h' for a detailed description.
|
||||
*
|
||||
@@ -21,9 +21,6 @@
|
||||
|
||||
#include "tinyproxy.h"
|
||||
|
||||
extern char *xstrstr(char *haystack, char *needle, size_t length,
|
||||
bool_t case_sensitive);
|
||||
|
||||
extern int httperr(struct conn_s *connptr, int err, const char *msg);
|
||||
|
||||
extern void makedaemon(void);
|
||||
|
||||
Reference in new issue
Block a user