/[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.65 by sysadm, Fri Oct 17 01:25:08 2025 UTC Revision 1.83 by sysadm, Fri Nov 21 07:36:41 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  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "bbs.h"  #include "bbs.h"
14    #include "bbs_net.h"
15  #include "common.h"  #include "common.h"
16  #include "io.h"  #include "io.h"
17  #include "log.h"  #include "log.h"
# Line 31  Line 28 
28  #include <time.h>  #include <time.h>
29  #include <unistd.h>  #include <unistd.h>
30  #include <arpa/inet.h>  #include <arpa/inet.h>
 #include <iconv.h>  
31  #include <libssh/libssh.h>  #include <libssh/libssh.h>
32  #include <libssh/server.h>  #include <libssh/server.h>
33  #include <libssh/callbacks.h>  #include <libssh/callbacks.h>
# Line 40  Line 36 
36  #include <sys/select.h>  #include <sys/select.h>
37  #include <sys/ioctl.h>  #include <sys/ioctl.h>
38  #include <sys/socket.h>  #include <sys/socket.h>
 #include <sys/epoll.h>  
39    
40  #define MENU_CONF_DELIM " \t\r\n"  #ifdef HAVE_SYS_EPOLL_H
41    #include <sys/epoll.h>
42    #else
43    #include <poll.h>
44    #endif
45    
46  #define MAX_PROCESS_BAR_LEN 30  static const char MENU_CONF_DELIM[] = " \t\r\n";
 #define MAXSTATION 26 * 2  
 #define STATION_PER_LINE 4  
47    
48  #define BBS_NET_DEFAULT_CHARSET "UTF-8"  enum _bbs_net_constant_t
49    {
50            MAX_PROCESS_BAR_LEN = 30,
51            MAXSTATION = 26 * 2,
52            STATION_PER_LINE = 4,
53    };
54    
55  struct _bbsnet_conf  struct _bbsnet_conf
56  {  {
# Line 56  struct _bbsnet_conf Line 58  struct _bbsnet_conf
58          char host2[40];          char host2[40];
59          char ip[40];          char ip[40];
60          in_port_t port;          in_port_t port;
61          char charset[20];          char charset[CHARSET_MAX_LEN + 1];
62  } bbsnet_conf[MAXSTATION];  } bbsnet_conf[MAXSTATION];
63    
64  MENU_SET bbsnet_menu;  static MENU_SET bbsnet_menu;
65    
66  int load_bbsnet_conf(const char *file_config)  static int load_bbsnet_conf(const char *file_config)
67  {  {
68          FILE *fp;          FILE *fp;
69          MENU *p_menu;          MENU *p_menu;
# Line 156  int load_bbsnet_conf(const char *file_co Line 158  int load_bbsnet_conf(const char *file_co
158          return 0;          return 0;
159  }  }
160    
161  void unload_bbsnet_conf(void)  static void unload_bbsnet_conf(void)
162  {  {
163          bbsnet_menu.menu_count = 0;          bbsnet_menu.menu_count = 0;
164          bbsnet_menu.menu_item_count = 0;          bbsnet_menu.menu_item_count = 0;
# Line 167  void unload_bbsnet_conf(void) Line 169  void unload_bbsnet_conf(void)
169          bbsnet_menu.p_menu_item_pool = NULL;          bbsnet_menu.p_menu_item_pool = NULL;
170  }  }
171    
172  void process_bar(int n, int len)  static void process_bar(int n, int len)
173  {  {
174          char buf[LINE_BUFFER_LEN];          char buf[LINE_BUFFER_LEN];
175          char buf2[LINE_BUFFER_LEN];          char buf2[LINE_BUFFER_LEN];
# Line 188  void process_bar(int n, int len) Line 190  void process_bar(int n, int len)
190          moveto(4, 0);          moveto(4, 0);
191          prints(" ------------------------------ \r\n");          prints(" ------------------------------ \r\n");
192          snprintf(buf, sizeof(buf), "            %3d%%              ", n * 100 / len);          snprintf(buf, sizeof(buf), "            %3d%%              ", n * 100 / len);
193          strncpy(buf2, buf, (size_t)n);          memcpy(buf2, buf, (size_t)n);
194          buf2[n] = '\0';          buf2[n] = '\0';
195          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);
196          prints(" ------------------------------ \r\n");          prints(" ------------------------------ \r\n");
197          iflush();          iflush();
198  }  }
199    
200  int bbsnet_io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char *p_conv, size_t conv_size, int *p_conv_len)  static int bbsnet_connect(int n)
 {  
         char *in_buf;  
         char *out_buf;  
         size_t in_bytes;  
         size_t out_bytes;  
         int ret;  
   
         in_buf = p_buf + *p_buf_offset;  
         in_bytes = (size_t)(*p_buf_len - *p_buf_offset);  
         out_buf = p_conv + *p_conv_len;  
         out_bytes = conv_size - (size_t)(*p_conv_len);  
   
         while (in_bytes > 0)  
         {  
                 ret = (int)iconv(cd, &in_buf, &in_bytes, &out_buf, &out_bytes);  
                 if (ret == -1)  
                 {  
                         if (errno == EINVAL) // Incomplete  
                         {  
 #ifdef _DEBUG  
                                 log_error("iconv(inbytes=%d, outbytes=%d) error: EINVAL\n", in_bytes, out_bytes);  
 #endif  
                                 *p_buf_len = (int)(p_buf + *p_buf_len - in_buf);  
                                 *p_buf_offset = 0;  
                                 *p_conv_len = (int)(conv_size - out_bytes);  
                                 memmove(p_buf, in_buf, (size_t)(*p_buf_len));  
   
                                 break;  
                         }  
                         else if (errno == E2BIG)  
                         {  
                                 log_error("iconv(inbytes=%d, outbytes=%d) error: E2BIG\n", in_bytes, out_bytes);  
                                 return -1;  
                         }  
                         else if (errno == EILSEQ)  
                         {  
                                 if (in_bytes > out_bytes || out_bytes <= 0)  
                                 {  
                                         log_error("iconv(inbytes=%d, outbytes=%d) error: EILSEQ and E2BIG\n", in_bytes, out_bytes);  
                                         return -2;  
                                 }  
   
                                 *out_buf = *in_buf;  
                                 in_buf++;  
                                 out_buf++;  
                                 in_bytes--;  
                                 out_bytes--;  
   
                                 continue;  
                         }  
                 }  
                 else  
                 {  
                         *p_buf_len = 0;  
                         *p_buf_offset = 0;  
                         *p_conv_len = (int)(conv_size - out_bytes);  
   
                         break;  
                 }  
         }  
   
         return 0;  
 }  
   
 int bbsnet_connect(int n)  
