| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
bbs_net.c - description |
/* |
| 3 |
------------------- |
* bbs_net |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - user interactive feature of site shuttle |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 by Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
|
/*************************************************************************** |
|
|
* * |
|
|
* 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. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 8 |
|
|
| 9 |
#include "bbs.h" |
#include "bbs.h" |
| 10 |
#include "common.h" |
#include "common.h" |
| 48 |
char charset[20]; |
char charset[20]; |
| 49 |
} bbsnet_conf[MAXSTATION]; |
} bbsnet_conf[MAXSTATION]; |
| 50 |
|
|
| 51 |
MENU_SET bbsnet_menu; |
static MENU_SET bbsnet_menu; |
| 52 |
|
|
| 53 |
int load_bbsnet_conf(const char *file_config) |
static int load_bbsnet_conf(const char *file_config) |
| 54 |
{ |
{ |
| 55 |
FILE *fp; |
FILE *fp; |
| 56 |
MENU *p_menu; |
MENU *p_menu; |
| 145 |
return 0; |
return 0; |
| 146 |
} |
} |
| 147 |
|
|
| 148 |
void unload_bbsnet_conf(void) |
static void unload_bbsnet_conf(void) |
| 149 |
{ |
{ |
| 150 |
bbsnet_menu.menu_count = 0; |
bbsnet_menu.menu_count = 0; |
| 151 |
bbsnet_menu.menu_item_count = 0; |
bbsnet_menu.menu_item_count = 0; |
| 156 |
bbsnet_menu.p_menu_item_pool = NULL; |
bbsnet_menu.p_menu_item_pool = NULL; |
| 157 |
} |
} |
| 158 |
|
|
| 159 |
void process_bar(int n, int len) |
static void process_bar(int n, int len) |
| 160 |
{ |
{ |
| 161 |
char buf[LINE_BUFFER_LEN]; |
char buf[LINE_BUFFER_LEN]; |
| 162 |
char buf2[LINE_BUFFER_LEN]; |
char buf2[LINE_BUFFER_LEN]; |
| 177 |
moveto(4, 0); |
moveto(4, 0); |
| 178 |
prints(" ------------------------------ \r\n"); |
prints(" ------------------------------ \r\n"); |
| 179 |
snprintf(buf, sizeof(buf), " %3d%% ", n * 100 / len); |
snprintf(buf, sizeof(buf), " %3d%% ", n * 100 / len); |
| 180 |
strncpy(buf2, buf, (size_t)n); |
memcpy(buf2, buf, (size_t)n); |
| 181 |
buf2[n] = '\0'; |
buf2[n] = '\0'; |
| 182 |
prints("|\033[46m%s\033[44m%s\033[m|\r\n", buf2, buf + n); |
prints("|\033[46m%s\033[44m%s\033[m|\r\n", buf2, buf + n); |
| 183 |
prints(" ------------------------------ \r\n"); |
prints(" ------------------------------ \r\n"); |
| 184 |
iflush(); |
iflush(); |
| 185 |
} |
} |
| 186 |
|
|
| 187 |
int bbsnet_connect(int n) |
static int bbsnet_connect(int n) |
| 188 |
{ |
{ |
| 189 |
int sock, ret, loop, error; |
int sock, ret, loop, error; |
| 190 |
int sock_connected = 0; |
int sock_connected = 0; |
| 416 |
log_common("BBSNET connect to %s:%d from %s:%d by [%s]\n", |
log_common("BBSNET connect to %s:%d from %s:%d by [%s]\n", |
| 417 |
remote_addr, remote_port, local_addr, local_port, BBS_username); |
remote_addr, remote_port, local_addr, local_port, BBS_username); |
| 418 |
|
|
| 419 |
snprintf(tocode, sizeof(tocode), "%s//TRANSLIT", bbsnet_conf[n].charset); |
snprintf(tocode, sizeof(tocode), "%s%s", bbsnet_conf[n].charset, |
| 420 |
|
(strcasecmp(stdio_charset, bbsnet_conf[n].charset) == 0 ? "" : "//IGNORE")); |
| 421 |
input_cd = iconv_open(tocode, stdio_charset); |
input_cd = iconv_open(tocode, stdio_charset); |
| 422 |
if (input_cd == (iconv_t)(-1)) |
if (input_cd == (iconv_t)(-1)) |
| 423 |
{ |
{ |
| 425 |
goto cleanup; |
goto cleanup; |
| 426 |
} |
} |
| 427 |
|
|
| 428 |
snprintf(tocode, sizeof(tocode), "%s//TRANSLIT", stdio_charset); |
snprintf(tocode, sizeof(tocode), "%s%s", stdio_charset, |
| 429 |
output_cd = iconv_open(stdio_charset, bbsnet_conf[n].charset); |
(strcasecmp(bbsnet_conf[n].charset, stdio_charset) == 0 ? "" : "//TRANSLIT")); |
| 430 |
|
output_cd = iconv_open(tocode, bbsnet_conf[n].charset); |
| 431 |
if (output_cd == (iconv_t)(-1)) |
if (output_cd == (iconv_t)(-1)) |
| 432 |
{ |
{ |
| 433 |
log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, tocode, errno); |
log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, tocode, errno); |
| 528 |
} |
} |
| 529 |
else if (ret == 0) |
else if (ret == 0) |
| 530 |
{ |
{ |
| 531 |
|
// Send NO-OP to remote server |
| 532 |
|
input_buf[input_buf_len] = '\0'; |
| 533 |
|
input_buf_len++; |
| 534 |
|
BBS_last_access_tm = time(NULL); |
| 535 |
|
|
| 536 |
stdin_read_wait = 0; |
stdin_read_wait = 0; |
| 537 |
break; // Check whether channel is still open |
break; // Check whether channel is still open |
| 538 |
} |
} |
| 588 |
{ |
{ |
| 589 |
if (input_buf_offset < input_buf_len) |
if (input_buf_offset < input_buf_len) |
| 590 |
{ |
{ |
| 591 |
|
// For debug |
| 592 |
|
#ifdef _DEBUG |
| 593 |
|
for (int j = input_buf_offset; j < input_buf_len; j++) |
| 594 |
|
{ |
| 595 |
|
log_error("Debug input: <--[%u]\n", (input_buf[j] + 256) % 256); |
| 596 |
|
} |
| 597 |
|
#endif |
| 598 |
|
|
| 599 |
ret = io_buf_conv(input_cd, input_buf, &input_buf_len, &input_buf_offset, input_conv, sizeof(input_conv), &input_conv_len); |
ret = io_buf_conv(input_cd, input_buf, &input_buf_len, &input_buf_offset, input_conv, sizeof(input_conv), &input_conv_len); |
| 600 |
if (ret < 0) |
if (ret < 0) |
| 601 |
{ |
{ |
| 602 |
log_error("io_buf_conv(input, %d, %d, %d) error\n", input_buf_len, input_buf_offset, input_conv_len); |
log_error("io_buf_conv(input, %d, %d, %d) error\n", input_buf_len, input_buf_offset, input_conv_len); |
| 603 |
|
input_buf_len = input_buf_offset; // Discard invalid sequence |
| 604 |
|
} |
| 605 |
|
|
| 606 |
|
// For debug |
| 607 |
|
#ifdef _DEBUG |
| 608 |
|
for (int j = input_conv_offset; j < input_conv_len; j++) |
| 609 |
|
{ |
| 610 |
|
log_error("Debug input_conv: <--[%u]\n", (input_conv[j] + 256) % 256); |
| 611 |
} |
} |
| 612 |
|
#endif |
| 613 |
} |
} |
| 614 |
|
|
| 615 |
while (input_conv_offset < input_conv_len && !SYS_server_exit) |
while (input_conv_offset < input_conv_len && !SYS_server_exit) |
| 704 |
if (ret < 0) |
if (ret < 0) |
| 705 |
{ |
{ |
| 706 |
log_error("io_buf_conv(output, %d, %d, %d) error\n", output_buf_len, output_buf_offset, output_conv_len); |
log_error("io_buf_conv(output, %d, %d, %d) error\n", output_buf_len, output_buf_offset, output_conv_len); |
| 707 |
|
output_buf_len = output_buf_offset; // Discard invalid sequence |
| 708 |
} |
} |
| 709 |
} |
} |
| 710 |
|
|
| 794 |
tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, |
tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, |
| 795 |
tm_used->tm_sec); |
tm_used->tm_sec); |
| 796 |
|
|
| 797 |
|
BBS_last_access_tm = time(NULL); |
| 798 |
|
|
| 799 |
return 0; |
return 0; |
| 800 |
} |
} |
| 801 |
|
|
| 802 |
static int |
static int bbsnet_refresh() |
|
bbsnet_refresh() |
|
| 803 |
{ |
{ |
| 804 |
clearscr(); |
clearscr(); |
| 805 |
moveto(1, 0); |
moveto(1, 0); |
| 823 |
return 0; |
return 0; |
| 824 |
} |
} |
| 825 |
|
|
| 826 |
int bbsnet_selchange() |
static int bbsnet_selchange() |
| 827 |
{ |
{ |
| 828 |
int i = bbsnet_menu.menu_item_pos[0]; |
int i = bbsnet_menu.menu_item_pos[0]; |
| 829 |
|
|
| 848 |
return 0; |
return 0; |
| 849 |
} |
} |
| 850 |
|
|
| 851 |
int bbs_net() |
extern int bbs_net() |
| 852 |
{ |
{ |
| 853 |
int ch, i; |
int ch, i; |
| 854 |
|
|
| 863 |
{ |
{ |
| 864 |
ch = igetch(100); |
ch = igetch(100); |
| 865 |
|
|
| 866 |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 867 |
{ |
{ |
| 868 |
BBS_last_access_tm = time(NULL); |
BBS_last_access_tm = time(NULL); |
| 869 |
} |
} |
| 870 |
|
|
| 871 |
switch (ch) |
switch (ch) |
| 872 |
{ |
{ |