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 virtual void connectedSuccessfullySignal (void) {}
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 setCustomPath(string path)
00192 {
00193 this->customPath = path;
00194 }
00195
00199 void allowSSHConnect (bool auth);
00200
00204 void invokeProxy (void);
00205
00213 string parseSSH (string message);
00214
00220
00221
00229 bool chooseResumable (int n);
00230
00239 bool terminateSession (int n);
00240
00241 void runSession (void);
00242
00243 void startX11 (string resolution, string name);
00244
00245 bool needX11Probe (void)
00246 {
00247 return x11Probe;
00248 }
00249
00250
00252 void doneAuth (void);
00253 void loginFailed (void);
00254
00255 void finished (void)
00256 {
00257 dbgln ("Finishing up on signal"); this->isFinished = true;
00258 }
00259
00260 void readyproxy (void)
00261 {
00262 dbgln ("ready for nxproxy"); this->readyForProxy = true;
00263 }
00264
00265 void reset (void);
00266 void processParseStdout (void);
00267 void processParseStderr (void);
00268
00274 void requestConfirmation (string msg);
00276
00277
00279
00282 void setUsername (string& user)
00283 {
00284 this->nxuser = user;
00285 this->session.setUsername (this->nxuser);
00286 }
00287
00291 void setPassword (string& pass)
00292 {
00293 this->nxpass = pass;
00294 this->session.setPassword (this->nxpass);
00295 }
00296
00297 void setResolution (int x, int y)
00298 {
00299 this->session.setResolution(x, y);
00300 }
00301
00302 void setDepth (int depth)
00303 {
00304 this->session.setDepth(depth);
00305 }
00306
00307 void setRender (bool render)
00308 {
00309 this->session.setRender(render);
00310 }
00311
00312 void setSessionData (NXSessionData *);
00313
00314 notQProcess* getNXSSHProcess (void)
00315 {
00316 return this->nxsshProcess;
00317 }
00318
00319 notQProcess* getNXProxyProcess (void)
00320 {
00321 return this->nxproxyProcess;
00322 }
00323
00324 notQProcess* getX11Process (void)
00325 {
00326 return this->x11Process;
00327 }
00328
00329 notQProcess* getNXAuthProcess (void)
00330 {
00331 return this->nxauthProcess;
00332 }
00333
00334 bool getIsFinished (void)
00335 {
00336 return this->isFinished;
00337 }
00338
00339 bool getReadyForProxy (void)
00340 {
00341 return this->readyForProxy;
00342 }
00343
00344 NXSession* getSession (void)
00345 {
00346 return &this->session;
00347 }
00348
00349 void setIsFinished (bool status)
00350 {
00351 this->isFinished = status;
00352 }
00353
00354 void setExternalCallbacks (NXClientLibExternalCallbacks * cb)
00355 {
00356 this->externalCallbacks = cb;
00357 }
00358
00359 bool getSessionRunning (void)
00360 {
00361 return this->sessionRunning;
00362 }
00364
00365 private:
00375 string getPath (string prog);
00376
00380 string customPath;
00381
00382 bool x11Probe;
00388 bool isFinished;
00392 bool readyForProxy;
00399 bool sessionRunning;
00403 bool password;
00404
00405
00406
00407
00408
00409
00410
00411
00415 notQProcess* nxsshProcess;
00419 notQProcess* nxproxyProcess;
00423 notQProcess* x11Process;
00427 notQProcess* nxauthProcess;
00433 NXClientLibCallbacks callbacks;
00437 notQTemporaryFile *keyFile;
00441 NXSession session;
00447 ProxyData proxyData;
00451 string nxuser;
00455 string nxpass;
00456 };
00457
00458 }
00459 #endif