[seahorse] Add Glib style debug messages
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] Add Glib style debug messages
- Date: Mon, 25 Jul 2011 17:45:52 +0000 (UTC)
commit af87f36c0aafdc75d4baa9fafa081d452a306e8a
Author: Stef Walter <stefw collabora co uk>
Date: Mon Jul 25 19:34:06 2011 +0200
Add Glib style debug messages
* This allows use of the SEAHORSE_DEBUG="all" environment variable.
* Use SEAHORSE_DEBUG="help" to figure out what flags are available
configure.ac | 2 +-
gkr/seahorse-gkr-operation.c | 14 ----
gkr/seahorse-gkr-source.c | 17 -----
libseahorse/Makefile.am | 1 +
libseahorse/seahorse-debug.c | 112 +++++++++++++++++++++++++++++
libseahorse/seahorse-debug.h | 91 +++++++++++++++++++++++
libseahorse/seahorse-dns-sd.c | 22 +-----
libseahorse/seahorse-operation.c | 42 ++++-------
libseahorse/seahorse-transfer-operation.c | 53 ++++++--------
libseahorse/seahorse-util.h | 6 --
pgp/seahorse-gpgme-key-op.c | 58 ++++++---------
pgp/seahorse-gpgme-operation.c | 57 ++++++---------
pgp/seahorse-gpgme-source.c | 32 +++------
pgp/seahorse-hkp-source.c | 31 +++-----
pgp/seahorse-ldap-source.c | 55 ++++++--------
pgp/seahorse-pgp-key-properties.c | 9 ++-
src/seahorse-key-manager-store.c | 39 ++++++-----
ssh/seahorse-ssh-operation.c | 83 +++++++++------------
ssh/seahorse-ssh-source.c | 31 ++------
19 files changed, 405 insertions(+), 350 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 503af18..f387c42 100644
--- a/configure.ac
+++ b/configure.ac
@@ -217,7 +217,7 @@ dnl fails, the user can play guess-the-dependency by using something
dnl like LDAP_LIBS="-lfoo" ./configure
if test "$try_ldap" = yes ; then
- for MY_LDAPLIBS in ${LDAP_LIBS+"$LDAP_LIBS"} "-lldap" "-lldap -llber" "-lldap -llber -lresolv"; do
+ for MY_LDAPLIBS in ${LDAP_LIBS+"$LDAP_LIBS"} "-lldap -llber" "-lldap" "-lldap -llber -lresolv"; do
_ldap_save_libs=$LIBS
LIBS="$MY_LDAPLIBS $NETLIBS $LIBS"
diff --git a/gkr/seahorse-gkr-operation.c b/gkr/seahorse-gkr-operation.c
index 7bb1f52..418eceb 100644
--- a/gkr/seahorse-gkr-operation.c
+++ b/gkr/seahorse-gkr-operation.c
@@ -33,20 +33,6 @@
#include <gnome-keyring.h>
-#ifndef DEBUG_OPERATION_ENABLE
-#if _DEBUG
-#define DEBUG_OPERATION_ENABLE 1
-#else
-#define DEBUG_OPERATION_ENABLE 0
-#endif
-#endif
-
-#if DEBUG_OPERATION_ENABLE
-#define DEBUG_OPERATION(x) g_printerr x
-#else
-#define DEBUG_OPERATION(x)
-#endif
-
/* -----------------------------------------------------------------------------
* DEFINITIONS
*/
diff --git a/gkr/seahorse-gkr-source.c b/gkr/seahorse-gkr-source.c
index 2d0c1a2..0fa6bb6 100644
--- a/gkr/seahorse-gkr-source.c
+++ b/gkr/seahorse-gkr-source.c
@@ -41,23 +41,6 @@
#include <gnome-keyring.h>
-/* Override the DEBUG_REFRESH_ENABLE switch here */
-#define DEBUG_REFRESH_ENABLE 0
-
-#ifndef DEBUG_REFRESH_ENABLE
-#if _DEBUG
-#define DEBUG_REFRESH_ENABLE 1
-#else
-#define DEBUG_REFRESH_ENABLE 0
-#endif
-#endif
-
-#if DEBUG_REFRESH_ENABLE
-#define DEBUG_REFRESH(x) g_printerr(x)
-#else
-#define DEBUG_REFRESH(x)
-#endif
-
enum {
PROP_0,
PROP_SOURCE_TAG,
diff --git a/libseahorse/Makefile.am b/libseahorse/Makefile.am
index af67555..e3e2b15 100644
--- a/libseahorse/Makefile.am
+++ b/libseahorse/Makefile.am
@@ -32,6 +32,7 @@ libseahorse_la_SOURCES = \
seahorse-combo-keys.c seahorse-combo-keys.h \
seahorse-commands.c seahorse-commands.h \
seahorse-context.c seahorse-context.h \
+ seahorse-debug.c seahorse-debug.h \
seahorse-dns-sd.c seahorse-dns-sd.h \
seahorse-gconf.c seahorse-gconf.h \
seahorse-gtkstock.c seahorse-gtkstock.h \
diff --git a/libseahorse/seahorse-debug.c b/libseahorse/seahorse-debug.c
new file mode 100644
index 0000000..d48cc9e
--- /dev/null
+++ b/libseahorse/seahorse-debug.c
@@ -0,0 +1,112 @@
+/* -*- 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 "seahorse-debug.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <glib/gstdio.h>
+
+#ifdef WITH_DEBUG
+
+static SeahorseDebugFlags current_flags = 0;
+
+static GDebugKey keys[] = {
+ { "operation", SEAHORSE_DEBUG_OPERATION },
+ { "dns-sd", SEAHORSE_DEBUG_DNSSD },
+ { "keys", SEAHORSE_DEBUG_KEYS },
+ { "drag", SEAHORSE_DEBUG_DRAG },
+ { "load", SEAHORSE_DEBUG_LOAD },
+ { "ldap", SEAHORSE_DEBUG_LDAP },
+ { "hkp", SEAHORSE_DEBUG_HKP},
+ { 0, }
+};
+
+static void
+debug_set_flags (SeahorseDebugFlags new_flags)
+{
+ current_flags |= new_flags;
+}
+
+void
+seahorse_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
+seahorse_debug_flag_is_set (SeahorseDebugFlags flag)
+{
+ return (flag & current_flags) != 0;
+}
+
+void
+seahorse_debug_message (SeahorseDebugFlags flag, const gchar *format, ...)
+{
+ static gsize initialized_flags = 0;
+ gchar *message;
+ va_list args;
+
+ if (g_once_init_enter (&initialized_flags)) {
+ seahorse_debug_set_flags (g_getenv ("SEAHORSE_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
+seahorse_debug_flag_is_set (SeahorseDebugFlags flag)
+{
+ return FALSE;
+}
+
+void
+seahorse_debug_message (SeahorseDebugFlags flag, const gchar *format, ...)
+{
+}
+
+void
+seahorse_debug_set_flags (const gchar *flags_string)
+{
+}
+
+#endif /* !WITH_DEBUG */
diff --git a/libseahorse/seahorse-debug.h b/libseahorse/seahorse-debug.h
new file mode 100644
index 0000000..6423738
--- /dev/null
+++ b/libseahorse/seahorse-debug.h
@@ -0,0 +1,91 @@
+/*
+ * 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 SEAHORSE_DEBUG_H
+#define SEAHORSE_DEBUG_H
+
+#include "config.h"
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/* Please keep this enum in sync with #keys in seahorse-debug.c */
+typedef enum {
+ SEAHORSE_DEBUG_KEYS = 1 << 1,
+ SEAHORSE_DEBUG_LOAD = 1 << 2,
+ SEAHORSE_DEBUG_DNSSD = 1 << 3,
+ SEAHORSE_DEBUG_LDAP = 1 << 4,
+ SEAHORSE_DEBUG_HKP = 1 << 5,
+ SEAHORSE_DEBUG_OPERATION = 1 << 6,
+ SEAHORSE_DEBUG_DRAG = 1 << 7,
+} SeahorseDebugFlags;
+
+gboolean seahorse_debug_flag_is_set (SeahorseDebugFlags flag);
+
+void seahorse_debug_set_flags (const gchar *flags_string);
+
+void seahorse_debug_message (SeahorseDebugFlags flag,
+ const gchar *format,
+ ...) G_GNUC_PRINTF (2, 3);
+
+G_END_DECLS
+
+#endif /* SEAHORSE_DEBUG_H */
+
+/* -----------------------------------------------------------------------------
+ * Below this point is outside the SEAHORSE_DEBUG_H guard - so it can take effect
+ * more than once. So you can do:
+ *
+ * #define DEBUG_FLAG SEAHORSE_DEBUG_ONE_THING
+ * #include "seahorse-debug.h"
+ * ...
+ * seahorse_debug ("if we're debugging one thing");
+ * ...
+ * #undef DEBUG_FLAG
+ * #define DEBUG_FLAG SEAHORSE_DEBUG_OTHER_THING
+ * #include "seahorse-debug.h"
+ * ...
+ * seahorse_debug ("if we're debugging the other thing");
+ * ...
+ */
+
+#ifdef DEBUG_FLAG
+#ifdef WITH_DEBUG
+
+#undef seahorse_debug
+#define seahorse_debug(format, ...) \
+ seahorse_debug_message (DEBUG_FLAG, "%s: " format, G_STRFUNC, ##__VA_ARGS__)
+
+#undef seahorse_debugging
+#define seahorse_debugging \
+ seahorse_debug_flag_is_set (DEBUG_FLAG)
+
+#else /* !defined (WITH_DEBUG) */
+
+#undef seahorse_debug
+#define seahorse_debug(format, ...) \
+ do {} while (0)
+
+#undef seahorse_debugging
+#define seahorse_debugging 0
+
+#endif /* !defined (WITH_DEBUG) */
+
+#endif /* defined (DEBUG_FLAG) */
diff --git a/libseahorse/seahorse-dns-sd.c b/libseahorse/seahorse-dns-sd.c
index 7a7173e..a3b36a7 100644
--- a/libseahorse/seahorse-dns-sd.c
+++ b/libseahorse/seahorse-dns-sd.c
@@ -35,22 +35,8 @@
#include "pgp/seahorse-server-source.h"
#endif
-/* Override the DEBUG_DNSSD_ENABLE switch here */
-/* #define DEBUG_DNSSD_ENABLE 1 */
-
-#ifndef DEBUG_DNSSD_ENABLE
-#if _DEBUG
-#define DEBUG_DNSSD_ENABLE 1
-#else
-#define DEBUG_DNSSD_ENABLE 0
-#endif
-#endif
-
-#if DEBUG_DNSSD_ENABLE
-#define DEBUG_DNSSD(x) g_printerr x
-#else
-#define DEBUG_DNSSD(x)
-#endif
+#define DEBUG_FLAG SEAHORSE_DEBUG_DNSSD
+#include "seahorse-debug.h"
#define HKP_SERVICE_TYPE "_pgpkey-hkp._tcp."
@@ -180,7 +166,7 @@ resolve_callback (AvahiServiceResolver *resolver, AvahiIfIndex iface, AvahiProto
seahorse_context_add_source (SCTX_APP (), SEAHORSE_SOURCE (ssrc));
}
- DEBUG_DNSSD (("DNS-SD added: %s %s\n", service_name, service_uri));
+ seahorse_debug ("added: %s %s\n", service_name, service_uri);
break;
default:
@@ -248,7 +234,7 @@ browse_callback(AvahiServiceBrowser *browser, AvahiIfIndex iface, AvahiProtocol
/* And remove it from our tables */
g_hash_table_remove (ssd->services, name);
g_signal_emit (ssd, signals[REMOVED], 0, name);
- DEBUG_DNSSD (("DNS-SD removed: %s\n", name));
+ seahorse_debug ("removed: %s\n", name);
break;
diff --git a/libseahorse/seahorse-operation.c b/libseahorse/seahorse-operation.c
index ce3533a..e8d64d6 100644
--- a/libseahorse/seahorse-operation.c
+++ b/libseahorse/seahorse-operation.c
@@ -24,6 +24,9 @@
#include "seahorse-marshal.h"
#include "seahorse-operation.h"
+#define DEBUG_FLAG SEAHORSE_DEBUG_OPERATION
+#include "seahorse-debug.h"
+
/**
* SECTION:seahorse-operation
* @short_description: Contains code for operations and multi operations (container for several operations)
@@ -31,23 +34,6 @@
*
**/
-/* Override the DEBUG_OPERATION_ENABLE switch here */
-#define DEBUG_OPERATION_ENABLE 0
-
-#ifndef DEBUG_OPERATION_ENABLE
-#if _DEBUG
-#define DEBUG_OPERATION_ENABLE 1
-#else
-#define DEBUG_OPERATION_ENABLE 0
-#endif
-#endif
-
-#if DEBUG_OPERATION_ENABLE
-#define DEBUG_OPERATION(x) g_printerr x
-#else
-#define DEBUG_OPERATION(x)
-#endif
-
/* -----------------------------------------------------------------------------
* SEAHORSE OPERATION
*/
@@ -585,9 +571,9 @@ multi_operation_progress (SeahorseOperation *operation, const gchar *message,
/* One or two operations, simple */
if (g_slist_length (list) <= 1) {
- DEBUG_OPERATION (("[multi-operation 0x%08X] single progress: %s %lf\n", (guint)mop,
- seahorse_operation_get_message (operation), operation->progress));
-
+ seahorse_debug ("[multi-operation %p] single progress: %s %lf", mop,
+ seahorse_operation_get_message (operation), operation->progress);
+
seahorse_operation_mark_progress (SEAHORSE_OPERATION (mop),
seahorse_operation_get_message (operation),
operation->progress);
@@ -620,14 +606,14 @@ multi_operation_progress (SeahorseOperation *operation, const gchar *message,
current += (seahorse_operation_is_running (op) ? 0 : 1);
else
current += op->progress;
- DEBUG_OPERATION ((" progres is: %lf\n", op->progress));
+ seahorse_debug (" progres is: %lf", op->progress);
}
}
progress = total ? current / total : -1;
- DEBUG_OPERATION (("[multi-operation 0x%08X] multi progress: %s %lf\n", (guint)mop,
- message, progress));
+ seahorse_debug ("[multi-operation %p] multi progress: %s %lf", mop,
+ message, progress);
seahorse_operation_mark_progress (SEAHORSE_OPERATION (mop), message, progress);
}
@@ -656,8 +642,8 @@ multi_operation_done (SeahorseOperation *op, SeahorseMultiOperation *mop)
if (!seahorse_operation_is_successful (op) && !SEAHORSE_OPERATION (mop)->error)
seahorse_operation_copy_error (op, &(SEAHORSE_OPERATION (mop)->error));
- DEBUG_OPERATION (("[multi-operation 0x%08X] part complete (%d): 0x%08X/%s\n", (guint)mop,
- g_slist_length (mop->operations), (guint)op, seahorse_operation_get_message (op)));
+ seahorse_debug ("[multi-operation %p] part complete (%d): %p/%s", mop,
+ g_slist_length (mop->operations), op, seahorse_operation_get_message (op));
/* Are we done with all of them? */
for (l = mop->operations; l; l = g_slist_next (l)) {
@@ -671,7 +657,7 @@ multi_operation_done (SeahorseOperation *op, SeahorseMultiOperation *mop)
return;
}
- DEBUG_OPERATION (("[multi-operation 0x%08X] complete\n", (guint)mop));
+ seahorse_debug ("[multi-operation %p] complete", mop);
/* Remove all the listeners */
for (l = mop->operations; l; l = g_slist_next (l)) {
@@ -821,11 +807,11 @@ seahorse_multi_operation_take (SeahorseMultiOperation* mop, SeahorseOperation *o
g_return_if_fail (SEAHORSE_OPERATION (op) != SEAHORSE_OPERATION (mop));
if(mop->operations == NULL) {
- DEBUG_OPERATION (("[multi-operation 0x%08X] start\n", (guint)mop));
+ seahorse_debug ("[multi-operation %p] start", mop);
seahorse_operation_mark_start (SEAHORSE_OPERATION (mop));
}
- DEBUG_OPERATION (("[multi-operation 0x%08X] adding part: 0x%08X\n", (guint)mop, (guint)op));
+ seahorse_debug ("[multi-operation %p] adding part: %p", mop, op);
mop->operations = seahorse_operation_list_add (mop->operations, op);
seahorse_operation_watch (op, (SeahorseDoneFunc)multi_operation_done, mop,
diff --git a/libseahorse/seahorse-transfer-operation.c b/libseahorse/seahorse-transfer-operation.c
index dd258c5..6ae7c19 100644
--- a/libseahorse/seahorse-transfer-operation.c
+++ b/libseahorse/seahorse-transfer-operation.c
@@ -26,19 +26,8 @@
#include "seahorse-transfer-operation.h"
#include "seahorse-util.h"
-#ifndef DEBUG_OPERATION_ENABLE
-#if _DEBUG
-#define DEBUG_OPERATION_ENABLE 1
-#else
-#define DEBUG_OPERATION_ENABLE 0
-#endif
-#endif
-
-#if DEBUG_OPERATION_ENABLE
-#define DEBUG_OPERATION(x) g_printerr x
-#else
-#define DEBUG_OPERATION(x)
-#endif
+#define DEBUG_FLAG SEAHORSE_DEBUG_OPERATION
+#include "seahorse-debug.h"
/* -----------------------------------------------------------------------------
* DEFINITIONS
@@ -92,9 +81,9 @@ import_progress (SeahorseOperation *op, const gchar *message,
SeahorseTransferOperationPrivate *pv = SEAHORSE_TRANSFER_OPERATION_GET_PRIVATE (top);
g_assert (op == pv->operation);
-
- DEBUG_OPERATION (("[transfer] import progress: %lf\n", fract));
-
+
+ seahorse_debug ("[transfer] import progress: %lf", fract);
+
if (seahorse_operation_is_running (SEAHORSE_OPERATION (top))) {
message = pv->message ? pv->message : message;
fract = fract <= 0 ? 0.5 : (0.5 + (fract / 2.0));
@@ -110,7 +99,7 @@ import_done (SeahorseOperation *op, SeahorseTransferOperation *top)
GError *err = NULL;
g_assert (op == pv->operation);
- DEBUG_OPERATION (("[transfer] import done\n"));
+ seahorse_debug ("[transfer] import done");
/* A release guard */
g_object_ref (top);
@@ -142,8 +131,8 @@ export_progress (SeahorseOperation *op, const gchar *message,
SeahorseTransferOperationPrivate *pv = SEAHORSE_TRANSFER_OPERATION_GET_PRIVATE (top);
g_assert (op == pv->operation);
- DEBUG_OPERATION (("[transfer] export progress: %lf\n", fract));
-
+ seahorse_debug ("[transfer] export progress: %lf", fract);
+
if (seahorse_operation_is_running (SEAHORSE_OPERATION (top)))
seahorse_operation_mark_progress (SEAHORSE_OPERATION (top),
pv->message ? pv->message : message,
@@ -161,7 +150,7 @@ export_done (SeahorseOperation *op, SeahorseTransferOperation *top)
gsize size;
g_assert (op == pv->operation);
- DEBUG_OPERATION (("[transfer] export done\n"));
+ seahorse_debug ("[transfer] export done");
/* A release guard */
g_object_ref (top);
@@ -181,13 +170,13 @@ export_done (SeahorseOperation *op, SeahorseTransferOperation *top)
/* End release guard */
g_object_unref (top);
-
- if (done) {
- DEBUG_OPERATION (("[transfer] stopped after export\n"));
- return;
- }
-
- /* Build an input stream for this */
+
+ if (done) {
+ seahorse_debug ("[transfer] stopped after export");
+ return;
+ }
+
+ /* Build an input stream for this */
data = g_memory_output_stream_get_data (pv->output);
size = seahorse_util_memory_output_length (pv->output);
@@ -195,9 +184,9 @@ export_done (SeahorseOperation *op, SeahorseTransferOperation *top)
seahorse_operation_mark_done (SEAHORSE_OPERATION (top), FALSE, NULL);
return;
}
-
- DEBUG_OPERATION (("[transfer] starting import\n"));
-
+
+ seahorse_debug ("[transfer] starting import");
+
g_return_if_fail (data);
input = g_memory_input_stream_new_from_data (g_memdup (data, size), size, g_free);
@@ -375,8 +364,8 @@ seahorse_transfer_operation_new (const gchar *message, SeahorseSource *from,
top = g_object_new (SEAHORSE_TYPE_TRANSFER_OPERATION, "message", message,
"from-key-source", from, "to-key-source", to, NULL);
-
- DEBUG_OPERATION (("[transfer] starting export\n"));
+
+ seahorse_debug ("[transfer] starting export");
/* A list of quarks, so a deep copy is not necessary */
g_object_set_data_full (G_OBJECT (top), "transfer-key-ids", g_slist_copy (keyids),
diff --git a/libseahorse/seahorse-util.h b/libseahorse/seahorse-util.h
index 2ca131c..d3bafe3 100644
--- a/libseahorse/seahorse-util.h
+++ b/libseahorse/seahorse-util.h
@@ -189,10 +189,4 @@ SeahorseVersion seahorse_util_parse_version (const char *version);
g_thread_yield (); \
}
-#ifdef _DEBUG
-#define DBG_PRINT(x) g_printerr x
-#else
-#define DBG_PRINT(x)
-#endif
-
#endif /* __SEAHORSE_UTIL_H__ */
diff --git a/pgp/seahorse-gpgme-key-op.c b/pgp/seahorse-gpgme-key-op.c
index 2cfdb33..0988256 100644
--- a/pgp/seahorse-gpgme-key-op.c
+++ b/pgp/seahorse-gpgme-key-op.c
@@ -41,6 +41,9 @@
#include "pgp/seahorse-gpgme-key-op.h"
#include "pgp/seahorse-gpgme-operation.h"
+#define DEBUG_FLAG SEAHORSE_DEBUG_KEYS
+#include "seahorse-debug.h"
+
#define PROMPT "keyedit.prompt"
#define QUIT "quit"
#define SAVE "keyedit.save.okay"
@@ -50,21 +53,6 @@
#define PRINT(args) if(!seahorse_util_print_fd args) return GPG_E (GPG_ERR_GENERAL)
#define PRINTF(args) if(!seahorse_util_printf_fd args) return GPG_E (GPG_ERR_GENERAL)
-
-#ifndef DEBUG_OPERATION_ENABLE
-#if _DEBUG
-#define DEBUG_OPERATION_ENABLE 1
-#else
-#define DEBUG_OPERATION_ENABLE 0
-#endif
-#endif
-
-#if DEBUG_OPERATION_ENABLE
-#define DEBUG_OPERATION(x) g_printerr x
-#else
-#define DEBUG_OPERATION(x)
-#endif
-
#define GPG_UNKNOWN 1
#define GPG_NEVER 2
#define GPG_MARGINAL 3
@@ -257,10 +245,10 @@ seahorse_gpgme_key_op_edit (gpointer data, gpgme_status_code_t status,
status == GPGME_STATUS_SIGEXPIRED || status == GPGME_STATUS_KEYEXPIRED ||
status == GPGME_STATUS_PROGRESS || status == GPGME_STATUS_KEY_CREATED ||
status == GPGME_STATUS_ALREADY_SIGNED || status == GPGME_STATUS_MISSING_PASSPHRASE)
- return parms->err;
-
- DEBUG_OPERATION (("[edit key] state: %d / status: %d / args: %s\n",
- parms->state, status, args));
+ return parms->err;
+
+ seahorse_debug ("[edit key] state: %d / status: %d / args: %s",
+ parms->state, status, args);
/* Choose the next state based on the current one and the input */
parms->state = parms->transit (parms->state, status, args, parms->data, &parms->err);
@@ -834,9 +822,9 @@ seahorse_gpgme_key_op_set_trust (SeahorseGpgmeKey *pkey, SeahorseValidity trust)
{
SeahorseEditParm *parms;
gint menu_choice;
-
- DEBUG_OPERATION(("[GPGME_KEY_OP] set_trust: trust = %i",trust));
-
+
+ seahorse_debug ("[GPGME_KEY_OP] set_trust: trust = %i", trust);
+
g_return_val_if_fail (SEAHORSE_IS_GPGME_KEY (pkey), GPG_E (GPG_ERR_WRONG_KEY_USAGE));
g_return_val_if_fail (trust >= SEAHORSE_VALIDITY_NEVER, GPG_E (GPG_ERR_INV_VALUE));
g_return_val_if_fail (seahorse_gpgme_key_get_trust (pkey) != trust, GPG_E (GPG_ERR_INV_VALUE));
@@ -2394,7 +2382,7 @@ photoid_load_transit (guint current_state, gpgme_status_code_t status,
case PHOTO_ID_LOAD_DESELECT:
if (parm->uid < parm->num_uids) {
parm->uid = parm->uid + 1;
- DEBUG_OPERATION (("PhotoIDLoad Next UID %i\n", parm->uid));
+ seahorse_debug ("PhotoIDLoad Next UID %i", parm->uid);
if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, PROMPT)) {
next_state = PHOTO_ID_LOAD_SELECT;
} else {
@@ -2404,7 +2392,7 @@ photoid_load_transit (guint current_state, gpgme_status_code_t status,
} else {
if (status == GPGME_STATUS_GET_LINE && g_str_equal (args, PROMPT)) {
next_state = PHOTO_ID_LOAD_QUIT;
- DEBUG_OPERATION (("PhotoIDLoad Quiting Load\n"));
+ seahorse_debug ("PhotoIDLoad Quiting Load");
} else {
*err = GPG_E (GPG_ERR_GENERAL);
g_return_val_if_reached (PHOTO_ID_LOAD_ERROR);
@@ -2415,7 +2403,7 @@ photoid_load_transit (guint current_state, gpgme_status_code_t status,
case PHOTO_ID_LOAD_QUIT:
/* Shouldn't be reached */
*err = GPG_E (GPG_ERR_GENERAL);
- DEBUG_OPERATION (("PhotoIDLoad Reached Quit\n"));
+ seahorse_debug ("PhotoIDLoad Reached Quit");
g_return_val_if_reached (PHOTO_ID_LOAD_ERROR);
break;
@@ -2449,9 +2437,9 @@ seahorse_gpgme_key_op_photos_load (SeahorseGpgmeKey *pkey)
g_return_val_if_fail (key, GPG_E (GPG_ERR_INV_VALUE));
g_return_val_if_fail (key->subkeys && key->subkeys->keyid, GPG_E (GPG_ERR_INV_VALUE));
keyid = key->subkeys->keyid;
-
- DEBUG_OPERATION (("PhotoIDLoad Start\n"));
-
+
+ seahorse_debug ("PhotoIDLoad Start");
+
fd = g_mkstemp (image_path);
if(fd == -1) {
gerr = GPG_E(GPG_ERR_GENERAL);
@@ -2467,11 +2455,11 @@ seahorse_gpgme_key_op_photos_load (SeahorseGpgmeKey *pkey)
photoid_load_parm.photos = NULL;
photoid_load_parm.output_file = image_path;
photoid_load_parm.key = key;
-
- DEBUG_OPERATION (("PhotoIdLoad KeyID %s\n", keyid));
+
+ seahorse_debug ("PhotoIdLoad KeyID %s", keyid);
gerr = seahorse_gpg_op_num_uids (NULL, keyid, &(photoid_load_parm.num_uids));
- DEBUG_OPERATION (("PhotoIDLoad Number of UIDs %i\n", photoid_load_parm.num_uids));
-
+ seahorse_debug ("PhotoIDLoad Number of UIDs %i", photoid_load_parm.num_uids);
+
if (GPG_IS_OK (gerr)) {
setenv ("SEAHORSE_IMAGE_FILE", image_path, 1);
@@ -2494,9 +2482,9 @@ seahorse_gpgme_key_op_photos_load (SeahorseGpgmeKey *pkey)
seahorse_object_list_free (photoid_load_parm.photos);
}
-
- DEBUG_OPERATION (("PhotoIDLoad Done\n"));
-
+
+ seahorse_debug ("PhotoIDLoad Done");
+
return gerr;
}
diff --git a/pgp/seahorse-gpgme-operation.c b/pgp/seahorse-gpgme-operation.c
index 5372ba6..a5ec916 100644
--- a/pgp/seahorse-gpgme-operation.c
+++ b/pgp/seahorse-gpgme-operation.c
@@ -27,21 +27,8 @@
#include "pgp/seahorse-gpgme-operation.h"
#include "pgp/seahorse-gpgme-source.h"
-#define DEBUG_OPERATION_ENABLE 0
-
-#ifndef DEBUG_OPERATION_ENABLE
-#if _DEBUG
-#define DEBUG_OPERATION_ENABLE 1
-#else
-#define DEBUG_OPERATION_ENABLE 0
-#endif
-#endif
-
-#if DEBUG_OPERATION_ENABLE
-#define DEBUG_OPERATION(x) g_printerr x
-#else
-#define DEBUG_OPERATION(x)
-#endif
+#define DEBUG_FLAG SEAHORSE_DEBUG_OPERATION
+#include "seahorse-debug.h"
/* -----------------------------------------------------------------------------
* DEFINITIONS
@@ -122,7 +109,7 @@ END_IMPLEMENT_OPERATION_PROPS
static gboolean
io_callback (GIOChannel *source, GIOCondition condition, WatchData *watch)
{
- DEBUG_OPERATION (("GPGME OP: io for GPGME on %d\n", watch->fd));
+ seahorse_debug ("GPGME OP: io for GPGME on %d", watch->fd);
(watch->fnc) (watch->fnc_data, g_io_channel_unix_get_fd (source));
return TRUE;
}
@@ -135,9 +122,9 @@ register_watch (WatchData *watch)
if (watch->registered)
return;
-
- DEBUG_OPERATION (("GPGME OP: registering watch %d\n", watch->fd));
-
+
+ seahorse_debug ("GPGME OP: registering watch %d", watch->fd);
+
channel = g_io_channel_unix_new (watch->fd);
watch->stag = g_io_add_watch_full (channel, G_PRIORITY_DEFAULT,
watch->dir ? READ_CONDITION : WRITE_CONDITION,
@@ -152,9 +139,9 @@ unregister_watch (WatchData *watch)
{
if (!watch->registered)
return;
-
- DEBUG_OPERATION (("GPGME OP: unregistering watch %d\n", watch->fd));
-
+
+ seahorse_debug ("GPGME OP: unregistering watch %d", watch->fd);
+
g_source_remove (watch->stag);
watch->stag = 0;
watch->registered = FALSE;
@@ -171,9 +158,9 @@ progress_cb (void *data, const char *what, int type,
{
SeahorseGpgmeOperation *pop = SEAHORSE_GPGME_OPERATION (data);
SeahorseGpgmeOperationPrivate *pv = SEAHORSE_GPGME_OPERATION_GET_PRIVATE (pop);
-
- DEBUG_OPERATION (("GPGME OP: got progress: %s %d/%d\n", what, current, total));
-
+
+ seahorse_debug ("GPGME OP: got progress: %s %d/%d", what, current, total);
+
if (total <= 0)
total = pv->def_total;
@@ -191,9 +178,9 @@ register_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc, void *fnc_data,
SeahorseGpgmeOperation *pop = SEAHORSE_GPGME_OPERATION (data);
SeahorseGpgmeOperationPrivate *pv = SEAHORSE_GPGME_OPERATION_GET_PRIVATE (pop);
WatchData *watch;
-
- DEBUG_OPERATION (("PGPOP: request to register watch %d\n", fd));
-
+
+ seahorse_debug ("PGPOP: request to register watch %d", fd);
+
watch = g_new0 (WatchData, 1);
watch->registered = FALSE;
watch->fd = fd;
@@ -224,7 +211,7 @@ remove_cb (void *tag)
pv = SEAHORSE_GPGME_OPERATION_GET_PRIVATE (watch->op);
- DEBUG_OPERATION (("PGPOP: request to remove watch %d\n", watch->fd));
+ seahorse_debug ("PGPOP: request to remove watch %d", watch->fd);
pv->watches = g_list_remove (pv->watches, watch);
unregister_watch (watch);
@@ -246,9 +233,9 @@ event_cb (void *data, gpgme_event_io_t type, void *type_data)
/* Called when the GPGME context starts an operation */
case GPGME_EVENT_START:
pv->busy = TRUE;
-
- DEBUG_OPERATION (("PGPOP: start event\n"));
-
+
+ seahorse_debug ("PGPOP: start event");
+
/* Since we weren't supposed to register these before, do it now */
for (list = pv->watches; list; list = g_list_next (list))
register_watch ((WatchData*)(list->data));
@@ -266,9 +253,9 @@ event_cb (void *data, gpgme_event_io_t type, void *type_data)
case GPGME_EVENT_DONE:
pv->busy = FALSE;
gerr = (gpgme_error_t*)type_data;
-
- DEBUG_OPERATION (("PGPOP: done event (err: %d)\n", *gerr));
-
+
+ seahorse_debug ("PGPOP: done event (err: %d)", *gerr);
+
/* Make sure we have no extra watches left over */
for (list = pv->watches; list; list = g_list_next (list))
unregister_watch ((WatchData*)(list->data));
diff --git a/pgp/seahorse-gpgme-source.c b/pgp/seahorse-gpgme-source.c
index b2cd86b..f08c27e 100644
--- a/pgp/seahorse-gpgme-source.c
+++ b/pgp/seahorse-gpgme-source.c
@@ -44,24 +44,10 @@
#include <libintl.h>
#include <locale.h>
-/* TODO: Verify properly that all keys we deal with are PGP keys */
-
-/* Override the DEBUG_REFRESH_ENABLE switch here */
-#define DEBUG_REFRESH_ENABLE 0
+#define DEBUG_FLAG SEAHORSE_DEBUG_OPERATION
+#include "seahorse-debug.h"
-#ifndef DEBUG_REFRESH_ENABLE
-#if _DEBUG
-#define DEBUG_REFRESH_ENABLE 1
-#else
-#define DEBUG_REFRESH_ENABLE 0
-#endif
-#endif
-
-#if DEBUG_REFRESH_ENABLE
-#define DEBUG_REFRESH(x) g_printerr(x)
-#else
-#define DEBUG_REFRESH(x)
-#endif
+/* TODO: Verify properly that all keys we deal with are PGP keys */
/* Amount of keys to load in a batch */
#define DEFAULT_LOAD_BATCH 200
@@ -538,7 +524,7 @@ scheduled_refresh (gpointer data)
{
SeahorseGpgmeSource *psrc = SEAHORSE_GPGME_SOURCE (data);
- DEBUG_REFRESH ("scheduled refresh event ocurring now\n");
+ seahorse_debug ("scheduled refresh event ocurring now");
cancel_scheduled_refresh (psrc);
seahorse_source_load_async (SEAHORSE_SOURCE (psrc));
@@ -549,7 +535,7 @@ static gboolean
scheduled_dummy (gpointer data)
{
SeahorseGpgmeSource *psrc = SEAHORSE_GPGME_SOURCE (data);
- DEBUG_REFRESH ("dummy refresh event occurring now\n");
+ seahorse_debug ("dummy refresh event occurring now");
psrc->pv->scheduled_refresh = 0;
return FALSE; /* don't run again */
}
@@ -558,7 +544,7 @@ static void
cancel_scheduled_refresh (SeahorseGpgmeSource *psrc)
{
if (psrc->pv->scheduled_refresh != 0) {
- DEBUG_REFRESH ("cancelling scheduled refresh event\n");
+ seahorse_debug ("cancelling scheduled refresh event");
g_source_remove (psrc->pv->scheduled_refresh);
psrc->pv->scheduled_refresh = 0;
}
@@ -578,7 +564,7 @@ monitor_gpg_homedir (GFileMonitor *handle, GFile *file, GFile *other_file,
name = g_file_get_basename (file);
if (g_str_has_suffix (name, SEAHORSE_EXT_GPG)) {
if (psrc->pv->scheduled_refresh == 0) {
- DEBUG_REFRESH ("scheduling refresh event due to file changes\n");
+ seahorse_debug ("scheduling refresh event due to file changes");
psrc->pv->scheduled_refresh = g_timeout_add (500, scheduled_refresh, psrc);
}
}
@@ -878,9 +864,9 @@ seahorse_gpgme_source_load (SeahorseSource *src)
/* Schedule a dummy refresh. This blocks all monitoring for a while */
cancel_scheduled_refresh (psrc);
psrc->pv->scheduled_refresh = g_timeout_add (500, scheduled_dummy, psrc);
- DEBUG_REFRESH ("scheduled a dummy refresh\n");
+ seahorse_debug ("scheduled a dummy refresh");
- DEBUG_REFRESH ("refreshing keys...\n");
+ seahorse_debug ("refreshing keys...");
/* Secret keys */
lop = seahorse_load_operation_start (psrc, NULL, 0, FALSE);
diff --git a/pgp/seahorse-hkp-source.c b/pgp/seahorse-hkp-source.c
index 177cca6..eb10b1e 100644
--- a/pgp/seahorse-hkp-source.c
+++ b/pgp/seahorse-hkp-source.c
@@ -42,6 +42,9 @@
#include <libsoup/soup.h>
+#define DEBUG_FLAG SEAHORSE_DEBUG_HKP
+#include "seahorse-debug.h"
+
/**
* SECTION: seahorse-hkp-source
* @short_description: Implements the HKP (HTTP Keyserver protocol) Source object
@@ -52,17 +55,6 @@
#ifdef WITH_HKP
-/* Override the DEBUG_HKP_ENABLE switch here */
-/* #define DEBUG_HKP_ENABLE 1 */
-
-#ifndef DEBUG_HKP_ENABLE
-#if _DEBUG
-#define DEBUG_HKP_ENABLE 1
-#else
-#define DEBUG_HKP_ENABLE 0
-#endif
-#endif
-
#define PGP_KEY_BEGIN "-----BEGIN PGP PUBLIC KEY BLOCK-----"
#define PGP_KEY_END "-----END PGP PUBLIC KEY BLOCK-----"
@@ -165,7 +157,7 @@ seahorse_hkp_operation_init (SeahorseHKPOperation *hop)
{
SoupURI *uri;
gchar *host;
-#if DEBUG_HKP_ENABLE
+#if WITH_DEBUG
SoupLogger *logger;
#endif
@@ -206,10 +198,12 @@ seahorse_hkp_operation_init (SeahorseHKPOperation *hop)
if (!hop->session)
hop->session = soup_session_async_new ();
-#if DEBUG_HKP_ENABLE
- logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1);
- soup_logger_attach (logger, hop->session);
- g_object_unref (logger);
+#if WITH_DEBUG
+ if (seahorse_debugging) {
+ logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1);
+ soup_logger_attach (logger, hop->session);
+ g_object_unref (logger);
+ }
#endif
}
@@ -490,9 +484,8 @@ parse_hkp_index (const gchar *response)
line = *l;
dehtmlize (line);
-#if DEBUG_HKP_ENABLE
- fprintf(stderr,"%s\n", line);
-#endif
+
+ seahorse_debug ("%s", line);
/* Start a new key */
if (g_ascii_strncasecmp (line, "pub ", 4) == 0) {
diff --git a/pgp/seahorse-ldap-source.c b/pgp/seahorse-ldap-source.c
index 9662c47..517851d 100644
--- a/pgp/seahorse-ldap-source.c
+++ b/pgp/seahorse-ldap-source.c
@@ -48,24 +48,8 @@
#ifdef WITH_LDAP
-/* Override the DEBUG_LDAP_ENABLE switch here */
-/* #define DEBUG_LDAP_ENABLE 1 */
-
-#ifndef DEBUG_LDAP_ENABLE
-#if _DEBUG
-#define DEBUG_LDAP_ENABLE 1
-#else
-#define DEBUG_LDAP_ENABLE 0
-#endif
-#endif
-
-#if DEBUG_LDAP_ENABLE
-#define DEBUG_LDAP(x) g_printerr x
-#define DEBUG_LDAP_ENTRY(a,b) dump_ldap_entry(a,b)
-#else
-#define DEBUG_LDAP(x)
-#define DEBUG_LDAP_ENTRY(a,b)
-#endif
+#define DEBUG_FLAG SEAHORSE_DEBUG_LDAP
+#include "seahorse-debug.h"
/* Amount of keys to load in a batch */
#define DEFAULT_LOAD_BATCH 30
@@ -146,7 +130,7 @@ get_ldap_values (LDAP *ld, LDAPMessage *entry, const char *attribute)
return (gchar**)g_array_free (array, FALSE);
}
-#if DEBUG_LDAP_ENABLE
+#if WITH_DEBUG
static void
dump_ldap_entry (LDAP *ld, LDAPMessage *res)
@@ -174,7 +158,7 @@ dump_ldap_entry (LDAP *ld, LDAPMessage *res)
ber_free (pos, 0);
}
-#endif
+#endif /* WITH_DEBUG */
static GQuark
get_ldap_error_domain ()
@@ -531,8 +515,11 @@ done_info_start_op (SeahorseOperation *op, LDAPMessage *result)
/* If we have results then fill in the server info */
if (r == LDAP_RES_SEARCH_ENTRY) {
- DEBUG_LDAP (("[ldap] Server Info Result:\n"));
- DEBUG_LDAP_ENTRY (lop->ldap, result);
+ seahorse_debug ("Server Info Result:");
+#ifdef WITH_DEBUG
+ if (seahorse_debugging)
+ dump_ldap_entry (lop->ldap, result);
+#endif
/* NOTE: When adding attributes here make sure to add them to kServerAttributes */
sinfo = g_new0 (LDAPServerInfo, 1);
@@ -860,10 +847,13 @@ search_entry (SeahorseOperation *op, LDAPMessage *result)
/* An LDAP entry */
if (r == LDAP_RES_SEARCH_ENTRY) {
-
- DEBUG_LDAP (("[ldap] Retrieved Key Entry:\n"));
- DEBUG_LDAP_ENTRY (lop->ldap, result);
-
+
+ seahorse_debug ("Retrieved Key Entry:");
+#ifdef WITH_DEBUG
+ if (seahorse_debugging)
+ dump_ldap_entry (lop->ldap, result);
+#endif
+
parse_key_from_ldap_entry (lop, result);
return TRUE;
@@ -918,8 +908,8 @@ start_search (SeahorseOperation *op, LDAPMessage *result)
sinfo = get_ldap_server_info (lop->lsrc, TRUE);
- DEBUG_LDAP (("[ldap] Searching Server ... base: %s, filter: %s\n",
- sinfo->base_dn, filter));
+ seahorse_debug ("Searching Server ... base: %s, filter: %s",
+ sinfo->base_dn, filter);
r = ldap_search_ext (lop->ldap, sinfo->base_dn, LDAP_SCOPE_SUBTREE,
filter, (char**)kPGPAttributes, 0,
@@ -1015,9 +1005,12 @@ get_callback (SeahorseOperation *op, LDAPMessage *result)
/* An LDAP Entry */
if (r == LDAP_RES_SEARCH_ENTRY) {
-
- DEBUG_LDAP (("[ldap] Retrieved Key Data:\n"));
- DEBUG_LDAP_ENTRY (lop->ldap, result);
+
+ seahorse_debug ("Server Info Result:");
+#ifdef WITH_DEBUG
+ if (seahorse_debugging)
+ dump_ldap_entry (lop->ldap, result);
+#endif
key = get_string_attribute (lop->ldap, result, sinfo->key_attr);
diff --git a/pgp/seahorse-pgp-key-properties.c b/pgp/seahorse-pgp-key-properties.c
index 8081045..5de3b68 100644
--- a/pgp/seahorse-pgp-key-properties.c
+++ b/pgp/seahorse-pgp-key-properties.c
@@ -48,6 +48,9 @@
#include "common/seahorse-bind.h"
+#define DEBUG_FLAG SEAHORSE_DEBUG_KEYS
+#include "seahorse-debug.h"
+
#include <time.h>
#define NOTEBOOK "notebook"
@@ -1110,8 +1113,8 @@ setup_details_trust (SeahorseWidget *swidget)
GtkTreeIter iter;
GtkCellRenderer *text_cell = gtk_cell_renderer_text_new ();
- DBG_PRINT(("KeyProperties: Setting up Trust Combo Box Store\n"));
-
+ seahorse_debug ("KeyProperties: Setting up Trust Combo Box Store");
+
object = SEAHORSE_OBJECT_WIDGET (swidget)->object;
etype = seahorse_object_get_usage (object);
@@ -1162,7 +1165,7 @@ setup_details_trust (SeahorseWidget *swidget)
gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (model));
- DBG_PRINT(("KeyProperties: Finished Setting up Trust Combo Box Store\n"));
+ seahorse_debug ("KeyProperties: Finished Setting up Trust Combo Box Store");
}
static void
diff --git a/src/seahorse-key-manager-store.c b/src/seahorse-key-manager-store.c
index d54d7f3..ee92703 100644
--- a/src/seahorse-key-manager-store.c
+++ b/src/seahorse-key-manager-store.c
@@ -34,6 +34,9 @@
#include "seahorse-util.h"
#include "seahorse-validity.h"
+#define DEBUG_FLAG SEAHORSE_DEBUG_DRAG
+#include "seahorse-debug.h"
+
#include "eggtreemultidnd.h"
#define KEY_MANAGER_SORT_KEY "/apps/seahorse/listing/sort_by"
@@ -471,9 +474,9 @@ drag_begin (GtkWidget *widget, GdkDragContext *context, SeahorseKeyManagerStore
#if GTK_CHECK_VERSION (2,22,0)
GdkWindow *source_window;
- #endif
-
- DBG_PRINT (("drag_begin -->\n"));
+#endif
+
+ seahorse_debug ("drag_begin -->");
g_free (skstore->priv->drag_destination);
skstore->priv->drag_destination = NULL;
@@ -497,7 +500,7 @@ drag_begin (GtkWidget *widget, GdkDragContext *context, SeahorseKeyManagerStore
}
#endif
- DBG_PRINT (("drag_begin <--\n"));
+ seahorse_debug ("drag_begin <--");
return skstore->priv->drag_objects ? TRUE : FALSE;
}
@@ -512,7 +515,7 @@ export_keys_to_output (GList *objects, GOutputStream *output, GError **error)
gboolean ret;
objects = seahorse_util_objects_sort (objects);
- DBG_PRINT (("exporting %d objects\n", g_list_length (objects)));
+ seahorse_debug ("exporting %d objects", g_list_length (objects));
while (objects) {
@@ -565,7 +568,7 @@ export_to_text (SeahorseKeyManagerStore *skstore, GtkSelectionData *selection_da
g_return_val_if_fail (skstore->priv->drag_objects, FALSE);
keys = g_list_copy (skstore->priv->drag_objects);
- DBG_PRINT (("exporting to text\n"));
+ seahorse_debug ("exporting to text");
output = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
g_return_val_if_fail (output, FALSE);
@@ -574,7 +577,7 @@ export_to_text (SeahorseKeyManagerStore *skstore, GtkSelectionData *selection_da
ret = export_keys_to_output (keys, output, &skstore->priv->drag_error) &&
g_output_stream_close (output, NULL, &skstore->priv->drag_error);
if (ret) {
- DBG_PRINT (("setting selection text\n"));
+ seahorse_debug ("setting selection text");
gtk_selection_data_set_text (selection_data,
g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output)),
seahorse_util_memory_output_length (G_MEMORY_OUTPUT_STREAM (output)));
@@ -596,8 +599,8 @@ export_to_filename (SeahorseKeyManagerStore *skstore, const gchar *filename)
gchar *uri;
GFile *file;
GList *keys;
-
- DBG_PRINT (("exporting to %s\n", filename));
+
+ seahorse_debug ("exporting to %s", filename);
ret = FALSE;
g_return_val_if_fail (skstore->priv->drag_objects, FALSE);
@@ -630,13 +633,13 @@ drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *sel
gchar *destination;
gboolean ret;
- DBG_PRINT (("drag_data_get %d -->\n", info));
+ seahorse_debug ("drag_data_get %d -->", info);
g_return_val_if_fail (skstore->priv->drag_objects, FALSE);
/* The caller wants plain text */
if (info == DRAG_INFO_TEXT) {
- DBG_PRINT (("returning object text\n"));
+ seahorse_debug ("returning object text");
export_to_text (skstore, selection_data);
/* The caller wants XDS */
@@ -654,10 +657,10 @@ drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *sel
/* Unrecognized format */
} else {
- DBG_PRINT (("Unrecognized format: %d\n", info));
+ seahorse_debug ("Unrecognized format: %d", info);
}
- DBG_PRINT(("drag_data_get <--\n"));
+ seahorse_debug ("drag_data_get <--");
return ret;
}
@@ -665,9 +668,9 @@ static void
drag_end (GtkWidget *widget, GdkDragContext *context, SeahorseKeyManagerStore *skstore)
{
gchar *filename, *name;
-
- DBG_PRINT (("drag_end -->\n"));
-
+
+ seahorse_debug ("drag_end -->");
+
if (skstore->priv->drag_destination && !skstore->priv->drag_error) {
g_return_if_fail (skstore->priv->drag_objects);
@@ -691,8 +694,8 @@ drag_end (GtkWidget *widget, GdkDragContext *context, SeahorseKeyManagerStore *s
skstore->priv->drag_objects = NULL;
g_free (skstore->priv->drag_destination);
skstore->priv->drag_destination = NULL;
-
- DBG_PRINT (("drag_end <--\n"));
+
+ seahorse_debug ("drag_end <--");
}
static gint
diff --git a/ssh/seahorse-ssh-operation.c b/ssh/seahorse-ssh-operation.c
index b89b2a2..2b3fbb9 100644
--- a/ssh/seahorse-ssh-operation.c
+++ b/ssh/seahorse-ssh-operation.c
@@ -35,21 +35,10 @@
#include "seahorse-util.h"
#include "seahorse-passphrase.h"
-#include <gnome-keyring.h>
-
-#ifndef DEBUG_OPERATION_ENABLE
-#if _DEBUG
-#define DEBUG_OPERATION_ENABLE 1
-#else
-#define DEBUG_OPERATION_ENABLE 0
-#endif
-#endif
+#define DEBUG_FLAG SEAHORSE_DEBUG_OPERATION
+#include "seahorse-debug.h"
-#if DEBUG_OPERATION_ENABLE
-#define DEBUG_OPERATION(x) g_printerr x
-#else
-#define DEBUG_OPERATION(x)
-#endif
+#include <gnome-keyring.h>
/* -----------------------------------------------------------------------------
* DEFINITIONS
@@ -127,8 +116,8 @@ static void
watch_ssh_process (GPid pid, gint status, SeahorseSSHOperation *sop)
{
SeahorseSSHOperationPrivate *pv = SEAHORSE_SSH_OPERATION_GET_PRIVATE (sop);
-
- DEBUG_OPERATION (("SSHOP: SSH process done\n"));
+
+ seahorse_debug ("SSHOP: SSH process done");
/* Close off the askpass io channel etc... */
if(pv->stag_askpass)
@@ -190,8 +179,8 @@ io_ssh_write (GIOChannel *source, GIOCondition condition, SeahorseSSHOperation *
gsize written = 0;
if (seahorse_operation_is_running (SEAHORSE_OPERATION (sop)) && pv->sin) {
- DEBUG_OPERATION (("SSHOP: SSH ready for input\n"));
-
+ seahorse_debug ("SSHOP: SSH ready for input");
+
status = g_io_channel_write_chars (pv->iin, pv->sin->str, pv->sin->len,
&written, &error);
switch (status) {
@@ -201,20 +190,20 @@ io_ssh_write (GIOChannel *source, GIOCondition condition, SeahorseSSHOperation *
case G_IO_STATUS_AGAIN:
break;
default:
- DEBUG_OPERATION (("SSHOP: Wrote %d bytes to SSH\n", (gint)written));
+ seahorse_debug ("SSHOP: Wrote %d bytes to SSH", (gint)written);
g_string_erase (pv->sin, 0, written);
break;
}
}
if (pv->sin && !pv->sin->len) {
- DEBUG_OPERATION (("SSHOP: Finished writing SSH input\n"));
+ seahorse_debug ("SSHOP: Finished writing SSH input");
g_string_free (pv->sin, TRUE);
pv->sin = NULL;
}
if (!seahorse_operation_is_running (SEAHORSE_OPERATION (sop)) || !pv->sin) {
- DEBUG_OPERATION (("SSHOP: Closing SSH input channel\n"));
+ seahorse_debug ("SSHOP: Closing SSH input channel");
g_io_channel_unref (pv->iin);
pv->iin = NULL;
g_source_remove (pv->win);
@@ -241,10 +230,10 @@ io_ssh_read (GIOChannel *source, GIOCondition condition, SeahorseSSHOperation *s
/* Figure out which buffer we're writing into */
if (source == pv->iout) {
str = pv->sout;
- DEBUG_OPERATION (("SSHOP: SSH output: "));
+ seahorse_debug ("SSHOP: SSH output: ");
} else if(source == pv->ierr) {
str = pv->serr;
- DEBUG_OPERATION (("SSHOP: SSH errout: "));
+ seahorse_debug ("SSHOP: SSH errout: ");
} else
g_assert_not_reached ();
@@ -260,7 +249,7 @@ io_ssh_read (GIOChannel *source, GIOCondition condition, SeahorseSSHOperation *s
break;
default:
g_string_append_len (str, buf, read);
- DEBUG_OPERATION (("%s\n", str->str + (str->len - read)));
+ seahorse_debug ("%s", str->str + (str->len - read));
break;
}
} while (read == sizeof (buf));
@@ -295,8 +284,8 @@ askpass_handler (GIOChannel *source, GIOCondition condition, SeahorseSSHOperatio
if (string && ret) {
string[length] = 0;
- DEBUG_OPERATION (("SSHOP: seahorse-ssh-askpass request: %s\n", string));
-
+ seahorse_debug ("SSHOP: seahorse-ssh-askpass request: \"%s\"", string);
+
if (g_ascii_strncasecmp (COMMAND_PASSWORD, string, COMMAND_PASSWORD_LEN) == 0) {
line = g_strstrip (string + COMMAND_PASSWORD_LEN);
@@ -308,7 +297,7 @@ askpass_handler (GIOChannel *source, GIOCondition condition, SeahorseSSHOperatio
if (!result) {
if (seahorse_operation_is_running (SEAHORSE_OPERATION (sop)))
seahorse_operation_cancel (SEAHORSE_OPERATION (sop));
- DEBUG_OPERATION (("SSHOP: password prompt cancelled\n"));
+ seahorse_debug ("SSHOP: password prompt cancelled");
ret = FALSE;
}
}
@@ -318,11 +307,11 @@ askpass_handler (GIOChannel *source, GIOCondition condition, SeahorseSSHOperatio
if (ret) {
/* And write the result back out to seahorse-ssh-askpass */
- DEBUG_OPERATION (("SSHOP: seahorse-ssh-askpass response: %s\n", result ? result : ""));
+ seahorse_debug ("SSHOP: seahorse-ssh-askpass response: %s", result ? result : "");
if (result)
g_io_channel_write_chars (pv->io_askpass, result, strlen (result), &length, &err);
if (err == NULL)
- g_io_channel_write_chars (pv->io_askpass, "\n", 1, &length, &err);
+ g_io_channel_write_chars (pv->io_askpass, "", 1, &length, &err);
if (err == NULL)
g_io_channel_flush (pv->io_askpass, &err);
if (err != NULL) {
@@ -623,7 +612,7 @@ seahorse_ssh_operation_new (SeahorseSSHSource *ssrc, const gchar *command,
g_return_val_if_fail (command && command[0], NULL);
if (!g_shell_parse_argv (command, &argc, &argv, NULL)) {
- g_critical ("couldn't parse ssh command line: %s\n", command);
+ g_critical ("couldn't parse ssh command line: %s", command);
g_return_val_if_reached (NULL);
}
@@ -632,9 +621,9 @@ seahorse_ssh_operation_new (SeahorseSSHSource *ssrc, const gchar *command,
sop->sksrc = ssrc;
pv->prompt_skey = SEAHORSE_OBJECT (skey);
-
- DEBUG_OPERATION (("SSHOP: Executing SSH command: %s\n", command));
-
+
+ seahorse_debug ("SSHOP: Executing SSH command: %s", command);
+
/* And off we go to run the program */
r = g_spawn_async_with_pipes (NULL, argv, NULL,
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_LEAVE_DESCRIPTORS_OPEN ,
@@ -648,8 +637,8 @@ seahorse_ssh_operation_new (SeahorseSSHSource *ssrc, const gchar *command,
/* Copy the input for later writing */
if (input) {
pv->sin = g_string_new_len (input, length == -1 ? strlen (input) : length);
- DEBUG_OPERATION (("SSHOP: Will send SSH input: %s", pv->sin->str));
-
+ seahorse_debug ("SSHOP: Will send SSH input: %s", pv->sin->str);
+
fcntl (fin, F_SETFL, O_NONBLOCK | fcntl (fin, F_GETFL));
pv->iin = g_io_channel_unix_new (fin);
g_io_channel_set_encoding (pv->iin, NULL, NULL);
@@ -712,12 +701,12 @@ seahorse_ssh_operation_sync (SeahorseSSHSource *ssrc, const gchar *command,
error = &err;
if (!g_shell_parse_argv (command, &argc, &argv, NULL)) {
- g_critical ("couldn't parse ssh command line: %s\n", command);
+ g_critical ("couldn't parse ssh command line: %s", command);
return NULL;
}
-
- DEBUG_OPERATION (("SSHOP: executing SSH command: %s\n", command));
-
+
+ seahorse_debug ("SSHOP: executing SSH command: %s", command);
+
r = g_spawn_sync (NULL, argv, NULL, 0, ssh_sync_child_setup, NULL,
&sout, &serr, &status, error);
g_strfreev (argv);
@@ -756,7 +745,7 @@ seahorse_ssh_operation_sync (SeahorseSSHSource *ssrc, const gchar *command,
static const gchar*
upload_password_cb (SeahorseSSHOperation *sop, const gchar* msg)
{
- DEBUG_OPERATION (("in upload_password_cb\n"));
+ seahorse_debug ("in upload_password_cb");
/* Just prompt over and over again */
return prompt_password (sop, _("Remote Host Password"), msg, NULL, FALSE);
@@ -842,9 +831,9 @@ change_password_cb (SeahorseSSHOperation *sop, const gchar* msg)
lcase = g_strdup (msg ? msg : "");
seahorse_util_string_lower (lcase);
-
- DEBUG_OPERATION (("in change_password_cb\n"));
-
+
+ seahorse_debug ("in change_password_cb");
+
/* Need the old passphrase */
if (strstr (lcase, "old pass"))
ret = prompt_passphrase (sop, _("Old Key Passphrase"),
@@ -924,7 +913,7 @@ static const gchar*
generate_password_cb (SeahorseSSHOperation *sop, const gchar* msg)
{
SeahorseSSHOperationPrivate *pv = SEAHORSE_SSH_OPERATION_GET_PRIVATE (sop);
- DEBUG_OPERATION (("in generate_password_cb\n"));
+ seahorse_debug ("in generate_password_cb");
/* If the first time then prompt */
if (!pv->prompt_dialog) {
@@ -1190,9 +1179,9 @@ seahorse_ssh_operation_rename (SeahorseSSHSource *ssrc, SeahorseSSHKey *skey,
if (!change_raw_comment (keydata, newcomment ? newcomment : ""))
g_return_val_if_reached (NULL);
-
- DEBUG_OPERATION (("renaming key to: %s", newcomment));
-
+
+ seahorse_debug ("renaming key to: %s", newcomment);
+
/* Just part of a file for this key */
if (keydata->partial) {
g_assert (keydata->pubfile);
diff --git a/ssh/seahorse-ssh-source.c b/ssh/seahorse-ssh-source.c
index 0619d86..8551361 100644
--- a/ssh/seahorse-ssh-source.c
+++ b/ssh/seahorse-ssh-source.c
@@ -41,23 +41,8 @@
#include <glib/gi18n.h>
-/* Override DEBUG switches here */
-#define DEBUG_REFRESH_ENABLE 0
-/* #define DEBUG_OPERATION_ENABLE 1 */
-
-#ifndef DEBUG_REFRESH_ENABLE
-#if _DEBUG
-#define DEBUG_REFRESH_ENABLE 1
-#else
-#define DEBUG_REFRESH_ENABLE 0
-#endif
-#endif
-
-#if DEBUG_REFRESH_ENABLE
-#define DEBUG_REFRESH(x) g_printerr x
-#else
-#define DEBUG_REFRESH(x)
-#endif
+#define DEBUG_FLAG SEAHORSE_DEBUG_LOAD
+#include "seahorse-debug.h"
enum {
PROP_0,
@@ -145,7 +130,7 @@ static void
cancel_scheduled_refresh (SeahorseSSHSource *ssrc)
{
if (ssrc->priv->scheduled_refresh != 0) {
- DEBUG_REFRESH ("cancelling scheduled refresh event\n");
+ seahorse_debug ("cancelling scheduled refresh event");
g_source_remove (ssrc->priv->scheduled_refresh);
ssrc->priv->scheduled_refresh = 0;
}
@@ -166,7 +151,7 @@ remove_key_from_context (gpointer hkey, SeahorseObject *dummy, SeahorseSSHSource
static gboolean
scheduled_refresh (SeahorseSSHSource *ssrc)
{
- DEBUG_REFRESH ("scheduled refresh event ocurring now\n");
+ seahorse_debug ("scheduled refresh event ocurring now");
cancel_scheduled_refresh (ssrc);
seahorse_source_load_async (SEAHORSE_SOURCE (ssrc));
return FALSE; /* don't run again */
@@ -175,7 +160,7 @@ scheduled_refresh (SeahorseSSHSource *ssrc)
static gboolean
scheduled_dummy (SeahorseSSHSource *ssrc)
{
- DEBUG_REFRESH ("dummy refresh event occurring now\n");
+ seahorse_debug ("dummy refresh event occurring now");
ssrc->priv->scheduled_refresh = 0;
return FALSE; /* don't run again */
}
@@ -218,7 +203,7 @@ monitor_ssh_homedir (GFileMonitor *handle, GFile *file, GFile *other_file,
}
g_free (path);
- DEBUG_REFRESH ("scheduling refresh event due to file changes\n");
+ seahorse_debug ("scheduling refresh event due to file changes");
ssrc->priv->scheduled_refresh = g_timeout_add (500, (GSourceFunc)scheduled_refresh, ssrc);
}
@@ -420,7 +405,7 @@ seahorse_ssh_source_load (SeahorseSource *sksrc)
/* Schedule a dummy refresh. This blocks all monitoring for a while */
cancel_scheduled_refresh (ssrc);
ssrc->priv->scheduled_refresh = g_timeout_add (500, (GSourceFunc)scheduled_dummy, ssrc);
- DEBUG_REFRESH ("scheduled a dummy refresh\n");
+ seahorse_debug ("scheduled a dummy refresh");
/* List the .ssh directory for private keys */
dir = g_dir_open (ssrc->priv->ssh_homedir, 0, &err);
@@ -559,7 +544,7 @@ seahorse_ssh_source_export (SeahorseSource *sksrc, GList *keys,
/* We should already have the data loaded */
if (keydata->pubfile) {
g_assert (keydata->rawdata);
- results = g_strdup_printf ("%s\n", keydata->rawdata);
+ results = g_strdup_printf ("%s", keydata->rawdata);
/* Public key without identity.pub. Export it. */
} else if (!keydata->pubfile) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]