00001 /* 00002 * Copyright (c) 2009 Nokia Corporation. 00003 */ 00004 00005 #include <avkon.hrh> 00006 #include <aknnotewrappers.h> 00007 #include <aknlists.h> // CAknSinglePopupMenuStyleListBox 00008 #include <uri8.h> 00009 #include <http.h> 00010 #include <stringloader.h> 00011 #include <chttpformencoder.h> 00012 #include <HttpStringConstants.h> 00013 #include <http\RHTTPTransaction.h> 00014 #include <http\RHTTPSession.h> 00015 #include <http\RHTTPHeaders.h> 00016 #include <HTTPClientExample.rsg> 00017 #include <CommDbConnPref.h> 00018 00019 #include "Client.pan" 00020 #include "Client.hrh" 00021 #include "ClientEngine.h" 00022 00023 // Used user agent for requests 00024 _LIT8(KUserAgent, "SimpleClient 1.0"); 00025 00026 // This client accepts all content types. 00027 // (change to e.g. "text/plain" for plain text only) 00028 _LIT8(KAccept, "*/*"); 00029 00030 _LIT(KTextPreferredCarrierAvailable,"Preferred carrier available"); 00031 _LIT(KTextNewCarrierActive, "New carrier active"); 00032 00033 const TInt KStatustextBufferSize = 32; 00034 const TInt KInfotextBufferSize = 64; 00035 const TInt KURIBufferSize = 128; 00036 00037 // ---------------------------------------------------------------------------- 00038 // CClientEngine::NewL() 00039 // ---------------------------------------------------------------------------- 00040 CClientEngine* CClientEngine::NewL(MClientObserver& aObserver) 00041 { 00042 CClientEngine* self = CClientEngine::NewLC(aObserver); 00043 CleanupStack::Pop(self); 00044 return self; 00045 } 00046 00047 00048 // ---------------------------------------------------------------------------- 00049 // CClientEngine::NewLC() 00050 // ---------------------------------------------------------------------------- 00051 CClientEngine* CClientEngine::NewLC(MClientObserver& aObserver) 00052 { 00053 CClientEngine* self = new (ELeave) CClientEngine(aObserver); 00054 CleanupStack::PushL(self); 00055 self->ConstructL(); 00056 return self; 00057 } 00058 00059 00060 // ---------------------------------------------------------------------------- 00061 // CClientEngine::CClientEngine() 00062 // ---------------------------------------------------------------------------- 00063 CClientEngine::CClientEngine(MClientObserver& aObserver) 00064 : CActive(CActive::EPriorityStandard), 00065 iObserver(aObserver), 00066 iPostData(NULL), 00067 iConnectionSetupDone(EFalse), 00068 iPrevProfileId(-1), 00069 iTransactionOpen(EFalse) 00070 { 00071 } 00072 00073 00074 // ---------------------------------------------------------------------------- 00075 // CClientEngine::~CClientEngine() 00076 // ---------------------------------------------------------------------------- 00077 CClientEngine::~CClientEngine() 00078 { 00079 Cancel(); 00080 00081 if (iTransactionOpen) 00082 { 00083 iTransaction.Close(); 00084 iTransactionOpen = EFalse; 00085 } 00086 00087 if (iMobility) 00088 { 00089 iMobility->Cancel(); 00090 } 00091 delete iMobility; 00092 00093 iSession.Close(); 00094 iConnection.Close(); 00095 iSocketServ.Close(); 00096 00097 delete iPostData; 00098 00099 delete iUri; 00100 delete iContentType; 00101 delete iBody; 00102 } 00103 00104 00105 // ---------------------------------------------------------------------------- 00106 // CClientEngine::ConstructL() 00107 // ---------------------------------------------------------------------------- 00108 void CClientEngine::ConstructL() 00109 { 00110 CActiveScheduler::Add(this); 00111 } 00112 00113 00114 // ---------------------------------------------------------------------------- 00115 // CClientEngine::SetupConnectionL() 00116 // ---------------------------------------------------------------------------- 00117 void CClientEngine::SetupConnectionL() 00118 { 00119 if (iConnectionSetupDone) 00120 { 00121 // Connection setup is done 00122 User::Leave(KErrAlreadyExists); 00123 } 00124 if (IsActive()) 00125 { 00126 User::Leave(KErrInUse); 00127 } 00128 00129 // Open HTTP Session 00130 iSession.OpenL(); 00131 00132 // Install this class as the callback for authentication requests. When 00133 // page requires authentication the framework calls GetCredentialsL to get 00134 // user name and password. 00135 InstallAuthenticationL(iSession); 00136 00137 // Open CCmApplicationSettingsUi 00138 TCmSettingSelection userSelection; 00139 CCmApplicationSettingsUi* settings = CCmApplicationSettingsUi::NewL(); 00140 CleanupStack::PushL(settings); 00141 TUint listedItems = CMManager::EShowAlwaysAsk | 00142 CMManager::EShowDefaultConnection | 00143 CMManager::EShowDestinations | 00144 CMManager::EShowConnectionMethods; 00145 TBearerFilterArray filter; 00146 TBool selected = settings->RunApplicationSettingsL(userSelection,listedItems,filter); 00147 CleanupStack::PopAndDestroy(settings); 00148 00149 // Check selection 00150 if (selected) { 00151 switch (userSelection.iResult) 00152 { 00153 case CMManager::EDestination: 00154 { 00155 TConnSnapPref prefs; 00156 prefs.SetSnap(userSelection.iId); 00157 00158 User::LeaveIfError(iSocketServ.Connect()); 00159 User::LeaveIfError(iConnection.Open(iSocketServ)); 00160 iConnection.Start(prefs, iStatus); 00161 break; 00162 } 00163 case CMManager::EConnectionMethod: 00164 { 00165 TCommDbConnPref prefs; 00166 prefs.SetIapId(userSelection.iId); 00167 prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); 00168 00169 User::LeaveIfError(iSocketServ.Connect()); 00170 User::LeaveIfError(iConnection.Open(iSocketServ)); 00171 iConnection.Start(prefs, iStatus); 00172 break; 00173 } 00174 case CMManager::EDefaultConnection: 00175 { 00176 User::LeaveIfError(iSocketServ.Connect()); 00177 User::LeaveIfError(iConnection.Open(iSocketServ)); 00178 iConnection.Start(iStatus); 00179 break; 00180 } 00181 default: // EAlwaysAsk 00182 { 00183 TCommDbConnPref prefs; 00184 prefs.SetDialogPreference(ECommDbDialogPrefPrompt); 00185 00186 User::LeaveIfError(iSocketServ.Connect()); 00187 User::LeaveIfError(iConnection.Open(iSocketServ)); 00188 iConnection.Start(prefs, iStatus); 00189 } 00190 } 00191 00192 SetActive(); 00193 } 00194 } 00195 00196 // ---------------------------------------------------------------------------- 00197 // CClientEngine::FindExistingConnection() 00198 // ---------------------------------------------------------------------------- 00199 TBool CClientEngine::FindExistingConnection() 00200 { 00201 // NOTE: this method is not in use 00202 00203 // Enumerates through existing connections and tries to find one that matches 00204 // the selected IAP. If one is found, ETrue is returned; otherwise, EFalse. 00205 TBool connected = EFalse; 00206 TConnectionInfoBuf connInfo; 00207 TUint count; 00208 if (iConnection.EnumerateConnections(count) == KErrNone) 00209 { 00210 for (TUint i=1; i<=count; i++) 00211 { 00212 // Note: GetConnectionInfo expects 1-based index. 00213 if (iConnection.GetConnectionInfo(i, connInfo) == KErrNone) 00214 { 00215 if (connInfo().iIapId == iSelectedIap) 00216 { 00217 connected = ETrue; 00218 break; 00219 } 00220 } 00221 } 00222 } 00223 return connected; 00224 } 00225 00226 // ---------------------------------------------------------------------------- 00227 // CClientEngine::SetHeaderL() 00228 // ---------------------------------------------------------------------------- 00229 void CClientEngine::SetHeaderL(RHTTPHeaders aHeaders, 00230 TInt aHdrField, 00231 const TDesC8& aHdrValue) 00232 { 00233 RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue); 00234 CleanupClosePushL(valStr); 00235 THTTPHdrVal val(valStr); 00236 aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField, 00237 RHTTPSession::GetTable()), val); 00238 CleanupStack::PopAndDestroy(); // valStr 00239 } 00240 00241 00242 // ---------------------------------------------------------------------------- 00243 // CClientEngine::IssueHTTPGetL() 00244 // ---------------------------------------------------------------------------- 00245 void CClientEngine::IssueHTTPGetL(const TDesC8& aUri) 00246 { 00247 if (IsActive()) 00248 { 00249 return; 00250 } 00251 00252 iEngineState = EGet; 00253 00254 delete iUri; iUri = NULL; 00255 delete iContentType; iContentType = NULL; 00256 delete iBody; iBody = NULL; 00257 00258 iUri = aUri.AllocL(); 00259 00260 // Create HTTP connection 00261 TRAPD(err, SetupConnectionL()); 00262 if (err == KErrAlreadyExists) 00263 { 00264 DoHTTPGetL(); 00265 } 00266 else if (err != KErrNone) 00267 { 00268 HBufC* resTxCancelled = StringLoader::LoadLC(R_HTTP_TX_CANCELLED); 00269 iObserver.ClientEvent(*resTxCancelled); 00270 CleanupStack::PopAndDestroy(resTxCancelled); 00271 return; 00272 } 00273 } 00274 00275 00276 // ---------------------------------------------------------------------------- 00277 // CClientEngine::DoHTTPGetL() 00278 // ---------------------------------------------------------------------------- 00279 void CClientEngine::DoHTTPGetL() 00280 { 00281 // Parse string to URI (as defined in RFC2396) 00282 TUriParser8 uri; 00283 uri.Parse(*iUri); 00284 00285 // Get request method string for HTTP GET 00286 RStringF method = iSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable()); 00287 00288 // Open transaction with previous method and parsed uri. This class will 00289 // receive transaction events in MHFRunL and MHFRunError. 00290 iTransaction = iSession.OpenTransactionL(uri, *this, method); 00291 iTransactionOpen = ETrue; 00292 00293 // Set headers for request; user agent and accepted content type 00294 RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection(); 00295 SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent); 00296 SetHeaderL(hdr, HTTP::EAccept, KAccept); 00297 00298 // Submit the transaction. After this the framework will give transaction 00299 // events via MHFRunL and MHFRunError. 00300 iTransaction.SubmitL(); 00301 00302 HBufC* resConnecting = StringLoader::LoadLC(R_HTTP_CONNECTING); 00303 iObserver.ClientEvent(*resConnecting); 00304 CleanupStack::PopAndDestroy(resConnecting); 00305 } 00306 00307 00308 // ---------------------------------------------------------------------------- 00309 // CClientEngine::IssueHTTPPostL() 00310 // ---------------------------------------------------------------------------- 00311 void CClientEngine::IssueHTTPPostL(const TDesC8& aUri, 00312 const TDesC8& aContentType, 00313 const TDesC8& aBody) 00314 { 00315 if (IsActive()) 00316 { 00317 return; 00318 } 00319 00320 iEngineState = EPost; 00321 00322 delete iUri; iUri = NULL; 00323 delete iContentType; iContentType = NULL; 00324 delete iBody; iBody = NULL; 00325 00326 iUri = aUri.AllocL(); 00327 iContentType = aContentType.AllocL(); 00328 iBody = aBody.AllocL(); 00329 00330 // Create HTTP connection 00331 TRAPD(err, SetupConnectionL()); 00332 if (err == KErrAlreadyExists) 00333 { 00334 DoHTTPPostL(); 00335 } 00336 else if (err != KErrNone) 00337 { 00338 HBufC* resTxCancelled = StringLoader::LoadLC(R_HTTP_TX_CANCELLED); 00339 iObserver.ClientEvent(*resTxCancelled); 00340 CleanupStack::PopAndDestroy(resTxCancelled); 00341 return; 00342 } 00343 } 00344 00345 // ---------------------------------------------------------------------------- 00346 // CClientEngine::DoHTTPPostL() 00347 // ---------------------------------------------------------------------------- 00348 void CClientEngine::DoHTTPPostL() 00349 { 00350 // Parse string to URI 00351 TUriParser8 uri; 00352 uri.Parse(*iUri); 00353 00354 // Copy data to be posted into member variable; iPostData is used later in 00355 // methods inherited from MHTTPDataSupplier. 00356 delete iPostData; 00357 iPostData = 0; 00358 iPostData = iBody->AllocL(); 00359 00360 // Get request method string for HTTP POST 00361 RStringF method = iSession.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable()); 00362 00363 // Open transaction with previous method and parsed uri. This class will 00364 // receive transaction events in MHFRunL and MHFRunError. 00365 iTransaction = iSession.OpenTransactionL(uri, *this, method); 00366 iTransactionOpen = ETrue; 00367 00368 // Set headers for request; user agent, accepted content type and body's 00369 // content type. 00370 RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection(); 00371 SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent); 00372 SetHeaderL(hdr, HTTP::EAccept, KAccept); 00373 SetHeaderL(hdr, HTTP::EContentType, *iContentType); 00374 00375 // Set this class as an data supplier. Inherited MHTTPDataSupplier methods 00376 // are called when framework needs to send body data. 00377 MHTTPDataSupplier* dataSupplier = this; 00378 iTransaction.Request().SetBody(*dataSupplier); 00379 00380 // Submit the transaction. After this the framework will give transaction 00381 // events via MHFRunL and MHFRunError. 00382 iTransaction.SubmitL(); 00383 00384 HBufC* resConnecting = StringLoader::LoadLC(R_HTTP_CONNECTING); 00385 iObserver.ClientEvent(*resConnecting); 00386 CleanupStack::PopAndDestroy(resConnecting); 00387 } 00388 00389 // ---------------------------------------------------------------------------- 00390 // CClientEngine::CancelTransaction() 00391 // ---------------------------------------------------------------------------- 00392 void CClientEngine::CancelTransaction() 00393 { 00394 iEngineState = EIdle; 00395 delete iUri; iUri = NULL; 00396 delete iContentType; iContentType = NULL; 00397 delete iBody; iBody = NULL; 00398 00399 // Close() also cancels transaction (Cancel() can also be used but 00400 // resources allocated by transaction must be still freed with Close()) 00401 if (iTransactionOpen) 00402 { 00403 iTransaction.Close(); 00404 iTransactionOpen = EFalse; 00405 00406 HBufC* resTxCancelled = StringLoader::LoadLC(R_HTTP_TX_CANCELLED); 00407 iObserver.ClientEvent(*resTxCancelled); 00408 CleanupStack::PopAndDestroy(resTxCancelled); 00409 } 00410 } 00411 00412 00413 // ---------------------------------------------------------------------------- 00414 // CClientEngine::MHFRunL() 00415 // ---------------------------------------------------------------------------- 00416 void CClientEngine::MHFRunL(RHTTPTransaction aTransaction, 00417 const THTTPEvent& aEvent) 00418 { 00419 switch (aEvent.iStatus) 00420 { 00421 case THTTPEvent::EGotResponseHeaders: 00422 { 00423 // HTTP response headers have been received. Use 00424 // aTransaction.Response() to get the response. However, it's not 00425 // necessary to do anything with the response when this event occurs. 00426 00427 // Get HTTP status code from header (e.g. 200) 00428 RHTTPResponse resp = aTransaction.Response(); 00429 TInt status = resp.StatusCode(); 00430 00431 // Get status text (e.g. "OK") 00432 TBuf<KStatustextBufferSize> statusText; 00433 statusText.Copy(resp.StatusText().DesC()); 00434 00435 HBufC* resHeaderReceived = StringLoader::LoadLC(R_HTTP_HEADER_RECEIVED, statusText, status); 00436 iObserver.ClientEvent(*resHeaderReceived); 00437 CleanupStack::PopAndDestroy(resHeaderReceived); 00438 break; 00439 } 00440 00441 case THTTPEvent::EGotResponseBodyData: 00442 { 00443 // Part (or all) of response's body data received. Use 00444 // aTransaction.Response().Body()->GetNextDataPart() to get the actual 00445 // body data. 00446 00447 // Get the body data supplier 00448 MHTTPDataSupplier* body = aTransaction.Response().Body(); 00449 TPtrC8 dataChunk; 00450 00451 // GetNextDataPart() returns ETrue, if the received part is the last 00452 // one. 00453 TBool isLast = body->GetNextDataPart(dataChunk); 00454 iObserver.ClientBodyReceived(dataChunk); 00455 00456 HBufC* resBytesReceived = StringLoader::LoadLC(R_HTTP_BYTES_RECEIVED, dataChunk.Length()); 00457 iObserver.ClientEvent(*resBytesReceived); 00458 CleanupStack::PopAndDestroy(resBytesReceived); 00459 00460 // NOTE: isLast may not be ETrue even if last data part received. 00461 // (e.g. multipart response without content length field) 00462 // Use EResponseComplete to reliably determine when body is completely 00463 // received. 00464 if (isLast) 00465 { 00466 HBufC* resBodyReceived = StringLoader::LoadLC(R_HTTP_BODY_RECEIVED); 00467 iObserver.ClientEvent(*resBodyReceived); 00468 CleanupStack::PopAndDestroy(resBodyReceived); 00469 } 00470 00471 // Always remember to release the body data. 00472 body->ReleaseData(); 00473 break; 00474 } 00475 00476 case THTTPEvent::EResponseComplete: 00477 { 00478 // Indicates that header & body of response is completely received. 00479 // No further action here needed. 00480 HBufC* resTxComplete = StringLoader::LoadLC(R_HTTP_TX_COMPLETE); 00481 iObserver.ClientEvent(*resTxComplete); 00482 CleanupStack::PopAndDestroy(resTxComplete); 00483 break; 00484 } 00485 00486 case THTTPEvent::ESucceeded: 00487 { 00488 // Indicates that transaction succeeded. 00489 HBufC* resTxSuccessful = StringLoader::LoadLC(R_HTTP_TX_SUCCESSFUL); 00490 iObserver.ClientEvent(*resTxSuccessful); 00491 CleanupStack::PopAndDestroy(resTxSuccessful); 00492 00493 // Transaction can be closed now. It's not needed anymore. 00494 aTransaction.Close(); 00495 iTransactionOpen = EFalse; 00496 break; 00497 } 00498 00499 case THTTPEvent::EFailed: 00500 { 00501 // Transaction completed with failure. 00502 HBufC* resTxFailed = StringLoader::LoadLC(R_HTTP_TX_FAILED); 00503 iObserver.ClientEvent(*resTxFailed); 00504 CleanupStack::PopAndDestroy(resTxFailed); 00505 aTransaction.Close(); 00506 iTransactionOpen = EFalse; 00507 break; 00508 } 00509 00510 default: 00511 // There are more events in THTTPEvent, but they are not usually 00512 // needed. However, event status smaller than zero should be handled 00513 // correctly since it's error. 00514 { 00515 if (aEvent.iStatus < 0) 00516 { 00517 HBufC* resNoInternetConnection = StringLoader::LoadLC( 00518 R_HTTP_NO_INTERNET_CONNECTION, aEvent.iStatus); 00519 iObserver.ClientEvent(*resNoInternetConnection); 00520 CleanupStack::PopAndDestroy(resNoInternetConnection); 00521 00522 // Close the transaction on errors 00523 aTransaction.Close(); 00524 iTransactionOpen = EFalse; 00525 } 00526 break; 00527 } 00528 } 00529 } 00530 00531 00532 // ---------------------------------------------------------------------------- 00533 // CClientEngine::IsRunning() 00534 // ---------------------------------------------------------------------------- 00535 TBool CClientEngine::IsRunning() 00536 { 00537 if (IsActive()) 00538 return ETrue; 00539 else 00540 return EFalse; 00541 } 00542 00543 // ---------------------------------------------------------------------------- 00544 // CClientEngine::MHFRunError() 00545 // ---------------------------------------------------------------------------- 00546 TInt CClientEngine::MHFRunError(TInt aError, 00547 RHTTPTransaction /*aTransaction*/, 00548 const THTTPEvent& /*aEvent*/) 00549 { 00550 // Just notify about the error and return KErrNone. 00551 HBufC* resMHFRunError = StringLoader::LoadLC(R_HTTP_MHFRUN_ERROR, aError); 00552 iObserver.ClientEvent(*resMHFRunError); 00553 CleanupStack::PopAndDestroy(resMHFRunError); 00554 return KErrNone; 00555 } 00556 00557 00558 // ---------------------------------------------------------------------------- 00559 // CClientEngine::GetNextDataPart() 00560 // ---------------------------------------------------------------------------- 00561 TBool CClientEngine::GetNextDataPart(TPtrC8& aDataPart) 00562 { 00563 if(iPostData) 00564 { 00565 // Provide pointer to next chunk of data (return ETrue, if last chunk) 00566 // Usually only one chunk is needed, but sending big file could require 00567 // loading the file in small parts. 00568 aDataPart.Set(iPostData->Des()); 00569 } 00570 return ETrue; 00571 } 00572 00573 00574 // ---------------------------------------------------------------------------- 00575 // CClientEngine::ReleaseData() 00576 // ---------------------------------------------------------------------------- 00577 void CClientEngine::ReleaseData() 00578 { 00579 // It's safe to delete iPostData now. 00580 delete iPostData; 00581 iPostData = NULL; 00582 } 00583 00584 // ---------------------------------------------------------------------------- 00585 // CClientEngine::Reset() 00586 // ---------------------------------------------------------------------------- 00587 TInt CClientEngine::Reset() 00588 { 00589 // Nothing needed since iPostData still exists and contains all the data. 00590 // (If a file is used and read in small parts we should seek to beginning 00591 // of file and provide the first chunk again in GetNextDataPart() ) 00592 return KErrNone; 00593 } 00594 00595 00596 // ---------------------------------------------------------------------------- 00597 // CClientEngine::OverallDataSize() 00598 // ---------------------------------------------------------------------------- 00599 TInt CClientEngine::OverallDataSize() 00600 { 00601 if(iPostData) 00602 return iPostData->Length(); 00603 else 00604 return KErrNotFound ; 00605 } 00606 00607 // ---------------------------------------------------------------------------- 00608 // CClientEngine::GetCredentialsL() 00609 // ---------------------------------------------------------------------------- 00610 TBool CClientEngine::GetCredentialsL(const TUriC8& aURI, 00611 RString aRealm, 00612 RStringF aAuthenticationType, 00613 RString& aUsername, 00614 RString& aPassword) 00615 { 00616 // aURI, aReal and aAuthenticationType are informational only. We only need 00617 // to set aUsername and aPassword and return ETrue, if aUsername and 00618 // aPassword are provided by user. 00619 00620 // Buffer for string parameters that may change order 00621 CDesCArrayFlat* strings = new CDesCArrayFlat(2); 00622 CleanupStack::PushL(strings); 00623 00624 // Initialize parameter buffer 00625 00626 // First parameter 00627 HBufC* uri16 = HBufC::NewLC(aURI.UriDes().Length()); 00628 uri16->Des().Copy(aURI.UriDes()); 00629 strings->AppendL(*uri16); 00630 CleanupStack::PopAndDestroy(uri16); 00631 00632 // Second parameter 00633 HBufC* authType16 = HBufC::NewLC(aAuthenticationType.DesC().Length()); 00634 authType16->Des().Copy(aAuthenticationType.DesC()); 00635 strings->AppendL(*authType16); 00636 CleanupStack::PopAndDestroy(authType16); 00637 00638 HBufC* resAuthNote = StringLoader::LoadLC(R_HTTP_AUTH_NOTE, *strings); 00639 HBufC* resAuthRequired = StringLoader::LoadLC(R_HTTP_AUTH_REQUIRED); 00640 CEikonEnv::Static()->InfoWinL(*resAuthRequired, *resAuthNote); 00641 00642 CleanupStack::PopAndDestroy(resAuthNote); 00643 CleanupStack::PopAndDestroy(resAuthRequired); 00644 00645 // Query user name and password 00646 TBuf<KDefaultBufferSize> userName; 00647 TBuf<KDefaultBufferSize> password; 00648 CAknMultiLineDataQueryDialog* dlg = 00649 CAknMultiLineDataQueryDialog::NewL(userName, password); 00650 00651 if (!dlg->ExecuteLD(R_DIALOG_USER_PASSWORD_QUERY)) 00652 return EFalse; // No credentials given; must return EFalse 00653 00654 // Set aUsername and aPassword 00655 TBuf8<KDefaultBufferSize> temp; 00656 temp.Copy(userName); 00657 TRAPD(err, aUsername = aRealm.Pool().OpenStringL(temp)); 00658 if (!err) 00659 { 00660 temp.Copy(password); 00661 TRAP(err, aPassword = aRealm.Pool().OpenStringL(temp)); 00662 if (!err) return ETrue; 00663 } 00664 00665 // Return ETrue if user has given credentials (username and password), 00666 // otherwise EFlase 00667 return EFalse; 00668 } 00669 00670 // ---------------------------------------------------------------------------- 00671 // CClientEngine::PreferredCarrierAvailable() 00672 // ---------------------------------------------------------------------------- 00673 void CClientEngine::PreferredCarrierAvailable(TAccessPointInfo /*aOldAPInfo*/, 00674 TAccessPointInfo /*aNewAPInfo*/, 00675 TBool /*aIsUpgrade*/, 00676 TBool aIsSeamless) 00677 { 00678 if (!aIsSeamless) 00679 { 00680 iMobility->MigrateToPreferredCarrier(); 00681 } 00682 } 00683 00684 // ---------------------------------------------------------------------------- 00685 // CClientEngine::NewCarrierActive() 00686 // ---------------------------------------------------------------------------- 00687 void CClientEngine::NewCarrierActive(TAccessPointInfo /*aNewAPInfo*/, 00688 TBool aIsSeamless) 00689 { 00690 if (!aIsSeamless) 00691 { 00692 iMobility->NewCarrierAccepted(); 00693 } 00694 } 00695 00696 // ---------------------------------------------------------------------------- 00697 // CClientEngine::Error() 00698 // ---------------------------------------------------------------------------- 00699 void CClientEngine::Error(TInt /*aError*/) 00700 { 00701 } 00702 00703 // ---------------------------------------------------------------------------- 00704 // CClientEngine::DoCancel() 00705 // ---------------------------------------------------------------------------- 00706 void CClientEngine::DoCancel() 00707 { 00708 iConnection.Stop(); 00709 } 00710 00711 // ---------------------------------------------------------------------------- 00712 // CClientEngine::RunL() 00713 // ---------------------------------------------------------------------------- 00714 void CClientEngine::RunL() 00715 { 00716 TInt statusCode = iStatus.Int(); 00717 00718 if (!iConnectionSetupDone && statusCode == KErrNone) 00719 { 00720 // Connection done ok 00721 iConnectionSetupDone = ETrue; 00722 // Register for mobility API 00723 iMobility = CActiveCommsMobilityApiExt::NewL(iConnection, *this); 00724 // Start selected HTTP action 00725 switch (iEngineState) 00726 { 00727 case EIdle: 00728 { 00729 CancelTransaction(); 00730 break; 00731 } 00732 case EGet: 00733 { 00734 DoHTTPGetL(); 00735 break; 00736 } 00737 case EPost: 00738 { 00739 DoHTTPPostL(); 00740 break; 00741 } 00742 }; 00743 } 00744 } 00745 00746 00747 // end of file
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.