2017-12-18 Fred Gleason <fredg@paravelsystems.com>

* Added a 'LOGS.LOCK_USER_NAME' field to the database.
	* Added a 'LOGS.LOCK_STATION_NAME' field to the database.
	* Added a 'LOGS.LOCK_IPV4_ADDRESS' field to the database.
	* Added a 'LOGS.LOCK_DATETIME' field to the database.
	* Incremented the database version to 273.
	* Added log locking logic to rdlogedit(1).
This commit is contained in:
Fred Gleason
2017-12-19 18:14:59 -05:00
parent b9773575a2
commit d3e6912663
20 changed files with 392 additions and 7 deletions

View File

@@ -166,10 +166,11 @@ dist_librd_la_SOURCES = dbversion.h\
rdlivewiredestination.cpp rdlivewiredestination.h\
rdlivewiresource.cpp rdlivewiresource.h\
rdlog.cpp rdlog.h\
rdlogfilter.cpp rdlogfilter.h\
rdlogedit_conf.cpp rdlogedit_conf.h\
rdlog_event.cpp rdlog_event.h\
rdlog_line.cpp rdlog_line.h\
rdlogedit_conf.cpp rdlogedit_conf.h\
rdlogfilter.cpp rdlogfilter.h\
rdloglock.cpp rdloglock.h\
rdmacro.cpp rdmacro.h\
rdmacro_event.cpp rdmacro_event.h\
rdmarker_bar.cpp rdmarker_bar.h\
@@ -302,6 +303,7 @@ nodist_librd_la_SOURCES = moc_rdadd_cart.cpp\
moc_rdlistview.cpp\
moc_rdlivewire.cpp\
moc_rdlogfilter.cpp\
moc_rdloglock.cpp\
moc_rdmacro_event.cpp\
moc_rdmarker_bar.cpp\
moc_rdmarker_edit.cpp\

View File

@@ -24,7 +24,7 @@
/*
* Current Database Version
*/
#define RD_VERSION_DATABASE 272
#define RD_VERSION_DATABASE 273
#endif // DBVERSION_H

View File

@@ -89,6 +89,7 @@ SOURCES += rdlog_event.cpp
SOURCES += rdlog_line.cpp
SOURCES += rdlogedit_conf.cpp
SOURCES += rdlogfilter.cpp
SOURCES += rdloglock.cpp
SOURCES += rdmacro.cpp
SOURCES += rdmacro_event.cpp
SOURCES += rdoneshot.cpp
@@ -230,6 +231,7 @@ HEADERS += rdlog_event.h
HEADERS += rdlog_line.h
HEADERS += rdlogedit_conf.h
HEADERS += rdlogfilter.h
HEADERS += rdloglock.h
HEADERS += rdmacro.h
HEADERS += rdmacro_event.h
HEADERS += rdoneshot.h

View File

@@ -567,4 +567,10 @@
*/
#define RD_LOGFILTER_LIMIT_QUAN 14
/*
* Log Locking Timeout
*/
#define RD_LOG_LOCK_TIMEOUT 30000
#endif // RD_H

147
lib/rdloglock.cpp Normal file
View File

