summaryrefslogtreecommitdiff
path: root/src/checker/errors
diff options
context:
space:
mode:
Diffstat (limited to 'src/checker/errors')
-rw-r--r--src/checker/errors/mail/empty.cpp9
-rw-r--r--src/checker/errors/mail/empty.hpp17
-rw-r--r--src/checker/errors/settings/port_number.cpp48
-rw-r--r--src/checker/errors/settings/port_number.hpp17
-rw-r--r--src/checker/errors/types/imails_error.hpp19
-rw-r--r--src/checker/errors/types/isettings_error.hpp22
6 files changed, 132 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/port_number.cpp b/src/checker/errors/settings/port_number.cpp
new file mode 100644
index 0000000..b02eec4
--- /dev/null
+++ b/src/checker/errors/settings/port_number.cpp
@@ -0,0 +1,48 @@
+#include <stdexcept>
+
+#include "port_number.hpp"
+#include "management/logger.hpp"
+
+namespace smtp::checker::errors::settings
+{
+ bool PortNumber::Check( const manage::SettingsFileDataType& line ) const
+ {
+ static const std::string PORT_FIELD = "port";
+ static constexpr int MIN_PORT_NUMBER = 0;
+ static constexpr int MAX_PORT_NUMBER = 65535;
+
+ //TODO общее использование полей
+ auto find = line.find( PORT_FIELD );
+ if( find == line.end() )
+ {
+ manage::Logger::LogError( "Port doesn't found" );
+ return false;
+ }
+ auto host_as_string = find->second;
+ if( host_as_string.empty())
+ {
+ return true;
+ }
+ int host_as_int{};
+ try
+ {
+ host_as_int = std::stoi( host_as_string );
+ }
+ catch( std::invalid_argument const& ex )
+ {
+ manage::Logger::LogError( "Port doesn't entered by numbers" );
+ return false;
+ }
+ catch( std::out_of_range const& ex )
+ {
+ manage::Logger::LogError( "Port out of range" );
+ return false;
+ }
+ catch( ... )
+ {
+ manage::Logger::LogError( "Port doesn't entered by numbers" );
+ return false;
+ }
+ return host_as_int >= MIN_PORT_NUMBER && host_as_int <= MAX_PORT_NUMBER;
+ }
+}
diff --git a/src/checker/errors/settings/port_number.hpp b/src/checker/errors/settings/port_number.hpp
new file mode 100644
index 0000000..42ab808
--- /dev/null
+++ b/src/checker/errors/settings/port_number.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "checker/errors/types/isettings_error.hpp"
+
+namespace smtp::checker::errors::settings
+{
+ class PortNumber : public types::IErrorSettings
+ {
+ public:
+ PortNumber() = default;
+ ~PortNumber() override = default;
+
+ 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..05f68e3
--- /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 "management/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