]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
Port password handling over to using new answer object
authorRay Strode <rstrode@redhat.com>
Mon, 2 Jun 2008 15:49:00 +0000 (11:49 -0400)
committerRay Strode <rstrode@redhat.com>
Mon, 2 Jun 2008 15:49:00 +0000 (11:49 -0400)
17 files changed:
src/Makefile.am
src/main.c
src/ply-boot-server.c
src/ply-boot-server.h
src/ply-boot-splash-plugin.h
src/ply-boot-splash.c
src/ply-boot-splash.h
src/splash-plugins/details/Makefile.am
src/splash-plugins/details/plugin.c
src/splash-plugins/fade-in/Makefile.am
src/splash-plugins/fade-in/plugin.c
src/splash-plugins/spinfinity/Makefile.am
src/splash-plugins/spinfinity/plugin.c
src/splash-plugins/text/Makefile.am
src/splash-plugins/text/plugin.c
src/tests/ply-boot-server-test.am
src/tests/ply-boot-splash-test.am

index 3aba79b8342cf9843b0968f11a9328171a94304a..a0e6c9d7c0dbeb798fa40316687e6a49e8ffcd71 100644 (file)
@@ -10,6 +10,8 @@ plymouthdbin_PROGRAMS = plymouthd
 plymouthd_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLYMOUTH_PLUGIN_PATH=\"$(libdir)/plymouth/\"
 plymouthd_LDADD = $(PLYMOUTH_LIBS) libply/libply.la
 plymouthd_SOURCES =                                                            \
+                   ply-answer.h                                               \
+                   ply-answer.c                                               \
                    ply-boot-protocol.h                                        \
                    ply-boot-server.h                                          \
                    ply-boot-server.c                                          \
index 70916fb38c944875bfd7de78b8c5be96d15a1687..1cf01f85bfa26006bd458c3640b0718482fec52c 100644 (file)
@@ -31,6 +31,7 @@
 #include <sysexits.h>
 #include <unistd.h>
 
+#include "ply-answer.h"
 #include "ply-boot-server.h"
 #include "ply-boot-splash.h"
 #include "ply-event-loop.h"
@@ -105,41 +106,17 @@ on_update (state_t     *state,
                                    status);
 }
 
-typedef struct
-{
-  ply_boot_server_password_answer_handler_t handler;
-  void *data;
-  state_t *state;
-} password_answer_closure_t;
-
 static void
-on_password_answer (password_answer_closure_t *closure,
-                    const char *password)
+on_ask_for_password (state_t      *state,
+                     ply_answer_t *answer)
 {
-  closure->handler (closure->data, password, closure->state->boot_server);
-}
-
-static void
-on_ask_for_password (state_t *state,
-                     ply_boot_server_password_answer_handler_t answer_handler,
-                     void *answer_data)
-{
-  password_answer_closure_t *closure;
-
   if (state->boot_splash != NULL)
     {
-      answer_handler (answer_data, "", state->boot_server);
+      ply_answer_with_string (answer, "");
       return;
     }
 
-  closure = malloc (sizeof (password_answer_closure_t));
-  closure->handler = answer_handler;
-  closure->data = answer_data;
-  closure->state = state;
-
-  ply_boot_splash_ask_for_password (state->boot_splash,
-                                    (ply_boot_splash_password_answer_handler_t)
-                                    on_password_answer, closure);
+  ply_boot_splash_ask_for_password (state->boot_splash, answer);
 }
 
 static void
index 84e4ad22562112c9efa82edd88ae5401d376c9d4..898ca21c85eea4a563d64668c09fca5f2aa64d8a 100644 (file)
@@ -183,7 +183,7 @@ ply_boot_connection_is_from_root (ply_boot_connection_t *connection)
 static void
 ply_boot_connection_on_password_answer (ply_boot_connection_t *connection,
                                         const char            *password,
-                                        ply_boot_server_t     *server)
+                                        ply_answer_t          *answer)
 {
 
   size_t size;
@@ -203,6 +203,8 @@ ply_boot_connection_on_password_answer (ply_boot_connection_t *connection,
       !ply_write (connection->fd,
                   password, size))
     ply_error ("could not write bytes: %m");
+
+  ply_answer_free (answer);
 }
 
 static void
