diff --git a/ChangeLog b/ChangeLog index bd404ef0..2531af5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19573,3 +19573,5 @@ * Added a 'delete_test' test harness. 2020-02-20 Fred Gleason * Rebased 'RDUpload' to 'RDTransfer'. +2020-02-20 Fred Gleason + * Rebased 'RDDownload' to 'RDTransfer'. diff --git a/lib/rddownload.cpp b/lib/rddownload.cpp index 3b425e23..564fde66 100644 --- a/lib/rddownload.cpp +++ b/lib/rddownload.cpp @@ -69,14 +69,27 @@ int DownloadErrorCallback(CURL *curl,curl_infotype type,char *msg,size_t size, } -RDDownload::RDDownload(RDConfig *config,QObject *parent) - : QObject(parent) +RDDownload::RDDownload(RDConfig *c,QObject *parent) + : RDTransfer(c,parent) { - conv_config=config; conv_aborting=false; } +QStringList RDDownload::supportedSchemes() const +{ + QStringList schemes; + + schemes.push_back("file"); + schemes.push_back("ftp"); + schemes.push_back("http"); + schemes.push_back("https"); + schemes.push_back("sftp"); + + return schemes; +} + + void RDDownload::setSourceUrl(const QString &url) { conv_src_url=url; @@ -107,8 +120,10 @@ RDDownload::ErrorCode RDDownload::runDownload(const QString &username, long response_code=0; RDDownload::ErrorCode ret=RDDownload::ErrorOk; RDSystemUser *user=NULL; - // char url[1024]; - char userpwd[256]; + + if(!urlIsSupported(conv_src_url)) { + return RDDownload::ErrorUnsupportedProtocol; + } // // Validate User for file: transfers @@ -140,17 +155,17 @@ RDDownload::ErrorCode RDDownload::runDownload(const QString &username, // url.replace("#","%23"); - curl_easy_setopt(curl,CURLOPT_URL,(const char *)url); + curl_easy_setopt(curl,CURLOPT_URL,url.constData()); curl_easy_setopt(curl,CURLOPT_WRITEDATA,f); - strncpy(userpwd,(username+":"+password).utf8(),256); - curl_easy_setopt(curl,CURLOPT_USERPWD,userpwd); + curl_easy_setopt(curl,CURLOPT_USERNAME,username.toUtf8().constData()); + curl_easy_setopt(curl,CURLOPT_PASSWORD,password.toUtf8().constData()); curl_easy_setopt(curl,CURLOPT_TIMEOUT,RD_CURL_TIMEOUT); curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,1); curl_easy_setopt(curl,CURLOPT_PROGRESSFUNCTION,DownloadProgressCallback); curl_easy_setopt(curl,CURLOPT_PROGRESSDATA,this); curl_easy_setopt(curl,CURLOPT_NOPROGRESS,0); curl_easy_setopt(curl,CURLOPT_USERAGENT, - (const char *)conv_config->userAgent().utf8()); + config()->userAgent().toUtf8().constData()); if(log_debug) { curl_easy_setopt(curl,CURLOPT_VERBOSE,1); curl_easy_setopt(curl,CURLOPT_DEBUGFUNCTION,DownloadErrorCallback); diff --git a/lib/rddownload.h b/lib/rddownload.h index 8db7533d..4e25dfaf 100644 --- a/lib/rddownload.h +++ b/lib/rddownload.h @@ -21,12 +21,12 @@ #ifndef RDDOWNLOAD_H #define RDDOWNLOAD_H -#include #include #include +#include -class RDDownload : public QObject +class RDDownload : public RDTransfer { Q_OBJECT; public: @@ -37,6 +37,7 @@ class RDDownload : public QObject ErrorInvalidLogin=11,ErrorRemoteAccess=12, ErrorRemoteConnection=13}; RDDownload(RDConfig *config,QObject *parent=0); + QStringList supportedSchemes() const; void setSourceUrl(const QString &url); void setDestinationFile(const QString &filename); int totalSteps() const; @@ -60,7 +61,6 @@ class RDDownload : public QObject QString conv_dst_filename; bool conv_aborting; uint conv_dst_size; - RDConfig *conv_config; };