Qore TelnetClient Module Reference  1.0
 All Classes Namespaces Functions Variables Groups Pages
TelnetClient.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file TelnetClient.qm Telnet module definition
3 
4 /* TelnetClient.qm Copyright 2012 - 2013 Qore Technologies sro
5 
6  Original Author: Pavol Potancok
7 
8  Permission is hereby granted, free of charge, to any person obtaining a
9  copy of this software and associated documentation files (the "Software"),
10  to deal in the Software without restriction, including without limitation
11  the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  and/or sell copies of the Software, and to permit persons to whom the
13  Software is furnished to do so, subject to the following conditions:
14 
15  The above copyright notice and this permission notice shall be included in
16  all copies or substantial portions of the Software.
17 
18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  DEALINGS IN THE SOFTWARE.
25 */
26 
27 
28 /* Version History
29  * 1.0: updated by David Nichols <david@qore.org> to a user module
30  * 0.9: original author Pavol Potancok <ppotancok@gmail.com>
31 */
32 
48 
49 namespace TelnetClient {
53  // default telnet port
54  const DefaultTelnetPort = 23;
55 
56  // default connection timeout
57  const DefaultConnTimeout = 15s;
58 
59  // default poll timeout
60  const DefaultTimeout = 100ms;
61 
62  // default terminal type
63  const DefaultTerminalType = "xterm";
64 
65  // default terminal speed
66  const DefaultTerminalSpeed = 38400;
68 
72  const IAC = 255;
73  const DONT = 254;
74  const DO = 253;
75  const WONT = 252;
76  const WILL = 251;
77  const SE = 240;
78  const NOP = 241;
79  const DM = 242;
80  const BRK = 243;
81  const IP = 244;
82  const AO = 245;
83  const AYT = 246;
84  const EC = 247;
85  const EL = 248;
86  const GA = 249;
87  const SB = 250;
88 
90  const CmdMap = (
91  IAC : "IAC",
92  DONT : "DONT",
93  DO : "DO",
94  WONT : "WONT",
95  WILL: "WILL",
96  SE : "SubnegotiationEnd",
97  NOP : "NoOperation",
98  DM: "DataMark",
99  BRK : "Break",
100  IP : "Interruptprocess",
101  AO : "Abortoutput",
102  AYT : "AreYouThere",
103  EC : "EraseCharacter",
104  EL : "EraseLine",
105  GA : "GoAhead",
106  SB : "SubnegotiationBegin",
107  );
109 
110  const SUPDUP_OPT = 21; // SUPDUP_OPT display protocol
111 
115  const TOPT_BIN = 0;
116  const TOPT_ECHO = 1;
117  const TOPT_RECN = 2;
118  const TOPT_SUPP = 3;
119  const TOPT_APRX = 4;
120  const TOPT_STAT = 5;
121  const TOPT_TIM = 6;
122  const TOPT_REM = 7;
123  const TOPT_OLW = 8;
124  const TOPT_OPS = 9;
125  const TOPT_OCRD = 10;
126  const TOPT_OHT = 11;
127  const TOPT_OHTD = 12;
128  const TOPT_OFD = 13;
129  const TOPT_OVT = 14;
130  const TOPT_OVTD = 15;
131  const TOPT_OLD = 16;
132  const TOPT_EXT = 17;
133  const TOPT_LOGO = 18;
134  const TOPT_BYTE = 19;
135  const TOPT_DATA = 20;
136  const TOPT_SUP = 21;
137  const TOPT_SUPO = 22;
138  const TOPT_SNDL = 23;
139  const TOPT_TERM = 24;
140  const TOPT_EOR = 25;
141  const TOPT_TACACS = 26;
142  const TOPT_OM = 27;
143  const TOPT_TLN = 28;
144  const TOPT_3270 = 29;
145  const TOPT_X3 = 30;
146  const TOPT_NAWS = 31;
147  const TOPT_TS = 32;
148  const TOPT_RFC = 33;
149  const TOPT_LINE = 34;
150  const TOPT_XDL = 35;
151  const TOPT_ENVIR = 36;
152  const TOPT_AUTH = 37;
153  const TOPT_ENVIR_NEW = 39;
154  const TOPT_TN3270 = 40;
155  const TOPT_X_AUTH = 41;
156  const TOPT_CHARSET = 42;
157  const TOPT_RSP = 43;
158  const TOPT_COMPORT = 44;
159  const TOPT_SLE = 45;
160  const TOPT_STARTTLS = 46;
161  const TOPT_KERMIT = 47;
162  const TOPT_SEND_URL = 48;
163  const TOPT_EXTOP = 255;
164 
166  const OptMap = (
167  TOPT_BIN : "BinaryTransmission",
168  TOPT_ECHO : "Echo|Is|Send",
169  TOPT_RECN : "Reconnection",
170  TOPT_SUPP : "SuppressGoAhead",
171  TOPT_APRX : "ApproxMessageSizeNegotiation",
172  TOPT_STAT : "Status",
173  TOPT_TIM : "TimingMark",
174  TOPT_REM : "RemoteControlledTransandEcho",
175  TOPT_OLW : "OutputLineWidth",
176  TOPT_OPS : "OutputPageSize",
177  TOPT_OCRD : "OutputCarriage-ReturnDisposition",
178  TOPT_OHT : "OutputHorizontalTabstops",
179  TOPT_OHTD : "OutputHorizontalTabDisposition",
180  TOPT_OFD : "OutputFormfeedDisposition",
181  TOPT_OVT : "OutputVerticalTabstops",
182  TOPT_OVTD : "OutputVerticalTabDisposition",
183  TOPT_OLD : "OutputLinefeedDisposition",
184  TOPT_EXT : "ExtendedASCII",
185  TOPT_LOGO : "Logout",
186  TOPT_BYTE : "ByteMacro",
187  TOPT_DATA : "DataEntryTerminal",
188  TOPT_SUP : "SUPDUP",
189  TOPT_SUPO : "SUPDUPOutput",
190  TOPT_SNDL : "SendLocation",
191  TOPT_TERM : "TerminalType",
192  TOPT_EOR : "EndofRecord",
193  TOPT_TACACS : "TACACSUserIdent",
194  TOPT_OM : "OutputMarking",
195  TOPT_TLN : "TerminalLocationNumber",
196  TOPT_3270 : "Telnet3270Regime",
197  TOPT_X3 : "X.3PAD",
198  TOPT_NAWS : "NegotiateAboutWindowSize",
199  TOPT_TS : "TerminalSpeed",
200  TOPT_RFC : "RemoteFlowControl",
201  TOPT_LINE : "Linemode",
202  TOPT_XDL : "XDisplayLocation",
203  TOPT_ENVIR : "TelnetEnvironmentOption",
204  TOPT_AUTH : "TelnetAuthenticationOption",
205  TOPT_ENVIR_NEW : "TelnetNewEnvironmentOption",
206  TOPT_TN3270 : "TN3270Enhancements",
207  TOPT_X_AUTH : "TelnetXAUTH",
208  TOPT_CHARSET : "TelnetCHARSET",
209  TOPT_RSP : "TelnetRemoteSerialPort",
210  TOPT_COMPORT : "TelnetComPortControl",
211  TOPT_SLE : "TelnetSuppressLocalEcho",
212  TOPT_STARTTLS : "TelnetStartTLS",
213  TOPT_KERMIT : "TelnetKERMIT",
214  TOPT_SEND_URL : "Send-URL",
215  TOPT_EXTOP : "Extended-Options-List",
216  );
218 
220 
223  class TelnetClient {
224 
225 public:
227  private :
228  // the connection string
229  string connect;
230 
231  // the socket for all communication with the server
232  Socket conn();
233 
234  // to manage contention on the Socket
235  Mutex m();
236 
237  // login user
238  *string user;
239 
240  // logging closures
241  *code log_info;
242  *code log_debug;
243 
244  // hash of features the telnet server has asked for
245  hash fh;
246 
247 public:
249 
250  // no public members
251 private:
252 
253 public:
254 
256 
261  constructor(string host, softint port, *code log, *code dbgLog);
262 
263 
265 
269  constructor(string connect, *code log, *code dbglog);
270 
271 
273  destructor();
274 
275 
277 
278 private:
279  log(string msg);
280 public:
281 
282 
284 
285 private:
286  logDbg(string msg);
287 public:
288 
289 
291 
294  connect(timeout timeout = DefaultConnTimeout);
295 
296 
298  bool isConnected();
299 
300 
302 
304  setUser(*string user);
305 
306 
308  *string getUser();
309 
310 
312 
314  disconnect();
315 
316 
318 
330  sendData(softlist arr);
331 
332 
334 
342  sendTextData(string str);
343 
344 
346 
352  *string getAvailableData(timeout t = DefaultTimeout);
353 
354 
356 
364  bool hasFeature(int fc);
365 
366 
368 
371 
372 
374 
377 private:
378  *string getDisplay();
379 public:
380 
381 
383 
386 private:
387  *string getTerminalType();
388 public:
389 
390 
392 
395 private:
397 public:
398 
399 
401 
404 private:
405  int getTerminalSpeed();
406 public:
407 
408 
410 
418 private:
420 public:
421 
422 
424  // don't override this method, fix/enhance it with a patch to the module
425 
426 private:
427  final disconnectIntern();
428 public:
429 
430 
431 
432 private:
433  checkConnIntern();
434 public:
435 
436 
437  // don't override this method, fix/enhance it with a patch to the module
438 
439 private:
440  final sendDataIntern(softlist arr, bool double_aic = False);
441 public:
442 
443 
444 
445 private:
446  sendTextDataIntern(string str);
447 public:
448 
449 
450  // don't override this method, fix/enhance it with a patch to the module
451 
452 private:
453  final *string getAvailableDataIntern(timeout t = DefaultTimeout);
454 public:
455 
456 
457  // don't override this method, fix/enhance it with a patch to the module
458 
459 private:
460  final updateWindowSizeIntern(hash wh);
461 public:
462 
463 
464  // don't override this method, fix/enhance it with a patch to the module
465 
466 private:
467  final processCmd(reference rv);
468 public:
469 
470 
471  // don't override this method, fix/enhance it with a patch to the module
472 
473 private:
474  final doSubNegotiation();
475 public:
476 
478  };
479 };