Initial import of CVS-v2_8_branch

This commit is contained in:
Fred Gleason
2014-08-12 15:13:02 -04:00
commit afd67c7af8
1508 changed files with 405304 additions and 0 deletions

62
web/rdxport/Makefile.am Normal file
View File

@@ -0,0 +1,62 @@
## automake.am
##
## Automake.am for rivendell/web/rdxport
##
## (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
##
## $Id: Makefile.am,v 1.6.6.3 2013/10/11 22:00:52 cvs Exp $
##
## 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.
##
## Use automake to process this into a Makefile.in
AM_CPPFLAGS = -Wall -DPREFIX=\"$(prefix)\" -DQTDIR=\"@QT_DIR@\" @QT_CXXFLAGS@
INCLUDES = -I$(top_srcdir)/lib
LIBS = @QT_LIBS@ -L$(top_srcdir)/lib
MOC = @QT_MOC@
libexec_PROGRAMS = rdxport.cgi
install-exec-hook:
chown root $(libexecdir)/rdxport.cgi
chmod 4755 $(libexecdir)/rdxport.cgi
dist_rdxport_cgi_SOURCES = audioinfo.cpp\
carts.cpp\
copyaudio.cpp\
deleteaudio.cpp\
groups.cpp\
export.cpp\
exportpeaks.cpp\
import.cpp\
logs.cpp\
rdxport.cpp rdxport.h\
services.cpp\
trimaudio.cpp
rdxport_cgi_LDADD = @LIB_RDLIBS@ -lsndfile @LIBVORBIS@
EXTRA_DIST = rdxport.pro
CLEANFILES = *~\
*.idb\
*ilk\
*.obj\
*.pdb\
*.qm\
moc_*
MAINTAINERCLEANFILES = *~\
Makefile.in\
moc_*

114
web/rdxport/audioinfo.cpp Normal file
View File

@@ -0,0 +1,114 @@
// audioinfo.cpp
//
// Rivendell web service portal -- AudioInfo service
//
// (C) Copyright 2011 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: audioinfo.cpp,v 1.4 2012/02/13 23:01:50 cvs Exp $
//
// 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 <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <rdformpost.h>
#include <rdweb.h>
#include <rdcart.h>
#include <rdwavefile.h>
#include <rdconf.h>
#include <rdxport.h>
void Xport::AudioInfo()
{
RDWaveFile::Format format=RDWaveFile::Pcm16;;
//
// Verify Post
//
int cartnum=0;
if(!xport_post->getValue("CART_NUMBER",&cartnum)) {
XmlExit("Missing CART_NUMBER",400);
}
int cutnum=0;
if(!xport_post->getValue("CUT_NUMBER",&cutnum)) {
XmlExit("Missing CUT_NUMBER",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cartnum)) {
XmlExit("No such cart",404);
}
//
// Open Audio File
//
RDWaveFile *wave=new RDWaveFile(RDCut::pathName(cartnum,cutnum));
if(!wave->openWave()) {
XmlExit("No such audio",404);
}
//
// Send Data
//
printf("Content-type: application/xml\n\n");
switch(wave->getFormatTag()) {
case WAVE_FORMAT_PCM:
format=RDWaveFile::Pcm16;
break;
case WAVE_FORMAT_IEEE_FLOAT:
format=RDWaveFile::Float32;
break;
case WAVE_FORMAT_MPEG:
switch(wave->getHeadLayer()) {
case 1:
format=RDWaveFile::MpegL1;
break;
case 2:
format=RDWaveFile::MpegL2;
break;
case 3:
format=RDWaveFile::MpegL3;
break;
}
break;
default:
XmlExit("Unknown audio format",400);
break;
}
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<audioInfo>\n");
printf(" <cartNumber>%u</cartNumber>\n",cartnum);
printf(" <cutNumber>%u</cutNumber>\n",cutnum);
printf(" <format>%d</format>\n",format);
printf(" <channels>%d</channels>\n",wave->getChannels());
printf(" <sampleRate>%d</sampleRate>\n",wave->getSamplesPerSec());
printf(" <frames>%u</frames>\n",wave->getSampleLength());
printf(" <length>%u</length>\n",wave->getExtTimeLength());
printf("</audioInfo>\n");
delete wave;
Exit(0);
}

771
web/rdxport/carts.cpp Normal file
View File

@@ -0,0 +1,771 @@
// carts.cpp
//
// Rivendell web service portal -- Cart services
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: carts.cpp,v 1.8.2.2.2.1 2014/03/19 22:13:01 cvs Exp $
//
// 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 <rdformpost.h>
#include <rdweb.h>
#include <rduser.h>
#include <rdgroup.h>
#include <rdconf.h>
#include <rdescape_string.h>
#include <rdcart_search_text.h>
#include <rdxport.h>
void Xport::AddCart()
{
RDCart *cart;
RDGroup *group;
QString group_name;
QString type;
RDCart::Type cart_type=RDCart::All;
int cart_number=0;
//
// Verify Post
//
if(!xport_post->getValue("GROUP_NAME",&group_name)) {
XmlExit("Missing GROUP_NAME",400);
}
if(!xport_post->getValue("TYPE",&type)) {
XmlExit("Missing TYPE",400);
}
if(type.lower()=="audio") {
cart_type=RDCart::Audio;
}
else {
if(type.lower()=="macro") {
cart_type=RDCart::Macro;
}
else {
XmlExit("Invalid TYPE",400);
}
}
xport_post->getValue("CART_NUMBER",&cart_number);
//
// Verify User Perms
//
if(!xport_user->groupAuthorized(group_name)) {
XmlExit("No such group",404);
}
group=new RDGroup(group_name,this);
if(cart_number==0) {
if((cart_number=group->nextFreeCart())==0) {
delete group;
XmlExit("No free carts in group",500);
}
}
if(!group->cartNumberValid(cart_number)) {
delete group;
XmlExit("Cart number out of range for group",401);
}
delete group;
if(!xport_user->createCarts()) {
XmlExit("Unauthorized",401);
}
//
// Process Request
//
cart=new RDCart(cart_number);
if(cart->exists()) {
delete cart;
XmlExit("Cart already exists",403);
}
if(!cart->create(group_name,cart_type)) {
delete cart;
XmlExit("Unable to create cart",500);
}
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<cartAdd>\n");
if(cart->exists()) {
printf("%s",(const char *)cart->xml(false));
}
delete cart;
printf("</cartAdd>\n");
Exit(0);
}
void Xport::ListCarts()
{
QString sql;
RDSqlQuery *q;
QString where="";
RDCart *cart;
QString group_name;
QString filter;
int include_cuts;
RDCart::Type cart_type=RDCart::All;
QString type;
//
// Verify Post
//
xport_post->getValue("GROUP_NAME",&group_name);
xport_post->getValue("FILTER",&filter);
xport_post->getValue("INCLUDE_CUTS",&include_cuts);
xport_post->getValue("TYPE",&type);
if(type.lower()=="audio") {
cart_type=RDCart::Audio;
}
if(type.lower()=="macro") {
cart_type=RDCart::Macro;
}
//
// Generate Cart List
//
if(group_name.isEmpty()||(group_name==tr("ALL"))) {
where=RDAllCartSearchText(filter,"ALL",xport_user->name(),false);
}
else {
sql=QString().
sprintf("select GROUP_NAME from USER_PERMS \
where (GROUP_NAME=\"%s\")&&(USER_NAME=\"%s\")",
(const char *)RDEscapeString(group_name),
(const char *)RDEscapeString(xport_user->name()));
q=new RDSqlQuery(sql);
if(!q->first()) {
delete q;
XmlExit("No such group",404);
}
where=RDCartSearchText(filter,group_name,"",false);
}
if(cart_type!=RDCart::All) {
where+=QString().sprintf("&&(TYPE=%u)",cart_type);
}
sql="select NUMBER from CART where "+where+"order by NUMBER";
q=new RDSqlQuery(sql);
//
// Process Request
//
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<cartList>\n");
while(q->next()) {
cart=new RDCart(q->value(0).toUInt());
printf("%s",(const char *)cart->xml(include_cuts));
delete cart;
}
printf("</cartList>\n");
delete q;
Exit(0);
}
void Xport::ListCart()
{
QString where="";
RDCart *cart;
int cart_number;
int include_cuts;
QString value;
//
// Verify Post
//
if(!xport_post->getValue("CART_NUMBER",&cart_number)) {
XmlExit("Missing CART_NUMBER",400);
}
xport_post->getValue("INCLUDE_CUTS",&include_cuts);
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cart_number)) {
XmlExit("No such cart",404);
}
//
// Process Request
//
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<cartList>\n");
cart=new RDCart(cart_number);
printf("%s",(const char *)cart->xml(include_cuts));
delete cart;
printf("</cartList>\n");
Exit(0);
}
void Xport::EditCart()
{
QString where="";
RDCart *cart;
int cart_number;
int include_cuts=0;
QString group_name;
QString value;
int number;
bool ok;
int line;
QString macro;
bool length_changed=false;
//
// Verify Post
//
if(!xport_post->getValue("CART_NUMBER",&cart_number)) {
XmlExit("Missing CART_NUMBER",400);
}
xport_post->getValue("INCLUDE_CUTS",&include_cuts);
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cart_number)) {
XmlExit("No such cart",404);
}
if(!xport_user->modifyCarts()) {
XmlExit("Unauthorized",401);
}
if(xport_post->getValue("GROUP_NAME",&group_name)) {
if(!xport_user->groupAuthorized(group_name)) {
XmlExit("No such group",404);
}
}
//
// Process Request
//
cart=new RDCart(cart_number);
if(!cart->exists()) {
delete cart;
XmlExit("No such cart",404);
}
if(xport_post->getValue("FORCED_LENGTH",&value)) {
number=RDSetTimeLength(value);
if(cart->type()==RDCart::Macro) {
delete cart;
XmlExit("Unsupported operation for cart type",403);
}
if(!cart->validateLengths(number)) {
delete cart;
XmlExit("Forced length out of range",403);
}
}
switch(cart->type()) {
case RDCart::Audio:
break;
case RDCart::Macro:
line=0;
while(xport_post->getValue(QString().sprintf("MACRO%d",line++),&value)) {
value.stripWhiteSpace();
if(value.right(1)!="!") {
delete cart;
XmlExit("Invalid macro data",400);
}
macro+=value;
}
cart->setMacros(macro);
break;
case RDCart::All:
break;
}
if(!group_name.isEmpty()) {
cart->setGroupName(group_name);
}
if(xport_post->getValue("TITLE",&value)) {
cart->setTitle(value);
}
if(xport_post->getValue("ARTIST",&value)) {
cart->setArtist(value);
}
if(xport_post->getValue("ALBUM",&value)) {
cart->setAlbum(value);
}
if(xport_post->getValue("YEAR",&value)) {
number=value.toInt(&ok);
if((ok)&&(number>0)) {
cart->setYear(number);
}
}
if(xport_post->getValue("LABEL",&value)) {
cart->setLabel(value);
}
if(xport_post->getValue("CLIENT",&value)) {
cart->setClient(value);
}
if(xport_post->getValue("AGENCY",&value)) {
cart->setAgency(value);
}
if(xport_post->getValue("PUBLISHER",&value)) {
cart->setPublisher(value);
}
if(xport_post->getValue("COMPOSER",&value)) {
cart->setComposer(value);
}
if(xport_post->getValue("USER_DEFINED",&value)) {
cart->setUserDefined(value);
}
if(xport_post->getValue("USAGE_CODE",&value)) {
number=value.toInt(&ok);
if((ok)&&(number>0)) {
cart->setUsageCode((RDCart::UsageCode)number);
}
}
if(xport_post->getValue("ENFORCE_LENGTH",&value)) {
number=value.toInt(&ok);
if((ok)&&(number>=0)&&(number<2)) {
cart->setEnforceLength(number);
length_changed=true;
}
}
if(xport_post->getValue("FORCED_LENGTH",&value)) {
cart->setForcedLength(RDSetTimeLength(value));
length_changed=true;
}
if(xport_post->getValue("ASYNCRONOUS",&value)) {
number=value.toInt(&ok);
if((ok)&&(number>=0)&&(number<2)) {
cart->setAsyncronous(number);
length_changed=true;
}
}
if(xport_post->getValue("OWNER",&value)) {
cart->setOwner(value);
}
if(xport_post->getValue("NOTES",&value)) {
cart->setNotes(value);
}
if(xport_post->getValue("SCHED_CODES",&value)) {
cart->setSchedCodes(value);
}
if(length_changed) {
cart->updateLength();
}
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<cartList>\n");
printf("%s",(const char *)cart->xml(include_cuts));
delete cart;
printf("</cartList>\n");
Exit(0);
}
void Xport::RemoveCart()
{
RDCart *cart;
int cart_number;
//
// Verify Post
//
if(!xport_post->getValue("CART_NUMBER",&cart_number)) {
XmlExit("Missing CART_NUMBER",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cart_number)) {
XmlExit("No such cart",404);
}
if(!xport_user->deleteCarts()) {
XmlExit("Unauthorized",401);
}
//
// Process Request
//
cart=new RDCart(cart_number);
if(!cart->exists()) {
delete cart;
XmlExit("No such cart",404);
}
if(!cart->remove(NULL,NULL,xport_config)) {
delete cart;
XmlExit("Unable to delete cart",500);
}
delete cart;
XmlExit("OK",200);
}
void Xport::AddCut()
{
RDCart *cart;
RDCut *cut;
int cart_number;
int cut_number;
//
// Verify Post
//
if(!xport_post->getValue("CART_NUMBER",&cart_number)) {
XmlExit("Missing CART_NUMBER",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cart_number)) {
XmlExit("No such cart",404);
}
if(!xport_user->editAudio()) {
XmlExit("Unauthorized",401);
}
//
// Process Request
//
cart=new RDCart(cart_number);
if(!cart->exists()) {
delete cart;
XmlExit("No such cart",404);
}
if((cut_number=cart->addCut(0,0,2))<0) {
delete cart;
XmlExit("No new cuts available",500);
}
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<cutAdd>\n");
cut=new RDCut(cart_number,cut_number);
if(cut->exists()) {
printf("%s",(const char *)cut->xml());
}
delete cut;
delete cart;
printf("</cutAdd>\n");
Exit(0);
}
void Xport::ListCuts()
{
RDCut *cut;
int cart_number;
QString sql;
RDSqlQuery *q;
//
// Verify Post
//
if(!xport_post->getValue("CART_NUMBER",&cart_number)) {
XmlExit("Missing CART_NUMBER",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cart_number)) {
XmlExit("No such cart",404);
}
//
// Process Request
//
sql=QString().sprintf("select CUT_NAME from CUTS where CART_NUMBER=%u \
order by CUT_NAME",
cart_number);
q=new RDSqlQuery(sql);
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<cutList>\n");
while(q->next()) {
cut=new RDCut(q->value(0).toString());
if(cut->exists()) {
printf("%s",(const char *)cut->xml());
}
delete cut;
}
delete q;
printf("</cutList>\n");
Exit(0);
}
void Xport::ListCut()
{
RDCut *cut;
int cart_number;
int cut_number;
//
// Verify Post
//
if(!xport_post->getValue("CART_NUMBER",&cart_number)) {
XmlExit("Missing CART_NUMBER",400);
}
if(!xport_post->getValue("CUT_NUMBER",&cut_number)) {
XmlExit("Missing CUT_NUMBER",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cart_number)) {
XmlExit("No such cart",404);
}
//
// Process Request
//
cut=new RDCut(cart_number,cut_number);
if(!cut->exists()) {
delete cut;
XmlExit("No such cut",404);
}
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<cutList>\n");
printf("%s",(const char *)cut->xml());
printf("</cutList>\n");
delete cut;
Exit(0);
}
void Xport::EditCut()
{
RDCut *cut;
int cart_number;
int cut_number;
QString str;
int num;
QDateTime datetime;
QTime time;
bool rotation_changed=false;
bool length_changed=false;
//
// Verify Post
//
if(!xport_post->getValue("CART_NUMBER",&cart_number)) {
XmlExit("Missing CART_NUMBER",400);
}
if(!xport_post->getValue("CUT_NUMBER",&cut_number)) {
XmlExit("Missing CUT_NUMBER",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cart_number)) {
XmlExit("No such cart",404);
}
if(!xport_user->editAudio()) {
XmlExit("Unauthorized",401);
}
//
// Process Request
//
cut=new RDCut(cart_number,cut_number);
if(!cut->exists()) {
delete cut;
XmlExit("No such cut",404);
}
if(xport_post->getValue("EVERGREEN",&num)) {
cut->setEvergreen(num);
rotation_changed=true;
}
if(xport_post->getValue("DESCRIPTION",&str)) {
cut->setDescription(str);
}
if(xport_post->getValue("OUTCUE",&str)) {
cut->setOutcue(str);
}
if(xport_post->getValue("ISRC",&str)) {
cut->setIsrc(str);
}
if(xport_post->getValue("ISCI",&str)) {
cut->setIsci(str);
}
if(xport_post->getValue("START_DATETIME",&datetime)) {
cut->setStartDatetime(datetime,!datetime.isNull());
length_changed=true;
rotation_changed=true;
}
if(xport_post->getValue("END_DATETIME",&datetime)) {
cut->setEndDatetime(datetime,!datetime.isNull());
length_changed=true;
rotation_changed=true;
}
if(xport_post->getValue("MON",&num)) {
cut->setWeekPart(1,num);
rotation_changed=true;
}
if(xport_post->getValue("TUE",&num)) {
cut->setWeekPart(2,num);
rotation_changed=true;
}
if(xport_post->getValue("WED",&num)) {
cut->setWeekPart(3,num);
rotation_changed=true;
}
if(xport_post->getValue("THU",&num)) {
cut->setWeekPart(4,num);
rotation_changed=true;
}
if(xport_post->getValue("FRI",&num)) {
cut->setWeekPart(5,num);
rotation_changed=true;
}
if(xport_post->getValue("SAT",&num)) {
cut->setWeekPart(6,num);
rotation_changed=true;
}
if(xport_post->getValue("SUN",&num)) {
cut->setWeekPart(7,num);
rotation_changed=true;
}
if(xport_post->getValue("START_DAYPART",&time)) {
cut->setStartDaypart(time,!time.isNull());
rotation_changed=true;
}
if(xport_post->getValue("END_DAYPART",&time)) {
cut->setEndDaypart(time,!time.isNull());
rotation_changed=true;
}
if(xport_post->getValue("WEIGHT",&num)) {
cut->setWeight(num);
rotation_changed=true;
}
if(xport_post->getValue("START_POINT",&num)) {
cut->setStartPoint(num);
length_changed=true;
}
if(xport_post->getValue("END_POINT",&num)) {
cut->setEndPoint(num);
length_changed=true;
}
if(xport_post->getValue("FADEUP_POINT",&num)) {
cut->setFadeupPoint(num);
length_changed=true;
}
if(xport_post->getValue("FADEDOWN_POINT",&num)) {
cut->setFadedownPoint(num);
length_changed=true;
}
if(xport_post->getValue("SEGUE_START_POINT",&num)) {
cut->setSegueStartPoint(num);
length_changed=true;
}
if(xport_post->getValue("SEGUE_END_POINT",&num)) {
cut->setSegueEndPoint(num);
length_changed=true;
}
if(xport_post->getValue("HOOK_START_POINT",&num)) {
cut->setHookStartPoint(num);
length_changed=true;
}
if(xport_post->getValue("HOOK_END_POINT",&num)) {
cut->setHookEndPoint(num);
length_changed=true;
}
if(xport_post->getValue("TALK_START_POINT",&num)) {
cut->setTalkStartPoint(num);
length_changed=true;
}
if(xport_post->getValue("TALK_END_POINT",&num)) {
cut->setTalkEndPoint(num);
length_changed=true;
}
if(length_changed||rotation_changed) {
RDCart *cart=new RDCart(cut->cartNumber());
if(length_changed) {
cart->updateLength();
}
if(rotation_changed) {
cart->resetRotation();
}
delete cart;
}
delete cut;
XmlExit("OK",200);
}
void Xport::RemoveCut()
{
RDCart *cart;
int cart_number;
int cut_number;
//
// Verify Post
//
if(!xport_post->getValue("CART_NUMBER",&cart_number)) {
XmlExit("Missing CART_NUMBER",400);
}
if(!xport_post->getValue("CUT_NUMBER",&cut_number)) {
XmlExit("Missing CUT_NUMBER",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cart_number)) {
XmlExit("No such cart",404);
}
if(!xport_user->editAudio()) {
XmlExit("Unauthorized",401);
}
//
// Process Request
//
cart=new RDCart(cart_number);
if(!cart->exists()) {
delete cart;
XmlExit("No such cart",404);
}
if(!cart->removeCut(NULL,NULL,RDCut::cutName(cart_number,cut_number),
xport_config)) {
delete cart;
XmlExit("No such cut",404);
}
delete cart;
XmlExit("OK",200);
}

