|
1 /* |
|
2 * Copyright (c) 2003 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: Proxy filter |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <http.h> |
|
22 #include <es_sock.h> |
|
23 #include <cdbstore.h> |
|
24 #include <commdbconnpref.h> |
|
25 |
|
26 // User Includes |
|
27 #include "httpfilterproxy.h" |
|
28 #include "httpfiltercommonstringsext.h" |
|
29 |
|
30 // EXTERNAL DATA STRUCTURES |
|
31 |
|
32 // EXTERNAL FUNCTION PROTOTYPES |
|
33 void PanicHttpFiltersProxy(TInt aErr = 0); |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt KProxyOrderOffset = 20; |
|
37 // MACROS |
|
38 |
|
39 // LOCAL CONSTANTS AND MACROS |
|
40 |
|
41 // MODULE DATA STRUCTURES |
|
42 |
|
43 // LOCAL FUNCTION PROTOTYPES |
|
44 |
|
45 // FORWARD DECLARATIONS |
|
46 |
|
47 // ============================= LOCAL FUNCTIONS =============================== |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // LocalHostCheckL |
|
51 // If the host is a local host, then remove the proxy property. Returns ETrue |
|
52 // if the transaction request URI was for a localhost. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 TBool LocalHostCheckL(RHTTPTransaction& aTransaction, RStringPool& aStringPool) |
|
56 { |
|
57 _LIT8(KLoopbackIPv4Url, "http://127.0.0.1"); |
|
58 |
|
59 RHTTPRequest request = aTransaction.Request(); |
|
60 TUriC8 uri = request.URI(); |
|
61 |
|
62 TUriParser8 parserLoopBack; |
|
63 parserLoopBack.Parse(KLoopbackIPv4Url()); |
|
64 TInt match = parserLoopBack.Compare(uri, EUriHost); |
|
65 |
|
66 if (KErrNone != match) |
|
67 { |
|
68 _LIT8(KLocalHostUrl, "http://localhost"); |
|
69 |
|
70 // try another compare - compare against the "localhost". |
|
71 TUriParser8 parserLocalHost; |
|
72 parserLocalHost.Parse(KLocalHostUrl()); |
|
73 match = parserLocalHost.Compare(uri, EUriHost); |
|
74 |
|
75 if (KErrNone == match) |
|
76 { |
|
77 _LIT8(KLoopbackIPv4, "127.0.0.1"); |
|
78 |
|
79 // "localhost" resolves to "::1", manually, replace with "127.0.0.1" |
|
80 CUri8* newUri = CUri8::NewLC(uri); |
|
81 newUri->SetComponentL(KLoopbackIPv4(), EUriHost); |
|
82 request.SetURIL(newUri->Uri()); |
|
83 CleanupStack::PopAndDestroy(newUri); |
|
84 } |
|
85 } |
|
86 |
|
87 if (KErrNone == match) |
|
88 { |
|
89 // request is for localhost, explicitly state that this transaction |
|
90 // must not be sent to proxy. |
|
91 RStringF proxyUsageStrF = aStringPool.StringF(HTTP::EProxyUsage, |
|
92 RHTTPSession::GetTable()); |
|
93 |
|
94 RStringF dontUseProxyStrF = aStringPool.StringF(HTTP::EDoNotUseProxy, |
|
95 RHTTPSession::GetTable()); |
|
96 |
|
97 aTransaction.PropertySet().RemoveProperty(proxyUsageStrF); |
|
98 aTransaction.PropertySet().SetPropertyL(proxyUsageStrF, dontUseProxyStrF); |
|
99 |
|
100 //RStringF proxyAddrStrF = aStringPool.StringF(HTTP::EProxyAddress, |
|
101 // RHTTPSession::GetTable()); |
|
102 |
|
103 //aTransaction.PropertySet().RemoveProperty(proxyAddrStrF); |
|
104 return ETrue; |
|
105 } |
|
106 return EFalse; |
|
107 } |
|
108 |
|
109 // ============================ MEMBER FUNCTIONS =============================== |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CHttpFilterProxy::CHttpFilterProxy |
|
113 // C++ default constructor can NOT contain any code, that |
|
114 // might leave. |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 CHttpFilterProxy::CHttpFilterProxy(RHTTPSession* aSession) |
|
118 { |
|
119 __ASSERT_DEBUG(aSession != NULL, PanicHttpFiltersProxy()); |
|
120 iSession = aSession; |
|
121 } |
|
122 |
|
123 |
|
124 // ------------------------------------------------------------------------------------------ |
|
125 // CHttpFilterProxy::ConstructL |
|
126 // Symbian 2nd phase constructor can leave. |
|
127 // ------------------------------------------------------------------------------------------ |
|
128 // |
|
129 void CHttpFilterProxy::ConstructL() |
|
130 { |
|
131 iStringPool = iSession->StringPool(); |
|
132 iConnInfo = iSession->ConnectionInfo(); |
|
133 |
|
134 // Added to fix panic when Proxy filter is used outside the browser initiated HTTP Framework. |
|
135 iSession->StringPool().OpenL(HttpFilterCommonStringsExt::GetTable()); |
|
136 |
|
137 // Register the filter for submit events, |
|
138 // Adds a filter to the session's filter queue. |
|
139 |
|
140 iSession->FilterCollection().AddFilterL(*this, // The filter to add |
|
141 THTTPEvent::ESubmit, // The event that triggers this filter |
|
142 RStringF(), // The header whose presence triggers this filter, or KNullDesC to trigger on any header |
|
143 KAnyStatusCode, // The status code that triggers this filter, or KAnyStatusCode to trigger on any status code |
|
144 ECache - KProxyOrderOffset,// The position of the filter in the queue |
|
145 iStringPool.StringF(HttpFilterCommonStringsExt::EProxyFilter,RHTTPSession::GetTable())); //The name of the filter to add |
|
146 |
|
147 // register for notification of KErrNotReady error codes |
|
148 // this allows us to re-start the connection if it fails |
|
149 iSession->FilterCollection().AddFilterL(*this, KErrNotReady, MHTTPFilter::ETidyUp -1, iStringPool.StringF(HttpFilterCommonStringsExt::EProxyFilter,RHTTPSession::GetTable())); |
|
150 } |
|
151 |
|
152 //--------------------------------------------------------------------------------------------- |
|
153 // Destructor |
|
154 //---------------------------------------------------------------------------------------------- |
|
155 // |
|
156 CHttpFilterProxy::~CHttpFilterProxy() |
|
157 { |
|
158 // Cleanup strings. |
|
159 iProxyAddress.Close(); |
|
160 iExceptions.Close(); |
|
161 |
|
162 /* |
|
163 // Closing RSocketServ is causing crash in SDK Applications. SDK Apps will have to close RSocketServ and RConnection after closing CHTTPSession. |
|
164 // It is not needed to close connection as soon as the CHttpConnectionManager close connection by |
|
165 // calling CHttpConnectionManager::CloseConnection() |
|
166 if(iFilterOwnsConnection) |
|
167 { |
|
168 // Close ESOCK handles |
|
169 iConnection.Close(); |
|
170 iSocketServ.Close(); |
|
171 } |
|
172 */ |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------------------------- |
|
176 // CHttpFilterProxy::InstallFilterL |
|
177 // Two-phased constructor. This function replaces NewL. |
|
178 // --------------------------------------------------------------------------------------------- |
|
179 // |
|
180 CHttpFilterProxy* CHttpFilterProxy::InstallFilterL(TAny* aSession) |
|
181 { |
|
182 __ASSERT_DEBUG(aSession != NULL, PanicHttpFiltersProxy()); |
|
183 RHTTPSession* session = REINTERPRET_CAST(RHTTPSession*, aSession); |
|
184 CHttpFilterProxy* filter = new (ELeave) CHttpFilterProxy( session ); |
|
185 CleanupStack::PushL(filter); |
|
186 filter->ConstructL(); |
|
187 CleanupStack::Pop(filter); |
|
188 return filter; |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------------------------- |
|
192 // CHttpFilterProxy::MHFLoad |
|
193 // Called when the filter is being added to the session's filter queue. |
|
194 // --------------------------------------------------------------------------------------------- |
|
195 // |
|
196 void CHttpFilterProxy::MHFLoad(RHTTPSession, THTTPFilterHandle) |
|
197 { |
|
198 ++iLoadCount; |
|
199 } |
|
200 |
|
201 // ---------------------------------------------------------------------------------------------- |
|
202 // CHttpFilterProxy::MHFUnload |
|
203 // Called when the filter is being removed from a session's filter queue. |
|
204 // ---------------------------------------------------------------------------------------------- |
|
205 // |
|
206 void CHttpFilterProxy::MHFUnload(RHTTPSession /*aSession*/, THTTPFilterHandle /*aFilterHandler*/) |
|
207 { |
|
208 __ASSERT_DEBUG(iLoadCount >= 0, PanicHttpFiltersProxy()); |
|
209 if (--iLoadCount) |
|
210 { |
|
211 return; |
|
212 } |
|
213 delete this; |
|
214 } |
|
215 |
|
216 // ------------------------------------------------------------------------------------------------ |
|
217 // CHttpFilterProxy::MHFRunL |
|
218 // Process a transaction event. |
|
219 // ------------------------------------------------------------------------------------------------ |
|
220 // |
|
221 void CHttpFilterProxy::MHFRunL(RHTTPTransaction aTransaction, |
|
222 const THTTPEvent& aEvent) |
|
223 { |
|
224 switch(aEvent.iStatus) |
|
225 { |
|
226 case THTTPEvent::ESubmit: |
|
227 { |
|
228 if (LocalHostCheckL(aTransaction, iStringPool)) |
|
229 { |
|
230 return; |
|
231 } |
|
232 SetProxyL(aTransaction); |
|
233 } |
|
234 break; |
|
235 |
|
236 case KErrNotReady: |
|
237 { |
|
238 if (LocalHostCheckL(aTransaction, iStringPool)) |
|
239 { |
|
240 return; |
|
241 } |
|
242 if(iFilterOwnsConnection) |
|
243 { |
|
244 // we must re-start the RConnection |
|
245 TInt err = iConnection.Start(); |
|
246 if (err == KErrAlreadyExists) |
|
247 { |
|
248 // the KErrNotReady must have come from elsewhere |
|
249 return; |
|
250 } |
|
251 |
|
252 User::LeaveIfError(err); |
|
253 |
|
254 // re-submit the transaction |
|
255 aTransaction.Cancel(); |
|
256 aTransaction.SubmitL(); |
|
257 } |
|
258 break; |
|
259 } |
|
260 |
|
261 default: |
|
262 break; |
|
263 } |
|
264 |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CHttpFilterProxy::MHFRunError |
|
269 // Process an error that occured while processing the transaction. |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 TInt CHttpFilterProxy::MHFRunError(TInt /*aError*/, |
|
273 RHTTPTransaction aTransaction, |
|
274 const THTTPEvent& /*aEvent*/) |
|
275 { |
|
276 // Cleanup strings. |
|
277 iProxyAddress.Close(); |
|
278 iExceptions.Close(); |
|
279 aTransaction.Fail(); |
|
280 return KErrNone; |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CHttpFilterProxy::MHFSessionRunL |
|
285 // Process a session event. |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 void CHttpFilterProxy::MHFSessionRunL(const THTTPSessionEvent& /*aEvent*/) |
|
289 { |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CHttpFilterProxy::MHFSessionRunError |
|
294 // Called when MHFRunL leaves from a session event. |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 TInt CHttpFilterProxy::MHFSessionRunError(TInt aError, const THTTPSessionEvent& /*aEvent*/) |
|
298 { |
|
299 return aError; |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CHttpFilterProxy::SetProxyL |
|
304 // Function to handle Submit events. |
|
305 // Set proxy properties (EUseProxy and EProxyAddress) in order to get connected throught |
|
306 // proxy when a new HTTP session will be in effect. The Proxy data will be taken from |
|
307 // the CommDb if a new connection has been used. If a proxy property has already been |
|
308 // set by a higher filter or by the client, then those settings are preferred over |
|
309 // CommsDB. |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 void CHttpFilterProxy::SetProxyL(const RHTTPTransaction aTransaction) |
|
313 { |
|
314 THTTPHdrVal isNewConn, proxyAddress; |
|
315 |
|
316 // If connection has been disconnected the user could change Access Point, so let's |
|
317 // check if a new connection has been used. |
|
318 TBool ret = iConnInfo.Property (iStringPool.StringF(HttpFilterCommonStringsExt::EHttpNewConnFlag, |
|
319 HttpFilterCommonStringsExt::GetTable()), isNewConn); |
|
320 |
|
321 if (ret && isNewConn.Type() == THTTPHdrVal::KTIntVal && (isNewConn.Int() == 1)) |
|
322 { |
|
323 iUsage = EFalse; |
|
324 // Read proxy info from the CommDB |
|
325 ReadProxyInfoL(iStringPool, |
|
326 iUsage, |
|
327 iProxyAddress, |
|
328 iExceptions); |
|
329 } |
|
330 else |
|
331 { |
|
332 TBool useProxy( ETrue ); |
|
333 THTTPHdrVal proxyUsageVal; |
|
334 |
|
335 // Is the property for proxy usage set? |
|
336 TBool hasUsageValue = iConnInfo.Property(iStringPool.StringF(HTTP::EProxyUsage, |
|
337 RHTTPSession::GetTable()), proxyUsageVal); |
|
338 |
|
339 // If the property is set, is it EUseProxy |
|
340 if (hasUsageValue) |
|
341 { |
|
342 useProxy = ( proxyUsageVal.StrF().Index(RHTTPSession::GetTable()) == HTTP::EUseProxy); |
|
343 } |
|
344 |
|
345 // Use proxy if the property value is EUseProxy or no property is set. |
|
346 if (useProxy || !hasUsageValue) |
|
347 { |
|
348 THTTPHdrVal proxyAddressVal; |
|
349 TBool hasValue = iConnInfo.Property(iStringPool.StringF(HTTP::EProxyAddress, |
|
350 RHTTPSession::GetTable()), proxyAddressVal); |
|
351 if (!hasValue) |
|
352 { |
|
353 // The proxyAddress has not been set, so Read proxy info from the CommDB |
|
354 ReadProxyInfoL(iStringPool, |
|
355 iUsage, |
|
356 iProxyAddress, |
|
357 iExceptions); |
|
358 |
|
359 } |
|
360 else |
|
361 { |
|
362 // Now get the proxy address... |
|
363 iProxyAddress = proxyAddressVal.StrF().Copy(); |
|
364 iUsage = ETrue; |
|
365 } |
|
366 } |
|
367 // } |
|
368 } |
|
369 |
|
370 // We should not use proxy if the uri matches to one of exceptions from the exception list |
|
371 // In this case the Origing server will be used |
|
372 |
|
373 ExcptionsCompare(aTransaction); |
|
374 |
|
375 // Respect proxy settings already defined by client or higher HTTP filter |
|
376 THTTPHdrVal proxyUsage; // Check if property present or not present, not the value. |
|
377 if ( !iConnInfo.Property(iStringPool.StringF(HTTP::EProxyUsage, |
|
378 RHTTPSession::GetTable()), proxyUsage)) |
|
379 { |
|
380 |
|
381 // Set the proxy address and proxy Usage |
|
382 proxyAddress = THTTPHdrVal(iProxyAddress); |
|
383 |
|
384 iConnInfo.RemoveProperty(iStringPool.StringF(HTTP::EProxyAddress, |
|
385 RHTTPSession::GetTable())); |
|
386 iConnInfo.SetPropertyL(iStringPool.StringF(HTTP::EProxyAddress, |
|
387 RHTTPSession::GetTable()), proxyAddress); |
|
388 |
|
389 iConnInfo.RemoveProperty(iStringPool.StringF(HTTP::EProxyUsage, |
|
390 RHTTPSession::GetTable())); |
|
391 if (iUsage) |
|
392 { |
|
393 iConnInfo.SetPropertyL(iStringPool.StringF(HTTP::EProxyUsage, |
|
394 RHTTPSession::GetTable()), iStringPool.StringF(HTTP::EUseProxy, |
|
395 RHTTPSession::GetTable())); |
|
396 } |
|
397 else |
|
398 { |
|
399 iConnInfo.SetPropertyL(iStringPool.StringF(HTTP::EProxyUsage, |
|
400 RHTTPSession::GetTable()), iStringPool.StringF(HTTP::EDoNotUseProxy, |
|
401 RHTTPSession::GetTable())); |
|
402 } |
|
403 |
|
404 } |
|
405 |
|
406 |
|
407 // Cleanup strings. |
|
408 iProxyAddress.Close(); |
|
409 iExceptions.Close(); |
|
410 } |
|
411 |
|
412 |
|
413 // ----------------------------------------------------------------------------- |
|
414 // CHttpFilterProxy::ReadProxyInfoL |
|
415 // Purpose: Reads the Proxy information from the comms database. |
|
416 // Gives the Proxy usage, a proxy address (<proxy name>:<proxy port>), |
|
417 // and proxy exceptions through the output arguments. |
|
418 // ----------------------------------------------------------------------------- |
|
419 // |
|
420 void CHttpFilterProxy::ReadProxyInfoL(const RStringPool aStringPool, |
|
421 TBool& aUsage, |
|
422 RStringF& aProxyAddress, |
|
423 RStringF& aExceptions) |
|
424 |
|
425 { |
|
426 // Let's find Internet Access point ID (ServiceId) in use from the RConnection associated with the HTTP framework |
|
427 THTTPHdrVal connValue; |
|
428 TUint32 serviceId; |
|
429 TUint pushCount = 0; |
|
430 RConnection* connPtr = NULL; |
|
431 THTTPHdrVal iapId; |
|
432 TCommDbConnPref pref; |
|
433 TBool hasValue = iConnInfo.Property (aStringPool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), |
|
434 connValue); |
|
435 |
|
436 if (hasValue && connValue.Type() == THTTPHdrVal::KTIntVal) |
|
437 { |
|
438 connPtr = REINTERPRET_CAST(RConnection*, connValue.Int()); |
|
439 } |
|
440 else |
|
441 { |
|
442 // Connect to ESOCK and open connection handle |
|
443 User::LeaveIfError(iSocketServ.Connect()); |
|
444 User::LeaveIfError(iConnection.Open(iSocketServ)); |
|
445 |
|
446 TBool ret = iConnInfo.Property (aStringPool.StringF(HttpFilterCommonStringsExt::EAccessPointID, HttpFilterCommonStringsExt::GetTable()), |
|
447 iapId); |
|
448 if (ret && (iapId.Type() == THTTPHdrVal::KTIntVal) && (iapId.Int() != 0) ) |
|
449 { |
|
450 pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
451 pref.SetIapId( iapId.Int() ); |
|
452 //pref.SetBearerSet( ECommDbBearerGPRS ); |
|
453 pref.SetDirection(ECommDbConnectionDirectionOutgoing); |
|
454 TInt err = iConnection.Start(pref); |
|
455 if ( err != KErrNone ) |
|
456 User::LeaveIfError(iConnection.Start()); |
|
457 } |
|
458 else |
|
459 { |
|
460 // start the connection - note that this thread will be blocked until the connection is established. |
|
461 User::LeaveIfError(iConnection.Start()); |
|
462 } |
|
463 |
|
464 connPtr = &iConnection; |
|
465 |
|
466 // set the ESOCK handles as session properties after successful connection |
|
467 iConnInfo.SetPropertyL(aStringPool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable()), iSocketServ.Handle()); |
|
468 iConnInfo.SetPropertyL(aStringPool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), reinterpret_cast<TInt>(&iConnection)); |
|
469 |
|
470 iFilterOwnsConnection = ETrue; |
|
471 } |
|
472 |
|
473 // Retrieve the service Id from the RConnection ; "<table name>/<field name> |
|
474 User::LeaveIfError(connPtr->GetIntSetting(_L("IAP\\IAPService"), serviceId)); |
|
475 |
|
476 // Retrieve the service Type from the RConnection |
|
477 HBufC* serviceType16 = HBufC::NewL(KCommsDbSvrMaxFieldLength); |
|
478 CleanupStack::PushL(serviceType16); |
|
479 pushCount++; |
|
480 TPtr serviceTypePtr16 = serviceType16->Des(); |
|
481 User::LeaveIfError(connPtr->GetDesSetting(_L("IAP\\IAPServiceType"), serviceTypePtr16)); |
|
482 |
|
483 // Open the Comms DB with the IAP style |
|
484 CCommsDatabase* db=CCommsDatabase::NewL(EDatabaseTypeUnspecified); |
|
485 CleanupStack::PushL(db); |
|
486 pushCount++; |
|
487 |
|
488 // Opens a view on records in the Proxies table with a specified range of service types and service IDs. |
|
489 // Proxies records are included that have matching service types and IDs. |
|
490 // When the use of the view object is complete, it should be popped from the cleanup stack, and deleted. |
|
491 CCommsDbTableView* pView = db->OpenViewOnProxyRecordLC(serviceId, serviceTypePtr16); |
|
492 |
|
493 pushCount++; |
|
494 TInt err = pView->GotoFirstRecord(); |
|
495 aUsage = ETrue; |
|
496 // if there is some other DB error. |
|
497 if ( err != KErrNotFound && err != KErrNone ) |
|
498 { |
|
499 User::LeaveIfError( err ); |
|
500 } |
|
501 if ( err == KErrNotFound ) |
|
502 {// setting to EFalse because proxy table view does not exisit, was not created during Access point creation? |
|
503 aUsage = EFalse; |
|
504 } |
|
505 else |
|
506 // no need to keep going as not Proxy will be used. |
|
507 { |
|
508 // Read the proxy usage flag from the selected Proxy record. |
|
509 pView->ReadBoolL(TPtrC(PROXY_USE_PROXY_SERVER), aUsage); |
|
510 |
|
511 // COntinue only if the proxy usage flag is set |
|
512 if (aUsage) |
|
513 { |
|
514 // Read the server name specified in the selected Proxy record. |
|
515 // The proxyAddress will be build based on the serverName and the port number |
|
516 // separated with ':' |
|
517 HBufC* serverName = pView->ReadLongTextLC(TPtrC(PROXY_SERVER_NAME)); |
|
518 pushCount++; |
|
519 TPtr serverNamePtr16 = serverName->Des(); |
|
520 serverNamePtr16.Trim(); |
|
521 |
|
522 // Continue only if we have a proxy name |
|
523 if (serverNamePtr16.Length() > 0 && serverNamePtr16.Ptr() != NULL) |
|
524 { |
|
525 // Read the port number specified in the selected Proxy record |
|
526 TUint32 portNumber = 8080; // default port number |
|
527 TInt length = 1; // add 1 for the separator ':' |
|
528 pView->ReadUintL(TPtrC(PROXY_PORT_NUMBER), portNumber); |
|
529 // calculate the length of portNumber |
|
530 |
|
531 if (portNumber == 0) |
|
532 { |
|
533 portNumber = 8080; |
|
534 } |
|
535 |
|
536 TUint32 portNumSave = portNumber; |
|
537 while (portNumSave > 0) |
|
538 { |
|
539 portNumSave = portNumSave/10; |
|
540 length++; |
|
541 } |
|
542 // convert number to string & add to the server name. We should get <serverName1>:<port number> |
|
543 HBufC8* proxyAddress8 = HBufC8::NewL(serverNamePtr16.Length() + length); |
|
544 CleanupStack::PushL(proxyAddress8); |
|
545 pushCount++; |
|
546 TPtr8 proxyAddressPtr8 = proxyAddress8->Des(); |
|
547 proxyAddressPtr8.Copy(serverNamePtr16); |
|
548 _LIT(KSeparator, ":"); |
|
549 proxyAddressPtr8.Append(KSeparator); |
|
550 proxyAddressPtr8.AppendNum((TInt)portNumber); |
|
551 |
|
552 // Set gateway as a service number - this is the proxy address |
|
553 aProxyAddress = aStringPool.OpenFStringL(proxyAddressPtr8); |
|
554 |
|
555 // Read the server name specified in the selected Proxy record. |
|
556 HBufC* exceptions16 = pView->ReadLongTextLC(TPtrC(PROXY_EXCEPTIONS)); |
|
557 pushCount++; |
|
558 TPtr exceptionsPtr16 = exceptions16->Des(); |
|
559 // Copy to 8-bits... |
|
560 HBufC8* exceptions8 = HBufC8::NewL(exceptionsPtr16.Length()); |
|
561 CleanupStack::PushL(exceptions8); |
|
562 pushCount++; |
|
563 TPtr8 exceptionsPtr8 = exceptions8->Des(); |
|
564 exceptionsPtr8.Copy(exceptionsPtr16); |
|
565 |
|
566 // Set gateway as a service number - this is the proxy address |
|
567 aExceptions = aStringPool.OpenFStringL(exceptionsPtr8); |
|
568 } |
|
569 else |
|
570 { |
|
571 aUsage = EFalse; |
|
572 } |
|
573 } |
|
574 } |
|
575 // All done - clean up |
|
576 CleanupStack::PopAndDestroy(pushCount); //pView, serverType16, db, serverName, proxyAddress8, exceptions8 exceptions16 |
|
577 } |
|
578 |
|
579 //--------------------------------------------------------------------------------- |
|
580 // |
|
581 // Get exception from the list of exceptions |
|
582 // Returns ETrue if there is at least one exception in the list. |
|
583 // Returns EFalse if list of exceptions is empty or there is no exceptions in the list any more. |
|
584 //--------------------------------------------------------------------------------- |
|
585 TBool CHttpFilterProxy::GetException(TPtr8& aException,TInt& aStartIndex) |
|
586 { |
|
587 TBool done; |
|
588 TPtrC8 exceptionsDesC = iExceptions.DesC(); |
|
589 TPtr8 exceptionsDes((TUint8*)exceptionsDesC.Ptr(), exceptionsDesC.Length(),exceptionsDesC.Length()); |
|
590 |
|
591 exceptionsDes.TrimAll(); |
|
592 // get part of string starting from aStartIndex. aStartIndex =0 when it is called the first time. |
|
593 TPtrC8 desPtr = exceptionsDes.Mid(aStartIndex); |
|
594 |
|
595 //The offset of the exception position from the beginning of the exception list |
|
596 const TChar separator(';'); |
|
597 TInt position = desPtr.Locate(separator); |
|
598 if (position != KErrNotFound) |
|
599 { |
|
600 // Extracts a portion of the data starting from the beggining |
|
601 // Get the rest of the descriptor without the separator that we have found |
|
602 aException.Set((unsigned char*)desPtr.Ptr(), position, position); |
|
603 aStartIndex = position + 1; |
|
604 done = ETrue; |
|
605 } |
|
606 else |
|
607 { |
|
608 aException.Set((unsigned char*)desPtr.Ptr(), desPtr.Length(), desPtr.Length()); |
|
609 done = EFalse; |
|
610 } |
|
611 return done; |
|
612 } |
|
613 |
|
614 // ----------------------------------------------------------------------------- |
|
615 // CHttpFilterProxy::ExcptionsCompare |
|
616 // Compare each exception from the exception list against the current uri. |
|
617 // ----------------------------------------------------------------------------- |
|
618 // |
|
619 void CHttpFilterProxy::ExcptionsCompare(const RHTTPTransaction aTransaction) |
|
620 { |
|
621 if (iUsage) |
|
622 { |
|
623 TBool isFound = ETrue; |
|
624 TInt index = 0; |
|
625 TInt loopCount = 0; |
|
626 TPtr8 exception (NULL, 0,0); |
|
627 // Let's get uri for this transaction to comapre the current uri with an exception. |
|
628 // If the current uri has an exception for proxy set proxy usage to EDoNotUseProxy. |
|
629 RHTTPRequest req = aTransaction.Request(); |
|
630 TUriC8 originalUri = req.URI(); |
|
631 const TDesC8& uriHost = originalUri.UriDes(); |
|
632 |
|
633 TPtrC8 exceptionsDes = iExceptions.DesC(); |
|
634 if (exceptionsDes.Length() != 0) |
|
635 { |
|
636 // at least one exception has been found in the list of exceptions |
|
637 while (isFound) |
|
638 { |
|
639 loopCount++; |
|
640 isFound = GetException(exception, index); |
|
641 if (exception.Compare(uriHost) == NULL) |
|
642 { |
|
643 iUsage = EFalse; |
|
644 isFound = EFalse; |
|
645 } |
|
646 } //while |
|
647 } |
|
648 } |
|
649 } |
|
650 |
|
651 // End of File |