From f350330dcb6f4e05d233385fbb052e5743febfbb Mon Sep 17 00:00:00 2001 From: InterLinked1 <24227567+InterLinked1@users.noreply.github.com> Date: Sun, 28 Jan 2024 07:54:11 -0500 Subject: [PATCH] modules, nets: Inhibit library debug logging by default. Certain modules have had library debugging logging enabled by default since they were written. However, this is generally not necessary and clutters the debug logs. We no longer enable these when the module loads, though they can be enabled manually via CLI commands. Other minor bug fixes: * mod_sysop: Add visual line break when escaping from history. * net_ws: Increase readline buffer, to accomodate requests with lots of / large cookies. * net_imap: Abort remote LIST-STATUS on multiple errors. --- modules/mod_slack.c | 19 ++++++++++++++----- modules/mod_sysop.c | 3 +++ nets/net_imap/imap_client_status.c | 9 +++++++-- nets/net_ws.c | 9 +++++---- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/modules/mod_slack.c b/modules/mod_slack.c index fe59960..681e87f 100644 --- a/modules/mod_slack.c +++ b/modules/mod_slack.c @@ -1194,11 +1194,23 @@ static int cli_slack_members(struct bbs_cli_args *a) return 0; } +static int cli_slack_debug(struct bbs_cli_args *a) +{ + int level = atoi(a->argv[2]); + if (level < 0) { + level = 0; + } + slack_set_log_level(level); + bbs_dprintf(a->fdout, "Set libslackrtm debug level to %d\n", level); + return 0; +} + static struct bbs_cli_entry cli_commands_slack[] = { BBS_CLI_COMMAND(cli_slack_relays, "slack relays", 2, "List all Slack relays", NULL), BBS_CLI_COMMAND(cli_slack_channels, "slack chans", 2, "List Slack channels", "slack chans []"), BBS_CLI_COMMAND(cli_slack_users, "slack users", 2, "List Slack users", "slack users []"), BBS_CLI_COMMAND(cli_slack_members, "slack members", 2, "List a Slack channel's members", "slack members "), + BBS_CLI_COMMAND(cli_slack_debug, "slack debug", 3, "Set Slack library debug level", "slack debug "), }; struct slack_callbacks slack_callbacks = { @@ -1440,15 +1452,12 @@ static int load_config(void) return 0; } -#define DEBUG_SLACK - static int load_module(void) { /* Initialize the library */ slack_set_logger(slack_log); -#ifdef DEBUG_SLACK - slack_set_log_level(SLACK_LOG_DEBUG + 7); -#endif + + /* Don't enable debug logging by default, but CLI command can be used to enable, if desired */ if (load_config()) { return -1; diff --git a/modules/mod_sysop.c b/modules/mod_sysop.c index 5cc37ba..e080c0a 100644 --- a/modules/mod_sysop.c +++ b/modules/mod_sysop.c @@ -220,6 +220,7 @@ static void print_time(int fdout) static inline void load_hist_command(struct sysop_console *console, const char **s) { + my_set_stdout_logging(console->fdout, 0); /* Disable logging so other stuff isn't trying to write to STDOUT at the same time. */ bbs_dprintf(console->fdout, TERM_RESET_LINE "\r/%s", *s); } @@ -415,6 +416,8 @@ static void *sysop_handler(void *varg) case KEY_ESC: bbs_history_reset(); histentry = NULL; + my_set_stdout_logging(sysopfdout, console->log); /* If running in foreground, re-enable STDOUT logging */ + bbs_dprintf(sysopfdout, "\n"); /* Print new line since we had history on the line */ break; case KEY_BACKSPACE: goto backsp; diff --git a/nets/net_imap/imap_client_status.c b/nets/net_imap/imap_client_status.c index 5616828..1a435f0 100644 --- a/nets/net_imap/imap_client_status.c +++ b/nets/net_imap/imap_client_status.c @@ -432,6 +432,7 @@ static int cache_remote_list_status(struct imap_client *client, const char *rtag ssize_t res; struct dyn_str dynstr; int i; + int unexpected = 0; struct bbs_tcp_client *tcpclient = &client->client; char *buf = tcpclient->rldata.buf; @@ -440,7 +441,7 @@ static int cache_remote_list_status(struct imap_client *client, const char *rtag client->virtlisttime = time(NULL); - for (i = 0; ; i++) { + for (i = 0; unexpected < 3; i++) { res = bbs_readline(tcpclient->rfd, &tcpclient->rldata, "\r\n", 10000); if (res <= 0) { bbs_warning("IMAP timeout (res: %ld) from LIST-STATUS - remote server issue?\n", res); @@ -456,6 +457,7 @@ static int cache_remote_list_status(struct imap_client *client, const char *rtag continue; } else if (!STARTS_WITH(buf, "* STATUS")) { bbs_warning("Unexpected LIST-STATUS response: %s\n", buf); + unexpected++; continue; } if (i) { @@ -551,7 +553,10 @@ ssize_t remote_status(struct imap_client *client, const char *remotename, const buf = client->buf; if (!client->virtlist && client->virtcapabilities & IMAP_CAPABILITY_LIST_STATUS) { /* Try LIST-STATUS if it's the first mailbox */ imap_client_send(client, "A.%s.1 LIST \"\" \"*\" RETURN (STATUS (%s%s%s%s))\r\n", tag, items, add1, add2, add3); - cache_remote_list_status(client, rtag, taglen); + if (cache_remote_list_status(client, rtag, taglen)) { + bbs_error("Remote IMAP command failed: A.%s.1 LIST \"\" \"*\" RETURN (STATUS (%s%s%s%s))\r\n", tag, items, add1, add2, add3); + return -1; + } } if (client->virtlist) { if (!remote_status_cached(client, remotename, remote_status_resp, sizeof(remote_status_resp))) { diff --git a/nets/net_ws.c b/nets/net_ws.c index 2852626..da7d706 100644 --- a/nets/net_ws.c +++ b/nets/net_ws.c @@ -926,7 +926,7 @@ static void ws_handler(struct bbs_node *node, struct http_session *http, int rfd elapsed_sec = this_poll_start - lastping; max_ms = (int) (max_websocket_timeout_ms - SEC_MS(elapsed_sec)); #ifdef DEBUG_POLL - bbs_debug(10, "ws.pollms: %d, %d s / %d ms have elapsed since last ping, %d ms is max allowed\n", ws.pollms, elapsed_sec, app_ms_elapsed, max_ms); + bbs_debug(10, "ws.pollms: %d, %d s / %ld ms have elapsed since last ping, %d ms is max allowed\n", ws.pollms, elapsed_sec, app_ms_elapsed, max_ms); #endif if (ws.pollms >= 0) { pollms = ws.pollms - app_ms_elapsed; @@ -965,6 +965,7 @@ static void ws_handler(struct bbs_node *node, struct http_session *http, int rfd res = wss_read(client, SEC_MS(55), 1); /* Pass in 1 since we already know poll returned activity for this fd */ if (res < 0) { bbs_debug(3, "Failed to read WebSocket frame\n"); + bbs_debug(7, "ws.pollms: %d, %ld s / %d ms have elapsed since last ping, %d ms is max allowed\n", ws.pollms, elapsed_sec, app_ms_elapsed, max_ms); if (wss_error_code(client)) { wss_close(client, wss_error_code(client)); } /* else, if client already closed, don't try writing any further */ @@ -1104,7 +1105,7 @@ static void ws_direct_handler(struct bbs_node *node, int secure) int res; /* needed for HTTP structure */ - char buf[1024]; + char buf[2048]; /* Accomodate cookies for other domains being sent, which could result in a huge Cookie header */ struct readline_data rldata; struct http_session http; @@ -1270,11 +1271,11 @@ static int load_module(void) return -1; } wss_set_logger(ws_log); - wss_set_log_level(WS_LOG_DEBUG + 5); - /* Register reverse proxy routes if needed */ + /* Don't enable debug logging by default, but CLI command can be used to do so, if desired */ bbs_register_tests(tests); + /* Register reverse proxy routes if needed */ /* XXX Need to register all routes? */ if (http_get_default_http_port() != -1) { res |= http_register_insecure_route(NULL, (unsigned short int) http_get_default_http_port(), "/ws", HTTP_METHOD_GET, ws_proxy_handler);