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 Pavol Potancok, David Nichols
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.
*/
/* Version History
* 1.0: updated by David Nichols <david@qore.org> to a user module
* 0.9: original author Pavol Potancok <ppotancok@gmail.com>
*/
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 connect, *code log, *code dbglog);
destructor();
private:
log(string msg);
public:
private:
logDbg(string msg);
public:
connect(timeout timeout = DefaultConnTimeout);
bool isConnected();
setUser(*string user);
*string getUser();
disconnect();
sendData(softlist arr);
sendTextData(string str);
*string getAvailableData(timeout t = DefaultTimeout);
bool hasFeature(int fc);
windowSizeUpdated();
private:
*string getDisplay();
public:
private:
*string getTerminalType();
public:
private:
hash getEnvironment();
public:
private:
int getTerminalSpeed();
public:
private:
hash getWindowSize();
public:
// don't override this method, fix/enhance it with a patch to the module
private:
final disconnectIntern();
public:
private:
checkConnIntern();
public:
// don't override this method, fix/enhance it with a patch to the module
private:
final sendDataIntern(softlist arr, bool double_aic = False);
public:
private:
sendTextDataIntern(string str);
public:
// don't override this method, fix/enhance it with a patch to the module
private:
final *string getAvailableDataIntern(timeout t = DefaultTimeout);
public:
// don't override this method, fix/enhance it with a patch to the module
private:
final updateWindowSizeIntern(hash wh);
public:
// don't override this method, fix/enhance it with a patch to the module
private:
final processCmd(reference rv);
public:
// don't override this method, fix/enhance it with a patch to the module
private:
final doSubNegotiation();
public:
};
};