@@ -256,10 +258,15 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection)
     }
   else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_PASSWORD) == 0)
     {
+      ply_answer_t *answer;
+
+      answer = ply_answer_new ((ply_answer_handler_t)
+                               ply_boot_connection_on_password_answer,
+                               connection);
+
       if (server->ask_for_password_handler != NULL)
         server->ask_for_password_handler (server->user_data,
-                                          ply_boot_connection_on_password_answer,
-                                          connection,
+                                          answer,
                                           server);
       /* will reply later
        */
index dd9f386e7806e7916d342b93ca8ed2436db731a8..a8eb7b2ee4dc36de0af04ef19780ff83831c2fc6 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdint.h>
 #include <unistd.h>
 
+#include "ply-answer.h"
 #include "ply-boot-protocol.h"
 #include "ply-event-loop.h"
 
@@ -42,8 +43,7 @@ typedef void (* ply_boot_server_password_answer_handler_t) (void              *a
                                                             const char        *password,
                                                             ply_boot_server_t *server);
 typedef void (* ply_boot_server_ask_for_password_handler_t) (void              *user_data,
-                                                             ply_boot_server_password_answer_handler_t on_answer_handler,
-                                                             void              *answer_data,
+                                                             ply_answer_t      *answer,
                                                              ply_boot_server_t *server);
 
 typedef void (* ply_boot_server_system_initialized_handler_t) (void              *user_data,
index a6fbb5d7f951924a4fe0bd86e95ccaa15a29b99e..cc4b39a0ea7b48f1fe88ac6d22a66b49c4997c1a 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdint.h>
 #include <unistd.h>
 
+#include "ply-answer.h"
 #include "ply-event-loop.h"
 #include "ply-window.h"
 #include "ply-buffer.h"
@@ -53,8 +54,7 @@ typedef struct
                                ply_window_t             *window);
 
   void (* ask_for_password) (ply_boot_splash_plugin_t *plugin,
-                             ply_boot_splash_password_answer_handler_t answer_handler,
-                             void                     *answer_data);
+                             ply_answer_t             *answer);
 } ply_boot_splash_plugin_interface_t;
 
 #endif /* PLY_BOOT_SPLASH_PLUGIN_H */
index 4811b1edc853d87399cb2af97c3320c4320a1e08..8266212cae830a4ebe49b27b65b2a01f6a491e3f 100644 (file)
@@ -216,8 +216,7 @@ ply_boot_splash_update_output (ply_boot_splash_t *splash,
 
 void
 ply_boot_splash_ask_for_password (ply_boot_splash_t *splash,
-                                  ply_boot_splash_password_answer_handler_t answer_handler,
-                                  void              *answer_data)
+                                  ply_answer_t      *answer)
 {
 
   assert (splash != NULL);
@@ -227,12 +226,12 @@ ply_boot_splash_ask_for_password (ply_boot_splash_t *splash,
 
   if (splash->plugin_interface->ask_for_password == NULL)
     {
-      answer_handler (answer_data, "");
+      ply_answer_with_string (answer, "");
       return;
     }
 
   splash->plugin_interface->ask_for_password (splash->plugin,
-                                              answer_handler, answer_data);
+                                              answer);
 }
 
 static void
index 64006b4f7f99e898dd05555d59f1f8e5df4f7e08..367af1e7dbd4de1e019e7ef8a527bf5c074a25a2 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdint.h>
 #include <unistd.h>
 
+#include "ply-answer.h"
 #include "ply-event-loop.h"
 #include "ply-window.h"
 #include "ply-buffer.h"
@@ -46,8 +47,7 @@ void ply_boot_splash_update_output (ply_boot_splash_t *splash,
                                     size_t             size);
 
 void ply_boot_splash_ask_for_password (ply_boot_splash_t *splash,
-                                       ply_boot_splash_password_answer_handler_t answer_handler,
-                                       void              *answer_data);
+                                       ply_answer_t      *answer);
 void ply_boot_splash_hide (ply_boot_splash_t *splash);
 void ply_boot_splash_attach_to_event_loop (ply_boot_splash_t *splash,
                                            ply_event_loop_t  *loop);
