diff options
-rw-r--r-- | src/anonymous.c | 7 | ||||
-rw-r--r-- | src/buffer.c | 25 | ||||
-rw-r--r-- | src/dnscache.c | 12 | ||||
-rw-r--r-- | src/sock.c | 21 |
4 files changed, 60 insertions, 5 deletions
diff --git a/src/anonymous.c b/src/anonymous.c index d99d46e..f346ccb 100644 --- a/src/anonymous.c +++ b/src/anonymous.c @@ -1,4 +1,4 @@ -/* $Id: anonymous.c,v 1.3 2000-10-23 21:43:52 rjkaes Exp $ +/* $Id: anonymous.c,v 1.4 2001-05-23 18:01:23 rjkaes Exp $ * * Handles insertion and searches for headers which should be let through when * the anonymous feature is turned on. The headers are stored in a Ternary @@ -23,6 +23,7 @@ #endif #include <sys/types.h> +#include <assert.h> #include <ctype.h> #include <stdlib.h> #include <unistd.h> @@ -40,10 +41,14 @@ int new_anonymous(void) int anon_search(char *s) { + assert(s != NULL); + return ternary_search(anonymous_tree, s, NULL); } void anon_insert(char *s) { + assert(s != NULL); + ternary_insert(anonymous_tree, s, NULL); } diff --git a/src/buffer.c b/src/buffer.c index 3d0d0c1..c38dc30 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1,4 +1,4 @@ -/* $Id: buffer.c,v 1.3 2000-09-11 23:41:32 rjkaes Exp $ +/* $Id: buffer.c,v 1.4 2001-05-23 18:01:23 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, @@ -48,6 +48,8 @@ struct buffer_s { */ unsigned int buffer_size(struct buffer_s *buffptr) { + assert(buffptr != NULL); + return buffptr->size; } @@ -59,6 +61,8 @@ static struct bufline_s *makenewline(unsigned char *data, unsigned int length) { struct bufline_s *newline; + assert(data != NULL); + if (!(newline = malloc(sizeof(struct bufline_s)))) return NULL; @@ -75,6 +79,8 @@ static struct bufline_s *makenewline(unsigned char *data, unsigned int length) */ static void free_line(struct bufline_s *line) { + assert(line != NULL); + if (!line) return; @@ -108,6 +114,8 @@ void delete_buffer(struct buffer_s *buffptr) { struct bufline_s *next; + assert(buffptr != NULL); + while (BUFFER_HEAD(buffptr)) { next = BUFFER_HEAD(buffptr)->next; free_line(BUFFER_HEAD(buffptr)); @@ -127,6 +135,9 @@ static int add_to_buffer(struct buffer_s *buffptr, unsigned char *data, { struct bufline_s *newline; + assert(buffptr != NULL); + assert(data != NULL); + if (!(newline = makenewline(data, length))) return -1; @@ -148,6 +159,8 @@ static struct bufline_s *remove_from_buffer(struct buffer_s *buffptr) { struct bufline_s *line; + assert(buffptr != NULL); + if (!BUFFER_HEAD(buffptr) && !BUFFER_TAIL(buffptr)) { line = BUFFER_HEAD(buffptr); BUFFER_HEAD(buffptr) = BUFFER_TAIL(buffptr) = NULL; @@ -176,6 +189,9 @@ int readbuff(int fd, struct buffer_s *buffptr) unsigned char inbuf[MAXBUFFSIZE]; unsigned char *buffer; + assert(fd >= 0); + assert(buffptr != NULL); + if (buffer_size(buffptr) >= MAXBUFFSIZE) return 0; @@ -221,7 +237,12 @@ int readbuff(int fd, struct buffer_s *buffptr) int writebuff(int fd, struct buffer_s *buffptr) { int bytessent; - struct bufline_s *line = BUFFER_HEAD(buffptr); + struct bufline_s *line; + + assert(fd >= 0); + assert(buffptr != NULL); + + line = BUFFER_HEAD(buffptr); if (buffer_size(buffptr) <= 0) return 0; diff --git a/src/dnscache.c b/src/dnscache.c index dc3fd87..46b5747 100644 --- a/src/dnscache.c +++ b/src/dnscache.c @@ -1,4 +1,4 @@ -/* $Id: dnscache.c,v 1.7 2000-10-23 21:42:31 rjkaes Exp $ +/* $Id: dnscache.c,v 1.8 2001-05-23 18:01:23 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 @@ -25,6 +25,7 @@ #endif #include <sys/types.h> +#include <assert.h> #include <ctype.h> #include <unistd.h> @@ -53,6 +54,9 @@ static int dns_lookup(struct in_addr *addr, char *domain) { struct dnscache_s *ptr; + assert(addr != NULL); + assert(domain != NULL); + if (TE_ISERROR(ternary_search(dns_tree, domain, (void *)&ptr))) return -1; @@ -68,6 +72,9 @@ static int dns_insert(struct in_addr *addr, char *domain) { struct dnscache_s *newptr; + assert(addr != NULL); + assert(domain != NULL); + if (!(newptr = malloc(sizeof(struct dnscache_s)))) { return -1; } @@ -85,6 +92,9 @@ int dnscache(struct in_addr *addr, char *domain) { struct hostent *resolv; + assert(addr != NULL); + assert(domain != NULL); + if (inet_aton(domain, (struct in_addr *) addr) != 0) return 0; @@ -1,4 +1,4 @@ -/* $Id: sock.c,v 1.3 2000-09-11 23:56:32 rjkaes Exp $ +/* $Id: sock.c,v 1.4 2001-05-23 18:01:23 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 @@ -59,6 +59,9 @@ int opensock(char *ip_addr, int port) struct sockaddr_in port_info; int ret; + assert(ip_addr != NULL); + assert(port > 0); + memset((SA *) &port_info, 0, sizeof(port_info)); port_info.sin_family = AF_INET; @@ -98,6 +101,8 @@ int socket_nonblocking(int sock) { int flags; + assert(sock >= 0); + flags = fcntl(sock, F_GETFL, 0); return fcntl(sock, F_SETFL, flags | O_NONBLOCK); } @@ -109,6 +114,8 @@ int socket_blocking(int sock) { int flags; + assert(sock >= 0); + flags = fcntl(sock, F_GETFL, 0); return fcntl(sock, F_SETFL, flags & ~O_NONBLOCK); } @@ -125,6 +132,9 @@ int listen_sock(unsigned int port, socklen_t *addrlen) const int on = 1; struct sockaddr_in addr; + assert(port > 0); + assert(addrlen != NULL); + listenfd = socket(AF_INET, SOCK_STREAM, 0); setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); @@ -156,6 +166,9 @@ char *getpeer_ip(int fd, char *ipaddr) struct sockaddr_in name; int namelen = sizeof(name); + assert(fd >= 0); + assert(ipaddr != NULL); + if (getpeername(fd, (struct sockaddr *) &name, &namelen) != 0) { log(LOG_ERR, "Connect: 'could not get peer name'"); } else { @@ -177,6 +190,9 @@ char *getpeer_string(int fd, char *string) int namelen = sizeof(name); struct hostent *peername; + assert(fd >= 0); + assert(string != NULL); + if (getpeername(fd, (struct sockaddr *) &name, &namelen) != 0) { log(LOG_ERR, "Connect: 'could not get peer name'"); } else { @@ -198,6 +214,9 @@ ssize_t readline(int fd, void *vptr, size_t maxlen) ssize_t n, rc; char c, *ptr; + assert(fd >= 0); + assert(vptr != NULL); + ptr = vptr; for (n = 1; n < maxlen; n++) { again: |