@@ -0,0 +1,147 @@
// rdloglock.cpp
//
// Log locking routines for Rivendell
//
// (C) Copyright 2017 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.
//
#ifndef WIN32
#include <syslog.h>
#endif // WIN32
#include <qdatetime.h>
#include "rddb.h"
#include "rdescape_string.h"
#include "rdloglock.h"
RDLogLock::RDLogLock(const QString &log_name,RDUser *user,RDStation *station,
QObject *parent)
: QObject(parent)
{
lock_log_name=log_name;
lock_user=user;
lock_station=station;
lock_locked=false;
lock_timer=new QTimer(this);
connect(lock_timer,SIGNAL(timeout()),this,SLOT(updateLock()));
}
RDLogLock::~RDLogLock()
{
if(lock_locked) {
clearLock();
}
delete lock_timer;
}
bool RDLogLock::isLocked() const
{
return lock_locked;
}
bool RDLogLock::tryLock(QString *username,QString *stationname,
QHostAddress *addr)
{
QString sql;
RDSqlQuery *q;
RDSqlQuery *q1;
bool ret=false;
QDateTime now=QDateTime::currentDateTime();
sql=QString("update LOGS set ")+
"LOCK_USER_NAME=\""+RDEscapeString(lock_user->name())+"\","+
"LOCK_STATION_NAME=\""+RDEscapeString(lock_station->name())+"\","+
"LOCK_IPV4_ADDRESS=\""+RDEscapeString(lock_station->address().toString())+
"\","+
"LOCK_DATETIME=now() where "+
"(NAME=\""+RDEscapeString(lock_log_name)+"\")&&"+
"((LOCK_DATETIME is null)||"+
"(LOCK_DATETIME<\""+RDEscapeString(now.addSecs(-RD_LOG_LOCK_TIMEOUT/1000).toString("yyyy-MM-dd hh:mm:ss"))+"\"))";
q=new RDSqlQuery(sql);
if(q->numRowsAffected()>0) {
lock_timer->start(RD_LOG_LOCK_TIMEOUT/2);
lock_locked=true;
ret=true;
}
else {
sql=QString("select ")+
"LOCK_USER_NAME,"+
"LOCK_STATION_NAME,"+
"LOCK_IPV4_ADDRESS "+
"from LOGS where "+
"NAME=\""+RDEscapeString(lock_log_name)+"\"";
q1=new RDSqlQuery(sql);
if(q1->first()) {
*username=q1->value(0).toString();
*stationname=q1->value(1).toString();
addr->setAddress(q1->value(2).toString());
}
delete q1;
}
delete q;
return ret;
}
void RDLogLock::clearLock()
{
QString sql;
RDSqlQuery *q;
sql=QString("update LOGS set ")+
"LOCK_USER_NAME=null,"+
"LOCK_STATION_NAME=null,"+
"LOCK_IPV4_ADDRESS=null,"+
"LOCK_DATETIME=null where "+
"(NAME=\""+RDEscapeString(lock_log_name)+"\")&&"+
"(LOCK_USER_NAME=\""+RDEscapeString(lock_user->name())+"\")&&"+
"(LOCK_STATION_NAME=\""+RDEscapeString(lock_station->name())+"\")&&"+
"(LOCK_IPV4_ADDRESS=\""+RDEscapeString(lock_station->address().toString())+
"\")";
q=new RDSqlQuery(sql);
delete q;
lock_timer->stop();
lock_locked=false;
}
void RDLogLock::updateLock()
{
QString sql;
RDSqlQuery *q;
sql=QString("update LOGS set ")+
"LOCK_DATETIME=now() where "+
"(NAME=\""+RDEscapeString(lock_log_name)+"\")&&"+
"(LOCK_USER_NAME=\""+RDEscapeString(lock_user->name())+"\")&&"+
"(LOCK_STATION_NAME=\""+RDEscapeString(lock_station->name())+"\")&&"+
"(LOCK_IPV4_ADDRESS=\""+RDEscapeString(lock_station->address().toString())+
"\")";
q=new RDSqlQuery(sql);
#ifndef WIN32
if(q->numRowsAffected()==0) {
syslog(LOG_WARNING,"lock on log \"%s\" has gone stale",
(const char *)lock_log_name);
}
#endif // WIN32
delete q;
}

55
lib/rdloglock.h Normal file
View File

@@ -0,0 +1,55 @@
// rdloglock.h
//
// Log locking routines for Rivendell
//
// (C) Copyright 2017 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.
//
#ifndef RDLOGLOCK_H
#define RDLOGLOCK_H
#include <qhostaddress.h>
#include <qobject.h>
#include <qtimer.h>
#include <rd.h>
#include <rduser.h>
#include <rdstation.h>
class RDLogLock : public QObject
{
Q_OBJECT;
public:
RDLogLock(const QString &log_name,RDUser *user,RDStation *station,
QObject *parent=0);
~RDLogLock();
bool isLocked() const;
bool tryLock(QString *username,QString *stationname,QHostAddress *addr);
void clearLock();
private slots:
void updateLock();
private:
QString lock_log_name;
RDUser *lock_user;
RDStation *lock_station;
QTimer *lock_timer;
bool lock_locked;
};
#endif // RDLOGLOCK_H