AmendHub

Download:

jcs

/

subtext

/

amendments

/

218

*: Add session signoff view, remove session_output_template

All remaining uses of session_output_template can use session_printf
which still does {{B}} and {{/B}} parsing.
 
Change session_output_view to session_output_view_or_printf to make it
easier to print a view and fallback to a string, rather than having to
check the result of session_output_view everywhere.

jcs made amendment 218 over 2 years ago
--- board.c Sun Jul 17 00:19:07 2022 +++ board.c Tue Jul 19 15:35:47 2022 @@ -407,7 +407,7 @@ post_compose_start: thread->subject = xstrdup(initial_subject); for (;;) { - session_output_template(s, "{{B}}Subject:{{/B}} "); + session_printf(s, "{{B}}Subject:{{/B}} "); session_flush(s); tmp = session_field_input(s, 100, 50, thread->subject, @@ -424,7 +424,7 @@ post_compose_start: rtrim(thread->subject, "\r\n\t "); if (thread->subject[0] == '\0') { - session_output_template(s, "{{B}}Error:{{/B}} Subject " + session_printf(s, "{{B}}Error:{{/B}} Subject " "cannot be blank (^C to cancel)\r\n"); session_flush(s); free(thread->subject); @@ -436,8 +436,7 @@ post_compose_start: } for (;;) { - session_output_template(s, - "{{B}}Message (^D when finished):{{/B}}\r\n"); + session_printf(s, "{{B}}Message (^D when finished):{{/B}}\r\n"); session_flush(s); tmp = session_field_input(s, 2048, s->terminal_columns - 1, @@ -462,7 +461,7 @@ post_compose_start: } for (;;) { - session_output_template(s, "\r\n{{B}}(P){{/B}}ost message, " + session_printf(s, "\r\n{{B}}(P){{/B}}ost message, " "{{B}}(E){{/B}}dit again, or {{B}}(C){{/B}}ancel? "); session_flush(s); --- db.h Sat Jul 16 23:12:38 2022 +++ db.h Tue Jul 19 15:20:39 2022 @@ -42,6 +42,7 @@ #define DB_TEXT_SIGNUP_ID 4 #define DB_TEXT_PAGE_SYSOP_ID 5 #define DB_TEXT_NO_FREE_NODES_ID 6 +#define DB_TEXT_SIGNOFF_ID 7 #define DB_USERNAME_LENGTH 16 --- folder.c Sun Jul 17 00:59:00 2022 +++ folder.c Tue Jul 19 15:36:09 2022 @@ -526,7 +526,7 @@ file_upload_annotate: rtrim(file.description, "\r\n\t "); if (file.description[0] == '\0') { - session_output_template(s, "{{B}}Error:{{/B}} File " + session_printf(s, "{{B}}Error:{{/B}} File " "description cannot be blank (^C to cancel)\r\n"); session_flush(s); continue; @@ -565,7 +565,7 @@ file_upload_annotate: } for (;;) { - session_output_template(s, "\r\n{{B}}(S){{/B}}ave file, " + session_printf(s, "\r\n{{B}}(S){{/B}}ave file, " "{{B}}(E){{/B}}dit again, or {{B}}(C){{/B}}ancel? "); session_flush(s); --- mail.c Sun Jul 17 20:01:17 2022 +++ mail.c Tue Jul 19 15:36:51 2022 @@ -255,13 +255,13 @@ mail_compose(struct session *s, char *initial_to, char if (initial_body) msg.body = xstrdup(initial_body); - session_output_template(s, "{{B}}Compose New Private Mail{{/B}}\r\n"); + session_printf(s, "{{B}}Compose New Private Mail{{/B}}\r\n"); session_printf(s, "{{B}}From: {{/B}} %s\r\n", s->user->username); session_flush(s); mail_compose_start: for (;;) { - session_output_template(s, "{{B}}To: {{/B}} "); + session_printf(s, "{{B}}To: {{/B}} "); session_flush(s); tmp = session_field_input(s, DB_USERNAME_LENGTH + 1, @@ -289,7 +289,7 @@ mail_compose_start: } for (;;) { - session_output_template(s, "{{B}}Subject:{{/B}} "); + session_printf(s, "{{B}}Subject:{{/B}} "); session_flush(s); tmp = session_field_input(s, 50, 50, msg.subject, false, 0); @@ -305,7 +305,7 @@ mail_compose_start: rtrim(msg.subject, "\r\n\t "); if (msg.subject[0] == '\0') { - session_output_template(s, "{{B}}Error:{{/B}} Subject cannot " + session_printf(s, "{{B}}Error:{{/B}} Subject cannot " "be blank (^C to cancel)\r\n"); session_flush(s); free(msg.subject); @@ -317,7 +317,7 @@ mail_compose_start: } for (;;) { - session_output_template(s, + session_printf(s, "{{B}}Message (^D when finished):{{/B}}\r\n"); session_flush(s); @@ -335,7 +335,7 @@ mail_compose_start: rtrim(msg.body, "\r\n\t "); if (msg.body[0] == '\0') { - session_output_template(s, "{{B}}Error:{{/B}} Message cannot " + session_printf(s, "{{B}}Error:{{/B}} Message cannot " "be blank (^C to cancel)\r\n"); session_flush(s); free(msg.body); @@ -347,7 +347,7 @@ mail_compose_start: } for (;;) { - session_output_template(s, "\r\n{{B}}(S){{/B}}end message, " + session_printf(s, "\r\n{{B}}(S){{/B}}end message, " "{{B}}(E){{/B}}dit again, or {{B}}(C){{/B}}ancel? "); session_flush(s); --- main.c Sat Jul 16 23:35:49 2022 +++ main.c Tue Jul 19 15:21:55 2022 @@ -331,6 +331,9 @@ handle_menu(long menu_id) case VIEWS_SUBMENU_NO_FREE_NODES_ID: view_editor_show(DB_TEXT_NO_FREE_NODES_ID, "Edit: No Free Nodes view"); break; + case VIEWS_SUBMENU_SIGNOFF_ID: + view_editor_show(DB_TEXT_SIGNOFF_ID, "Edit: Session Signoff view"); + break; } ret = 1; break; @@ -363,7 +366,7 @@ blanker_idle(void) } if (blanker_on && (nsessions || - (Time - blanker_last_blank > db->config.blanker_runtime_seconds))) + (Time - blanker_last_blank >= db->config.blanker_runtime_seconds))) blanker_unblank(); } --- session.c Sat Jul 16 22:59:31 2022 +++ session.c Tue Jul 19 16:09:43 2022 @@ -43,6 +43,8 @@ struct session_tally session_today_tally = { 0 }; void session_run(struct uthread *uthread, void *arg); short session_login(struct session *s); +size_t session_vprintf(struct session *session, const char *format, + va_list ap); size_t session_expand_var(struct session *session, char *ivar, char **ret, bool *end_expansion); void session_page_sysop(struct session *s); @@ -125,14 +127,17 @@ session_run(struct uthread *uthread, void *arg) s->terminal_lines = DEFAULT_TERMINAL_LINES; snprintf(s->terminal_type, sizeof(s->terminal_type), "vt100"); - if (s->node_funcs->setup) + if (s->node_funcs->setup) { s->node_funcs->setup(s); - if (!session_output_view(s, DB_TEXT_ISSUE_ID)) { - session_printf(s, "\r\n" - "Welcome to %s (%s)\r\n" - "\r\n", db->config.name, s->node); + if (s->ending) { + session_close(s); + return; + } } + + session_output_view_or_printf(s, DB_TEXT_ISSUE_ID, + "\r\nWelcome to %s (%s)\r\n\r\n", db->config.name, s->node); session_flush(s); auth = session_login(s); @@ -141,7 +146,7 @@ session_run(struct uthread *uthread, void *arg) return; } - s->logged_in = 1; + s->logged_in = true; logger_update_title(); /* update session log */ @@ -183,8 +188,8 @@ session_run(struct uthread *uthread, void *arg) session_flush(s); main_menu: - if (!session_output_view(s, DB_TEXT_MENU_ID)) - session_printf(s, "\r\n[ Menu missing! ]\r\n\r\n"); + session_output_view_or_printf(s, DB_TEXT_MENU_ID, + "\r\n[ Menu missing! ]\r\n\r\n"); session_flush(s); while (!done && !s->ending) { @@ -221,7 +226,8 @@ get_another_char: case 'g': case 'G': /* goodbye */ - session_printf(s, "Goodbye!\r\n"); + session_output_view_or_printf(s, DB_TEXT_SIGNOFF_ID, + "Goodbye!\r\n"); session_flush(s); done = true; break; @@ -278,14 +284,13 @@ get_another_char: case '?': if (last_c == '?') { /* asking twice in a row will print the full menu */ - if (!session_output_view(s, DB_TEXT_MENU_ID)) - session_printf(s, "\r\n[ Menu missing! ]\r\n\r\n"); + session_output_view_or_printf(s, DB_TEXT_MENU_ID, + "\r\n[ Menu missing! ]\r\n\r\n"); } else { - if (!session_output_view(s, DB_TEXT_SHORTMENU_ID)) { - if (!session_output_view(s, DB_TEXT_MENU_ID)) - session_printf(s, "\r\n[ Short and long menu " - "missing! ]\r\n\r\n"); - } + if (session_output_view_or_printf(s, DB_TEXT_SHORTMENU_ID, + NULL) == 0) + session_output_view_or_printf(s, DB_TEXT_MENU_ID, + "\r\n[ Short and long menu missing! ]\r\n\r\n"); } session_flush(s); break; @@ -416,8 +421,20 @@ session_output(struct session *session, const char *st size_t session_printf(struct session *session, const char *format, ...) { - static char session_printf_ebuf[160], session_printf_tbuf[160]; va_list ap; + size_t len; + + va_start(ap, format); + len = session_vprintf(session, format, ap); + va_end(ap); + + return len; +} + +size_t +session_vprintf(struct session *session, const char *format, va_list ap) +{ + static char session_printf_ebuf[160], session_printf_tbuf[160]; size_t len, n, en; bool stop = false; @@ -458,10 +475,8 @@ session_printf(struct session *session, const char *fo session_printf_ebuf[en] = '\0'; } - va_start(ap, format); len = vsnprintf(session_printf_tbuf, sizeof(session_printf_tbuf), session_printf_ebuf, ap); - va_end(ap); if (len > sizeof(session_printf_tbuf)) panic("session_printf overflow! (%ld > %ld)", len, @@ -471,40 +486,44 @@ session_printf(struct session *session, const char *fo } size_t -session_output_view(struct session *session, short id) +session_output_view_or_printf(struct session *session, short id, + const char *format, ...) { size_t size; struct bile_object *o; - char *view; + char *view, *output; + va_list ap; /* can't use bile_read_alloc because we need to null terminate */ o = bile_find(db->bile, DB_TEXT_TYPE, id); - if (o == NULL) - return 0; + if (o == NULL || o->size == 0) { + if (o) + free(0); + + if (format == NULL) + return 0; + + va_start(ap, format); + size = session_vprintf(session, format, ap); + va_end(ap); + return size; + } + view = xmalloc(o->size + 1); size = bile_read_object(db->bile, o, view, o->size); + view[size] = '\0'; free(o); - view[size] = '\0'; - size = session_output_template(session, view); - free(view); - - return size; -} - -size_t -session_output_template(struct session *session, const char *str) -{ - size_t size; - char *output; - - size = session_expand_template(session, str, &output); - if (!size) + size = session_expand_template(session, view, &output); + if (!size) { + free(view); return 0; - + } + size = session_output(session, output, size); free(output); + free(view); return size; } @@ -1191,13 +1210,14 @@ session_page_sysop(struct session *s) { char *message = NULL; - session_output_template(s, "{{B}}Page Sysop{{/B}} " + session_printf(s, "{{B}}Page Sysop{{/B}} " "(^C to cancel)\r\n" "{{B}}-------------------------{{/B}}\r\n"); - session_output_view(s, DB_TEXT_PAGE_SYSOP_ID); + session_output_view_or_printf(s, DB_TEXT_PAGE_SYSOP_ID, + "(Instructions missing)\r\n"); session_flush(s); - session_output_template(s, "{{B}}Message:{{/B}} "); + session_printf(s, "{{B}}Message:{{/B}} "); session_flush(s); message = session_field_input(s, 64, 64, NULL, false, 0); session_output(s, "\r\n", 2); @@ -1210,7 +1230,7 @@ session_page_sysop(struct session *s) /* TODO: enter chat with sysop */ - session_output_template(s, "{{B}}TODO!{{/B}}\r\n"); + session_printf(s, "{{B}}TODO!{{/B}}\r\n"); session_flush(s); page_done: @@ -1233,8 +1253,8 @@ session_recents(struct session *s) char sdate[12]; short printed; - session_output_template(s, "{{B}}Recent Logins{{/B}}\r\n"); - session_output_template(s, + session_printf(s, "{{B}}Recent Logins{{/B}}\r\n"); + session_printf(s, "{{B}}Date Node User Via Speed{{/B}}\r\n"); session_flush(s); @@ -1274,8 +1294,8 @@ session_who(struct session *s) unsigned long idle; short n; - session_output_template(s, "{{B}}Who's Online{{/B}}\r\n"); - session_output_template(s, + session_printf(s, "{{B}}Who's Online{{/B}}\r\n"); + session_printf(s, "{{B}}Node User Via Speed Idle{{/B}}\r\n"); session_flush(s); --- session.h Sat Jul 16 21:42:56 2022 +++ session.h Tue Jul 19 15:29:07 2022 @@ -132,7 +132,8 @@ void session_flush(struct session *session); size_t session_log(struct session *session, const char *format, ...); size_t session_output(struct session *session, const char *str, size_t len); size_t session_printf(struct session *session, const char *format, ...); -size_t session_output_view(struct session *session, short id); +size_t session_output_view_or_printf(struct session *session, short id, + const char *format, ...); size_t session_output_template(struct session *session, const char *str); size_t session_expand_template(struct session *session, const char *str, char **ret); --- settings.c Fri Jun 24 09:48:13 2022 +++ settings.c Tue Jul 19 15:37:11 2022 @@ -152,8 +152,7 @@ get_menu_option: } if (!found) { - session_output_template(s, - "Invalid option ({{B}}?{{/B}} for help)\r\n"); + session_printf(s, "Invalid option ({{B}}?{{/B}} for help)\r\n"); session_flush(s); continue; } --- signup.c Mon Jul 11 15:26:49 2022 +++ signup.c Tue Jul 19 15:54:17 2022 @@ -34,10 +34,11 @@ signup(struct session *s) session_log(s, "Signing up for an account"); - session_output_template(s, "{{B}}Create Account{{/B}} " + session_printf(s, "{{B}}Create Account{{/B}} " "(^C to cancel)\r\n" "{{B}}----------------------------{{/B}}\r\n"); - session_output_view(s, DB_TEXT_SIGNUP_ID); + session_output_view_or_printf(s, DB_TEXT_SIGNUP_ID, + "[ Signup instructions missing ]"); session_flush(s); for (;;) { @@ -63,7 +64,7 @@ signup(struct session *s) } for (;;) { - session_output_template(s, "{{B}}Password:{{/B}} "); + session_printf(s, "{{B}}Password:{{/B}} "); session_flush(s); password = session_field_input(s, 64, 64, NULL, false, '*'); session_output(s, "\r\n", 2); @@ -79,7 +80,7 @@ signup(struct session *s) continue; } - session_output_template(s, "{{B}}Password (again):{{/B}} "); + session_printf(s, "{{B}}Password (again):{{/B}} "); session_flush(s); password_confirm = session_field_input(s, 64, 64, NULL, false, '*'); --- subtext.π.r Tue Jun 7 21:47:55 2022 +++ subtext.π.r Tue Jul 19 16:22:19 2022 @@ -30,7 +30,10 @@ data 'MENU' (132) { $"686F 7274 204D 656E 752E 2E2E 0000 0000" /* hort Menu....... */ $"1141 6363 6F75 6E74 2053 6967 6E75 702E" /* .Account Signup. */ $"2E2E 0000 0000 0D50 6167 6520 5379 736F" /* ......¬Page Syso */ - $"702E 2E2E 0000 0000 00" /* p........ */ + $"702E 2E2E 0000 0000 104E 6F20 4672 6565" /* p........No Free */ + $"204E 6F64 6573 2E2E 2E00 0000 0012 5365" /* Nodes........Se */ + $"7373 696F 6E20 5369 676E 6F66 662E 2E2E" /* ssion Signoff... */ + $"0000 0000 00" /* ..... */ }; data 'MBAR' (128) { --- subtext.h Sat Jul 16 23:35:31 2022 +++ subtext.h Tue Jul 19 15:21:32 2022 @@ -45,6 +45,7 @@ #define VIEWS_SUBMENU_SIGNUP_ID 4 #define VIEWS_SUBMENU_PAGE_SYSOP_ID 5 #define VIEWS_SUBMENU_NO_FREE_NODES_ID 6 +#define VIEWS_SUBMENU_SIGNOFF_ID 7 #define STR_LAST_DB 128 --- user.c Thu Jun 30 11:06:41 2022 +++ user.c Tue Jul 19 15:38:19 2022 @@ -311,13 +311,13 @@ user_change_password(struct session *s, struct user *u char *password = NULL, *password_confirm = NULL; if (!user) { - session_output_template(s, "{{B}}Error{{/B}}: Guest accounts " + session_printf(s, "{{B}}Error{{/B}}: Guest accounts " "cannot change passwords\r\n"); return; } while (!s->ending) { - session_output_template(s, "{{B}}New Password:{{/B}} "); + session_printf(s, "{{B}}New Password:{{/B}} "); session_flush(s); password = session_field_input(s, 64, 64, NULL, false, '*'); session_output(s, "\r\n", 2); @@ -327,14 +327,14 @@ user_change_password(struct session *s, struct user *u break; if (password[0] == '\0') { - session_output_template(s, "{{B}}Error:{{/B}} " + session_printf(s, "{{B}}Error:{{/B}} " "Password cannot be blank\r\n"); free(password); password = NULL; continue; } - session_output_template(s, "{{B}}New Password (again):{{/B}} "); + session_printf(s, "{{B}}New Password (again):{{/B}} "); session_flush(s); password_confirm = session_field_input(s, 64, 64, NULL, false, '*'); session_output(s, "\r\n", 2); @@ -344,7 +344,7 @@ user_change_password(struct session *s, struct user *u break; if (strcmp(password_confirm, password) != 0) { - session_output_template(s, "{{B}}Error:{{/B}} " + session_printf(s, "{{B}}Error:{{/B}} " "Passwords do not match\r\n"); free(password); password = NULL; @@ -358,12 +358,12 @@ user_change_password(struct session *s, struct user *u if (strcmp(s->user->username, user->username) == 0) { session_log(s, "User changed password"); - session_output_template(s, "{{B}}Your password has been " + session_printf(s, "{{B}}Your password has been " "changed{{/B}}\r\n"); } else { session_log(s, "User %s changed password for %s", s->user->username, user->username); - session_output_template(s, "{{B}}Password has been " + session_printf(s, "{{B}}Password has been " "changed{{/B}}\r\n"); } --- user_settings.c Tue Jul 12 09:47:11 2022 +++ user_settings.c Tue Jul 19 15:38:50 2022 @@ -37,7 +37,7 @@ user_settings_renegotiate(struct session *s) short cols, lines; char *tsize; - session_output_template(s, + session_printf(s, "Does this terminal support VT100 escape sequences? [Y/n] "); session_flush(s); @@ -58,7 +58,7 @@ try_again: } if (!s->vt100) { - session_output_template(s, + session_printf(s, "Does this terminal support VT52 escape sequences? [Y/n] "); session_flush(s); @@ -125,13 +125,13 @@ user_settings_username(struct session *s) char *username = NULL, *error = NULL; if (!s->user) { - session_output_template(s, "{{B}}Error{{/B}}: Guest accounts " + session_printf(s, "{{B}}Error{{/B}}: Guest accounts " "cannot change username\r\n"); return; } while (!s->ending) { - session_output_template(s, "{{B}}Username:{{/B}} "); + session_printf(s, "{{B}}Username:{{/B}} "); session_flush(s); username = session_field_input(s, DB_USERNAME_LENGTH, DB_USERNAME_LENGTH, s->user->username, false, 0); @@ -142,7 +142,7 @@ user_settings_username(struct session *s) break; if (username[0] == '\0') { - session_output_template(s, "{{B}}Error:{{/B}} " + session_printf(s, "{{B}}Error:{{/B}} " "Username cannot be blank\r\n"); free(username); username = NULL;