From 7a446d48b9270dbe2628b462a54a7a23ff43c572 Mon Sep 17 00:00:00 2001 From: claiff Date: Mon, 19 Sep 2022 14:03:14 +0300 Subject: temp --- src/checker/errors/mail/empty.cpp | 9 +++++++ src/checker/errors/mail/empty.hpp | 17 +++++++++++++ src/checker/errors/settings/host_number.cpp | 36 ++++++++++++++++++++++++++++ src/checker/errors/settings/host_number.hpp | 17 +++++++++++++ src/checker/errors/types/imails_error.hpp | 19 +++++++++++++++ src/checker/errors/types/isettings_error.hpp | 22 +++++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 src/checker/errors/mail/empty.cpp create mode 100644 src/checker/errors/mail/empty.hpp create mode 100644 src/checker/errors/settings/host_number.cpp create mode 100644 src/checker/errors/settings/host_number.hpp create mode 100644 src/checker/errors/types/imails_error.hpp create mode 100644 src/checker/errors/types/isettings_error.hpp (limited to 'src/checker/errors') 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 +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 +#include + +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; +} + + 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 + +#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; +} \ No newline at end of file -- cgit v1.2.3