2021-09-15 Fred Gleason <fredg@paravelsystems.com>

* Added a ' SaveWebgetFilesDirectory=' directive to rd.conf(5).

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2021-09-15 19:00:45 -04:00
parent 5ec73d077a
commit 0b030e45c2
6 changed files with 91 additions and 2 deletions

View File

@ -20800,3 +20800,5 @@
Traffic import markers.
2021-09-07 Fred Gleason <fredg@paravelsystems.com>
* Incremented the package version to 3.6.2int2.
2021-09-15 Fred Gleason <fredg@paravelsystems.com>
* Added a ' SaveWebgetFilesDirectory=' directive to rd.conf(5).

View File

@ -180,3 +180,12 @@ TranscodingDelay=0
; Suppress the generation of Music Link Markers in logs, even if the
; 'Include Import Markers in Finished Logs' box is checked in rdadmin(1).
; SuppressMusicImportLinks=No
; Save original files processed by the Webget service to the indicated
; directory. Files so saved will have the date-time that the file was
; processed prepended to the original filename, for example:
;
; myfile.mp3 => YYYYMMDD-HHMMSS-myfile.mp3
;
; Default action is to not save files.
; SaveWebgetFilesDirectory=

View File

@ -388,6 +388,12 @@ bool RDConfig::suppressMusicImportLinks() const
}
QString RDConfig::saveWebgetFilesDirectory() const
{
return conf_save_webget_files_directory;
}
int RDConfig::meterBasePort() const
{
return conf_meter_base_port;
@ -610,6 +616,9 @@ bool RDConfig::load()
conf_suppress_music_import_links=
profile->boolValue("Hacks","SuppressMusicImportLinks",false);
conf_save_webget_files_directory=
profile->stringValue("Hacks","SaveWebgetFilesDirectory");
conf_lock_rdairplay_memory=
profile->boolValue("Hacks","LockRdairplayMemory",false);
@ -739,6 +748,7 @@ void RDConfig::clear()
conf_jack_ports[0].clear();
conf_jack_ports[1].clear();
conf_disable_maint_checks=false;
conf_save_webget_files_directory="";
conf_suppress_music_import_links=false;
conf_lock_rdairplay_memory=false;
conf_meter_base_port=RD_DEFAULT_METER_SOCKET_BASE_UDP_PORT;

View File

@ -101,6 +101,7 @@ class RDConfig
bool disableMaintChecks() const;
bool lockRdairplayMemory() const;
bool suppressMusicImportLinks() const;
QString saveWebgetFilesDirectory() const;
int meterBasePort() const;
int meterPortRange() const;
bool enableMixerLogging() const;
@ -174,6 +175,7 @@ class RDConfig
bool conf_disable_maint_checks;
bool conf_lock_rdairplay_memory;
bool conf_suppress_music_import_links;
QString conf_save_webget_files_directory;
int conf_meter_base_port;
int conf_meter_port_range;
std::vector<QString> conf_jack_ports[2];

View File

@ -21,6 +21,7 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdint.h>
@ -470,6 +471,9 @@ void MainObject::PutAudio()
//
QStringList args;
if(!rda->config()->saveWebgetFilesDirectory().isEmpty()) {
SaveSourceFile(filename);
}
args.push_back(QString("--ticket=")+webget_ticket+":"+
webget_post->clientAddress().toString());
args.push_back("--send-mail");
@ -767,6 +771,67 @@ bool MainObject::Authenticate()
}
void MainObject::SaveSourceFile(const QString &filepath) const
{
char buffer[1024];
ssize_t n;
int src_fd=-1;
int dst_fd=-1;
QDir dir(rda->config()->saveWebgetFilesDirectory());
if(!dir.exists()) {
rda->syslog(LOG_WARNING,"SaveWebgetFilesDirectory \"%s\" does not exist",
rda->config()->saveWebgetFilesDirectory().toUtf8().constData());
return;
}
QDateTime now=QDateTime::currentDateTime();
QStringList f0=filepath.split("/",QString::SkipEmptyParts);
QString filename=rda->config()->saveWebgetFilesDirectory()+"/"+
now.toString("yyyyMMdd-hhmmss-")+f0.last();
//
// Open Source File
//
if((src_fd=open(filepath.toUtf8(),O_RDONLY))<0) {
rda->syslog(LOG_WARNING,
"unable to open source file \"%s\" for SaveWebgetFilesDirectory [%s]",
filepath.toUtf8().constData(),strerror(errno));
return;
}
//
// Open Destination File
//
int num=1;
while((dst_fd=open(filename.toUtf8(),O_WRONLY|O_CREAT|O_EXCL,S_IRUSR|S_IRGRP))<0) {
if(errno!=EEXIST) {
rda->syslog(LOG_WARNING,
"unable to open destination file \"%s\" for SaveWebgetFilesDirectory [%s]",
filename.toUtf8().constData(),strerror(errno));
close(src_fd);
return;
}
filename=rda->config()->saveWebgetFilesDirectory()+"/"+
now.toString("yyyyMMdd-hhmmss")+QString().sprintf("[%d]-",num)+f0.last();
num++;
}
//
// Move the data
//
while((n=read(src_fd,buffer,1024))>0) {
write(dst_fd,buffer,n);
}
if(n<0) {
rda->syslog(LOG_WARNING,"error while reading source file \"%s\" for SaveWebgetFilesDirectory [%s]",
filepath.toUtf8().constData(),strerror(errno));
}
close(src_fd);
close(dst_fd);
rda->syslog(LOG_INFO,"saved Webget file \"%s\"",
filename.toUtf8().constData());
}
void MainObject::Exit(int code)
{
if(webget_post!=NULL) {

View File

@ -2,7 +2,7 @@
//
// Rivendell audio upload/download utility
//
// (C) Copyright 2018-2020 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2018-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
@ -21,7 +21,7 @@
#ifndef WEBGET_H
#define WEBGET_H
#include <qobject.h>
#include <QObject>
#include <rdaudioconvert.h>
#include <rdformpost.h>
@ -46,6 +46,7 @@ class MainObject : public QObject
void ServeForm();
void ServeLogin(int resp_code);
bool Authenticate();
void SaveSourceFile(const QString &filepath) const;
void Exit(int code);
void TextExit(const QString &msg,int code,int line) const;
RDFormPost *webget_post;