|
1 /* |
|
2 * Copyright (c) 2002-2005 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 // INCLUDE FILES |
|
21 #include "senwebservicesession.h" |
|
22 |
|
23 #include <SenServiceConnection.h> // error codes etc |
|
24 |
|
25 #include "senservicesession.h" |
|
26 #include "SenServiceConnection.h" // session status constants |
|
27 #include "SenSoapMessage.h" |
|
28 #include "senwsdescription.h" |
|
29 #include "msencoreservicemanager.h" |
|
30 #include "msenremoteserviceconsumer.h" |
|
31 #include "SenXmlUtils.h" |
|
32 #include "SenDateUtils.h" |
|
33 #include "msentransport.h" |
|
34 #include "SenCredential.h" |
|
35 //#include "SenPolicy.h" |
|
36 #include "SenSoapFault.h" |
|
37 #include "sendebug.h" |
|
38 #include "senservicemanagerdefines.h" |
|
39 #include "senservicepolicy.h" |
|
40 #include "seninternalcredential.h" |
|
41 #include "sensaxutils.h" |
|
42 #include <xmlengnodelist.h> |
|
43 #include <SenIdentityProvider.h> |
|
44 #include "senlogger.h" |
|
45 #include <SenXmlConstants.h> |
|
46 |
|
47 #include <SenTransportProperties.h> |
|
48 // CONSTANTS |
|
49 |
|
50 namespace |
|
51 { |
|
52 _LIT8(KServiceInterval1,"ServiceInterval"); |
|
53 _LIT(KInvalideDate,"19000101:"); |
|
54 /* microseconds before actual notOnOrAfter time |
|
55 * when credentials are treated |
|
56 * as expired. |
|
57 */ |
|
58 const TInt KClockSlipMicroSeconds = 3*60*1000*1000; |
|
59 |
|
60 // constants for parsing |
|
61 _LIT8(KSDFramework,"<ServiceDescription framework=\""); |
|
62 _LIT8(KContractStart, "<Contract>"); |
|
63 _LIT8(KContractEnd, "</Contract>"); |
|
64 _LIT8(KTagWithAttrEnd, "\">"); |
|
65 _LIT8(KEndPointStart, "<Endpoint>"); |
|
66 _LIT8(KEndPointStartWithCue, "<Endpoint cue=\""); |
|
67 _LIT8(KTagWithAttrClose, "\"/>"); |
|
68 _LIT8(KEndPointEnd, "</Endpoint>"); |
|
69 _LIT8(KCredentialsStart, "<Credentials"); |
|
70 _LIT8(KCredentialsEnd, "</Credentials>"); |
|
71 _LIT8(KNotOnOrAfterFormat, " notOnOrAfter=\"%S\" >"); |
|
72 _LIT8(KEmptyTagEnd, " >"); |
|
73 _LIT8(KSDEnd, "</ServiceDescription>"); |
|
74 // localnames for element(s) |
|
75 _LIT8(KProviderPolicyLocalName, "ProviderPolicy"); |
|
76 _LIT8(KNewLine, "\n"); |
|
77 |
|
78 const TInt KCredIdBufSize = 128; |
|
79 _LIT8(KCredentialIdLocalName, "SenCredentialId"); |
|
80 _LIT8(KCredentialIdStart, "<SenCredentialId>"); |
|
81 _LIT8(KCredentialIdEnd, "</SenCredentialId>"); |
|
82 _LIT8(KEndpointLocalname, "Endpoint"); |
|
83 // _LIT8(KContractLocalname, "Contract"); |
|
84 } |
|
85 |
|
86 EXPORT_C CSenWebServiceSession::CSenWebServiceSession(TDescriptionClassType aType, |
|
87 MSIF& aFramework) |
|
88 : CSenServiceSession(aType, aFramework) |
|
89 { |
|
90 } |
|
91 |
|
92 EXPORT_C void CSenWebServiceSession::ConstructL() |
|
93 { |
|
94 |
|
95 // Sets the local name to "ServiceDescription" |
|
96 // and initiates the inner ipElement |
|
97 CSenServiceSession::BaseConstructL(); |
|
98 // Init member variables |
|
99 iClientServerInterval = 0; |
|
100 iValidUntil = Time::NullTTime(); |
|
101 iFrameworkId = iFramework.Id().AllocL(); |
|
102 } |
|
103 |
|
104 EXPORT_C CSenWebServiceSession::~CSenWebServiceSession() |
|
105 { |
|
106 delete iSecurity; |
|
107 delete iContract; |
|
108 delete iEndpoint; |
|
109 delete iFrameworkId; |
|
110 iFrameworkId = NULL; |
|
111 delete iTransportCue; |
|
112 iTransportCue = NULL; |
|
113 iCredentialPtr.RemoveCredentialObserver(*this); |
|
114 iCredentialPtr.Close(); |
|
115 } |
|
116 |
|
117 EXPORT_C TPtrC8 CSenWebServiceSession::TransportCue() |
|
118 { |
|
119 if( iTransportCue ) |
|
120 { |
|
121 return *iTransportCue; |
|
122 } |
|
123 else |
|
124 { |
|
125 return CSenServiceSession::TransportCue(); |
|
126 } |
|
127 } |
|
128 |
|
129 EXPORT_C TInt CSenWebServiceSession::InitializeFromL(MSenServiceDescription& aServiceDescription) |
|
130 { |
|
131 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,_L("Zapping filelogged messages (.xml)")); |
|
132 |
|
133 // Call superclass method to initialize facets, transport (endpoint) cue, etc.. |
|
134 CSenServiceSession::InitializeFromL(aServiceDescription); |
|
135 |
|
136 HBufC8* pContract = aServiceDescription.Contract().AllocL(); |
|
137 delete iContract; |
|
138 iContract = pContract; |
|
139 |
|
140 HBufC8* pEndpoint = aServiceDescription.Endpoint().AllocL(); |
|
141 delete iEndpoint; |
|
142 iEndpoint = pEndpoint; |
|
143 |
|
144 if(aServiceDescription.DescriptionClassType() |
|
145 == |
|
146 MSenServiceDescription::EWSDescription |
|
147 || |
|
148 aServiceDescription.DescriptionClassType() |
|
149 == |
|
150 MSenServiceDescription::EWSPattern |
|
151 || |
|
152 aServiceDescription.DescriptionClassType() |
|
153 == |
|
154 MSenServiceDescription::EIdentityProvider |
|
155 ) |
|
156 { |
|
157 |
|
158 CSenWSDescription& xmlDesc = |
|
159 (CSenWSDescription&)aServiceDescription; |
|
160 |
|
161 CSenElement* pElement = |
|
162 (xmlDesc.AsElement()).Element(KServiceInterval1); |
|
163 if(pElement) |
|
164 { |
|
165 TLex8 lex(pElement->Content()); |
|
166 TInt64 val; |
|
167 User::LeaveIfError(lex.Val(val)); |
|
168 iClientServerInterval = val; |
|
169 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase, KNormalLogLevel , _L8("Interval in microseconds (from file): %d"), |
|
170 iClientServerInterval.Int64())); |
|
171 } |
|
172 |
|
173 RCredentialList& credentials = xmlDesc.Credentials(); |
|
174 TInt count(credentials.Count()); |
|
175 for(TInt i=0; i<count; i++) |
|
176 { |
|
177 CSenCredential* pCredential = credentials[i]; |
|
178 if(pCredential) |
|
179 { |
|
180 // note: errors while adding single credential must ignored: |
|
181 // - the remaining credentials (array) must be processed.. |
|
182 |
|
183 //CSenCredential* pCopy = CSenCredential::NewL(*pCredential); |
|
184 //CleanupStack::PushL(pCopy); |
|
185 AddCredentialL(*pCredential); |
|
186 //CleanupStack::Pop(); // pCopy |
|
187 } |
|
188 } |
|
189 // rebuild provider policy definition |
|
190 RebuildFrom(xmlDesc); |
|
191 // update provider policy information (new feature) |
|
192 |
|
193 MSenServicePolicy* servicePolicy = ServicePolicy(); |
|
194 if(servicePolicy) |
|
195 { |
|
196 MSenServicePolicy* givenServicePolicy = xmlDesc.ServicePolicy(); |
|
197 if(givenServicePolicy) |
|
198 (CSenServicePolicy*)servicePolicy->RebuildServicePolicyFrom(*givenServicePolicy); |
|
199 } |
|
200 } |
|
201 SetStatusL(); |
|
202 return KErrNone; // err value not currently in use |
|
203 } |
|
204 |
|
205 EXPORT_C TInt CSenWebServiceSession::ComputeStatusL() |
|
206 { |
|
207 TInt retVal = CSenServiceSession::ComputeStatusL(); |
|
208 |
|
209 if (retVal == KSenConnectionStatusReady) |
|
210 { |
|
211 TTime now; |
|
212 now.UniversalTime(); |
|
213 now += iClientServerInterval; |
|
214 |
|
215 #ifdef _SENDEBUG |
|
216 if (iValidUntil != Time::NullTTime()) |
|
217 { |
|
218 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase, KNormalLogLevel , _L8("Client-Server Interval in microseconds: %d"), |
|
219 iClientServerInterval.Int64())); |
|
220 |
|
221 TBuf8<SenDateUtils::KXmlDateTimeMaxLength> ts; |
|
222 TInt leaveCode(KErrNone); |
|
223 TRAP(leaveCode, SenDateUtils::ToXmlDateTimeUtf82L(ts, now);) |
|
224 if (leaveCode == KErrNone) |
|
225 { |
|
226 |
|
227 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KNormalLogLevel, _L8("Fixed client time : %S"), &ts)); |
|
228 |
|
229 TBuf8<SenDateUtils::KXmlDateTimeMaxLength> ts2; |
|
230 TRAP(leaveCode, SenDateUtils::ToXmlDateTimeUtf82L(ts2, iValidUntil);) |
|
231 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KNormalLogLevel, _L8("Credential time : %S, clockslip: %d micros"), &ts2, KClockSlipMicroSeconds)); |
|
232 } |
|
233 leaveCode = 0; // not used |
|
234 } |
|
235 #endif // _SENDEBUG |
|
236 |
|
237 if ((iValidUntil != Time::NullTTime() ) && |
|
238 now > |
|
239 (iValidUntil-TTimeIntervalMicroSeconds(KClockSlipMicroSeconds))) |
|
240 { |
|
241 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,_L("Credential is expired.")); |
|
242 retVal = KSenConnectionStatusExpired; |
|
243 } |
|
244 } |
|
245 return retVal; |
|
246 } |
|
247 |
|
248 EXPORT_C TBool CSenWebServiceSession::IsExpiredL() |
|
249 { |
|
250 ComputeStatusL(); |
|
251 return (CSenServiceSession::StatusL() == KSenConnectionStatusExpired); |
|
252 } |
|
253 |
|
254 EXPORT_C TInt CSenWebServiceSession::AddCredentialL( |
|
255 CSenCredential& aCredential) |
|
256 { |
|
257 if ( aCredential.AsElement().LocalName() == KCredentialIdLocalName ) |
|
258 { |
|
259 delete iSecurity; |
|
260 iSecurity = NULL; |
|
261 iSecurity = aCredential.AsXmlL(); |
|
262 |
|
263 TInt credentialId; |
|
264 TLex8 lex; |
|
265 lex.Assign(aCredential.AsElement().Content()); |
|
266 lex.Val(credentialId); |
|
267 |
|
268 TInt error(KErrNone); |
|
269 RSenCredentialPtr credentialPtr; |
|
270 credentialPtr = ((MSenServiceManager&)iFramework.Manager()).CredentialL(credentialId, |
|
271 error); |
|
272 if ( error == KErrNone ) |
|
273 { |
|
274 iCredentialPtr = credentialPtr.Clone(); |
|
275 iCredentialPtr.AddCredentialObserverL(*this); //codescannerwarnings |
|
276 iValidUntil = iCredentialPtr.Credential()->ValidUntil(); |
|
277 if ( iClientServerInterval == 0 ) |
|
278 { |
|
279 TPtrC8 value; |
|
280 TInt ret = iCredentialPtr.Credential()->PropertiesL().PropertyL( KServiceInterval1, |
|
281 value ); |
|
282 if ( ret == KErrNone ) |
|
283 { |
|
284 TLex8 lex(value); |
|
285 TInt64 val; |
|
286 ret = lex.Val(val); |
|
287 if ( ret == KErrNone ) |
|
288 { |
|
289 iClientServerInterval = val; |
|
290 } |
|
291 } |
|
292 } |
|
293 } |
|
294 else |
|
295 { |
|
296 // invalidate the session, because we have no credential |
|
297 iValidUntil.Set(KInvalideDate); // way back in history: January 1st 1900 |
|
298 |
|
299 iCredentialPtr.RemoveCredentialObserver(*this); |
|
300 iCredentialPtr.Close(); |
|
301 |
|
302 delete iSecurity; |
|
303 iSecurity = NULL; |
|
304 |
|
305 TBuf8<KCredIdBufSize> buffer; |
|
306 buffer.Num(KErrNotFound); |
|
307 |
|
308 iSecurity = HBufC8::NewL(buffer.Length()+KCredentialIdStart().Length()+KCredentialIdEnd().Length()); |
|
309 TPtr8 sec = iSecurity->Des(); |
|
310 sec.Append(KCredentialIdStart); |
|
311 sec.Append(buffer); |
|
312 sec.Append(KCredentialIdEnd); |
|
313 } |
|
314 } |
|
315 else |
|
316 { |
|
317 TInt retVal(KErrNone); |
|
318 |
|
319 delete iSecurity; |
|
320 iSecurity = NULL; |
|
321 HBufC8* pSecurityToken = 0; |
|
322 retVal = ConstructSecurityTokenL(aCredential, pSecurityToken); |
|
323 if (KErrNone != retVal) |
|
324 { |
|
325 if ( pSecurityToken != NULL ) |
|
326 { |
|
327 delete pSecurityToken; |
|
328 pSecurityToken = NULL; |
|
329 iCredentialPtr.RemoveCredentialObserver(*this); |
|
330 iCredentialPtr.Close(); |
|
331 } |
|
332 return retVal; |
|
333 } |
|
334 |
|
335 iValidUntil = aCredential.ValidUntil(); // SetSecurityL needs up-to-date iValidUntil(!) |
|
336 |
|
337 CleanupStack::PushL(pSecurityToken); |
|
338 SetSecurityL(*pSecurityToken); |
|
339 CleanupStack::PopAndDestroy(pSecurityToken); |
|
340 } |
|
341 |
|
342 SetStatusL(); |
|
343 |
|
344 return KErrNone; |
|
345 } |
|
346 |
|
347 EXPORT_C TInt CSenWebServiceSession::ConstructSecurityTokenL( CSenCredential& aCredential, |
|
348 HBufC8*& aToken ) |
|
349 { |
|
350 aToken = aCredential.AsXmlL(); |
|
351 return KErrNone; |
|
352 } |
|
353 |
|
354 EXPORT_C TInt CSenWebServiceSession::NewMessageL( CSenSoapMessage*& aMessage ) |
|
355 { |
|
356 aMessage = CSenSoapMessage::NewL(); |
|
357 return KErrNone; |
|
358 } |
|
359 |
|
360 EXPORT_C TInt CSenWebServiceSession::MessageForSendingL( const TDesC8& aBody, |
|
361 const TDesC8& /* aSenderID */, |
|
362 CSenSoapMessage*& aMessage ) |
|
363 { |
|
364 TInt retVal(KErrNone); |
|
365 aMessage = CSenSoapMessage::NewL(); |
|
366 CleanupStack::PushL(aMessage); |
|
367 SetFrameworkHeadersL(*aMessage); |
|
368 aMessage->SetBodyL(aBody); |
|
369 CleanupStack::Pop(); // aMessage |
|
370 return retVal; |
|
371 } |
|
372 |
|
373 EXPORT_C TInt CSenWebServiceSession::ParseResponseL( const TDesC8& aResponse, |
|
374 HBufC8*& aParsed ) |
|
375 { |
|
376 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::ParseResponseL(const TDesC8&, HBufC8*&)"); |
|
377 // this called only from the synchronous submit(..) methods |
|
378 TInt retVal(KErrNone); |
|
379 CSenSoapMessage* pSoapMessage = NULL; |
|
380 retVal = ParseResponseL(aResponse, pSoapMessage); |
|
381 if(retVal!=KErrNone) |
|
382 { |
|
383 delete pSoapMessage; |
|
384 return retVal; |
|
385 } |
|
386 |
|
387 CleanupStack::PushL(pSoapMessage); |
|
388 |
|
389 // Check for completeMessages |
|
390 TBool completeServerMessages; |
|
391 HasFacetL(KCompleteMessagesFacet,completeServerMessages); |
|
392 if (completeServerMessages) |
|
393 { |
|
394 aParsed = pSoapMessage->AsXmlL(); |
|
395 } |
|
396 else |
|
397 { |
|
398 // If the message contained SOAP fault it will be in the body. |
|
399 // It's up to the client to check for a Fault. |
|
400 aParsed = pSoapMessage->BodyAsStringL(); |
|
401 if (!aParsed) |
|
402 { |
|
403 retVal = KErrSenNoSoapBody; |
|
404 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::ParseResponseL - NULL from BodyAsStringL - return KErrSenNoSoapBody"); |
|
405 } |
|
406 } |
|
407 |
|
408 CleanupStack::PopAndDestroy(); // pSoapMessage |
|
409 return retVal; |
|
410 } |
|
411 |
|
412 |
|
413 EXPORT_C TInt CSenWebServiceSession::SendSoapMessageToConsumerL( CSenSoapMessage* apMessage, |
|
414 const TInt aTxnId, |
|
415 MSenRemoteServiceConsumer& aConsumer, |
|
416 MSenProperties* aResponseTransportProperties ) |
|
417 { |
|
418 if ( !apMessage ) |
|
419 { |
|
420 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SendSoapMessageToConsumerL"); |
|
421 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"Fatal()!: NULL argument passed instead of valid pointer to CSenSoapMessage"); |
|
422 return HandleErrorL( KErrSenInternal, NULL, aTxnId, aConsumer, aResponseTransportProperties ); |
|
423 } |
|
424 |
|
425 CleanupStack::PushL(apMessage); |
|
426 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SendSoapMessageToConsumerL"); |
|
427 TInt retVal(KErrNone); |
|
428 // Check if consumer wishes to receive complete server messages: |
|
429 TBool completeServerMessages; |
|
430 HasFacetL(KCompleteMessagesFacet, completeServerMessages); |
|
431 if(completeServerMessages) |
|
432 { |
|
433 HBufC8* pMessageAsXML = apMessage->AsXmlL(); |
|
434 CleanupStack::PopAndDestroy(apMessage); |
|
435 if (pMessageAsXML) |
|
436 { |
|
437 retVal = aConsumer.HandleMessageL( pMessageAsXML, aTxnId, aResponseTransportProperties ); |
|
438 } |
|
439 } |
|
440 else |
|
441 { |
|
442 //HBufC8* pBody = apMessage->BodyL().Content().AllocL(); |
|
443 HBufC8* pBody = apMessage->BodyAsStringL(); |
|
444 CleanupStack::PopAndDestroy(apMessage); |
|
445 retVal = aConsumer.HandleMessageL( pBody, aTxnId, aResponseTransportProperties ); |
|
446 } |
|
447 return retVal; |
|
448 } |
|
449 |
|
450 // SYNC, takes ownership of apSoapMessage |
|
451 EXPORT_C TInt CSenWebServiceSession::HandleSoapFaultL( CSenSoapMessage* apSoapMessage, |
|
452 HBufC8*& aResponse /*, |
|
453 CSenTransportProperties*& aResponseTransportProperties */) |
|
454 { |
|
455 if( apSoapMessage ) |
|
456 { |
|
457 CleanupStack::PushL(apSoapMessage); |
|
458 CSenSoapFault* pDetached = apSoapMessage->DetachFaultL(); |
|
459 CleanupStack::PopAndDestroy( apSoapMessage ); |
|
460 TBool completeServerMessages(ETrue); |
|
461 HasFacetL(KCompleteMessagesFacet, completeServerMessages); |
|
462 if(pDetached) |
|
463 { |
|
464 CleanupStack::PushL(pDetached); |
|
465 // Response contains only soapfault in case no completeServerMessages facet |
|
466 // otherwise it should be left empty |
|
467 // aResponse is updated only when detached soap fault is required. |
|
468 if(completeServerMessages == EFalse) |
|
469 { |
|
470 aResponse = pDetached->AsXmlL(); |
|
471 } |
|
472 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::HandleErrorL:"); |
|
473 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"- successfully detached SOAP fault:"); |
|
474 CleanupStack::PopAndDestroy(pDetached); // pDetached |
|
475 // From *this* method, KErrSenSoapFault is *OK return code*, |
|
476 // just like KErrNone generally is.. |
|
477 return KErrSenSoapFault; |
|
478 } |
|
479 } |
|
480 return KErrNotFound; // SOAP fault not found |
|
481 } |
|
482 |
|
483 // ASYNC, takes ownership of apSoapMessage |
|
484 EXPORT_C TInt CSenWebServiceSession::HandleSoapFaultL( CSenSoapMessage* apSoapMessage, |
|
485 const TInt aErrorCode, |
|
486 const TInt aTxnId, |
|
487 MSenRemoteServiceConsumer& aConsumer, |
|
488 MSenProperties* aResponseTransportProperties ) |
|
489 { |
|
490 TInt retVal( KErrSenInternal ); |
|
491 if ( apSoapMessage ) |
|
492 { |
|
493 CleanupStack::PushL(apSoapMessage); // ownership is here |
|
494 |
|
495 CSenSoapFault* pDetached = apSoapMessage->DetachFaultL(); |
|
496 if(pDetached) |
|
497 { |
|
498 CleanupStack::PopAndDestroy( apSoapMessage ); // de-alloc msg, detach OK |
|
499 |
|
500 CleanupStack::PushL(pDetached); |
|
501 HBufC8* pAsXml = pDetached->AsXmlL(); |
|
502 CleanupStack::PopAndDestroy(pDetached); |
|
503 |
|
504 retVal = aConsumer.HandleErrorL(pAsXml, aErrorCode, aTxnId, aResponseTransportProperties); |
|
505 } |
|
506 else |
|
507 { |
|
508 // Could not detach Soap fault (this method was called, but aSoapMessage did not include fault!) |
|
509 HBufC8* pAsXml = apSoapMessage->AsXmlL(); |
|
510 CleanupStack::PopAndDestroy( apSoapMessage ); // de-alloc, serialization ok |
|
511 retVal = aConsumer.HandleErrorL(pAsXml, aErrorCode, aTxnId, aResponseTransportProperties); |
|
512 } |
|
513 } |
|
514 else |
|
515 { |
|
516 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"Fatal(!): CSenWebServiceSession::HandleSoapFaultL - apSoapMessage arg is NULL. "); |
|
517 retVal = aConsumer.HandleErrorL(NULL, aErrorCode, aTxnId, aResponseTransportProperties); |
|
518 } |
|
519 return retVal; |
|
520 } |
|
521 |
|
522 EXPORT_C TInt CSenWebServiceSession::SendToConsumerL( HBufC8* apMessage, |
|
523 const TInt aTxnId, |
|
524 MSenRemoteServiceConsumer& aConsumer, |
|
525 MSenProperties* aResponseTransportProperties ) |
|
526 { |
|
527 CleanupStack::PushL( apMessage ); |
|
528 CSLOG_L( aConsumer.ConnectionId(), KMinLogLevel,"CSenWebServiceSession::SendToConsumerL - begin" ); |
|
529 TInt retVal(KErrNone); |
|
530 |
|
531 // Check whether this is a response to one-way request; in such case, |
|
532 // there is no body to validate (but only few response properties): |
|
533 if ( aResponseTransportProperties ) |
|
534 { |
|
535 TBool isOnewayMsgRsp(EFalse); |
|
536 aResponseTransportProperties->BoolPropertyL( KSenOnewayMessageOnOff, isOnewayMsgRsp ); |
|
537 if ( isOnewayMsgRsp ) |
|
538 { |
|
539 // There is no response body to process, halt the execution of this method in here, |
|
540 // and invoke the consumer immediately: |
|
541 CSLOG_L( aConsumer.ConnectionId(), KMinLogLevel,"-- About to invoke MSenRemoteServiceConsumer::HandleMessageL" ); |
|
542 CleanupStack::Pop( apMessage ); |
|
543 retVal = aConsumer.HandleMessageL( apMessage, aTxnId, aResponseTransportProperties ); |
|
544 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("CSenWebServiceSession::SendToConsumerL - end: HandleMessageL returned: %d"), retVal)); |
|
545 return retVal; // skip the SOAP validation, response carries no body |
|
546 } |
|
547 } |
|
548 |
|
549 |
|
550 // SOAP orientated implementation: |
|
551 CSenSoapMessage* pSoapMessage = NULL; |
|
552 TInt leaveCode(KErrNone); |
|
553 |
|
554 if( apMessage && apMessage->Length() > 0 ) |
|
555 { |
|
556 TRAP( leaveCode, retVal = ParseResponseL( *apMessage, pSoapMessage ); ) |
|
557 } |
|
558 else // apMessage == NULL or descriptor is of zero-length |
|
559 { |
|
560 if ( !apMessage ) |
|
561 { |
|
562 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Note: apMessage argument is NULL => response is treated through KErrSenNoSoapBody"); |
|
563 } |
|
564 retVal = KErrSenNoSoapBody; // clearly, WSS assumes that all messages are SOAP! |
|
565 } |
|
566 |
|
567 if( leaveCode != KErrNone ) |
|
568 { |
|
569 // Parsing WAS attempted, but it failed(!) |
|
570 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SendToConsumerL"); |
|
571 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- Error: response could not be parsed into SOAP msg, leave code from parse: %d"), leaveCode)); |
|
572 pSoapMessage = NULL; |
|
573 if( retVal==KErrNone ) |
|
574 { |
|
575 // indicate with return value, that response is |
|
576 // invalid - even though submit was ok, the |
|
577 // response could NOT be parsed! |
|
578 retVal = leaveCode; |
|
579 } |
|
580 } |
|
581 |
|
582 if(retVal == KErrNone) |
|
583 { |
|
584 CleanupStack::PopAndDestroy(apMessage); |
|
585 CleanupStack::PushL( pSoapMessage ); |
|
586 // Response was parsed OK, now check whether it is a SOAP fault: |
|
587 if (pSoapMessage->IsFault()) |
|
588 { |
|
589 CleanupStack::Pop(pSoapMessage); // next method takes the ownership: |
|
590 retVal = HandleSoapFaultL(pSoapMessage, KErrSenSoapFault, aTxnId, aConsumer, aResponseTransportProperties); |
|
591 if( retVal == KErrSenSoapFault ) |
|
592 { |
|
593 // SOAP fault response is treated as "OK" |
|
594 retVal = KErrNone; |
|
595 } |
|
596 } |
|
597 else |
|
598 { |
|
599 // Response is a valid SOAP envelope |
|
600 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel ,"CSenWebServiceSession::SendToConsumerL:"); |
|
601 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel ,"- Sending SOAP message to consumer."); |
|
602 CleanupStack::Pop(pSoapMessage); // next method takes the ownership: |
|
603 retVal = SendSoapMessageToConsumerL( pSoapMessage, aTxnId, aConsumer, aResponseTransportProperties ); |
|
604 #ifdef _SENDEBUG |
|
605 if( retVal!=KErrNone ) |
|
606 { |
|
607 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SendToConsumerL:"); |
|
608 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- SendSoapMessageToConsumerL failed: %d"), retVal )); |
|
609 } |
|
610 #endif |
|
611 } |
|
612 } |
|
613 else // error recognized |
|
614 { |
|
615 delete pSoapMessage; |
|
616 pSoapMessage = NULL; |
|
617 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SendToConsumerL"); |
|
618 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Error: response is not a SOAP message!"); |
|
619 |
|
620 CleanupStack::Pop(apMessage); |
|
621 retVal = HandleErrorL(retVal, apMessage, aTxnId, aConsumer, aResponseTransportProperties); |
|
622 } |
|
623 CSLOG_L( aConsumer.ConnectionId(), KMinLogLevel,"CSenWebServiceSession::SendToConsumerL - end" ); |
|
624 return retVal; |
|
625 } |
|
626 |
|
627 // THIS IS WHAT TRANSPORT SEES: |
|
628 EXPORT_C TInt CSenWebServiceSession::SendErrorToConsumerL( const TInt aErrorCode, |
|
629 HBufC8* apError, |
|
630 const TInt aTxnId, |
|
631 MSenRemoteServiceConsumer& aConsumer, |
|
632 MSenProperties* aResponseTransportProperties ) |
|
633 { |
|
634 CleanupStack::PushL(apError); |
|
635 TInt retVal(KErrNone); |
|
636 |
|
637 // Check whether this is a response to one-way request; in such case, |
|
638 // there is no body to validate (but only few response properties): |
|
639 if ( aResponseTransportProperties ) |
|
640 { |
|
641 TBool isOnewayMsgRsp(EFalse); |
|
642 aResponseTransportProperties->BoolPropertyL( KSenOnewayMessageOnOff, isOnewayMsgRsp ); |
|
643 if ( isOnewayMsgRsp ) |
|
644 { |
|
645 // There is no response body to process, halt the execution of this method in here, |
|
646 // and invoke the consumer immediately: |
|
647 CSLOG_L( aConsumer.ConnectionId(), KMinLogLevel,"-- About to invoke MSenRemoteServiceConsumer::HandleMessageL" ); |
|
648 CleanupStack::Pop( apError ); |
|
649 retVal = aConsumer.HandleErrorL( apError, aErrorCode, aTxnId, aResponseTransportProperties ); |
|
650 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("CSenWebServiceSession::SendToConsumerL - end: HandleMessageL returned: %d"), retVal)); |
|
651 return retVal; // skip the SOAP validation, response carries no body |
|
652 } |
|
653 } |
|
654 |
|
655 // SOAP orientated implementation: |
|
656 CSenSoapMessage* pSoapMessage = NULL; |
|
657 |
|
658 TInt leaveCode(KErrNone); |
|
659 |
|
660 if( apError && apError->Length() > 0 ) |
|
661 { |
|
662 TRAP( leaveCode, retVal = ParseResponseL( *apError, pSoapMessage ); ) |
|
663 } |
|
664 else // apMessage == NULL or descriptor is of zero-length |
|
665 { |
|
666 if ( !apError ) |
|
667 { |
|
668 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Note: apError argument is NULL => response is treated through KErrSenNoSoapBody"); |
|
669 } |
|
670 retVal = KErrSenNoSoapBody; // clearly, WSS assumes that all messages are SOAP! |
|
671 } |
|
672 |
|
673 if( leaveCode != KErrNone ) |
|
674 { |
|
675 // Parsing WAS attempted, but it failed(!) |
|
676 pSoapMessage = NULL; |
|
677 |
|
678 // THE RESPONSE IS NOT SOAP |
|
679 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SendErrorToConsumerL"); |
|
680 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Error: response could not be parsed into SOAP msg!"); |
|
681 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- ParseResponseL leaved: %d"), leaveCode )); |
|
682 if( aErrorCode == KErrNone ) |
|
683 { |
|
684 // In this rare case, indicate that SOAP envelope was broken! |
|
685 // So, return KErrSenBrokenSoapEnvelope in here. |
|
686 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- aErrorCode==KErrNone, but SOAP env is broken!"); |
|
687 |
|
688 CleanupStack::Pop(apError); |
|
689 retVal = HandleErrorL(KErrSenBrokenSoapEnvelope, apError, aTxnId, aConsumer, aResponseTransportProperties); |
|
690 } |
|
691 else |
|
692 { |
|
693 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- Returning error code received from transport: %d"), |
|
694 aErrorCode)); |
|
695 |
|
696 CleanupStack::Pop(apError); |
|
697 retVal = HandleErrorL(aErrorCode, apError, aTxnId, aConsumer, aResponseTransportProperties); |
|
698 } |
|
699 } |
|
700 else // ParseResponseL did not leave |
|
701 { |
|
702 if (retVal == KErrNone ) |
|
703 { |
|
704 CleanupStack::PopAndDestroy(apError); |
|
705 // ParseResponseL OK |
|
706 // Call for functionality which checks certain, "recoverable" SOAP errors: |
|
707 // Some frameworks might be able to handle certain SOAP faults themselves |
|
708 retVal = HandleSoapFaultL(pSoapMessage, aErrorCode, aTxnId, aConsumer, aResponseTransportProperties); |
|
709 } |
|
710 else // parsing failed or apError == NULL |
|
711 { |
|
712 delete pSoapMessage; |
|
713 // ParseResponseL NOT ok! |
|
714 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SendErrorToConsumerL"); |
|
715 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Error: response is not a SOAP message!"); |
|
716 if ( aErrorCode == KErrNone ) |
|
717 { |
|
718 // Rare case: for some odd reason transport did not return error code: |
|
719 // - return the error code from ParseResponseL |
|
720 CSLOG_L(aConsumer.ConnectionId() , KNormalLogLevel,"- Transport did not return error code."); |
|
721 CleanupStack::Pop(apError); |
|
722 retVal = HandleErrorL(retVal, apError, aTxnId, aConsumer, aResponseTransportProperties); |
|
723 } |
|
724 else |
|
725 { |
|
726 // Just pass forward the error code received from transport: |
|
727 CSLOG_L(aConsumer.ConnectionId() , KNormalLogLevel,"- Just pass forward error code from transport."); |
|
728 CleanupStack::Pop(apError); |
|
729 retVal = HandleErrorL(aErrorCode, apError, aTxnId, aConsumer, aResponseTransportProperties); |
|
730 } |
|
731 } |
|
732 } |
|
733 return retVal; |
|
734 } |
|
735 |
|
736 EXPORT_C TInt CSenWebServiceSession::HandleErrorL( const TInt aErrorCode, |
|
737 HBufC8* apError, |
|
738 const TInt aTxnId, |
|
739 MSenRemoteServiceConsumer& aConsumer, |
|
740 MSenProperties* aResponseTransportProperties ) |
|
741 { |
|
742 // Current implementation does not handle non-SOAP errors |
|
743 // that occured at transport layer. Instead, the error is |
|
744 // simply passed to consumer: |
|
745 return aConsumer.HandleErrorL(apError, aErrorCode, aTxnId, aResponseTransportProperties); |
|
746 // Frameworks should override this method in order to recover |
|
747 // from specific errors/faults |
|
748 } |
|
749 |
|
750 |
|
751 EXPORT_C CSenXmlReader* CSenWebServiceSession::XmlReader() |
|
752 { |
|
753 return iFramework.Manager().XMLReader(); |
|
754 } |
|
755 |
|
756 EXPORT_C TInt CSenWebServiceSession::ParseResponseL(const TDesC8& aResponse, |
|
757 CSenSoapMessage*& aMessage) |
|
758 { |
|
759 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::ParseResponseL(TDesC8&, CSenSoapMessage*&"); |
|
760 |
|
761 TInt retVal(KErrNone); |
|
762 retVal = NewMessageL(aMessage); |
|
763 |
|
764 CleanupStack::PushL(aMessage); |
|
765 |
|
766 if (retVal != KErrNone) |
|
767 { |
|
768 return retVal; |
|
769 } |
|
770 |
|
771 ////////////////////////////////////////////////////////////////////////// |
|
772 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMaxLogLevel ,(_L("******************************************************"))); |
|
773 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMaxLogLevel , _L("Response to be parsed (%d bytes):"), aResponse.Length())); |
|
774 { |
|
775 TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase , KMaxLogLevel ,aResponse); |
|
776 //FILELOGALL(_L("WsLog"), _L("last_rsp.xml"), aResponse); |
|
777 } |
|
778 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMaxLogLevel ,(_L("******************************************************"))); |
|
779 ////////////////////////////////////////////////////////////////////////// |
|
780 |
|
781 aMessage->SetReader(*XmlReader()); |
|
782 TInt leaveCode(KErrNone); |
|
783 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"- Parsing response into SOAP message object:"); |
|
784 TBool normalParsing(ETrue); |
|
785 if ( aResponse.Size() > KSenMaxLengthSaxParsingSoapMsg ) |
|
786 { |
|
787 TInt ret(KErrNotFound); |
|
788 TRAP(leaveCode, ret = HandleBodyWithoutParsingL(*aMessage, aResponse);) |
|
789 if (leaveCode == KErrNone && ret == KErrNone) |
|
790 { |
|
791 normalParsing = EFalse; |
|
792 } |
|
793 } |
|
794 |
|
795 if ( normalParsing ) |
|
796 { |
|
797 TRAP(leaveCode, aMessage->ParseL(aResponse)); |
|
798 } |
|
799 |
|
800 if(leaveCode==KErrNone) |
|
801 { |
|
802 #ifdef _SENDEBUG |
|
803 /////////////////////////////////////////////////////////////////////// |
|
804 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMaxLogLevel ,(_L("---------------------------------------------------"))); |
|
805 HBufC8* pAsXml = aMessage->AsXmlL(); |
|
806 if(pAsXml) |
|
807 { |
|
808 CleanupStack::PushL(pAsXml); |
|
809 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::ParseResponseL: OK!"); |
|
810 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMaxLogLevel , _L(" SOAP message (%d bytes)"), |
|
811 pAsXml->Length())); |
|
812 TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase , KMaxLogLevel ,(*pAsXml)); |
|
813 CleanupStack::PopAndDestroy(); //pAsXml |
|
814 } |
|
815 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMaxLogLevel ,(_L("---------------------------------------------------"))); |
|
816 /////////////////////////////////////////////////////////////////////// |
|
817 #endif // _SENDEBUG |
|
818 retVal = ParseMessageL(*aMessage); |
|
819 } |
|
820 else |
|
821 { |
|
822 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"- Response is not SOAP message!"); |
|
823 retVal = leaveCode; |
|
824 } |
|
825 CleanupStack::Pop(); // aMessage |
|
826 return retVal; |
|
827 } |
|
828 |
|
829 EXPORT_C TInt CSenWebServiceSession::ParseMessageL(CSenSoapMessage& aSoapMessage) |
|
830 { |
|
831 // We can verify, that SOAP message has Body: |
|
832 if(!aSoapMessage.HasBody()) |
|
833 { |
|
834 return KErrSenNoSoapBody; |
|
835 } |
|
836 else |
|
837 { |
|
838 return KErrNone; |
|
839 } |
|
840 /** |
|
841 * We could verify wsse:Security headers |
|
842 * but we don't have a need for that right now. |
|
843 */ |
|
844 } |
|
845 |
|
846 EXPORT_C TInt CSenWebServiceSession::AddConsumerL(MSenRemoteServiceConsumer& aConsumer) |
|
847 { |
|
848 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::AddConsumerL"); |
|
849 iConsumerList.Reset(); |
|
850 TInt retVal = iConsumerList.Append(&aConsumer); |
|
851 return retVal; |
|
852 } |
|
853 |
|
854 // 2005: refactored GetConsumer() to Consumer() |
|
855 // Note: Same as client() in Java Ref. Impl. |
|
856 EXPORT_C MSenRemoteServiceConsumer* CSenWebServiceSession::Consumer() |
|
857 { |
|
858 TInt count(iConsumerList.Count()); |
|
859 if(count>0) |
|
860 { |
|
861 return iConsumerList[0]; |
|
862 } |
|
863 else |
|
864 { |
|
865 return NULL; |
|
866 } |
|
867 } |
|
868 |
|
869 EXPORT_C TBool CSenWebServiceSession::IsReadyL() |
|
870 { |
|
871 return (CSenServiceSession::StatusL() == KSenConnectionStatusReady); |
|
872 } |
|
873 |
|
874 EXPORT_C TInt CSenWebServiceSession::SubmitL(const TDesC8& aMessage, |
|
875 const TDesC8& aTransportProperties, |
|
876 MSenRemoteServiceConsumer& aConsumer, |
|
877 HBufC8*& aResponse /*, |
|
878 CSenTransportProperities*& apResponseTransportProperties */) |
|
879 { |
|
880 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitL"); |
|
881 |
|
882 CSenSoapMessage* pMsg = NULL; |
|
883 TInt retVal( MessageForSendingL(aMessage, aConsumer.Id(), pMsg) ); |
|
884 CleanupStack::PushL(pMsg); |
|
885 |
|
886 if(retVal!=KErrNone) |
|
887 { |
|
888 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- MessageForSendingL returned an error: %d"), retVal)); |
|
889 CleanupStack::PopAndDestroy(); // pMsg |
|
890 return retVal; |
|
891 } |
|
892 |
|
893 HBufC8* pHttpBody = pMsg->AsXmlL(); |
|
894 if ( pHttpBody ) |
|
895 { |
|
896 TPtrC8 endpoint = Endpoint(); |
|
897 CleanupStack::PushL(pHttpBody); |
|
898 TPtr8 httpBody = pHttpBody->Des(); |
|
899 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"////////////////////////////////////////////////////////"); |
|
900 CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Endpoint: %S"), &endpoint)); |
|
901 CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Message (%d) about to submit:"), |
|
902 httpBody.Length())); |
|
903 //CSLOG_ALL(aConsumer.ConnectionId() , KMaxLogLevel,(httpBody)); |
|
904 //wslog FILELOGALL(_L("WsLog"), _L("last_req.xml"), httpBody); |
|
905 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"////////////////////////////////////////////////////////"); |
|
906 |
|
907 |
|
908 MSenTransport& transport = aConsumer.TransportL(); |
|
909 retVal = transport.SubmitL(endpoint, httpBody, aTransportProperties, aResponse, aConsumer); |
|
910 |
|
911 CleanupStack::PopAndDestroy(); // pHttpBody |
|
912 } |
|
913 |
|
914 CleanupStack::PopAndDestroy(); // pMsg |
|
915 |
|
916 if ( !aResponse ) |
|
917 { |
|
918 // Response was NULL: probably either out |
|
919 // of heap or some transport malfunction. |
|
920 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitL:"); |
|
921 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Received NULL from transport."); |
|
922 return retVal; |
|
923 } |
|
924 |
|
925 else if( aResponse->Length() < KSenSoapEnvelopeName().Length()*2 ) |
|
926 { |
|
927 // No use parsing, Envelope -root element not there |
|
928 |
|
929 // deliver non-soap body to consumer |
|
930 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitL:"); |
|
931 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- response is not a SOAP envelope."); |
|
932 return retVal; |
|
933 } |
|
934 |
|
935 CSenSoapMessage* pResponseSoapMsg = NULL; |
|
936 TInt leaveCode(KErrNone); |
|
937 TInt parseRetVal(KErrNone); |
|
938 TRAP( leaveCode, parseRetVal = ParseResponseL(*aResponse, pResponseSoapMsg)); |
|
939 |
|
940 if( leaveCode!=KErrNone ) // parsing leaved! |
|
941 { |
|
942 |
|
943 pResponseSoapMsg = NULL; |
|
944 |
|
945 // Return directly the response, which was received from |
|
946 // transport. Note that pResponseSoapMsg has already |
|
947 // been deleted because of leave |
|
948 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel , "CSenWebServiceSession::SubmitL:"); |
|
949 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel , "- Error: response could not be parsed into SOAP msg!"); |
|
950 |
|
951 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- ParseResponseL leaved: %d"), leaveCode )); |
|
952 |
|
953 retVal = leaveCode; |
|
954 // else return the error code received from transport (retVal) |
|
955 } |
|
956 else // parsing did not leave.. |
|
957 { |
|
958 if ( parseRetVal != KErrNone ) // .. but parsing failed |
|
959 { |
|
960 // Not mandatory, ParseResponseL should take |
|
961 // care of gc, if it returns an error: |
|
962 delete pResponseSoapMsg; |
|
963 |
|
964 // NOTE - 2005 change: now the body of such |
|
965 // response will be returned to the caller |
|
966 // (with the error code). |
|
967 |
|
968 // Response could not be parsed into SOAP message(!) |
|
969 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- Response could not be parsed, error: (%d)"), |
|
970 parseRetVal)); |
|
971 |
|
972 if(retVal==KErrNone) |
|
973 { |
|
974 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Returning error code from ParseResponseL"); |
|
975 // transport did not return error, return error from ParseResponseL |
|
976 retVal = parseRetVal; |
|
977 } |
|
978 // else: return the error code received from transport |
|
979 } |
|
980 else // .. and parsing went ok |
|
981 { |
|
982 CleanupStack::PushL( pResponseSoapMsg ); |
|
983 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Response is a SOAP message"); |
|
984 |
|
985 // Check whether "complete server messages" is on or off |
|
986 TBool completeServerMessages(EFalse); |
|
987 HasFacetL(KCompleteMessagesFacet, completeServerMessages); |
|
988 |
|
989 // Response is OK and SOAP message. |
|
990 if( pResponseSoapMsg->IsFault() ) |
|
991 { |
|
992 // Response is a SOAP fault |
|
993 retVal = KErrSenSoapFault; // might change, if framework handles this fault |
|
994 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"Response is a SOAP fault. Calling HandleErrorL."); |
|
995 |
|
996 // Check if SOAP fault could be handled by the framework: |
|
997 HBufC8* pResponse = NULL; |
|
998 |
|
999 // Note that HandleSoapFaultL -method normally detaches any SOAP fault: |
|
1000 CleanupStack::Pop(pResponseSoapMsg); |
|
1001 retVal = HandleSoapFaultL(pResponseSoapMsg, pResponse); |
|
1002 if(retVal == KErrSenSoapFault) |
|
1003 { |
|
1004 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitL:"); |
|
1005 if( completeServerMessages ) |
|
1006 { |
|
1007 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Returning SOAP envelope with fault"); |
|
1008 // The following lines are important when there is a resending |
|
1009 // the new response is copied to aResponse. |
|
1010 // When there is no resend, then pResponse = NULL no copy happens |
|
1011 if(pResponse) |
|
1012 { |
|
1013 delete aResponse; |
|
1014 aResponse = pResponse; |
|
1015 } |
|
1016 // aResponse will be returned (original response from transport) |
|
1017 } |
|
1018 else // we can pass the detached fault |
|
1019 { |
|
1020 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Returning detached a SOAP fault."); |
|
1021 // Destroy the original response buffer received from transport, |
|
1022 // since now the parsed SOAP envelope can be returned |
|
1023 delete aResponse; |
|
1024 aResponse = pResponse; |
|
1025 } |
|
1026 } |
|
1027 else if ( retVal == KErrNone ) |
|
1028 { |
|
1029 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitL:"); |
|
1030 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Framework handled this SOAP fault."); |
|
1031 // KErrNone means that fault was handled |
|
1032 // properly (by framework spesific code) |
|
1033 // and consumer may receive the response |
|
1034 // it requested. |
|
1035 |
|
1036 // Currently there are no SOAP faults handled |
|
1037 // in WebServiceSession class, so KErrNone is |
|
1038 // never returned. This if -section is here |
|
1039 // only for *frameworks to extend*. |
|
1040 |
|
1041 // Destroy the original response buffer received from transport, |
|
1042 // since now the parsed SOAP envelope can be returned |
|
1043 delete aResponse; |
|
1044 aResponse = pResponse; |
|
1045 } |
|
1046 else if ( retVal == KErrNotFound ) |
|
1047 { |
|
1048 // SOAP fault element could not be found |
|
1049 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitL - MAJOR:"); |
|
1050 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"-IsFault()==true BUT fault element NOT found!"); |
|
1051 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"-returning KErrSenBrokenSoapFault"); |
|
1052 retVal = KErrSenBrokenSoapFault; |
|
1053 // Note: 2005 change: now the broken (original) response |
|
1054 // from the transport is returned, instead of NULL |
|
1055 } |
|
1056 #ifdef _SENDEBUG |
|
1057 else |
|
1058 { |
|
1059 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitL:"); |
|
1060 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- HandleErrorL failed: %d"), retVal)); |
|
1061 } |
|
1062 #endif // _SENDEBUG |
|
1063 |
|
1064 } |
|
1065 else // This SOAP envelope is NOT a fault |
|
1066 { |
|
1067 if ( completeServerMessages ) |
|
1068 { |
|
1069 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitL:"); |
|
1070 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Returning complete SOAP envelope."); |
|
1071 // Destroy the original response buffer received from |
|
1072 // transport, since now the parsed SOAP envelope can |
|
1073 // be returned |
|
1074 |
|
1075 delete aResponse; |
|
1076 aResponse = NULL; |
|
1077 aResponse = pResponseSoapMsg->AsXmlL(); |
|
1078 } |
|
1079 else |
|
1080 { |
|
1081 HBufC8* pBody = pResponseSoapMsg->BodyAsStringL(); |
|
1082 if(pBody) |
|
1083 { |
|
1084 // Destroy the original response buffer received from |
|
1085 // transport, since now the SOAP body must be returned |
|
1086 delete aResponse; |
|
1087 aResponse = pBody; |
|
1088 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitL:"); |
|
1089 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Detached SOAP message body."); |
|
1090 } |
|
1091 else |
|
1092 { |
|
1093 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitL:"); |
|
1094 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Could not detach SOAP body(!) - return KErrSenNoSoapBody"); |
|
1095 retVal = KErrSenNoSoapBody; |
|
1096 } |
|
1097 } |
|
1098 CleanupStack::PopAndDestroy(pResponseSoapMsg); |
|
1099 } |
|
1100 } |
|
1101 } |
|
1102 |
|
1103 #ifdef _SENDEBUG |
|
1104 if(aResponse) |
|
1105 { |
|
1106 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"-------------------------------------------------------------------"); |
|
1107 CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("Submit response (%d bytes):"), |
|
1108 aResponse->Length())); |
|
1109 //CSLOG_ALL(aConsumer.ConnectionId() , KMaxLogLevel,( *aResponse )); |
|
1110 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"-------------------------------------------------------------------"); |
|
1111 } |
|
1112 #endif |
|
1113 |
|
1114 return retVal; |
|
1115 } |
|
1116 |
|
1117 EXPORT_C TInt CSenWebServiceSession::SendL( const TDesC8& aMessage, |
|
1118 const TDesC8& aTransportProperties, |
|
1119 MSenRemoteServiceConsumer& aConsumer, |
|
1120 TInt& aTxnId, |
|
1121 HBufC8*& /*aRevalidationError*/ ) |
|
1122 { |
|
1123 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SendL"); |
|
1124 |
|
1125 CSenSoapMessage* pMsg = NULL; |
|
1126 TInt retVal( MessageForSendingL(aMessage, aConsumer.Id(), pMsg) ); |
|
1127 CleanupStack::PushL(pMsg); |
|
1128 |
|
1129 if(retVal!=KErrNone) |
|
1130 { |
|
1131 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- MessageForSendingL returned an error: %d"), retVal)); |
|
1132 CleanupStack::PopAndDestroy(); // pMsg |
|
1133 return retVal; |
|
1134 } |
|
1135 |
|
1136 HBufC8* pHttpBody = pMsg->AsXmlL(); |
|
1137 if(pHttpBody) |
|
1138 { |
|
1139 TPtrC8 endpoint = Endpoint(); |
|
1140 CleanupStack::PushL(pHttpBody); |
|
1141 TPtr8 httpBody = pHttpBody->Des(); |
|
1142 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"////////////////////////////////////////////////////////"); |
|
1143 CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Endpoint: %S"), &endpoint)); |
|
1144 CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Message (%d bytes) about to send:"), httpBody.Length())); |
|
1145 CSLOG_ALL(aConsumer.ConnectionId() , KMaxLogLevel,(httpBody)); |
|
1146 //wslog FILELOGALL(_L("WsLog"), _L("last_req.xml"), httpBody); |
|
1147 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"////////////////////////////////////////////////////////"); |
|
1148 |
|
1149 MSenTransport& t = aConsumer.TransportL(); |
|
1150 |
|
1151 retVal = t.SendL( endpoint, httpBody, aTransportProperties, *this, aConsumer, aTxnId ); |
|
1152 |
|
1153 CleanupStack::PopAndDestroy(); // pHttpBody |
|
1154 } |
|
1155 |
|
1156 CleanupStack::PopAndDestroy(); // pMsg |
|
1157 return retVal; |
|
1158 } |
|
1159 |
|
1160 |
|
1161 |
|
1162 EXPORT_C void CSenWebServiceSession::SetFrameworkHeadersL(CSenSoapMessage& aMsg) |
|
1163 { |
|
1164 if ( iCredentialPtr.Credential() ) |
|
1165 { |
|
1166 CSenInternalCredential* pCred = iCredentialPtr.Credential(); |
|
1167 HBufC8* pAsXml = pCred->AsXmlL(); |
|
1168 CleanupStack::PushL(pAsXml); |
|
1169 aMsg.SetSecurityHeaderL(*pAsXml); |
|
1170 CleanupStack::PopAndDestroy(pAsXml); |
|
1171 } |
|
1172 else |
|
1173 { |
|
1174 // There is no credential available |
|
1175 aMsg.SetSecurityHeaderL(KNullDesC8); |
|
1176 } |
|
1177 } |
|
1178 |
|
1179 EXPORT_C TInt CSenWebServiceSession::SetUserNameL(TDesC8& aUsername) |
|
1180 { |
|
1181 TInt retVal(KErrNone); |
|
1182 HBufC8* pToken8 = NULL; |
|
1183 |
|
1184 retVal = CSenWsSecurityHeader::UsernameTokenL(aUsername, pToken8); |
|
1185 CleanupStack::PushL(pToken8); |
|
1186 |
|
1187 if(retVal != KErrNone) |
|
1188 { |
|
1189 CleanupStack::PopAndDestroy(1); // token |
|
1190 return retVal; |
|
1191 } |
|
1192 else if(pToken8) |
|
1193 { |
|
1194 if(iSecurity == NULL) |
|
1195 { |
|
1196 iSecurity = pToken8->Des().AllocL(); |
|
1197 } |
|
1198 else |
|
1199 { |
|
1200 TPtr8 ptr = iSecurity->Des(); |
|
1201 |
|
1202 if (ptr.MaxLength() < pToken8->Length() + ptr.Length()) |
|
1203 { |
|
1204 HBufC8* newSecurity = HBufC8::NewLC(pToken8->Length() |
|
1205 +ptr.Length()); |
|
1206 TPtr8 newPtr = newSecurity->Des(); |
|
1207 newPtr.Append(*iSecurity); |
|
1208 newPtr.Append(*pToken8); |
|
1209 delete iSecurity; |
|
1210 iSecurity = newSecurity; |
|
1211 CleanupStack::Pop(); // newSecurity |
|
1212 } |
|
1213 else |
|
1214 { |
|
1215 ptr.Append(*pToken8); |
|
1216 } |
|
1217 } |
|
1218 } |
|
1219 CleanupStack::PopAndDestroy(); // pToken8 |
|
1220 |
|
1221 return retVal; |
|
1222 } |
|
1223 |
|
1224 EXPORT_C TPtrC8 CSenWebServiceSession::Endpoint() |
|
1225 { |
|
1226 if(iEndpoint) |
|
1227 return *iEndpoint; |
|
1228 else |
|
1229 return KNullDesC8(); |
|
1230 } |
|
1231 |
|
1232 EXPORT_C TPtrC8 CSenWebServiceSession::Contract() |
|
1233 { |
|
1234 if(iContract) |
|
1235 return *iContract; |
|
1236 else |
|
1237 return KNullDesC8(); |
|
1238 } |
|
1239 |
|
1240 EXPORT_C TPtrC8 CSenWebServiceSession::FrameworkId() |
|
1241 { |
|
1242 if(iFrameworkId) |
|
1243 return *iFrameworkId; |
|
1244 else |
|
1245 return KNullDesC8(); |
|
1246 } |
|
1247 |
|
1248 EXPORT_C TPtrC8 CSenWebServiceSession::FrameworkVersion() |
|
1249 { |
|
1250 return KNullDesC8(); |
|
1251 } |
|
1252 |
|
1253 EXPORT_C void CSenWebServiceSession::SetContractL(const TDesC8& aContract) |
|
1254 { |
|
1255 HBufC8* pNew = NULL; |
|
1256 if(aContract!=KNullDesC8) |
|
1257 { |
|
1258 pNew = aContract.AllocL(); |
|
1259 } |
|
1260 |
|
1261 delete iContract; |
|
1262 iContract = pNew; |
|
1263 } |
|
1264 |
|
1265 EXPORT_C void CSenWebServiceSession::SetEndPointL(const TDesC8& aEndpoint) |
|
1266 { |
|
1267 HBufC8* pNew =NULL; |
|
1268 if(aEndpoint!=KNullDesC8) |
|
1269 { |
|
1270 pNew = aEndpoint.AllocL(); |
|
1271 } |
|
1272 |
|
1273 delete iEndpoint; |
|
1274 iEndpoint = pNew; |
|
1275 |
|
1276 SetStatusL(); |
|
1277 } |
|
1278 |
|
1279 EXPORT_C void CSenWebServiceSession::SetSecurityL(const TDesC8& aSecurity) |
|
1280 { |
|
1281 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::SetSecurityL"); |
|
1282 TInt retVal(KErrNone); |
|
1283 |
|
1284 if ( aSecurity.Length() < 1 ) |
|
1285 { |
|
1286 delete iSecurity; |
|
1287 iSecurity = NULL; |
|
1288 iCredentialPtr.RemoveCredentialObserver(*this); |
|
1289 iCredentialPtr.Close(); |
|
1290 |
|
1291 // invalidate the session, because we have no credential |
|
1292 //iValidUntil.Set(_L("19000101:")); // way back in history: January 1st 1900 |
|
1293 //acording to ID-WSF no need of reset the credential here |
|
1294 } |
|
1295 else |
|
1296 { |
|
1297 if ( HasSecurity() ) |
|
1298 { |
|
1299 iCredentialPtr.RemoveCredentialObserver(*this); |
|
1300 ((MSenServiceManager&)iFramework.Manager()).UpdateCredentialL( |
|
1301 iCredentialPtr.Credential()->IdentifierL().IdL(), |
|
1302 aSecurity, |
|
1303 retVal); |
|
1304 if ( retVal == KErrNone ) |
|
1305 { |
|
1306 iCredentialPtr.AddCredentialObserverL(*this); |
|
1307 CSenInternalCredential* pCred = iCredentialPtr.Credential(); |
|
1308 |
|
1309 if ( iClientServerInterval.Int64() != 0 ) |
|
1310 { |
|
1311 TBuf8<64> buf; |
|
1312 buf.AppendNum(iClientServerInterval.Int64()); |
|
1313 pCred->PropertiesL().SetPropertyL(KServiceInterval1, buf); |
|
1314 } |
|
1315 FillCredentialIdentifierL(pCred->IdentifierL()); |
|
1316 |
|
1317 TTime validUntil = iValidUntil; |
|
1318 pCred->PropertiesL().SetValidUntilL(validUntil); |
|
1319 } |
|
1320 else |
|
1321 { |
|
1322 delete iSecurity; |
|
1323 iSecurity = NULL; |
|
1324 iCredentialPtr.Close(); |
|
1325 |
|
1326 // invalidate the session, because we have no credential |
|
1327 iValidUntil.Set(KInvalideDate); // way back in history: January 1st 1900 //CodeScannerWarnings |
|
1328 } |
|
1329 } |
|
1330 else |
|
1331 { |
|
1332 RSenCredentialPtr credentialPtr = |
|
1333 ((MSenServiceManager&)iFramework.Manager()).AddCredentialL(aSecurity, retVal); |
|
1334 |
|
1335 if ( retVal == KErrNone ) |
|
1336 { |
|
1337 |
|
1338 iCredentialPtr.RemoveCredentialObserver(*this); |
|
1339 iCredentialPtr.Close(); |
|
1340 iCredentialPtr = credentialPtr.Clone(); |
|
1341 iCredentialPtr.AddCredentialObserverL(*this); //codescannerwarnings |
|
1342 |
|
1343 CSenInternalCredential* pCred = iCredentialPtr.Credential(); |
|
1344 |
|
1345 if ( iClientServerInterval.Int64() != 0 ) |
|
1346 { |
|
1347 TBuf8<64> buf; |
|
1348 buf.AppendNum(iClientServerInterval.Int64()); |
|
1349 pCred->PropertiesL().SetPropertyL(KServiceInterval1, buf); |
|
1350 } |
|
1351 FillCredentialIdentifierL(pCred->IdentifierL()); //codescannerwarnings |
|
1352 |
|
1353 TTime validUntil = iValidUntil; |
|
1354 pCred->PropertiesL().SetValidUntilL(validUntil); |
|
1355 |
|
1356 SetCredentialIdL(pCred->IdentifierL().IdL()); |
|
1357 } |
|
1358 else |
|
1359 { |
|
1360 delete iSecurity; |
|
1361 iSecurity = NULL; |
|
1362 iCredentialPtr.RemoveCredentialObserver(*this); |
|
1363 iCredentialPtr.Close(); |
|
1364 |
|
1365 // invalidate the session, because we have no credential |
|
1366 iValidUntil.Set(KInvalideDate); // way back in history: January 1st 1900 |
|
1367 } |
|
1368 } |
|
1369 } |
|
1370 } |
|
1371 |
|
1372 /* |
|
1373 EXPORT_C TInt CSenWebServiceSession::RemoveConsumerL(MSenRemoteServiceConsumer& aConsumer) |
|
1374 { |
|
1375 LOG_WRITE_L("CSenWebServiceSession::RemoveConsumerL"); |
|
1376 CSenServiceSession::RemoveConsumerL(aConsumer); |
|
1377 |
|
1378 // If this session has no consumers, we can hold our grip to the credential |
|
1379 // (note: this does NOT mean that credential is removed, not at all(!), but |
|
1380 // that new search for the credential has to be performed). |
|
1381 |
|
1382 // NOTE: this cannot be done at ws service session layer as long as ID-WSF does not |
|
1383 // use credential sharing / lookup mechanism in cases where session is found invalid |
|
1384 // (this is done in WS-* framework plug-in) |
|
1385 TInt count(iConsumerList.Count()); |
|
1386 if( count == 0 ) |
|
1387 { |
|
1388 LOG_WRITE_L("- Credential count == 0"); |
|
1389 LOG_WRITE_L("-> Closing the handle to the credential owned by Credential Manager."); |
|
1390 SetSecurityL(KNullDesC8); |
|
1391 } |
|
1392 } |
|
1393 */ |
|
1394 void CSenWebServiceSession::SetCredentialIdL(TInt aCredentialId) |
|
1395 { |
|
1396 TBuf8<KCredIdBufSize> buffer; |
|
1397 buffer.Num(aCredentialId); |
|
1398 |
|
1399 delete iSecurity; |
|
1400 iSecurity = NULL; |
|
1401 TInt leaveCode( KErrNone ); |
|
1402 TRAP( leaveCode, iSecurity = HBufC8::NewL( buffer.Length()+KCredentialIdStart().Length()+KCredentialIdEnd().Length() ); ) |
|
1403 if( !leaveCode && iSecurity ) |
|
1404 { |
|
1405 TPtr8 sec = iSecurity->Des(); |
|
1406 sec.Append( KCredentialIdStart ); |
|
1407 sec.Append( buffer); |
|
1408 sec.Append( KCredentialIdEnd ); |
|
1409 } |
|
1410 #ifdef _SENDEBUG |
|
1411 else |
|
1412 { |
|
1413 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::SetCredentialId(): iSecurity = HBufC8::NewL leaved (OOM)!"); |
|
1414 } |
|
1415 #endif // _SENDEBUG |
|
1416 } |
|
1417 |
|
1418 EXPORT_C TInt CSenWebServiceSession::GetCredentialIdL() |
|
1419 { |
|
1420 TInt retVal(0); |
|
1421 if (HasSecurity()) |
|
1422 { |
|
1423 retVal = iCredentialPtr.Credential()->IdentifierL().IdL(); //codescannerwarnings |
|
1424 } |
|
1425 return retVal; |
|
1426 } |
|
1427 |
|
1428 |
|
1429 EXPORT_C void CSenWebServiceSession::FillCredentialIdentifierL(CSenCredentialIdentifier& aIdentifier) |
|
1430 { |
|
1431 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::FillCredentialIdentifierL"); |
|
1432 if ( iEndpoint ) |
|
1433 { |
|
1434 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KNormalLogLevel , _L8("- Setting endpoint to credential as property: %S"), iEndpoint )); |
|
1435 aIdentifier.SetPropertyL(KEndpointLocalname, *iEndpoint); |
|
1436 } |
|
1437 } |
|
1438 |
|
1439 EXPORT_C TInt CSenWebServiceSession::TryToSearchValidCredentialL() |
|
1440 { |
|
1441 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::TryToSearchValidCredentialL()"); |
|
1442 |
|
1443 // Get CredentialIdentifier which should include ProviderID |
|
1444 CSenCredentialIdentifier* pCredIdentifier = CSenCredentialIdentifier::NewLC(); |
|
1445 FillCredentialIdentifierL(*pCredIdentifier); |
|
1446 |
|
1447 CSenWSDescription* pPattern = CSenWSDescription::NewLC(); |
|
1448 CSenElement& patternElement = ((CSenWSDescription*)pPattern)->AsElement(); |
|
1449 |
|
1450 TPtrC8 providerId(KNullDesC8); |
|
1451 |
|
1452 RXmlEngNodeList<TXmlEngElement> list; |
|
1453 CleanupClosePushL(list); |
|
1454 TXmlEngElement element = pCredIdentifier->AsElementL(); |
|
1455 element.GetChildElements(list); |
|
1456 while ( list.HasNext() ) |
|
1457 { |
|
1458 TXmlEngElement element = list.Next(); |
|
1459 if ( element.Name() != KSenIdpProviderIdLocalname ) |
|
1460 { |
|
1461 CSenElement& addedElement = patternElement.AddElementL(element.Name()); |
|
1462 addedElement.SetContentL(element.Text()); |
|
1463 } |
|
1464 else |
|
1465 { |
|
1466 providerId.Set(element.Text()); |
|
1467 } |
|
1468 } |
|
1469 |
|
1470 CSenIdentityProvider* pIdentityProvider = NULL; |
|
1471 if ( providerId != KNullDesC8 ) |
|
1472 { |
|
1473 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::TryToSearchValidCredentialL():"); |
|
1474 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KNormalLogLevel , _L8("- Trying to search IdentityProvider using ProviderId : %S"), &providerId)); |
|
1475 CSenWSDescription* pIdpPattern = CSenWSDescription::NewLC(); |
|
1476 pIdpPattern->SetEndPointL(providerId); |
|
1477 pIdentityProvider = iFramework.Manager().IdentityProviderL(*pIdpPattern); |
|
1478 CleanupStack::PopAndDestroy(pIdpPattern); |
|
1479 } |
|
1480 |
|
1481 RSenCredentialPtrArray credentialPtrsArray; |
|
1482 CleanupClosePushL(credentialPtrsArray); |
|
1483 |
|
1484 TInt retVal(KErrNone); |
|
1485 if ( pIdentityProvider ) |
|
1486 { |
|
1487 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::TryToSearchValidCredentialL() - IdentityProvider was found. Trying to search related Credentials."); |
|
1488 retVal = ((MSenServiceManager&)iFramework.Manager()).CredentialsL(*pPattern, |
|
1489 *pIdentityProvider, |
|
1490 credentialPtrsArray); |
|
1491 } |
|
1492 else |
|
1493 { |
|
1494 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::TryToSearchValidCredentialL() - FATAL: IdentityProvider was NOT found:"); |
|
1495 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"- Trying to search Credentials without IdentityProvider information."); |
|
1496 retVal = ((MSenServiceManager&)iFramework.Manager()).CredentialsL(*pPattern, |
|
1497 credentialPtrsArray); |
|
1498 } |
|
1499 |
|
1500 if ( (retVal == KErrNone) && (credentialPtrsArray.Count() > 0) ) |
|
1501 { |
|
1502 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KNormalLogLevel ,_L8("CSenWebServiceSession::TryToSearchValidCredentialL(): %d Credentials found."), credentialPtrsArray.Count())); |
|
1503 // Take the first valid Credential from found Credentials array. |
|
1504 TBool credentialOK(EFalse); |
|
1505 TInt count = credentialPtrsArray.Count(); |
|
1506 for (TInt i=0; i < count; i++) |
|
1507 { |
|
1508 SetCredentialPtrL(credentialPtrsArray[0]);//codescannerwarnings |
|
1509 iValidUntil = iCredentialPtr.Credential()->PropertiesL().ValidUntilL(); //codescannerwarnings |
|
1510 |
|
1511 if ( ComputeStatusL() == KSenConnectionStatusReady) |
|
1512 { |
|
1513 credentialOK = ETrue; |
|
1514 break; |
|
1515 } |
|
1516 } |
|
1517 |
|
1518 if ( credentialOK ) |
|
1519 { |
|
1520 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel , _L8("CSenWebServiceSession::TryToSearchValidCredentialL(): Valid Credential were found. CredentialId : %d"), |
|
1521 iCredentialPtr.Credential()->IdentifierL().IdL())); //codescannerwarnings |
|
1522 retVal = KErrNone; |
|
1523 } |
|
1524 else |
|
1525 { |
|
1526 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::TryToSearchValidCredentialL(): Valid Credentials were not found."); |
|
1527 SetSecurityL(KNullDesC8); |
|
1528 retVal = KErrNotFound; |
|
1529 } |
|
1530 } |
|
1531 else |
|
1532 { |
|
1533 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenWebServiceSession::TryToSearchValidCredentialL(): Credentials were not found."); |
|
1534 retVal = KErrNotFound; |
|
1535 } |
|
1536 |
|
1537 CleanupStack::PopAndDestroy(&credentialPtrsArray); |
|
1538 |
|
1539 CleanupStack::PopAndDestroy(&list); // Close() |
|
1540 CleanupStack::PopAndDestroy(pPattern); |
|
1541 CleanupStack::PopAndDestroy(pCredIdentifier); |
|
1542 |
|
1543 return retVal; |
|
1544 } |
|
1545 |
|
1546 EXPORT_C const TTime& CSenWebServiceSession::ValidUntilL() |
|
1547 { |
|
1548 if (iValidUntil != Time::NullTTime()) |
|
1549 { |
|
1550 return iValidUntil; |
|
1551 } |
|
1552 else |
|
1553 { |
|
1554 const TTime& MAX_TIME = Time::MaxTTime(); |
|
1555 return MAX_TIME; // if no expiration was set, the session is |
|
1556 // valid forever(!) |
|
1557 } |
|
1558 } |
|
1559 |
|
1560 EXPORT_C void CSenWebServiceSession::WriteAsXMLToL(RWriteStream& aWriteStream) |
|
1561 { |
|
1562 _LIT8(KTouch, "touch"); |
|
1563 aWriteStream.WriteL(KSDFramework); |
|
1564 aWriteStream.WriteL(FrameworkId()); |
|
1565 CSenElement* elem = &AsElement(); |
|
1566 |
|
1567 const TDesC8* attrVal = elem->AttrValue(KTouch); |
|
1568 if(attrVal != NULL) |
|
1569 { |
|
1570 aWriteStream.WriteL(KSenDblQuot); |
|
1571 aWriteStream.WriteL(KSenSpace); |
|
1572 aWriteStream.WriteL(KTouch); |
|
1573 aWriteStream.WriteL(KSenEqualsDblQuot); |
|
1574 aWriteStream.WriteL(*attrVal); |
|
1575 } |
|
1576 aWriteStream.WriteL(KTagWithAttrEnd); |
|
1577 |
|
1578 // write contract |
|
1579 if(iContract && iContract->Length()>0) |
|
1580 { |
|
1581 aWriteStream.WriteL(KContractStart); |
|
1582 aWriteStream.WriteL(*iContract); |
|
1583 aWriteStream.WriteL(KContractEnd); |
|
1584 } |
|
1585 |
|
1586 // write endpoint |
|
1587 TPtrC8 cue = TransportCue(); |
|
1588 if(iEndpoint && iEndpoint->Length()>0) |
|
1589 { |
|
1590 if( iTransportCue && iTransportCue->Length()>0) |
|
1591 { |
|
1592 // both cue and endpoint |
|
1593 aWriteStream.WriteL(KEndPointStartWithCue); |
|
1594 aWriteStream.WriteL(*iTransportCue); |
|
1595 aWriteStream.WriteL(KTagWithAttrEnd); |
|
1596 aWriteStream.WriteL(*iEndpoint); |
|
1597 aWriteStream.WriteL(KEndPointEnd); |
|
1598 |
|
1599 } |
|
1600 else |
|
1601 { |
|
1602 // just endpoint |
|
1603 aWriteStream.WriteL(KEndPointStart); |
|
1604 aWriteStream.WriteL(*iEndpoint); |
|
1605 aWriteStream.WriteL(KEndPointEnd); |
|
1606 } |
|
1607 } |
|
1608 else if ( iTransportCue && iTransportCue->Length() > 0 ) |
|
1609 { |
|
1610 // only cue, but no endpoint |
|
1611 aWriteStream.WriteL(KEndPointStartWithCue); |
|
1612 aWriteStream.WriteL(*iTransportCue); |
|
1613 aWriteStream.WriteL(KTagWithAttrClose); |
|
1614 } |
|
1615 |
|
1616 // write security credentials |
|
1617 if(iSecurity) |
|
1618 { |
|
1619 aWriteStream.WriteL(KCredentialsStart); |
|
1620 if (iValidUntil != Time::NullTTime()) |
|
1621 { |
|
1622 HBufC8* dateDes = HBufC8::NewLC(256); |
|
1623 TPtr8 datePtr = dateDes->Des(); |
|
1624 SenDateUtils::ToXmlDateTimeUtf82L(datePtr, iValidUntil); |
|
1625 HBufC8* tempBuf = HBufC8::NewLC(KNotOnOrAfterFormat().Length() + |
|
1626 datePtr.Length()); |
|
1627 |
|
1628 TPtr8 ptr = tempBuf->Des(); |
|
1629 ptr.Format(KNotOnOrAfterFormat, dateDes); |
|
1630 |
|
1631 aWriteStream.WriteL(ptr); |
|
1632 CleanupStack::PopAndDestroy(2); // tempBuf, dateDes |
|
1633 tempBuf = NULL; |
|
1634 } |
|
1635 else |
|
1636 { |
|
1637 aWriteStream.WriteL(KEmptyTagEnd); |
|
1638 } |
|
1639 |
|
1640 aWriteStream.WriteL(*iSecurity); |
|
1641 aWriteStream.WriteL(KCredentialsEnd); |
|
1642 } |
|
1643 |
|
1644 CSenElement* pProviderPolicyElement = |
|
1645 AsElement().Element(KProviderPolicyLocalName); |
|
1646 |
|
1647 if(pProviderPolicyElement) |
|
1648 { |
|
1649 HBufC8* pProviderPolicyAsXmlUtf8 = pProviderPolicyElement->AsXmlL(); |
|
1650 if(pProviderPolicyAsXmlUtf8) |
|
1651 { |
|
1652 CleanupStack::PushL(pProviderPolicyAsXmlUtf8); |
|
1653 aWriteStream.WriteL(*pProviderPolicyAsXmlUtf8); |
|
1654 CleanupStack::PopAndDestroy(); // pProviderPolicyAsXmlUtf8 |
|
1655 } |
|
1656 } |
|
1657 |
|
1658 WriteExtensionsAsXMLToL(aWriteStream); |
|
1659 |
|
1660 //Writing the ServicePolicy to XML |
|
1661 MSenServicePolicy* servicePolicy = ServicePolicy(); |
|
1662 if(servicePolicy) |
|
1663 { |
|
1664 CSenServicePolicy* ele = (CSenServicePolicy*)servicePolicy; |
|
1665 CSenElement* pServicePolicyElement = &ele->AsElement(); |
|
1666 if(pServicePolicyElement) |
|
1667 { |
|
1668 HBufC8* pServicePolicyAsXmlUtf8 = pServicePolicyElement->AsXmlL(); |
|
1669 if(pServicePolicyAsXmlUtf8) |
|
1670 { |
|
1671 CleanupStack::PushL(pServicePolicyAsXmlUtf8); |
|
1672 aWriteStream.WriteL(*pServicePolicyAsXmlUtf8); |
|
1673 CleanupStack::PopAndDestroy(); // pProviderPolicyAsXmlUtf8 |
|
1674 } |
|
1675 } |
|
1676 } |
|
1677 |
|
1678 aWriteStream.WriteL(KSDEnd); |
|
1679 aWriteStream.WriteL(KNewLine); |
|
1680 |
|
1681 |
|
1682 |
|
1683 } |
|
1684 |
|
1685 |
|
1686 |
|
1687 EXPORT_C TInt CSenWebServiceSession::SubmitSoapL(const TDesC8& aSoapMessage, |
|
1688 const TDesC8& aTransportProperties, |
|
1689 MSenRemoteServiceConsumer& aConsumer, |
|
1690 HBufC8*& aResponse) |
|
1691 { |
|
1692 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1693 TPtrC8 endpoint = Endpoint(); |
|
1694 #ifdef _SENDEBUG |
|
1695 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"////////////////////////////////////////////////////////"); |
|
1696 CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Endpoint: %S"), &endpoint)); |
|
1697 CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Message (%d bytes) about to submit:"), aSoapMessage.Length())); |
|
1698 CSLOG_ALL(aConsumer.ConnectionId() , KMaxLogLevel,( aSoapMessage )); |
|
1699 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"////////////////////////////////////////////////////////"); |
|
1700 #endif |
|
1701 |
|
1702 MSenTransport& t = aConsumer.TransportL(); |
|
1703 |
|
1704 TInt retVal = t.SubmitL(endpoint, aSoapMessage, aTransportProperties, aResponse, aConsumer); |
|
1705 |
|
1706 if(!aResponse) |
|
1707 { |
|
1708 // Response was NULL: probably either out |
|
1709 // of heap or some transport malfunction. |
|
1710 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1711 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Received NULL from transport."); |
|
1712 return retVal; |
|
1713 } |
|
1714 else if(aResponse->Length() < KSenSoapEnvelopeName().Length()*2) |
|
1715 { |
|
1716 // No use parsing, Envelope -root element not there. |
|
1717 // Just deliver this "non-soap" response to consumer |
|
1718 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1719 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Response is not a SOAP envelope."); |
|
1720 return retVal; |
|
1721 } |
|
1722 |
|
1723 // Attempt to parse the response here. SOAP faults |
|
1724 // are to be searched after, |
|
1725 CSenSoapMessage* pResponseSoapMsg = NULL; |
|
1726 TInt leaveCode(KErrNone); |
|
1727 TInt parseRetCode(KErrNone); |
|
1728 TRAP( leaveCode, (parseRetCode = |
|
1729 ParseResponseL(*aResponse, pResponseSoapMsg)) ); |
|
1730 |
|
1731 if(leaveCode!=KErrNone) |
|
1732 { |
|
1733 // Return directly the response, which was received from |
|
1734 // transport. Note that pResponseSoapMsg has already |
|
1735 // been deleted because of leave |
|
1736 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1737 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8(" - ParseResponseL leaved: %d"), leaveCode )); |
|
1738 |
|
1739 if(retVal==KErrNone) // retVal still SubmitL() return value |
|
1740 { |
|
1741 // Indicate with return value, that response is |
|
1742 // invalid - even though submit was ok, the |
|
1743 // response could NOT be parsed(!). |
|
1744 retVal = leaveCode; |
|
1745 } |
|
1746 } |
|
1747 else // ParseResponseL did not leave.. |
|
1748 { |
|
1749 if(parseRetCode != KErrNone) // .. but returned an error |
|
1750 { |
|
1751 // Not mandatory, ParseResponseL should take |
|
1752 // care of gc, if it returns an error: |
|
1753 delete pResponseSoapMsg; |
|
1754 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1755 |
|
1756 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- Parsing failed, error: %d"), |
|
1757 parseRetCode)); |
|
1758 |
|
1759 if(retVal==KErrNone) // submit was ok |
|
1760 { |
|
1761 // Indicate with return value, that response is |
|
1762 // invalid - even though submit was ok, the |
|
1763 // response could NOT be parsed! |
|
1764 retVal = parseRetCode; |
|
1765 } |
|
1766 } |
|
1767 else // .. and parsing was successful |
|
1768 { |
|
1769 CleanupStack::PushL(pResponseSoapMsg); |
|
1770 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1771 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Response is a SOAP message"); |
|
1772 |
|
1773 TBool completeServerMessages(ETrue); |
|
1774 HasFacetL(KCompleteMessagesFacet, completeServerMessages); |
|
1775 |
|
1776 // response is OK and in SOAP form. |
|
1777 if(pResponseSoapMsg->IsFault()) |
|
1778 { |
|
1779 // Response is a SOAP fault |
|
1780 retVal = KErrSenSoapFault; // might change, if framework handles this fault |
|
1781 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1782 |
|
1783 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Response is a SOAP fault. Calling HandleErrorL."); |
|
1784 |
|
1785 // Check if this SOAP fault could be handled by the framework |
|
1786 HBufC8* pResponse = NULL; |
|
1787 CleanupStack::Pop(pResponseSoapMsg); |
|
1788 retVal = HandleSoapFaultL(pResponseSoapMsg, pResponse/*, aResponseTransportProperties */); |
|
1789 |
|
1790 if(retVal == KErrSenSoapFault) |
|
1791 { |
|
1792 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1793 if(completeServerMessages) |
|
1794 { |
|
1795 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Returning SOAP envelope with fault"); |
|
1796 // The following lines are important when there is a resending |
|
1797 // the new response is copied to aResponse. |
|
1798 // When there is no resend, then pResponse = NULL no copy happens |
|
1799 if(pResponse) |
|
1800 { |
|
1801 delete aResponse; |
|
1802 aResponse = pResponse; |
|
1803 } // aResponse will be returned (original response from transport) |
|
1804 } |
|
1805 else // Pass the detached fault |
|
1806 { |
|
1807 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Returning detached a SOAP fault."); |
|
1808 // Destroy the original response buffer received from transport, |
|
1809 // since now the parsed SOAP envelope can be returned |
|
1810 delete aResponse; |
|
1811 aResponse = pResponse; |
|
1812 } |
|
1813 } |
|
1814 else if(retVal == KErrNone) |
|
1815 { |
|
1816 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1817 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Framework handled this SOAP fault."); |
|
1818 // KErrNone means that fault was handled |
|
1819 // properly (by framework spesific code) |
|
1820 // and consumer may receive the response |
|
1821 // it requested. |
|
1822 |
|
1823 // Currently there are no SOAP faults handled |
|
1824 // in WebServiceSession class, so KErrNone is |
|
1825 // never returned. This if -section is here |
|
1826 // only for *frameworks to extend*. |
|
1827 |
|
1828 // Destroy the original response buffer received from transport, |
|
1829 // since now the parsed SOAP envelope can be returned |
|
1830 delete aResponse; |
|
1831 aResponse = pResponse; |
|
1832 } |
|
1833 else if(retVal==KErrNotFound) |
|
1834 { |
|
1835 // SOAP fault element could not be found |
|
1836 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL - MAJOR:"); |
|
1837 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"-IsFault()==true BUT fault element NOT found!"); |
|
1838 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"-returning KErrSenBrokenSoapFault"); |
|
1839 retVal = KErrSenBrokenSoapFault; |
|
1840 // Note: 2005 change: now the broken (original) response |
|
1841 // from the transport is returned, instead of NULL |
|
1842 } |
|
1843 #ifdef _SENDEBUG |
|
1844 else |
|
1845 { |
|
1846 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1847 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- HandleErrorL failed: %d"), retVal)); |
|
1848 } |
|
1849 #endif // _SENDEBUG |
|
1850 } |
|
1851 else // this SOAP envelope is NOT a fault |
|
1852 { |
|
1853 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1854 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Response is a SOAP envelope."); |
|
1855 |
|
1856 // Check complete server messages on/off |
|
1857 if(!completeServerMessages) |
|
1858 { |
|
1859 HBufC8* pBody = pResponseSoapMsg->BodyAsStringL(); |
|
1860 if(pBody) |
|
1861 { |
|
1862 // Destroy the original response buffer received from transport, |
|
1863 // since now the parsed SOAP envelope can be returned |
|
1864 delete aResponse; |
|
1865 aResponse = pBody; |
|
1866 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1867 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Detached SOAP message body."); |
|
1868 } |
|
1869 else |
|
1870 { |
|
1871 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1872 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- Could not detach SOAP body(!) - return KErrSenNoSoapBody"); |
|
1873 // Note: 2005 change: now the broken (original) response |
|
1874 // from the transport is returned, instead of NULL |
|
1875 retVal = KErrSenNoSoapBody; |
|
1876 } |
|
1877 } |
|
1878 |
|
1879 CleanupStack::PopAndDestroy(pResponseSoapMsg); |
|
1880 } |
|
1881 // else { // return complete server message } |
|
1882 |
|
1883 } |
|
1884 } |
|
1885 |
|
1886 #ifdef _SENDEBUG |
|
1887 if(aResponse) |
|
1888 { |
|
1889 |
|
1890 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"------------------------------------------------------------"); |
|
1891 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"CSenWebServiceSession::SubmitSoapL:"); |
|
1892 CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Response (%d bytes):"), aResponse->Length())); |
|
1893 CSLOG_ALL(aConsumer.ConnectionId() , KMaxLogLevel,( *aResponse )); |
|
1894 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"------------------------------------------------------------"); |
|
1895 } |
|
1896 #endif |
|
1897 return retVal; |
|
1898 } |
|
1899 |
|
1900 EXPORT_C TInt CSenWebServiceSession::SendSoapL( const TDesC8& aSoapMessage, |
|
1901 const TDesC8& aTransportProperties, |
|
1902 MSenRemoteServiceConsumer& aConsumer, |
|
1903 TInt& aTxnId, |
|
1904 HBufC8*& /* aRevalidationError*/ ) // SIFs should utilize aRevalidationError |
|
1905 { |
|
1906 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SendSoapL:"); |
|
1907 TPtrC8 endpoint = Endpoint(); |
|
1908 #ifdef _SENDEBUG |
|
1909 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"////////////////////////////////////////////////////////"); |
|
1910 CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Endpoint: %S:"), &endpoint)); |
|
1911 CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Message (%d bytes) about to send:"), |
|
1912 aSoapMessage.Length())); |
|
1913 CSLOG_ALL(aConsumer.ConnectionId() , KMaxLogLevel,( aSoapMessage )); |
|
1914 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"////////////////////////////////////////////////////////"); |
|
1915 #endif |
|
1916 |
|
1917 MSenTransport& t = aConsumer.TransportL(); |
|
1918 TInt retVal( t.SendL(endpoint, aSoapMessage, aTransportProperties, *this, aConsumer, aTxnId) ); |
|
1919 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenWebServiceSession::SendSoapL:"); |
|
1920 |
|
1921 CSLOG_FORMAT((aConsumer.ConnectionId() , KMinLogLevel, _L8("- Received transaction ID: %d"), aTxnId)); |
|
1922 return retVal; |
|
1923 } |
|
1924 |
|
1925 |
|
1926 |
|
1927 // NOTE: the ownership of the consumer-pointer(s), which are copied (appended) |
|
1928 // into aConsumers array is NOT transfered to the caller! |
|
1929 |
|
1930 // 2005: refactored GetConsumers() to Consumers() |
|
1931 EXPORT_C TInt CSenWebServiceSession::Consumers(RServiceConsumerArray& aConsumers) const |
|
1932 { |
|
1933 TInt count(iConsumerList.Count()); |
|
1934 { |
|
1935 for(TInt i=0; i<count; i++) |
|
1936 { |
|
1937 // creates a copy of pointers, but ownership is NOT transferred! |
|
1938 TInt error = aConsumers.Append(iConsumerList[i]); |
|
1939 if(error != KErrNone) |
|
1940 return error; |
|
1941 } |
|
1942 } |
|
1943 return KErrNone; |
|
1944 } |
|
1945 |
|
1946 EXPORT_C TTimeIntervalMicroSeconds |
|
1947 CSenWebServiceSession::ClientServerInterval() |
|
1948 { |
|
1949 return iClientServerInterval; |
|
1950 } |
|
1951 |
|
1952 EXPORT_C void CSenWebServiceSession::SetClientServerIntervalL( |
|
1953 TTimeIntervalMicroSeconds aInterval) //codescannerwarnings |
|
1954 { |
|
1955 iClientServerInterval = aInterval; |
|
1956 if ( iCredentialPtr.Credential() ) |
|
1957 { |
|
1958 TBuf8<64> buf; |
|
1959 buf.AppendNum(iClientServerInterval.Int64()); |
|
1960 iCredentialPtr.Credential()->PropertiesL().SetPropertyL(KServiceInterval1, buf); //CodeScannerWarnings |
|
1961 } |
|
1962 } |
|
1963 |
|
1964 EXPORT_C TBool CSenWebServiceSession::HasConsumer() const |
|
1965 { |
|
1966 if (iConsumerList.Count() > 0) |
|
1967 { |
|
1968 return ETrue; |
|
1969 } |
|
1970 else |
|
1971 { |
|
1972 return EFalse; |
|
1973 } |
|
1974 } |
|
1975 |
|
1976 EXPORT_C void CSenWebServiceSession::StartTransaction() |
|
1977 { |
|
1978 // Nothing in framework base class level |
|
1979 } |
|
1980 |
|
1981 EXPORT_C void CSenWebServiceSession::TransactionCompleted() |
|
1982 { |
|
1983 // Nothing in framework base class level |
|
1984 } |
|
1985 |
|
1986 EXPORT_C TBool CSenWebServiceSession::HasSuperClass( TDescriptionClassType aType ) |
|
1987 { |
|
1988 if( aType == MSenServiceDescription::EServiceSession ) // direct superclass! |
|
1989 { |
|
1990 // If asked type is the know *direct* father/mother, return true: |
|
1991 return ETrue; |
|
1992 } |
|
1993 else |
|
1994 { |
|
1995 // Otherwise, ask from direct superclass (may invoke chain of recursive calls) |
|
1996 return CSenServiceSession::HasSuperClass( aType ); |
|
1997 } |
|
1998 } |
|
1999 |
|
2000 EXPORT_C TInt CSenWebServiceSession::SetTransportCueL(const TDesC8& aCue) |
|
2001 { |
|
2002 HBufC8* pNew =NULL; |
|
2003 if(aCue!=KNullDesC8) |
|
2004 { |
|
2005 pNew = aCue.AllocL(); |
|
2006 } |
|
2007 delete iTransportCue; |
|
2008 iTransportCue = pNew; |
|
2009 |
|
2010 return KErrNone; |
|
2011 } |
|
2012 |
|
2013 EXPORT_C HBufC8* CSenWebServiceSession::SecurityL() |
|
2014 { |
|
2015 if ( HasSecurity() ) |
|
2016 { |
|
2017 return iCredentialPtr.Credential()->AsXmlL(); |
|
2018 } |
|
2019 else |
|
2020 { |
|
2021 return NULL; |
|
2022 } |
|
2023 } |
|
2024 |
|
2025 EXPORT_C TBool CSenWebServiceSession::HasSecurity() |
|
2026 { |
|
2027 if ( iCredentialPtr.Credential() ) |
|
2028 { |
|
2029 return ETrue; |
|
2030 } |
|
2031 |
|
2032 return EFalse; |
|
2033 } |
|
2034 |
|
2035 EXPORT_C void CSenWebServiceSession::SetCredentialPtrL(RSenCredentialPtr aCredentialPtr) //codescannerwarnings |
|
2036 { |
|
2037 // Stop observing the removal of credential as this instance is itself doing the removal |
|
2038 iCredentialPtr.RemoveCredentialObserver(*this); |
|
2039 //temp pointer eliminate self deleting when counter = 1 and aCredentail points same data as iCredentialPtr |
|
2040 // in other words there is a chance that closing iCredentialPtr make dirty aCredentialPtr. Temp ptr keeps balance so |
|
2041 // that counter has proper value. |
|
2042 RSenCredentialPtr tempPtr = iCredentialPtr.Clone(); |
|
2043 iCredentialPtr.Close(); |
|
2044 iCredentialPtr = aCredentialPtr.Clone(); |
|
2045 tempPtr.Close(); |
|
2046 // Start observing the new credential |
|
2047 iCredentialPtr.AddCredentialObserverL(*this); //codescannerwarnings |
|
2048 SetCredentialIdL(iCredentialPtr.Credential()->IdentifierL().IdL()); //codescannerwarnings |
|
2049 } |
|
2050 |
|
2051 EXPORT_C TInt CSenWebServiceSession::SendToHostletL(MSenRemoteHostlet& aReceiver, |
|
2052 const TDesC8& aMessage, |
|
2053 const TInt aTxnId, |
|
2054 MSenRemoteServiceConsumer& aFrom, |
|
2055 MSenProperties* aProperties) |
|
2056 { |
|
2057 // default impelementation routes the request directly to the hostlet |
|
2058 // Handler aware framework could load the required handlers in here |
|
2059 // to enable addressing / message correlation etc. |
|
2060 return CSenServiceSession::SendToHostletL(aReceiver, aMessage, aTxnId, aFrom, aProperties); |
|
2061 } |
|
2062 |
|
2063 EXPORT_C TInt CSenWebServiceSession::ProvideHostletResponseL( MSenRemoteHostlet& aProvider, |
|
2064 const TInt aTxnId, |
|
2065 const TInt aServiceCode, |
|
2066 const TDesC8& aRecipientsConsumerId, |
|
2067 CSenChunk& aMessageChunk) |
|
2068 { |
|
2069 return CSenServiceSession::ProvideHostletResponseL( aProvider, |
|
2070 aTxnId, |
|
2071 aServiceCode, |
|
2072 aRecipientsConsumerId, |
|
2073 aMessageChunk ); |
|
2074 } |
|
2075 |
|
2076 TInt CSenWebServiceSession::HandleBodyWithoutParsingL(CSenSoapMessage& aMessage, |
|
2077 const TDesC8& aResponse) |
|
2078 { |
|
2079 TInt ret; |
|
2080 TInt endTagStart; |
|
2081 TInt endTagEnd; |
|
2082 TInt startTagStart; |
|
2083 TInt startTagEnd; |
|
2084 TPtrC8 prefix; |
|
2085 |
|
2086 ret = SenSaxUtils::SearchEndTagL(aResponse,KSenSoapEnvelopeBodyName, |
|
2087 endTagStart, endTagEnd, prefix); |
|
2088 if ( ret != KErrNotFound ) |
|
2089 { |
|
2090 ret = SenSaxUtils::SearchStartTagL(aResponse,prefix,KSenSoapEnvelopeBodyName, |
|
2091 startTagStart, startTagEnd); |
|
2092 if ( ret != KErrNotFound ) |
|
2093 { |
|
2094 TPtrC8 startPart(aResponse.Ptr(),startTagEnd+1); |
|
2095 TPtrC8 endPart(aResponse.Ptr()+endTagStart,aResponse.Size()-endTagStart); |
|
2096 HBufC8* pXmlWithoutBody = HBufC8::NewLC(startPart.Length()+endPart.Length()); |
|
2097 pXmlWithoutBody->Des().Append(startPart); |
|
2098 pXmlWithoutBody->Des().Append(endPart); |
|
2099 |
|
2100 aMessage.ParseL(*pXmlWithoutBody); |
|
2101 CleanupStack::PopAndDestroy(pXmlWithoutBody); |
|
2102 |
|
2103 TPtrC8 bodyContent(aResponse.Ptr()+startTagEnd+1, endTagStart-startTagEnd-1); |
|
2104 aMessage.SetBodyL(bodyContent); |
|
2105 } |
|
2106 } |
|
2107 |
|
2108 return ret; |
|
2109 } |
|
2110 |
|
2111 EXPORT_C void CSenWebServiceSession::CredentialChanged(TSenCredentialChange aChange, |
|
2112 TAny* /* aPointer */) |
|
2113 { |
|
2114 if ( aChange == MSenCredentialObserver::EDestroyed ) |
|
2115 { |
|
2116 iValidUntil.Set(KInvalideDate); // way back in history: January 1st 1900 \\CodeScannerWarnings |
|
2117 TRAP_IGNORE( SetStatusL(); ) |
|
2118 } |
|
2119 } |
|
2120 |
|
2121 EXPORT_C TInt CSenWebServiceSession::AddCredentialObserverL(CSenInternalCredential& aCredential) |
|
2122 { |
|
2123 TInt error(KErrNone); |
|
2124 RSenCredentialPtr credentialPtr = |
|
2125 ((MSenServiceManager&)iFramework.Manager()).CredentialL( |
|
2126 aCredential.IdentifierL().IdL(), error); |
|
2127 if ( error == KErrNone ) |
|
2128 { |
|
2129 iCredentialPtr.RemoveCredentialObserver(*this); |
|
2130 iCredentialPtr.Close(); |
|
2131 iCredentialPtr = credentialPtr.Clone(); |
|
2132 iCredentialPtr.AddCredentialObserverL(*this); |
|
2133 iValidUntil = credentialPtr.Credential()->PropertiesL().ValidUntilL(); |
|
2134 if ( iClientServerInterval == 0 ) |
|
2135 { |
|
2136 TPtrC8 value; |
|
2137 TInt ret = iCredentialPtr.Credential()->PropertiesL().PropertyL(_L8("ServiceInterval"), |
|
2138 value); |
|
2139 if ( ret == KErrNone ) |
|
2140 { |
|
2141 TLex8 lex(value); |
|
2142 TInt64 val; |
|
2143 ret = lex.Val(val); |
|
2144 if ( ret == KErrNone ) |
|
2145 { |
|
2146 iClientServerInterval = val; |
|
2147 } |
|
2148 } |
|
2149 } |
|
2150 |
|
2151 } |
|
2152 CredentialChanged(MSenCredentialObserver::EAdded, NULL); |
|
2153 SetStatusL(); |
|
2154 |
|
2155 return KErrNone; |
|
2156 } |
|
2157 |
|
2158 // End of File |