diff options
author | rofl0r <rofl0r@users.noreply.github.com> | 2020-09-16 02:07:52 +0100 |
---|---|---|
committer | rofl0r <rofl0r@users.noreply.github.com> | 2020-09-16 02:39:09 +0100 |
commit | e843519fb899f36780756894f634238d67857ad8 (patch) | |
tree | bf055a1327a9fdae1e80b0a30c49f3590123e33f | |
parent | a5381223df30968054c61dffd8bb81b2a29a1535 (diff) |
listen_addrs: use sblist
-rw-r--r-- | src/child.c | 17 | ||||
-rw-r--r-- | src/child.h | 4 | ||||
-rw-r--r-- | src/conf.c | 29 | ||||
-rw-r--r-- | src/conf.h | 2 | ||||
-rw-r--r-- | src/transparent-proxy.c | 10 |
5 files changed, 33 insertions, 29 deletions
diff --git a/src/child.c b/src/child.c index bec0ca3..89a081c 100644 --- a/src/child.c +++ b/src/child.c @@ -251,10 +251,10 @@ void child_free_children(void) { /** * Listen on the various configured interfaces */ -int child_listening_sockets(vector_t listen_addrs, uint16_t port) +int child_listening_sockets(sblist *listen_addrs, uint16_t port) { int ret; - ssize_t i; + size_t i; assert (port > 0); @@ -267,8 +267,7 @@ int child_listening_sockets(vector_t listen_addrs, uint16_t port) } } - if ((listen_addrs == NULL) || - (vector_length(listen_addrs) == 0)) + if (!listen_addrs || !sblist_getsize(listen_addrs)) { /* * no Listen directive: @@ -278,17 +277,17 @@ int child_listening_sockets(vector_t listen_addrs, uint16_t port) return ret; } - for (i = 0; i < vector_length(listen_addrs); i++) { - const char *addr; + for (i = 0; i < sblist_getsize(listen_addrs); i++) { + char **addr; - addr = (char *)vector_getentry(listen_addrs, i, NULL); - if (addr == NULL) { + addr = sblist_get(listen_addrs, i); + if (!addr || !*addr) { log_message(LOG_WARNING, "got NULL from listen_addrs - skipping"); continue; } - ret = listen_sock(addr, port, listen_fds); + ret = listen_sock(*addr, port, listen_fds); if (ret != 0) { return ret; } diff --git a/src/child.h b/src/child.h index efc6fe3..ffcd9d0 100644 --- a/src/child.h +++ b/src/child.h @@ -21,7 +21,7 @@ #ifndef TINYPROXY_CHILD_H #define TINYPROXY_CHILD_H -#include "vector.h" +#include "sblist.h" typedef enum { CHILD_MAXCLIENTS, @@ -32,7 +32,7 @@ typedef enum { } child_config_t; extern short int child_pool_create (void); -extern int child_listening_sockets (vector_t listen_addrs, uint16_t port); +extern int child_listening_sockets (sblist *listen_addrs, uint16_t port); extern void child_close_sock (void); extern void child_main_loop (void); extern void child_kill_children (int sig); @@ -287,23 +287,29 @@ free_added_headers (sblist* add_headers) sblist_free (add_headers); } +static void stringlist_free(sblist *sl) { + size_t i; + char **s; + if(sl) { + for(i = 0; i < sblist_getsize(sl); i++) { + s = sblist_get(sl, i); + if(s) safefree(*s); + } + sblist_free(sl); + } +} + void free_config (struct config_s *conf) { - char *k, **s; + char *k; htab_value *v; size_t it; safefree (conf->logf_name); safefree (conf->stathost); safefree (conf->user); safefree (conf->group); - vector_delete(conf->listen_addrs); - if(conf->basicauth_list) { - for(it = 0; it < sblist_getsize(conf->basicauth_list); it++) { - s = sblist_get(conf->basicauth_list, it); - if(s) safefree(*s); - } - sblist_free(conf->basicauth_list); - } + stringlist_free(conf->basicauth_list); + stringlist_free(conf->listen_addrs); #ifdef FILTER_ENABLE safefree (conf->filter); #endif /* FILTER_ENABLE */ @@ -813,7 +819,7 @@ static HANDLE_FUNC (handle_listen) } if (conf->listen_addrs == NULL) { - conf->listen_addrs = vector_create(); + conf->listen_addrs = sblist_new(sizeof(char*), 16); if (conf->listen_addrs == NULL) { log_message(LOG_WARNING, "Could not create a list " "of listen addresses."); @@ -822,11 +828,10 @@ static HANDLE_FUNC (handle_listen) } } - vector_append (conf->listen_addrs, arg, strlen(arg) + 1); + sblist_add (conf->listen_addrs, &arg); log_message(LOG_INFO, "Added address [%s] to listen addresses.", arg); - safefree (arg); return 0; } @@ -47,7 +47,7 @@ struct config_s { unsigned int maxclients; char *user; char *group; - vector_t listen_addrs; + sblist *listen_addrs; #ifdef FILTER_ENABLE char *filter; unsigned int filter_url; /* boolean */ diff --git a/src/transparent-proxy.c b/src/transparent-proxy.c index e40bce2..e3265f9 100644 --- a/src/transparent-proxy.c +++ b/src/transparent-proxy.c @@ -60,7 +60,7 @@ do_transparent_proxy (struct conn_s *connptr, orderedmap hashofheaders, socklen_t length; char *data; size_t ulen = strlen (*url); - ssize_t i; + size_t i; data = orderedmap_find (hashofheaders, "host"); if (!data) { @@ -123,12 +123,12 @@ do_transparent_proxy (struct conn_s *connptr, orderedmap hashofheaders, return 1; } - for (i = 0; i < vector_length(conf->listen_addrs); i++) { - const char *addr; + for (i = 0; i < sblist_getsize(conf->listen_addrs); i++) { + char **addr; - addr = (char *)vector_getentry(conf->listen_addrs, i, NULL); + addr = sblist_get(conf->listen_addrs, i); - if (addr && strcmp(request->host, addr) == 0) { + if (addr && *addr && strcmp(request->host, *addr) == 0) { log_message(LOG_ERR, "transparent: destination IP %s is local " "on socket fd %d", |