00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _NXCLIENTLIB_H_
00025 #define _NXCLIENTLIB_H_
00026
00027 #include <iostream>
00028 #include "nxsession.h"
00029 #include <list>
00030 #include "notQt.h"
00031
00032
00033 using namespace std;
00034
00035 namespace nxcl {
00036
00037 struct ProxyData {
00038 string id;
00039 int display;
00040 string cookie;
00041 string proxyIP;
00042 bool encrypted;
00043 int port;
00044 string server;
00045 };
00046
00052 class NXClientLibExternalCallbacks
00053 {
00054 public:
00055 NXClientLibExternalCallbacks () {}
00056 virtual ~NXClientLibExternalCallbacks () {}
00057 virtual void write (string msg) {}
00058 virtual void write (int num, string msg) {}
00059 virtual void error (string msg) {}
00060 virtual void debug (string msg) {}
00061 virtual void stdoutSignal (string msg) {}
00062 virtual void stderrSignal (string msg) {}
00063 virtual void stdinSignal (string msg) {}
00064 virtual void resumeSessionsSignal (list<NXResumeData>) {}
00065 virtual void noSessionsSignal (void) {}
00066 virtual void serverCapacitySignal (void) {}
00067
00068 };
00069
00081 class NXClientLibBase
00082 {
00083 public:
00084 NXClientLibBase() {}
00085 virtual ~NXClientLibBase() {}
00086
00087 virtual void setIsFinished (bool status) {}
00088 virtual void processParseStdout (void) {}
00089 virtual void processParseStderr (void) {}
00090 virtual void loginFailed (void) {}
00091 virtual void readyproxy (void) {}
00092 virtual void doneAuth (void) {}
00093
00100 NXClientLibExternalCallbacks * externalCallbacks;
00101 };
00102
00107 class NXClientLibCallbacks : public notQProcessCallbacks,
00108 public NXSessionCallbacks
00109 {
00110 public:
00111 NXClientLibCallbacks();
00112 ~NXClientLibCallbacks();
00113
00122 void startedSignal (string name);
00123 void errorSignal (int error);
00124 void processFinishedSignal (string name);
00125 void readyReadStandardOutputSignal (void);
00126 void readyReadStandardErrorSignal (void);
00128
00132 void noSessionsSignal (void);
00133 void loginFailedSignal (void);
00134 void readyForProxySignal (void);
00135 void authenticatedSignal (void);
00136 void sessionsSignal (list<NXResumeData>);
00138
00139
00144 void setParent (NXClientLibBase * p) { this->parent = p; }
00145 private:
00146 NXClientLibBase * parent;
00147 };
00148
00149 class NXClientLib : public NXClientLibBase
00150 {
00151 public:
00152 NXClientLib();
00153 ~NXClientLib();
00154
00174 void invokeNXSSH (string publicKey = "supplied",
00175 string serverHost = "",
00176 bool encryption = true,
00177 string key = "",
00178 int port = 22);
00179
00186 void write (string data);
00187
00191 void allowSSHConnect (bool auth);
00192
00196 void invokeProxy (void);
00197
00205 string parseSSH (string message);
00206
00212
00213
00221 bool chooseResumable (int n);
00222
00231 bool terminateSession (int n);
00232
00233 void runSession (void);
00234
00235
00237 void doneAuth (void);
00238 void loginFailed (void);
00239
00240 void finished (void)
00241 {
00242 dbgln ("Finishing up on signal"); this->isFinished = true;
00243 }
00244
00245 void readyproxy (void)
00246 {
00247 dbgln ("ready for nxproxy"); this->readyForProxy = true;
00248 }
00249
00250 void reset (void);
00251 void processParseStdout (void);
00252 void processParseStderr (void);
00253
00259 void requestConfirmation (string msg);
00261
00262
00264
00267 void setUsername (string& user)
00268 {
00269 this->nxuser = user;
00270 this->session.setUsername (this->nxuser);
00271 }
00272
00276 void setPassword (string& pass)
00277 {
00278 this->nxpass = pass;
00279 this->session.setPassword (this->nxpass);
00280 }
00281
00282 void setResolution (int x, int y)
00283 {
00284 this->session.setResolution(x, y);
00285 }
00286
00287 void setDepth (int depth)
00288 {
00289 this->session.setDepth(depth);
00290 }
00291
00292 void setRender (bool render)
00293 {
00294 this->session.setRender(render);
00295 }
00296
00297 void setSessionData (NXSessionData *);
00298
00299 notQProcess* getNXSSHProcess (void)
00300 {
00301 return this->pNxsshProcess;
00302 }
00303
00304 notQProcess* getNXProxyProcess (void)
00305 {
00306 return this->pNxproxyProcess;
00307 }
00308
00309 bool getIsFinished (void)
00310 {
00311 return this->isFinished;
00312 }
00313
00314 bool getReadyForProxy (void)
00315 {
00316 return this->readyForProxy;
00317 }
00318
00319 NXSession* getSession (void)
00320 {
00321 return &this->session;
00322 }
00323
00324 void setIsFinished (bool status)
00325 {
00326 this->isFinished = status;
00327 }
00328
00329 void setExternalCallbacks (NXClientLibExternalCallbacks * cb)
00330 {
00331 this->externalCallbacks = cb;
00332 }
00333
00334 bool getSessionRunning (void)
00335 {
00336 return this->sessionRunning;
00337 }
00339
00340 private:
00350 string getPath (string prog);
00351
00357 bool isFinished;
00361 bool readyForProxy;
00368 bool sessionRunning;
00372 bool password;
00373
00374
00375
00376
00377
00378
00379
00380
00384 notQProcess nxsshProcess;
00385 notQProcess* pNxsshProcess;
00389 notQProcess nxproxyProcess;
00390 notQProcess* pNxproxyProcess;
00396 NXClientLibCallbacks callbacks;
00400 notQTemporaryFile *keyFile;
00404 NXSession session;
00410 ProxyData proxyData;
00414 string nxuser;
00418 string nxpass;
00419 };
00420
00421 }
00422 #endif