[PATCH 3/11] Common error strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx>

---
 include/xtables.h |    9 ++++++++-
 xtables.c         |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)

Index: iptables-modules/include/xtables.h
===================================================================
--- iptables-modules.orig/include/xtables.h
+++ iptables-modules/include/xtables.h
@@ -220,7 +220,13 @@ enum exittype {
 	OTHER_PROBLEM = 1,
 	PARAMETER_PROBLEM,
 	VERSION_PROBLEM,
-	RESOURCE_PROBLEM
+	RESOURCE_PROBLEM,
+	P_ONLY_ONCE,
+	P_NO_INVERT,
+	P_BAD_VALUE,
+	P_NEED_MATCH,
+	P_NEED_ACTION,
+	P_ONE_ACTION,
 };
 
 /* this is a special 64bit data type that is 8-byte aligned */
@@ -229,6 +235,7 @@ enum exittype {
 int check_inverse(const char option[], int *invert, int *optind, int argc);
 void exit_error(enum exittype, const char *, ...)__attribute__((noreturn,
 							  format(printf,2,3)));
+extern void param_act(enum exittype, const char *, ...);
 extern const char *program_name, *program_version;
 
 #define _init __attribute__((constructor)) my_init
Index: iptables-modules/xtables.c
===================================================================
--- iptables-modules.orig/xtables.c
+++ iptables-modules/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,52 @@ void xtables_register_target(struct xtab
 	me->t = NULL;
 	me->tflags = 0;
 }
+
+void param_act(enum exittype status, const char *p1, ...)
+{
+	const char *p2, *p3;
+	va_list args;
+	bool b3;
+
+	va_start(args, msg);
+
+	switch (status) {
+	case P_ONLY_ONCE:
+		exit_error(PARAMETER_PROBLEM,
+		           "%s: \"%s\" option may only be specified once\n",
+		           p1, va_arg(args, const char *));
+		break;
+	case P_NO_INVERT:
+		p2 = va_arg(args, const char *);
+		b3 = va_arg(args, bool);
+		if (!b3)
+			return;
+		exit_error(PARAMETER_PROBLEM,
+		           "%s: Unexpected \"!\" after \"%s\" option",
+		           p1, va_arg(args, const char *));
+		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_NEED_MATCH:
+		exit_error(PARAMETER_PROBLEM,
+		           "%s: Need at least one match option", p1);
+		break;
+	case P_NEED_ACTION:
+		exit_error(PARAMETER_PROBLEM,
+		           "%s: Need at least one action option", p1);
+		break;
+	case P_ONE_ACTION:
+		exit_error(PARAMETER_PROBLEM,
+		             "%s: At most one action is possible", p1);
+		break;
+	default:
+		exit_error(status, msg, args);
+	}
+
+	va_end(args);
+}
-
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux