From 8b4b8c3fb0e960bba43c25826cb1b2bf6c6a3376 Mon Sep 17 00:00:00 2001 From: bol-van Date: Thu, 31 Oct 2024 19:59:26 +0300 Subject: [PATCH] nfqws,tpws: remove unneeded code --- nfq/helpers.c | 47 ----------------------------------------------- nfq/helpers.h | 3 --- nfq/nfqws.c | 11 ++++------- nfq/params.h | 4 ++-- tpws/helpers.c | 47 ----------------------------------------------- tpws/helpers.h | 3 --- tpws/params.h | 5 +++-- tpws/tpws.c | 11 ++++------- 8 files changed, 13 insertions(+), 118 deletions(-) diff --git a/nfq/helpers.c b/nfq/helpers.c index 9b563d0..2d2d320 100644 --- a/nfq/helpers.c +++ b/nfq/helpers.c @@ -8,8 +8,6 @@ #include #include #include -#include -#include #include "params.h" @@ -505,48 +503,3 @@ bool parse_cidr6(char *s, struct cidr6 *cidr) if (p) *p=d; // restore char return b; } - - -void free_command_line(char **argv, int argc) -{ - int i; - if (argv) - { - for (i = 0; i < argc; i++) - if (argv[i]) free(argv[i]); - free(argv); - } -} - -char **split_command_line(const char *cmdline, int *argc) -{ - int i; - char **argv = NULL; - wordexp_t p; - - *argc=0; - - // Note! This expands shell variables. - if (!cmdline || wordexp(cmdline, &p, WRDE_NOCMD)) - return NULL; - - if (!(argv = malloc(p.we_wordc * sizeof(char *)))) - { - wordfree(&p); - return NULL; - } - - for (i = 0; i < p.we_wordc; i++) - { - if (!(argv[i] = strdup(p.we_wordv[i]))) - { - wordfree(&p); - free_command_line(argv,i); - return NULL; - } - } - *argc=i; - - wordfree(&p); - return argv; -} diff --git a/nfq/helpers.h b/nfq/helpers.h index 0f914dd..c06862e 100644 --- a/nfq/helpers.h +++ b/nfq/helpers.h @@ -107,6 +107,3 @@ static inline const struct in6_addr *mask_from_preflen6(uint8_t preflen) { return ip6_mask+preflen; } - -void free_command_line(char **argv, int argc); -char **split_command_line(const char *cmdline, int *argc); diff --git a/nfq/nfqws.c b/nfq/nfqws.c index 5c291c9..b35e065 100644 --- a/nfq/nfqws.c +++ b/nfq/nfqws.c @@ -554,9 +554,7 @@ static bool parse_ws_scale_factor(char *s, uint16_t *wsize, uint8_t *wscale) static void cleanup_args() { - free_command_line(params.argv,params.argc); - params.argv = NULL; - params.argc = 0; + wordfree(¶ms.wexp); } static void cleanup_params(void) @@ -1066,14 +1064,13 @@ int main(int argc, char **argv) replace_char(buf,'\n',' '); replace_char(buf,'\r',' '); replace_char(buf,'\t',' '); - params.argv = split_command_line(buf,¶ms.argc); - if (!params.argv) + if (wordexp(buf, ¶ms.wexp, WRDE_NOCMD)) { DLOG_ERR("failed to split command line options from file '%s'\n",argv[1]+1); exit_clean(1); } - argv=params.argv; - argc=params.argc; + argv=params.wexp.we_wordv; + argc=params.wexp.we_wordc; } const struct option long_options[] = { diff --git a/nfq/params.h b/nfq/params.h index 1203455..143fd24 100644 --- a/nfq/params.h +++ b/nfq/params.h @@ -14,6 +14,7 @@ #include #include #include +#include #define TLS_PARTIALS_ENABLE true @@ -95,8 +96,7 @@ bool dp_list_have_autohostlist(struct desync_profile_list_head *head); struct params_s { - char **argv; // for file based config - int argc; + wordexp_t wexp; // for file based config enum log_target debug_target; char debug_logfile[PATH_MAX]; diff --git a/tpws/helpers.c b/tpws/helpers.c index 7423009..481c69f 100644 --- a/tpws/helpers.c +++ b/tpws/helpers.c @@ -10,8 +10,6 @@ #include #include #include -#include -#include void rtrim(char *s) { @@ -420,48 +418,3 @@ bool parse_cidr6(char *s, struct cidr6 *cidr) if (p) *p=d; // restore char return b; } - - -void free_command_line(char **argv, int argc) -{ - int i; - if (argv) - { - for (i = 0; i < argc; i++) - if (argv[i]) free(argv[i]); - free(argv); - } -} - -char **split_command_line(const char *cmdline, int *argc) -{ - int i; - char **argv = NULL; - wordexp_t p; - - *argc=0; - - // Note! This expands shell variables. - if (!cmdline || wordexp(cmdline, &p, WRDE_NOCMD)) - return NULL; - - if (!(argv = malloc(p.we_wordc * sizeof(char *)))) - { - wordfree(&p); - return NULL; - } - - for (i = 0; i < p.we_wordc; i++) - { - if (!(argv[i] = strdup(p.we_wordv[i]))) - { - wordfree(&p); - free_command_line(argv,i); - return NULL; - } - } - *argc=i; - - wordfree(&p); - return argv; -} diff --git a/tpws/helpers.h b/tpws/helpers.h index 39476b7..9d7d35c 100644 --- a/tpws/helpers.h +++ b/tpws/helpers.h @@ -112,6 +112,3 @@ static inline const struct in6_addr *mask_from_preflen6(uint8_t preflen) { return ip6_mask+preflen; } - -void free_command_line(char **argv, int argc); -char **split_command_line(const char *cmdline, int *argc); diff --git a/tpws/params.h b/tpws/params.h index fedace7..b34238c 100644 --- a/tpws/params.h +++ b/tpws/params.h @@ -6,6 +6,8 @@ #include #include #include +#include + #include "tpws.h" #include "pools.h" #include "helpers.h" @@ -79,8 +81,7 @@ void dp_list_destroy(struct desync_profile_list_head *head); struct params_s { - char **argv; // for file based config - int argc; + wordexp_t wexp; // for file based config int debug; enum log_target debug_target; diff --git a/tpws/tpws.c b/tpws/tpws.c index e36199a..0bb4cf8 100644 --- a/tpws/tpws.c +++ b/tpws/tpws.c @@ -217,9 +217,7 @@ static void exithelp(void) } static void cleanup_args() { - free_command_line(params.argv,params.argc); - params.argv = NULL; - params.argc = 0; + wordfree(¶ms.wexp); } static void cleanup_params(void) { @@ -423,14 +421,13 @@ void parse_params(int argc, char *argv[]) replace_char(buf,'\n',' '); replace_char(buf,'\r',' '); replace_char(buf,'\t',' '); - params.argv = split_command_line(buf,¶ms.argc); - if (!params.argv) + if (wordexp(buf, ¶ms.wexp, WRDE_NOCMD)) { DLOG_ERR("failed to split command line options from file '%s'\n",argv[1]+1); exit_clean(1); } - argv=params.argv; - argc=params.argc; + argv=params.wexp.we_wordv; + argc=params.wexp.we_wordc; } const struct option long_options[] = {