/[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.84 by sysadm, Sun Nov 30 10:05:16 2025 UTC Revision 1.89 by sysadm, Tue Dec 16 12:59:14 2025 UTC
# Line 58  enum _bbs_net_constant_t Line 58  enum _bbs_net_constant_t
58    
59  struct _bbsnet_conf  struct _bbsnet_conf
60  {  {
61          char host1[20];          char org_name[40];
62          char host2[40];          char site_name[40];
63          char ip[40];          char host_name[IP_ADDR_LEN];
64          in_port_t port;          in_port_t port;
65          int8_t use_ssh;          int8_t use_ssh;
66          char charset[CHARSET_MAX_LEN + 1];          char charset[CHARSET_MAX_LEN + 1];
# Line 68  struct _bbsnet_conf Line 68  struct _bbsnet_conf
68    
69  static MENU_SET bbsnet_menu;  static MENU_SET bbsnet_menu;
70    
71    static void unload_bbsnet_conf(void);
72    
73  static int load_bbsnet_conf(const char *file_config)  static int load_bbsnet_conf(const char *file_config)
74  {  {
75          FILE *fp;          FILE *fp;
76          MENU *p_menu;          MENU *p_menu;
77          MENU_ITEM *p_menu_item;          MENU_ITEM *p_menu_item;
78          MENU_ITEM_ID menu_item_id;          MENU_ITEM_ID menu_item_id;
79          char t[256], *t1, *t2, *t3, *t4, *t5, *t6, *saveptr;          char line[LINE_BUFFER_LEN], *t1, *t2, *t3, *t4, *t5, *t6, *saveptr;
80            int port;
81    
82          fp = fopen(file_config, "r");          unload_bbsnet_conf();
         if (fp == NULL)  
         {  
                 return -1;  
         }  
83    
84          bbsnet_menu.p_menu_pool = calloc(1, sizeof(MENU));          bbsnet_menu.p_menu_pool = calloc(1, sizeof(MENU));
85          if (bbsnet_menu.p_menu_pool == NULL)          if (bbsnet_menu.p_menu_pool == NULL)
86          {          {
87                  log_error("calloc(p_menu_pool) error\n");                  log_error("calloc(p_menu_pool) error\n");
88                  return -3;                  return -1;
89          }          }
90          bbsnet_menu.menu_count = 1;          bbsnet_menu.menu_count = 1;
91    
# Line 94  static int load_bbsnet_conf(const char * Line 93  static int load_bbsnet_conf(const char *
93          if (bbsnet_menu.p_menu_item_pool == NULL)          if (bbsnet_menu.p_menu_item_pool == NULL)
94          {          {
95                  log_error("calloc(p_menu_item_pool) error\n");                  log_error("calloc(p_menu_item_pool) error\n");
96                  return -3;                  unload_bbsnet_conf();
97                    return -1;
98          }          }
99          bbsnet_menu.menu_item_count = MAXSTATION;          bbsnet_menu.menu_item_count = MAXSTATION;
100    
# Line 105  static int load_bbsnet_conf(const char * Line 105  static int load_bbsnet_conf(const char *
105          p_menu->title.show = 0;          p_menu->title.show = 0;
106          p_menu->screen_show = 0;          p_menu->screen_show = 0;
107    
108            fp = fopen(file_config, "r");
109            if (fp == NULL)
110            {
111                    unload_bbsnet_conf();
112                    return -2;
113            }
114    
115          menu_item_id = 0;          menu_item_id = 0;
116          while (fgets(t, 255, fp) && menu_item_id < MAXSTATION)          while (fgets(line, sizeof(line), fp) && menu_item_id < MAXSTATION)
117          {          {
118                  t1 = strtok_r(t, MENU_CONF_DELIM, &saveptr);                  t1 = strtok_r(line, MENU_CONF_DELIM, &saveptr);
119                  t2 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);                  t2 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
120                  t3 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);                  t3 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
121                  t4 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);                  t4 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
# Line 116  static int load_bbsnet_conf(const char * Line 123  static int load_bbsnet_conf(const char *
123                  t6 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);                  t6 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
124    
125                  if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL ||                  if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL ||
126                          t5 == NULL || t6 == NULL || t[0] == '#' || t[0] == '*')                          t5 == NULL || t6 == NULL || line[0] == '#' || line[0] == '*')
127                  {                  {
128                          continue;                          continue;
129                  }                  }
130    
131                  strncpy(bbsnet_conf[menu_item_id].host1, t2, sizeof(bbsnet_conf[menu_item_id].host1) - 1);                  strncpy(bbsnet_conf[menu_item_id].site_name, t2, sizeof(bbsnet_conf[menu_item_id].site_name) - 1);
132                  bbsnet_conf[menu_item_id].host1[sizeof(bbsnet_conf[menu_item_id].host1) - 1] = '\0';                  bbsnet_conf[menu_item_id].site_name[sizeof(bbsnet_conf[menu_item_id].site_name) - 1] = '\0';
133                  strncpy(bbsnet_conf[menu_item_id].host2, t1, sizeof(bbsnet_conf[menu_item_id].host2) - 1);                  strncpy(bbsnet_conf[menu_item_id].org_name, t1, sizeof(bbsnet_conf[menu_item_id].org_name) - 1);
134                  bbsnet_conf[menu_item_id].host2[sizeof(bbsnet_conf[menu_item_id].host2) - 1] = '\0';                  bbsnet_conf[menu_item_id].org_name[sizeof(bbsnet_conf[menu_item_id].org_name) - 1] = '\0';
135                  strncpy(bbsnet_conf[menu_item_id].ip, t3, sizeof(bbsnet_conf[menu_item_id].ip) - 1);                  strncpy(bbsnet_conf[menu_item_id].host_name, t3, sizeof(bbsnet_conf[menu_item_id].host_name) - 1);
136                  bbsnet_conf[menu_item_id].ip[sizeof(bbsnet_conf[menu_item_id].ip) - 1] = '\0';                  bbsnet_conf[menu_item_id].host_name[sizeof(bbsnet_conf[menu_item_id].host_name) - 1] = '\0';
137                  bbsnet_conf[menu_item_id].port = (in_port_t)(t4 ? atoi(t4) : 23);                  port = atoi(t4);
138                    if (port <= 0 || port > 65535)
139                    {
140                            log_error("Invalid port value %d of menu item %d\n", port, menu_item_id);
141                            fclose(fp);
142                            unload_bbsnet_conf();
143                            return -3;
144                    }
145                    bbsnet_conf[menu_item_id].port = (in_port_t)port;
146                  bbsnet_conf[menu_item_id].use_ssh = (toupper(t5[0]) == 'Y');                  bbsnet_conf[menu_item_id].use_ssh = (toupper(t5[0]) == 'Y');
147                  strncpy(bbsnet_conf[menu_item_id].charset, t6, sizeof(bbsnet_conf[menu_item_id].charset) - 1);                  strncpy(bbsnet_conf[menu_item_id].charset, t6, sizeof(bbsnet_conf[menu_item_id].charset) - 1);
148                  bbsnet_conf[menu_item_id].charset[sizeof(bbsnet_conf[menu_item_id].charset) - 1] = '\0';                  bbsnet_conf[menu_item_id].charset[sizeof(bbsnet_conf[menu_item_id].charset) - 1] = '\0';
# Line 136  static int load_bbsnet_conf(const char * Line 151  static int load_bbsnet_conf(const char *
151                  if (p_menu_item == NULL)                  if (p_menu_item == NULL)
152                  {                  {
153                          log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);                          log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);
154                          return -1;                          fclose(fp);
155                            unload_bbsnet_conf();
156                            return -3;
157                  }                  }
158    
159                  p_menu_item->row = (int16_t)(2 + menu_item_id / STATION_PER_LINE);                  p_menu_item->row = (int16_t)(2 + menu_item_id / STATION_PER_LINE);
# Line 148  static int load_bbsnet_conf(const char * Line 165  static int load_bbsnet_conf(const char *
165                  p_menu_item->name[0] =                  p_menu_item->name[0] =
166                          (char)(menu_item_id < MAXSTATION / 2 ? 'A' + menu_item_id : 'a' + menu_item_id);                          (char)(menu_item_id < MAXSTATION / 2 ? 'A' + menu_item_id : 'a' + menu_item_id);
167                  p_menu_item->name[1] = '\0';                  p_menu_item->name[1] = '\0';
168                  snprintf(p_menu_item->text, sizeof(p_menu_item->text), "%c. %s",                  snprintf(p_menu_item->text, sizeof(p_menu_item->text), "\033[1;36m%c.\033[m %s",
169                                   p_menu_item->name[0], bbsnet_conf[menu_item_id].host1);                                   p_menu_item->name[0], bbsnet_conf[menu_item_id].site_name);
170    
171                  p_menu->items[p_menu->item_count] = menu_item_id;                  p_menu->items[p_menu->item_count] = menu_item_id;
172                  p_menu->item_count++;                  p_menu->item_count++;
# Line 171  static void unload_bbsnet_conf(void) Line 188  static void unload_bbsnet_conf(void)
188          bbsnet_menu.menu_count = 0;          bbsnet_menu.menu_count = 0;
189          bbsnet_menu.menu_item_count = 0;          bbsnet_menu.menu_item_count = 0;
190    
191          free(bbsnet_menu.p_menu_pool);          if (bbsnet_menu.p_menu_pool)
192          bbsnet_menu.p_menu_pool = NULL;          {
193          free(bbsnet_menu.p_menu_item_pool);                  free(bbsnet_menu.p_menu_pool);
194          bbsnet_menu.p_menu_item_pool = NULL;                  bbsnet_menu.p_menu_pool = NULL;
195            }
196    
197            if (bbsnet_menu.p_menu_item_pool)
198            {
199                    free(bbsnet_menu.p_menu_item_pool);
200                    bbsnet_menu.p_menu_item_pool = NULL;
201            }
202  }  }
203    
204  static void process_bar(int n, int len)  static void process_bar(int n, int len)
# Line 182  static void process_bar(int n, int len) Line 206  static void process_bar(int n, int len)
206          char buf[LINE_BUFFER_LEN];          char buf[LINE_BUFFER_LEN];
207          char buf2[LINE_BUFFER_LEN];          char buf2[LINE_BUFFER_LEN];
208    
209          if (len > LINE_BUFFER_LEN)          if (len <= 0)
210            {
211                    len = 1;
212            }
213            else if (len > LINE_BUFFER_LEN)
214          {          {
215                  len = LINE_BUFFER_LEN - 1;                  len = LINE_BUFFER_LEN - 1;
216          }          }
# Line 207  static void process_bar(int n, int len) Line 235  static void process_bar(int n, int len)
235    
236  static int bbsnet_connect(int n)  static int bbsnet_connect(int n)
237  {  {
238          int sock, ret, loop, error;          int sock = -1;
239            int ret;
240            int loop;
241            int error;
242          int sock_connected = 0;          int sock_connected = 0;
243          int flags_sock;          int flags_sock = -1;
244          int flags_stdin;          int flags_stdin = -1;
245          int flags_stdout;          int flags_stdout = -1;
         int len;  
246          struct sockaddr_in sin;          struct sockaddr_in sin;
247          char input_buf[LINE_BUFFER_LEN];          char input_buf[LINE_BUFFER_LEN];
248          char output_buf[LINE_BUFFER_LEN];          char output_buf[LINE_BUFFER_LEN];
# Line 226  static int bbsnet_connect(int n) Line 256  static int bbsnet_connect(int n)
256          int output_conv_len = 0;          int output_conv_len = 0;
257          int input_conv_offset = 0;          int input_conv_offset = 0;
258          int output_conv_offset = 0;          int output_conv_offset = 0;
259          iconv_t input_cd = NULL;          iconv_t input_cd = (iconv_t)(-1);
260          iconv_t output_cd = NULL;          iconv_t output_cd = (iconv_t)(-1);
261          char tocode[32];          char tocode[CHARSET_MAX_LEN + 20];
262    
263  #ifdef HAVE_SYS_EPOLL_H  #ifdef HAVE_SYS_EPOLL_H
264          struct epoll_event ev, events[MAX_EVENTS];          struct epoll_event ev, events[MAX_EVENTS];
265          int epollfd;          int epollfd = -1;
266  #else  #else
267          struct pollfd pfds[3];          struct pollfd pfds[3];
268  #endif  #endif
# Line 257  static int bbsnet_connect(int n) Line 287  static int bbsnet_connect(int n)
287          ssh_session session = NULL;          ssh_session session = NULL;
288          ssh_channel channel = NULL;          ssh_channel channel = NULL;
289          int ssh_process_config = 0;          int ssh_process_config = 0;
290          int ssh_log_level = SSH_LOG_PROTOCOL;          int ssh_log_level = SSH_LOG_NOLOG;
291            long ssh_timeout = 0;
292    
293          if (user_online_update("BBS_NET") < 0)          if (user_online_update("BBS_NET") < 0)
294          {          {
# Line 277  static int bbsnet_connect(int n) Line 308  static int bbsnet_connect(int n)
308                  }                  }
309    
310                  moveto(1, 1);                  moveto(1, 1);
311                  prints("通过SSH方式连接[%s]...", bbsnet_conf[n].host1);                  prints("通过SSH方式连接[%s]...", bbsnet_conf[n].site_name);
312                  moveto(2, 1);                  moveto(2, 1);
313                  prints("请输入用户名: ");                  prints("请输入用户名: ");
314                  iflush();                  iflush();
# Line 307  static int bbsnet_connect(int n) Line 338  static int bbsnet_connect(int n)
338    
339          moveto(1, 1);          moveto(1, 1);
340          prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n",          prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n",
341                     bbsnet_conf[n].host1, bbsnet_conf[n].ip);                     bbsnet_conf[n].site_name, bbsnet_conf[n].host_name);
342          iflush();          iflush();
343    
344          p_host = gethostbyname(bbsnet_conf[n].ip);          p_host = gethostbyname(bbsnet_conf[n].host_name);
345    
346          if (p_host == NULL)          if (p_host == NULL)
347          {          {
348                  prints("\033[1;31m查找主机名失败!\033[m\r\n");                  prints("\033[1;31m查找主机名失败!\033[m\r\n");
349                  press_any_key();                  press_any_key();
350                  return -1;                  goto cleanup;
351          }          }
352    
353          sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);          sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
# Line 325  static int bbsnet_connect(int n) Line 356  static int bbsnet_connect(int n)
356          {          {
357                  prints("\033[1;31m无法创建socket!\033[m\r\n");                  prints("\033[1;31m无法创建socket!\033[m\r\n");
358                  press_any_key();                  press_any_key();
359                  return -1;                  goto cleanup;
360          }          }
361    
362          sin.sin_family = AF_INET;          sin.sin_family = AF_INET;
# Line 336  static int bbsnet_connect(int n) Line 367  static int bbsnet_connect(int n)
367          {          {
368                  log_error("Bind address %s:%u failed (%d)\n",                  log_error("Bind address %s:%u failed (%d)\n",
369                                    inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), errno);                                    inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), errno);
370                  return -2;                  goto cleanup;
371          }          }
372    
373          memset(&sin, 0, sizeof(sin));          memset(&sin, 0, sizeof(sin));
# Line 352  static int bbsnet_connect(int n) Line 383  static int bbsnet_connect(int n)
383          process_bar(0, MAX_PROCESS_BAR_LEN);          process_bar(0, MAX_PROCESS_BAR_LEN);
384    
385          // Set socket as non-blocking          // Set socket as non-blocking
386          flags_sock = fcntl(sock, F_GETFL, 0);          if ((flags_sock = fcntl(sock, F_GETFL, 0)) == -1)
387          fcntl(sock, F_SETFL, flags_sock | O_NONBLOCK);          {
388                    log_error("fcntl(F_GETFL) error (%d)\n", errno);
389                    goto cleanup;
390            }
391            if ((fcntl(sock, F_SETFL, flags_sock | O_NONBLOCK)) == -1)
392            {
393                    log_error("fcntl(F_SETFL) error (%d)\n", errno);
394                    goto cleanup;
395            }
396    
397          // Set STDIN/STDOUT as non-blocking          // Set STDIN/STDOUT as non-blocking
398          flags_stdin = fcntl(STDIN_FILENO, F_GETFL, 0);          if ((flags_stdin = fcntl(STDIN_FILENO, F_GETFL, 0)) == -1)
399          flags_stdout = fcntl(STDOUT_FILENO, F_GETFL, 0);          {
400          fcntl(STDIN_FILENO, F_SETFL, flags_stdin | O_NONBLOCK);                  log_error("fcntl(F_GETFL) error (%d)\n", errno);
401          fcntl(STDOUT_FILENO, F_SETFL, flags_stdout | O_NONBLOCK);                  goto cleanup;
402            }
403            if ((flags_stdout = fcntl(STDOUT_FILENO, F_GETFL, 0)) == -1)
404            {
405                    log_error("fcntl(F_GETFL) error (%d)\n", errno);
406                    goto cleanup;
407            }
408            if ((fcntl(STDIN_FILENO, F_SETFL, flags_stdin | O_NONBLOCK)) == -1)
409            {
410                    log_error("fcntl(F_SETFL) error (%d)\n", errno);
411                    goto cleanup;
412            }
413            if ((fcntl(STDOUT_FILENO, F_SETFL, flags_stdout | O_NONBLOCK)) == -1)
414            {
415                    log_error("fcntl(F_SETFL) error (%d)\n", errno);
416                    goto cleanup;
417            }
418    
419  #ifdef HAVE_SYS_EPOLL_H  #ifdef HAVE_SYS_EPOLL_H
420          epollfd = epoll_create1(0);          epollfd = epoll_create1(0);
421          if (epollfd < 0)          if (epollfd < 0)
422          {          {
423                  log_error("epoll_create1() error (%d)\n", errno);                  log_error("epoll_create1() error (%d)\n", errno);
424                  return -1;                  goto cleanup;
425          }          }
426    
427          ev.events = EPOLLOUT | EPOLLET;          ev.events = EPOLLOUT | EPOLLET;
# Line 453  static int bbsnet_connect(int n) Line 508  static int bbsnet_connect(int n)
508                                  if (pfds[i].fd == sock && (pfds[i].revents & POLLOUT))                                  if (pfds[i].fd == sock && (pfds[i].revents & POLLOUT))
509  #endif  #endif
510                                  {                                  {
511                                          len = sizeof(error);                                          socklen_t len = sizeof(error);
512                                          if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&len) < 0)                                          if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
513                                          {                                          {
514                                                  log_error("getsockopt() error (%d) !\n", error);                                                  log_error("getsockopt() error (%d) !\n", errno);
515                                                  goto cleanup;                                                  goto cleanup;
516                                          }                                          }
517                                          if (error == 0)                                          if (error == 0)
# Line 522  static int bbsnet_connect(int n) Line 577  static int bbsnet_connect(int n)
577    
578                  if (ssh_options_set(session, SSH_OPTIONS_FD, &sock) < 0 ||                  if (ssh_options_set(session, SSH_OPTIONS_FD, &sock) < 0 ||
579                          ssh_options_set(session, SSH_OPTIONS_PROCESS_CONFIG, &ssh_process_config) < 0 ||                          ssh_options_set(session, SSH_OPTIONS_PROCESS_CONFIG, &ssh_process_config) < 0 ||
580                          ssh_options_set(session, SSH_OPTIONS_HOST, bbsnet_conf[n].ip) < 0 ||                          ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, SSH_KNOWN_HOSTS_FILE) < 0 ||
581                            ssh_options_set(session, SSH_OPTIONS_HOST, bbsnet_conf[n].host_name) < 0 ||
582                          ssh_options_set(session, SSH_OPTIONS_USER, remote_user) < 0 ||                          ssh_options_set(session, SSH_OPTIONS_USER, remote_user) < 0 ||
583                          ssh_options_set(session, SSH_OPTIONS_HOSTKEYS, "+ssh-rsa") < 0 ||                          ssh_options_set(session, SSH_OPTIONS_HOSTKEYS, "+ssh-rsa") < 0 ||
584                          ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0)                          ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0)
# Line 531  static int bbsnet_connect(int n) Line 587  static int bbsnet_connect(int n)
587                          goto cleanup;                          goto cleanup;
588                  }                  }
589    
590                    ssh_timeout = 5; // second
591                    if (ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0)
592                    {
593                            log_error("Error setting SSH options: %s\n", ssh_get_error(session));
594                            goto cleanup;
595                    }
596    
597                  while (!SYS_server_exit)                  while (!SYS_server_exit)
598                  {                  {
599                          ret = ssh_connect(session);                          ret = ssh_connect(session);
# Line 545  static int bbsnet_connect(int n) Line 608  static int bbsnet_connect(int n)
608                          }                          }
609                  }                  }
610    
611                  ssh_set_blocking(session, 0);                  ret = ssh_session_is_known_server(session);
612                    switch (ret)
613                    {
614                    case SSH_KNOWN_HOSTS_NOT_FOUND:
615                    case SSH_KNOWN_HOSTS_UNKNOWN:
616                            if (ssh_session_update_known_hosts(session) != SSH_OK)
617                            {
618                                    log_error("ssh_session_update_known_hosts(%s) error\n", bbsnet_conf[n].host_name);
619                                    prints("\033[1;31m无法添加服务器证书\033[m");
620                                    press_any_key();
621                                    goto cleanup;
622                            }
623                            log_common("SSH key of (%s) is added into %s\n", bbsnet_conf[n].host_name, SSH_KNOWN_HOSTS_FILE);
624                    case SSH_KNOWN_HOSTS_OK:
625                            break;
626                    case SSH_KNOWN_HOSTS_CHANGED:
627                    case SSH_KNOWN_HOSTS_OTHER:
628                            log_error("ssh_session_is_known_server(%s) error: %d\n", bbsnet_conf[n].host_name, ret);
629                            prints("\033[1;31m服务器证书已变更\033[m");
630                            press_any_key();
631                            goto cleanup;
632                    }
633    
634                  for (int i = 0; !SYS_server_exit;)                  for (int i = 0; !SYS_server_exit;)
635                  {                  {
# Line 637  static int bbsnet_connect(int n) Line 721  static int bbsnet_connect(int n)
721                                  goto cleanup;                                  goto cleanup;
722                          }                          }
723                  }                  }
724    
725                    ssh_timeout = 0; // second
726                    if (ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0)
727                    {
728                            log_error("Error setting SSH options: %s\n", ssh_get_error(session));
729                            goto cleanup;
730                    }
731    
732                    ssh_set_blocking(session, 0);
733          }          }
734    
735          prints("\033[1;31m连接成功!\033[m\r\n");          prints("\033[1;31m连接成功!\033[m\r\n");
# Line 659  static int bbsnet_connect(int n) Line 752  static int bbsnet_connect(int n)
752          if (output_cd == (iconv_t)(-1))          if (output_cd == (iconv_t)(-1))
753          {          {
754                  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);
                 iconv_close(input_cd);  
755                  goto cleanup;                  goto cleanup;
756          }          }
757    
# Line 1078  static int bbsnet_connect(int n) Line 1170  static int bbsnet_connect(int n)
1170                  }                  }
1171          }          }
1172    
         iconv_close(input_cd);  
         iconv_close(output_cd);  
   