index 0550db027534d0113cd7385534873498c6488bbe..b289d52b3e65373381bcc040060fe9baf9a4208b 100644 (file)
@@ -11,6 +11,8 @@ details_la_CFLAGS = $(PLYMOUTH_CFLAGS)
 details_la_LDFLAGS = -module -avoid-version -export-dynamic
 details_la_LIBADD = $(PLYMOUTH_LIBS) ../../libply/libply.la
 details_la_SOURCES = $(srcdir)/../../ply-boot-splash-plugin.h         \
+                     $(srcdir)/../../ply-answer.h                     \
+                     $(srcdir)/../../ply-answer.c                     \
                      $(srcdir)/../../ply-window.h                     \
                      $(srcdir)/../../ply-window.c                     \
                      $(srcdir)/plugin.c
index 48d5ac99f6e61726e3a7facf989c7af0b57a74f8..9c9f5f40d6d3d0f34fca068e347dda8f459cf99a 100644 (file)
@@ -40,6 +40,7 @@
 #include <wchar.h>
 #include <values.h>
 
+#include "ply-answer.h"
 #include "ply-boot-splash-plugin.h"
 #include "ply-buffer.h"
 #include "ply-event-loop.h"
@@ -59,8 +60,7 @@ struct _ply_boot_splash_plugin
 {
   ply_event_loop_t *loop;
 
-  ply_boot_splash_password_answer_handler_t password_answer_handler;
-  void *password_answer_data;
+  ply_answer_t *pending_password_answer;
 
   uint32_t keyboard_input_is_hidden : 1;
 };
@@ -117,12 +117,11 @@ void
 on_enter (ply_boot_splash_plugin_t *plugin,
           const char               *line)
 {
-  if (plugin->password_answer_handler != NULL)
+  if (plugin->pending_password_answer != NULL)
     {
-      plugin->password_answer_handler (plugin->password_answer_data,
-                                       line);
+      ply_answer_with_string (plugin->pending_password_answer, line);
       plugin->keyboard_input_is_hidden = false;
-      plugin->password_answer_handler = NULL;
+      plugin->pending_password_answer = NULL;
       write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE));
     }
 }
