|
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: SyncML HTTP client |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "nsmlhttp.h" |
|
20 #include "nsmlhttpclient.h" |
|
21 #include <e32property.h> |
|
22 #include <DevManInternalCRKeys.h> |
|
23 #include <centralrepository.h> |
|
24 #include "nsmlprivatepskeys.h" |
|
25 |
|
26 |
|
27 #include "nsmlerror.h" |
|
28 #ifdef __NSML_DEBUG__ |
|
29 #include "wbxml2xmlconverter.h" |
|
30 #endif // __NSML_DEBUG__ |
|
31 |
|
32 #include <centralrepository.h> |
|
33 #include <ssl.h> |
|
34 #include "PMUtilInternalCRKeys.h" |
|
35 #include "nsmlhttpPrivateCRKeys.h" |
|
36 #include <nsmlunicodeconverter.h> |
|
37 #include <ezcompressor.h> |
|
38 #include <ezdecompressor.h> |
|
39 |
|
40 #ifndef __WINS__ |
|
41 // This lowers the unnecessary compiler warning (armv5) to remark. |
|
42 // "Warning: #174-D: expression has no effect..." is caused by |
|
43 // DBG_ARGS8 macro in no-debug builds. |
|
44 #pragma diag_remark 174 |
|
45 #endif |
|
46 #include <featmgr.h> |
|
47 |
|
48 // ============================ MEMBER FUNCTIONS =============================== |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CNSmlHTTP::NewL() |
|
52 // Two-phased constructor. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CNSmlHTTP* CNSmlHTTP::NewL() |
|
56 { |
|
57 CNSmlHTTP* self = new (ELeave) CNSmlHTTP(); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(); //self |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CNSmlHTTP::CNSmlHTTP() |
|
66 // constructor |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CNSmlHTTP::CNSmlHTTP() |
|
70 : CActive( EPriorityStandard ), iReqBodySubmitBufferPtr( 0,0 ) |
|
71 { |
|
72 CActiveScheduler::Add( this ); |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CNSmlHTTP::ConstructL() |
|
77 // 2-phase constructor |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CNSmlHTTP::ConstructL() |
|
81 { |
|
82 // construct shutdown timer |
|
83 DBG_FILE(_S8("CNSmlHTTP::ConstructL BEGIN")); |
|
84 FeatureManager::InitializeLibL(); |
|
85 iShutdown = new (ELeave) CNSmlXptShutdownTimer( this ); |
|
86 iShutdown->ConstructL(); |
|
87 iNetworkStatusEngine = NULL; |
|
88 // do this only if session is DM |
|
89 TInt session=0; |
|
90 TInt r=RProperty::Get( KPSUidNSmlSOSServerKey, KNSmlSyncJobOngoing, session); |
|
91 DBG_FILE_CODE(session, _S8("CNSmlHTTP::ConstructL Current Session is (DM = 2, DS = 1) ")); |
|
92 if( session == ESyncMLDMSession )//for dm session |
|
93 { |
|
94 TInt dmsessionTimeout = -1; |
|
95 CRepository *rep = NULL; |
|
96 TRAPD( err1, rep = CRepository::NewL( KCRUidDeviceManagementInternalKeys )) |
|
97 DBG_FILE_CODE(err1, _S8("CNSmlHTTP::ConstructL cenrep read error code ")); |
|
98 if(err1 == KErrNone) |
|
99 { |
|
100 rep->Get( KDevManDMSessionTimeout, dmsessionTimeout ); |
|
101 delete rep; |
|
102 DBG_FILE_CODE(dmsessionTimeout, _S8("CNSmlHTTP::ContructL, DMSessiontimeout feature value from cenrep")); |
|
103 if( dmsessionTimeout > KNSmlDMMaxSessionTimeout || dmsessionTimeout < KNSmlDMMinSessionTimeout) |
|
104 { |
|
105 dmsessionTimeout = -1; |
|
106 } |
|
107 DBG_FILE_CODE(dmsessionTimeout, _S8("CNSmlHTTP::ContructL, DMSessiontimeout feature value ")); |
|
108 } |
|
109 if(dmsessionTimeout != -1) |
|
110 { |
|
111 iNetworkStatusEngine = new (ELeave) CNsmlNetworkStatusEngine( this ); |
|
112 iNetworkStatusEngine->ConstructL(); |
|
113 iNetworkStatusEngine->NotifyL(); |
|
114 } |
|
115 } |
|
116 |
|
117 iPreemptRequest = 0; |
|
118 |
|
119 iServerContentEncoding = ExptNone; |
|
120 iServerAcceptEncoding = ExptNone; |
|
121 iSession = ESyncMLSessionUnknown; |
|
122 RProperty::Get( KPSUidNSmlSOSServerKey, KNSmlSyncJobOngoing, iSession); |
|
123 // construct dialup agent |
|
124 iDialUpAgent = new (ELeave) CNSmlDialUpAgent(); |
|
125 iDialUpAgent->ConstructL(); |
|
126 |
|
127 iEngineState = ExptIdle; |
|
128 iTimeOut = EFalse; |
|
129 iLastPart = EFalse; |
|
130 iAuthRetryCount=0; |
|
131 iAuthUsed=0; |
|
132 |
|
133 iTransObs = CHttpEventHandler::NewL(); |
|
134 iTransObs->ConstructL( this ); |
|
135 iMaxMsgSize = KNSmlDefaultWorkspaceSize; |
|
136 |
|
137 if( iSession == ESyncMLDSSession ) |
|
138 { |
|
139 TInt value(0); |
|
140 TRAPD( err, ReadRepositoryL( KNSmlMaxMsgSizeKey, value) ); |
|
141 if ( err == KErrNone ) |
|
142 { |
|
143 iMaxMsgSize = value; |
|
144 } |
|
145 } |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------- |
|
149 // CNSmlHTTP::ReadRepositoryL(TInt aKey, TInt& aValue) |
|
150 // |
|
151 // --------------------------------------------------------- |
|
152 TInt CNSmlHTTP::ReadRepositoryL(TInt aKey, TInt& aValue) |
|
153 { |
|
154 const TUid KRepositoryId = KCRUidNSmlDSEngine; |
|
155 |
|
156 CRepository* rep = CRepository::NewLC(KRepositoryId); |
|
157 TInt err = rep->Get(aKey, aValue); |
|
158 CleanupStack::PopAndDestroy(rep); |
|
159 |
|
160 return err; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CNSmlHTTP::~CNSmlHTTP() |
|
165 // desctructor |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 CNSmlHTTP::~CNSmlHTTP() |
|
169 { |
|
170 DBG_FILE(_S8("CNSmlHTTP::~CNSmlHTTP() BEGIN")); |
|
171 if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement)) |
|
172 { |
|
173 DeleteCertificate(); |
|
174 } |
|
175 |
|
176 Cancel(); |
|
177 delete iData; |
|
178 delete iReqBodySubmitBuffer; |
|
179 delete iURI; |
|
180 delete iMimeType; |
|
181 delete iHTTPusername; |
|
182 delete iHTTPpassword; |
|
183 delete iShutdown; |
|
184 iShutdown = NULL; |
|
185 if(iNetworkStatusEngine) |
|
186 { |
|
187 delete iNetworkStatusEngine; |
|
188 iNetworkStatusEngine = NULL; |
|
189 } |
|
190 iSess.Close(); |
|
191 delete iTransObs; |
|
192 delete iDialUpAgent; |
|
193 delete iIAPidArray; |
|
194 FeatureManager::UnInitializeLib(); |
|
195 DBG_FILE(_S8("CNSmlHTTP::~CNSmlHTTP() END")); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CNSmlHTTP::DoCancel() |
|
200 // DoCancel() from CActive |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CNSmlHTTP::DoCancel() |
|
204 {DBG_FILE(_S8("CNSmlHTTP::DoCancel() BEGIN")); |
|
205 iEngineState = ExptIdle; |
|
206 TInt cancelReason; |
|
207 |
|
208 iShutdown->Cancel(); |
|
209 iDialUpAgent->Cancel(); |
|
210 iSess.Close(); |
|
211 |
|
212 if( iTimeOut ) |
|
213 {DBG_FILE(_S8("CNSmlHTTP::DoCancel() timing out")); |
|
214 cancelReason = TNSmlHTTPErrCode::ENSmlHTTPErr_RequestTimeout; |
|
215 } |
|
216 else |
|
217 { |
|
218 cancelReason = KErrCancel; |
|
219 } |
|
220 // signal current (engine) thread request semaphore that this AO's |
|
221 // request has completed |
|
222 TRequestStatus* status = &iStatus; |
|
223 User::RequestComplete( status, cancelReason ); |
|
224 // signal agent |
|
225 TRequestStatus* agentStatus = iAgentStatus; |
|
226 User::RequestComplete( agentStatus, cancelReason ); |
|
227 DBG_FILE(_S8("CNSmlHTTP::DoCancel() END")); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CNSmlHTTP::CompleteRequest() |
|
232 // called when asynchronous request should be completed with a purpose |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CNSmlHTTP::CompleteRequest() |
|
236 { |
|
237 DBG_FILE(_S8("CNSmlHTTP::CompleteRequest BEGIN")); |
|
238 |
|
239 if(IsActive()) |
|
240 { |
|
241 DBG_FILE(_S8("CNSmlHTTP::CompleteRequest iTrans.Cancel();")); |
|
242 iTrans.Cancel(); |
|
243 DBG_FILE(_S8("CNSmlHTTP::CompleteRequest iTrans.Close();")); |
|
244 iTrans.Close(); |
|
245 DBG_FILE(_S8("CNSmlHTTP::CompleteRequest isActive returned TRUE ")); |
|
246 iPreemptRequest++; |
|
247 DBG_FILE_CODE( iPreemptRequest, _S8("Increasing value of iPreemptRequest ") ); |
|
248 TRequestStatus* status = &iStatus; |
|
249 User::RequestComplete( status, KErrTimedOut ); |
|
250 } |
|
251 |
|
252 DBG_FILE(_S8("CNSmlHTTP::CompleteRequest ENDS ")); |
|
253 } |
|
254 // CNSmlHTTP::RunL() |
|
255 // Runl() from CActive |
|
256 // called when asynchronous request completed |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CNSmlHTTP::RunL() |
|
260 { |
|
261 DBG_FILE(_S8("CNSmlHTTP::RunL begins")); |
|
262 |
|
263 DBG_FILE_CODE( iEngineState, _S8("RunL iEgnineStatus is : ") ); |
|
264 DBG_FILE_CODE( iStatus.Int(), _S8("RunL httpClient status is : ") ); |
|
265 if(iEngineState == ExptOpenCommunication) |
|
266 { |
|
267 DBG_FILE(_S8("CNSmlHTTP::RunL before SetHttpConnectionInfoL")); |
|
268 DBG_FILE_CODE( iStatus.Int(), _S8("RunL HTTP client iStatus: ") ); |
|
269 if( iStatus == KErrNone) |
|
270 { |
|
271 DBG_FILE(_S8("CNSmlHTTP::RunL Status was NO ERROR")); |
|
272 TRAPD( ret, SetHttpConnectionInfoL( EFalse ) ); |
|
273 if ( ret != KErrNone ) |
|
274 { |
|
275 DBG_FILE_CODE( ret, _S8("CNSmlHTTP::RunL SetHttpConnectionInfoL\ |
|
276 error:") ); |
|
277 iShutdown->Cancel(); |
|
278 TRequestStatus* status = iAgentStatus; |
|
279 User::RequestComplete( status, ret ); |
|
280 iTimeOut = EFalse; |
|
281 return; |
|
282 } |
|
283 } |
|
284 DBG_FILE(_S8("CNSmlHTTP::RunL after SetHttpConnectionInfoL")); |
|
285 } |
|
286 |
|
287 iShutdown->Cancel(); |
|
288 TRequestStatus* status = iAgentStatus; |
|
289 User::RequestComplete( status, iStatus.Int() ); |
|
290 iTimeOut = EFalse; |
|
291 DBG_FILE(_S8("CNSmlHTTP::RunL ends")); |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CNSmlHTTP::OpenCommunicationL |
|
296 // Establishes a communication using the protocol service with the given ID. |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CNSmlHTTP::OpenCommunicationL( |
|
300 CArrayFixFlat<TUint32>* aIAPidArray, |
|
301 TDesC8& aURI, |
|
302 TDesC8& aMimeType, |
|
303 TRequestStatus &aStatus, |
|
304 TDesC8& aHTTPusername, |
|
305 TDesC8& aHTTPpassword, |
|
306 TInt aHTTPauthused ) |
|
307 { |
|
308 __ASSERT_ALWAYS( !IsActive(), User::Panic( _L("CNSmlHTTP"), 1 ) ); |
|
309 if ( !iShutdown->IsActive() ) |
|
310 { |
|
311 iShutdown->Start(); |
|
312 } |
|
313 iAgentStatus = &aStatus; |
|
314 iEngineState = ExptOpenCommunication; |
|
315 |
|
316 iIAPidArray = new ( ELeave ) CArrayFixFlat<TUint32>(KSmlArrayGranularity); |
|
317 |
|
318 for ( TInt i = 0 ; i < aIAPidArray->Count() ; i++ ) |
|
319 { |
|
320 iIAPidArray->AppendL( aIAPidArray->At( i ) ); |
|
321 } |
|
322 |
|
323 iAuthUsed = aHTTPauthused; |
|
324 |
|
325 // Open the RHTTPSession |
|
326 iSess.OpenL(); |
|
327 |
|
328 // Install this class as the callback for authentication requests |
|
329 if( iAuthUsed ) |
|
330 { |
|
331 InstallAuthenticationL(iSess); |
|
332 } |
|
333 |
|
334 delete iURI; |
|
335 iURI = NULL; |
|
336 iURI = HBufC8::NewL( aURI.Length() ); |
|
337 TPtr8 iURIptr( iURI->Des() ); |
|
338 iURIptr.Copy( aURI ); |
|
339 |
|
340 delete iMimeType; |
|
341 iMimeType = NULL; |
|
342 iMimeType = HBufC8::NewL( aMimeType.Length() ); |
|
343 TPtr8 iMIMEptr( iMimeType->Des() ); |
|
344 iMIMEptr.Copy( aMimeType ); |
|
345 |
|
346 delete iHTTPusername; |
|
347 iHTTPusername = NULL; |
|
348 if(aHTTPusername.Length()!=0) |
|
349 { |
|
350 iHTTPusername = HBufC8::NewL( aHTTPusername.Length() ); |
|
351 TPtr8 iHTTPusernameptr( iHTTPusername->Des() ); |
|
352 iHTTPusernameptr.Copy( aHTTPusername ); |
|
353 } |
|
354 else |
|
355 { |
|
356 iHTTPusername = KNullDesC8().AllocL(); |
|
357 } |
|
358 |
|
359 delete iHTTPpassword; |
|
360 iHTTPpassword = NULL; |
|
361 if(aHTTPpassword.Length()!=0) |
|
362 { |
|
363 iHTTPpassword = HBufC8::NewL( aHTTPpassword.Length() ); |
|
364 TPtr8 iHTTPpasswordptr( iHTTPpassword->Des() ); |
|
365 iHTTPpasswordptr.Copy( aHTTPpassword ); |
|
366 } |
|
367 else |
|
368 { |
|
369 iHTTPpassword = KNullDesC8().AllocL(); |
|
370 } |
|
371 |
|
372 TRAPD( err, ProcessRequestL() ); |
|
373 User::LeaveIfError( err ); |
|
374 } |
|
375 |
|
376 // ----------------------------------------------------------------------------- |
|
377 // CNSmlHTTP::CloseCommunicationL( TRequestStatus &aStatus ) |
|
378 // Closes a previously opened communication. |
|
379 // ----------------------------------------------------------------------------- |
|
380 // |
|
381 void CNSmlHTTP::CloseCommunicationL( TRequestStatus &aStatus ) |
|
382 { |
|
383 __ASSERT_ALWAYS( !IsActive(), User::Panic( _L("CNSmlHTTP"), 1 ) ); |
|
384 iAgentStatus = &aStatus; |
|
385 iEngineState = ExptCloseCommunication; |
|
386 TRAPD( err, ProcessRequestL() ); |
|
387 User::LeaveIfError( err ); |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CNSmlHTTP::ReceiveDataL |
|
392 // Read data across a connection. |
|
393 // ----------------------------------------------------------------------------- |
|
394 // |
|
395 void CNSmlHTTP::ReceiveDataL( TDes8& aStartPtr, TRequestStatus &aStatus ) |
|
396 { |
|
397 __ASSERT_ALWAYS( !IsActive(), User::Panic( _L("CNSmlHTTP"), 1 ) ); |
|
398 iAgentStatus = &aStatus; |
|
399 if ( !iShutdown->IsActive() ) |
|
400 { |
|
401 iShutdown->Start(); |
|
402 } |
|
403 iEngineState = ExptReceiveData; |
|
404 GetResponseBodyL( aStartPtr ); |
|
405 |
|
406 DBG_DUMP((void*)aStartPtr.Ptr(), aStartPtr.Length(), |
|
407 _S8("ReceiveDataL (WBXML)")); |
|
408 #ifdef __NSML_DEBUG__ |
|
409 _DBG_FILE("CNSmlHTTP::ReceiveDataL(): CWbxml2XmlConverter::ConvertL()\ |
|
410 begin"); |
|
411 CWbxml2XmlConverter* c = CWbxml2XmlConverter::NewLC(); |
|
412 c->ConvertL(aStartPtr.Ptr(), aStartPtr.Length()); |
|
413 DBG_DUMP((void*)c->Document().Ptr(), c->Document().Length(), |
|
414 _S8("ReceiveDataL (XML)") ); |
|
415 CleanupStack::PopAndDestroy(); // c |
|
416 _DBG_FILE("CNSmlHTTP::ReceiveDataL(): CWbxml2XmlConverter::ConvertL() end"); |
|
417 #endif // __NSML_DEBUG__ |
|
418 |
|
419 TRAPD( err, ProcessRequestL() ); |
|
420 User::LeaveIfError( err ); |
|
421 } |
|
422 |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CNSmlHTTP::DeleteCertificate() |
|
426 // Delete HTTP connection certificate. |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 void CNSmlHTTP::DeleteCertificate( ) |
|
430 { |
|
431 if(!FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement)) |
|
432 { |
|
433 |
|
434 } |
|
435 else |
|
436 { |
|
437 CRepository *re = NULL; |
|
438 TRAPD( erx, re = CRepository::NewL ( |
|
439 KCRUidPolicyManagementUtilInternalKeys ) ); |
|
440 if (erx == KErrNone ) |
|
441 { |
|
442 re->Reset( KSyncMLSessionCertificate ); |
|
443 delete re; |
|
444 re = NULL; |
|
445 } |
|
446 else |
|
447 { |
|
448 DBG_ARGS8(_S8("ERROR Failed to delete reposiritry key %d"), erx ); |
|
449 } |
|
450 } |
|
451 } |
|
452 |
|
453 // ----------------------------------------------------------------------------- |
|
454 // CNSmlHTTP::SaveCertificateL( RHTTPTransaction &aTransaction ) |
|
455 // save HTTP connection certificate. |
|
456 // ----------------------------------------------------------------------------- |
|
457 // |
|
458 void CNSmlHTTP::SaveCertificateL( RHTTPTransaction &aTransaction ) |
|
459 { |
|
460 if(!FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement)) |
|
461 { |
|
462 User::Leave(KErrNotSupported); |
|
463 } |
|
464 TCertInfo info ; |
|
465 TInt errx( aTransaction.ServerCert( info ) ); |
|
466 if ( errx == KErrNone ) |
|
467 { |
|
468 CRepository *re = NULL; |
|
469 TRAPD( erx, re = CRepository::NewL ( |
|
470 KCRUidPolicyManagementUtilInternalKeys ) ); |
|
471 if (erx == KErrNone ) |
|
472 { |
|
473 TPckg<TCertInfo> pcert( info ); |
|
474 errx = re->Create( KSyncMLSessionCertificate, pcert ) ; |
|
475 if ( errx == KErrNone ) |
|
476 { |
|
477 DBG_ARGS8(_S8("Wrote reposotry key %S"), &pcert ); |
|
478 } |
|
479 else |
|
480 { |
|
481 if ( errx == KErrAlreadyExists ) |
|
482 { |
|
483 errx = re->Set( KSyncMLSessionCertificate, pcert ) ; |
|
484 if ( errx != KErrNone ) |
|
485 { |
|
486 DBG_ARGS8( _S8("ERROR Failed to add reposiritry \ |
|
487 key %d"), errx ); |
|
488 } |
|
489 } |
|
490 else |
|
491 { |
|
492 DBG_ARGS8( _S8("ERROR Failed to create reposiritry \ |
|
493 key %d"), errx ); |
|
494 } |
|
495 } |
|
496 delete re ; |
|
497 re = NULL; |
|
498 } |
|
499 else |
|
500 { |
|
501 DBG_ARGS8(_S8("ERROR Failed to open reposiritry %d"), erx ); |
|
502 } |
|
503 } |
|
504 else |
|
505 { |
|
506 DBG_ARGS8(_S8("ERROR Failed to get certificate %d"), errx ); |
|
507 } |
|
508 |
|
509 } |
|
510 |
|
511 // ----------------------------------------------------------------------------- |
|
512 // CNSmlHTTP::CompressL |
|
513 // Compress the data. |
|
514 // ----------------------------------------------------------------------------- |
|
515 // |
|
516 void CNSmlHTTP::CompressL(TDesC8& aStartPtr) |
|
517 { |
|
518 HBufC8* tempBufferPtr = HBufC8::NewLC(iMaxMsgSize); |
|
519 TPtr8 unCompressed( tempBufferPtr->Des()); |
|
520 unCompressed.Copy( aStartPtr ); |
|
521 |
|
522 iReqBodySubmitBuffer = NULL; |
|
523 iReqBodySubmitBuffer = HBufC8::NewMaxL( iMaxMsgSize ); |
|
524 |
|
525 iReqBodySubmitBufferPtr.Set( iReqBodySubmitBuffer->Des() ); |
|
526 TRAPD(err, CEZCompressor::CompressL(iReqBodySubmitBufferPtr, unCompressed, Z_BEST_COMPRESSION)); |
|
527 CleanupStack::PopAndDestroy(); |
|
528 if(err == KErrNone) |
|
529 { |
|
530 iDocumentLength = iReqBodySubmitBufferPtr.Length(); |
|
531 } |
|
532 } |
|
533 |
|
534 |
|
535 // ----------------------------------------------------------------------------- |
|
536 // CNSmlHTTP::SendDataL |
|
537 // Send data across a connection. |
|
538 // ----------------------------------------------------------------------------- |
|
539 // |
|
540 void CNSmlHTTP::SendDataL( |
|
541 TDesC8& aStartPtr, |
|
542 TBool /*aFinalPacket*/, |
|
543 TRequestStatus &aStatus ) |
|
544 { |
|
545 __ASSERT_ALWAYS( !IsActive(), User::Panic( _L("CNSmlHTTP"), 1 ) ); |
|
546 iAgentStatus = &aStatus; |
|
547 if ( !iShutdown->IsActive() ) |
|
548 { |
|
549 iShutdown->Start(); |
|
550 } |
|
551 iEngineState = ExptSendData; |
|
552 |
|
553 DBG_DUMP((void*)aStartPtr.Ptr(), aStartPtr.Length(), |
|
554 _S8("SendDataL (WBXML)") ); |
|
555 #ifdef __NSML_DEBUG__ |
|
556 _DBG_FILE("CNSmlHTTP::SendDataL(): CWbxml2XmlConverter::ConvertL() begin"); |
|
557 CWbxml2XmlConverter* c = CWbxml2XmlConverter::NewLC(); |
|
558 c->ConvertL(aStartPtr.Ptr(), aStartPtr.Length()); |
|
559 DBG_DUMP((void*)c->Document().Ptr(), c->Document().Length(), |
|
560 _S8("SendDataL (XML)") ); |
|
561 CleanupStack::PopAndDestroy(); // c |
|
562 _DBG_FILE("CNSmlHTTP::SendDataL(): CWbxml2XmlConverter::ConvertL() end"); |
|
563 #endif // __NSML_DEBUG__ |
|
564 |
|
565 delete iReqBodySubmitBuffer; |
|
566 iReqBodySubmitBuffer = NULL; |
|
567 |
|
568 if( (iSession == ESyncMLDSSession) && (iServerAcceptEncoding == ExptDeflate) ) |
|
569 { |
|
570 TRAPD( err, CompressL(aStartPtr) ); |
|
571 User::LeaveIfError( err ); |
|
572 } |
|
573 else |
|
574 { |
|
575 iReqBodySubmitBuffer = HBufC8::NewMaxL( iMaxMsgSize ); |
|
576 iReqBodySubmitBufferPtr.Set( iReqBodySubmitBuffer->Des() ); |
|
577 iReqBodySubmitBufferPtr.Copy( aStartPtr ); |
|
578 iDocumentLength = aStartPtr.Length(); |
|
579 } |
|
580 TRAPD( err, ProcessRequestL() ); |
|
581 User::LeaveIfError( err ); |
|
582 } |
|
583 |
|
584 // ----------------------------------------------------------------------------- |
|
585 // CNSmlHTTP::DecompressL |
|
586 // Decompress the data. |
|
587 // ----------------------------------------------------------------------------- |
|
588 // |
|
589 void CNSmlHTTP::DecompressL(TDes8& aStartPtr) |
|
590 { |
|
591 TPtr8 ptrCompressed( iData->Des() ); |
|
592 HBufC8* ideCompressed = HBufC8::NewLC(iMaxMsgSize); |
|
593 TPtr8 ptrdeCompressed( ideCompressed->Des() ); |
|
594 |
|
595 TRAPD(err, CEZDecompressor::DecompressL(ptrdeCompressed,ptrCompressed)); |
|
596 |
|
597 if(err == KErrNone) |
|
598 { |
|
599 aStartPtr.Copy( ideCompressed->Des()); |
|
600 } |
|
601 CleanupStack::PopAndDestroy(); |
|
602 } |
|
603 |
|
604 |
|
605 // ----------------------------------------------------------------------------- |
|
606 // CNSmlHTTP::ProcessRequestL() |
|
607 // wake up thread (or create one) to handle requested service |
|
608 // ----------------------------------------------------------------------------- |
|
609 // |
|
610 void CNSmlHTTP::ProcessRequestL() |
|
611 { |
|
612 TRequestStatus* statusOwn = &this->iStatus; |
|
613 // set AO (CNSmlHTTP) active |
|
614 this->iStatus = KRequestPending; |
|
615 this->SetActive(); |
|
616 // agent |
|
617 *iAgentStatus = KRequestPending; |
|
618 |
|
619 if ( iEngineState == ExptOpenCommunication ) |
|
620 { |
|
621 this->iDialUpAgent->ConnectL( iIAPidArray, iStatus ); |
|
622 } |
|
623 else if ( iEngineState == ExptCloseCommunication ) |
|
624 { |
|
625 this->Cancel(); |
|
626 } |
|
627 else if ( iEngineState == ExptReceiveData ) |
|
628 { |
|
629 User::RequestComplete( statusOwn, KErrNone ); |
|
630 } |
|
631 else if ( iEngineState == ExptSendData ) |
|
632 { |
|
633 RStringPool strP = iSess.StringPool(); |
|
634 RStringF method; |
|
635 method = strP.StringF( HTTP::EPOST, RHTTPSession::GetTable() ); |
|
636 |
|
637 RHTTPConnectionInfo connInfo = iSess.ConnectionInfo(); |
|
638 connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ, |
|
639 RHTTPSession::GetTable() ), |
|
640 THTTPHdrVal ( |
|
641 this->iDialUpAgent->iSocketServer.Handle() ) ); |
|
642 TInt connPtr = REINTERPRET_CAST(TInt, &this->iDialUpAgent->iConnection); |
|
643 connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection, |
|
644 RHTTPSession::GetTable() ), |
|
645 THTTPHdrVal (connPtr) ); |
|
646 TInt session=0; |
|
647 TInt r1=RProperty::Get( KPSUidNSmlSOSServerKey, KNSmlSyncJobOngoing, session); |
|
648 if( session == ESyncMLDMSession )//for dm session |
|
649 { |
|
650 TInt dmsessionTimeout = -1; |
|
651 CRepository *rep = NULL; |
|
652 TRAPD( err1, rep = CRepository::NewL( KCRUidDeviceManagementInternalKeys )); |
|
653 DBG_FILE_CODE(err1, _S8("CNSmlHTTP::ConstructL cenrep read error code ")); |
|
654 if(err1 == KErrNone) |
|
655 { |
|
656 rep->Get( KDevManDMSessionTimeout, dmsessionTimeout ); |
|
657 delete rep; |
|
658 DBG_FILE_CODE(dmsessionTimeout, _S8("DMSessiontimeout feature value from cenrep")); |
|
659 if( dmsessionTimeout < KNSmlDMMaxSessionTimeout && dmsessionTimeout > KNSmlDMMinSessionTimeout) |
|
660 { |
|
661 THTTPHdrVal immediateShutdown = strP.StringF(HTTP::ESocketShutdownImmediate, RHTTPSession::GetTable() ); |
|
662 connInfo.SetPropertyL ( |
|
663 strP.StringF(HTTP::ESocketShutdownMode, RHTTPSession::GetTable()), |
|
664 immediateShutdown ); |
|
665 } |
|
666 } |
|
667 } |
|
668 if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement)) |
|
669 { |
|
670 TInt Session=0; |
|
671 TInt r=RProperty::Get( KPSUidNSmlSOSServerKey, KNSmlSyncJobOngoing, Session); |
|
672 if( Session == ESyncMLDMSession )//for dm session |
|
673 { |
|
674 THTTPHdrVal secDlgNo( strP.StringF(HTTP::EDialogNoPrompt, |
|
675 RHTTPSession::GetTable() ) ); |
|
676 connInfo.SetPropertyL ( strP.StringF(HTTP::ESecureDialog, |
|
677 RHTTPSession::GetTable() ), secDlgNo ); |
|
678 DBG_FILE_CODE( Session, _S8("In HTTP No prompt set ") ); |
|
679 } |
|
680 } |
|
681 |
|
682 |
|
683 InvokeHttpMethodL( iURI->Des(), method ); |
|
684 } |
|
685 } |
|
686 |
|
687 // ----------------------------------------------------------------------------- |
|
688 // CNSmlHTTP::ChangeTargetURIL( TDesC8& aURI ) |
|
689 // Changes target URI |
|
690 // ----------------------------------------------------------------------------- |
|
691 // |
|
692 void CNSmlHTTP::ChangeTargetURIL( TDesC8& aURI ) |
|
693 { |
|
694 delete iURI; |
|
695 iURI = NULL; |
|
696 iURI = HBufC8::NewL( aURI.Length() ); |
|
697 TPtr8 iURIptr( iURI->Des() ); |
|
698 iURIptr.Copy( aURI ); |
|
699 } |
|
700 |
|
701 // ----------------------------------------------------------------------------- |
|
702 // CNSmlHTTP::SetErrorStatus( Tint aError ) |
|
703 // Returns the internal http error status code for 4xx-5xx statuses |
|
704 // ----------------------------------------------------------------------------- |
|
705 // |
|
706 TInt CNSmlHTTP::SetErrorStatus( TInt aError ) |
|
707 { |
|
708 TInt error = aError; |
|
709 DBG_FILE_CODE( aError, _S8("http Error code in SetError CNSmlHTTP ") ); |
|
710 if( aError == 400 ) |
|
711 { |
|
712 return TNSmlHTTPErrCode::ENSmlHTTPErr_BadRequest; |
|
713 } |
|
714 else if ( aError == 401) |
|
715 { |
|
716 return TNSmlHTTPErrCode::ENSmlHTTPErr_Unauthorized; |
|
717 } |
|
718 else if ( aError == 402) |
|
719 { |
|
720 return TNSmlHTTPErrCode::ENSmlHTTPErr_PaymentRequired; |
|
721 } |
|
722 else if ( aError == 403) |
|
723 { |
|
724 return TNSmlHTTPErrCode::ENSmlHTTPErr_Forbidden; |
|
725 } |
|
726 else if ( aError == 404) |
|
727 { |
|
728 return TNSmlHTTPErrCode::ENSmlHTTPErr_NotFound; |
|
729 } |
|
730 else if ( aError == 405) |
|
731 { |
|
732 return TNSmlHTTPErrCode::ENSmlHTTPErr_MethodNotAllowed; |
|
733 } |
|
734 else if ( aError == 406) |
|
735 { |
|
736 return TNSmlHTTPErrCode::ENSmlHTTPErr_NotAcceptable; |
|
737 } |
|
738 else if ( aError == 407) |
|
739 { |
|
740 return TNSmlHTTPErrCode::ENSmlHTTPErr_ProxyAuthenticationRequired; |
|
741 } |
|
742 else if ( aError == 408) |
|
743 { |
|
744 return TNSmlHTTPErrCode::ENSmlHTTPErr_RequestTimeout; |
|
745 } |
|
746 else if ( aError == 409) |
|
747 { |
|
748 return TNSmlHTTPErrCode::ENSmlHTTPErr_Conflict; |
|
749 } |
|
750 else if ( aError == 410) |
|
751 { |
|
752 return TNSmlHTTPErrCode::ENSmlHTTPErr_Gone; |
|
753 } |
|
754 else if ( aError == 411) |
|
755 { |
|
756 return TNSmlHTTPErrCode::ENSmlHTTPErr_LengthRequired; |
|
757 } |
|
758 else if ( aError == 412) |
|
759 { |
|
760 return TNSmlHTTPErrCode::ENSmlHTTPErr_PreconditionFailed; |
|
761 } |
|
762 else if ( aError == 413) |
|
763 { |
|
764 return TNSmlHTTPErrCode::ENSmlHTTPErr_RequestEntityTooLarge; |
|
765 } |
|
766 else if ( aError == 414) |
|
767 { |
|
768 return TNSmlHTTPErrCode::ENSmlHTTPErr_RequestURITooLong; |
|
769 } |
|
770 else if ( aError == 415) |
|
771 { |
|
772 return TNSmlHTTPErrCode::ENSmlHTTPErr_UnsupportedMediaType; |
|
773 } |
|
774 else if ( aError == 416) |
|
775 { |
|
776 return TNSmlHTTPErrCode::ENSmlHTTPErr_RequestedRangeNotSatisfiable; |
|
777 } |
|
778 else if ( aError == 417) |
|
779 { |
|
780 return TNSmlHTTPErrCode::ENSmlHTTPErr_ExpectationFailed; |
|
781 } |
|
782 else if ( aError == 500) |
|
783 { |
|
784 return TNSmlHTTPErrCode::ENSmlHTTPErr_InternalServerError; |
|
785 } |
|
786 else if ( aError == 501) |
|
787 { |
|
788 return TNSmlHTTPErrCode::ENSmlHTTPErr_NotImplemented; |
|
789 } |
|
790 else if ( aError == 502) |
|
791 { |
|
792 return TNSmlHTTPErrCode::ENSmlHTTPErr_BadGateway; |
|
793 } |
|
794 else if ( aError == 503) |
|
795 { |
|
796 return TNSmlHTTPErrCode::ENSmlHTTPErr_ServiceUnavailable; |
|
797 } |
|
798 else if ( aError == 504) |
|
799 { |
|
800 return TNSmlHTTPErrCode::ENSmlHTTPErr_GatewayTimeout; |
|
801 } |
|
802 else if ( aError == 505) |
|
803 { |
|
804 return TNSmlHTTPErrCode::ENSmlHTTPErr_HTTPVersionNotSupported; |
|
805 } |
|
806 else |
|
807 { |
|
808 return error; |
|
809 } |
|
810 } |
|
811 |
|
812 // ----------------------------------------------------------------------------- |
|
813 // CNSmlHTTP::GetCredentialsL (const TUriC8 &aURI,RString aRealm, |
|
814 // RStringF aAuthenticationType,RString &aUsername,RString &aPassword) |
|
815 // Gets some credentials |
|
816 // ----------------------------------------------------------------------------- |
|
817 // |
|
818 TBool CNSmlHTTP::GetCredentialsL ( |
|
819 const TUriC8 &/*aURI*/, |
|
820 RString aRealm, |
|
821 RStringF /*aAuthenticationType*/, |
|
822 RString &aUsername, |
|
823 RString &aPassword) |
|
824 { |
|
825 |
|
826 if(iAuthRetryCount > 1) |
|
827 { |
|
828 return EFalse; |
|
829 } |
|
830 |
|
831 TRAPD(err, aUsername = aRealm.Pool().OpenStringL(*iHTTPusername)); |
|
832 if (!err) |
|
833 { |
|
834 TRAP(err, aPassword = aRealm.Pool().OpenStringL(*iHTTPpassword)); |
|
835 } |
|
836 |
|
837 if (!err) |
|
838 { |
|
839 iAuthRetryCount++; |
|
840 return ETrue; |
|
841 } |
|
842 else |
|
843 { |
|
844 return EFalse; |
|
845 } |
|
846 } |
|
847 |
|
848 // ----------------------------------------------------------------------------- |
|
849 // CNSmlHTTP::SetHttpConnectionInfoL( TBool aUseOwnConnection ) |
|
850 // Sets proxy for the connection, if it is configured for the IAP.. |
|
851 // ----------------------------------------------------------------------------- |
|
852 // |
|
853 void CNSmlHTTP::SetHttpConnectionInfoL( TBool aUseOwnConnection ) |
|
854 { |
|
855 DBG_FILE(_S8("CNSmlHTTP::SetHttpConnectionInfo begins")); |
|
856 TInt result; |
|
857 TBuf<100> serviceType; |
|
858 TUint32 serviceId; |
|
859 TBuf<100> query; |
|
860 TBuf<100> proxyAddr; |
|
861 TBuf8<100> proxyAddr2; |
|
862 TUint32 proxyPort; |
|
863 TUint connCount; |
|
864 TBool useProxy; |
|
865 CCommsDatabase* TheDb; |
|
866 RStringF proxyName; |
|
867 |
|
868 // Trick to get new values into use |
|
869 iSess.Close(); |
|
870 iSess.OpenL(); |
|
871 |
|
872 RStringPool strPool = iSess.StringPool(); |
|
873 |
|
874 |
|
875 // Remove first session properties just in case. |
|
876 RHTTPConnectionInfo connInfo = iSess.ConnectionInfo(); |
|
877 |
|
878 // Clear RConnection and Socket Server instances |
|
879 connInfo.RemoveProperty(strPool.StringF(HTTP::EHttpSocketServ, |
|
880 RHTTPSession::GetTable())); |
|
881 connInfo.RemoveProperty(strPool.StringF(HTTP::EHttpSocketConnection, |
|
882 RHTTPSession::GetTable())); |
|
883 |
|
884 // Clear the proxy settings |
|
885 THTTPHdrVal proxyUsage(strPool.StringF(HTTP::EUseProxy, |
|
886 RHTTPSession::GetTable())); |
|
887 connInfo.RemoveProperty(strPool.StringF(HTTP::EProxyUsage, |
|
888 RHTTPSession::GetTable())); |
|
889 connInfo.RemoveProperty(strPool.StringF(HTTP::EProxyAddress, |
|
890 RHTTPSession::GetTable())); |
|
891 |
|
892 if(!aUseOwnConnection) |
|
893 { |
|
894 // RConnection has been started, set proxy (if defined) and RConnection and |
|
895 // Socket Server session properties. |
|
896 |
|
897 DBG_FILE(_S8("CNSmlHTTP::SetHttpConnectionInfo !aUseOwnConnection")); |
|
898 // Proxy |
|
899 result = this->iDialUpAgent->iConnection. |
|
900 EnumerateConnections(connCount); |
|
901 User::LeaveIfError(result); |
|
902 |
|
903 // |
|
904 // Get service and service type for this connection |
|
905 // |
|
906 query.Format(_L("%s\\%s"), IAP, IAP_SERVICE); |
|
907 result = this->iDialUpAgent->iConnection.GetIntSetting(query, |
|
908 serviceId); |
|
909 |
|
910 query.Format(_L("%s\\%s"), IAP, IAP_SERVICE_TYPE); |
|
911 result = this->iDialUpAgent->iConnection.GetDesSetting(query, |
|
912 serviceType); |
|
913 User::LeaveIfError(result); |
|
914 |
|
915 TheDb = CCommsDatabase::NewL(); |
|
916 CleanupStack::PushL(TheDb); |
|
917 |
|
918 CCommsDbTableView* view = TheDb->OpenViewOnProxyRecordLC(serviceId, |
|
919 serviceType); |
|
920 result = view->GotoFirstRecord(); |
|
921 |
|
922 if(result == KErrNone) |
|
923 { |
|
924 // This IAP uses proxy, set it to http session |
|
925 view->ReadBoolL(TPtrC(PROXY_USE_PROXY_SERVER), useProxy); |
|
926 if(useProxy) |
|
927 { |
|
928 DBG_FILE(_S8("CNSmlHTTP::SetHttpConnectionInfo WE are using PROXY!")); |
|
929 |
|
930 TRAPD(err ,view->ReadUintL(TPtrC(PROXY_PORT_NUMBER), proxyPort)); |
|
931 |
|
932 if (err == KErrNone) |
|
933 { |
|
934 DBG_FILE(_S8("Proxy Port Number Found")); |
|
935 HBufC* k = view->ReadLongTextLC(TPtrC(PROXY_SERVER_NAME)); |
|
936 proxyAddr.Copy(k->Des()); |
|
937 proxyAddr.AppendFormat(_L(":%d"), proxyPort); |
|
938 |
|
939 proxyAddr2.Copy(proxyAddr); |
|
940 |
|
941 CleanupClosePushL(proxyName); |
|
942 proxyName = iSess.StringPool().OpenFStringL(proxyAddr2); |
|
943 connInfo.SetPropertyL(strPool.StringF(HTTP::EProxyUsage, |
|
944 RHTTPSession::GetTable()), proxyUsage); |
|
945 connInfo.SetPropertyL(strPool.StringF(HTTP::EProxyAddress, |
|
946 RHTTPSession::GetTable()), proxyName); |
|
947 CleanupStack::PopAndDestroy(); // proxyName |
|
948 CleanupStack::PopAndDestroy(); //k |
|
949 } |
|
950 } |
|
951 |
|
952 } |
|
953 CleanupStack::PopAndDestroy(2); // view, TheDb |
|
954 |
|
955 DBG_FILE(_S8("CNSmlHTTP::SetHttpConnectionInfo before SetPropertys")); |
|
956 // RConnection and Socket Server |
|
957 connInfo.SetPropertyL ( |
|
958 strPool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable()), |
|
959 THTTPHdrVal (this->iDialUpAgent->iSocketServer.Handle()) ); |
|
960 |
|
961 TInt connPtr1 = REINTERPRET_CAST(TInt, &this->iDialUpAgent->iConnection); |
|
962 connInfo.SetPropertyL ( |
|
963 strPool.StringF(HTTP::EHttpSocketConnection, |
|
964 RHTTPSession::GetTable() ), THTTPHdrVal (connPtr1) ); |
|
965 |
|
966 if( iAuthUsed ) |
|
967 { |
|
968 DBG_FILE(_S8("CNSmlHTTP::SetHttpConnectionInfo \ |
|
969 before installing auth filter")); |
|
970 InstallAuthenticationL( iSess ); |
|
971 } |
|
972 |
|
973 } |
|
974 |
|
975 DBG_FILE(_S8("CNSmlHTTP::SetHttpConnectionInfo ends")); |
|
976 } |
|
977 |
|
978 // ----------------------------------------------------------------------------- |
|
979 // CNSmlHTTP::GetNextDataPart( TPtrC8& aDataPart ) |
|
980 // |
|
981 // ----------------------------------------------------------------------------- |
|
982 // |
|
983 TBool CNSmlHTTP::GetNextDataPart( TPtrC8& aDataPart ) |
|
984 { |
|
985 aDataPart.Set( iReqBodySubmitBufferPtr ); |
|
986 iLastPart = ETrue; |
|
987 return iLastPart; |
|
988 } |
|
989 |
|
990 // ----------------------------------------------------------------------------- |
|
991 // CNSmlHTTP::ReleaseData() |
|
992 // |
|
993 // ----------------------------------------------------------------------------- |
|
994 // |
|
995 void CNSmlHTTP::ReleaseData() |
|
996 { |
|
997 |
|
998 // Fix for BPSS-7H7H5S |
|
999 |
|
1000 // Clear out the submit buffer |
|
1001 //TPtr8 buff = iReqBodySubmitBuffer->Des(); |
|
1002 //buff.Zero(); |
|
1003 |
|
1004 if (iLastPart) |
|
1005 return; |
|
1006 // Notify HTTP of more data available immediately, since it's being read |
|
1007 //from file |
|
1008 TRAPD( err, iTrans.NotifyNewRequestBodyPartL() ); |
|
1009 if ( err != KErrNone ) |
|
1010 User::Panic( KSmlHttpClientPanic, KCouldNotNotifyBodyDataPart ); |
|
1011 } |
|
1012 |
|
1013 // ----------------------------------------------------------------------------- |
|
1014 // CNSmlHTTP::OverallDataSize() |
|
1015 // |
|
1016 // ----------------------------------------------------------------------------- |
|
1017 // |
|
1018 TInt CNSmlHTTP::OverallDataSize() |
|
1019 { |
|
1020 return iDocumentLength; |
|
1021 } |
|
1022 |
|
1023 // ----------------------------------------------------------------------------- |
|
1024 // CNSmlHTTP::Reset() |
|
1025 // |
|
1026 // ----------------------------------------------------------------------------- |
|
1027 // |
|
1028 TInt CNSmlHTTP::Reset() |
|
1029 { |
|
1030 // Reset is called when the posted data needs to be resend |
|
1031 return KErrNone; |
|
1032 } |
|
1033 |
|
1034 // ----------------------------------------------------------------------------- |
|
1035 // CNSmlHTTP::InvokeHttpMethodL( const TDesC8& aUri, RStringF aMethod ) |
|
1036 // Invoke the http method |
|
1037 // This actually creates the transaction, sets the headers and |
|
1038 // body and then starts the transaction |
|
1039 // ----------------------------------------------------------------------------- |
|
1040 // |
|
1041 void CNSmlHTTP::InvokeHttpMethodL( const TDesC8& aUri, RStringF aMethod ) |
|
1042 { |
|
1043 TUriParser8 uri; |
|
1044 uri.Parse( aUri ); |
|
1045 iTrans = iSess.OpenTransactionL( uri, *iTransObs, aMethod ); |
|
1046 RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection(); |
|
1047 |
|
1048 // Add headers appropriate to all methods |
|
1049 TInt error; |
|
1050 HBufC* useragent = HBufC::NewLC( NCentralRepositoryConstants::KMaxUnicodeStringLength ); |
|
1051 TPtr ptr (useragent->Des() ); |
|
1052 CRepository* rep = CRepository::NewLC( KCRUidNsmlHttp ); |
|
1053 error = rep->Get( KNsmlHttpUAHeader, ptr ); |
|
1054 if( error == KErrNone ) |
|
1055 { |
|
1056 HBufC8* uaheader; |
|
1057 NSmlUnicodeConverter::HBufC8InUTF8LC( *useragent, uaheader ); |
|
1058 TPtr8 ptr8( uaheader->Des() ); |
|
1059 SetHeaderL( hdr, HTTP::EUserAgent, uaheader->Des() ); |
|
1060 DBG_ARGS8(_S8("CNSmlHTTP::InvokeHttpMethodL KNsmlHttpUAHeader key value %S"), &ptr8); |
|
1061 CleanupStack::PopAndDestroy( uaheader ); |
|
1062 } |
|
1063 else |
|
1064 { |
|
1065 DBG_FILE(_S8("CNSmlHTTP::InvokeHttpMethodL KNsmlHttpUAHeader key error ")); |
|
1066 } |
|
1067 CleanupStack::PopAndDestroy( rep ); |
|
1068 CleanupStack::PopAndDestroy( useragent ); |
|
1069 SetHeaderL( hdr, HTTP::ECacheControl, KSmlCacheControl ); |
|
1070 SetHeaderL( hdr, HTTP::EAcceptCharset, KSmlAcceptCharSet ); |
|
1071 SetHeaderL( hdr, HTTP::EAcceptLanguage , KSmlAcceptLanguage ); |
|
1072 |
|
1073 if( iSession == ESyncMLDSSession )//for ds session |
|
1074 { |
|
1075 if(iServerAcceptEncoding == ExptDeflate) |
|
1076 { |
|
1077 SetHeaderL( hdr, HTTP::EContentEncoding , KSmlContentDeflate ); |
|
1078 } |
|
1079 SetHeaderL( hdr, HTTP::EAcceptEncoding , KSmlContentDeflate ); |
|
1080 } |
|
1081 |
|
1082 // Add headers and body data for methods that use request bodies |
|
1083 // Content type header |
|
1084 TBuf8<KMaxContentTypeSize> contTypeBuf; |
|
1085 contTypeBuf.Copy( iMimeType->Des() ); |
|
1086 RStringF contTypeStr; |
|
1087 CleanupClosePushL( contTypeStr ); |
|
1088 contTypeStr = iSess.StringPool().OpenFStringL( contTypeBuf ); |
|
1089 THTTPHdrVal contType( contTypeStr ); |
|
1090 hdr.SetFieldL( iSess.StringPool().StringF( HTTP::EContentType, |
|
1091 RHTTPSession::GetTable()), contType ); |
|
1092 CleanupStack::PopAndDestroy(); // contTypeStr |
|
1093 |
|
1094 |
|
1095 // Accept header |
|
1096 TBuf8<KMaxContentTypeSize> acceptTypeBuf; |
|
1097 acceptTypeBuf.Copy( iMimeType->Des() ); |
|
1098 RStringF acceptTypeStr; |
|
1099 CleanupClosePushL( acceptTypeStr ); |
|
1100 acceptTypeStr = iSess.StringPool().OpenFStringL( acceptTypeBuf ); |
|
1101 THTTPHdrVal acceptType( acceptTypeStr ); |
|
1102 hdr.SetFieldL( iSess.StringPool().StringF( HTTP::EAccept, |
|
1103 RHTTPSession::GetTable()), acceptType ); |
|
1104 CleanupStack::PopAndDestroy(); // acceptTypeStr |
|
1105 |
|
1106 // Expect: 100-continue |
|
1107 THTTPHdrVal expectVal( iSess.StringPool().StringF( HTTP::E100Continue, |
|
1108 RHTTPSession::GetTable() ) ); |
|
1109 hdr.SetFieldL( iSess.StringPool().StringF( HTTP::EExpect, |
|
1110 RHTTPSession::GetTable() ), expectVal ); |
|
1111 |
|
1112 RStringF expectStr( iSess.StringPool().StringF( HTTP::EExpect, |
|
1113 RHTTPSession::GetTable() ) ); |
|
1114 hdr.RemoveField( expectStr ); |
|
1115 |
|
1116 MHTTPDataSupplier* dataSupplier = this; |
|
1117 iTrans.Request().SetBody( *dataSupplier ); |
|
1118 |
|
1119 // submit the transaction |
|
1120 iTrans.SubmitL(); |
|
1121 } |
|
1122 |
|
1123 // ----------------------------------------------------------------------------- |
|
1124 // CNSmlHTTP::GetResponseBodyL( TDes8& aStartPtr ) |
|
1125 // |
|
1126 // ----------------------------------------------------------------------------- |
|
1127 // |
|
1128 void CNSmlHTTP::GetResponseBodyL( TDes8& aStartPtr ) |
|
1129 { |
|
1130 if( iData != NULL ) |
|
1131 { |
|
1132 if (aStartPtr.MaxLength() < (iData->Des()).Length()) |
|
1133 { |
|
1134 User::LeaveIfError( TNSmlError::ESmlStatusSizeMismatch ); |
|
1135 } |
|
1136 else |
|
1137 { |
|
1138 if ( (iSession == ESyncMLDSSession) && (iServerContentEncoding == ExptDeflate) ) |
|
1139 { |
|
1140 TRAPD( err, DecompressL( aStartPtr ) ); |
|
1141 User::LeaveIfError( err ); |
|
1142 } |
|
1143 else |
|
1144 { |
|
1145 aStartPtr.Copy( iData->Des() ); |
|
1146 } |
|
1147 } |
|
1148 } |
|
1149 } |
|
1150 |
|
1151 // ----------------------------------------------------------------------------- |
|
1152 // CNSmlHTTP::SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField, |
|
1153 // const TDesC8& aHdrValue ) |
|
1154 // |
|
1155 // ----------------------------------------------------------------------------- |
|
1156 // |
|
1157 void CNSmlHTTP::SetHeaderL( |
|
1158 RHTTPHeaders aHeaders, |
|
1159 TInt aHdrField, |
|
1160 const TDesC8& aHdrValue ) |
|
1161 { |
|
1162 RStringF valStr; |
|
1163 CleanupClosePushL( valStr ); |
|
1164 valStr = iSess.StringPool().OpenFStringL( aHdrValue ); |
|
1165 THTTPHdrVal val( valStr ); |
|
1166 aHeaders.SetFieldL( iSess.StringPool().StringF( aHdrField, |
|
1167 RHTTPSession::GetTable() ), val ); |
|
1168 CleanupStack::PopAndDestroy(); // valStr |
|
1169 } |
|
1170 |
|
1171 |
|
1172 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
1173 |
|
1174 // ----------------------------------------------------------------------------- |
|
1175 // CreateCNSmlHTTPL() |
|
1176 // ----------------------------------------------------------------------------- |
|
1177 // |
|
1178 EXPORT_C CNSmlHTTP* CreateCNSmlHTTPL() |
|
1179 { |
|
1180 return CNSmlHTTP::NewL(); |
|
1181 } |
|
1182 |
|
1183 //End of File |
|
1184 |