/[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.55 by sysadm, Sat Jun 21 02:15:18 2025 UTC Revision 1.72 by sysadm, Mon Oct 20 03:38:23 2025 UTC
# Line 53  struct _bbsnet_conf Line 53  struct _bbsnet_conf
53          char host2[40];          char host2[40];
54          char ip[40];          char ip[40];
55          in_port_t port;          in_port_t port;
56            char charset[20];
57  } bbsnet_conf[MAXSTATION];  } bbsnet_conf[MAXSTATION];
58    
59  MENU_SET bbsnet_menu;  MENU_SET bbsnet_menu;
# Line 63  int load_bbsnet_conf(const char *file_co Line 64  int load_bbsnet_conf(const char *file_co
64          MENU *p_menu;          MENU *p_menu;
65          MENU_ITEM *p_menu_item;          MENU_ITEM *p_menu_item;
66          MENU_ITEM_ID menu_item_id;          MENU_ITEM_ID menu_item_id;
67          char t[256], *t1, *t2, *t3, *t4, *saveptr;          char t[256], *t1, *t2, *t3, *t4, *t5, *saveptr;
68    
69          fp = fopen(file_config, "r");          fp = fopen(file_config, "r");
70          if (fp == NULL)          if (fp == NULL)
# Line 101  int load_bbsnet_conf(const char *file_co Line 102  int load_bbsnet_conf(const char *file_co
102                  t2 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);                  t2 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
103                  t3 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);                  t3 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
104                  t4 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);                  t4 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
105                    t5 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
106    
107                  if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL || t[0] == '#' || t[0] == '*')                  if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL || t5 == NULL || t[0] == '#' || t[0] == '*')
108                  {                  {
109                          continue;                          continue;
110                  }                  }
# Line 114  int load_bbsnet_conf(const char *file_co Line 116  int load_bbsnet_conf(const char *file_co
116                  strncpy(bbsnet_conf[menu_item_id].ip, t3, sizeof(bbsnet_conf[menu_item_id].ip) - 1);                  strncpy(bbsnet_conf[menu_item_id].ip, t3, sizeof(bbsnet_conf[menu_item_id].ip) - 1);
117                  bbsnet_conf[menu_item_id].ip[sizeof(bbsnet_conf[menu_item_id].ip) - 1] = '\0';                  bbsnet_conf[menu_item_id].ip[sizeof(bbsnet_conf[menu_item_id].ip) - 1] = '\0';
118                  bbsnet_conf[menu_item_id].port = (in_port_t)(t4 ? atoi(t4) : 23);                  bbsnet_conf[menu_item_id].port = (in_port_t)(t4 ? atoi(t4) : 23);
119                    strncpy(bbsnet_conf[menu_item_id].charset, t5, sizeof(bbsnet_conf[menu_item_id].charset) - 1);
120                    bbsnet_conf[menu_item_id].charset[sizeof(bbsnet_conf[menu_item_id].charset) - 1] = '\0';
121    
122                  p_menu_item = get_menu_item_by_id(&bbsnet_menu, menu_item_id);                  p_menu_item = get_menu_item_by_id(&bbsnet_menu, menu_item_id);
123                  if (p_menu_item == NULL)                  if (p_menu_item == NULL)
# Line 203  int bbsnet_connect(int n) Line 207  int bbsnet_connect(int n)
207          int output_buf_len = 0;          int output_buf_len = 0;
208          int input_buf_offset = 0;          int input_buf_offset = 0;
209          int output_buf_offset = 0;          int output_buf_offset = 0;
210            char input_conv[LINE_BUFFER_LEN * 2];
211            char output_conv[LINE_BUFFER_LEN * 2];
212            int input_conv_len = 0;
213            int output_conv_len = 0;
214            int input_conv_offset = 0;
215            int output_conv_offset = 0;
216            iconv_t input_cd = NULL;
217            iconv_t output_cd = NULL;
218            char tocode[32];
219          struct epoll_event ev, events[MAX_EVENTS];          struct epoll_event ev, events[MAX_EVENTS];
220          int nfds, epollfd;          int nfds, epollfd;
221          int stdin_read_wait = 0;          int stdin_read_wait = 0;
# Line 213  int bbsnet_connect(int n) Line 226  int bbsnet_connect(int n)
226          int tos;          int tos;
227          char remote_addr[IP_ADDR_LEN];          char remote_addr[IP_ADDR_LEN];
228          int remote_port;          int remote_port;
229          time_t t_used;          char local_addr[IP_ADDR_LEN];
230            int local_port;
231            socklen_t sock_len;
232            time_t t_used = time(NULL);
233          struct tm *tm_used;          struct tm *tm_used;
234          int ch;          int ch;
235    
# Line 225  int bbsnet_connect(int n) Line 241  int bbsnet_connect(int n)
241          clearscr();          clearscr();
242    
243          moveto(0, 0);          moveto(0, 0);
244          prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n",          prints("\033[1;32m姝e湪娴嬭瘯寰 %s (%s) 鐨勮繛鎺ワ紝璇风◢鍊... \033[m\r\n",
245                     bbsnet_conf[n].host1, bbsnet_conf[n].ip);                     bbsnet_conf[n].host1, bbsnet_conf[n].ip);
246          iflush();          iflush();
247    
# Line 233  int bbsnet_connect(int n) Line 249  int bbsnet_connect(int n)
249    
250          if (p_host == NULL)          if (p_host == NULL)
251          {          {
252                  prints("\033[1;31m查找主机名失败!\033[m\r\n");                  prints("\033[1;31m鏌ユ壘涓绘満鍚嶅け璐ワ紒\033[m\r\n");
253                  press_any_key();                  press_any_key();
254                  return -1;                  return -1;
255          }          }
# Line 242  int bbsnet_connect(int n) Line 258  int bbsnet_connect(int n)
258    
259          if (sock < 0)          if (sock < 0)
260          {          {
261                  prints("\033[1;31m无法创建socket!\033[m\r\n");                  prints("\033[1;31m鏃犳硶鍒涘缓socket锛乗033[m\r\n");
262                  press_any_key();                  press_any_key();
263                  return -1;                  return -1;
264          }          }
# Line 267  int bbsnet_connect(int n) Line 283  int bbsnet_connect(int n)
283          remote_addr[sizeof(remote_addr) - 1] = '\0';          remote_addr[sizeof(remote_addr) - 1] = '\0';
284          remote_port = ntohs(sin.sin_port);          remote_port = ntohs(sin.sin_port);
285    
286          prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n");          prints("\033[1;32m绌挎杩涘害鏉℃彁绀烘偍褰撳墠宸蹭娇鐢ㄧ殑鏃堕棿锛屾寜\033[1;33mCtrl+C\033[1;32m涓柇銆俓033[m\r\n");
287          process_bar(0, MAX_PROCESS_BAR_LEN);          process_bar(0, MAX_PROCESS_BAR_LEN);
288    
289          // Set socket as non-blocking          // Set socket as non-blocking
# Line 287  int bbsnet_connect(int n) Line 303  int bbsnet_connect(int n)
303                  return -1;                  return -1;
304          }          }
305    
306          ev.events = EPOLLOUT;          ev.events = EPOLLOUT | EPOLLET;
307          ev.data.fd = sock;          ev.data.fd = sock;
308          if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev) == -1)          if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev) == -1)
309          {          {
# Line 295  int bbsnet_connect(int n) Line 311  int bbsnet_connect(int n)
311                  goto cleanup;                  goto cleanup;
312          }          }
313    
314          ev.events = EPOLLIN;          ev.events = EPOLLIN | EPOLLET;
315          ev.data.fd = STDIN_FILENO;          ev.data.fd = STDIN_FILENO;
316          if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) == -1)          if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) == -1)
317          {          {
# Line 322  int bbsnet_connect(int n) Line 338  int bbsnet_connect(int n)
338                          {                          {
339                                  log_error("connect(socket) error (%d)\n", errno);                                  log_error("connect(socket) error (%d)\n", errno);
340    
341                                  prints("\033[1;31m连接失败!\033[m\r\n");                                  prints("\033[1;31m杩炴帴澶辫触锛乗033[m\r\n");
342                                  press_any_key();                                  press_any_key();
343    
344                                  goto cleanup;                                  goto cleanup;
# Line 380  int bbsnet_connect(int n) Line 396  int bbsnet_connect(int n)
396          }          }
397          if (!sock_connected)          if (!sock_connected)
398          {          {
399                  prints("\033[1;31m连接失败!\033[m\r\n");                  prints("\033[1;31m杩炴帴澶辫触锛乗033[m\r\n");
400                  press_any_key();                  press_any_key();
401    
402                  goto cleanup;                  goto cleanup;
# Line 392  int bbsnet_connect(int n) Line 408  int bbsnet_connect(int n)
408                  log_error("setsockopt IP_TOS=%d error (%d)\n", tos, errno);                  log_error("setsockopt IP_TOS=%d error (%d)\n", tos, errno);
409          }          }
410    
411          prints("\033[1;31m连接成功!\033[m\r\n");          sock_len = sizeof(sin);
412            if (getsockname(sock, (struct sockaddr *)&sin, &sock_len) < 0)
413            {
414                    log_error("getsockname() error: %d", errno);
415                    goto cleanup;
416            }
417    
418            strncpy(local_addr, inet_ntoa(sin.sin_addr), sizeof(local_addr) - 1);
419            local_addr[sizeof(local_addr) - 1] = '\0';
420            local_port = ntohs(sin.sin_port);
421    
422            prints("\033[1;31m杩炴帴鎴愬姛锛乗033[m\r\n");
423          iflush();          iflush();
424          log_common("BBSNET connect to %s:%d\n", remote_addr, remote_port);          log_common("BBSNET connect to %s:%d from %s:%d by [%s]\n",
425                               remote_addr, remote_port, local_addr, local_port, BBS_username);
426    
427            snprintf(tocode, sizeof(tocode), "%s%s", bbsnet_conf[n].charset,
428                             (strcasecmp(stdio_charset, bbsnet_conf[n].charset) == 0 ? "" : "//IGNORE"));
429            input_cd = iconv_open(tocode, stdio_charset);
430            if (input_cd == (iconv_t)(-1))
431            {
432                    log_error("iconv_open(%s->%s) error: %d\n", stdio_charset, tocode, errno);
433                    goto cleanup;
434            }
435    
436            snprintf(tocode, sizeof(tocode), "%s%s", stdio_charset,
437                             (strcasecmp(bbsnet_conf[n].charset, stdio_charset) == 0 ? "" : "//TRANSLIT"));
438            output_cd = iconv_open(tocode, bbsnet_conf[n].charset);
439            if (output_cd == (iconv_t)(-1))
440            {
441                    log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, tocode, errno);
442                    iconv_close(input_cd);
443                    goto cleanup;
444            }
445    
446          ev.events = EPOLLIN | EPOLLOUT | EPOLLET;          ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
447          ev.data.fd = sock;          ev.data.fd = sock;
# Line 404  int bbsnet_connect(int n) Line 451  int bbsnet_connect(int n)
451                  goto cleanup;                  goto cleanup;
452          }          }
453    
454          ev.events = EPOLLOUT;          ev.events = EPOLLOUT | EPOLLET;
455          ev.data.fd = STDOUT_FILENO;          ev.data.fd = STDOUT_FILENO;
456          if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDOUT_FILENO, &ev) == -1)          if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDOUT_FILENO, &ev) == -1)
457          {          {
# Line 441  int bbsnet_connect(int n) Line 488  int bbsnet_connect(int n)
488                          {                          {
489                                  break;                                  break;
490                          }                          }
                         continue;  
491                  }                  }
492    
493                  for (int i = 0; i < nfds; i++)                  for (int i = 0; i < nfds; i++)
494                  {                  {
495                          if (events[i].data.fd == STDIN_FILENO || stdin_read_wait)                          if (events[i].data.fd == STDIN_FILENO)
496                          {                          {
497                                  stdin_read_wait = 1;                                  stdin_read_wait = 1;
498                                  while (input_buf_len < sizeof(input_buf) && !SYS_server_exit)                          }
499    
500                            if (events[i].data.fd == sock)
501                            {
502                                    if (events[i].events & EPOLLIN)
503                                    {
504                                            sock_read_wait = 1;
505                                    }
506                                    if (events[i].events & EPOLLOUT)
507                                    {
508                                            sock_write_wait = 1;
509                                    }
510                            }
511    
512                            if (events[i].data.fd == STDOUT_FILENO)
513                            {
514                                    stdout_write_wait = 1;
515                            }
516                    }
517    
518                    if (stdin_read_wait)
519                    {
520                            while (input_buf_len < sizeof(input_buf) && !SYS_server_exit)
521                            {
522                                    if (SSH_v2)
523                                  {                                  {
524                                          if (SSH_v2)                                          ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0);
525                                            if (ret == SSH_ERROR)
526                                          {                                          {
527                                                  ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0);                                                  log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session));
528                                                  if (ret == SSH_ERROR)                                                  loop = 0;
529                                                  {                                                  break;
                                                         log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session));  
                                                         loop = 0;  
                                                         break;  
                                                 }  
                                                 else if (ret == SSH_EOF)  
                                                 {  
                                                         stdin_read_wait = 0;  
                                                         loop = 0;  
                                                         break;  
                                                 }  
                                                 else if (ret == 0)  
                                                 {  
                                                         stdin_read_wait = 0;  
                                                         break; // Check whether channel is still open  
                                                 }  
530                                          }                                          }
531                                          else                                          else if (ret == SSH_EOF)
532                                          {                                          {
533                                                  ret = (int)read(STDIN_FILENO, input_buf + input_buf_len, sizeof(input_buf) - (size_t)input_buf_len);                                                  stdin_read_wait = 0;
534                                                    loop = 0;
535                                                    break;
536                                          }                                          }
537                                          if (ret < 0)                                          else if (ret == 0)
538                                          {                                          {
539                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)                                                  // Send NO-OP to remote server
540                                                  {                                                  input_buf[input_buf_len] = '\0';
541                                                          stdin_read_wait = 0;                                                  input_buf_len++;
542                                                          break;  
543                                                  }                                                  stdin_read_wait = 0;
544                                                  else if (errno == EINTR)                                                  break; // Check whether channel is still open
                                                 {  
                                                         continue;  
                                                 }  
                                                 else  
                                                 {  
                                                         log_error("read(STDIN) error (%d)\n", errno);  
                                                         loop = 0;  
                                                         break;  
                                                 }  
545                                          }                                          }
546                                          else if (ret == 0) // broken pipe                                  }
547                                    else
548                                    {
549                                            ret = (int)read(STDIN_FILENO, input_buf + input_buf_len, sizeof(input_buf) - (size_t)input_buf_len);
550                                    }
551                                    if (ret < 0)
552                                    {
553                                            if (errno == EAGAIN || errno == EWOULDBLOCK)
554                                          {                                          {
 #ifdef _DEBUG  
                                                 log_error("read(STDIN) EOF\n");  
 #endif  
555                                                  stdin_read_wait = 0;                                                  stdin_read_wait = 0;
                                                 loop = 0;  
556                                                  break;                                                  break;
557                                          }                                          }
558                                          else                                          else if (errno == EINTR)
559                                          {                                          {
                                                 input_buf_len += ret;  
                                                 BBS_last_access_tm = time(NULL);  
560                                                  continue;                                                  continue;
561                                          }                                          }
562                                            else
563                                            {
564                                                    log_error("read(STDIN) error (%d)\n", errno);
565                                                    loop = 0;
566                                                    break;
567                                            }
568                                    }
569                                    else if (ret == 0) // broken pipe
570                                    {
571    #ifdef _DEBUG
572                                            log_error("read(STDIN) EOF\n");
573    #endif
574                                            stdin_read_wait = 0;
575                                            loop = 0;
576                                            break;
577                                    }
578                                    else
579                                    {
580                                            input_buf_len += ret;
581                                            BBS_last_access_tm = time(NULL);
582    
583                                            // Refresh current action while user input
584                                            if (user_online_update("BBS_NET") < 0)
585                                            {
586                                                    log_error("user_online_update(BBS_NET) error\n");
587                                            }
588    
589                                            continue;
590                                  }                                  }
591                          }                          }
592                    }
593    
594                          if (events[i].data.fd == sock || sock_write_wait) // EPOLLOUT                  if (sock_write_wait)
595                    {
596                            if (input_buf_offset < input_buf_len)
597                          {                          {
598                                  sock_write_wait = 1;                                  // For debug
599                                  while (input_buf_offset < input_buf_len && !SYS_server_exit)  #ifdef _DEBUG
600                                    for (int j = input_buf_offset; j < input_buf_len; j++)
601                                  {                                  {
602                                          ret = (int)write(sock, input_buf + input_buf_offset, (size_t)(input_buf_len - input_buf_offset));                                          log_error("Debug input: <--[%u]\n", (input_buf[j] + 256) % 256);
603                                          if (ret < 0)                                  }
604                                          {  #endif
605                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)  
606                                                  {                                  ret = io_buf_conv(input_cd, input_buf, &input_buf_len, &input_buf_offset, input_conv, sizeof(input_conv), &input_conv_len);
607                                                          sock_write_wait = 0;                                  if (ret < 0)
608                                                          break;                                  {
609                                                  }                                          log_error("io_buf_conv(input, %d, %d, %d) error\n", input_buf_len, input_buf_offset, input_conv_len);
610                                                  else if (errno == EINTR)                                          input_buf_len = input_buf_offset; // Discard invalid sequence
611                                                  {                                  }
612                                                          continue;  
613                                                  }                                  // For debug
                                                 else  
                                                 {  
                                                         log_error("write(socket) error (%d)\n", errno);  
                                                         loop = 0;  
                                                         break;  
                                                 }  
                                         }  
                                         else if (ret == 0) // broken pipe  
                                         {  
614  #ifdef _DEBUG  #ifdef _DEBUG
615                                                  log_error("write(socket) EOF\n");                                  for (int j = input_conv_offset; j < input_conv_len; j++)
616                                    {
617                                            log_error("Debug input_conv: <--[%u]\n", (input_conv[j] + 256) % 256);
618                                    }
619  #endif  #endif
620                            }
621    
622                            while (input_conv_offset < input_conv_len && !SYS_server_exit)
623                            {
624                                    ret = (int)write(sock, input_conv + input_conv_offset, (size_t)(input_conv_len - input_conv_offset));
625                                    if (ret < 0)
626                                    {
627                                            if (errno == EAGAIN || errno == EWOULDBLOCK)
628                                            {
629                                                  sock_write_wait = 0;                                                  sock_write_wait = 0;
                                                 loop = 0;  
630                                                  break;                                                  break;
631                                          }                                          }
632                                          else                                          else if (errno == EINTR)
633                                          {                                          {
                                                 input_buf_offset += ret;  
                                                 if (input_buf_offset >= input_buf_len) // Output buffer complete  
                                                 {  
                                                         input_buf_offset = 0;  
                                                         input_buf_len = 0;  
                                                         break;  
                                                 }  
634                                                  continue;                                                  continue;
635                                          }                                          }
636                                            else
637                                            {
638                                                    log_error("write(socket) error (%d)\n", errno);
639                                                    loop = 0;
640                                                    break;
641                                            }
642                                    }
643                                    else if (ret == 0) // broken pipe
644                                    {
645    #ifdef _DEBUG
646                                            log_error("write(socket) EOF\n");
647    #endif
648                                            sock_write_wait = 0;
649                                            loop = 0;
650                                            break;
651                                    }
652                                    else
653                                    {
654                                            input_conv_offset += ret;
655                                            if (input_conv_offset >= input_conv_len) // Output buffer complete
656                                            {
657                                                    input_conv_offset = 0;
658                                                    input_conv_len = 0;
659                                                    break;
660                                            }
661                                            continue;
662                                  }                                  }
663                          }                          }
664                    }
665    
666                          if (events[i].data.fd == sock || sock_read_wait) // EPOLLIN                  if (sock_read_wait)
667                    {
668                            while (output_buf_len < sizeof(output_buf) && !SYS_server_exit)
669                          {                          {
670                                  sock_read_wait = 1;                                  ret = (int)read(sock, output_buf + output_buf_len, sizeof(output_buf) - (size_t)output_buf_len);
671                                  while (output_buf_len < sizeof(output_buf) && !SYS_server_exit)                                  if (ret < 0)
672                                  {                                  {
673                                          ret = (int)read(sock, output_buf + output_buf_len, sizeof(output_buf) - (size_t)output_buf_len);                                          if (errno == EAGAIN || errno == EWOULDBLOCK)
                                         if (ret < 0)  
                                         {  
                                                 if (errno == EAGAIN || errno == EWOULDBLOCK)  
                                                 {  
                                                         sock_read_wait = 0;  
                                                         break;  
                                                 }  
                                                 else if (errno == EINTR)  
                                                 {  
                                                         continue;  
                                                 }  
                                                 else  
                                                 {  
                                                         log_error("read(socket) error (%d)\n", errno);  
                                                         loop = 0;  
                                                         break;  
                                                 }  
                                         }  
                                         else if (ret == 0) // broken pipe  
674                                          {                                          {
 #ifdef _DEBUG  
                                                 log_error("read(socket) EOF\n");  
 #endif  
675                                                  sock_read_wait = 0;                                                  sock_read_wait = 0;
                                                 loop = 0;  
676                                                  break;                                                  break;
677                                          }                                          }
678                                          else                                          else if (errno == EINTR)
679                                          {                                          {
                                                 output_buf_len += ret;  
680                                                  continue;                                                  continue;
681                                          }                                          }
682                                            else
683                                            {
684                                                    log_error("read(socket) error (%d)\n", errno);
685                                                    loop = 0;
686                                                    break;
687                                            }
688                                    }
689                                    else if (ret == 0) // broken pipe
690                                    {
691    #ifdef _DEBUG
692                                            log_error("read(socket) EOF\n");
693    #endif
694                                            sock_read_wait = 0;
695                                            loop = 0;
696                                            break;
697                                    }
698                                    else
699                                    {
700                                            output_buf_len += ret;
701                                            continue;
702                                  }                                  }
703                          }                          }
704                    }
705    
706                          if (events[i].data.fd == STDOUT_FILENO || stdout_write_wait)                  if (stdout_write_wait)
707                    {
708                            if (output_buf_offset < output_buf_len)
709                          {                          {
710                                  stdout_write_wait = 1;                                  ret = io_buf_conv(output_cd, output_buf, &output_buf_len, &output_buf_offset, output_conv, sizeof(output_conv), &output_conv_len);
711                                  while (output_buf_offset < output_buf_len && !SYS_server_exit)                                  if (ret < 0)
712                                  {                                  {
713                                          if (SSH_v2)                                          log_error("io_buf_conv(output, %d, %d, %d) error\n", output_buf_len, output_buf_offset, output_conv_len);
714                                            output_buf_len = output_buf_offset; // Discard invalid sequence
715                                    }
716                            }
717    
718                            while (output_conv_offset < output_conv_len && !SYS_server_exit)
719                            {
720                                    if (SSH_v2)
721                                    {
722                                            ret = ssh_channel_write(SSH_channel, output_conv + output_conv_offset, (uint32_t)(output_conv_len - output_conv_offset));
723                                            if (ret == SSH_ERROR)
724                                          {                                          {
725                                                  ret = ssh_channel_write(SSH_channel, output_buf + output_buf_offset, (uint32_t)(output_buf_len - output_buf_offset));                                                  log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session));
726                                                  if (ret == SSH_ERROR)                                                  loop = 0;
727                                                  {                                                  break;
                                                         log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session));  
                                                         loop = 0;  
                                                         break;  
                                                 }  
728                                          }                                          }
729                                          else                                  }
730                                    else
731                                    {
732                                            ret = (int)write(STDOUT_FILENO, output_conv + output_conv_offset, (size_t)(output_conv_len - output_conv_offset));
733                                    }
734                                    if (ret < 0)
735                                    {
736                                            if (errno == EAGAIN || errno == EWOULDBLOCK)
737                                          {                                          {
738                                                  ret = (int)write(STDOUT_FILENO, output_buf + output_buf_offset, (size_t)(output_buf_len - output_buf_offset));                                                  stdout_write_wait = 0;
739                                                    break;
740                                          }                                          }
741                                          if (ret < 0)                                          else if (errno == EINTR)
742                                          {                                          {
743                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)                                                  continue;
                                                 {  
                                                         stdout_write_wait = 0;  
                                                         break;  
                                                 }  
                                                 else if (errno == EINTR)  
                                                 {  
                                                         continue;  
                                                 }  
                                                 else  
                                                 {  
                                                         log_error("write(STDOUT) error (%d)\n", errno);  
                                                         loop = 0;  
                                                         break;  
                                                 }  
744                                          }                                          }
745                                          else if (ret == 0) // broken pipe                                          else
746                                          {                                          {
747  #ifdef _DEBUG                                                  log_error("write(STDOUT) error (%d)\n", errno);
                                                 log_error("write(STDOUT) EOF\n");  
 #endif  
                                                 stdout_write_wait = 0;  
748                                                  loop = 0;                                                  loop = 0;
749                                                  break;                                                  break;
750                                          }                                          }
751                                          else                                  }
752                                    else if (ret == 0) // broken pipe
753                                    {
754    #ifdef _DEBUG
755                                            log_error("write(STDOUT) EOF\n");
756    #endif
757                                            stdout_write_wait = 0;
758                                            loop = 0;
759                                            break;
760                                    }
761                                    else
762                                    {
763                                            output_conv_offset += ret;
764                                            if (output_conv_offset >= output_conv_len) // Output buffer complete
765                                          {                                          {
766                                                  output_buf_offset += ret;                                                  output_conv_offset = 0;
767                                                  if (output_buf_offset >= output_buf_len) // Output buffer complete                                                  output_conv_len = 0;
768                                                  {                                                  break;
                                                         output_buf_offset = 0;  
                                                         output_buf_len = 0;  
                                                         break;  
                                                 }  
                                                 continue;  
769                                          }                                          }
770                                            continue;
771                                  }                                  }
772                          }                          }
773                  }                  }
774          }          }
775    
776            iconv_close(input_cd);
777            iconv_close(output_cd);
778    
779  cleanup:  cleanup:
780          if (close(epollfd) < 0)          if (close(epollfd) < 0)
781          {          {
# Line 687  cleanup: Line 801  cleanup:
801                             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,
802                             tm_used->tm_sec);                             tm_used->tm_sec);
803    
804            BBS_last_access_tm = time(NULL);
805    
806          return 0;          return 0;
807  }  }
808    
# Line 708  bbsnet_refresh() Line 824  bbsnet_refresh()
824          moveto(22, 0);          moveto(22, 0);
825          prints(" ----------------------------------------------------------------------------- ");          prints(" ----------------------------------------------------------------------------- ");
826          moveto(23, 0);          moveto(23, 0);
827          prints(" [\x1b[1;32mCtrl+C\x1b[m]退出");          prints(" [\x1b[1;32mCtrl+C\x1b[m]閫鍑");
828    
829          iflush();          iflush();
830    
# Line 721  int bbsnet_selchange() Line 837  int bbsnet_selchange()
837    
838          moveto(20, 0);          moveto(20, 0);
839          clrtoeol();          clrtoeol();
840          prints("|\x1b[1m单位:\x1b[1;33m%-18s\x1b[m  站名:\x1b[1;33m%s\x1b[m",          prints("|\x1b[1m鍗曚綅:\x1b[1;33m%-18s\x1b[m  绔欏悕:\x1b[1;33m%s\x1b[m",
841                     bbsnet_conf[i].host2, bbsnet_conf[i].host1);                     bbsnet_conf[i].host2, bbsnet_conf[i].host1);
842          moveto(20, 79);          moveto(20, 79);
843          prints("|");          prints("|");
844          moveto(21, 0);          moveto(21, 0);
845          clrtoeol();          clrtoeol();
846          prints("|\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[i].ip);          prints("|\x1b[1m杩炲線:\x1b[1;33m%-20s", bbsnet_conf[i].ip);
847          if (bbsnet_conf[i].port != 23)          if (bbsnet_conf[i].port != 23)
848          {          {
849                  prints("  %d", bbsnet_conf[i].port);                  prints("  %d", bbsnet_conf[i].port);
# Line 746  int bbs_net() Line 862  int bbs_net()
862    
863          load_bbsnet_conf(CONF_BBSNET);          load_bbsnet_conf(CONF_BBSNET);
864    
         BBS_last_access_tm = time(NULL);  
   
865          clearscr();          clearscr();
866          bbsnet_refresh();          bbsnet_refresh();
867          display_menu(&bbsnet_menu);          display_menu(&bbsnet_menu);
# Line 757  int bbs_net() Line 871  int bbs_net()
871          {          {
872                  ch = igetch(100);                  ch = igetch(100);
873    
874                    if (ch != KEY_NULL && ch != KEY_TIMEOUT)
875                    {
876                            BBS_last_access_tm = time(NULL);
877                    }
878    
879                  switch (ch)                  switch (ch)
880                  {                  {
881                  case KEY_NULL: // broken pipe                  case KEY_NULL: // broken pipe
882                  case KEY_ESC:                          log_error("KEY_NULL\n");
                 case Ctrl('C'): // user cancel  
883                          goto cleanup;                          goto cleanup;
884                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
885                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
886                          {                          {
887                                    log_error("User input timeout\n");
888                                  goto cleanup;                                  goto cleanup;
889                          }                          }
890                          continue;                          continue;
891                    case KEY_ESC:
892                    case Ctrl('C'): // user cancel
893                            goto cleanup;
894                  case CR:                  case CR:
                         igetch_reset();  
895                          bbsnet_connect(bbsnet_menu.menu_item_pos[0]);                          bbsnet_connect(bbsnet_menu.menu_item_pos[0]);
896                          bbsnet_refresh();                          bbsnet_refresh();
897                          display_menu(&bbsnet_menu);                          display_menu(&bbsnet_menu);
# Line 813  int bbs_net() Line 934  int bbs_net()
934                          bbsnet_selchange();                          bbsnet_selchange();
935                          break;                          break;
936                  }                  }
                 BBS_last_access_tm = time(NULL);  
937          }          }
938    
939  cleanup:  cleanup:


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

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