82
web/rdxport/copyaudio.cpp Normal file
View File

@@ -0,0 +1,82 @@
// copyaudio.cpp
//
// Rivendell web service portal -- CopyAudio service
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: copyaudio.cpp,v 1.4 2012/02/13 23:01:50 cvs Exp $
//
// 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 <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <rdformpost.h>
#include <rdweb.h>
#include <rdcart.h>
#include <rdaudioconvert.h>
#include <rdsettings.h>
#include <rdconf.h>
#include <rdxport.h>
void Xport::CopyAudio()
{
//
// Verify Post
//
int source_cartnum=0;
if(!xport_post->getValue("SOURCE_CART_NUMBER",&source_cartnum)) {
XmlExit("Missing SOURCE_CART_NUMBER",400);
}
int source_cutnum=0;
if(!xport_post->getValue("SOURCE_CUT_NUMBER",&source_cutnum)) {
XmlExit("Missing SOURCE_CUT_NUMBER",400);
}
int destination_cartnum=0;
if(!xport_post->getValue("DESTINATION_CART_NUMBER",&destination_cartnum)) {
XmlExit("Missing DESTINATION_CART_NUMBER",400);
}
int destination_cutnum=0;
if(!xport_post->getValue("DESTINATION_CUT_NUMBER",&destination_cutnum)) {
XmlExit("Missing DESTINATION_CUT_NUMBER",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(source_cartnum)) {
XmlExit("No such cart",404);
}
if(!xport_user->cartAuthorized(destination_cartnum)) {
XmlExit("No such cart",404);
}
//
// Make the copy
//
unlink(RDCut::pathName(destination_cartnum,destination_cutnum));
if(link(RDCut::pathName(source_cartnum,source_cutnum),
RDCut::pathName(destination_cartnum,destination_cutnum))!=0) {
XmlExit(strerror(errno),400);
}
XmlExit("OK",200);
}

View File

@@ -0,0 +1,66 @@
// deleteaudio.cpp
//
// Rivendell web service portal -- DeleteAudio service
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: deleteaudio.cpp,v 1.6.2.1 2012/07/17 19:29:43 cvs Exp $
//
// 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 <rdformpost.h>
#include <rdweb.h>
#include <rdcart.h>
#include <rdconf.h>
#include <rdxport.h>
void Xport::DeleteAudio()
{
//
// Verify Post
//
int cartnum=0;
if(!xport_post->getValue("CART_NUMBER",&cartnum)) {
XmlExit("Missing CART_NUMBER",400);
}
int cutnum=0;
if(!xport_post->getValue("CUT_NUMBER",&cutnum)) {
XmlExit("Missing CUT_NUMBER",400);
}
//
// Process Request
//
if((!xport_user->deleteCarts())&&(!xport_user->adminConfig())) {
XmlExit("User not authorized",401);
}
RDCut *cut=new RDCut(cartnum,cutnum);
if(!cut->exists()) {
delete cut;
XmlExit("No such cut",404);
}
unlink(RDCut::pathName(cartnum,cutnum));
unlink(RDCut::pathName(cartnum,cutnum)+".energy");
syslog(LOG_NOTICE,"unlink(%s): %s",(const char *)RDCut::pathName(cartnum,cutnum),strerror(errno));
delete cut;
XmlExit("OK",200);
}

202
web/rdxport/export.cpp Normal file
View File

@@ -0,0 +1,202 @@
// export.cpp
//
// Rivendell web service portal -- Export service
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: export.cpp,v 1.6.2.2 2013/10/02 18:25:12 cvs Exp $
//
// 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 <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <rdformpost.h>
#include <rdweb.h>
#include <rdcart.h>
#include <rdaudioconvert.h>
#include <rdsettings.h>
#include <rdconf.h>
#include <rdxport.h>
void Xport::Export()
{
RDAudioConvert::ErrorCode conv_err=RDAudioConvert::ErrorOk;
int resp_code=0;
//
// Verify Post
//
int cartnum=0;
if(!xport_post->getValue("CART_NUMBER",&cartnum)) {
XmlExit("Missing CART_NUMBER",400);
}
int cutnum=0;
if(!xport_post->getValue("CUT_NUMBER",&cutnum)) {
XmlExit("Missing CUT_NUMBER",400);
}
int format=0;
if(!xport_post->getValue("FORMAT",&format)) {
XmlExit("Missing FORMAT",400);
}
int channels=0;
if(!xport_post->getValue("CHANNELS",&channels)) {
XmlExit("Missing CHANNELS",400);
}
int sample_rate=0;
if(!xport_post->getValue("SAMPLE_RATE",&sample_rate)) {
XmlExit("Missing SAMPLE_RATE",400);
}
int bit_rate=0;
if(!xport_post->getValue("BIT_RATE",&bit_rate)) {
XmlExit("Missing BIT_RATE",400);
}
int quality=0;
if(!xport_post->getValue("QUALITY",&quality)) {
XmlExit("Missing QUALITY",400);
}
int start_point=-1;
if(!xport_post->getValue("START_POINT",&start_point)) {
XmlExit("Missing START_POINT",400);
}
int end_point=-1;
if(!xport_post->getValue("END_POINT",&end_point)) {
XmlExit("Missing END_POINT",400);
}
int normalization_level=0;
if(!xport_post->getValue("NORMALIZATION_LEVEL",&normalization_level)) {
XmlExit("Missing NORMALIZATION_LEVEL",400);
}
int enable_metadata=false;
if(!xport_post->getValue("ENABLE_METADATA",&enable_metadata)) {
XmlExit("Missing ENABLE_METADATA",400);
}
if(!RDCart::exists(cartnum)) {
XmlExit("No such cart",404);
}
if(!RDCut::exists(cartnum,cutnum)) {
XmlExit("No such cut",404);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cartnum)) {
XmlExit("No such cart",404);
}
//
// Generate Metadata
//
RDWaveData *wavedata=NULL;
float speed_ratio=1.0;
if(enable_metadata!=0) {
wavedata=new RDWaveData();
}
if(wavedata!=NULL) {
RDCart *cart=new RDCart(cartnum);
RDCut *cut=new RDCut(cartnum,cutnum);
cart->getMetadata(wavedata);
cut->getMetadata(wavedata);
if(cart->enforceLength()) {
speed_ratio=(float)cut->length()/(float)cart->forcedLength();
}
delete cut;
delete cart;
}
//
// Export Cut
//
int fd;
ssize_t n;
uint8_t data[2048];
QString tmpdir=RDTempDir();
QString tmpfile=tmpdir+"/exported_audio";
RDSettings *settings=new RDSettings();
settings->setFormat((RDSettings::Format)format);
settings->setChannels(channels);
settings->setSampleRate(sample_rate);
settings->setBitRate(bit_rate);
settings->setQuality(quality);
settings->setNormalizationLevel(normalization_level);
RDAudioConvert *conv=new RDAudioConvert(xport_config->stationName());
conv->setSourceFile(RDCut::pathName(cartnum,cutnum));
conv->setDestinationFile(tmpfile);
conv->setDestinationSettings(settings);
conv->setDestinationWaveData(wavedata);
conv->setRange(start_point,end_point);
conv->setSpeedRatio(speed_ratio);
switch(conv_err=conv->convert()) {
case RDAudioConvert::ErrorOk:
switch(settings->format()) {
case RDSettings::Pcm16:
printf("Content-type: audio/x-wav\n\n");
break;
case RDSettings::MpegL1:
case RDSettings::MpegL2:
case RDSettings::MpegL2Wav:
case RDSettings::MpegL3:
printf("Content-type: audio/x-mpeg\n\n");
break;
case RDSettings::OggVorbis:
printf("Content-type: audio/ogg\n\n");
break;
case RDSettings::Flac:
printf("Content-type: audio/flac\n\n");
break;
}
fflush(NULL);
if((fd=open(tmpfile,O_RDONLY))>=0) {
while((n=read(fd,data,2048))>0) {
write(1,data,n);
}
}
close(fd);
break;
case RDAudioConvert::ErrorFormatNotSupported:
case RDAudioConvert::ErrorInvalidSettings:
resp_code=415;
break;
case RDAudioConvert::ErrorNoSource:
case RDAudioConvert::ErrorNoDestination:
case RDAudioConvert::ErrorInvalidSource:
case RDAudioConvert::ErrorNoSpace:
case RDAudioConvert::ErrorInternal:
case RDAudioConvert::ErrorNoDisc:
case RDAudioConvert::ErrorNoTrack:
case RDAudioConvert::ErrorInvalidSpeed:
case RDAudioConvert::ErrorFormatError:
resp_code=500;
break;
}
delete conv;
delete settings;
if(wavedata!=NULL) {
delete wavedata;
}
unlink(tmpfile);
rmdir(tmpdir);
exit(0);
}

View File

@@ -0,0 +1,79 @@
// exportpeaks.cpp
//
// Rivendell web service portal -- ExportPeaks service
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: exportpeaks.cpp,v 1.4 2012/02/13 23:01:50 cvs Exp $
//
// 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 <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <rdformpost.h>
#include <rdweb.h>
#include <rdcart.h>
#include <rdaudioconvert.h>
#include <rdsettings.h>
#include <rdconf.h>
#include <rdxport.h>
void Xport::ExportPeaks()
{
//
// Verify Post
//
int cartnum=0;
if(!xport_post->getValue("CART_NUMBER",&cartnum)) {
XmlExit("Missing CART_NUMBER",400);
}
int cutnum=0;
if(!xport_post->getValue("CUT_NUMBER",&cutnum)) {
XmlExit("Missing CUT_NUMBER",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cartnum)) {
XmlExit("No such cart",404);
}
//
// Open Audio File
//
RDWaveFile *wave=new RDWaveFile(RDCut::pathName(cartnum,cutnum));
if(!wave->openWave()) {
XmlExit("No such audio",404);
}
if(!wave->hasEnergy()) {
XmlExit("No peak data available",400);
}
//
// Send Data
//
printf("Content-type: application/octet-stream\n\n");
fflush(NULL);
unsigned short *peaks=new unsigned short[wave->energySize()];
wave->readEnergy(peaks,wave->energySize());
write(1,peaks,sizeof(unsigned short)*wave->energySize());
Exit(0);
}

110
web/rdxport/groups.cpp Normal file
View File

@@ -0,0 +1,110 @@
// groups.cpp
//
// Rivendell web service portal -- Group services
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: groups.cpp,v 1.5 2012/02/13 23:01:50 cvs Exp $
//
// 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 <rdformpost.h>
#include <rdweb.h>
#include <rduser.h>
#include <rdgroup.h>
#include <rdconf.h>
#include <rdescape_string.h>
#include <rdxport.h>
void Xport::ListGroups()
{
QString sql;
RDSqlQuery *q;
RDGroup *group;
//
// Generate Group List
//
sql=QString().sprintf("select GROUP_NAME from USER_PERMS \
where USER_NAME=\"%s\" order by GROUP_NAME",
(const char *)RDEscapeString(xport_user->name()));
q=new RDSqlQuery(sql);
//
// Process Request
//
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<groupList>\n");
while(q->next()) {
group=new RDGroup(q->value(0).toString());
printf("%s",(const char *)group->xml());
delete group;
}
printf("</groupList>\n");
delete q;
Exit(0);
}
void Xport::ListGroup()
{
QString sql;
RDSqlQuery *q;
RDGroup *group;
//
// Verify Post
//
QString group_name;
if(!xport_post->getValue("GROUP_NAME",&group_name)) {
XmlExit("Missing GROUP_NAME",400);
}
//
// Check Group Accessibility
//
sql=QString().sprintf("select GROUP_NAME from USER_PERMS \
where (USER_NAME=\"%s\")&&(GROUP_NAME=\"%s\")",
(const char *)RDEscapeString(xport_user->name()),
(const char *)RDEscapeString(group_name));
q=new RDSqlQuery(sql);
if(!q->first()) {
delete q;
XmlExit("No such group",404);
}
//
// Process Request
//
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
group=new RDGroup(q->value(0).toString());
printf("%s",(const char *)group->xml());
delete group;
delete q;
Exit(0);
}

170
web/rdxport/import.cpp Normal file
View File

@@ -0,0 +1,170 @@
// import.cpp
//
// Rivendell web service portal -- Import service
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: import.cpp,v 1.12.2.2 2014/01/15 19:56:32 cvs Exp $
//
// 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 <rdformpost.h>
#include <rdweb.h>
#include <rdcart.h>
#include <rdaudioconvert.h>
#include <rdsettings.h>
#include <rdconf.h>
#include <rdlibrary_conf.h>
#include <rdxport.h>
void Xport::Import()
{
unsigned length_deviation=0;
unsigned msecs;
int resp_code=0;
//
// Verify Post
//
int cartnum=0;
if(!xport_post->getValue("CART_NUMBER",&cartnum)) {
XmlExit("Missing CART_NUMBER",400);
}
int cutnum=0;
if(!xport_post->getValue("CUT_NUMBER",&cutnum)) {
XmlExit("Missing CUT_NUMBER",400);
}
int channels=0;
if(!xport_post->getValue("CHANNELS",&channels)) {
XmlExit("Missing CHANNELS",400);
}
int normalization_level=0;
if(!xport_post->getValue("NORMALIZATION_LEVEL",&normalization_level)) {
XmlExit("Missing NORMALIZATION_LEVEL",400);
}
int autotrim_level=0;
if(!xport_post->getValue("AUTOTRIM_LEVEL",&autotrim_level)) {
XmlExit("Missing AUTOTRIM_LEVEL",400);
}
int use_metadata=0;
if(!xport_post->getValue("USE_METADATA",&use_metadata)) {
XmlExit("Missing USE_METADATA",400);
}
QString filename;
if(!xport_post->getValue("FILENAME",&filename)) {
XmlExit("Missing FILENAME",400);
}
if(!RDCart::exists(cartnum)) {
XmlExit("No such cart",404);
}
if(!RDCut::exists(cartnum,cutnum)) {
XmlExit("No such cut",404);
}
if(!xport_post->isFile("FILENAME")) {
XmlExit("Missing file data",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cartnum)) {
XmlExit("No such cart",404);
}
if(!xport_user->editAudio()) {
XmlExit("Unauthorized",401);
}
//
// Load Configuration
//
RDCart *cart=new RDCart(cartnum);
RDCut *cut=new RDCut(cartnum,cutnum);
RDLibraryConf *conf=new RDLibraryConf(xport_config->stationName(),0);
RDSettings *settings=new RDSettings();
switch(conf->defaultFormat()) {
case 0:
settings->setFormat(RDSettings::Pcm16);
break;
case 1:
settings->setFormat(RDSettings::MpegL2Wav);
break;
}
settings->setChannels(channels);
settings->setSampleRate(xport_system->sampleRate());
settings->setBitRate(channels*conf->defaultBitrate());
settings->setNormalizationLevel(normalization_level);
RDWaveFile *wave=new RDWaveFile(filename);
if(!wave->openWave()) {
delete wave;
XmlExit("Format Not Supported",415);
}
msecs=wave->getExtTimeLength();
delete wave;
RDAudioConvert *conv=new RDAudioConvert(xport_config->stationName());
conv->setSourceFile(filename);
conv->setDestinationFile(RDCut::pathName(cartnum,cutnum));
conv->setDestinationSettings(settings);
RDAudioConvert::ErrorCode conv_err=conv->convert();
switch(conv_err) {
case RDAudioConvert::ErrorOk:
cut->checkInRecording(xport_config->stationName(),settings,msecs);
if(use_metadata>0) {
cart->setMetadata(conv->sourceWaveData());
cut->setMetadata(conv->sourceWaveData());
}
if(autotrim_level!=0) {
cut->autoTrim(RDCut::AudioBoth,100*autotrim_level);
}
cart->updateLength();
cart->resetRotation();
cart->calculateAverageLength(&length_deviation);
cart->setLengthDeviation(length_deviation);
resp_code=200;
break;
case RDAudioConvert::ErrorFormatNotSupported:
case RDAudioConvert::ErrorInvalidSettings:
resp_code=415;
break;
case RDAudioConvert::ErrorNoSource:
case RDAudioConvert::ErrorNoDestination:
case RDAudioConvert::ErrorInvalidSource:
case RDAudioConvert::ErrorInternal:
case RDAudioConvert::ErrorNoSpace:
case RDAudioConvert::ErrorNoDisc:
case RDAudioConvert::ErrorNoTrack:
case RDAudioConvert::ErrorInvalidSpeed:
resp_code=500;
break;
case RDAudioConvert::ErrorFormatError:
resp_code=400;
break;
}
delete conv;
delete settings;
delete conf;
delete cut;
delete cart;
XmlExit(RDAudioConvert::errorText(conv_err),resp_code,conv_err);
}

123
web/rdxport/logs.cpp Normal file
View File

@@ -0,0 +1,123 @@
// logs.cpp
//
// Rivendell web service portal -- Log services
//
// (C) Copyright 2013 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: logs.cpp,v 1.1.2.4 2013/10/23 23:32:54 cvs Exp $
//
// 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 <rddb.h>
#include <rdformpost.h>
#include <rdweb.h>
#include <rduser.h>
#include <rdlog.h>
#include <rdconf.h>
#include <rdescape_string.h>
#include <rdxport.h>
void Xport::ListLogs()
{
QString sql;
RDSqlQuery *q;
RDLog *log;
QString service_name="";
QString trackable;
//
// Get Options
//
xport_post->getValue("SERVICE_NAME",&service_name);
xport_post->getValue("TRACKABLE",&trackable);
//
// Generate Log List
//
sql="select NAME from LOGS";
if((!service_name.isEmpty())||(trackable=="1")) {
sql+=" where";
if(!service_name.isEmpty()) {
sql+=" (SERVICE=\""+RDEscapeString(service_name)+"\")&&";
}
if(trackable=="1") {
sql+=" (SCHEDULED_TRACKS>0)&&";
}
sql=sql.left(sql.length()-2);
}
sql+=" order by NAME";
q=new RDSqlQuery(sql);
//
// Process Request
//
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<logList>\n");
while(q->next()) {
log=new RDLog(q->value(0).toString());
printf("%s",(const char *)log->xml());
delete log;
}
printf("</logList>\n");
delete q;
Exit(0);
}
void Xport::ListLog()
{
RDLog *log;
QString name="";
//
// Get Options
//
xport_post->getValue("NAME",&name);
//
// Verify that log exists
//
log=new RDLog(name);
if(!log->exists()) {
delete log;
XmlExit("No such log",404);
}
//
// Generate Log Listing
//
RDLogEvent *log_event=log->createLogEvent();
log_event->load(true);
//
// Process Request
//
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("%s\n",(const char *)log_event->xml());
Exit(0);
}

287
web/rdxport/rdxport.cpp Normal file
View File

@@ -0,0 +1,287 @@
// rdxport.cpp
//
// Rivendell web service portal
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: rdxport.cpp,v 1.10.2.3 2013/10/14 04:23:54 cvs Exp $
//
// 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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <map>
#include <qapplication.h>
#include <qdatetime.h>
#include <qstringlist.h>
#include <rddb.h>
#include <rdweb.h>
#include <rdformpost.h>
#include <rdxport_interface.h>
#include <dbversion.h>
#include <rdxport.h>
Xport::Xport(QObject *parent,const char *name)
:QObject(parent,name)
{
xport_user=NULL;
//
// Read Configuration
//
xport_config=new RDConfig();
xport_config->load();
//
// Drop Root Perms
//
if(setgid(xport_config->gid())<0) {
XmlExit("Unable to set Rivendell group",500);
}
if(setuid(xport_config->uid())<0) {
XmlExit("Unable to set Rivendell user",500);
}
if(getuid()==0) {
XmlExit("Rivendell user should never be \"root\"!",500);
}
//
// Open Database
//
QSqlDatabase *db=QSqlDatabase::addDatabase(xport_config->mysqlDriver());
if(!db) {
printf("Content-type: text/html\n\n");
printf("rdfeed: unable to initialize connection to database\n");
Exit(0);
}
db->setDatabaseName(xport_config->mysqlDbname());
db->setUserName(xport_config->mysqlUsername());
db->setPassword(xport_config->mysqlPassword());
db->setHostName(xport_config->mysqlHostname());
if(!db->open()) {
printf("Content-type: text/html\n\n");
printf("rdxport: unable to connect to database\n");
db->removeDatabase(xport_config->mysqlDbname());
Exit(0);
}
RDSqlQuery *q=new RDSqlQuery("select DB from VERSION");
if(!q->first()) {
printf("Content-type: text/html\n");
printf("Status: 500\n\n");
printf("rdxport: missing/invalid database version!\n");
db->removeDatabase(xport_config->mysqlDbname());
Exit(0);
}
if(q->value(0).toUInt()!=RD_VERSION_DATABASE) {
printf("Content-type: text/html\n");
printf("Status: 500\n\n");
printf("rdxport: skewed database version!\n");
db->removeDatabase(xport_config->mysqlDbname());
Exit(0);
}
delete q;
//
// Determine Connection Type
//
if(getenv("REQUEST_METHOD")==NULL) {
printf("Content-type: text/html\n\n");
printf("rdxport: missing REQUEST_METHOD\n");
db->removeDatabase(xport_config->mysqlDbname());
Exit(0);
}
if(QString(getenv("REQUEST_METHOD")).lower()!="post") {
printf("Content-type: text/html\n\n");
printf("rdxport: invalid web method\n");
db->removeDatabase(xport_config->mysqlDbname());
Exit(0);
}
//
// Load System Settings
//
xport_system=new RDSystem();
//
// Generate Post
//
xport_post=new RDFormPost(RDFormPost::AutoEncoded,false);
if(xport_post->error()!=RDFormPost::ErrorOk) {
XmlExit(xport_post->errorString(xport_post->error()),400);
Exit(0);
}
//
// Authenticate Connection
//
if(!Authenticate()) {
XmlExit("Invalid User",403);
}
//
// Read Command Variable and Dispatch
//
int command=xport_post->value("COMMAND").toInt();
switch(command) {
case RDXPORT_COMMAND_EXPORT:
Export();
break;
case RDXPORT_COMMAND_IMPORT:
Import();
break;
case RDXPORT_COMMAND_DELETEAUDIO:
DeleteAudio();
break;
case RDXPORT_COMMAND_LISTGROUPS:
ListGroups();
break;
case RDXPORT_COMMAND_LISTGROUP:
ListGroup();
break;
case RDXPORT_COMMAND_ADDCART:
AddCart();
break;
case RDXPORT_COMMAND_LISTCARTS:
ListCarts();
break;
case RDXPORT_COMMAND_LISTCART:
ListCart();
break;
case RDXPORT_COMMAND_EDITCART:
EditCart();
break;
case RDXPORT_COMMAND_REMOVECART:
RemoveCart();
break;
case RDXPORT_COMMAND_ADDCUT:
AddCut();
break;
case RDXPORT_COMMAND_LISTCUTS:
ListCuts();
break;
case RDXPORT_COMMAND_LISTCUT:
ListCut();
break;
case RDXPORT_COMMAND_EDITCUT:
EditCut();
break;
case RDXPORT_COMMAND_REMOVECUT:
RemoveCut();
break;
case RDXPORT_COMMAND_EXPORT_PEAKS:
ExportPeaks();
break;
case RDXPORT_COMMAND_TRIMAUDIO:
TrimAudio();
break;
case RDXPORT_COMMAND_COPYAUDIO:
CopyAudio();
break;
case RDXPORT_COMMAND_AUDIOINFO:
AudioInfo();
break;
case RDXPORT_COMMAND_LISTLOGS:
ListLogs();
break;
case RDXPORT_COMMAND_LISTLOG:
ListLog();
break;
case RDXPORT_COMMAND_LISTSERVICES:
ListServices();
break;
default:
printf("Content-type: text/html\n\n");
printf("rdxport: missing/invalid command\n");
db->removeDatabase(xport_config->mysqlDbname());
Exit(0);
break;
}
Exit(0);
}
bool Xport::Authenticate()
{
QString name;
QString passwd;
if(!xport_post->getValue("LOGIN_NAME",&name)) {
return false;
}
if(!xport_post->getValue("PASSWORD",&passwd)) {
return false;
}
xport_user=new RDUser(name);
return xport_user->checkPassword(passwd,false);
}
void Xport::Exit(int code)
{
if(xport_post!=NULL) {
delete xport_post;
}
exit(code);
}
void Xport::XmlExit(const QString &str,int code,RDAudioConvert::ErrorCode err)
{
if(xport_post!=NULL) {
delete xport_post;
}
RDXMLResult(str,code,err);
exit(0);
}
int main(int argc,char *argv[])
{
QApplication a(argc,argv,false);
new Xport(NULL,"main");
return a.exec();
}

72
web/rdxport/rdxport.h Normal file
View File

@@ -0,0 +1,72 @@
// rdxport.h
//
// Rivendell web service portal
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: rdxport.h,v 1.7.2.3 2013/10/14 04:23:54 cvs Exp $
//
// 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 RDXPORT_H
#define RDXPORT_H
#include <qobject.h>
#include <rdconfig.h>
#include <rduser.h>
#include <rdsystem.h>
class Xport : public QObject
{
public:
Xport(QObject *parent=0,const char *name=0);
private:
bool Authenticate();
void Export();
void Import();
void DeleteAudio();
void AddCart();
void ListCarts();
void ListCart();
void EditCart();
void RemoveCart();
void AddCut();
void ListCuts();
void ListCut();
void EditCut();
void RemoveCut();
void ListGroups();
void ListGroup();
void ExportPeaks();
void TrimAudio();
void CopyAudio();
void AudioInfo();
void ListLogs();
void ListLog();
void ListServices();
void Exit(int code);
void XmlExit(const QString &str,int code,
RDAudioConvert::ErrorCode err=RDAudioConvert::ErrorOk);
RDFormPost *xport_post;
RDUser *xport_user;
RDConfig *xport_config;
RDSystem *xport_system;
};
#endif // RDXPORT_H

0
web/rdxport/rdxport.pro Normal file
View File

77
web/rdxport/services.cpp Normal file
View File

@@ -0,0 +1,77 @@
// services.cpp
//
// Rivendell web service portal -- Service services
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: services.cpp,v 1.1.2.1 2013/10/11 22:00:53 cvs Exp $
//
// 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 <rddb.h>
#include <rdformpost.h>
#include <rdweb.h>
#include <rduser.h>
#include <rdsvc.h>
#include <rdconf.h>
#include <rdescape_string.h>
#include <rdxport.h>
void Xport::ListServices()
{
QString sql;
RDSqlQuery *q;
RDSvc *svc;
QString trackable;
//
// Get Options
//
xport_post->getValue("TRACKABLE",&trackable);
//
// Generate Service List
//
sql="select NAME from SERVICES";
if(trackable=="1") {
sql+=" where (TRACK_GROUP!=\"\")&&(TRACK_GROUP is not null)";
}
sql+=" order by NAME";
q=new RDSqlQuery(sql);
//
// Process Request
//
printf("Content-type: application/xml\n");
printf("Status: 200\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<serviceList>\n");
while(q->next()) {
svc=new RDSvc(q->value(0).toString());
printf("%s",(const char *)svc->xml());
delete svc;
}
printf("</serviceList>\n");
delete q;
Exit(0);
}

98
web/rdxport/trimaudio.cpp Normal file
View File

@@ -0,0 +1,98 @@
// trimaudio.cpp
//
// Rivendell web service portal -- TrimAudio service
//
// (C) Copyright 2010 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: trimaudio.cpp,v 1.4 2012/02/13 23:01:50 cvs Exp $
//
// 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 <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <rdformpost.h>
#include <rdweb.h>
#include <rdcart.h>
#include <rdaudioconvert.h>
#include <rdsettings.h>
#include <rdconf.h>
#include <rdxport.h>
void Xport::TrimAudio()
{
int point;
//
// Verify Post
//
int cartnum=0;
if(!xport_post->getValue("CART_NUMBER",&cartnum)) {
XmlExit("Missing CART_NUMBER",400);
}
int cutnum=0;
if(!xport_post->getValue("CUT_NUMBER",&cutnum)) {
XmlExit("Missing CUT_NUMBER",400);
}
int trim_level=0;
if(!xport_post->getValue("TRIM_LEVEL",&trim_level)) {
XmlExit("Missing TRIM_LEVEL",400);
}
//
// Verify User Perms
//
if(!xport_user->cartAuthorized(cartnum)) {
XmlExit("No such cart",404);
}
//
// Open Audio File
//
RDWaveFile *wave=new RDWaveFile(RDCut::pathName(cartnum,cutnum));
if(!wave->openWave()) {
XmlExit("No such audio",404);
}
if(!wave->hasEnergy()) {
XmlExit("No peak data available",400);
}
//
// Send Data
//
printf("Content-type: application/xml\n\n");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<trimPoint>\n");
printf(" <cartNumber>%u</cartNumber>\n",cartnum);
printf(" <cutNumber>%d</cutNumber>\n",cutnum);
printf(" <trimLevel>%d</trimLevel>\n",trim_level);
point=wave->startTrim(REFERENCE_LEVEL-trim_level);
if(point>=0) {
point=(double)point*1000.0/(double)wave->getSamplesPerSec();
}
printf(" <startTrimPoint>%d</startTrimPoint>\n",point);
point=wave->endTrim(REFERENCE_LEVEL-trim_level);
if(point>=0) {
point=(double)point*1000.0/(double)wave->getSamplesPerSec();
}
printf(" <endTrimPoint>%d</endTrimPoint>\n",point);
printf("</trimPoint>\n");
Exit(0);
}