mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-03 13:31:11 +03:00
channel: Refactor channel_write_common() code.
This makes it easier to read and easier to debug.
This commit is contained in:
@@ -1287,8 +1287,8 @@ static int channel_write_common(ssh_channel channel,
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
|
|
||||||
|
|
||||||
|
if (channel->session->session_state == SSH_SESSION_STATE_ERROR) {
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
#ifdef WITH_SSH1
|
#ifdef WITH_SSH1
|
||||||
@@ -1328,27 +1328,45 @@ static int channel_write_common(ssh_channel channel,
|
|||||||
|
|
||||||
effectivelen = MIN(effectivelen, maxpacketlen);;
|
effectivelen = MIN(effectivelen, maxpacketlen);;
|
||||||
|
|
||||||
if (buffer_add_u8(session->out_buffer, is_stderr ?
|
rc = buffer_add_u8(session->out_buffer,
|
||||||
SSH2_MSG_CHANNEL_EXTENDED_DATA : SSH2_MSG_CHANNEL_DATA) < 0 ||
|
is_stderr ? SSH2_MSG_CHANNEL_EXTENDED_DATA
|
||||||
buffer_add_u32(session->out_buffer,
|
: SSH2_MSG_CHANNEL_DATA);
|
||||||
htonl(channel->remote_channel)) < 0) {
|
if (rc < 0) {
|
||||||
ssh_set_error_oom(session);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
/* stderr message has an extra field */
|
|
||||||
if (is_stderr &&
|
|
||||||
buffer_add_u32(session->out_buffer, htonl(SSH2_EXTENDED_DATA_STDERR)) < 0) {
|
|
||||||
ssh_set_error_oom(session);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
/* append payload data */
|
|
||||||
if (buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
|
|
||||||
buffer_add_data(session->out_buffer, data, effectivelen) < 0) {
|
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet_send(session) == SSH_ERROR) {
|
rc = buffer_add_u32(session->out_buffer, htonl(channel->remote_channel));
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* stderr message has an extra field */
|
||||||
|
if (is_stderr) {
|
||||||
|
rc = buffer_add_u32(session->out_buffer,
|
||||||
|
htonl(SSH2_EXTENDED_DATA_STDERR));
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* append payload data */
|
||||||
|
rc = buffer_add_u32(session->out_buffer, htonl(effectivelen));
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = buffer_add_data(session->out_buffer, data, effectivelen);
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = packet_send(session);
|
||||||
|
if (rc == SSH_ERROR) {
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1359,10 +1377,13 @@ static int channel_write_common(ssh_channel channel,
|
|||||||
len -= effectivelen;
|
len -= effectivelen;
|
||||||
data = ((uint8_t*)data + effectivelen);
|
data = ((uint8_t*)data + effectivelen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* it's a good idea to flush the socket now */
|
/* it's a good idea to flush the socket now */
|
||||||
rc = ssh_channel_flush(channel);
|
rc = ssh_channel_flush(channel);
|
||||||
if(rc == SSH_ERROR)
|
if (rc == SSH_ERROR) {
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return (int)(origlen - len);
|
return (int)(origlen - len);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user