/[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.44 by sysadm, Thu May 15 09:15:52 2025 UTC Revision 1.47 by sysadm, Thu Jun 5 05:24:56 2025 UTC
# Line 36  Line 36 
36  #include <netinet/in.h>  #include <netinet/in.h>
37  #include <netinet/ip.h>  #include <netinet/ip.h>
38  #include <arpa/inet.h>  #include <arpa/inet.h>
39    #include <libssh/libssh.h>
40    #include <libssh/server.h>
41    #include <libssh/callbacks.h>
42    
43  #define MENU_CONF_DELIM " \t\r\n"  #define MENU_CONF_DELIM " \t\r\n"
44    
# Line 357  int bbsnet_connect(int n) Line 360  int bbsnet_connect(int n)
360                                  else if (events[i].data.fd == STDIN_FILENO)                                  else if (events[i].data.fd == STDIN_FILENO)
361                                  {                                  {
362                                          ch = igetch(0);                                          ch = igetch(0);
363                                          if (ch == Ctrl('C'))                                          if (ch == Ctrl('C') || ch == KEY_ESC)
364                                          {                                          {
365                                                  goto cleanup;                                                  goto cleanup;
366                                          }                                          }
# Line 385  int bbsnet_connect(int n) Line 388  int bbsnet_connect(int n)
388    
389          prints("\033[1;31m连接成功!\033[m\r\n");          prints("\033[1;31m连接成功!\033[m\r\n");
390          iflush();          iflush();
391          log_std("BBSNET connect to %s:%d\n", remote_addr, remote_port);          log_common("BBSNET connect to %s:%d\n", remote_addr, remote_port);
392    
393          ev.events = EPOLLIN | EPOLLOUT | EPOLLET;          ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
394          ev.data.fd = sock;          ev.data.fd = sock;
# Line 408  int bbsnet_connect(int n) Line 411  int bbsnet_connect(int n)
411    
412          while (loop && !SYS_server_exit)          while (loop && !SYS_server_exit)
413          {          {
414                    if (SSH_v2 && ssh_channel_is_closed(SSH_channel))
415                    {
416                            log_error("SSH channel is closed\n");
417                            loop = 0;
418                            break;
419                    }
420    
421                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second
422    
423                  if (nfds < 0)                  if (nfds < 0)
# Line 435  int bbsnet_connect(int n) Line 445  int bbsnet_connect(int n)
445                                  stdin_read_wait = 1;                                  stdin_read_wait = 1;
446                                  while (input_buf_len < sizeof(input_buf) && !SYS_server_exit)                                  while (input_buf_len < sizeof(input_buf) && !SYS_server_exit)
447                                  {                                  {
448                                          ret = (int)read(STDIN_FILENO, input_buf + input_buf_len, sizeof(input_buf) - (size_t)input_buf_len);                                          if (SSH_v2)
449                                            {
450                                                    ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0);
451                                                    if (ret == SSH_ERROR)
452                                                    {
453                                                            log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session));
454                                                            loop = 0;
455                                                            break;
456                                                    }
457                                                    else if (ret == SSH_EOF)
458                                                    {
459                                                            stdin_read_wait = 0;
460                                                            loop = 0;
461                                                            break;
462                                                    }
463                                                    else if (ret == 0)
464                                                    {
465                                                            stdin_read_wait = 0;
466                                                            break; // Check whether channel is still open
467                                                    }
468                                            }
469                                            else
470                                            {
471                                                    ret = (int)read(STDIN_FILENO, input_buf + input_buf_len, sizeof(input_buf) - (size_t)input_buf_len);
472                                            }
473                                          if (ret < 0)                                          if (ret < 0)
474                                          {                                          {
475                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)
# Line 456  int bbsnet_connect(int n) Line 490  int bbsnet_connect(int n)
490                                          }                                          }
491                                          else if (ret == 0) // broken pipe                                          else if (ret == 0) // broken pipe
492                                          {                                          {
493                                                  log_std("read(STDIN) EOF\n");                                                  log_common("read(STDIN) EOF\n");
494                                                  stdin_read_wait = 0;                                                  stdin_read_wait = 0;
495                                                  loop = 0;                                                  loop = 0;
496                                                  break;                                                  break;
# Line 496  int bbsnet_connect(int n) Line 530  int bbsnet_connect(int n)
530                                          }                                          }
531                                          else if (ret == 0) // broken pipe                                          else if (ret == 0) // broken pipe
532                                          {                                          {
533                                                  log_std("write(socket) EOF\n");                                                  log_common("write(socket) EOF\n");
534                                                  sock_write_wait = 0;                                                  sock_write_wait = 0;
535                                                  loop = 0;                                                  loop = 0;
536                                                  break;                                                  break;
# Line 541  int bbsnet_connect(int n) Line 575  int bbsnet_connect(int n)
575                                          }                                          }
576                                          else if (ret == 0) // broken pipe                                          else if (ret == 0) // broken pipe
577                                          {                                          {
578                                                  log_std("read(socket) EOF\n");                                                  log_common("read(socket) EOF\n");
579                                                  sock_read_wait = 0;                                                  sock_read_wait = 0;
580                                                  loop = 0;                                                  loop = 0;
581                                                  break;                                                  break;
# Line 559  int bbsnet_connect(int n) Line 593  int bbsnet_connect(int n)
593                                  stdout_write_wait = 1;                                  stdout_write_wait = 1;
594                                  while (output_buf_offset < output_buf_len && !SYS_server_exit)                                  while (output_buf_offset < output_buf_len && !SYS_server_exit)
595                                  {                                  {
596                                          ret = (int)write(STDOUT_FILENO, output_buf + output_buf_offset, (size_t)(output_buf_len - output_buf_offset));                                          if (SSH_v2)
597                                            {
598                                                    ret = ssh_channel_write(SSH_channel, output_buf + output_buf_offset, (uint32_t)(output_buf_len - output_buf_offset));
599                                                    if (ret == SSH_ERROR)
600                                                    {
601                                                            log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session));
602                                                            loop = 0;
603                                                            break;
604                                                    }
605                                            }
606                                            else
607                                            {
608                                                    ret = (int)write(STDOUT_FILENO, output_buf + output_buf_offset, (size_t)(output_buf_len - output_buf_offset));
609                                            }
610                                          if (ret < 0)                                          if (ret < 0)
611                                          {                                          {
612                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)
# Line 580  int bbsnet_connect(int n) Line 627  int bbsnet_connect(int n)
627                                          }                                          }
628                                          else if (ret == 0) // broken pipe                                          else if (ret == 0) // broken pipe
629                                          {                                          {
630                                                  log_std("write(STDOUT) EOF\n");                                                  log_common("write(STDOUT) EOF\n");
631                                                  stdout_write_wait = 0;                                                  stdout_write_wait = 0;
632                                                  loop = 0;                                                  loop = 0;
633                                                  break;                                                  break;
# Line 622  cleanup: Line 669  cleanup:
669          t_used = time(0) - t_used;          t_used = time(0) - t_used;
670          tm_used = gmtime(&t_used);          tm_used = gmtime(&t_used);
671    
672          log_std("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n",          log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n",
673                          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,
674                          tm_used->tm_sec);                             tm_used->tm_sec);
675    
676          return 0;          return 0;
677  }  }
# Line 697  int bbs_net() Line 744  int bbs_net()
744                  ch = igetch(100);                  ch = igetch(100);
745                  switch (ch)                  switch (ch)
746                  {                  {
747                  case KEY_NULL:  // broken pipe                  case KEY_NULL: // broken pipe
748                    case KEY_ESC:
749                  case Ctrl('C'): // user cancel                  case Ctrl('C'): // user cancel
750                          goto cleanup;                          goto cleanup;
751                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:


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

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