From a2ed880a19d0861342b3515721804b18d698bf44 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 2 Aug 2018 17:05:17 +0200 Subject: xshared: Consolidate argv construction routines Implementations were equal in {ip,ip6,x}tables-restore.c. The one in iptables-xml.c differed slightly. For now, collect all features together. Maybe it would make sense to migrate iptables-xml.c to using add_param_to_argv() at some point and therefore extend the latter to store whether a given parameter was quoted or not. While being at it, a few improvements were done: * free_argv() now also resets 'newargc' variable, so users don't have to do that anymore. * Indenting level in add_param_to_argv() was reduced a bit. * That long error message is put into a single line to aid in grepping for it. * Explicit call to exit() after xtables_error() is removed since the latter does not return anyway. Signed-off-by: Phil Sutter Signed-off-by: Florian Westphal --- iptables/iptables-xml.c | 64 ------------------------------------------------- 1 file changed, 64 deletions(-) (limited to 'iptables/iptables-xml.c') diff --git a/iptables/iptables-xml.c b/iptables/iptables-xml.c index 8ba45d55..788a67c6 100644 --- a/iptables/iptables-xml.c +++ b/iptables/iptables-xml.c @@ -50,16 +50,6 @@ print_usage(const char *name, const char *version) exit(1); } -/* global new argv and argc */ -static char *newargv[255]; -static unsigned int newargc; - -static char *oldargv[255]; -static unsigned int oldargc; - -/* arg meta data, were they quoted, frinstance */ -static int newargvattr[255]; - #define XT_CHAIN_MAXNAMELEN XT_TABLE_MAXNAMELEN static char closeActionTag[XT_TABLE_MAXNAMELEN + 1]; static char closeRuleTag[XT_TABLE_MAXNAMELEN + 1]; @@ -77,57 +67,6 @@ struct chain { static struct chain chains[maxChains]; static int nextChain; -/* funCtion adding one argument to newargv, updating newargc - * returns true if argument added, false otherwise */ -static int -add_argv(char *what, int quoted) -{ - DEBUGP("add_argv: %d %s\n", newargc, what); - if (what && newargc + 1 < ARRAY_SIZE(newargv)) { - newargv[newargc] = strdup(what); - newargvattr[newargc] = quoted; - newargc++; - return 1; - } else - return 0; -} - -static void -free_argv(void) -{ - unsigned int i; - - for (i = 0; i < newargc; i++) { - free(newargv[i]); - newargv[i] = NULL; - } - newargc = 0; - - for (i = 0; i < oldargc; i++) { - free(oldargv[i]); - oldargv[i] = NULL; - } - oldargc = 0; -} - -/* Save parsed rule for comparison with next rule to perform action aggregation - * on duplicate conditions. - */ -static void -save_argv(void) -{ - unsigned int i; - - for (i = 0; i < oldargc; i++) - free(oldargv[i]); - oldargc = newargc; - newargc = 0; - for (i = 0; i < oldargc; i++) { - oldargv[i] = newargv[i]; - newargv[i] = NULL; - } -} - /* like puts but with xml encoding */ static void xmlEncode(char *text) @@ -720,9 +659,6 @@ iptables_xml_main(int argc, char *argv[]) int quote_open, quoted; char param_buffer[1024]; - /* reset the newargv */ - newargc = 0; - if (buffer[0] == '[') { /* we have counters in our input */ ptr = strchr(buffer, ']'); -- cgit v1.2.3