|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 // User Include |
|
18 #include "ROContentHandler.h" |
|
19 #include "MessageComposer.h" |
|
20 |
|
21 //Rights object text MIME types |
|
22 _LIT8(KROTextContentType, "application/vnd.oma.drm.rights+xml"); |
|
23 _LIT(KROBinContentType, "application/vnd.oma.drm.rights+wbxml"); |
|
24 |
|
25 #if defined(_DEBUG) |
|
26 _LIT(KErrPushMsgNull, "NULL CPushMessage"); |
|
27 #endif |
|
28 |
|
29 //temp output file |
|
30 _LIT(KWapPushDir, "C:\\system\\data\\wappush\\"); |
|
31 _LIT(KTempROFile, "rightsobject.Dat"); |
|
32 |
|
33 // Constants |
|
34 _LIT(KReserved, "Reserved"); |
|
35 |
|
36 const TInt KXMLHeader=12; |
|
37 |
|
38 void CROContentHandler::CPushHandlerBase_Reserved1() |
|
39 { |
|
40 User::Panic(KReserved, KErrNotSupported); |
|
41 } |
|
42 |
|
43 void CROContentHandler::CPushHandlerBase_Reserved2() |
|
44 { |
|
45 User::Panic(KReserved, KErrNotSupported); |
|
46 } |
|
47 |
|
48 /** |
|
49 * The RO Content handler private constructor. |
|
50 **/ |
|
51 CROContentHandler::CROContentHandler(): CContentHandlerBase(), iPushMsgAction(KErrNotFound) |
|
52 { |
|
53 //Do nothing |
|
54 } |
|
55 |
|
56 /** |
|
57 * This will complete initialization of the object |
|
58 **/ |
|
59 void CROContentHandler::ConstructL() |
|
60 { |
|
61 CActiveScheduler::Add(this); |
|
62 User::LeaveIfError(iFs.Connect()); |
|
63 } |
|
64 |
|
65 /** |
|
66 * Static Factory Construction |
|
67 * |
|
68 * Version of NewL which leaves nothing |
|
69 * on the cleanup stack |
|
70 **/ |
|
71 CROContentHandler* CROContentHandler::NewL() |
|
72 { |
|
73 CROContentHandler* self = new(ELeave) CROContentHandler; |
|
74 CleanupStack::PushL(self); |
|
75 self->ConstructL(); |
|
76 CleanupStack::Pop(self); |
|
77 return self; |
|
78 } |
|
79 |
|
80 /** |
|
81 * Default d'tor |
|
82 */ |
|
83 CROContentHandler::~CROContentHandler() |
|
84 { |
|
85 __LOG_PTR_DEBUG("CROContentHandler:: Destructor Called"); |
|
86 delete iCAFInterface; |
|
87 delete iData; |
|
88 } |
|
89 |
|
90 /** |
|
91 * HandleMessage Async. Version |
|
92 * Takes ownership of Push Message and sets self active to continue |
|
93 * processing message. |
|
94 * @param aPushMsg |
|
95 * CPushMessage to process |
|
96 * @param aStatus |
|
97 * request status variable for use in asynchronous operations |
|
98 */ |
|
99 void CROContentHandler::HandleMessageL(CPushMessage* aPushMsg, TRequestStatus& aStatus) |
|
100 { |
|
101 __LOG_PTR_DEBUG("CROContentHandler:: HandleMessage Async Func. Called"); |
|
102 __ASSERT_DEBUG( aPushMsg != NULL, User::Panic(KErrPushMsgNull, KErrNone)); |
|
103 |
|
104 iMessage = aPushMsg; |
|
105 SetConfirmationStatus(aStatus); |
|
106 |
|
107 iState= EConverting; |
|
108 IdleComplete(); |
|
109 } |
|
110 |
|
111 /** |
|
112 * HandleMessage Sync. Version |
|
113 * Takes ownership of Push Message and sets self active to continue |
|
114 * processing message. |
|
115 * |
|
116 * Initial State: Set data members then go to the next state |
|
117 * @param aPushMsg |
|
118 * CPushMessage to process |
|
119 */ |
|
120 void CROContentHandler::HandleMessageL(CPushMessage* aPushMsg) |
|
121 { |
|
122 __LOG_PTR_DEBUG("CROContentHandler:: HandleMessage Sync Func. Called"); |
|
123 __ASSERT_DEBUG( aPushMsg != NULL, User::Panic(KErrPushMsgNull, KErrNone)); |
|
124 |
|
125 iMessage = aPushMsg; |
|
126 |
|
127 iState =EConverting; |
|
128 IdleComplete(); |
|
129 } |
|
130 |
|
131 /** |
|
132 * Convert the RO message from WBXML to XML if necessary |
|
133 * @leave KErrNotFound |
|
134 * indicates general processing error and to abandon processing |
|
135 * @leave KErrCorrupt |
|
136 * there is no body in the message |
|
137 * @leave TDesC::AllocL |
|
138 |
|
139 */ |
|
140 void CROContentHandler::ConvertPushMsgL() |
|
141 { |
|
142 __LOG_PTR_DEBUG("CROContentHandler:: ConvertPushMsgL Called"); |
|
143 |
|
144 TPtrC contentType; |
|
145 iMessage->GetContentType(contentType); |
|
146 |
|
147 if(contentType.CompareF(KROBinContentType) == 0) |
|
148 { |
|
149 //This is a WBXML Push Msg, we need to convert it into XML format before passing to DRM agent. |
|
150 CMessageComposer* msgComposer = CMessageComposer::NewL ( *iMessage ); |
|
151 CleanupStack::PushL ( msgComposer ); |
|
152 const TDesC8& convertedMsg = msgComposer->ParseMessageL (); |
|
153 User::LeaveIfError ( msgComposer->LastError() ); |
|
154 HBufC8* msgBody = convertedMsg.AllocLC(); |
|
155 TPtrC8 hdr; |
|
156 iMessage->GetHeader(hdr); |
|
157 HBufC8* hdrBuf = hdr.AllocLC(); |
|
158 delete iMessage; |
|
159 iMessage = NULL; |
|
160 |
|
161 //CPushMessage now takes ownership of hdrBuf and convertedBody |
|
162 //replace received Binary Push message with newly converted XML Massage |
|
163 iMessage = CPushMessage::NewL(hdrBuf, msgBody); |
|
164 |
|
165 CleanupStack::Pop(2,msgBody); //msgBody, hdrBuf |
|
166 CleanupStack::PopAndDestroy( msgComposer ); |
|
167 } |
|
168 iState = EStoring; |
|
169 IdleComplete(); |
|
170 } |
|
171 |
|
172 |
|
173 /** |
|
174 * Save push message in message store. |
|
175 * Creates link to message service provided by wap push utils |
|
176 * and uses this and the associated push entry class to save |
|
177 * the push message. |
|
178 */ |
|
179 void CROContentHandler::SaveROToXMLFileL() |
|
180 { |
|
181 __LOG_PTR_DEBUG("CROContentHandler:: SaveROToXMLFile called"); |
|
182 |
|
183 TPtrC8 body; |
|
184 iMessage->GetMessageBody(body); |
|
185 // If there is no body in the message leave with an error |
|
186 if (body.Length() ==0) |
|
187 { |
|
188 User::Leave(KErrCorrupt); |
|
189 } |
|
190 |
|
191 HBufC8* bodyBuf = body.AllocLC(); |
|
192 //Create file to store the message in Wap Push temp area |
|
193 TFileName rofilename; |
|
194 RFile file; |
|
195 rofilename.Append(KWapPushDir); |
|
196 rofilename.Append(KTempROFile); |
|
197 iFs.MkDirAll(KWapPushDir); |
|
198 User::LeaveIfError(file.Replace(iFs, rofilename, EFileWrite)); |
|
199 CleanupClosePushL(file); |
|
200 |
|
201 //Create a heap buffer to store message with header. |
|
202 //Agent expects the 12 bytes of header to store the message. |
|
203 //First four bytes to store the offset of the rights message size in the buffer. |
|
204 //Next four bytes to store the offset of the content message size in the buffer. |
|
205 //Last four bytes to store the size of rights message. |
|
206 TInt size=bodyBuf->Length(); |
|
207 iData=HBufC8::NewL(size+KXMLHeader); |
|
208 TPtr8 bufPtr(iData->Des()); |
|
209 TPckg<TInt> rightsOffset(8); //There is no content. the rights message size is at offset of 8 bytes. |
|
210 bufPtr.Append(rightsOffset); |
|
211 TPckg<TInt> contentOffset(0); |
|
212 bufPtr.Append(contentOffset); //No content. Hence set it to zero. |
|
213 TPckg<TInt> rightsSize(size); |
|
214 bufPtr.Append(rightsSize); //Append the size of the rights message |
|
215 //Append the xml message |
|
216 bufPtr.Append(*bodyBuf); |
|
217 |
|
218 //Now write this buffer to file |
|
219 User::LeaveIfError(file.Write(*iData)); |
|
220 CleanupStack::PopAndDestroy(&file); |
|
221 CleanupStack::PopAndDestroy(bodyBuf); |
|
222 |
|
223 iState = ECAFInterface; |
|
224 IdleComplete(); |
|
225 } |
|
226 |
|
227 void CROContentHandler::ProcessToCAFL() |
|
228 { |
|
229 __LOG_PTR_DEBUG("CROContentHandler:: ProcessToCAF called"); |
|
230 |
|
231 iCAFInterface = new(ELeave) CROCHCAFInterface(iFs); |
|
232 |
|
233 //Register with the CAF session - this initialises the generic variables |
|
234 iCAFInterface->RegisterL(KROTextContentType); |
|
235 |
|
236 if(!iCAFInterface->Registered()) |
|
237 { |
|
238 //No CAF agent registered which can handle this mime type. |
|
239 User::Leave(KErrNotFound); |
|
240 } |
|
241 //Initialise the CAF session - this initialises the interface variables and import file |
|
242 iCAFInterface->PrepareProcessingL(); |
|
243 //Then start the CAF processing |
|
244 |
|
245 |
|
246 if(iCAFInterface->Processing()) |
|
247 { |
|
248 //Write the data to CAF |
|
249 iCAFInterface->WriteDataL(*iData); |
|
250 //Finally terminate CAF session |
|
251 iCAFInterface->EndProcessingL(); |
|
252 } |
|
253 |
|
254 iState = EDeleteFile; |
|
255 IdleComplete(); |
|
256 } |
|
257 |
|
258 void CROContentHandler::DeleteTempROFile() |
|
259 { |
|
260 TFileName roFileName; |
|
261 roFileName.Append(KWapPushDir); |
|
262 roFileName.Append(KTempROFile); |
|
263 iFs.Delete(roFileName); |
|
264 iState = EDone; |
|
265 IdleComplete(); |
|
266 } |
|
267 |
|
268 /** |
|
269 * Same functionality as DoCancel() |
|
270 */ |
|
271 void CROContentHandler::CancelHandleMessage() |
|
272 { |
|
273 __LOG_PTR_DEBUG("CROContentHandler:: CancelHandleMessage called"); |
|
274 Complete(KErrCancel); |
|
275 } |
|
276 |
|
277 /** |
|
278 * Cancels the handling of the message and revokes the active status |
|
279 * of the handler |
|
280 */ |
|
281 void CROContentHandler::DoCancel() |
|
282 { |
|
283 __LOG_PTR_DEBUG("CROContentHandler:: DoCancel Called"); |
|
284 Complete(KErrCancel); |
|
285 } |
|
286 |
|
287 /** |
|
288 * Step through the various representative states for handling a message |
|
289 * 1. Conversion of WBXML if necessary |
|
290 * 2. Store the xml file |
|
291 * 3. Pass file to CAF |
|
292 * 4. Delete File |
|
293 * 5. Complete |
|
294 */ |
|
295 void CROContentHandler::RunL() |
|
296 { |
|
297 __LOG_PTR_DEBUG("CROContentHandler:: RunL Called"); |
|
298 |
|
299 |
|
300 // use active state machine routine to manage activites: |
|
301 switch (iState) |
|
302 { |
|
303 case EConverting : |
|
304 ConvertPushMsgL(); |
|
305 break; |
|
306 case EStoring: |
|
307 SaveROToXMLFileL(); |
|
308 break; |
|
309 case ECAFInterface: |
|
310 ProcessToCAFL(); |
|
311 break; |
|
312 case EDeleteFile: |
|
313 DeleteTempROFile(); |
|
314 break; |
|
315 case EDone: |
|
316 Complete(KErrNone); |
|
317 break; |
|
318 default: |
|
319 break; |
|
320 } |
|
321 } |
|
322 |
|
323 /** |
|
324 * CPluginActiveBase methods |
|
325 */ |
|
326 TInt CROContentHandler::RunError(TInt aError) |
|
327 { |
|
328 __LOG_PTR_DEBUG("CROContentHandler:: RunError Called"); |
|
329 iState=EDone; |
|
330 Complete(aError); |
|
331 return KErrNone; |
|
332 } |