2022-09-06 Fred Gleason <fredg@paravelsystems.com>

* Added code to the podcasting subsystem to log extended curl(1)
	information to syslog.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2022-09-06 14:51:00 -04:00
parent e28f72677b
commit ba0374ee17
5 changed files with 128 additions and 16 deletions

View File

@@ -2,7 +2,7 @@
//
// Abstract a Rivendell Podcast
//
// (C) Copyright 2002-2020 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2022 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
@@ -36,20 +36,15 @@
//
// CURL Callbacks
//
int PodcastErrorCallback(CURL *curl,curl_infotype type,char *msg,size_t size,
void *clientp)
int __RDPodcast_Debug_Callback(CURL *handle,curl_infotype type,char *data,
size_t size,void *userptr)
{
char str[1000];
QStringList *lines=(QStringList *)userptr;
if(type!=CURLINFO_TEXT) {
return 0;
if(type==CURLINFO_TEXT) {
lines->push_back(QString::fromUtf8(QByteArray(data,size)));
}
if(size>999) {
size=999;
}
memset(&str,0,size+1);
memcpy(str,msg,size);
rda->syslog(LOG_DEBUG,"CURL MSG: %s",str);
return 0;
}
@@ -376,6 +371,7 @@ bool RDPodcast::removePodcast() const
long response_code;
CURL *curl=NULL;
CURLcode curl_err;
QStringList *err_msgs=NULL;
struct curl_httppost *first=NULL;
struct curl_httppost *last=NULL;
@@ -404,6 +400,7 @@ bool RDPodcast::removePodcast() const
curl_formfree(first);
return false;
}
err_msgs=SetupCurlLogging(curl);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,stdout);
curl_easy_setopt(curl,CURLOPT_HTTPPOST,first);
curl_easy_setopt(curl,CURLOPT_USERAGENT,
@@ -421,6 +418,7 @@ bool RDPodcast::removePodcast() const
if((curl_err=curl_easy_perform(curl))!=CURLE_OK) {
curl_easy_cleanup(curl);
curl_formfree(first);
ProcessCurlLogging("RDPodcast::removePodcast()",err_msgs);
return false;
}
@@ -435,8 +433,10 @@ bool RDPodcast::removePodcast() const
// Process the results
//
if((response_code<200)||(response_code>299)) {
ProcessCurlLogging("RDPodcast::removePodcast()",err_msgs);
return false;
}
delete err_msgs;
return true;
}
@@ -461,6 +461,7 @@ bool RDPodcast::DeletePodcast(unsigned cast_id) const
long response_code;
CURL *curl=NULL;
CURLcode curl_err;
QStringList *err_msgs=NULL;
struct curl_httppost *first=NULL;
struct curl_httppost *last=NULL;
@@ -489,6 +490,7 @@ bool RDPodcast::DeletePodcast(unsigned cast_id) const
curl_formfree(first);
return false;
}
err_msgs=SetupCurlLogging(curl);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,stdout);
curl_easy_setopt(curl,CURLOPT_HTTPPOST,first);
curl_easy_setopt(curl,CURLOPT_USERAGENT,
@@ -506,6 +508,7 @@ bool RDPodcast::DeletePodcast(unsigned cast_id) const
if((curl_err=curl_easy_perform(curl))!=CURLE_OK) {
curl_easy_cleanup(curl);
curl_formfree(first);
ProcessCurlLogging("RDPodcast::",err_msgs);
return false;
}
@@ -520,13 +523,43 @@ bool RDPodcast::DeletePodcast(unsigned cast_id) const
// Process the results
//
if((response_code<200)||(response_code>299)) {
ProcessCurlLogging("RDPodcast::",err_msgs);
return false;
}
delete err_msgs;
return true;
}
QStringList *RDPodcast::SetupCurlLogging(CURL *curl) const
{
QStringList *err_msgs=new QStringList();
curl_easy_setopt(curl,CURLOPT_DEBUGFUNCTION,__RDPodcast_Debug_Callback);
curl_easy_setopt(curl,CURLOPT_DEBUGDATA,err_msgs);
curl_easy_setopt(curl,CURLOPT_VERBOSE,1);
return err_msgs;
}
void RDPodcast::ProcessCurlLogging(const QString &label,
QStringList *err_msgs) const
{
if(err_msgs->size()>0) {
rda->syslog(LOG_ERR,"*** %s: extended CURL information begins ***",
label.toUtf8().constData());
for(int i=0;i<err_msgs->size();i++) {
rda->syslog(LOG_ERR,"[%d]: %s",i,err_msgs->at(i).toUtf8().constData());
}
rda->syslog(LOG_ERR,"*** %s: extended CURL information ends ***",
label.toUtf8().constData());
}
delete err_msgs;
}
void RDPodcast::SetRow(const QString &param,int value) const
{
QString sql;