Convert sftp.c to ssh_channel_read
Этот коммит содержится в:
родитель
9f7e2c3252
Коммит
c4e67730a3
28
src/sftp.c
28
src/sftp.c
@ -288,8 +288,10 @@ int sftp_packet_write(sftp_session sftp, uint8_t type, ssh_buffer payload){
|
||||
}
|
||||
|
||||
sftp_packet sftp_packet_read(sftp_session sftp) {
|
||||
unsigned char buffer[4096];
|
||||
sftp_packet packet = NULL;
|
||||
uint32_t size;
|
||||
int r;
|
||||
|
||||
sftp_enter_function();
|
||||
|
||||
@ -306,13 +308,14 @@ sftp_packet sftp_packet_read(sftp_session sftp) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (channel_read_buffer(sftp->channel, packet->payload, 4, 0) <= 0) {
|
||||
r=ssh_channel_read(sftp->channel, buffer, 4, 0);
|
||||
if (r < 0) {
|
||||
ssh_buffer_free(packet->payload);
|
||||
SAFE_FREE(packet);
|
||||
sftp_leave_function();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer_add_data(packet->payload,buffer, r);
|
||||
if (buffer_get_u32(packet->payload, &size) != sizeof(uint32_t)) {
|
||||
ssh_set_error(sftp->session, SSH_FATAL, "Short sftp packet!");
|
||||
ssh_buffer_free(packet->payload);
|
||||
@ -322,23 +325,36 @@ sftp_packet sftp_packet_read(sftp_session sftp) {
|
||||
}
|
||||
|
||||
size = ntohl(size);
|
||||
if (channel_read_buffer(sftp->channel, packet->payload, 1, 0) <= 0) {
|
||||
r=ssh_channel_read(sftp->channel, buffer, 1, 0);
|
||||
if (r <= 0) {
|
||||
/* TODO: check if there are cases where an error needs to be set here */
|
||||
ssh_buffer_free(packet->payload);
|
||||
SAFE_FREE(packet);
|
||||
sftp_leave_function();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer_add_data(packet->payload, buffer, r);
|
||||
buffer_get_u8(packet->payload, &packet->type);
|
||||
if (size > 1) {
|
||||
if (channel_read_buffer(sftp->channel, packet->payload, size - 1, 0) <= 0) {
|
||||
size=size-1;
|
||||
while (size>0){
|
||||
r=ssh_channel_read(sftp->channel,buffer,
|
||||
sizeof(buffer)>size ? size:sizeof(buffer),0);
|
||||
|
||||
if(r <= 0) {
|
||||
/* TODO: check if there are cases where an error needs to be set here */
|
||||
ssh_buffer_free(packet->payload);
|
||||
SAFE_FREE(packet);
|
||||
sftp_leave_function();
|
||||
return NULL;
|
||||
}
|
||||
if(buffer_add_data(packet->payload,buffer,r)==SSH_ERROR){
|
||||
ssh_buffer_free(packet->payload);
|
||||
SAFE_FREE(packet);
|
||||
sftp_leave_function();
|
||||
ssh_set_error_oom(sftp->session);
|
||||
return NULL;
|
||||
}
|
||||
size -= r;
|
||||
}
|
||||
|
||||
sftp_leave_function();
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user