Added ASSERT statements.

This commit is contained in:
Robert James Kaes 2001-05-23 18:01:23 +00:00
parent 86313eb6f5
commit d32e0d1ccb
4 changed files with 60 additions and 5 deletions

View File

@ -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 * 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 * the anonymous feature is turned on. The headers are stored in a Ternary
@ -23,6 +23,7 @@
#endif #endif
#include <sys/types.h> #include <sys/types.h>
#include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -40,10 +41,14 @@ int new_anonymous(void)
int anon_search(char *s) int anon_search(char *s)
{ {
assert(s != NULL);
return ternary_search(anonymous_tree, s, NULL); return ternary_search(anonymous_tree, s, NULL);
} }
void anon_insert(char *s) void anon_insert(char *s)
{ {
assert(s != NULL);
ternary_insert(anonymous_tree, s, NULL); ternary_insert(anonymous_tree, s, NULL);
} }

View File

@ -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 * 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, * 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) unsigned int buffer_size(struct buffer_s *buffptr)
{ {
assert(buffptr != NULL);
return buffptr->size; return buffptr->size;
} }
@ -59,6 +61,8 @@ static struct bufline_s *makenewline(unsigned char *data, unsigned int length)
{ {
struct bufline_s *newline; struct bufline_s *newline;
assert(data != NULL);
if (!(newline = malloc(sizeof(struct bufline_s)))) if (!(newline = malloc(sizeof(struct bufline_s))))
return NULL; 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) static void free_line(struct bufline_s *line)
{ {
assert(line != NULL);
if (!line) if (!line)
return; return;
@ -108,6 +114,8 @@ void delete_buffer(struct buffer_s *buffptr)
{ {
struct bufline_s *next; struct bufline_s *next;
assert(buffptr != NULL);
while (BUFFER_HEAD(buffptr)) { while (BUFFER_HEAD(buffptr)) {
next = BUFFER_HEAD(buffptr)->next; next = BUFFER_HEAD(buffptr)->next;
free_line(BUFFER_HEAD(buffptr)); 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; struct bufline_s *newline;
assert(buffptr != NULL);
assert(data != NULL);
if (!(newline = makenewline(data, length))) if (!(newline = makenewline(data, length)))
return -1; return -1;
@ -148,6 +159,8 @@ static struct bufline_s *remove_from_buffer(struct buffer_s *buffptr)
{ {
struct bufline_s *line; struct bufline_s *line;
assert(buffptr != NULL);
if (!BUFFER_HEAD(buffptr) && !BUFFER_TAIL(buffptr)) { if (!BUFFER_HEAD(buffptr) && !BUFFER_TAIL(buffptr)) {
line = BUFFER_HEAD(buffptr); line = BUFFER_HEAD(buffptr);
BUFFER_HEAD(buffptr) = BUFFER_TAIL(buffptr) = NULL; 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 inbuf[MAXBUFFSIZE];
unsigned char *buffer; unsigned char *buffer;
assert(fd >= 0);
assert(buffptr != NULL);
if (buffer_size(buffptr) >= MAXBUFFSIZE) if (buffer_size(buffptr) >= MAXBUFFSIZE)
return 0; return 0;
@ -221,7 +237,12 @@ int readbuff(int fd, struct buffer_s *buffptr)
int writebuff(int fd, struct buffer_s *buffptr) int writebuff(int fd, struct buffer_s *buffptr)
{ {
int bytessent; 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) if (buffer_size(buffptr) <= 0)
return 0; return 0;

View File

@ -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 * 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 * and see if there is already an answer for it. The domains are placed in a
@ -25,6 +25,7 @@
#endif #endif
#include <sys/types.h> #include <sys/types.h>
#include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
@ -53,6 +54,9 @@ static int dns_lookup(struct in_addr *addr, char *domain)
{ {
struct dnscache_s *ptr; struct dnscache_s *ptr;
assert(addr != NULL);
assert(domain != NULL);
if (TE_ISERROR(ternary_search(dns_tree, domain, (void *)&ptr))) if (TE_ISERROR(ternary_search(dns_tree, domain, (void *)&ptr)))
return -1; return -1;
@ -68,6 +72,9 @@ static int dns_insert(struct in_addr *addr, char *domain)
{ {
struct dnscache_s *newptr; struct dnscache_s *newptr;
assert(addr != NULL);
assert(domain != NULL);
if (!(newptr = malloc(sizeof(struct dnscache_s)))) { if (!(newptr = malloc(sizeof(struct dnscache_s)))) {
return -1; return -1;
} }
@ -85,6 +92,9 @@ int dnscache(struct in_addr *addr, char *domain)
{ {
struct hostent *resolv; struct hostent *resolv;
assert(addr != NULL);
assert(domain != NULL);
if (inet_aton(domain, (struct in_addr *) addr) != 0) if (inet_aton(domain, (struct in_addr *) addr) != 0)
return 0; return 0;

View File

@ -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 * 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 * 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; struct sockaddr_in port_info;
int ret; int ret;
assert(ip_addr != NULL);
assert(port > 0);
memset((SA *) &port_info, 0, sizeof(port_info)); memset((SA *) &port_info, 0, sizeof(port_info));
port_info.sin_family = AF_INET; port_info.sin_family = AF_INET;
@ -98,6 +101,8 @@ int socket_nonblocking(int sock)
{ {
int flags; int flags;
assert(sock >= 0);
flags = fcntl(sock, F_GETFL, 0); flags = fcntl(sock, F_GETFL, 0);
return fcntl(sock, F_SETFL, flags | O_NONBLOCK); return fcntl(sock, F_SETFL, flags | O_NONBLOCK);
} }
@ -109,6 +114,8 @@ int socket_blocking(int sock)
{ {
int flags; int flags;
assert(sock >= 0);
flags = fcntl(sock, F_GETFL, 0); flags = fcntl(sock, F_GETFL, 0);
return fcntl(sock, F_SETFL, flags & ~O_NONBLOCK); 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; const int on = 1;
struct sockaddr_in addr; struct sockaddr_in addr;
assert(port > 0);
assert(addrlen != NULL);
listenfd = socket(AF_INET, SOCK_STREAM, 0); listenfd = socket(AF_INET, SOCK_STREAM, 0);
setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
@ -156,6 +166,9 @@ char *getpeer_ip(int fd, char *ipaddr)
struct sockaddr_in name; struct sockaddr_in name;
int namelen = sizeof(name); int namelen = sizeof(name);
assert(fd >= 0);
assert(ipaddr != NULL);
if (getpeername(fd, (struct sockaddr *) &name, &namelen) != 0) { if (getpeername(fd, (struct sockaddr *) &name, &namelen) != 0) {
log(LOG_ERR, "Connect: 'could not get peer name'"); log(LOG_ERR, "Connect: 'could not get peer name'");
} else { } else {
@ -177,6 +190,9 @@ char *getpeer_string(int fd, char *string)
int namelen = sizeof(name); int namelen = sizeof(name);
struct hostent *peername; struct hostent *peername;
assert(fd >= 0);
assert(string != NULL);
if (getpeername(fd, (struct sockaddr *) &name, &namelen) != 0) { if (getpeername(fd, (struct sockaddr *) &name, &namelen) != 0) {
log(LOG_ERR, "Connect: 'could not get peer name'"); log(LOG_ERR, "Connect: 'could not get peer name'");
} else { } else {
@ -198,6 +214,9 @@ ssize_t readline(int fd, void *vptr, size_t maxlen)
ssize_t n, rc; ssize_t n, rc;
char c, *ptr; char c, *ptr;
assert(fd >= 0);
assert(vptr != NULL);
ptr = vptr; ptr = vptr;
for (n = 1; n < maxlen; n++) { for (n = 1; n < maxlen; n++) {
again: again: