From 05cec243c28f50bd5ee7a167067501f7bd8db3ff Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 5 May 2014 17:23:21 +0300 Subject: Validate xml downloads, and if failed, use another mirror. --- src/net/download.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/net/download.cpp') diff --git a/src/net/download.cpp b/src/net/download.cpp index 26a3cfe58..e1b5012fd 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -60,9 +60,12 @@ namespace Net std::string Download::mUploadResponse = ""; -Download::Download(void *const ptr, const std::string &url, +Download::Download(void *const ptr, + const std::string &url, const DownloadUpdate updateFunction, - const bool ignoreError, const bool isUpload) : + const bool ignoreError, + const bool isUpload, + const bool isXml) : mPtr(ptr), mUrl(url), mOptions(), @@ -77,7 +80,8 @@ Download::Download(void *const ptr, const std::string &url, mFormPost(nullptr), mError(static_cast(calloc(CURL_ERROR_SIZE + 1, 1))), mIgnoreError(ignoreError), - mUpload(isUpload) + mUpload(isUpload), + mIsXml(isXml) { if (mError) mError[0] = 0; @@ -417,6 +421,7 @@ int Download::downloadThread(void *ptr) continue; // Bail out here to avoid the renaming } } + if (file) { fclose(file); @@ -427,6 +432,16 @@ int Download::downloadThread(void *ptr) // otherwise the rename will fail on Windows. if (!d->mOptions.cancel) { + if (d->mIsXml) + { + if (!XML::Document::validateXml(outFilename)) + { + logger->log_r("Xml file validation error"); + attempts++; + continue; + } + } + ::remove(d->mFileName.c_str()); Files::renameFile(outFilename, d->mFileName); -- cgit v1.2.3-60-g2f50