nxclientlib.h

00001 /***************************************************************************
00002                                nxclientlib.h
00003                              -------------------
00004     begin                : Sat 22nd July 2006
00005     remove Qt dependency : Started June 2007
00006     modifications        : June-July 2007
00007     copyright            : (C) 2006 by George Wright
00008     modifications        : (C) 2007 Embedded Software Foundry Ltd. (U.K.)
00009                          :     Author: Sebastian James
00010                          : (C) 2008 Defuturo Ltd
00011                          :     Author: George Wright
00012     email                : seb@esfnet.co.uk, gwright@kde.org
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #ifndef _NXCLIENTLIB_H_
00025 #define _NXCLIENTLIB_H_
00026 
00027 #include <iostream>
00028 #include <list>
00029 
00030 #include "nxsession.h"
00031 #include "notQt.h"
00032 
00033 extern "C" {
00034             #include <dirent.h>
00035 }
00036 
00037 using namespace std;
00038 
00039 namespace nxcl {
00040 
00041     struct ProxyData {
00042         string id;
00043         int    display;
00044         string cookie;
00045         string proxyIP;
00046         bool   encrypted;
00047         int    port;
00048         string server;
00049     };
00050 
00056     class NXClientLibExternalCallbacks
00057     {
00058         public:
00059             NXClientLibExternalCallbacks () {}
00060             virtual ~NXClientLibExternalCallbacks () {}
00061             virtual void write (string msg) {}
00062             virtual void write (int num, string msg) {}
00063             virtual void error (string msg) {}
00064             virtual void debug (string msg) {}
00065             virtual void stdoutSignal (string msg) {}
00066             virtual void stderrSignal (string msg) {}
00067             virtual void stdinSignal (string msg) {}
00068             virtual void resumeSessionsSignal (list<NXResumeData>) {}
00069             virtual void noSessionsSignal (void) {}
00070             virtual void serverCapacitySignal (void) {}
00071             virtual void connectedSuccessfullySignal (void) {}
00072     };
00073 
00085     class NXClientLibBase 
00086     {
00087         public:
00088             NXClientLibBase() {}
00089             virtual ~NXClientLibBase() {}
00090 
00091             virtual void setIsFinished (bool status) {}
00092             virtual void processParseStdout (void) {}
00093             virtual void processParseStderr (void) {}
00094             virtual void loginFailed (void) {}
00095             virtual void readyproxy (void) {}
00096             virtual void doneAuth (void) {}
00097 
00104             NXClientLibExternalCallbacks * externalCallbacks;
00105     };
00106 
00111     class NXClientLibCallbacks : public notQProcessCallbacks,
00112         public NXSessionCallbacks
00113     {
00114         public:
00115             NXClientLibCallbacks();
00116             ~NXClientLibCallbacks();
00117 
00126             void startedSignal (string name);
00127             void errorSignal (int error);
00128             void processFinishedSignal (string name);
00129             void readyReadStandardOutputSignal (void);
00130             void readyReadStandardErrorSignal (void);
00132 
00136             void noSessionsSignal (void);
00137             void loginFailedSignal (void);
00138             void readyForProxySignal (void);
00139             void authenticatedSignal (void);
00140             void sessionsSignal (list<NXResumeData>);
00142 
00143 
00148             void setParent (NXClientLibBase * p) { this->parent = p; }
00149         private:
00150             NXClientLibBase * parent;
00151     };
00152 
00153     class NXClientLib : public NXClientLibBase
00154     {
00155         public:
00156             NXClientLib();
00157             ~NXClientLib();
00158 
00178             void invokeNXSSH (string publicKey = "supplied",
00179                     string serverHost = "",
00180                     bool encryption = true,
00181                     string key = "",
00182                     int port = 22);
00183 
00195             void setProxy (string proxyHost,
00196                     string proxyUser,
00197                     string proxyPass,
00198                     int proxyPort);
00205             void write (string data);
00206 
00210             void setCustomPath(string path)
00211             {
00212                 this->customPath = path;
00213             }
00214             
00218             void allowSSHConnect (bool auth);
00219 
00223             void invokeProxy (void);
00224 
00232             string parseSSH (string message);
00233 
00239             //void checkSession (void);
00240 
00248             bool chooseResumable (int n); 
00249 
00258             bool terminateSession (int n);
00259 
00260             void runSession (void);
00261 
00262             void startX11 (string resolution, string name);
00263 
00264             bool needX11Probe (void)
00265             {
00266                 return x11Probe;
00267             }
00268             
00269             // public slots:
00271             void doneAuth (void);
00272             void loginFailed (void);
00273             
00274             void finished (void)
00275             {
00276                 dbgln ("Finishing up on signal"); this->isFinished = true;
00277             }
00278 
00279             void readyproxy (void)
00280             {
00281                 dbgln ("ready for nxproxy"); this->readyForProxy = true;
00282             }
00283 
00284             void reset (void);
00285             void processParseStdout (void);
00286             void processParseStderr (void);
00287 
00293             void requestConfirmation (string msg);
00295 
00296             // Accessors
00298 
00301             void setUsername (string& user)
00302             {
00303                 this->nxuser = user;
00304                 this->session.setUsername (this->nxuser);
00305             }
00306 
00310             void setPassword (string& pass)
00311             {
00312                 this->nxpass = pass;
00313                 this->session.setPassword (this->nxpass);
00314             }
00315 
00316             void setResolution (int x, int y)
00317             {
00318                 this->session.setResolution(x, y);
00319             }
00320 
00321             void setDepth (int depth)
00322             {
00323                 this->session.setDepth(depth);
00324             }
00325 
00326             void setRender (bool render)
00327             {
00328                 this->session.setRender(render);
00329             }
00330 
00331             void setSessionData (NXSessionData *);
00332 
00333             notQProcess* getNXSSHProcess (void)
00334             {
00335                 return this->nxsshProcess;
00336             }
00337 
00338             notQProcess* getNXProxyProcess (void)
00339             {
00340                 return this->nxproxyProcess;
00341             }
00342 
00343             notQProcess* getX11Process (void)
00344             {
00345                 return this->x11Process;
00346             }
00347 
00348             notQProcess* getNXAuthProcess (void)
00349             {
00350                 return this->nxauthProcess;
00351             }
00352 
00353             bool getIsFinished (void)
00354             {
00355                 return this->isFinished;
00356             }
00357 
00358             bool getReadyForProxy (void)
00359             {
00360                 return this->readyForProxy;
00361             }
00362 
00363             NXSession* getSession (void)
00364             {
00365                 return &this->session;
00366             }
00367 
00368             void setIsFinished (bool status)
00369             {
00370                 this->isFinished = status;
00371             }
00372 
00373             void setExternalCallbacks (NXClientLibExternalCallbacks * cb)
00374             {
00375                 this->externalCallbacks = cb;
00376             }
00377 
00378             bool getSessionRunning (void)
00379             {
00380                 return this->sessionRunning;
00381             }
00382 
00383             // static function so we do not need an explicit object
00384             // for deleting the session files
00385             static bool deleteAllSessionfiles(void);
00386 
00388 
00389         private:
00399             string getPath (string prog);
00400 
00404             string customPath;
00405 
00406             bool x11Probe;
00412             bool isFinished;
00416             bool readyForProxy;
00423             bool sessionRunning;
00427             bool password;
00428 
00429             // FIXME: I hold the actual data, and a pointer to the
00430             // data here. I tried to get rid of the pointer, and
00431             // modify main.cpp in ../nxcl and that didn't work
00432             // properly - I'm not sure why. I suppose I could get
00433             // rid of the objects here, and then call
00434             // pNxsshProcess = new notQProcess; in the
00435             // constructor...
00439             notQProcess* nxsshProcess;
00443             notQProcess* nxproxyProcess;
00447             notQProcess* x11Process;
00451             notQProcess* nxauthProcess;
00457             NXClientLibCallbacks callbacks;
00461             notQTemporaryFile *keyFile;
00465             NXSession session;
00471             ProxyData proxyData;
00475             string nxuser;
00479             string nxpass;
00483             bool useHttpProxy;
00487             string httpProxyHost;
00491             bool httpProxyAuthenticated;
00495             string httpProxyUser;
00499             string httpProxyPass;
00503             int httpProxyPort;
00504 
00505             static int fmatch(const struct dirent *direntry);
00506     };
00507 
00508 } // namespace
00509 #endif

Generated on Wed Oct 29 12:18:16 2008 for nxcl by  doxygen 1.5.1