Merge branch 'script-password-argument' into 'main'

script: add password argument to display password callback

Closes #150

See merge request plymouth/plymouth!166
This commit is contained in:
Ray Strode 2022-03-25 20:00:49 +00:00
commit bce1856745
8 changed files with 95 additions and 0 deletions

View file

@ -95,6 +95,10 @@ typedef struct
const char *entry_text);
void (*become_idle)(ply_boot_splash_plugin_t *plugin,
ply_trigger_t *idle_trigger);
void (*display_prompt)(ply_boot_splash_plugin_t *plugin,
const char *prompt,
const char *entry_text,
bool is_secret);
} ply_boot_splash_plugin_interface_t;
#endif /* PLY_BOOT_SPLASH_PLUGIN_H */

View file

@ -640,6 +640,18 @@ void ply_boot_splash_display_question (ply_boot_splash_t *splash,
splash->plugin_interface->display_question (splash->plugin, prompt, entry_text);
}
void ply_boot_splash_display_prompt (ply_boot_splash_t *splash,
const char *prompt,
const char *entry_text,
bool is_secret)
{
assert (splash != NULL);
assert (splash->plugin_interface != NULL);
assert (splash->plugin != NULL);
if (splash->plugin_interface->display_prompt != NULL)
splash->plugin_interface->display_prompt (splash->plugin, prompt, entry_text, is_secret);
}
void

View file

@ -82,6 +82,10 @@ void ply_boot_splash_display_password (ply_boot_splash_t *splash,
void ply_boot_splash_display_question (ply_boot_splash_t *splash,
const char *prompt,
const char *entry_text);
void ply_boot_splash_display_prompt (ply_boot_splash_t *splash,
const char *prompt,
const char *entry_text,
bool is_secret);
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,

View file

@ -1462,10 +1462,18 @@ update_display (state_t *state)
ply_boot_splash_display_password (state->boot_splash,
entry_trigger->prompt,
bullets);
ply_boot_splash_display_prompt (state->boot_splash,
entry_trigger->prompt,
ply_buffer_get_bytes (state->entry_buffer),
true);
} else if (entry_trigger->type == PLY_ENTRY_TRIGGER_TYPE_QUESTION) {
ply_boot_splash_display_question (state->boot_splash,
entry_trigger->prompt,
ply_buffer_get_bytes (state->entry_buffer));
ply_boot_splash_display_prompt (state->boot_splash,
entry_trigger->prompt,
ply_buffer_get_bytes (state->entry_buffer),
false);
} else {
ply_trace ("unkown entry type");
}

View file

@ -509,6 +509,21 @@ display_question (ply_boot_splash_plugin_t *plugin,
unpause_displays (plugin);
}
static void
display_prompt (ply_boot_splash_plugin_t *plugin,
const char *prompt,
const char *entry_text,
bool is_secret)
{
pause_displays (plugin);
script_lib_plymouth_on_display_prompt (plugin->script_state,
plugin->script_plymouth_lib,
prompt,
entry_text,
is_secret);
unpause_displays (plugin);
}
static void
display_message (ply_boot_splash_plugin_t *plugin,
const char *message)
@ -552,6 +567,7 @@ ply_boot_splash_plugin_get_interface (void)
.display_normal = display_normal,
.display_password = display_password,
.display_question = display_question,
.display_prompt = display_prompt,
.display_message = display_message,
.hide_message = hide_message,
};

View file

@ -104,6 +104,7 @@ script_lib_plymouth_data_t *script_lib_plymouth_setup (script_state_t *st
data->script_display_normal_func = script_obj_new_null ();
data->script_display_password_func = script_obj_new_null ();
data->script_display_question_func = script_obj_new_null ();
data->script_display_prompt_func = script_obj_new_null ();
data->script_display_message_func = script_obj_new_null ();
data->script_hide_message_func = script_obj_new_null ();
data->script_quit_func = script_obj_new_null ();
@ -166,6 +167,12 @@ script_lib_plymouth_data_t *script_lib_plymouth_setup (script_state_t *st
&data->script_display_question_func,
"function",
NULL);
script_add_native_function (plymouth_hash,
"SetDisplayPromptFunction",
plymouth_set_function,
&data->script_display_prompt_func,
"function",
NULL);
script_add_native_function (plymouth_hash,
"SetDisplayMessageFunction",
plymouth_set_function,
@ -215,6 +222,7 @@ void script_lib_plymouth_destroy (script_lib_plymouth_data_t *data)
script_obj_unref (data->script_display_normal_func);
script_obj_unref (data->script_display_password_func);
script_obj_unref (data->script_display_question_func);
script_obj_unref (data->script_display_prompt_func);
script_obj_unref (data->script_display_message_func);
script_obj_unref (data->script_hide_message_func);
script_obj_unref (data->script_quit_func);
@ -342,6 +350,29 @@ void script_lib_plymouth_on_display_question (script_state_t *state,
script_obj_unref (ret.object);
}
void script_lib_plymouth_on_display_prompt (script_state_t *state,
script_lib_plymouth_data_t *data,
const char *prompt,
const char *entry_text,
bool is_secret)
{
script_obj_t *prompt_obj = script_obj_new_string (prompt);
script_obj_t *entry_text_obj = script_obj_new_string (entry_text);
script_obj_t *is_secret_obj = script_obj_new_number (is_secret);
script_return_t ret = script_execute_object (state,
data->script_display_prompt_func,
NULL,
prompt_obj,
entry_text_obj,
is_secret_obj,
NULL);
script_obj_unref (prompt_obj);
script_obj_unref (entry_text_obj);
script_obj_unref (is_secret_obj);
script_obj_unref (ret.object);
}
void script_lib_plymouth_on_display_message (script_state_t *state,
script_lib_plymouth_data_t *data,
const char *message)

View file

@ -36,6 +36,7 @@ typedef struct
script_obj_t *script_display_normal_func;
script_obj_t *script_display_password_func;
script_obj_t *script_display_question_func;
script_obj_t *script_display_prompt_func;
script_obj_t *script_display_message_func;
script_obj_t *script_hide_message_func;
script_obj_t *script_quit_func;
@ -73,6 +74,11 @@ void script_lib_plymouth_on_display_question (script_state_t *state,
script_lib_plymouth_data_t *data,
const char *prompt,
const char *entry_text);
void script_lib_plymouth_on_display_prompt (script_state_t *state,
script_lib_plymouth_data_t *data,
const char *prompt,
const char *entry_text,
bool is_secret);
void script_lib_plymouth_on_display_message (script_state_t *state,
script_lib_plymouth_data_t *data,
const char *new_message);

View file

@ -89,6 +89,15 @@ static script_return_t script_lib_string_sub_string (script_state_t *state,
return script_return_obj (substring_obj);
}
static script_return_t script_lib_string_length (script_state_t *state,
void *user_data)
{
char *text = script_obj_as_string (state->this);
size_t text_length = strlen(text);
free (text);
return script_return_obj (script_obj_new_number (text_length));
}
script_lib_string_data_t *script_lib_string_setup (script_state_t *state)
{
script_lib_string_data_t *data = malloc (sizeof(script_lib_string_data_t));
@ -108,6 +117,11 @@ script_lib_string_data_t *script_lib_string_setup (script_state_t *state)
"start",
"end",
NULL);
script_add_native_function (string_hash,
"Length",
script_lib_string_length,
NULL,
NULL);
script_obj_unref (string_hash);
data->script_main_op = script_parse_string (script_lib_string_string, "script-lib-string.script");
script_return_t ret = script_execute (state, data->script_main_op);