summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-03-27 23:13:46 +0300
committerAndrei Karas <akaras@inbox.ru>2013-03-27 23:13:46 +0300
commit2a16d37f9b1a8e009aab482b8a003a224f81a31a (patch)
treeb2ab0df9f57d3d70ade95f80601351b10c456a42 /src/net
parent0fe0f8bae7b754453e6e6bb7c7b29903facb9311 (diff)
downloadplus-2a16d37f9b1a8e009aab482b8a003a224f81a31a.tar.gz
plus-2a16d37f9b1a8e009aab482b8a003a224f81a31a.tar.bz2
plus-2a16d37f9b1a8e009aab482b8a003a224f81a31a.tar.xz
plus-2a16d37f9b1a8e009aab482b8a003a224f81a31a.zip
improve download class.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/download.cpp33
-rw-r--r--src/net/download.h17
2 files changed, 26 insertions, 24 deletions
diff --git a/src/net/download.cpp b/src/net/download.cpp
index 2124736ca..a4ca23198 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -51,8 +51,9 @@ enum
namespace Net
{
-Download::Download(void *ptr, const std::string &url,
- DownloadUpdate updateFunction, bool ignoreError) :
+Download::Download(void *const ptr, const std::string &url,
+ const DownloadUpdate updateFunction,
+ const bool ignoreError) :
mPtr(ptr),
mUrl(url),
mFileName(""),
@@ -88,14 +89,14 @@ Download::~Download()
/**
* Calculates the Alder-32 checksum for the given file.
*/
-unsigned long Download::fadler32(FILE *file)
+unsigned long Download::fadler32(FILE *const file)
{
if (!file)
return 0;
// Obtain file size
fseek(file, 0, SEEK_END);
- long fileSize = ftell(file);
+ const long fileSize = ftell(file);
if (fileSize < 0)
{ // file size error
return 0;
@@ -103,7 +104,7 @@ unsigned long Download::fadler32(FILE *file)
rewind(file);
// Calculate Adler-32 checksum
- char *buffer = static_cast<char*>(malloc(fileSize));
+ char *const buffer = static_cast<char*>(malloc(fileSize));
const uInt read = static_cast<uInt>(fread(buffer, 1, fileSize, file));
unsigned long adler = adler32(0L, Z_NULL, 0);
adler = adler32(static_cast<uInt>(adler),
@@ -124,7 +125,7 @@ void Download::noCache()
addHeader("Cache-Control: no-cache");
}
-void Download::setFile(const std::string &filename, int64_t adler32)
+void Download::setFile(const std::string &filename, const int64_t adler32)
{
mOptions.memoryWrite = 0;
mFileName = filename;
@@ -175,7 +176,7 @@ void Download::cancel()
mThread = nullptr;
}
-char *Download::getError()
+char *Download::getError() const
{
return mError;
}
@@ -183,7 +184,7 @@ char *Download::getError()
int Download::downloadProgress(void *clientp, double dltotal, double dlnow,
double ultotal A_UNUSED, double ulnow A_UNUSED)
{
- Download *d = reinterpret_cast<Download*>(clientp);
+ Download *const d = reinterpret_cast<Download *const>(clientp);
if (!d)
return -5;
@@ -203,19 +204,17 @@ int Download::downloadThread(void *ptr)
{
int attempts = 0;
bool complete = false;
- Download *d = reinterpret_cast<Download*>(ptr);
+ Download *const d = reinterpret_cast<Download*>(ptr);
CURLcode res;
- std::string outFilename;
if (!d)
return 0;
- if (!d->mOptions.memoryWrite)
- outFilename = d->mFileName + ".part";
+ const std::string outFilename = !d->mOptions.memoryWrite
+ ? (d->mFileName + ".part") : "";
while (attempts < 3 && !complete && !d->mOptions.cancel)
{
-
d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_STARTING, 0, 0);
if (d->mOptions.cancel)
@@ -305,7 +304,7 @@ int Download::downloadThread(void *ptr)
// Don't check resources.xml checksum
if (d->mOptions.checkAdler)
{
- unsigned long adler = fadler32(file);
+ const unsigned long adler = fadler32(file);
if (d->mAdler != adler)
{
@@ -387,7 +386,7 @@ int Download::downloadThread(void *ptr)
return 0;
}
-void Download::addProxy(CURL *curl)
+void Download::addProxy(CURL *const curl)
{
const int mode = config.getIntValue("downloadProxyType");
if (!mode)
@@ -433,12 +432,14 @@ void Download::addProxy(CURL *curl)
}
}
-void Download::secureCurl(CURL *curl)
+void Download::secureCurl(CURL *const curl)
{
curl_easy_setopt(curl, CURLOPT_PROTOCOLS,
CURLPROTO_HTTP | CURLPROTO_HTTPS);
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS,
CURLPROTO_HTTP | CURLPROTO_HTTPS);
+ curl_easy_setopt(curl, CURLOPT_WILDCARDMATCH, 0);
+ curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3);
}
} // namespace Net
diff --git a/src/net/download.h b/src/net/download.h
index f9f842588..53ecf4171 100644
--- a/src/net/download.h
+++ b/src/net/download.h
@@ -56,8 +56,9 @@ namespace Net
class Download final
{
public:
- Download(void *ptr, const std::string &url,
- DownloadUpdate updateFunction, bool ignoreError = false);
+ Download(void *const ptr, const std::string &url,
+ const DownloadUpdate updateFunction,
+ const bool ignoreError = false);
A_DELETE_COPY(Download)
@@ -70,7 +71,7 @@ class Download final
*/
void noCache();
- void setFile(const std::string &filename, int64_t adler32 = -1);
+ void setFile(const std::string &filename, const int64_t adler32 = -1);
void setWriteFunction(WriteFunction write);
@@ -88,16 +89,16 @@ class Download final
*/
void cancel();
- char *getError() A_WARN_UNUSED;
+ char *getError() const A_WARN_UNUSED;
- void setIgnoreError(bool n)
+ void setIgnoreError(const bool n)
{ mIgnoreError = n; }
- static unsigned long fadler32(FILE *file) A_WARN_UNUSED;
+ static unsigned long fadler32(FILE *const file) A_WARN_UNUSED;
- static void addProxy(CURL *curl);
+ static void addProxy(CURL *const curl);
- static void secureCurl(CURL *curl);
+ static void secureCurl(CURL *const curl);
private:
static int downloadThread(void *ptr);