|
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: Stores smart card provisioned settings into Inbox |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CWPBioMsgHandler.h" |
|
22 #include "CWPEngine.pan" |
|
23 |
|
24 #include <biodb.h> // Message DB API |
|
25 #include <msvapi.h> |
|
26 #include <msvuids.h> // KUidMsvMessageEntry |
|
27 #include <biouids.h> // KUidBioMessageTypeMtm |
|
28 #include <WPAdapterUtil.h> |
|
29 #include <mtclreg.h> // mtm |
|
30 #include <mtclbase.h> |
|
31 #include <txtrich.h> |
|
32 #include <smsclnt.h> |
|
33 #include <smuthdr.h> |
|
34 #include <smutset.h> |
|
35 #include <ProvisioningSC.rsg> |
|
36 #include <pushmessage.h> |
|
37 #include <e32std.h> |
|
38 #include <sysutil.h> |
|
39 #include "CWPPushMessage.h" |
|
40 #include "WPProvScPaths.h" |
|
41 #include "ProvisioningDebug.h" |
|
42 |
|
43 #include <csmsgetdetdescinterface.h> |
|
44 |
|
45 // CONSTANTS |
|
46 const TInt KHeaderSize = 1; |
|
47 |
|
48 _LIT( KResourceName, "ProvisioningSC" ); |
|
49 |
|
50 GLDEF_C void Panic( TWPPanic aPanic ) |
|
51 { |
|
52 User::Panic( KWPProvSCName, aPanic ); |
|
53 } |
|
54 |
|
55 // ============================ MEMBER FUNCTIONS =============================== |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CWPBioMsgHandler::CWPBioMsgHandler |
|
59 // C++ default constructor can NOT contain any code, that |
|
60 // might leave. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CWPBioMsgHandler::CWPBioMsgHandler() : iSession(NULL), iMtm(NULL), |
|
64 iMtmRegistry(NULL) |
|
65 { |
|
66 } |
|
67 |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CWPBioMsgHandler::ConstructL |
|
71 // Symbian 2nd phase constructor can leave. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CWPBioMsgHandler::ConstructL() |
|
75 { |
|
76 iSession = CMsvSession::OpenSyncL( *this ); |
|
77 iMtmRegistry = CClientMtmRegistry::NewL( *iSession ); |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CWPBioMsgHandler::NewL |
|
82 // Two-phased constructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CWPBioMsgHandler* CWPBioMsgHandler::NewL() |
|
86 { |
|
87 CWPBioMsgHandler* handler = CWPBioMsgHandler::NewLC(); |
|
88 CleanupStack::Pop(); |
|
89 return handler; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CWPBioMsgHandler::NewLC |
|
94 // Two-phased constructor. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 CWPBioMsgHandler* CWPBioMsgHandler::NewLC() |
|
98 { |
|
99 CWPBioMsgHandler* self = new( ELeave ) CWPBioMsgHandler; |
|
100 CleanupStack::PushL( self ); |
|
101 self->ConstructL(); |
|
102 return self; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CWPBioMsgHandler::~CWPBioMsgHandler |
|
107 // Destructor |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 CWPBioMsgHandler::~CWPBioMsgHandler() |
|
111 { |
|
112 delete iMtm; |
|
113 delete iMtmRegistry; |
|
114 delete iSession; |
|
115 delete iMessage; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CWPBioMsgHandler::HandleSessionEventL |
|
120 // Handles async open msvsession |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 void CWPBioMsgHandler::HandleSessionEventL(TMsvSessionEvent aEvent, |
|
124 TAny* /* aArg1 */, TAny* /*aArg2*/, |
|
125 TAny* /*aArg3*/) |
|
126 { |
|
127 switch ( aEvent ) |
|
128 { |
|
129 case EMsvServerReady: |
|
130 { |
|
131 break; |
|
132 } |
|
133 case EMsvCloseSession: |
|
134 { |
|
135 iSession->CloseMessageServer(); |
|
136 break; |
|
137 } |
|
138 case EMsvServerTerminated: |
|
139 { |
|
140 iSession->CloseMessageServer(); |
|
141 break; |
|
142 } |
|
143 default: |
|
144 { |
|
145 break; |
|
146 } |
|
147 } |
|
148 } |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CWPBioMsgHandler::StoreMessageL |
|
151 // Stores provisioned settings into Inbox |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CWPBioMsgHandler::StoreMessageL( CWPPushMessage& aMessage ) |
|
155 { |
|
156 FLOG( _L( "[ProvisioningSC] CWPBioMsgHandler::StoreMessageL:" ) ); |
|
157 |
|
158 TMsvEntry entry; |
|
159 // create blank entry |
|
160 PrepareEntryL( entry ); |
|
161 // Look up the details |
|
162 TFileName fileName; |
|
163 #ifndef __WINS__ |
|
164 fileName = RProcess().FileName(); |
|
165 #else |
|
166 Dll::FileName( fileName ); |
|
167 #endif |
|
168 |
|
169 HBufC* details = WPAdapterUtil::ReadHBufCL( fileName, |
|
170 KResourceName, |
|
171 R_FROM_SERVICEPROVIDER ); |
|
172 CleanupStack::PushL( details ); // 1 |
|
173 entry.iDetails.Set( *details ); |
|
174 entry.iBioType = iBioUid.iUid; |
|
175 entry.iMtm = KUidBIOMessageTypeMtm; |
|
176 // Look up and set the description |
|
177 TInt index; |
|
178 CBIODatabase* bioDB = CBIODatabase::NewLC( iSession->FileSession() ); // 2 |
|
179 bioDB->GetBioIndexWithMsgIDL( iBioUid, index); |
|
180 HBufC* description = bioDB->BifReader( index ).Description().AllocL(); |
|
181 entry.iDescription.Set( *description ); |
|
182 CleanupStack::PopAndDestroy(); // bioDB 2 |
|
183 CleanupStack::PushL( description ); // 2 |
|
184 // store entry |
|
185 StoreEntryL( aMessage, entry ); |
|
186 CleanupStack::PopAndDestroy( 2 ); // description, details |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CWPBioMsgHandler::StoreMessageL |
|
191 // Stores note into Inbox |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CWPBioMsgHandler::StoreMessageL( TInt aResource, CWPPushMessage& aMessage ) |
|
195 { |
|
196 FLOG( _L( "[ProvisioningSC] CWPBioMsgHandler::StoreMessageL2:" ) ); |
|
197 |
|
198 // create an invisible blank entry |
|
199 TMsvEntry entry; |
|
200 PrepareEntryL( entry ); |
|
201 entry.iMtm = KUidMsgTypeSMS; |
|
202 |
|
203 // Store entry in inbox |
|
204 CMsvEntry* msvEntry = iSession->GetEntryL( KMsvGlobalInBoxIndexEntryId ); |
|
205 CleanupStack::PushL( msvEntry ); |
|
206 msvEntry->CreateL( entry ); |
|
207 msvEntry->Session().CleanupEntryPushL( entry.Id() ); |
|
208 msvEntry->SetEntryL( entry.Id() ); |
|
209 |
|
210 // Save the message body |
|
211 CMsvStore* store = msvEntry->EditStoreL(); |
|
212 CleanupStack::PushL( store ); |
|
213 CParaFormatLayer* paraFormat = CParaFormatLayer::NewL(); |
|
214 CleanupStack::PushL( paraFormat ); |
|
215 CCharFormatLayer* charFormat = CCharFormatLayer::NewL(); |
|
216 CleanupStack::PushL( charFormat ); |
|
217 CRichText* body = CRichText::NewL( paraFormat, charFormat ); |
|
218 CleanupStack::PushL( body ); |
|
219 |
|
220 TFileName fileName; |
|
221 #ifndef __WINS__ |
|
222 fileName = RProcess().FileName(); |
|
223 #else |
|
224 Dll::FileName( fileName ); |
|
225 #endif |
|
226 |
|
227 // Look up text |
|
228 HBufC* text = WPAdapterUtil::ReadHBufCL( fileName, |
|
229 KResourceName, |
|
230 aResource ); |
|
231 CleanupStack::PushL( text ); |
|
232 |
|
233 // set text |
|
234 body->InsertL( 0, *text ); |
|
235 store->StoreBodyTextL( *body ); |
|
236 |
|
237 // Store the actual message for post-mortem analysis |
|
238 aMessage.StoreL( *store ); |
|
239 |
|
240 // Save the SMS header and create a description field |
|
241 CSmsHeader* header = CSmsHeader::NewL( CSmsPDU::ESmsDeliver, *body ); |
|
242 CleanupStack::PushL( header ); |
|
243 TBuf<KSmsDescriptionLength> description; |
|
244 |
|
245 CSmsGetDetDescInterface* smsPlugin = CSmsGetDetDescInterface::NewL(); |
|
246 CleanupStack::PushL( smsPlugin ); |
|
247 smsPlugin->GetDescription( header->Message(), description ); |
|
248 CleanupStack::PopAndDestroy( smsPlugin ); |
|
249 |
|
250 entry.iDescription.Set( description ); |
|
251 header->StoreL( *store ); |
|
252 store->CommitL(); |
|
253 CleanupStack::PopAndDestroy( 5 ); // header,text,body,charformat,paraFormat |
|
254 |
|
255 // Complete processing the message |
|
256 entry.SetReadOnly( EFalse ); |
|
257 entry.SetVisible( ETrue ); |
|
258 entry.SetInPreparation( EFalse ); |
|
259 msvEntry->ChangeL( entry ); |
|
260 CleanupStack::PopAndDestroy(); //store |
|
261 msvEntry->Session().CleanupEntryPop(); //entry |
|
262 CleanupStack::PopAndDestroy( ); // msvEntry |
|
263 |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CWPBioMsgHandler::CreateMessageL |
|
268 // passes the ownership of the created push message |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 CWPPushMessage* CWPBioMsgHandler::CreateMessageLC( TDesC8& aProvisioningDoc ) |
|
272 { |
|
273 FLOG( _L( "[ProvisioningSC] CWPBioMsgHandler::CreateMessageLC begin" ) ); |
|
274 CWPPushMessage* message = CWPPushMessage::NewLC(); |
|
275 CPushMessage* pushMsg = CreatePushMessageL( aProvisioningDoc ); |
|
276 CleanupStack::PushL( pushMsg ); // 2 |
|
277 TPtrC8 bodyValue; |
|
278 TPtrC8 headerValue; |
|
279 if (pushMsg->GetMessageBody( bodyValue ) |
|
280 && pushMsg->GetHeader( headerValue ) ) |
|
281 { |
|
282 // set member message, takes copy of arguments |
|
283 message->SetL( headerValue, bodyValue ); |
|
284 } |
|
285 // set member uid |
|
286 BioMessageTypeL( *pushMsg ); |
|
287 CleanupStack::PopAndDestroy(); // pushMsg, 2 |
|
288 FLOG( _L( "[ProvisioningSC] CWPBioMsgHandler::CreateMessageLC end" ) ); |
|
289 return message; |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CWPBioMsgHandler::CreatePushMessageL |
|
294 // Stores note into Inbox |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 CPushMessage* CWPBioMsgHandler::CreatePushMessageL( TDesC8& aProvisioningDoc ) |
|
298 { |
|
299 TBuf8<KHeaderSize> header; |
|
300 header.Append( 0xB6 ); // Wap push header value |
|
301 HBufC8* hdrBuf = header.AllocLC(); |
|
302 HBufC8* bodyBuf = aProvisioningDoc.AllocLC(); |
|
303 CPushMessage* pushMsg = CPushMessage::NewL( hdrBuf, bodyBuf ); |
|
304 CleanupStack::Pop( 2 ); // hdrBuf, bodyBuf |
|
305 return pushMsg; |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CWPBioMsgHandler::PrepareEntryL |
|
310 // |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 void CWPBioMsgHandler::PrepareEntryL( TMsvEntry& aEntry ) |
|
314 { |
|
315 // Current time |
|
316 TTime time; |
|
317 |
|
318 // Get Universal time |
|
319 time.UniversalTime(); |
|
320 |
|
321 aEntry.iType = KUidMsvMessageEntry; |
|
322 aEntry.SetVisible(EFalse); |
|
323 aEntry.SetInPreparation(ETrue); |
|
324 aEntry.SetReadOnly(EFalse); |
|
325 aEntry.SetUnread(ETrue); |
|
326 aEntry.iDate = time; |
|
327 aEntry.iServiceId = KMsvLocalServiceIndexEntryId; |
|
328 aEntry.iError = KErrNone; |
|
329 } |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // CWPBioMsgHandler::StoreEntryL |
|
333 // |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 void CWPBioMsgHandler::StoreEntryL( CWPPushMessage& aPushMsg, TMsvEntry& aEntry) |
|
337 { |
|
338 if( SysUtil::FFSSpaceBelowCriticalLevelL( NULL, aPushMsg.Body().Length() ) ) |
|
339 { |
|
340 FLOG( _L( "[ProvisioningSC] CWPBioMsgHandler::StoreEntryL KErrDiskfull:" ) ); |
|
341 User::Leave( KErrDiskFull ); |
|
342 } |
|
343 // Store entry in inbox |
|
344 CMsvEntry* msvEntry = iSession->GetEntryL( KMsvGlobalInBoxIndexEntryId ); |
|
345 CleanupStack::PushL( msvEntry ); // 1 |
|
346 msvEntry->CreateL( aEntry ); |
|
347 msvEntry->Session().CleanupEntryPushL( aEntry.Id() ); |
|
348 msvEntry->SetEntryL( aEntry.Id() ); |
|
349 |
|
350 // Save the message |
|
351 CMsvStore* store = msvEntry->EditStoreL(); |
|
352 CleanupStack::PushL( store ); // 2 |
|
353 aPushMsg.StoreL( *store ); |
|
354 store->CommitL(); |
|
355 |
|
356 // Complete processing the message |
|
357 aEntry.SetReadOnly( EFalse ); |
|
358 aEntry.SetVisible( ETrue ); |
|
359 aEntry.SetInPreparation( EFalse ); |
|
360 msvEntry->ChangeL( aEntry ); |
|
361 |
|
362 CleanupStack::PopAndDestroy(); // store, 2 |
|
363 msvEntry->Session().CleanupEntryPop(); //msvEntry's entry |
|
364 CleanupStack::PopAndDestroy(); // msvEntry, 1 |
|
365 } |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // CWPBioMsgHandler::BioMessageTypeL |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 void CWPBioMsgHandler::BioMessageTypeL( CPushMessage& aMessage ) |
|
372 { |
|
373 // need to create local RFs for BIO otherwise raises exception |
|
374 RFs localFS; |
|
375 User::LeaveIfError( localFS.Connect() ); |
|
376 CleanupClosePushL( localFS ); |
|
377 CBIODatabase* bioDB = CBIODatabase::NewLC( localFS ); |
|
378 TPtrC contentTypePtr; |
|
379 aMessage.GetContentType( contentTypePtr ); |
|
380 iBioUid = KNullUid; |
|
381 // Ignored return type: KErrNone if found or KErrNotFound if not found |
|
382 bioDB->IsBioMessageL( EBioMsgIdIana, contentTypePtr, NULL, iBioUid ); |
|
383 CleanupStack::PopAndDestroy(2); // bioDB, localFS |
|
384 } |
|
385 |
|
386 // End of File |