All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
telnet.h
Go to the documentation of this file.
/*
* telnet.h
*
* TELNET Socket class.
*
* Portable Windows Library
*
* Copyright (c) 1993-2002 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_TELNET_H
#define PTLIB_TELNET_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptlib/sockets.h>
class PTelnetSocket : public PTCPSocket
{
PCLASSINFO(PTelnetSocket, PTCPSocket)
public:
PTelnetSocket();
// Create an unopened TELNET socket.
PTelnetSocket(
const PString & address
);
// Create an opened TELNET socket.
// Overrides from class PChannel
PBoolean Read(
void * buf,
PINDEX len
);
PBoolean Write(
const void * buf,
PINDEX len
);
virtual bool SetLocalEcho(
bool localEcho
);
virtual PBoolean Connect(
const PString & address
);
virtual PBoolean Accept(
PSocket & socket
);
virtual void OnOutOfBand(
const void * buf,
PINDEX len
);
// New functions
enum Command {
IAC = 255,
DONT = 254,
DO = 253,
WONT = 252,
WILL = 251,
SB = 250,
GoAhead = 249,
EraseLine = 248,
EraseChar = 247,
AreYouThere = 246,
AbortOutput = 245,
InterruptProcess = 244,
Break = 243,
DataMark = 242,
NOP = 241,
SE = 240,
EndOfReccord = 239,
AbortProcess = 238,
SuspendProcess= 237,
EndOfFile = 236
};
// Defined telnet commands codes
PBoolean SendCommand(
Command cmd,
int opt = 0
);
enum Options {
TransmitBinary = 0,
EchoOption = 1,
ReconnectOption = 2,
SuppressGoAhead = 3,
MessageSizeOption = 4,
StatusOption = 5,
TimingMark = 6,
RCTEOption = 7,
OutputLineWidth = 8,
OutputPageSize = 9,
CRDisposition = 10,
HorizontalTabsStops = 11,
HorizTabDisposition = 12,
FormFeedDisposition = 13,
VerticalTabStops = 14,
VertTabDisposition = 15,
LineFeedDisposition = 16,
ExtendedASCII = 17,
ForceLogout = 18,
ByteMacroOption = 19,
DataEntryTerminal = 20,
SupDupProtocol = 21,
SupDupOutput = 22,
SendLocation = 23,
TerminalType = 24,
EndOfRecordOption = 25,
TACACSUID = 26,
OutputMark = 27,
TerminalLocation = 28,
Use3270RegimeOption = 29,
UseX3PADOption = 30,
WindowSize = 31,
TerminalSpeed = 32,
FlowControl = 33,
LineModeOption = 34,
XDisplayLocation = 35,
EnvironmentOption = 36,
AuthenticateOption = 37,
EncriptionOption = 38,
EncryptionOption = 38,
ExtendedOptionsList = 255,
MaxOptions
};
// Defined TELNET options.
virtual PBoolean SendDo(
BYTE option
);
virtual PBoolean SendDont(
BYTE option
);
virtual PBoolean SendWill(
BYTE option
);
virtual PBoolean SendWont(
BYTE option
);
enum SubOptionCodes {
SubOptionIs = 0,
SubOptionSend = 1,
};
// Codes for sub option negotiation.
PBoolean SendSubOption(
BYTE code,
const BYTE * info,
PINDEX len,
int subCode = -1
);
void SetOurOption(
BYTE code,
PBoolean state = true
) { option[code].weCan = state; }
void SetTheirOption(
BYTE code,
PBoolean state = true
) { option[code].theyShould = state; }
PBoolean IsOurOption(
BYTE code
) const { return option[code].ourState == OptionInfo::IsYes; }
PBoolean IsTheirOption(
BYTE code
) const { return option[code].theirState == OptionInfo::IsYes; }
void SetTerminalType(
const PString & newType
);
// Set the terminal type description string for TELNET protocol.
const PString & GetTerminalType() const { return terminalType; }
// Get the terminal type description string for TELNET protocol.
void SetWindowSize(
WORD width,
WORD height
);
// Set the width and height of the Network Virtual Terminal window.
void GetWindowSize(
WORD & width,
WORD & height
) const;
// Get the width and height of the Network Virtual Terminal window.
protected:
void Construct();
// Common construct code for TELNET socket channel.
virtual void OnDo(
BYTE option
);
virtual void OnDont(
BYTE option
);
virtual void OnWill(
BYTE option
);
virtual void OnWont(
BYTE option
);
virtual void OnSubOption(
BYTE code,
const BYTE * info,
PINDEX len
);
virtual PBoolean OnCommand(
BYTE code
);
// Member variables.
struct OptionInfo {
enum {
IsNo, IsYes, WantNo, WantNoQueued, WantYes, WantYesQueued
};
unsigned weCan:1; // We can do the option if they want us to do.
unsigned ourState:3;
unsigned theyShould:1; // They should if they will.
unsigned theirState:3;
};
OptionInfo option[MaxOptions];
// Information on protocol options.
PString terminalType;
// Type of terminal connected to telnet socket, defaults to "UNKNOWN"
WORD windowWidth, windowHeight;
// Size of the "window" used by the NVT.
private:
enum State {
StateNormal,
StateCarriageReturn,
StateIAC,
StateDo,
StateDont,
StateWill,
StateWont,
StateSubNegotiations,
StateEndNegotiations
};
// Internal states for the TELNET decoder
State state;
// Current state of incoming characters.
PBYTEArray subOption;
// Storage for sub-negotiated options
unsigned synchronising;
};
#endif // PTLIB_TELNET_H
// End Of File ///////////////////////////////////////////////////////////////
PTelnetSocket::EnvironmentOption
Provide environment information.
Definition: telnet.h:243
PTelnetSocket::Connect
virtual PBoolean Connect(const PString &address)
Connect a socket to a remote host on the specified port number.
PTelnetSocket::SetWindowSize
void SetWindowSize(WORD width, WORD height)
PTelnetSocket::HorizTabDisposition
Negotiate about horizontal tab disposition.
Definition: telnet.h:219
PTelnetSocket
A TCP/IP socket for the TELNET high level protocol.
Definition: telnet.h:43
PTelnetSocket::SetTerminalType
void SetTerminalType(const PString &newType)
PTelnetSocket::EndOfRecordOption
Record boundary marker.
Definition: telnet.h:232
PTelnetSocket::GetWindowSize
void GetWindowSize(WORD &width, WORD &height) const
PTelnetSocket::ByteMacroOption
Byte macro.
Definition: telnet.h:226
PTelnetSocket::IsTheirOption
PBoolean IsTheirOption(BYTE code) const
Determine if the option on their side is enabled.
Definition: telnet.h:337
PTelnetSocket::SendSubOption
PBoolean SendSubOption(BYTE code, const BYTE *info, PINDEX len, int subCode=-1)
Send a sub-option with the information given.
PTelnetSocket::EndOfReccord
End of record for transparent mode.
Definition: telnet.h:173
PTelnetSocket::OutputLineWidth
Negotiate about output line width.
Definition: telnet.h:215
PTelnetSocket::AbortProcess
Abort the entire process.
Definition: telnet.h:174
PTelnetSocket::StatusOption
Status packets are understood.
Definition: telnet.h:212
PTelnetSocket::TimingMark
Marker for synchronisation.
Definition: telnet.h:213
PTelnetSocket::OptionInfo::IsNo
Definition: telnet.h:436
PTelnetSocket::OptionInfo::weCan
unsigned weCan
Definition: telnet.h:438
PTelnetSocket::AbortOutput
Function AO, abort output stream.
Definition: telnet.h:167
PTelnetSocket::SupDupOutput
supdup output.
Definition: telnet.h:229
PCLASSINFO
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PTelnetSocket::OptionInfo::WantYesQueued
Definition: telnet.h:436
PTelnetSocket::SendWont
virtual PBoolean SendWont(BYTE option)
Send WONT command.
PTelnetSocket::IAC
Interpret As Command - escape character.
Definition: telnet.h:157
PTelnetSocket::terminalType
PString terminalType
Definition: telnet.h:447
PTelnetSocket::Options
Options
Definition: telnet.h:206
PTelnetSocket::UseX3PADOption
X.3 PAD.
Definition: telnet.h:237
PTelnetSocket::OutputMark
Output marker or banner text.
Definition: telnet.h:234
PTelnetSocket::TerminalSpeed
Provide terminal speed information.
Definition: telnet.h:239
PTelnetSocket::EchoOption
Automatically echo characters sent.
Definition: telnet.h:208
PTelnetSocket::SB
Subnegotiation begin.
Definition: telnet.h:162
PTelnetSocket::HorizontalTabsStops
Negotiate about horizontal tabstops.
Definition: telnet.h:218
PTelnetSocket::VerticalTabStops
Negotiate about vertical tab stops.
Definition: telnet.h:221
PTelnetSocket::SendCommand
PBoolean SendCommand(Command cmd, int opt=0)
Send an escaped IAC command.
PTelnetSocket::FormFeedDisposition
Negotiate about formfeed disposition.
Definition: telnet.h:220
PTelnetSocket::NOP
No operation.
Definition: telnet.h:171
PTelnetSocket::OptionInfo::WantNo
Definition: telnet.h:436
PTelnetSocket::SetTheirOption
void SetTheirOption(BYTE code, PBoolean state=true)
Set if the option on their side is desired, this does not mean it is set it only means that in respon...
Definition: telnet.h:318
PTelnetSocket::OnDo
virtual void OnDo(BYTE option)
This callback function is called by the system when it receives a DO request from the remote system...
PTelnetSocket::windowWidth
WORD windowWidth
Definition: telnet.h:450
PTelnetSocket::OnWill
virtual void OnWill(BYTE option)
This callback function is called by the system when it receives a WILL request from the remote system...
PTelnetSocket::Read
PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
PTelnetSocket::PTelnetSocket
PTelnetSocket()
PTelnetSocket::SendDont
virtual PBoolean SendDont(BYTE option)
Send DONT command.
PTelnetSocket::ForceLogout
Force logout.
Definition: telnet.h:225
PTelnetSocket::SubOptionIs
Sub-option is...
Definition: telnet.h:290
PBoolean
BOOL PBoolean
Definition: object.h:102
PTelnetSocket::SendWill
virtual PBoolean SendWill(BYTE option)
Send WILL request.
PTelnetSocket::option
OptionInfo option[MaxOptions]
Definition: telnet.h:444
PTelnetSocket::SubOptionCodes
SubOptionCodes
Definition: telnet.h:289
PTelnetSocket::TerminalType
Provide terminal type information.
Definition: telnet.h:231
PTelnetSocket::DO
Request to use option.
Definition: telnet.h:159
PTelnetSocket::DataEntryTerminal
data entry terminal.
Definition: telnet.h:227
PTelnetSocket::OptionInfo
Definition: telnet.h:434
PTelnetSocket::OptionInfo::IsYes
Definition: telnet.h:436
PBYTEArray
Array of unsigned characters.
Definition: array.h:670
PTelnetSocket::SetLocalEcho
virtual bool SetLocalEcho(bool localEcho)
Set local echo mode.
PTelnetSocket::EraseLine
Function EL, erase the current line.
Definition: telnet.h:164
PTelnetSocket::LineModeOption
Terminal in line mode option.
Definition: telnet.h:241
PTelnetSocket::InterruptProcess
Function IP, interrupt process, permanently.
Definition: telnet.h:168
PTelnetSocket::AreYouThere
Function AYT, are you there?
Definition: telnet.h:166
PTelnetSocket::OptionInfo::WantYes
Definition: telnet.h:436
PTelnetSocket::TransmitBinary
Assume binary 8 bit data is transferred.
Definition: telnet.h:207
PTelnetSocket::FlowControl
Remote flow control.
Definition: telnet.h:240
PTelnetSocket::ExtendedOptionsList
Code for extended options.
Definition: telnet.h:247
PTelnetSocket::OptionInfo::ourState
unsigned ourState
Definition: telnet.h:439
PTelnetSocket::ExtendedASCII
Extended ascic character set.
Definition: telnet.h:224
PTelnetSocket::SendLocation
Send location.
Definition: telnet.h:230
PTelnetSocket::SendDo
virtual PBoolean SendDo(BYTE option)
Send DO request.
PTelnetSocket::DataMark
Marker for connection cleaning.
Definition: telnet.h:170
PTelnetSocket::WindowSize
NAWS - Negotiate About Window Size.
Definition: telnet.h:238
PTelnetSocket::MaxOptions
Definition: telnet.h:248
PTelnetSocket::EndOfFile
End of file marker.
Definition: telnet.h:176
PTelnetSocket::SetOurOption
void SetOurOption(BYTE code, PBoolean state=true)
Set if the option on our side is possible, this does not mean it is set it only means that in respons...
Definition: telnet.h:310
PString
The character string class.
Definition: pstring.h:108
PTelnetSocket::ReconnectOption
Prepare to reconnect.
Definition: telnet.h:209
PTCPSocket
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:44
PTelnetSocket::SE
Subnegotiation end.
Definition: telnet.h:172
PTelnetSocket::OnWont
virtual void OnWont(BYTE option)
This callback function is called by the system when it receives a WONT request from the remote system...
PTelnetSocket::AuthenticateOption
Authenticate option.
Definition: telnet.h:244
PTelnetSocket::SupDupProtocol
supdup protocol.
Definition: telnet.h:228
PTelnetSocket::CRDisposition
Negotiate about CR disposition.
Definition: telnet.h:217
PTelnetSocket::WONT
Refuse use of option.
Definition: telnet.h:160
PTelnetSocket::SubOptionSend
Request to send option.
Definition: telnet.h:291
PTelnetSocket::IsOurOption
PBoolean IsOurOption(BYTE code) const
Determine if the option on our side is enabled.
Definition: telnet.h:328
PTelnetSocket::Write
PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
PTelnetSocket::WILL
Accept the use of option.
Definition: telnet.h:161
PTelnetSocket::DONT
You are not to use option.
Definition: telnet.h:158
PTelnetSocket::OnOutOfBand
virtual void OnOutOfBand(const void *buf, PINDEX len)
This is callback function called by the system whenever out of band data from the TCP/IP stream is re...
PTelnetSocket::LineFeedDisposition
Negotiate about output LF disposition.
Definition: telnet.h:223
PTelnetSocket::OutputPageSize
Negotiate about output page size.
Definition: telnet.h:216
PTelnetSocket::OnCommand
virtual PBoolean OnCommand(BYTE code)
This callback function is called by the system when it receives an telnet command that it does not do...
PTelnetSocket::TerminalLocation
Terminals physical location information.
Definition: telnet.h:235
PTelnetSocket::TACACSUID
TACACS user identification.
Definition: telnet.h:233
PTelnetSocket::EraseChar
Function EC, erase the current character.
Definition: telnet.h:165
PTelnetSocket::OnSubOption
virtual void OnSubOption(BYTE code, const BYTE *info, PINDEX len)
This callback function is called by the system when it receives a sub-option command from the remote ...
PTelnetSocket::Command
Command
Definition: telnet.h:156
PTelnetSocket::EncriptionOption
Encryption option.
Definition: telnet.h:245
sockets.h
PTelnetSocket::RCTEOption
Remote controlled transmission and echo.
Definition: telnet.h:214
PTelnetSocket::OptionInfo::theyShould
unsigned theyShould
Definition: telnet.h:440
PTelnetSocket::MessageSizeOption
Negatiate approximate message size.
Definition: telnet.h:211
PTelnetSocket::VertTabDisposition
Negotiate about vertical tab disposition.
Definition: telnet.h:222
PTelnetSocket::OnDont
virtual void OnDont(BYTE option)
This callback function is called by the system when it receives a DONT request from the remote system...
PTelnetSocket::Break
NVT character break.
Definition: telnet.h:169
PTelnetSocket::GoAhead
Function GA, you may reverse the line.
Definition: telnet.h:163
PTelnetSocket::EncryptionOption
Duplicate to fix spelling mistake and remain backwards compatible.
Definition: telnet.h:246
PSocket
A network communications channel.
Definition: socket.h:58
PTelnetSocket::GetTerminalType
const PString & GetTerminalType() const
Definition: telnet.h:346
PTelnetSocket::Accept
virtual PBoolean Accept(PSocket &socket)
Open a socket to a remote host on the specified port number.
PTelnetSocket::XDisplayLocation
X Display location.
Definition: telnet.h:242
PTelnetSocket::Construct
void Construct()
PTelnetSocket::Use3270RegimeOption
3270 regime.
Definition: telnet.h:236
PTelnetSocket::SuspendProcess
Suspend the process.
Definition: telnet.h:175
PTelnetSocket::OptionInfo::theirState
unsigned theirState
Definition: telnet.h:441
PTelnetSocket::SuppressGoAhead
Do not use the GA protocol.
Definition: telnet.h:210
PTelnetSocket::windowHeight
WORD windowHeight
Definition: telnet.h:450
PTelnetSocket::OptionInfo::WantNoQueued
Definition: telnet.h:436