|
1 /* |
|
2 * Copyright (c) 2002-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: |
|
15 * handler class for im client. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <imcvcodc.h> |
|
22 #include "impsimcli.h" |
|
23 #include "impsimhandler.h" |
|
24 #include "impsfields.h" |
|
25 #include "impsservercommon.h" |
|
26 #include "impserrors.h" |
|
27 #include "impsutils.h" |
|
28 #include "impsdataaccessor.h" |
|
29 #include "impscdatautils.h" |
|
30 #include "impsliterals.h" |
|
31 |
|
32 // MACROS |
|
33 #ifndef _DEBUG |
|
34 #define _NO_IMPS_LOGGING_ |
|
35 #endif |
|
36 |
|
37 // ================= MEMBER FUNCTIONS ======================= |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // CImpsImHandler2::CImpsImHandler2 |
|
41 // ---------------------------------------------------------------------------- |
|
42 CImpsImHandler2::CImpsImHandler2( |
|
43 TInt aPriority, |
|
44 RImpsImClient2& aClient ) : |
|
45 // The base class adds this to the scheduler |
|
46 CImpsHandler2( aPriority, aClient ) |
|
47 { |
|
48 } |
|
49 |
|
50 // ---------------------------------------------------------------------------- |
|
51 // CImpsImHandler2::NewL |
|
52 // ---------------------------------------------------------------------------- |
|
53 CImpsImHandler2* CImpsImHandler2::NewL( |
|
54 RImpsImClient2& aClient, |
|
55 TInt aPriority ) |
|
56 { |
|
57 |
|
58 // Perform the construction. |
|
59 CImpsImHandler2* self = new (ELeave) |
|
60 CImpsImHandler2( aPriority, aClient); |
|
61 |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop( self ); |
|
65 |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CImpsImHandler2::~CImpsImHandler2() |
|
71 // ---------------------------------------------------------------------------- |
|
72 CImpsImHandler2::~CImpsImHandler2() |
|
73 { |
|
74 |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // CImpsImHandler2::ConstructL |
|
79 // ---------------------------------------------------------------------------- |
|
80 void CImpsImHandler2::ConstructL() |
|
81 { |
|
82 CImpsHandler2::ConstructL(); |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CImpsImHandler2::HandleEventL() |
|
87 // ---------------------------------------------------------------------------- |
|
88 |
|
89 void CImpsImHandler2::HandleEventL( CImpsFields* aErrorFields ) |
|
90 { |
|
91 // get the event data from server thread. |
|
92 SImpsEventData* event = (SImpsEventData*)iEventData.Ptr(); |
|
93 |
|
94 #ifndef _NO_IMPS_LOGGING_ |
|
95 CImpsClientLogger::Log(_L("CImpsImHandler2::HandleEventL opid=%d cli=%d"), |
|
96 event->iOpCode, (TInt)&iClient ); |
|
97 #endif |
|
98 |
|
99 if ( event->iStatus != ( Imps_ERROR_BASE - 200 ) && |
|
100 event->iStatus != KErrNone ) |
|
101 { |
|
102 HandleErrorEventL( event->iOpCode, event->iStatus, aErrorFields ); |
|
103 } |
|
104 // Call regular observer |
|
105 // iStatus is error code or message size |
|
106 else if ( iStatus >= 0 ) |
|
107 { |
|
108 HandleImEventL( ); |
|
109 } |
|
110 } |
|
111 |
|
112 // ---------------------------------------------------------------------------- |
|
113 // CImpsImHandler2::HandleImEventL() |
|
114 // ---------------------------------------------------------------------------- |
|
115 void CImpsImHandler2::HandleImEventL( ) |
|
116 { |
|
117 SImpsEventData* event = (SImpsEventData*)iEventData.Ptr(); |
|
118 RImpsImClient2& client = (RImpsImClient2&)iClient; |
|
119 MImpsImHandler2* imhandler = client.Handler(); |
|
120 MImpsBlockingHandler2* blockhandler = client.BlockHandler(); |
|
121 |
|
122 TInt err( KErrNone ); |
|
123 |
|
124 // Check incoming message type |
|
125 TInt myType = event->iMessageType; |
|
126 |
|
127 CImpsDataAccessor* myAccess = CImpsDataAccessor::NewLC( iFields ); // << |
|
128 CImpsKey* myKey = CImpsKey::NewLC(); // <<< myKey |
|
129 |
|
130 switch ( myType ) |
|
131 { |
|
132 case EImpsNewMessage: |
|
133 { |
|
134 if ( !imhandler ) |
|
135 { |
|
136 break; |
|
137 } |
|
138 |
|
139 // get messageID |
|
140 TPtrC msgId = TPtrC( KNullDesC ); |
|
141 (void)TImpsCDataUtils::GetNewMessageIdL( |
|
142 myKey, myAccess, msgId ); |
|
143 |
|
144 myKey->Reset(); |
|
145 |
|
146 // arrays |
|
147 // notice: optimize creation of arrays |
|
148 CPtrC16Array* users = new ( ELeave )CPtrC16Array( 4 ); |
|
149 CleanupStack::PushL( users ); // <<< users |
|
150 CPtrC16Array* sns = new ( ELeave )CPtrC16Array( 4 ); |
|
151 CleanupStack::PushL( sns ); // <<< sns |
|
152 CPtrC16Array* grs = new ( ELeave )CPtrC16Array( 4 ); |
|
153 CleanupStack::PushL( grs ); // <<< grs |
|
154 CPtrC16Array* sng = new (ELeave) CPtrC16Array(5); |
|
155 CleanupStack::PushL( sng ); // <<< grs |
|
156 |
|
157 TImpsCDataUtils::AddValuesFromArrayL( |
|
158 myKey, |
|
159 KNewMessageElements, |
|
160 sizeof( KNewMessageElements ) / |
|
161 sizeof( KNewMessageElements[0] ) ); |
|
162 myKey->AddL( CREATEKEY( EImpsKeyMessageInfo, 0 ) ); |
|
163 TPtrC mySender; |
|
164 TPtrC myGroup; |
|
165 TImpsCDataUtils::GetSenderL( myKey, myAccess, |
|
166 mySender, myGroup ); |
|
167 TImpsCDataUtils::GetRecipientsL( myKey, myAccess, |
|
168 grs, users, sng, sns ); |
|
169 |
|
170 myKey->PopL(); |
|
171 |
|
172 TPtrC myType; |
|
173 TImpsCDataUtils::GetContentTypeL( myAccess, myType ); |
|
174 |
|
175 // !!!! Fix for JKIO-6PAGQ3 !!!! |
|
176 // Check whether the content type starts with "text/plain" |
|
177 if ( !myType.Left(KImpsContentType().Length()).CompareF( KImpsContentType ) || myType.Length() == 0 ) |
|
178 { |
|
179 TPtrC myContent; |
|
180 TImpsCDataUtils::GetContentDataL( myKey, myAccess, myContent ); |
|
181 |
|
182 // Call API observer method |
|
183 #ifndef _NO_IMPS_LOGGING_ |
|
184 CImpsClientLogger::Log(_L("CImpsImHandler2::call HandleNewTextMessageL opid=%d"), event->iOpCode ); |
|
185 #endif |
|
186 TRAP( err, imhandler->HandleNewTextMessageL( |
|
187 event->iOpCode, |
|
188 msgId, |
|
189 mySender, |
|
190 myGroup, |
|
191 *users, |
|
192 *sns, |
|
193 myContent, |
|
194 *iClient.CspIdentifier() )); |
|
195 } |
|
196 else |
|
197 { |
|
198 TPtrC8 myContent; |
|
199 TInt inCleanup(0); |
|
200 TDesC8* content; |
|
201 myKey->Reset(); |
|
202 TImpsCDataUtils::AddValuesFromArrayL( |
|
203 myKey, |
|
204 KNewMessageElements, |
|
205 sizeof( KNewMessageElements ) / |
|
206 sizeof( KNewMessageElements[0] ) ); |
|
207 |
|
208 myKey->AddL( CREATEKEY( EImpsKeyContentData, 0 ) ); |
|
209 if ( myAccess->RestoreDesc8L( myKey, content ) ) |
|
210 { |
|
211 TInt encoding (-1); |
|
212 TImpsCDataUtils::GetContentEncodingL( myAccess, encoding); |
|
213 if ( encoding == EImpsBASE64 ) |
|
214 { |
|
215 // allocate buffer for decoding |
|
216 HBufC8* contentBuf = HBufC8::NewLC( content->Length() ); // << contentBuf |
|
217 inCleanup++; |
|
218 // BASE64 decoding |
|
219 TImCodecB64 codec; |
|
220 codec.Initialise(); |
|
221 TPtr8 ptr( contentBuf->Des() ); |
|
222 codec.Decode( *content , ptr ); |
|
223 myContent.Set(*contentBuf); |
|
224 } |
|
225 else |
|
226 { |
|
227 myContent.Set( *content ); |
|
228 } |
|
229 } |
|
230 else |
|
231 { |
|
232 myContent.Set( KNullDesC8 ); |
|
233 } |
|
234 // Call API observer method |
|
235 #ifndef _NO_IMPS_LOGGING_ |
|
236 CImpsClientLogger::Log(_L("CImpsImHandler2::HandleNewContentMessageL opid=%d length=%d"), event->iOpCode, myContent.Length() ); |
|
237 |
|
238 #endif |
|
239 TRAP( err, imhandler->HandleNewContentMessageL( |
|
240 event->iOpCode, |
|
241 msgId, |
|
242 mySender, |
|
243 myGroup, |
|
244 *users, |
|
245 *sns, |
|
246 myType, |
|
247 myContent, |
|
248 *iClient.CspIdentifier() )); |
|
249 if ( inCleanup > 0 ) |
|
250 { |
|
251 CleanupStack::PopAndDestroy( inCleanup ); // >>> contentBuf |
|
252 } |
|
253 myKey->PopL(); |
|
254 |
|
255 } |
|
256 CleanupStack::PopAndDestroy(4); // >>> users, sns, grs, sng |
|
257 } |
|
258 break; |
|
259 |
|
260 case EImpsDeliveryReportReq: |
|
261 { |
|
262 if ( !imhandler ) |
|
263 { |
|
264 break; |
|
265 } |
|
266 TImpsCDataUtils::AddValuesFromArrayL( |
|
267 myKey, |
|
268 KTransContentElements, |
|
269 sizeof( KTransContentElements ) / |
|
270 sizeof( KTransContentElements[0] ) ); |
|
271 myKey->AddL( CREATEKEY( EImpsKeyDeliveryReport_Request, 0 ) ); |
|
272 myKey->AddL( CREATEKEY( EImpsKeyMessageInfo, 0 ) ); |
|
273 myKey->AddL( CREATEKEY( EImpsKeyMessageID, 0 ) ); |
|
274 TDesC* msgId; |
|
275 myAccess->RestoreDescL( myKey, msgId ); |
|
276 myKey->PopL( 2 ); |
|
277 |
|
278 myKey->AddL( CREATEKEY( EImpsKeyResult, 0 ) ); |
|
279 myKey->AddL( CREATEKEY( EImpsKeyCode, 0 ) ); |
|
280 TInt result( 0 ); |
|
281 myAccess->RestoreIntegerL( myKey, result ); |
|
282 myKey->PopL(); |
|
283 |
|
284 myKey->AddL( CREATEKEY( EImpsKeyDescription, 0 ) ); |
|
285 TDesC* description; |
|
286 myAccess->RestoreDescL( myKey, description ); |
|
287 |
|
288 TRAP( err, imhandler->HandleDeliveryReportL( |
|
289 *msgId, result, description, *iClient.CspIdentifier() ) ); |
|
290 |
|
291 // myKey->ResetL( ); |
|
292 } |
|
293 break; |
|
294 |
|
295 case EImpsGetBlockedListRes: |
|
296 if ( blockhandler ) |
|
297 { |
|
298 |
|
299 TBool blockedInUse( EFalse ); |
|
300 TBool grantedInUse( EFalse ); |
|
301 |
|
302 CPtrC16Array* blockedList = new ( ELeave )CPtrC16Array( 4 ); |
|
303 CleanupStack::PushL( blockedList ); // <<< blockedList |
|
304 |
|
305 CPtrC16Array* grantedList = new ( ELeave )CPtrC16Array( 4 ); |
|
306 CleanupStack::PushL( grantedList ); // <<< grantedList |
|
307 |
|
308 // Get data from internal data format to API method |
|
309 TImpsCDataUtils::GetBlockedListResponseL( |
|
310 myKey, myAccess, |
|
311 blockedList, |
|
312 blockedInUse, |
|
313 grantedList, |
|
314 grantedInUse ); |
|
315 |
|
316 #ifndef _NO_IMPS_LOGGING_ |
|
317 CImpsClientLogger::Log(_L("CImpsImHandler2::call GetBlockedListResponseL opid=%d"), event->iOpCode ); |
|
318 #endif |
|
319 // Call API observer method |
|
320 TRAP( err, blockhandler->GetBlockedListResponseL( |
|
321 blockedList, |
|
322 blockedInUse, |
|
323 grantedList, |
|
324 grantedInUse, |
|
325 *client.CspIdentifier() ) ); |
|
326 |
|
327 CleanupStack::PopAndDestroy(2); // >> blockedList, grantedlist |
|
328 |
|
329 } |
|
330 break; |
|
331 |
|
332 |
|
333 default: // responses |
|
334 if ( event->iReqMesType == EImpsBlockEntityReq && blockhandler) |
|
335 { |
|
336 #ifndef _NO_IMPS_LOGGING_ |
|
337 CImpsClientLogger::Log(_L("CImpsImHandler2::call HandleCompleteL opid=%d"), event->iOpCode ); |
|
338 #endif |
|
339 TRAP( err, blockhandler->HandleCompleteL( event->iOpCode, /*event->iStatus,*/ *iClient.CspIdentifierL() )); |
|
340 } |
|
341 else if ( event->iReqMesType == EImpsSendMessageReq && imhandler) |
|
342 { |
|
343 #ifndef _NO_IMPS_LOGGING_ |
|
344 CImpsClientLogger::Log(_L("CImpsImHandler2::call HandleSendCompleteL opid=%d"), event->iOpCode ); |
|
345 #endif |
|
346 TRAP( err, imhandler->HandleSendCompleteL( |
|
347 event->iOpCode, EFalse, *iClient.CspIdentifier())); |
|
348 } |
|
349 else |
|
350 { |
|
351 #ifndef _NO_IMPS_LOGGING_ |
|
352 CImpsClientLogger::Log(_L("CImpsImHandler2:: ERROR CORRUPTED ***** opid=%d"), event->iOpCode ); |
|
353 #endif |
|
354 __ASSERT_DEBUG( 0 == 1, |
|
355 User::Panic( KImpsPanicCategory, |
|
356 EImpsCorrupted ) ); |
|
357 User::Leave( KErrNotSupported ); |
|
358 } |
|
359 break; |
|
360 } // switch |
|
361 |
|
362 CleanupStack::PopAndDestroy(2); // myKey, myAccess |
|
363 |
|
364 } |
|
365 |
|
366 // End of File |