aboutsummaryrefslogtreecommitdiff
path: root/src/messages.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2015-07-07 00:05:29 +0200
committerAndreas Schneider <asn@cryptomilk.org>2016-05-02 16:56:54 +0200
commitbbe437dbb163ef912f7778a1cb7ce346d687e440 (patch)
treec7475b97a6eaa2eb30bbdf047c7d7e978a371d9f /src/messages.c
parent5c67530f1ee1e688d50ca11e8fb7620d9e142fe8 (diff)
downloadlibssh-bbe437dbb163ef912f7778a1cb7ce346d687e440.tar.gz
libssh-bbe437dbb163ef912f7778a1cb7ce346d687e440.tar.xz
libssh-bbe437dbb163ef912f7778a1cb7ce346d687e440.zip
callbacks: Implement list of callbacks for channels
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/messages.c')
-rw-r--r--src/messages.c175
1 files changed, 99 insertions, 76 deletions
diff --git a/src/messages.c b/src/messages.c
index 0e2b781a..2b139fbc 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -166,90 +166,113 @@ static int ssh_execute_server_request(ssh_session session, ssh_message msg)
case SSH_REQUEST_CHANNEL:
channel = msg->channel_request.channel;
- if (msg->channel_request.type == SSH_CHANNEL_REQUEST_PTY &&
- ssh_callbacks_exists(channel->callbacks, channel_pty_request_function)) {
- rc = channel->callbacks->channel_pty_request_function(session, channel,
- msg->channel_request.TERM,
- msg->channel_request.width, msg->channel_request.height,
- msg->channel_request.pxwidth, msg->channel_request.pxheight,
- channel->callbacks->userdata);
- if (rc == 0) {
- ssh_message_channel_request_reply_success(msg);
- } else {
- ssh_message_reply_default(msg);
+ if (msg->channel_request.type == SSH_CHANNEL_REQUEST_PTY){
+ ssh_callbacks_iterate(channel->callbacks,
+ ssh_channel_callbacks,
+ channel_pty_request_function) {
+ rc = ssh_callbacks_iterate_exec(session,
+ channel,
+ msg->channel_request.TERM,
+ msg->channel_request.width,
+ msg->channel_request.height,
+ msg->channel_request.pxwidth,
+ msg->channel_request.pxheight);
+ if (rc == 0) {
+ ssh_message_channel_request_reply_success(msg);
+ } else {
+ ssh_message_reply_default(msg);
+ }
+ return SSH_OK;
}
-
- return SSH_OK;
- } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_SHELL &&
- ssh_callbacks_exists(channel->callbacks, channel_shell_request_function)) {
- rc = channel->callbacks->channel_shell_request_function(session,
- channel,
- channel->callbacks->userdata);
- if (rc == 0) {
- ssh_message_channel_request_reply_success(msg);
- } else {
- ssh_message_reply_default(msg);
+ ssh_callbacks_iterate_end();
+ } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_SHELL){
+ ssh_callbacks_iterate(channel->callbacks,
+ ssh_channel_callbacks,
+ channel_shell_request_function) {
+ rc = ssh_callbacks_iterate_exec(session, channel);
+ if (rc == 0) {
+ ssh_message_channel_request_reply_success(msg);
+ } else {
+ ssh_message_reply_default(msg);
+ }
+ return SSH_OK;
}
-
- return SSH_OK;
- } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_X11 &&
- ssh_callbacks_exists(channel->callbacks, channel_x11_req_function)) {
- channel->callbacks->channel_x11_req_function(session,
- channel,
- msg->channel_request.x11_single_connection,
- msg->channel_request.x11_auth_protocol,
- msg->channel_request.x11_auth_cookie,
- msg->channel_request.x11_screen_number,
- channel->callbacks->userdata);
- ssh_message_channel_request_reply_success(msg);
-
- return SSH_OK;
- } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_WINDOW_CHANGE &&
- ssh_callbacks_exists(channel->callbacks, channel_pty_window_change_function)) {
- rc = channel->callbacks->channel_pty_window_change_function(session,
- channel,
- msg->channel_request.width, msg->channel_request.height,
- msg->channel_request.pxwidth, msg->channel_request.pxheight,
- channel->callbacks->userdata);
- } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_EXEC &&
- ssh_callbacks_exists(channel->callbacks, channel_exec_request_function)) {
- rc = channel->callbacks->channel_exec_request_function(session,
- channel,
- msg->channel_request.command,
- channel->callbacks->userdata);
- if (rc == 0) {
+ ssh_callbacks_iterate_end();
+ } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_X11){
+ ssh_callbacks_iterate(channel->callbacks,
+ ssh_channel_callbacks,
+ channel_x11_req_function) {
+ ssh_callbacks_iterate_exec(session,
+ channel,
+ msg->channel_request.x11_single_connection,
+ msg->channel_request.x11_auth_protocol,
+ msg->channel_request.x11_auth_cookie,
+ msg->channel_request.x11_screen_number);
ssh_message_channel_request_reply_success(msg);
- } else {
- ssh_message_reply_default(msg);
+ return SSH_OK;
}
-
- return SSH_OK;
- } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_ENV &&
- ssh_callbacks_exists(channel->callbacks, channel_env_request_function)) {
- rc = channel->callbacks->channel_env_request_function(session,
- channel,
- msg->channel_request.var_name, msg->channel_request.var_value,
- channel->callbacks->userdata);
- if (rc == 0) {
- ssh_message_channel_request_reply_success(msg);
- } else {
- ssh_message_reply_default(msg);
+ ssh_callbacks_iterate_end();
+ } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_WINDOW_CHANGE){
+ ssh_callbacks_iterate(channel->callbacks,
+ ssh_channel_callbacks,
+ channel_pty_window_change_function) {
+ rc = ssh_callbacks_iterate_exec(session,
+ channel,
+ msg->channel_request.width,
+ msg->channel_request.height,
+ msg->channel_request.pxwidth,
+ msg->channel_request.pxheight);
+ return SSH_OK;
}
+ ssh_callbacks_iterate_end();
+ } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_EXEC){
+ ssh_callbacks_iterate(channel->callbacks,
+ ssh_channel_callbacks,
+ channel_exec_request_function) {
+ rc = ssh_callbacks_iterate_exec(session,
+ channel,
+ msg->channel_request.command);
+ if (rc == 0) {
+ ssh_message_channel_request_reply_success(msg);
+ } else {
+ ssh_message_reply_default(msg);
+ }
- return SSH_OK;
- } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_SUBSYSTEM &&
- ssh_callbacks_exists(channel->callbacks, channel_subsystem_request_function)) {
- rc = channel->callbacks->channel_subsystem_request_function(session,
- channel,
- msg->channel_request.subsystem,
- channel->callbacks->userdata);
- if (rc == 0) {
- ssh_message_channel_request_reply_success(msg);
- } else {
- ssh_message_reply_default(msg);
+ return SSH_OK;
}
+ ssh_callbacks_iterate_end();
+ } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_ENV){
+ ssh_callbacks_iterate(channel->callbacks,
+ ssh_channel_callbacks,
+ channel_env_request_function) {
+ rc = ssh_callbacks_iterate_exec(session,
+ channel,
+ msg->channel_request.var_name,
+ msg->channel_request.var_value);
+ if (rc == 0) {
+ ssh_message_channel_request_reply_success(msg);
+ } else {
+ ssh_message_reply_default(msg);
+ }
+ return SSH_OK;
+ }
+ ssh_callbacks_iterate_end();
+ } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_SUBSYSTEM){
+ ssh_callbacks_iterate(channel->callbacks,
+ ssh_channel_callbacks,
+ channel_subsystem_request_function) {
+ rc = ssh_callbacks_iterate_exec(session,
+ channel,
+ msg->channel_request.subsystem);
+ if (rc == 0) {
+ ssh_message_channel_request_reply_success(msg);
+ } else {
+ ssh_message_reply_default(msg);
+ }
- return SSH_OK;
+ return SSH_OK;
+ }
+ ssh_callbacks_iterate_end();
}
break;
case SSH_REQUEST_SERVICE: