aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/utils')
-rw-r--r--src/libstrongswan/utils/capabilities.c2
-rw-r--r--src/libstrongswan/utils/debug.c112
-rw-r--r--src/libstrongswan/utils/debug.h154
-rw-r--r--src/libstrongswan/utils/leak_detective.c2
-rw-r--r--src/libstrongswan/utils/optionsfrom.c2
5 files changed, 269 insertions, 3 deletions
diff --git a/src/libstrongswan/utils/capabilities.c b/src/libstrongswan/utils/capabilities.c
index 34128d010..c36a76efe 100644
--- a/src/libstrongswan/utils/capabilities.c
+++ b/src/libstrongswan/utils/capabilities.c
@@ -27,7 +27,7 @@
# include <sys/prctl.h>
#endif /* HAVE_PRCTL */
-#include <debug.h>
+#include <utils/debug.h>
#if !defined(HAVE_GETPWNAM_R) || !defined(HAVE_GETGRNAM_R)
# include <threading/mutex.h>
diff --git a/src/libstrongswan/utils/debug.c b/src/libstrongswan/utils/debug.c
new file mode 100644
index 000000000..e8c9e6b98
--- /dev/null
+++ b/src/libstrongswan/utils/debug.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2006 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include <stdarg.h>
+
+#include "debug.h"
+
+ENUM(debug_names, DBG_DMN, DBG_LIB,
+ "DMN",
+ "MGR",
+ "IKE",
+ "CHD",
+ "JOB",
+ "CFG",
+ "KNL",
+ "NET",
+ "ASN",
+ "ENC",
+ "TNC",
+ "IMC",
+ "IMV",
+ "PTS",
+ "TLS",
+ "APP",
+ "ESP",
+ "LIB",
+);
+
+ENUM(debug_lower_names, DBG_DMN, DBG_LIB,
+ "dmn",
+ "mgr",
+ "ike",
+ "chd",
+ "job",
+ "cfg",
+ "knl",
+ "net",
+ "asn",
+ "enc",
+ "tnc",
+ "imc",
+ "imv",
+ "pts",
+ "tls",
+ "app",
+ "esp",
+ "lib",
+);
+
+/**
+ * level logged by the default logger
+ */
+static level_t default_level = 1;
+
+/**
+ * stream logged to by the default logger
+ */
+static FILE *default_stream = NULL;
+
+/**
+ * default dbg function which printf all to stderr
+ */
+void dbg_default(debug_t group, level_t level, char *fmt, ...)
+{
+ if (!default_stream)
+ {
+ default_stream = stderr;
+ }
+ if (level <= default_level)
+ {
+ va_list args;
+
+ va_start(args, fmt);
+ vfprintf(default_stream, fmt, args);
+ fprintf(default_stream, "\n");
+ va_end(args);
+ }
+}
+
+/**
+ * set the level logged by the default stderr logger
+ */
+void dbg_default_set_level(level_t level)
+{
+ default_level = level;
+}
+
+/**
+ * set the stream logged by dbg_default() to
+ */
+void dbg_default_set_stream(FILE *stream)
+{
+ default_stream = stream;
+}
+
+/**
+ * The registered debug hook.
+ */
+void (*dbg) (debug_t group, level_t level, char *fmt, ...) = dbg_default;
+
diff --git a/src/libstrongswan/utils/debug.h b/src/libstrongswan/utils/debug.h
new file mode 100644
index 000000000..c46d3fe55
--- /dev/null
+++ b/src/libstrongswan/utils/debug.h
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2006 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup debug debug
+ * @{ @ingroup utils
+ */
+
+#ifndef DEBUG_H_
+#define DEBUG_H_
+
+typedef enum debug_t debug_t;
+typedef enum level_t level_t;
+
+#include <stdio.h>
+
+#include "utils/enum.h"
+
+/**
+ * Debug message group.
+ */
+enum debug_t {
+ /** daemon specific */
+ DBG_DMN,
+ /** IKE_SA_MANAGER */
+ DBG_MGR,
+ /** IKE_SA */
+ DBG_IKE,
+ /** CHILD_SA */
+ DBG_CHD,
+ /** job processing */
+ DBG_JOB,
+ /** configuration backends */
+ DBG_CFG,
+ /** kernel interface */
+ DBG_KNL,
+ /** networking/sockets */
+ DBG_NET,
+ /** low-level encoding/decoding (ASN.1, X.509 etc.) */
+ DBG_ASN,
+ /** message encoding/decoding */
+ DBG_ENC,
+ /** trusted network connect */
+ DBG_TNC,
+ /** integrity measurement client */
+ DBG_IMC,
+ /** integrity measurement verifier */
+ DBG_IMV,
+ /** platform trust service */
+ DBG_PTS,
+ /** libtls */
+ DBG_TLS,
+ /** applications other than daemons */
+ DBG_APP,
+ /** libipsec */
+ DBG_ESP,
+ /** libstrongswan */
+ DBG_LIB,
+ /** number of groups */
+ DBG_MAX,
+ /** pseudo group with all groups */
+ DBG_ANY = DBG_MAX,
+};
+
+/**
+ * short names of debug message group.
+ */
+extern enum_name_t *debug_names;
+
+/**
+ * short names of debug message group, lower case.
+ */
+extern enum_name_t *debug_lower_names;
+
+/**
+ * Debug levels used to control output verbosity.
+ */
+enum level_t {
+ /** absolutely silent */
+ LEVEL_SILENT = -1,
+ /** most important auditing logs */
+ LEVEL_AUDIT = 0,
+ /** control flow */
+ LEVEL_CTRL = 1,
+ /** diagnose problems */
+ LEVEL_DIAG = 2,
+ /** raw binary blobs */
+ LEVEL_RAW = 3,
+ /** including sensitive data (private keys) */
+ LEVEL_PRIVATE = 4,
+};
+
+#ifndef DEBUG_LEVEL
+# define DEBUG_LEVEL 4
+#endif /* DEBUG_LEVEL */
+
+/** debug macros, they call the dbg function hook */
+#if DEBUG_LEVEL >= 0
+# define DBG0(group, fmt, ...) dbg(group, 0, fmt, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+#if DEBUG_LEVEL >= 1
+# define DBG1(group, fmt, ...) dbg(group, 1, fmt, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+#if DEBUG_LEVEL >= 2
+# define DBG2(group, fmt, ...) dbg(group, 2, fmt, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+#if DEBUG_LEVEL >= 3
+# define DBG3(group, fmt, ...) dbg(group, 3, fmt, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+#if DEBUG_LEVEL >= 4
+# define DBG4(group, fmt, ...) dbg(group, 4, fmt, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+
+#ifndef DBG0
+# define DBG0(...) {}
+#endif
+#ifndef DBG1
+# define DBG1(...) {}
+#endif
+#ifndef DBG2
+# define DBG2(...) {}
+#endif
+#ifndef DBG3
+# define DBG3(...) {}
+#endif
+#ifndef DBG4
+# define DBG4(...) {}
+#endif
+
+/** dbg function hook, uses dbg_default() by default */
+extern void (*dbg) (debug_t group, level_t level, char *fmt, ...);
+
+/** default logging function */
+void dbg_default(debug_t group, level_t level, char *fmt, ...);
+
+/** set the level logged by dbg_default() */
+void dbg_default_set_level(level_t level);
+
+/** set the stream logged by dbg_default() to */
+void dbg_default_set_stream(FILE *stream);
+
+#endif /** DEBUG_H_ @}*/
diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c
index 723f33098..2b0be1661 100644
--- a/src/libstrongswan/utils/leak_detective.c
+++ b/src/libstrongswan/utils/leak_detective.c
@@ -32,7 +32,7 @@
#include "leak_detective.h"
#include <library.h>
-#include <debug.h>
+#include <utils/debug.h>
#include <utils/backtrace.h>
#include <collections/hashtable.h>
diff --git a/src/libstrongswan/utils/optionsfrom.c b/src/libstrongswan/utils/optionsfrom.c
index 5fd4cfd4d..a550c1aa3 100644
--- a/src/libstrongswan/utils/optionsfrom.c
+++ b/src/libstrongswan/utils/optionsfrom.c
@@ -17,7 +17,7 @@
#include <errno.h>
#include <library.h>
-#include <debug.h>
+#include <utils/debug.h>
#include <utils/lexparser.h>
#include "optionsfrom.h"