2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
36 #define __TELNETSESSDEBUG__ // Put in Debug mode
40 // Used by client to retrieve RFC option state
41 // Flags for Telnet negotiated options
42 // 1 = Enabled 0 = Disabled
45 Defines the supported, RFC-defined, option status.
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)
70 // Used by client to configure the Symbian Telnet
73 * Specifies telnet session configuration information.
75 * The client must provide a reference to an instance of this class as a parameter
76 * to the CTelnetSession::NewL() function.
78 * Configuration options can be modified, when the session is in progress, using
79 * the CTelnetSession::DoModifyConfig() function.
81 * Configuration option state can be obtained using the CTelnetSession::OptionStatus()
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
102 * Specifies the client's window size.
104 * The default is 80 columns by 24 rows which constructs to x=80, y=24.
107 /** The client window's width (number of columns). */
109 /** The client window's height (number of rows). */
114 * Specifies the client's window size.
116 * The default is 80 columns by 24 rows.
118 * (RFC 1073 -- Set to Configure Window Size)
120 TWindowSize iWindowSize;
123 * Specifies the speed of the telnet connection.
125 * The default is "38400" (in ASCII characters). Must be set to a server-supported rate.
127 * (RFC 1079 -- Set to Configure Terminal Speed)
129 TBuf8<20> iTermSpeed;
132 * Specifies the terminal type.
134 * The default is "dumb" (in ASCII characters).
136 * (RFC 1091 -- Set to Configure Terminal Type)
141 * Specifies whether the telnet server can logout the client.
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.
146 * (RFC 727 -- Set/Clear to Enable/Disable Server Logout)
151 * Enables or disables telnet server echo to client.
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.
157 * (RFC 857 -- Set/Clear to Enable/Disable Server Echo to client)
162 // Client can pass these in overloaded CTelnetSession::Write(TTelnetUserControl& aControlCode);
165 * Specifies the telnet control code to send to the server.
167 * This is done using the overloaded CTelnetSession::Write() function.
171 enum TTelnetUserControl
173 /** Control code not supported. */
177 * Break (the NVT 129th ASCII break code).
178 * The default is 243. This is not a valid control in Binary mode.
184 * The default is 244.
190 * The default is 245.
196 * The default is 246.
202 * The default is 247. This is not a valid control in Binary mode.
208 * The default is 248. This is not a valid control in Binary mode.
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
217 * Symbian telnet notification interface.
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.
227 * Reports errors on the Telnet connection.
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.
233 * @param aError Error code from server.
235 virtual void Error(TInt aError) = 0; ///< Miscellaneous Error callback
238 * Passes the data that was received from the server to the client.
240 * It is recommended that the client copies the data from this buffer, as it
241 * is owned by the Symbian telnet.
243 * @param aBuffer Data received from server.
245 virtual void ReadComplete(const TDesC8& aBuffer) = 0; ///< Last Read to Server completion callback
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
250 /** Notifies the client that the connection to the server has been closed. */
251 virtual void ConnectionClosed() = 0; ///< Telnet Connection Closed callback
253 /** Notifies the client that a connection to the server has been made. */
254 virtual void Connected() = 0; ///< Telnet Connected callback
256 /** Notifies the client that telnet configuration options have changed. */
257 virtual void OptionsChanged() = 0; ///< Telnet RFC Options Changed callback
260 class CTelnetControl;
262 class CTelnetSession : public CBase
264 * The main Symbian telnet class.
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.
270 * The protocol interface includes member functions that get and set telnet configuration.
281 // Need to add max buffer size to constructor [check]
282 IMPORT_C static CTelnetSession* NewL(const TTelnetConfig& aConfig,const MTelnetNotification* aNotifier);
284 IMPORT_C void ConstructL(const TTelnetConfig& aConfig,const MTelnetNotification* aNotifier);
286 // Connection Interface
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.
299 // Protocol Interface
301 IMPORT_C TInt DoForceLogout();
302 IMPORT_C TInt DoModifyConfig(TTelnetConfig& aConfig);
303 IMPORT_C TInt OptionStatus(TOptionStatus& aStatus);
308 MTelnetNotification* iNotifier;
309 CTelnetControl* iTelnetProtocol;
314 #endif // _TELNETPROTOCOLAPI_H_