00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00050
00051 PTelnetSocket(
00052 const PString & address
00053 );
00054
00055
00056
00057
00073 PBoolean Read(
00074 void * buf,
00075 PINDEX len
00076 );
00077
00091 PBoolean Write(
00092 const void * buf,
00093 PINDEX len
00094 );
00095
00096
00108 virtual PBoolean Connect(
00109 const PString & address
00110 );
00111
00112
00127 virtual PBoolean Accept(
00128 PSocket & socket
00129 );
00130
00131
00138 virtual void OnOutOfBand(
00139 const void * buf,
00140 PINDEX len
00141 );
00142
00143
00144
00145 enum Command {
00146 IAC = 255,
00147 DONT = 254,
00148 DO = 253,
00149 WONT = 252,
00150 WILL = 251,
00151 SB = 250,
00152 GoAhead = 249,
00153 EraseLine = 248,
00154 EraseChar = 247,
00155 AreYouThere = 246,
00156 AbortOutput = 245,
00157 InterruptProcess = 244,
00158 Break = 243,
00159 DataMark = 242,
00160 NOP = 241,
00161 SE = 240,
00162 EndOfReccord = 239,
00163 AbortProcess = 238,
00164 SuspendProcess= 237,
00165 EndOfFile = 236
00166 };
00167
00168
00189 PBoolean SendCommand(
00190 Command cmd,
00191 int opt = 0
00192 );
00193
00194
00195 enum Options {
00196 TransmitBinary = 0,
00197 EchoOption = 1,
00198 ReconnectOption = 2,
00199 SuppressGoAhead = 3,
00200 MessageSizeOption = 4,
00201 StatusOption = 5,
00202 TimingMark = 6,
00203 RCTEOption = 7,
00204 OutputLineWidth = 8,
00205 OutputPageSize = 9,
00206 CRDisposition = 10,
00207 HorizontalTabsStops = 11,
00208 HorizTabDisposition = 12,
00209 FormFeedDisposition = 13,
00210 VerticalTabStops = 14,
00211 VertTabDisposition = 15,
00212 LineFeedDisposition = 16,
00213 ExtendedASCII = 17,
00214 ForceLogout = 18,
00215 ByteMacroOption = 19,
00216 DataEntryTerminal = 20,
00217 SupDupProtocol = 21,
00218 SupDupOutput = 22,
00219 SendLocation = 23,
00220 TerminalType = 24,
00221 EndOfRecordOption = 25,
00222 TACACSUID = 26,
00223 OutputMark = 27,
00224 TerminalLocation = 28,
00225 Use3270RegimeOption = 29,
00226 UseX3PADOption = 30,
00227 WindowSize = 31,
00228 TerminalSpeed = 32,
00229 FlowControl = 33,
00230 LineModeOption = 34,
00231 XDisplayLocation = 35,
00232 EnvironmentOption = 36,
00233 AuthenticateOption = 37,
00234 EncriptionOption = 38,
00235 EncryptionOption = 38,
00236 ExtendedOptionsList = 255,
00237 MaxOptions
00238 };
00239
00240
00241
00247 virtual PBoolean SendDo(
00248 BYTE option
00249 );
00250
00256 virtual PBoolean SendDont(
00257 BYTE option
00258 );
00259
00265 virtual PBoolean SendWill(
00266 BYTE option
00267 );
00268
00274 virtual PBoolean SendWont(
00275 BYTE option
00276 );
00277
00278 enum SubOptionCodes {
00279 SubOptionIs = 0,
00280 SubOptionSend = 1,
00281 };
00282
00283
00289 PBoolean SendSubOption(
00290 BYTE code,
00291 const BYTE * info,
00292 PINDEX len,
00293 int subCode = -1
00294 );
00295
00299 void SetOurOption(
00300 BYTE code,
00301 PBoolean state = PTrue
00302 ) { option[code].weCan = state; }
00303
00307 void SetTheirOption(
00308 BYTE code,
00309 PBoolean state = PTrue
00310 ) { option[code].theyShould = state; }
00311
00317 PBoolean IsOurOption(
00318 BYTE code
00319 ) const { return option[code].ourState == OptionInfo::IsYes; }
00320
00326 PBoolean IsTheirOption(
00327 BYTE code
00328 ) const { return option[code].theirState == OptionInfo::IsYes; }
00329
00330 void SetTerminalType(
00331 const PString & newType
00332 );
00333
00334
00335 const PString & GetTerminalType() const { return terminalType; }
00336
00337
00338 void SetWindowSize(
00339 WORD width,
00340 WORD height
00341 );
00342
00343
00344 void GetWindowSize(
00345 WORD & width,
00346 WORD & height
00347 ) const;
00348
00349
00350
00351 protected:
00352 void Construct();
00353
00354
00364 virtual void OnDo(
00365 BYTE option
00366 );
00367
00374 virtual void OnDont(
00375 BYTE option
00376 );
00377
00384 virtual void OnWill(
00385 BYTE option
00386 );
00387
00394 virtual void OnWont(
00395 BYTE option
00396 );
00397
00401 virtual void OnSubOption(
00402 BYTE code,
00403 const BYTE * info,
00404 PINDEX len
00405 );
00406
00407
00417 virtual PBoolean OnCommand(
00418 BYTE code
00419 );
00420
00421
00422
00423 struct OptionInfo {
00424 enum {
00425 IsNo, IsYes, WantNo, WantNoQueued, WantYes, WantYesQueued
00426 };
00427 unsigned weCan:1;
00428 unsigned ourState:3;
00429 unsigned theyShould:1;
00430 unsigned theirState:3;
00431 };
00432
00433 OptionInfo option[MaxOptions];
00434
00435
00436 PString terminalType;
00437
00438
00439 WORD windowWidth, windowHeight;
00440
00441
00442 PBoolean debug;
00443
00444
00445
00446 private:
00447 enum State {
00448 StateNormal,
00449 StateCarriageReturn,
00450 StateIAC,
00451 StateDo,
00452 StateDont,
00453 StateWill,
00454 StateWont,
00455 StateSubNegotiations,
00456 StateEndNegotiations
00457 };
00458
00459
00460 State state;
00461
00462
00463 PBYTEArray subOption;
00464
00465
00466 unsigned synchronising;
00467
00468 PBoolean StartSend(const char * which, BYTE code);
00469 };
00470
00471
00472 #endif // PTLIB_TELNET_H
00473
00474
00475