#1. Initial implementation of Session and Channel classes for separation of...
#1. Initial implementation of Session and Channel classes for separation of session and execution channels to support multi-threaded environment.
rsmcore/session.cc
0 → 100644
rsmcore/session.hh
0 → 100644
#ifndef RSM_RSMCORE_SESSION_HH_ | ||
#define RSM_RSMCORE_SESSION_HH_ | ||
#include <QObject> | ||
#include "rsmcore/declspec.hh" | ||
#include "rsmcore/sessionlog.hh" | ||
namespace rsm | ||
{ | ||
enum class SessionAuthState | ||
{ | ||
SUCCESS = 0, | ||
DENIED, | ||
PARTIAL, | ||
INFO, | ||
AGAIN, | ||
ERROR = -1 | ||
}; | ||
enum class SessionAuthMethod | ||
{ | ||
UNKNOWN = 0x0000u, | ||
NONE = 0x0001u, | ||
PASSWORD = 0x0002u, | ||
PUBLICKEY = 0x0004u, | ||
HOSTBASED = 0x0008u, | ||
INTERACTIVE = 0x0010u, | ||
GSSAPI_MIC = 0x0020u, | ||
}; | ||
/** | ||
* @brief The SessionHostState enum | ||
*/ | ||
enum class SessionHostState | ||
{ /** | ||
* There had been an error checking the host. | ||
*/ | ||
ERROR = -2, | ||
/** | ||
* The known host file does not exist. The host is thus unknown. File will | ||
* be created if host key is accepted. | ||
*/ | ||
NOT_FOUND = -1, | ||
/** | ||
* The server is unknown. User should confirm the public key hash is | ||
* correct. | ||
*/ | ||
UNKNOWN = 0, | ||
/** | ||
* The server is known and has not changed. | ||
*/ | ||
OK, | ||
/** | ||
* The server key has changed. Either you are under attack or the | ||
* administrator changed the key. You HAVE to warn the user about a | ||
* possible attack. | ||
*/ | ||
CHANGED, | ||
/** | ||
* The server gave use a key of a type while we had another type recorded. | ||
* It is a possible attack. | ||
*/ | ||
OTHER, | ||
}; | ||
/** Forward declaration of private implementation */ | ||
class ChannelImpl; | ||
class SessionImpl; | ||
class Session; | ||
class RSM_PUBLIC Channel | ||
{ | ||
protected: | ||
// Private implementation | ||
ChannelImpl* p; | ||
// constructor is protected to only be used by "friend Session" | ||
Channel(); | ||
public: | ||
~Channel(); | ||
/** | ||
* @brief open Opens the channel for execution | ||
* @return | ||
*/ | ||
bool open(); | ||
/** | ||
* @brief isOpen Checks if the channel is open for execution | ||
* @return | ||
*/ | ||
bool isOpen() const; | ||
/** | ||
* @brief close Close channel of execution | ||
* Channel is no longer usable | ||
* @return | ||
*/ | ||
void close(); | ||
/** | ||
* @brief exec Execute command on remote system | ||
* @param command | ||
* @return true on success, false on failure | ||
*/ | ||
bool exec(QString command); | ||
/** | ||
* @brief readExecOut Read execution's standard output | ||
* @return | ||
*/ | ||
QString readExecOut(); | ||
/** | ||
* @brief readExecErr Read execution's standard error | ||
* @return | ||
*/ | ||
QString readExecErr(); | ||
friend Session; | ||
}; // class Channel | ||
class RSM_PUBLIC Session | ||
{ | ||
private: | ||
// Private implementation | ||
SessionImpl* p; | ||
public: | ||
/** | ||
* Basic Constructor | ||
*/ | ||
Session(); | ||
/** | ||
* Contructs with host name | ||
*/ | ||
Session(QString host); | ||
~Session(); | ||
/** | ||
* Set the remote host to connect to | ||
*/ | ||
void setHost(QString host); | ||
/** | ||
* @brief host Get the host name of the session | ||
*/ | ||
std::string host() const; | ||
/** | ||
* Set the Log verbosity | ||
*/ | ||
void setLogVerbosity(SessionVerbosity level); | ||
/** | ||
* Set the ssh port number | ||
*/ | ||
void setPort(int port); | ||
/** | ||
* Set the user | ||
* Defaults to system user | ||
*/ | ||
void setUser(QString name); | ||
/** | ||
* @brief user get the username | ||
* @return | ||
*/ | ||
std::string user() const; | ||
/** | ||
* Set the proxy command | ||
* @param command | ||
*/ | ||
void setProxyCommand(QString command); | ||
/** | ||
* Perform hand-shake to connect to host. | ||
< |