diff options
author | claiff <claiff@mail.ru> | 2022-09-19 14:03:14 +0300 |
---|---|---|
committer | claiff <claiff@mail.ru> | 2022-09-21 14:28:10 +0300 |
commit | 7a446d48b9270dbe2628b462a54a7a23ff43c572 (patch) | |
tree | 8e677b755c3cb529a40ee17078828bc8cc73bf31 /src/checker | |
parent | 629929ebbe386277c25740bc0f4971aac38444d0 (diff) | |
download | obmc-sila-smtp-7a446d48b9270dbe2628b462a54a7a23ff43c572.tar.xz |
temp
Diffstat (limited to 'src/checker')
-rw-r--r-- | src/checker/errors/mail/empty.cpp | 9 | ||||
-rw-r--r-- | src/checker/errors/mail/empty.hpp | 17 | ||||
-rw-r--r-- | src/checker/errors/settings/host_number.cpp | 36 | ||||
-rw-r--r-- | src/checker/errors/settings/host_number.hpp | 17 | ||||
-rw-r--r-- | src/checker/errors/types/imails_error.hpp | 19 | ||||
-rw-r--r-- | src/checker/errors/types/isettings_error.hpp | 22 | ||||
-rw-r--r-- | src/checker/registrator_mails.cpp | 22 | ||||
-rw-r--r-- | src/checker/registrator_mails.hpp | 19 | ||||
-rw-r--r-- | src/checker/registrator_settings.hpp | 35 |
9 files changed, 196 insertions, 0 deletions
diff --git a/src/checker/errors/mail/empty.cpp b/src/checker/errors/mail/empty.cpp new file mode 100644 index 0000000..06f6f4c --- /dev/null +++ b/src/checker/errors/mail/empty.cpp @@ -0,0 +1,9 @@ +#include "empty.hpp" + +namespace smtp::checker::errors::settings +{ + bool Empty::Check( std::string const& line ) const + { + return !line.empty(); + } +} diff --git a/src/checker/errors/mail/empty.hpp b/src/checker/errors/mail/empty.hpp new file mode 100644 index 0000000..9e8c0da --- /dev/null +++ b/src/checker/errors/mail/empty.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "checker/errors/types/imails_error.hpp" + +namespace smtp::checker::errors::settings +{ + class Empty : public types::IError + { + public: + Empty() = default; + ~Empty() override = default; + + bool Check( std::string const& line ) const override; + }; +} + + diff --git a/src/checker/errors/settings/host_number.cpp b/src/checker/errors/settings/host_number.cpp new file mode 100644 index 0000000..3580265 --- /dev/null +++ b/src/checker/errors/settings/host_number.cpp @@ -0,0 +1,36 @@ +#include "host_number.hpp" +#include "managment/logger.hpp" +#include <stdexcept> +namespace smtp::checker::errors::settings +{ + bool HostNumber::Check( const manage::SettingsFileDataType& line ) const + { + //TODO общее использование полей + auto find = line.find("host"); + if(find == line.end()) + { + manage::Logger::LogError("Host doesn't found"); + return false; + } + int host_as_int{}; + auto host_as_string = find->second; + if(host_as_string.empty()) + { + return true; + } + + try + { + host_as_int = std::stoi( host_as_string ); + } + catch( std::invalid_argument const& ex ) + { + manage::Logger::LogError("Host doesn't entered by numbers"); + } + catch( std::out_of_range const& ex ) + { + manage::Logger::LogError("Host out of range"); + } + return host_as_int >= 0 && host_as_int <= 65535; + } +} diff --git a/src/checker/errors/settings/host_number.hpp b/src/checker/errors/settings/host_number.hpp new file mode 100644 index 0000000..1f2bfe7 --- /dev/null +++ b/src/checker/errors/settings/host_number.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "checker/errors/types/isettings_error.hpp" + +namespace smtp::checker::errors::settings +{ + class HostNumber : public types::IErrorSettings + { + public: + HostNumber() = default; + ~HostNumber() override = default; + + virtual bool Check( const manage::SettingsFileDataType& line ) const override; + }; +} + + diff --git a/src/checker/errors/types/imails_error.hpp b/src/checker/errors/types/imails_error.hpp new file mode 100644 index 0000000..d696bbd --- /dev/null +++ b/src/checker/errors/types/imails_error.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include <memory> +#include <string> + +namespace smtp::checker::errors::types +{ + class IError + { + public: + IError() = default; + virtual ~IError() = default; + + virtual bool Check( std::string const& line ) const = 0; + }; + using IErrorPtr = std::shared_ptr<IError>; +} + + diff --git a/src/checker/errors/types/isettings_error.hpp b/src/checker/errors/types/isettings_error.hpp new file mode 100644 index 0000000..d5a788f --- /dev/null +++ b/src/checker/errors/types/isettings_error.hpp @@ -0,0 +1,22 @@ +// +// Created by claiff on 18.09.22. +// + +#pragma once + +#include <memory> + +#include "managment/general.hpp" + +namespace smtp::checker::errors::types +{ + class IErrorSettings + { + public: + IErrorSettings() = default; + virtual ~IErrorSettings() = default; + + virtual bool Check( manage::SettingsFileDataType const& line ) const = 0; + }; + using IErrorSettingsPtr = std::shared_ptr<IErrorSettings>; +}
\ No newline at end of file diff --git a/src/checker/registrator_mails.cpp b/src/checker/registrator_mails.cpp new file mode 100644 index 0000000..7e844c0 --- /dev/null +++ b/src/checker/registrator_mails.cpp @@ -0,0 +1,22 @@ +#include "registrator_mails.hpp" + +namespace smtp::checker +{ + void RegistratorMails::Add(errors::types::IErrorPtr const& error ) + { + mErrors.push_back( error ); + } + + bool RegistratorMails::Check( std::string const& line ) const + { + for( const auto& error : mErrors ) + { + if( !error->Check( line ) ) + { + return false; + } + } + return true; + } + +} // namespace smtp::checker diff --git a/src/checker/registrator_mails.hpp b/src/checker/registrator_mails.hpp new file mode 100644 index 0000000..86eb41a --- /dev/null +++ b/src/checker/registrator_mails.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "errors/types/imails_error.hpp" +#include <list> + +namespace smtp::checker +{ + class RegistratorMails + { + public: + RegistratorMails() = default; + ~RegistratorMails() = default; + + void Add( errors::types::IErrorPtr const &error ); + bool Check( std::string const& line ) const; + private: + std::list<errors::types::IErrorPtr> mErrors; + }; +} // namespace smtp::checker diff --git a/src/checker/registrator_settings.hpp b/src/checker/registrator_settings.hpp new file mode 100644 index 0000000..fbd12f5 --- /dev/null +++ b/src/checker/registrator_settings.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include "errors/types/isettings_error.hpp" +#include <list> + +namespace smtp::checker +{ + class RegistratorSettings + { + public: + RegistratorSettings() = default; + ~RegistratorSettings() = default; + + void Add( errors::types::IErrorSettingsPtr const& error ) + { + mErrors.push_back( error ); + } + + template<typename T> + bool Check( T const& line ) const + { + for( const auto& error: mErrors ) + { + if( !error->Check( line )) + { + return false; + } + } + return true; + } + + private: + std::list < errors::types::IErrorSettingsPtr > mErrors; + }; +} |