summaryrefslogtreecommitdiffhomepage
path: root/src/conns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/conns.c')
-rw-r--r--src/conns.c60
1 files changed, 29 insertions, 31 deletions
diff --git a/src/conns.c b/src/conns.c
index 3859d69..ca8f24e 100644
--- a/src/conns.c
+++ b/src/conns.c
@@ -30,14 +30,21 @@
#include "log.h"
#include "stats.h"
-struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
- const char *string_addr,
- const char *sock_ipaddr)
+void conn_struct_init(struct conn_s *connptr) {
+ connptr->error_number = -1;
+ connptr->client_fd = -1;
+ connptr->server_fd = -1;
+ /* There is _no_ content length initially */
+ connptr->content_length.server = connptr->content_length.client = -1;
+}
+
+int conn_init_contents (struct conn_s *connptr, const char *ipaddr,
+ const char *sock_ipaddr,
+ const char *sock_ipaddr_alt)
{
- struct conn_s *connptr;
struct buffer_s *cbuffer, *sbuffer;
- assert (client_fd >= 0);
+ assert (connptr->client_fd >= 0);
/*
* Allocate the memory for all the internal components
@@ -48,16 +55,6 @@ struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
if (!cbuffer || !sbuffer)
goto error_exit;
- /*
- * Allocate the space for the conn_s structure itself.
- */
- connptr = (struct conn_s *) safemalloc (sizeof (struct conn_s));
- if (!connptr)
- goto error_exit;
-
- connptr->client_fd = client_fd;
- connptr->server_fd = -1;
-
connptr->cbuffer = cbuffer;
connptr->sbuffer = sbuffer;
@@ -78,18 +75,13 @@ struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
connptr->server_ip_addr = (sock_ipaddr ?
safestrdup (sock_ipaddr) : NULL);
+ connptr->server_ip_addr_alt = (sock_ipaddr_alt ?
+ safestrdup (sock_ipaddr_alt) : NULL);
connptr->client_ip_addr = safestrdup (ipaddr);
- connptr->client_string_addr = safestrdup (string_addr);
-
- connptr->upstream_proxy = NULL;
update_stats (STAT_OPEN);
-#ifdef REVERSE_SUPPORT
- connptr->reversepath = NULL;
-#endif
-
- return connptr;
+ return 1;
error_exit:
/*
@@ -100,10 +92,10 @@ error_exit:
if (sbuffer)
delete_buffer (sbuffer);
- return NULL;
+ return 0;
}
-void destroy_conn (struct conn_s *connptr)
+void conn_destroy_contents (struct conn_s *connptr)
{
assert (connptr != NULL);
@@ -111,10 +103,12 @@ void destroy_conn (struct conn_s *connptr)
if (close (connptr->client_fd) < 0)
log_message (LOG_INFO, "Client (%d) close message: %s",
connptr->client_fd, strerror (errno));
+ connptr->client_fd = -1;
if (connptr->server_fd != -1)
if (close (connptr->server_fd) < 0)
log_message (LOG_INFO, "Server (%d) close message: %s",
connptr->server_fd, strerror (errno));
+ connptr->server_fd = -1;
if (connptr->cbuffer)
delete_buffer (connptr->cbuffer);
@@ -124,8 +118,16 @@ void destroy_conn (struct conn_s *connptr)
if (connptr->request_line)
safefree (connptr->request_line);
- if (connptr->error_variables)
- hashmap_delete (connptr->error_variables);
+ if (connptr->error_variables) {
+ char *k;
+ htab_value *v;
+ size_t it = 0;
+ while((it = htab_next(connptr->error_variables, it, &k, &v))) {
+ safefree(v->p);
+ safefree(k);
+ }
+ htab_destroy (connptr->error_variables);
+ }
if (connptr->error_string)
safefree (connptr->error_string);
@@ -134,15 +136,11 @@ void destroy_conn (struct conn_s *connptr)
safefree (connptr->server_ip_addr);
if (connptr->client_ip_addr)
safefree (connptr->client_ip_addr);
- if (connptr->client_string_addr)
- safefree (connptr->client_string_addr);
#ifdef REVERSE_SUPPORT
if (connptr->reversepath)
safefree (connptr->reversepath);
#endif
- safefree (connptr);
-
update_stats (STAT_CLOSE);
}