From d32aa115f7ac35ab4ceb97899e03a42cacb8dc99 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Fri, 10 Jan 2020 17:06:36 -0500 Subject: [PATCH] 2020-01-10 Fred Gleason * Removed all Qt3Support dependencies from the 'RDUpload' class. * Removed all Qt3Support dependencies from the 'RDDownload' class. * Added a 'test_download' test harness. --- .gitignore | 1 + ChangeLog | 4 ++ lib/rddownload.cpp | 21 +++++--- lib/rddownload.h | 6 +-- lib/rdupload.cpp | 19 ++++--- lib/rdupload.h | 6 +-- tests/Makefile.am | 4 ++ tests/download_test.cpp | 110 ++++++++++++++++++++++++++++++++++++++++ tests/download_test.h | 43 ++++++++++++++++ 9 files changed, 192 insertions(+), 22 deletions(-) create mode 100644 tests/download_test.cpp create mode 100644 tests/download_test.h diff --git a/.gitignore b/.gitignore index 6a5c5ba3..ca1fd243 100644 --- a/.gitignore +++ b/.gitignore @@ -108,6 +108,7 @@ tests/audio_peaks_test tests/datedecode_test tests/dateparse_test tests/db_charset_test +tests/download_test tests/getpids_test tests/log_unlink_test tests/mcast_recv_test diff --git a/ChangeLog b/ChangeLog index 642602d3..3d43c46f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19400,3 +19400,7 @@ configuration of the 'pypad_xds.py' PyPAD script. 2020-01-08 Fred Gleason * Incremented the package version to 3.2.0int10. +2020-01-10 Fred Gleason + * Removed all Qt3Support dependencies from the 'RDUpload' class. + * Removed all Qt3Support dependencies from the 'RDDownload' class. + * Added a 'test_download' test harness. diff --git a/lib/rddownload.cpp b/lib/rddownload.cpp index d131287c..3b425e23 100644 --- a/lib/rddownload.cpp +++ b/lib/rddownload.cpp @@ -2,7 +2,7 @@ // // Download a File // -// (C) Copyright 2010-2019 Fred Gleason +// (C) Copyright 2010-2020 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -107,7 +107,7 @@ RDDownload::ErrorCode RDDownload::runDownload(const QString &username, long response_code=0; RDDownload::ErrorCode ret=RDDownload::ErrorOk; RDSystemUser *user=NULL; - char url[1024]; + // char url[1024]; char userpwd[256]; // @@ -128,14 +128,19 @@ RDDownload::ErrorCode RDDownload::runDownload(const QString &username, curl_easy_cleanup(curl); return RDDownload::ErrorNoDestination; } + // - // Write out URL as a C string before passing to curl_easy_setopt(), - // otherwise some versions of LibCurl will throw a 'bad/illegal format' - // error. + // Write out an encoded URL // - strncpy(url,conv_src_url. - toString(conv_src_url.protocol().lower().left(4)=="http").utf8(),1024); - curl_easy_setopt(curl,CURLOPT_URL,url); + QByteArray url=conv_src_url.toEncoded(QUrl::RemoveUserInfo); + + // + // An URL anchor element will never occur here, so treat any '#' + // characters as part of the path. + // + url.replace("#","%23"); + + curl_easy_setopt(curl,CURLOPT_URL,(const char *)url); curl_easy_setopt(curl,CURLOPT_WRITEDATA,f); strncpy(userpwd,(username+":"+password).utf8(),256); curl_easy_setopt(curl,CURLOPT_USERPWD,userpwd); diff --git a/lib/rddownload.h b/lib/rddownload.h index ddca6225..8db7533d 100644 --- a/lib/rddownload.h +++ b/lib/rddownload.h @@ -2,7 +2,7 @@ // // Download a File // -// (C) Copyright 2010,2016-2017 Fred Gleason +// (C) Copyright 2010-2020 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -22,7 +22,7 @@ #define RDDOWNLOAD_H #include -#include +#include #include @@ -56,7 +56,7 @@ class RDDownload : public QObject void UpdateProgress(int step); friend int DownloadProgressCallback(void *clientp,double dltotal,double dlnow, double ultotal,double ulnow); - Q3Url conv_src_url; + QUrl conv_src_url; QString conv_dst_filename; bool conv_aborting; uint conv_dst_size; diff --git a/lib/rdupload.cpp b/lib/rdupload.cpp index 85dbfadb..3a635e94 100644 --- a/lib/rdupload.cpp +++ b/lib/rdupload.cpp @@ -2,7 +2,7 @@ // // Upload a File // -// (C) Copyright 2010-2019 Fred Gleason +// (C) Copyright 2010-2020 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -107,7 +107,6 @@ RDUpload::ErrorCode RDUpload::runUpload(const QString &username, FILE *f; RDUpload::ErrorCode ret=RDUpload::ErrorOk; RDSystemUser *user=NULL; - char url[1024]; char userpwd[256]; // @@ -130,13 +129,17 @@ RDUpload::ErrorCode RDUpload::runUpload(const QString &username, } // - // Write out URL as a C string before passing to curl_easy_setopt(), - // otherwise some versions of LibCurl will throw a 'bad/illegal format' - // error. + // Write out an encoded URL // - strncpy(url,conv_dst_url.toString(conv_dst_url.protocol().lower()=="http").utf8(), - 1024); - curl_easy_setopt(curl,CURLOPT_URL,url); + QByteArray url=conv_dst_url.toEncoded(QUrl::RemoveUserInfo); + + // + // An URL anchor element will never occur here, so treat any '#' + // characters as part of the path. + // + url.replace("#","%23"); + + curl_easy_setopt(curl,CURLOPT_URL,(const char *)url); curl_easy_setopt(curl,CURLOPT_UPLOAD,1); curl_easy_setopt(curl,CURLOPT_READDATA,f); curl_easy_setopt(curl,CURLOPT_INFILESIZE,(long)conv_src_size); diff --git a/lib/rdupload.h b/lib/rdupload.h index ff77b4cf..babba14c 100644 --- a/lib/rdupload.h +++ b/lib/rdupload.h @@ -2,7 +2,7 @@ // // Upload a File // -// (C) Copyright 2010,2016-2018 Fred Gleason +// (C) Copyright 2010-2020 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -22,7 +22,7 @@ #define RDUPLOAD_H #include -#include +#include class RDUpload : public QObject { @@ -55,7 +55,7 @@ class RDUpload : public QObject friend int UploadProgressCallback(void *clientp,double dltotal,double dlnow, double ultotal,double ulnow); QString conv_src_filename; - Q3Url conv_dst_url; + QUrl conv_dst_url; bool conv_aborting; uint conv_src_size; }; diff --git a/tests/Makefile.am b/tests/Makefile.am index b884b77f..fbaa1002 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -34,6 +34,7 @@ noinst_PROGRAMS = audio_convert_test\ datedecode_test\ dateparse_test\ db_charset_test\ + download_test\ getpids_test\ log_unlink_test\ mcast_recv_test\ @@ -71,6 +72,9 @@ dateparse_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ -lQt3Support dist_db_charset_test_SOURCES = db_charset_test.cpp db_charset_test.h db_charset_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ -lQt3Support +dist_download_test_SOURCES = download_test.cpp download_test.h +download_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ -lQt3Support + dist_getpids_test_SOURCES = getpids_test.cpp getpids_test.h getpids_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ -lQt3Support diff --git a/tests/download_test.cpp b/tests/download_test.cpp new file mode 100644 index 00000000..61b94bf3 --- /dev/null +++ b/tests/download_test.cpp @@ -0,0 +1,110 @@ +// download_test.cpp +// +// Test Rivendell file downloading. +// +// (C) Copyright 2010-2020 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#include + +#include + +#include +#include +//#include +#include + +#include "download_test.h" + +MainObject::MainObject(QObject *parent) + :QObject(parent) +{ + QString err_msg; + + username=""; + password=""; + RDDownload::ErrorCode conv_err; + + // + // Open the Database + // + rda=new RDApplication("download_test","download_test",DOWNLOAD_TEST_USAGE,this); + if(!rda->open(&err_msg)) { + fprintf(stderr,"download_test: %s\n",(const char *)err_msg); + exit(1); + } + + // + // Read Command Options + // + for(unsigned i=0;icmdSwitch()->keys();i++) { + if(rda->cmdSwitch()->key(i)=="--username") { + username=rda->cmdSwitch()->value(i); + rda->cmdSwitch()->setProcessed(i,true); + } + if(rda->cmdSwitch()->key(i)=="--password") { + password=rda->cmdSwitch()->value(i); + rda->cmdSwitch()->setProcessed(i,true); + } + if(rda->cmdSwitch()->key(i)=="--source-url") { + source_url=rda->cmdSwitch()->value(i); + rda->cmdSwitch()->setProcessed(i,true); + } + if(rda->cmdSwitch()->key(i)=="--destination-filename") { + destination_filename=rda->cmdSwitch()->value(i); + rda->cmdSwitch()->setProcessed(i,true); + } + if(!rda->cmdSwitch()->processed(i)) { + fprintf(stderr,"download_test: unknown command option \"%s\"\n", + (const char *)rda->cmdSwitch()->key(i)); + exit(2); + } + } + + // + // Sanity Checks + // + if(source_url.isEmpty()) { + fprintf(stderr,"download_test: missing source-url\n"); + exit(256); + } + if(destination_filename.isEmpty()) { + fprintf(stderr,"download_test: missing destination-filename\n"); + exit(256); + } + + // + // Run the Test + // + RDDownload *conv=new RDDownload(rda->config(),this); + conv->setSourceUrl(source_url); + conv->setDestinationFile(destination_filename); + printf("Downloading...\n"); + conv_err=conv-> + runDownload(username,password,rda->config()->logXloadDebugData()); + printf("Result: %s\n",(const char *)RDDownload::errorText(conv_err)); + delete conv; + + exit(0); +} + + +int main(int argc,char *argv[]) +{ + QApplication a(argc,argv,false); + new MainObject(); + return a.exec(); +} diff --git a/tests/download_test.h b/tests/download_test.h new file mode 100644 index 00000000..5b98e225 --- /dev/null +++ b/tests/download_test.h @@ -0,0 +1,43 @@ +// download_test.h +// +// Test Rivendell file downloading +// +// (C) Copyright 2010-2020 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#ifndef DOWNLOAD_TEST_H +#define DOWNLOAD_TEST_H + +#include + +#include + +#define DOWNLOAD_TEST_USAGE "[options]\n\nTest the Rivendell download routines\n\nOptions are:\n--username=\n\n--password=\n\n--source-url=\n\n--destination-file=\n\n" + +class MainObject : public QObject +{ + public: + MainObject(QObject *parent=0); + + private: + QString username; + QString password; + QString source_url; + QString destination_filename; +}; + + +#endif // DOWNLOAD_TEST_H