All Classes Namespaces Functions Variables Groups Pages
TelnetClient.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file TelnetClient.qm Telnet module definition
/* TelnetClient.qm Copyright 2012 - 2015 Qore Technologies sro
Original Author: Pavol Potancok
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// minimum required Qore version
// assume local var scope, do not use "$" for vars, members, and method calls
/* Version History
* 1.2: David Nichols <david@qore.org>: converted to new-style
* 1.1: David Nichols <david@qore.org>: added socket instrumention support from Qore 0.8.9
* 1.0: David Nichols <david@qore.org>: updated to a user module
* 0.9: Pavol Potancok <ppotancok@gmail.com>: original author
*/
namespace TelnetClient {
// default telnet port
const DefaultTelnetPort = 23;
// default connection timeout
const DefaultConnTimeout = 15s;
// default poll timeout
const DefaultTimeout = 100ms;
// default terminal type
const DefaultTerminalType = "xterm";
// default terminal speed
const DefaultTerminalSpeed = 38400;
const IAC = 255;
const DONT = 254;
const DO = 253;
const WONT = 252;
const WILL = 251;
const SE = 240;
const NOP = 241;
const DM = 242;
const BRK = 243;
const IP = 244;
const AO = 245;
const AYT = 246;
const EC = 247;
const EL = 248;
const GA = 249;
const SB = 250;
const CmdMap = (
IAC : "IAC",
DONT : "DONT",
DO : "DO",
WONT : "WONT",
WILL: "WILL",
SE : "SubnegotiationEnd",
NOP : "NoOperation",
DM: "DataMark",
BRK : "Break",
IP : "Interruptprocess",
AO : "Abortoutput",
AYT : "AreYouThere",
EC : "EraseCharacter",
EL : "EraseLine",
GA : "GoAhead",
SB : "SubnegotiationBegin",
);
const SUPDUP_OPT = 21; // SUPDUP_OPT display protocol
const TOPT_BIN = 0;
const TOPT_ECHO = 1;
const TOPT_RECN = 2;
const TOPT_SUPP = 3;
const TOPT_APRX = 4;
const TOPT_STAT = 5;
const TOPT_TIM = 6;
const TOPT_REM = 7;
const TOPT_OLW = 8;
const TOPT_OPS = 9;
const TOPT_OCRD = 10;
const TOPT_OHT = 11;
const TOPT_OHTD = 12;
const TOPT_OFD = 13;
const TOPT_OVT = 14;
const TOPT_OVTD = 15;
const TOPT_OLD = 16;
const TOPT_EXT = 17;
const TOPT_LOGO = 18;
const TOPT_BYTE = 19;
const TOPT_DATA = 20;
const TOPT_SUP = 21;
const TOPT_SUPO = 22;
const TOPT_SNDL = 23;
const TOPT_TERM = 24;
const TOPT_EOR = 25;
const TOPT_TACACS = 26;
const TOPT_OM = 27;
const TOPT_TLN = 28;
const TOPT_3270 = 29;
const TOPT_X3 = 30;
const TOPT_NAWS = 31;
const TOPT_TS = 32;
const TOPT_RFC = 33;
const TOPT_LINE = 34;
const TOPT_XDL = 35;
const TOPT_ENVIR = 36;
const TOPT_AUTH = 37;
const TOPT_ENVIR_NEW = 39;
const TOPT_TN3270 = 40;
const TOPT_X_AUTH = 41;
const TOPT_CHARSET = 42;
const TOPT_RSP = 43;
const TOPT_COMPORT = 44;
const TOPT_SLE = 45;
const TOPT_STARTTLS = 46;
const TOPT_KERMIT = 47;
const TOPT_SEND_URL = 48;
const TOPT_EXTOP = 255;
const OptMap = (
TOPT_BIN : "BinaryTransmission",
TOPT_ECHO : "Echo|Is|Send",
TOPT_RECN : "Reconnection",
TOPT_SUPP : "SuppressGoAhead",
TOPT_APRX : "ApproxMessageSizeNegotiation",
TOPT_STAT : "Status",
TOPT_TIM : "TimingMark",
TOPT_REM : "RemoteControlledTransandEcho",
TOPT_OLW : "OutputLineWidth",
TOPT_OPS : "OutputPageSize",
TOPT_OCRD : "OutputCarriage-ReturnDisposition",
TOPT_OHT : "OutputHorizontalTabstops",
TOPT_OHTD : "OutputHorizontalTabDisposition",
TOPT_OFD : "OutputFormfeedDisposition",
TOPT_OVT : "OutputVerticalTabstops",
TOPT_OVTD : "OutputVerticalTabDisposition",
TOPT_OLD : "OutputLinefeedDisposition",
TOPT_EXT : "ExtendedASCII",
TOPT_LOGO : "Logout",
TOPT_BYTE : "ByteMacro",
TOPT_DATA : "DataEntryTerminal",
TOPT_SUP : "SUPDUP",
TOPT_SUPO : "SUPDUPOutput",
TOPT_SNDL : "SendLocation",
TOPT_TERM : "TerminalType",
TOPT_EOR : "EndofRecord",
TOPT_TACACS : "TACACSUserIdent",
TOPT_OM : "OutputMarking",
TOPT_TLN : "TerminalLocationNumber",
TOPT_3270 : "Telnet3270Regime",
TOPT_X3 : "X.3PAD",
TOPT_NAWS : "NegotiateAboutWindowSize",
TOPT_TS : "TerminalSpeed",
TOPT_RFC : "RemoteFlowControl",
TOPT_LINE : "Linemode",
TOPT_XDL : "XDisplayLocation",
TOPT_ENVIR : "TelnetEnvironmentOption",
TOPT_AUTH : "TelnetAuthenticationOption",
TOPT_ENVIR_NEW : "TelnetNewEnvironmentOption",
TOPT_TN3270 : "TN3270Enhancements",
TOPT_X_AUTH : "TelnetXAUTH",
TOPT_CHARSET : "TelnetCHARSET",
TOPT_RSP : "TelnetRemoteSerialPort",
TOPT_COMPORT : "TelnetComPortControl",
TOPT_SLE : "TelnetSuppressLocalEcho",
TOPT_STARTTLS : "TelnetStartTLS",
TOPT_KERMIT : "TelnetKERMIT",
TOPT_SEND_URL : "Send-URL",
TOPT_EXTOP : "Extended-Options-List",
);
class TelnetClient {
public:
private :
// the connection string
string connect;
// the socket for all communication with the server
Socket conn();
// to manage contention on the Socket
Mutex m();
// login user
*string user;
// logging closures
*code log_info;
*code log_debug;
// hash of features the telnet server has asked for
hash fh;
public:
// no public members
private:
public:
constructor(string host, softint port, *code log, *code dbgLog);
constructor(string n_connect, *code n_log, *code n_dbglog);
destructor();
private log(string msg);
private logDbg(string msg);
connect(timeout timeout = DefaultConnTimeout);
bool isConnected();
setUser(*string n_user);
*string getUser();
disconnect();
sendData(softlist arr);
sendTextData(string str);
*string getAvailableData(timeout t = DefaultTimeout);
bool hasFeature(int fc);
windowSizeUpdated();
private *string getDisplay();
private *string getTerminalType();
private hash getEnvironment();
private int getTerminalSpeed();
private hash getWindowSize();
nothing clearWarningQueue();
nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, any arg, timeout min_ms = 1s);
hash getUsageInfo();
clearStats();
// don't override this method, fix/enhance it with a patch to the module
private final disconnectIntern();
private checkConnIntern();
// don't override this method, fix/enhance it with a patch to the module
private final sendDataIntern(softlist arr, bool double_aic = False);
private sendTextDataIntern(string str);
// don't override this method, fix/enhance it with a patch to the module
private final *string getAvailableDataIntern(timeout t = DefaultTimeout);
// don't override this method, fix/enhance it with a patch to the module
private final updateWindowSizeIntern(hash wh);
// don't override this method, fix/enhance it with a patch to the module
private final processCmd(reference rv);
// don't override this method, fix/enhance it with a patch to the module
private final doSubNegotiation();
};
};
TelnetClient::TOPT_OCRD
const TOPT_OCRD
OutputCarriage-ReturnDisposition.
Definition: TelnetClient.qm.dox.h:133
TelnetClient::TelnetClient::setUser
setUser(*string n_user)
sets or clears (in case passed with no value) the username parameter for logging in to the telnet ser...
TelnetClient::TOPT_OHTD
const TOPT_OHTD
OutputHorizontalTabDisposition.
Definition: TelnetClient.qm.dox.h:135
TelnetClient::TelnetClient::clearStats
clearStats()
Clears performance statistics.
TelnetClient::BRK
const BRK
Break.
Definition: TelnetClient.qm.dox.h:88
TelnetClient::TOPT_SUPO
const TOPT_SUPO
SUPDUPOutput.
Definition: TelnetClient.qm.dox.h:145
TelnetClient::GA
const GA
Go Ahead.
Definition: TelnetClient.qm.dox.h:94
TelnetClient::TelnetClient::isConnected
bool isConnected()
returns True if the client is connected to the server
TelnetClient::TOPT_EXTOP
const TOPT_EXTOP
Extended-Options-List.
Definition: TelnetClient.qm.dox.h:171
TelnetClient::TOPT_APRX
const TOPT_APRX
ApproxMessageSizeNegotiation.
Definition: TelnetClient.qm.dox.h:127
TelnetClient::TelnetClient::getUser
*string getUser()
returns the current value of the username parameter
TelnetClient::TOPT_NAWS
const TOPT_NAWS
NegotiateAboutWindowSize.
Definition: TelnetClient.qm.dox.h:154
TelnetClient::TOPT_OVTD
const TOPT_OVTD
OutputVerticalTabDisposition.
Definition: TelnetClient.qm.dox.h:138
TelnetClient::TOPT_TS
const TOPT_TS
TerminalSpeed.
Definition: TelnetClient.qm.dox.h:155
TelnetClient::TOPT_SUP
const TOPT_SUP
SUPDUP.
Definition: TelnetClient.qm.dox.h:144
TelnetClient::TelnetClient::getTerminalSpeed
private int getTerminalSpeed()
this method provides the value that will be given as the terminal speed in protocol negotiation ...
TelnetClient::TOPT_STAT
const TOPT_STAT
Status.
Definition: TelnetClient.qm.dox.h:128
TelnetClient::TelnetClient::constructor
constructor(string host, softint port, *code log, *code dbgLog)
creates the TelnetClient object
TelnetClient::TOPT_STARTTLS
const TOPT_STARTTLS
TelnetStartTLS.
Definition: TelnetClient.qm.dox.h:168
TelnetClient::TOPT_SUPP
const TOPT_SUPP
SuppressGoAhead.
Definition: TelnetClient.qm.dox.h:126
TelnetClient::TOPT_DATA
const TOPT_DATA
DataEntryTerminal.
Definition: TelnetClient.qm.dox.h:143
TelnetClient::TelnetClient::hasFeature
bool hasFeature(int fc)
returns True if the server has confirmed with a DO command that it supports the given feature ...
TelnetClient::TOPT_COMPORT
const TOPT_COMPORT
TelnetComPortControl.
Definition: TelnetClient.qm.dox.h:166
TelnetClient::WILL
const WILL
WILL.
Definition: TelnetClient.qm.dox.h:84
TelnetClient::TOPT_X_AUTH
const TOPT_X_AUTH
TelnetXAUTH.
Definition: TelnetClient.qm.dox.h:163
TelnetClient::TelnetClient::clearWarningQueue
nothing clearWarningQueue()
Removes any warning Queue object from the Socket.
TelnetClient::EL
const EL
Erase Line.
Definition: TelnetClient.qm.dox.h:93
TelnetClient::TelnetClient::connect
connect(timeout timeout=DefaultConnTimeout)
connects to the Telnet server
False
const False
TelnetClient::TOPT_OM
const TOPT_OM
OutputMarking.
Definition: TelnetClient.qm.dox.h:150
TelnetClient::TOPT_CHARSET
const TOPT_CHARSET
TelnetCHARSET.
Definition: TelnetClient.qm.dox.h:164
TelnetClient::TelnetClient::windowSizeUpdated
windowSizeUpdated()
this method should be called externally when the window size has changed
TelnetClient::DO
const DO
DO.
Definition: TelnetClient.qm.dox.h:82
TelnetClient::TOPT_SNDL
const TOPT_SNDL
SendLocation.
Definition: TelnetClient.qm.dox.h:146
TelnetClient::TelnetClient
The TelnetClient class allows communication with a telnet server; it can be used directly or subclass...
Definition: TelnetClient.qm.dox.h:231
TelnetClient::TOPT_OFD
const TOPT_OFD
OutputFormfeedDisposition.
Definition: TelnetClient.qm.dox.h:136
TelnetClient::TOPT_OPS
const TOPT_OPS
OutputPageSize.
Definition: TelnetClient.qm.dox.h:132
TelnetClient::SB
const SB
Subnegotiation Begin.
Definition: TelnetClient.qm.dox.h:95
TelnetClient::TOPT_REM
const TOPT_REM
RemoteControlledTransandEcho.
Definition: TelnetClient.qm.dox.h:130
TelnetClient::TOPT_BIN
const TOPT_BIN
BinaryTransmission.
Definition: TelnetClient.qm.dox.h:123
TelnetClient::TOPT_LOGO
const TOPT_LOGO
Logout.
Definition: TelnetClient.qm.dox.h:141
TelnetClient::EC
const EC
Erase Character.
Definition: TelnetClient.qm.dox.h:92
TelnetClient::TOPT_OLW
const TOPT_OLW
OutputLineWidth.
Definition: TelnetClient.qm.dox.h:131
TelnetClient::TelnetClient::getUsageInfo
hash getUsageInfo()
Returns performance statistics for the socket.
TelnetClient::AYT
const AYT
Are You There.
Definition: TelnetClient.qm.dox.h:91
TelnetClient::TelnetClient::getEnvironment
private hash getEnvironment()
this method provides the value that will be given as the user&#39;s environment in protocol negotiation ...
TelnetClient::TOPT_SEND_URL
const TOPT_SEND_URL
Send-URL.
Definition: TelnetClient.qm.dox.h:170
TelnetClient::TOPT_TERM
const TOPT_TERM
TerminalType.
Definition: TelnetClient.qm.dox.h:147
TelnetClient::TelnetClient::sendData
sendData(softlist arr)
sends data to the server
TelnetClient::TelnetClient::log
private log(string msg)
logs the message to the log closure set with the constructor (if any)
TelnetClient::TelnetClient::getTerminalType
private *string getTerminalType()
this method provides the value that will be given as the terminal type in protocol negotiation ...
TelnetClient::TOPT_ECHO
const TOPT_ECHO
Echo|Is|Send.
Definition: TelnetClient.qm.dox.h:124
TelnetClient::TelnetClient::sendTextData
sendTextData(string str)
sends literal string data to the server; the text dat is converted to the socket&#39;s encoding if necess...
TelnetClient::TelnetClient::getDisplay
private *string getDisplay()
this method provides the value that will be given as the DISPLAY value in protocol negotiation ...
TelnetClient::TOPT_TACACS
const TOPT_TACACS
TACACSUserIdent.
Definition: TelnetClient.qm.dox.h:149
HttpServer::DefaultTimeout
const DefaultTimeout
TelnetClient::TOPT_TLN
const TOPT_TLN
TerminalLocationNumber.
Definition: TelnetClient.qm.dox.h:151
TelnetClient::TelnetClient::destructor
destructor()
disconnects from the server if connected and deletes the object
TelnetClient::CmdMap
const CmdMap
command name map
Definition: TelnetClient.qm.dox.h:98
TelnetClient::TOPT_XDL
const TOPT_XDL
XDisplayLocation.
Definition: TelnetClient.qm.dox.h:158
TelnetClient::TOPT_TN3270
const TOPT_TN3270
TN3270Enhancements.
Definition: TelnetClient.qm.dox.h:162
TelnetClient::TelnetClient::disconnect
disconnect()
disconnects from the Telnet server
TelnetClient::TOPT_LINE
const TOPT_LINE
Linemode.
Definition: TelnetClient.qm.dox.h:157
TelnetClient::TOPT_AUTH
const TOPT_AUTH
TelnetAuthenticationOption.
Definition: TelnetClient.qm.dox.h:160
TelnetClient::IP
const IP
Interrupt process.
Definition: TelnetClient.qm.dox.h:89
TelnetClient::TOPT_EOR
const TOPT_EOR
EndofRecord.
Definition: TelnetClient.qm.dox.h:148
TelnetClient::TOPT_ENVIR
const TOPT_ENVIR
TelnetEnvironmentOption.
Definition: TelnetClient.qm.dox.h:159
TelnetClient::TOPT_BYTE
const TOPT_BYTE
ByteMacro.
Definition: TelnetClient.qm.dox.h:142
TelnetClient::TOPT_ENVIR_NEW
const TOPT_ENVIR_NEW
TelnetNewEnvironmentOption.
Definition: TelnetClient.qm.dox.h:161
TelnetClient::TOPT_OLD
const TOPT_OLD
OutputLinefeedDisposition.
Definition: TelnetClient.qm.dox.h:139
TelnetClient::TelnetClient::setWarningQueue
nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, any arg, timeout min_ms=1s)
Sets a Queue object to receive socket warnings.
TelnetClient::AO
const AO
Abort output.
Definition: TelnetClient.qm.dox.h:90
TelnetClient::TOPT_OVT
const TOPT_OVT
OutputVerticalTabstops.
Definition: TelnetClient.qm.dox.h:137
TelnetClient::NOP
const NOP
No Operation.
Definition: TelnetClient.qm.dox.h:86
TelnetClient::TelnetClient::logDbg
private logDbg(string msg)
logs the message to the debug log closure set with the constructor (if any)
TelnetClient::TOPT_X3
const TOPT_X3
X.3PAD.
Definition: TelnetClient.qm.dox.h:153
hash
hash hash(object obj)
TelnetClient::TOPT_OHT
const TOPT_OHT
OutputHorizontalTabstops.
Definition: TelnetClient.qm.dox.h:134
TelnetClient::IAC
const IAC
IAC.
Definition: TelnetClient.qm.dox.h:80
TelnetClient::TOPT_RSP
const TOPT_RSP
TelnetRemoteSerialPort.
Definition: TelnetClient.qm.dox.h:165
TelnetClient::TOPT_SLE
const TOPT_SLE
TelnetSuppressLocalEcho.
Definition: TelnetClient.qm.dox.h:167
TelnetClient::TOPT_RFC
const TOPT_RFC
RemoteFlowControl.
Definition: TelnetClient.qm.dox.h:156
TelnetClient::WONT
const WONT
WONT.
Definition: TelnetClient.qm.dox.h:83
TelnetClient::DONT
const DONT
DONT.
Definition: TelnetClient.qm.dox.h:81
TelnetClient::TOPT_RECN
const TOPT_RECN
Reconnection.
Definition: TelnetClient.qm.dox.h:125
TelnetClient::SE
const SE
Subnegotiation End.
Definition: TelnetClient.qm.dox.h:85
TelnetClient::TOPT_KERMIT
const TOPT_KERMIT
TelnetKERMIT.
Definition: TelnetClient.qm.dox.h:169
TelnetClient::DM
const DM
Data Mark.
Definition: TelnetClient.qm.dox.h:87
TelnetClient::TelnetClient::getWindowSize
private hash getWindowSize()
this method provides the value that will be given as the terminal window size in protocol negotiation...
TelnetClient::OptMap
const OptMap
option map, maps codes to text descriptions
Definition: TelnetClient.qm.dox.h:174
TelnetClient::TOPT_EXT
const TOPT_EXT
ExtendedASCII.
Definition: TelnetClient.qm.dox.h:140
TelnetClient::TOPT_3270
const TOPT_3270
Telnet3270Regime.
Definition: TelnetClient.qm.dox.h:152
TelnetClient::TelnetClient::getAvailableData
*string getAvailableData(timeout t=DefaultTimeout)
returns all data available as a string (which could be an empty string if no data is available in the...
TelnetClient::TOPT_TIM
const TOPT_TIM
TimingMark.
Definition: TelnetClient.qm.dox.h:129