summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-05 17:23:21 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-06 13:06:50 +0300
commit05cec243c28f50bd5ee7a167067501f7bd8db3ff (patch)
treeb3b4e97b873ebf5e082ee1092a4c33a1ebdd72b8 /src/net
parent25bed1bb7f7dbfa3caa0f239c63dbabd3b0bd50d (diff)
downloadplus-05cec243c28f50bd5ee7a167067501f7bd8db3ff.tar.gz
plus-05cec243c28f50bd5ee7a167067501f7bd8db3ff.tar.bz2
plus-05cec243c28f50bd5ee7a167067501f7bd8db3ff.tar.xz
plus-05cec243c28f50bd5ee7a167067501f7bd8db3ff.zip
Validate xml downloads, and if failed, use another mirror.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/download.cpp21
-rw-r--r--src/net/download.h8
2 files changed, 24 insertions, 5 deletions
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<char*>(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);
diff --git a/src/net/download.h b/src/net/download.h
index 2201aaff2..bc12a8f7c 100644
--- a/src/net/download.h
+++ b/src/net/download.h
@@ -55,9 +55,12 @@ namespace Net
class Download final
{
public:
- Download(void *const ptr, const std::string &url,
+ 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);
A_DELETE_COPY(Download)
@@ -141,6 +144,7 @@ class Download final
char *mError;
bool mIgnoreError;
bool mUpload;
+ bool mIsXml;
};
} // namespace Net