@@ -203,11 +202,9 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin,
 
 void
 ask_for_password (ply_boot_splash_plugin_t *plugin,
-                  ply_boot_splash_password_answer_handler_t answer_handler,
-                  void *answer_data)
+                  ply_answer_t             *answer)
 {
-  plugin->password_answer_handler = answer_handler;
-  plugin->password_answer_data = answer_data;
+  plugin->pending_password_answer = answer;
 
   write (STDOUT_FILENO, "\nPassword: ", strlen ("\nPassword: "));
   plugin->keyboard_input_is_hidden = true;
index bc37f284d939947cbe93440513628bcf80723853..4e26835b70872987935d0d7619ffcdcc7cbf6452 100644 (file)
@@ -14,6 +14,8 @@ fade_in_la_CFLAGS = $(PLYMOUTH_CFLAGS)                                        \
 fade_in_la_LDFLAGS = -module -avoid-version -export-dynamic
 fade_in_la_LIBADD = $(PLYMOUTH_LIBS) ../../libply/libply.la
 fade_in_la_SOURCES = $(srcdir)/../../ply-boot-splash-plugin.h                 \
+                     $(srcdir)/../../ply-answer.h                             \
+                     $(srcdir)/../../ply-answer.c                             \
                      $(srcdir)/../../ply-window.h                             \
                      $(srcdir)/../../ply-window.c                             \
                      $(srcdir)/plugin.c
index c30e94370190a29ec5797120a0da5d9a8fb488c4..13236d310175fa6dbb7f08e5f75efefeb2101079 100644 (file)
@@ -39,6 +39,7 @@
 #include <unistd.h>
 #include <wchar.h>
 
+#include "ply-answer.h"
 #include "ply-boot-splash-plugin.h"
 #include "ply-buffer.h"
 #include "ply-event-loop.h"
@@ -84,8 +85,7 @@ struct _ply_boot_splash_plugin
 
   entry_t *entry;
 
-  ply_boot_splash_password_answer_handler_t password_answer_handler;
-  void *password_answer_data;
+  ply_answer_t *pending_password_answer;
 
   double start_time;
   double now;
@@ -376,7 +376,7 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin,
                    const char               *keyboard_input,
                    size_t                    character_size)
 {
-  if (plugin->password_answer_handler == NULL)
+  if (plugin->pending_password_answer == NULL)
     return;
 
   plugin->entry->number_of_bullets++;
@@ -394,8 +394,13 @@ void
 on_enter (ply_boot_splash_plugin_t *plugin,
           const char               *text)
 {
-  plugin->password_answer_handler (plugin->password_answer_data,
-                                   text);
+
+  if (plugin->pending_password_answer == NULL)
+    return;
+
+  ply_answer_with_string (plugin->pending_password_answer, text);
+  plugin->pending_password_answer = NULL;
+
   plugin->entry->number_of_bullets = 0;
   entry_free (plugin->entry);
   plugin->entry = NULL;
@@ -650,11 +655,9 @@ show_password_entry (ply_boot_splash_plugin_t *plugin)
 
 void
 ask_for_password (ply_boot_splash_plugin_t *plugin,
-                  ply_boot_splash_password_answer_handler_t answer_handler,
-                  void *answer_data)
+                  ply_answer_t             *answer)
 {
-  plugin->password_answer_handler = answer_handler;
-  plugin->password_answer_data = answer_data;
+  plugin->pending_password_answer = answer;
 
   stop_animation (plugin);
   show_password_entry (plugin);
index fa6784d208c9b7cb61846bd7e3de947794ab626c..23cdd54e70f027ec80a4407450e9d5730b06012d 100644 (file)
@@ -15,6 +15,8 @@ spinfinity_la_CFLAGS = $(PLYMOUTH_CFLAGS)                                    \
 spinfinity_la_LDFLAGS = -module -avoid-version -export-dynamic
 spinfinity_la_LIBADD = $(PLYMOUTH_LIBS) ../../libply/libply.la
 spinfinity_la_SOURCES = $(srcdir)/../../ply-boot-splash-plugin.h             \
+                            $(srcdir)/../../ply-answer.h                     \
+                            $(srcdir)/../../ply-answer.c                     \
                             $(srcdir)/../../ply-window.h                     \
                             $(srcdir)/../../ply-window.c                     \
                             $(srcdir)/throbber.h                             \
index 24298e7f2e747403f28a7d5d63e7bdd79c375764..b8f9b53c07c579753e9c7a1cb27869ccbd120e65 100644 (file)
@@ -39,6 +39,7 @@
 #include <unistd.h>
 #include <wchar.h>
 
+#include "ply-answer.h"
 #include "ply-boot-splash-plugin.h"
 #include "ply-buffer.h"
 #include "ply-event-loop.h"
@@ -78,8 +79,7 @@ struct _ply_boot_splash_plugin
   entry_t *entry;
   throbber_t *throbber;
 
-  ply_boot_splash_password_answer_handler_t password_answer_handler;
-  void *password_answer_data;
+  ply_answer_t *pending_password_answer;
 };
 
 static void detach_from_event_loop (ply_boot_splash_plugin_t *plugin);
@@ -245,7 +245,7 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin,
                    const char               *keyboard_input,
                    size_t                    character_size)
 {
-  if (plugin->password_answer_handler == NULL)
+  if (plugin->pending_password_answer == NULL)
     return;
 
   plugin->entry->number_of_bullets++;
@@ -263,11 +263,11 @@ void
 on_enter (ply_boot_splash_plugin_t *plugin,
           const char               *text)
 {
-  if (plugin->password_answer_handler == NULL)
+  if (plugin->pending_password_answer == NULL)
     return;
 
-  plugin->password_answer_handler (plugin->password_answer_data,
-                                   text);
+  ply_answer_with_string (plugin->pending_password_answer, text);
+  plugin->pending_password_answer = NULL;
 
   if (plugin->entry != NULL)
     {
@@ -456,11 +456,9 @@ show_password_entry (ply_boot_splash_plugin_t *plugin)
 
 void
 ask_for_password (ply_boot_splash_plugin_t *plugin,
-                  ply_boot_splash_password_answer_handler_t answer_handler,
-                  void *answer_data)
+                  ply_answer_t             *answer)
 {
-  plugin->password_answer_handler = answer_handler;
-  plugin->password_answer_data = answer_data;
+  plugin->pending_password_answer = answer;
 
   stop_animation (plugin);
   show_password_entry (plugin);
index 27b2cf70cec06f96b5d5023b2c462aae46343a29..2d9ba7348e72326f2062cc87c3cc0a6b161e9f29 100644 (file)
@@ -11,6 +11,8 @@ text_la_CFLAGS = $(PLYMOUTH_CFLAGS)
 text_la_LDFLAGS = -module -avoid-version -export-dynamic
 text_la_LIBADD = $(PLYMOUTH_LIBS) ../../libply/libply.la
 text_la_SOURCES = $(srcdir)/../../ply-boot-splash-plugin.h         \
+                  $(srcdir)/../../ply-answer.h                     \
+                  $(srcdir)/../../ply-answer.c                     \
                   $(srcdir)/../../ply-window.h                     \
                   $(srcdir)/../../ply-window.c                     \
                   $(srcdir)/plugin.c
index a342fa75b720783f2ca7346133e1c4ca7fd0762e..3ad92348926cc7680d1893bac252c47273603f85 100644 (file)
@@ -40,6 +40,7 @@
 #include <values.h>
 #include <wchar.h>
 
+#include "ply-answer.h"
 #include "ply-boot-splash-plugin.h"
 #include "ply-buffer.h"
 #include "ply-event-loop.h"
@@ -60,8 +61,8 @@ struct _ply_boot_splash_plugin
   ply_event_loop_t *loop;
 
   int console_fd;
-  ply_boot_splash_password_answer_handler_t password_answer_handler;
-  void *password_answer_data;
+
+  ply_answer_t *pending_password_answer;
 
   uint32_t keyboard_input_is_hidden : 1;
 };
@@ -132,12 +133,11 @@ void
 on_enter (ply_boot_splash_plugin_t *plugin,
           const char               *line)
 {
-  if (plugin->password_answer_handler != NULL)
+  if (plugin->pending_password_answer != NULL)
     {
-      plugin->password_answer_handler (plugin->password_answer_data,
-                                       line);
+      ply_answer_with_string (plugin->pending_password_answer, line);
       plugin->keyboard_input_is_hidden = false;
-      plugin->password_answer_handler = NULL;
+      plugin->pending_password_answer = NULL;
       write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE));
     }
 }
