2020-09-17 Fred Gleason <fredg@paravelsystems.com>

* Added an 'RDUser::feedAuthorized()' method.
	* Added a 'SavePodcast' method to the Web API.
	* Added a 'GetPodcast' method to the Web API.
	* Added a 'DeletePodcast' method to the Web API.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2020-09-17 16:19:26 -04:00
parent 288b7a9826
commit 6516c20ff6
13 changed files with 559 additions and 3 deletions

View File

@ -20280,3 +20280,8 @@
2020-08-28 Fred Gleason <fredg@paravelsystems.com>
* Added an 'RDNotification::FeedType' value to the
'RDNotification::Type' enumeration.
2020-09-17 Fred Gleason <fredg@paravelsystems.com>
* Added an 'RDUser::feedAuthorized()' method.
* Added a 'SavePodcast' method to the Web API.
* Added a 'GetPodcast' method to the Web API.
* Added a 'DeletePodcast' method to the Web API.

View File

@ -831,6 +831,68 @@
</table>
</sect1>
<sect1>
<title>DeletePodcast</title>
<subtitle>Delete posted podcast audio from the audio store</subtitle>
<para>
Command Code: <code>RDXPORT_COMMAND_DELETE_PODCAST</code>
</para>
<para>
Required User Permissions: <code>Delete Podcast</code>, Feed Permission
</para>
<para>
A <computeroutput>404</computeroutput> error will be returned if the
requested podcast's parent feed is not authorized for the specified
Rivendell user in RDAdmin->ManageUsers->PodcastFeedPermissions.
</para>
<table xml:id="ex.delete_podcast
" frame="all">
<title>GetPodcast Call Fields</title>
<tgroup cols="3" align="left" colsep="1" rowsep="1">
<colspec colname="FIELD NAME" />
<colspec colname="MEANING" />
<colspec colname="REMARKS" />
<thead>
<row>
<entry>
FIELD NAME
</entry>
<entry>
MEANING
</entry>
<entry>
REMARKS
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
COMMAND
</entry>
<entry>
39
</entry>
<entry>
Mandatory
</entry>
</row>
<row>
<entry>
ID
</entry>
<entry>
ID of podcast item (integer)
</entry>
<entry>
Mandatory
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1>
<sect1>
<title>EditCart</title>
<subtitle>
@ -1717,6 +1779,68 @@
</table>
</sect1>
<sect1>
<title>GetPodcast</title>
<subtitle>Get posted podcast audio</subtitle>
<para>
Command Code: <code>RDXPORT_COMMAND_GET_PODCAST</code>
</para>
<para>
Required User Permissions: <code>Edit Podcast</code>, Feed Permission
</para>
<para>
A <computeroutput>404</computeroutput> error will be returned if the
requested podcast's parent feed is not authorized for the specified
Rivendell user in RDAdmin->ManageUsers->PodcastFeedPermissions.
</para>
<table xml:id="ex.get_podcast
" frame="all">
<title>GetPodcast Call Fields</title>
<tgroup cols="3" align="left" colsep="1" rowsep="1">
<colspec colname="FIELD NAME" />
<colspec colname="MEANING" />
<colspec colname="REMARKS" />
<thead>
<row>
<entry>
FIELD NAME
</entry>
<entry>
MEANING
</entry>
<entry>
REMARKS
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
COMMAND
</entry>
<entry>
37
</entry>
<entry>
Mandatory
</entry>
</row>
<row>
<entry>
ID
</entry>
<entry>
ID of podcast item (integer)
</entry>
<entry>
Mandatory
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1>
<sect1>
<title>Import</title>
<subtitle>Import audio data into the audio store</subtitle>
@ -3526,6 +3650,82 @@
</table>
</sect1>
<sect1>
<title>SavePodcast</title>
<subtitle>Save posted podcast audio</subtitle>
<para>
Command Code: <code>RDXPORT_COMMAND_SAVE_PODCAST</code>
</para>
<para>
Required User Permissions: <code>Create Podcast</code>, Feed Permission
</para>
<para>
A <computeroutput>404</computeroutput> error will be returned if the
requested podcast's parent feed is not authorized for the specified
Rivendell user in RDAdmin->ManageUsers->PodcastFeedPermissions.
</para>
<para>
NOTE: The method must be called with 'multipart/form-data' encoding.
</para>
<table xml:id="ex.save_podcast
" frame="all">
<title>SavePodcast Call Fields</title>
<tgroup cols="3" align="left" colsep="1" rowsep="1">
<colspec colname="FIELD NAME" />
<colspec colname="MEANING" />
<colspec colname="REMARKS" />
<thead>
<row>
<entry>
FIELD NAME
</entry>
<entry>
MEANING
</entry>
<entry>
REMARKS
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
COMMAND
</entry>
<entry>
38
</entry>
<entry>
Mandatory
</entry>
</row>
<row>
<entry>
ID
</entry>
<entry>
ID of podcast (integer)
</entry>
<entry>
Mandatory
</entry>
</row>
<row>
<entry>
FILENAME
</entry>
<entry>
Binary file data
</entry>
<entry>
Mandatory
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1>
<sect1>
<title>SaveString</title>
<subtitle>

View File

@ -544,6 +544,22 @@ bool RDUser::cartAuthorized(unsigned cartnum) const
}
bool RDUser::feedAuthorized(const QString &keyname)
{
QString sql;
RDSqlQuery *q;
bool ret=false;
sql=QString("select ID from FEED_PERMS where ")+
"(USER_NAME=\""+RDEscapeString(user_name)+"\")&&"+
"(KEY_NAME=\""+RDEscapeString(keyname)+"\")";
q=new RDSqlQuery(sql);
ret=q->first();
delete q;
return ret;
}
QString RDUser::serviceCheckDefault(QString serv) const
{
bool match_flag = false;

View File

@ -93,6 +93,7 @@ class RDUser
bool groupAuthorized(const QString &group_name);
QStringList groups() const;
bool cartAuthorized(unsigned cartnum) const;
bool feedAuthorized(const QString &keyname);
QString serviceCheckDefault(QString serv) const;
QStringList services() const;
static bool emailIsValid(const QString &addr);

View File

@ -57,6 +57,9 @@
#define RDXPORT_COMMAND_LOCKLOG 34
#define RDXPORT_COMMAND_SAVESTRING 35
#define RDXPORT_COMMAND_SAVEFILE 36
#define RDXPORT_COMMAND_GET_PODCAST 37
#define RDXPORT_COMMAND_SAVE_PODCAST 38
#define RDXPORT_COMMAND_DELETE_PODCAST 39
#endif // RDXPORT_INTERFACE_H

View File

@ -40,6 +40,7 @@ dist_rdxport_cgi_SOURCES = audioinfo.cpp\
exportpeaks.cpp\
import.cpp\
logs.cpp\
podcasts.cpp\
rdxport.cpp rdxport.h\
rehash.cpp\
tests.cpp\

204
web/rdxport/podcasts.cpp Normal file
View File

@ -0,0 +1,204 @@
// podcasts.cpp
//
// Rivendell web service portal -- Podcast services
//
// (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 <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <rdapplication.h>
#include <rdconf.h>
#include <rdescape_string.h>
#include <rdformpost.h>
#include <rdgroup.h>
#include <rdpodcast.h>
#include <rduser.h>
#include <rdweb.h>
#include "rdxport.h"
void Xport::SavePodcast()
{
int cast_id=0;
QString keyname;
QString destpath;
QString err_msg;
RDPodcast *cast=NULL;
RDFeed *feed=NULL;
QString filename;
QString msg="OK";
if(!xport_post->getValue("ID",&cast_id)) {
XmlExit("Missing ID",400,"podcasts.cpp",LINE_NUMBER);
}
if(!xport_post->getValue("FILENAME",&filename)) {
XmlExit("Missing FILENAME",400,"podcasts.cpp",LINE_NUMBER);
}
if(!xport_post->isFile("FILENAME")) {
XmlExit("Missing file data",400,"podcasts.cpp",LINE_NUMBER);
}
cast=new RDPodcast(rda->config(),cast_id);
if(!cast->exists()) {
delete cast;
XmlExit("No such podcast",404,"podcasts.cpp",LINE_NUMBER);
}
keyname=cast->keyName();
if((!rda->user()->addPodcast())||(!rda->user()->feedAuthorized(keyname))) {
delete cast;
XmlExit("No such podcast",404,"podcasts.cpp",LINE_NUMBER);
}
feed=new RDFeed(keyname,rda->config(),this);
destpath=QString(RD_AUDIO_ROOT)+"/"+cast->audioFilename();
if(!RDCopy(filename,destpath)) {
delete feed;
delete cast;
XmlExit("Internal server error [copy failed]",500,"podcasts.cpp",
LINE_NUMBER);
}
if(chmod(destpath.toUtf8(),S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)!=0) {
err_msg=QString().sprintf("Internal server error [%s]",strerror(errno));
unlink(destpath.toUtf8());
delete feed;
delete cast;
XmlExit(err_msg.toUtf8(),500,"podcasts.cpp",LINE_NUMBER);
}
printf("Content-type: text/html; charset: UTF-8\n");
printf("Status: 200\n\n");
printf("OK\n");
rda->syslog(LOG_DEBUG,"saved podcast \"%s\"",destpath.toUtf8().constData());
delete feed;
delete cast;
Exit(0);
}
void Xport::GetPodcast()
{
int cast_id=0;
QString keyname;
QString destpath;
QString err_msg;
RDPodcast *cast=NULL;
QString msg="OK";
int fd=-1;
struct stat st;
ssize_t n=0;
char *data=NULL;
if(!xport_post->getValue("ID",&cast_id)) {
XmlExit("Missing ID",400,"podcasts.cpp",LINE_NUMBER);
}
cast=new RDPodcast(rda->config(),cast_id);
if(!cast->exists()) {
delete cast;
XmlExit("No such podcast",404,"podcasts.cpp",LINE_NUMBER);
}
keyname=cast->keyName();
if((!rda->user()->editPodcast())||(!rda->user()->feedAuthorized(keyname))) {
delete cast;
XmlExit("No such podcast",404,"podcasts.cpp",LINE_NUMBER);
}
destpath=QString(RD_AUDIO_ROOT)+"/"+cast->audioFilename();
if((fd=open(destpath.toUtf8(),O_RDONLY))<0) {
err_msg=QString().sprintf("Internal server error [%s]",strerror(errno));
delete cast;
XmlExit(err_msg.toUtf8(),500,"podcasts.cpp",LINE_NUMBER);
}
memset(&st,0,sizeof(st));
if(fstat(fd,&st)!=0) {
err_msg=QString().sprintf("Internal server error [%s]",strerror(errno));
delete cast;
XmlExit(err_msg.toUtf8(),500,"podcasts.cpp",LINE_NUMBER);
}
printf("Content-type: audio/x-mpeg\n");
printf("Content-length: %ld\n",st.st_size);
printf("\n");
fflush(stdout);
data=new char[st.st_blksize];
n=read(fd,data,st.st_blksize);
while(n>0) {
write(1,data,n);
n=read(fd,data,st.st_blksize);
}
delete data;
close(fd);
rda->syslog(LOG_DEBUG,"served podcast \"%s\"",destpath.toUtf8().constData());
delete cast;
Exit(0);
}
void Xport::DeletePodcast()
{
int cast_id=0;
QString keyname;
QString destpath;
QString err_msg;
RDPodcast *cast=NULL;
QString msg="OK";
if(!xport_post->getValue("ID",&cast_id)) {
XmlExit("Missing ID",400,"podcasts.cpp",LINE_NUMBER);
}
cast=new RDPodcast(rda->config(),cast_id);
if(!cast->exists()) {
delete cast;
XmlExit("No such podcast",404,"podcasts.cpp",LINE_NUMBER);
}
keyname=cast->keyName();
if((!rda->user()->deletePodcast())||(!rda->user()->feedAuthorized(keyname))) {
delete cast;
XmlExit("No such podcast",404,"podcasts.cpp",LINE_NUMBER);
}
destpath=QString(RD_AUDIO_ROOT)+"/"+cast->audioFilename();
if(unlink(destpath.toUtf8())!=0) {
if(errno!=ENOENT) {
err_msg=QString().sprintf("Internal server error [%s]",strerror(errno));
delete cast;
XmlExit(err_msg.toUtf8(),500,"podcasts.cpp",LINE_NUMBER);
}
}
printf("Content-type: text/html; charset: UTF-8\n");
printf("Status: 200\n\n");
printf("OK\n");
rda->syslog(LOG_DEBUG,"deleted podcast \"%s\"",destpath.toUtf8().constData());
delete cast;
Exit(0);
}

View File

@ -2,7 +2,7 @@
//
// Rivendell web service portal
//
// (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
@ -154,6 +154,7 @@ void Xport::ripcConnectedData(bool state)
// Read Command Variable and Dispatch
//
int command=xport_post->value("COMMAND").toInt();
switch(command) {
case RDXPORT_COMMAND_EXPORT:
Export();
@ -295,6 +296,18 @@ void Xport::ripcConnectedData(bool state)
SaveFile();
break;
case RDXPORT_COMMAND_SAVE_PODCAST:
SavePodcast();
break;
case RDXPORT_COMMAND_GET_PODCAST:
GetPodcast();
break;
case RDXPORT_COMMAND_DELETE_PODCAST:
DeletePodcast();
break;
default:
printf("Content-type: text/html\n\n");
printf("rdxport: missing/invalid command\n");

View File

@ -82,6 +82,9 @@ class Xport : public QObject
void ListCartSchedCodes();
void ListServices();
void ListSystemSettings();
void SavePodcast();
void GetPodcast();
void DeletePodcast();
void LockLog();
QString LogLockXml(bool result,const QString &log_name,const QString &guid,
const QString &username,const QString &stationname,

View File

@ -2,7 +2,7 @@
##
## Automake.am for rivendell/web/tests
##
## (C) Copyright 2010,2013-2015 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
@ -31,13 +31,14 @@ install-exec-am:
cp createticket.html $(DESTDIR)@libexecdir@
cp delete_audio.html $(DESTDIR)@libexecdir@
cp deletelog.html $(DESTDIR)@libexecdir@
cp deletepodcast.html $(DESTDIR)@libexecdir@
cp editcart.html $(DESTDIR)@libexecdir@
cp editcut.js $(DESTDIR)@libexecdir@
cp editcut.html $(DESTDIR)@libexecdir@
cp editcart.js $(DESTDIR)@libexecdir@
cp export.html $(DESTDIR)@libexecdir@
cp exportpeaks.html $(DESTDIR)@libexecdir@
cp import.html $(DESTDIR)@libexecdir@
cp getpodcast.html $(DESTDIR)@libexecdir@
cp import.html $(DESTDIR)@libexecdir@
cp listcart.html $(DESTDIR)@libexecdir@
cp listcarts.html $(DESTDIR)@libexecdir@
@ -57,6 +58,7 @@ install-exec-am:
cp removecut.html $(DESTDIR)@libexecdir@
cp savefile.html $(DESTDIR)@libexecdir@
cp savelog.html $(DESTDIR)@libexecdir@
cp savepodcast.html $(DESTDIR)@libexecdir@
cp savestring.html $(DESTDIR)@libexecdir@
cp trimaudio.html $(DESTDIR)@libexecdir@
cp unassignschedcode.html $(DESTDIR)@libexecdir@
@ -73,12 +75,14 @@ uninstall-local:
rm -f $(DESTDIR)@libexecdir@/createticket.html
rm -f $(DESTDIR)@libexecdir@/delete_audio.html
rm -f $(DESTDIR)@libexecdir@/deletelog.html
rm -f $(DESTDIR)@libexecdir@/deletepodcast.html
rm -f $(DESTDIR)@libexecdir@/editcart.html
rm -f $(DESTDIR)@libexecdir@/editcart.js
rm -f $(DESTDIR)@libexecdir@/editcut.html
rm -f $(DESTDIR)@libexecdir@/editcut.js
rm -f $(DESTDIR)@libexecdir@/export.html
rm -f $(DESTDIR)@libexecdir@/exportpeaks.html
rm -f $(DESTDIR)@libexecdir@/getpodcast.html
rm -f $(DESTDIR)@libexecdir@/import.html
rm -f $(DESTDIR)@libexecdir@/listcart.html
rm -f $(DESTDIR)@libexecdir@/listcarts.html
@ -98,6 +102,7 @@ uninstall-local:
rm -f $(DESTDIR)@libexecdir@/removecut.html
rm -f $(DESTDIR)@libexecdir@/savefile.html
rm -f $(DESTDIR)@libexecdir@/savelog.html
rm -f $(DESTDIR)@libexecdir@/savepodcast.html
rm -f $(DESTDIR)@libexecdir@/savestring.html
rm -f $(DESTDIR)@libexecdir@/trimaudio.html
rm -f $(DESTDIR)@libexecdir@/unassignschedcode.html
@ -113,12 +118,14 @@ EXTRA_DIST = addcart.html\
createticket.html\
delete_audio.html\
deletelog.html\
deletepodcast.html\
editcart.html\
editcart.js\
editcut.html\
editcut.js\
export.html\
exportpeaks.html\
getpodcast.html\
import.html\
listcart.html\
listcarts.html\
@ -138,6 +145,7 @@ EXTRA_DIST = addcart.html\
removecut.html\
savefile.html\
savelog.html\
savepodcast.html\
savestring.html\
trimaudio.html\
unassignschedcode.html\

View File

@ -0,0 +1,33 @@
<html>
<head>
<title>Rivendell DELETEPODCAST Service Test Harness</title>
<body>
<form action="/rd-bin/rdxport.cgi" method="post" enctype="multipart/form-data">
<input type="hidden" name="COMMAND" value="39">
<table cellpadding="0" cellspacing="2" border="0">
<tr>
<td align="right">LOGIN NAME:</td>
<td><input type="text" name="LOGIN_NAME" size="20" maxlength="255"></td>
</tr>
<tr>
<td align="right">PASSWORD:</td>
<td><input type="password" name="PASSWORD" size="20" maxlength="32"></td>
</tr>
<tr>
<td align="right">TICKET:</td>
<td><input type="text" name="TICKET" size="40" maxlength="40"></td>
</tr>
<tr>
<td align="right">ID:</td>
<td><input type="text" name="ID" size="12" maxlength="12"></td>
</tr>
<tr>
<td colspan="2" align="right">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="OK"></td>
</tr>
</table>
</form>
</body>
</html>

33
web/tests/getpodcast.html Normal file
View File

@ -0,0 +1,33 @@
<html>
<head>
<title>Rivendell GETPODCAST Service Test Harness</title>
<body>
<form action="/rd-bin/rdxport.cgi" method="post" enctype="multipart/form-data">
<input type="hidden" name="COMMAND" value="37">
<table cellpadding="0" cellspacing="2" border="0">
<tr>
<td align="right">LOGIN NAME:</td>
<td><input type="text" name="LOGIN_NAME" size="20" maxlength="255"></td>
</tr>
<tr>
<td align="right">PASSWORD:</td>
<td><input type="password" name="PASSWORD" size="20" maxlength="32"></td>
</tr>
<tr>
<td align="right">TICKET:</td>
<td><input type="text" name="TICKET" size="40" maxlength="40"></td>
</tr>
<tr>
<td align="right">ID:</td>
<td><input type="text" name="ID" size="12" maxlength="12"></td>
</tr>
<tr>
<td colspan="2" align="right">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="OK"></td>
</tr>
</table>
</form>
</body>
</html>

View File

@ -0,0 +1,36 @@
<html>
<head>
<title>Rivendel SAVEPODCAST Service Test Harness</title>
<body>
<form action="/rd-bin/rdxport.cgi" method="post" enctype="multipart/form-data">
<input type="hidden" name="COMMAND" value="38">
<table cellpadding="0" cellspacing="2" border="0">
<tr>
<td align="right">LOGIN NAME:</td>
<td><input type="text" name="LOGIN_NAME" size="20" maxlength="255"></td>
</tr>
<tr>
<td align="right">PASSWORD:</td>
<td><input type="password" name="PASSWORD" size="20" maxlength="32"></td>
</tr>
<tr>
<td align="right">TICKET:</td>
<td><input type="text" name="TICKET" size="40" maxlength="40"></td>
</tr>
<td align="right">ID:</td>
<td><input type="text" name="ID" size="12" maxlength="12"></td>
</tr>
<tr>
<td align="right">FILENAME:</td>
<td><input type="file" name="FILENAME" size="20" maxlength="64"></td>
</tr>
<tr>
<td colspan="2" align="right">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="OK"></td>
</tr>
</table>
</form>
</body>
</html>