blob: ecddf9a9ca81b8b97074f2036f7753ed61183c9d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include <regex>
#include "server.hpp"
#include "logger/logger_set.hpp"
namespace smtp::checker::errors::settings
{
//
//Public methods
//
bool Server::Check( general::SettingsFileDataType const& line ) const
{
static const std::string SERVER_FIELD = "host";
auto find = line.find( SERVER_FIELD );
if( find == line.end() )
{
logger::LoggerSet::GetInstance()->LogError( GetMethodName(), "Host doesn't found" );
return false;
}
auto result = IsNormalName( find->second ) || IsIpName( find->second );
if( !result )
{
logger::LoggerSet::GetInstance()->LogError( GetMethodName(), "Host set incorrectly" );
}
return result;
}
//
//Private methods
//
bool Server::IsNormalName( std::string const& line ) const
{
std::string mask = "^[a-zA-Z](?:\.?[a-zA-Z0-9 ]+)+$";
return std::regex_search( line, std::regex{mask} );
}
bool Server::IsIpName( std::string const& line) const
{
std::string mask = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
return std::regex_search( line, std::regex{mask} );
}
}
|