epoc32/include/telsess.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 telsess.h
     1 /**
       
     2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Telnet Session API
       
    16 * 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25  @file TELSESS.H
       
    26 */
       
    27 
       
    28 #ifndef _TELSESS_H_
       
    29 #define _TELSESS_H_
       
    30 
       
    31 #include <in_sock.h>
       
    32 #include <e32std.h>
       
    33 #include <e32cons.h>
       
    34 #include <f32file.h>
       
    35 
       
    36 #define __TELNETSESSDEBUG__ // Put in Debug mode
       
    37 
       
    38 class CTelnetControl;
       
    39 
       
    40 // Used by client to retrieve RFC option state
       
    41 // Flags for Telnet negotiated options
       
    42 // 1 = Enabled 0 = Disabled
       
    43 
       
    44 /**
       
    45 Defines the supported, RFC-defined, option status.
       
    46 
       
    47 @publishedAll
       
    48 @released 
       
    49 */
       
    50 typedef struct
       
    51     {
       
    52 	/** If ETrue, the server is sending in binary (RFC 856). */
       
    53     TBool    iServerBinary; ///< RFC 856  (Server Sending in Binary)
       
    54 	/** If ETrue, the client is sending in binary (RFC 856). */
       
    55     TBool    iClientBinary; ///< RFC 856  (Client Sending in Binary)
       
    56 	/** If ETrue, the server is echoing data back to the client (RFC 857). */
       
    57     TBool    iEcho;         ///< RFC 857  (Server Echoing Data from Client)
       
    58 	/** If ETrue, the client will negotiate about window size (RFC 1073). */
       
    59     TBool    iNAWS;         ///< RFC 1073 (Client Providing Window Size Information)
       
    60 	/** If ETrue, the terminal speed option is enabled (RFC 1079). */
       
    61     TBool    iTerminalSpeed;///< RFC 1079 (Client Providing Terminal Speed Information)
       
    62 	/** If ETrue, the client is providing terminal type information (RFC 1091). */
       
    63     TBool    iTerminalType; ///< RFC 1091 (Client Providing Terminal Type Information)
       
    64 	/** If ETrue, if the server is providing status information (RFC 859). */
       
    65     TBool    iServerStatus; ///< RFC 859  (Server Providing Status Information)
       
    66 	/** If ETrue, if the client is providing status information (RFC 859). */
       
    67     TBool    iClientStatus; ///< RFC 859  (Client Providing Status Information)
       
    68     }TOptionStatus;
       
    69 
       
    70 // Used by client to configure the Symbian Telnet
       
    71 class TTelnetConfig
       
    72 /**
       
    73 * Specifies telnet session configuration information.
       
    74 * 
       
    75 * The client must provide a reference to an instance of this class as a parameter 
       
    76 * to the CTelnetSession::NewL() function. 
       
    77 * 
       
    78 * Configuration options can be modified, when the session is in progress, using 
       
    79 * the CTelnetSession::DoModifyConfig() function. 
       
    80 * 
       
    81 * Configuration option state can be obtained using the CTelnetSession::OptionStatus() 
       
    82 * function.
       
    83 * @publishedAll
       
    84 * @released 
       
    85 */
       
    86     {
       
    87  public:
       
    88 
       
    89 	/** Constructor. */
       
    90 	 TTelnetConfig() {
       
    91 		              iAllowLogout = TRUE;        // RFC 727  - Default TRUE = Server Can Logout Client
       
    92 					  iWindowSize.x = (TInt16)80; // RFC 1073 - Default 80 x 24
       
    93 					  iWindowSize.y = (TInt16)24;
       
    94 					  iTermSpeed = _L8("38400");  // RFC 1079 - Default to 38400 Baud Terminal
       
    95 					  iTermType  = _L8("dumb");   // RFC 1091 - Default to base NVT Terminal
       
    96 					}
       
    97 	/** Destructor. */
       
    98 	 ~TTelnetConfig(){}
       
    99 
       
   100 	typedef struct
       
   101 		/** 
       
   102 		* Specifies the client's window size.
       
   103 		* 
       
   104 		* The default is 80 columns by 24 rows which constructs to x=80, y=24. 
       
   105 		*/
       
   106 		{
       
   107 		/** The client window's width (number of columns). */
       
   108 		TInt16 x;
       
   109 		/** The client window's height (number of rows). */
       
   110 		TInt16 y;
       
   111 		}TWindowSize;
       
   112 
       
   113 	/** 
       
   114 	* Specifies the client's window size.
       
   115 	* 
       
   116 	* The default is 80 columns by 24 rows. 
       
   117 	* 
       
   118 	* (RFC 1073 -- Set to Configure Window Size) 
       
   119 	*/
       
   120 	TWindowSize	iWindowSize; 
       
   121 	
       
   122 	/**
       
   123 	* Specifies the speed of the telnet connection.
       
   124 	* 
       
   125 	* The default is "38400" (in ASCII characters). Must be set to a server-supported rate.
       
   126 	* 
       
   127 	* (RFC 1079 -- Set to Configure Terminal Speed) 
       
   128 	*/
       
   129 	TBuf8<20>	iTermSpeed;  
       
   130 	
       
   131 	/**
       
   132 	* Specifies the terminal type.
       
   133 	* 
       
   134 	* The default is "dumb" (in ASCII characters). 
       
   135 	* 
       
   136 	* (RFC 1091 -- Set to Configure Terminal Type) 
       
   137 	*/
       
   138 	TBuf8<20>	iTermType;
       
   139 	
       
   140 	/**
       
   141 	* Specifies whether the telnet server can logout the client.
       
   142 	* 
       
   143 	* The default, ETrue, enables the server to logout the client. If EFalse any 
       
   144 	* logout request from the telnet server is rejected by the client.
       
   145 	*
       
   146 	* (RFC 727 -- Set/Clear to Enable/Disable Server Logout) 
       
   147 	*/
       
   148 	TBool		iAllowLogout;
       
   149 	
       
   150 	/**
       
   151 	* Enables or disables telnet server echo to client.
       
   152 	* 
       
   153 	* The default, ETrue, enables server echo. Note that although this is normal 
       
   154 	* telnet server behaviour, it is not a formal telnet requirement. It is therefore 
       
   155 	* recommended that the client implement an optional local echo. 
       
   156 	*
       
   157 	* (RFC 857 -- Set/Clear to Enable/Disable Server Echo to client) 
       
   158 	*/
       
   159 	TBool		iServerEcho;
       
   160     };
       
   161 
       
   162 // Client can pass these in overloaded CTelnetSession::Write(TTelnetUserControl& aControlCode);
       
   163 
       
   164 /**
       
   165 * Specifies the telnet control code to send to the server.
       
   166 *
       
   167 * This is done using the overloaded CTelnetSession::Write() function.
       
   168 * @publishedAll
       
   169 * @released 
       
   170 */
       
   171 enum TTelnetUserControl 
       
   172     {
       
   173 	/** Control code not supported. */
       
   174     ENotSupported = 0,
       
   175 	
       
   176 	/**
       
   177 	* Break (the NVT 129th ASCII break code).
       
   178 	* The default is 243. This is not a valid control in Binary mode. 
       
   179 	*/
       
   180     EBrk	= 243,
       
   181 	
       
   182 	/**
       
   183 	* Interupt Process.
       
   184 	* The default is 244.
       
   185 	*/
       
   186     EIp		= 244,
       
   187 	
       
   188 	/** 
       
   189 	* Abort Output.
       
   190 	* The default is 245. 
       
   191 	*/
       
   192     EAo		= 245,
       
   193 	
       
   194 	/**
       
   195 	Are you there?
       
   196 	* The default is 246. 
       
   197 	*/
       
   198     EAyt	= 246,
       
   199 	
       
   200 	/**
       
   201 	* Erase Character. 
       
   202 	* The default is 247. This is not a valid control in Binary mode. 
       
   203 	*/
       
   204     EEc		= 247,
       
   205 	
       
   206 	/** 
       
   207 	* Erase Line.
       
   208 	* The default is 248. This is not a valid control in Binary mode. 
       
   209 	*/
       
   210     EEl		= 248,
       
   211     };
       
   212 
       
   213 // Client MUST override this class
       
   214 // Client MUST provide a pointer to an instance of this class as a parameter to CTelnetSession::NewL()
       
   215 class MTelnetNotification
       
   216 /**
       
   217 * Symbian telnet notification interface.
       
   218 * 
       
   219 * Informs the client when an error occurs, when reads and writes have completed, 
       
   220 * when a connection is made or closed and when configuration options change.
       
   221 * @publishedAll
       
   222 * @released 
       
   223 */
       
   224     {
       
   225  public:
       
   226 	/** 
       
   227 	* Reports errors on the Telnet connection.
       
   228 	*
       
   229 	* The error code is supplied by the server. If this function is called, it is 
       
   230 	* likely that the connection has failed. Therefore it is recommended that the 
       
   231 	* client disconnects and resets its state.
       
   232 	* 
       
   233 	* @param aError	Error code from server. 
       
   234 	 */
       
   235     virtual void Error(TInt aError) = 0; ///< Miscellaneous Error callback
       
   236 	
       
   237 	/** 
       
   238 	* Passes the data that was received from the server to the client.
       
   239 	* 
       
   240 	* It is recommended that the client copies the data from this buffer, as it 
       
   241 	* is owned by the Symbian telnet.
       
   242 	* 
       
   243 	* @param aBuffer	Data received from server. 
       
   244 	*/
       
   245     virtual void ReadComplete(const TDesC8& aBuffer) = 0; ///< Last Read to Server completion callback
       
   246 	
       
   247 	/** Notifies the client that a write to the server from the client has completed. */
       
   248     virtual void WriteComplete() = 0; ///< Last Write to Server completion callback
       
   249 	
       
   250 	/** Notifies the client that the connection to the server has been closed. */
       
   251     virtual void ConnectionClosed() = 0; ///< Telnet Connection Closed callback
       
   252 	
       
   253 	/** Notifies the client that a connection to the server has been made. */
       
   254     virtual void Connected() = 0; ///< Telnet Connected callback
       
   255 	
       
   256 	/** Notifies the client that telnet configuration options have changed. */
       
   257     virtual void OptionsChanged() = 0;                    ///< Telnet RFC Options Changed callback
       
   258     };
       
   259 
       
   260 class CTelnetControl;
       
   261 
       
   262 class CTelnetSession : public CBase
       
   263 /**
       
   264 * The main Symbian telnet class.
       
   265 * 
       
   266 * Consists of a connection interface and a protocol interface. The connection 
       
   267 * interface comprises member functions that: connect to, read from, write to 
       
   268 * and disconnect from a telnet server.
       
   269 * 
       
   270 * The protocol interface includes member functions that get and set telnet configuration.
       
   271 *
       
   272 * @publishedAll
       
   273 * @released 
       
   274 */
       
   275     {
       
   276     //public:
       
   277     // Data Structures
       
   278  public:
       
   279     ~CTelnetSession();
       
   280     // Construction
       
   281     // Need to add max buffer size to constructor [check]
       
   282     IMPORT_C static CTelnetSession* NewL(const TTelnetConfig& aConfig,const MTelnetNotification* aNotifier);
       
   283  protected:
       
   284     IMPORT_C void ConstructL(const TTelnetConfig& aConfig,const MTelnetNotification* aNotifier);
       
   285     //
       
   286     // Connection Interface
       
   287     //
       
   288  public:
       
   289     IMPORT_C TInt Connect(const TInetAddr& aNetAddr); ///< Connects to aNetAddr on the standard telnet port (port 23)
       
   290     IMPORT_C TInt Connect(const TInetAddr& aNetAddr, TUint aPort); ///< Connects to aNetAddr on user specified port
       
   291     IMPORT_C TInt Connect(const TDesC& aServerName); ///< Connects to aSeverName on the standard telnet port (port 23)
       
   292     IMPORT_C TInt Connect(const TDesC& aServerName, TUint aPort); ///< Connects to aServerName on user specified port
       
   293     IMPORT_C TInt Disconnect(); ///< Disconnects current connection 
       
   294     IMPORT_C TInt Write(const TDesC8& aBuffer); ///< Writes a byte stream over the open telnet connection.
       
   295     IMPORT_C TInt Write(TTelnetUserControl& aControlCode); ///< Writes NVT code to stream. Prepends \<IAC\> code (255)
       
   296     IMPORT_C TInt Read(); ///< Read data received over telnet buffer.
       
   297     
       
   298 	//
       
   299 	// Protocol Interface 
       
   300 	//
       
   301 	IMPORT_C TInt DoForceLogout();
       
   302 	IMPORT_C TInt DoModifyConfig(TTelnetConfig& aConfig);
       
   303 	IMPORT_C TInt OptionStatus(TOptionStatus& aStatus);
       
   304  private:
       
   305     CTelnetSession();
       
   306 
       
   307  private:
       
   308     MTelnetNotification* iNotifier;
       
   309     CTelnetControl* iTelnetProtocol;
       
   310 
       
   311     };
       
   312 
       
   313 
       
   314 #endif // _TELNETPROTOCOLAPI_H_