@@ -207,11 +207,9 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin,
 
 void
 ask_for_password (ply_boot_splash_plugin_t *plugin,
-                  ply_boot_splash_password_answer_handler_t answer_handler,
-                  void *answer_data)
+                  ply_answer_t             *answer)
 {
-  plugin->password_answer_handler = answer_handler;
-  plugin->password_answer_data = answer_data;
+  plugin->pending_password_answer = answer;
 
   write (STDOUT_FILENO, "\nPassword: ", strlen ("\nPassword: "));
   plugin->keyboard_input_is_hidden = true;
index cc283487fa7853262979c28f004c8b6e674b205b..028edceee438b9b743ac733fb2b9fb85b006cf4c 100644 (file)
@@ -4,5 +4,7 @@ ply_boot_server_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_BOOT_SERVER_ENABLE_TEST
 ply_boot_server_test_LDADD = $(PLYMOUTH_LIBS) ../libply/libply.la
 
 ply_boot_server_test_SOURCES =                                                \
+                          $(srcdir)/../ply-answer.h                           \
+                          $(srcdir)/../ply-answer.c                           \
                           $(srcdir)/../ply-boot-server.h                      \
                           $(srcdir)/../ply-boot-server.c
index af67aad48bd9a62b147936b2d872df6b740c46d6..063bdcca121b3c953ab418dd73a43c0a463e9257 100644 (file)
@@ -4,6 +4,8 @@ ply_boot_splash_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_BOOT_SPLASH_ENABLE_TEST
 ply_boot_splash_test_LDADD = $(PLYMOUTH_LIBS) ../libply/libply.la
 
 ply_boot_splash_test_SOURCES =                                                \
+                          $(srcdir)/../ply-answer.h                           \
+                          $(srcdir)/../ply-answer.c                           \
                           $(srcdir)/../ply-boot-splash-plugin.h               \
                           $(srcdir)/../ply-window.h                           \
                           $(srcdir)/../ply-window.c                           \