PTLib
Version 2.10.4
|
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 * $Revision: 24177 $ 00027 * $Author: rjongbloed $ 00028 * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $ 00029 */ 00030 00031 #ifndef PTLIB_TELNET_H 00032 #define PTLIB_TELNET_H 00033 00034 #ifdef P_USE_PRAGMA 00035 #pragma interface 00036 #endif 00037 00038 #include <ptlib/sockets.h> 00039 00040 00043 class PTelnetSocket : public PTCPSocket 00044 { 00045 PCLASSINFO(PTelnetSocket, PTCPSocket) 00046 00047 public: 00048 PTelnetSocket(); 00049 // Create an unopened TELNET socket. 00050 00051 PTelnetSocket( 00052 const PString & address 00053 ); 00054 // Create an opened TELNET socket. 00055 00056 00057 // Overrides from class PChannel 00073 PBoolean Read( 00074 void * buf, 00075 PINDEX len 00076 ); 00077 00091 PBoolean Write( 00092 const void * buf, 00093 PINDEX len 00094 ); 00095 00103 virtual bool SetLocalEcho( 00104 bool localEcho 00105 ); 00106 00107 00119 virtual PBoolean Connect( 00120 const PString & address 00121 ); 00122 00123 00138 virtual PBoolean Accept( 00139 PSocket & socket 00140 ); 00141 00142 00149 virtual void OnOutOfBand( 00150 const void * buf, 00151 PINDEX len 00152 ); 00153 00154 00155 // New functions 00156 enum Command { 00157 IAC = 255, 00158 DONT = 254, 00159 DO = 253, 00160 WONT = 252, 00161 WILL = 251, 00162 SB = 250, 00163 GoAhead = 249, 00164 EraseLine = 248, 00165 EraseChar = 247, 00166 AreYouThere = 246, 00167 AbortOutput = 245, 00168 InterruptProcess = 244, 00169 Break = 243, 00170 DataMark = 242, 00171 NOP = 241, 00172 SE = 240, 00173 EndOfReccord = 239, 00174 AbortProcess = 238, 00175 SuspendProcess= 237, 00176 EndOfFile = 236 00177 }; 00178 // Defined telnet commands codes 00179 00200 PBoolean SendCommand( 00201 Command cmd, 00202 int opt = 0 00203 ); 00204 00205 00206 enum Options { 00207 TransmitBinary = 0, 00208 EchoOption = 1, 00209 ReconnectOption = 2, 00210 SuppressGoAhead = 3, 00211 MessageSizeOption = 4, 00212 StatusOption = 5, 00213 TimingMark = 6, 00214 RCTEOption = 7, 00215 OutputLineWidth = 8, 00216 OutputPageSize = 9, 00217 CRDisposition = 10, 00218 HorizontalTabsStops = 11, 00219 HorizTabDisposition = 12, 00220 FormFeedDisposition = 13, 00221 VerticalTabStops = 14, 00222 VertTabDisposition = 15, 00223 LineFeedDisposition = 16, 00224 ExtendedASCII = 17, 00225 ForceLogout = 18, 00226 ByteMacroOption = 19, 00227 DataEntryTerminal = 20, 00228 SupDupProtocol = 21, 00229 SupDupOutput = 22, 00230 SendLocation = 23, 00231 TerminalType = 24, 00232 EndOfRecordOption = 25, 00233 TACACSUID = 26, 00234 OutputMark = 27, 00235 TerminalLocation = 28, 00236 Use3270RegimeOption = 29, 00237 UseX3PADOption = 30, 00238 WindowSize = 31, 00239 TerminalSpeed = 32, 00240 FlowControl = 33, 00241 LineModeOption = 34, 00242 XDisplayLocation = 35, 00243 EnvironmentOption = 36, 00244 AuthenticateOption = 37, 00245 EncriptionOption = 38, 00246 EncryptionOption = 38, 00247 ExtendedOptionsList = 255, 00248 MaxOptions 00249 }; 00250 // Defined TELNET options. 00251 00252 00258 virtual PBoolean SendDo( 00259 BYTE option 00260 ); 00261 00267 virtual PBoolean SendDont( 00268 BYTE option 00269 ); 00270 00276 virtual PBoolean SendWill( 00277 BYTE option 00278 ); 00279 00285 virtual PBoolean SendWont( 00286 BYTE option 00287 ); 00288 00289 enum SubOptionCodes { 00290 SubOptionIs = 0, 00291 SubOptionSend = 1, 00292 }; 00293 // Codes for sub option negotiation. 00294 00300 PBoolean SendSubOption( 00301 BYTE code, 00302 const BYTE * info, 00303 PINDEX len, 00304 int subCode = -1 00305 ); 00306 00310 void SetOurOption( 00311 BYTE code, 00312 PBoolean state = true 00313 ) { option[code].weCan = state; } 00314 00318 void SetTheirOption( 00319 BYTE code, 00320 PBoolean state = true 00321 ) { option[code].theyShould = state; } 00322 00328 PBoolean IsOurOption( 00329 BYTE code 00330 ) const { return option[code].ourState == OptionInfo::IsYes; } 00331 00337 PBoolean IsTheirOption( 00338 BYTE code 00339 ) const { return option[code].theirState == OptionInfo::IsYes; } 00340 00341 void SetTerminalType( 00342 const PString & newType 00343 ); 00344 // Set the terminal type description string for TELNET protocol. 00345 00346 const PString & GetTerminalType() const { return terminalType; } 00347 // Get the terminal type description string for TELNET protocol. 00348 00349 void SetWindowSize( 00350 WORD width, 00351 WORD height 00352 ); 00353 // Set the width and height of the Network Virtual Terminal window. 00354 00355 void GetWindowSize( 00356 WORD & width, 00357 WORD & height 00358 ) const; 00359 // Get the width and height of the Network Virtual Terminal window. 00360 00361 00362 protected: 00363 void Construct(); 00364 // Common construct code for TELNET socket channel. 00365 00375 virtual void OnDo( 00376 BYTE option 00377 ); 00378 00385 virtual void OnDont( 00386 BYTE option 00387 ); 00388 00395 virtual void OnWill( 00396 BYTE option 00397 ); 00398 00405 virtual void OnWont( 00406 BYTE option 00407 ); 00408 00412 virtual void OnSubOption( 00413 BYTE code, 00414 const BYTE * info, 00415 PINDEX len 00416 ); 00417 00418 00428 virtual PBoolean OnCommand( 00429 BYTE code 00430 ); 00431 00432 00433 // Member variables. 00434 struct OptionInfo { 00435 enum { 00436 IsNo, IsYes, WantNo, WantNoQueued, WantYes, WantYesQueued 00437 }; 00438 unsigned weCan:1; // We can do the option if they want us to do. 00439 unsigned ourState:3; 00440 unsigned theyShould:1; // They should if they will. 00441 unsigned theirState:3; 00442 }; 00443 00444 OptionInfo option[MaxOptions]; 00445 // Information on protocol options. 00446 00447 PString terminalType; 00448 // Type of terminal connected to telnet socket, defaults to "UNKNOWN" 00449 00450 WORD windowWidth, windowHeight; 00451 // Size of the "window" used by the NVT. 00452 00453 00454 private: 00455 enum State { 00456 StateNormal, 00457 StateCarriageReturn, 00458 StateIAC, 00459 StateDo, 00460 StateDont, 00461 StateWill, 00462 StateWont, 00463 StateSubNegotiations, 00464 StateEndNegotiations 00465 }; 00466 // Internal states for the TELNET decoder 00467 00468 State state; 00469 // Current state of incoming characters. 00470 00471 PBYTEArray subOption; 00472 // Storage for sub-negotiated options 00473 00474 unsigned synchronising; 00475 }; 00476 00477 00478 #endif // PTLIB_TELNET_H 00479 00480 00481 // End Of File ///////////////////////////////////////////////////////////////