Skip to content

Commit

Permalink
modules, nets: Inhibit library debug logging by default.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
InterLinked1 committed Jan 28, 2024
1 parent 11357b0 commit f350330
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
19 changes: 14 additions & 5 deletions modules/mod_slack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<relay>]"),
BBS_CLI_COMMAND(cli_slack_users, "slack users", 2, "List Slack users", "slack users [<relay>]"),
BBS_CLI_COMMAND(cli_slack_members, "slack members", 2, "List a Slack channel's members", "slack members <channel>"),
BBS_CLI_COMMAND(cli_slack_debug, "slack debug", 3, "Set Slack library debug level", "slack debug <level>"),
};

struct slack_callbacks slack_callbacks = {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions modules/mod_sysop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions nets/net_imap/imap_client_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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))) {
Expand Down
9 changes: 5 additions & 4 deletions nets/net_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f350330

Please sign in to comment.