|
1 /* |
|
2 * Copyright (c) 2006 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: IMPS Protocol implementation for Presence Framework |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ximpprotocolconnectionhost.h> |
|
20 #include "CUpdateOwnPresenceSubscriptionPifRequest.h" |
|
21 #include "impsconnectionmanagercontrolif.h" |
|
22 #include "impsdebugprint.h" |
|
23 #include "CImpsPluginAccessHandler.h" |
|
24 #include "CImpsPluginPureDataHandler.h" |
|
25 #include <presenceinfo.h> |
|
26 |
|
27 #include "CPEngXMLParser.h" |
|
28 #include "MPEngXMLParser.h" |
|
29 #include "CPEngXmlSerializer.h" |
|
30 #include "MPEngXmlSerializer.h" |
|
31 #include "CImpsPluginConnectionManager.h" |
|
32 #include "PEngXMLTags.h" |
|
33 |
|
34 #include <ximpobjectfactory.h> |
|
35 #include <ximpobjectcollection.h> |
|
36 #include <protocolpresentitygroupsdatahost.h> |
|
37 #include <presentitygroupinfo.h> |
|
38 #include <presentitygroupmemberinfo.h> |
|
39 #include <ximpidentity.h> |
|
40 #include <presenceinfofilter.h> |
|
41 #include "PImpsAdapXMLTools.h" |
|
42 |
|
43 // ======== MEMBER FUNCTIONS ======== |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CUpdateOwnPresenceSubscriptionPifRequest::CUpdateOwnPresenceSubscriptionPifRequest |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CUpdateOwnPresenceSubscriptionPifRequest::CUpdateOwnPresenceSubscriptionPifRequest( |
|
50 MImpsPrtPluginConnectionManager& aConnMan, |
|
51 TXIMPRequestId aRequestId ) : |
|
52 CActive( EPriorityNormal ), |
|
53 iRequestId( aRequestId ), |
|
54 iConnMan( aConnMan ) |
|
55 { |
|
56 IMPS_DP( D_IMPS_LIT( "::CUpdateOwnPresenceSubscriptionPifRequest Start" ) ); |
|
57 CActiveScheduler::Add( this ); |
|
58 |
|
59 IMPS_DP( D_IMPS_LIT( "::CUpdateOwnPresenceSubscriptionPifRequest End" ) ); |
|
60 } |
|
61 |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CUpdateOwnPresenceSubscriptionPifRequest::ConstructL |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void CUpdateOwnPresenceSubscriptionPifRequest::ConstructL() |
|
68 { |
|
69 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::ConstructL Start" ) ); |
|
70 |
|
71 iParser = CreateXMLParserL(); |
|
72 |
|
73 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::ConstructL End" ) ); |
|
74 } |
|
75 |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CUpdateOwnPresenceSubscriptionPifRequest::NewL |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 CUpdateOwnPresenceSubscriptionPifRequest* CUpdateOwnPresenceSubscriptionPifRequest::NewL( |
|
82 MImpsPrtPluginConnectionManager& aConnMan, |
|
83 TXIMPRequestId aRequestId ) |
|
84 { |
|
85 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::NewL Start" ) ); |
|
86 |
|
87 CUpdateOwnPresenceSubscriptionPifRequest* self = |
|
88 new( ELeave ) CUpdateOwnPresenceSubscriptionPifRequest( aConnMan, aRequestId ); |
|
89 CleanupStack::PushL( self ); |
|
90 self->ConstructL(); |
|
91 CleanupStack::Pop( self ); |
|
92 |
|
93 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::NewL End" ) ); |
|
94 return self; |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // CUpdateOwnPresenceSubscriptionPifRequest::NewLC |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 CUpdateOwnPresenceSubscriptionPifRequest* CUpdateOwnPresenceSubscriptionPifRequest::NewLC( |
|
103 MImpsPrtPluginConnectionManager& aConnMan, |
|
104 TXIMPRequestId aRequestId ) |
|
105 { |
|
106 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::NewLC Start" ) ); |
|
107 |
|
108 CUpdateOwnPresenceSubscriptionPifRequest* self = |
|
109 CUpdateOwnPresenceSubscriptionPifRequest::NewL( aConnMan, aRequestId ); |
|
110 CleanupStack::PushL( self ); |
|
111 |
|
112 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::NewLC End" ) ); |
|
113 return self; |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CUpdateOwnPresenceSubscriptionPifRequest::~CUpdateOwnPresenceSubscriptionPifRequest |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 CUpdateOwnPresenceSubscriptionPifRequest::~CUpdateOwnPresenceSubscriptionPifRequest() |
|
121 { |
|
122 IMPS_DP( D_IMPS_LIT( "::~CUpdateOwnPresenceSubscriptionPifRequest Start" ) ); |
|
123 |
|
124 delete iResponse; |
|
125 delete iListId; |
|
126 CActive::Cancel(); |
|
127 iConnMan.Remove( this ); |
|
128 delete iParser; |
|
129 |
|
130 IMPS_DP( D_IMPS_LIT( "::~CUpdateOwnPresenceSubscriptionPifRequest End" ) ); |
|
131 } |
|
132 |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CUpdateOwnPresenceSubscriptionPifRequest::DoCancel() |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void CUpdateOwnPresenceSubscriptionPifRequest::DoCancel() |
|
139 { |
|
140 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::DoCancel Start" ) ); |
|
141 |
|
142 iConnMan.DataHandler().CancelSending( iSendId ); |
|
143 |
|
144 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::DoCancel End" ) ); |
|
145 } |
|
146 |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // CUpdateOwnPresenceSubscriptionPifRequest::RunL() |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 void CUpdateOwnPresenceSubscriptionPifRequest::RunL() |
|
153 { |
|
154 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::RunL Start" ) ); |
|
155 |
|
156 User::LeaveIfError( iStatus.Int() ); |
|
157 |
|
158 iResponse = iConnMan.DataHandler().ResponseL( iSendId ); |
|
159 |
|
160 TPtrC8 resultBlock( NULL, 0 ); |
|
161 TInt wvErrorCode = KErrNone; |
|
162 |
|
163 // Check if we got 200 |
|
164 if ( iParser->DecodeL( *iResponse, KResultXMLTag, ETrue ) ) |
|
165 { |
|
166 resultBlock.Set( iParser->ResultL() ); |
|
167 if ( iParser->DecodeL( resultBlock, KCodeXMLTag, EFalse ) ) |
|
168 { |
|
169 TPtrC8 cspStatusCodeBlock( iParser->ResultL() ); |
|
170 TInt cspStatusInt; |
|
171 TLex8 lexer( cspStatusCodeBlock ); |
|
172 lexer.SkipSpace(); |
|
173 TInt lexErr = lexer.Val( cspStatusInt ); |
|
174 if ( lexErr == KErrNone ) |
|
175 { |
|
176 wvErrorCode = cspStatusInt; |
|
177 } |
|
178 } |
|
179 } |
|
180 |
|
181 iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, wvErrorCode ); |
|
182 // handle notifications. |
|
183 |
|
184 delete this; |
|
185 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::RunL End" ) ); |
|
186 } |
|
187 |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // CUpdateOwnPresenceSubscriptionPifRequest::RunError |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 TInt CUpdateOwnPresenceSubscriptionPifRequest::RunError( TInt aError ) |
|
194 { |
|
195 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::RunError Start" ) ); |
|
196 |
|
197 iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, aError ); |
|
198 |
|
199 delete this; |
|
200 IMPS_DP( D_IMPS_LIT( "CUpdateOwnPresenceSubscriptionPifRequest::RunError End" ) ); |
|
201 return KErrNone; |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // CUpdateOwnPresenceSubscriptionPifRequest::UpdateOwnPresenceSubscriptionPifL |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 void CUpdateOwnPresenceSubscriptionPifRequest::UpdateOwnPresenceSubscriptionPifL( |
|
209 const MPresenceInfoFilter& aPif ) |
|
210 { |
|
211 IMPS_DP( D_IMPS_LIT( "::UpdateOwnPresenceSubscriptionPifL Start" ) ); |
|
212 |
|
213 TPtr8 ptrbuffer( iConnMan.DataHandler().TransferBufferL() ); |
|
214 MPEngXMLSerializer* serializer = CreateXmlSerializerLC( ptrbuffer ); |
|
215 |
|
216 NImpsAdapXMLTools::AppendTransactionContentTagXmlL( *serializer, iConnMan.GetVersion() ); |
|
217 |
|
218 serializer->StartTagL( KSubscribePresence ); |
|
219 |
|
220 // userId or contactlist Id or both are allowed |
|
221 serializer->StartTagL( KUserIDXMLTag |
|
222 ).NarrowTextL( KWVXMLTag |
|
223 ).WvAddressL( iConnMan.UserName() |
|
224 ).EndTagL( KUserIDXMLTag ); |
|
225 |
|
226 serializer->StartTagL( KPresenceSubList ); |
|
227 serializer->AttributeL( KXmlXmlns, KPresenceSubListAttributesNS_CSP12 ); |
|
228 |
|
229 // fetch attributes from the pif and send it over to the server |
|
230 TBool statusmessage = aPif.MatchPersonFilter( NPresenceInfo::NFieldType::KStatusMessage ); |
|
231 TBool availability = aPif.MatchPersonFilter( NPresenceInfo::NFieldType::KAvailability ); |
|
232 TBool allattributes = aPif.MatchPersonFilter( NPresenceInfo::NFieldType::KAcceptAll ); |
|
233 |
|
234 if ( !allattributes ) |
|
235 { |
|
236 if ( statusmessage ) |
|
237 { |
|
238 serializer->StartTagL( KStatusMood ).EndTagL( KStatusMood ); |
|
239 serializer->StartTagL( KOnlineStatusXMLTag ).EndTagL( KOnlineStatusXMLTag ); |
|
240 serializer->StartTagL( KStatusTextXMLTag ).EndTagL( KStatusTextXMLTag ); |
|
241 serializer->StartTagL( KStatusContentXMLTag ).EndTagL( KStatusContentXMLTag ); |
|
242 } |
|
243 if ( availability ) |
|
244 { |
|
245 serializer->StartTagL( KUserAvailabilityXMLTag ).EndTagL( KUserAvailabilityXMLTag ); |
|
246 } |
|
247 } |
|
248 |
|
249 // empty list so that all attributes |
|
250 serializer->EndTagL( KPresenceSubList ); |
|
251 |
|
252 serializer->StartTagL( KAutoSubscribe ).NarrowTextL( KXMLValueTrue ).EndTagL( KAutoSubscribe ); |
|
253 |
|
254 serializer->EndTagL( KSubscribePresence ); |
|
255 serializer->EndTagL( KTransactionContent ); |
|
256 |
|
257 CleanupStack::PopAndDestroy(); //serializer |
|
258 |
|
259 |
|
260 iSendId = iConnMan.DataHandler().SendDataL( iStatus ); |
|
261 |
|
262 IMPS_DP( D_IMPS_LIT( " SendData Request id %d " ), iSendId ); |
|
263 // signal the scheduler |
|
264 SetActive(); |
|
265 |
|
266 IMPS_DP( D_IMPS_LIT( "::UpdateOwnPresenceSubscriptionPifL End" ) ); |
|
267 } |
|
268 |
|
269 // End of file |