--- lbbs/src/bbs_net.c 2025/10/20 03:38:23 1.72 +++ lbbs/src/bbs_net.c 2025/11/05 04:19:21 1.80 @@ -1,18 +1,10 @@ -/*************************************************************************** - bbs_net.c - description - ------------------- - Copyright : (C) 2004-2025 by Leaflet - Email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * bbs_net + * - user interactive feature of site shuttle + * + * Copyright (C) 2004-2025 Leaflet + */ #include "bbs.h" #include "common.h" @@ -41,11 +33,14 @@ #include #include -#define MENU_CONF_DELIM " \t\r\n" +static const char MENU_CONF_DELIM[] = " \t\r\n"; -#define MAX_PROCESS_BAR_LEN 30 -#define MAXSTATION 26 * 2 -#define STATION_PER_LINE 4 +enum _bbs_net_constant_t +{ + MAX_PROCESS_BAR_LEN = 30, + MAXSTATION = 26 * 2, + STATION_PER_LINE = 4, +}; struct _bbsnet_conf { @@ -53,12 +48,12 @@ struct _bbsnet_conf char host2[40]; char ip[40]; in_port_t port; - char charset[20]; + char charset[CHARSET_MAX_LEN + 1]; } bbsnet_conf[MAXSTATION]; -MENU_SET bbsnet_menu; +static MENU_SET bbsnet_menu; -int load_bbsnet_conf(const char *file_config) +static int load_bbsnet_conf(const char *file_config) { FILE *fp; MENU *p_menu; @@ -153,7 +148,7 @@ int load_bbsnet_conf(const char *file_co return 0; } -void unload_bbsnet_conf(void) +static void unload_bbsnet_conf(void) { bbsnet_menu.menu_count = 0; bbsnet_menu.menu_item_count = 0; @@ -164,7 +159,7 @@ void unload_bbsnet_conf(void) bbsnet_menu.p_menu_item_pool = NULL; } -void process_bar(int n, int len) +static void process_bar(int n, int len) { char buf[LINE_BUFFER_LEN]; char buf2[LINE_BUFFER_LEN]; @@ -185,14 +180,14 @@ void process_bar(int n, int len) moveto(4, 0); prints(" ------------------------------ \r\n"); snprintf(buf, sizeof(buf), " %3d%% ", n * 100 / len); - strncpy(buf2, buf, (size_t)n); + memcpy(buf2, buf, (size_t)n); buf2[n] = '\0'; prints("|\033[46m%s\033[44m%s\033[m|\r\n", buf2, buf + n); prints(" ------------------------------ \r\n"); iflush(); } -int bbsnet_connect(int n) +static int bbsnet_connect(int n) { int sock, ret, loop, error; int sock_connected = 0; @@ -484,7 +479,7 @@ int bbsnet_connect(int n) } else if (nfds == 0) // timeout { - if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) + if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { break; } @@ -539,6 +534,7 @@ int bbsnet_connect(int n) // Send NO-OP to remote server input_buf[input_buf_len] = '\0'; input_buf_len++; + BBS_last_access_tm = time(NULL); stdin_read_wait = 0; break; // Check whether channel is still open @@ -806,8 +802,7 @@ cleanup: return 0; } -static int -bbsnet_refresh() +static int bbsnet_refresh() { clearscr(); moveto(1, 0); @@ -831,7 +826,7 @@ bbsnet_refresh() return 0; } -int bbsnet_selchange() +static int bbsnet_selchange() { int i = bbsnet_menu.menu_item_pos[0]; @@ -856,7 +851,7 @@ int bbsnet_selchange() return 0; } -int bbs_net() +extern int bbs_net() { int ch, i; @@ -882,7 +877,7 @@ int bbs_net() log_error("KEY_NULL\n"); goto cleanup; case KEY_TIMEOUT: - if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) + if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { log_error("User input timeout\n"); goto cleanup;