]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
Add client object support for mutiple answers
authorRay Strode <rstrode@redhat.com>
Wed, 20 Aug 2008 19:46:30 +0000 (15:46 -0400)
committerRay Strode <rstrode@redhat.com>
Wed, 20 Aug 2008 19:50:55 +0000 (15:50 -0400)
If the daemon sends a reply with multiple answers,
deserialize it into an array and dispatch to a
multireply handler.

src/client/ply-boot-client.c
src/client/ply-boot-client.h

index c6b307514d04d122d41115d76d588e5950de3e13..56a0c66ed79083a58a5ac09f36713a6c61130bfb 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include "ply-array.h"
 #include "ply-event-loop.h"
 #include "ply-list.h"
 #include "ply-logger.h"
@@ -282,6 +283,52 @@ ply_boot_client_process_incoming_replies (ply_boot_client_t *client)
 
       ((ply_boot_client_answer_handler_t) request->handler) (request->user_data, answer, client);
     }
+  else if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_MULTIPLE_ANSWERS, sizeof (uint8_t)) == 0)
+    {
+      ply_array_t *array;
+      char **answers;
+      char *answer;
+      char *p;
+      char *q;
+      uint8_t i;
+
+      array = NULL;
+      answers = NULL;
+
+      if (!ply_read (client->socket_fd, &size, sizeof (uint8_t)))
+        goto out;
+
+      assert (size > 0);
+
+      answer = malloc (size);
+
+      if (!ply_read (client->socket_fd, answer, size))
+        {
+          free (answer);
+          goto out;
+        }
+
+      array = ply_array_new ();
+
+      p = answer;
+      p = q;
+      for (i = 0; i < size; i++, q++)
+        {
+          if (*q == '\0')
+            {
+              ply_array_add_element (array, strdup (p));
+              p = q + 1;
+            }
+        }
+      free (answer);
+
+      answers = (char **) ply_array_steal_elements (array);
+      ply_array_free (array);
+
+      ((ply_boot_client_multiple_answers_handler_t) request->handler) (request->user_data, (const char * const *) answers, client);
+
+      ply_free_string_array (answers);
+    }
   else if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER, sizeof (uint8_t)) == 0)
     {
       ((ply_boot_client_answer_handler_t) request->handler) (request->user_data, NULL, client);
@@ -507,6 +554,19 @@ ply_boot_client_ask_daemon_for_password (ply_boot_client_t                  *cli
                                  handler, failed_handler, user_data);
 }
 
+void
+ply_boot_client_ask_daemon_for_cached_passwords (ply_boot_client_t                  *client,
+                                                 ply_boot_client_multiple_answers_handler_t    handler,
+                                                 ply_boot_client_response_handler_t  failed_handler,
+                                                 void                               *user_data)
+{
+  assert (client != NULL);
+
+  ply_boot_client_queue_request (client, PLY_BOOT_PROTOCOL_REQUEST_TYPE_CACHED_PASSWORD,
+                                 NULL, (ply_boot_client_response_handler_t)
+                                 handler, failed_handler, user_data);
+}
+
 void
 ply_boot_client_tell_daemon_to_show_splash (ply_boot_client_t                  *client,
                                             ply_boot_client_response_handler_t  handler,
index c14c7539e9ac47056bef25578d91bc3761203cdd..75b165fdf0c72ffe96a383dc5e2630065f5df17f 100644 (file)
@@ -35,6 +35,10 @@ typedef void (* ply_boot_client_response_handler_t) (void              *user_dat
 typedef void (* ply_boot_client_answer_handler_t) (void              *user_data,
                                                    const char        *answer,
                                                    ply_boot_client_t *client);
+
+typedef void (* ply_boot_client_multiple_answers_handler_t) (void    *user_data,
+                                                             const char * const *answers,
+                                                             ply_boot_client_t *client);
 typedef void (* ply_boot_client_disconnect_handler_t) (void              *user_data,
                                                        ply_boot_client_t *client);
 
@@ -63,6 +67,11 @@ void ply_boot_client_ask_daemon_for_password (ply_boot_client_t
                                               ply_boot_client_answer_handler_t    handler,
                                               ply_boot_client_response_handler_t  failed_handler,
                                               void                               *user_data);
+
+void ply_boot_client_ask_daemon_for_cached_passwords (ply_boot_client_t                  *client,
+                                                      ply_boot_client_multiple_answers_handler_t    handler,
+                                                      ply_boot_client_response_handler_t  failed_handler,
+                                                      void                               *user_data);
 void ply_boot_client_tell_daemon_system_is_initialized (ply_boot_client_t                  *client,
                                                         ply_boot_client_response_handler_t  handler,
                                                         ply_boot_client_response_handler_t  failed_handler,