Exemplo n.º 1
0
void
RSSManager::updateAllFeeds()
{
	unsigned int iNewNews = 0;
	NewsList l_fire_added_array;
	{
		CFlyLock(g_csFeed); // [+] IRainman fix.
		for (auto i = g_feeds.cbegin(); i != g_feeds.cend(); ++i)
		{
			if ((*i)->UpdateFeedNewXML())
			{
				const RSSFeed::RSSItemList& list = (*i)->getNewsList();
				for (auto j = list.cbegin(); j != list.cend(); ++j)
				{
					const RSSItem *l_item = new RSSItem(*j);
					CFlyFastLock(g_csNews);
					if (canAdd(l_item))
					{
						g_newsList.push_back(l_item);
						l_fire_added_array.push_back(l_item);
					}
					else
					{
						safe_delete(l_item);
					}
				}
				iNewNews += list.size();
			}
		}
	}
	for (auto i = l_fire_added_array.begin(); i !=  l_fire_added_array.end(); ++i)
	{
		fly_fire1(RSSListener::Added(), *i);
	}
	
	if (iNewNews)
	{
		fly_fire1(RSSListener::NewRSS(), iNewNews);
	}
}
Exemplo n.º 2
0
void FinishedManager::rotation_items(const FinishedItemPtr& p_item, eType p_type)
{
	// For fix - crash https://drdump.com/DumpGroup.aspx?DumpGroupID=301739
	CFlyWriteLock(*g_cs[p_type]);
	auto& l_item_array = g_finished[p_type];
#ifdef FLYLINKDC_USE_ROTATION_FINISHED_MANAGER
	while (!l_item_array.empty()
#ifndef _DEBUG
	        && l_item_array.size() > static_cast<size_t>(p_type == e_Download ? SETTING(MAX_FINISHED_DOWNLOADS) : SETTING(MAX_FINISHED_UPLOADS)))
#else
	        && l_item_array.size() > 1)
#endif
	{
		if (p_type == e_Download)
			fly_fire1(FinishedManagerListener::RemovedDl(), *l_item_array.cbegin());
		else
			fly_fire1(FinishedManagerListener::RemovedUl(), *l_item_array.cbegin());
		delete *l_item_array.cbegin(); // ћутное место
		l_item_array.pop_front();
	}
	// [~] IRainman
#endif // FLYLINKDC_USE_ROTATION_FINISHED_MANAGER
	l_item_array.push_back(p_item);
}
Exemplo n.º 3
0
/**
 * Downloads a file and returns it as a string
 * @todo Report exceptions
 * @todo Abort download
 * @param aUrl Full URL of file
 * @return A string with the content, or empty if download failed
 */
