aboutsummaryrefslogtreecommitdiff
path: root/src/hci/tui/login_ui.c
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2024-04-15 15:59:49 +0100
committerMichael Brown <mcb30@ipxe.org>2024-04-15 15:59:49 +0100
commit40b51124400df9cb0c57512ff93ac21827d5bac0 (patch)
treefefb7a187eda31347f14f7317b29ed6427a271e2 /src/hci/tui/login_ui.c
parent27ecc36c0bef804d12dbf8c29684c8e8159c8e47 (diff)
downloadipxe-40b51124400df9cb0c57512ff93ac21827d5bac0.zip
ipxe-40b51124400df9cb0c57512ff93ac21827d5bac0.tar.gz
ipxe-40b51124400df9cb0c57512ff93ac21827d5bac0.tar.bz2
[hci] Use dynamically allocated buffers for editable strings
Editable strings currently require a fixed-size buffer, which is inelegant and limits the potential for creating interactive forms with a variable number of edit box widgets. Remove this limitation by switching to using a dynamically allocated buffer for editable strings and edit box widgets. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/hci/tui/login_ui.c')
-rw-r--r--src/hci/tui/login_ui.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/hci/tui/login_ui.c b/src/hci/tui/login_ui.c
index 3c55325..bd24991 100644
--- a/src/hci/tui/login_ui.c
+++ b/src/hci/tui/login_ui.c
@@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*/
#include <string.h>
+#include <stdlib.h>
#include <errno.h>
#include <curses.h>
#include <ipxe/console.h>
@@ -49,8 +50,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define EDITBOX_WIDTH 20U
int login_ui ( void ) {
- char username[64];
- char password[64];
+ char *username;
+ char *password;
struct edit_box username_box;
struct edit_box password_box;
struct edit_box *current_box = &username_box;
@@ -58,19 +59,16 @@ int login_ui ( void ) {
int rc = -EINPROGRESS;
/* Fetch current setting values */
- fetch_string_setting ( NULL, &username_setting, username,
- sizeof ( username ) );
- fetch_string_setting ( NULL, &password_setting, password,
- sizeof ( password ) );
+ fetchf_setting_copy ( NULL, &username_setting, NULL, NULL, &username );
+ fetchf_setting_copy ( NULL, &password_setting, NULL, NULL, &password );
/* Initialise UI */
initscr();
start_color();
- init_editbox ( &username_box, username, sizeof ( username ), NULL,
- USERNAME_ROW, EDITBOX_COL, EDITBOX_WIDTH, 0 );
- init_editbox ( &password_box, password, sizeof ( password ), NULL,
- PASSWORD_ROW, EDITBOX_COL, EDITBOX_WIDTH,
- EDITBOX_STARS );
+ init_editbox ( &username_box, &username, NULL, USERNAME_ROW,
+ EDITBOX_COL, EDITBOX_WIDTH, 0 );
+ init_editbox ( &password_box, &password, NULL, PASSWORD_ROW,
+ EDITBOX_COL, EDITBOX_WIDTH, EDITBOX_STARS );
/* Draw initial UI */
color_set ( CPAIR_NORMAL, NULL );
@@ -122,16 +120,15 @@ int login_ui ( void ) {
erase();
endwin();
- if ( rc != 0 )
- return rc;
+ /* Store settings on successful completion */
+ if ( rc == 0 )
+ rc = storef_setting ( NULL, &username_setting, username );
+ if ( rc == 0 )
+ rc = storef_setting ( NULL, &password_setting, password );
- /* Store settings */
- if ( ( rc = store_setting ( NULL, &username_setting, username,
- strlen ( username ) ) ) != 0 )
- return rc;
- if ( ( rc = store_setting ( NULL, &password_setting, password,
- strlen ( password ) ) ) != 0 )
- return rc;
+ /* Free setting values */
+ free ( username );
+ free ( password );
- return 0;
+ return rc;
}