mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-27 13:21:11 +03:00
channels: Reformat channel_rcv_change_window
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
This commit is contained in:
188
src/channels.c
188
src/channels.c
@@ -556,110 +556,114 @@ SSH_PACKET_CALLBACK(channel_rcv_change_window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* is_stderr is set to 1 if the data are extended, ie stderr */
|
/* is_stderr is set to 1 if the data are extended, ie stderr */
|
||||||
SSH_PACKET_CALLBACK(channel_rcv_data){
|
SSH_PACKET_CALLBACK(channel_rcv_data)
|
||||||
ssh_channel channel;
|
{
|
||||||
ssh_string str;
|
ssh_channel channel = NULL;
|
||||||
ssh_buffer buf;
|
ssh_string str = NULL;
|
||||||
uint32_t len;
|
ssh_buffer buf = NULL;
|
||||||
int is_stderr;
|
void *data = NULL;
|
||||||
int rest;
|
uint32_t len;
|
||||||
(void)user;
|
int is_stderr;
|
||||||
|
int rest;
|
||||||
|
|
||||||
if(type==SSH2_MSG_CHANNEL_DATA)
|
(void)user;
|
||||||
is_stderr=0;
|
|
||||||
else
|
|
||||||
is_stderr=1;
|
|
||||||
|
|
||||||
channel = channel_from_msg(session,packet);
|
if (type == SSH2_MSG_CHANNEL_DATA) {
|
||||||
if (channel == NULL) {
|
is_stderr = 0;
|
||||||
SSH_LOG(SSH_LOG_FUNCTIONS,
|
} else {
|
||||||
"%s", ssh_get_error(session));
|
is_stderr = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return SSH_PACKET_USED;
|
channel = channel_from_msg(session, packet);
|
||||||
}
|
if (channel == NULL) {
|
||||||
|
SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
|
||||||
|
|
||||||
if (is_stderr) {
|
return SSH_PACKET_USED;
|
||||||
uint32_t ignore;
|
}
|
||||||
/* uint32 data type code. we can ignore it */
|
|
||||||
ssh_buffer_get_u32(packet, &ignore);
|
|
||||||
}
|
|
||||||
|
|
||||||
str = ssh_buffer_get_ssh_string(packet);
|
if (is_stderr) {
|
||||||
if (str == NULL) {
|
uint32_t ignore;
|
||||||
SSH_LOG(SSH_LOG_PACKET, "Invalid data packet!");
|
/* uint32 data type code. we can ignore it */
|
||||||
|
ssh_buffer_get_u32(packet, &ignore);
|
||||||
|
}
|
||||||
|
|
||||||
return SSH_PACKET_USED;
|
str = ssh_buffer_get_ssh_string(packet);
|
||||||
}
|
if (str == NULL) {
|
||||||
len = ssh_string_len(str);
|
SSH_LOG(SSH_LOG_PACKET, "Invalid data packet!");
|
||||||
|
|
||||||
SSH_LOG(SSH_LOG_PACKET,
|
return SSH_PACKET_USED;
|
||||||
"Channel receiving %" PRIu32 " bytes data in %d (local win=%" PRIu32 " remote win=%" PRIu32 ")",
|
}
|
||||||
len,
|
len = ssh_string_len(str);
|
||||||
is_stderr,
|
|
||||||
channel->local_window,
|
|
||||||
channel->remote_window);
|
|
||||||
|
|
||||||
/* What shall we do in this case? Let's accept it anyway */
|
SSH_LOG(SSH_LOG_PACKET,
|
||||||
if (len > channel->local_window) {
|
"Channel receiving %" PRIu32 " bytes data in %d (local win=%" PRIu32
|
||||||
SSH_LOG(SSH_LOG_RARE,
|
" remote win=%" PRIu32 ")",
|
||||||
"Data packet too big for our window(%" PRIu32 " vs %" PRIu32 ")",
|
len,
|
||||||
len,
|
is_stderr,
|
||||||
channel->local_window);
|
channel->local_window,
|
||||||
}
|
channel->remote_window);
|
||||||
|
|
||||||
|
/* What shall we do in this case? Let's accept it anyway */
|
||||||
|
if (len > channel->local_window) {
|
||||||
|
SSH_LOG(SSH_LOG_RARE,
|
||||||
|
"Data packet too big for our window(%" PRIu32 " vs %" PRIu32 ")",
|
||||||
|
len,
|
||||||
|
channel->local_window);
|
||||||
|
}
|
||||||
|
|
||||||
|
data = ssh_string_data(str);
|
||||||
|
if (channel_default_bufferize(channel, data, len, is_stderr) < 0) {
|
||||||
|
SSH_STRING_FREE(str);
|
||||||
|
|
||||||
|
return SSH_PACKET_USED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len <= channel->local_window) {
|
||||||
|
channel->local_window -= len;
|
||||||
|
} else {
|
||||||
|
channel->local_window = 0; /* buggy remote */
|
||||||
|
}
|
||||||
|
|
||||||
|
SSH_LOG(SSH_LOG_PACKET,
|
||||||
|
"Channel windows are now (local win=%" PRIu32 " remote win=%" PRIu32 ")",
|
||||||
|
channel->local_window,
|
||||||
|
channel->remote_window);
|
||||||
|
|
||||||
if (channel_default_bufferize(channel, ssh_string_data(str), len,
|
|
||||||
is_stderr) < 0) {
|
|
||||||
SSH_STRING_FREE(str);
|
SSH_STRING_FREE(str);
|
||||||
|
|
||||||
|
if (is_stderr) {
|
||||||
|
buf = channel->stderr_buffer;
|
||||||
|
} else {
|
||||||
|
buf = channel->stdout_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_callbacks_iterate(channel->callbacks,
|
||||||
|
ssh_channel_callbacks,
|
||||||
|
channel_data_function) {
|
||||||
|
if (ssh_buffer_get(buf) == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rest = ssh_callbacks_iterate_exec(channel_data_function,
|
||||||
|
channel->session,
|
||||||
|
channel,
|
||||||
|
ssh_buffer_get(buf),
|
||||||
|
ssh_buffer_get_len(buf),
|
||||||
|
is_stderr);
|
||||||
|
if (rest > 0) {
|
||||||
|
if (channel->counter != NULL) {
|
||||||
|
channel->counter->in_bytes += rest;
|
||||||
|
}
|
||||||
|
ssh_buffer_pass_bytes(buf, rest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ssh_callbacks_iterate_end();
|
||||||
|
|
||||||
|
if (channel->local_window + ssh_buffer_get_len(buf) < WINDOWLIMIT) {
|
||||||
|
if (grow_window(session, channel, 0) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
return SSH_PACKET_USED;
|
return SSH_PACKET_USED;
|
||||||
}
|
|
||||||
|
|
||||||
if (len <= channel->local_window) {
|
|
||||||
channel->local_window -= len;
|
|
||||||
} else {
|
|
||||||
channel->local_window = 0; /* buggy remote */
|
|
||||||
}
|
|
||||||
|
|
||||||
SSH_LOG(SSH_LOG_PACKET,
|
|
||||||
"Channel windows are now (local win=%" PRIu32 " remote win=%" PRIu32 ")",
|
|
||||||
channel->local_window,
|
|
||||||
channel->remote_window);
|
|
||||||
|
|
||||||
SSH_STRING_FREE(str);
|
|
||||||
|
|
||||||
if (is_stderr) {
|
|
||||||
buf = channel->stderr_buffer;
|
|
||||||
} else {
|
|
||||||
buf = channel->stdout_buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssh_callbacks_iterate(channel->callbacks,
|
|
||||||
ssh_channel_callbacks,
|
|
||||||
channel_data_function) {
|
|
||||||
if (ssh_buffer_get(buf) == NULL) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
rest = ssh_callbacks_iterate_exec(channel_data_function,
|
|
||||||
channel->session,
|
|
||||||
channel,
|
|
||||||
ssh_buffer_get(buf),
|
|
||||||
ssh_buffer_get_len(buf),
|
|
||||||
is_stderr);
|
|
||||||
if (rest > 0) {
|
|
||||||
if (channel->counter != NULL) {
|
|
||||||
channel->counter->in_bytes += rest;
|
|
||||||
}
|
|
||||||
ssh_buffer_pass_bytes(buf, rest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ssh_callbacks_iterate_end();
|
|
||||||
|
|
||||||
if (channel->local_window + ssh_buffer_get_len(buf) < WINDOWLIMIT) {
|
|
||||||
if (grow_window(session, channel, 0) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return SSH_PACKET_USED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SSH_PACKET_CALLBACK(channel_rcv_eof) {
|
SSH_PACKET_CALLBACK(channel_rcv_eof) {
|
||||||
|
|||||||
Reference in New Issue
Block a user