Qore TelnetClient Module Reference  1.3
TelnetClient.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file TelnetClient.qm Telnet module definition
3 
4 /* TelnetClient.qm Copyright 2012 - 2017 Qore Technologies s.r.o.
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 // minimum required Qore version
28 
29 // assume local var scope, do not use "$" for vars, members, and method calls
30 
31 
32 
75 namespace TelnetClient {
80  // default telnet port
81  const DefaultTelnetPort = 23;
82 
83  // default connection timeout
84  const DefaultConnTimeout = 15s;
85 
86  // default poll timeout
87  const DefaultTimeout = 100ms;
88 
89  // default terminal type
90  const DefaultTerminalType = "xterm";
91 
92  // default terminal speed
93  const DefaultTerminalSpeed = 38400;
95 
99  const IAC = 255;
100  const DONT = 254;
101  const DO = 253;
102  const WONT = 252;
103  const WILL = 251;
104  const SE = 240;
105  const NOP = 241;
106  const DM = 242;
107  const BRK = 243;
108  const IP = 244;
109  const AO = 245;
110  const AYT = 246;
111  const EC = 247;
112  const EL = 248;
113  const GA = 249;
114  const SB = 250;
115 
117  const CmdMap = (
118  IAC : "IAC",
119  DONT : "DONT",
120  DO : "DO",
121  WONT : "WONT",
122  WILL: "WILL",
123  SE : "SubnegotiationEnd",
124  NOP : "NoOperation",
125  DM: "DataMark",
126  BRK : "Break",
127  IP : "Interruptprocess",
128  AO : "Abortoutput",
129  AYT : "AreYouThere",
130  EC : "EraseCharacter",
131  EL : "EraseLine",
132  GA : "GoAhead",
133  SB : "SubnegotiationBegin",
134  );
136 
137  const SUPDUP_OPT = 21; // SUPDUP_OPT display protocol
138 
142  const TOPT_BIN = 0;
143  const TOPT_ECHO = 1;
144  const TOPT_RECN = 2;
145  const TOPT_SUPP = 3;
146  const TOPT_APRX = 4;
147  const TOPT_STAT = 5;
148  const TOPT_TIM = 6;
149  const TOPT_REM = 7;
150  const TOPT_OLW = 8;
151  const TOPT_OPS = 9;
152  const TOPT_OCRD = 10;
153  const TOPT_OHT = 11;
154  const TOPT_OHTD = 12;
155  const TOPT_OFD = 13;
156  const TOPT_OVT = 14;
157  const TOPT_OVTD = 15;
158  const TOPT_OLD = 16;
159  const TOPT_EXT = 17;
160  const TOPT_LOGO = 18;
161  const TOPT_BYTE = 19;
162  const TOPT_DATA = 20;
163  const TOPT_SUP = 21;
164  const TOPT_SUPO = 22;
165  const TOPT_SNDL = 23;
166  const TOPT_TERM = 24;
167  const TOPT_EOR = 25;
168  const TOPT_TACACS = 26;
169  const TOPT_OM = 27;
170  const TOPT_TLN = 28;
171  const TOPT_3270 = 29;
172  const TOPT_X3 = 30;
173  const TOPT_NAWS = 31;
174  const TOPT_TS = 32;
175  const TOPT_RFC = 33;
176  const TOPT_LINE = 34;
177  const TOPT_XDL = 35;
178  const TOPT_ENVIR = 36;
179  const TOPT_AUTH = 37;
180  const TOPT_ENVIR_NEW = 39;
181  const TOPT_TN3270 = 40;
182  const TOPT_X_AUTH = 41;
183  const TOPT_CHARSET = 42;
184  const TOPT_RSP = 43;
185  const TOPT_COMPORT = 44;
186  const TOPT_SLE = 45;
187  const TOPT_STARTTLS = 46;
188  const TOPT_KERMIT = 47;
189  const TOPT_SEND_URL = 48;
190  const TOPT_EXTOP = 255;
191 
193  const OptMap = (
194  TOPT_BIN : "BinaryTransmission",
195  TOPT_ECHO : "Echo|Is|Send",
196  TOPT_RECN : "Reconnection",
197  TOPT_SUPP : "SuppressGoAhead",
198  TOPT_APRX : "ApproxMessageSizeNegotiation",
199  TOPT_STAT : "Status",
200  TOPT_TIM : "TimingMark",
201  TOPT_REM : "RemoteControlledTransandEcho",
202  TOPT_OLW : "OutputLineWidth",
203  TOPT_OPS : "OutputPageSize",
204  TOPT_OCRD : "OutputCarriage-ReturnDisposition",
205  TOPT_OHT : "OutputHorizontalTabstops",
206  TOPT_OHTD : "OutputHorizontalTabDisposition",
207  TOPT_OFD : "OutputFormfeedDisposition",
208  TOPT_OVT : "OutputVerticalTabstops",
209  TOPT_OVTD : "OutputVerticalTabDisposition",
210  TOPT_OLD : "OutputLinefeedDisposition",
211  TOPT_EXT : "ExtendedASCII",
212  TOPT_LOGO : "Logout",
213  TOPT_BYTE : "ByteMacro",
214  TOPT_DATA : "DataEntryTerminal",
215  TOPT_SUP : "SUPDUP",
216  TOPT_SUPO : "SUPDUPOutput",
217  TOPT_SNDL : "SendLocation",
218  TOPT_TERM : "TerminalType",
219  TOPT_EOR : "EndofRecord",
220  TOPT_TACACS : "TACACSUserIdent",
221  TOPT_OM : "OutputMarking",
222  TOPT_TLN : "TerminalLocationNumber",
223  TOPT_3270 : "Telnet3270Regime",
224  TOPT_X3 : "X.3PAD",
225  TOPT_NAWS : "NegotiateAboutWindowSize",
226  TOPT_TS : "TerminalSpeed",
227  TOPT_RFC : "RemoteFlowControl",
228  TOPT_LINE : "Linemode",
229  TOPT_XDL : "XDisplayLocation",
230  TOPT_ENVIR : "TelnetEnvironmentOption",
231  TOPT_AUTH : "TelnetAuthenticationOption",
232  TOPT_ENVIR_NEW : "TelnetNewEnvironmentOption",
233  TOPT_TN3270 : "TN3270Enhancements",
234  TOPT_X_AUTH : "TelnetXAUTH",
235  TOPT_CHARSET : "TelnetCHARSET",
236  TOPT_RSP : "TelnetRemoteSerialPort",
237  TOPT_COMPORT : "TelnetComPortControl",
238  TOPT_SLE : "TelnetSuppressLocalEcho",
239  TOPT_STARTTLS : "TelnetStartTLS",
240  TOPT_KERMIT : "TelnetKERMIT",
241  TOPT_SEND_URL : "Send-URL",
242  TOPT_EXTOP : "Extended-Options-List",
243  );
245 
247 
250  class TelnetClient {
251 
252 public:
254  private :
255  // the connection string
256  string connect;
257 
258  // the socket for all communication with the server
259  Socket conn();
260 
261  // to manage contention on the Socket
262  Mutex m();
263 
264  // login user
265  *string user;
266 
267  // logging closures
268  *code log_info;
269  *code log_debug;
270 
271  // hash of features the telnet server has asked for
272  hash fh;
273 
274 public:
276 
277  // no public members
278 private:
279 
280 public:
281 
283 
288  constructor(string host, softint port, *code log, *code dbglog);
289 
290 
292 
304  constructor(string connect, *code log, *code dbglog);
305 
306 
308  destructor();
309 
310 
312 
313 private:
314  log(string msg);
315 public:
316 
317 
319 
320 private:
321  logDbg(string msg);
322 public:
323 
324 
326 
329  connect(timeout timeout = DefaultConnTimeout);
330 
331 
333  bool isConnected();
334 
335 
337 
341  setUser(*string n_user);
342 
343 
345  *string getUser();
346 
347 
349 
351  disconnect();
352 
353 
355 
367  sendData(softlist arr);
368 
369 
371 
379  sendTextData(string str);
380 
381 
383 
389  *string getAvailableData(timeout t = DefaultTimeout);
390 
391 
393 
401  bool hasFeature(int fc);
402 
403 
405 
407  windowSizeUpdated();
408 
409 
411 
414 private:
415  *string getDisplay();
416 public:
417 
418 
420 
423 private:
424  *string getTerminalType();
425 public:
426 
427 
429 
432 private:
433  hash getEnvironment();
434 public:
435 
436 
438 
441 private:
442  int getTerminalSpeed();
443 public:
444 
445 
447 
455 private:
456  hash getWindowSize();
457 public:
458 
459 
461 
470  nothing clearWarningQueue();
471 
472 
474 
504  nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, any arg, timeout min_ms = 1s);
505 
506 
508 
526  hash getUsageInfo();
527 
528 
530 
539  clearStats();
540 
541 
543 
545  string getTarget();
546 
547 
549  // don't override this method, fix/enhance it with a patch to the module
550 
551 private:
552  final disconnectIntern();
553 public:
554 
555 
556 
557 private:
558  checkConnIntern();
559 public:
560 
561 
562  // don't override this method, fix/enhance it with a patch to the module
563 
564 private:
565  final sendDataIntern(softlist arr, bool double_aic = False);
566 public:
567 
568 
569 
570 private:
571  sendTextDataIntern(string str);
572 public:
573 
574 
575  // don't override this method, fix/enhance it with a patch to the module
576 
577 private:
578  final *string getAvailableDataIntern(timeout t = DefaultTimeout);
579 public:
580 
581 
582  // don't override this method, fix/enhance it with a patch to the module
583 
584 private:
585  final updateWindowSizeIntern(hash wh);
586 public:
587 
588 
589  // don't override this method, fix/enhance it with a patch to the module
590 
591 private:
592  final processCmd(reference<string> rv);
593 public:
594 
595 
596  // don't override this method, fix/enhance it with a patch to the module
597 
598 private:
599  final doSubNegotiation();
600 public:
601 
603  };
604 
606 
613 
614 public:
616 
623  constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
624 
625 
627  string getType();
628 
629 
631 
636 
637 
639 
647 private:
648  TelnetClient getImpl(bool connect = True, *hash rtopts);
649 public:
650 
651 
653  static TelnetConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
654  };
655 };
const TOPT_OCRD
OutputCarriage-ReturnDisposition.
Definition: TelnetClient.qm.dox.h:152
const TOPT_OHTD
OutputHorizontalTabDisposition.
Definition: TelnetClient.qm.dox.h:154
const BRK
Break.
Definition: TelnetClient.qm.dox.h:107
const TOPT_SUPO
SUPDUPOutput.
Definition: TelnetClient.qm.dox.h:164
const GA
Go Ahead.
Definition: TelnetClient.qm.dox.h:113
const TOPT_EXTOP
Extended-Options-List.
Definition: TelnetClient.qm.dox.h:190
const TOPT_APRX
ApproxMessageSizeNegotiation.
Definition: TelnetClient.qm.dox.h:146
*hash getRuntimeOptions()
returns runtime options
const TOPT_NAWS
NegotiateAboutWindowSize.
Definition: TelnetClient.qm.dox.h:173
const TOPT_OVTD
OutputVerticalTabDisposition.
Definition: TelnetClient.qm.dox.h:157
const TOPT_TS
TerminalSpeed.
Definition: TelnetClient.qm.dox.h:174
const TOPT_SUP
SUPDUP.
Definition: TelnetClient.qm.dox.h:163
contains constant definitions and the definition of the TelnetClient class
Definition: TelnetClient.qm.dox.h:76
const TOPT_STAT
Status.
Definition: TelnetClient.qm.dox.h:147
const True
const TOPT_STARTTLS
TelnetStartTLS.
Definition: TelnetClient.qm.dox.h:187
const TOPT_SUPP
SuppressGoAhead.
Definition: TelnetClient.qm.dox.h:145
const TOPT_DATA
DataEntryTerminal.
Definition: TelnetClient.qm.dox.h:162
const TOPT_COMPORT
TelnetComPortControl.
Definition: TelnetClient.qm.dox.h:185
const WILL
WILL.
Definition: TelnetClient.qm.dox.h:103
const TOPT_X_AUTH
TelnetXAUTH.
Definition: TelnetClient.qm.dox.h:182
const EL
Erase Line.
Definition: TelnetClient.qm.dox.h:112
const False
const TOPT_OM
OutputMarking.
Definition: TelnetClient.qm.dox.h:169
const TOPT_CHARSET
TelnetCHARSET.
Definition: TelnetClient.qm.dox.h:183
const DO
DO.
Definition: TelnetClient.qm.dox.h:101
const TOPT_SNDL
SendLocation.
Definition: TelnetClient.qm.dox.h:165
const TOPT_OFD
OutputFormfeedDisposition.
Definition: TelnetClient.qm.dox.h:155
const TOPT_OPS
OutputPageSize.
Definition: TelnetClient.qm.dox.h:151
const SB
Subnegotiation Begin.
Definition: TelnetClient.qm.dox.h:114
const TOPT_REM
RemoteControlledTransandEcho.
Definition: TelnetClient.qm.dox.h:149
const TOPT_BIN
BinaryTransmission.
Definition: TelnetClient.qm.dox.h:142
const TOPT_LOGO
Logout.
Definition: TelnetClient.qm.dox.h:160
const EC
Erase Character.
Definition: TelnetClient.qm.dox.h:111
const TOPT_OLW
OutputLineWidth.
Definition: TelnetClient.qm.dox.h:150
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the TelnetConnection object
const AYT
Are You There.
Definition: TelnetClient.qm.dox.h:110
const TOPT_SEND_URL
Send-URL.
Definition: TelnetClient.qm.dox.h:189
const TOPT_TERM
TerminalType.
Definition: TelnetClient.qm.dox.h:166
string getType()
returns "telnet"
const TOPT_ECHO
Echo|Is|Send.
Definition: TelnetClient.qm.dox.h:143
const TOPT_TACACS
TACACSUserIdent.
Definition: TelnetClient.qm.dox.h:168
const DefaultTimeout
const TOPT_TLN
TerminalLocationNumber.
Definition: TelnetClient.qm.dox.h:170
const CmdMap
command name map
Definition: TelnetClient.qm.dox.h:117
const TOPT_XDL
XDisplayLocation.
Definition: TelnetClient.qm.dox.h:177
const TOPT_TN3270
TN3270Enhancements.
Definition: TelnetClient.qm.dox.h:181
const TOPT_LINE
Linemode.
Definition: TelnetClient.qm.dox.h:176
const TOPT_AUTH
TelnetAuthenticationOption.
Definition: TelnetClient.qm.dox.h:179
TelnetClient getImpl(bool connect=True, *hash rtopts)
returns an TelnetClient object
static TelnetConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
const IP
Interrupt process.
Definition: TelnetClient.qm.dox.h:108
const TOPT_EOR
EndofRecord.
Definition: TelnetClient.qm.dox.h:167
const TOPT_ENVIR
TelnetEnvironmentOption.
Definition: TelnetClient.qm.dox.h:178
const TOPT_BYTE
ByteMacro.
Definition: TelnetClient.qm.dox.h:161
const TOPT_ENVIR_NEW
TelnetNewEnvironmentOption.
Definition: TelnetClient.qm.dox.h:180
const TOPT_OLD
OutputLinefeedDisposition.
Definition: TelnetClient.qm.dox.h:158
const AO
Abort output.
Definition: TelnetClient.qm.dox.h:109
const TOPT_OVT
OutputVerticalTabstops.
Definition: TelnetClient.qm.dox.h:156
const NOP
No Operation.
Definition: TelnetClient.qm.dox.h:105
const TOPT_X3
X.3PAD.
Definition: TelnetClient.qm.dox.h:172
hash hash(object obj)
const TOPT_OHT
OutputHorizontalTabstops.
Definition: TelnetClient.qm.dox.h:153
const IAC
IAC.
Definition: TelnetClient.qm.dox.h:99
const TOPT_RSP
TelnetRemoteSerialPort.
Definition: TelnetClient.qm.dox.h:184
class for Telnet connections; returns an object of class TelnetClient for connecting to telnet sessio...
Definition: TelnetClient.qm.dox.h:612
const TOPT_SLE
TelnetSuppressLocalEcho.
Definition: TelnetClient.qm.dox.h:186
const TOPT_RFC
RemoteFlowControl.
Definition: TelnetClient.qm.dox.h:175
const WONT
WONT.
Definition: TelnetClient.qm.dox.h:102
const DONT
DONT.
Definition: TelnetClient.qm.dox.h:100
const TOPT_RECN
Reconnection.
Definition: TelnetClient.qm.dox.h:144
const SE
Subnegotiation End.
Definition: TelnetClient.qm.dox.h:104
const TOPT_KERMIT
TelnetKERMIT.
Definition: TelnetClient.qm.dox.h:188
const DM
Data Mark.
Definition: TelnetClient.qm.dox.h:106
const OptMap
option map, maps codes to text descriptions
Definition: TelnetClient.qm.dox.h:193
const TOPT_EXT
ExtendedASCII.
Definition: TelnetClient.qm.dox.h:159
const TOPT_3270
Telnet3270Regime.
Definition: TelnetClient.qm.dox.h:171
const TOPT_TIM
TimingMark.
Definition: TelnetClient.qm.dox.h:148