From f4946d6269e11c72fb152dc9597c07542b2bc6c3 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 20 Aug 2008 15:46:30 -0400 Subject: [PATCH] Add client object support for mutiple answers 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 | 60 ++++++++++++++++++++++++++++++++++++ src/client/ply-boot-client.h | 9 ++++++ 2 files changed, 69 insertions(+) diff --git a/src/client/ply-boot-client.c b/src/client/ply-boot-client.c index c6b30751..56a0c66e 100644 --- a/src/client/ply-boot-client.c +++ b/src/client/ply-boot-client.c @@ -30,6 +30,7 @@ #include #include +#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, diff --git a/src/client/ply-boot-client.h b/src/client/ply-boot-client.h index c14c7539..75b165fd 100644 --- a/src/client/ply-boot-client.h +++ b/src/client/ply-boot-client.h @@ -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, -- 2.47.3