Version upgrade 4.00 #45
3 changed files with 109 additions and 0 deletions
|
@ -55,6 +55,8 @@ set(PROJECT_SOURCES
|
|||
|
||||
customs/treewidgetitems.h
|
||||
|
||||
utilities/bwlists.h
|
||||
utilities/bwutils.cpp
|
||||
utilities/chars.h
|
||||
utilities/checks.h
|
||||
utilities/checks.cpp
|
||||
|
|
53
logdoctor/utilities/bwlists.h
Normal file
53
logdoctor/utilities/bwlists.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
#ifndef LOGDOCTOR__UTILITIES__BWLISTS_H
|
||||
#define LOGDOCTOR__UTILITIES__BWLISTS_H
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
//! BWutils
|
||||
/*!
|
||||
Utilities for blacklists and warnlists
|
||||
\see Blasklists, Warnlists
|
||||
*/
|
||||
namespace BWutils
|
||||
{
|
||||
|
||||
//! Returns a sanitized item which can be inserted in a list
|
||||
/*!
|
||||
This fuction doesn't check if the method is actually
|
||||
a valid HTTP method, only whether the given string
|
||||
is sintattically acceptable.
|
||||
\throw BWlistException
|
||||
*/
|
||||
std::string sanitizedMethod( const std::string& item );
|
||||
|
||||
//! Returns a sanitized item which can be inserted in a list
|
||||
/*!
|
||||
This function percent-encodes some of the characters
|
||||
in the provided string: /#&?=+
|
||||
\throw BWlistException
|
||||
*/
|
||||
std::string sanitizedUri( const std::string& item );
|
||||
|
||||
//! Returns a sanitized item which can be inserted in a list
|
||||
/*!
|
||||
This functions doesn't check it the client is actually
|
||||
a valid IP address, only whether it is composed by the
|
||||
proper set of characters (for an IPv4 or an IPv6)
|
||||
\throw BWlistException
|
||||
*/
|
||||
std::string sanitizedClient( const std::string& item );
|
||||
|
||||
//! Returns a sanitized item which can be inserted in a list
|
||||
/*!
|
||||
This function back-slashes every double-quotes in the
|
||||
provided string
|
||||
\throw BWlistException
|
||||
*/
|
||||
std::string sanitizedUserAgent( std::string_view item );
|
||||
|
||||
} // namespace BWutils
|
||||
|
||||
|
||||
#endif // LOGDOCTOR__UTILITIES__BWLISTS_H
|
54
logdoctor/utilities/bwutils.cpp
Normal file
54
logdoctor/utilities/bwutils.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
|
||||
#include "utilities/bwlists.h"
|
||||
|
||||
#include "utilities/strings.h"
|
||||
|
||||
#include "modules/exceptions.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
|
||||
namespace BWutils
|
||||
{
|
||||
|
||||
std::string sanitizedMethod( const std::string& item )
|
||||
{
|
||||
const std::string sanitized_item{ StringOps::strip( item ) };
|
||||
if ( ! StringOps::isAlphabetic( sanitized_item ) ) {
|
||||
// only letters allowed
|
||||
throw BWlistException("Invalid Method");
|
||||
}
|
||||
return StringOps::toUpper( sanitized_item );
|
||||
}
|
||||
|
||||
|
||||
std::string sanitizedUri( const std::string& item )
|
||||
{
|
||||
const std::string sanitized_item{ StringOps::lstrip( item ) };
|
||||
if ( sanitized_item.empty() ) {
|
||||
throw BWlistException("Invalid URI");
|
||||
}
|
||||
return QUrl::toPercentEncoding(
|
||||
QString::fromStdString( sanitized_item ),
|
||||
"/#&?=+"
|
||||
).toStdString();
|
||||
}
|
||||
|
||||
|
||||
std::string sanitizedClient( const std::string& item )
|
||||
{
|
||||
const std::string sanitized_item{ StringOps::strip( item ) };
|
||||
if ( ! StringOps::isIP( sanitized_item ) ) {
|
||||
// only IPv4/IPv6 allowed
|
||||
throw BWlistException("Invalid Client");
|
||||
}
|
||||
return sanitized_item;
|
||||
}
|
||||
|
||||
|
||||
std::string sanitizedUserAgent( std::string_view item )
|
||||
{
|
||||
return StringOps::replace( item, R"(")", R"(\")" );
|
||||
}
|
||||
|
||||
} // namespace BWutils
|
Loading…
Reference in a new issue