|
1 /* |
|
2 * Copyright (c) 2005 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: An EMN handler WAP Push Plugin. |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <push/ccontenthandlerbase.h> |
|
21 #include "EMNHandler.h" |
|
22 #include "EMNLogging.h" |
|
23 |
|
24 #include <ecom/implementationproxy.h> // for ECOM |
|
25 |
|
26 #include <xml/parser.h> |
|
27 |
|
28 _LIT( KReserved, "Reserved" ); |
|
29 _LIT( KEMNWBXMLMediaType, "application/vnd.wap.emn+wbxml" ); |
|
30 _LIT( KEMNXMLMediaType, "text/vnd.wap.emn+xml" ); |
|
31 _LIT8( KDictionaryUri, "-//WAPFORUM//DTD EMN 1.0//EN~0" ); |
|
32 _LIT8( KWBXMLMimeType, "text/wbxml"); |
|
33 _LIT8( KXMLMimeType, "text/xml"); |
|
34 |
|
35 //----------------------------------------------------------------------------- |
|
36 // |
|
37 //----------------------------------------------------------------------------- |
|
38 void CEMNHandler::CPushHandlerBase_Reserved1() |
|
39 { |
|
40 User::Panic(KReserved, KErrNotSupported); |
|
41 } |
|
42 |
|
43 //----------------------------------------------------------------------------- |
|
44 // |
|
45 //----------------------------------------------------------------------------- |
|
46 void CEMNHandler::CPushHandlerBase_Reserved2() |
|
47 { |
|
48 User::Panic(KReserved, KErrNotSupported); |
|
49 } |
|
50 |
|
51 //----------------------------------------------------------------------------- |
|
52 // |
|
53 //----------------------------------------------------------------------------- |
|
54 CEMNHandler::CEMNHandler() : CPushHandlerBase() |
|
55 { |
|
56 CActiveScheduler::Add( this ); |
|
57 } |
|
58 |
|
59 //----------------------------------------------------------------------------- |
|
60 // |
|
61 //----------------------------------------------------------------------------- |
|
62 void CEMNHandler::ConstructL() |
|
63 { |
|
64 } |
|
65 |
|
66 //----------------------------------------------------------------------------- |
|
67 // |
|
68 //----------------------------------------------------------------------------- |
|
69 CEMNHandler* CEMNHandler::NewL() |
|
70 { |
|
71 CEMNHandler* self = new (ELeave) CEMNHandler(); |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL(); |
|
74 CleanupStack::Pop( self ); |
|
75 return self; |
|
76 } |
|
77 |
|
78 //----------------------------------------------------------------------------- |
|
79 // |
|
80 //----------------------------------------------------------------------------- |
|
81 CEMNHandler::~CEMNHandler() |
|
82 { |
|
83 KEMNLOGGER_FN1("CEMNHandler::~CEMNHandler()"); |
|
84 |
|
85 delete iMessage; |
|
86 delete iBody; |
|
87 |
|
88 KEMNLOGGER_FN2("CEMNHandler::~CEMNHandler()"); |
|
89 } |
|
90 |
|
91 //----------------------------------------------------------------------------- |
|
92 // |
|
93 //----------------------------------------------------------------------------- |
|
94 void CEMNHandler::IdleComplete() |
|
95 { |
|
96 TRequestStatus* status = &iStatus; |
|
97 User::RequestComplete( status, KErrNone ); |
|
98 SetActive(); |
|
99 } |
|
100 |
|
101 //----------------------------------------------------------------------------- |
|
102 // |
|
103 //----------------------------------------------------------------------------- |
|
104 void CEMNHandler::Done( TInt aError ) |
|
105 { |
|
106 if ( iAsyncHandling ) |
|
107 { |
|
108 SignalConfirmationStatus( aError ); |
|
109 } |
|
110 // Time to commit suicide |
|
111 iPluginKiller->KillPushPlugin(); |
|
112 } |
|
113 |
|
114 //----------------------------------------------------------------------------- |
|
115 // |
|
116 //----------------------------------------------------------------------------- |
|
117 void CEMNHandler::HandleMessageL( CPushMessage* aPushMsg, TRequestStatus& aStatus ) |
|
118 { |
|
119 KEMNLOGGER_FN1("CEMNHandler::HandleMessageL() 1"); |
|
120 |
|
121 iAsyncHandling = ETrue; |
|
122 SetConfirmationStatus( aStatus ); |
|
123 HandleMessageL( aPushMsg ); |
|
124 |
|
125 KEMNLOGGER_FN2("CEMNHandler::HandleMessageL() 1"); |
|
126 } |
|
127 |
|
128 //----------------------------------------------------------------------------- |
|
129 // |
|
130 //----------------------------------------------------------------------------- |
|
131 void CEMNHandler::HandleMessageL( CPushMessage* aPushMsg ) |
|
132 { |
|
133 KEMNLOGGER_FN1("CEMNHandler::HandleMessageL() 2"); |
|
134 |
|
135 if ( iMessage ) |
|
136 { |
|
137 delete iMessage; |
|
138 iMessage = NULL; |
|
139 } |
|
140 iMessage = aPushMsg; |
|
141 iState = EParsing; |
|
142 IdleComplete(); |
|
143 |
|
144 KEMNLOGGER_FN2("CEMNHandler::HandleMessageL() 2"); |
|
145 } |
|
146 |
|
147 //----------------------------------------------------------------------------- |
|
148 // |
|
149 //----------------------------------------------------------------------------- |
|
150 void CEMNHandler::CancelHandleMessage() |
|
151 { |
|
152 Done( KErrCancel ); |
|
153 } |
|
154 |
|
155 //----------------------------------------------------------------------------- |
|
156 // |
|
157 //----------------------------------------------------------------------------- |
|
158 void CEMNHandler::DoCancel() |
|
159 { |
|
160 KEMNLOGGER_FN1("CEMNHandler::DoCancel()"); |
|
161 |
|
162 Done( KErrCancel ); |
|
163 |
|
164 KEMNLOGGER_FN2("CEMNHandler::DoCancel()"); |
|
165 } |
|
166 |
|
167 //----------------------------------------------------------------------------- |
|
168 // |
|
169 //----------------------------------------------------------------------------- |
|
170 void CEMNHandler::RunL() |
|
171 { |
|
172 switch ( iState ) |
|
173 { |
|
174 case EParsing : |
|
175 iState = EProcessing; |
|
176 ParsePushMsgL(); |
|
177 break; |
|
178 |
|
179 case EProcessing: |
|
180 iState = EDone; |
|
181 ProcessPushMsgL(); |
|
182 break; |
|
183 |
|
184 case EDone: |
|
185 Done( KErrNone ); |
|
186 break; |
|
187 |
|
188 default: |
|
189 iState = EDone; // EMN silently discarded if something went wrong. |
|
190 break; |
|
191 } |
|
192 } |
|
193 |
|
194 //----------------------------------------------------------------------------- |
|
195 // |
|
196 //----------------------------------------------------------------------------- |
|
197 void CEMNHandler::ParsePushMsgL() |
|
198 { |
|
199 KEMNLOGGER_FN1("CEMNHandler::ParsePushMsgL()"); |
|
200 |
|
201 TPtrC8 body; |
|
202 TPtrC contentType; |
|
203 CParser* parser = NULL; |
|
204 CEMNXMLContentHandler* handler = NULL; |
|
205 |
|
206 // Check content type and leave if not correct |
|
207 iMessage->GetContentType( contentType ); |
|
208 if ( contentType.FindF( KEMNXMLMediaType ) == KErrNotFound && |
|
209 contentType.FindF( KEMNWBXMLMediaType ) == KErrNotFound ) |
|
210 { |
|
211 User::Leave( KErrNotSupported ); |
|
212 } |
|
213 |
|
214 if ( iMessage->GetMessageBody( body ) ) |
|
215 { |
|
216 User::LeaveIfNull( iBody = body.Alloc() ); |
|
217 } |
|
218 |
|
219 KEMNLOGGER_WRITE_FORMAT("CEMNHandler::ParsePushMsgL(): contentType = %s ", contentType.Ptr() ); |
|
220 |
|
221 if ( iBody && |
|
222 contentType.FindF( KEMNXMLMediaType ) != KErrNotFound ) |
|
223 { |
|
224 // Ascii |
|
225 KEMNLOGGER_WRITE("CEMNHandler::ParsePushMsgL(): Ascii"); |
|
226 |
|
227 // Create a new content handler |
|
228 handler = CEMNXMLContentHandler::NewLC( iElement, ETrue ); |
|
229 |
|
230 // Create a new XML parser and push it to cleanup stack |
|
231 parser = CParser::NewLC( KXMLMimeType, *handler ); |
|
232 parser->ParseBeginL(); |
|
233 parser->ParseL( iBody->Des() ); |
|
234 parser->ParseEndL(); |
|
235 |
|
236 CleanupStack::PopAndDestroy( 2, handler ); // parser // CSI: 12,47 # nothing wrong |
|
237 } |
|
238 else if ( iBody && |
|
239 contentType.FindF( KEMNWBXMLMediaType ) != KErrNotFound ) |
|
240 { |
|
241 // Binary |
|
242 KEMNLOGGER_WRITE("CEMNHandler::ParsePushMsgL(): Binary"); |
|
243 // Create a new content handler |
|
244 handler = CEMNXMLContentHandler::NewLC( iElement, EFalse ); |
|
245 |
|
246 // Create a new WBXML parser and push it to cleanup stack |
|
247 parser = CParser::NewLC( KWBXMLMimeType, *handler ); |
|
248 // Set correct String Dictionary into use |
|
249 parser->AddPreloadedDictionaryL( KDictionaryUri ); |
|
250 // Start the actual parse operation. |
|
251 parser->ParseBeginL(); |
|
252 parser->ParseL( iBody->Des() ); |
|
253 parser->ParseEndL(); |
|
254 |
|
255 CleanupStack::PopAndDestroy( 2, handler ); // parser // CSI: 12,47 # nothing wrong |
|
256 } |
|
257 else |
|
258 { |
|
259 KEMNLOGGER_WRITE("CEMNHandler::ParsePushMsgL(): Body missing or unknown content type -> discarding"); |
|
260 } |
|
261 |
|
262 if ( iElement.mailbox.Length() == 0 ) |
|
263 { |
|
264 // No need to call AOEmailPlugin if there was no email address in EMN. |
|
265 iState = EDone; |
|
266 } |
|
267 |
|
268 IdleComplete(); |
|
269 KEMNLOGGER_FN2("CEMNHandler::ParsePushMsgL()"); |
|
270 } |
|
271 |
|
272 //----------------------------------------------------------------------------- |
|
273 // |
|
274 //----------------------------------------------------------------------------- |
|
275 void CEMNHandler::ProcessPushMsgL() |
|
276 { |
|
277 KEMNLOGGER_FN1("CEMNHandler::ProcessPushMsgL()"); |
|
278 |
|
279 // Create a command that server should execute |
|
280 TAlwaysOnlineServerAPICommands command = EServerAPIEmailEMNReceived; |
|
281 |
|
282 // Create a package descriptor from iElement, in order to be able to send it to server as a TDes8& |
|
283 TPckg<TEMNElement> parameters( iElement ); |
|
284 |
|
285 // Connect client and close the connection after the message is sent |
|
286 TInt err = iAOClient.Connect(); |
|
287 if ( err == KErrNone ) |
|
288 { |
|
289 iAOClient.RelayCommandL( command, parameters ); |
|
290 iAOClient.Close(); |
|
291 } |
|
292 else |
|
293 { |
|
294 KEMNLOGGER_WRITE_FORMAT("CEMNHandler::ProcessPushMsgL(): err = %d", err ); |
|
295 } |
|
296 |
|
297 IdleComplete(); |
|
298 |
|
299 KEMNLOGGER_FN2("CEMNHandler::ProcessPushMsgL()"); |
|
300 } |
|
301 |
|
302 //----------------------------------------------------------------------------- |
|
303 // ECOM PLUGIN LOADING STUFF |
|
304 //----------------------------------------------------------------------------- |
|
305 const TImplementationProxy ImplementationTable[] = |
|
306 { |
|
307 IMPLEMENTATION_PROXY_ENTRY( 0x1027508C, CEMNHandler::NewL ) |
|
308 }; |
|
309 |
|
310 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
|
311 TInt& aTableCount ) |
|
312 { |
|
313 aTableCount = |
|
314 sizeof( ImplementationTable ) / sizeof( TImplementationProxy ); |
|
315 return ImplementationTable; |
|
316 } |
|
317 |