PTLib  Version 2.10.10
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  * $Revision: 24177 $
27  * $Author: rjongbloed $
28  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
29  */
30 
31 #ifndef PTLIB_TELNET_H
32 #define PTLIB_TELNET_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <ptlib/sockets.h>
39 
40 
43 class PTelnetSocket : public PTCPSocket
44 {
46 
47  public:
48  PTelnetSocket();
49  // Create an unopened TELNET socket.
50 
52  const PString & address
53  );
54  // Create an opened TELNET socket.
55 
56 
57  // Overrides from class PChannel
73  PBoolean Read(
74  void * buf,
75  PINDEX len
76  );
77 
92  const void * buf,
93  PINDEX len
94  );
95 
103  virtual bool SetLocalEcho(
104  bool localEcho
105  );
106 
107 
119  virtual PBoolean Connect(
120  const PString & address
121  );
122 
123 
138  virtual PBoolean Accept(
139  PSocket & socket
140  );
141 
142 
149  virtual void OnOutOfBand(
150  const void * buf,
151  PINDEX len
152  );
153 
154 
155  // New functions
156  enum Command {
157  IAC = 255,
158  DONT = 254,
159  DO = 253,
160  WONT = 252,
161  WILL = 251,
162  SB = 250,
163  GoAhead = 249,
164  EraseLine = 248,
165  EraseChar = 247,
166  AreYouThere = 246,
167  AbortOutput = 245,
169  Break = 243,
170  DataMark = 242,
171  NOP = 241,
172  SE = 240,
173  EndOfReccord = 239,
174  AbortProcess = 238,
176  EndOfFile = 236
177  };
178  // Defined telnet commands codes
179 
201  Command cmd,
202  int opt = 0
203  );
204 
205 
206  enum Options {
225  ForceLogout = 18,
233  TACACSUID = 26,
234  OutputMark = 27,
238  WindowSize = 31,
240  FlowControl = 33,
249  };
250  // Defined TELNET options.
251 
252 
258  virtual PBoolean SendDo(
259  BYTE option
260  );
261 
267  virtual PBoolean SendDont(
268  BYTE option
269  );
270 
276  virtual PBoolean SendWill(
277  BYTE option
278  );
279 
285  virtual PBoolean SendWont(
286  BYTE option
287  );
288 
292  };
293  // Codes for sub option negotiation.
294 
301  BYTE code,
302  const BYTE * info,
303  PINDEX len,
304  int subCode = -1
305  );
306 
311  BYTE code,
312  PBoolean state = true
313  ) { option[code].weCan = state; }
314 
319  BYTE code,
320  PBoolean state = true
321  ) { option[code].theyShould = state; }
322 
329  BYTE code
330  ) const { return option[code].ourState == OptionInfo::IsYes; }
331 
338  BYTE code
339  ) const { return option[code].theirState == OptionInfo::IsYes; }
340 
341  void SetTerminalType(
342  const PString & newType
343  );
344  // Set the terminal type description string for TELNET protocol.
345 
346  const PString & GetTerminalType() const { return terminalType; }
347  // Get the terminal type description string for TELNET protocol.
348 
349  void SetWindowSize(
350  WORD width,
351  WORD height
352  );
353  // Set the width and height of the Network Virtual Terminal window.
354 
355  void GetWindowSize(
356  WORD & width,
357  WORD & height
358  ) const;
359  // Get the width and height of the Network Virtual Terminal window.
360 
361 
362  protected:
363  void Construct();
364  // Common construct code for TELNET socket channel.
365 
375  virtual void OnDo(
376  BYTE option
377  );
378 
385  virtual void OnDont(
386  BYTE option
387  );
388 
395  virtual void OnWill(
396  BYTE option
397  );
398 
405  virtual void OnWont(
406  BYTE option
407  );
408 
412  virtual void OnSubOption(
413  BYTE code,
414  const BYTE * info,
415  PINDEX len
416  );
417 
418 
428  virtual PBoolean OnCommand(
429  BYTE code
430  );
431 
432 
433  // Member variables.
434  struct OptionInfo {
435  enum {
437  };
438  unsigned weCan:1; // We can do the option if they want us to do.
439  unsigned ourState:3;
440  unsigned theyShould:1; // They should if they will.
441  unsigned theirState:3;
442  };
443 
445  // Information on protocol options.
446 
448  // Type of terminal connected to telnet socket, defaults to "UNKNOWN"
449 
451  // Size of the "window" used by the NVT.
452 
453 
454  private:
455  enum State {
456  StateNormal,
457  StateCarriageReturn,
458  StateIAC,
459  StateDo,
460  StateDont,
461  StateWill,
462  StateWont,
463  StateSubNegotiations,
464  StateEndNegotiations
465  };
466  // Internal states for the TELNET decoder
467 
468  State state;
469  // Current state of incoming characters.
470 
471  PBYTEArray subOption;
472  // Storage for sub-negotiated options
473 
474  unsigned synchronising;
475 };
476 
477 
478 #endif // PTLIB_TELNET_H
479 
480 
481 // End Of File ///////////////////////////////////////////////////////////////
Provide environment information.
Definition: telnet.h:243
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:219
A TCP/IP socket for the TELNET high level protocol.
Definition: telnet.h:43
void SetTerminalType(const PString &newType)
Record boundary marker.
Definition: telnet.h:232
void GetWindowSize(WORD &width, WORD &height) const
Byte macro.
Definition: telnet.h:226
PBoolean IsTheirOption(BYTE code) const
Determine if the option on their side is enabled.
Definition: telnet.h:337
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:173
Negotiate about output line width.
Definition: telnet.h:215
Abort the entire process.
Definition: telnet.h:174
Status packets are understood.
Definition: telnet.h:212
Marker for synchronisation.
Definition: telnet.h:213
Definition: telnet.h:436
unsigned weCan
Definition: telnet.h:438
Function AO, abort output stream.
Definition: telnet.h:167
supdup output.
Definition: telnet.h:229
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
virtual PBoolean SendWont(BYTE option)
Send WONT command.
Interpret As Command - escape character.
Definition: telnet.h:157
PString terminalType
Definition: telnet.h:447
Options
Definition: telnet.h:206
X.3 PAD.
Definition: telnet.h:237
Output marker or banner text.
Definition: telnet.h:234
Provide terminal speed information.
Definition: telnet.h:239
Automatically echo characters sent.
Definition: telnet.h:208
Subnegotiation begin.
Definition: telnet.h:162
Negotiate about horizontal tabstops.
Definition: telnet.h:218
Negotiate about vertical tab stops.
Definition: telnet.h:221
PBoolean SendCommand(Command cmd, int opt=0)
Send an escaped IAC command.
Negotiate about formfeed disposition.
Definition: telnet.h:220
No operation.
Definition: telnet.h:171
Definition: telnet.h:436
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
virtual void OnDo(BYTE option)
This callback function is called by the system when it receives a DO request from the remote system...
WORD windowWidth
Definition: telnet.h:450
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:225
Sub-option is...
Definition: telnet.h:290
BOOL PBoolean
Definition: object.h:102
virtual PBoolean SendWill(BYTE option)
Send WILL request.
OptionInfo option[MaxOptions]
Definition: telnet.h:444
SubOptionCodes
Definition: telnet.h:289
Provide terminal type information.
Definition: telnet.h:231
Request to use option.
Definition: telnet.h:159
data entry terminal.
Definition: telnet.h:227
Definition: telnet.h:434
Definition: telnet.h:436
Array of unsigned characters.
Definition: array.h:670
virtual bool SetLocalEcho(bool localEcho)
Set local echo mode.
Function EL, erase the current line.
Definition: telnet.h:164
Terminal in line mode option.
Definition: telnet.h:241
Function IP, interrupt process, permanently.
Definition: telnet.h:168
Function AYT, are you there?
Definition: telnet.h:166
Definition: telnet.h:436
Assume binary 8 bit data is transferred.
Definition: telnet.h:207
Remote flow control.
Definition: telnet.h:240
Code for extended options.
Definition: telnet.h:247
unsigned ourState
Definition: telnet.h:439
Extended ascic character set.
Definition: telnet.h:224
Send location.
Definition: telnet.h:230
virtual PBoolean SendDo(BYTE option)
Send DO request.
Marker for connection cleaning.
Definition: telnet.h:170
NAWS - Negotiate About Window Size.
Definition: telnet.h:238
Definition: telnet.h:248
End of file marker.
Definition: telnet.h:176
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
The character string class.
Definition: pstring.h:108
Prepare to reconnect.
Definition: telnet.h:209
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:44
Subnegotiation end.
Definition: telnet.h:172
virtual void OnWont(BYTE option)
This callback function is called by the system when it receives a WONT request from the remote system...
Authenticate option.
Definition: telnet.h:244
supdup protocol.
Definition: telnet.h:228
Negotiate about CR disposition.
Definition: telnet.h:217
Refuse use of option.
Definition: telnet.h:160
Request to send option.
Definition: telnet.h:291
PBoolean IsOurOption(BYTE code) const
Determine if the option on our side is enabled.
Definition: telnet.h:328
PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
Accept the use of option.
Definition: telnet.h:161
You are not to use option.
Definition: telnet.h:158
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...
Negotiate about output LF disposition.
Definition: telnet.h:223
Negotiate about output page size.
Definition: telnet.h:216
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:235
TACACS user identification.
Definition: telnet.h:233
Function EC, erase the current character.
Definition: telnet.h:165
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:156
Encryption option.
Definition: telnet.h:245
Remote controlled transmission and echo.
Definition: telnet.h:214
unsigned theyShould
Definition: telnet.h:440
Negatiate approximate message size.
Definition: telnet.h:211
Negotiate about vertical tab disposition.
Definition: telnet.h:222
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:169
Function GA, you may reverse the line.
Definition: telnet.h:163
Duplicate to fix spelling mistake and remain backwards compatible.
Definition: telnet.h:246
A network communications channel.
Definition: socket.h:58
const PString & GetTerminalType() const
Definition: telnet.h:346
virtual PBoolean Accept(PSocket &socket)
Open a socket to a remote host on the specified port number.
X Display location.
Definition: telnet.h:242
void Construct()
3270 regime.
Definition: telnet.h:236
Suspend the process.
Definition: telnet.h:175
unsigned theirState
Definition: telnet.h:441
Do not use the GA protocol.
Definition: telnet.h:210
WORD windowHeight
Definition: telnet.h:450