From 424818f2917f2a5b50b7574aae8024548479d9a8 Mon Sep 17 00:00:00 2001 From: Charles Brej Date: Wed, 3 Dec 2008 16:03:25 +0000 Subject: [PATCH] Clearword entry and moving password entry to a higher level. --- src/client/ply-boot-client.c | 15 ++ src/client/ply-boot-client.h | 5 + src/client/plymouth.c | 80 +++++++- src/libply/ply-buffer.c | 16 +- src/libplybootsplash/ply-boot-splash-plugin.h | 18 +- src/libplybootsplash/ply-entry.c | 111 +++++++--- src/libplybootsplash/ply-entry.h | 2 + src/libplybootsplash/ply-window.c | 17 +- src/main.c | 190 +++++++++++++++--- src/plugins/splash/details/plugin.c | 173 +++++++++------- src/plugins/splash/fade-in/bullet.png | Bin 745 -> 246 bytes src/plugins/splash/fade-in/plugin.c | 78 +++---- src/plugins/splash/pulser/plugin.c | 105 ++++++---- src/plugins/splash/solar/plugin.c | 148 +++++++------- src/plugins/splash/spinfinity/plugin.c | 143 +++++++------ src/plugins/splash/text/plugin.c | 106 +++++----- src/ply-boot-protocol.h | 1 + src/ply-boot-server.c | 74 ++++++- src/ply-boot-server.h | 9 +- src/ply-boot-splash.c | 50 ++--- src/ply-boot-splash.h | 7 +- 21 files changed, 880 insertions(+), 468 deletions(-) diff --git a/src/client/ply-boot-client.c b/src/client/ply-boot-client.c index 43d55072..7f81ceee 100644 --- a/src/client/ply-boot-client.c +++ b/src/client/ply-boot-client.c @@ -569,6 +569,21 @@ ply_boot_client_ask_daemon_for_cached_passwords (ply_boot_client_t handler, failed_handler, user_data); } +void +ply_boot_client_ask_daemon_for_clearword (ply_boot_client_t *client, + + const char *prompt, + 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_CLEARWORD, + prompt, (ply_boot_client_response_handler_t) + handler, failed_handler, user_data); +} + void ply_boot_client_ask_daemon_to_watch_for_keystroke (ply_boot_client_t *client, const char *keys, diff --git a/src/client/ply-boot-client.h b/src/client/ply-boot-client.h index dcdf9240..7e157cfc 100644 --- a/src/client/ply-boot-client.h +++ b/src/client/ply-boot-client.h @@ -76,6 +76,11 @@ void ply_boot_client_ask_daemon_for_cached_passwords (ply_boot_client_t ply_boot_client_multiple_answers_handler_t handler, ply_boot_client_response_handler_t failed_handler, void *user_data); +void ply_boot_client_ask_daemon_for_clearword (ply_boot_client_t *client, + const char *prompt, + ply_boot_client_answer_handler_t handler, + ply_boot_client_response_handler_t failed_handler, + void *user_data); void ply_boot_client_ask_daemon_to_watch_for_keystroke (ply_boot_client_t *client, const char *keys, ply_boot_client_key_answer_handler_t handler, diff --git a/src/client/plymouth.c b/src/client/plymouth.c index 3b9fa8cc..9f6eca41 100644 --- a/src/client/plymouth.c +++ b/src/client/plymouth.c @@ -52,12 +52,17 @@ typedef struct int number_of_tries_left; } answer_state_t; - typedef struct { state_t *state; char *command; char *prompt; +} clearword_answer_state_t; + +typedef struct +{ + state_t *state; + char *command; char *keys; } key_answer_state_t; @@ -105,7 +110,7 @@ split_string (const char *command, } static bool -answer_via_command (answer_state_t *answer_state, +answer_via_command (char *command, const char *answer, int *exit_status) { @@ -132,7 +137,7 @@ answer_via_command (answer_state_t *answer_state, if (pid == 0) { char **args; - args = split_string (answer_state->command, ' '); + args = split_string (command, ' '); if (answer != NULL) { close (command_input_sender_fd); @@ -181,7 +186,7 @@ on_answer (answer_state_t *answer_state, bool command_started = false; exit_status = 127; - command_started = answer_via_command (answer_state, answer, + command_started = answer_via_command (answer_state->command, answer, &exit_status); if (command_started && (!WIFEXITED (exit_status) || @@ -210,18 +215,36 @@ on_answer (answer_state_t *answer_state, ply_event_loop_exit (answer_state->state->loop, WEXITSTATUS (exit_status)); } +static void +on_clearword_reply (clearword_answer_state_t *answer_state, + const char *answer, + ply_boot_client_t *client) +{ + if (answer_state->command != NULL) + { + bool command_started = false; + + command_started = answer_via_command (answer_state->command, answer, NULL); + } + else + { + if (answer) write (STDOUT_FILENO, answer, strlen (answer)); + } + + if (answer) ply_event_loop_exit (answer_state->state->loop, 0); + ply_event_loop_exit (answer_state->state->loop, 1); +} static void -on_key_reply (answer_state_t *answer_state, +on_key_reply (key_answer_state_t *answer_state, const char *answer, ply_boot_client_t *client) { - if (answer_state->command != NULL) { bool command_started = false; - command_started = answer_via_command (answer_state, answer, NULL); + command_started = answer_via_command (answer_state->command, answer, NULL); } else { @@ -249,7 +272,7 @@ on_multiple_answers (answer_state_t *answer_state, { bool command_started; exit_status = 127; - command_started = answer_via_command (answer_state, answers[i], + command_started = answer_via_command (answer_state->command, answers[i], &exit_status); if (command_started && WIFEXITED (exit_status) && WEXITSTATUS (exit_status) == 0) @@ -353,6 +376,37 @@ on_password_request (state_t *state, } } +static void +on_clearword_request (state_t *state, + const char *command) +{ + char *prompt; + char *program; + int number_of_tries; + answer_state_t *answer_state; + + prompt = NULL; + program = NULL; + number_of_tries = 0; + ply_command_parser_get_command_options (state->command_parser, + command, + "command", &program, + "prompt", &prompt, + NULL); + + answer_state = calloc (1, sizeof (answer_state_t)); + answer_state->state = state; + answer_state->command = program; + answer_state->prompt = prompt; + + ply_boot_client_ask_daemon_for_clearword (state->client, + answer_state->prompt, + (ply_boot_client_answer_handler_t) + on_clearword_reply, + (ply_boot_client_response_handler_t) + on_failure, answer_state); +} + static void on_keystroke_request (state_t *state, const char *command) @@ -461,6 +515,16 @@ main (int argc, PLY_COMMAND_OPTION_TYPE_INTEGER, NULL); + ply_command_parser_add_command (state.command_parser, + "ask-for-clearword", "Ask user for password", + (ply_command_handler_t) + on_clearword_request, &state, + "command", "Command to send clearword to via standard input", + PLY_COMMAND_OPTION_TYPE_STRING, + "prompt", "Message to display when asking for clearword", + PLY_COMMAND_OPTION_TYPE_STRING, + NULL); + ply_command_parser_add_command (state.command_parser, "watch-keystroke", "Become sensitive to a keystroke", diff --git a/src/libply/ply-buffer.c b/src/libply/ply-buffer.c index 052195c8..7c991f5a 100644 --- a/src/libply/ply-buffer.c +++ b/src/libply/ply-buffer.c @@ -83,6 +83,7 @@ ply_buffer_remove_bytes (ply_buffer_t *buffer, buffer->size - bytes_to_remove); buffer->size -= bytes_to_remove; } + buffer->data[buffer->size] = '\0'; } void @@ -94,6 +95,7 @@ ply_buffer_remove_bytes_at_end (ply_buffer_t *buffer, bytes_to_remove = MIN (buffer->size, bytes_to_remove); buffer->size -= bytes_to_remove; + buffer->data[buffer->size] = '\0'; } ply_buffer_t * @@ -182,16 +184,17 @@ ply_buffer_append_bytes (ply_buffer_t *buffer, assert (buffer != NULL); assert (bytes != NULL); assert (length != 0); - - if ((buffer->size + length) >= buffer->capacity) + + if (length >PLY_BUFFER_MAX_BUFFER_CAPACITY){ + bytes += length - (PLY_BUFFER_MAX_BUFFER_CAPACITY-1); + length = (PLY_BUFFER_MAX_BUFFER_CAPACITY-1); + } + + while ((buffer->size + length) >= buffer->capacity) { if (!ply_buffer_increase_capacity (buffer)) { ply_buffer_remove_bytes (buffer, length); - - if ((buffer->size + length) >= buffer->capacity) - if (!ply_buffer_increase_capacity (buffer)) - return; } } @@ -201,6 +204,7 @@ ply_buffer_append_bytes (ply_buffer_t *buffer, bytes, length); buffer->size += length; + buffer->data[buffer->size] = '\0'; } void diff --git a/src/libplybootsplash/ply-boot-splash-plugin.h b/src/libplybootsplash/ply-boot-splash-plugin.h index cf16f688..d24df011 100644 --- a/src/libplybootsplash/ply-boot-splash-plugin.h +++ b/src/libplybootsplash/ply-boot-splash-plugin.h @@ -33,7 +33,16 @@ typedef struct _ply_boot_splash_plugin ply_boot_splash_plugin_t; -typedef void (* ply_boot_splash_password_answer_handler_t) (void *answer_data, const char *password); +typedef enum { + PLY_BOOT_SPLASH_DISPLAY_NORMAL, + PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY, + PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY +} ply_boot_splash_display_type_t; + +typedef union { + struct {const char *prompt; const char *entry_text;} clearword; + struct {const char *prompt; int bullets;} password; +} ply_boot_splash_display_info_t; typedef struct { @@ -59,10 +68,9 @@ typedef struct void (* on_root_mounted) (ply_boot_splash_plugin_t *plugin); void (* hide_splash_screen) (ply_boot_splash_plugin_t *plugin, ply_event_loop_t *loop); - - void (* ask_for_password) (ply_boot_splash_plugin_t *plugin, - const char *prompt, - ply_trigger_t *answer); + void (* update_display) (ply_boot_splash_plugin_t *plugin, + ply_boot_splash_display_type_t type, + ply_boot_splash_display_info_t *info); void (* become_idle) (ply_boot_splash_plugin_t *plugin, ply_trigger_t *idle_trigger); } ply_boot_splash_plugin_interface_t; diff --git a/src/libplybootsplash/ply-entry.c b/src/libplybootsplash/ply-entry.c index 0a424161..686f4b19 100644 --- a/src/libplybootsplash/ply-entry.c +++ b/src/libplybootsplash/ply-entry.c @@ -43,6 +43,7 @@ #include "ply-entry.h" #include "ply-event-loop.h" #include "ply-array.h" +#include "ply-label.h" #include "ply-logger.h" #include "ply-frame-buffer.h" #include "ply-image.h" @@ -64,11 +65,14 @@ struct _ply_entry ply_frame_buffer_area_t area; ply_image_t *text_field_image; ply_image_t *bullet_image; + ply_label_t *label; + char* text; int number_of_bullets; int max_number_of_visible_bullets; uint32_t is_hidden : 1; + uint32_t is_password : 1; }; ply_entry_t * @@ -90,8 +94,13 @@ ply_entry_new (const char *image_dir) asprintf (&image_path, "%s/bullet.png", image_dir); entry->bullet_image = ply_image_new (image_path); free (image_path); + entry->label = ply_label_new (); + entry->number_of_bullets = 0; + entry->text = strdup(""); + entry->is_hidden = true; + entry->is_password = true; return entry; } @@ -103,6 +112,8 @@ ply_entry_free (ply_entry_t *entry) return; ply_image_free (entry->text_field_image); ply_image_free (entry->bullet_image); + ply_label_free (entry->label); + free (entry); } @@ -162,59 +173,95 @@ ply_entry_draw (ply_entry_t *entry) ply_frame_buffer_fill_with_argb32_data (entry->frame_buffer, &entry->area, 0, 0, text_field_data); - - bullet_data = ply_image_get_data (entry->bullet_image); - bullet_area.width = ply_image_get_width (entry->bullet_image); - bullet_area.height = ply_image_get_height (entry->bullet_image); - - if (entry->number_of_bullets < entry->max_number_of_visible_bullets) - number_of_visible_bullets = entry->number_of_bullets; + + if (entry->is_password) + { + bullet_data = ply_image_get_data (entry->bullet_image); + bullet_area.width = ply_image_get_width (entry->bullet_image); + bullet_area.height = ply_image_get_height (entry->bullet_image); + + if (entry->number_of_bullets < entry->max_number_of_visible_bullets) + number_of_visible_bullets = entry->number_of_bullets; + else + { + number_of_visible_bullets = entry->max_number_of_visible_bullets; + + /* We've got more bullets than we can show in the available space, so + * draw a little half bullet to indicate some bullets are offscreen + */ + bullet_area.x = entry->area.x; + bullet_area.y = entry->area.y + entry->area.height / 2.0 - bullet_area.height / 2.0; + + ply_frame_buffer_fill_with_argb32_data (entry->frame_buffer, + &bullet_area, bullet_area.width / 2.0, 0, + bullet_data); + } + + for (i = 0; i < number_of_visible_bullets; i++) + { + bullet_area.x = entry->area.x + i * bullet_area.width + bullet_area.width / 2.0; + bullet_area.y = entry->area.y + entry->area.height / 2.0 - bullet_area.height / 2.0; + + ply_frame_buffer_fill_with_argb32_data (entry->frame_buffer, + &bullet_area, 0, 0, + bullet_data); + } + } else { - number_of_visible_bullets = entry->max_number_of_visible_bullets; - - /* We've got more bullets than we can show in the available space, so - * draw a little half bullet to indicate some bullets are offscreen - */ - bullet_area.x = entry->area.x; - bullet_area.y = entry->area.y + entry->area.height / 2.0 - bullet_area.height / 2.0; - - ply_frame_buffer_fill_with_argb32_data (entry->frame_buffer, - &bullet_area, bullet_area.width / 2.0, 0, - bullet_data); + ply_label_set_text (entry->label, entry->text); + ply_label_show (entry->label, entry->window, entry->area.x, entry->area.y); + } + ply_frame_buffer_unpause_updates (entry->frame_buffer); +} - for (i = 0; i < number_of_visible_bullets; i++) +void +ply_entry_set_bullets (ply_entry_t *entry, int count) +{ + count = MAX(0, count); + if (!entry->is_password || entry->number_of_bullets != count) { - bullet_area.x = entry->area.x + i * bullet_area.width + bullet_area.width / 2.0; - bullet_area.y = entry->area.y + entry->area.height / 2.0 - bullet_area.height / 2.0; - - ply_frame_buffer_fill_with_argb32_data (entry->frame_buffer, - &bullet_area, 0, 0, - bullet_data); + entry->is_password = true; + entry->number_of_bullets = count; + ply_entry_draw (entry); } - ply_frame_buffer_unpause_updates (entry->frame_buffer); +} + +int +ply_entry_get_bullets (ply_entry_t *entry) +{ + return entry->number_of_bullets; } void ply_entry_add_bullet (ply_entry_t *entry) { - entry->number_of_bullets++; - ply_entry_draw (entry); + ply_entry_set_bullets (entry, ply_entry_get_bullets (entry)+1); } void ply_entry_remove_bullet (ply_entry_t *entry) { - entry->number_of_bullets--; - ply_entry_draw (entry); + ply_entry_set_bullets (entry, ply_entry_get_bullets (entry)-1); } void ply_entry_remove_all_bullets (ply_entry_t *entry) { - entry->number_of_bullets = 0; - ply_entry_draw (entry); + ply_entry_set_bullets (entry, 0); +} + +void +ply_entry_set_text (ply_entry_t *entry, char* text) +{ + if (entry->is_password || strcmp(entry->text, text) != 0) + { + entry->is_password = false; + free(entry->text); + entry->text = strdup(text); + ply_entry_draw (entry); + } } void diff --git a/src/libplybootsplash/ply-entry.h b/src/libplybootsplash/ply-entry.h index ac34a4c5..554e8aa8 100644 --- a/src/libplybootsplash/ply-entry.h +++ b/src/libplybootsplash/ply-entry.h @@ -49,6 +49,8 @@ bool ply_entry_is_hidden (ply_entry_t *entry); long ply_entry_get_width (ply_entry_t *entry); long ply_entry_get_height (ply_entry_t *entry); +void ply_entry_set_bullets (ply_entry_t *entry, int count); +int ply_entry_get_bullets (ply_entry_t *entry); void ply_entry_add_bullet (ply_entry_t *entry); void ply_entry_remove_bullet (ply_entry_t *entry); void ply_entry_remove_all_bullets (ply_entry_t *entry); diff --git a/src/libplybootsplash/ply-window.c b/src/libplybootsplash/ply-window.c index 564ade43..d37379fa 100644 --- a/src/libplybootsplash/ply-window.c +++ b/src/libplybootsplash/ply-window.c @@ -234,7 +234,7 @@ process_backspace (ply_window_t *window) bytes = ply_buffer_get_bytes (window->line_buffer); size = ply_buffer_get_size (window->line_buffer); - bytes_to_remove = MB_CUR_MAX; + bytes_to_remove = MIN(size, MB_CUR_MAX); while ((previous_character_size = mbrlen (bytes + size - bytes_to_remove, bytes_to_remove, NULL)) < bytes_to_remove && previous_character_size > 0) bytes_to_remove -= previous_character_size; @@ -242,13 +242,13 @@ process_backspace (ply_window_t *window) if (bytes_to_remove <= size) { ply_buffer_remove_bytes_at_end (window->line_buffer, bytes_to_remove); + } - for (node = ply_list_get_first_node(window->backspace_handler_list); node; node = ply_list_get_next_node(window->backspace_handler_list, node)) - { - ply_window_callback_t *callback = ply_list_node_get_data (node); - ply_window_backspace_handler_t backspace_handler = callback->function; - backspace_handler (callback->user_data); - } + for (node = ply_list_get_first_node(window->backspace_handler_list); node; node = ply_list_get_next_node(window->backspace_handler_list, node)) + { + ply_window_callback_t *callback = ply_list_node_get_data (node); + ply_window_backspace_handler_t backspace_handler = callback->function; + backspace_handler (callback->user_data); } } @@ -670,7 +670,8 @@ ply_window_set_text_cursor_position (ply_window_t *window, int row) { char *sequence; - + column = MAX(column, 0); + row = MAX(row, 0); sequence = NULL; asprintf (&sequence, MOVE_CURSOR_SEQUENCE, row, column); write (window->tty_fd, sequence, strlen (sequence)); diff --git a/src/main.c b/src/main.c index bbc57dea..5eec3d33 100644 --- a/src/main.c +++ b/src/main.c @@ -54,6 +54,15 @@ typedef struct ply_trigger_t *trigger; } ply_keystroke_trigger_t; +typedef struct +{ + enum {PLY_ENTRY_TRIGGER_TYPE_PASSWORD, + PLY_ENTRY_TRIGGER_TYPE_CLEARWORD} + type; + const char *prompt; + ply_trigger_t *trigger; +} ply_entry_trigger_t; + typedef struct { ply_event_loop_t *loop; @@ -64,6 +73,8 @@ typedef struct ply_buffer_t *boot_buffer; ply_progress_t *progress; ply_list_t *keystroke_triggers; + ply_list_t *entry_triggers; + ply_buffer_t *entry_buffer; long ptmx; char kernel_command_line[PLY_MAX_COMMAND_LINE_SIZE]; @@ -87,6 +98,7 @@ static ply_window_t *create_window (state_t *state, static bool attach_to_running_session (state_t *state); static void on_escape_pressed (state_t *state); static void dump_details_and_quit_splash (state_t *state); +static void update_display (state_t *state); static void on_session_output (state_t *state, @@ -155,18 +167,28 @@ on_ask_for_password (state_t *state, const char *prompt, ply_trigger_t *answer) { - if (state->boot_splash == NULL) - { - show_detailed_splash (state); - if (state->boot_splash == NULL) - ply_trigger_pull (answer, ""); - return; - } - - ply_boot_splash_ask_for_password (state->boot_splash, - prompt, answer); + ply_entry_trigger_t *entry_trigger = + calloc (1, sizeof (ply_entry_trigger_t)); + entry_trigger->type = PLY_ENTRY_TRIGGER_TYPE_PASSWORD; + entry_trigger->prompt = prompt; + entry_trigger->trigger = answer; + ply_list_append_data (state->entry_triggers, entry_trigger); + update_display (state); } +static void +on_ask_for_clearword (state_t *state, + const char *prompt, + ply_trigger_t *answer) +{ + ply_entry_trigger_t *entry_trigger = + calloc (1, sizeof (ply_entry_trigger_t)); + entry_trigger->type = PLY_ENTRY_TRIGGER_TYPE_CLEARWORD; + entry_trigger->prompt = prompt; + entry_trigger->trigger = answer; + ply_list_append_data (state->entry_triggers, entry_trigger); + update_display (state); +} static void on_watch_for_keystroke (state_t *state, @@ -439,7 +461,7 @@ static void dump_details_and_quit_splash (state_t *state) { state->showing_details = false; - on_escape_pressed (state); +/* on_escape_pressed (state); FIXME_brejc8 Check with halfline*/ if (state->boot_splash != NULL) ply_boot_splash_hide (state->boot_splash); @@ -504,6 +526,7 @@ start_boot_server (state_t *state) server = ply_boot_server_new ((ply_boot_server_update_handler_t) on_update, (ply_boot_server_ask_for_password_handler_t) on_ask_for_password, + (ply_boot_server_ask_for_clearword_handler_t) on_ask_for_clearword, (ply_boot_server_watch_for_keystroke_handler_t) on_watch_for_keystroke, (ply_boot_server_ignore_keystroke_handler_t) on_ignore_keystroke, (ply_boot_server_show_splash_handler_t) on_show_splash, @@ -527,6 +550,49 @@ start_boot_server (state_t *state) return server; } + +static void +update_display (state_t *state) +{ + if (!state->boot_splash) return; + + ply_list_node_t *node; + node = ply_list_get_first_node (state->entry_triggers); + if (node) + { + ply_entry_trigger_t* entry_trigger = ply_list_node_get_data (node); + if (entry_trigger->type == PLY_ENTRY_TRIGGER_TYPE_PASSWORD) + { + ply_boot_splash_display_info_t info; + info.password.prompt = entry_trigger->prompt; + info.password.bullets = mbstowcs (NULL, ply_buffer_get_bytes (state->entry_buffer), 0); + info.password.bullets = MAX(info.password.bullets,0); + ply_boot_splash_update_display (state->boot_splash, + PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY, + &info); + } + else if (entry_trigger->type == PLY_ENTRY_TRIGGER_TYPE_CLEARWORD) + { + ply_boot_splash_display_info_t info; + info.clearword.prompt = entry_trigger->prompt; + info.clearword.entry_text = ply_buffer_get_bytes (state->entry_buffer); + ply_boot_splash_update_display (state->boot_splash, + PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY, + &info); + } + else { + ply_trace("unkown entry type"); + } + } + else + { + ply_boot_splash_update_display (state->boot_splash, + PLY_BOOT_SPLASH_DISPLAY_NORMAL, + NULL); + } + +} + static void on_escape_pressed (state_t *state) { @@ -547,6 +613,7 @@ on_escape_pressed (state_t *state) show_default_splash (state); state->showing_details = false; } + update_display (state); } static void @@ -555,21 +622,70 @@ on_keyboard_input (state_t *state, size_t character_size) { ply_list_node_t *node; - - for (node = ply_list_get_first_node (state->keystroke_triggers); node; - node = ply_list_get_next_node (state->keystroke_triggers, node)) + node = ply_list_get_first_node (state->entry_triggers); + if (node) { - ply_keystroke_trigger_t* keystroke_trigger = ply_list_node_get_data (node); - if (!keystroke_trigger->keys || strstr(keystroke_trigger->keys, keyboard_input)) /* assume strstr works on utf8 arrays */ + ply_buffer_append_bytes (state->entry_buffer, keyboard_input, character_size); + update_display (state); + } + else + { + for (node = ply_list_get_first_node (state->keystroke_triggers); node; + node = ply_list_get_next_node (state->keystroke_triggers, node)) { - ply_trigger_pull (keystroke_trigger->trigger, keyboard_input); - ply_list_remove_node (state->keystroke_triggers, node); - return; + ply_keystroke_trigger_t* keystroke_trigger = ply_list_node_get_data (node); + if (!keystroke_trigger->keys || strstr(keystroke_trigger->keys, keyboard_input)) /* assume strstr works on utf8 arrays */ + { + ply_trigger_pull (keystroke_trigger->trigger, keyboard_input); + ply_list_remove_node (state->keystroke_triggers, node); + free(keystroke_trigger); + return; + } } + return; + } +} +void +on_backspace (state_t *state) +{ + ssize_t bytes_to_remove; + ssize_t previous_character_size; + const char *bytes; + size_t size; + ply_list_node_t *node = ply_list_get_first_node (state->entry_triggers); + if (!node) return; + + bytes = ply_buffer_get_bytes (state->entry_buffer); + size = ply_buffer_get_size (state->entry_buffer); + + bytes_to_remove = MIN(size, MB_CUR_MAX); + while ((previous_character_size = mbrlen (&bytes[size - bytes_to_remove], bytes_to_remove, NULL)) < bytes_to_remove && + previous_character_size > 0) + bytes_to_remove -= previous_character_size; + + ply_buffer_remove_bytes_at_end (state->entry_buffer, bytes_to_remove); + update_display (state); +} + +void +on_enter (state_t *state, + const char *line) +{ + ply_list_node_t *node; + node = ply_list_get_first_node (state->entry_triggers); + if (node) + { + ply_entry_trigger_t* entry_trigger = ply_list_node_get_data (node); + const char* reply_text = ply_buffer_get_bytes (state->entry_buffer); + ply_trigger_pull (entry_trigger->trigger, reply_text); + ply_buffer_clear (state->entry_buffer); + ply_list_remove_node (state->entry_triggers, node); + free(entry_trigger); + update_display (state); } - return; } + static ply_window_t * create_window (state_t *state, const char *tty_name) @@ -606,12 +722,6 @@ add_windows_to_boot_splash (state_t *state, { ply_trace ("adding window to boot splash"); ply_boot_splash_add_window (splash, window); - ply_trace ("listening for escape key"); - ply_window_add_escape_handler (window, (ply_window_escape_handler_t) - on_escape_pressed, state); - ply_trace ("listening for keystrokes"); - ply_window_add_keyboard_input_handler (window, - (ply_window_keyboard_input_handler_t) on_keyboard_input, state); } node = next_node; } @@ -644,7 +754,6 @@ start_boot_splash (state_t *state, ply_trace ("adding windows to boot splash"); add_windows_to_boot_splash (state, splash); - ply_trace ("showing plugin"); if (!ply_boot_splash_show (splash)) { @@ -654,6 +763,7 @@ start_boot_splash (state_t *state, return NULL; } + update_display (state); return splash; } @@ -848,6 +958,7 @@ static bool initialize_environment (state_t *state) { ply_trace ("initializing minimal work environment"); + ply_list_node_t *node; if (!get_kernel_command_line (state)) return false; @@ -857,13 +968,36 @@ initialize_environment (state_t *state) state->windows = ply_list_new (); state->keystroke_triggers = ply_list_new (); + state->entry_triggers = ply_list_new (); + state->entry_buffer = ply_buffer_new(); check_for_consoles (state); if (state->console != NULL) redirect_standard_io_to_device (state->console); else redirect_standard_io_to_device ("tty1"); - + + + for (node = ply_list_get_first_node (state->windows); node; + node = ply_list_get_next_node (state->windows, node)) + { + ply_window_t *window = ply_list_node_get_data (node); + + ply_trace ("listening for escape key"); + ply_window_add_escape_handler (window, (ply_window_escape_handler_t) + on_escape_pressed, state); + ply_trace ("listening for keystrokes"); + ply_window_add_keyboard_input_handler (window, + (ply_window_keyboard_input_handler_t) on_keyboard_input, state); + ply_trace ("listening for backspace"); + ply_window_add_backspace_handler (window, + (ply_window_backspace_handler_t) on_backspace, state); + ply_trace ("listening for enter"); + ply_window_add_enter_handler (window, + (ply_window_enter_handler_t) on_enter, state); + } + + ply_trace ("initialized minimal work environment"); return true; } diff --git a/src/plugins/splash/details/plugin.c b/src/plugins/splash/details/plugin.c index f7259fca..00f255e5 100644 --- a/src/plugins/splash/details/plugin.c +++ b/src/plugins/splash/details/plugin.c @@ -53,20 +53,17 @@ #include -void ask_for_password (ply_boot_splash_plugin_t *plugin, - const char *prompt, - ply_trigger_t *answer); +#define CLEAR_LINE_SEQUENCE "\033[2K\r" + typedef void (* ply_boot_splash_plugin_window_handler_t) (ply_window_t *window, ply_boot_splash_plugin_t *, void *user_data, void *other_user_data); ply_boot_splash_plugin_interface_t *ply_boot_splash_plugin_get_interface (void); struct _ply_boot_splash_plugin { ply_event_loop_t *loop; - - ply_trigger_t *pending_password_answer; ply_list_t *windows; + ply_boot_splash_display_type_t state; - uint32_t keyboard_input_is_hidden : 1; }; ply_boot_splash_plugin_t * @@ -78,7 +75,7 @@ create_plugin (void) plugin = calloc (1, sizeof (ply_boot_splash_plugin_t)); plugin->windows = ply_list_new (); - + plugin->state = PLY_BOOT_SPLASH_DISPLAY_NORMAL; return plugin; } @@ -103,12 +100,6 @@ detach_from_event_loop (ply_boot_splash_plugin_t *plugin) ply_trace ("detaching from event loop"); } - -static void -write_text_on_window (ply_window_t *window, - ply_boot_splash_plugin_t *plugin, - const char *text, - void *user_data); static void for_each_window (ply_boot_splash_plugin_t *plugin, ply_boot_splash_plugin_window_handler_t handler, @@ -149,45 +140,31 @@ write_text_on_window (ply_window_t *window, write (fd, text, size); } +static void +clear_line_on_window (ply_window_t *window, + ply_boot_splash_plugin_t *plugin, + void *user_data, + void *more_user_data) +{ + ply_window_clear_text_line (window); +} + void on_keyboard_input (ply_boot_splash_plugin_t *plugin, const char *keyboard_input, size_t character_size) { - if (plugin->keyboard_input_is_hidden) - for_each_window (plugin, - (ply_boot_splash_plugin_window_handler_t) - write_text_on_window, (void *) "*", - (void *) strlen ("*")); - else - for_each_window (plugin, - (ply_boot_splash_plugin_window_handler_t) - write_text_on_window, (void *) keyboard_input, - (void *) character_size); } void on_backspace (ply_boot_splash_plugin_t *plugin) { - for_each_window (plugin, - (ply_boot_splash_plugin_window_handler_t) - ply_window_clear_text_character, NULL, NULL); } void on_enter (ply_boot_splash_plugin_t *plugin, const char *line) { - if (plugin->pending_password_answer != NULL) - { - ply_trigger_pull (plugin->pending_password_answer, line); - plugin->keyboard_input_is_hidden = false; - plugin->pending_password_answer = NULL; - - for_each_window (plugin, - (ply_boot_splash_plugin_window_handler_t) - ply_window_clear_text_line, NULL, NULL); - } } void @@ -221,10 +198,6 @@ initialize_window (ply_window_t *window, ply_window_add_enter_handler (window, (ply_window_enter_handler_t) on_enter, plugin); - - interface = ply_boot_splash_plugin_get_interface (); - - interface->ask_for_password = ask_for_password; } static void @@ -299,13 +272,6 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, (ply_boot_splash_plugin_window_handler_t) uninitialize_window, NULL, NULL); - if (plugin->pending_password_answer != NULL) - { - ply_trigger_pull (plugin->pending_password_answer, ""); - plugin->pending_password_answer = NULL; - plugin->keyboard_input_is_hidden = false; - } - ply_event_loop_stop_watching_for_exit (plugin->loop, (ply_event_loop_exit_handler_t) detach_from_event_loop, @@ -313,37 +279,93 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, detach_from_event_loop (plugin); } -static void -ask_for_password_on_window (ply_window_t *window, - ply_boot_splash_plugin_t *plugin, - const char *prompt) +void +update_display (ply_boot_splash_plugin_t *plugin, + ply_boot_splash_display_type_t type, + ply_boot_splash_display_info_t *info) { - int fd; - - ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT); - - fd = ply_window_get_tty_fd (window); - - if (prompt != NULL) + if (type == PLY_BOOT_SPLASH_DISPLAY_NORMAL) { - write (fd, "\r\n", strlen ("\r\n")); - write (fd, prompt, strlen (prompt)); + if (plugin->state != type) + { + for_each_window (plugin, + (ply_boot_splash_plugin_window_handler_t) + write_text_on_window, + (void *) "\r\n", (void *) strlen ("\r\n")); + } + plugin->state = type; + } + else if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY ) + { + if (plugin->state != type) + { + for_each_window (plugin, + (ply_boot_splash_plugin_window_handler_t) + write_text_on_window, + (void *) "\r\n", (void *) strlen ("\r\n")); + } + else + { + for_each_window (plugin, + (ply_boot_splash_plugin_window_handler_t) + write_text_on_window, + (void *) CLEAR_LINE_SEQUENCE, + (void *) strlen (CLEAR_LINE_SEQUENCE)); + } + plugin->state = type; + if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY) + { + if (info->clearword.prompt) + for_each_window (plugin, + (ply_boot_splash_plugin_window_handler_t) + write_text_on_window, + (void *) info->clearword.prompt, + (void *) strlen (info->clearword.prompt)); + for_each_window (plugin, + (ply_boot_splash_plugin_window_handler_t) + write_text_on_window, + (void *) ":", + (void *) strlen (":")); + for_each_window (plugin, + (ply_boot_splash_plugin_window_handler_t) + write_text_on_window, + (void *) info->clearword.entry_text, + (void *) strlen (info->clearword.entry_text)); + } + if (type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + int i; + if (info->password.prompt) + for_each_window (plugin, + (ply_boot_splash_plugin_window_handler_t) + write_text_on_window, + (void *) info->password.prompt, + (void *) strlen (info->password.prompt)); + else + for_each_window (plugin, + (ply_boot_splash_plugin_window_handler_t) + write_text_on_window, + (void *) "Password", + (void *) strlen ("Password")); + + for_each_window (plugin, + (ply_boot_splash_plugin_window_handler_t) + write_text_on_window, + (void *) ":", + (void *) strlen (":")); + for (i=0; ipassword.bullets; i++) + for_each_window (plugin, + (ply_boot_splash_plugin_window_handler_t) + write_text_on_window, + (void *) "*", + (void *) strlen ("*")); + } + } + else + { + ply_trace ("unkown display type"); } - - write (fd, "\r\nPassword: ", strlen ("\r\nPassword: ")); - plugin->keyboard_input_is_hidden = true; -} - -void -ask_for_password (ply_boot_splash_plugin_t *plugin, - const char *prompt, - ply_trigger_t *answer) -{ - plugin->pending_password_answer = answer; - - for_each_window (plugin, - (ply_boot_splash_plugin_window_handler_t) - ask_for_password_on_window, (void *) prompt, NULL); } ply_boot_splash_plugin_interface_t * @@ -359,6 +381,7 @@ ply_boot_splash_plugin_get_interface (void) .update_status = update_status, .on_boot_output = on_boot_output, .hide_splash_screen = hide_splash_screen, + .update_display = update_display, }; return &plugin_interface; diff --git a/src/plugins/splash/fade-in/bullet.png b/src/plugins/splash/fade-in/bullet.png index 691fb8033bf2c9747ff7b33e0b21e0709f74905c..97296fb468f86f2134eb20917f81507897923516 100644 GIT binary patch delta 158 zc-ni(`i)VsGr-TCmrII^fq{Y7)59eQNOOQN2OE$)!oRP3qM{uq4>Px+0jKV|PZKlL z(-{IiT^vIsF1MaP$k|{Z;Bs-foa)}l&gEC88U^|AZ4=yaTo2?Z7d zH5S{5dT)_vCw~G&NklFlt$bnM}M1R$soWcTo0v_vtRY|QJxB}jQ zpN9NRej~3sQE^38&Vftd3>Y*#aVO%(z=!VwlI=m2U20`MVQzr07GR8jNeo#ZV7x(f z38pkuyrlqKN)b?W#}bJRV7{(U#2YHiIWTUxlGTA40N=nXu-NrL4m@-y%{KXi#JW|X z6u6LmCV!#ZrbM0jwmoXx(q2<%j~d$mk)zJ3wdg{ye=$c+na&8$R^pDVd>jR)j;+$j zY%h`XUZVm8Qr0WX3Q&mZ;Kpx&hCKip8X)EAjkE2vO92&aILHVU>Hri3P_OI&6ar8q zXUr{F0Tc(IP=IvcP=5@jD43Q;sHTPCugd8j0Doy0XclPN6<9r`$olXlP?faAUbq|U zOguDOi92#gp8`|qU(E5Ed^F9bB!IPZ3*7Bm`#C*23O3}&qLS)xs!f0?&SCvJpasjG zW>-_sq}oK{+^LXx=+ioUNIC>_4_vcsrBt?FwIsU)RT`$uJ%tbR$B$*_Otnw|ZY9lT zK3;$f)SP7-FcGL^59{Sw7XPH|nu#m^z^i~Q8dl3zWxB4K`2aE{T?^E^wL>Q!6f+Yx v6-DkO#THe*star_image = ply_image_new (PLYMOUTH_IMAGE_DIR "fade-in/star.png"); plugin->lock_image = ply_image_new (PLYMOUTH_IMAGE_DIR "fade-in/lock.png"); plugin->entry = ply_entry_new (PLYMOUTH_IMAGE_DIR "fade-in"); + plugin->state = PLY_BOOT_SPLASH_DISPLAY_NORMAL; plugin->stars = ply_list_new (); return plugin; @@ -259,7 +259,6 @@ animate_at_time (ply_boot_splash_plugin_t *plugin, ply_frame_buffer_unpause_updates (plugin->frame_buffer); } -static void draw_password_entry (ply_boot_splash_plugin_t *plugin); static void on_timeout (ply_boot_splash_plugin_t *plugin) { @@ -381,31 +380,17 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin, const char *keyboard_input, size_t character_size) { - if (plugin->pending_password_answer == NULL) - return; - - ply_entry_add_bullet (plugin->entry); } void on_backspace (ply_boot_splash_plugin_t *plugin) { - ply_entry_remove_bullet (plugin->entry); } void on_enter (ply_boot_splash_plugin_t *plugin, const char *text) { - - if (plugin->pending_password_answer == NULL) - return; - - ply_trigger_pull (plugin->pending_password_answer, text); - plugin->pending_password_answer = NULL; - - ply_entry_hide (plugin->entry); - start_animation (plugin); } void @@ -424,10 +409,10 @@ on_draw (ply_boot_splash_plugin_t *plugin, draw_background (plugin, &area); - if (plugin->pending_password_answer != NULL) - ply_entry_draw (plugin->entry); - else + if (plugin->state != PLY_BOOT_SPLASH_DISPLAY_NORMAL) animate_at_time (plugin, plugin->now); + else + ply_entry_draw (plugin->entry); } void @@ -613,13 +598,6 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, { assert (plugin != NULL); - if (plugin->pending_password_answer != NULL) - { - ply_trigger_pull (plugin->pending_password_answer, ""); - plugin->pending_password_answer = NULL; - } - - (plugin->window, NULL, NULL); ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); @@ -663,20 +641,46 @@ show_password_entry (ply_boot_splash_plugin_t *plugin) x = area.width / 2.0 - (lock_width + entry_width) / 2.0 + lock_width; y = area.height / 2.0 - entry_height / 2.0; - draw_background (plugin, NULL); - ply_entry_show (plugin->entry, plugin->loop, plugin->window, x, y); } void -ask_for_password (ply_boot_splash_plugin_t *plugin, - const char *prompt, - ply_trigger_t *answer) +update_display (ply_boot_splash_plugin_t *plugin, + ply_boot_splash_display_type_t type, + ply_boot_splash_display_info_t *info) { - plugin->pending_password_answer = answer; - - stop_animation (plugin); - show_password_entry (plugin); + if (type == PLY_BOOT_SPLASH_DISPLAY_NORMAL) + { + if (plugin->state == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + plugin->state == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + ply_entry_hide (plugin->entry); + start_animation(plugin); + } + } + else if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY ) + { + if (plugin->state != PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY && + plugin->state != PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + stop_animation (plugin); + show_password_entry (plugin); + } + if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY) + { + ply_entry_set_text (plugin->entry, info->clearword.entry_text); + } + if (type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + ply_entry_set_bullets (plugin->entry, info->password.bullets); + } + } + else + { + ply_trace ("unkown display type"); + } + plugin->state = type; } ply_boot_splash_plugin_interface_t * @@ -691,7 +695,7 @@ ply_boot_splash_plugin_get_interface (void) .show_splash_screen = show_splash_screen, .update_status = update_status, .hide_splash_screen = hide_splash_screen, - .ask_for_password = ask_for_password, + .update_display = update_display, }; return &plugin_interface; diff --git a/src/plugins/splash/pulser/plugin.c b/src/plugins/splash/pulser/plugin.c index c2d4352e..4468c050 100644 --- a/src/plugins/splash/pulser/plugin.c +++ b/src/plugins/splash/pulser/plugin.c @@ -61,7 +61,6 @@ struct _ply_boot_splash_plugin { ply_event_loop_t *loop; - ply_trigger_t *pending_password_answer; ply_window_t *window; ply_text_pulser_t *pulser; @@ -169,30 +168,17 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin, const char *keyboard_input, size_t character_size) { - if (plugin->keyboard_input_is_hidden) - write (STDOUT_FILENO, "•", strlen ("•")); - else - write (STDOUT_FILENO, keyboard_input, character_size); } void on_backspace (ply_boot_splash_plugin_t *plugin) { - write (STDOUT_FILENO, BACKSPACE, strlen (BACKSPACE)); } void on_enter (ply_boot_splash_plugin_t *plugin, const char *line) { - if (plugin->pending_password_answer != NULL) - { - ply_trigger_pull (plugin->pending_password_answer, line); - plugin->keyboard_input_is_hidden = false; - plugin->pending_password_answer = NULL; - - start_animation (plugin); - } } void @@ -283,12 +269,6 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, ply_trace ("hiding splash screen"); - if (plugin->pending_password_answer != NULL) - { - ply_trigger_pull (plugin->pending_password_answer, ""); - plugin->pending_password_answer = NULL; - } - if (plugin->loop != NULL) { stop_animation (plugin); @@ -318,34 +298,71 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, } void -ask_for_password (ply_boot_splash_plugin_t *plugin, - const char *prompt, - ply_trigger_t *answer) +update_display (ply_boot_splash_plugin_t *plugin, + ply_boot_splash_display_type_t type, + ply_boot_splash_display_info_t *info) { - int window_width, window_height; - - plugin->pending_password_answer = answer; - - stop_animation (plugin); - ply_window_set_background_color (plugin->window, PLY_WINDOW_COLOR_DEFAULT); - ply_window_clear_screen (plugin->window); - - window_width = ply_window_get_number_of_text_columns (plugin->window); - window_height = ply_window_get_number_of_text_rows (plugin->window); - - if (prompt != NULL) + if (type == PLY_BOOT_SPLASH_DISPLAY_NORMAL) + { + start_animation(plugin); + return; + } + else if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY ) { + int window_width, window_height; + int i; + const char* prompt; + stop_animation (plugin); + ply_window_set_background_color (plugin->window, PLY_WINDOW_COLOR_DEFAULT); + ply_window_clear_screen (plugin->window); + + window_width = ply_window_get_number_of_text_columns (plugin->window); + window_height = ply_window_get_number_of_text_rows (plugin->window); + + prompt = ""; + if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY) + { + prompt = info->clearword.prompt; + if (!prompt) prompt = ""; + } + if (type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + prompt = info->password.prompt; + if (!prompt) prompt = "Password"; + } + + ply_window_set_text_cursor_position (plugin->window, + 0, window_height / 2); + + for (i=0; i < window_width; i++) + { + write (STDOUT_FILENO, " ", strlen (" ")); + } ply_window_set_text_cursor_position (plugin->window, - window_width / 2 - strlen (prompt) / 2, - window_height / 2 - 1); + window_width / 2 - (strlen (prompt)), + window_height / 2); write (STDOUT_FILENO, prompt, strlen (prompt)); + write (STDOUT_FILENO, ":", strlen (":")); + + if (type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + for (i=0; i < info->password.bullets; i++) + { + write (STDOUT_FILENO, "•", strlen ("•")); + } + } + else if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY) + { + const char* entry_text = info->clearword.entry_text; + write (STDOUT_FILENO, entry_text, strlen (entry_text)); + } + ply_window_show_text_cursor (plugin->window); + } + else + { + ply_trace ("unkown display type"); } - ply_window_set_text_cursor_position (plugin->window, - window_width / 2 - strlen ("Password: "), - window_height / 2); - write (STDOUT_FILENO, "Password: ", strlen ("Password: ")); - ply_window_show_text_cursor (plugin->window); - plugin->keyboard_input_is_hidden = true; } ply_boot_splash_plugin_interface_t * @@ -360,7 +377,7 @@ ply_boot_splash_plugin_get_interface (void) .show_splash_screen = show_splash_screen, .update_status = update_status, .hide_splash_screen = hide_splash_screen, - .ask_for_password = ask_for_password, + .update_display = update_display, }; return &plugin_interface; diff --git a/src/plugins/splash/solar/plugin.c b/src/plugins/splash/solar/plugin.c index bd1e5681..473111c0 100644 --- a/src/plugins/splash/solar/plugin.c +++ b/src/plugins/splash/solar/plugin.c @@ -179,8 +179,8 @@ struct _ply_boot_splash_plugin ply_entry_t *entry; ply_label_t *label; + ply_boot_splash_display_type_t state; - ply_trigger_t *pending_password_answer; ply_trigger_t *idle_trigger; ply_list_t *sprites; @@ -224,6 +224,7 @@ create_plugin (void) #endif plugin->entry = ply_entry_new (PLYMOUTH_IMAGE_DIR "solar"); plugin->label = ply_label_new (); + plugin->state = PLY_BOOT_SPLASH_DISPLAY_NORMAL; plugin->sprites = ply_list_new(); plugin->progress = 0; plugin->progress_target = -1; @@ -971,31 +972,17 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin, const char *keyboard_input, size_t character_size) { - if (plugin->pending_password_answer == NULL) - return; - - ply_entry_add_bullet (plugin->entry); } void on_backspace (ply_boot_splash_plugin_t *plugin) { - ply_entry_remove_bullet (plugin->entry); } void on_enter (ply_boot_splash_plugin_t *plugin, const char *text) { - if (plugin->pending_password_answer == NULL) - return; - - ply_trigger_pull (plugin->pending_password_answer, text); - plugin->pending_password_answer = NULL; - - ply_entry_hide (plugin->entry); - ply_entry_remove_all_bullets (plugin->entry); - start_animation (plugin); } @@ -1021,7 +1008,8 @@ on_draw (ply_boot_splash_plugin_t *plugin, else ply_frame_buffer_pause_updates (plugin->frame_buffer); - if (plugin->pending_password_answer != NULL) + if (plugin->state == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + plugin->state == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY ) { draw_background (plugin, &clip_area); ply_entry_draw (plugin->entry); @@ -1449,12 +1437,6 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, { assert (plugin != NULL); - if (plugin->pending_password_answer != NULL) - { - ply_trigger_pull (plugin->pending_password_answer, ""); - plugin->pending_password_answer = NULL; - } - ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); ply_window_remove_enter_handler (plugin->window, (ply_window_enter_handler_t) on_enter); @@ -1489,38 +1471,44 @@ show_password_prompt (ply_boot_splash_plugin_t *plugin, assert (plugin != NULL); - draw_background (plugin, NULL); - - ply_frame_buffer_get_size (plugin->frame_buffer, &area); - plugin->box_area.width = ply_image_get_width (plugin->box_image); - plugin->box_area.height = ply_image_get_height (plugin->box_image); - plugin->box_area.x = area.width / 2.0 - plugin->box_area.width / 2.0; - plugin->box_area.y = area.height / 2.0 - plugin->box_area.height / 2.0; + if (ply_entry_is_hidden (plugin->entry)) + { + draw_background (plugin, NULL); - plugin->lock_area.width = ply_image_get_width (plugin->lock_image); - plugin->lock_area.height = ply_image_get_height (plugin->lock_image); + ply_frame_buffer_get_size (plugin->frame_buffer, &area); + plugin->box_area.width = ply_image_get_width (plugin->box_image); + plugin->box_area.height = ply_image_get_height (plugin->box_image); + plugin->box_area.x = area.width / 2.0 - plugin->box_area.width / 2.0; + plugin->box_area.y = area.height / 2.0 - plugin->box_area.height / 2.0; - entry_width = ply_entry_get_width (plugin->entry); - entry_height = ply_entry_get_height (plugin->entry); + plugin->lock_area.width = ply_image_get_width (plugin->lock_image); + plugin->lock_area.height = ply_image_get_height (plugin->lock_image); - x = area.width / 2.0 - (plugin->lock_area.width + entry_width) / 2.0 + plugin->lock_area.width; - y = area.height / 2.0 - entry_height / 2.0; + entry_width = ply_entry_get_width (plugin->entry); + entry_height = ply_entry_get_height (plugin->entry); - plugin->lock_area.x = area.width / 2.0 - (plugin->lock_area.width + entry_width) / 2.0; - plugin->lock_area.y = area.height / 2.0 - plugin->lock_area.height / 2.0; + x = area.width / 2.0 - (plugin->lock_area.width + entry_width) / 2.0 + plugin->lock_area.width; + y = area.height / 2.0 - entry_height / 2.0; - box_data = ply_image_get_data (plugin->box_image); - ply_frame_buffer_fill_with_argb32_data (plugin->frame_buffer, - &plugin->box_area, 0, 0, - box_data); + plugin->lock_area.x = area.width / 2.0 - (plugin->lock_area.width + entry_width) / 2.0; + plugin->lock_area.y = area.height / 2.0 - plugin->lock_area.height / 2.0; - ply_entry_show (plugin->entry, plugin->loop, plugin->window, x, y); + box_data = ply_image_get_data (plugin->box_image); + ply_frame_buffer_fill_with_argb32_data (plugin->frame_buffer, + &plugin->box_area, 0, 0, + box_data); - lock_data = ply_image_get_data (plugin->lock_image); - ply_frame_buffer_fill_with_argb32_data (plugin->frame_buffer, - &plugin->lock_area, 0, 0, - lock_data); + ply_entry_show (plugin->entry, plugin->loop, plugin->window, x, y); + lock_data = ply_image_get_data (plugin->lock_image); + ply_frame_buffer_fill_with_argb32_data (plugin->frame_buffer, + &plugin->lock_area, 0, 0, + lock_data); + } + else + { + ply_entry_draw (plugin->entry); + } if (prompt != NULL) { int label_width, label_height; @@ -1530,32 +1518,13 @@ show_password_prompt (ply_boot_splash_plugin_t *plugin, label_height = ply_label_get_height (plugin->label); x = plugin->box_area.x + plugin->lock_area.width / 2; - y = plugin->box_area.y + plugin->box_area.height + label_height; + y = plugin->box_area.y + plugin->box_area.height; ply_label_show (plugin->label, plugin->window, x, y); } } -void -ask_for_password (ply_boot_splash_plugin_t *plugin, - const char *prompt, - ply_trigger_t *answer) -{ - plugin->pending_password_answer = answer; - - if (ply_entry_is_hidden (plugin->entry)) - { - stop_animation (plugin, NULL); - show_password_prompt (plugin, prompt); - } - else - { - ply_entry_draw (plugin->entry); - ply_label_draw (plugin->label); - } -} - void on_root_mounted (ply_boot_splash_plugin_t *plugin) { @@ -1569,6 +1538,49 @@ become_idle (ply_boot_splash_plugin_t *plugin, stop_animation (plugin, idle_trigger); } +void +update_display (ply_boot_splash_plugin_t *plugin, + ply_boot_splash_display_type_t type, + ply_boot_splash_display_info_t *info) +{ + if (type == PLY_BOOT_SPLASH_DISPLAY_NORMAL) + { + if (plugin->state == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + plugin->state == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + plugin->state = type; + ply_entry_hide (plugin->entry); + start_animation(plugin); + } + } + else if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY ) + { + if (plugin->state != PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY && + plugin->state != PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + stop_animation (plugin, NULL); + } + + plugin->state = type; + + if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY) + { + show_password_prompt (plugin, info->clearword.prompt); + ply_entry_set_text (plugin->entry, info->clearword.entry_text); + } + if (type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + show_password_prompt (plugin, info->password.prompt); + ply_entry_set_bullets (plugin->entry, info->password.bullets); + } + } + else + { + ply_trace ("unkown display type"); + } +} + ply_boot_splash_plugin_interface_t * ply_boot_splash_plugin_get_interface (void) { @@ -1582,9 +1594,9 @@ ply_boot_splash_plugin_get_interface (void) .update_status = update_status, .on_boot_progress = on_boot_progress, .hide_splash_screen = hide_splash_screen, - .ask_for_password = ask_for_password, .on_root_mounted = on_root_mounted, - .become_idle = become_idle + .become_idle = become_idle, + .update_display = update_display, }; return &plugin_interface; diff --git a/src/plugins/splash/spinfinity/plugin.c b/src/plugins/splash/spinfinity/plugin.c index e94c8986..c9b51721 100644 --- a/src/plugins/splash/spinfinity/plugin.c +++ b/src/plugins/splash/spinfinity/plugin.c @@ -80,8 +80,8 @@ struct _ply_boot_splash_plugin ply_throbber_t *throbber; ply_label_t *label; ply_progress_bar_t *progress_bar; + ply_boot_splash_display_type_t state; - ply_trigger_t *pending_password_answer; ply_trigger_t *idle_trigger; uint32_t root_is_mounted : 1; @@ -264,10 +264,6 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin, const char *keyboard_input, size_t character_size) { - if (plugin->pending_password_answer == NULL) - return; - - ply_entry_add_bullet (plugin->entry); } void @@ -280,15 +276,6 @@ void on_enter (ply_boot_splash_plugin_t *plugin, const char *text) { - if (plugin->pending_password_answer == NULL) - return; - - ply_trigger_pull (plugin->pending_password_answer, text); - plugin->pending_password_answer = NULL; - - ply_entry_hide (plugin->entry); - ply_entry_remove_all_bullets (plugin->entry); - start_animation (plugin); } void @@ -308,7 +295,8 @@ on_draw (ply_boot_splash_plugin_t *plugin, ply_frame_buffer_pause_updates (plugin->frame_buffer); draw_background (plugin, &area); - if (plugin->pending_password_answer != NULL) + if (plugin->state == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + plugin->state == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY ) { ply_entry_draw (plugin->entry); ply_label_draw (plugin->label); @@ -458,11 +446,6 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, { assert (plugin != NULL); - if (plugin->pending_password_answer != NULL) - { - ply_trigger_pull (plugin->pending_password_answer, ""); - plugin->pending_password_answer = NULL; - } ply_window_remove_keyboard_input_handler (plugin->window, (ply_window_keyboard_input_handler_t) on_keyboard_input); ply_window_remove_backspace_handler (plugin->window, (ply_window_backspace_handler_t) on_backspace); @@ -498,38 +481,44 @@ show_password_prompt (ply_boot_splash_plugin_t *plugin, assert (plugin != NULL); - draw_background (plugin, NULL); - - ply_frame_buffer_get_size (plugin->frame_buffer, &area); - plugin->box_area.width = ply_image_get_width (plugin->box_image); - plugin->box_area.height = ply_image_get_height (plugin->box_image); - plugin->box_area.x = area.width / 2.0 - plugin->box_area.width / 2.0; - plugin->box_area.y = area.height / 2.0 - plugin->box_area.height / 2.0; + if (ply_entry_is_hidden (plugin->entry)) + { + draw_background (plugin, NULL); - plugin->lock_area.width = ply_image_get_width (plugin->lock_image); - plugin->lock_area.height = ply_image_get_height (plugin->lock_image); + ply_frame_buffer_get_size (plugin->frame_buffer, &area); + plugin->box_area.width = ply_image_get_width (plugin->box_image); + plugin->box_area.height = ply_image_get_height (plugin->box_image); + plugin->box_area.x = area.width / 2.0 - plugin->box_area.width / 2.0; + plugin->box_area.y = area.height / 2.0 - plugin->box_area.height / 2.0; - entry_width = ply_entry_get_width (plugin->entry); - entry_height = ply_entry_get_height (plugin->entry); + plugin->lock_area.width = ply_image_get_width (plugin->lock_image); + plugin->lock_area.height = ply_image_get_height (plugin->lock_image); - x = area.width / 2.0 - (plugin->lock_area.width + entry_width) / 2.0 + plugin->lock_area.width; - y = area.height / 2.0 - entry_height / 2.0; + entry_width = ply_entry_get_width (plugin->entry); + entry_height = ply_entry_get_height (plugin->entry); - plugin->lock_area.x = area.width / 2.0 - (plugin->lock_area.width + entry_width) / 2.0; - plugin->lock_area.y = area.height / 2.0 - plugin->lock_area.height / 2.0; + x = area.width / 2.0 - (plugin->lock_area.width + entry_width) / 2.0 + plugin->lock_area.width; + y = area.height / 2.0 - entry_height / 2.0; - box_data = ply_image_get_data (plugin->box_image); - ply_frame_buffer_fill_with_argb32_data (plugin->frame_buffer, - &plugin->box_area, 0, 0, - box_data); + plugin->lock_area.x = area.width / 2.0 - (plugin->lock_area.width + entry_width) / 2.0; + plugin->lock_area.y = area.height / 2.0 - plugin->lock_area.height / 2.0; - ply_entry_show (plugin->entry, plugin->loop, plugin->window, x, y); + box_data = ply_image_get_data (plugin->box_image); + ply_frame_buffer_fill_with_argb32_data (plugin->frame_buffer, + &plugin->box_area, 0, 0, + box_data); - lock_data = ply_image_get_data (plugin->lock_image); - ply_frame_buffer_fill_with_argb32_data (plugin->frame_buffer, - &plugin->lock_area, 0, 0, - lock_data); + ply_entry_show (plugin->entry, plugin->loop, plugin->window, x, y); + lock_data = ply_image_get_data (plugin->lock_image); + ply_frame_buffer_fill_with_argb32_data (plugin->frame_buffer, + &plugin->lock_area, 0, 0, + lock_data); + } + else + { + ply_entry_draw (plugin->entry); + } if (prompt != NULL) { int label_width, label_height; @@ -539,32 +528,13 @@ show_password_prompt (ply_boot_splash_plugin_t *plugin, label_height = ply_label_get_height (plugin->label); x = plugin->box_area.x + plugin->lock_area.width / 2; - y = plugin->box_area.y + plugin->box_area.height + label_height; + y = plugin->box_area.y + plugin->box_area.height; ply_label_show (plugin->label, plugin->window, x, y); } } -void -ask_for_password (ply_boot_splash_plugin_t *plugin, - const char *prompt, - ply_trigger_t *answer) -{ - plugin->pending_password_answer = answer; - - if (ply_entry_is_hidden (plugin->entry)) - { - stop_animation (plugin, NULL); - show_password_prompt (plugin, prompt); - } - else - { - ply_entry_draw (plugin->entry); - ply_label_draw (plugin->label); - } -} - void on_root_mounted (ply_boot_splash_plugin_t *plugin) { @@ -578,6 +548,49 @@ become_idle (ply_boot_splash_plugin_t *plugin, stop_animation (plugin, idle_trigger); } +void +update_display (ply_boot_splash_plugin_t *plugin, + ply_boot_splash_display_type_t type, + ply_boot_splash_display_info_t *info) +{ + if (type == PLY_BOOT_SPLASH_DISPLAY_NORMAL) + { + if (plugin->state == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + plugin->state == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + plugin->state = type; + ply_entry_hide (plugin->entry); + start_animation(plugin); + } + } + else if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY ) + { + if (plugin->state != PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY && + plugin->state != PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + stop_animation (plugin, NULL); + } + + plugin->state = type; + + if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY) + { + show_password_prompt (plugin, info->clearword.prompt); + ply_entry_set_text (plugin->entry, info->clearword.entry_text); + } + if (type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + show_password_prompt (plugin, info->password.prompt); + ply_entry_set_bullets (plugin->entry, info->password.bullets); + } + } + else + { + ply_trace ("unkown display type"); + } +} + ply_boot_splash_plugin_interface_t * ply_boot_splash_plugin_get_interface (void) { @@ -591,9 +604,9 @@ ply_boot_splash_plugin_get_interface (void) .update_status = update_status, .on_boot_progress = on_boot_progress, .hide_splash_screen = hide_splash_screen, - .ask_for_password = ask_for_password, .on_root_mounted = on_root_mounted, .become_idle = become_idle, + .update_display = update_display, }; return &plugin_interface; diff --git a/src/plugins/splash/text/plugin.c b/src/plugins/splash/text/plugin.c index 69e0e87d..f08c1b7f 100644 --- a/src/plugins/splash/text/plugin.c +++ b/src/plugins/splash/text/plugin.c @@ -62,12 +62,10 @@ struct _ply_boot_splash_plugin { ply_event_loop_t *loop; - ply_trigger_t *pending_password_answer; ply_window_t *window; ply_text_progress_bar_t *progress_bar; - uint32_t keyboard_input_is_hidden : 1; uint32_t is_animating : 1; }; void hide_splash_screen (ply_boot_splash_plugin_t *plugin, @@ -175,30 +173,17 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin, const char *keyboard_input, size_t character_size) { - if (plugin->keyboard_input_is_hidden) - write (STDOUT_FILENO, "•", strlen ("•")); - else - write (STDOUT_FILENO, keyboard_input, character_size); } void on_backspace (ply_boot_splash_plugin_t *plugin) { - write (STDOUT_FILENO, BACKSPACE, strlen (BACKSPACE)); } void on_enter (ply_boot_splash_plugin_t *plugin, const char *line) { - if (plugin->pending_password_answer != NULL) - { - ply_trigger_pull (plugin->pending_password_answer, line); - plugin->keyboard_input_is_hidden = false; - plugin->pending_password_answer = NULL; - - start_animation (plugin); - } } void @@ -307,12 +292,6 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, ply_trace ("hiding splash screen"); - if (plugin->pending_password_answer != NULL) - { - ply_trigger_pull (plugin->pending_password_answer, ""); - plugin->pending_password_answer = NULL; - } - if (plugin->loop != NULL) { stop_animation (plugin); @@ -342,36 +321,73 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, } void -ask_for_password (ply_boot_splash_plugin_t *plugin, - const char *prompt, - ply_trigger_t *answer) +update_display (ply_boot_splash_plugin_t *plugin, + ply_boot_splash_display_type_t type, + ply_boot_splash_display_info_t *info) { - int window_width, window_height; - - plugin->pending_password_answer = answer; - - stop_animation (plugin); - ply_window_set_background_color (plugin->window, PLY_WINDOW_COLOR_DEFAULT); - ply_window_clear_screen (plugin->window); - - window_width = ply_window_get_number_of_text_columns (plugin->window); - window_height = ply_window_get_number_of_text_rows (plugin->window); - - if (prompt != NULL) + if (type == PLY_BOOT_SPLASH_DISPLAY_NORMAL) { + start_animation(plugin); + } + else if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY || + type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY ) + { + int window_width, window_height; + int i; + const char* prompt; + stop_animation (plugin); + ply_window_set_background_color (plugin->window, PLY_WINDOW_COLOR_DEFAULT); + ply_window_clear_screen (plugin->window); + + window_width = ply_window_get_number_of_text_columns (plugin->window); + window_height = ply_window_get_number_of_text_rows (plugin->window); + + prompt = ""; + if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY) + { + prompt = info->clearword.prompt; + if (!prompt) prompt = ""; + } + if (type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + prompt = info->password.prompt; + if (!prompt) prompt = "Password"; + } + ply_window_set_text_cursor_position (plugin->window, - window_width / 2 - strlen (prompt) / 2, - window_height / 2 - 1); + 0, window_height / 2); + + for (i=0; i < window_width; i++) + { + write (STDOUT_FILENO, " ", strlen (" ")); + } + ply_window_set_text_cursor_position (plugin->window, + window_width / 2 - (strlen (prompt)), + window_height / 2); write (STDOUT_FILENO, prompt, strlen (prompt)); + write (STDOUT_FILENO, ":", strlen (":")); + + if (type == PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY) + { + for (i=0; i < info->password.bullets; i++) + { + write (STDOUT_FILENO, "*", strlen ("*")); + } + } + else if (type == PLY_BOOT_SPLASH_DISPLAY_CLEARWORD_ENTRY) + { + const char* entry_text = info->clearword.entry_text; + write (STDOUT_FILENO, entry_text, strlen (entry_text)); + } + ply_window_show_text_cursor (plugin->window); + } + else + { + ply_trace ("unkown display type"); } - ply_window_set_text_cursor_position (plugin->window, - window_width / 2 - strlen ("Password: "), - window_height / 2); - write (STDOUT_FILENO, "Password: ", strlen ("Password: ")); - ply_window_show_text_cursor (plugin->window); - plugin->keyboard_input_is_hidden = true; } + ply_boot_splash_plugin_interface_t * ply_boot_splash_plugin_get_interface (void) { @@ -385,7 +401,7 @@ ply_boot_splash_plugin_get_interface (void) .update_status = update_status, .on_boot_progress = on_boot_progress, .hide_splash_screen = hide_splash_screen, - .ask_for_password = ask_for_password, + .update_display = update_display, }; return &plugin_interface; diff --git a/src/ply-boot-protocol.h b/src/ply-boot-protocol.h index a8a27b10..49bbcf89 100644 --- a/src/ply-boot-protocol.h +++ b/src/ply-boot-protocol.h @@ -29,6 +29,7 @@ #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_QUIT "Q" #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_PASSWORD "*" #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_CACHED_PASSWORD "c" +#define PLY_BOOT_PROTOCOL_REQUEST_TYPE_CLEARWORD "W" #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_KEYSTROKE "K" #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_KEYSTROKE_REMOVE "L" #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_SHOW_SPLASH "$" diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c index 3a9d6077..8b54c37c 100644 --- a/src/ply-boot-server.c +++ b/src/ply-boot-server.c @@ -60,6 +60,7 @@ struct _ply_boot_server ply_boot_server_show_splash_handler_t show_splash_handler; ply_boot_server_hide_splash_handler_t hide_splash_handler; ply_boot_server_ask_for_password_handler_t ask_for_password_handler; + ply_boot_server_ask_for_clearword_handler_t ask_for_clearword_handler; ply_boot_server_watch_for_keystroke_handler_t watch_for_keystroke_handler; ply_boot_server_ignore_keystroke_handler_t ignore_keystroke_handler; ply_boot_server_quit_handler_t quit_handler; @@ -71,6 +72,7 @@ struct _ply_boot_server ply_boot_server_t * ply_boot_server_new (ply_boot_server_update_handler_t update_handler, ply_boot_server_ask_for_password_handler_t ask_for_password_handler, + ply_boot_server_ask_for_clearword_handler_t ask_for_clearword_handler, ply_boot_server_watch_for_keystroke_handler_t watch_for_keystroke_handler, ply_boot_server_ignore_keystroke_handler_t ignore_keystroke_handler, ply_boot_server_show_splash_handler_t show_splash_handler, @@ -90,6 +92,7 @@ ply_boot_server_new (ply_boot_server_update_handler_t update_handler, server->is_listening = false; server->update_handler = update_handler; server->ask_for_password_handler = ask_for_password_handler; + server->ask_for_clearword_handler = ask_for_clearword_handler; server->watch_for_keystroke_handler = watch_for_keystroke_handler; server->ignore_keystroke_handler = ignore_keystroke_handler; server->newroot_handler = newroot_handler; @@ -221,9 +224,6 @@ ply_boot_connection_on_password_answer (ply_boot_connection_t *connection, uint8_t size; - /* splash plugin isn't able to ask for password, - * punt to client - */ if (password == NULL) { if (!ply_write (connection->fd, @@ -255,6 +255,42 @@ ply_boot_connection_on_password_answer (ply_boot_connection_t *connection, } + +static void +ply_boot_connection_on_clearword_answer (ply_boot_connection_t *connection, + const char *password) +{ + + uint8_t size; + + if (password == NULL) + { + if (!ply_write (connection->fd, + PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER, + strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER))) + ply_error ("could not write bytes: %m"); + } + else + { + /* FIXME: support up to 4 billion + */ + if (strlen (password) > 255) + ply_error ("password to long to fit in buffer"); + + size = (uint8_t) strlen (password); + + if (!ply_write (connection->fd, + PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER, + strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER)) || + !ply_write (connection->fd, + &size, sizeof (uint8_t)) || + !ply_write (connection->fd, + password, size)) + ply_error ("could not write bytes: %m"); + } + +} + static void ply_boot_connection_on_keystroke_answer (ply_boot_connection_t *connection, const char *key) @@ -262,9 +298,6 @@ ply_boot_connection_on_keystroke_answer (ply_boot_connection_t *connection, uint8_t size; - /* splash plugin isn't able to ask for password, - * punt to client - */ if (key == NULL) { if (!ply_write (connection->fd, @@ -442,6 +475,26 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection) free(command); return; } + else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_CLEARWORD) == 0) + { + ply_trigger_t *answer; + + answer = ply_trigger_new (NULL); + ply_trigger_add_handler (answer, + (ply_trigger_handler_t) + ply_boot_connection_on_clearword_answer, + connection); + + if (server->ask_for_clearword_handler != NULL) + server->ask_for_clearword_handler (server->user_data, + argument, + answer, + server); + /* will reply later + */ + free(command); + return; + } else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_KEYSTROKE) == 0) { ply_trigger_t *answer; @@ -637,6 +690,14 @@ on_ask_for_password (ply_event_loop_t *loop) return; } +static void +on_ask_for_clearword (ply_event_loop_t *loop) +{ + printf ("got clearword request, returning 'password'...\n"); + + return; +} + static void on_watch_for_keystroke (ply_event_loop_t *loop) { @@ -668,6 +729,7 @@ main (int argc, server = ply_boot_server_new ((ply_boot_server_update_handler_t) on_update, (ply_boot_server_ask_for_password_handler_t) on_ask_for_password, + (ply_boot_server_ask_for_clearword_handler_t) on_ask_for_clearword, (ply_boot_server_watch_for_keystroke_handler_t) on_watch_for_keystroke, (ply_boot_server_ignore_keystroke_handler_t) on_ignore_keystroke, (ply_boot_server_show_splash_handler_t) on_show_splash, diff --git a/src/ply-boot-server.h b/src/ply-boot-server.h index 1c5c376b..1f38ef28 100644 --- a/src/ply-boot-server.h +++ b/src/ply-boot-server.h @@ -53,7 +53,13 @@ typedef void (* ply_boot_server_ask_for_password_handler_t) (void * const char *prompt, ply_trigger_t *answer, ply_boot_server_t *server); - +typedef void (* ply_boot_server_clearword_answer_handler_t) (void *answer_data, + const char *clearword, + ply_boot_server_t *server); +typedef void (* ply_boot_server_ask_for_clearword_handler_t) (void *user_data, + const char *prompt, + ply_trigger_t *answer, + ply_boot_server_t *server); typedef void (* ply_boot_server_watch_for_keystroke_handler_t) (void *user_data, const char *keys, ply_trigger_t *answer, @@ -76,6 +82,7 @@ typedef void (* ply_boot_server_quit_handler_t) (void *user_data, #ifndef PLY_HIDE_FUNCTION_DECLARATIONS ply_boot_server_t *ply_boot_server_new (ply_boot_server_update_handler_t update_handler, ply_boot_server_ask_for_password_handler_t ask_for_password_handler, + ply_boot_server_ask_for_clearword_handler_t ask_for_clearword_handler, ply_boot_server_watch_for_keystroke_handler_t watch_for_keystroke_handler, ply_boot_server_ignore_keystroke_handler_t ignore_keystroke_handler, ply_boot_server_show_splash_handler_t show_splash_handler, diff --git a/src/ply-boot-splash.c b/src/ply-boot-splash.c index 02fbba19..256a508c 100644 --- a/src/ply-boot-splash.c +++ b/src/ply-boot-splash.c @@ -283,42 +283,6 @@ ply_boot_splash_root_mounted (ply_boot_splash_t *splash) splash->plugin_interface->on_root_mounted (splash->plugin); } -static void -on_password_answered (ply_boot_splash_t *splash) -{ - if (splash->progress) - ply_progress_unpause (splash->progress); -} - -void -ply_boot_splash_ask_for_password (ply_boot_splash_t *splash, - const char *prompt, - ply_trigger_t *trigger) -{ - - assert (splash != NULL); - assert (splash->plugin_interface != NULL); - assert (splash->plugin != NULL); - assert (splash->is_shown); - - if (splash->plugin_interface->ask_for_password == NULL) - { - ply_trigger_pull (trigger, NULL); - return; - } - - if (splash->progress) - ply_progress_pause (splash->progress); - - ply_trigger_add_handler (trigger, - (ply_trigger_handler_t) - on_password_answered, splash); - - splash->plugin_interface->ask_for_password (splash->plugin, - prompt, - trigger); -} - static void ply_boot_splash_detach_from_event_loop (ply_boot_splash_t *splash) { @@ -354,6 +318,20 @@ ply_boot_splash_hide (ply_boot_splash_t *splash) } } + +void +ply_boot_splash_update_display (ply_boot_splash_t *splash, + ply_boot_splash_display_type_t type, + ply_boot_splash_display_info_t *info) +{ + assert (splash != NULL); + assert (splash->plugin_interface != NULL); + assert (splash->plugin != NULL); + if (splash->plugin_interface->update_display != NULL) + splash->plugin_interface->update_display (splash->plugin, type, info); +} + + void ply_boot_splash_attach_to_event_loop (ply_boot_splash_t *splash, ply_event_loop_t *loop) diff --git a/src/ply-boot-splash.h b/src/ply-boot-splash.h index d55f45f1..3c3fbcb6 100644 --- a/src/ply-boot-splash.h +++ b/src/ply-boot-splash.h @@ -53,11 +53,10 @@ void ply_boot_splash_update_output (ply_boot_splash_t *splash, const char *output, size_t size); void ply_boot_splash_root_mounted (ply_boot_splash_t *splash); - -void ply_boot_splash_ask_for_password (ply_boot_splash_t *splash, - const char *prompt, - ply_trigger_t *answer); void ply_boot_splash_hide (ply_boot_splash_t *splash); +void ply_boot_splash_update_display (ply_boot_splash_t *splash, + ply_boot_splash_display_type_t type, + ply_boot_splash_display_info_t *info); void ply_boot_splash_attach_to_event_loop (ply_boot_splash_t *splash, ply_event_loop_t *loop); void ply_boot_splash_attach_progress (ply_boot_splash_t *splash, -- 2.47.2