/[LeafOK_CVS]/lbbs/src/bbs_net.c
ViewVC logotype

Diff of /lbbs/src/bbs_net.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.67 by sysadm, Sat Oct 18 05:02:15 2025 UTC Revision 1.76 by sysadm, Tue Nov 4 13:49:51 2025 UTC
# Line 1  Line 1 
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"
# Line 56  struct _bbsnet_conf Line 48  struct _bbsnet_conf
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;
# Line 153  int load_bbsnet_conf(const char *file_co Line 145  int load_bbsnet_conf(const char *file_co
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;
# Line 164  void unload_bbsnet_conf(void) Line 156  void unload_bbsnet_conf(void)
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];
# Line 185  void process_bar(int n, int len) Line 177  void process_bar(int n, int 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;
# Line 215  int bbsnet_connect(int n) Line 207  int bbsnet_connect(int n)
207          int output_conv_offset = 0;          int output_conv_offset = 0;
208          iconv_t input_cd = NULL;          iconv_t input_cd = NULL;
209          iconv_t output_cd = NULL;          iconv_t output_cd = NULL;
210            char tocode[32];
211          struct epoll_event ev, events[MAX_EVENTS];          struct epoll_event ev, events[MAX_EVENTS];
212          int nfds, epollfd;          int nfds, epollfd;
213          int stdin_read_wait = 0;          int stdin_read_wait = 0;
# Line 423  int bbsnet_connect(int n) Line 416  int bbsnet_connect(int n)
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          input_cd = iconv_open(bbsnet_conf[n].charset, stdio_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);
422          if (input_cd == (iconv_t)(-1))          if (input_cd == (iconv_t)(-1))
423          {          {
424                  log_error("iconv_open(%s->%s) error: %d\n", stdio_charset, bbsnet_conf[n].charset, errno);                  log_error("iconv_open(%s->%s) error: %d\n", stdio_charset, tocode, errno);
425                  goto cleanup;                  goto cleanup;
426          }          }
427          output_cd = iconv_open(stdio_charset, bbsnet_conf[n].charset);  
428            snprintf(tocode, sizeof(tocode), "%s%s", stdio_charset,
429                             (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, stdio_charset, errno);                  log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, tocode, errno);
434                  iconv_close(input_cd);                  iconv_close(input_cd);
435                  goto cleanup;                  goto cleanup;
436          }          }
# Line 530  int bbsnet_connect(int n) Line 528  int bbsnet_connect(int n)
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                                          }                                          }
# Line 585  int bbsnet_connect(int n) Line 588  int bbsnet_connect(int n)
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)
# Line 684  int bbsnet_connect(int n) Line 704  int bbsnet_connect(int n)
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    
# Line 773  cleanup: Line 794  cleanup:
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);
# Line 801  bbsnet_refresh() Line 823  bbsnet_refresh()
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    
# Line 826  int bbsnet_selchange() Line 848  int bbsnet_selchange()
848          return 0;          return 0;
849  }  }
850    
851  int bbs_net()  extern int bbs_net()
852  {  {
853          int ch, i;          int ch, i;
854    
# Line 841  int bbs_net() Line 863  int bbs_net()
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                  {                  {


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1