|
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 the License "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: Implementation of CMultiPartMixedContentHandler. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 |
|
20 #include "CMultiPartMixedContentHandler.h" |
|
21 #include <push/pushdispatcher.h> |
|
22 #include <push/cmultiparttextiterator.h> |
|
23 #include <push/cmultipartbiniterator.h> |
|
24 |
|
25 // Constants |
|
26 |
|
27 _LIT(KReserved, "Reserved"); |
|
28 #if defined(_DEBUG) |
|
29 _LIT(KErrPushMsgNull, "NULL CPushMessage"); |
|
30 #endif |
|
31 |
|
32 /** |
|
33 * Static Factory Construction |
|
34 * |
|
35 * @param aFs Reference to a file session |
|
36 * @param aLibrary Reference to DLL Library Object |
|
37 * @param aIndex Index number corresponding to the Unknown App Handler Class |
|
38 * 'EMultiPartMixedContentHandler' |
|
39 * |
|
40 * @return fully initialized instance of this class |
|
41 */ |
|
42 CMultiPartMixedContentHandler* CMultiPartMixedContentHandler::NewL() |
|
43 { |
|
44 CMultiPartMixedContentHandler* self = |
|
45 new (ELeave) CMultiPartMixedContentHandler; |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 /** |
|
53 * Destructor |
|
54 */ |
|
55 CMultiPartMixedContentHandler::~CMultiPartMixedContentHandler() |
|
56 { |
|
57 Cancel(); |
|
58 delete iMultiMessage; |
|
59 iContentHandler = NULL; // Not owned. |
|
60 } |
|
61 |
|
62 /** |
|
63 * Constructor |
|
64 * |
|
65 * @param aFs Reference to a file session |
|
66 * @param aLibrary Reference to DLL Library Object |
|
67 * @param aIndex Index number corresponding to the Unknown App Handler Class |
|
68 * 'EMultiPartMixedContentHandler' |
|
69 */ |
|
70 CMultiPartMixedContentHandler::CMultiPartMixedContentHandler() |
|
71 : CContentHandlerBase() |
|
72 { |
|
73 } |
|
74 |
|
75 /** |
|
76 * This will complete initialization of the object |
|
77 */ |
|
78 void CMultiPartMixedContentHandler::ConstructL() |
|
79 { |
|
80 CActiveScheduler::Add(this); |
|
81 } |
|
82 |
|
83 #ifdef __TEST_MULTIPART_MIX_SUPP |
|
84 |
|
85 /** |
|
86 * Creates a Multipart Binary Iterator that will be used for splitting apart the binary |
|
87 * mulitpart. |
|
88 * |
|
89 * @param aPushMsg A WAP binary multipart.mixed message that will be processed |
|
90 */ |
|
91 void CMultiPartMixedContentHandler::LoadMultipartMsgL() |
|
92 { |
|
93 __ASSERT_DEBUG( iMessage!= 0 , User::Panic(KErrPushMsgNull,0)); |
|
94 |
|
95 TPtrC contentType; |
|
96 iMessage->GetContentType(contentType); |
|
97 if (!contentType.FindF(KMultipartText)) |
|
98 iMultiMessage = CMultipartTextIterator::NewL(*iMessage); |
|
99 else if (!contentType.FindF(KMultipartBin)) |
|
100 iMultiMessage = CMultipartBinIterator::NewL(*iMessage); |
|
101 else |
|
102 User::Leave(KErrCorrupt); |
|
103 |
|
104 iMultiMessage->FirstL(); |
|
105 iState = EHandlePart; |
|
106 |
|
107 IdleComplete(); |
|
108 } |
|
109 |
|
110 /** |
|
111 * Handles the Message Part returned from the Multipart iterator |
|
112 * by creating a new handler based on the Content-Type, then dispatches it |
|
113 * synchronously. |
|
114 */ |
|
115 void CMultiPartMixedContentHandler::HandlePartL() |
|
116 { |
|
117 CPushMessage* msgPart = iMultiMessage->PartL(); |
|
118 CleanupStack::PushL(msgPart); |
|
119 |
|
120 TPtrC contentType; |
|
121 msgPart->GetContentType(contentType); |
|
122 CContentHandlerBase& contentHandler = |
|
123 PushContentTypeDispatcher::GetHandlerL( contentType, *iLog, *iManager ); |
|
124 iContentHandler = &contentHandler; |
|
125 CleanupStack::Pop(msgPart); |
|
126 |
|
127 // treat as an acknowledged message always to ensure |
|
128 // sequential creation of handlers |
|
129 iContentHandler->HandleMessageL(msgPart, iStatus); |
|
130 iState = ENextPart; |
|
131 SetActive(); |
|
132 } |
|
133 |
|
134 /** |
|
135 * Moves multipart iterator to the next part. If there is none, |
|
136 * State: EDone will be set to complete this handler |
|
137 */ |
|
138 void CMultiPartMixedContentHandler::NextPartL() |
|
139 { |
|
140 if (iMultiMessage->NextL()) |
|
141 iState = EHandlePart; |
|
142 else |
|
143 iState = EDone; |
|
144 |
|
145 IdleComplete(); |
|
146 } |
|
147 |
|
148 #endif // __TEST_MULTIPART_MIX_SUPP |
|
149 |
|
150 /** |
|
151 * The Asynchronous entry point for this plug-in to handle the CPushMessage. |
|
152 * |
|
153 * Since we really didn't start an async event, make it look as though our |
|
154 * asynchronous request has been completed. |
|
155 * |
|
156 * @param aPushMsg A WAP binary multipart.mixed message that will be processed |
|
157 * @param aStatus The TRequestStatus of the caller indicating that this will |
|
158 * be used aysnchronously |
|
159 */ |
|
160 void CMultiPartMixedContentHandler::HandleMessageL( CPushMessage* aPushMsg, |
|
161 TRequestStatus& aStatus ) |
|
162 { |
|
163 __ASSERT_DEBUG( aPushMsg != NULL, User::Panic(KErrPushMsgNull, KErrNone)); |
|
164 |
|
165 #ifdef __TEST_MULTIPART_MIX_SUPP |
|
166 iAcknowledge = ETrue; |
|
167 iMessage = aPushMsg; |
|
168 SetConfirmationStatus(aStatus); |
|
169 iState = ELoadMsgData; |
|
170 IdleComplete(); |
|
171 #else // __TEST_MULTIPART_MIX_SUPP |
|
172 iAcknowledge = ETrue; |
|
173 iMessage = aPushMsg; |
|
174 SetConfirmationStatus(aStatus); |
|
175 // Drop all multipart/mixed messages. |
|
176 iState = EDone; |
|
177 IdleComplete(); |
|
178 #endif // __TEST_MULTIPART_MIX_SUPP |
|
179 } |
|
180 |
|
181 |
|
182 /** |
|
183 * The Synchronous entry point for this plug-in to handle the CPushMessage. |
|
184 * |
|
185 * @param aPushMsg A WAP binary multipart.mixed message that will be processed |
|
186 * @param aStatus The TRequestStatus of the caller indicating that this will be |
|
187 * used aysnchronously |
|
188 */ |
|
189 void CMultiPartMixedContentHandler::HandleMessageL( CPushMessage* aPushMsg ) |
|
190 { |
|
191 __ASSERT_DEBUG( aPushMsg != NULL, User::Panic(KErrPushMsgNull, KErrNone)); |
|
192 |
|
193 #ifdef __TEST_MULTIPART_MIX_SUPP |
|
194 iAcknowledge = EFalse; |
|
195 iMessage = aPushMsg; |
|
196 iState = ELoadMsgData; |
|
197 IdleComplete(); |
|
198 #else // __TEST_MULTIPART_MIX_SUPP |
|
199 iAcknowledge = EFalse; |
|
200 iMessage = aPushMsg; |
|
201 // Drop all multipart messages. |
|
202 iState = EDone; |
|
203 IdleComplete(); |
|
204 #endif // __TEST_MULTIPART_MIX_SUPP |
|
205 } |
|
206 |
|
207 /** |
|
208 * Cancels Asynronous requests on called handler. |
|
209 */ |
|
210 void CMultiPartMixedContentHandler::CancelHandleMessage() |
|
211 { |
|
212 Cancel(); |
|
213 } |
|
214 |
|
215 void CMultiPartMixedContentHandler::CPushHandlerBase_Reserved1() |
|
216 { |
|
217 User::Panic(KReserved, KErrNotSupported); |
|
218 } |
|
219 |
|
220 void CMultiPartMixedContentHandler::CPushHandlerBase_Reserved2() |
|
221 { |
|
222 User::Panic(KReserved, KErrNotSupported); |
|
223 } |
|
224 |
|
225 /** |
|
226 * Cancels Asynronous requests on caller and completes self. |
|
227 */ |
|
228 void CMultiPartMixedContentHandler::DoCancel() |
|
229 { |
|
230 if ( iContentHandler ) |
|
231 { |
|
232 iContentHandler->CancelHandleMessage(); |
|
233 } |
|
234 Complete( KErrCancel ); |
|
235 } |
|
236 |
|
237 /** |
|
238 * State machine to step through the multipart message until it is done |
|
239 * |
|
240 * State EHandlePart: Starts the processing of each part of the multipart |
|
241 * State ENextPart: Moves the interator to point to the next part of the multipart |
|
242 * when there are no more parts, EDone will be the next state |
|
243 * State EDone: Clean up and complete |
|
244 */ |
|
245 void CMultiPartMixedContentHandler::RunL() |
|
246 { |
|
247 switch(iState) |
|
248 { |
|
249 |
|
250 #ifdef __TEST_MULTIPART_MIX_SUPP |
|
251 |
|
252 case ELoadMsgData: |
|
253 { |
|
254 LoadMultipartMsgL(); |
|
255 break; |
|
256 } |
|
257 case EHandlePart: |
|
258 { |
|
259 HandlePartL(); |
|
260 break; |
|
261 } |
|
262 case ENextPart: |
|
263 { |
|
264 NextPartL(); |
|
265 break; |
|
266 } |
|
267 |
|
268 #endif // __TEST_MULTIPART_MIX_SUPP |
|
269 |
|
270 case EDone: |
|
271 { |
|
272 Complete(KErrNone); |
|
273 break; |
|
274 } |
|
275 default: |
|
276 { |
|
277 break; |
|
278 } |
|
279 } |
|
280 } |
|
281 |
|
282 /** |
|
283 * Clean up |
|
284 */ |
|
285 TInt CMultiPartMixedContentHandler::RunError(TInt aError) |
|
286 { |
|
287 iState=EDone; |
|
288 Complete(aError); |
|
289 return KErrNone; |
|
290 } |
|
291 |