Beispiel #1
0
PRBool CFDMForFirefox::TransferUrlToFDM(IFDMUrl *url)
{
	IWGUrlReceiverPtr spUrlRcvr;
	spUrlRcvr.CreateInstance (__uuidof (WGUrlReceiver));

	assert (spUrlRcvr != NULL);
    if (spUrlRcvr == NULL)
		return FALSE;

	if (NS_OK != CFDMUrlReceiver::ApplyUrlToReceiver (spUrlRcvr, url))
		return FALSE;

	spUrlRcvr->put_IgnoreSize (FALSE);

	if (FAILED (spUrlRcvr->ShowAddDownloadDialog ()))
		return FALSE;

	DWORD dwAllow = TRUE;
	m_keyFDMMonitor.QueryValue (dwAllow, "AllowDownload");
	if (dwAllow == FALSE)
		return TRUE;	

	BSTR bstrState = NULL;
	do {
		if (bstrState)
			SysFreeString (bstrState);
		Sleep (5);
		spUrlRcvr->get_UIState (&bstrState);
	} while (wcsicmp (bstrState, L"in_progress") == 0);

	BOOL bAdded = wcsicmp (bstrState, L"added") == 0;
	SysFreeString (bstrState);

	return bAdded;
}  
void CFDMFlashVideoDownloads::ProcessHtml(LPCSTR pszHost, LPCSTR pszHtml)
{
	vmsVideoSiteHtmlCodeParser vshcp;
	if (FALSE == vshcp.Parse (pszHost, pszHtml))
		return;

	USES_CONVERSION;

	IWGUrlReceiverPtr spRcvr;
	spRcvr.CreateInstance (__uuidof (WGUrlReceiver));
	spRcvr->put_Url (A2W (vshcp.get_VideoUrl ()));

	if (vshcp.get_IsVideoUrlDirectLink ())
	{
		CString str = vshcp.get_VideoTitle ();
		str += "."; str += vshcp.get_VideoType ();
		spRcvr->put_FileName (A2W (str));

		spRcvr->put_Comment (A2W (vshcp.get_VideoTitle ()));

		spRcvr->put_FlashVideoDownload (TRUE);
	}

	spRcvr->AddDownload ();
}
BOOL vmsFdmWebInterfaceServer::RequestCreateNewDownload(LPCSTR pszRes, vmsHttpResponse &response)
{
	CoInitialize (NULL);

	IWGUrlReceiverPtr spUrlRcvr;
	spUrlRcvr.CreateInstance (__uuidof (WGUrlReceiver));
	ASSERT (spUrlRcvr != NULL);

	if (spUrlRcvr == NULL)
	{
		CoUninitialize ();
		_bstr_t bstrAddDownloadRes_err(m_strAddDownloadRes_err.c_str ());
		response.set_Body ((const char*)bstrAddDownloadRes_err, m_strAddDownloadRes_err.length ());
		return TRUE;
	}

	spUrlRcvr->put_ForceSilentEx (TRUE);
	spUrlRcvr->put_CheckExtension (FALSE);
	spUrlRcvr->put_ForceDownloadAutoStart (TRUE);
	spUrlRcvr->put_DisableMaliciousChecking (TRUE);
	spUrlRcvr->put_DisableURLExistsCheck (TRUE);

	CStringA strUrl;
	pszRes += lstrlenA ("/adddownload.req?");
	if (strnicmp (pszRes, "URL=", 4))
	{
		CoUninitialize ();
		_bstr_t bstrAddDownloadRes_err(m_strAddDownloadRes_err.c_str ());
		response.set_Body ((const char*)bstrAddDownloadRes_err, m_strAddDownloadRes_err.length ());
		return FALSE;
	}
	pszRes += 4;

	

	while (*pszRes)
	{
		char c;

		
		if (*pszRes == '%')
		{
			pszRes++;
			char sz [3];
			sz [0] = *pszRes++; 
			if (*pszRes == 0)
				return FALSE;
			sz [1] = *pszRes++;
			sz [2] = 0;
			int i;
			sscanf (sz, "%x", &i);
			c = (char)i;
		}
		else
		{
			c = *pszRes++;
			
			if (c == '+')
				c = ' ';
		}

		strUrl += c;
	}

	
	
	CString str;
	int i = 0;
	for (i = 0; i < strUrl.GetLength () - 1;)
	{
		if (strUrl [i] == '&' && strUrl [i+1] == '#')
		{
			int k = i + 2;
			CStringA str2; 
			bool bHex = false;
			if (k < strUrl.GetLength ())
				bHex = strUrl [k] == 'x';
			if (bHex)
				k++;
			while (isdigit (strUrl [k]))
				str2 += strUrl [k++];
			if (str2.IsEmpty () == FALSE && 
				 (strUrl [k] == ';' || strUrl.GetLength () == k))
			{
				i = ++k;
				wchar_t wsz [2];
				if (bHex)
				{
					int j;
					sscanf (str2, "%x", &j);
					wsz [0] = (wchar_t)j;
				}
				else
				{
					wsz [0] = atoi (str2);
				}
				wsz [1] = 0;
				char sz [2];
				WideCharToMultiByte (CP_ACP, 0, wsz, -1, sz, 1, NULL, NULL);
				sz [1] = 0;
				str += sz;
				continue;
			}

		}

		str += strUrl [i++];
	}
	if (i == strUrl.GetLength () - 1)
		str += strUrl [i];
	strUrl = str;
	

	USES_CONVERSION;
	CComBSTR bstr = A2W (strUrl);
	spUrlRcvr->put_Url (bstr);

	HRESULT hr = spUrlRcvr->AddDownload ();

	BOOL bAdded = FALSE;

	
	if (SUCCEEDED (hr))
	{
		CComBSTR bstrState;

		do {
			Sleep (10);
			spUrlRcvr->get_UIState (&bstrState);
		} while (bstrState == L"in_progress");

		bAdded = bstrState == L"added";
	}

	_bstr_t bstrAddDownloadRes_err(m_strAddDownloadRes_err.c_str ());
	_bstr_t bstrAddDownloadRes_ok(m_strAddDownloadRes_ok.c_str ());

	if (bAdded == FALSE)
		response.set_Body ((const char*)bstrAddDownloadRes_err, m_strAddDownloadRes_err.length ());
	else
		response.set_Body ((const char*)bstrAddDownloadRes_ok, m_strAddDownloadRes_ok.length ());

	spUrlRcvr = NULL;
	CoUninitialize ();

	return TRUE;
}
STDMETHODIMP CFDMFlashVideoDownloads::ShowAddDownloadsDialog(BSTR bstrSrcWebPageUrl, SAFEARRAY *psaDownloads)
{
	USES_CONVERSION;

	CComObject <CFdmUiWindow> *pUiWindow = NULL;
	CComObject <CFdmUiWindow>::CreateInstance (&pUiWindow);

	vmsAUTOLOCKSECTION (m_csLastUiWindow);
	m_spLastUiWindow = pUiWindow;
	vmsAUTOLOCKSECTION_UNLOCK (m_csLastUiWindow);

	if (psaDownloads == NULL)
		return E_INVALIDARG;

	UINT cDim = SafeArrayGetDim (psaDownloads);
	if (cDim != 1)
		return E_INVALIDARG;

	LONG lLBound = 0, lUBound = 0;
	SafeArrayGetLBound (psaDownloads, 1, &lLBound);
	SafeArrayGetUBound (psaDownloads, 1, &lUBound);

	std::vector <vmsNewDownloadInfo> *pvDlds = new std::vector <vmsNewDownloadInfo>;

	for (long i = lLBound; i <= lUBound; i++)
	{
		IDispatchPtr spDisp;
		SafeArrayGetElement (psaDownloads, &i, &spDisp);

		IFdmFlvDownloadPtr spFlvDld (spDisp);

		if (spFlvDld == NULL)
		{
			delete pvDlds;
			return E_INVALIDARG;
		}
		IWGUrlReceiverPtr spUrl;
		spFlvDld->get_Url (&spUrl);
		if (spUrl == NULL)
		{
			delete pvDlds;
			return E_INVALIDARG;
		}

		CComBSTR bstr;
		spUrl->get_Url (&bstr);

		CString strUrl = W2CT (bstr);
		bool bSkip = false;

		for (size_t j = 0; j < pvDlds->size (); j++)
		{
			if (pvDlds->at (j).strUrl == strUrl)
			{
				bSkip = true; 
				break;
			}
		}

		if (bSkip)
			continue;

		vmsNewDownloadInfo dlInfo;

		dlInfo.strUrl = W2CA (bstr);

		spUrl->get_Referer (&bstr);
		dlInfo.strReferer = W2CA (bstr);

		spUrl->get_Comment (&bstr);
		dlInfo.strComment = bstr;

		dlInfo.dwWhatIsValid = NDIV_AP;

		dlInfo.ap.dwMask = DWCDAP_FLAGS;
		dlInfo.ap.dwFlags = DWDCDAP_F_FLASHVIDEODOWNLOAD;

		spUrl->get_Cookies (&bstr);
		if (bstr.Length ())
		{
			dlInfo.ap.dwMask |= DWCDAP_COOKIES;
			dlInfo.ap.strCookies = W2CA (bstr);
		}

		spUrl->get_PostData (&bstr);
		if (bstr.Length ())
		{
			dlInfo.ap.dwMask |= DWCDAP_POSTDATA;
			dlInfo.ap.strPostData = W2CA (bstr);
		}

		spUrl->get_FileName (&bstr);
		if (bstr.Length ())
		{
			dlInfo.ap.dwMask |= DWCDAP_FILENAME;
			dlInfo.ap.strFileName = W2CA (bstr);
		}

		spUrl->get_FileSize (&bstr);
		if (bstr.Length ())
		{
			dlInfo.ap.dwMask |= DWCDAP_FILESIZE;
			dlInfo.ap.uFileSize = (UINT64)_wtoi64 (bstr);
		}

		pvDlds->push_back (dlInfo);
	}

	CFlashVideoDownloadsWnd::WmFvdwLparam *lp = new CFlashVideoDownloadsWnd::WmFvdwLparam;
	lp->strSrcWebPageUrl = W2CA(bstrSrcWebPageUrl);
	lp->pvDlds = pvDlds;
	lp->pUiWindow = pUiWindow; 
	if (pUiWindow)
		pUiWindow->AddRef ();
	_pwndFVDownloads->PostMessage (WM_FVDW_CREATEDOWNLOADS, 0, (LPARAM)lp);

	return S_OK;
}
PRBool CFDMForFirefox::TransferUrlToFDM(IFDMUrl *url)
{
	assert (url != NULL);
	if (!url)
		return FALSE;

	IWGUrlReceiverPtr spUrlRcvr;
	spUrlRcvr.CreateInstance (__uuidof (WGUrlReceiver));

	assert (spUrlRcvr != NULL);
    if (spUrlRcvr == NULL)
		return FALSE;

	if (NS_OK != CFDMUrlReceiver::ApplyUrlToReceiver (spUrlRcvr, url))
		return FALSE;

	spUrlRcvr->put_IgnoreSize (FALSE);

	if (FAILED (spUrlRcvr->ShowAddDownloadDialog ()))
		return FALSE;

	IServiceProviderPtr spSP (spUrlRcvr);
	IFdmUiWindowPtr spUiWindow;
	if (spSP)
		spSP->QueryService (__uuidof (IFdmUiWindow), __uuidof (IFdmUiWindow), (void**)&spUiWindow);
	if (spUiWindow != NULL)
	{
		spUiWindow->WaitForWindowCreation (5000);
		ULONG u = 0;
		spUiWindow->get_Handle (&u);
		if (u)
		{
			SetForegroundWindow ((HWND)u);
			BringWindowToTop ((HWND)u);
		}
	}

	DWORD dwAllow = TRUE;
	m_keyFDMMonitor.QueryValue (dwAllow, "AllowDownload");
	if (dwAllow == FALSE)
		return TRUE;	

	BSTR bstrState = NULL;
	do {
		if (bstrState)
		{
			SysFreeString (bstrState);
			bstrState = NULL;
		}
		Sleep (5);
		spUrlRcvr->get_UIState (&bstrState);
		assert (bstrState != NULL);
		if (!bstrState)
			return FALSE;
	} while (wcsicmp (bstrState, L"in_progress") == 0);

	BOOL bAdded = wcsicmp (bstrState, L"added") == 0;
	SysFreeString (bstrState);

	return bAdded;
}