mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-12-30 00:18:50 +01:00
2020-09-23 Fred Gleason <fredg@paravelsystems.com>
* Added 'RD_PostRss()' and 'RD_RemoveRss()' calls to the rivwebcapi API. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
@@ -53,9 +53,11 @@ dist_librivwebcapi_la_SOURCES = rd_addcart.c rd_addcart.h \
|
||||
rd_listschedcodes.c rd_listschedcodes.h \
|
||||
rd_listsystemsettings.c rd_listsystemsettings.h \
|
||||
rd_postimage.c rd_postimage.h \
|
||||
rd_postrss.c rd_postrss.h \
|
||||
rd_removecart.c rd_removecart.h \
|
||||
rd_removecut.c rd_removecut.h \
|
||||
rd_removeimage.c rd_removeimage.h \
|
||||
rd_removerss.c rd_removerss.h \
|
||||
rd_savelog.c rd_savelog.h \
|
||||
rd_trimaudio.c rd_trimaudio.h \
|
||||
rd_unassignschedcode.c rd_unassignschedcode.h
|
||||
@@ -99,11 +101,13 @@ include_HEADERS = rd_addcart.h\
|
||||
rd_listservices.h\
|
||||
rd_listsystemsettings.h \
|
||||
rd_postimage.h \
|
||||
rd_postrss.h \
|
||||
rd_savelog.h\
|
||||
rd_schedcodes.h\
|
||||
rd_removecart.h\
|
||||
rd_removecut.h\
|
||||
rd_removeimage.h\
|
||||
rd_removerss.h\
|
||||
rd_trimaudio.h\
|
||||
rd_unassignschedcode.h
|
||||
|
||||
|
||||
197
apis/rivwebcapi/rivwebcapi/rd_postrss.c
Normal file
197
apis/rivwebcapi/rivwebcapi/rd_postrss.c
Normal file
@@ -0,0 +1,197 @@
|
||||
/* rd_postrss.c
|
||||
*
|
||||
* Implementation of the Post Image Rivendell Access Library
|
||||
*
|
||||
* (C) Copyright 2015 Todd Baker <bakert@rfa.org>
|
||||
* (C) Copyright 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 <string.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <expat.h>
|
||||
|
||||
#include "rd_postrss.h"
|
||||
#include "rd_common.h"
|
||||
#include "rd_getuseragent.h"
|
||||
|
||||
struct xml_data {
|
||||
char elem_name[256];
|
||||
char strbuf[1024];
|
||||
};
|
||||
|
||||
static void XMLCALL __PostRssElementStart(void *data, const char *el,
|
||||
const char **attr)
|
||||
{
|
||||
struct xml_data *xml_data=(struct xml_data *)data;
|
||||
strlcpy(xml_data->elem_name,el,256);
|
||||
memset(xml_data->strbuf,0,1024);
|
||||
}
|
||||
|
||||
static void XMLCALL __PostRssElementData(void *data,const XML_Char *s,
|
||||
int len)
|
||||
{
|
||||
struct xml_data *xml_data=(struct xml_data *)data;
|
||||
|
||||
memcpy(xml_data->strbuf+strlen(xml_data->strbuf),s,len);
|
||||
}
|
||||
|
||||
static void XMLCALL __PostRssElementEnd(void *data, const char *el)
|
||||
{
|
||||
struct xml_data *xml_data=(struct xml_data *)data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
size_t __PostRssCallback(void *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
XML_Parser p=(XML_Parser)userdata;
|
||||
|
||||
XML_Parse(p,ptr,size*nmemb,0);
|
||||
|
||||
return size*nmemb;
|
||||
}
|
||||
|
||||
|
||||
int RD_PostRss( const char hostname[],
|
||||
const char username[],
|
||||
const char passwd[],
|
||||
const char ticket[],
|
||||
const unsigned feed_id,
|
||||
const char user_agent[])
|
||||
{
|
||||
char post[1500];
|
||||
char url[1500];
|
||||
CURL *curl=NULL;
|
||||
XML_Parser parser;
|
||||
struct xml_data xml_data;
|
||||
long response_code;
|
||||
char errbuf[CURL_ERROR_SIZE];
|
||||
CURLcode res;
|
||||
char user_agent_string[255];
|
||||
char id_buffer[21];
|
||||
struct curl_httppost *first=NULL;
|
||||
struct curl_httppost *last=NULL;
|
||||
|
||||
if((curl=curl_easy_init())==NULL) {
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup the CURL call
|
||||
*/
|
||||
memset(&xml_data,0,sizeof(xml_data));
|
||||
parser=XML_ParserCreate(NULL);
|
||||
XML_SetUserData(parser,&xml_data);
|
||||
XML_SetElementHandler(parser,__PostRssElementStart,
|
||||
__PostRssElementEnd);
|
||||
XML_SetCharacterDataHandler(parser,__PostRssElementData);
|
||||
snprintf(url,1500,"http://%s/rd-bin/rdxport.cgi",hostname);
|
||||
|
||||
curl_formadd(&first,
|
||||
&last,
|
||||
CURLFORM_PTRNAME,
|
||||
"COMMAND",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
"42",
|
||||
CURLFORM_END);
|
||||
|
||||
curl_formadd(&first,
|
||||
&last,
|
||||
CURLFORM_PTRNAME,
|
||||
"LOGIN_NAME",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
username,
|
||||
CURLFORM_END);
|
||||
|
||||
curl_formadd(&first,
|
||||
&last,
|
||||
CURLFORM_PTRNAME,
|
||||
"PASSWORD",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
passwd,
|
||||
CURLFORM_END);
|
||||
|
||||
curl_formadd(&first,
|
||||
&last,
|
||||
CURLFORM_PTRNAME,
|
||||
"TICKET",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
ticket,
|
||||
CURLFORM_END);
|
||||
|
||||
snprintf(id_buffer,21,"%u",feed_id);
|
||||
curl_formadd(&first,
|
||||
&last,
|
||||
CURLFORM_PTRNAME,
|
||||
"ID",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
id_buffer,
|
||||
CURLFORM_END);
|
||||
|
||||
curl_easy_setopt(curl,CURLOPT_WRITEDATA,parser);
|
||||
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,__PostRssCallback);
|
||||
curl_easy_setopt(curl,CURLOPT_URL,url);
|
||||
curl_easy_setopt(curl,CURLOPT_POST,1);
|
||||
curl_easy_setopt(curl,CURLOPT_HTTPPOST,first);
|
||||
curl_easy_setopt(curl,CURLOPT_NOPROGRESS,1);
|
||||
curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,errbuf);
|
||||
// curl_easy_setopt(curl,CURLOPT_VERBOSE,1);
|
||||
|
||||
// Check if User Agent Present otherwise set to default
|
||||
if (strlen(user_agent)> 0){
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT,user_agent);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(user_agent_string, RD_GetUserAgent());
|
||||
strcat(user_agent_string,VERSION);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT,user_agent_string);
|
||||
}
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
if(res != CURLE_OK) {
|
||||
#ifdef RIVC_DEBUG_OUT
|
||||
size_t len = strlen(errbuf);
|
||||
fprintf(stderr, "\nlibcurl error: (%d)", res);
|
||||
if (len)
|
||||
fprintf(stderr, "%s%s", errbuf,
|
||||
((errbuf[len-1] != '\n') ? "\n" : ""));
|
||||
else
|
||||
fprintf(stderr, "%s\n", curl_easy_strerror(res));
|
||||
#endif
|
||||
curl_formfree(first);
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
/* The response OK - so figure out if we got what we wanted.. */
|
||||
|
||||
curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response_code);
|
||||
curl_formfree(first);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if (response_code > 199 && response_code < 300) { //Success
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
#ifdef RIVC_DEBUG_OUT
|
||||
fprintf(stderr," rd_postrss Call Returned Error: %s\n",xml_data.strbuf);
|
||||
#endif
|
||||
return (int)response_code;
|
||||
}
|
||||
}
|
||||
39
apis/rivwebcapi/rivwebcapi/rd_postrss.h
Normal file
39
apis/rivwebcapi/rivwebcapi/rd_postrss.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* rd_postrss.h
|
||||
*
|
||||
* Header for the Post RSS XML Rivendell Access Library
|
||||
*
|
||||
* (C) Copyright 2015 Todd Baker <bakert@rfa.org>
|
||||
* (C) Copyright 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 RD_POSTRSS_H
|
||||
#define RD_POSTRSS_H
|
||||
|
||||
#include <rivwebcapi/rd_common.h>
|
||||
|
||||
_MYRIVLIB_INIT_DECL
|
||||
|
||||
int RD_PostRss(const char hostname[],
|
||||
const char username[],
|
||||
const char passwd[],
|
||||
const char ticket[],
|
||||
const unsigned feed_id,
|
||||
const char user_agent[]);
|
||||
|
||||
_MYRIVLIB_FINI_DECL
|
||||
|
||||
|
||||
#endif // RD_POSTRSS_H
|
||||
197
apis/rivwebcapi/rivwebcapi/rd_removerss.c
Normal file
197
apis/rivwebcapi/rivwebcapi/rd_removerss.c
Normal file
@@ -0,0 +1,197 @@
|
||||
/* rd_removerss.c
|
||||
*
|
||||
* Implementation of the Remove RSS XML Rivendell Access Library
|
||||
*
|
||||
* (C) Copyright 2015 Todd Baker <bakert@rfa.org>
|
||||
* (C) Copyright 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 <string.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <expat.h>
|
||||
|
||||
#include "rd_removerss.h"
|
||||
#include "rd_common.h"
|
||||
#include "rd_getuseragent.h"
|
||||
|
||||
struct xml_data {
|
||||
char elem_name[256];
|
||||
char strbuf[1024];
|
||||
};
|
||||
|
||||
static void XMLCALL __RemoveRssElementStart(void *data, const char *el,
|
||||
const char **attr)
|
||||
{
|
||||
struct xml_data *xml_data=(struct xml_data *)data;
|
||||
strlcpy(xml_data->elem_name,el,256);
|
||||
memset(xml_data->strbuf,0,1024);
|
||||
}
|
||||
|
||||
static void XMLCALL __RemoveRssElementData(void *data,const XML_Char *s,
|
||||
int len)
|
||||
{
|
||||
struct xml_data *xml_data=(struct xml_data *)data;
|
||||
|
||||
memcpy(xml_data->strbuf+strlen(xml_data->strbuf),s,len);
|
||||
}
|
||||
|
||||
static void XMLCALL __RemoveRssElementEnd(void *data, const char *el)
|
||||
{
|
||||
struct xml_data *xml_data=(struct xml_data *)data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
size_t __RemoveRssCallback(void *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
XML_Parser p=(XML_Parser)userdata;
|
||||
|
||||
XML_Parse(p,ptr,size*nmemb,0);
|
||||
|
||||
return size*nmemb;
|
||||
}
|
||||
|
||||
|
||||
int RD_RemoveRss( const char hostname[],
|
||||
const char username[],
|
||||
const char passwd[],
|
||||
const char ticket[],
|
||||
const unsigned feed_id,
|
||||
const char user_agent[])
|
||||
{
|
||||
char post[1500];
|
||||
char url[1500];
|
||||
CURL *curl=NULL;
|
||||
XML_Parser parser;
|
||||
struct xml_data xml_data;
|
||||
long response_code;
|
||||
char errbuf[CURL_ERROR_SIZE];
|
||||
CURLcode res;
|
||||
char user_agent_string[255];
|
||||
char id_buffer[21];
|
||||
struct curl_httppost *first=NULL;
|
||||
struct curl_httppost *last=NULL;
|
||||
|
||||
if((curl=curl_easy_init())==NULL) {
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup the CURL call
|
||||
*/
|
||||
memset(&xml_data,0,sizeof(xml_data));
|
||||
parser=XML_ParserCreate(NULL);
|
||||
XML_SetUserData(parser,&xml_data);
|
||||
XML_SetElementHandler(parser,__RemoveRssElementStart,
|
||||
__RemoveRssElementEnd);
|
||||
XML_SetCharacterDataHandler(parser,__RemoveRssElementData);
|
||||
snprintf(url,1500,"http://%s/rd-bin/rdxport.cgi",hostname);
|
||||
|
||||
curl_formadd(&first,
|
||||
&last,
|
||||
CURLFORM_PTRNAME,
|
||||
"COMMAND",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
"43",
|
||||
CURLFORM_END);
|
||||
|
||||
curl_formadd(&first,
|
||||
&last,
|
||||
CURLFORM_PTRNAME,
|
||||
"LOGIN_NAME",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
username,
|
||||
CURLFORM_END);
|
||||
|
||||
curl_formadd(&first,
|
||||
&last,
|
||||
CURLFORM_PTRNAME,
|
||||
"PASSWORD",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
passwd,
|
||||
CURLFORM_END);
|
||||
|
||||
curl_formadd(&first,
|
||||
&last,
|
||||
CURLFORM_PTRNAME,
|
||||
"TICKET",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
ticket,
|
||||
CURLFORM_END);
|
||||
|
||||
snprintf(id_buffer,21,"%u",feed_id);
|
||||
curl_formadd(&first,
|
||||
&last,
|
||||
CURLFORM_PTRNAME,
|
||||
"ID",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
id_buffer,
|
||||
CURLFORM_END);
|
||||
|
||||
curl_easy_setopt(curl,CURLOPT_WRITEDATA,parser);
|
||||
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,__RemoveRssCallback);
|
||||
curl_easy_setopt(curl,CURLOPT_URL,url);
|
||||
curl_easy_setopt(curl,CURLOPT_POST,1);
|
||||
curl_easy_setopt(curl,CURLOPT_HTTPPOST,first);
|
||||
curl_easy_setopt(curl,CURLOPT_NOPROGRESS,1);
|
||||
curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,errbuf);
|
||||
// curl_easy_setopt(curl,CURLOPT_VERBOSE,1);
|
||||
|
||||
// Check if User Agent Present otherwise set to default
|
||||
if (strlen(user_agent)> 0){
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT,user_agent);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(user_agent_string, RD_GetUserAgent());
|
||||
strcat(user_agent_string,VERSION);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT,user_agent_string);
|
||||
}
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
if(res != CURLE_OK) {
|
||||
#ifdef RIVC_DEBUG_OUT
|
||||
size_t len = strlen(errbuf);
|
||||
fprintf(stderr, "\nlibcurl error: (%d)", res);
|
||||
if (len)
|
||||
fprintf(stderr, "%s%s", errbuf,
|
||||
((errbuf[len-1] != '\n') ? "\n" : ""));
|
||||
else
|
||||
fprintf(stderr, "%s\n", curl_easy_strerror(res));
|
||||
#endif
|
||||
curl_formfree(first);
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
/* The response OK - so figure out if we got what we wanted.. */
|
||||
|
||||
curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response_code);
|
||||
curl_formfree(first);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if (response_code > 199 && response_code < 300) { //Success
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
#ifdef RIVC_DEBUG_OUT
|
||||
fprintf(stderr," rd_removerss Call Returned Error: %s\n",xml_data.strbuf);
|
||||
#endif
|
||||
return (int)response_code;
|
||||
}
|
||||
}
|
||||
39
apis/rivwebcapi/rivwebcapi/rd_removerss.h
Normal file
39
apis/rivwebcapi/rivwebcapi/rd_removerss.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* rd_removerss.h
|
||||
*
|
||||
* Header for the Remove RSS XML Rivendell Access Library
|
||||
*
|
||||
* (C) Copyright 2015 Todd Baker <bakert@rfa.org>
|
||||
* (C) Copyright 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 RD_REMOVERSS_H
|
||||
#define RD_REMOVERSS_H
|
||||
|
||||
#include <rivwebcapi/rd_common.h>
|
||||
|
||||
_MYRIVLIB_INIT_DECL
|
||||
|
||||
int RD_RemoveRss(const char hostname[],
|
||||
const char username[],
|
||||
const char passwd[],
|
||||
const char ticket[],
|
||||
const unsigned feed_id,
|
||||
const char user_agent[]);
|
||||
|
||||
_MYRIVLIB_FINI_DECL
|
||||
|
||||
|
||||
#endif // RD_REMOVERSS_H
|
||||
Reference in New Issue
Block a user