[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] requestExec() and openSession() are now throwable and return value. ssh::Session::getCSession() is now public method. Added ssh::Channel::getCChannel() public method which returns the underlying ssh_channel
[Thread Prev] | [Thread Next]
- Subject: [PATCH] requestExec() and openSession() are now throwable and return value. ssh::Session::getCSession() is now public method. Added ssh::Channel::getCChannel() public method which returns the underlying ssh_channel
- From: Angel Kolev <ankolev@xxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Thu, 4 Jun 2015 17:40:12 +0300
- To: libssh@xxxxxxxxxx
- Cc: Angel Kolev <ankolev@xxxxxxxxx>
---
include/libssh/libsshpp.hpp | 52 +++++++++++++++++++++++++++++++++++++--------
1 file changed, 43 insertions(+), 9 deletions(-)
diff --git a/include/libssh/libsshpp.hpp b/include/libssh/libsshpp.hpp
index af08a91..3bda163 100644
--- a/include/libssh/libsshpp.hpp
+++ b/include/libssh/libsshpp.hpp
@@ -133,6 +133,26 @@ public:
ssh_free(c_session);
c_session=NULL;
}
+
+ /** @brief get the underlying SSH session
+ * @returns ssh_session
+ */
+ ssh_session getCSession(){
+ return c_session;
+ }
+
+ /** @brief Get session status.
+ * @throws SshException on SSH_CLOSED_ERROR
+ * @returns A bitmask including SSH_CLOSED, SSH_READ_PENDING, SSH_WRITE_PENDING or SSH_CLOSED_ERROR which respectively means the session is closed, has data to read on the connection socket and session was closed due to an error.
+ * @see ssh_get_status
+ */
+ int getStatus()
+ {
+ int ret=ssh_get_status(c_session);
+ ssh_throw(ret);
+ return ret;
+ }
+
/** @brief sets an SSH session options
* @param type Type of option
* @param option cstring containing the value of option
@@ -380,9 +400,6 @@ public:
private:
ssh_session c_session;
- ssh_session getCSession(){
- return c_session;
- }
/* No copy constructor, no = operator */
Session(const Session &);
Session& operator=(const Session &);
@@ -445,6 +462,12 @@ public:
Session &getSession(){
return *session;
}
+ /** @brief get the underlying SSH ssh_channel
+ * @returns ssh_channel
+ */
+ ssh_channel getCChannel(){
+ return channel;
+ }
/** @brief returns true if channel is in closed state
* @see ssh_channel_is_closed
*/
@@ -471,10 +494,15 @@ public:
return err;
}
/* TODO: completely remove this ? */
- void_throwable openSession(){
+ /** @brief Open a session channel (suited for a shell, not TCP forwarding).
+ * @returns SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
+ * @throws SshException in case of error
+ * @see ssh_channel_open_session
+ */
+ int openSession(){
int err=ssh_channel_open_session(channel);
ssh_throw(err);
- return_throwable;
+ return err;
}
int poll(bool is_stderr=false){
int err=ssh_channel_poll(channel,is_stderr);
@@ -522,11 +550,17 @@ public:
ssh_throw(err);
return_throwable;
}
-
- void_throwable requestExec(const char *cmd){
- int err=ssh_channel_request_exec(channel,cmd);
+ /** @brief Run a shell command without an interactive shell.
+ * This is similar to 'sh -c command'.
+ * @returns SSH_OK on success, SSH_ERROR if an error occurred, SSH_AGAIN if in nonblocking mode and call has to be done again.
+ * @param cmd The command to execute (e.g. "ls ~/ -al | grep -i reports").
+ * @throws SshException in case of error
+ * @see ssh_channel_request_exec
+ */
+ int requestExec(const char *cmd){
+ int err=ssh_channel_request_exec(channel, cmd);
ssh_throw(err);
- return_throwable;
+ return err;
}
void_throwable requestPty(const char *term=NULL, int cols=0, int rows=0){
int err;
--
2.1.4
Archive administrator: postmaster@lists.cynapses.org