|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 #include "wsoviserviceupdatehandler.h" |
|
26 #include "sendebug.h" |
|
27 #include "senlogger.h" |
|
28 #include "wsovitokencreationresponse.h" |
|
29 #include "sencryptoutils.h" |
|
30 #include "wsovicons.h" |
|
31 #include "wsovierrorresponse.h" |
|
32 #include <httpstd.h> |
|
33 #include <SenHttpTransportProperties.h> |
|
34 #include "senlayeredhttptransportproperties.h" |
|
35 using namespace OAuth; |
|
36 |
|
37 |
|
38 |
|
39 class CWSOviHandlerContext; |
|
40 // Create instance of concrete ECOM interface implementation |
|
41 CWSOviServiceUpdateHandler* CWSOviServiceUpdateHandler::NewL(TAny* aHandlerCtx) |
|
42 { |
|
43 |
|
44 MSenHandlerContext* handlerCtx = |
|
45 reinterpret_cast<MSenHandlerContext*>(aHandlerCtx); |
|
46 CWSOviServiceUpdateHandler* self = new (ELeave) CWSOviServiceUpdateHandler(*handlerCtx); |
|
47 CleanupStack::PushL (self); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // Constructor |
|
54 CWSOviServiceUpdateHandler::CWSOviServiceUpdateHandler(MSenHandlerContext& aCtx):CSenSessionHandler(aCtx) |
|
55 { |
|
56 |
|
57 } |
|
58 |
|
59 // Destructor |
|
60 CWSOviServiceUpdateHandler::~CWSOviServiceUpdateHandler() |
|
61 { |
|
62 } |
|
63 |
|
64 // Second phase construction. |
|
65 void CWSOviServiceUpdateHandler::ConstructL() |
|
66 { |
|
67 } |
|
68 |
|
69 TInt CWSOviServiceUpdateHandler::InvokeL(MSenSessionContext& aCtx) |
|
70 { |
|
71 CWSOviServiceSession* remoteServiceSession = |
|
72 (CWSOviServiceSession*)aCtx.GetSenRemoteServiceSessionL( |
|
73 WSOviContextKeys::KServiceSession()); |
|
74 const TDesC8* message = ((CWSOviSessionContext&)aCtx).GetDesC8L(WSOviContextKeys::KMessageBody); |
|
75 const TInt* errorCode = ((CWSOviSessionContext&)aCtx).GetIntL(WSOviContextKeys::KErrCode); |
|
76 |
|
77 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,(_L("CWSOviPlugin::ProcessInboundDispatch"))); |
|
78 CWSOviServiceSession* oviServiceSession = ((CWSOviServiceSession*)remoteServiceSession); |
|
79 CWSOviSessionContext& pCtx = (CWSOviSessionContext&)aCtx; |
|
80 //fault scenarios |
|
81 if (message && errorCode) |
|
82 { |
|
83 if (*errorCode == EHttp_401_Unauthorized-KHttpPluginStatusBase) |
|
84 { |
|
85 CWSOviErrorResponse* errFragment = CWSOviErrorResponse::NewLC(); |
|
86 errFragment->SetReader(*iHandlerContext.GetSenCoreServiceManager()->XMLReader()); |
|
87 errFragment->BuildFrom(*message); |
|
88 if (! errFragment->Code().Compare(WSOviResponse::KErrorCodeInvalidAccessToken())) |
|
89 { |
|
90 if (!pCtx.GetSenRemoteServiceSessionL(WSOviContextKeys::KServiceSession)) |
|
91 { |
|
92 pCtx.Add(WSOviContextKeys::KServiceSession, *(MSenRemoteServiceSession*)remoteServiceSession); |
|
93 } |
|
94 pCtx.Update(WSOviContextKeys::KReAuthNeeded, ETrue); |
|
95 oviServiceSession->ClearCredentialL(); |
|
96 oviServiceSession->SetStatusL();//in order to compute state |
|
97 } |
|
98 else if(! errFragment->Code().Compare(WSOviResponse::KErrorCodeUnauthorized())) |
|
99 { |
|
100 MSenProperties* tp = (MSenProperties*)pCtx.GetAnyL(WSOviContextKeys::KTP()); |
|
101 if (tp) |
|
102 { |
|
103 switch (tp->PropertiesClassType()) |
|
104 { |
|
105 case MSenProperties::ESenHttpTransportProperties: |
|
106 { |
|
107 TInt minutes; |
|
108 ((CSenHttpTransportProperties*)tp)->IntPropertyL(WSOviSession::KDateHttpHeader(), minutes); |
|
109 pCtx.Update(WSOviContextKeys::KRetryNeeded, minutes); |
|
110 } |
|
111 break; |
|
112 case MSenProperties::ESenLayeredHttpTransportProperties: |
|
113 { |
|
114 TInt minutes; |
|
115 ((CSenLayeredHttpTransportProperties*)tp)->IntPropertyL(WSOviSession::KDateHttpHeader(), minutes); |
|
116 pCtx.Update(WSOviContextKeys::KRetryNeeded, minutes); |
|
117 } |
|
118 default: |
|
119 break; |
|
120 } |
|
121 } |
|
122 } |
|
123 CleanupStack::PopAndDestroy(errFragment); |
|
124 } |
|
125 //positive scenario, for example: signup proces already returns token |
|
126 else if (*errorCode == KErrNone) |
|
127 { |
|
128 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviPlugin::ProcessInboundDispatch - token exists"); |
|
129 CWSOviTokenCreationResponse* responseFragment = CWSOviTokenCreationResponse::NewLC(); |
|
130 responseFragment->SetReader(*iHandlerContext.GetSenCoreServiceManager()->XMLReader()); |
|
131 responseFragment->BuildFrom(*message); |
|
132 if (responseFragment->IsTokenUpdate()) |
|
133 { |
|
134 TPtrC8 ttl = responseFragment->TTL(); |
|
135 TBool ttlInfinitive = EFalse; |
|
136 if (ttl.Length()) |
|
137 { |
|
138 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,ttl); |
|
139 User::LeaveIfError(pCtx.Update(WSOviContextKeys::KTTL,ttl)); |
|
140 } |
|
141 else |
|
142 { |
|
143 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviPlugin::ProcessInboundDispatch - ttl is missing"); |
|
144 const TInt KMaxTTLLength = 20; |
|
145 TBuf8<KMaxTTLLength> ttlMaxInt; |
|
146 ttlMaxInt.AppendNum(KMaxTInt); |
|
147 User::LeaveIfError(pCtx.Update(WSOviContextKeys::KTTL, ttlMaxInt)); |
|
148 ttlInfinitive = ETrue; |
|
149 } |
|
150 TPtrC8 tokenSecret = responseFragment->TokenSecret(); |
|
151 if (tokenSecret.Length()) |
|
152 { |
|
153 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,tokenSecret); |
|
154 User::LeaveIfError(pCtx.Update(WSOviContextKeys::KTokenSecret,tokenSecret)); |
|
155 } |
|
156 HBufC8* created = SenCryptoUtils::GetTimestampL(); |
|
157 CleanupStack::PushL(created); |
|
158 User::LeaveIfError(pCtx.Update(WSOviContextKeys::KTokenCreationTime,*created)); |
|
159 CleanupStack::PopAndDestroy(created); |
|
160 |
|
161 TPtrC8 token = responseFragment->Token(); |
|
162 if (!token.Length()) |
|
163 { |
|
164 pCtx.Remove(WSOviContextKeys::KTokenCreationTime); |
|
165 } |
|
166 else |
|
167 { |
|
168 TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,token); |
|
169 if (!oviServiceSession->ExistConsumerL()) |
|
170 { |
|
171 pCtx.Remove(WSOviContextKeys::KTokenCreationTime); |
|
172 } |
|
173 else |
|
174 { |
|
175 pCtx.SetTokenKeysL(token); |
|
176 } |
|
177 } |
|
178 if (!ttlInfinitive) |
|
179 { |
|
180 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviPlugin::ProcessInboundDispatch - Call ActiveTicketObserverL()"); |
|
181 oviServiceSession->ActiveTicketObserverL(); |
|
182 } |
|
183 |
|
184 TPtrC8 username = responseFragment->Username(); |
|
185 if (username.Length()) |
|
186 { |
|
187 oviServiceSession->SetTrustAnchorL(username); |
|
188 oviServiceSession->SetProviderIDL(username); |
|
189 } |
|
190 } |
|
191 CleanupStack::PopAndDestroy(responseFragment); |
|
192 pCtx.Update(WSOviContextKeys::KRetryNeeded, 0); |
|
193 } |
|
194 } |
|
195 return KErrNone; |
|
196 } |
|
197 |
|
198 SenHandler::THandlerDirection CWSOviServiceUpdateHandler::Direction() const |
|
199 { |
|
200 return SenHandler::EIncoming; |
|
201 }; |
|
202 SenHandler::THandlerPhase CWSOviServiceUpdateHandler::Phase() |
|
203 { |
|
204 return SenHandler::EMessage; |
|
205 }; |
|
206 |
|
207 |
|
208 |
|
209 //--------------------------------------------------------------------------- |
|
210 // Logger using during DEBUG mode |
|
211 //--------------------------------------------------------------------------- |
|
212 // |
|
213 |
|
214 TInt CWSOviServiceUpdateHandler::InitL(MSenHandlerContext& aCtx) |
|
215 { |
|
216 iHandlerContext = aCtx; |
|
217 return KErrNone; |
|
218 } |
|
219 |
|
220 // END OF FILE |
|
221 |