--- lbbs/src/bbs_net.c 2025/10/19 09:09:17 1.68 +++ lbbs/src/bbs_net.c 2025/11/04 13:49:51 1.76 @@ -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 by Leaflet + */ #include "bbs.h" #include "common.h" @@ -56,9 +48,9 @@ struct _bbsnet_conf char charset[20]; } 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 +145,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 +156,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 +177,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; @@ -424,7 +416,8 @@ int bbsnet_connect(int n) log_common("BBSNET connect to %s:%d from %s:%d by [%s]\n", remote_addr, remote_port, local_addr, local_port, BBS_username); - snprintf(tocode, sizeof(tocode), "%s//TRANSLIT", bbsnet_conf[n].charset); + snprintf(tocode, sizeof(tocode), "%s%s", bbsnet_conf[n].charset, + (strcasecmp(stdio_charset, bbsnet_conf[n].charset) == 0 ? "" : "//IGNORE")); input_cd = iconv_open(tocode, stdio_charset); if (input_cd == (iconv_t)(-1)) { @@ -432,8 +425,9 @@ int bbsnet_connect(int n) goto cleanup; } - snprintf(tocode, sizeof(tocode), "%s//TRANSLIT", stdio_charset); - output_cd = iconv_open(stdio_charset, bbsnet_conf[n].charset); + snprintf(tocode, sizeof(tocode), "%s%s", stdio_charset, + (strcasecmp(bbsnet_conf[n].charset, stdio_charset) == 0 ? "" : "//TRANSLIT")); + output_cd = iconv_open(tocode, bbsnet_conf[n].charset); if (output_cd == (iconv_t)(-1)) { log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, tocode, errno); @@ -534,6 +528,11 @@ int bbsnet_connect(int n) } else if (ret == 0) { + // 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 } @@ -589,11 +588,28 @@ int bbsnet_connect(int n) { if (input_buf_offset < input_buf_len) { + // For debug +#ifdef _DEBUG + for (int j = input_buf_offset; j < input_buf_len; j++) + { + log_error("Debug input: <--[%u]\n", (input_buf[j] + 256) % 256); + } +#endif + ret = io_buf_conv(input_cd, input_buf, &input_buf_len, &input_buf_offset, input_conv, sizeof(input_conv), &input_conv_len); if (ret < 0) { log_error("io_buf_conv(input, %d, %d, %d) error\n", input_buf_len, input_buf_offset, input_conv_len); + input_buf_len = input_buf_offset; // Discard invalid sequence + } + + // For debug +#ifdef _DEBUG + for (int j = input_conv_offset; j < input_conv_len; j++) + { + log_error("Debug input_conv: <--[%u]\n", (input_conv[j] + 256) % 256); } +#endif } while (input_conv_offset < input_conv_len && !SYS_server_exit) @@ -688,6 +704,7 @@ int bbsnet_connect(int n) if (ret < 0) { log_error("io_buf_conv(output, %d, %d, %d) error\n", output_buf_len, output_buf_offset, output_conv_len); + output_buf_len = output_buf_offset; // Discard invalid sequence } } @@ -777,11 +794,12 @@ cleanup: tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, tm_used->tm_sec); + BBS_last_access_tm = time(NULL); + return 0; } -static int -bbsnet_refresh() +static int bbsnet_refresh() { clearscr(); moveto(1, 0); @@ -805,7 +823,7 @@ bbsnet_refresh() return 0; } -int bbsnet_selchange() +static int bbsnet_selchange() { int i = bbsnet_menu.menu_item_pos[0]; @@ -830,7 +848,7 @@ int bbsnet_selchange() return 0; } -int bbs_net() +extern int bbs_net() { int ch, i; @@ -845,10 +863,10 @@ int bbs_net() { ch = igetch(100); - if (ch != KEY_NULL && ch != KEY_TIMEOUT) - { - BBS_last_access_tm = time(NULL); - } + if (ch != KEY_NULL && ch != KEY_TIMEOUT) + { + BBS_last_access_tm = time(NULL); + } switch (ch) {