[gnome-keyring/dbus-api] Fixes for prompt signals and responses.
- From: Stefan Walter <stefw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-keyring/dbus-api] Fixes for prompt signals and responses.
- Date: Thu, 5 Nov 2009 05:54:34 +0000 (UTC)
commit cadeede096be1a9af79bf41aca2e2d3d84394bb4
Author: Stef Walter <stef memberwebs com>
Date: Thu Nov 5 03:24:57 2009 +0000
Fixes for prompt signals and responses.
* Redisplay prompt if responded returns FALSE.
* Fix various other crashers and warnings.
daemon/dbus/gkd-secrets-prompt.c | 4 +-
daemon/dbus/gkd-secrets-prompt.h | 2 +-
daemon/dbus/gkd-secrets-unlock.c | 1 -
daemon/prompt/gkd-prompt.c | 79 ++++++++++++++++++++++++++++++-------
4 files changed, 67 insertions(+), 19 deletions(-)
---
diff --git a/daemon/dbus/gkd-secrets-prompt.c b/daemon/dbus/gkd-secrets-prompt.c
index 7f0a382..195e325 100644
--- a/daemon/dbus/gkd-secrets-prompt.c
+++ b/daemon/dbus/gkd-secrets-prompt.c
@@ -158,13 +158,13 @@ gkd_secrets_prompt_responded (GkdPrompt *base)
res = gkd_prompt_get_response (GKD_PROMPT (self));
if (res == GKD_RESPONSE_NO || res == GKD_RESPONSE_FAILURE) {
gkd_secrets_prompt_dismiss (self);
- return TRUE;
+ return FALSE;
}
/* Check with the prompt ready guys */
g_return_val_if_fail (GKD_SECRETS_PROMPT_GET_CLASS (self)->prompt_ready, TRUE);
GKD_SECRETS_PROMPT_GET_CLASS (self)->prompt_ready (self);
- return self->pv->completed;
+ return !self->pv->completed;
}
static void
diff --git a/daemon/dbus/gkd-secrets-prompt.h b/daemon/dbus/gkd-secrets-prompt.h
index 9c57931..e5a672e 100644
--- a/daemon/dbus/gkd-secrets-prompt.h
+++ b/daemon/dbus/gkd-secrets-prompt.h
@@ -44,7 +44,7 @@ struct _GkdSecretsPrompt {
};
struct _GkdSecretsPromptClass {
- GObjectClass parent_class;
+ GkdPromptClass parent_class;
/* virtual methods */
void (*prompt_ready) (GkdSecretsPrompt *self);
diff --git a/daemon/dbus/gkd-secrets-unlock.c b/daemon/dbus/gkd-secrets-unlock.c
index 5000a27..92f779c 100644
--- a/daemon/dbus/gkd-secrets-unlock.c
+++ b/daemon/dbus/gkd-secrets-unlock.c
@@ -89,7 +89,6 @@ prepare_unlock_prompt (GkdSecretsUnlock *self, GP11Object *coll)
g_free (text);
gkd_prompt_hide_widget (prompt, "name_area");
- gkd_prompt_hide_widget (prompt, "original_area");
gkd_prompt_hide_widget (prompt, "confirm_area");
gkd_prompt_hide_widget (prompt, "details_area");
diff --git a/daemon/prompt/gkd-prompt.c b/daemon/prompt/gkd-prompt.c
index 1777e85..7f45ee7 100644
--- a/daemon/prompt/gkd-prompt.c
+++ b/daemon/prompt/gkd-prompt.c
@@ -70,6 +70,9 @@ struct _GkdPromptPrivate {
G_DEFINE_TYPE (GkdPrompt, gkd_prompt, G_TYPE_OBJECT);
+/* Forward declaration*/
+static void display_async_prompt (GkdPrompt *);
+
/* -----------------------------------------------------------------------------
* INTERNAL
*/
@@ -89,6 +92,31 @@ mark_completed (GkdPrompt *self)
g_signal_emit (self, signals[COMPLETED], 0);
}
+static void
+mark_failed (GkdPrompt *self)
+{
+ g_assert (!self->pv->failure);
+ self->pv->failure = TRUE;
+ if (!self->pv->completed)
+ mark_completed (self);
+}
+
+static void
+mark_responded (GkdPrompt *self)
+{
+ gboolean continu = FALSE;
+ g_signal_emit (self, signals[RESPONDED], 0, &continu);
+
+ /* The prompt gets displayed again */
+ if (continu) {
+ display_async_prompt (self);
+
+ /* The prompt has completed */
+ } else {
+ mark_completed (self);
+ }
+}
+
static gboolean
on_standard_input (int fd, gpointer user_data)
{
@@ -106,7 +134,7 @@ on_standard_input (int fd, gpointer user_data)
if (ret <= 0) {
g_warning ("couldn't write all input to prompt process");
- self->pv->failure = TRUE;
+ mark_failed (self);
return FALSE;
}
@@ -126,7 +154,7 @@ on_standard_output (int fd, gpointer user_data)
ret = egg_spawn_read_output (fd, buffer, sizeof (buffer));
if (ret < 0) {
g_warning ("couldn't read output data from prompt process");
- self->pv->failure = TRUE;
+ mark_failed (self);
return FALSE;
}
@@ -151,7 +179,7 @@ on_standard_error (int fd, gpointer user_data)
ret = egg_spawn_read_output (fd, buffer, sizeof (buffer));
if (ret < 0) {
g_warning ("couldn't read error data from prompt process");
- self->pv->failure = TRUE;
+ mark_failed (self);
return FALSE;
}
@@ -163,9 +191,9 @@ on_standard_error (int fd, gpointer user_data)
/* Print all stderr lines as messages */
while ((ptr = strchr (self->pv->err_data->str, '\n')) != NULL) {
*ptr = '\0';
- g_message ("%s", self->pv->err_data->str);
+ g_printerr ("%s\n", self->pv->err_data->str);
g_string_erase (self->pv->err_data, 0,
- ptr - self->pv->err_data->str);
+ ptr - self->pv->err_data->str + 1);
}
return ret > 0;
@@ -192,6 +220,13 @@ on_io_completed (gpointer user_data)
/* Parse the output data properly */
if (!self->pv->failure) {
+ if (!self->pv->out_data->len) {
+ g_warning ("no data returned from the prompt");
+ mark_failed (self);
+ }
+ }
+
+ if (!self->pv->failure) {
#if DEBUG_PROMPT
g_printerr ("PROMPT OUTPUT:\n%s\n", self->pv->out_data->str);
#endif
@@ -202,9 +237,9 @@ on_io_completed (gpointer user_data)
g_warning ("couldn't parse output from prompt: %s",
error && error->message ? error->message : "");
g_clear_error (&error);
- self->pv->failure = TRUE;
+ mark_failed (self);
} else {
- g_signal_emit (self, signals[RESPONDED], 0);
+ mark_responded (self);
}
}
}
@@ -221,13 +256,13 @@ on_child_exited (GPid pid, gint status, gpointer user_data)
if (WIFEXITED (status)) {
code = WEXITSTATUS (status);
if (code != 0) {
- g_warning ("prompt process exited with failure code: %d", code);
- self->pv->failure = TRUE;
+ g_message ("prompt process exited with failure code: %d", code);
+ mark_failed (self);
}
} else if (WIFSIGNALED (status)) {
code = WTERMSIG (status);
- g_warning ("prompt process was killed with signal: %d", code);
- self->pv->failure = TRUE;
+ g_message ("prompt process was killed with signal: %d", code);
+ mark_failed (self);
}
}
}
@@ -300,8 +335,7 @@ prepare_input_data (GkdPrompt *self)
g_warning ("couldn't encode data for prompt: %s",
error && error->message ? error->message : "");
g_clear_error (&error);
- self->pv->failure = TRUE;
- mark_completed (self);
+ mark_failed (self);
return FALSE;
}
@@ -359,8 +393,7 @@ display_async_prompt (GkdPrompt *self)
error && error->message ? error->message : "");
g_clear_error (&error);
self->pv->pid = 0;
- self->pv->failure = TRUE;
- mark_completed (self);
+ mark_failed (self);
return;
}
@@ -418,6 +451,19 @@ clear_prompt_data (GkdPrompt *self)
* OBJECT
*/
+static gboolean
+gkd_prompt_real_responded (GkdPrompt *self)
+{
+ /* The prompt is done, if nobody overrode this signal and returned TRUE */
+ return FALSE;
+}
+
+static void
+gkd_prompt_real_completed (GkdPrompt *self)
+{
+ /* Nothing to do */
+}
+
static GObject*
gkd_prompt_constructor (GType type, guint n_props, GObjectConstructParam *props)
{
@@ -479,6 +525,9 @@ gkd_prompt_class_init (GkdPromptClass *klass)
gobject_class->dispose = gkd_prompt_dispose;
gobject_class->finalize = gkd_prompt_finalize;
+ klass->responded = gkd_prompt_real_responded;
+ klass->completed = gkd_prompt_real_completed;
+
g_type_class_add_private (klass, sizeof (GkdPromptPrivate));
signals[COMPLETED] = g_signal_new ("completed", GKD_TYPE_PROMPT,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]