PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
telnet.h
Go to the documentation of this file.
1 /*
2  * telnet.h
3  *
4  * TELNET Socket class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef PTLIB_TELNET_H
28 #define PTLIB_TELNET_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #include <ptlib/sockets.h>
35 
36 
39 class PTelnetSocket : public PTCPSocket
40 {
42 
43  public:
44  PTelnetSocket();
45  // Create an unopened TELNET socket.
46 
48  const PString & address
49  );
50  // Create an opened TELNET socket.
51 
52 
53  // Overrides from class PChannel
69  PBoolean Read(
70  void * buf,
71  PINDEX len
72  );
73 
88  const void * buf,
89  PINDEX len
90  );
91 
99  virtual bool SetLocalEcho(
100  bool localEcho
101  );
102 
103 
115  virtual PBoolean Connect(
116  const PString & address
117  );
118 
119 
134  virtual PBoolean Accept(
135  PSocket & socket
136  );
137 
138 
145  virtual void OnOutOfBand(
146  const void * buf,
147  PINDEX len
148  );
149 
150 
151  // New functions
152  enum Command {
153  IAC = 255,
154  DONT = 254,
155  DO = 253,
156  WONT = 252,
157  WILL = 251,
158  SB = 250,
159  GoAhead = 249,
160  EraseLine = 248,
161  EraseChar = 247,
162  AreYouThere = 246,
163  AbortOutput = 245,
165  Break = 243,
166  DataMark = 242,
167  NOP = 241,
168  SE = 240,
169  EndOfReccord = 239,
170  AbortProcess = 238,
172  EndOfFile = 236
173  };
174  // Defined telnet commands codes
175 
197  Command cmd,
198  int opt = 0
199  );
200 
201 
202  enum Options {
221  ForceLogout = 18,
229  TACACSUID = 26,
230  OutputMark = 27,
234  WindowSize = 31,
236  FlowControl = 33,
245  };
246  // Defined TELNET options.
247 
248 
254  virtual PBoolean SendDo(
255  BYTE option
256  );
257 
263  virtual PBoolean SendDont(
264  BYTE option
265  );
266 
272  virtual PBoolean SendWill(
273  BYTE option
274  );
275 
281  virtual PBoolean SendWont(
282  BYTE option
283  );
284 
288  };
289  // Codes for sub option negotiation.
290 
297  BYTE code,
298  const BYTE * info,
299  PINDEX len,
300  int subCode = -1
301  );
302 
307  BYTE code,
308  PBoolean state = true
309  ) { m_option[code].weCan = state; }
310 
315  BYTE code,
316  PBoolean state = true
317  ) { m_option[code].theyShould = state; }
318 
325  BYTE code
326  ) const { return m_option[code].ourState == OptionInfo::IsYes; }
327 
334  BYTE code
335  ) const { return m_option[code].theirState == OptionInfo::IsYes; }
336 
337  void SetTerminalType(
338  const PString & newType
339  );
340  // Set the terminal type description string for TELNET protocol.
341 
342  const PString & GetTerminalType() const { return m_terminalType; }
343  // Get the terminal type description string for TELNET protocol.
344 
345  void SetWindowSize(
346  WORD width,
347  WORD height
348  );
349  // Set the width and height of the Network Virtual Terminal window.
350 
351  void GetWindowSize(
352  WORD & width,
353  WORD & height
354  ) const;
355  // Get the width and height of the Network Virtual Terminal window.
356 
357 
358  protected:
359  void Construct();
360  // Common construct code for TELNET socket channel.
361 
371  virtual void OnDo(
372  BYTE option
373  );
374 
381  virtual void OnDont(
382  BYTE option
383  );
384 
391  virtual void OnWill(
392  BYTE option
393  );
394 
401  virtual void OnWont(
402  BYTE option
403  );
404 
408  virtual void OnSubOption(
409  BYTE code,
410  const BYTE * info,
411  PINDEX len
412  );
413 
414 
424  virtual PBoolean OnCommand(
425  BYTE code
426  );
427 
428 
429  // Member variables.
430  struct OptionInfo {
431  enum {
433  };
434  unsigned weCan:1; // We can do the option if they want us to do.
435  unsigned ourState:3;
436  unsigned theyShould:1; // They should if they will.
437  unsigned theirState:3;
438  };
439 
441  // Information on protocol options.
442 
444  // Type of terminal connected to telnet socket, defaults to "UNKNOWN"
445 
447  // Size of the "window" used by the NVT.
448 
449 
450  private:
451  // Internal states for the TELNET decoder
452  enum State {
453  StateNormal,
454  StateCarriageReturn,
455  StateIAC,
456  StateDo,
457  StateDont,
458  StateWill,
459  StateWont,
460  StateSubNegotiations,
461  StateEndNegotiations
462  };
463 
464  State m_state; // Current state of incoming characters.
465  PBYTEArray m_subOption; // Storage for sub-negotiated options
466  unsigned m_synchronising;
467 };
468 
469 
470 #endif // PTLIB_TELNET_H
471 
472 
473 // End Of File ///////////////////////////////////////////////////////////////
Provide environment information.
Definition: telnet.h:239
virtual PBoolean Connect(const PString &address)
Connect a socket to a remote host on the specified port number.
void SetWindowSize(WORD width, WORD height)
Negotiate about horizontal tab disposition.
Definition: telnet.h:215
A TCP/IP socket for the TELNET high level protocol.
Definition: telnet.h:39
void SetTerminalType(const PString &newType)
Record boundary marker.
Definition: telnet.h:228
void GetWindowSize(WORD &width, WORD &height) const
Byte macro.
Definition: telnet.h:222
PBoolean IsTheirOption(BYTE code) const
Determine if the option on their side is enabled.
Definition: telnet.h:333
PBoolean SendSubOption(BYTE code, const BYTE *info, PINDEX len, int subCode=-1)
Send a sub-option with the information given.
End of record for transparent mode.
Definition: telnet.h:169
Negotiate about output line width.
Definition: telnet.h:211
Abort the entire process.
Definition: telnet.h:170
Status packets are understood.
Definition: telnet.h:208
Marker for synchronisation.
Definition: telnet.h:209
unsigned weCan
Definition: telnet.h:434
Function AO, abort output stream.
Definition: telnet.h:163
supdup output.
Definition: telnet.h:225
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
virtual PBoolean SendWont(BYTE option)
Send WONT command.
Definition: telnet.h:432
Interpret As Command - escape character.
Definition: telnet.h:153
Options
Definition: telnet.h:202
X.3 PAD.
Definition: telnet.h:233
Output marker or banner text.
Definition: telnet.h:230
Provide terminal speed information.
Definition: telnet.h:235
Automatically echo characters sent.
Definition: telnet.h:204
Subnegotiation begin.
Definition: telnet.h:158
Negotiate about horizontal tabstops.
Definition: telnet.h:214
Negotiate about vertical tab stops.
Definition: telnet.h:217
PBoolean SendCommand(Command cmd, int opt=0)
Send an escaped IAC command.
WORD m_windowHeight
Definition: telnet.h:446
Negotiate about formfeed disposition.
Definition: telnet.h:216
No operation.
Definition: telnet.h:167
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:314
Definition: telnet.h:432
virtual void OnDo(BYTE option)
This callback function is called by the system when it receives a DO request from the remote system...
virtual void OnWill(BYTE option)
This callback function is called by the system when it receives a WILL request from the remote system...
PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
virtual PBoolean SendDont(BYTE option)
Send DONT command.
Force logout.
Definition: telnet.h:221
Sub-option is...
Definition: telnet.h:286
virtual PBoolean SendWill(BYTE option)
Send WILL request.
SubOptionCodes
Definition: telnet.h:285
Provide terminal type information.
Definition: telnet.h:227
Request to use option.
Definition: telnet.h:155
data entry terminal.
Definition: telnet.h:223
Definition: telnet.h:430
Array of unsigned characters.
Definition: array.h:605
virtual bool SetLocalEcho(bool localEcho)
Set local echo mode.
Function EL, erase the current line.
Definition: telnet.h:160
Definition: telnet.h:432
Terminal in line mode option.
Definition: telnet.h:237
Function IP, interrupt process, permanently.
Definition: telnet.h:164
Function AYT, are you there?
Definition: telnet.h:162
Definition: telnet.h:432
Assume binary 8 bit data is transferred.
Definition: telnet.h:203
Remote flow control.
Definition: telnet.h:236
Code for extended options.
Definition: telnet.h:243
unsigned ourState
Definition: telnet.h:435
Extended ascic character set.
Definition: telnet.h:220
Send location.
Definition: telnet.h:226
bool PBoolean
Definition: object.h:174
virtual PBoolean SendDo(BYTE option)
Send DO request.
Marker for connection cleaning.
Definition: telnet.h:166
NAWS - Negotiate About Window Size.
Definition: telnet.h:234
Definition: telnet.h:244
End of file marker.
Definition: telnet.h:172
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:306
The character string class.
Definition: pstring.h:108
Prepare to reconnect.
Definition: telnet.h:205
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:40
Subnegotiation end.
Definition: telnet.h:168
virtual void OnWont(BYTE option)
This callback function is called by the system when it receives a WONT request from the remote system...
PString m_terminalType
Definition: telnet.h:443
Authenticate option.
Definition: telnet.h:240
supdup protocol.
Definition: telnet.h:224
Negotiate about CR disposition.
Definition: telnet.h:213
Refuse use of option.
Definition: telnet.h:156
Request to send option.
Definition: telnet.h:287
PBoolean IsOurOption(BYTE code) const
Determine if the option on our side is enabled.
Definition: telnet.h:324
PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
Accept the use of option.
Definition: telnet.h:157
You are not to use option.
Definition: telnet.h:154
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...
WORD m_windowWidth
Definition: telnet.h:446
Negotiate about output LF disposition.
Definition: telnet.h:219
Negotiate about output page size.
Definition: telnet.h:212
virtual PBoolean OnCommand(BYTE code)
This callback function is called by the system when it receives an telnet command that it does not do...
Terminals physical location information.
Definition: telnet.h:231
TACACS user identification.
Definition: telnet.h:229
Function EC, erase the current character.
Definition: telnet.h:161
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 ...
Command
Definition: telnet.h:152
Encryption option.
Definition: telnet.h:241
OptionInfo m_option[MaxOptions]
Definition: telnet.h:440
Remote controlled transmission and echo.
Definition: telnet.h:210
unsigned theyShould
Definition: telnet.h:436
Negatiate approximate message size.
Definition: telnet.h:207
Negotiate about vertical tab disposition.
Definition: telnet.h:218
virtual void OnDont(BYTE option)
This callback function is called by the system when it receives a DONT request from the remote system...
NVT character break.
Definition: telnet.h:165
Function GA, you may reverse the line.
Definition: telnet.h:159
Duplicate to fix spelling mistake and remain backwards compatible.
Definition: telnet.h:242
A network communications channel.
Definition: socket.h:59
const PString & GetTerminalType() const
Definition: telnet.h:342
virtual PBoolean Accept(PSocket &socket)
Open a socket to a remote host on the specified port number.
X Display location.
Definition: telnet.h:238
void Construct()
3270 regime.
Definition: telnet.h:232
Suspend the process.
Definition: telnet.h:171
unsigned theirState
Definition: telnet.h:437
Do not use the GA protocol.
Definition: telnet.h:206