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

Diff of /lbbs/src/io.c

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

Revision 1.34 by sysadm, Tue May 20 12:07:06 2025 UTC Revision 1.41 by sysadm, Mon Jun 9 15:39:05 2025 UTC
# Line 27  Line 27 
27  #include <sys/select.h>  #include <sys/select.h>
28  #include <sys/ioctl.h>  #include <sys/ioctl.h>
29  #include <sys/epoll.h>  #include <sys/epoll.h>
30    #include <libssh/libssh.h>
31    #include <libssh/server.h>
32    #include <libssh/callbacks.h>
33    
34  static char stdout_buf[BUFSIZ];  static char stdout_buf[BUFSIZ];
35  static int stdout_buf_len = 0;  static int stdout_buf_len = 0;
# Line 58  int prints(const char *format, ...) Line 61  int prints(const char *format, ...)
61                  {                  {
62                          errno = EAGAIN;                          errno = EAGAIN;
63                          ret = (BUFSIZ - stdout_buf_len - ret);                          ret = (BUFSIZ - stdout_buf_len - ret);
64                            log_error("Output buffer is full, additional %d is required\n", ret);
65                  }                  }
66          }          }
67    
# Line 146  int iflush() Line 150  int iflush()
150                          {                          {
151                                  while (stdout_buf_offset < stdout_buf_len && !SYS_server_exit) // write until complete or error                                  while (stdout_buf_offset < stdout_buf_len && !SYS_server_exit) // write until complete or error
152                                  {                                  {
153                                          ret = (int)write(STDOUT_FILENO, stdout_buf + stdout_buf_offset, (size_t)(stdout_buf_len - stdout_buf_offset));                                          if (SSH_v2)
154                                            {
155                                                    ret = ssh_channel_write(SSH_channel, stdout_buf + stdout_buf_offset, (uint32_t)(stdout_buf_len - stdout_buf_offset));
156                                                    if (ret == SSH_ERROR)
157                                                    {
158                                                            log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session));
159                                                            retry = 0;
160                                                            break;
161                                                    }
162                                            }
163                                            else
164                                            {
165                                                    ret = (int)write(STDOUT_FILENO, stdout_buf + stdout_buf_offset, (size_t)(stdout_buf_len - stdout_buf_offset));
166                                            }
167                                          if (ret < 0)                                          if (ret < 0)
168                                          {                                          {
169                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)
# Line 248  int igetch(int timeout) Line 265  int igetch(int timeout)
265                  len = 0;                  len = 0;
266                  pos = 0;                  pos = 0;
267    
268                    if (SSH_v2 && ssh_channel_is_closed(SSH_channel))
269                    {
270                            log_error("SSH channel is closed\n");
271                            loop = 0;
272                            break;
273                    }
274    
275                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, timeout);                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, timeout);
276    
277                  if (nfds < 0)                  if (nfds < 0)
# Line 271  int igetch(int timeout) Line 295  int igetch(int timeout)
295                          {                          {
296                                  while (len < sizeof(buf) && !SYS_server_exit) // read until complete or error                                  while (len < sizeof(buf) && !SYS_server_exit) // read until complete or error
297                                  {                                  {
298                                          ret = (int)read(STDIN_FILENO, buf + len, sizeof(buf) - (size_t)len);                                          if (SSH_v2)
299                                            {
300                                                    ret = ssh_channel_read_nonblocking(SSH_channel, buf + len, sizeof(buf) - (uint32_t)len, 0);
301                                                    if (ret == SSH_ERROR)
302                                                    {
303                                                            log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session));
304                                                            loop = 0;
305                                                            break;
306                                                    }
307                                                    else if (ret == SSH_EOF)
308                                                    {
309                                                            loop = 0;
310                                                            break;
311                                                    }
312                                                    else if (ret == 0)
313                                                    {
314                                                            out = 0;
315                                                            break; // Check whether channel is still open
316                                                    }
317                                            }
318                                            else
319                                            {
320                                                    ret = (int)read(STDIN_FILENO, buf + len, sizeof(buf) - (size_t)len);
321                                            }
322                                          if (ret < 0)                                          if (ret < 0)
323                                          {                                          {
324                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)
# Line 308  int igetch(int timeout) Line 355  int igetch(int timeout)
355                  // For debug                  // For debug
356                  // for (int j = pos; j < len; j++)                  // for (int j = pos; j < len; j++)
357                  // {                  // {
358                  //      log_std("Debug: <--[%u]\n", (buf[j] + 256) % 256);                  //      log_common("Debug: <--[%u]\n", (buf[j] + 256) % 256);
359                  // }                  // }
360          }          }
361    
# Line 340  int igetch(int timeout) Line 387  int igetch(int timeout)
387                          continue;                          continue;
388                  }                  }
389    
390                  if (c == ESC_KEY)                  if (c == KEY_ESC)
391                  {                  {
392                          if (in_esc == 0)                          if (in_esc == 0)
393                          {                          {
# Line 351  int igetch(int timeout) Line 398  int igetch(int timeout)
398                          }                          }
399                          else                          else
400                          {                          {
401                                  out = ESC_KEY;                                  out = KEY_CSI;
402                                  in_esc = 0;                                  in_esc = 0;
403                                  break;                                  break;
404                          }                          }
# Line 507  int igetch(int timeout) Line 554  int igetch(int timeout)
554                                          break;                                          break;
555                                  }                                  }
556                          }                          }
557                          if (i == 4 && tmp[0] == 91 && tmp[1] == 49 && tmp[3] == 126)  // Fterm                          if (i == 4 && tmp[0] == 91 && tmp[1] == 49 && tmp[3] == 126) // Fterm
558                          {                          {
559                                  in_ascii = 0;                                  in_ascii = 0;
560                                  switch (tmp[2])                                  switch (tmp[2])
# Line 577  int igetch(int timeout) Line 624  int igetch(int timeout)
624                                  in_ascii = 0;                                  in_ascii = 0;
625                                  switch (tmp[4])                                  switch (tmp[4])
626                                  {                                  {
627                                    case 65:
628                                            out = KEY_CTRL_UP;
629                                            break;
630                                    case 66:
631                                            out = KEY_CTRL_DOWN;
632                                            break;
633                                    case 67:
634                                            out = KEY_CTRL_RIGHT;
635                                            break;
636                                    case 68:
637                                            out = KEY_CTRL_LEFT;
638                                            break;
639                                    case 70:
640                                            out = KEY_CTRL_END;
641                                            break;
642                                    case 72:
643                                            out = KEY_CTRL_HOME;
644                                            break;
645                                  case 80:                                  case 80:
646                                          out = KEY_CTRL_F1;                                          out = KEY_CTRL_F1;
647                                          break;                                          break;
# Line 736  int igetch(int timeout) Line 801  int igetch(int timeout)
801                  log_error("close(epoll) error (%d)\n");                  log_error("close(epoll) error (%d)\n");
802          }          }
803    
804            // For ESC key
805            if (out == 0 && in_esc)
806            {
807                    out = KEY_ESC;
808            }
809    
810          // for debug          // for debug
811          // if (out != KEY_TIMEOUT && out != KEY_NULL)          // if (out != KEY_TIMEOUT && out != KEY_NULL)
812          // {          // {
813          //      log_std ("Debug: -->[0x %x]\n", out);          //      log_common("Debug: -->[0x %x]\n", out);
814          // }          // }
815    
816          return out;          return out;


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

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