Пример #1
0
int fsSitesMgr::FindSite(LPCSTR pszName, DWORD dwValidFor, BOOL bAllReq)
{
    for (int i = 0; i < m_vSites.size (); i++)
    {
        fsSiteInfo *site = m_vSites [i];
        if (fsIsServersEqual (site->strName, pszName, site->dwValidFor & SITE_VALIDFOR_SUBDOMAINS))
        {
            if (bAllReq)
            {

                if ((site->dwValidFor & dwValidFor) == dwValidFor)
                    return i;
            }
            else
            {


                if (site->dwValidFor & dwValidFor)
                    return i;
            }
        }
    }

    return -1;
}
Пример #2
0
fsInternetResult fsMirrorURLsMgr::OnSearchScriptResultsReceived()
{
    fsHTMLParser parser;

    parser.SetKillDupes (TRUE);
    parser.ParseHTML (LPSTR (m_dldr.Get_FileBuffer ()));

    m_vMirrorURLs.clear ();

    for (int i = 0; i < parser.GetUrlCount () && m_bAbort == FALSE; i++)
    {
        fsURL url;
        LPCSTR pszUrl = parser.GetUrl (i);

        if (IR_SUCCESS != url.Crack (pszUrl))
            continue;

        if (fsIsServersEqual (url.GetHostName (), m_strBaseServer, TRUE) ||
                fsIsServersEqual (m_strBaseServer, url.GetHostName (), TRUE)    )
            continue;

        char szFileName [10000];
        fsFileNameFromUrlPath (url.GetPath (), url.GetInternetScheme () == INTERNET_SCHEME_FTP,
                               TRUE, szFileName, sizeof (szFileName));

        if (stricmp (szFileName, m_strFile) == 0)
        {


            if (IsMirrorURLGood (pszUrl) == FALSE)
                continue;

            m_vMirrorURLs.add (pszUrl);
        }
    }

    m_dldr.Free_FileBuffer ();

    if (m_bAbort)
        return IR_S_FALSE;

    Event (MUME_DONE);
    return IR_SUCCESS;
}
Пример #3
0
DWORD WINAPI fsInternetFileListMgr::_threadGetList(LPVOID lp)
{
	fsInternetFileListMgr* pThis = (fsInternetFileListMgr*) lp;

	CString strProxy, strPUser, strPPassword;
	fsURL url;

	if (url.Crack (pThis->_strUrl) != IR_SUCCESS)
	{
		pThis->m_lastError = IR_BADURL;
		goto _lExit;
	}

	if (*url.GetHostName () == 0 || *url.GetPath () == 0)
	{
		pThis->m_lastError = IR_BADURL;
		goto _lExit;
	}

	if (*url.GetUserName ())
	{
		if (pThis->m_strUser != url.GetUserName ())
		{
			pThis->m_strUser = url.GetUserName ();
			pThis->m_strPassword = url.GetPassword ();
			pThis->Free (FALSE);
			pThis->m_bConnected = FALSE;
		}
	}
	else
	{
		if (pThis->m_strUser != pThis->_strUser)
		{
			if (pThis->_strUser != NULL || fsIsServersEqual (url.GetHostName (), pThis->m_server.GetServerName ()) == FALSE)
			{
				pThis->m_strUser = pThis->_strUser;
				pThis->m_strPassword = pThis->_strPassword;
				pThis->m_bConnected = FALSE;
			}
		}
	}

	pThis->m_bCurPathIsRoot = strcmp (url.GetPath (), "/") == 0 || strcmp (url.GetPath (), "\\") == 0;

_lConnect:

	
	
	if (pThis->m_bConnected == FALSE ||
		 FALSE == fsIsServersEqual (pThis->m_server.GetServerName (), url.GetHostName ()) ||
		 pThis->m_server.GetScheme () != url.GetInternetScheme () )
	{
		pThis->Free (FALSE);

		

		fsGetProxy (fsSchemeToNP (url.GetInternetScheme ()), strProxy, strPUser, strPPassword);

		pThis->m_session.Create (_App.Agent (), _App.InternetAccessType (), strProxy,
			fsSchemeToNP (url.GetInternetScheme ()));
		pThis->m_session.SetProxyAuth (strPUser, strPPassword);
		pThis->m_session.SetTimeout (_App.Timeout ());
		pThis->m_server.Initialize (&pThis->m_session);
		pThis->m_server.UseFtpPassiveMode (pThis->m_bFtpPassiveMode);

		UINT cAttempts = _App.MaxAttempts ();

		do
		{
			pThis->Event (FLME_CONNECTING);

			
			
			pThis->m_lastError = pThis->m_server.Connect (pThis->_strUrl, pThis->m_strUser, pThis->m_strPassword, url.GetPort ());
			if (pThis->m_lastError != IR_SUCCESS)
			{
				if (pThis->m_lastError != IR_S_FALSE)
					pThis->Event (FLME_ERROR);
			}
			else
			{
				
				if (pThis->m_server.IsFtpServer ())
					pThis->Event (FLME_CONNECTED);
			}

			if (pThis->m_lastError != IR_SUCCESS)
			{
				if (pThis->m_lastError == IR_LOGINFAILURE || pThis->m_lastError == IR_INVALIDUSERNAME ||
					 pThis->m_lastError == IR_INVALIDPASSWORD)
				{
					

					fsSiteInfo *site = _SitesMgr.FindSite2 (url.GetHostName (), fsNPToSiteValidFor (fsSchemeToNP (url.GetInternetScheme ())));
					if (site && site->strUser)
					{
						CString strPass = site->strPassword ? site->strPassword : "";
						if (site->strUser != pThis->m_strUser || strPass != pThis->m_strPassword)
						{
							

							pThis->Event (FLME_TRYINGTOUSESITEMGRLOGIN);
							pThis->m_strUser = site->strUser;
							pThis->m_strPassword = strPass;
							continue;
						}
					}

					

					if (pThis->AskForLogin (url.GetHostName ()))
						continue;
					else
						break;
				}

				pThis->SleepInterval ();
			}

			cAttempts--;

			if (cAttempts == 0)
				break;
		}
		while (pThis->m_lastError != IR_SUCCESS && pThis->m_bAbort == FALSE);

		if (pThis->m_lastError == IR_SUCCESS && pThis->m_bAbort == FALSE)
		{
			if (pThis->m_server.IsFtpServer ())
			{
				pThis->m_bConnected = TRUE;
			}
		}
		else
		{
			pThis->Event (FLME_STOPPED);
			goto _lExit2;
		}
	}
	else if (pThis->m_server.IsFtpServer () == FALSE)
		pThis->Event (FLME_CONNECTING);

	UINT cAttempts;
	cAttempts = _App.MaxAttempts ();

	do
	{
		
		if (pThis->m_server.IsFtpServer ())
			pThis->Event (FLME_GETTINGLIST);

		fsnew1 (pThis->m_files, fsInternetURLFiles);
		pThis->m_files->SetHttpEventFunc (_HttpEvents, pThis);
		pThis->m_files->RetreiveInfoWhileGettingList (pThis->m_bRetreiveInfoWhileGettingList);
		
		pThis->m_lastError = pThis->m_files->GetList (&pThis->m_server, url.GetPath ());

		if (pThis->m_lastError == IR_S_REDIRECTED)
			pThis->m_lastError = IR_SUCCESS;
	
		if (pThis->m_lastError != IR_SUCCESS && pThis->m_lastError != IR_S_REDIRECTED)
		{
			fsInternetURLFiles *files = pThis->m_files;
			pThis->m_files = NULL;
			delete files;

			if (pThis->m_lastError != IR_S_FALSE)
				pThis->Event (FLME_ERROR);

			if (pThis->m_bAbort)
				break;

			switch (pThis->m_lastError)
			{
				case IR_CONNECTIONABORTED:
				case IR_LOSTCONNECTION:
					pThis->Event (FLME_CONNECTIONWASLOST_RESTORE);
					pThis->m_bConnected = FALSE;
					goto _lConnect;
				break;

				case IR_LOGINFAILURE:
				case IR_INVALIDUSERNAME:
				case IR_INVALIDPASSWORD:
					if (pThis->AskForLogin (url.GetHostName ()))
						goto _lConnect;
					else
					{
						pThis->Event (FLME_STOPPED);
						goto _lExit2;
					}
				break;
			}

			cAttempts--;

			if (cAttempts == 0 || pThis->m_bAbort)
				break;

			pThis->SleepInterval ();

			if (pThis->m_bAbort == FALSE)
				pThis->Event (FLME_CONNECTING);
		}
	}
	while (pThis->m_lastError != IR_SUCCESS && pThis->m_bAbort == FALSE);

	pThis->_strUrl = NULL;

	if (pThis->m_lastError == IR_SUCCESS)
		pThis->m_vFiles.add (pThis->m_files);
	else
	{
		pThis->Event (FLME_STOPPED);
		goto _lExit2;
	}

_lExit:

	if (pThis->m_lastError != IR_SUCCESS)
	{
		if (pThis->m_lastError != IR_S_FALSE)
			pThis->Event (FLME_ERROR);
	}
	else
		pThis->Event (FLME_DONE);

_lExit2:
	
	pThis->m_bThread = FALSE;

	return 0;
}
Пример #4
0
int vmsIETmpCookies::Find(LPCSTR pszUrl)
{
	fsURL url;
	if (IR_SUCCESS != url.Crack (pszUrl))
		return -1;

	char szCookie [50000] = "";
	DWORD dw = sizeof (szCookie);
	InternetGetCookie (pszUrl, NULL, szCookie, &dw);
	vmsCookie cookie; cookie.Set (szCookie);

	GetListOfKnownCookies ();

	
	fs::list <int> vFit;

	for (int i = 0; i < m_vBeforeNavUrls.size (); i++)
	{
		if (m_vBeforeNavUrls [i] == pszUrl)
		{
			
			
			vFit.add (i);
			break;
		}
	}

	for (int bEx = 0; bEx < 2 && vFit.size () == 0; bEx++)
	{
		

		for (int i = 0; i < m_vUrls.size (); i++)
		{
			fsURL url2;
			if (IR_SUCCESS != url2.Crack (m_vUrls [i].c_str ()))
				continue;

			if (fsIsServersEqual (url.GetHostName (), url2.GetHostName (), bEx))
				vFit.add (i);
		}
	}

	if (vFit.size () == 0)
	{
		

		string str1 = GetLevel2DomainName (url.GetHostName ());

		for (int i = 0; i < m_vUrls.size (); i++)
		{
			fsURL url2;
			if (IR_SUCCESS != url2.Crack (m_vUrls [i].c_str ()))
				continue;

			string str2 = GetLevel2DomainName (url2.GetHostName ());

			if (str1 == str2)
				vFit.add (i);
		}
	}

	int nIndex = -1;
	int cCI = -1;
	int len = 0;
	
	
	for (i = 0; i < vFit.size (); i++)
	{
		int n = vFit [i];	
		vmsCookie c; c.Set (get_Cookies (n));
		int cCI2 = cookie.GetCommonItemCount (&c);
		if (cCI2 > cCI || (cCI2 == cCI && len < c.get_ItemCount ()))
		{
			nIndex = n;
			cCI = cCI2;
			len = c.get_ItemCount ();
		}
	}

	if (nIndex != -1)
	{
		vmsCookie c; c.Set (get_Cookies (nIndex));
		cookie.Add (&c);
		m_vCookies [nIndex] = cookie.toString ();
	}

	return nIndex;
}