|
1 /* |
|
2 * TcpTestEngine.h |
|
3 * |
|
4 * Created on: Jan 28, 2010 |
|
5 * Author: GUNAGI |
|
6 */ |
|
7 |
|
8 #ifndef TE_TCPSSLTESTENGINE_H_ |
|
9 #define TE_TCPSSLTESTENGINE_H_ |
|
10 |
|
11 #include <e32cons.h> |
|
12 #include <c32comm.h> |
|
13 #include <in_sock.h> |
|
14 #include <es_sock.h> |
|
15 #include <f32file.h> |
|
16 #include <commdbconnpref.h> |
|
17 |
|
18 /** Number of chars allowed for address & page settings */ |
|
19 const TInt KSettingFieldWidth = 128; |
|
20 |
|
21 /** Global variables */ |
|
22 // File system sesion path |
|
23 // IP file where the system IP is mentioned |
|
24 //_LIT8(hostIpAddress, "10.225.164.117"); |
|
25 //const TInt KPortNum = 80; |
|
26 |
|
27 _LIT8(hostIpAddress, "10.1.1.1"); |
|
28 const TInt KPortNum = 80; |
|
29 |
|
30 /** Connection settings to access a server */ |
|
31 struct TConnectSettings |
|
32 { |
|
33 /** Server address (as text) */ |
|
34 TBuf<KSettingFieldWidth> iAddress; |
|
35 /** Server port */ |
|
36 TInt iPortNum; |
|
37 /** Web page to get from the server */ |
|
38 TBuf8<KSettingFieldWidth> iPage; |
|
39 }; |
|
40 |
|
41 /** |
|
42 Manages connection to a SSL web server. |
|
43 */ |
|
44 class CTcpSslTestEngine : public CActive |
|
45 { |
|
46 public: |
|
47 /** |
|
48 Allocates and constructs a new engine. |
|
49 @return New object |
|
50 */ |
|
51 static CTcpSslTestEngine *NewL(); |
|
52 /** |
|
53 Destructor. |
|
54 */ |
|
55 ~CTcpSslTestEngine(); |
|
56 /** |
|
57 Initiates the connection to a server and the transaction |
|
58 |
|
59 @param aAddress Server address (e.g. www.symbian.com or dotted decimal format) |
|
60 |
|
61 @param aPortNum Server port for secure web (e.g. 443) |
|
62 |
|
63 @param aPage Web page to get from the server. The leading `/` should be included, e.g. /webpage.html. |
|
64 |
|
65 @param aCipherSuite Cipher suites that client will tell server it supports (decimal). This |
|
66 should be in decimal, with 2 characters, ie for suites 3,7,8,9, this field would be 03070809. |
|
67 By entering a single `0` for this field, the SSL default cipher suites will be passed. |
|
68 |
|
69 @param aCipher Cipher suite that server is expected to use (decimal). This is compared with |
|
70 actual cipher for pass/fail. If this field is 0, no comparisons with the actual cipher |
|
71 suite used will be made. |
|
72 |
|
73 */ |
|
74 void ConnectL( const TConnectSettings& aConnectSettings ); |
|
75 /** |
|
76 Sets the console to write messages to |
|
77 |
|
78 @param aConsole The console |
|
79 */ |
|
80 void SetConsole( CConsoleBase& aConsole ); |
|
81 |
|
82 /** |
|
83 Sets the (opened) file to write server response to |
|
84 |
|
85 @param aOutputFile The file |
|
86 */ |
|
87 void SetOutputFile( RFile& aOutputFile ); |
|
88 |
|
89 |
|
90 void Initialize(); |
|
91 |
|
92 /** |
|
93 Tests if the connection is in progress. |
|
94 |
|
95 @return True if in progress else false |
|
96 */ |
|
97 TBool InUse(); |
|
98 |
|
99 |
|
100 private: |
|
101 /** Engine states */ |
|
102 enum TStates |
|
103 { |
|
104 /** IP connection initiated */ |
|
105 ESocketConnected, |
|
106 /** Setting the ciphers for a secure connection */ |
|
107 ESettingCiphers, |
|
108 /** Secure socket request initiated */ |
|
109 ESecureConnected, |
|
110 /** Send get page request to server */ |
|
111 EGetRequestSent, |
|
112 /** Server has responded to request */ |
|
113 EDataReceived, |
|
114 /** Connection closed down */ |
|
115 EConnectionClosed |
|
116 }; |
|
117 |
|
118 private: |
|
119 /** Constructor. */ |
|
120 CTcpSslTestEngine(); |
|
121 /** Second phase constructor. */ |
|
122 void ConstructL(); |
|
123 |
|
124 // Methods from CActive |
|
125 /** Previous state has completed. */ |
|
126 void RunL(); |
|
127 /** Cancel request */ |
|
128 void DoCancel(); |
|
129 /** Handles a leave occurring in RunL(). */ |
|
130 TInt RunError( TInt aError ); |
|
131 |
|
132 // Handle particular engine states |
|
133 /** Attempts secure connection. */ |
|
134 void MakeConnectionL(); |
|
135 /** Sends page request to server */ |
|
136 void MakePageRequestL(); |
|
137 /** Start getting server's response to the request */ |
|
138 void GetServerResponseL(); |
|
139 /** Finish getting server's response */ |
|
140 void ReadServerResponseL(); |
|
141 /** Handle connection completed */ |
|
142 void ConnectionClosed(); |
|
143 |
|
144 private: |
|
145 // Sockets objects |
|
146 /** The socket server */ |
|
147 RSocketServ iSocketServ; |
|
148 /** Socket to make connection on */ |
|
149 RSocket iSocket; |
|
150 /** For resolving DNS addresses */ |
|
151 RHostResolver iHostResolver; |
|
152 /** Server address */ |
|
153 TInetAddr iInetAddr; |
|
154 |
|
155 // Connection parameters |
|
156 const TConnectSettings* iConnectSettings; |
|
157 |
|
158 // Transfer buffers and counters |
|
159 /** Data sent buffer */ |
|
160 TPtr8 iSndBuffer; |
|
161 /** #bytes sent */ |
|
162 TSockXfrLength iBytesSent; |
|
163 /** Data received buffer */ |
|
164 TPtr8 iRcvBuffer; |
|
165 /** #bytes received */ |
|
166 TInt iTotalBytesRead; |
|
167 |
|
168 /** For retries, after a delay */ |
|
169 RTimer iTimer; |
|
170 |
|
171 /** Output console */ |
|
172 CConsoleBase *iConsole; |
|
173 /** Output file */ |
|
174 RFile* iOutputFile; |
|
175 |
|
176 // Flags and state |
|
177 /** True if the transation completed successfully */ |
|
178 TBool iSuccess; |
|
179 /** True if success on first attempt */ |
|
180 TBool iFirstRunFlag; |
|
181 /** True if connection is in progress */ |
|
182 TBool iInUse; |
|
183 /** Engine state (a TStates value) */ |
|
184 TInt iRunState; |
|
185 |
|
186 /** Counter for stopping making connections */ |
|
187 TInt iCounter; |
|
188 |
|
189 RFs iFs; |
|
190 }; |
|
191 |
|
192 |
|
193 #endif /* TE_TCPSSLTESTENGINE_H_ */ |