|
1 /* |
|
2 * Copyright (c) 2002-2006 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 // INCLUDE FILES |
|
29 #include <SenServiceConnection.h> |
|
30 #include "senhttpchanneltransportplugin.h" |
|
31 #include "senhttpchannelimpl.h" |
|
32 #include "senhttpsyncrequester.h" |
|
33 #include "SenXmlUtils.h" |
|
34 #include "SenIdentityProvider.h" |
|
35 #include "senwspattern.h" |
|
36 #include "SenFragment.h" |
|
37 #include "SenElement.h" |
|
38 #include "sendebug.h" |
|
39 #include "MSenProperty.h" |
|
40 #include "SenHttpTransportProperties.h" // Utils\inc |
|
41 #include "sentransportcontext.h" |
|
42 #include "senlayeredhttptransportproperties.h" // internal Framework\inc |
|
43 #include "msenmessagecontext.h" |
|
44 #include "MSenMessage.h" |
|
45 #include "SenSoapMessage2.h" |
|
46 #include "RSenDocument.h" |
|
47 #include "SenParser.h" |
|
48 #include "senservicesession.h" |
|
49 #include "senlogger.h" |
|
50 #include "senclientsession.h" |
|
51 #include <xmlengchunkcontainer.h> |
|
52 #include <xmlengfilecontainer.h> |
|
53 #include <xmlengserializer.h> |
|
54 |
|
55 |
|
56 |
|
57 namespace |
|
58 { |
|
59 /* Fix for compiler warning #177-D |
|
60 #ifdef _SENDEBUG |
|
61 // logging constants |
|
62 _LIT(KLogDir, "SenHttpChannelObserver"); |
|
63 _LIT(KLogFile, "SenHttpChannelObserver.log"); |
|
64 #endif*/ |
|
65 |
|
66 _LIT8(KContentType, "text/xml; charset=UTF-8"); |
|
67 } |
|
68 |
|
69 |
|
70 |
|
71 // Create instance of concrete ECOM interface implementation |
|
72 //CSenHttpChannelTransportPlugin* CSenHttpChannelTransportPlugin::NewL( |
|
73 // MSenCoreServiceManager& aServiceManager) |
|
74 // { |
|
75 // CSenHttpChannelTransportPlugin* pNew = CSenHttpChannelTransportPlugin::NewLC(aServiceManager); |
|
76 |
|
77 CSenHttpChannelTransportPlugin* CSenHttpChannelTransportPlugin::NewL(CSenTransportContext* apCtx) |
|
78 { |
|
79 CSenHttpChannelTransportPlugin* pNew = CSenHttpChannelTransportPlugin::NewLC(apCtx); |
|
80 CleanupStack::Pop(); |
|
81 return pNew; |
|
82 } |
|
83 |
|
84 CSenHttpChannelTransportPlugin* CSenHttpChannelTransportPlugin::NewLC(CSenTransportContext* apCtx) |
|
85 { |
|
86 if(apCtx == NULL) |
|
87 { |
|
88 User::Leave( KErrArgument ); |
|
89 } |
|
90 |
|
91 MSenCoreServiceManager& core = apCtx->GetCoreL(); |
|
92 CSenHttpChannelTransportPlugin* pNew = new (ELeave) CSenHttpChannelTransportPlugin(apCtx, core); |
|
93 CleanupStack::PushL(pNew); |
|
94 pNew->ConstructL(); |
|
95 return pNew; |
|
96 } |
|
97 |
|
98 CSenHttpChannelTransportPlugin::CSenHttpChannelTransportPlugin(CSenTransportContext* apCtx, |
|
99 MSenCoreServiceManager& aCore) |
|
100 : CSenTransport(apCtx), |
|
101 iServiceManager(aCore), |
|
102 iRequester(NULL), |
|
103 iHttpChannel(NULL), |
|
104 iProperties(NULL), |
|
105 iConsumerMap(EFalse, ETrue), |
|
106 iSessionMap(EFalse, EFalse), // iConsumerMap deletes the txnIds (using same "new reserved" TInt here!) |
|
107 iStatusCode(0) |
|
108 { |
|
109 } |
|
110 |
|
111 CSenHttpChannelTransportPlugin::~CSenHttpChannelTransportPlugin() |
|
112 { |
|
113 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::~CSenHttpChannelTransportPlugin()"); |
|
114 iConsumerMap.Reset(); // deletes the txnIds! |
|
115 iSessionMap.Reset(); |
|
116 |
|
117 delete iHttpChannel; |
|
118 delete iRequester; |
|
119 delete iProperties; |
|
120 |
|
121 delete ipCtx; |
|
122 ipCtx = NULL; |
|
123 |
|
124 TLSLOG(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,(_L("Got last data chunk."))); |
|
125 TLSLOG_CLOSE(KSenHttpChannelObserverLogChannelBase); |
|
126 } |
|
127 |
|
128 void CSenHttpChannelTransportPlugin::ConstructL() |
|
129 { |
|
130 TLSLOG_OPEN(KSenHttpChannelObserverLogChannelBase,KSenHttpChannelObserverLogLevel,KSenHttpChannelObserverLogDir,KSenHttpChannelObserverLogFile ); |
|
131 // Open connection to the file logger server |
|
132 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ConstructL(): log file opened."); |
|
133 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ConstructL - Version 2 [2006-05-09]"); |
|
134 |
|
135 if( ipCtx ) |
|
136 { |
|
137 // Attempt to find pre-defined IAP ID from transport context |
|
138 CSenWSDescription& initializer = ipCtx->GetInitializerL(); |
|
139 |
|
140 |
|
141 TUint32 predefinedIapId; |
|
142 if( initializer.DescriptionClassType() == MSenServiceDescription::EWSPattern ) |
|
143 { |
|
144 // Check if <ConsumerPolicy/> was defined in SC initializer (constructor argument) |
|
145 // and if IAP was predefined |
|
146 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- Initializer XML SD type is: EWSPattern."); |
|
147 CSenWSPattern* pConsumerPolicy = (CSenWSPattern*)&initializer; |
|
148 |
|
149 TInt retVal = pConsumerPolicy->ConsumerIapId( predefinedIapId ); |
|
150 if( retVal==KErrNone && predefinedIapId < (TUint)KErrNotFound ) // IAP ID must be 0...INT_MAX, since (TUInt)KErrNotFound == INT_MAX+1 |
|
151 { |
|
152 iHttpChannel = CSenHttpChannelImpl::NewL(iServiceManager, predefinedIapId); |
|
153 } |
|
154 else |
|
155 { |
|
156 // Check if <ProviderPolicy/> was defined in SC initializer (constructor argument) |
|
157 // and if IAP was predefined |
|
158 retVal = initializer.IapId( predefinedIapId ); |
|
159 if( retVal==KErrNone && predefinedIapId < (TUint)KErrNotFound ) |
|
160 { |
|
161 iHttpChannel = CSenHttpChannelImpl::NewL(iServiceManager, predefinedIapId); |
|
162 } |
|
163 } |
|
164 } |
|
165 else if( initializer.DescriptionClassType() == MSenServiceDescription::EWSDescription ) |
|
166 { |
|
167 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- Initializer XML SD type is EWSDescription."); |
|
168 TUint32 predefinedIapId(0); |
|
169 TInt retVal = initializer.IapId( predefinedIapId ); |
|
170 if( retVal==KErrNone && predefinedIapId < (TUint)KErrNotFound ) // IAP ID must be 0...INT_MAX, since (TUInt)KErrNotFound == INT_MAX+1 |
|
171 { |
|
172 iHttpChannel = CSenHttpChannelImpl::NewL(iServiceManager, predefinedIapId); |
|
173 } |
|
174 } |
|
175 |
|
176 if( !iHttpChannel ) |
|
177 { |
|
178 // Check if **the service session** contains <ProviderPolicy/> |
|
179 CSenServiceSession* pSession = (CSenServiceSession*)ipCtx->GetSession(); |
|
180 if( pSession ) |
|
181 { |
|
182 // Check if IAP was predefined / try to figure out if IAP ID was |
|
183 // set in <ProviderPolicy/> of this session (XML SD): |
|
184 TInt retVal = pSession->IapId( predefinedIapId ); |
|
185 if( retVal == KErrNone && predefinedIapId < (TUint)KErrNotFound ) // IAP ID must be 0...INT_MAX, since (TUInt)KErrNotFound == INT_MAX+1 |
|
186 { |
|
187 iHttpChannel = CSenHttpChannelImpl::NewL(iServiceManager, predefinedIapId); |
|
188 } |
|
189 } |
|
190 } |
|
191 } |
|
192 if( !iHttpChannel ) |
|
193 { |
|
194 // IAP ID was not found from transport context |
|
195 iHttpChannel = CSenHttpChannelImpl::NewL( iServiceManager ); |
|
196 } |
|
197 |
|
198 iRequester = CSenHttpSyncRequester::NewL( iHttpChannel, this ); |
|
199 } |
|
200 |
|
201 // Messaging methods start: |
|
202 TInt CSenHttpChannelTransportPlugin::SubmitL(const TDesC8& aEndpoint, |
|
203 const TDesC8& aMessage, |
|
204 const TDesC8& aTransportProperties, |
|
205 HBufC8*& aResponse, |
|
206 MSenRemoteServiceConsumer& aConsumer ) |
|
207 { |
|
208 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::SubmitL:"); |
|
209 |
|
210 // Sanity check the endpoint |
|
211 if (aEndpoint.Length() <= 0) |
|
212 { |
|
213 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- No endpoint!"); |
|
214 return KErrSenNoEndpoint; |
|
215 } |
|
216 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("- Endpoint: %S"), &aEndpoint)); |
|
217 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMaxLogLevel,"- Message:"); |
|
218 TLSLOG_ALL(KSenHttpChannelObserverLogChannelBase,KMaxLogLevel,( aMessage )); |
|
219 |
|
220 CSenLayeredHttpTransportProperties& properties = LayeredPropertiesL(); |
|
221 properties.ReadFromL(aTransportProperties, MSenLayeredProperties::ESenMessageLayer); |
|
222 |
|
223 ApplyPropertiesL(); |
|
224 |
|
225 HBufC8* pRespContentType = NULL; |
|
226 |
|
227 // Uses HttpSyncRequester class: |
|
228 |
|
229 TInt statusCode(KErrNone); |
|
230 TInt leaveCode(KErrNone); |
|
231 TRAP( leaveCode, iRequester->SubmitL(aEndpoint, // endpoint |
|
232 properties, |
|
233 aMessage, // request body |
|
234 pRespContentType, // response content type |
|
235 aResponse, // response body |
|
236 statusCode); ) |
|
237 |
|
238 // Propagate data traffic counters to consumer |
|
239 |
|
240 aConsumer.SetDataTrafficDetails(iDetails); |
|
241 |
|
242 properties.ShrinkTo(MSenLayeredProperties::ESenConsumerSessionLayer); |
|
243 if(leaveCode!=KErrNone) |
|
244 { |
|
245 // SubmitL leaved, return leave code instead of status code |
|
246 statusCode = leaveCode; |
|
247 } |
|
248 delete pRespContentType; // not used currently |
|
249 return statusCode; |
|
250 } |
|
251 |
|
252 // async request |
|
253 TInt CSenHttpChannelTransportPlugin::SendL( const TDesC8& aEndpoint, |
|
254 const TDesC8& aMessage, |
|
255 const TDesC8& aTransportProperties, |
|
256 MSenServiceSession& aReplyTo, |
|
257 MSenRemoteServiceConsumer& aConsumer, // "adressee", could be CSenIdentifier |
|
258 TInt& aTxnId ) |
|
259 { |
|
260 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::SendL:"); |
|
261 |
|
262 // Sanity check the endpoint |
|
263 if (aEndpoint.Length() <= 0) |
|
264 { |
|
265 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- No endpoint!"); |
|
266 return KErrSenNoEndpoint; |
|
267 } |
|
268 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("- Endpoint: %S"), &aEndpoint)); |
|
269 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMaxLogLevel,"- Content:"); |
|
270 TLSLOG_ALL(KSenHttpChannelObserverLogChannelBase,KMaxLogLevel,(aMessage)); |
|
271 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMaxLogLevel,"- Properties:"); |
|
272 TLSLOG_ALL(KSenHttpChannelObserverLogChannelBase,KMaxLogLevel,(aTransportProperties)); |
|
273 |
|
274 CSenLayeredHttpTransportProperties& properties = LayeredPropertiesL(); |
|
275 properties.ReadFromL(aTransportProperties, MSenLayeredProperties::ESenMessageLayer); |
|
276 |
|
277 ApplyPropertiesL(); |
|
278 |
|
279 // Reset the status code to zero. Async callbacks may then later update iStatusCode. |
|
280 |
|
281 iStatusCode = 0; |
|
282 |
|
283 // Note: regardless of name, SubmitL() is an async method in HttpChannel class |
|
284 TInt* submitID = new (ELeave) TInt(KErrNone); |
|
285 CleanupStack::PushL(submitID); |
|
286 TInt leaveCode(KErrNone); |
|
287 |
|
288 |
|
289 CSenSoapEnvelope2* pSoapEnvelope2 = NULL; |
|
290 TInt err(KErrNone); |
|
291 MSenMessageContext* pMsgCtx = aConsumer.MessageContextByTxnIdL(aTxnId, err); |
|
292 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("- aConsumer.MessageContextByTxnIdL(%d) returned: %d"), aTxnId, err)); |
|
293 if( pMsgCtx ) |
|
294 { |
|
295 MSenMessage* pMessage = pMsgCtx->MessageL(); |
|
296 if( pMessage ) |
|
297 { |
|
298 if( pMessage->IsSafeToCast(MSenMessage::ESoapEnvelope2 )) |
|
299 { |
|
300 pSoapEnvelope2 = (CSenSoapEnvelope2*)pMessage; |
|
301 |
|
302 properties.SetPropertyL(KAcceptLocalName, KMimeAccept); |
|
303 |
|
304 TRAP( leaveCode, (*submitID) = iHttpChannel->SendL( *this, aEndpoint, *pSoapEnvelope2, properties ); ) |
|
305 |
|
306 } |
|
307 else if( pMessage->IsSafeToCast(MSenMessage::EAtomMessage )) |
|
308 { |
|
309 CSenAtomEntry* pAtomEntry = (CSenAtomEntry*)pMessage; |
|
310 |
|
311 TRAP( leaveCode, (*submitID) = iHttpChannel->SendL( *this, aEndpoint, *pAtomEntry, properties ); ) |
|
312 |
|
313 } |
|
314 |
|
315 else |
|
316 { |
|
317 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- MSenMessage type is: %d"), pMessage->Type())); |
|
318 TRAP( leaveCode, (*submitID) = iHttpChannel->SendL(*this, aEndpoint, aMessage, properties); ) |
|
319 } |
|
320 } |
|
321 else |
|
322 { |
|
323 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- MSenMessage arch. is not used."); |
|
324 |
|
325 RFile &file = pMsgCtx->ChunkL()->RequestFileHandle() ; //pMsgCtx->ChunkL() must not be null !! |
|
326 if (file.SubSessionHandle()) |
|
327 { |
|
328 TRAP( leaveCode, (*submitID) = iHttpChannel->SendL(*this, aEndpoint, file, properties);) |
|
329 } |
|
330 else |
|
331 { |
|
332 TRAP( leaveCode, (*submitID) = iHttpChannel->SendL(*this, aEndpoint, aMessage, properties);) |
|
333 } |
|
334 } |
|
335 } |
|
336 else |
|
337 { |
|
338 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"Fatal(!): message context not found!"); |
|
339 } |
|
340 |
|
341 TInt timeOutSec(0); |
|
342 LayeredPropertiesL().MaxTimeToLiveL(timeOutSec); |
|
343 properties.ShrinkTo(MSenLayeredProperties::ESenConsumerSessionLayer); |
|
344 |
|
345 |
|
346 if(leaveCode==KErrNone) |
|
347 { |
|
348 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- iHttpChannel returned OK."); |
|
349 // No leave occurred |
|
350 aTxnId = *submitID; |
|
351 if (timeOutSec) |
|
352 { |
|
353 iHttpChannel->EnableTimeOutL(aTxnId, timeOutSec); |
|
354 } |
|
355 |
|
356 TInt retVal = iSessionMap.Append(&aReplyTo, submitID); |
|
357 if(retVal==KErrNone) |
|
358 { |
|
359 retVal = iConsumerMap.Append(&aConsumer, submitID); |
|
360 if(retVal!=KErrNone) |
|
361 { |
|
362 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("- iConsumerMap.Append failed: %d"), retVal )); |
|
363 |
|
364 // Last entry to iSessionMap must be removed |
|
365 TInt removeRetVal = iSessionMap.Remove(*submitID); |
|
366 #ifdef _SENDEBUG |
|
367 if(removeRetVal==KErrNotFound) |
|
368 { |
|
369 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("- MAJOR: Could not remove session by txnId(%d)"), *submitID)); |
|
370 } |
|
371 #endif // _SENDEBUG |
|
372 removeRetVal = 0; // not used in release builds |
|
373 } |
|
374 } |
|
375 else |
|
376 { |
|
377 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("- FATAL: iConsumerMap.Append failed: %d"), retVal )); |
|
378 } |
|
379 CleanupStack::Pop(submitID); |
|
380 } |
|
381 else |
|
382 { |
|
383 CleanupStack::PopAndDestroy(submitID); |
|
384 } |
|
385 return leaveCode; |
|
386 } |
|
387 |
|
388 void CSenHttpChannelTransportPlugin::ResponseReceivedL(TInt aRequestId, |
|
389 const TAny* /* aContentType */, |
|
390 HBufC8* apContent, |
|
391 CSenHttpTransportProperties* aHttpProperties) |
|
392 { |
|
393 |
|
394 iHttpChannel->DisableTimeOutL(aRequestId); |
|
395 CleanupStack::PushL(apContent); |
|
396 |
|
397 #ifdef _SENDEBUG |
|
398 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ResponseReceivedL:"); |
|
399 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- Request's txnID: %d"), aRequestId)); |
|
400 if ( apContent ) |
|
401 { |
|
402 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMaxLogLevel, _L8("- apContent:"))); |
|
403 TLSLOG_ALL(KSenHttpChannelObserverLogChannelBase,KMaxLogLevel,(*apContent)); |
|
404 } |
|
405 else |
|
406 { |
|
407 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"Fatal(!): - apContent == NULL."); |
|
408 } |
|
409 #endif // _SENDEBUG |
|
410 |
|
411 TInt index = iSessionMap.FindValue(aRequestId); |
|
412 if(index != KErrNotFound) |
|
413 { |
|
414 // session found OK |
|
415 MSenServiceSession* pSession = |
|
416 iSessionMap.KeyAt(index); |
|
417 iSessionMap.Remove(aRequestId); // does not delete anything |
|
418 |
|
419 index = iConsumerMap.FindValue(aRequestId); |
|
420 |
|
421 if(index != KErrNotFound) |
|
422 { |
|
423 // consumer found OK |
|
424 MSenRemoteServiceConsumer* pConsumer = |
|
425 iConsumerMap.KeyAt(index); |
|
426 |
|
427 iConsumerMap.Remove(aRequestId); // deletes TxnId |
|
428 |
|
429 CleanupStack::Pop(apContent); |
|
430 pSession->SendToConsumerL(apContent, aRequestId, *pConsumer, aHttpProperties); |
|
431 pConsumer->SetDataTrafficDetails(iDetails); |
|
432 } |
|
433 else |
|
434 { |
|
435 CleanupStack::PopAndDestroy(apContent); |
|
436 #ifdef _SENDEBUG |
|
437 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ResponseReceivedL:"); |
|
438 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- pending consumer not found, txn cancelled?"); |
|
439 #endif // _SENDEBUG |
|
440 } |
|
441 } |
|
442 else |
|
443 { |
|
444 CleanupStack::PopAndDestroy(apContent); |
|
445 #ifdef _SENDEBUG |
|
446 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ResponseReceivedL:"); |
|
447 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- pending session not found, txn cancelled?"); |
|
448 #endif // _SENDEBUG |
|
449 } |
|
450 } |
|
451 |
|
452 // Method to catch async error responses from httpchannel |
|
453 void CSenHttpChannelTransportPlugin::ResponseErrorL(TInt aRequestId, TInt aErrorCode, HBufC8* apErrorBody,CSenHttpTransportProperties* aHttpProperties) |
|
454 { |
|
455 CleanupStack::PushL(apErrorBody); |
|
456 iHttpChannel->DisableTimeOutL(aRequestId); |
|
457 #ifdef _SENDEBUG |
|
458 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ResponseErrorL:"); |
|
459 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- Request's txnID: %d"), aRequestId)); |
|
460 if ( apErrorBody ) |
|
461 { |
|
462 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMaxLogLevel, _L8("- apErrorBody:"))); |
|
463 TLSLOG_ALL(KSenHttpChannelObserverLogChannelBase,KMaxLogLevel,(*apErrorBody)); |
|
464 } |
|
465 else |
|
466 { |
|
467 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"Fatal(!): - apErrorBody == NULL."); |
|
468 } |
|
469 #endif // _SENDEBUG |
|
470 |
|
471 iStatusCode = aErrorCode; |
|
472 |
|
473 TInt index = iSessionMap.FindValue(aRequestId); |
|
474 if(index != KErrNotFound) |
|
475 { |
|
476 // session found OK |
|
477 MSenServiceSession* pSession = |
|
478 iSessionMap.KeyAt(index); |
|
479 iSessionMap.Remove(aRequestId); // does not delete anything |
|
480 |
|
481 index = iConsumerMap.FindValue(aRequestId); |
|
482 if(index != KErrNotFound) |
|
483 { |
|
484 // consumer found OK |
|
485 MSenRemoteServiceConsumer* pConsumer = |
|
486 iConsumerMap.KeyAt(index); |
|
487 |
|
488 iConsumerMap.Remove(aRequestId); // deletes TxnId |
|
489 |
|
490 CleanupStack::Pop(apErrorBody); |
|
491 pSession->SendErrorToConsumerL(aErrorCode, |
|
492 apErrorBody, |
|
493 aRequestId, |
|
494 *pConsumer, |
|
495 aHttpProperties); |
|
496 apErrorBody = NULL; |
|
497 pConsumer->SetDataTrafficDetails(iDetails); |
|
498 } |
|
499 else |
|
500 { |
|
501 CleanupStack::PopAndDestroy(apErrorBody); |
|
502 #ifdef _SENDEBUG |
|
503 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ResponseErrorL:"); |
|
504 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- pending consumer not found, txn cancelled?"); |
|
505 #endif // _SENDEBUG |
|
506 } |
|
507 } |
|
508 else |
|
509 { |
|
510 //CleanupStack::PopAndDestroy(apErrorBody); |
|
511 CleanupStack::Pop(apErrorBody); // for EPSK-76XFAN |
|
512 #ifdef _SENDEBUG |
|
513 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ResponseErrorL:"); |
|
514 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- pending session not found, txn cancelled?"); |
|
515 #endif // _SENDEBUG |
|
516 } |
|
517 } |
|
518 |
|
519 /* |
|
520 RFileLogger* CSenHttpChannelTransportPlugin::Log() const |
|
521 { |
|
522 return (RFileLogger*) &iLogger; |
|
523 } |
|
524 */ |
|
525 |
|
526 TInt CSenHttpChannelTransportPlugin::SetPropertiesL(const TDesC8& aProperties, |
|
527 MSenLayeredProperties::TSenPropertiesLayer aTargetLayer, |
|
528 MSenRemoteServiceConsumer* /*aConsumer*/) |
|
529 { |
|
530 TInt retVal(KErrNone); |
|
531 if ( aTargetLayer == MSenLayeredProperties::ESenTransportLayer ) |
|
532 { |
|
533 retVal = KErrNotSupported; |
|
534 } |
|
535 else |
|
536 { |
|
537 LayeredPropertiesL().ReadFromL(aProperties, aTargetLayer); |
|
538 retVal = ApplyPropertiesL(); |
|
539 } |
|
540 return retVal; |
|
541 } |
|
542 |
|
543 TInt CSenHttpChannelTransportPlugin::PropertiesL(HBufC8*& aProperties) |
|
544 { |
|
545 aProperties = PropertiesL().AsUtf8L(); |
|
546 return KErrNone; |
|
547 } |
|
548 |
|
549 TInt CSenHttpChannelTransportPlugin::ApplyPropertiesL() |
|
550 { |
|
551 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ApplyPropertiesL()"); |
|
552 |
|
553 TInt retVal(KErrNone); |
|
554 |
|
555 // ALWAYS HANDLE IAP ID FIRST, SINCE IT *CAN RESET* HTTPCHANNEL! |
|
556 |
|
557 TUint32 iapId(KErrNone); |
|
558 |
|
559 retVal = LayeredPropertiesL().IapIdL(iapId); |
|
560 if(retVal==KErrNone) |
|
561 { |
|
562 TInt resetPerformed = ResetHttpChannelByIapIdL(iapId); |
|
563 #ifdef _SENDEBUG |
|
564 if(resetPerformed == KErrNone) |
|
565 { |
|
566 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- IAP re-set performed: (%d)"), iapId)); |
|
567 } |
|
568 #endif // _SENDEBUG |
|
569 } |
|
570 |
|
571 // Handle ProxyHost and ProxyPort |
|
572 TPtrC8 proxyHost; |
|
573 retVal = LayeredPropertiesL().ProxyHostL(proxyHost); |
|
574 if ( retVal == KErrNone ) |
|
575 { |
|
576 TInt proxyPort(KErrNotFound); |
|
577 retVal = LayeredPropertiesL().ProxyPortL(proxyPort); |
|
578 iHttpChannel->SetProxyL(proxyHost, proxyPort); |
|
579 } |
|
580 |
|
581 |
|
582 // HttpVersion |
|
583 CSenLayeredHttpTransportProperties::TSenHttpVersion httpVersion; |
|
584 retVal = LayeredPropertiesL().HttpVersionL(httpVersion); |
|
585 if ( retVal == KErrNone ) |
|
586 { |
|
587 switch ( httpVersion ) |
|
588 { |
|
589 case CSenLayeredHttpTransportProperties::ESenHttp10: |
|
590 { |
|
591 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- SetHttpVersionL(ESenHttp10)"); |
|
592 iHttpChannel->SetHttpVersionL(0); |
|
593 } |
|
594 break; |
|
595 case CSenLayeredHttpTransportProperties::ESenHttp11: |
|
596 { |
|
597 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- SetHttpVersionL(ESenHttp11)"); |
|
598 iHttpChannel->SetHttpVersionL(1); |
|
599 } |
|
600 break; |
|
601 default: |
|
602 // Not possible |
|
603 break; |
|
604 } |
|
605 } |
|
606 return KErrNone; |
|
607 } |
|
608 |
|
609 TInt CSenHttpChannelTransportPlugin::ResetHttpChannelByIapIdL(TUint32 aIapId) |
|
610 { |
|
611 TUint32 effectiveIapId(KErrNone); |
|
612 TBool explicitIapIdDefined(EFalse); |
|
613 if(iHttpChannel) |
|
614 { |
|
615 explicitIapIdDefined = iHttpChannel->EffectiveIapId(effectiveIapId); |
|
616 } |
|
617 |
|
618 TInt retVal(KErrNone); |
|
619 if(!explicitIapIdDefined || explicitIapIdDefined && effectiveIapId != aIapId) |
|
620 { |
|
621 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ResetHttpChannel():"); |
|
622 |
|
623 delete iHttpChannel; |
|
624 iHttpChannel = NULL; |
|
625 delete iRequester; |
|
626 iRequester = NULL; |
|
627 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- New IAP ID: %d"), aIapId)); |
|
628 CSenHttpChannel* pHttpChannel = CSenHttpChannelImpl::NewL(iServiceManager, aIapId); |
|
629 |
|
630 CleanupStack::PushL(pHttpChannel); |
|
631 |
|
632 CSenHttpSyncRequester* pRequester = CSenHttpSyncRequester::NewL(pHttpChannel, this); |
|
633 |
|
634 iHttpChannel = pHttpChannel; |
|
635 iRequester = pRequester; |
|
636 |
|
637 CleanupStack::Pop(pHttpChannel); |
|
638 } |
|
639 else |
|
640 { |
|
641 retVal = KErrAlreadyExists; |
|
642 } |
|
643 return retVal; |
|
644 } |
|
645 |
|
646 TInt CSenHttpChannelTransportPlugin::CompleteTransaction(const TInt aTxnId, |
|
647 const TInt /* aCompletionCode */) |
|
648 { |
|
649 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("CSenHttpChannelTransportPlugin::CompleteTransaction(txn ID: %d)"), aTxnId /*, aCompletionCode */)); |
|
650 |
|
651 // Remove the session and consumer from arrays to prevent |
|
652 // any unneccessary processing of completed transactions.. |
|
653 |
|
654 // Handle completed session |
|
655 TInt index = iSessionMap.FindValue(aTxnId); |
|
656 if(index != KErrNotFound) |
|
657 { |
|
658 // Session found |
|
659 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- Pending session found, removing it from list."), index)); |
|
660 |
|
661 //MSenServiceSession* pSession = |
|
662 // iSessionMap.KeyAt(index); |
|
663 |
|
664 index = iSessionMap.Remove(aTxnId); // does not delete anything |
|
665 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- Remove() returned: %d"), index)); |
|
666 } |
|
667 #ifdef _SENDEBUG |
|
668 else |
|
669 { |
|
670 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- Cannot find pending session with given ID."); |
|
671 } |
|
672 #endif |
|
673 // Handle cancelled consumer |
|
674 TInt index2 = iConsumerMap.FindValue(aTxnId); |
|
675 if(index2 != KErrNotFound) |
|
676 { |
|
677 // Consumer found |
|
678 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- Pending consumer (%d) found, removing it from list."), |
|
679 index2)); |
|
680 |
|
681 //MSenRemoteServiceConsumer* pConsumer = |
|
682 // iConsumerMap.KeyAt(index2); |
|
683 |
|
684 index2 = iConsumerMap.Remove(aTxnId); // deletes TxnId |
|
685 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- Remove() returned: %d"), index2)); |
|
686 } |
|
687 #ifdef _SENDEBUG |
|
688 else |
|
689 { |
|
690 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- Cannot find pending consumer with given ID."); |
|
691 } |
|
692 #endif |
|
693 return index<index2?index:index2; |
|
694 } |
|
695 |
|
696 TInt CSenHttpChannelTransportPlugin::CancelTransaction(const TInt aTxnId) |
|
697 { |
|
698 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("CSenHttpChannelTransportPlugin::CancelTransaction(%d)"), aTxnId)); |
|
699 TInt index = CompleteTransaction(aTxnId, KErrSenCancelled); |
|
700 if(iHttpChannel) |
|
701 { |
|
702 iHttpChannel->CancelTransaction(aTxnId); |
|
703 } |
|
704 return index; |
|
705 } |
|
706 |
|
707 TPtrC8 CSenHttpChannelTransportPlugin::UriSchemeL() |
|
708 { |
|
709 return KSenHttpChannelTransportUriScheme(); |
|
710 } |
|
711 |
|
712 |
|
713 // Private helper |
|
714 CSenLayeredHttpTransportProperties& CSenHttpChannelTransportPlugin::LayeredPropertiesL() |
|
715 { |
|
716 if ( !iProperties ) |
|
717 { |
|
718 iProperties = CSenLayeredHttpTransportProperties::NewL(); |
|
719 iProperties->SetPropertyL(KAcceptLocalName, KSenHttpChannelAcceptHeaderDefault, KHttpHeaderType); |
|
720 iProperties->SetPropertyL(KUserAgentLocalName, KSenHttpChannelUserAgentHeaderDefault, KHttpHeaderType); |
|
721 iProperties->SetPropertyL(KContentTypeLocalName, KContentType, KHttpHeaderType); |
|
722 } |
|
723 iProperties->SetReader(*iServiceManager.XMLReader()); |
|
724 return *iProperties; |
|
725 } |
|
726 |
|
727 MSenProperties& CSenHttpChannelTransportPlugin::PropertiesL() |
|
728 { |
|
729 CSenLayeredHttpTransportProperties& properties = LayeredPropertiesL(); |
|
730 if( iHttpChannel ) |
|
731 { |
|
732 TUint32 iapId(0); |
|
733 TInt error = properties.IapIdL( iapId ); |
|
734 if ( error || iapId == 0 || iapId >=(TUint32)KErrNotFound ) // IAP is either not found from properties, or it is 0 or > MAX_INT (signed) |
|
735 { |
|
736 TBool isIapSet = iHttpChannel->EffectiveIapId( iapId ); |
|
737 if( isIapSet && iapId > 0 ) |
|
738 { |
|
739 TBuf8<128> buf; |
|
740 buf.AppendFormat(_L8("%u"), iapId); |
|
741 properties.SetPropertyL( KIapIdLocalName, buf ); |
|
742 } |
|
743 if( iHttpChannel->UsedIap() ) |
|
744 { |
|
745 TBuf8<128> buf; |
|
746 buf.AppendFormat(_L8("%u"), iHttpChannel->UsedIap()); |
|
747 properties.SetPropertyL( KIapIdLocalName, buf ); |
|
748 } |
|
749 } |
|
750 } |
|
751 return properties; |
|
752 } |
|
753 |
|
754 // Propagate http status code to remote service consumer |
|
755 void CSenHttpChannelTransportPlugin::StateChanged(TInt aRequestId, |
|
756 TInt aState) |
|
757 { |
|
758 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMaxLogLevel,"CSenHttpChannelTransportPlugin::StateChanged:"); |
|
759 TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMaxLogLevel, _L8("- request txnID: %d"), aRequestId)); |
|
760 |
|
761 TInt index = iConsumerMap.FindValue(aRequestId); |
|
762 if(index != KErrNotFound) |
|
763 { |
|
764 // propagate the Status code |
|
765 MSenRemoteServiceConsumer* pConsumer = iConsumerMap.KeyAt(index); |
|
766 |
|
767 |
|
768 TInt state = KSenTransportStatusCodeOffsetBaseHttp + aState; |
|
769 pConsumer->StateChanged(state); |
|
770 } |
|
771 #ifdef _SENDEBUG |
|
772 else |
|
773 { |
|
774 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::StateChanged:"); |
|
775 TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"- pending consumer not found, txn cancelled?"); |
|
776 } |
|
777 #endif // _SENDEBUG |
|
778 } |
|
779 |
|
780 void CSenHttpChannelTransportPlugin::FileProgress(TInt aTxnId, TBool aIncoming, |
|
781 TBool aIsSoap, const TDesC8& aSoapOrCid, TInt aProgress) |
|
782 { |
|
783 TInt index = iConsumerMap.FindValue(aTxnId); |
|
784 if (index != KErrNotFound) |
|
785 { |
|
786 iConsumerMap.KeyAt(index)->FileProgress(aTxnId, aIncoming, aIsSoap, |
|
787 aSoapOrCid, aProgress); |
|
788 } |
|
789 } |
|
790 |
|
791 void CSenHttpChannelTransportPlugin::SetTrafficDetails(TSenDataTrafficDetails& aDetails) |
|
792 { |
|
793 iDetails = aDetails; |
|
794 } |
|
795 |
|
796 void CSenHttpChannelTransportPlugin::DataTrafficDetails(TSenDataTrafficDetails& aDetails) |
|
797 { |
|
798 aDetails = iDetails; |
|
799 } |
|
800 // End of File |