void HttpConnection::downloadFile(const string& aUrl, const string& aUserAgent)
{
	dcassert(!m_http_socket);
	if (m_http_socket) // [+] PPA fix
	{
		LogManager::message("HttpConnection::downloadFile \"" + aUrl + "\"- recursive call! Downloads cancelling...");
		dcassert(0);
		return;
	}
	dcassert(Util::isHttpLink(aUrl) || Util::isHttpsLink(aUrl));
	currentUrl = aUrl;
	m_userAgent = aUserAgent;
	// Trim spaces
	/* [-] IRainman: please check user input data. Don't use this cruth.
	while (currentUrl[0] == ' ')
	    currentUrl.erase(0, 1);
	while (currentUrl[currentUrl.length() - 1] == ' ')
	{
	    currentUrl.erase(currentUrl.length() - 1);
	}
	[!] IRainman: please check user input data. Don't use this cruth.*/
	// reset all settings (as in constructor), moved here from onLine(302) because ok was not reset properly
	moved302 = false;
	ok = false;
	size = -1;
	// set download type
	if (stricmp(currentUrl.substr(currentUrl.size() - 4).c_str(), ".bz2") == 0)
	{
		fly_fire1(HttpConnectionListener::TypeBZ2(), this);
	}
	else
	{
		fly_fire1(HttpConnectionListener::TypeNormal(), this);
	}
	
	bool isSecure = false;
	string proto, query, fragment;
	const string& l_httpProxyAdress = SETTING(HTTP_PROXY); // [+] IRainman opt.
	if (l_httpProxyAdress.empty())
	{
		Util::decodeUrl(currentUrl, proto, server, port, file, isSecure, query, fragment);
		if (file.empty())
			file = '/';
	}
	else
	{
		Util::decodeUrl(l_httpProxyAdress, proto, server, port, file, isSecure, query, fragment);
		file = currentUrl;
	}
	
	if (!query.empty())
		file += '?' + query;
		
#ifdef RIP_USE_CORAL
	if (BOOLSETTING(CORAL) && coralizeState != CST_NOCORALIZE)
	{
		{
			if (server.length() > CORAL_SUFFIX.length() && server.compare(server.length() - CORAL_SUFFIX.length(), CORAL_SUFFIX.length(), CORAL_SUFFIX) != 0)
			{
				server += CORAL_SUFFIX;
			}
			else
			{
				coralizeState = CST_NOCORALIZE;
			}
			
		}
	}
#endif
	
	if (port == 0)
		port = 80;
		
	if (!m_http_socket)
	{
		m_http_socket = BufferedSocket::getBufferedSocket(0x0a);
	}
	m_http_socket->addListener(this);
	try
	{
		m_http_socket->connect(server, port, isSecure, true, false);
	}
	catch (const Exception& e)
	{
		fly_fire1(HttpConnectionListener::Failed(), this, e.getError() + " (" + currentUrl + ")");
	}
}
Exemplo n.º 4
0
void HttpConnection::on(BufferedSocketListener::Data, uint8_t * aBuf, size_t aLen) noexcept
{
	fly_fire1(HttpConnectionListener::Data(), this, aBuf, aLen);
}
Exemplo n.º 5
0
void HttpConnection::on(BufferedSocketListener::Line, const string & aLine) noexcept
{
	if (!ok)
	{
		dcdebug("%s\n", aLine.c_str());
		if (aLine.find("200") == string::npos)
		{
			if (aLine.find("301") != string::npos || aLine.find("302") != string::npos)
			{
				moved302 = true;
			}
			else
			{
				socket_cleanup(false);
#ifdef RIP_USE_CORAL
				if (SETTING(CORAL) && coralizeState != CST_NOCORALIZE)
				{
					fly_fire1(HttpConnectionListener::Retried(), this, coralizeState == CST_CONNECTED);
					coralizeState = CST_NOCORALIZE;
					dcdebug("HTTP error with Coral, retrying : %s\n", currentUrl.c_str());
					downloadFile(currentUrl);
					return;
				}
#endif
				fly_fire1(HttpConnectionListener::Failed(), this, aLine + " (" + currentUrl + ")");
#ifdef RIP_USE_CORAL
				coralizeState = CST_DEFAULT;
#endif
				return;
			}
		}
		ok = true;
	}
	else if (moved302 && Util::findSubString(aLine, "Location") != string::npos)
	{
		dcassert(m_http_socket);
		socket_cleanup(false);
		string location302 = aLine.substr(10, aLine.length() - 11);
		// make sure we can also handle redirects with relative paths
		// if (Util::isHttpLink(location302)) [-] IRainman fix: support for part-time redirect URL.
		{
			if (location302[0] == '/') // [!] IRainman fix
			{
				string proto, query, fragment;
				Util::decodeUrl(currentUrl, proto, server, port, file, query, fragment);
				string tmp = "http://" + server;
				if (port != 80)
					tmp += ':' + Util::toString(port);
				location302 = tmp + location302;
			}
			else
			{
				string::size_type i = currentUrl.rfind('/');
				dcassert(i != string::npos);
				location302 = currentUrl.substr(0, i + 1) + location302;
			}
		}
		
		if (location302 == currentUrl)
		{
			fly_fire1(HttpConnectionListener::Failed(), this, "Endless redirection loop: " + currentUrl);
			return;
		}
		
		fly_fire1(HttpConnectionListener::Redirected(), this, location302);
		
#ifdef RIP_USE_CORAL
		coralizeState = CST_DEFAULT;
#endif
		downloadFile(location302);
		
	}
	else if (aLine == "\x0d")
	{
		m_http_socket->setDataMode(size);
	}
	else if (Util::findSubString(aLine, "Content-Length") != string::npos)
	{
		size = Util::toInt(aLine.substr(16, aLine.length() - 17));
	}
	else if (Util::findSubString(aLine, "Content-Encoding") != string::npos)
	{
		if (aLine.substr(18, aLine.length() - 19) == "x-bzip2")
			fly_fire1(HttpConnectionListener::TypeBZ2(), this);
	}
}
void SettingsAutoUpdate::fail(const string& p_error)
{
	dcdebug("SettingsAutoUpdate: New command when already failed: %s\n", p_error.c_str());
	//LogManager::message("SettingsAutoUpdate: " + p_error);
	fly_fire1(SettingsAutoUpdateListener::Failed(), p_error);
}