summaryrefslogtreecommitdiffstats
path: root/src/channels.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-08-13 08:22:28 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-08-13 08:22:28 +0200
commitfc8081cd066c077c24a63dcdf78817bd505f5425 (patch)
tree34b73d077649336e419e32f9009a7398d713dcf4 /src/channels.c
parent7a64dd1b9a1cc958218a1e52a87c35d1bb6ed456 (diff)
downloadlibssh-fc8081cd066c077c24a63dcdf78817bd505f5425.tar.gz
libssh-fc8081cd066c077c24a63dcdf78817bd505f5425.tar.xz
libssh-fc8081cd066c077c24a63dcdf78817bd505f5425.zip
channel: Refactor channel_write_common() code.
This makes it easier to read and easier to debug.
Diffstat (limited to 'src/channels.c')
-rw-r--r--src/channels.c53
1 files changed, 37 insertions, 16 deletions
diff --git a/src/channels.c b/src/channels.c
index ffb087c..f4376e8 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -1287,8 +1287,8 @@ static int channel_write_common(ssh_channel channel,
return -1;
}
- if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
+ if (channel->session->session_state == SSH_SESSION_STATE_ERROR) {
return SSH_ERROR;
}
#ifdef WITH_SSH1
@@ -1328,28 +1328,46 @@ static int channel_write_common(ssh_channel channel,
effectivelen = MIN(effectivelen, maxpacketlen);;
- if (buffer_add_u8(session->out_buffer, is_stderr ?
- SSH2_MSG_CHANNEL_EXTENDED_DATA : SSH2_MSG_CHANNEL_DATA) < 0 ||
- buffer_add_u32(session->out_buffer,
- htonl(channel->remote_channel)) < 0) {
+ rc = buffer_add_u8(session->out_buffer,
+ is_stderr ? SSH2_MSG_CHANNEL_EXTENDED_DATA
+ : SSH2_MSG_CHANNEL_DATA);
+ 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) {
+
+ 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 */
- if (buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
- buffer_add_data(session->out_buffer, data, effectivelen) < 0) {
- ssh_set_error_oom(session);
- goto error;
+ rc = buffer_add_u32(session->out_buffer, htonl(effectivelen));
+ if (rc < 0) {
+ ssh_set_error_oom(session);
+ goto error;
}
- if (packet_send(session) == SSH_ERROR) {
- return SSH_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;
}
SSH_LOG(SSH_LOG_RARE,
@@ -1359,10 +1377,13 @@ static int channel_write_common(ssh_channel channel,
len -= effectivelen;
data = ((uint8_t*)data + effectivelen);
}
+
/* it's a good idea to flush the socket now */
rc = ssh_channel_flush(channel);
- if(rc == SSH_ERROR)
- goto error;
+ if (rc == SSH_ERROR) {
+ goto error;
+ }
+
out:
return (int)(origlen - len);