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