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