void UT_CRtpComm::SetupL( ) { iTimer = CPeriodic::NewL( EPriorityNormal ); iErr=0; TCommDbConnPref prefs; prefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); prefs.SetDirection( ECommDbConnectionDirectionOutgoing ); prefs.SetIapId( KDefaultIap );//6 TInt err( KErrCouldNotConnect ); // Opens a session to the socket server // i.e. creates an IPC communication channel to the socket server if ( ( err = iSocketServ.Connect() ) != KErrNone ) { EUNIT_ASSERT( err==KErrNone ); } // Opens a new RConnection instance else if (( err = iConnection.Open( iSocketServ )) != KErrNone ) { iConnection.Close(); EUNIT_ASSERT( err==KErrNone ); } else if (( err = iConnection.Start( prefs )) != KErrNone ) { iConnection.Close(); EUNIT_ASSERT( err==KErrNone ); } }
void UT_MNATFWMediaWrapper::Setup2L() { iWaitScheduler = new(ELeave) CActiveSchedulerWait(); iMediaConnWrapper = CNATFWSocketMediaConnWrapper::NewL( KTcpPort, KProtocolInetTcp, KStreamId ); User::LeaveIfError( iSocketSrv.Connect() ); // Open an RConnection object. Note that you must provide an RSocketServ object User::LeaveIfError( iConn.Open( iSocketSrv ) ); TCommDbConnPref pref; pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); pref.SetIapId( /*6*/10 ); // Start an Outgoing Connection iConn.Start( pref, iStatus ); User::WaitForRequest( iStatus ); User::LeaveIfError( iStatus.Int() ); iMediaConnWrapper->RegisterMediaWrapperObserverL( this, iSocketSrv, iWrapperLocalAddr ); iSocketMediaConnWrapper = iMediaConnWrapper; iMediaWrapper = iMediaConnWrapper; iConn.Close(); }
TBool CAppMain::GetState(){ Log(_L8("CAppMain::GetState() begin")); TBool r=ETrue; if(iFirstConnect){ iSocketServ.Connect(); TCommDbConnPref prefs; //有些手机需要搜索接入点 prefs.SetIapId(iDefaultAccessPointID); if(0==iConnection.Open(iSocketServ)){ //提示用户选择接入点 Log(_L8("CAppMain::GetState(): Hint user to select the access point")); prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); TInt err=0; #ifndef _MANUALAPN_ Log(_L8("err=iConnection.Start(prefs);")); err=iConnection.Start(prefs); #else Log(_L8("err=iConnection.Start();")); err = iConnection.Start(); #endif if(0==err){ iFirstConnect=EFalse; return ETrue; } r=EFalse; } } Log(_L8("CAppMain::GetState() end")); return r; }
void UT_CNATFWUNSAFServerQuery::SetupL() { iResultArray = new (ELeave) RArray<TInetAddr>; User::LeaveIfError(iServer.Connect(KESockDefaultMessageSlots)); User::LeaveIfError(iConnection.Open(iServer, KConnectionTypeDefault)); TCommDbConnPref prefs; prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); prefs.SetDirection(ECommDbConnectionDirectionOutgoing); prefs.SetIapId(10); User::LeaveIfError(iConnection.Start(prefs)); iHostResolver = CNATFWUNSAFHostResolver::NewL(iServer, iConnection); iObserver = UT_CNATFWUNSAFServerResolverObserverStub::NewL(); CNATFWUNSAFQueryData* query = CNATFWUNSAFQueryData::NewL( iObserver, 5060, _L8("udp"), _L8("testi.net"), _L8("stun"), *iHostResolver, *iResultArray ); CleanupStack::PushL(query); iServerQuery = CNATFWUNSAFServerQuery::NewL( iObserver, query ); CleanupStack::Pop( query ); }
void UT_CNATFWUNSAFUdpSender::SetupL() { User::LeaveIfError( iServer.Connect( 8 ) ); User::LeaveIfError( iConn.Open( iServer, KConnectionTypeDefault ) ); TCommDbConnPref prefs; prefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); prefs.SetDirection( ECommDbConnectionDirectionOutgoing ); prefs.SetIapId(10); User::LeaveIfError( iConn.Start( prefs ) ); User::LeaveIfError( iSocket.Open( iServer, KAfInet, KSockDatagram, KProtocolInetUdp, iConn ) ); iMsg = NATFWUNSAFTransportTestUtils::CreateUNSAFBindingRequestL(); iAddr = TInetAddr( INET_ADDR( 127, 0, 0, 1 ) ); iSender = CNATFWUNSAFUdpSender::NewL( iSocket, *this ); iIsMsgSent = EFalse; }
/** * Function that opens and starts an RConnection. */ TInt CPanConnections::StartIAP() { TInt rerr = KErrNone; // Create a set of connection preferences to override existing // set in CommDb when RConnection::Start is called. TCommDbConnPref connPref; PanProfileIAPs iap(EGeneralIAP); connPref.SetIapId(iap); connPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); // load BT stack rerr = Initialise(); if(rerr == KErrNone) { // Open the connection rerr = iConnection.Open(iSockSvr); if(rerr == KErrNone) { // Start the connection // use the iStatus of active object, if it doesn't complete (we are listening) // then the active object deals with it, otherwise AO calls IapStarted function on this class // Something wrong with RConnection start iActiveMode = EIAPStart; iConnection.Start(connPref, iStatus); SetActive(); iIapLoading = ETrue; } } return rerr; }
TInt CResourceManager::SetIap(TUint32 aIapId, TBool aIsWap) { m_bUseOutNetSettting = false; m_socketServ.Connect(); m_connection.Open(m_socketServ); m_iapId = aIapId; m_isWap = aIsWap; TInt err = KErrNone; // Now we have the iap Id. Use it to connect for the connection. // Create a connection preference variable. TCommDbConnPref connectPref; // setup preferences connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); connectPref.SetDirection(ECommDbConnectionDirectionUnknown); connectPref.SetBearerSet(ECommDbBearerGPRS | ECommDbBearerWLAN | ECommDbBearerLAN); //Sets the CommDb ID of the IAP to use for this connection connectPref.SetIapId(aIapId); err = m_connection.Start(connectPref); if (err == KErrNone) { m_IAPSeted = true; m_IAPReady = true; ResendRequest(); } return err; }
void ut_cstunbinding::SetupL( ) { iCallbackCalled = EFalse; TUint iapID( 6 ); TInt retransmitInterval( 10 ); TBufC8<13> serveraddress( KServerAddress ); TUint serverport( 2000 ); TBufC8<4> protocol( KStun ); TBool obtainsharedsecret( EFalse ); TBool failifnoSRVrecordfound( EFalse ); iDeltatimer = CDeltaTimer::NewL( 1 ); User::LeaveIfError( iSocketServ.Connect() ); iStreamId = 1; iSubstreamId = 1; TBool icmpUsed( EFalse ); iMux = CNcmConnectionMultiplexer::NewL( *this ); TCommDbConnPref pref; pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); pref.SetIapId( iapID ); User::LeaveIfError( iConnection.Open( iSocketServ ) ); iConnection.Start( pref, iStatus ); User::WaitForRequest( iStatus ); User::LeaveIfError( iStatus.Int() ); iStunclient = CSTUNClient::NewL( retransmitInterval, serveraddress, serverport, protocol, iSocketServ, iConnection, *iDeltatimer, *this, obtainsharedsecret, failifnoSRVrecordfound, icmpUsed, iMux ); if ( ut_cstunbinding::iActiveSchedulerWait.IsStarted() ) { ut_cstunbinding::iActiveSchedulerWait.AsyncStop(); } ut_cstunbinding::iActiveSchedulerWait.Start(); if ( !iCallbackCalled ) { // Callback not called because of memory running out inside callback execution User::Leave( KErrNoMemory ); } User::LeaveIfError( iSocket.Open( iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp )); iBinding = CSTUNBinding::NewL( *iStunclient, iSocket ); }
int ILibSocketWrapper_socket(int socketType) { int RetVal; // create a new connection for the socket RConnection* pConnection = new RConnection; // open a connection pConnection->Open(socketServer); TCommDbConnPref prefs; // set the preference for the requested interface prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); pConnection->Start(prefs); if ( (socketType == SOCK_DGRAM) || (socketType == SOCK_STREAM) ) { RSocket *pSocket = new RSocket(); if ( socketType == SOCK_DGRAM ) { pSocket->Open(socketServer, KAfInet, KSockDatagram, KProtocolInetUdp, *pConnection); } else { pSocket->Open(socketServer, KAfInet, KSockStream, KProtocolInetTcp, *pConnection); } RetVal = ILibSocketWrapper_GetNextAvailableHandle(); if( RetVal >= 0 ) { SocketArray[RetVal] = (int)pSocket; ConnectionArray[RetVal] = pConnection; } else { pSocket->Close(); delete pSocket; pConnection->Close(); delete pConnection; RetVal = -1; } } return RetVal; }
// ----------------------------------------------------------------------------- // CApplicationTriggeringConnDlg::StartL // ----------------------------------------------------------------------------- // void CApplicationTriggeringConnDlg::StartL() { User::LeaveIfError( iConnection.Open( iSocketServer ) ); TCommDbConnPref prefs; prefs.SetDialogPreference( ECommDbDialogPrefPrompt ); PrintL( R_OUTPUT_PROMPT_CONNECTION_DIALOG ); iConnection.Start( prefs, iStatus ); SetActive(); }
// ----------------------------------------------------------------------------- // CSIPExSocketEngine::StartInterfaceL // Activates PDP ctx // ----------------------------------------------------------------------------- // void CSIPExSocketEngine::StartInterfaceL( const TUint32 aIapId ) { if( !iConnection.SubSessionHandle() ) { User::LeaveIfError( iConnection.Open( iSocketServer ) ); } TCommDbConnPref prefs; prefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); prefs.SetDirection( ECommDbConnectionDirectionOutgoing ); prefs.SetIapId( aIapId ); User::LeaveIfError( iConnection.Start( prefs ) ); }
/* * Open an Explicit UDP Socket */ void CMultipleArray::OpenExplicitUdpSocketL(TInt aExtraSocksToJoin, RSocketServ iSocketServer) { /* Get number of sockets from script * Open a UDP socket * Store socket handle * Return the EFail or EPass */ RSocket* sock; RConnection* conn; TCommDbConnPref prefs; TInt err = 0; sock = new (ELeave) RSocket; conn = new (ELeave) RConnection; CleanupStack::PushL(sock); CleanupStack::PushL(conn); // Start an outgoing connection err = conn->Open(iSocketServer); if (err!=KErrNone) { iQoSStep->iQoSSuite->Log(_L("Failed to open Connection: return value = <%d>"), err); User::Leave(err); } // Setup SetBearerSet prefs.SetBearerSet(iSetBearerSet[aExtraSocksToJoin]); // Setup IAP prefs.SetIapId(iIAP[aExtraSocksToJoin]); err = conn->Start(prefs); if (err!=KErrNone) { iQoSStep->iQoSSuite->Log(_L("Failed to open socket: return value = <%d>"), err); User::Leave(err); } err = sock->Open(iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp, *conn); if (err!=KErrNone) { iQoSStep->iQoSSuite->Log(_L("Failed to open socket: return value = <%d>"), err); User::Leave(err); } AddSocketToListL(sock); AddConnectionToListL(conn); CleanupStack::Pop(2); //sock and conn }
void UT_CNATFWUNSAFServerResolver::SetupL() { iResultArray = new (ELeave) RArray<TInetAddr>; User::LeaveIfError(iServer.Connect(KESockDefaultMessageSlots)); User::LeaveIfError(iConnection.Open(iServer, KConnectionTypeDefault)); TCommDbConnPref prefs; prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); prefs.SetDirection(ECommDbConnectionDirectionOutgoing); prefs.SetIapId(10); User::LeaveIfError(iConnection.Start(prefs)); iObserver = UT_CNATFWUNSAFServerResolverObserverStub::NewL(); iServerResolver = CNATFWUNSAFServerResolver::NewL(iServer, iConnection, *iObserver, EFalse); }
void CConnectionManager::OpenLinkLayerConnectionL() { #ifdef USE_RCONNECTION User::LeaveIfError(iSocketServ->Connect()); User::LeaveIfError(iConnection->Open(*iSocketServ)); TCommDbConnPref prefs = TCommDbConnPref(); if (iIAP >= 0) { prefs.SetIapId(iIAP); prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); iConnection->Start(prefs, iStatus); } else if (iIAP == -2) { // Debug mode - use system default iConnection->Start(iStatus); } else { // Use Always ask prefs.SetDialogPreference(ECommDbDialogPrefPrompt); prefs.SetDirection(ECommDbConnectionDirectionOutgoing); # ifdef NAV2_CLIENT_SERIES60_V2 prefs.SetBearerSet( EApBearerTypeGPRS | EApBearerTypeHSCSD ); # else //s80, s90 prefs.SetBearerSet( ECommDbBearerCSD | ECommDbBearerWcdma | ECommDbBearerCdma2000 | ECommDbBearerPSD ); # endif iConnection->Start(prefs, iStatus); } SetActive(); #endif }
/** * Connect to the network using this IAP ID */ TInt CRconn::Start(TUint32 aIapId, TBool aPrompt) { DEBUG_INFO("CRconn::Start: IAP id %u\n", aIapId); Cancel(); TCommDbConnPref prefs; prefs.SetIapId(aIapId); if (aPrompt) prefs.SetDialogPreference(ECommDbDialogPrefPrompt); else prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); prefs.SetDirection(ECommDbConnectionDirectionOutgoing); iConn.Start(prefs, iStatus); SetActive(); return 0; }
void UT_CNATTraversalController::SetupL() { User::LeaveIfError(iSocketServ.Connect()); User::LeaveIfError(iConnection.Open(iSocketServ)); TCommDbConnPref prefs; prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); prefs.SetDirection(ECommDbConnectionDirectionOutgoing); prefs.SetIapId(KIapId); User::LeaveIfError(iConnection.Start(prefs)); User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection)); User::LeaveIfError(iLocalAddr.Input(KLocalAddr)); User::LeaveIfError(iNextHopAddr.Input(KNextHopAddr)); TSIPNATTraversalControllerInitParams initParams(iSocketServ); iController = CNATTraversalController::NewL(&initParams); }
void CUdpProcess::ConstructL() { //Create the data buffer User::LeaveIfError(iSendBuf.Create(iSize)); User::LeaveIfError(iRecvBuf.Create(iSize)); iRecvSize = iSize; User::LeaveIfError(iSockServ.Connect()); // Start NCM IAP RConnection conn; User::LeaveIfError(conn.Open(iSockServ)); TCommDbConnPref pref; pref.SetIapId(13); pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); User::LeaveIfError(conn.Start(pref)); User::LeaveIfError(iSocket.Open(iSockServ, KAfInet, KSockDatagram, KProtocolInetUdp, conn)); iConsole.Printf(_L("In constructL, port=%d"), iAddr.Port()); if (iMode) { iProcessState = EDataTransfer; User::LeaveIfError(iSocket.SetLocalPort(iPort)); iSocket.RecvFrom(iRecvBuf, iPeerAddr, 0, iStatus); iConsole.Printf(_L("\nWait for UDP incoming data at port[%d]...\n"),iPort); SetActive(); } else { iProcessState = EDataSending; SetActive(); TRequestStatus* status = &iStatus; User::RequestComplete(status, KErrNone); } }
void CTcpProcess::ConstructL() { //Create the data buffer User::LeaveIfError(iSendBuf.Create(iSize)); User::LeaveIfError(iRecvBuf.Create(iSize)); iRecvSize = iSize; iProcessState = ECreateConnection; User::LeaveIfError(iSockServ.Connect()); if(iMode) { //Listen at specified port TBuf<5> protocol = _L("tcp"); User::LeaveIfError(iListenSocket.Open(iSockServ, protocol)); User::LeaveIfError(iListenSocket.SetOpt(KSoReuseAddr, KProtocolInetIp, 1)); User::LeaveIfError(iListenSocket.SetLocalPort(iPort)); User::LeaveIfError(iListenSocket.Listen(5)); User::LeaveIfError(iSocket.Open(iSockServ)); iListenSocket.Accept(iSocket, iStatus); iConsole.Printf(_L("\nWait for a connection at port[%d].\n"), iPort); } else { RConnection conn; User::LeaveIfError(conn.Open(iSockServ)); TCommDbConnPref pref; pref.SetIapId(13); pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); User::LeaveIfError(conn.Start(pref)); //Connect to specified server User::LeaveIfError(iSocket.Open(iSockServ, KAfInet, KSockStream, KProtocolInetTcp, conn)); iSocket.Connect(iAddr, iStatus); iConsole.Printf(_L("\nConnecting....\n")); } SetActive(); }
void ut_cstunbinding::UT_CSTUNBinding_NewLC_1L( ) { CSTUNClient* client = NULL; TUint iapID( 6 ); TInt retransmitInterval( 10 ); TBufC8<13> serveraddress( KServerAddress ); TUint serverport( 2000 ); TBufC8<4> protocol( KStun ); TBool obtainsharedsecret( EFalse ); TBool failifnoSRVrecordfound( EFalse ); TBool icmpUsed( EFalse ); TCommDbConnPref pref; pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); pref.SetIapId( iapID ); TRAPD( error, client = CSTUNClient::NewL( retransmitInterval, serveraddress, serverport, protocol, iSocketServ, iConnection, *iDeltatimer, *this, obtainsharedsecret, failifnoSRVrecordfound, icmpUsed, iMux ) ); if ( KErrNoMemory == error ) { User::Leave( error ); } CleanupStack::PushL( client ); CSTUNBinding* binding = CSTUNBinding::NewLC( *client, iStreamId, iSubstreamId ); CleanupStack::PopAndDestroy( binding ); CleanupStack::PopAndDestroy( client ); }
void CommonSocketConnection::SetupConnectionL() { iSocketServ.Connect(); iSocketServ.ShareAuto(); iConnection.Open(iSocketServ); iStatus = KRequestPending; TCommDbConnPref pref; pref.SetDirection(ECommDbConnectionDirectionOutgoing); if(iAccessPointId!=INVALID_IAPID) { pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); pref.SetIapId(iAccessPointId); iConnection.Start(pref,iStatus); } else { //SetDefaultIap(0); //cmnet pref.SetDialogPreference(ECommDbDialogPrefPrompt); iConnection.Start(pref,iStatus); } iConnectionState = EConnecting; SetActive(); }
void FConnection::ConstructL() { iLastError = KErrNone; StringBuffer errMsg; TCommDbConnPref prefs; // Connect SocketServer session iLastError = iSession.Connect(); if (iLastError != KErrNone) { errMsg.sprintf("FConnection error: unable to connect SocketServ (code %d)", iLastError); goto error; } // *Note*: THIS IS MANDATORY TO USE THE SAME SESSION FROM DIFFERENT THREADS! // After calling this function the RSocketServ object // may be used by threads other than than the one that created it. iLastError = iSession.ShareAuto(); if (iLastError != KErrNone) { errMsg.sprintf("FConnection error: unable to share SocketServ (code %d)", iLastError); goto error; } // // Default preferences: no prompt, just to initialize the connection object // prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); prefs.SetDirection(ECommDbConnectionDirectionUnknown); prefs.SetIapId(0); // Opens the connection openConnection(); return; error: LOG.error("%s", errMsg.c_str()); }
TInt CTS_MultiHomingStep::SetConnPrefs(TCommDbConnPref& aPrefs, TDesC& aName) /** * Fills up a CStoreableOverrideSettings* with script file configs * @param aPrefs A pointer to a CStoreableOverrideSettings object * @param aName Name of the connection to get prefs for * @return KErrNone if sucessful, otherwise system wide error codes * @exception Can leave */ { TInt theIap = 0; TInt theNet = 0; // Get the IAP index and use it to complete the .ini file section name if(GetIntFromConfig(aName, KConnIap, theIap)) { aPrefs.SetIapId(theIap); } if(GetIntFromConfig(aName, KConnNet, theNet)) { aPrefs.SetNetId(theNet); } return KErrNone; }
// --------------------------------------------------------------------------- // CNcmSession::ConstructL // --------------------------------------------------------------------------- // void CNcmSession::ConstructL( TUint /*aPortRangeStart*/, TUint /*aPortRangeStop*/ ) { iIpv4Addr.SetAddress( KLocalAddress ); iIpv4Addr.SetPort( KLocalPort ); /* iPortStore = CNcmPortStore::NewL( aPortRangeStart, aPortRangeStop ); */ User::LeaveIfError( iSocketServ.Connect( KESockMessageSlots ) ); TCommDbConnPref pref; pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); pref.SetIapId( iIapId ); User::LeaveIfError( iConnection.Open( iSocketServ ) ); TSecurityPolicy policy( ECapabilityNetworkServices ); TSecurityPolicyBuf securityBuf(policy); User::LeaveIfError( iConnection.Control( KCOLConnection, KCoEnableCloneOpen, securityBuf ) ); iConnection.Start( pref/*, iStatus*/ ); // SetActive(); }
// ---------------------------------------------------------------------------- // 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))) ); }
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; }
TVerdict CTestConnectStep::doTestStepL() /** * @return - TVerdict code * Override of base class pure virtual * Demonstrates reading configuration parameters fom an ini file section */ { if(TestStepResult()==EPass) { INFO_PRINTF1(_L("In Test Step ConnectWithOverrides")); // When bootstrapping C32 we have to avoid the PhBkSyncServer being started, since // it needs a different CommDB TInt ret = StartC32WithCMISuppressions(KPhbkSyncCMI); if((ret!=KErrNone) && (ret!=KErrAlreadyExists)) { INFO_PRINTF2(_L("error is : %d \n"),ret); } else { INFO_PRINTF1(_L("Started C32\n")); } RHostResolver hr; INFO_PRINTF1(_L("Connect to RSocketServ")); User::LeaveIfError(iSocketServ.Connect()); // Set up the connections, both overridden as host resolver won't work // on the default interface INFO_PRINTF1(_L("Open the RConnection interface")); User::LeaveIfError(iConnection.Open(iSocketServ)); // get the IapNumber value from the ini file if(!GetIntFromConfig(ConfigSection(), KIapNumber, iIapNumber)) { if(!GetIntFromConfig(KIap, KIapNumber, iIapNumber)) { iIapNumber=1; INFO_PRINTF1(_L("Failed to read Iap from ini file, using default")); } } INFO_PRINTF2((_L("IapNumber = %d")), iIapNumber); TRequestStatus status; #ifdef SIROCCO_CODE_MIGRATION TCommDbConnPref prefs; prefs.SetIapId(iIapNumber); prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); const TUid KMyPropertyCat = {0x101FD9C5}; const TUint32 KMyPropertyDestPortv4 = 67; TInt err = RProperty::Define(KMyPropertyCat, KMyPropertyDestPortv4, RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass), TSecurityPolicy(ECapabilityWriteDeviceData)); User::LeaveIfError(RProperty::Set(KMyPropertyCat, KMyPropertyDestPortv4, 93)); #else TInt rank = 1; // Create a multiple connection preference object TCommDbMultiConnPref prefs; for(TInt i=0;i<iapCount;i++) { TCommDbConnPref pref; // Set the direction pref.SetDirection(ECommDbConnectionDirectionOutgoing); // Set the bear ser pref.SetBearerSet(KCommDbBearerPSD | KCommDbBearerCSD); // Set the IAP pref.SetIapId(iIapNumber + i); // Set the dialog preference to Do Not Prompt pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); // Set the rank User::LeaveIfError(prefs.SetPreference(rank, pref)); rank++; } prefs.SetConnectionAttempts(rank-1); #endif // Start the connection iConnection.Start(prefs, status); User::WaitForRequest(status); TInt result = status.Int(); if(result!=KErrNone) { ERR_PRINTF2(_L("Failed to start connection. Error %d"), result); SetTestStepResult(EFail); User::Leave(EFail); } else { INFO_PRINTF1(_L("Connection started with overrides")); } // Set up the host resolver INFO_PRINTF1(_L("Initialise a host resolver service")); User::LeaveIfError(hr.Open(iSocketServ, KAfInet, KProtocolInetTcp, iConnection)); CleanupClosePushL(hr); // Test the interfaces conn, host resolution should work ok TBuf<64> hostname; TRequestStatus status1; TNameEntry nameEntry; TPtrC temphost; if(GetStringFromConfig(KTCPConfig, KHostName, temphost)) { INFO_PRINTF2(_L("Hostname is : %S"), &temphost); } else { ERR_PRINTF1(_L("No hostname")); SetTestStepResult(EFail); User::Leave(EFail); } hostname = temphost; hr.GetByName(hostname, nameEntry, status1); User::WaitForRequest(status1); TInt result1 = status1.Int(); if(result1!=KErrNone) { ERR_PRINTF2(_L("Failed to resolve the name. Error %d"), result1); SetTestStepResult(EFail); User::Leave(EFail); } else { INFO_PRINTF1(_L("Resolved the name successfully")); } // open socket INFO_PRINTF1(_L("Open the socket")); User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp, iConnection)); CleanupClosePushL(iSocket); // print the host resolver's ip address TInetAddr inetAddr; inetAddr = TInetAddr(nameEntry().iAddr); TBuf<50> addr; inetAddr.Output(addr); INFO_PRINTF2(_L("The host resolver's ip address is: %S"), &addr); // get the port number from the ini file if(!GetIntFromConfig(KTCPConfig, KPort, iPort)) { ERR_PRINTF1(_L("Failed to read Port from ini file")); SetTestStepResult(EFail); User::Leave(EFail); } INFO_PRINTF2((_L("Port = %d")), iPort); // connect to the socket inetAddr.SetPort(iPort); //nameEntry().iAddr.SetPort(iPort); TRequestStatus status2; //iSocket.Connect(nameEntry().iAddr,status2); iSocket.Connect(inetAddr,status2); User::WaitForRequest(status2); TInt result2 = status2.Int(); if(result2!=KErrNone) { ERR_PRINTF2(_L("Failed to connect to the socket. Error %d"), result2); SetTestStepResult(EFail); User::Leave(EFail); } else { INFO_PRINTF1(_L("Connect to the socket successfully")); } TPtrC ptrDNSName; if(GetStringFromConfig(KTCPConfig, KDNSName, ptrDNSName)) { INFO_PRINTF2(_L("DNSName is : %S"), &ptrDNSName); } else { ERR_PRINTF1(_L("No DNSName")); SetTestStepResult(EFail); User::Leave(EFail); } TBuf8<256> bufDnsName; bufDnsName.Copy(ptrDNSName); // connect to the secure socket CTestSecureSocket* iTestSecureSocket = CTestSecureSocket::NewL(*this, iSocket, bufDnsName); CleanupStack::PushL(iTestSecureSocket); iTestSecureSocket->StartHandshake(); CActiveScheduler::Start(); CleanupStack::PopAndDestroy(3); //iTestSecureSocket, iSocket, hr } return TestStepResult(); }
void Syscall::StartNetworkingL(ConnOp& connOp) { LOGST("StartNetworkingL"); DEBUG_ASSERT(gNetworkingState != EStarted); if(gNetworkingState == EStarting) { LOGST("SN pending"); connOp.iStatus = KRequestPending; connOp.SetActive(); gConnOpsWaitingForNetworkingStart.AppendL(&connOp); return; } gNetworkingState = EStarting; LHEL(gConnection.Open(gSocketServ)); TCommDbConnPref pref; #ifdef __SERIES60_3X__ if(gIapMethod == MA_IAP_METHOD_WLAN) { #if 0 // didn't work; prompted anyway. pref.SetBearerSet(KCommDbBearerWLAN); #endif RArray<TUint> iaps; if(gWlanAvailable) { LHEL(gWlanClient->GetAvailableIaps(iaps)); LOG("%i WLAN IAPs available.\n", iaps.Count()); } if(iaps.Count() > 0) { LOG("Picked IAP %i\n", iaps[0]); pref.SetIapId(iaps[0]); pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); } else { LOG("No WLAN IAPs available. Failing...\n"); //connOp.SendResult(CONNERR_NETWORK); connOp.mConn.connErr = CONNERR_NETWORK; //connOp.RunL(); connOp.SetActive(); TRequestStatus* rsp = &connOp.iStatus; User::RequestComplete(rsp, KErrGeneral); return; } } else if(gIapMethod == MA_IAP_METHOD_STANDARD) #endif //__SERIES60_3X__ { bool hasSavedIap = getSavedIap(gIapId); if(hasSavedIap) { LOG("Saved IAP: %u\n", gIapId); pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); pref.SetIapId(gIapId); DEBUG_ASSERT(pref.IapId() == gIapId); } else { LOG("No saved IAP, showing dialog...\n"); #ifdef __SERIES60_3X__ if(gIapFilter == MA_IAP_FILTER_NOT_WLAN) { // Note: doesn't work on E61i. WLAN is still displayed. LOG("Not wlan.\n"); pref.SetBearerSet(0xFF & ~KCommDbBearerWLAN); } else if(gIapFilter == MA_IAP_FILTER_WLAN) { LOG("Wlan only.\n"); pref.SetBearerSet(KCommDbBearerWLAN); } else { DEBUG_ASSERT(gIapFilter == MA_IAP_FILTER_ALL); } #endif //__SERIES60_3X__ pref.SetDialogPreference(ECommDbDialogPrefPrompt); } } #ifdef __SERIES60_3X__ else { DEBIG_PHAT_ERROR; } #endif //__SERIES60_3X__ gConnection.Start(pref, connOp.iStatus); connOp.SetActive(); LOGST("SN active"); }
const int FConnection::startConnection(const StringBuffer& aIAPName) { LOG.info("Starting new connection..."); LOG.debug("Looking for '%s' IAP name", aIAPName.c_str()); iLastError = KErrNone; StringBuffer errMsg; TCommDbConnPref prefs; prefs.SetDirection(ECommDbConnectionDirectionUnknown); if (aIAPName == "Default") { // // Use the default IAP without prompting the user // prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); prefs.SetIapId(0); } else if (aIAPName.empty() || aIAPName == "Ask") { // // Prompt user for IAP selection // } else { // // Search for the desired IAP. If not found, will prompt the user. // TInt iapID = GetIAPIDFromName(aIAPName); if (iapID >= 0) { LOG.debug("SetDialogPreference"); prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); prefs.SetIapId(iapID); } else { LOG.debug("IAP '%s' not found!", aIAPName.c_str()); } } /* * **** TODO: check if we need this! **** In S60 3rd Edition, enabling/disabling the inactivity timer will require the NetworkControl capability, which is only accessed via Symbian partner. */ //#if !defined(__SERIES60_3X__) || defined(__S60_3X_NET_CTRL__) // // Disable inactivity timer, otherwise inactive connection is closed // // within few seconds if there are no activity (e.g sockets) // iConnection.SetOpt(KCOLProvider, KConnDisableTimers, ETrue); //#endif // Opens the connection openConnection(); // Start connection iLastError = iConnection.Start(prefs); if (iLastError != KErrNone) { errMsg.sprintf("FConnection error: unable to start connection (code %d)", iLastError); LOG.debug("Goto retry"); goto retry; } // Save the IAP ID & name of the active connection. // Query the CommDb database for the IAP ID in use. _LIT(KIAPSettingName, "IAP\\Id"); iConnection.GetIntSetting(KIAPSettingName, iIAP); iIAPName = GetIAPNameFromID(iIAP); LOG.debug("Current active IAP ID = %d, name = '%s'", iIAP, iIAPName.c_str()); // // TODO: should we persist the iIAPName in the config, here? // iRetryConnection = 0; return 0; retry: LOG.error("%s", errMsg.c_str()); if (iIAPName.empty() || iIAPName == "Ask") { LOG.debug("Connection error and no IAP stored: don't retry"); return iLastError; } LOG.debug("About to retry..."); if (iRetryConnection < MAX_RETRY_CONNECTION) { iRetryConnection ++; LOG.info("Retry connection (%d time)...", iRetryConnection); startConnection(iIAPName); } else { LOG.error("FConnection: %d connection failed", iRetryConnection); } return iLastError; }
// Main void MainL() { /* Inetd Setup Create a inetd process */ RProcess inetd; CleanupClosePushL(inetd); User::LeaveIfError(inetd.Create(_L("inetd"), _L(""))); // Resume inetd inetd.Resume(); // Wait for inetd to be ready console->Printf(_L("[ press any key ]")); console->Getch(); // Get and ignore character /* IPEcho Part Connect to socket server */ console->Printf(_L("Connect to socket server ... \n")); RSocketServ socketServ; CleanupClosePushL(socketServ); User::LeaveIfError(socketServ.Connect()); // Open RConnection console->Printf(_L("Open RConnection ... \n")); RConnection connect; CleanupClosePushL(connect); User::LeaveIfError(connect.Open(socketServ, KConnectionTypeDefault)); // Start RConnection console->Printf(_L("Start RConnection ... \n")); TCommDbConnPref prefs; prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); User::LeaveIfError(connect.Start(prefs)); // Handle options here like (ie: No Prompt) // Open RSocket console->Printf(_L("Open Socket ... \n")); RSocket sock; CleanupClosePushL(sock); User::LeaveIfError(sock.Open(socketServ, KAfInet, KSockStream, KProtocolInetTcp, connect)); // Connect console->Printf(_L("Connect Socket ... \n")); TRequestStatus status; TInetAddr echoServAddr(KInetAddrLoop, 7); // 7: TCP port sock.Connect(echoServAddr, status); User::WaitForRequest(status); User::LeaveIfError(status.Int()); // Wait for the socket transfer to be over console->Printf(_L("[ press any key ]")); console->Getch(); // Get and ignore character // Send a packet console->Printf(_L("Send a packet ... \n")); HBufC8* packet = HBufC8::NewL(KSocketDefaultBufferSize); CleanupStack::PushL(packet); packet->Des().SetMax(); packet->Des().FillZ(); sock.Send(packet->Des(), 0, status); User::WaitForRequest(status); User::LeaveIfError(status.Int()); // Receive it back console->Printf(_L("Received it back ... \n")); packet->Des().Zero(); TPtr8 buff = packet->Des(); sock.Recv(buff, 0, status); User::WaitForRequest(status); User::LeaveIfError(status.Int()); // Terminates console->Printf(_L("Terminates ... \n")); CleanupStack::PopAndDestroy(packet); CleanupStack::PopAndDestroy(&sock); CleanupStack::PopAndDestroy(&connect); CleanupStack::PopAndDestroy(&socketServ); CleanupStack::PopAndDestroy(&inetd); }
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 if ( gSelectedConnectionId == -1 ) gSelectedConnectionId = SelectIAP(); iSelectedConnectionId = gSelectedConnectionId; 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; }