summaryrefslogtreecommitdiffstats
path: root/libssh/channels.c
diff options
context:
space:
mode:
authorPreston A. Elder <prez@neuromancy.net>2009-07-28 10:21:40 -0700
committerAndreas Schneider <mail@cynapses.org>2009-07-29 18:41:48 +0200
commit4f70cc13e2aa28657e40f91dfcf03dd9c82a41e9 (patch)
tree5fd13768b42e2b0c93cc16f5f97a0f0a26088fa3 /libssh/channels.c
parentb4111c5c187cf9212eba0ae459edb630dbddb656 (diff)
downloadlibssh-4f70cc13e2aa28657e40f91dfcf03dd9c82a41e9.tar.gz
libssh-4f70cc13e2aa28657e40f91dfcf03dd9c82a41e9.tar.xz
libssh-4f70cc13e2aa28657e40f91dfcf03dd9c82a41e9.zip
Fleshed out server interface
- Enables channel_request_open types of DIRECT_TCPIP, FORWARDED_TCPIP and X11 (ie. implemented the handling of those channel_request_open types). - Adds functions to retrieve the extra information relating to channel_request_open messages and channel_request messages. - Adds a channel_write_stderr method (obviously for writing to the STDERR channel from server side) - well, technically just converted the exiting channel_write to take an extra argument and created two wrapper functions. - Actually does the invoking of message_handle() from channel_recv_request. - Implemented the handling of the window-change and env channel_requests. - Implemented a few functions in server.h that were declared but not defined (eg. ssh_message_channel_request_channel). Signed-off-by: Preston A. Elder <prez@neuromancy.net> Signed-off-by: Andreas Schneider <mail@cynapses.org>
Diffstat (limited to 'libssh/channels.c')
-rw-r--r--libssh/channels.c58
1 files changed, 43 insertions, 15 deletions
diff --git a/libssh/channels.c b/libssh/channels.c
index cf8bbf6..f40ebc9 100644
--- a/libssh/channels.c
+++ b/libssh/channels.c
@@ -472,6 +472,7 @@ static void channel_rcv_request(SSH_SESSION *session) {
ssh_string request_s;
char *request;
uint32_t status;
+ uint32_t startpos = session->in_buffer->pos;
enter_function();
@@ -542,8 +543,13 @@ static void channel_rcv_request(SSH_SESSION *session) {
leave_function();
return;
}
+
/* TODO call message_handle since it handles channel requests as messages */
/* *but* reset buffer before !! */
+
+ session->in_buffer->pos = startpos;
+ message_handle(session, SSH2_MSG_CHANNEL_REQUEST);
+
ssh_log(session, SSH_LOG_PACKET, "Unknown request %s", request);
SAFE_FREE(request);
@@ -852,20 +858,7 @@ error:
return rc;
}
-/**
- * @brief Blocking write on channel.
- *
- * @param channel The channel to write to.
- *
- * @param data A pointer to the data to write.
- *
- * @param len The length of the buffer to write to.
- *
- * @return The number of bytes written, SSH_ERROR on error.
- *
- * @see channel_read()
- */
-int channel_write(ssh_channel channel, const void *data, uint32_t len) {
+int channel_write_common(ssh_channel channel, const void *data, uint32_t len, int is_stderr) {
SSH_SESSION *session = channel->session;
int origlen = len;
int effectivelen;
@@ -916,7 +909,8 @@ int channel_write(ssh_channel channel, const void *data, uint32_t len) {
effectivelen = len;
}
- if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_DATA) < 0 ||
+ 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 ||
buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
@@ -947,6 +941,40 @@ error:
}
/**
+ * @brief Blocking write on channel.
+ *
+ * @param channel The channel to write to.
+ *
+ * @param data A pointer to the data to write.
+ *
+ * @param len The length of the buffer to write to.
+ *
+ * @return The number of bytes written, SSH_ERROR on error.
+ *
+ * @see channel_read()
+ */
+int channel_write(ssh_channel channel, const void *data, uint32_t len) {
+ return channel_write_common(channel, data, len, 0);
+}
+
+/**
+ * @brief Blocking write on channel for stderr.
+ *
+ * @param channel The channel to write to.
+ *
+ * @param data A pointer to the data to write.
+ *
+ * @param len The length of the buffer to write to.
+ *
+ * @return The number of bytes written, SSH_ERROR on error.
+ *
+ * @see channel_read()
+ */
+int channel_write_stderr(ssh_channel channel, const void *data, uint32_t len) {
+ return channel_write_common(channel, data, len, 1);
+}
+
+/**
* @brief Check if the channel is open or not.
*
* @param channel The channel to check.