|
1 // Copyright (c) 2003-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 #include <push/csipushmsgentry.h> |
|
17 |
|
18 GLDEF_C TPtrC16 LimitStringSize(const TPtrC16& aString, TInt aMaxSize) |
|
19 { |
|
20 if (aString.Length() < aMaxSize) |
|
21 return aString; |
|
22 else |
|
23 return aString.Left(aMaxSize); |
|
24 } |
|
25 |
|
26 |
|
27 /** |
|
28 Allocates and constructs a new Service Indication WAP Push message entry. |
|
29 |
|
30 @return |
|
31 New Service Indication WAP Push message entry. |
|
32 */ |
|
33 EXPORT_C CSIPushMsgEntry* CSIPushMsgEntry::NewL() |
|
34 { |
|
35 CSIPushMsgEntry* self = new (ELeave) CSIPushMsgEntry(); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(); |
|
39 return self; |
|
40 } |
|
41 |
|
42 |
|
43 /** |
|
44 Allocates and constructs a new Service Indication WAP Push message entry, specifying |
|
45 the AppId as a string. |
|
46 |
|
47 @param aAppURI |
|
48 AppId in string form. |
|
49 |
|
50 @return |
|
51 New Service Indication WAP Push message entry. |
|
52 */ |
|
53 EXPORT_C CSIPushMsgEntry* CSIPushMsgEntry::NewL(const TPtrC8& aAppURI) |
|
54 { |
|
55 CSIPushMsgEntry* self = new (ELeave) CSIPushMsgEntry(); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(aAppURI); |
|
58 CleanupStack::Pop(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 /** |
|
64 Allocates and constructs a new Service Indication WAP Push message entry, specifying |
|
65 the AppId as a number. |
|
66 |
|
67 @param aAppID |
|
68 AppId in integer form. |
|
69 |
|
70 @return |
|
71 New Service Indication WAP Push message entry. |
|
72 */ |
|
73 EXPORT_C CSIPushMsgEntry* CSIPushMsgEntry::NewL(TInt& aAppID) |
|
74 { |
|
75 CSIPushMsgEntry* self = new (ELeave) CSIPushMsgEntry(); |
|
76 CleanupStack::PushL(self); |
|
77 self->ConstructL(aAppID); |
|
78 CleanupStack::Pop(); |
|
79 return self; |
|
80 } |
|
81 |
|
82 |
|
83 /** |
|
84 Destructor. |
|
85 */ |
|
86 EXPORT_C CSIPushMsgEntry::~CSIPushMsgEntry() |
|
87 { |
|
88 delete iText; |
|
89 delete iUrl; |
|
90 delete iMsgID; |
|
91 delete iOriginUri; |
|
92 } |
|
93 |
|
94 |
|
95 /** |
|
96 Sets the ID of SI Push Entry. |
|
97 |
|
98 @param aID |
|
99 The SI message ID. |
|
100 */ |
|
101 EXPORT_C void CSIPushMsgEntry::SetIdL(const TDesC& aID) |
|
102 { |
|
103 HBufC* tempID = aID.AllocL(); |
|
104 |
|
105 delete iMsgID; |
|
106 iMsgID = tempID; |
|
107 } |
|
108 |
|
109 |
|
110 /** |
|
111 Gets the Action level for the SI Push Message. |
|
112 |
|
113 The Action levels are defined by TSIPushMsgAction. |
|
114 |
|
115 @return |
|
116 Action level for the SI Push Message. |
|
117 |
|
118 @see CSIPushMsgEntry::TSIPushMsgAction |
|
119 */ |
|
120 EXPORT_C TInt CSIPushMsgEntry::Action() const |
|
121 { |
|
122 //Action is stored in Bits 4-7 of iMtmData1 of the TMsvEntry in the Message Server Index. |
|
123 //Therefore the function has to mask out all the other bits, and then bitwise shift the |
|
124 //values to get the Action level. |
|
125 |
|
126 TInt action = iEntry.MtmData1() & KPushMaskOnlyAction; //Get the value of Bits 4-7 for action |
|
127 action = action >> 4; // bitshift 4 places right |
|
128 return action; |
|
129 } |
|
130 |
|
131 |
|
132 /** |
|
133 Sets the Action level for the SI Push Message. |
|
134 |
|
135 The Action levels are defined by TSIPushMsgAction. |
|
136 |
|
137 @param aActionFlags |
|
138 Action level for the SI Push Message. |
|
139 |
|
140 @see CSIPushMsgEntry::TSIPushMsgAction |
|
141 */ |
|
142 EXPORT_C void CSIPushMsgEntry::SetAction(TInt aActionFlags) |
|
143 { |
|
144 //Action value is stored in Bits 4-7 of iMtmData1 of the TMsvEntry in the Message Server |
|
145 //Index. Therefore the function has to clear the old action bits through bitwise AND with |
|
146 //a mask, and then bitwise shift the action level to the correct Bit position. |
|
147 TInt everythingButAction = iEntry.MtmData1() & KPushMaskEverythingButAction; |
|
148 |
|
149 TInt action = aActionFlags << 4; // bitshift left 4 places, i.e to Bits 4-7 |
|
150 action = action & KPushMaskOnlyAction; //eliminate any non action bits |
|
151 iEntry.SetMtmData1( action + everythingButAction ); |
|
152 } |
|
153 |
|
154 |
|
155 /** |
|
156 Sets the URL of the service to be accessed. |
|
157 |
|
158 @param aUrl |
|
159 URL of the service to be accessed. |
|
160 */ |
|
161 EXPORT_C void CSIPushMsgEntry::SetUrlL(const TDesC& aUrl) |
|
162 { |
|
163 HBufC* tempBuf = aUrl.AllocL(); |
|
164 |
|
165 delete iUrl; |
|
166 iUrl = tempBuf; |
|
167 } |
|
168 |
|
169 |
|
170 /** |
|
171 Gets the notification text of the SI message. |
|
172 |
|
173 @return |
|
174 SI Text information |
|
175 */ |
|
176 EXPORT_C const TDesC& CSIPushMsgEntry::Text() const |
|
177 { |
|
178 if (iText) |
|
179 return *iText; |
|
180 else |
|
181 return KNullDesC; |
|
182 } |
|
183 |
|
184 |
|
185 /** |
|
186 Sets the notification text for the SI entry. |
|
187 |
|
188 @param aText |
|
189 Notification text to be stored. |
|
190 */ |
|
191 EXPORT_C void CSIPushMsgEntry::SetTextL(const TDesC& aText) |
|
192 { |
|
193 HBufC* temp = aText.AllocL(); |
|
194 delete iText; |
|
195 iText = NULL; |
|
196 iText = temp; |
|
197 } |
|
198 |
|
199 |
|
200 /** |
|
201 Constructor. |
|
202 |
|
203 Initialises expiry date to Null. |
|
204 */ |
|
205 CSIPushMsgEntry::CSIPushMsgEntry() |
|
206 { |
|
207 iExpiryDate = Time::NullTTime(); |
|
208 } |
|
209 |
|
210 |
|
211 /** |
|
212 Externalises the object to a message store stream. |
|
213 |
|
214 @param aStream |
|
215 The stream to which the data should be externalised. |
|
216 */ |
|
217 void CSIPushMsgEntry::ExternalizeL(RMsvWriteStream& aStream) |
|
218 {// Call the Base Class method to store iHeader & iFrom. |
|
219 // Custom code for iExpiryDate. Data in iText & iUrl assigned to iEntry - no problem |
|
220 CPushMsgEntryBase::ExternalizeL(aStream); |
|
221 aStream << iExpiryDate.Int64(); |
|
222 aStream << LimitStringSize(Text(), KLongestStringAllowed); |
|
223 aStream<< LimitStringSize(Url(), KLongestStringAllowed);; |
|
224 aStream << iCreatedDate.Int64(); |
|
225 |
|
226 if (iMsgID) |
|
227 aStream << *iMsgID; |
|
228 else |
|
229 aStream << KNullDesC; |
|
230 |
|
231 aStream << MsgOriginUri(); |
|
232 } |
|
233 |
|
234 |
|
235 /** |
|
236 Internalises the object from a message store stream. |
|
237 |
|
238 @param aStream |
|
239 The stream from which the data should be internalised. |
|
240 */ |
|
241 void CSIPushMsgEntry::InternalizeL(RMsvReadStream& aStream) |
|
242 { |
|
243 // Base class restores iHeader & iFrom. We only have to do iExpiryDate |
|
244 CPushMsgEntryBase::InternalizeL(aStream); |
|
245 |
|
246 //Read in the Time & Date as a 64 bit int |
|
247 TInt64 expiryTime; |
|
248 aStream >> expiryTime; |
|
249 iExpiryDate = expiryTime; |
|
250 |
|
251 delete iText; |
|
252 iText = NULL; |
|
253 iText = HBufC::NewL(aStream, KLongestStringAllowed); |
|
254 |
|
255 delete iUrl; |
|
256 iUrl = NULL; |
|
257 iUrl = HBufC::NewL(aStream, KLongestStringAllowed); |
|
258 |
|
259 //Read in Created Time & Date as a 64 bit int |
|
260 TInt64 createdTime; |
|
261 aStream >> createdTime; |
|
262 iCreatedDate = createdTime; |
|
263 |
|
264 delete iMsgID; |
|
265 iMsgID = NULL; |
|
266 iMsgID = HBufC::NewL(aStream, KLongestStringAllowed); |
|
267 |
|
268 delete iOriginUri; |
|
269 iOriginUri = NULL; |
|
270 iOriginUri = HBufC8::NewL(aStream, KLongestStringAllowed); |
|
271 } |
|
272 |
|
273 |
|
274 /** |
|
275 Gets the SI push message type UID. |
|
276 |
|
277 For this class, this is KUidWapPushMsgSI. |
|
278 |
|
279 @return |
|
280 Push message type UID as a long integer |
|
281 */ |
|
282 EXPORT_C TInt32 CSIPushMsgEntry::PushMsgType() const |
|
283 { |
|
284 return KUidWapPushMsgSI.iUid; |
|
285 } |
|
286 |
|
287 |
|
288 /** |
|
289 Sets the SI push message type UID. |
|
290 |
|
291 For this class, this is KUidWapPushMsgSI. |
|
292 */ |
|
293 void CSIPushMsgEntry::SetPushMsgType() |
|
294 { |
|
295 iEntry.iBioType = KUidWapPushMsgSI.iUid; |
|
296 } |
|
297 |
|
298 |
|
299 /** |
|
300 Sets the 8th bit of TMsvEntry::iMtmData1 to indicate whether the SI message is from a |
|
301 whitelisted source or from an unknown origin. |
|
302 |
|
303 @param aTrusted ETrue - push PDU source address is in whitelist. |
|
304 EFalse - push PDU is from unknown origin. |
|
305 |
|
306 @see TMsvEntry |
|
307 */ |
|
308 EXPORT_C void CSIPushMsgEntry::SetTrusted(TBool aTrusted) |
|
309 { |
|
310 (aTrusted == 1) ? (iEntry.SetMtmData1((iEntry.MtmData1()) | 0x00000100)) : (iEntry.SetMtmData1((iEntry.MtmData1()) & 0xFFFFFEFF)); |
|
311 } |
|
312 |
|
313 |
|
314 /** |
|
315 Reads the 8th bit of TMsvEntry::iMtmEntry1 and returns true if the SI message is from a |
|
316 whitelisted origin and false if the SI message is from an unknown origin. |
|
317 |
|
318 @return ETrue - push PDU source address is in whitelist. |
|
319 EFalse - push PDU is from unknown origin. |
|
320 */ |
|
321 EXPORT_C TBool CSIPushMsgEntry::Trusted() const |
|
322 { |
|
323 // Unmask and return the bit-8 |
|
324 return (((iEntry.MtmData1() & 0x00000100) == 0x00000100) ? ETrue : EFalse); |
|
325 } |
|
326 |
|
327 |
|
328 /** |
|
329 Sets the origin URI of the SI message. |
|
330 |
|
331 @param aOriginUri Origin URI of the SI message. |
|
332 */ |
|
333 EXPORT_C void CSIPushMsgEntry::SetMsgOriginUriL(const TDesC8& aOriginUri) |
|
334 { |
|
335 delete iOriginUri; |
|
336 iOriginUri = NULL; |
|
337 iOriginUri = aOriginUri.AllocL(); |
|
338 } |
|
339 |
|
340 |
|
341 /** |
|
342 Gets the origin URI of the SI message. |
|
343 |
|
344 @return Origin URI of the SI message. |
|
345 */ |
|
346 EXPORT_C const TDesC8& CSIPushMsgEntry::MsgOriginUri() const |
|
347 { |
|
348 if (iOriginUri) |
|
349 { |
|
350 return (*(iOriginUri)); |
|
351 } |
|
352 else |
|
353 { |
|
354 return KNullDesC8; |
|
355 } |
|
356 } |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |