Skip to content

Commit

Permalink
Fix #3842 by always using https links (#3854)
Browse files Browse the repository at this point in the history
  • Loading branch information
vampy authored and Benau committed Apr 19, 2019
1 parent 27023b2 commit deba8d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/addons/news_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

using namespace Online;

NewsManager *NewsManager::m_news_manager=NULL;
NewsManager *NewsManager::m_news_manager = nullptr;
std::string NewsManager::m_news_filename = "online_news.xml";

// ----------------------------------------------------------------------------
NewsManager::NewsManager() : m_news(std::vector<NewsMessage>())
Expand All @@ -45,7 +46,7 @@ NewsManager::NewsManager() : m_news(std::vector<NewsMessage>())
m_force_refresh = false;

// Clean .part file which may be left behind
std::string news_part = file_manager->getAddonsFile("news.xml.part");
std::string news_part = file_manager->getAddonsFile(m_news_filename + ".part");
if (file_manager->fileExists(news_part))
file_manager->removeFile(news_part);

Expand All @@ -60,16 +61,16 @@ NewsManager::~NewsManager()
// ---------------------------------------------------------------------------
/** This function initialises the data for the news manager. It starts a
* separate thread to execute downloadNews() - which (if necessary) downloads
* the news.xml file and updates the list of news messages. It also
* the m_news_filename file and updates the list of news messages. It also
* initialises the addons manager (which can trigger another download of
* news.xml).
* \param force_refresh Re-download news.xml, even if
* m_news_filename).
* \param force_refresh Re-download m_news_filename, even if
*/
void NewsManager::init(bool force_refresh)
{
m_force_refresh = force_refresh;

// The rest (which potentially involves downloading news.xml) is handled
// The rest (which potentially involves downloading m_news_filename) is handled
// in a separate thread, so that the GUI remains responsive. It is only
// started if internet access is enabled, else nothing is done in the
// thread anyway (and the addons menu is disabled as a result).
Expand All @@ -93,7 +94,7 @@ void NewsManager::init(bool force_refresh)
} //init

// ---------------------------------------------------------------------------
/** This function submits request which will download the news.xml file
/** This function submits request which will download the m_news_filename file
* if necessary. It is running in its own thread, so we can use blocking
* download calls without blocking the GUI.
* \param obj This is 'this' object, passed on during pthread creation.
Expand All @@ -104,15 +105,15 @@ void* NewsManager::downloadNews(void *obj)
NewsManager *me = (NewsManager*)obj;
me->clearErrorMessage();

std::string xml_file = file_manager->getAddonsFile("news.xml");
std::string xml_file = file_manager->getAddonsFile(m_news_filename);
// Prevent downloading when .part file created, which is already downloaded
std::string xml_file_part = file_manager->getAddonsFile("news.xml.part");
std::string xml_file_part = file_manager->getAddonsFile(m_news_filename + ".part");
bool news_exists = file_manager->fileExists(xml_file);

// The news message must be updated if either it has never been updated,
// or if the time of the last update was more than news_frequency ago,
// or because a 'refresh' was explicitly requested by the user, or no
// news.xml file exists.
// m_news_filename file exists.
bool download = ( UserConfigParams::m_news_last_updated==0 ||
UserConfigParams::m_news_last_updated
+UserConfigParams::m_news_frequency
Expand Down Expand Up @@ -149,8 +150,8 @@ void* NewsManager::downloadNews(void *obj)
{
core::stringw error_message("");

HTTPRequest *download_req = new HTTPRequest("news.xml");
download_req->setAddonsURL("news.xml");
HTTPRequest *download_req = new HTTPRequest(m_news_filename);
download_req->setAddonsURL(m_news_filename);

// Initialise the online portion of the addons manager.
if(UserConfigParams::logAddons())
Expand All @@ -167,10 +168,10 @@ void* NewsManager::downloadNews(void *obj)

// We need a new object, since the state of the old
// download request is now done.
download_req = new HTTPRequest("news.xml");
download_req = new HTTPRequest(m_news_filename);

// make sure the new server address is actually used
download_req->setAddonsURL("news.xml");
download_req->setAddonsURL(m_news_filename);
download_req->executeNow();

if(download_req->hadDownloadError())
Expand Down
3 changes: 3 additions & 0 deletions src/addons/news_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class NewsManager : public CanBeDeleted
bool isImportant() const { return m_important; }
}; // NewsMessage

/** The name of the news file on the remote server */
static std::string m_news_filename;

mutable Synchronised< std::vector<NewsMessage> > m_news;

/** Index of the current news message that is being displayed. */
Expand Down

0 comments on commit deba8d3

Please sign in to comment.