00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _NXSESSION_H_
00024 #define _NXSESSION_H_
00025
00026 #include <sstream>
00027 #include <fstream>
00028 #include <fcntl.h>
00029 #include <unistd.h>
00030 #include "nxdata.h"
00031 #include <list>
00032
00033 namespace nxcl {
00034
00039 class NXSessionCallbacks
00040 {
00041 public:
00042 NXSessionCallbacks() {}
00043 virtual ~NXSessionCallbacks() {}
00044 virtual void noSessionsSignal (void) {}
00045 virtual void loginFailedSignal (void) {}
00046 virtual void readyForProxySignal (void) {}
00051 virtual void authenticatedSignal (void) {}
00052 virtual void sessionsSignal (list<NXResumeData>) {}
00053 };
00054
00059 class NXSession
00060 {
00061 public:
00062 NXSession();
00063 ~NXSession();
00064
00065 string parseSSH (string);
00066 int parseResponse (string);
00067 void parseResumeSessions (list<string>);
00068 void resetSession (void);
00069 void wipeSessions (void);
00070 bool chooseResumable (int n);
00071 bool terminateSession (int n);
00072 string generateCookie (void);
00073 void runSession (void) { sessionDataSet = true; }
00074
00079 void setUsername (string& user) { nxUsername = user; }
00080 void setPassword (string& pass) { nxPassword = pass; }
00081 void setResolution (int x, int y)
00082 {
00083 this->sessionData->xRes = x;
00084 this->sessionData->yRes = y;
00085 }
00086
00087 void setDepth (int d)
00088 {
00089 this->sessionData->depth = d;
00090 }
00091
00092 void setRender (bool isRender)
00093 {
00094 if (this->sessionDataSet) {
00095 this->sessionData->render = isRender;
00096 }
00097 }
00098
00099 void setEncryption (bool enc)
00100 {
00101 if (this->sessionDataSet) {
00102 this->sessionData->encryption = enc;
00103 }
00104 }
00105
00106 void setContinue (bool allow)
00107 {
00108 doSSH = allow;
00109 }
00110
00111 void setSessionData (NXSessionData*);
00112
00113 NXSessionData* getSessionData()
00114 {
00115 return this->sessionData;
00116 }
00117
00118 bool getSessionDataSet (void)
00119 {
00120 return this->sessionDataSet;
00121 }
00122
00123 void setCallbacks (NXSessionCallbacks * cb)
00124 {
00125 this->callbacks = cb;
00126 }
00128
00129 private:
00130 void reset (void);
00131 void fillRand(unsigned char *, size_t);
00132
00139 bool doSSH;
00144 bool suspendedSessions;
00148 bool sessionDataSet;
00154 int stage;
00158 int devurand_fd;
00162 string nxUsername;
00166 string nxPassword;
00170 list<string> resumeSessions;
00175 list<NXResumeData> runningSessions;
00179 NXSessionData *sessionData;
00183 NXSessionCallbacks * callbacks;
00184 };
00185
00186 }
00187 #endif