nxcl  @VERSION@
nxclientlib.h
1 /***************************************************************************
2  nxclientlib.h
3  -------------------
4  begin : Sat 22nd July 2006
5  remove Qt dependency : Started June 2007
6  modifications : June-July 2007
7  copyright : (C) 2006 by George Wright
8  modifications : (C) 2007 Embedded Software Foundry Ltd. (U.K.)
9  : Author: Sebastian James
10  : (C) 2008 Defuturo Ltd
11  : Author: George Wright
12  email : seb@esfnet.co.uk, gwright@kde.org
13  ***************************************************************************/
14 
15 /***************************************************************************
16  * *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or *
20  * (at your option) any later version. *
21  * *
22  ***************************************************************************/
23 
24 #ifndef _NXCLIENTLIB_H_
25 #define _NXCLIENTLIB_H_
26 
27 #include <iostream>
28 #include "nxsession.h"
29 #include <list>
30 #include "notQt.h"
31 
32 
33 using namespace std;
34 
35 namespace nxcl {
36 
37  struct ProxyData {
38  string id;
39  int display;
40  string cookie;
41  string proxyIP;
42  bool encrypted;
43  int port;
44  string server;
45  };
46 
53  {
54  public:
56  virtual ~NXClientLibExternalCallbacks () {}
57  virtual void write (string msg) {}
58  virtual void write (int num, string msg) {}
59  virtual void error (string msg) {}
60  virtual void debug (string msg) {}
61  virtual void stdoutSignal (string msg) {}
62  virtual void stderrSignal (string msg) {}
63  virtual void stdinSignal (string msg) {}
64  virtual void resumeSessionsSignal (list<NXResumeData>) {}
65  virtual void noSessionsSignal (void) {}
66  virtual void serverCapacitySignal (void) {}
67  virtual void connectedSuccessfullySignal (void) {}
68  };
69 
82  {
83  public:
84  NXClientLibBase() {}
85  virtual ~NXClientLibBase() {}
86 
87  virtual void setIsFinished (bool status) {}
88  virtual void processParseStdout (void) {}
89  virtual void processParseStderr (void) {}
90  virtual void loginFailed (void) {}
91  virtual void readyproxy (void) {}
92  virtual void doneAuth (void) {}
93 
101  };
102 
108  public NXSessionCallbacks
109  {
110  public:
113 
122  void startedSignal (string name);
123  void errorSignal (int error);
124  void processFinishedSignal (string name);
125  void readyReadStandardOutputSignal (void);
126  void readyReadStandardErrorSignal (void);
128 
132  void noSessionsSignal (void);
133  void loginFailedSignal (void);
134  void readyForProxySignal (void);
135  void authenticatedSignal (void);
136  void sessionsSignal (list<NXResumeData>);
138 
139 
144  void setParent (NXClientLibBase * p) { this->parent = p; }
145  private:
146  NXClientLibBase * parent;
147  };
148 
150  {
151  public:
152  NXClientLib();
153  ~NXClientLib();
154 
174  void invokeNXSSH (string publicKey = "supplied",
175  string serverHost = "",
176  bool encryption = true,
177  string key = "",
178  int port = 22);
179 
186  void write (string data);
187 
191  void setCustomPath(string path)
192  {
193  this->customPath = path;
194  }
195 
199  void allowSSHConnect (bool auth);
200 
204  void invokeProxy (void);
205 
213  string parseSSH (string message);
214 
220  //void checkSession (void);
221 
229  bool chooseResumable (int n);
230 
239  bool terminateSession (int n);
240 
241  void runSession (void);
242 
243  void startX11 (string resolution, string name);
244 
245  bool needX11Probe (void)
246  {
247  return x11Probe;
248  }
249 
250  // public slots:
252  void doneAuth (void);
253  void loginFailed (void);
254 
255  void finished (void)
256  {
257  dbgln ("Finishing up on signal"); this->isFinished = true;
258  }
259 
260  void readyproxy (void)
261  {
262  dbgln ("ready for nxproxy"); this->readyForProxy = true;
263  }
264 
265  void reset (void);
266  void processParseStdout (void);
267  void processParseStderr (void);
268 
274  void requestConfirmation (string msg);
276 
277  // Accessors
279 
282  void setUsername (string& user)
283  {
284  this->nxuser = user;
285  this->session.setUsername (this->nxuser);
286  }
287 
291  void setPassword (string& pass)
292  {
293  this->nxpass = pass;
294  this->session.setPassword (this->nxpass);
295  }
296 
297  void setResolution (int x, int y)
298  {
299  this->session.setResolution(x, y);
300  }
301 
302  void setDepth (int depth)
303  {
304  this->session.setDepth(depth);
305  }
306 
307  void setRender (bool render)
308  {
309  this->session.setRender(render);
310  }
311 
312  void setSessionData (NXSessionData *);
313 
314  notQProcess* getNXSSHProcess (void)
315  {
316  return this->nxsshProcess;
317  }
318 
319  notQProcess* getNXProxyProcess (void)
320  {
321  return this->nxproxyProcess;
322  }
323 
324  notQProcess* getX11Process (void)
325  {
326  return this->x11Process;
327  }
328 
329  notQProcess* getNXAuthProcess (void)
330  {
331  return this->nxauthProcess;
332  }
333 
334  bool getIsFinished (void)
335  {
336  return this->isFinished;
337  }
338 
339  bool getReadyForProxy (void)
340  {
341  return this->readyForProxy;
342  }
343 
344  NXSession* getSession (void)
345  {
346  return &this->session;
347  }
348 
349  void setIsFinished (bool status)
350  {
351  this->isFinished = status;
352  }
353 
354  void setExternalCallbacks (NXClientLibExternalCallbacks * cb)
355  {
356  this->externalCallbacks = cb;
357  }
358 
359  bool getSessionRunning (void)
360  {
361  return this->sessionRunning;
362  }
364 
365  private:
375  string getPath (string prog);
376 
380  string customPath;
381 
382  bool x11Probe;
388  bool isFinished;
392  bool readyForProxy;
399  bool sessionRunning;
403  bool password;
404 
405  // FIXME: I hold the actual data, and a pointer to the
406  // data here. I tried to get rid of the pointer, and
407  // modify main.cpp in ../nxcl and that didn't work
408  // properly - I'm not sure why. I suppose I could get
409  // rid of the objects here, and then call
410  // pNxsshProcess = new notQProcess; in the
411  // constructor...
415  notQProcess* nxsshProcess;
419  notQProcess* nxproxyProcess;
423  notQProcess* x11Process;
427  notQProcess* nxauthProcess;
433  NXClientLibCallbacks callbacks;
437  notQTemporaryFile *keyFile;
441  NXSession session;
447  ProxyData proxyData;
451  string nxuser;
455  string nxpass;
456  };
457 
458 } // namespace
459 #endif