| 64 |
static int stdin_conv_offset = 0; |
static int stdin_conv_offset = 0; |
| 65 |
static int stdout_conv_offset = 0; |
static int stdout_conv_offset = 0; |
| 66 |
|
|
| 67 |
static iconv_t stdin_cd = NULL; |
static iconv_t stdin_cd = (iconv_t)(-1); |
| 68 |
static iconv_t stdout_cd = NULL; |
static iconv_t stdout_cd = (iconv_t)(-1); |
| 69 |
|
|
| 70 |
int io_init(void) |
int io_init(void) |
| 71 |
{ |
{ |
| 308 |
ret = ssh_channel_write(SSH_channel, stdout_conv + stdout_conv_offset, (uint32_t)(stdout_conv_len - stdout_conv_offset)); |
ret = ssh_channel_write(SSH_channel, stdout_conv + stdout_conv_offset, (uint32_t)(stdout_conv_len - stdout_conv_offset)); |
| 309 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 310 |
{ |
{ |
| 311 |
|
#ifdef _DEBUG |
| 312 |
log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session)); |
log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session)); |
| 313 |
|
#endif |
| 314 |
retry = 0; |
retry = 0; |
| 315 |
break; |
break; |
| 316 |
} |
} |
| 394 |
{ |
{ |
| 395 |
if (SSH_v2 && ssh_channel_is_closed(SSH_channel)) |
if (SSH_v2 && ssh_channel_is_closed(SSH_channel)) |
| 396 |
{ |
{ |
| 397 |
|
#ifdef _DEBUG |
| 398 |
log_error("SSH channel is closed\n"); |
log_error("SSH channel is closed\n"); |
| 399 |
|
#endif |
| 400 |
loop = 0; |
loop = 0; |
| 401 |
break; |
break; |
| 402 |
} |
} |
| 454 |
ret = ssh_channel_read_nonblocking(SSH_channel, stdin_buf + stdin_buf_len, sizeof(stdin_buf) - (uint32_t)stdin_buf_len, 0); |
ret = ssh_channel_read_nonblocking(SSH_channel, stdin_buf + stdin_buf_len, sizeof(stdin_buf) - (uint32_t)stdin_buf_len, 0); |
| 455 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 456 |
{ |
{ |
| 457 |
|
#ifdef _DEBUG |
| 458 |
log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session)); |
log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session)); |
| 459 |
|
#endif |
| 460 |
loop = 0; |
loop = 0; |
| 461 |
break; |
break; |
| 462 |
} |
} |
| 1040 |
int ret; |
int ret; |
| 1041 |
int in_control = 0; |
int in_control = 0; |
| 1042 |
size_t i = 0; |
size_t i = 0; |
| 1043 |
|
int skip_current = 0; |
| 1044 |
|
|
| 1045 |
if (cd == NULL || p_buf == NULL || p_buf_len == NULL || p_buf_offset == NULL || p_conv == NULL || p_conv_len == NULL) |
if (cd == NULL || p_buf == NULL || p_buf_len == NULL || p_buf_offset == NULL || p_conv == NULL || p_conv_len == NULL) |
| 1046 |
{ |
{ |
| 1064 |
} |
} |
| 1065 |
} |
} |
| 1066 |
|
|
| 1067 |
if (in_control) |
if (in_control || skip_current) |
| 1068 |
{ |
{ |
| 1069 |
|
skip_current = 0; |
| 1070 |
|
|
| 1071 |
if (out_bytes <= 0) |
if (out_bytes <= 0) |
| 1072 |
{ |
{ |
| 1073 |
log_error("No enough free space in p_conv, conv_len=%d, conv_size=%d\n", *p_conv_len, conv_size); |
log_error("No enough free space in p_conv, conv_len=%d, conv_size=%d\n", *p_conv_len, conv_size); |
| 1081 |
out_bytes--; |
out_bytes--; |
| 1082 |
|
|
| 1083 |
(*p_buf_offset)++; |
(*p_buf_offset)++; |
| 1084 |
*p_conv_len = (int)(conv_size - out_bytes); |
(*p_conv_len)++; |
| 1085 |
|
|
| 1086 |
i++; |
i++; |
| 1087 |
if (i >= 2) |
if (i >= 2) |
| 1101 |
#endif |
#endif |
| 1102 |
if (p_buf != in_buf) |
if (p_buf != in_buf) |
| 1103 |
{ |
{ |
| 1104 |
*p_buf_len = (int)(p_buf + *p_buf_len - in_buf); |
*p_buf_len -= (int)(in_buf - p_buf); |
| 1105 |
*p_buf_offset = 0; |
*p_buf_offset = 0; |
| 1106 |
*p_conv_len = (int)(conv_size - out_bytes); |
*p_conv_len = (int)(conv_size - out_bytes); |
| 1107 |
memmove(p_buf, in_buf, (size_t)(*p_buf_len)); |
memmove(p_buf, in_buf, (size_t)(*p_buf_len)); |
| 1126 |
if (in_bytes == 0) |
if (in_bytes == 0) |
| 1127 |
{ |
{ |
| 1128 |
in_bytes = (size_t)(*p_buf_len - *p_buf_offset); |
in_bytes = (size_t)(*p_buf_len - *p_buf_offset); |
| 1129 |
|
#ifdef _DEBUG |
| 1130 |
|
log_error("Reset in_bytes from 0 to %d\n", in_bytes); |
| 1131 |
|
#endif |
| 1132 |
} |
} |
| 1133 |
|
|
| 1134 |
*out_buf = *in_buf; |
#ifdef _DEBUG |
| 1135 |
in_buf++; |
log_error("iconv(in_bytes=%d, out_bytes=%d) error: EILSEQ, in_buf[0]=%d\n", |
| 1136 |
out_buf++; |
in_bytes, out_bytes, in_buf[0]); |
| 1137 |
in_bytes--; |
#endif |
| 1138 |
out_bytes--; |
skip_current = 1; |
| 1139 |
|
} |
| 1140 |
continue; |
else // something strange |
| 1141 |
|
{ |
| 1142 |
|
#ifdef _DEBUG |
| 1143 |
|
log_error("iconv(in_bytes=%d, out_bytes=%d) error: %d, in_buf[0]=%d\n", |
| 1144 |
|
in_bytes, out_bytes, errno, in_buf[0]); |
| 1145 |
|
#endif |
| 1146 |
|
*p_buf_offset = (int)(in_buf - p_buf); |
| 1147 |
|
*p_conv_len = (int)(conv_size - out_bytes); |
| 1148 |
|
skip_current = 1; |
| 1149 |
} |
} |
| 1150 |
} |
} |
| 1151 |
else |
else |
| 1152 |
{ |
{ |
| 1153 |
*p_buf_len = 0; |
*p_buf_offset = (int)(in_buf - p_buf); |
|
*p_buf_offset = 0; |
|
| 1154 |
*p_conv_len = (int)(conv_size - out_bytes); |
*p_conv_len = (int)(conv_size - out_bytes); |
|
|
|
|
break; |
|
| 1155 |
} |
} |
| 1156 |
} |
} |
| 1157 |
|
|
| 1158 |
|
if (*p_buf_offset >= *p_buf_len) |
| 1159 |
|
{ |
| 1160 |
|
*p_buf_len = 0; |
| 1161 |
|
*p_buf_offset = 0; |
| 1162 |
|
} |
| 1163 |
|
|
| 1164 |
return 0; |
return 0; |
| 1165 |
} |
} |
| 1166 |
|
|
| 1195 |
{ |
{ |
| 1196 |
log_error("iconv_open(%s->%s) error: %d\n", BBS_default_charset, tocode, errno); |
log_error("iconv_open(%s->%s) error: %d\n", BBS_default_charset, tocode, errno); |
| 1197 |
iconv_close(stdin_cd); |
iconv_close(stdin_cd); |
| 1198 |
|
stdin_cd = (iconv_t)(-1); |
| 1199 |
return -2; |
return -2; |
| 1200 |
} |
} |
| 1201 |
|
|
| 1204 |
|
|
| 1205 |
int io_conv_cleanup(void) |
int io_conv_cleanup(void) |
| 1206 |
{ |
{ |
| 1207 |
if (stdin_cd != NULL) |
if (stdin_cd != (iconv_t)(-1)) |
| 1208 |
{ |
{ |
| 1209 |
iconv_close(stdin_cd); |
iconv_close(stdin_cd); |
| 1210 |
stdin_cd = NULL; |
stdin_cd = (iconv_t)(-1); |
| 1211 |
} |
} |
| 1212 |
if (stdout_cd != NULL) |
if (stdout_cd != (iconv_t)(-1)) |
| 1213 |
{ |
{ |
| 1214 |
iconv_close(stdout_cd); |
iconv_close(stdout_cd); |
| 1215 |
stdout_cd = NULL; |
stdout_cd = (iconv_t)(-1); |
| 1216 |
} |
} |
| 1217 |
|
|
| 1218 |
return 0; |
return 0; |