[gnome-keyring] pkcs11: Add initial debug logging to gkm module
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] pkcs11: Add initial debug logging to gkm module
- Date: Sat, 15 Oct 2011 20:52:32 +0000 (UTC)
commit f2bfd5b52e96636c04781080642faa8a38215da9
Author: Stef Walter <stefw collabora co uk>
Date: Sat Oct 15 22:36:30 2011 +0200
pkcs11: Add initial debug logging to gkm module
pkcs11/gkm/Makefile.am | 1 +
pkcs11/gkm/gkm-debug.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++
pkcs11/gkm/gkm-debug.h | 85 ++++++++++++++++++++++++++++++++++++++
3 files changed, 193 insertions(+), 0 deletions(-)
---
diff --git a/pkcs11/gkm/Makefile.am b/pkcs11/gkm/Makefile.am
index b413850..54f867c 100644
--- a/pkcs11/gkm/Makefile.am
+++ b/pkcs11/gkm/Makefile.am
@@ -28,6 +28,7 @@ libgkm_la_SOURCES = \
gkm-data-asn1.c gkm-data-asn1.h \
gkm-data-der.c gkm-data-der.h \
gkm-data-types.h \
+ gkm-debug.c gkm-debug.h \
gkm-dh-key.c gkm-dh-key.h \
gkm-dh-mechanism.c gkm-dh-mechanism.h \
gkm-dh-private-key.c gkm-dh-private-key.h \
diff --git a/pkcs11/gkm/gkm-debug.c b/pkcs11/gkm/gkm-debug.c
new file mode 100644
index 0000000..7c29bd8
--- /dev/null
+++ b/pkcs11/gkm/gkm-debug.c
@@ -0,0 +1,107 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/*
+ * Copyright (C) 2007 Collabora Ltd.
+ * Copyright (C) 2007 Nokia Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+
+#include "gkm-debug.h"
+
+#include <stdarg.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <glib/gstdio.h>
+
+#ifdef WITH_DEBUG
+
+static GkmDebugFlags current_flags = 0;
+
+static GDebugKey keys[] = {
+ { "storage", GKM_DEBUG_STORAGE },
+ { 0, }
+};
+
+static void
+debug_set_flags (GkmDebugFlags new_flags)
+{
+ current_flags |= new_flags;
+}
+
+void
+gkm_debug_set_flags (const gchar *flags_string)
+{
+ guint nkeys;
+
+ for (nkeys = 0; keys[nkeys].value; nkeys++);
+
+ if (flags_string)
+ debug_set_flags (g_parse_debug_string (flags_string, keys, nkeys));
+}
+
+gboolean
+gkm_debug_flag_is_set (GkmDebugFlags flag)
+{
+ return (flag & current_flags) != 0;
+}
+
+void
+gkm_debug_message (GkmDebugFlags flag,
+ const gchar *format,
+ ...)
+{
+ static gsize initialized_flags = 0;
+ gchar *message;
+ va_list args;
+
+ if (g_once_init_enter (&initialized_flags)) {
+ gkm_debug_set_flags (g_getenv ("GKM_DEBUG"));
+ g_once_init_leave (&initialized_flags, 1);
+ }
+
+ va_start (args, format);
+ message = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ if (flag & current_flags)
+ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s", message);
+
+ g_free (message);
+}
+
+#else /* !WITH_DEBUG */
+
+gboolean
+gkm_debug_flag_is_set (GkmDebugFlags flag)
+{
+ return FALSE;
+}
+
+void
+gkm_debug_message (GkmDebugFlags flag,
+ const gchar *format,
+ ...)
+{
+}
+
+void
+gkm_debug_set_flags (const gchar *flags_string)
+{
+}
+
+#endif /* !WITH_DEBUG */
diff --git a/pkcs11/gkm/gkm-debug.h b/pkcs11/gkm/gkm-debug.h
new file mode 100644
index 0000000..26b01ad
--- /dev/null
+++ b/pkcs11/gkm/gkm-debug.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2007 Nokia Corporation
+ * Copyright (C) 2007-2011 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef GKM_DEBUG_H
+#define GKM_DEBUG_H
+
+#include "config.h"
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/* Please keep this enum in sync with #keys in gcr-debug.c */
+typedef enum {
+ GKM_DEBUG_STORAGE = 1 << 1,
+} GkmDebugFlags;
+
+gboolean gkm_debug_flag_is_set (GkmDebugFlags flag);
+
+void gkm_debug_set_flags (const gchar *flags_string);
+
+void gkm_debug_message (GkmDebugFlags flag,
+ const gchar *format,
+ ...) G_GNUC_PRINTF (2, 3);
+
+G_END_DECLS
+
+#endif /* GKM_DEBUG_H */
+
+/* -----------------------------------------------------------------------------
+ * Below this point is outside the GKM_DEBUG_H guard - so it can take effect
+ * more than once. So you can do:
+ *
+ * #define DEBUG_FLAG GKM_DEBUG_ONE_THING
+ * #include "gcr-debug.h"
+ * ...
+ * DEBUG ("if we're debugging one thing");
+ * ...
+ * #undef DEBUG_FLAG
+ * #define DEBUG_FLAG GKM_DEBUG_OTHER_THING
+ * #include "gcr-debug.h"
+ * ...
+ * DEBUG ("if we're debugging the other thing");
+ * ...
+ */
+
+#ifdef DEBUG_FLAG
+#ifdef WITH_DEBUG
+
+#undef gkm_debug
+#define gkm_debug(format, ...) \
+ gkm_debug_message (DEBUG_FLAG, "%s: " format, G_STRFUNC, ##__VA_ARGS__)
+
+#undef gkm_debugging
+#define gkm_debugging \
+ gkm_debug_flag_is_set (DEBUG_FLAG)
+
+#else /* !defined (WITH_DEBUG) */
+
+#undef gkm_debug
+#define gkm_debug(format, ...) \
+ do {} while (0)
+
+#undef gkm_debugging
+#define gkm_debugging 0
+
+#endif /* !defined (WITH_DEBUG) */
+
+#endif /* defined (DEBUG_FLAG) */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]