1173  cleanup:  cleanup:
1174            if (input_cd != (iconv_t)(-1))
1175            {
1176                    iconv_close(input_cd);
1177            }
1178            if (output_cd != (iconv_t)(-1))
1179            {
1180                    iconv_close(output_cd);
1181            }
1182    
1183  #ifdef HAVE_SYS_EPOLL_H  #ifdef HAVE_SYS_EPOLL_H
1184          if (close(epollfd) < 0)          if (epollfd != -1 && close(epollfd) < 0)
1185          {          {
1186                  log_error("close(epoll) error (%d)\n");                  log_error("close(epoll) error (%d)\n");
1187          }          }
# Line 1091  cleanup: Line 1189  cleanup:
1189    
1190          if (bbsnet_conf[n].use_ssh)          if (bbsnet_conf[n].use_ssh)
1191          {          {
1192                  ssh_channel_free(channel);                  if (channel != NULL)
1193                  ssh_disconnect(session);                  {
1194                  ssh_free(session);                          ssh_channel_free(channel);
1195                    }
1196                    if (session != NULL)
1197                    {
1198                            ssh_disconnect(session);
1199                            ssh_free(session);
1200                    }
1201          }          }
1202    
1203          // Restore STDIN/STDOUT flags          // Restore STDIN/STDOUT flags
1204          fcntl(STDIN_FILENO, F_SETFL, flags_stdin);          if (flags_stdin != -1 &&fcntl(STDIN_FILENO, F_SETFL, flags_stdin) == -1)
1205          fcntl(STDOUT_FILENO, F_SETFL, flags_stdout);          {
1206                    log_error("fcntl(F_SETFL) error (%d)\n", errno);
1207            }
1208            if (flags_stdout != -1 && fcntl(STDOUT_FILENO, F_SETFL, flags_stdout) == -1)
1209            {
1210                    log_error("fcntl(F_SETFL) error (%d)\n", errno);
1211            }
1212    
1213          if (close(sock) == -1)          if (sock != -1 && close(sock) == -1)
1214          {          {
1215                  log_error("Close socket failed\n");                  log_error("Close socket failed\n");
1216          }          }
# Line 1148  static int bbsnet_selchange() Line 1258  static int bbsnet_selchange()
1258    
1259          moveto(20, 1);          moveto(20, 1);
1260          clrtoeol();          clrtoeol();
1261          prints("|\033[1m单位: \033[1;33m%s\033[m%*s  站名: \033[1;33m%s\033[m",          prints("|\033[1m单位: \033[1;33m%s\033[m%*s  站名: \033[1;33m%s\033[m%*s  类型: \033[1;33m%s\033[m",
1262                     bbsnet_conf[i].host2, 20 - str_length(bbsnet_conf[i].host2, 1), "", bbsnet_conf[i].host1);                     bbsnet_conf[i].org_name, 20 - str_length(bbsnet_conf[i].org_name, 1), "",
1263                       bbsnet_conf[i].site_name, 20 - str_length(bbsnet_conf[i].site_name, 1), "",
1264                       (bbsnet_conf[i].use_ssh ? "SSH" : "Telnet"));
1265          moveto(20, 80);          moveto(20, 80);
1266          prints("|");          prints("|");
1267          moveto(21, 1);          moveto(21, 1);
1268          clrtoeol();          clrtoeol();
1269          prints("|\033[1m连往: \033[1;33m%-20s\033[m  端口: \033[1;33m%-5d\033[m            类型: \033[1;33m%s\033[m",          prints("|\033[1m连往: \033[1;33m%-20s\033[m  端口: \033[1;33m%-5d\033[m                 编码: \033[1;33m%s\033[m",
1270                     bbsnet_conf[i].ip, bbsnet_conf[i].port, (bbsnet_conf[i].use_ssh ? "SSH" : "Telnet"));                     bbsnet_conf[i].host_name, bbsnet_conf[i].port, bbsnet_conf[i].charset);
1271          moveto(21, 80);          moveto(21, 80);
1272          prints("|");          prints("|");
1273          iflush();          iflush();
# Line 1167  int bbs_net() Line 1279  int bbs_net()
1279  {  {
1280          int ch, i;          int ch, i;
1281    
1282          load_bbsnet_conf(CONF_BBSNET);          if (load_bbsnet_conf(CONF_BBSNET) < 0)
1283            {
1284                    clearscr();
1285                    moveto(1, 1);
1286                    prints("加载穿梭配置失败!");
1287                    press_any_key();
1288                    return -1;
1289            }
1290    
1291          bbsnet_refresh();          bbsnet_refresh();
1292          display_menu(&bbsnet_menu);          display_menu(&bbsnet_menu);


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

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