Exemplo n.º 1
0
nsNotifyAddrListener::~nsNotifyAddrListener()
{
#ifdef WINCE_WINDOWS_MOBILE
  if (mConnectionHandle)
    ConnMgrReleaseConnection(mConnectionHandle, 0);
#endif
}
Exemplo n.º 2
0
static nsresult DoPPCConnection()
{
    static HANDLE    gConnectionHandle = NULL;

    // Make the connection to the new network
    CONNMGR_CONNECTIONINFO conn_info;
    memset(&conn_info, 0, sizeof(CONNMGR_CONNECTIONINFO));

    conn_info.cbSize      = sizeof(CONNMGR_CONNECTIONINFO);
    conn_info.dwParams    = CONNMGR_PARAM_GUIDDESTNET;
    conn_info.dwPriority  = CONNMGR_PRIORITY_USERINTERACTIVE;
    conn_info.guidDestNet = IID_DestNetInternet;
    conn_info.bExclusive  = FALSE;
    conn_info.bDisabled   = FALSE;

    HANDLE tempConnectionHandle;
    DWORD status;
    HRESULT result = ConnMgrEstablishConnectionSync(&conn_info, 
                                                    &tempConnectionHandle, 
                                                    60000,
                                                    &status);

    if (result != S_OK)
    {
      return NS_ERROR_FAILURE;
    }

    if (status != CONNMGR_STATUS_CONNECTED)
    {
      // could not connect to this network.  release the
      // temp connection.
      ConnMgrReleaseConnection(tempConnectionHandle, 0);
      return NS_ERROR_FAILURE;
    }

    // At this point, we have a new connection, so release
    // the old connection
    if (gConnectionHandle)
      ConnMgrReleaseConnection(gConnectionHandle, 0);
      
    gConnectionHandle = tempConnectionHandle;
    return NS_OK;
}
Exemplo n.º 3
0
bool CNetRequestImpl::SetupInternetConnection(LPCTSTR url)
{
#if defined (_WIN32_WCE)
	int iNetwork;
	HRESULT hResult = E_FAIL;
	DWORD   dwStatus;
    static HANDLE hConnection = NULL;

	// cleanup the old connection
	if(NULL != hConnection)
	{
		hResult = ConnMgrConnectionStatus( hConnection, &dwStatus );
		if( SUCCEEDED(hResult) )
		{
			LOG(INFO) + "Internet connection exist, use it";
			if( dwStatus & CONNMGR_STATUS_CONNECTED )
				return true;
		}
		ConnMgrReleaseConnection(hConnection, FALSE);
		LOG(INFO) + "Internet connection droped, open new one";
		hConnection = NULL;
	}

	// get the right network to connect to
	iNetwork = 0;
	//CONNMGR_DESTINATION_INFO DestInfo;

	GUID pguid;
	if( FAILED( ConnMgrMapURL(url, &pguid, NULL) ) )
		return false;

	//while( SUCCEEDED(ConnMgrEnumDestinations(iNetwork++, &DestInfo)))
	{	
		LOG(INFO) + "Try establish Internet connection";
		// actually try to establish the connection
		CONNMGR_CONNECTIONINFO ConnInfo;

		ZeroMemory(&ConnInfo, sizeof(ConnInfo));
		ConnInfo.cbSize = sizeof(ConnInfo);
		ConnInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
		ConnInfo.dwPriority = CONNMGR_PRIORITY_HIPRIBKGND;//CONNMGR_PRIORITY_USERBACKGROUND;
#if ( _WIN32_WCE >= 0x500 )
		ConnInfo.dwFlags = CONNMGR_FLAG_NO_ERROR_MSGS;
#endif
		ConnInfo.guidDestNet = pguid;

		hResult = ConnMgrEstablishConnection(&ConnInfo, &hConnection);

		// check to see if the attempt failed
		int count = 0;
		while(SUCCEEDED(hResult) && count++ < 60 )
		{
			LOG(INFO) + "Wait for connect (" + count + ")";
			DWORD dwResult = WaitForSingleObject(hConnection, 1000); 
			if (dwResult == (WAIT_OBJECT_0))
			{ 
				hResult=ConnMgrConnectionStatus(hConnection,&dwStatus);
				if( SUCCEEDED(hResult) )
				{
					if( dwStatus & CONNMGR_STATUS_CONNECTED )
					{
						LOG(INFO) + "Connected";
						return true;
					}
					if( dwStatus & CONNMGR_STATUS_WAITINGCONNECTION )
					{
						continue;
					}
					break;
				}
			}
		}
	}
	LOG(ERROR) + "Failed to connect";
	return false;
#else
	return true;
#endif //_WIN32_WCE
}
/**
* Download and install from a remote location using HTTP.
* @param url the url indicating the location of the widget.
* @param widget receives the constructed widget on success.
*/
STDMETHODIMP CBondiWidgetLibrary::RemoteInstall(BSTR url, IBondiWidget** widget)
{
	HRESULT hRes = S_OK;

	try
	{
		TCHAR appDataPath[MAX_PATH];
		WidgetUtils::GetAppFolder(NULL,appDataPath);

		TCHAR canonicalURL[1024];
		DWORD nSize = 1024;
		InternetCanonicalizeUrl(url, canonicalURL, &nSize, ICU_BROWSER_MODE);

		// Check for an internet connection.
		if (InternetAttemptConnect(0) != ERROR_SUCCESS)
			BONDI_RAISE_ERROR(E_BONDI_WIDGET_NO_INTERNET,_T("no internet connection found"));

		// Open a connection.
		HINTERNET hINet = InternetOpen(agentName,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);

		if (hINet != 0)
		{
			HANDLE hConnection = ConnectToNetwork(25);
			if (hConnection != NULL)
			{
				// Attempt to access the resource at the url.
				DWORD options = INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_HYPERLINK|INTERNET_FLAG_RESYNCHRONIZE|INTERNET_FLAG_RELOAD;
				HINTERNET hFile = InternetOpenUrl( hINet, canonicalURL, NULL, 0, options, 0 );

				if (hFile != 0)
				{
					// Determine the file name to store the downloaded widget resource.
					TCHAR fName[MAX_PATH];
					_tsplitpath_s(url, NULL, 0, NULL, 0, fName, _MAX_FNAME, NULL, 0); 

					// Create the target local file.
					_bstr_t downloadPath = appDataPath + _bstr_t("\\") + _bstr_t(fName) + _bstr_t(".wgt");			
					HANDLE target = ::CreateFile(downloadPath,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

					// Read chunks.
					BYTE buffer[1024];
					DWORD dwRead;
					while (::InternetReadFile( hFile, buffer, 1024, &dwRead ) )
					{
						if ( dwRead == 0 )
							break;

						::WriteFile(target,buffer,dwRead,&dwRead,NULL);
					}

					::CloseHandle(target);

					InternetCloseHandle(hFile);

					CComObject<CBondiWidget>* newWidget;
					BONDI_CHECK_ERROR(CComObject<CBondiWidget>::CreateInstance(&newWidget),(IBondiWidgetLibrary*)this);
					newWidget->AddRef();

					// Do the installation.
					_bstr_t locale("en");
					hRes = newWidget->Install(downloadPath,locale,VARIANT_FALSE,VARIANT_FALSE);
					BONDI_CHECK_ERROR(hRes,(IBondiWidget*)newWidget);					

					if (hRes == S_OK)
					{
						// Set the install URL.
						CComPtr<IBondiWidgetAppConfig> appConfig;
						BONDI_CHECK_ERROR(newWidget->get_AppSettings(&appConfig),(IBondiWidget*)newWidget);
						if (appConfig != NULL)
							BONDI_CHECK_ERROR(appConfig->PutBondiSetting(_T("bondi.installUri"),canonicalURL,VARIANT_TRUE),appConfig);

						newWidget->InitialiseAppSettings();

						// We've finished with the temporary downloaded resource.
						::DeleteFile(downloadPath);

						*widget = (IBondiWidget*)newWidget;
					}
					else
					{
						// Didn't install (probably because of an existing widget).
						*widget = NULL;
					}
				}
				else
				{				 
					DWORD err = GetLastError();
					BONDI_RAISE_ERROR(E_BONDI_WIDGET_URL_OPEN_FAILED,_T("couldn't open url: ") + CString(canonicalURL));
				}

#ifdef UNDER_CE
				ConnMgrReleaseConnection(hConnection,1);
				CloseHandle(hConnection);
#endif
			}

			InternetCloseHandle(hINet);
		}
		else
		{
			BONDI_RAISE_ERROR(E_BONDI_WIDGET_NO_INTERNET,_T("error opening internet connection"));
		}
	}
	catch (_com_error& err)
	{
		hRes = BONDI_SET_ERROR(err,"CBondiWidgetLibrary::RemoteInstall - COM exception");
	}
	catch (...)
	{
		hRes = BONDI_SET_ERROR(E_FAIL,"CBondiWidgetLibrary::RemoteInstall - C++ exception");
	}

	return hRes;
}