Morphed blacklists and warnlists into dedicated entities
This commit is contained in:
parent
9320b90001
commit
2a87d5d343
15 changed files with 599 additions and 0 deletions
|
@ -98,6 +98,22 @@ set(PROJECT_SOURCES
|
||||||
modules/dialogs/ida_dialog.h
|
modules/dialogs/ida_dialog.h
|
||||||
modules/dialogs/ida_dialog.cpp
|
modules/dialogs/ida_dialog.cpp
|
||||||
|
|
||||||
|
modules/blacklists/blacklists.h
|
||||||
|
modules/blacklists/blacklists.cpp
|
||||||
|
modules/blacklists/modules/lib.h
|
||||||
|
modules/blacklists/modules/blacklist.h
|
||||||
|
modules/blacklists/modules/blacklist.cpp
|
||||||
|
modules/blacklists/modules/blacklist_item.h
|
||||||
|
modules/blacklists/modules/blacklist_item.cpp
|
||||||
|
|
||||||
|
modules/warnlists/warnlists.h
|
||||||
|
modules/warnlists/warnlists.cpp
|
||||||
|
modules/warnlists/modules/lib.h
|
||||||
|
modules/warnlists/modules/warnlist.h
|
||||||
|
modules/warnlists/modules/warnlist.cpp
|
||||||
|
modules/warnlists/modules/warnlist_item.h
|
||||||
|
modules/warnlists/modules/warnlist_item.cpp
|
||||||
|
|
||||||
modules/craplog/craplog.h
|
modules/craplog/craplog.h
|
||||||
modules/craplog/craplog.cpp
|
modules/craplog/craplog.cpp
|
||||||
modules/craplog/modules/lib.h
|
modules/craplog/modules/lib.h
|
||||||
|
|
35
logdoctor/modules/blacklists/blacklists.cpp
Normal file
35
logdoctor/modules/blacklists/blacklists.cpp
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
|
||||||
|
#include "blacklists.h"
|
||||||
|
|
||||||
|
#include "modules/exceptions.h"
|
||||||
|
|
||||||
|
|
||||||
|
const Blacklist& Blacklists::getConst( const WebServer ws ) const
|
||||||
|
{
|
||||||
|
switch (ws) {
|
||||||
|
case WebServer::Apache:
|
||||||
|
return this->apache;
|
||||||
|
case WebServer::Nginx:
|
||||||
|
return this->nginx;
|
||||||
|
case WebServer::IIS:
|
||||||
|
return this->iis;
|
||||||
|
default:
|
||||||
|
// should be unreachable
|
||||||
|
throw DoNotCatchException( "Unexpected WebServer" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Blacklist& Blacklists::get( const WebServer ws )
|
||||||
|
{
|
||||||
|
switch (ws) {
|
||||||
|
case WebServer::Apache:
|
||||||
|
return this->apache;
|
||||||
|
case WebServer::Nginx:
|
||||||
|
return this->nginx;
|
||||||
|
case WebServer::IIS:
|
||||||
|
return this->iis;
|
||||||
|
default:
|
||||||
|
// should be unreachable
|
||||||
|
throw DoNotCatchException( "Unexpected WebServer" );
|
||||||
|
}
|
||||||
|
}
|
74
logdoctor/modules/blacklists/blacklists.h
Normal file
74
logdoctor/modules/blacklists/blacklists.h
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
#ifndef LOGDOCTOR__BLACKLISTS__H
|
||||||
|
#define LOGDOCTOR__BLACKLISTS__H
|
||||||
|
|
||||||
|
|
||||||
|
#include "main_lib.h"
|
||||||
|
|
||||||
|
#include "modules/blacklists/modules/blacklist.h"
|
||||||
|
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
|
|
||||||
|
struct Blacklists final
|
||||||
|
{
|
||||||
|
Blacklist apache;
|
||||||
|
Blacklist nginx;
|
||||||
|
Blacklist iis;
|
||||||
|
|
||||||
|
explicit Blacklists() noexcept = default;
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline bool isUsed( const WebServer ws, const BlacklistField fld )
|
||||||
|
{ return get( ws ).isUsed( fld ); }
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline void setUsed( const WebServer ws, const BlacklistField fld, const bool used )
|
||||||
|
{ get( ws ).setUsed( fld, used ); }
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
const Blacklist& getConst( const WebServer ws ) const;
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
Blacklist& get( const WebServer ws );
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline BlacklistItem& get( const WebServer ws, const BlacklistField fld )
|
||||||
|
{ return get( ws ).get( fld ); }
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline std::vector<std::string>& getList( const WebServer ws, const BlacklistField fld )
|
||||||
|
{ return get( ws, fld ).list; }
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline const std::vector<std::string>& getListConst( const WebServer ws, const BlacklistField fld )
|
||||||
|
{ return get( ws, fld ).list; }
|
||||||
|
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
inline void setList( const WebServer ws, const BlacklistField fld, const std::vector<std::string>& list )
|
||||||
|
{ get( ws, fld ).set( list ); }
|
||||||
|
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
inline void clearList( const WebServer ws, const BlacklistField fld )
|
||||||
|
{ getList( ws, fld ).clear(); }
|
||||||
|
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
inline void addItem( const WebServer ws, const BlacklistField fld, const std::string& item )
|
||||||
|
{ get( ws, fld ).add( item ); }
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
inline void removeItem( const WebServer ws, const BlacklistField fld, const std::string& item )
|
||||||
|
{ get( ws, fld ).remove( item ); }
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
inline int moveUpItem( const WebServer ws, const BlacklistField fld, const std::string& item )
|
||||||
|
{ return get( ws, fld ).moveUp( item ); }
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
inline int moveDownItem( const WebServer ws, const BlacklistField fld, const std::string& item )
|
||||||
|
{ return get( ws, fld ).moveDown( item ); }
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(Blacklists)
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LOGDOCTOR__BLACKLISTS__H
|
21
logdoctor/modules/blacklists/modules/blacklist.cpp
Normal file
21
logdoctor/modules/blacklists/modules/blacklist.cpp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
#include "blacklist.h"
|
||||||
|
|
||||||
|
#include "modules/exceptions.h"
|
||||||
|
|
||||||
|
|
||||||
|
Blacklist::Blacklist() noexcept
|
||||||
|
: client{ BlacklistField::Client }
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BlacklistItem& Blacklist::get( const BlacklistField field )
|
||||||
|
{
|
||||||
|
switch (field) {
|
||||||
|
case BlacklistField::Client:
|
||||||
|
return this->client;
|
||||||
|
default:
|
||||||
|
throw DoNotCatchException( "Unexpected BlacklistField" );
|
||||||
|
}
|
||||||
|
}
|
27
logdoctor/modules/blacklists/modules/blacklist.h
Normal file
27
logdoctor/modules/blacklists/modules/blacklist.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef LOGDOCTOR__BLACKLISTS__BLACKLIST__H
|
||||||
|
#define LOGDOCTOR__BLACKLISTS__BLACKLIST__H
|
||||||
|
|
||||||
|
|
||||||
|
#include "modules/blacklists/modules/blacklist_item.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct Blacklist final
|
||||||
|
{
|
||||||
|
BlacklistItem client;
|
||||||
|
|
||||||
|
explicit Blacklist() noexcept;
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
BlacklistItem& get( const BlacklistField field );
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline bool isUsed( const BlacklistField field )
|
||||||
|
{ return get( field ).used; }
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline void setUsed( const BlacklistField field, const bool used )
|
||||||
|
{ get( field ).used = used; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LOGDOCTOR__BLACKLISTS__BLACKLIST__H
|
76
logdoctor/modules/blacklists/modules/blacklist_item.cpp
Normal file
76
logdoctor/modules/blacklists/modules/blacklist_item.cpp
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
|
||||||
|
#include "blacklist_item.h"
|
||||||
|
|
||||||
|
#include "modules/shared.h"
|
||||||
|
|
||||||
|
#include "modules/exceptions.h"
|
||||||
|
|
||||||
|
#include "utilities/bwlists.h"
|
||||||
|
|
||||||
|
|
||||||
|
const char* BlacklistItem::fieldName() const
|
||||||
|
{
|
||||||
|
switch (this->field) {
|
||||||
|
case BlacklistField::Client:
|
||||||
|
return FIELDS__CLIENT.c_str();
|
||||||
|
default:
|
||||||
|
// should be unreachable
|
||||||
|
throw DoNotCatchException( "Unexpected BlacklistField" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlacklistItem::set( const std::vector<std::string>& new_list )
|
||||||
|
{
|
||||||
|
this->list.clear();
|
||||||
|
this->list.reserve( new_list.size() );
|
||||||
|
for ( const std::string& item : new_list ) {
|
||||||
|
this->add( item );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlacklistItem::add( const std::string& item )
|
||||||
|
{
|
||||||
|
this->list.push_back( this->sanitized( item ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlacklistItem::remove( const std::string& item )
|
||||||
|
{
|
||||||
|
if ( const auto it{ std::find( this->list.cbegin(), this->list.cend(), item ) }; it != this->list.cend() ) {
|
||||||
|
this->list.erase( it );
|
||||||
|
} else {
|
||||||
|
throw BWlistException( "Failed to remove the item: "+item );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int BlacklistItem::moveUp( const std::string& item )
|
||||||
|
{
|
||||||
|
if ( auto it{ std::find( std::next(this->list.begin()), this->list.end(), item ) }; it != this->list.end() ) {
|
||||||
|
const int pos{ static_cast<int>( std::distance(this->list.begin(), it) ) - 1 };
|
||||||
|
std::swap( *it, *std::prev(it) );
|
||||||
|
return pos;
|
||||||
|
} else {
|
||||||
|
throw BWlistException( "Failed to move up the item: "+item );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int BlacklistItem::moveDown( const std::string& item )
|
||||||
|
{
|
||||||
|
if ( auto it{ std::find( this->list.begin(), std::prev(this->list.end()), item ) }; it != this->list.end() ) {
|
||||||
|
const int pos{ static_cast<int>( std::distance(this->list.begin(), it) ) + 1 };
|
||||||
|
std::swap( *it, *std::next(it) );
|
||||||
|
return pos;
|
||||||
|
} else {
|
||||||
|
throw BWlistException( "Failed to move down the item: "+item );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BlacklistItem::sanitized(const std::string& item ) const
|
||||||
|
{
|
||||||
|
switch (this->field) {
|
||||||
|
case BlacklistField::Client:
|
||||||
|
return BWutils::sanitizedClient( item );
|
||||||
|
default:
|
||||||
|
// should be unreachable
|
||||||
|
throw DoNotCatchException( "Unexpected BlacklistField" );
|
||||||
|
}
|
||||||
|
}
|
46
logdoctor/modules/blacklists/modules/blacklist_item.h
Normal file
46
logdoctor/modules/blacklists/modules/blacklist_item.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#ifndef LOGDOCTOR__BLACKLISTS__BLACKLISTITEM__H
|
||||||
|
#define LOGDOCTOR__BLACKLISTS__BLACKLISTITEM__H
|
||||||
|
|
||||||
|
|
||||||
|
#include "modules/blacklists/modules/lib.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
struct BlacklistItem final
|
||||||
|
{
|
||||||
|
bool used;
|
||||||
|
BlacklistField field;
|
||||||
|
std::vector<std::string> list;
|
||||||
|
|
||||||
|
BlacklistItem( const BlacklistField fld ) noexcept
|
||||||
|
: used{false}, field{fld} {}
|
||||||
|
BlacklistItem( const bool use, const BlacklistField fld ) noexcept
|
||||||
|
: used{use}, field{fld} {}
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
const char* fieldName() const;
|
||||||
|
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
void set( const std::vector<std::string>& new_list );
|
||||||
|
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
void add( const std::string& item );
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
void remove( const std::string& item );
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
int moveUp( const std::string& item );
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
int moveDown( const std::string& item );
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
std::string sanitized( const std::string& item ) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LOGDOCTOR__BLACKLISTS__BLACKLISTITEM__H
|
11
logdoctor/modules/blacklists/modules/lib.h
Normal file
11
logdoctor/modules/blacklists/modules/lib.h
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef LOGDOCTOR__BLACKLISTS__LIB__H
|
||||||
|
#define LOGDOCTOR__BLACKLISTS__LIB__H
|
||||||
|
|
||||||
|
|
||||||
|
enum class BlacklistField
|
||||||
|
{
|
||||||
|
Client
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LOGDOCTOR__BLACKLISTS__LIB__H
|
14
logdoctor/modules/warnlists/modules/lib.h
Normal file
14
logdoctor/modules/warnlists/modules/lib.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef LOGDOCTOR__WARNLISTS__LIB__H
|
||||||
|
#define LOGDOCTOR__WARNLISTS__LIB__H
|
||||||
|
|
||||||
|
|
||||||
|
enum class WarnlistField
|
||||||
|
{
|
||||||
|
Method,
|
||||||
|
Uri,
|
||||||
|
Client,
|
||||||
|
UserAgent
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LOGDOCTOR__WARNLISTS__LIB__H
|
30
logdoctor/modules/warnlists/modules/warnlist.cpp
Normal file
30
logdoctor/modules/warnlists/modules/warnlist.cpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
|
||||||
|
#include "warnlist.h"
|
||||||
|
|
||||||
|
#include "modules/exceptions.h"
|
||||||
|
|
||||||
|
|
||||||
|
Warnlist::Warnlist() noexcept
|
||||||
|
: method{ WarnlistField::Method }
|
||||||
|
, uri{ WarnlistField::Uri }
|
||||||
|
, client{ WarnlistField::Client }
|
||||||
|
, user_agent{ WarnlistField::UserAgent }
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WarnlistItem& Warnlist::get( const WarnlistField field )
|
||||||
|
{
|
||||||
|
switch (field) {
|
||||||
|
case WarnlistField::Method:
|
||||||
|
return this->method;
|
||||||
|
case WarnlistField::Uri:
|
||||||
|
return this->uri;
|
||||||
|
case WarnlistField::Client:
|
||||||
|
return this->client;
|
||||||
|
case WarnlistField::UserAgent:
|
||||||
|
return this->user_agent;
|
||||||
|
default:
|
||||||
|
throw DoNotCatchException( "Unexpected WarnlistField" );
|
||||||
|
}
|
||||||
|
}
|
29
logdoctor/modules/warnlists/modules/warnlist.h
Normal file
29
logdoctor/modules/warnlists/modules/warnlist.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef LOGDOCTOR__WARNLISTS__WARNLIST__H
|
||||||
|
#define LOGDOCTOR__WARNLISTS__WARNLIST__H
|
||||||
|
|
||||||
|
|
||||||
|
#include "modules/warnlists/modules/warnlist_item.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct Warnlist final
|
||||||
|
{
|
||||||
|
WarnlistItem method;
|
||||||
|
WarnlistItem uri;
|
||||||
|
WarnlistItem client;
|
||||||
|
WarnlistItem user_agent;
|
||||||
|
|
||||||
|
explicit Warnlist() noexcept;
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
WarnlistItem& get( const WarnlistField field );
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline bool isUsed( const WarnlistField field )
|
||||||
|
{ return get( field ).used; }
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline void setUsed( const WarnlistField field, const bool used )
|
||||||
|
{ get( field ).used = used; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOGDOCTOR__WARNLISTS__WARNLIST__H
|
88
logdoctor/modules/warnlists/modules/warnlist_item.cpp
Normal file
88
logdoctor/modules/warnlists/modules/warnlist_item.cpp
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
|
||||||
|
#include "warnlist_item.h"
|
||||||
|
|
||||||
|
#include "modules/shared.h"
|
||||||
|
|
||||||
|
#include "modules/exceptions.h"
|
||||||
|
|
||||||
|
#include "utilities/bwlists.h"
|
||||||
|
|
||||||
|
|
||||||
|
const char* WarnlistItem::fieldName() const
|
||||||
|
{
|
||||||
|
switch (this->field) {
|
||||||
|
case WarnlistField::Method:
|
||||||
|
return FIELDS__METHOD.c_str();
|
||||||
|
case WarnlistField::Uri:
|
||||||
|
return FIELDS__URI.c_str();
|
||||||
|
case WarnlistField::Client:
|
||||||
|
return FIELDS__CLIENT.c_str();
|
||||||
|
case WarnlistField::UserAgent:
|
||||||
|
return FIELDS__USER_AGENT.c_str();
|
||||||
|
default:
|
||||||
|
// should be unreachable
|
||||||
|
throw DoNotCatchException( "Unexpected WarnlistField" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WarnlistItem::set( const std::vector<std::string>& new_list )
|
||||||
|
{
|
||||||
|
this->list.clear();
|
||||||
|
this->list.reserve( new_list.size() );
|
||||||
|
for ( const std::string& item : new_list ) {
|
||||||
|
this->add( item );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WarnlistItem::add( const std::string& item )
|
||||||
|
{
|
||||||
|
this->list.push_back( this->sanitized( item ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void WarnlistItem::remove( const std::string& item )
|
||||||
|
{
|
||||||
|
if ( const auto it{ std::find( this->list.cbegin(), this->list.cend(), item ) }; it != this->list.cend() ) {
|
||||||
|
this->list.erase( it );
|
||||||
|
} else {
|
||||||
|
throw BWlistException( "Failed to remove the item: "+item );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int WarnlistItem::moveUp( const std::string& item )
|
||||||
|
{
|
||||||
|
if ( auto it{ std::find( std::next(this->list.begin()), this->list.end(), item ) }; it != this->list.end() ) {
|
||||||
|
const int pos{ static_cast<int>( std::distance(this->list.begin(), it) ) - 1 };
|
||||||
|
std::swap( *it, *std::prev(it) );
|
||||||
|
return pos;
|
||||||
|
} else {
|
||||||
|
throw BWlistException( "Failed to move up the item: "+item );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int WarnlistItem::moveDown( const std::string& item )
|
||||||
|
{
|
||||||
|
if ( auto it{ std::find( this->list.begin(), std::prev(this->list.end()), item ) }; it != this->list.end() ) {
|
||||||
|
const int pos{ static_cast<int>( std::distance(this->list.begin(), it) ) + 1 };
|
||||||
|
std::swap( *it, *std::next(it) );
|
||||||
|
return pos;
|
||||||
|
} else {
|
||||||
|
throw BWlistException( "Failed to move down the item: "+item );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string WarnlistItem::sanitized( const std::string& item ) const
|
||||||
|
{
|
||||||
|
switch (this->field) {
|
||||||
|
case WarnlistField::Method:
|
||||||
|
return BWutils::sanitizedMethod( item );
|
||||||
|
case WarnlistField::Uri:
|
||||||
|
return BWutils::sanitizedUri( item );
|
||||||
|
case WarnlistField::Client:
|
||||||
|
return BWutils::sanitizedClient( item );
|
||||||
|
case WarnlistField::UserAgent:
|
||||||
|
return BWutils::sanitizedUserAgent( item );
|
||||||
|
default:
|
||||||
|
// should be unreachable
|
||||||
|
throw DoNotCatchException( "Unexpected WarnlistField" );
|
||||||
|
}
|
||||||
|
}
|
45
logdoctor/modules/warnlists/modules/warnlist_item.h
Normal file
45
logdoctor/modules/warnlists/modules/warnlist_item.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef LOGDOCTOR__WARNLISTS__WARNLISTITEM__H
|
||||||
|
#define LOGDOCTOR__WARNLISTS__WARNLISTITEM__H
|
||||||
|
|
||||||
|
|
||||||
|
#include "modules/warnlists/modules/lib.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
struct WarnlistItem final
|
||||||
|
{
|
||||||
|
bool used;
|
||||||
|
WarnlistField field;
|
||||||
|
std::vector<std::string> list;
|
||||||
|
|
||||||
|
WarnlistItem( const WarnlistField fld ) noexcept
|
||||||
|
: used{false}, field{fld} {}
|
||||||
|
WarnlistItem( const bool use, const WarnlistField fld ) noexcept
|
||||||
|
: used{use}, field{fld} {}
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
const char* fieldName() const;
|
||||||
|
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
void set( const std::vector<std::string>& new_list );
|
||||||
|
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
void add( const std::string& item );
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
void remove( const std::string& item );
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
int moveUp( const std::string& item );
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
int moveDown( const std::string& item );
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
std::string sanitized( const std::string& item ) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOGDOCTOR__WARNLISTS__WARNLISTITEM__H
|
20
logdoctor/modules/warnlists/warnlists.cpp
Normal file
20
logdoctor/modules/warnlists/warnlists.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
#include "warnlists.h"
|
||||||
|
|
||||||
|
#include "modules/exceptions.h"
|
||||||
|
|
||||||
|
|
||||||
|
Warnlist& Warnlists::get( const WebServer ws )
|
||||||
|
{
|
||||||
|
switch (ws) {
|
||||||
|
case WebServer::Apache:
|
||||||
|
return this->apache;
|
||||||
|
case WebServer::Nginx:
|
||||||
|
return this->nginx;
|
||||||
|
case WebServer::IIS:
|
||||||
|
return this->iis;
|
||||||
|
default:
|
||||||
|
// should be unreachable
|
||||||
|
throw DoNotCatchException( "Unexpected WebServer" );
|
||||||
|
}
|
||||||
|
}
|
67
logdoctor/modules/warnlists/warnlists.h
Normal file
67
logdoctor/modules/warnlists/warnlists.h
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#ifndef LOGDOCTOR__WARNLISTS__H
|
||||||
|
#define LOGDOCTOR__WARNLISTS__H
|
||||||
|
|
||||||
|
|
||||||
|
#include "main_lib.h"
|
||||||
|
|
||||||
|
#include "modules/warnlists/modules/warnlist.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct Warnlists final
|
||||||
|
{
|
||||||
|
Warnlist apache;
|
||||||
|
Warnlist nginx;
|
||||||
|
Warnlist iis;
|
||||||
|
|
||||||
|
explicit Warnlists() noexcept = default;
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline bool isUsed( const WebServer ws, const WarnlistField fld )
|
||||||
|
{ return get( ws ).isUsed( fld ); }
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline void setUsed( const WebServer ws, const WarnlistField fld, const bool used )
|
||||||
|
{ get( ws ).setUsed( fld, used ); }
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
Warnlist& get( const WebServer ws );
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline WarnlistItem& get( const WebServer ws, const WarnlistField fld )
|
||||||
|
{ return get( ws ).get( fld ); }
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline std::vector<std::string>& getList( const WebServer ws, const WarnlistField fld )
|
||||||
|
{ return get( ws, fld ).list; }
|
||||||
|
|
||||||
|
//! \throw DoNotCatchException
|
||||||
|
inline const std::vector<std::string>& getListConst( const WebServer ws, const WarnlistField fld )
|
||||||
|
{ return get( ws, fld ).list; }
|
||||||
|
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
inline void setList( const WebServer ws, const WarnlistField fld, const std::vector<std::string>& list )
|
||||||
|
{ get( ws, fld ).set( list ); }
|
||||||
|
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
inline void clearList( const WebServer ws, const WarnlistField fld )
|
||||||
|
{ getList( ws, fld ).clear(); }
|
||||||
|
|
||||||
|
//! \throw BWlistException, DoNotCatchException
|
||||||
|
inline void addItem( const WebServer ws, const WarnlistField fld, const std::string& item )
|
||||||
|
{ get( ws, fld ).add( item ); }
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
inline void removeItem( const WebServer ws, const WarnlistField fld, const std::string& item )
|
||||||
|
{ get( ws, fld ).remove( item ); }
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
inline int moveUpItem( const WebServer ws, const WarnlistField fld, const std::string& item )
|
||||||
|
{ return get( ws, fld ).moveUp( item ); }
|
||||||
|
|
||||||
|
//! \throw BWlistException
|
||||||
|
inline int moveDownItem( const WebServer ws, const WarnlistField fld, const std::string& item )
|
||||||
|
{ return get( ws, fld ).moveDown( item ); }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LOGDOCTOR__WARNLISTS__H
|
Loading…
Reference in a new issue