201  {  {
202          int sock, ret, loop, error;          int sock, ret, loop, error;
203          int sock_connected = 0;          int sock_connected = 0;
# Line 275  int bbsnet_connect(int n) Line 212  int bbsnet_connect(int n)
212          int output_buf_len = 0;          int output_buf_len = 0;
213          int input_buf_offset = 0;          int input_buf_offset = 0;
214          int output_buf_offset = 0;          int output_buf_offset = 0;
         iconv_t input_cd = NULL;  
215          char input_conv[LINE_BUFFER_LEN * 2];          char input_conv[LINE_BUFFER_LEN * 2];
216          char output_conv[LINE_BUFFER_LEN * 2];          char output_conv[LINE_BUFFER_LEN * 2];
217          int input_conv_len = 0;          int input_conv_len = 0;
218          int output_conv_len = 0;          int output_conv_len = 0;
219          int input_conv_offset = 0;          int input_conv_offset = 0;
220          int output_conv_offset = 0;          int output_conv_offset = 0;
221            iconv_t input_cd = NULL;
222          iconv_t output_cd = NULL;          iconv_t output_cd = NULL;
223            char tocode[32];
224    
225    #ifdef HAVE_SYS_EPOLL_H
226          struct epoll_event ev, events[MAX_EVENTS];          struct epoll_event ev, events[MAX_EVENTS];
227          int nfds, epollfd;          int epollfd;
228    #else
229            struct pollfd pfds[3];
230    #endif
231    
232            int nfds;
233          int stdin_read_wait = 0;          int stdin_read_wait = 0;
234          int stdout_write_wait = 0;          int stdout_write_wait = 0;
235          int sock_read_wait = 0;          int sock_read_wait = 0;
# Line 363  int bbsnet_connect(int n) Line 308  int bbsnet_connect(int n)
308          fcntl(STDIN_FILENO, F_SETFL, flags_stdin | O_NONBLOCK);          fcntl(STDIN_FILENO, F_SETFL, flags_stdin | O_NONBLOCK);
309          fcntl(STDOUT_FILENO, F_SETFL, flags_stdout | O_NONBLOCK);          fcntl(STDOUT_FILENO, F_SETFL, flags_stdout | O_NONBLOCK);
310    
311    #ifdef HAVE_SYS_EPOLL_H
312          epollfd = epoll_create1(0);          epollfd = epoll_create1(0);
313          if (epollfd < 0)          if (epollfd < 0)
314          {          {
# Line 385  int bbsnet_connect(int n) Line 331  int bbsnet_connect(int n)
331                  log_error("epoll_ctl(STDIN_FILENO) error (%d)\n", errno);                  log_error("epoll_ctl(STDIN_FILENO) error (%d)\n", errno);
332                  goto cleanup;                  goto cleanup;
333          }          }
334    #endif
335    
336          while (!SYS_server_exit)          while (!SYS_server_exit)
337          {          {
# Line 415  int bbsnet_connect(int n) Line 362  int bbsnet_connect(int n)
362    
363          for (int j = 0; j < MAX_PROCESS_BAR_LEN && !sock_connected && !SYS_server_exit; j++)          for (int j = 0; j < MAX_PROCESS_BAR_LEN && !sock_connected && !SYS_server_exit; j++)
364          {          {
365    #ifdef HAVE_SYS_EPOLL_H
366                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 500); // 0.5 second                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 500); // 0.5 second
367                    ret = nfds;
368    #else
369                    pfds[0].fd = sock;
370                    pfds[0].events = POLLOUT;
371                    pfds[1].fd = STDIN_FILENO;
372                    pfds[1].events = POLLIN;
373                    nfds = 2;
374                    ret = poll(pfds, (nfds_t)nfds, 500); // 0.5 second
375    #endif
376    
377                  if (nfds < 0)                  if (ret < 0)
378                  {                  {
379                          if (errno != EINTR)                          if (errno != EINTR)
380                          {                          {
381    #ifdef HAVE_SYS_EPOLL_H
382                                  log_error("epoll_wait() error (%d)\n", errno);                                  log_error("epoll_wait() error (%d)\n", errno);
383    #else
384                                    log_error("poll() error (%d)\n", errno);
385    #endif
386                                  break;                                  break;
387                          }                          }
388                  }                  }
389                  else if (nfds == 0) // timeout                  else if (ret == 0) // timeout
390                  {                  {
391                          process_bar(j + 1, MAX_PROCESS_BAR_LEN);                          process_bar(j + 1, MAX_PROCESS_BAR_LEN);
392                  }                  }
# Line 433  int bbsnet_connect(int n) Line 394  int bbsnet_connect(int n)
394                  {                  {
395                          for (int i = 0; i < nfds; i++)                          for (int i = 0; i < nfds; i++)
396                          {                          {
397    #ifdef HAVE_SYS_EPOLL_H
398                                  if (events[i].data.fd == sock)                                  if (events[i].data.fd == sock)
399    #else
400                                    if (pfds[i].fd == sock && (pfds[i].revents & POLLOUT))
401    #endif
402                                  {                                  {
403                                          len = sizeof(error);                                          len = sizeof(error);
404                                          if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&len) < 0)                                          if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&len) < 0)
# Line 446  int bbsnet_connect(int n) Line 411  int bbsnet_connect(int n)
411                                                  sock_connected = 1;                                                  sock_connected = 1;
412                                          }                                          }
413                                  }                                  }
414    #ifdef HAVE_SYS_EPOLL_H
415                                  else if (events[i].data.fd == STDIN_FILENO)                                  else if (events[i].data.fd == STDIN_FILENO)
416    #else
417                                    else if (pfds[i].fd == STDIN_FILENO && (pfds[i].revents & POLLIN))
418    #endif
419                                  {                                  {
420                                          ch = igetch(0);                                          ch = igetch(0);
421                                          if (ch == Ctrl('C') || ch == KEY_ESC)                                          if (ch == Ctrl('C') || ch == KEY_ESC)
# Line 491  int bbsnet_connect(int n) Line 460  int bbsnet_connect(int n)
460          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",
461                             remote_addr, remote_port, local_addr, local_port, BBS_username);                             remote_addr, remote_port, local_addr, local_port, BBS_username);
462    
463          input_cd = iconv_open(bbsnet_conf[n].charset, BBS_NET_DEFAULT_CHARSET);          snprintf(tocode, sizeof(tocode), "%s%s", bbsnet_conf[n].charset,
464                             (strcasecmp(stdio_charset, bbsnet_conf[n].charset) == 0 ? "" : "//IGNORE"));
465            input_cd = iconv_open(tocode, stdio_charset);
466          if (input_cd == (iconv_t)(-1))          if (input_cd == (iconv_t)(-1))
467          {          {
468                  log_error("iconv_open(%s->%s) error: %d\n", BBS_NET_DEFAULT_CHARSET, bbsnet_conf[n].charset, errno);                  log_error("iconv_open(%s->%s) error: %d\n", stdio_charset, tocode, errno);
469                  goto cleanup;                  goto cleanup;
470          }          }
471          output_cd = iconv_open(BBS_NET_DEFAULT_CHARSET, bbsnet_conf[n].charset);  
472          if (input_cd == (iconv_t)(-1))          snprintf(tocode, sizeof(tocode), "%s%s", stdio_charset,
473                             (strcasecmp(bbsnet_conf[n].charset, stdio_charset) == 0 ? "" : "//TRANSLIT"));
474            output_cd = iconv_open(tocode, bbsnet_conf[n].charset);
475            if (output_cd == (iconv_t)(-1))
476          {          {
477                  log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, BBS_NET_DEFAULT_CHARSET, errno);                  log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, tocode, errno);
478                  iconv_close(input_cd);                  iconv_close(input_cd);
479                  goto cleanup;                  goto cleanup;
480          }          }
481    
482    #ifdef HAVE_SYS_EPOLL_H
483          ev.events = EPOLLIN | EPOLLOUT | EPOLLET;          ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
484          ev.data.fd = sock;          ev.data.fd = sock;
485          if (epoll_ctl(epollfd, EPOLL_CTL_MOD, sock, &ev) == -1)          if (epoll_ctl(epollfd, EPOLL_CTL_MOD, sock, &ev) == -1)
# Line 520  int bbsnet_connect(int n) Line 495  int bbsnet_connect(int n)
495                  log_error("epoll_ctl(STDOUT_FILENO) error (%d)\n", errno);                  log_error("epoll_ctl(STDOUT_FILENO) error (%d)\n", errno);
496                  goto cleanup;                  goto cleanup;
497          }          }
498    #endif
499    
500          BBS_last_access_tm = t_used = time(NULL);          BBS_last_access_tm = t_used = time(NULL);
501          loop = 1;          loop = 1;
# Line 533  int bbsnet_connect(int n) Line 509  int bbsnet_connect(int n)
509                          break;                          break;
510                  }                  }
511    
512    #ifdef HAVE_SYS_EPOLL_H
513                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second
514                    ret = nfds;
515    #else
516                    pfds[0].fd = STDIN_FILENO;
517                    pfds[0].events = POLLIN;
518                    pfds[1].fd = sock;
519                    pfds[1].events = POLLIN | POLLOUT;
520                    pfds[2].fd = STDOUT_FILENO;
521                    pfds[2].events = POLLOUT;
522                    nfds = 3;
523                    ret = poll(pfds, (nfds_t)nfds, 100); // 0.1 second
524    #endif
525    
526                  if (nfds < 0)                  if (ret < 0)
527                  {                  {
528                          if (errno != EINTR)                          if (errno != EINTR)
529                          {                          {
530    #ifdef HAVE_SYS_EPOLL_H
531                                  log_error("epoll_wait() error (%d)\n", errno);                                  log_error("epoll_wait() error (%d)\n", errno);
532    #else
533                                    log_error("poll() error (%d)\n", errno);
534    #endif
535                                  break;                                  break;
536                          }                          }
537                          continue;                          continue;
538                  }                  }
539                  else if (nfds == 0) // timeout                  else if (ret == 0) // timeout
540                  {                  {
541                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
542                          {                          {
543                                  break;                                  break;
544                          }                          }
# Line 554  int bbsnet_connect(int n) Line 546  int bbsnet_connect(int n)
546    
547                  for (int i = 0; i < nfds; i++)                  for (int i = 0; i < nfds; i++)
548                  {                  {
549    #ifdef HAVE_SYS_EPOLL_H
550                          if (events[i].data.fd == STDIN_FILENO)                          if (events[i].data.fd == STDIN_FILENO)
551    #else
552                            if (pfds[i].fd == STDIN_FILENO && (pfds[i].revents & POLLIN))
553    #endif
554                          {                          {
555                                  stdin_read_wait = 1;                                  stdin_read_wait = 1;
556                          }                          }
557    
558    #ifdef HAVE_SYS_EPOLL_H
559                          if (events[i].data.fd == sock)                          if (events[i].data.fd == sock)
560    #else
561                            if (pfds[i].fd == sock)
562    #endif
563                          {                          {
564    #ifdef HAVE_SYS_EPOLL_H
565                                  if (events[i].events & EPOLLIN)                                  if (events[i].events & EPOLLIN)
566    #else
567                                    if (pfds[i].revents & POLLIN)
568    #endif
569                                  {                                  {
570                                          sock_read_wait = 1;                                          sock_read_wait = 1;
571                                  }                                  }
572    
573    #ifdef HAVE_SYS_EPOLL_H
574                                  if (events[i].events & EPOLLOUT)                                  if (events[i].events & EPOLLOUT)
575    #else
576                                    if (pfds[i].revents & POLLOUT)
577    #endif
578                                  {                                  {
579                                          sock_write_wait = 1;                                          sock_write_wait = 1;
580                                  }                                  }
581                          }                          }
582    
583    #ifdef HAVE_SYS_EPOLL_H
584                          if (events[i].data.fd == STDOUT_FILENO)                          if (events[i].data.fd == STDOUT_FILENO)
585    #else
586                            if (pfds[i].fd == STDOUT_FILENO && (pfds[i].revents & POLLOUT))
587    #endif  
588                          {                          {
589                                  stdout_write_wait = 1;                                  stdout_write_wait = 1;
590                          }                          }
# Line 598  int bbsnet_connect(int n) Line 611  int bbsnet_connect(int n)
611                                          }                                          }
612                                          else if (ret == 0)                                          else if (ret == 0)
613                                          {                                          {
614                                                    // Send NO-OP to remote server
615                                                    input_buf[input_buf_len] = '\0';
616                                                    input_buf_len++;
617                                                    BBS_last_access_tm = time(NULL);
618    
619                                                  stdin_read_wait = 0;                                                  stdin_read_wait = 0;
620                                                  break; // Check whether channel is still open                                                  break; // Check whether channel is still open
621                                          }                                          }
# Line 653  int bbsnet_connect(int n) Line 671  int bbsnet_connect(int n)
671                  {                  {
672                          if (input_buf_offset < input_buf_len)                          if (input_buf_offset < input_buf_len)
673                          {                          {
674                                  ret = bbsnet_io_buf_conv(input_cd, input_buf, &input_buf_len, &input_buf_offset, input_conv, sizeof(input_conv), &input_conv_len);                                  // For debug
675    #ifdef _DEBUG
676                                    for (int j = input_buf_offset; j < input_buf_len; j++)
677                                    {
678                                            log_error("Debug input: <--[%u]\n", (input_buf[j] + 256) % 256);
679                                    }
680    #endif
681    
682                                    ret = io_buf_conv(input_cd, input_buf, &input_buf_len, &input_buf_offset, input_conv, sizeof(input_conv), &input_conv_len);
683                                  if (ret < 0)                                  if (ret < 0)
684                                  {                                  {
685                                          log_error("bbsnet_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);
686                                            input_buf_len = input_buf_offset; // Discard invalid sequence
687                                  }                                  }
688    
689                                    // For debug
690    #ifdef _DEBUG
691                                    for (int j = input_conv_offset; j < input_conv_len; j++)
692                                    {
693                                            log_error("Debug input_conv: <--[%u]\n", (input_conv[j] + 256) % 256);
694                                    }
695    #endif
696                          }                          }
697    
698                          while (input_conv_offset < input_conv_len && !SYS_server_exit)                          while (input_conv_offset < input_conv_len && !SYS_server_exit)
# Line 748  int bbsnet_connect(int n) Line 783  int bbsnet_connect(int n)
783                  {                  {
784                          if (output_buf_offset < output_buf_len)                          if (output_buf_offset < output_buf_len)
785                          {                          {
786                                  ret = bbsnet_io_buf_conv(output_cd, output_buf, &output_buf_len, &output_buf_offset, output_conv, sizeof(output_conv), &output_conv_len);                                  ret = io_buf_conv(output_cd, output_buf, &output_buf_len, &output_buf_offset, output_conv, sizeof(output_conv), &output_conv_len);
787                                  if (ret < 0)                                  if (ret < 0)
788                                  {                                  {
789                                          log_error("bbsnet_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);
790                                            output_buf_len = output_buf_offset; // Discard invalid sequence
791                                  }                                  }
792                          }                          }
793    
# Line 817  int bbsnet_connect(int n) Line 853  int bbsnet_connect(int n)
853          iconv_close(output_cd);          iconv_close(output_cd);
854    
855  cleanup:  cleanup:
856    #ifdef HAVE_SYS_EPOLL_H
857          if (close(epollfd) < 0)          if (close(epollfd) < 0)
858          {          {
859                  log_error("close(epoll) error (%d)\n");                  log_error("close(epoll) error (%d)\n");
860          }          }
861    #endif
862    
863          // Restore STDIN/STDOUT flags          // Restore STDIN/STDOUT flags
864          fcntl(STDIN_FILENO, F_SETFL, flags_stdin);          fcntl(STDIN_FILENO, F_SETFL, flags_stdin);
865          fcntl(STDOUT_FILENO, F_SETFL, flags_stdout);          fcntl(STDOUT_FILENO, F_SETFL, flags_stdout);
866    
         // Restore socket flags  
         fcntl(sock, F_SETFL, flags_sock);  
   
867          if (close(sock) == -1)          if (close(sock) == -1)
868          {          {
869                  log_error("Close socket failed\n");                  log_error("Close socket failed\n");
# Line 841  cleanup: Line 876  cleanup:
876                             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,
877                             tm_used->tm_sec);                             tm_used->tm_sec);
878    
879            BBS_last_access_tm = time(NULL);
880    
881          return 0;          return 0;
882  }  }
883    
884  static int  static int bbsnet_refresh()
 bbsnet_refresh()  
885  {  {
886          clearscr();          clearscr();
887          moveto(1, 0);          moveto(1, 0);
# Line 869  bbsnet_refresh() Line 905  bbsnet_refresh()
905          return 0;          return 0;
906  }  }
907    
908  int bbsnet_selchange()  static int bbsnet_selchange()
909  {  {
910          int i = bbsnet_menu.menu_item_pos[0];          int i = bbsnet_menu.menu_item_pos[0];
911    
# Line 909  int bbs_net() Line 945  int bbs_net()
945          {          {
946                  ch = igetch(100);                  ch = igetch(100);
947    
948          if (ch != KEY_NULL && ch != KEY_TIMEOUT)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
949          {                  {
950              BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
951          }                  }
952    
953                  switch (ch)                  switch (ch)
954                  {                  {
# Line 920  int bbs_net() Line 956  int bbs_net()
956                          log_error("KEY_NULL\n");                          log_error("KEY_NULL\n");
957                          goto cleanup;                          goto cleanup;
958                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
959                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
960                          {                          {
961                                  log_error("User input timeout\n");                                  log_error("User input timeout\n");
962                                  goto cleanup;                                  goto cleanup;


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

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