summaryrefslogtreecommitdiffstats
path: root/xtables.c
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2008-01-20 13:19:40 +0000
committerPatrick McHardy <kaber@trash.net>2008-01-20 13:19:40 +0000
commitaafd269675fc45bac6340027c866ea6073643c3b (patch)
tree6d7391a52374293edc0cce5e61126ab1ea9409ee /xtables.c
parentcd9e7aa106e80c44bd526af74b616701b0772d05 (diff)
common error messages
Error messages vary wildly among modules, and there is a lot of reundance in it too. Introduce a helper function that does all of the parameter checking boilerplate and gives unique messages. Signed-off-by: Jan Engelhardt <jengelh@computergmbh.de>
Diffstat (limited to 'xtables.c')
-rw-r--r--xtables.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/xtables.c b/xtables.c
index 4313f5ba..0a2fdb1d 100644
--- a/xtables.c
+++ b/xtables.c
@@ -19,6 +19,7 @@
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
+#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -639,3 +640,51 @@ void xtables_register_target(struct xtables_target *me)
me->t = NULL;
me->tflags = 0;
}
+
+void param_act(unsigned int status, const char *p1, ...)
+{
+ const char *p2, *p3;
+ va_list args;
+ bool b;
+
+ va_start(args, p1);
+
+ switch (status) {
+ case P_ONLY_ONCE:
+ p2 = va_arg(args, const char *);
+ b = va_arg(args, unsigned int);
+ if (!b)
+ return;
+ exit_error(PARAMETER_PROBLEM,
+ "%s: \"%s\" option may only be specified once",
+ p1, p2);
+ break;
+ case P_NO_INVERT:
+ p2 = va_arg(args, const char *);
+ b = va_arg(args, unsigned int);
+ if (!b)
+ return;
+ exit_error(PARAMETER_PROBLEM,
+ "%s: \"%s\" option cannot be inverted", p1, p2);
+ break;
+ case P_BAD_VALUE:
+ p2 = va_arg(args, const char *);
+ p3 = va_arg(args, const char *);
+ exit_error(PARAMETER_PROBLEM,
+ "%s: Bad value for \"%s\" option: \"%s\"",
+ p1, p2, p3);
+ break;
+ case P_ONE_ACTION:
+ b = va_arg(args, unsigned int);
+ if (!b)
+ return;
+ exit_error(PARAMETER_PROBLEM,
+ "%s: At most one action is possible", p1);
+ break;
+ default:
+ exit_error(status, p1, args);
+ break;
+ }
+
+ va_end(args);
+}