|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Login Request to the Network Server. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cossprotocolloginrequest.h" |
|
20 #include <ximpprotocolconnectionhost.h> |
|
21 #include "mossprotocolconnectionmanager.h" |
|
22 #include "ossprotocolpluginlogger.h" |
|
23 #include "cossprotocolconnection.h" |
|
24 #include "cossprotocolconnectionmanager.h" |
|
25 #include <stdlib.h> |
|
26 #include "stringutils.h" |
|
27 #include <string.h> |
|
28 #include "msgliterals.h" |
|
29 #include "msg_enums.h" |
|
30 #include "xmppparameters.h" |
|
31 #include "waittimer.h" |
|
32 #include <e32math.h> |
|
33 |
|
34 #include <ximperrors.hrh> |
|
35 |
|
36 // ======== MEMBER FUNCTIONS ======== |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // COSSProtocolLoginRequest::COSSProtocolLoginRequest() |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 COSSProtocolLoginRequest::COSSProtocolLoginRequest ( |
|
43 MOSSProtocolConnectionManager& aConnMan, |
|
44 TXIMPRequestId aRequestId ) : |
|
45 CActive ( CActive::EPriorityStandard ), |
|
46 iRequestId ( aRequestId ), |
|
47 iConnMan ( aConnMan ) |
|
48 { |
|
49 LOGGER ( TXT ( "COSSProtocolLoginRequest::COSSProtocolLoginRequest Start" ) ); |
|
50 CActiveScheduler::Add ( this ); |
|
51 LOGGER ( TXT ( "COSSProtocolLoginRequest::COSSProtocolLoginRequest End" ) ); |
|
52 } |
|
53 |
|
54 // COSSProtocolLoginRequest::ConstructL() |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 void COSSProtocolLoginRequest::ConstructL() |
|
58 { |
|
59 LOGGER ( TXT ( "COSSProtocolLoginRequest::COSSProtocolLoginRequest Start-End" ) ); |
|
60 LOGGER ( TXT ( "COSSProtocolLoginRequest::COSSProtocolLoginRequest End" ) ); |
|
61 } |
|
62 |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // COSSProtocolLoginRequest::NewL() |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 COSSProtocolLoginRequest* COSSProtocolLoginRequest::NewL ( |
|
69 MOSSProtocolConnectionManager& aConnMan, |
|
70 TXIMPRequestId aRequestId ) |
|
71 { |
|
72 LOGGER ( TXT ( "COSSProtocolLoginRequest::NewL Start" ) ); |
|
73 |
|
74 COSSProtocolLoginRequest* self = |
|
75 new ( ELeave ) COSSProtocolLoginRequest ( aConnMan, aRequestId ); |
|
76 CleanupStack::PushL ( self ); |
|
77 self->ConstructL(); |
|
78 CleanupStack::Pop ( self ); |
|
79 |
|
80 LOGGER ( TXT ( "COSSProtocolLoginRequest::NewL End" ) ); |
|
81 return self; |
|
82 } |
|
83 |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // COSSProtocolLoginRequest::NewLC() |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 COSSProtocolLoginRequest* COSSProtocolLoginRequest::NewLC ( |
|
90 MOSSProtocolConnectionManager& aConnMan, |
|
91 TXIMPRequestId aRequestId ) |
|
92 { |
|
93 LOGGER ( TXT ( "COSSProtocolLoginRequest::NewLC Start" ) ); |
|
94 |
|
95 COSSProtocolLoginRequest* self = |
|
96 COSSProtocolLoginRequest::NewL ( aConnMan, aRequestId ); |
|
97 CleanupStack::PushL ( self ); |
|
98 |
|
99 LOGGER ( TXT ( "COSSProtocolLoginRequest::NewLC End" ) ); |
|
100 return self; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // COSSProtocolLoginRequest::~COSSProtocolLoginRequest() |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 COSSProtocolLoginRequest::~COSSProtocolLoginRequest() |
|
108 { |
|
109 LOGGER ( TXT ( "::~COSSProtocolLoginRequest Start-End" ) ); |
|
110 Cancel(); |
|
111 if( iUserName ) |
|
112 { |
|
113 delete iUserName; |
|
114 } |
|
115 |
|
116 LOGGER ( TXT ( "::~COSSProtocolLoginRequest End\n" ) ); |
|
117 } |
|
118 |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // COSSProtocolLoginRequest::DoCancel() |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void COSSProtocolLoginRequest::DoCancel() |
|
125 { |
|
126 } |
|
127 |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // COSSProtocolLoginRequest::RunL() |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void COSSProtocolLoginRequest::RunL() |
|
134 { |
|
135 LOGGER ( TXT ( "COSSProtocolLoginRequest::RunL Start" ) ); |
|
136 message_hdr_resp* msg_struct = NULL; |
|
137 User::LeaveIfError ( iStatus.Int() ); |
|
138 char* pResponse = NULL; |
|
139 pResponse = iConnMan.DataHandler().ResponseL ( iSendId ); |
|
140 |
|
141 msg_struct = ( message_hdr_resp* )pResponse ; |
|
142 if( !( msg_struct->response ) ) |
|
143 { |
|
144 switch( msg_struct->error_type ) |
|
145 { |
|
146 case ELOGIN_NETWORK_ERROR: |
|
147 LOGGER ( TXT ( "COSSProtocolLoginRequest::RunL ELOGIN_NETWORK_ERROR" ) ); |
|
148 case ELOGIN_NONE_SPECIFIED: |
|
149 //XImpfw is not giving any error code for canceling accespoint so we are using KErrDisconnected |
|
150 //once error code is provided by ximpfw we can remove |
|
151 LOGGER ( TXT ( "COSSProtocolLoginRequest::RunL ELOGIN_NONE_SPECIFIED" ) ); |
|
152 iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, KErrDisconnected ); |
|
153 break; |
|
154 case ELOGIN_AUTHENTICATION: //The username or password was invalid. |
|
155 LOGGER ( TXT ( "COSSProtocolLoginRequest::RunL ELOGIN_AUTHENTICATION" ) ); |
|
156 iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, KXIMPErrServiceAuthenticationFailed ); |
|
157 break; |
|
158 default: //for all other error codes like ssl related are mapped to general error ELOGIN_AUTHORIZATION |
|
159 LOGGER ( TXT ( "COSSProtocolLoginRequest::RunL defualt" ) ); |
|
160 iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, KXIMPErrServiceGeneralError ); |
|
161 break; |
|
162 } |
|
163 } |
|
164 else |
|
165 { |
|
166 iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, KErrNone ); |
|
167 MPresenceBuddyInfo2* buddyPresInfo = MPresenceBuddyInfo2::NewLC(); |
|
168 MPresenceCacheWriter2* presenceCacheWriter = MPresenceCacheWriter2::CreateWriterL(); |
|
169 HBufC* userName = HBufC::NewLC( iUserName->Length() + iConnMan.ServiceName().Length() + KColon().Length() ); |
|
170 TPtr namePtr( userName->Des() ); |
|
171 namePtr.Zero(); |
|
172 namePtr.Append(iConnMan.ServiceName()); // prepend service name |
|
173 namePtr.Append(KColon); |
|
174 namePtr.Append(iUserName->Des() ); |
|
175 buddyPresInfo->SetIdentityL(namePtr); |
|
176 LOGGER ( TXT ( "COSSProtocolLoginRequest::owndata:%S " ), userName ); |
|
177 CleanupStack::PopAndDestroy();//userName |
|
178 _LIT(KAvailable,"available");//since not getting the own status from downlayer.here |
|
179 _LIT(KStatusTest,"Online");//is hardcoded once logged in is successfully |
|
180 HBufC16 *message = KAvailable().AllocLC(); |
|
181 buddyPresInfo->SetAvailabilityL( MPresenceBuddyInfo2::EAvailable,*message); |
|
182 HBufC16 *statusmessage = KStatusTest().AllocLC(); |
|
183 buddyPresInfo->SetStatusMessageL(*statusmessage); |
|
184 |
|
185 TInt cacheerror = presenceCacheWriter->WritePresenceL(buddyPresInfo); |
|
186 User::LeaveIfError ( cacheerror); |
|
187 CleanupStack::PopAndDestroy ( 3 ); //buddyPresInfo, message ,statusmessage |
|
188 delete presenceCacheWriter ; |
|
189 } |
|
190 |
|
191 |
|
192 free( pResponse ); |
|
193 delete this; |
|
194 |
|
195 LOGGER ( TXT ( "COSSProtocolLoginRequest::RunL End" ) ); |
|
196 |
|
197 } |
|
198 |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // COSSProtocolLoginRequest::RunError() |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 TInt COSSProtocolLoginRequest::RunError ( TInt aError ) |
|
205 { |
|
206 LOGGER ( TXT ( "COSSProtocolLoginRequest::RunError Start" ) ); |
|
207 |
|
208 iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, aError ); |
|
209 |
|
210 delete this; |
|
211 LOGGER ( TXT ( "COSSProtocolLoginRequest::RunError End" ) ); |
|
212 return KErrNone; |
|
213 } |
|
214 |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // COSSProtocolLoginRequest::IssueLoginRequestL() |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 void COSSProtocolLoginRequest::IssueLoginRequestL() |
|
221 { |
|
222 LOGGER ( TXT ( "COSSProtocolLoginRequest::IssueLoginRequestL Start" ) ); |
|
223 |
|
224 char *smsg = NULL; |
|
225 char *tmpmsg = NULL; |
|
226 message_hdr_req msgHdr = {0,}; |
|
227 int userLen = 0; |
|
228 int totalLen = 0; |
|
229 int err = 0; |
|
230 |
|
231 smsg = ( char* ) User::AllocLC(MAX_MSG_SIZE); |
|
232 |
|
233 tmpmsg = ( char* ) User::AllocLC(MAX_MSG_SIZE); |
|
234 |
|
235 HBufC* buffer = HBufC::NewLC ( MAX_MSG_SIZE ); |
|
236 TPtr bufferPtr ( buffer->Des() ); |
|
237 bufferPtr.Zero(); |
|
238 memset ( smsg, '\0', MAX_MSG_SIZE ); |
|
239 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
240 |
|
241 msgHdr.message_type = ELogin_Request; |
|
242 iConnMan.DataHandler().IncreaseOpId(); |
|
243 TInt Opid = iConnMan.DataHandler().GetOpId(); |
|
244 msgHdr.request_id = Opid; |
|
245 memcpy ( smsg, &msgHdr, sizeof ( message_hdr_req ) ); |
|
246 totalLen += sizeof ( message_hdr_req ); |
|
247 bufferPtr.Zero(); |
|
248 |
|
249 if ( iConnMan.UserName().Length() == 0 && iConnMan.Password().Length() == 0 ) //if username and pwd are not passed from client.read default settings |
|
250 { |
|
251 bufferPtr.Append ( iConnMan.XmppParams().UserName() ); |
|
252 iUserName = bufferPtr.AllocL(); |
|
253 LOGGER ( TXT ( "COSSProtocolLoginRequest::UserName:%S " ), & ( iConnMan.XmppParams().UserName() ) ); |
|
254 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
255 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
256 if( -1 == err) |
|
257 { |
|
258 iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, err ); |
|
259 } |
|
260 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
261 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
262 totalLen += userLen; |
|
263 |
|
264 bufferPtr.Zero(); |
|
265 bufferPtr.Append ( iConnMan.XmppParams().Passwd() ); |
|
266 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
267 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
268 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
269 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
270 totalLen += userLen; |
|
271 } |
|
272 else |
|
273 { |
|
274 iUserName = iConnMan.UserName().AllocL(); |
|
275 bufferPtr.Append ( iConnMan.UserName() ); |
|
276 LOGGER ( TXT ( "COSSProtocolLoginRequest::UserName:%S " ), & ( iConnMan.UserName() ) ); |
|
277 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
278 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
279 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
280 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
281 totalLen += userLen; |
|
282 |
|
283 bufferPtr.Zero(); |
|
284 bufferPtr.Append ( iConnMan.Password() ); |
|
285 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
286 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
287 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
288 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
289 totalLen += userLen; |
|
290 |
|
291 } |
|
292 |
|
293 bufferPtr.Zero(); |
|
294 |
|
295 bufferPtr.Append ( iConnMan.XmppParams().ServerAddress() ); |
|
296 LOGGER ( TXT ( "COSSProtocolLoginRequest::RunL:ServerAddress:%S " ), & ( iConnMan.XmppParams().ServerAddress() ) ); |
|
297 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
298 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
299 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
300 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
301 totalLen += userLen; |
|
302 |
|
303 //resource |
|
304 bufferPtr.Zero(); |
|
305 bufferPtr.Append ( GenResourceId(iConnMan.XmppParams().Resource()) ); |
|
306 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
307 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
308 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
309 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
310 totalLen += userLen; |
|
311 |
|
312 //ssl |
|
313 bufferPtr.Zero(); |
|
314 bufferPtr.AppendNum ( iConnMan.XmppParams().Ssl() ); |
|
315 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
316 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
317 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
318 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
319 totalLen += userLen; |
|
320 |
|
321 //ServerPort |
|
322 bufferPtr.Zero(); |
|
323 bufferPtr.AppendNum ( iConnMan.XmppParams().ServerPort() ); |
|
324 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
325 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
326 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
327 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
328 totalLen += userLen; |
|
329 |
|
330 //IapId |
|
331 bufferPtr.Zero(); |
|
332 bufferPtr.AppendNum ( iConnMan.XmppParams().IapId() ); |
|
333 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
334 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
335 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
336 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
337 totalLen += userLen; |
|
338 |
|
339 //connmgr_bus |
|
340 bufferPtr.Zero(); |
|
341 bufferPtr.Append ( iConnMan.XmppParams().ConnMgrBus() ); |
|
342 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
343 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
344 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
345 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
346 totalLen += userLen; |
|
347 |
|
348 //connmgr_path |
|
349 bufferPtr.Zero(); |
|
350 bufferPtr.Append ( iConnMan.XmppParams().ConnMgrPath() ); |
|
351 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
352 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
353 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
354 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
355 totalLen += userLen; |
|
356 |
|
357 //protocol |
|
358 bufferPtr.Zero(); |
|
359 bufferPtr.Append ( iConnMan.XmppParams().Protocol() ); |
|
360 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
361 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
362 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
363 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
364 totalLen += userLen; |
|
365 |
|
366 #ifdef __WINSCW__ |
|
367 //ProxyServer |
|
368 bufferPtr.Zero(); |
|
369 bufferPtr.Append ( iConnMan.XmppParams().ProxyServer() ); |
|
370 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
371 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
372 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
373 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
374 totalLen += userLen; |
|
375 |
|
376 //ProxyPort |
|
377 bufferPtr.Zero(); |
|
378 bufferPtr.AppendNum ( iConnMan.XmppParams().ProxyPort() ); |
|
379 memset ( tmpmsg, '\0', MAX_MSG_SIZE ); |
|
380 err = tbufC16tochar ( bufferPtr, tmpmsg ); |
|
381 userLen = strlen ( tmpmsg ) + 1; //for '\0' |
|
382 memcpy ( smsg + totalLen, tmpmsg, userLen ); |
|
383 totalLen += userLen; |
|
384 #endif |
|
385 |
|
386 |
|
387 iSendId = iConnMan.DataHandler().SendDataL ( iStatus, smsg, totalLen ); |
|
388 |
|
389 // signal the scheduler |
|
390 SetActive(); |
|
391 CleanupStack::PopAndDestroy (buffer); |
|
392 CleanupStack::PopAndDestroy (tmpmsg); |
|
393 CleanupStack::PopAndDestroy (smsg); |
|
394 LOGGER ( TXT ( "COSSProtocolConnection::OpenSessionL() End" ) ); |
|
395 } |
|
396 // --------------------------------------------------------------------------- |
|
397 // COSSProtocolLoginRequest::GenResourceId() |
|
398 // --------------------------------------------------------------------------- |
|
399 // |
|
400 TPtrC COSSProtocolLoginRequest::GenResourceId( const TDesC& aResourceId ) |
|
401 { |
|
402 TBuf<KImpsMaxResourceIdLen> tempRId = aResourceId; |
|
403 //initialise client id |
|
404 iResourceId.SetLength(0); |
|
405 |
|
406 //generate Resourse here |
|
407 iResourceId.Append(tempRId); |
|
408 |
|
409 TTime time; |
|
410 time.HomeTime(); |
|
411 TInt64 seed = time.Int64(); |
|
412 |
|
413 TInt i = Math::Rand( seed ); |
|
414 |
|
415 iResourceId.AppendFormat( _L("%d"), i); |
|
416 |
|
417 return iResourceId; |
|
418 } |
|
419 |
|
420 // End of file |