[krb5-auth-dialog] applet: Make signal numbers private
- From: Guido Günther <guidog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [krb5-auth-dialog] applet: Make signal numbers private
- Date: Fri, 14 Oct 2022 19:53:23 +0000 (UTC)
commit e5ce037112b432894c0fafcd6370e8617704a268
Author: Guido Günther <agx sigxcpu org>
Date: Thu Oct 13 14:06:00 2022 +0200
applet: Make signal numbers private
This makes sure signal number changes ripple through the whole
codebase. E.g. the DBus code relied on emitting all but one
signal and then did string replacements, make explicit instead.
src/ka-applet-priv.h | 14 +-------------
src/ka-applet.c | 38 ++++++++++++++++++++++++++------------
src/ka-dbus.c | 33 +++++++--------------------------
src/ka-kerberos.c | 3 +--
4 files changed, 35 insertions(+), 53 deletions(-)
---
diff --git a/src/ka-applet-priv.h b/src/ka-applet-priv.h
index 770ea1e..07f24ec 100644
--- a/src/ka-applet-priv.h
+++ b/src/ka-applet-priv.h
@@ -43,25 +43,13 @@ G_BEGIN_DECLS
#define KA_PROP_NAME_TGT_RENEWABLE "tgt-renewable"
#define KA_PROP_NAME_CONF_TICKETS "conf-tickets"
-/* signals emitted by KaApplet */
-typedef enum {
- KA_SIGNAL_ACQUIRED_TGT, /* New TGT acquired */
- KA_SIGNAL_RENEWED_TGT, /* TGT got renewed */
- KA_SIGNAL_EXPIRED_TGT, /* TGT expired or ticket cache got destroyed */
- KA_CCACHE_CHANGED, /* The credential cache changed */
- KA_SIGNAL_COUNT
-} KaAppletSignalNumber;
-
-extern const gchar *ka_signal_names[];
-
/* public functions */
void ka_applet_set_tgt_renewable (KaApplet *self, gboolean renewable);
gboolean ka_applet_get_tgt_renewable (const KaApplet *self);
guint ka_applet_get_pw_prompt_secs (const KaApplet *self);
KaPwDialog *ka_applet_get_pwdialog (const KaApplet *self);
GSettings *ka_applet_get_settings (const KaApplet *self);
-void ka_applet_signal_emit (KaApplet *self, KaAppletSignalNumber signum,
- krb5_timestamp expiry);
+void ka_applet_emit_renewed (KaApplet *self, krb5_timestamp expiry);
void ka_applet_set_msg (KaApplet *self, const char *msg);
GtkWindow* ka_applet_last_focused_window(KaApplet *self);
/* update tooltip and icon */
diff --git a/src/ka-applet.c b/src/ka-applet.c
index 3ed3193..13725ad 100644
--- a/src/ka-applet.c
+++ b/src/ka-applet.c
@@ -50,13 +50,21 @@ enum {
};
static GParamSpec *props[KA_PROP_LAST_PROP];
-const gchar *ka_signal_names[KA_SIGNAL_COUNT] = {
+enum _KaAppletSignalNumber {
+ KA_SIGNAL_ACQUIRED_TGT, /* New TGT acquired */
+ KA_SIGNAL_RENEWED_TGT, /* TGT got renewed */
+ KA_SIGNAL_EXPIRED_TGT, /* TGT expired or ticket cache got destroyed */
+ KA_CCACHE_CHANGED, /* The credential cache changed */
+ KA_SIGNAL_COUNT
+};
+static guint signals[KA_SIGNAL_COUNT];
+
+const gchar *ka_signal_names[] = {
"krb-tgt-acquired",
"krb-tgt-renewed",
"krb-tgt-expired",
"krb-ccache-changed",
};
-static guint signals[KA_SIGNAL_COUNT];
struct _KaApplet {
GtkApplication parent;
@@ -91,6 +99,18 @@ G_DEFINE_TYPE (KaApplet, ka_applet, GTK_TYPE_APPLICATION);
static gboolean is_initialized;
+static void
+ka_applet_signal_emit (KaApplet *this, guint signum, krb5_timestamp expiry)
+{
+ g_autofree char *princ = NULL;
+
+ princ = ka_unparse_name ();
+ if (!princ)
+ return;
+
+ g_signal_emit (this, signals[signum], 0, princ, (guint32) expiry);
+}
+
static void
ka_applet_activate (GApplication *application G_GNUC_UNUSED)
{
@@ -747,21 +767,15 @@ ka_applet_set_msg (KaApplet *self, const char *msg)
}
void
-ka_applet_signal_emit (KaApplet *this,
- KaAppletSignalNumber signum,
- krb5_timestamp expiry)
+ka_applet_emit_renewed (KaApplet *self, krb5_timestamp expiry)
{
- char *princ;
+ g_autofree char *princ = NULL;
- princ = ka_unparse_name ();
- if (!princ)
- return;
+ g_return_if_fail (KA_IS_APPLET (self));
- g_signal_emit (this, signals[signum], 0, princ, (guint32) expiry);
- g_free (princ);
+ ka_applet_signal_emit (self, KA_SIGNAL_RENEWED_TGT, expiry);
}
-
int
main (int argc, char *argv[])
{
diff --git a/src/ka-dbus.c b/src/ka-dbus.c
index 8000e50..c45f79a 100644
--- a/src/ka-dbus.c
+++ b/src/ka-dbus.c
@@ -107,30 +107,15 @@ ka_dbus_handle_method_call (GDBusConnection *connection G_GNUC_UNUSED,
}
}
-static gchar* ka_dbus_signal_name (const gchar *name)
-{
- gchar *c;
- gchar *signal_name = g_strdup(name);
-
- /* The DBus signal names use underscores */
- for (c = signal_name; *c != '\0'; c++ ) {
- if (*c == '-')
- *c = '_';
- }
-
- return signal_name;
-}
-
/* Emit DBus signals */
static void
ka_dbus_signal_cb (gpointer *applet G_GNUC_UNUSED,
gchar *princ,
guint when, gpointer user_data)
{
- GError *error = NULL;
- gchar *signal_name;
+ g_autoptr (GError) error = NULL;
+ gchar *signal_name = user_data;
- signal_name = ka_dbus_signal_name(user_data);
if (!g_dbus_connection_emit_signal (dbus_connection,
NULL,
dbus_object_path,
@@ -143,22 +128,18 @@ ka_dbus_signal_cb (gpointer *applet G_GNUC_UNUSED,
g_warning ("Failed to emit DBus signal %s: %s",
signal_name,
error->message);
- g_clear_error (&error);
}
- g_free (signal_name);
}
static void
ka_dbus_connect_signals(KaApplet *applet)
{
- int i;
-
- for (i = 0; i < KA_SIGNAL_COUNT-1; i++) {
- g_signal_connect (applet, ka_signal_names[i],
- G_CALLBACK (ka_dbus_signal_cb),
- (gpointer)ka_signal_names[i]);
- }
+ g_object_connect (applet,
+ "signal::krb-tgt-acquired", ka_dbus_signal_cb, "krb_tgt_acquired",
+ "signal::krb-tgt-renewed", ka_dbus_signal_cb, "krb_tgt_renewed",
+ "signal::krb-tgt-expired", ka_dbus_signal_cb, "krb_tgt_expired",
+ NULL);
}
diff --git a/src/ka-kerberos.c b/src/ka-kerberos.c
index 3db6c0d..c0b534e 100644
--- a/src/ka-kerberos.c
+++ b/src/ka-kerberos.c
@@ -834,8 +834,7 @@ ka_renew_credentials (KaApplet *applet)
ka_log_error_message ("krb5_cc_store_cred", kcontext, retval);
goto out;
}
- ka_applet_signal_emit (applet, KA_SIGNAL_RENEWED_TGT,
- my_creds.times.endtime);
+ ka_applet_emit_renewed (applet, my_creds.times.endtime);
}
out:
if (!retval)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]