#include #include "server.hpp" #include "logger/logger_set.hpp" namespace smtp::checker::errors::settings { // //Public methods // bool Server::Check( manage::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} ); } }