| 31 |
#include <time.h> |
#include <time.h> |
| 32 |
#include <unistd.h> |
#include <unistd.h> |
| 33 |
#include <arpa/inet.h> |
#include <arpa/inet.h> |
| 34 |
|
#include <iconv.h> |
| 35 |
#include <libssh/libssh.h> |
#include <libssh/libssh.h> |
| 36 |
#include <libssh/server.h> |
#include <libssh/server.h> |
| 37 |
#include <libssh/callbacks.h> |
#include <libssh/callbacks.h> |
| 54 |
char host2[40]; |
char host2[40]; |
| 55 |
char ip[40]; |
char ip[40]; |
| 56 |
in_port_t port; |
in_port_t port; |
| 57 |
|
char charset[20]; |
| 58 |
} bbsnet_conf[MAXSTATION]; |
} bbsnet_conf[MAXSTATION]; |
| 59 |
|
|
| 60 |
MENU_SET bbsnet_menu; |
MENU_SET bbsnet_menu; |
| 65 |
MENU *p_menu; |
MENU *p_menu; |
| 66 |
MENU_ITEM *p_menu_item; |
MENU_ITEM *p_menu_item; |
| 67 |
MENU_ITEM_ID menu_item_id; |
MENU_ITEM_ID menu_item_id; |
| 68 |
char t[256], *t1, *t2, *t3, *t4, *saveptr; |
char t[256], *t1, *t2, *t3, *t4, *t5, *saveptr; |
| 69 |
|
|
| 70 |
fp = fopen(file_config, "r"); |
fp = fopen(file_config, "r"); |
| 71 |
if (fp == NULL) |
if (fp == NULL) |
| 103 |
t2 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
t2 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 104 |
t3 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
t3 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 105 |
t4 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
t4 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 106 |
|
t5 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 107 |
|
|
| 108 |
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] == '*') |
| 109 |
{ |
{ |
| 110 |
continue; |
continue; |
| 111 |
} |
} |
| 117 |
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); |
| 118 |
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'; |
| 119 |
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); |
| 120 |
|
strncpy(bbsnet_conf[menu_item_id].charset, t5, sizeof(bbsnet_conf[menu_item_id].charset) - 1); |
| 121 |
|
bbsnet_conf[menu_item_id].charset[sizeof(bbsnet_conf[menu_item_id].charset) - 1] = '\0'; |
| 122 |
|
|
| 123 |
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); |
| 124 |
if (p_menu_item == NULL) |
if (p_menu_item == NULL) |
| 193 |
iflush(); |
iflush(); |
| 194 |
} |
} |
| 195 |
|
|
| 196 |
|
int bbsnet_io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char *p_conv, size_t conv_size, int *p_conv_len) |
| 197 |
|
{ |
| 198 |
|
char *in_buf; |
| 199 |
|
char *out_buf; |
| 200 |
|
size_t in_bytes; |
| 201 |
|
size_t out_bytes; |
| 202 |
|
int ret; |
| 203 |
|
|
| 204 |
|
in_buf = p_buf + *p_buf_offset; |
| 205 |
|
in_bytes = (size_t)(*p_buf_len - *p_buf_offset); |
| 206 |
|
out_buf = p_conv + *p_conv_len; |
| 207 |
|
out_bytes = conv_size - (size_t)(*p_conv_len); |
| 208 |
|
|
| 209 |
|
while (in_bytes > 0) |
| 210 |
|
{ |
| 211 |
|
ret = (int)iconv(cd, &in_buf, &in_bytes, &out_buf, &out_bytes); |
| 212 |
|
if (ret == -1) |
| 213 |
|
{ |
| 214 |
|
if (errno == EINVAL) // Incomplete |
| 215 |
|
{ |
| 216 |
|
*p_buf_len = (int)(p_buf + *p_buf_len - in_buf); |
| 217 |
|
*p_buf_offset = 0; |
| 218 |
|
*p_conv_len = (int)(conv_size - out_bytes); |
| 219 |
|
memmove(p_buf, in_buf, (size_t)(*p_buf_len)); |
| 220 |
|
|
| 221 |
|
break; |
| 222 |
|
} |
| 223 |
|
else if (errno == E2BIG) |
| 224 |
|
{ |
| 225 |
|
log_error("iconv(inbytes=%d, outbytes=%d) error: E2BIG\n", in_bytes, out_bytes); |
| 226 |
|
return -1; |
| 227 |
|
} |
| 228 |
|
else if (errno == EILSEQ) |
| 229 |
|
{ |
| 230 |
|
if (in_bytes > out_bytes || out_bytes <= 0) |
| 231 |
|
{ |
| 232 |
|
errno = E2BIG; |
| 233 |
|
return -1; |
| 234 |
|
} |
| 235 |
|
|
| 236 |
|
*out_buf++ = *in_buf++; |
| 237 |
|
in_bytes--; |
| 238 |
|
out_bytes--; |
| 239 |
|
|
| 240 |
|
continue; |
| 241 |
|
} |
| 242 |
|
} |
| 243 |
|
else |
| 244 |
|
{ |
| 245 |
|
*p_buf_len = 0; |
| 246 |
|
*p_buf_offset = 0; |
| 247 |
|
*p_conv_len = (int)(conv_size - out_bytes); |
| 248 |
|
|
| 249 |
|
break; |
| 250 |
|
} |
| 251 |
|
} |
| 252 |
|
|
| 253 |
|
return 0; |
| 254 |
|
} |
| 255 |
|
|
| 256 |
int bbsnet_connect(int n) |
int bbsnet_connect(int n) |
| 257 |
{ |
{ |
| 258 |
int sock, ret, loop, error; |
int sock, ret, loop, error; |
| 268 |
int output_buf_len = 0; |
int output_buf_len = 0; |
| 269 |
int input_buf_offset = 0; |
int input_buf_offset = 0; |
| 270 |
int output_buf_offset = 0; |
int output_buf_offset = 0; |
| 271 |
|
iconv_t input_cd = NULL; |
| 272 |
|
char input_conv[LINE_BUFFER_LEN * 2]; |
| 273 |
|
char output_conv[LINE_BUFFER_LEN * 2]; |
| 274 |
|
int input_conv_len = 0; |
| 275 |
|
int output_conv_len = 0; |
| 276 |
|
int input_conv_offset = 0; |
| 277 |
|
int output_conv_offset = 0; |
| 278 |
|
iconv_t output_cd = NULL; |
| 279 |
struct epoll_event ev, events[MAX_EVENTS]; |
struct epoll_event ev, events[MAX_EVENTS]; |
| 280 |
int nfds, epollfd; |
int nfds, epollfd; |
| 281 |
int stdin_read_wait = 0; |
int stdin_read_wait = 0; |
| 360 |
return -1; |
return -1; |
| 361 |
} |
} |
| 362 |
|
|
| 363 |
ev.events = EPOLLOUT; |
ev.events = EPOLLOUT | EPOLLET; |
| 364 |
ev.data.fd = sock; |
ev.data.fd = sock; |
| 365 |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev) == -1) |
| 366 |
{ |
{ |
| 368 |
goto cleanup; |
goto cleanup; |
| 369 |
} |
} |
| 370 |
|
|
| 371 |
ev.events = EPOLLIN; |
ev.events = EPOLLIN | EPOLLET; |
| 372 |
ev.data.fd = STDIN_FILENO; |
ev.data.fd = STDIN_FILENO; |
| 373 |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) == -1) |
| 374 |
{ |
{ |
| 469 |
iflush(); |
iflush(); |
| 470 |
log_common("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
log_common("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
| 471 |
|
|
| 472 |
|
input_cd = iconv_open(bbsnet_conf[n].charset, "UTF-8"); |
| 473 |
|
if (input_cd == (iconv_t)(-1)) |
| 474 |
|
{ |
| 475 |
|
log_error("iconv_open(UTF8->GBK) error: %d\n", errno); |
| 476 |
|
goto cleanup; |
| 477 |
|
} |
| 478 |
|
output_cd = iconv_open("UTF-8", bbsnet_conf[n].charset); |
| 479 |
|
if (input_cd == (iconv_t)(-1)) |
| 480 |
|
{ |
| 481 |
|
log_error("iconv_open(GBK->UTF-8) error: %d\n", errno); |
| 482 |
|
iconv_close(input_cd); |
| 483 |
|
goto cleanup; |
| 484 |
|
} |
| 485 |
|
|
| 486 |
ev.events = EPOLLIN | EPOLLOUT | EPOLLET; |
ev.events = EPOLLIN | EPOLLOUT | EPOLLET; |
| 487 |
ev.data.fd = sock; |
ev.data.fd = sock; |
| 488 |
if (epoll_ctl(epollfd, EPOLL_CTL_MOD, sock, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_MOD, sock, &ev) == -1) |
| 491 |
goto cleanup; |
goto cleanup; |
| 492 |
} |
} |
| 493 |
|
|
| 494 |
ev.events = EPOLLOUT; |
ev.events = EPOLLOUT | EPOLLET; |
| 495 |
ev.data.fd = STDOUT_FILENO; |
ev.data.fd = STDOUT_FILENO; |
| 496 |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDOUT_FILENO, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDOUT_FILENO, &ev) == -1) |
| 497 |
{ |
{ |
| 528 |
{ |
{ |
| 529 |
break; |
break; |
| 530 |
} |
} |
|
continue; |
|
| 531 |
} |
} |
| 532 |
|
|
| 533 |
for (int i = 0; i < nfds; i++) |
for (int i = 0; i < nfds; i++) |
| 534 |
{ |
{ |
| 535 |
if (events[i].data.fd == STDIN_FILENO || stdin_read_wait) |
if (events[i].data.fd == STDIN_FILENO) |
| 536 |
{ |
{ |
| 537 |
stdin_read_wait = 1; |
stdin_read_wait = 1; |
| 538 |
while (input_buf_len < sizeof(input_buf) && !SYS_server_exit) |
} |
| 539 |
|
|
| 540 |
|
if (events[i].data.fd == sock) |
| 541 |
|
{ |
| 542 |
|
if (events[i].events & EPOLLIN) |
| 543 |
|
{ |
| 544 |
|
sock_read_wait = 1; |
| 545 |
|
} |
| 546 |
|
if (events[i].events & EPOLLOUT) |
| 547 |
{ |
{ |
| 548 |
if (SSH_v2) |
sock_write_wait = 1; |
| 549 |
|
} |
| 550 |
|
} |
| 551 |
|
|
| 552 |
|
if (events[i].data.fd == STDOUT_FILENO) |
| 553 |
|
{ |
| 554 |
|
stdout_write_wait = 1; |
| 555 |
|
} |
| 556 |
|
} |
| 557 |
|
|
| 558 |
|
if (stdin_read_wait) |
| 559 |
|
{ |
| 560 |
|
while (input_buf_len < sizeof(input_buf) && !SYS_server_exit) |
| 561 |
|
{ |
| 562 |
|
if (SSH_v2) |
| 563 |
|
{ |
| 564 |
|
ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0); |
| 565 |
|
if (ret == SSH_ERROR) |
| 566 |
{ |
{ |
| 567 |
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)); |
| 568 |
if (ret == SSH_ERROR) |
loop = 0; |
| 569 |
{ |
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 |
|
|
} |
|
| 570 |
} |
} |
| 571 |
else |
else if (ret == SSH_EOF) |
| 572 |
{ |
{ |
| 573 |
ret = (int)read(STDIN_FILENO, input_buf + input_buf_len, sizeof(input_buf) - (size_t)input_buf_len); |
stdin_read_wait = 0; |
| 574 |
|
loop = 0; |
| 575 |
|
break; |
| 576 |
} |
} |
| 577 |
if (ret < 0) |
else if (ret == 0) |
| 578 |
{ |
{ |
| 579 |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
stdin_read_wait = 0; |
| 580 |
{ |
break; // Check whether channel is still open |
|
stdin_read_wait = 0; |
|
|
break; |
|
|
} |
|
|
else if (errno == EINTR) |
|
|
{ |
|
|
continue; |
|
|
} |
|
|
else |
|
|
{ |
|
|
log_error("read(STDIN) error (%d)\n", errno); |
|
|
loop = 0; |
|
|
break; |
|
|
} |
|
| 581 |
} |
} |
| 582 |
else if (ret == 0) // broken pipe |
} |
| 583 |
|
else |
| 584 |
|
{ |
| 585 |
|
ret = (int)read(STDIN_FILENO, input_buf + input_buf_len, sizeof(input_buf) - (size_t)input_buf_len); |
| 586 |
|
} |
| 587 |
|
if (ret < 0) |
| 588 |
|
{ |
| 589 |
|
if (errno == EAGAIN || errno == EWOULDBLOCK) |
| 590 |
{ |
{ |
|
#ifdef _DEBUG |
|
|
log_error("read(STDIN) EOF\n"); |
|
|
#endif |
|
| 591 |
stdin_read_wait = 0; |
stdin_read_wait = 0; |
|
loop = 0; |
|
| 592 |
break; |
break; |
| 593 |
} |
} |
| 594 |
else |
else if (errno == EINTR) |
| 595 |
{ |
{ |
|
input_buf_len += ret; |
|
|
BBS_last_access_tm = time(NULL); |
|
| 596 |
continue; |
continue; |
| 597 |
} |
} |
| 598 |
|
else |
| 599 |
|
{ |
| 600 |
|
log_error("read(STDIN) error (%d)\n", errno); |
| 601 |
|
loop = 0; |
| 602 |
|
break; |
| 603 |
|
} |
| 604 |
|
} |
| 605 |
|
else if (ret == 0) // broken pipe |
| 606 |
|
{ |
| 607 |
|
#ifdef _DEBUG |
| 608 |
|
log_error("read(STDIN) EOF\n"); |
| 609 |
|
#endif |
| 610 |
|
stdin_read_wait = 0; |
| 611 |
|
loop = 0; |
| 612 |
|
break; |
| 613 |
|
} |
| 614 |
|
else |
| 615 |
|
{ |
| 616 |
|
input_buf_len += ret; |
| 617 |
|
BBS_last_access_tm = time(NULL); |
| 618 |
|
|
| 619 |
|
// Refresh current action while user input |
| 620 |
|
if (user_online_update("BBS_NET") < 0) |
| 621 |
|
{ |
| 622 |
|
log_error("user_online_update(BBS_NET) error\n"); |
| 623 |
|
} |
| 624 |
|
|
| 625 |
|
continue; |
| 626 |
|
} |
| 627 |
|
} |
| 628 |
|
} |
| 629 |
|
|
| 630 |
|
if (sock_write_wait) |
| 631 |
|
{ |
| 632 |
|
if (input_buf_offset < input_buf_len) |
| 633 |
|
{ |
| 634 |
|
ret = bbsnet_io_buf_conv(input_cd, input_buf, &input_buf_len, &input_buf_offset, input_conv, sizeof(input_conv), &input_conv_len); |
| 635 |
|
if (ret < 0) |
| 636 |
|
{ |
| 637 |
|
log_error("bbsnet_io_buf_conv(input, %d, %d, %d) error\n", input_buf_len, input_buf_offset, input_conv_len); |
| 638 |
} |
} |
| 639 |
} |
} |
| 640 |
|
|
| 641 |
if (events[i].data.fd == sock || sock_write_wait) // EPOLLOUT |
while (input_conv_offset < input_conv_len && !SYS_server_exit) |
| 642 |
{ |
{ |
| 643 |
sock_write_wait = 1; |
ret = (int)write(sock, input_conv + input_conv_offset, (size_t)(input_conv_len - input_conv_offset)); |
| 644 |
while (input_buf_offset < input_buf_len && !SYS_server_exit) |
if (ret < 0) |
| 645 |
{ |
{ |
| 646 |
ret = (int)write(sock, input_buf + input_buf_offset, (size_t)(input_buf_len - input_buf_offset)); |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
| 647 |
if (ret < 0) |
{ |
| 648 |
|
sock_write_wait = 0; |
| 649 |
|
break; |
| 650 |
|
} |
| 651 |
|
else if (errno == EINTR) |
| 652 |
{ |
{ |
| 653 |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
continue; |
|
{ |
|
|
sock_write_wait = 0; |
|
|
break; |
|
|
} |
|
|
else if (errno == EINTR) |
|
|
{ |
|
|
continue; |
|
|
} |
|
|
else |
|
|
{ |
|
|
log_error("write(socket) error (%d)\n", errno); |
|
|
loop = 0; |
|
|
break; |
|
|
} |
|
| 654 |
} |
} |
| 655 |
else if (ret == 0) // broken pipe |
else |
| 656 |
{ |
{ |
| 657 |
#ifdef _DEBUG |
log_error("write(socket) error (%d)\n", errno); |
|
log_error("write(socket) EOF\n"); |
|
|
#endif |
|
|
sock_write_wait = 0; |
|
| 658 |
loop = 0; |
loop = 0; |
| 659 |
break; |
break; |
| 660 |
} |
} |
| 661 |
else |
} |
| 662 |
|
else if (ret == 0) // broken pipe |
| 663 |
|
{ |
| 664 |
|
#ifdef _DEBUG |
| 665 |
|
log_error("write(socket) EOF\n"); |
| 666 |
|
#endif |
| 667 |
|
sock_write_wait = 0; |
| 668 |
|
loop = 0; |
| 669 |
|
break; |
| 670 |
|
} |
| 671 |
|
else |
| 672 |
|
{ |
| 673 |
|
input_conv_offset += ret; |
| 674 |
|
if (input_conv_offset >= input_conv_len) // Output buffer complete |
| 675 |
{ |
{ |
| 676 |
input_buf_offset += ret; |
input_conv_offset = 0; |
| 677 |
if (input_buf_offset >= input_buf_len) // Output buffer complete |
input_conv_len = 0; |
| 678 |
{ |
break; |
|
input_buf_offset = 0; |
|
|
input_buf_len = 0; |
|
|
break; |
|
|
} |
|
|
continue; |
|
| 679 |
} |
} |
| 680 |
|
continue; |
| 681 |
} |
} |
| 682 |
} |
} |
| 683 |
|
} |
| 684 |
|
|
| 685 |
if (events[i].data.fd == sock || sock_read_wait) // EPOLLIN |
if (sock_read_wait) |
| 686 |
|
{ |
| 687 |
|
while (output_buf_len < sizeof(output_buf) && !SYS_server_exit) |
| 688 |
{ |
{ |
| 689 |
sock_read_wait = 1; |
ret = (int)read(sock, output_buf + output_buf_len, sizeof(output_buf) - (size_t)output_buf_len); |
| 690 |
while (output_buf_len < sizeof(output_buf) && !SYS_server_exit) |
if (ret < 0) |
| 691 |
{ |
{ |
| 692 |
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) |
|
| 693 |
{ |
{ |
|
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 |
|
|
{ |
|
|
#ifdef _DEBUG |
|
|
log_error("read(socket) EOF\n"); |
|
|
#endif |
|
| 694 |
sock_read_wait = 0; |
sock_read_wait = 0; |
|
loop = 0; |
|
| 695 |
break; |
break; |
| 696 |
} |
} |
| 697 |
else |
else if (errno == EINTR) |
| 698 |
{ |
{ |
|
output_buf_len += ret; |
|
| 699 |
continue; |
continue; |
| 700 |
} |
} |
| 701 |
|
else |
| 702 |
|
{ |
| 703 |
|
log_error("read(socket) error (%d)\n", errno); |
| 704 |
|
loop = 0; |
| 705 |
|
break; |
| 706 |
|
} |
| 707 |
|
} |
| 708 |
|
else if (ret == 0) // broken pipe |
| 709 |
|
{ |
| 710 |
|
#ifdef _DEBUG |
| 711 |
|
log_error("read(socket) EOF\n"); |
| 712 |
|
#endif |
| 713 |
|
sock_read_wait = 0; |
| 714 |
|
loop = 0; |
| 715 |
|
break; |
| 716 |
|
} |
| 717 |
|
else |
| 718 |
|
{ |
| 719 |
|
output_buf_len += ret; |
| 720 |
|
continue; |
| 721 |
} |
} |
| 722 |
} |
} |
| 723 |
|
} |
| 724 |
|
|
| 725 |
if (events[i].data.fd == STDOUT_FILENO || stdout_write_wait) |
if (stdout_write_wait) |
| 726 |
|
{ |
| 727 |
|
if (output_buf_offset < output_buf_len) |
| 728 |
{ |
{ |
| 729 |
stdout_write_wait = 1; |
ret = bbsnet_io_buf_conv(output_cd, output_buf, &output_buf_len, &output_buf_offset, output_conv, sizeof(output_conv), &output_conv_len); |
| 730 |
while (output_buf_offset < output_buf_len && !SYS_server_exit) |
if (ret < 0) |
| 731 |
{ |
{ |
| 732 |
if (SSH_v2) |
log_error("bbsnet_io_buf_conv(output, %d, %d, %d) error\n", output_buf_len, output_buf_offset, output_conv_len); |
| 733 |
|
} |
| 734 |
|
} |
| 735 |
|
|
| 736 |
|
while (output_conv_offset < output_conv_len && !SYS_server_exit) |
| 737 |
|
{ |
| 738 |
|
if (SSH_v2) |
| 739 |
|
{ |
| 740 |
|
ret = ssh_channel_write(SSH_channel, output_conv + output_conv_offset, (uint32_t)(output_conv_len - output_conv_offset)); |
| 741 |
|
if (ret == SSH_ERROR) |
| 742 |
{ |
{ |
| 743 |
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)); |
| 744 |
if (ret == SSH_ERROR) |
loop = 0; |
| 745 |
{ |
break; |
|
log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session)); |
|
|
loop = 0; |
|
|
break; |
|
|
} |
|
| 746 |
} |
} |
| 747 |
else |
} |
| 748 |
|
else |
| 749 |
|
{ |
| 750 |
|
ret = (int)write(STDOUT_FILENO, output_conv + output_conv_offset, (size_t)(output_conv_len - output_conv_offset)); |
| 751 |
|
} |
| 752 |
|
if (ret < 0) |
| 753 |
|
{ |
| 754 |
|
if (errno == EAGAIN || errno == EWOULDBLOCK) |
| 755 |
{ |
{ |
| 756 |
ret = (int)write(STDOUT_FILENO, output_buf + output_buf_offset, (size_t)(output_buf_len - output_buf_offset)); |
stdout_write_wait = 0; |
| 757 |
|
break; |
| 758 |
} |
} |
| 759 |
if (ret < 0) |
else if (errno == EINTR) |
| 760 |
{ |
{ |
| 761 |
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; |
|
|
} |
|
| 762 |
} |
} |
| 763 |
else if (ret == 0) // broken pipe |
else |
| 764 |
{ |
{ |
| 765 |
#ifdef _DEBUG |
log_error("write(STDOUT) error (%d)\n", errno); |
|
log_error("write(STDOUT) EOF\n"); |
|
|
#endif |
|
|
stdout_write_wait = 0; |
|
| 766 |
loop = 0; |
loop = 0; |
| 767 |
break; |
break; |
| 768 |
} |
} |
| 769 |
else |
} |
| 770 |
|
else if (ret == 0) // broken pipe |
| 771 |
|
{ |
| 772 |
|
#ifdef _DEBUG |
| 773 |
|
log_error("write(STDOUT) EOF\n"); |
| 774 |
|
#endif |
| 775 |
|
stdout_write_wait = 0; |
| 776 |
|
loop = 0; |
| 777 |
|
break; |
| 778 |
|
} |
| 779 |
|
else |
| 780 |
|
{ |
| 781 |
|
output_conv_offset += ret; |
| 782 |
|
if (output_conv_offset >= output_conv_len) // Output buffer complete |
| 783 |
{ |
{ |
| 784 |
output_buf_offset += ret; |
output_conv_offset = 0; |
| 785 |
if (output_buf_offset >= output_buf_len) // Output buffer complete |
output_conv_len = 0; |
| 786 |
{ |
break; |
|
output_buf_offset = 0; |
|
|
output_buf_len = 0; |
|
|
break; |
|
|
} |
|
|
continue; |
|
| 787 |
} |
} |
| 788 |
|
continue; |
| 789 |
} |
} |
| 790 |
} |
} |
| 791 |
} |
} |
| 792 |
} |
} |
| 793 |
|
|
| 794 |
|
iconv_close(input_cd); |
| 795 |
|
iconv_close(output_cd); |
| 796 |
|
|
| 797 |
cleanup: |
cleanup: |
| 798 |
if (close(epollfd) < 0) |
if (close(epollfd) < 0) |
| 799 |
{ |
{ |