PWLib
1.10.10
|
00001 /* 00002 * telnet.h 00003 * 00004 * TELNET Socket class. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-2002 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Contributor(s): ______________________________________. 00025 * 00026 * $Log: telnet.h,v $ 00027 * Revision 1.24 2005/11/30 12:47:37 csoutheren 00028 * Removed tabs, reformatted some code, and changed tags for Doxygen 00029 * 00030 * Revision 1.23 2002/11/06 22:47:24 robertj 00031 * Fixed header comment (copyright etc) 00032 * 00033 * Revision 1.22 2002/09/16 01:08:59 robertj 00034 * Added #define so can select if #pragma interface/implementation is used on 00035 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00036 * 00037 * Revision 1.21 1999/03/09 08:01:47 robertj 00038 * Changed comments for doc++ support (more to come). 00039 * 00040 * Revision 1.20 1999/02/16 08:07:10 robertj 00041 * MSVC 6.0 compatibility changes. 00042 * 00043 * Revision 1.19 1998/11/30 02:50:56 robertj 00044 * New directory structure 00045 * 00046 * Revision 1.18 1998/09/23 06:20:04 robertj 00047 * Added open source copyright license. 00048 * 00049 * Revision 1.17 1996/08/08 10:08:54 robertj 00050 * Directory structure changes for common files. 00051 * 00052 * Revision 1.16 1995/06/17 11:13:32 robertj 00053 * Documentation update. 00054 * 00055 * Revision 1.15 1995/06/17 00:47:38 robertj 00056 * Changed overloaded Open() calls to 3 separate function names. 00057 * More logical design of port numbers and service names. 00058 * 00059 * Revision 1.14 1995/06/04 12:46:26 robertj 00060 * Slight redesign of port numbers on sockets. 00061 * 00062 * Revision 1.13 1995/04/25 11:12:30 robertj 00063 * Fixed functions hiding ancestor virtuals. 00064 * 00065 * Revision 1.12 1995/04/01 08:32:10 robertj 00066 * Finally got a working TELNET. 00067 * 00068 * Revision 1.11 1995/03/18 06:27:50 robertj 00069 * Rewrite of telnet socket protocol according to RFC1143. 00070 * 00071 * Revision 1.10 1995/03/14 12:42:47 robertj 00072 * Updated documentation to use HTML codes. 00073 * 00074 * Revision 1.9 1995/02/21 11:25:33 robertj 00075 * Further implementation of telnet socket, feature complete now. 00076 * 00077 * Revision 1.8 1995/01/03 09:36:23 robertj 00078 * Documentation. 00079 * 00080 * Revision 1.7 1995/01/01 01:07:33 robertj 00081 * More implementation. 00082 * 00083 * Revision 1.6 1994/11/28 12:38:59 robertj 00084 * Added DONT and WONT states. 00085 * 00086 * Revision 1.5 1994/08/23 11:32:52 robertj 00087 * Oops 00088 * 00089 * Revision 1.4 1994/08/22 00:46:48 robertj 00090 * Added pragma fro GNU C++ compiler. 00091 * 00092 * Revision 1.3 1994/08/21 23:43:02 robertj 00093 * Changed type of socket port number for better portability. 00094 * 00095 * Revision 1.2 1994/07/25 03:36:03 robertj 00096 * Added sockets to common, normalising to same comment standard. 00097 * 00098 */ 00099 00100 #ifndef _PTELNETSOCKET 00101 #define _PTELNETSOCKET 00102 00103 #ifdef P_USE_PRAGMA 00104 #pragma interface 00105 #endif 00106 00107 #include <ptlib/sockets.h> 00108 00109 00112 class PTelnetSocket : public PTCPSocket 00113 { 00114 PCLASSINFO(PTelnetSocket, PTCPSocket) 00115 00116 public: 00117 PTelnetSocket(); 00118 // Create an unopened TELNET socket. 00119 00120 PTelnetSocket( 00121 const PString & address 00122 ); 00123 // Create an opened TELNET socket. 00124 00125 00126 // Overrides from class PChannel 00142 BOOL Read( 00143 void * buf, 00144 PINDEX len 00145 ); 00146 00160 BOOL Write( 00161 const void * buf, 00162 PINDEX len 00163 ); 00164 00165 00177 virtual BOOL Connect( 00178 const PString & address 00179 ); 00180 00181 00196 virtual BOOL Accept( 00197 PSocket & socket 00198 ); 00199 00200 00207 virtual void OnOutOfBand( 00208 const void * buf, 00209 PINDEX len 00210 ); 00211 00212 00213 // New functions 00214 enum Command { 00215 IAC = 255, 00216 DONT = 254, 00217 DO = 253, 00218 WONT = 252, 00219 WILL = 251, 00220 SB = 250, 00221 GoAhead = 249, 00222 EraseLine = 248, 00223 EraseChar = 247, 00224 AreYouThere = 246, 00225 AbortOutput = 245, 00226 InterruptProcess = 244, 00227 Break = 243, 00228 DataMark = 242, 00229 NOP = 241, 00230 SE = 240, 00231 EndOfReccord = 239, 00232 AbortProcess = 238, 00233 SuspendProcess= 237, 00234 EndOfFile = 236 00235 }; 00236 // Defined telnet commands codes 00237 00258 BOOL SendCommand( 00259 Command cmd, 00260 int opt = 0 00261 ); 00262 00263 00264 enum Options { 00265 TransmitBinary = 0, 00266 EchoOption = 1, 00267 ReconnectOption = 2, 00268 SuppressGoAhead = 3, 00269 MessageSizeOption = 4, 00270 StatusOption = 5, 00271 TimingMark = 6, 00272 RCTEOption = 7, 00273 OutputLineWidth = 8, 00274 OutputPageSize = 9, 00275 CRDisposition = 10, 00276 HorizontalTabsStops = 11, 00277 HorizTabDisposition = 12, 00278 FormFeedDisposition = 13, 00279 VerticalTabStops = 14, 00280 VertTabDisposition = 15, 00281 LineFeedDisposition = 16, 00282 ExtendedASCII = 17, 00283 ForceLogout = 18, 00284 ByteMacroOption = 19, 00285 DataEntryTerminal = 20, 00286 SupDupProtocol = 21, 00287 SupDupOutput = 22, 00288 SendLocation = 23, 00289 TerminalType = 24, 00290 EndOfRecordOption = 25, 00291 TACACSUID = 26, 00292 OutputMark = 27, 00293 TerminalLocation = 28, 00294 Use3270RegimeOption = 29, 00295 UseX3PADOption = 30, 00296 WindowSize = 31, 00297 TerminalSpeed = 32, 00298 FlowControl = 33, 00299 LineModeOption = 34, 00300 XDisplayLocation = 35, 00301 EnvironmentOption = 36, 00302 AuthenticateOption = 37, 00303 EncriptionOption = 38, 00304 EncryptionOption = 38, 00305 ExtendedOptionsList = 255, 00306 MaxOptions 00307 }; 00308 // Defined TELNET options. 00309 00310 00316 virtual BOOL SendDo( 00317 BYTE option 00318 ); 00319 00325 virtual BOOL SendDont( 00326 BYTE option 00327 ); 00328 00334 virtual BOOL SendWill( 00335 BYTE option 00336 ); 00337 00343 virtual BOOL SendWont( 00344 BYTE option 00345 ); 00346 00347 enum SubOptionCodes { 00348 SubOptionIs = 0, 00349 SubOptionSend = 1, 00350 }; 00351 // Codes for sub option negotiation. 00352 00358 BOOL SendSubOption( 00359 BYTE code, 00360 const BYTE * info, 00361 PINDEX len, 00362 int subCode = -1 00363 ); 00364 00368 void SetOurOption( 00369 BYTE code, 00370 BOOL state = TRUE 00371 ) { option[code].weCan = state; } 00372 00376 void SetTheirOption( 00377 BYTE code, 00378 BOOL state = TRUE 00379 ) { option[code].theyShould = state; } 00380 00386 BOOL IsOurOption( 00387 BYTE code 00388 ) const { return option[code].ourState == OptionInfo::IsYes; } 00389 00395 BOOL IsTheirOption( 00396 BYTE code 00397 ) const { return option[code].theirState == OptionInfo::IsYes; } 00398 00399 void SetTerminalType( 00400 const PString & newType 00401 ); 00402 // Set the terminal type description string for TELNET protocol. 00403 00404 const PString & GetTerminalType() const { return terminalType; } 00405 // Get the terminal type description string for TELNET protocol. 00406 00407 void SetWindowSize( 00408 WORD width, 00409 WORD height 00410 ); 00411 // Set the width and height of the Network Virtual Terminal window. 00412 00413 void GetWindowSize( 00414 WORD & width, 00415 WORD & height 00416 ) const; 00417 // Get the width and height of the Network Virtual Terminal window. 00418 00419 00420 protected: 00421 void Construct(); 00422 // Common construct code for TELNET socket channel. 00423 00433 virtual void OnDo( 00434 BYTE option 00435 ); 00436 00443 virtual void OnDont( 00444 BYTE option 00445 ); 00446 00453 virtual void OnWill( 00454 BYTE option 00455 ); 00456 00463 virtual void OnWont( 00464 BYTE option 00465 ); 00466 00470 virtual void OnSubOption( 00471 BYTE code, 00472 const BYTE * info, 00473 PINDEX len 00474 ); 00475 00476 00486 virtual BOOL OnCommand( 00487 BYTE code 00488 ); 00489 00490 00491 // Member variables. 00492 struct OptionInfo { 00493 enum { 00494 IsNo, IsYes, WantNo, WantNoQueued, WantYes, WantYesQueued 00495 }; 00496 unsigned weCan:1; // We can do the option if they want us to do. 00497 unsigned ourState:3; 00498 unsigned theyShould:1; // They should if they will. 00499 unsigned theirState:3; 00500 }; 00501 00502 OptionInfo option[MaxOptions]; 00503 // Information on protocol options. 00504 00505 PString terminalType; 00506 // Type of terminal connected to telnet socket, defaults to "UNKNOWN" 00507 00508 WORD windowWidth, windowHeight; 00509 // Size of the "window" used by the NVT. 00510 00511 BOOL debug; 00512 // Debug socket, output messages to PError stream. 00513 00514 00515 private: 00516 enum State { 00517 StateNormal, 00518 StateCarriageReturn, 00519 StateIAC, 00520 StateDo, 00521 StateDont, 00522 StateWill, 00523 StateWont, 00524 StateSubNegotiations, 00525 StateEndNegotiations 00526 }; 00527 // Internal states for the TELNET decoder 00528 00529 State state; 00530 // Current state of incoming characters. 00531 00532 PBYTEArray subOption; 00533 // Storage for sub-negotiated options 00534 00535 unsigned synchronising; 00536 00537 BOOL StartSend(const char * which, BYTE code); 00538 }; 00539 00540 00541 #endif 00542 00543 00544 // End Of File /////////////////////////////////////////////////////////////// 00545