home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Communications / Internet / TurboTCP 2.1 ƒ / TurboTCP core / CTelnetInterp.h < prev    next >
Encoding:
Text File  |  1995-01-06  |  5.0 KB  |  156 lines  |  [TEXT/MMCC]

  1. //
  2. // CTelnetInterp.h
  3. //
  4. //    TurboTCP library
  5. //    Generic Telnet protocol interpreter
  6. //
  7. //    Copyright © 1993-95, FrostByte Design / Eric Scouten
  8. //
  9.  
  10. #pragma once
  11.  
  12. #include "TurboTCP.buildflags.h"
  13. #include "CTCPEndpoint.h"
  14. #include "Telnet.protocol.h"
  15.  
  16. #if TurboTCP_TCL
  17.     #include "TCL.h"
  18. #endif
  19.  
  20.  
  21. // state variable for the Telnet command parser
  22.  
  23.  
  24.  
  25. //***********************************************************
  26.  
  27. class CTelnetInterp : public CTCPEndpoint {
  28.  
  29. // This abstract class is a specialized TCP protocol interpreter. It is a subclass of the
  30. // CTCPEndpoint mix-in class which implements the basic Telnet protocol. It may be
  31. // used to implement command-line protocols which are based on the Telnet protocol
  32. // (i.e., NNTP or FTP).
  33.  
  34. // This class provides no user interface behaviors and assumes no character-based
  35. // terminal. You will need to subclass this class to interpret the specific protocol
  36. // you are implementing. For an example, see the CTelnetTerminal class in the MiniTelnet
  37. // application.
  38.  
  39. // NOTE: This class is provided only as a convenience. You need not include it in your project.
  40.  
  41.  
  42.  
  43. public:
  44.                     CTelnetInterp(unsigned short theDefaultPort,
  45.                         unsigned long recBufferSize = recReceiveSize,
  46.                         unsigned short autoReceiveSize = recAutoRecSize,
  47.                         unsigned short autoReceiveNum = recAutoRecNum,
  48.                         Boolean doUseCName = true);
  49.  
  50.  
  51.     // respond to incoming data
  52.     
  53.         // Override these methods to place characters on the terminal window or
  54.         // interpret them. All Telnet commands are processed before these methods
  55.         // are called (i.e. the character stream sent to these methods is intended
  56.         // directly for the terminal). Both methods *must* be implemented.
  57.         //
  58.         // HandleNVTChar receives a single character.
  59.         // HandleNVTLine receives a pointer to a C string (maximum 81 characters)
  60.         //        which may or may not be terminated by /n or /r.
  61.  
  62. protected:
  63.     typedef unsigned char uchar;
  64.     virtual void        HandleNVTChar(uchar theChar) = 0;
  65.     virtual void        HandleNVTLine(char* theLine) = 0;
  66.     
  67.  
  68.     // Telnet command handling
  69.     
  70.         // If you wish to respond to specific Telnet commands, override these methods.
  71.         // You may ignore any or all of these methods.
  72.  
  73.     virtual void        ReceivedWill(uchar theOption);
  74.                         // default method responds [WONT <option>]
  75.     virtual void        ReceivedWont(uchar theOption) {}
  76.     virtual void        ReceivedDo(uchar theOption);
  77.                         // default method responds [WONT <option>]
  78.     virtual void        ReceivedDont(uchar theOption) {}
  79.     virtual void        ReceivedBRK() {}
  80.     virtual void        ReceivedSynch() {}
  81.     virtual void        ReceivedIP() {}
  82.     virtual void        ReceivedAO() {}
  83.     virtual void        ReceivedAYT() {}
  84.     virtual void        ReceivedEC() {}
  85.     virtual void        ReceivedEL() {}
  86.     virtual void        ReceivedGA() {}
  87.     virtual void        ReceivedSB(uchar theChar);
  88.                         // default method collects characters until [IAC SE] is received
  89.                         // (characters are ignored unless ReceivedSE is overriden)
  90.     virtual void        ReceivedSE() {}
  91.  
  92.  
  93.     // debugging methods
  94.  
  95.         // Override these methods if you wish to use the debugging features built into
  96.         // this class. If the showDebug field is set, you these methods will receive
  97.         // notifications such as [IAC EC] when Telnet commands are received over
  98.         // the data stream.
  99.         //
  100.         // These methods were useful to me in debugging the implementation of various Telnet
  101.         // options. In a terminal-based method (such as MiniTelnet’s CTelnetTerminal), these
  102.         // should be hooked up to routines that print the relevant data to the display screen.
  103.         //
  104.         //    PrintDebugStr() should display a C string to the terminal.
  105.         //    PrintDebugCharNum() should display a bracketed character number to
  106.         //        the terminal (i.e. if you call PrintDebugCharNum('!', '[', ']'), [33]
  107.         //        should be written to the terminal).
  108.  
  109.     virtual void        PrintDebugStr(char* theDebugStr) {}
  110.     virtual void        PrintDebugCharNum(char theChar, char leftBracket, char rightBracket) {}
  111.  
  112.  
  113.     // respond to incoming data — do not override these methods
  114.     
  115. private:
  116.     virtual void        HandleDataArrived(void* theData, unsigned short theDataSize, Boolean isUrgent);
  117.     virtual void        ReceivedIAC(uchar theCommand);
  118.  
  119.  
  120.     // state variable for Telnet interpreter
  121.  
  122. protected:
  123.     enum TelnetState {
  124.         normalChar,                            // interpret as character
  125.         gotIAC,                                // received an IAC character
  126.         gotSB,                                // in subnegotiation
  127.         gotWILL,                                // received a WILL option
  128.         gotWONT,                                // received a WONT option
  129.         gotDO,                                // received a DO option
  130.         gotDONT,                                // received a DONT option
  131.         gotIACinSB                            // received IAC while in SB
  132.     };
  133.     typedef enum TelnetState TelnetState;
  134.  
  135.     enum {
  136.         sbBfrMax = 80,                        // max size of subnegotiation buffer
  137.         lineBfrMax = 80                        // max size of line buffer
  138.     };
  139.  
  140.  
  141.     // data members
  142.  
  143.     TelnetState        itsState;                    // current command parser state
  144.     short            sbBfrIndex;                // current index to subnegotiation buffer
  145.     char            sbBfr[sbBfrMax];            // subnegotiation buffer
  146.     short            lineBfrIndex;                // current index to linemode buffer
  147.     char            lineBfr[lineBfrMax];            // linemode buffer
  148.     Boolean            useLineBfr;                // hold all characters until full line received
  149.     Boolean            showDebug;                // show debugging codes
  150.  
  151.     #if TurboTCP_TCL
  152.         TCL_DECLARE_CLASS;
  153.     #endif
  154.  
  155. };
  156.