AmendHub

Download:

jcs

/

subtext

/

amendments

/

325

struct_editor: Add support for password fields

In session_field_input, if we have a mask character, print the
initial string with it

jcs made amendment 325 about 1 year ago
--- session.c Thu Feb 23 14:49:12 2023 +++ session.c Tue Feb 28 09:27:22 2023 @@ -843,7 +843,11 @@ session_field_input(struct session *session, unsigned if (initial_input) { ipos = ilen = strlcpy(field, initial_input, size); /* TODO: handle initial value being longer than width */ - session_output(session, field, ilen); + if (mask) { + for (n = 0; n < ilen; n++) + session_output(session, &mask, 1); + } else + session_output(session, field, ilen); session_flush(session); } --- settings.c Sun Feb 5 10:43:38 2023 +++ settings.c Tue Feb 28 09:22:22 2023 @@ -51,7 +51,7 @@ struct_editor(struct session *s, const struct struct_f long lval; char co, initial[20]; char *input = NULL, *new_data; - short n, sval; + short n, i, sval; bool found, any_changes = false; unsigned short c; @@ -76,6 +76,13 @@ print_options: case CONFIG_TYPE_STRING: session_printf(s, "%s", new_data + sf->off); break; + case CONFIG_TYPE_PASSWORD: + i = strlen(new_data + sf->off); + while (i) { + session_output(s, "*", 1); + i--; + } + break; case CONFIG_TYPE_SHORT: sval = CHARS_TO_SHORT(new_data[sf->off], new_data[sf->off + 1]); session_printf(s, "%d", sval); @@ -163,8 +170,9 @@ get_input: switch (sf->type) { case CONFIG_TYPE_STRING: + case CONFIG_TYPE_PASSWORD: input = session_field_input(s, sf->max, 50, new_data + sf->off, - false, 0); + false, (sf->type == CONFIG_TYPE_PASSWORD ? '*' : 0)); session_output(s, "\r\n", 2); session_flush(s); if (input == NULL || s->ending) --- settings.h Sun Feb 5 10:44:01 2023 +++ settings.h Tue Feb 28 08:50:37 2023 @@ -24,7 +24,8 @@ enum { CONFIG_TYPE_SHORT, CONFIG_TYPE_LONG, CONFIG_TYPE_BOOLEAN, - CONFIG_TYPE_IP + CONFIG_TYPE_IP, + CONFIG_TYPE_PASSWORD }; struct struct_field {