1 /* |
|
2 * Copyright (c) 2002 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 * Bio control for Provisioning documents. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CWPBioControl.h" |
|
21 #include <msvapi.h> |
|
22 #include <bldvariant.hrh> |
|
23 #include <msvids.h> |
|
24 #include <featmgr.h> |
|
25 #include <sysutil.h> |
|
26 #include "CWPEngine.h" |
|
27 #include "CWPAdapter.h" |
|
28 #include "MWPPhone.h" |
|
29 #include "WPPhoneFactory.h" |
|
30 #include "CWPPushMessage.h" |
|
31 #include "ProvisioningUIDs.h" |
|
32 #include "MWPContextManager.h" |
|
33 #include "ProvisioningDebug.h" |
|
34 #include "CWPNameValue.h" |
|
35 #include <aknmessagequerydialog.h> |
|
36 #include "ProvisioningInternalCRKeys.h" |
|
37 |
|
38 // CONSTANTS |
|
39 /// Maximum length of PIN code |
|
40 const TInt KMaxPinSize = 20; |
|
41 /// Number of retries for PIN |
|
42 // const TInt KPinRetries = 3; // Removed, because iMtmData1 data member of TMsvEntry in CWPMessage.cpp contains Max tries, default=3. |
|
43 ///NONE |
|
44 _LIT(KNone,""); |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS =============================== |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // Constructor. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CWPBioControl::CWPBioControl(CMsvSession* aSession,TMsvId aId) |
|
53 |
|
54 { |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CWPBioControl::ConstructL |
|
59 // Symbian 2nd phase constructor can leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CWPBioControl::ConstructL(CMsvSession* aSession,TMsvId aId) |
|
63 { |
|
64 FLOG( _L( "[ProvisioningBC] CWPBioControl::ConstructL:" ) ); |
|
65 FeatureManager::InitializeLibL(); |
|
66 iSession = aSession; |
|
67 iId = aId; |
|
68 iEngine = CWPEngine::NewL(); |
|
69 RestoreMsgL(); |
|
70 FLOG( _L( "[ProvisioningBC] CWPBioControl::ConstructL: done" ) ); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CWPBioControl::NewL |
|
75 // Two-phased constructor. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C CWPBioControl* CWPBioControl::NewL(CMsvSession* aSession,TMsvId aId) |
|
79 { |
|
80 CWPBioControl* self = new( ELeave ) CWPBioControl(aSession,aId); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(aSession,aId); |
|
83 CleanupStack::Pop(); |
|
84 return self; |
|
85 } |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CWPBioControl::returnEngine |
|
88 // Return CWPEngine pointer |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C CWPEngine* CWPBioControl::returnEngine() |
|
92 { |
|
93 return iEngine; |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // Destructor |
|
98 // ----------------------------------------------------------------------------- |
|
99 CWPBioControl::~CWPBioControl() |
|
100 { |
|
101 delete iEngine; |
|
102 delete iMessage; |
|
103 FeatureManager::UnInitializeLib(); |
|
104 } |
|
105 // ---------------------------------------------------------------------------- |
|
106 // CWPBioControl ::RestoreMsgL |
|
107 // ---------------------------------------------------------------------------- |
|
108 // |
|
109 void CWPBioControl::RestoreMsgL() |
|
110 { |
|
111 CMsvEntry* entry = iSession->GetEntryL(iId); |
|
112 CleanupStack::PushL( entry ); |
|
113 TMsvEntry tentry( entry->Entry() ); |
|
114 iMessage = CWPPushMessage::NewL(); |
|
115 CMsvStore* readStore = entry->ReadStoreL(); |
|
116 CleanupStack::PushL( readStore ); |
|
117 iMessage->RestoreL( *readStore ); |
|
118 CleanupStack::PopAndDestroy(); // readStore |
|
119 |
|
120 TRAPD( result, iEngine->ImportDocumentL( iMessage->Body() ) ); |
|
121 if( result == KErrCorrupt ) |
|
122 { |
|
123 //result = KErrMsgBioMessageNotValid; |
|
124 } |
|
125 FTRACE(RDebug::Print(_L("[ProvisioningBC] CWPBioControl::RestoreMsgL result (%d)"), result)); |
|
126 User::LeaveIfError( result ); |
|
127 |
|
128 TBool preAuthenticated( iMessage->Authenticated() ); |
|
129 // If the message was not authenticated, give a warning |
|
130 AuthenticateL( *iMessage ); |
|
131 if( !tentry.ReadOnly() && preAuthenticated != iMessage->Authenticated() ) |
|
132 { |
|
133 // If the entry can be written to, get its edit store and save |
|
134 // authentication flag. Failing is not dangerous, as the only |
|
135 // effect is that the user has to re-enter the PIN. |
|
136 // FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 4 " ) ); |
|
137 TRAPD( ignoreError, SaveMessageL() ); |
|
138 if ( ignoreError ) ignoreError = 0; // prevent compiler warning |
|
139 } |
|
140 |
|
141 iEngine->PopulateL(); |
|
142 if( iEngine->ItemCount() == 0 ) |
|
143 { |
|
144 FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 7 " ) ); |
|
145 } |
|
146 |
|
147 TPtrC8 orig8( iMessage->Originator() ); |
|
148 HBufC* orig16 = HBufC::NewLC( orig8.Length() ); |
|
149 orig16->Des().Copy( orig8 ); |
|
150 FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 8 " ) ); |
|
151 if( iMessage->Authenticated() |
|
152 && iEngine->ContextExistsL( *orig16 ) ) |
|
153 { |
|
154 TUint32 context( iEngine->ContextL( *orig16 ) ); |
|
155 iEngine->SetCurrentContextL( context ); |
|
156 } |
|
157 else |
|
158 { |
|
159 iEngine->SetCurrentContextL( KWPMgrUidNoContext ); |
|
160 } |
|
161 |
|
162 |
|
163 CleanupStack::PopAndDestroy(2); |
|
164 FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL done" ) ); |
|
165 } |
|
166 |
|
167 // ---------------------------------------------------------------------------- |
|
168 // CWPBioControl ::AuthenticateL |
|
169 // ---------------------------------------------------------------------------- |
|
170 // |
|
171 void CWPBioControl::AuthenticateL( CWPPushMessage& aMessage ) |
|
172 { |
|
173 if( !aMessage.Authenticated() ) |
|
174 { |
|
175 MWPPhone* phone = NULL; |
|
176 TBuf<KMaxPinSize> imsi; |
|
177 TRAPD(err, phone = WPPhoneFactory::CreateL()); |
|
178 if(err!=KErrNone) |
|
179 { |
|
180 imsi = KNone; |
|
181 } |
|
182 else |
|
183 { |
|
184 imsi = phone->SubscriberId(); |
|
185 } |
|
186 CWPBootstrap* bootstrap = CWPBootstrap::NewL( imsi ); |
|
187 if(phone) |
|
188 delete phone; |
|
189 |
|
190 CleanupStack::PushL( bootstrap ); |
|
191 CWPBootstrap::TBootstrapResult result( bootstrap->BootstrapL(aMessage,*iEngine,KNullDesC ) ); |
|
192 if( result == CWPBootstrap::EPinRequired ) |
|
193 { |
|
194 CMsvEntry* entry = iSession->GetEntryL(iId); |
|
195 TInt count = (entry->Entry()).MtmData1(); |
|
196 TInt ipin = 1234; |
|
197 TBuf<KMaxPinSize> pin; |
|
198 pin.AppendNum(ipin); |
|
199 result = bootstrap->BootstrapL( aMessage, *iEngine, pin ); |
|
200 CleanupStack::PopAndDestroy( bootstrap ); |
|
201 } |
|
202 } |
|
203 if (aMessage.Authenticated() ) |
|
204 { |
|
205 //update Cenrep key |
|
206 TBuf8<100> orig; |
|
207 orig.Copy(aMessage.Originator()); |
|
208 TRAPD(err, SetCenrepKeyL(orig)); |
|
209 User::LeaveIfError(err); |
|
210 |
|
211 } |
|
212 } |
|
213 // ---------------------------------------------------------------------------- |
|
214 // CWPBioControl ::SaveMessageL |
|
215 // ---------------------------------------------------------------------------- |
|
216 // |
|
217 void CWPBioControl::SaveMessageL() |
|
218 { |
|
219 CMsvEntry* entry = iSession->GetEntryL(iId); |
|
220 CleanupStack::PushL( entry ); |
|
221 |
|
222 CMsvStore* editStore = entry->EditStoreL(); |
|
223 CleanupStack::PushL( editStore ); |
|
224 iMessage->StoreL( *editStore ); |
|
225 editStore->CommitL(); |
|
226 CleanupStack::PopAndDestroy(2); // editStore, entry |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // CWPBioControl ::CollectItemsL |
|
231 // ---------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C RPointerArray<CWPNameValue>* CWPBioControl::CollectItemsLC() const |
|
234 { |
|
235 RPointerArray<CWPNameValue>* array = new(ELeave) RPointerArray<CWPNameValue>; |
|
236 CleanupStack::PushL( TCleanupItem( Cleanup, array ) ); |
|
237 |
|
238 TInt count( iEngine->ItemCount() ); |
|
239 FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 83 " ) ); |
|
240 for( TInt index = 0; index < count; index++ ) |
|
241 { |
|
242 const TDesC& text = iEngine->SummaryText( index ); |
|
243 const TDesC& title = iEngine->SummaryTitle( index ); |
|
244 |
|
245 CWPNameValue* pair = CWPNameValue::NewLC( title, text ); |
|
246 User::LeaveIfError( array->Append( pair ) ); |
|
247 CleanupStack::Pop( pair ); |
|
248 } |
|
249 array->Sort( TLinearOrder<CWPNameValue>( CWPBioControl::Compare ) ); |
|
250 return array; |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CWPBioControl::Cleanup |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CWPBioControl::Cleanup( TAny* aAny ) |
|
258 { |
|
259 RPointerArray<CWPNameValue>* array = reinterpret_cast<RPointerArray<CWPNameValue>*>( aAny ); |
|
260 array->ResetAndDestroy(); |
|
261 array->Close(); |
|
262 delete array; |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CWPBioControl::Compare |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 TInt CWPBioControl::Compare( const CWPNameValue& aItem1, |
|
270 const CWPNameValue& aItem2 ) |
|
271 { |
|
272 return aItem1.Name().Compare( aItem2.Name() ); |
|
273 } |
|
274 |
|
275 // ---------------------------------------------------------------------------- |
|
276 // CWPBioControl ::SetCenrepKey |
|
277 // ---------------------------------------------------------------------------- |
|
278 // |
|
279 void CWPBioControl::SetCenrepKeyL(const TDesC8& aValue) |
|
280 { |
|
281 |
|
282 FLOG( _L( "[ProvisioningBC] CWPBioControl::SetCenrepKeyL" ) ); |
|
283 |
|
284 CRepository* rep= NULL; |
|
285 TInt errorStatus = KErrNone; |
|
286 |
|
287 TRAPD( errVal, rep = CRepository::NewL( KCRUidOMAProvisioningLV )) |
|
288 ; |
|
289 |
|
290 if (errVal == KErrNone) |
|
291 { |
|
292 errorStatus = rep->Set(KOMAProvOriginatorContent, aValue); |
|
293 } |
|
294 else |
|
295 { |
|
296 errorStatus = errVal; |
|
297 } |
|
298 |
|
299 if (rep) |
|
300 { |
|
301 delete rep; |
|
302 } |
|
303 |
|
304 if (errorStatus != KErrNone) |
|
305 { |
|
306 User::Leave(errorStatus); |
|
307 } |
|
308 |
|
309 FLOG( _L( "[ProvisioningBC] CWPBioControl::SetCenrepKeyL done" ) ); |
|
310 |
|
311 } |
|
312 // End of File |
|