bool vmsUrlMonRequestCollector::onInternetProtocolRoot_Continue(IInternetProtocolRoot* pProt, PROTOCOLDATA* pProtocolData)
{
	if (pProtocolData == &_protocolData || 
			(pProtocolData->dwState == 0 && pProtocolData->pData == _protocolData_pData && pProtocolData->cbData == 13))
	{
		vmsCriticalSectionAutoLock csal (&m_csReq);
		int nIndex = findRequestIndexByProtocol (pProt);
		assert (nIndex != -1);
		if (nIndex == -1)
		{
			LOGsnl ("WARNING: no request found for pProt in onInternetProtocolRoot_Continue");
			return true;
		}
		Request *req = getRequest (nIndex);

		if (!req->dwthridContinue)
		{
			if (req->dwTicksCompleted)
				req->spProt = NULL;

			req->dwthridContinue = GetCurrentThreadId ();

#ifdef SCL_ENABLE
			LOGsnl ("Update for request:");
			USES_CONVERSION;
			LOG (" URL: %s", W2CA (req->wstrUrl.c_str ()));
			LOG (" thridContinue: %d", req->dwthridContinue);
#endif

			HMODULE hBhoDll = GetModuleHandle (_T ("iefdm2.dll"));
			if (hBhoDll)
			{
				typedef BSTR (WINAPI *FNfdmbho_getTabUrl) (DWORD dwThreadId);
				FNfdmbho_getTabUrl pfn = (FNfdmbho_getTabUrl)GetProcAddress (hBhoDll, "fdmbho_getTabUrl");
				if (pfn)
				{
					BSTR bstrTabUrl = pfn (req->dwthridContinue);
					if (!bstrTabUrl)
						bstrTabUrl = pfn (req->dwthridStart);
					if (bstrTabUrl)
					{
						req->wstrSrcTabUrl = bstrTabUrl;
						SysFreeString (bstrTabUrl);
					}
#ifdef SCL_ENABLE
					LOG (" SRC TAB URL: %s", req->wstrSrcTabUrl.empty () ? "<NOT_FOUND>" : W2CA (req->wstrSrcTabUrl.c_str ()));
#endif
				}
			}
		}
		return true;
	}

	return false;
}
Exemple #2
0
HRESULT STDMETHODCALLTYPE CSuneidoAPP::Start(
	/* [in] */ LPCWSTR szUrl,
	/* [in] */ IInternetProtocolSink __RPC_FAR* pOIProtSink,
	/* [in] */ IInternetBindInfo __RPC_FAR* pOIBindInfo,
	/* [in] */ DWORD grfPI,
	/* [in] */ DWORD dwReserved) {
	USES_CONVERSION;
	const char* url = W2CA(szUrl);
	ULONG buflen = strlen(url) + 10; // shouldn't get any bigger?
	char* buf = new char[buflen];
	InternetCanonicalizeUrl(url, buf, &buflen, ICU_DECODE | ICU_NO_ENCODE);
	LOG("Start: " << buf);

	int n;
	str = trycall("SuneidoAPP", buf, &n);
	if (str == 0)
		return INET_E_DATA_NOT_AVAILABLE;
	str = localmemdup(str, n);
	len = n;
	pos = 0;

	LOG("ReportData");
	pOIProtSink->ReportData(BSCF_DATAFULLYAVAILABLE | BSCF_LASTDATANOTIFICATION,
		len, len); // MUST call this
	LOG("end Start");
	return S_OK;
}
bool CFindServersDlg::FindServers()
{
	m_ServerList.RemoveAll();
	CMainFrame::CStatusMsg	status(IDS_FSRV_FINDING);
	bool	retc;
	try {
		COptionsDlg&	OptsDlg = theApp.GetMain()->GetOptionsDlg();
		LPCTSTR	HostIP = OptsDlg.GetNicIPAddressOrNull();
#ifdef UNICODE
		USES_CONVERSION;
		m_Finder = new WFindServers(NULL, m_PortNumber, W2CA(HostIP));
#else
		m_Finder = new WFindServers(NULL, m_PortNumber, HostIP);
#endif
		switch (m_Method) {
		case FSM_BROADCAST:
			retc = FindServersBroadcast();
			break;
		case FSM_ADDR_RANGE:
			retc = FindServersAddressRange();
			break;
		default:
			ASSERT(0);	// logic error
			retc = 0;
		}
		delete m_Finder;
	}
	catch (const WError& e) {
		CString	msg(e.what());
		AfxMessageBox(msg);
		return(FALSE);
	}
	return(retc);
}
bool CPacketConn::Create(LPCTSTR HostName, DWORD Port, LPCTSTR ServerIP, HWND hWnd, int Cookie, WTcp *Tcp)
{
	ASSERT(hWnd);
	Destroy();
	if (Tcp != NULL) {
		m_Tcp = Tcp;	// take ownership of TCP object
		m_Passive = TRUE;
	} else {
		try {	// TCP constructor throws
#ifdef UNICODE
			USES_CONVERSION;
			m_Tcp = new WTcp(W2CA(HostName), Port, W2CA(ServerIP));	// convert to MBCS
#else
			m_Tcp = new WTcp(HostName, Port, ServerIP);
#endif
		}
		catch (const WError& e) {
			m_LastErrorStr = e.what();
			return(FALSE);
		}
	}
	m_hWnd = hWnd;
	m_Cookie = Cookie;
	m_Server = m_Tcp->Server();
	m_Kill = FALSE;
	m_Trusted = FALSE;
	m_ClientAddr = HostName;
	if (!m_RcvThr.Create(NULL, 0, RcvThrFunc, this, 0, NULL))
		return(FALSE);
	if (m_Server)
		m_Tcp->InstallConnectionHandler(ConnHand, this);
	else {	// we're a client
		if (!m_Passive) {
			if (!Write(m_AuthQuery, sizeof(m_AuthQuery))) {	// query server
				Destroy();
				return(FALSE);
			}
		}
		if (WaitForSingleObject(m_Tcp->GetReadEvent(), AUTH_TIMEOUT) != WAIT_OBJECT_0) {
			Destroy();
			return(FALSE);	// server didn't reply in time
		}
	}
	return(TRUE);
}
void CChordEaseDoc::WriteSongText(CFile& File, const CString& Text)
{
#ifdef UNICODE
	USES_CONVERSION;
	LPCSTR	pText = W2CA(Text);	// convert text from Unicode to ANSI
	File.Write(pText, UINT64TO32(strlen(pText)));	// write text to file
#else	// ANSI
	File.Write(Text, Text.GetLength());	// write text to file
#endif
}
void vmsUrlMonRequestCollector::onNewRequest(Request *request)
{
	_BrowsersSharedData.ModifyActiveDownloadsCount (1);

	RemoveTooOldRequests ();

	request->dwTicksStarted = GetTickCount ();

	IServiceProviderPtr spSP (request->spSink);
	assert (spSP != NULL);
	if (spSP != NULL)
		spSP->QueryService (IID_IHttpNegotiate, IID_IHttpNegotiate, (void**)&request->spHttpNegotiate);

	request->dwthridStart = GetCurrentThreadId ();

	if (_IEVersion.m_appVersion.empty () || _IEVersion.m_appVersion [0] < 10)
	{
		BINDINFO bi; DWORD dwBindF;
		ZeroMemory (&bi, sizeof (bi));
		bi.cbSize = sizeof (bi);
		request->spBindInfo->GetBindInfo (&dwBindF, &bi);

		if (bi.dwBindVerb == BINDVERB_POST && bi.cbstgmedData)
		{
			
			if (bi.stgmedData.tymed == TYMED_HGLOBAL)
			{
				LPVOID pData = GlobalLock (bi.stgmedData.hGlobal);
				if (pData)
				{
					request->vbPostData.resize (bi.cbstgmedData);
					CopyMemory (&request->vbPostData [0], pData, bi.cbstgmedData);
					GlobalUnlock (bi.stgmedData.hGlobal);
				}
			}
		}
	}

	vmsCriticalSectionAutoLock csal (&m_csReq);
	m_vReq.push_back (request);

#ifdef SCL_ENABLE
	LOGsnl ("New request:");
	USES_CONVERSION;
	LOG (" URL: %s", W2CA (request->wstrUrl.c_str ()));
	LOG (" thridStart: %d", request->dwthridStart);
	LOG (" post data size: %d", request->vbPostData.size ());
#endif

	request->spSink->Switch (&_protocolData);
}
void vmsUrlMonRequestCollector::onInternetProtocolSink_ReportProgress(IInternetProtocolSink* pSink, ULONG ulStatusCode, LPCWSTR szStatusText)
{
#ifdef SCL_ENABLE
	{USES_CONVERSION;
	vmsCriticalSectionAutoLock csal (&m_csReq);
	int nIndex = findRequestIndexBySink (pSink);
	if (nIndex == -1)
		return;
	Request *req = getRequest (nIndex);
	LOGsnl ("Progress for request:");
	LOG (" URL: %s", W2CA (req->wstrUrl.c_str ()));
	LOG (" ulStatusCode: %d", ulStatusCode);
	LOG (" szStatusText: %s", W2CA (szStatusText));}
#endif

	if (ulStatusCode != BINDSTATUS_REDIRECTING)
		return;

	assert (szStatusText != NULL);
	if (!szStatusText)
		return;

	vmsCriticalSectionAutoLock csal (&m_csReq);
	int nIndex = findRequestIndexBySink (pSink);
	if (nIndex == -1)
		return;
	Request *req = getRequest (nIndex);

	req->wstrRedirectedUrl = szStatusText;

#ifdef SCL_ENABLE
	LOGsnl ("Update for request:");
	USES_CONVERSION;
	LOG (" URL: %s", W2CA (req->wstrUrl.c_str ()));
	LOG (" Redirecting to URL: %s", W2CA (szStatusText));
	LOG (" TICKCOUNT: %d", GetTickCount ());
#endif
}
void vmsUrlMonRequestCollector::onInternetProtocolSink_ReportData(IInternetProtocolSink* pSink, DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax)
{
	vmsCriticalSectionAutoLock csal (&m_csReq);
	int nIndex = findRequestIndexBySink (pSink);
	if (nIndex == -1)
		return;
	Request *req = getRequest (nIndex);
	req->dwState |= Request::GotResponse;

#ifdef SCL_ENABLE
	USES_CONVERSION;
	LOGsnl ("Report data for request:");
	LOG (" URL: %s", W2CA (req->wstrUrl.c_str ()));
	LOG (" grfBSCF: %d", grfBSCF);
	LOG (" progress: %d", ulProgress);
	LOG (" progress max: %d", ulProgressMax);
#endif
}
Exemple #9
0
BOOL COledbRecordset::GetField(short iIndex, std::string& pData)
{
   _ASSERTE(IsOpen());
   iIndex += m_iAdjustIndex;
   _ASSERTE(iIndex>=0 && iIndex<m_nCols);
   USES_CONVERSION;
   switch( m_rgBindings[iIndex].wType ) {
   case DBTYPE_STR:
      pData = (char*) ((LPBYTE) m_pData + m_rgBindings[iIndex].obValue);
      return TRUE;
   case DBTYPE_WSTR:
      pData = W2CA( (WCHAR*) ((LPBYTE) m_pData + m_rgBindings[iIndex].obValue) );
      return TRUE;
   default:
      _ASSERTE(false);
      return FALSE;
   }
}
// IContextMenu::GetCommandString
// Gets information about a shortcut menu command, including the help string
// and the name for the command.
STDMETHODIMP
CWatchedOverlayIcon::GetCommandString(
    UINT_PTR idCmd,
    UINT uFlags, 
    UINT* pwReserved,
    PSTR pszName, 
    UINT cchMax
)
{
    try
    {
        // Check command ID, which must be 0 since we have only one menu item.
        if (0 != idCmd)
        {
            return E_INVALIDARG;
        }

        // If Explorer is asking for a help string, copy our string into the
        // supplied buffer.
        if (uFlags & GCS_HELPTEXT)
        {
            PCWSTR wszText = L"This is the simple shell extension's help";
            
            if (uFlags & GCS_UNICODE)
            {
                lstrcpynW((LPWSTR) pszName, wszText, cchMax);
            }
            else
            {
                USES_CONVERSION;
                lstrcpynA(pszName, W2CA(wszText), cchMax);
            }

            return S_OK;
        }

        return E_INVALIDARG;
    }
    catch (...)
    {
        return E_FAIL;
    }
}
void vmsUrlMonRequestCollector::CloseRequest(Request* request)
{
#ifdef SCL_ENABLE
	LOGsnl ("Close request:");
	USES_CONVERSION;
	LOG (" URL: %s", W2CA (request->wstrUrl.c_str ()));
#endif

	assert (!request->dwTicksCompleted);
	if (request->dwTicksCompleted)
		return;

	_BrowsersSharedData.ModifyActiveDownloadsCount (-1);

	request->dwTicksCompleted = GetTickCount ();
	request->spHttpNegotiate = NULL;
	request->spSink = NULL;
	request->spBindInfo = NULL;
	request->spUri = NULL;
	if (request->dwthridContinue)
		request->spProt = NULL; 
}
Exemple #12
0
STDMETHODIMP CMyBHO::Invoke(DISPID dispidMember,REFIID riid, LCID lcid, 
							WORD wFlags, DISPPARAMS * pDispParams, 
							VARIANT * pvarResult,EXCEPINFO * pexcepinfo, 
							UINT * puArgErr)
{	
	UNREFERENCED_PARAMETER(lcid);
	UNREFERENCED_PARAMETER(wFlags);
	UNREFERENCED_PARAMETER(pvarResult);
	UNREFERENCED_PARAMETER(pexcepinfo);
	UNREFERENCED_PARAMETER(puArgErr);

	VARIANT v[5]; // Used to hold converted event parameters before passing them onto the event handling method
	int n;
	PVOID pv;
	LONG lbound,ubound,sz;

	for(n=0;n<5;n++) VariantInit(&v[n]);


	switch (dispidMember)
	{
	case DISPID_BEFORENAVIGATE2:
#ifdef __LEA_LOG
#ifdef DEBUG
		{
			VariantChangeType(&v[0],&pDispParams->rgvarg[5],0,VT_BSTR); // url
			VariantChangeType(&v[1],&pDispParams->rgvarg[4],0,VT_I4); // Flags
			VariantChangeType(&v[2],&pDispParams->rgvarg[3],0,VT_BSTR); // TargetFrameName
			VariantChangeType(&v[3],&pDispParams->rgvarg[2],0,VT_UI1|VT_ARRAY); // PostData
			VariantChangeType(&v[4],&pDispParams->rgvarg[1],0,VT_BSTR); // Headers
			if(v[3].vt!=VT_EMPTY) {
				SafeArrayGetLBound(v[3].parray,0,&lbound);
				SafeArrayGetUBound(v[3].parray,0,&ubound);
				sz=ubound-lbound+1;
				SafeArrayAccessData(v[3].parray,&pv);
			} else {
				sz=0;
				pv=NULL;
			}

			/*TCHAR Msg[1024];
			wsprintf(Msg,L"Message from Invoke.  \nUrl = %ls",v[0].bstrVal);
			MessageBox(NULL,Msg,_T("DISPID_BEFORENAVIGATE2"),MB_OK|MB_ICONINFORMATION);*/
			USES_CONVERSION;
			if(m_fpLog != NULL && (stricmp(W2CA(v[0].bstrVal),"about:blank") != 0)&&(stricmp(W2CA(v[0].bstrVal),"about:Tabs") != 0))
			{
				fprintf(m_fpLog,"DISPID_BEFORENAVIGATE2 -- %ls\n",v[0].bstrVal);
				fflush(m_fpLog);
			}		
		}
#endif
#endif
		break;
	case DISPID_DOCUMENTCOMPLETE:
		{
			BSTR msg;
			m_spWebBrowser->get_LocationURL(&msg);
			TCHAR *pMsg = OLE2T(msg);
			//MessageBox(NULL,pMsg,L"DISPID_DOCUMENTCOMPLETE",MB_OK|MB_ICONINFORMATION);
#ifdef __LEA_LOG
			USES_CONVERSION;
			if(stricmp(m_szLastOrgURL.c_str(),W2CA(pMsg)) != 0)
			{
				m_szLastOrgURL = W2CA(pMsg);
				if(m_fpLog != NULL && (stricmp(W2CA(pMsg),"about:blank") != 0) && (stricmp(W2CA(pMsg),"about:Tabs") != 0))
				{
					fprintf(m_fpLog,"%ls\n",pMsg);
					fflush(m_fpLog);
				}	
			}
#endif
			SysFreeString(msg);

		}	
		break;
	case DISPID_NAVIGATECOMPLETE2:
		{
			BSTR msg;
			m_spWebBrowser->get_LocationURL(&msg);
			TCHAR *pMsg = OLE2T(msg);
			//MessageBox(NULL,pMsg,L"DISPID_NAVIGATECOMPLETE2",MB_OK|MB_ICONINFORMATION);
#ifdef __LEA_LOG
			USES_CONVERSION;
			if(stricmp(m_szLastOrgURL.c_str(),W2CA(pMsg)) != 0)
			{
				m_szLastOrgURL = W2CA(pMsg);
				if(m_fpLog != NULL && (stricmp(W2CA(pMsg),"about:blank") != 0) && (stricmp(W2CA(pMsg),"about:Tabs") != 0))
				{
					fprintf(m_fpLog,"%ls\n",pMsg);
					fflush(m_fpLog);
				}	
			}
#endif
			SysFreeString(msg);
		}
		break;
	case DISPID_DOWNLOADCOMPLETE:
		{
			BSTR msg;
			m_spWebBrowser->get_LocationURL(&msg);
			TCHAR *pMsg = OLE2T(msg);
			//MessageBox(NULL,pMsg,L"DISPID_DOWNLOADCOMPLETE",MB_OK|MB_ICONINFORMATION);
#ifdef __LEA_LOG

			USES_CONVERSION;
			if(stricmp(m_szLastOrgURL.c_str(),W2CA(pMsg)) != 0)
			{
				m_szLastOrgURL = W2CA(pMsg);
				if(m_fpLog != NULL && (stricmp(W2CA(pMsg),"about:blank") != 0) && (stricmp(W2CA(pMsg),"about:Tabs") != 0))
				{
					fprintf(m_fpLog,"%ls\n",pMsg);
					fflush(m_fpLog);
				}		
			}
#endif
			SysFreeString(msg);
		}
		break;
	case DISPID_NEWWINDOW3:
		{
			BSTR msg;
			m_spWebBrowser->get_LocationURL(&msg);
			TCHAR *pMsg = OLE2T(msg);
			//MessageBox(NULL,pMsg,L"DISPID_DOWNLOADCOMPLETE",MB_OK|MB_ICONINFORMATION);
#ifdef __LEA_LOG
			USES_CONVERSION;
			if(stricmp(m_szLastOrgURL.c_str(),W2CA(pMsg)) != 0)
			{
				m_szLastOrgURL = W2CA(pMsg);
				if(m_fpLog != NULL && (stricmp(W2CA(pMsg),"about:blank") != 0) && (stricmp(W2CA(pMsg),"about:Tabs") != 0))
				{
					fprintf(m_fpLog,"%ls\n",pMsg);
					fflush(m_fpLog);
				}		
			}
#endif
			SysFreeString(msg);
		}
		break;
	default:
		break;
	}
	return E_FAIL;
}
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;
}
unsigned long winet_addr(const WCHAR *cp)
{
	USES_CONVERSION;
	return(inet_addr(W2CA(cp)));	// convert to MBCS
}