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