2020-01-10 Fred Gleason <fredg@paravelsystems.com>

* Removed all Qt3Support dependencies from the 'RDUpload' class.
	* Removed all Qt3Support dependencies from the 'RDDownload' class.
	* Added a 'test_download' test harness.
This commit is contained in:
Fred Gleason 2020-01-10 17:06:36 -05:00
parent aa7a2ab01d
commit d32aa115f7
9 changed files with 192 additions and 22 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -19400,3 +19400,7 @@
configuration of the 'pypad_xds.py' PyPAD script.
2020-01-08 Fred Gleason <fredg@paravelsystems.com>
* Incremented the package version to 3.2.0int10.
2020-01-10 Fred Gleason <fredg@paravelsystems.com>
* Removed all Qt3Support dependencies from the 'RDUpload' class.
* Removed all Qt3Support dependencies from the 'RDDownload' class.
* Added a 'test_download' test harness.

View File

@ -2,7 +2,7 @@
//
// Download a File
//
// (C) Copyright 2010-2019 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2010-2020 Fred Gleason <fredg@paravelsystems.com>
//
// 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);

View File

@ -2,7 +2,7 @@
//
// Download a File
//
// (C) Copyright 2010,2016-2017 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2010-2020 Fred Gleason <fredg@paravelsystems.com>
//
// 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 <qobject.h>
#include <q3url.h>
#include <qurl.h>
#include <rdconfig.h>
@ -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;

View File

@ -2,7 +2,7 @@
//
// Upload a File
//
// (C) Copyright 2010-2019 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2010-2020 Fred Gleason <fredg@paravelsystems.com>
//
// 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);

View File

@ -2,7 +2,7 @@
//
// Upload a File
//
// (C) Copyright 2010,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2010-2020 Fred Gleason <fredg@paravelsystems.com>
//
// 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 <qobject.h>
#include <q3url.h>
#include <qurl.h>
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;
};

View File

@ -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

110
tests/download_test.cpp Normal file
View File

@ -0,0 +1,110 @@
// download_test.cpp
//
// Test Rivendell file downloading.
//
// (C) Copyright 2010-2020 Fred Gleason <fredg@paravelsystems.com>
//
// 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 <stdlib.h>
#include <qapplication.h>
#include <rdapplication.h>
#include <rddb.h>
//#include <rdcmd_switch.h>
#include <rddownload.h>
#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;i<rda->cmdSwitch()->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();
}

43
tests/download_test.h Normal file
View File

@ -0,0 +1,43 @@
// download_test.h
//
// Test Rivendell file downloading
//
// (C) Copyright 2010-2020 Fred Gleason <fredg@paravelsystems.com>
//
// 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 <list>
#include <qobject.h>
#define DOWNLOAD_TEST_USAGE "[options]\n\nTest the Rivendell download routines\n\nOptions are:\n--username=<username>\n\n--password=<password>\n\n--source-url=<url>\n\n--destination-file=<filename>\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