summaryrefslogtreecommitdiffstats
path: root/src/rhgb-client/ply-boot-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhgb-client/ply-boot-client.c')
-rw-r--r--src/rhgb-client/ply-boot-client.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/src/rhgb-client/ply-boot-client.c b/src/rhgb-client/ply-boot-client.c
index 28a285d..08eb6b9 100644
--- a/src/rhgb-client/ply-boot-client.c
+++ b/src/rhgb-client/ply-boot-client.c
@@ -231,10 +231,13 @@ ply_boot_client_process_incoming_replies (ply_boot_client_t *client)
{
ply_list_node_t *request_node;
ply_boot_client_request_t *request;
+ bool processed_reply;
uint8_t byte[2] = "";
+ uint8_t size;
assert (client != NULL);
+ processed_reply = false;
if (ply_list_get_length (client->requests_waiting_for_replies) == 0)
{
ply_error ("received unexpected response from boot status daemon");
@@ -248,22 +251,36 @@ ply_boot_client_process_incoming_replies (ply_boot_client_t *client)
assert (request != NULL);
if (!ply_read (client->socket_fd, byte, sizeof (uint8_t)))
+ goto out;
+
+ if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK, sizeof (uint8_t)) == 0)
+ request->handler (request->user_data, client);
+ else if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER, sizeof (uint8_t)) == 0)
{
- if (request->failed_handler != NULL)
- request->failed_handler (request->user_data, client);
- ply_list_remove_node (client->requests_waiting_for_replies, request_node);
- return;
+ char answer[257] = "";
+
+ /* FIXME: should make this 4 bytes instead of 1
+ */
+ if (!ply_read (client->socket_fd, &size, sizeof (uint8_t)))
+ goto out;
+
+ if (!ply_read (client->socket_fd, answer, size))
+ goto out;
+
+ ((ply_boot_client_answer_handler_t) request->handler) (request->user_data, answer, client);
}
+ else
+ goto out;
+
+ processed_reply = true;
- if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK, sizeof (uint8_t)) != 0)
+out:
+ if (!processed_reply)
{
if (request->failed_handler != NULL)
request->failed_handler (request->user_data, client);
- ply_list_remove_node (client->requests_waiting_for_replies, request_node);
- return;
}
- request->handler (request->user_data, client);
ply_list_remove_node (client->requests_waiting_for_replies, request_node);
if (ply_list_get_length (client->requests_waiting_for_replies) == 0)
@@ -438,6 +455,19 @@ ply_boot_client_tell_daemon_system_is_initialized (ply_boot_client_t
}
void
+ply_boot_client_ask_daemon_for_password (ply_boot_client_t *client,
+ ply_boot_client_answer_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_PASSWORD,
+ NULL, (ply_boot_client_response_handler_t)
+ handler, failed_handler, user_data);
+}
+
+void
ply_boot_client_tell_daemon_to_quit (ply_boot_client_t *client,
ply_boot_client_response_handler_t handler,
ply_boot_client_response_handler_t failed_handler,