2021-09-16 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-16 12:16:08 -04:00
parent 2666c2998e
commit 1bf1d94bfe
6 changed files with 91 additions and 3 deletions

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>
@@ -473,6 +474,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");
@@ -770,6 +774,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;