summaryrefslogtreecommitdiff
path: root/src/checker/errors/settings/server.cpp
blob: c3f29af1af153652e5dac98e0fe8bbe2651cfd2d (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
#include <regex>

#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;
        }
        return IsNormalName( find->second ) || IsIpName( find->second );
    }

    //
    //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} );
    }

}