|
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: Handler to update contact list subscription. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngContactListMngTransSubcription.h" |
|
20 |
|
21 #include "MPEngContactListSettingsManager.h" |
|
22 #include "CPEngContactListSettings.h" |
|
23 #include "CPEngContactListModBase.h" |
|
24 |
|
25 #include "PEngListLibTools.h" |
|
26 #include "MPEngXMLSerializer.h" |
|
27 #include "MPEngXMLParser.h" |
|
28 #include "CPEngTransactionStatus.h" |
|
29 #include "PEngWVPresenceErrors2.h" |
|
30 #include "PresenceDebugPrint.h" |
|
31 |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CPEngContactListMngTransSubcription::CPEngContactListMngTransSubcription() |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CPEngContactListMngTransSubcription::CPEngContactListMngTransSubcription( |
|
40 CPEngContactListModBase& aContactList, |
|
41 CPEngSessionSlotId& aSessionSlotId, |
|
42 TPEngWVCspVersion& aCSPVersion, |
|
43 TInt aOperationId ) |
|
44 : iContactList ( aContactList ), |
|
45 iSessionSlotId( aSessionSlotId ), |
|
46 iTransactionCompleted( EFalse ), |
|
47 iCSPVersion( aCSPVersion ), |
|
48 iOperationId( aOperationId ) |
|
49 |
|
50 { |
|
51 PENG_DP( D_PENG_LIT( "CPEngContactListMngTransSubcription::CPEngContactListMngTransSubcription() [%S]" ), |
|
52 &( iContactList.ListProperties().Name() ) ); |
|
53 |
|
54 iContactList.Open(); // CSI: 65 # |
|
55 iContactList.Lock( EStorageLockLevelHigh ); |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CPEngContactListMngTransSubcription::ConstructL() |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CPEngContactListMngTransSubcription::ConstructL() |
|
64 { |
|
65 iTransactionStatus = CPEngTransactionStatus::NewL(); |
|
66 } |
|
67 |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CPEngContactListMngTransSubcription::NewLC() |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CPEngContactListMngTransSubcription* CPEngContactListMngTransSubcription::NewLC( |
|
74 CPEngContactListModBase& aContactList, |
|
75 CPEngSessionSlotId& aSessionSlotId, |
|
76 TPEngWVCspVersion& aCSPVersion, |
|
77 TInt aOperationId ) |
|
78 { |
|
79 CPEngContactListMngTransSubcription* self = |
|
80 new ( ELeave ) CPEngContactListMngTransSubcription( aContactList, |
|
81 aSessionSlotId, |
|
82 aCSPVersion, |
|
83 aOperationId ); |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL( ); |
|
86 |
|
87 return self; |
|
88 } |
|
89 |
|
90 |
|
91 // Destructor |
|
92 CPEngContactListMngTransSubcription::~CPEngContactListMngTransSubcription() |
|
93 { |
|
94 iContactList.Unlock(); |
|
95 iContactList.Close(); |
|
96 delete iTransactionStatus; |
|
97 } |
|
98 |
|
99 |
|
100 |
|
101 // =========================================================================== |
|
102 // =============Function from MPEngOutgoingTransactionHandler ================ |
|
103 // =========================================================================== |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CPEngContactListMngTransSubcription::RequestL() |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CPEngContactListMngTransSubcription::RequestL( |
|
110 TDes8& aSendBuffer ) |
|
111 { |
|
112 aSendBuffer.Zero(); |
|
113 MPEngXMLSerializer* xmlSerializer = CreateXmlSerializerL( aSendBuffer ); |
|
114 CleanupClosePushL( *xmlSerializer ); |
|
115 |
|
116 // <TransactionContent xmlns="http://www.wireless -village.org/TRC1.1"> |
|
117 NListLibTools::AppendTransactionContentTagXmlL( *xmlSerializer, iCSPVersion ); |
|
118 |
|
119 // check if contact list needs to be re-subscribed, or unsubscribed |
|
120 if ( iContactList.Settings().Property( KPEngCntLstSubscribe, |
|
121 KPEngCntLstPropertyNativePermanent ) ) |
|
122 { |
|
123 GetXMLSubscribeListL( *xmlSerializer ); |
|
124 } |
|
125 else |
|
126 { |
|
127 GetXMLUnsubscribeListL( *xmlSerializer ); |
|
128 } |
|
129 |
|
130 // end of transaction |
|
131 // </TransactionContent> |
|
132 xmlSerializer->EndTagL( KTransactionContent ); |
|
133 CleanupStack::PopAndDestroy( ); // xmlSerializer |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CPEngContactListMngTransSubcription::LastRunningTransactionHandler() |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CPEngContactListMngTransSubcription::LastRunningTransactionHandler() |
|
141 { |
|
142 } |
|
143 |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CPEngContactListMngTransSubcription::ProcessResponseL() |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CPEngContactListMngTransSubcription::ProcessResponseL( |
|
150 const TDesC8& aResponse, |
|
151 TRequestStatus& /* aStatus */ ) |
|
152 { |
|
153 MPEngXMLParser* XMLparser = CreateXMLParserLC(); |
|
154 |
|
155 // try if there were some errors |
|
156 // check what kind of the request was it |
|
157 if ( iContactList.Settings().Property( KPEngCntLstSubscribe , |
|
158 KPEngCntLstPropertyNativePermanent ) ) |
|
159 { |
|
160 ParseSubscribeListResponseL( aResponse, *XMLparser ); |
|
161 } |
|
162 else |
|
163 { |
|
164 ParseUnsubscribeListResponseL( aResponse, *XMLparser ); |
|
165 } |
|
166 |
|
167 |
|
168 CleanupStack::PopAndDestroy(); // XMLparser |
|
169 iTransactionCompleted = ETrue; |
|
170 } |
|
171 |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CPEngContactListMngTransSubcription::CancelProcessing() |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CPEngContactListMngTransSubcription::CancelProcessing() |
|
178 { |
|
179 } |
|
180 |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // CPEngContactListMngTransSubcription::NewTransactionHandlersL() |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 void CPEngContactListMngTransSubcription::NewTransactionHandlersL( |
|
187 RPointerArray<MPEngOutgoingTransactionHandler>& /* aTransactionsArray*/ ) |
|
188 { |
|
189 } |
|
190 |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CPEngContactListMngTransSubcription::TransactionCompleted() |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 TBool CPEngContactListMngTransSubcription::TransactionCompleted() |
|
197 { |
|
198 return iTransactionCompleted; |
|
199 } |
|
200 |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CPEngContactListMngTransSubcription::TransactionResult() |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 CPEngTransactionStatus* CPEngContactListMngTransSubcription::TransactionResult() |
|
207 { |
|
208 CPEngTransactionStatus* temp = iTransactionStatus; |
|
209 iTransactionStatus = NULL; |
|
210 return temp; |
|
211 } |
|
212 |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CPEngContactListMngTransSubcription::ReleaseHandler() |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 void CPEngContactListMngTransSubcription::ReleaseHandler() |
|
219 { |
|
220 iTransactionCompleted = ETrue; |
|
221 } |
|
222 |
|
223 |
|
224 // ============================================================================= |
|
225 // ==============NEW FUNCTIONS of the base class =============================== |
|
226 // ============================================================================= |
|
227 |
|
228 // ----------------------------------------------------------------------------- |
|
229 // CPEngContactListMngTransSubcription::GetXMLContactListUpdateL() |
|
230 // Creates XML message to unsubscribe contact lists |
|
231 // (other items were commented in a header). |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void CPEngContactListMngTransSubcription::GetXMLUnsubscribeListL( |
|
235 MPEngXMLSerializer& aXmlSerializer ) |
|
236 { |
|
237 // <UnsubscribePresence-Request> |
|
238 aXmlSerializer.StartTagL( KUnsubscribePresence ); |
|
239 |
|
240 NListLibTools::AppendContactListNameXmlL( aXmlSerializer, iContactList.Settings() ); |
|
241 |
|
242 // </UnsubscribePresence-Request> |
|
243 aXmlSerializer.EndTagL( KUnsubscribePresence ); |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CPEngContactListMngTransSubcription::GetXMLSubscribeList() |
|
248 // Creates XML message to re-subscribe contact list |
|
249 // (other items were commented in a header). |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void CPEngContactListMngTransSubcription::GetXMLSubscribeListL( |
|
253 MPEngXMLSerializer& aXmlSerializer ) |
|
254 { |
|
255 // <SubscribePresence-Request> |
|
256 aXmlSerializer.StartTagL( KSubscribePresence ); |
|
257 |
|
258 NListLibTools::AppendContactListNameXmlL( aXmlSerializer, |
|
259 iContactList.Settings() ); |
|
260 |
|
261 NListLibTools::AppendAttributesForSubscriptionXmlL( |
|
262 iContactList.Settings().SubscriptionAttributes(), |
|
263 aXmlSerializer, |
|
264 iSessionSlotId, |
|
265 iCSPVersion ); |
|
266 |
|
267 // if server supports 1.2 CSP, use autosubscribe |
|
268 if ( iCSPVersion == EWVCspV12 ) |
|
269 { |
|
270 // <AutoSubscribe>T</AutoSubscribe> |
|
271 aXmlSerializer.StartTagL( KAutoSubscribe ). |
|
272 NarrowTextL( KXMLValueTrue ). |
|
273 EndTagL( KAutoSubscribe ); |
|
274 } |
|
275 |
|
276 |
|
277 // </SubscribePresence-Request> |
|
278 aXmlSerializer.EndTagL( KSubscribePresence ); |
|
279 |
|
280 // init attribute models |
|
281 TPEngContactlistDesViewWraper contacts( iContactList ); |
|
282 NListLibTools::ActivatePresenceAttributesL( contacts, iSessionSlotId ); |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CPEngContactListMngTransSubcription::ParseUnsubscreAllResponseL() |
|
287 // Parse XML Unsubscribe contact list response |
|
288 // (other items were commented in a header). |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CPEngContactListMngTransSubcription::ParseUnsubscribeListResponseL( |
|
292 const TDesC8& aResponse, |
|
293 MPEngXMLParser& aXMLparser ) |
|
294 { |
|
295 // if contact list was not unsubscribed successfully, |
|
296 // just relax, it will be done by next log in anyway |
|
297 TInt err ( aXMLparser.ParseResultL( aResponse, |
|
298 iOperationId, |
|
299 *iTransactionStatus ) ); |
|
300 // ignore |
|
301 switch ( err ) |
|
302 { |
|
303 case KErrNone: |
|
304 // partial success is same as success in this case |
|
305 case KPEngNwErrPartiallySuccessful: |
|
306 { |
|
307 iContactList.Settings().DeletePropertyL( |
|
308 KPEngSubcriptionUpdate, |
|
309 KPEngCntLstPropertyNativeCached ); |
|
310 TPEngContactlistDesViewWraper contacts( iContactList ); |
|
311 NListLibTools::DeactivatePresenceAttributesL( contacts, iSessionSlotId ); |
|
312 break; |
|
313 } |
|
314 default: |
|
315 { |
|
316 // client will be notified about fail by Transaction Status |
|
317 break; |
|
318 } |
|
319 } |
|
320 } |
|
321 // ----------------------------------------------------------------------------- |
|
322 // CPEngContactListMngTransSubcription::ParseSubscribeListResponseL() |
|
323 // Parse XML re-subscribe contact list response |
|
324 // (other items were commented in a header). |
|
325 // ----------------------------------------------------------------------------- |
|
326 // |
|
327 void CPEngContactListMngTransSubcription::ParseSubscribeListResponseL( |
|
328 const TDesC8& aResponse, |
|
329 MPEngXMLParser& aXMLparser ) |
|
330 { |
|
331 TInt err ( aXMLparser.ParseContactListResultL( aResponse, |
|
332 iOperationId, |
|
333 iContactList.StorageId(), |
|
334 *iTransactionStatus ) ); |
|
335 switch ( err ) |
|
336 { |
|
337 // |
|
338 case KPEngNwErrPartiallySuccessful: |
|
339 { |
|
340 // only wrong contact Ids are checked here |
|
341 NListLibTools::MarkForRemoveBadContactsL( *iTransactionStatus, iContactList ); |
|
342 break; |
|
343 } |
|
344 |
|
345 case KErrNone: |
|
346 { |
|
347 // Contact list was subscribed successfully |
|
348 iContactList.Settings().DeletePropertyL( |
|
349 KPEngSubcriptionUpdate, |
|
350 KPEngCntLstPropertyNativeCached ); |
|
351 break; |
|
352 } |
|
353 |
|
354 case KPEngNwErrUnknownUser: |
|
355 { |
|
356 // deactivate attribute models |
|
357 TPEngContactlistDesViewWraper contacts( iContactList ); |
|
358 NListLibTools::DeactivatePresenceAttributesL( contacts, iSessionSlotId ); |
|
359 // all contact Ids are wrong, remove them |
|
360 iContactList.ResetLocalView(); |
|
361 break; |
|
362 } |
|
363 case KPEngNwErrContactListDoesNotExist: |
|
364 { |
|
365 iContactList.Settings().DeletePropertyL( |
|
366 KPEngListExistsOnServer, |
|
367 KPEngCntLstPropertyNativeCached ); |
|
368 break; |
|
369 } |
|
370 // ignore all other errors |
|
371 default: |
|
372 { |
|
373 } |
|
374 } |
|
375 } |
|
376 |
|
377 // End of File |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |