Rivendellaudio/web/rdxport/copyaudio.cpp
Fred Gleason 2ac26727c8 2024-10-23 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in 'CopyAudio' Web API service that failed to log the
	correct	error message when the operation failed.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
2024-10-23 11:13:55 -04:00

90 lines
2.8 KiB
C++

// copyaudio.cpp
//
// Rivendell web service portal -- CopyAudio service
//
// (C) Copyright 2010-2021 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 <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <rdapplication.h>
#include <rdaudioconvert.h>
#include <rdcart.h>
#include <rdconf.h>
#include <rdformpost.h>
#include <rdsettings.h>
#include <rdweb.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,"copyaudio.cpp",LINE_NUMBER);
}
int source_cutnum=0;
if(!xport_post->getValue("SOURCE_CUT_NUMBER",&source_cutnum)) {
XmlExit("Missing SOURCE_CUT_NUMBER",400,"copyaudio.cpp",LINE_NUMBER);
}
int destination_cartnum=0;
if(!xport_post->getValue("DESTINATION_CART_NUMBER",&destination_cartnum)) {
XmlExit("Missing DESTINATION_CART_NUMBER",400,"copyaudio.cpp",LINE_NUMBER);
}
int destination_cutnum=0;
if(!xport_post->getValue("DESTINATION_CUT_NUMBER",&destination_cutnum)) {
XmlExit("Missing DESTINATION_CUT_NUMBER",400,"copyaudio.cpp",LINE_NUMBER);
}
//
// Verify User Perms
//
if(!rda->user()->cartAuthorized(source_cartnum)) {
XmlExit("No such cart",404,"copyaudio.cpp",LINE_NUMBER);
}
if(!rda->user()->cartAuthorized(destination_cartnum)) {
XmlExit("No such cart",404,"copyaudio.cpp",LINE_NUMBER);
}
//
// Make the copy
//
rda->syslog(LOG_NOTICE,"creating hard link %s => %s",
RDCut::pathName(source_cartnum,source_cutnum).toUtf8().constData(),
RDCut::pathName(destination_cartnum,destination_cutnum).toUtf8().constData());
unlink(RDCut::pathName(destination_cartnum,destination_cutnum).toUtf8());
if(link(RDCut::pathName(source_cartnum,source_cutnum).toUtf8(),
RDCut::pathName(destination_cartnum,destination_cutnum).toUtf8())!=0) {
QString err_msg=strerror(errno);
XmlExit(err_msg,400,"copyaudio.cpp",LINE_NUMBER);
}
SendNotification(RDNotification::CartType,RDNotification::ModifyAction,
QVariant(destination_cartnum));
XmlExit("OK",200,"copyaudio.cpp",LINE_NUMBER);
}