|
1 /* |
|
2 * Copyright (c) 2008 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: HttpSessionClient |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "httpsessionclient.h" |
|
19 #include "chttptransactionclient.h" |
|
20 #include "javavalidationfilter.h" |
|
21 #include <http/thttpfilteriterator.h> |
|
22 #include <httpstringconstants.h> |
|
23 #include <e32svr.h> |
|
24 #include "logger.h" |
|
25 #include <commdbconnpref.h> |
|
26 |
|
27 #include <http/cecomfilter.h> |
|
28 #include <httpfilterproxyinterface.h> |
|
29 #include <httpfiltercommonstringsext.h> |
|
30 |
|
31 |
|
32 //const TUint32 KMIDletSuiteAPNNotSpecified = KMaxTUint32; |
|
33 |
|
34 HttpSessionClient::HttpSessionClient() |
|
35 { |
|
36 |
|
37 } |
|
38 |
|
39 |
|
40 /*HttpSessionClient* HttpSessionClient::NewL() |
|
41 { |
|
42 LOG(ESOCKET,EInfo,"+HttpSessionClient::NewL "); |
|
43 return HttpSessionClient::NewL(-1, -1); |
|
44 }*/ |
|
45 |
|
46 HttpSessionClient* HttpSessionClient::NewL(TInt aType,TInt aAPNId,TInt * apnerr) |
|
47 { |
|
48 HttpSessionClient* self = new(ELeave) HttpSessionClient(); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(aType,aAPNId,apnerr); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 /* |
|
56 * -j2me expects the http stack to be able to post body data with no content type |
|
57 * the native stack default validation filter does not allow this. |
|
58 * -j2me expects the http stack to allow post requests to have body data |
|
59 * the native stack default validation filter does not allow this. |
|
60 */ |
|
61 |
|
62 /** |
|
63 * To remove default Redirection filter. |
|
64 * |
|
65 * Preconditions. The following conditions must be true prior to calling |
|
66 * this method; otherwise, its operation is undefined. |
|
67 * - None. |
|
68 * |
|
69 * Postconditions. The following condition is true immediately after |
|
70 * returning from this method. |
|
71 * - Java HTTP session does not have Redirection filter. |
|
72 * |
|
73 * @param None. |
|
74 * @return None. |
|
75 * @exception None. |
|
76 */ |
|
77 void HttpSessionClient::RemoveRedirectionFilter() |
|
78 { |
|
79 RHTTPFilterCollection filtColl = iHttpSession.FilterCollection(); |
|
80 |
|
81 if (filtColl.CanChangeFilters()) |
|
82 { |
|
83 |
|
84 // Remove default redirection filter. |
|
85 RStringF valFilter = iHttpSession.StringPool().StringF(HTTP::ERedirect, RHTTPSession::GetTable()); |
|
86 filtColl.RemoveFilter(valFilter); |
|
87 } |
|
88 } |
|
89 |
|
90 void HttpSessionClient::ReplaceValidationFilterL() |
|
91 { |
|
92 RHTTPFilterCollection filtColl = iHttpSession.FilterCollection(); |
|
93 if (filtColl.CanChangeFilters()) |
|
94 { |
|
95 RStringF valFilter = iHttpSession.StringPool().StringF(HTTP::EValidation,RHTTPSession::GetTable()); |
|
96 //Remove default validation filter |
|
97 filtColl.RemoveFilter(valFilter); |
|
98 |
|
99 valFilter = iHttpSession.StringPool().StringF(HTTP::EDeflate, RHTTPSession::GetTable()); |
|
100 //Remove default deflate filter |
|
101 filtColl.RemoveFilter(valFilter); |
|
102 |
|
103 valFilter = iHttpSession.StringPool().StringF(HTTP::EUserAgent, RHTTPSession::GetTable()); |
|
104 //Remove default useragent filter |
|
105 filtColl.RemoveFilter(valFilter); |
|
106 |
|
107 //Install the java validation filter |
|
108 iValidationFilter = CJavaValidationFilter::InstallFilterL(&iHttpSession); |
|
109 } |
|
110 } |
|
111 |
|
112 void HttpSessionClient::ConstructL(TInt aType, TInt aAPNId, TInt * apnerr) |
|
113 { |
|
114 LOG(ESOCKET,EInfo,"+HttpSessionClient::ConstructL "); |
|
115 |
|
116 /*CActiveScheduler * scheduler = new CActiveScheduler(); |
|
117 CActiveScheduler::Install(scheduler); |
|
118 CActiveScheduler::Add(this);*/ |
|
119 |
|
120 iHttpSession.OpenL(); |
|
121 LOG(ESOCKET,EInfo,"+HttpSessionClient::ConstructL- RHttpSession opened "); |
|
122 //Update the exiting Http filter with a java rules based filter |
|
123 ReplaceValidationFilterL(); |
|
124 |
|
125 RemoveRedirectionFilter(); |
|
126 if (aType == 2) // SNAP ID |
|
127 { |
|
128 LOG(ESOCKET,EInfo,"type is snap id"); |
|
129 if (aAPNId != -1) |
|
130 { |
|
131 iApnId = aAPNId; |
|
132 // Creates connection with selected SNAP ID |
|
133 int ret = iSocketServ.Connect(); |
|
134 LOG1(ESOCKET,EInfo,"iSocketServ.Connect() returned %d",ret); |
|
135 if (ret < 0) |
|
136 { |
|
137 LOG(ESOCKET,EInfo,"+HttpSessionClient::iSocketServ.Connect() failed "); |
|
138 *apnerr = ret; |
|
139 return; |
|
140 } |
|
141 ret = iConnection.Open(iSocketServ); |
|
142 LOG1(ESOCKET,EInfo,"iConnection.Open returned %d",ret); |
|
143 if (ret < 0) |
|
144 { |
|
145 LOG(ESOCKET,EInfo,"+HttpSessionClient::iConnection.Open failed "); |
|
146 *apnerr = ret; |
|
147 return; |
|
148 } |
|
149 |
|
150 TCommSnapPref connPref; |
|
151 connPref.SetSnap(aAPNId); |
|
152 ret = iConnection.Start(connPref); |
|
153 LOG1(ESOCKET,EInfo,"iConnection.Start returned %d",ret); |
|
154 if (ret < 0) |
|
155 { |
|
156 *apnerr = ret; |
|
157 // return; |
|
158 } |
|
159 else |
|
160 { |
|
161 RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo(); |
|
162 connInfo.SetPropertyL(iHttpSession.StringPool().StringF( |
|
163 HTTP::EHttpSocketServ, RHTTPSession::GetTable()), THTTPHdrVal(iSocketServ.Handle())); |
|
164 TInt connPtr = REINTERPRET_CAST(TInt, &iConnection); |
|
165 connInfo.SetPropertyL(iHttpSession.StringPool().StringF( |
|
166 HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal(connPtr)); |
|
167 } |
|
168 } // end of if(apnid != -1) |
|
169 LOG1(ESOCKET,EInfo,"apnerr = %d",*apnerr); |
|
170 } // end of if(aType == 3 ) |
|
171 else |
|
172 { |
|
173 if (aType == 3) // IAP Id |
|
174 { |
|
175 if (aAPNId != -1) |
|
176 { |
|
177 // Creates connection with selected IAP ID |
|
178 int ret = iSocketServ.Connect(); |
|
179 if (ret < 0) |
|
180 { |
|
181 LOG(ESOCKET,EInfo,"+HttpSessionClient::iSocketServ.Connect() failed "); |
|
182 *apnerr = ret; |
|
183 return; |
|
184 } |
|
185 ret = iConnection.Open(iSocketServ); |
|
186 if (ret < 0) |
|
187 { |
|
188 LOG(ESOCKET,EInfo,"+HttpSessionClient::iConnection.Open failed "); |
|
189 *apnerr = ret; |
|
190 return; |
|
191 } |
|
192 TCommDbConnPref pref; |
|
193 pref.SetIapId(aAPNId); |
|
194 pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
195 ret = iConnection.Start(pref); |
|
196 if (ret < 0) |
|
197 { |
|
198 *apnerr = ret; |
|
199 //return; |
|
200 } |
|
201 RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo(); |
|
202 connInfo.SetPropertyL(iHttpSession.StringPool().StringF( |
|
203 HttpFilterCommonStringsExt::EAccessPointID, HttpFilterCommonStringsExt::GetTable()), aAPNId); |
|
204 } // end of if ( aAPNId != -1) |
|
205 } // end of if(aType == 4) |
|
206 else |
|
207 { |
|
208 // Creates connection with no selected Network Access. |
|
209 } |
|
210 |
|
211 } // end of else |
|
212 |
|
213 LOG1(ESOCKET,EInfo,"apnerr = ",*apnerr); |
|
214 |
|
215 // This is special case when that IAP/SNAP is not found |
|
216 // Override the http stack's feaute of using device default |
|
217 if (*apnerr < 0) |
|
218 { |
|
219 LOG(ESOCKET,EInfo,"ECommDbDialogPrefPrompt set for the http session"); |
|
220 int ret = iSocketServ.Connect(); |
|
221 ret = iConnection.Open(iSocketServ); |
|
222 TCommDbConnPref pref; |
|
223 pref.SetDialogPreference(ECommDbDialogPrefPrompt); |
|
224 ret = iConnection.Start(pref); |
|
225 |
|
226 RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo(); |
|
227 connInfo.SetPropertyL(iHttpSession.StringPool().StringF( |
|
228 HTTP::EHttpSocketServ, RHTTPSession::GetTable()), THTTPHdrVal(iSocketServ.Handle())); |
|
229 TInt connPtr = REINTERPRET_CAST(TInt, &iConnection); |
|
230 connInfo.SetPropertyL(iHttpSession.StringPool().StringF( |
|
231 HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal(connPtr)); |
|
232 } |
|
233 |
|
234 //Add proxy support |
|
235 TRAP_IGNORE(LoadProxyLibraryL(aAPNId)); |
|
236 |
|
237 // Try to load the customiser plugin, which enables customisation |
|
238 // of the loaded filters and headers. |
|
239 /* LoadCustomiserLibrary(); |
|
240 if ( iCustomiser ) |
|
241 { |
|
242 iCustomiser->CustomiseFiltersL(iHttpSession); |
|
243 } */ |
|
244 } |
|
245 |
|
246 //_LIT(KHttpClientCustomiserPath, "MIDP2HTTPClientCustomiser.dll"); |
|
247 |
|
248 //typedef MHttpClientCustomiser* (*GetCustomiser)(void); |
|
249 |
|
250 /*void HttpSessionClient::LoadCustomiserLibrary() |
|
251 { |
|
252 TInt err = iCustomiserLib.Load(KHttpClientCustomiserPath); |
|
253 if ( KErrNone == err ) |
|
254 { |
|
255 iCustomiser = reinterpret_cast<GetCustomiser>(iCustomiserLib.Lookup(1))(); |
|
256 } |
|
257 |
|
258 }*/ |
|
259 |
|
260 void HttpSessionClient::LoadProxyLibraryL(TUint32 /*aAPNId*/) |
|
261 { |
|
262 iHttpSession.StringPool().OpenL(HttpFilterCommonStringsExt::GetTable()); |
|
263 CHttpFilterProxyInterface::InstallFilterL(iHttpSession) ; |
|
264 } |
|
265 |
|
266 HttpSessionClient::~HttpSessionClient() |
|
267 { |
|
268 iHttpSession.Close(); |
|
269 iConnection.Close(); |
|
270 iSocketServ.Close(); |
|
271 |
|
272 /* if ( iCustomiser ) |
|
273 { |
|
274 delete iCustomiser; |
|
275 iCustomiser = NULL; |
|
276 iCustomiserLib.Close(); |
|
277 }*/ |
|
278 } |
|
279 |
|
280 /* RStringPool HttpSessionClient::StringPool() const |
|
281 { |
|
282 return iHttpSession.StringPool(); |
|
283 } |
|
284 */ |
|
285 /*void HttpSessionClient::CustomiseHeadersL(RHTTPHeaders &aHeaders) |
|
286 { |
|
287 if ( iCustomiser ) |
|
288 { |
|
289 iCustomiser->CustomiseHeadersL(iHttpSession, aHeaders); |
|
290 } |
|
291 }*/ |
|
292 |
|
293 void HttpSessionClient::RestartConnection() |
|
294 { |
|
295 LOG(ESOCKET,EInfo,"+HttpSessionClient::RestartConnection12 + "); |
|
296 iConnection.Close(); |
|
297 TInt ret = iConnection.Open(iSocketServ); |
|
298 |
|
299 TCommSnapPref connPref; |
|
300 if (iApnId!=-1) |
|
301 connPref.SetSnap(iApnId); |
|
302 ret = iConnection.Start(connPref); |
|
303 LOG(ESOCKET,EInfo,"+HttpSessionClient::RestartConnection + "); |
|
304 |
|
305 } |