Ejemplo n.º 1
0
	const wchar_t * pathToURI(const std::wstring path)
	{
		DWORD url_size = MAX_PATH*5;
		LPWSTR pszUrl = new WCHAR[url_size]; //We have to account for chars that must be escaped into %XX sequences

		HRESULT ret = UrlCreateFromPath(path.c_str(), pszUrl, &url_size, NULL);
       
		if (ret != S_OK)
		{
	    	MWLOG(LEV_ERROR, MOD_APL, L"XadesSignature: UrlCreateFromPath returned error, \
			URI is probably wrongly encoded");
			return std::wstring(L"file://localhost" + path).c_str();
		}
Ejemplo n.º 2
0
static void loadURL(BSTR urlBStr)
{
    IWebFrame* frame = 0;
    IWebMutableURLRequest* request = 0;
    static BSTR methodBStr = 0;

    if (!methodBStr)
        methodBStr = SysAllocString(TEXT("GET"));

    if (urlBStr && urlBStr[0] && (PathFileExists(urlBStr) || PathIsUNC(urlBStr))) {
        TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
        DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
        if (SUCCEEDED(UrlCreateFromPath(urlBStr, fileURL, &fileURLLength, 0)))
            urlBStr = fileURL;
    }

    HRESULT hr = gWebView->mainFrame(&frame);
    if (FAILED(hr))
        goto exit;

    hr = CoCreateInstance(CLSID_WebMutableURLRequest, 0, CLSCTX_ALL, IID_IWebMutableURLRequest, (void**)&request);
    if (FAILED(hr))
        goto exit;

    hr = request->initWithURL(urlBStr, WebURLRequestUseProtocolCachePolicy, 0);
    if (FAILED(hr))
        goto exit;

    hr = request->setHTTPMethod(methodBStr);
    if (FAILED(hr))
        goto exit;

    hr = frame->loadRequest(request);
    if (FAILED(hr))
        goto exit;

    SetFocus(gViewWindow);

exit:
    if (frame)
        frame->Release();
    if (request)
        request->Release();
}
Ejemplo n.º 3
0
void web_page::make_url( LPCWSTR url, LPCWSTR basepath, std::wstring& out )
{
	if(PathIsRelative(url) && !PathIsURL(url))
	{
		if(basepath && basepath[0])
		{
			DWORD dl = lstrlen(url) + lstrlen(basepath) + 1;
			LPWSTR abs_url = new WCHAR[dl];
			HRESULT res = UrlCombine(basepath, url, abs_url, &dl, 0);
			if (res == E_POINTER)
			{
				delete abs_url;
				abs_url = new WCHAR[dl + 1];
				if (UrlCombine(basepath, url, abs_url, &dl, 0) == S_OK)
				{
					out = abs_url;
				}
			}
			else if (res == S_OK)
			{
				out = abs_url;
			}
			delete abs_url;
		}
		else
		{
			DWORD dl = lstrlen(url) + (DWORD) m_base_path.length() + 1;
			LPWSTR abs_url = new WCHAR[dl];
			HRESULT res = UrlCombine(m_base_path.c_str(), url, abs_url, &dl, 0);
			if (res == E_POINTER)
			{
				delete abs_url;
				abs_url = new WCHAR[dl + 1];
				if (UrlCombine(m_base_path.c_str(), url, abs_url, &dl, 0) == S_OK)
				{
					out = abs_url;
				}
			}
			else if (res == S_OK)
			{
				out = abs_url;
			}
			delete abs_url;
		}
	} else
	{
		if(PathIsURL(url))
		{
			out = url;
		} else
		{
			DWORD dl = lstrlen(url) + 1;
			LPWSTR abs_url = new WCHAR[dl];
			HRESULT res = UrlCreateFromPath(url, abs_url, &dl, 0);
			if (res == E_POINTER)
			{
				delete abs_url;
				abs_url = new WCHAR[dl + 1];
				if (UrlCreateFromPath(url, abs_url, &dl, 0) == S_OK)
				{
					out = abs_url;
				}
			}
			else if (res == S_OK)
			{
				out = abs_url;
			}
			delete abs_url;
		}
	}
	if(out.substr(0, 8) == L"file:///")
	{
		out.erase(5, 1);
	}
	if(out.substr(0, 7) == L"file://")
	{
		out.erase(0, 7);
	}
}