aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2019-09-17 15:58:07 +0200
committerJakub Jelen <jjelen@redhat.com>2019-09-24 16:04:52 +0200
commit89a9eb8811da56095a56a82d7967e01fdbdc7d27 (patch)
tree78cc578b15c68555fb0610e24b11ce5ed31183f9
parent3cf2b41f5eafacc92ac8a04d887ca448af88fab2 (diff)
downloadlibssh-89a9eb8811da56095a56a82d7967e01fdbdc7d27.tar.gz
libssh-89a9eb8811da56095a56a82d7967e01fdbdc7d27.tar.xz
libssh-89a9eb8811da56095a56a82d7967e01fdbdc7d27.zip
Reformat channel_open()
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
-rw-r--r--src/channels.c124
1 files changed, 67 insertions, 57 deletions
diff --git a/src/channels.c b/src/channels.c
index 15f232e1..74aef62c 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -277,74 +277,84 @@ static int ssh_channel_open_termination(void *c){
*
* @return SSH_OK if successful; SSH_ERROR otherwise.
*/
-static int channel_open(ssh_channel channel, const char *type, int window,
- int maxpacket, ssh_buffer payload) {
- ssh_session session = channel->session;
- int err=SSH_ERROR;
- int rc;
+static int
+channel_open(ssh_channel channel,
+ const char *type,
+ int window,
+ int maxpacket,
+ ssh_buffer payload)
+{
+ ssh_session session = channel->session;
+ int err = SSH_ERROR;
+ int rc;
- switch(channel->state){
- case SSH_CHANNEL_STATE_NOT_OPEN:
- break;
- case SSH_CHANNEL_STATE_OPENING:
- goto pending;
- case SSH_CHANNEL_STATE_OPEN:
- case SSH_CHANNEL_STATE_CLOSED:
- case SSH_CHANNEL_STATE_OPEN_DENIED:
- goto end;
- default:
- ssh_set_error(session,SSH_FATAL,"Bad state in channel_open: %d",channel->state);
- }
- channel->local_channel = ssh_channel_new_id(session);
- channel->local_maxpacket = maxpacket;
- channel->local_window = window;
+ switch (channel->state) {
+ case SSH_CHANNEL_STATE_NOT_OPEN:
+ break;
+ case SSH_CHANNEL_STATE_OPENING:
+ goto pending;
+ case SSH_CHANNEL_STATE_OPEN:
+ case SSH_CHANNEL_STATE_CLOSED:
+ case SSH_CHANNEL_STATE_OPEN_DENIED:
+ goto end;
+ default:
+ ssh_set_error(session, SSH_FATAL, "Bad state in channel_open: %d",
+ channel->state);
+ }
- SSH_LOG(SSH_LOG_PROTOCOL,
- "Creating a channel %d with %d window and %d max packet",
- channel->local_channel, window, maxpacket);
+ channel->local_channel = ssh_channel_new_id(session);
+ channel->local_maxpacket = maxpacket;
+ channel->local_window = window;
- rc = ssh_buffer_pack(session->out_buffer,
- "bsddd",
- SSH2_MSG_CHANNEL_OPEN,
- type,
- channel->local_channel,
- channel->local_window,
- channel->local_maxpacket);
- if (rc != SSH_OK){
- ssh_set_error_oom(session);
- return err;
- }
+ SSH_LOG(SSH_LOG_PROTOCOL,
+ "Creating a channel %d with %d window and %d max packet",
+ channel->local_channel, window, maxpacket);
- if (payload != NULL) {
- if (ssh_buffer_add_buffer(session->out_buffer, payload) < 0) {
- ssh_set_error_oom(session);
+ rc = ssh_buffer_pack(session->out_buffer,
+ "bsddd",
+ SSH2_MSG_CHANNEL_OPEN,
+ type,
+ channel->local_channel,
+ channel->local_window,
+ channel->local_maxpacket);
+ if (rc != SSH_OK) {
+ ssh_set_error_oom(session);
+ return err;
+ }
+
+ if (payload != NULL) {
+ if (ssh_buffer_add_buffer(session->out_buffer, payload) < 0) {
+ ssh_set_error_oom(session);
- return err;
+ return err;
+ }
+ }
+ channel->state = SSH_CHANNEL_STATE_OPENING;
+ if (ssh_packet_send(session) == SSH_ERROR) {
+ return err;
}
- }
- channel->state = SSH_CHANNEL_STATE_OPENING;
- if (ssh_packet_send(session) == SSH_ERROR) {
- return err;
- }
+ SSH_LOG(SSH_LOG_PACKET,
+ "Sent a SSH_MSG_CHANNEL_OPEN type %s for channel %d",
+ type, channel->local_channel);
- SSH_LOG(SSH_LOG_PACKET,
- "Sent a SSH_MSG_CHANNEL_OPEN type %s for channel %d",
- type, channel->local_channel);
pending:
- /* wait until channel is opened by server */
- err = ssh_handle_packets_termination(session,
- SSH_TIMEOUT_DEFAULT,
- ssh_channel_open_termination,
- channel);
-
- if (session->session_state == SSH_SESSION_STATE_ERROR)
- err = SSH_ERROR;
+ /* wait until channel is opened by server */
+ err = ssh_handle_packets_termination(session,
+ SSH_TIMEOUT_DEFAULT,
+ ssh_channel_open_termination,
+ channel);
+
+ if (session->session_state == SSH_SESSION_STATE_ERROR) {
+ err = SSH_ERROR;
+ }
+
end:
- if(channel->state == SSH_CHANNEL_STATE_OPEN)
- err=SSH_OK;
+ if (channel->state == SSH_CHANNEL_STATE_OPEN) {
+ err = SSH_OK;
+ }
- return err;
+ return err;
}
/* return channel with corresponding local id, or NULL if not found */