|
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: Declaration of CSIContentHandler. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __CSICONTENTHANDLER_H__ |
|
21 #define __CSICONTENTHANDLER_H__ |
|
22 |
|
23 |
|
24 // INCLUDE FILES |
|
25 |
|
26 #include "CPushContentHandlerBase.h" |
|
27 #include "PushContentHandlerDef.hrh" |
|
28 #include <E32Base.h> |
|
29 #include <msvstd.h> |
|
30 #include <nw_dom_attribute.h> |
|
31 #include <CharConv.h> |
|
32 |
|
33 // CONSTANTS |
|
34 |
|
35 const TUid KUidPushSIContentHandler = { EUidPushSIContentHandler }; |
|
36 _LIT(KSIContentHandlerData,"text/vnd.wap.si||application/vnd.wap.sic"); |
|
37 |
|
38 // FORWARD DECLARATIONS |
|
39 |
|
40 class CSIPushMsgEntry; |
|
41 |
|
42 // CLASS DECLARATION |
|
43 |
|
44 /** |
|
45 * CSIContentHandler handles Service Indication content |
|
46 * |
|
47 * This handler takes ownership of the SI message and processes it |
|
48 * according to the Reception rules |
|
49 * [WAP Service Indication version 31-July-2001] |
|
50 * and either stores the message or deletes it. |
|
51 * Also S60 specific requirements are applied. |
|
52 * |
|
53 * OVERVIEW: |
|
54 * The main body of this class and its functionality lies within |
|
55 * HandleMessage (asynchonous). This : |
|
56 * 1. takes ownership of the push message |
|
57 * 2. validates the message and generates a parsed document tree |
|
58 * 3. extracts the message attribute values from document tree |
|
59 * 4. processes the received message |
|
60 * 5. finishes |
|
61 * |
|
62 * NB: A received message with no creation date will be stored (unless |
|
63 * its action is set to delete or the expiry condition is met). This |
|
64 * means that the si-id in the message store will not be unique. |
|
65 */ |
|
66 class CSIContentHandler : public CPushContentHandlerBase |
|
67 { |
|
68 public: // Constructors and destructor |
|
69 |
|
70 /** |
|
71 * Two-phased constructor. Leaves on failure. |
|
72 * @return The constructed object. |
|
73 */ |
|
74 static CSIContentHandler* NewL(); |
|
75 |
|
76 /** |
|
77 * Destructor. |
|
78 */ |
|
79 virtual ~CSIContentHandler(); |
|
80 |
|
81 private: // Constructors |
|
82 |
|
83 /** |
|
84 * Constructor. |
|
85 */ |
|
86 CSIContentHandler(); |
|
87 |
|
88 /** |
|
89 * Symbian OS constructor. |
|
90 */ |
|
91 void ConstructL(); |
|
92 |
|
93 private: // New functions |
|
94 |
|
95 /** |
|
96 * Do Garbage Collection synchronously. |
|
97 * @return None. |
|
98 */ |
|
99 void CollectGarbageL(); |
|
100 |
|
101 /** |
|
102 * Parse the current message. If the SI is wbxml encoded then it is |
|
103 * decoded first to XML format. Then the message details (attributes) |
|
104 * are earned from the XML tree. |
|
105 * @return None. |
|
106 */ |
|
107 void ParsePushMsgL(); |
|
108 |
|
109 /** |
|
110 * Parse the indication element. |
|
111 * @param aIndication The element to be parsed. |
|
112 * @return None. |
|
113 */ |
|
114 void ParseIndicationL( NW_DOM_ElementNode_t& aIndication ); |
|
115 |
|
116 /** |
|
117 * Parse an attribute of the indication element. |
|
118 * @param aAttrHandle The attribute to be parsed. |
|
119 * @return None. |
|
120 */ |
|
121 void ParseIndAttributeL( NW_DOM_AttributeHandle_t& aAttrHandle ); |
|
122 |
|
123 /** |
|
124 * Parse the text of the indication element. |
|
125 * @param aTextNode The text node to be parsed. |
|
126 * @return None. |
|
127 */ |
|
128 void ParseTextL( NW_DOM_TextNode_t& aTextNode ); |
|
129 |
|
130 |
|
131 /** |
|
132 * Converts the given buffer to unicode (UCS-2). |
|
133 * @param aSrc Source text. |
|
134 * @param aCharSetId Character set ID. |
|
135 * @return The UCS-2 unicode buffer. |
|
136 */ |
|
137 HBufC16* ConvertToUnicodeL( const TDesC8& aSrc, TUint aCharSetId ); |
|
138 |
|
139 /** |
|
140 * Converts the given buffer to unicode (UCS-2). |
|
141 * @param aString Source text. |
|
142 * @param aCharEncoding Character encoding. |
|
143 * @return The UCS-2 unicode buffer. |
|
144 */ |
|
145 HBufC16* ConvertToUnicodeL( NW_String_t& aString, NW_Uint32 aCharEncoding ); |
|
146 |
|
147 /** |
|
148 * Initialise the converter. |
|
149 * @return None. |
|
150 */ |
|
151 void InitialiseCharacterSetConverterL(); |
|
152 |
|
153 |
|
154 /** |
|
155 * Convert the action string to a representative numeric value to |
|
156 * facilitate storing the message. |
|
157 * @param aActionString The attribute value indicating the action level |
|
158 * eg 'signal-high' |
|
159 * @return TUint: a value representing the action type. |
|
160 */ |
|
161 TUint ConvertActionString( const TDesC8& aActionString ) const; |
|
162 |
|
163 /** |
|
164 * The entry fields are set to the correct values. |
|
165 * @return None. |
|
166 */ |
|
167 void SetSIPushMsgEntryFieldsL( CSIPushMsgEntry& aSIPushMsgEntry ); |
|
168 |
|
169 /** |
|
170 * Do the final processing of the message according to the OMA and S60 |
|
171 * requirements. |
|
172 * @return None. |
|
173 */ |
|
174 void ProcessingPushMsgEntryL(); |
|
175 |
|
176 /** |
|
177 * Store the new message to Messaging. |
|
178 * @param aMatchingEntryId ID of the matching SI entry. |
|
179 * @return None. |
|
180 */ |
|
181 void StoreSIMessageL( TMsvId aMatchingEntryId ); |
|
182 |
|
183 /** |
|
184 * Handle message order reception. |
|
185 * NB: A received message with no creation date will be stored (unless |
|
186 * its action is set to delete or the expiry condition is met). This |
|
187 * means that the si-id in the message store will not be unique. |
|
188 * @param aMatchingEntryId ID of the matching SI entry. |
|
189 * It is changed only if the function returns EFalse (replace)! |
|
190 * @return ETrue if the entry has to be discarded. |
|
191 */ |
|
192 TBool HandleMsgOrderReceptionL( TMsvId& aMatchingEntryId ); |
|
193 |
|
194 // conversion utilities |
|
195 |
|
196 /** |
|
197 * Convert UTC date time into native TTime format. Method can leave. |
|
198 * @param aDateTime The UTC string representing the date and time. |
|
199 * @param aConvertedDate Member date variable passed in to accept |
|
200 * converted UTC date as TTime varaible. |
|
201 * @return TBool indicates if conversion successful (ETrue) or |
|
202 * conversion failed (EFalse) |
|
203 */ |
|
204 TBool ConvertDateTimeL( const TDesC& aDateTime, |
|
205 TTime& aConvertedDate ) const; |
|
206 |
|
207 /** |
|
208 * Convert OPAQUE data to UTC date time as specified in SI spec. |
|
209 * @param aOpaque OPAQUE data. |
|
210 * @return The UTC time. |
|
211 */ |
|
212 HBufC* ConvertOpaqueToUtcL( const TDesC8& aOpaque ) const; |
|
213 |
|
214 /** |
|
215 * Check given UTC time string conforms to expected format: |
|
216 * YYYY-MM-DDTHH:MM:SSZ and strip out formatting characters |
|
217 * then validate the remaining characters are all digits. |
|
218 * If validated then add TTime formating character so final |
|
219 * string returned will be of the format YYYYMMDD:HHMMSS. |
|
220 * @param aDateTime UTC string which is validated and returned. |
|
221 * @return boolean: indicates if given date is valid (ETrue) |
|
222 * or not (EFalse) |
|
223 */ |
|
224 TBool IsValidUTCTime( TDes& aDateTime ) const; |
|
225 |
|
226 /** |
|
227 * Convert OPAQUE or STRING attribute to TTime. |
|
228 * @param aAttrHandle Handle to the attribute. |
|
229 * @param aConvertedDate The resulted TTime. |
|
230 * @return ETrue if the conversion succeeded. |
|
231 */ |
|
232 TBool AttributeToTTimeL( NW_DOM_AttributeHandle_t& aAttrHandle, |
|
233 TTime& aConvertedDate ) const; |
|
234 |
|
235 // Attribute flags |
|
236 |
|
237 /** |
|
238 * Flag whether message has an action attribute |
|
239 * @param aAction boolean to set flag to - |
|
240 * ETrue for action attrib present |
|
241 * EFalse for no action attrib. |
|
242 */ |
|
243 inline void SetActionFlag( TBool aAction ); |
|
244 |
|
245 /** |
|
246 * Check status of action flag to see if message has an action |
|
247 * attribute. |
|
248 * @return TBool ETrue - action attribute present in message |
|
249 * EFalse - no action attribute. |
|
250 */ |
|
251 inline TBool ActionFlag() const; |
|
252 |
|
253 /** |
|
254 * Flag whether message has a created date attribute. |
|
255 * @param aCreated boolean to set flag to - |
|
256 * ETrue for si-created attrib present |
|
257 * EFalse for no si-created attrib |
|
258 */ |
|
259 inline void SetCreatedFlag( TBool aCreated ); |
|
260 |
|
261 /** |
|
262 * Check status of created flag to see if message has a si-created |
|
263 * attribute. |
|
264 * @return TBool ETrue - si-created attribute present in message |
|
265 * EFalse - no si-created attribute |
|
266 */ |
|
267 inline TBool CreatedFlag() const; |
|
268 |
|
269 /** |
|
270 * Flag whether message has a Href attribute |
|
271 * @param aHref boolean to set flag to - |
|
272 * ETrue for Href attrib present |
|
273 * EFalse for no href attrib |
|
274 */ |
|
275 inline void SetHrefFlag( TBool aHref ); |
|
276 |
|
277 /** |
|
278 * Check status of href flag to see if message has an href attribute. |
|
279 * @return TBool |
|
280 * ETrue - href attribute present in message |
|
281 * EFalse - no href attribute |
|
282 */ |
|
283 inline TBool HrefFlag() const; |
|
284 |
|
285 /** |
|
286 * Flag whether message has an expiry date attribute (si-expires). |
|
287 * @param aExpires boolean to set flag to - |
|
288 * ETrue for si-expires present |
|
289 * EFalse for no si-expires date |
|
290 */ |
|
291 inline void SetExpiresFlag( TBool aExpires ); |
|
292 |
|
293 /** |
|
294 * Check status of flag to see if message has an expiry date attribute. |
|
295 * @return TBool |
|
296 * ETrue - si-expires attribute present in message |
|
297 * EFalse - no si-expires attribute |
|
298 */ |
|
299 inline TBool ExpiresFlag() const; |
|
300 |
|
301 /** |
|
302 * Flag whether message has a si-id attribute |
|
303 * @param aSiId boolean to set flag to - |
|
304 * ETrue for si-id attrib present |
|
305 * EFalse for no si-id attrib |
|
306 */ |
|
307 inline void SetSiIdFlag( TBool aSiId ); |
|
308 |
|
309 /** |
|
310 * Check status of flag to see if message has an si-id attribute. |
|
311 * @return TBool |
|
312 * ETrue - si-id attribute present in message |
|
313 * EFalse - no si-id attribute |
|
314 */ |
|
315 inline TBool SiIdFlag() const; |
|
316 |
|
317 /** |
|
318 * Flag whether message has a Data attribute (text) |
|
319 * @param aData |
|
320 * boolean to set flag to - ETrue for data attrib present |
|
321 * EFalse for no data attrib |
|
322 */ |
|
323 inline void SetDataFlag( TBool aData ); |
|
324 |
|
325 /** |
|
326 * Check status of data flag to see if message has any data. |
|
327 * @return TBool |
|
328 * ETrue - data attribute present in message |
|
329 * EFalse - no data attribute |
|
330 */ |
|
331 inline TBool DataFlag() const; |
|
332 |
|
333 private: // Methods from CPushHandlerBase |
|
334 |
|
335 /** |
|
336 * HandleMessage Async. Version. Takes ownership of Push Message and |
|
337 * sets self active to continue processing message. |
|
338 * @param aPushMsg CPushMessage to process. |
|
339 * @param aStatus Request status variable for use in asynchronous |
|
340 * operations. |
|
341 * @return None. |
|
342 */ |
|
343 void HandleMessageL( CPushMessage* aPushMsg, TRequestStatus& aStatus ); |
|
344 |
|
345 /** |
|
346 * HandleMessage Sync. Version. Takes ownership of Push Message and |
|
347 * sets self active to continue processing message. |
|
348 * Initial State: Set data members then go to the next state |
|
349 * @param aPushMsg CPushMessage to process. |
|
350 */ |
|
351 void HandleMessageL( CPushMessage* aPushMsg ); |
|
352 |
|
353 /** |
|
354 * Same functionality as DoCancel() |
|
355 */ |
|
356 void CancelHandleMessage(); |
|
357 |
|
358 /** |
|
359 * Reserved function. |
|
360 */ |
|
361 void CPushHandlerBase_Reserved1(); |
|
362 |
|
363 /** |
|
364 * Reserved function. |
|
365 */ |
|
366 void CPushHandlerBase_Reserved2(); |
|
367 |
|
368 private: // Methods from CActive |
|
369 |
|
370 /** |
|
371 * Terminates any activity |
|
372 * @return None. |
|
373 */ |
|
374 void DoCancel(); |
|
375 |
|
376 /** |
|
377 * Step through the various representative states for handling a message |
|
378 * States: |
|
379 * EGarbageCollecting - Deleting expired SI msgs from messaging |
|
380 * EFilteringAndParsing - Filter push msg according to Service message |
|
381 * settings and Parses SI push message (retrieving the |
|
382 * attributes) |
|
383 * EProcessing - Processing the current entry. OMA and S60 rules are |
|
384 * applied, then save or update SI msg in the Msg store |
|
385 * EDone - Clean up, complete observer |
|
386 * @return None. |
|
387 */ |
|
388 void RunL(); |
|
389 |
|
390 /** |
|
391 * This is invoked when RunL Leaves with an error so clean up and |
|
392 * return. |
|
393 * @return Error code to scheduler. |
|
394 */ |
|
395 TInt RunError(TInt aError); |
|
396 |
|
397 private: // Data |
|
398 |
|
399 enum |
|
400 { |
|
401 EAction = 0x01, |
|
402 ECreated = 0x02, |
|
403 EHref = 0x04, |
|
404 EExpires = 0x08, |
|
405 ESiId = 0x10, |
|
406 EData = 0x20 |
|
407 }; |
|
408 |
|
409 enum TState |
|
410 { |
|
411 EGarbageCollecting, |
|
412 EFilteringAndParsing, |
|
413 EProcessing, |
|
414 EDone |
|
415 }; |
|
416 |
|
417 TMsvId iSavedMsgId; ///< ID of the message saved. |
|
418 TUint32 iAttributes; ///< Attribute indication (set or not). |
|
419 TInt iPushMsgAction; ///< Action attribute |
|
420 HBufC* iHrefBuf; ///< Href attribute. Has. |
|
421 HBufC* iSiIdBuf; ///< Si-id attribute. Has. |
|
422 TTime iExpiresTime; ///< Expiration attribute. |
|
423 TTime iCreatedTime; ///< Created attribute. |
|
424 HBufC* iData; ///< Message text. Has. |
|
425 |
|
426 NW_Uint32 iCharEncoding; ///< Char encoding of the current msg. |
|
427 |
|
428 // |
|
429 CCnvCharacterSetConverter* iCharacterSetConverter; ///< Owned. |
|
430 CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* iCharacterSetsAvailable; ///< Owned. |
|
431 }; |
|
432 |
|
433 #include "CSIContentHandler.inl" |
|
434 |
|
435 #endif // __CSICONTENTHANDLER_H__ |
|
436 |