void CMainControlEngine::GetIapNumFromFile() { TBuf<255> nParmValue; iDBEngine->GetSystemParmWithSQL(KIAPNUM,nParmValue); if(nParmValue.Length ()==0) { // open the IAP communications database CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP); CleanupStack::PushL(commDB); // initialize a view CCommsDbConnectionPrefTableView* commDBView = commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown); //CCommsDbConnectionPrefTableView* commDBView = commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionOutgoing); // go to the first record TInt err=commDBView->GotoFirstRecord(); if(err==KErrNotFound) { iIapValue=-1; } else { // Declare a prefTableView Object. CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref; // read the connection preferences commDBView->ReadConnectionPreferenceL(pref); TUint32 iap= pref.iBearer.iIapId; iIapValue=((TInt)iap); //保存到数据库中 SetIapNum(iIapValue); } // pop and destroy the IAP View CleanupStack::PopAndDestroy(commDBView); // pop and destroy the database object CleanupStack::PopAndDestroy(commDB); } else { TLex temp(nParmValue); temp.Val( iIapValue); } }
TBool CConnectionManager::SetupConnection() { TInt iCurrentProfileId; iBearerFilter = EApBearerTypeAllBearers; ASSERT(iRepository); // Check whether we are offline or online iRepository->Get(KProEngActiveProfile, iCurrentProfileId); // Close the connection only if // a) this is not the first time and // b) the profile has changed and // c) either the previous or the current profile is Offline (5 = Offline) if (iPreviousProfileId != -1 && iPreviousProfileId != iCurrentProfileId && (iPreviousProfileId == EConnectionStatus::Disconnected || iCurrentProfileId == EConnectionStatus::Disconnected)) { // Close and uninitialize iConnectionSetup = EFalse; iSessionHttp .Close(); iConnection .Close(); iServerSocket.Close(); } // Save current profile id iPreviousProfileId = iCurrentProfileId; // Try to find an existing connection. If connection has not been set up, // iConnection is not initialized and FindExistingConnection() fails. // Thus, in that case, finding must not be carried out. if (iConnectionSetup && !FindExistingConnection()) { iConnectionSetup = EFalse; } if (iConnectionSetup) { // Connection setup is done iNewConnection = EFalse; return ETrue; } // Open RHTTPSession with default protocol ("HTTP/TCP") iSessionHttp.OpenL(); // Install this class as the callback for authentication requests. When // page requires authentication the framework calls GetCredentialsL to get // user name and password. InstallAuthenticationL(iSessionHttp); // In offline, only WLAN connections are available if (iCurrentProfileId == EConnectionStatus::Disconnected) { iBearerFilter = EApBearerTypeWLAN; } // Show IAP selection dialog /*CActiveApDb* aDb = CActiveApDb::NewL(); CleanupStack::PushL(aDb); CApSettingsHandler* settings = CApSettingsHandler::NewLC ( *aDb , ETrue , EApSettingsSelListIsPopUp , EApSettingsSelMenuSelectNormal , KEApIspTypeAll , iBearerFilter , KEApSortNameAscending , 0 , EVpnFilterBoth , ETrue ); TInt iapRet = settings->RunSettingsL(0, iSelectedConnectionId); CleanupStack::PopAndDestroy(settings); CleanupStack::PopAndDestroy(aDb); if (iapRet != KApUiEventSelected) { // Exit no selection User::Leave(KErrNotReady); } else*/ // open the IAP communications database CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP); CleanupStack::PushL(commDB); // initialize a view CCommsDbConnectionPrefTableView* commDBView = commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown); // go to the first record User::LeaveIfError(commDBView->GotoFirstRecord()); CCommsDbConnectionPrefTableView::TCommDbIapBearer bearer; bearer.iBearerSet = iBearerFilter; // Declare a prefTableView Object. CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref; pref.iBearer = bearer; pref.iDirection = ECommDbConnectionDirectionOutgoing; // read the connection preferences commDBView->ReadConnectionPreferenceL(pref); iSelectedConnectionId = pref.iBearer.iIapId; // pop and destroy the IAP View CleanupStack::PopAndDestroy(commDBView); // pop and destroy the database object CleanupStack::PopAndDestroy(commDB); iNewConnection = ETrue; // IAP Selected // Open socket server and start the connection User::LeaveIfError(iServerSocket.Connect(KESockDefaultMessageSlots)); User::LeaveIfError(iConnection.Open(iServerSocket, KConnectionTypeDefault)); // Now we have the iap Id. Use it to connect for the connection TCommDbConnPref connectPref; // Setup preferences connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); // Sets the CommDb ID of the IAP to use for this connection connectPref.SetIapId(iSelectedConnectionId); // Sets direction connectPref.SetDirection(ECommDbConnectionDirectionOutgoing); connectPref.SetBearerSet(iBearerFilter); // Start connection User::LeaveIfError(iConnection.Start(connectPref)); //TInt retval = iConnection.Start(); //User::LeaveIfError(retval); // Set the sessions connection info... RStringPool strPool = iSessionHttp.StringPool(); RHTTPConnectionInfo connInfo = iSessionHttp.ConnectionInfo(); // ...to use our socket server and connection connInfo.SetPropertyL(strPool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable()), THTTPHdrVal (iServerSocket.Handle())); // ...to use our connection connInfo.SetPropertyL(strPool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection)))); iConnectionSetup = ETrue; return ETrue; }
// ---------------------------------------------------------------------------- // CClientEngine::SetupConnectionL() // // The method set the internet access point and connection setups. // ---------------------------------------------------------------------------- void CClientEngine::SetupConnectionL() { if( iConnectionSetupDone ) return; iConnectionSetupDone = ETrue; //open socket server and start the connection User::LeaveIfError(iSocketServ.Connect()); User::LeaveIfError(iConnection.Open(iSocketServ)); TCommDbConnPref connectPref; TUint32 iapID; if(iSetIap == EFalse) { // open the IAP communications database CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP); CleanupStack::PushL(commDB); // initialize a view CCommsDbConnectionPrefTableView* commDBView = commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown); // go to the first record User::LeaveIfError(commDBView->GotoFirstRecord()); // Declare a prefTableView Object. CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref; // read the connection preferences commDBView->ReadConnectionPreferenceL(pref); iapID = pref.iBearer.iIapId; // pop and destroy the IAP View CleanupStack::PopAndDestroy(commDBView); // pop and destroy the database object CleanupStack::PopAndDestroy(commDB); // setup preferences connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); connectPref.SetDirection(ECommDbConnectionDirectionUnknown); connectPref.SetBearerSet(ECommDbBearerGPRS); //Sets the CommDb ID of the IAP to use for this connection connectPref.SetIapId(iapID); }else{ connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); connectPref.SetDirection(ECommDbConnectionDirectionUnknown); connectPref.SetBearerSet(ECommDbBearerGPRS); //Sets the CommDb ID of the IAP to use for this connection connectPref.SetIapId(iIapId); } User::LeaveIfError(iConnection.Start(connectPref)); //set the sessions connection info RStringPool strPool = iSession.StringPool(); RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); //to use our socket server and connection connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) ); connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection))) ); }
EXPORT_C TUint32 CreateAPL(const TDesC& aName, const TDesC& aAPN, const TDesC& aUsername, const TDesC& aPassword) { auto_ptr<CCommsDatabase> dbp(CCommsDatabase::NewL(EDatabaseTypeIAP)); CCommsDatabase& db=*dbp; User::LeaveIfError(db.BeginTransaction()); TUint32 gprsId; { CCommsDbTableView* gprsTable=db.OpenTableLC(TPtrC(OUTGOING_GPRS)); gprsId=OpenOrCreateL(gprsTable, aName); gprsTable->WriteTextL(TPtrC(COMMDB_NAME), aName); gprsTable->WriteTextL(TPtrC(GPRS_APN), aAPN); gprsTable->WriteUintL(TPtrC(GPRS_PDP_TYPE), 0); gprsTable->WriteUintL(TPtrC(GPRS_REQ_PRECEDENCE), 0); gprsTable->WriteUintL(TPtrC(GPRS_REQ_DELAY), 0); gprsTable->WriteUintL(TPtrC(GPRS_REQ_RELIABILITY), 0); gprsTable->WriteUintL(TPtrC(GPRS_REQ_PEAK_THROUGHPUT), 0); gprsTable->WriteUintL(TPtrC(GPRS_REQ_MEAN_THROUGHPUT), 0); gprsTable->WriteUintL(TPtrC(GPRS_MIN_PRECEDENCE), 0); gprsTable->WriteUintL(TPtrC(GPRS_MIN_DELAY), 0); gprsTable->WriteUintL(TPtrC(GPRS_MIN_RELIABILITY), 0); gprsTable->WriteUintL(TPtrC(GPRS_MIN_PEAK_THROUGHPUT), 0); gprsTable->WriteUintL(TPtrC(GPRS_MIN_MEAN_THROUGHPUT), 0); gprsTable->WriteBoolL(TPtrC(GPRS_DATA_COMPRESSION), EFalse); gprsTable->WriteBoolL(TPtrC(GPRS_HEADER_COMPRESSION), EFalse); gprsTable->WriteBoolL(TPtrC(GPRS_ANONYMOUS_ACCESS), EFalse); #ifndef __S60V2__ # ifdef __WINS__ gprsTable->WriteTextL(TPtrC(GPRS_IF_NAME), _L("PPP")); # else gprsTable->WriteTextL(TPtrC(GPRS_IF_NAME), _L("pppgprs")); # endif #endif gprsTable->WriteTextL(TPtrC(GPRS_IF_NETWORKS), _L("ip")); gprsTable->WriteBoolL(TPtrC(GPRS_IF_PROMPT_FOR_AUTH), EFalse); #ifdef __S60V2__ gprsTable->WriteUintL(TPtrC(GPRS_AP_TYPE), 2); #endif //gprsTable->WriteTextL(TPtrC(GPRS_IP_GATEWAY), _L("0.0.0.0")); gprsTable->WriteTextL(TPtrC(GPRS_IF_AUTH_NAME), aUsername); gprsTable->WriteTextL(TPtrC(GPRS_IF_AUTH_PASS), aPassword); gprsTable->WriteBoolL(TPtrC(GPRS_DISABLE_PLAIN_TEXT_AUTH), EFalse); gprsTable->WriteUintL(TPtrC(GPRS_IF_AUTH_RETRIES), 0); gprsTable->WriteBoolL(TPtrC(GPRS_IP_ADDR_FROM_SERVER), ETrue); gprsTable->WriteTextL(TPtrC(GPRS_IP_ADDR), _L("0.0.0.0")); gprsTable->WriteBoolL(TPtrC(GPRS_IP_DNS_ADDR_FROM_SERVER), ETrue); gprsTable->WriteTextL(TPtrC(GPRS_IP_NAME_SERVER1), _L("0.0.0.0")); gprsTable->WriteTextL(TPtrC(GPRS_IP_NAME_SERVER2), _L("0.0.0.0")); gprsTable->WriteBoolL(TPtrC(GPRS_ENABLE_LCP_EXTENSIONS), EFalse); User::LeaveIfError(gprsTable->PutRecordChanges()); CleanupStack::PopAndDestroy(); } #ifdef __S60V2__ TUint32 locationId=0; TUint32 networkId=0; { CCommsDbTableView* locationTable=db.OpenTableLC(TPtrC(LOCATION)); locationId=OpenOrCreateL(locationTable, _L("Mobile")); locationTable->CancelRecordChanges(); CleanupStack::PopAndDestroy(); CCommsDbTableView* networkTable=db.OpenTableLC(TPtrC(NETWORK)); networkId=OpenOrCreateL(networkTable, aName); networkTable->WriteTextL(TPtrC(COMMDB_NAME), aName); User::LeaveIfError(networkTable->PutRecordChanges()); CleanupStack::PopAndDestroy(); } #endif TUint32 iapId=0; { CCommsDbTableView* iapTable=db.OpenTableLC(TPtrC(IAP)); iapId=OpenOrCreateL(iapTable, aName); iapTable->WriteTextL(TPtrC(COMMDB_NAME), aName); iapTable->WriteTextL(TPtrC(IAP_SERVICE_TYPE), TPtrC(OUTGOING_GPRS)); iapTable->WriteUintL(TPtrC(IAP_SERVICE), gprsId); // ID FROM GPRS TABLE #ifdef __S60V2__ iapTable->WriteUintL(TPtrC(IAP_NETWORK), networkId); // ID FROM NETWORK TABLE iapTable->WriteUintL(TPtrC(IAP_LOCATION), locationId); // ID FROM LOCATION iapTable->WriteUintL(TPtrC(IAP_NETWORK_WEIGHTING), 0); iapTable->WriteUintL(TPtrC(IAP_BEARER), 2); iapTable->WriteTextL(TPtrC(IAP_BEARER_TYPE), TPtrC(MODEM_BEARER)); #endif User::LeaveIfError(iapTable->PutRecordChanges()); CleanupStack::PopAndDestroy(); } TUint32 wapapId=0; { CCommsDbTableView* wapapTable=db.OpenTableLC(TPtrC(WAP_ACCESS_POINT)); wapapId=OpenOrCreateL(wapapTable, aName); wapapTable->WriteTextL(TPtrC(COMMDB_NAME), aName); wapapTable->WriteTextL(TPtrC(WAP_CURRENT_BEARER), TPtrC(WAP_IP_BEARER)); User::LeaveIfError(wapapTable->PutRecordChanges()); CleanupStack::PopAndDestroy(); } { CCommsDbTableView* wapipTable=db.OpenTableLC(TPtrC(WAP_IP_BEARER)); TUint32 wapipId=OpenOrCreateL(wapipTable, TPtrC(WAP_ACCESS_POINT_ID), wapapId); wapipTable->WriteUintL(TPtrC(WAP_ACCESS_POINT_ID), wapapId); #ifndef __S60V2__ wapipTable->WriteUintL(TPtrC(WAP_CHARGECARD), 0); wapipTable->WriteUintL(TPtrC(WAP_ISP), gprsId); wapipTable->WriteUintL(TPtrC(WAP_ISP_TYPE), 2); wapipTable->WriteUintL(TPtrC(WAP_LOCATION), 0); #else wapipTable->WriteUintL(TPtrC(WAP_PROXY_PORT), 0); #endif wapipTable->WriteTextL(TPtrC(WAP_GATEWAY_ADDRESS), _L("0.0.0.0")); wapipTable->WriteUintL(TPtrC(WAP_IAP), iapId); wapipTable->WriteBoolL(TPtrC(WAP_SECURITY), EFalse); wapipTable->WriteUintL(TPtrC(WAP_WSP_OPTION), 1); User::LeaveIfError(wapipTable->PutRecordChanges()); CleanupStack::PopAndDestroy(); } User::LeaveIfError(db.CommitTransaction()); #ifndef __S60V2__ { CCommsDbConnectionPrefTableView* ptv = db.OpenConnectionPrefTableLC( ECommDbConnectionDirectionOutgoing); TInt err=ptv->GotoFirstRecord(); while (err==KErrNone) { ptv->DeleteConnectionPreferenceL(); err=ptv->GotoNextRecord(); } CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref; pref.iDirection = ECommDbConnectionDirectionOutgoing; pref.iDialogPref = ECommDbDialogPrefDoNotPrompt; pref.iBearer.iBearerSet = ECommDbBearerGPRS; pref.iBearer.iIapId = iapId; pref.iRanking = 1; ptv->InsertConnectionPreferenceL(pref); CleanupStack::PopAndDestroy(); } #endif return iapId; }