Example #1
0
wxCurlThreadError wxCurlBaseThread::SetURL(const wxString &url)
{
    wxCHECK_MSG(!IsAlive(), wxCTE_NO_RESOURCE, wxS("Cannot use this function after the tranfer has begun"));

    // which protocol is required by given url?
    wxCurlProtocol curr = GetProtocolFromURL(url);
    if (curr == wxCP_INVALID)
        return wxCTE_INVALID_PROTOCOL;

    if (curr != m_protocol)
    {
        m_protocol = curr;

        // we need to (re)create the m_pCurl object
        wxDELETE(m_pCurl);
        m_pCurl = CreateHandlerFor(m_protocol);
    }

    if (!m_pCurl || !m_pCurl->IsOk())
        return wxCTE_INVALID_PROTOCOL;

    // enable event sending (it's the only way the wxCurlDownloadThread user can
    // receive info about the progress of the transfer)
    m_pCurl->SetEvtHandler(GetEvtHandler(), GetId());
    m_pCurl->SetFlags(wxCURL_SEND_PROGRESS_EVENTS | wxCURL_SEND_BEGINEND_EVENTS);

    m_url = url;

    return wxCTE_NO_ERROR;
}
Example #2
0
void *wxCurlSizeQueryThread::Entry()
{
    wxLogDebug(wxS("wxSizeCacherThread::Entry - caching file sizes"));

    wxMemoryOutputStream os;
    bool allok = true;
    wxCurlHTTP http;
    wxCurlFTP ftp;

    m_urlSize.Clear();
    for (size_t i=0; i<m_urls.GetCount() && !TestDestroy(); i++)
    {
        unsigned long sz;

        wxCurlProtocol prot = GetProtocolFromURL(m_urls[i]);
        switch (prot)
        {
            case wxCP_HTTP:
            {
                http.OverrideProgressCallback(wxcurl_size_query_progress_func, &sz);
                allok &= http.Get(os, m_urls[i]);
            }
            break;

            case wxCP_FTP:
            {
                ftp.OverrideProgressCallback(wxcurl_size_query_progress_func, &sz);
                allok &= ftp.Get(os, m_urls[i]);
            }
            break;

            default:
                sz = (unsigned long)-1;
                wxFAIL;
        }

        m_urlSize.Add(sz);

        // send the event
        wxCurlSizeEvent ev(GetId(), m_urls[i], sz);
        wxPostEvent(GetEvtHandler(), ev);
    }

    wxLogDebug(wxS("wxSizeCacherThread::Entry - caching of file sizes completed"));
    return (void *)allok;
}
Example #3
0
/**
* \author	Darryn Campbell (DCC, JRQ768)
* \date		February 2010 - Initial Creation, DCC
* \date		June 2010	  - Moving to a common location for File Transfer and Engines
*                           to both use, DCC
*/
BOOL DereferenceURL(LPCTSTR tcRelativeURLConst, TCHAR* tcDereferencedURL, 
					TCHAR* tcCurrentURL, PBModule* pModule)
{
	BOOL retVal = FALSE;
	TCHAR tcRelativeURL[MAX_URL];
	wcscpy(tcRelativeURL, tcRelativeURLConst);
	if (tcRelativeURL)
	{
		//  First work out how many levels we need to navigate up from the 
		//  current URL (specified as ../)
		int iLevelsUp = 0;
		wchar_t* temp = wcsstr(tcRelativeURL, L"..");
		while (temp != NULL && (wcslen(temp) >= 2))
		{
			iLevelsUp++;
			temp = wcsstr(temp + 2, L"..");
		}
			
		//  We now know how many levels up we want to go from the current URL.
		//  Starting at the end of the current URL search for '/' or '\' and 
		//  work out if we can go up that many levels.
		TCHAR* pSzCurrentURL = tcCurrentURL + wcslen(tcCurrentURL) - 1;
		//  We do not want to include the protocol slashs in our search
		TCHAR tempProtocol[10];
		memset(tempProtocol, 0, 10 * sizeof(TCHAR));
		int iLengthOfProtocol = GetProtocolFromURL(tcCurrentURL, tempProtocol) + 3;
		while (pSzCurrentURL != tcCurrentURL + iLengthOfProtocol - 1)
		{
			if (*pSzCurrentURL == L'/' || *pSzCurrentURL == L'\\')
			{
				iLevelsUp--;
				if (iLevelsUp == -1)
				{
					//  pSzCurrentURL is pointing to the end of the URL 
					//  we want to use as our base
					break;
				}
			}

			pSzCurrentURL--;
		}

		//  If we exit the while loop and 'levelsUp' is not -1 then there were 
		//  insufficient backslashes in the current URL to go up the number
		//  of levels specified in the relative URL.
		if (iLevelsUp != -1)
		{
			if (pModule)
			{
#ifndef PB_ENGINE_IE_CE
#ifndef PB_ENGINE_IE_MOBILE
				pModule->Log(PB_LOG_ERROR, L"Unable to work out relative URL", 
				_T(__FUNCTION__), __LINE__);
#endif
#endif
			}
			return FALSE;
		}

		//  The actual URL we require is the juxtaposition of m_szCurrentURL
		//  up to the pSzCurrentURL with the first non . | / | \ charcter in 
		//  the relative URL
		int iFirstNonRelativeCharacter = wcsspn(tcRelativeURL, L"./\\");
		if (iFirstNonRelativeCharacter == wcslen(tcRelativeURL))
		{
			//  User specified relative string without filename, e.g. .././../
			if (pModule)
			{
#ifndef PB_ENGINE_IE_CE
#ifndef PB_ENGINE_IE_MOBILE
				pModule->Log(PB_LOG_ERROR, L"Unable to work out relative URL Filename", 
					_T(__FUNCTION__), __LINE__);
#endif
#endif
			}
			return FALSE;
		}
		TCHAR* pSzRelativeURLFilePathAndName = tcRelativeURL;
		pSzRelativeURLFilePathAndName += iFirstNonRelativeCharacter;

		//  Test the new URL is not too long
		if ((pSzCurrentURL - tcCurrentURL + 1) + 
			wcslen(pSzRelativeURLFilePathAndName) > MAX_URL)
		{
			if (pModule)
			{
#ifndef PB_ENGINE_IE_CE
#ifndef PB_ENGINE_IE_MOBILE
				pModule->Log(PB_LOG_ERROR, L"Relative URL produces URL string longer than maximum allowed", 
					_T(__FUNCTION__), __LINE__);
#endif
#endif
			}
			return FALSE;
		}

		wcsncpy(tcDereferencedURL, tcCurrentURL, pSzCurrentURL - tcCurrentURL + 1);
		wcscat(tcDereferencedURL, pSzRelativeURLFilePathAndName);
		retVal = TRUE;
	}
	return retVal;
}