summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclaiff <claiff@mail.ru>2022-10-05 16:02:06 +0300
committerclaiff <claiff@mail.ru>2022-10-05 16:02:06 +0300
commit3f1f70a3b945605c6abb7d23f46042b963db243a (patch)
treec7ae9c113d29aa3350eca04f27a933bd3b5f769c
parent9ed43c1057eeec6a01b8fdfd4d2ee54f9df39670 (diff)
parent43e721305c866ad4b2c4c35d1133f169e41dd49b (diff)
downloadobmc-sila-smtp-3f1f70a3b945605c6abb7d23f46042b963db243a.tar.xz
Merge branch 'devtool' into refactor/3009refactor/3009
-rw-r--r--CMakeLists.txt27
-rw-r--r--src/converter/file_to_string.cpp24
-rw-r--r--src/converter/file_to_string.hpp19
-rw-r--r--src/converter/struct_to_file.hpp5
-rw-r--r--src/file/mail.hpp27
-rw-r--r--src/file/mail/checker_decorator.cpp58
-rw-r--r--src/file/mail/checker_decorator.hpp25
-rw-r--r--src/file/mail/file_decorator.cpp (renamed from src/file/mail.cpp)30
-rw-r--r--src/file/mail/file_decorator.hpp24
-rw-r--r--src/file/mail/sort_decorator.cpp33
-rw-r--r--src/file/mail/sort_decorator.hpp19
-rw-r--r--src/file/mail/types/ifile_manipulator.hpp18
-rw-r--r--src/file/settings.cpp99
-rw-r--r--src/file/settings/checker_decorator.cpp42
-rw-r--r--src/file/settings/checker_decorator.hpp21
-rw-r--r--src/file/settings/file_decorator.cpp77
-rw-r--r--src/file/settings/file_decorator.hpp22
-rw-r--r--src/file/settings/parser.cpp (renamed from src/file/parser/settings.cpp)2
-rw-r--r--src/file/settings/parser.hpp (renamed from src/file/parser/settings.hpp)0
-rw-r--r--src/file/settings/settings.cpp31
-rw-r--r--src/file/settings/settings.hpp (renamed from src/file/settings.hpp)9
-rw-r--r--src/file/settings/types/ifile_manipulator.hpp18
-rw-r--r--src/management/builder/mail.cpp20
-rw-r--r--src/management/builder/mail.hpp3
-rw-r--r--src/management/builder/settings.cpp27
-rw-r--r--src/management/builder/settings.hpp4
-rw-r--r--src/management/mail.cpp56
-rw-r--r--src/management/mail.hpp14
-rw-r--r--src/management/settings.cpp2
-rw-r--r--src/management/settings.hpp6
-rw-r--r--src/service/smtp.cpp2
31 files changed, 539 insertions, 225 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 270cfb4..cba5aa3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -93,7 +93,6 @@ set(MESSAGE_DIR src/message)
set(SERVICE_DIR src/service)
set(MANAGEMENT_DIR src/management)
set(FILE_DIR src/file)
-set(PARSER_DIR src/file/parser)
set(MANAGER_BUILDER_DIR src/management/builder)
set(CONVERTER_DIR src/converter)
set(LOGGER_DIR src/logger)
@@ -129,21 +128,33 @@ set(SRC_FILES
${MANAGEMENT_DIR}/settings.cpp
${MANAGEMENT_DIR}/general.hpp
- ${FILE_DIR}/mail.hpp
- ${FILE_DIR}/mail.cpp
- ${FILE_DIR}/settings.hpp
- ${FILE_DIR}/settings.cpp
+ ${FILE_DIR}/mail/file_decorator.hpp
+ ${FILE_DIR}/mail/file_decorator.cpp
+ ${FILE_DIR}/mail/sort_decorator.hpp
+ ${FILE_DIR}/mail/sort_decorator.cpp
+ ${FILE_DIR}/mail/checker_decorator.hpp
+ ${FILE_DIR}/mail/checker_decorator.cpp
+ ${FILE_DIR}/mail/types/ifile_manipulator.hpp
+
+ ${FILE_DIR}/settings/settings.hpp
+ ${FILE_DIR}/settings/settings.cpp
+ ${FILE_DIR}/settings/parser.hpp
+ ${FILE_DIR}/settings/parser.cpp
+ ${FILE_DIR}/settings/file_decorator.hpp
+ ${FILE_DIR}/settings/file_decorator.cpp
+ ${FILE_DIR}/settings/checker_decorator.hpp
+ ${FILE_DIR}/settings/checker_decorator.cpp
+ ${FILE_DIR}/settings/types/ifile_manipulator.hpp
${CONVERTER_DIR}/struct_to_file.hpp
${CONVERTER_DIR}/struct_to_file.cpp
${CONVERTER_DIR}/file_to_struct.hpp
${CONVERTER_DIR}/file_to_struct.cpp
+ ${CONVERTER_DIR}/file_to_string.hpp
+ ${CONVERTER_DIR}/file_to_string.cpp
${CONVERTER_DIR}/struct_to_string.hpp
${CONVERTER_DIR}/struct_to_string.cpp
- ${PARSER_DIR}/settings.hpp
- ${PARSER_DIR}/settings.cpp
-
${MANAGER_BUILDER_DIR}/settings.hpp
${MANAGER_BUILDER_DIR}/settings.cpp
${MANAGER_BUILDER_DIR}/mail.hpp
diff --git a/src/converter/file_to_string.cpp b/src/converter/file_to_string.cpp
new file mode 100644
index 0000000..3d8860e
--- /dev/null
+++ b/src/converter/file_to_string.cpp
@@ -0,0 +1,24 @@
+#include "file_to_string.hpp"
+
+namespace smtp::converter
+{
+
+ std::list<std::string> FileToString::Convert( manage::SettingsFileDataType const& from) const
+ {
+ std::list<std::string> result;
+ for(auto const& settings_line : from)
+ {
+ result.push_back(BuildParam(settings_line));
+ }
+ return result;
+ }
+
+ std::string FileToString::BuildParam( std::pair < std::string, std::string > const& data ) const
+ {
+ std::string result;
+ result += data.first;
+ result += '=';
+ result += data.second;
+ return result;
+ }
+}
diff --git a/src/converter/file_to_string.hpp b/src/converter/file_to_string.hpp
new file mode 100644
index 0000000..14e1633
--- /dev/null
+++ b/src/converter/file_to_string.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "management/general.hpp"
+
+namespace smtp::converter
+{
+ class FileToString
+ {
+ public:
+ FileToString() = default;
+ ~FileToString() = default;
+
+ std::list<std::string> Convert( manage::SettingsFileDataType const& from ) const;
+ private:
+ std::string BuildParam( std::pair < std::string, std::string > const& data ) const;
+ };
+}
+
+
diff --git a/src/converter/struct_to_file.hpp b/src/converter/struct_to_file.hpp
index 22f7260..67a9f96 100644
--- a/src/converter/struct_to_file.hpp
+++ b/src/converter/struct_to_file.hpp
@@ -1,8 +1,5 @@
#pragma once
-#include <unordered_map>
-#include <string>
-
#include "management/general.hpp"
namespace smtp::converter
@@ -13,7 +10,7 @@ namespace smtp::converter
StructToFile() = default;
~StructToFile() = default;
- std::unordered_map<std::string, std::string> Convert( manage::SettingsFields const& from ) const;
+ manage::SettingsFileDataType Convert( manage::SettingsFields const& from ) const;
private:
void ApplyAuth( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const;
void ApplySsl( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const;
diff --git a/src/file/mail.hpp b/src/file/mail.hpp
deleted file mode 100644
index b68049b..0000000
--- a/src/file/mail.hpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#pragma once
-
-#include <string>
-#include <optional>
-
-#include "management/general.hpp"
-#include "checker/registrator_mails.hpp"
-
-namespace smtp::file
-{
- class Mail
- {
- public:
- explicit Mail( std::string const& path_file, checker::RegistratorMails const& registrator_errors );
- ~Mail() = default;
-
- manage::MailsSet Read() const;
- bool Write( manage::MailsSet const& data ) const;
- private:
- manage::MailsSet ReadFile( std::ifstream& mail_file ) const;
- bool WriteFile( std::ofstream& mail_file, manage::MailsSet const& data ) const;
-
- std::string mPathFile;
- checker::RegistratorMails mRegistratorErrors;
- };
-
-}
diff --git a/src/file/mail/checker_decorator.cpp b/src/file/mail/checker_decorator.cpp
new file mode 100644
index 0000000..54da9da
--- /dev/null
+++ b/src/file/mail/checker_decorator.cpp
@@ -0,0 +1,58 @@
+#include "checker_decorator.hpp"
+#include "logger/logger_set.hpp"
+
+namespace smtp::file::mail
+{
+
+ //
+ //Constructors
+ //
+
+ CheckerDecorator::CheckerDecorator( checker::RegistratorMails const& registrator_errors )
+ : mRegistratorErrors( registrator_errors )
+ {
+ }
+
+ //
+ //Public methods
+ //
+
+ manage::MailsSet CheckerDecorator::Read() const
+ {
+ manage::MailsSet result;
+
+ if( !mBase )
+ {
+ return result;
+ }
+
+ auto parsed_data = mBase->Read();
+
+ for( auto const& line : parsed_data )
+ {
+ if( mRegistratorErrors.Check( line ) )
+ {
+ result.push_back( line );
+ }
+ }
+ return result;
+ }
+
+ bool CheckerDecorator::Write( manage::MailsSet const& data ) const
+ {
+ manage::MailsSet result;
+
+ for( const auto& line : data )
+ {
+ if( mRegistratorErrors.Check( line ) )
+ {
+ result.push_back( line );
+ }
+ }
+ if( mBase )
+ {
+ return mBase->Write(result);
+ }
+ return false;
+ }
+}
diff --git a/src/file/mail/checker_decorator.hpp b/src/file/mail/checker_decorator.hpp
new file mode 100644
index 0000000..ed87fc5
--- /dev/null
+++ b/src/file/mail/checker_decorator.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "management/general.hpp"
+#include "checker/registrator_mails.hpp"
+#include "message/builder/types/idecorator.hpp"
+#include "types/ifile_manipulator.hpp"
+
+namespace smtp::file::mail
+{
+ class CheckerDecorator : public smtp::message::builder::types::IDecorator< types::IFileManipulator>
+ {
+ public:
+ explicit CheckerDecorator( checker::RegistratorMails const& registrator_errors );
+ ~CheckerDecorator() override = default;
+
+ manage::MailsSet Read() const override;
+ bool Write( manage::MailsSet const& data ) const override;
+ private:
+ manage::MailsSet ReadFile( std::ifstream& mail_file ) const;
+ bool WriteFile( std::ofstream& mail_file, manage::MailsSet const& data ) const;
+
+ checker::RegistratorMails mRegistratorErrors;
+ };
+
+}
diff --git a/src/file/mail.cpp b/src/file/mail/file_decorator.cpp
index a7e30ea..82111ac 100644
--- a/src/file/mail.cpp
+++ b/src/file/mail/file_decorator.cpp
@@ -1,18 +1,17 @@
#include <fstream>
-#include "mail.hpp"
+#include "file_decorator.hpp"
#include "logger/logger_set.hpp"
-namespace smtp::file
+namespace smtp::file::mail
{
//
//Constructors
//
- Mail::Mail( std::string const& path_file, checker::RegistratorMails const& registrator_errors )
+ FileDecorator::FileDecorator( std::string const& path_file )
: mPathFile( path_file )
- , mRegistratorErrors( registrator_errors )
{
}
@@ -20,7 +19,7 @@ namespace smtp::file
//Public methods
//
- manage::MailsSet Mail::Read() const
+ manage::MailsSet FileDecorator::Read() const
{
static const std::string METHOD_NAME = "Read mails";
@@ -37,7 +36,7 @@ namespace smtp::file
return result;
}
- bool Mail::Write( manage::MailsSet const& data ) const
+ bool FileDecorator::Write( manage::MailsSet const& data ) const
{
static const std::string METHOD_NAME = "Write mails";
@@ -60,34 +59,25 @@ namespace smtp::file
//Private methods
//
- manage::MailsSet Mail::ReadFile( std::ifstream& mail_file ) const
+ manage::MailsSet FileDecorator::ReadFile( std::ifstream& mail_file ) const
{
std::string line{};
manage::MailsSet result;
while ( std::getline( mail_file, line ) )
{
- if( mRegistratorErrors.Check( line ) )
- {
- result.push_back( line );
- }
+ result.push_back( line );
}
return result;
}
- bool Mail::WriteFile( std::ofstream& mail_file, manage::MailsSet const& data ) const
+ bool FileDecorator::WriteFile( std::ofstream& mail_file, manage::MailsSet const& data ) const
{
bool result = true;
+
for( const auto& mail : data )
{
- if( mRegistratorErrors.Check( mail ) )
- {
- mail_file << mail << "\n";
- }
- else
- {
- result = false;
- }
+ mail_file << mail << "\n";
}
return result;
}
diff --git a/src/file/mail/file_decorator.hpp b/src/file/mail/file_decorator.hpp
new file mode 100644
index 0000000..21dab10
--- /dev/null
+++ b/src/file/mail/file_decorator.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "management/general.hpp"
+#include "message/builder/types/idecorator.hpp"
+#include "types/ifile_manipulator.hpp"
+
+namespace smtp::file::mail
+{
+ class FileDecorator : public smtp::message::builder::types::IDecorator< types::IFileManipulator>
+ {
+ public:
+ explicit FileDecorator( std::string const& path_file );
+ ~FileDecorator() override = default;
+
+ manage::MailsSet Read() const override;
+ bool Write( manage::MailsSet const& data ) const override;
+ private:
+ manage::MailsSet ReadFile( std::ifstream& mail_file ) const;
+ bool WriteFile( std::ofstream& mail_file, manage::MailsSet const& data ) const;
+
+ std::string mPathFile;
+ };
+
+}
diff --git a/src/file/mail/sort_decorator.cpp b/src/file/mail/sort_decorator.cpp
new file mode 100644
index 0000000..dca464f
--- /dev/null
+++ b/src/file/mail/sort_decorator.cpp
@@ -0,0 +1,33 @@
+#include "sort_decorator.hpp"
+
+namespace smtp::file::mail
+{
+
+ //
+ //Public methods
+ //
+
+ manage::MailsSet SortDecorator::Read() const
+ {
+ manage::MailsSet result;
+
+ if(!mBase)
+ {
+ return result;
+ }
+ result = mBase->Read();
+
+ result.sort();
+
+ return result;
+ }
+
+ bool SortDecorator::Write( manage::MailsSet const& data ) const
+ {
+ if( mBase )
+ {
+ return mBase->Write( data );
+ }
+ return false;
+ }
+}
diff --git a/src/file/mail/sort_decorator.hpp b/src/file/mail/sort_decorator.hpp
new file mode 100644
index 0000000..80edf1d
--- /dev/null
+++ b/src/file/mail/sort_decorator.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "management/general.hpp"
+#include "message/builder/types/idecorator.hpp"
+#include "types/ifile_manipulator.hpp"
+
+namespace smtp::file::mail
+{
+ class SortDecorator : public smtp::message::builder::types::IDecorator< types::IFileManipulator>
+ {
+ public:
+ SortDecorator() = default;
+ ~SortDecorator() = default;
+
+ manage::MailsSet Read() const;
+ bool Write( manage::MailsSet const& data ) const;
+ };
+
+}
diff --git a/src/file/mail/types/ifile_manipulator.hpp b/src/file/mail/types/ifile_manipulator.hpp
new file mode 100644
index 0000000..62965e7
--- /dev/null
+++ b/src/file/mail/types/ifile_manipulator.hpp
@@ -0,0 +1,18 @@
+ #pragma once
+
+#include <memory>
+
+#include "management/general.hpp"
+
+namespace smtp::file::mail::types
+{
+ class IFileManipulator
+ {
+ public:
+ virtual ~IFileManipulator() = default;
+
+ virtual manage::MailsSet Read() const = 0;
+ virtual bool Write( manage::MailsSet const& data ) const = 0;
+ };
+ using IFileManipulatorPtr = std::shared_ptr<IFileManipulator>;
+}
diff --git a/src/file/settings.cpp b/src/file/settings.cpp
deleted file mode 100644
index eb8ed5d..0000000
--- a/src/file/settings.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-#include <fstream>
-
-#include "settings.hpp"
-#include "logger/logger_set.hpp"
-#include "converter/file_to_struct.hpp"
-#include "converter/struct_to_file.hpp"
-#include "parser/settings.hpp"
-
-namespace smtp::file
-{
-
- //
- //Constructors
- //
-
- Settings::Settings( std::string const& path_file, checker::RegistratorSettings const& registrator_errors )
- : mPathFile( path_file )
- , mRegistratorErrors( registrator_errors )
- {
-
- }
-
- //
- //Public methods
- //
-
- manage::SettingsFields Settings::Read() const
- {
- auto parsed_store = GetParsedStore();
- return converter::FileToStruct{}.Convert( parsed_store );
- }
-
- bool Settings::Write( manage::SettingsFields const& settings_fields ) const
- {
- auto parsed_data = converter::StructToFile{}.Convert( settings_fields );
- return mRegistratorErrors.Check( parsed_data ) && SetParsedData( parsed_data );
- }
-
- //
- //Private methods
- //
-
- manage::SettingsFileDataType Settings::GetParsedStore() const
- {
- static const std::string METHOD_NAME = "Read settings";
-
- std::ifstream settings_file{mPathFile, std::fstream::in};
- if( !settings_file.is_open() )
- {
- logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Unable to open file to read " + mPathFile );
- return {};
- }
- auto result = GetDataFromFile( settings_file );
-
- settings_file.close();
- return mRegistratorErrors.Check( result ) ? result : manage::SettingsFileDataType{};
- }
-
- manage::SettingsFileDataType Settings::GetDataFromFile( std::ifstream& settings_file ) const
- {
- std::string line{};
- manage::SettingsFileDataType result;
-
- while( std::getline( settings_file, line ))
- {
- auto parsed_data = parser::Settings{}.Parse( line );
- result.insert( parsed_data );
- }
- return result;
- }
-
- bool Settings::SetParsedData( manage::SettingsFileDataType const& parsed_data ) const
- {
- static const std::string METHOD_NAME = "Write settings";
-
- std::ofstream settings_file{mPathFile, std::fstream::out | std::fstream::trunc};
- if( !settings_file.is_open())
- {
- logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Unable to open file to write " + mPathFile );
- return false;
- }
- for( const auto& data : parsed_data )
- {
- auto line = BuildParam( data );
- settings_file << line << "\n";
- }
- settings_file.close();
- return true;
- }
-
- std::string Settings::BuildParam( std::pair < std::string, std::string > const& data ) const
- {
- std::string result;
- result += data.first;
- result += '=';
- result += data.second;
- return result;
- }
-}
diff --git a/src/file/settings/checker_decorator.cpp b/src/file/settings/checker_decorator.cpp
new file mode 100644
index 0000000..ef560ad
--- /dev/null
+++ b/src/file/settings/checker_decorator.cpp
@@ -0,0 +1,42 @@
+#include "checker_decorator.hpp"
+
+namespace smtp::file::settings
+{
+
+ //
+ //Constructors
+ //
+
+ CheckerDecorator::CheckerDecorator( checker::RegistratorSettings const& registrator_errors )
+ : mRegistratorErrors( registrator_errors )
+ {
+ }
+
+ //
+ //Public methods
+ //
+
+ manage::SettingsFileDataType CheckerDecorator::Read() const
+ {
+ manage::SettingsFileDataType result;
+ if(!mBase)
+ {
+ return result;
+ }
+ result = mBase->Read();
+ return mRegistratorErrors.Check( result ) ? result : manage::SettingsFileDataType{};
+ }
+
+ bool CheckerDecorator::Write( manage::SettingsFileDataType const& settings_fields ) const
+ {
+ if( !mBase )
+ {
+ return false;
+ }
+ if( mRegistratorErrors.Check( settings_fields ) )
+ {
+ return mBase->Write(settings_fields);
+ }
+ return false;
+ }
+}
diff --git a/src/file/settings/checker_decorator.hpp b/src/file/settings/checker_decorator.hpp
new file mode 100644
index 0000000..ecaba5a
--- /dev/null
+++ b/src/file/settings/checker_decorator.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "management/general.hpp"
+#include "checker/registrator_settings.hpp"
+#include "types/ifile_manipulator.hpp"
+#include "message/builder/types/idecorator.hpp"
+
+namespace smtp::file::settings
+{
+ class CheckerDecorator : public smtp::message::builder::types::IDecorator< types::IFileManipulator>
+ {
+ public:
+ explicit CheckerDecorator( checker::RegistratorSettings const& registrator_errors );
+ ~CheckerDecorator() = default;
+
+ manage::SettingsFileDataType Read() const override;
+ bool Write( manage::SettingsFileDataType const& data ) const override;
+ private:
+ checker::RegistratorSettings mRegistratorErrors;
+ };
+}
diff --git a/src/file/settings/file_decorator.cpp b/src/file/settings/file_decorator.cpp
new file mode 100644
index 0000000..38b42ce
--- /dev/null
+++ b/src/file/settings/file_decorator.cpp
@@ -0,0 +1,77 @@
+#include <fstream>
+
+#include "file_decorator.hpp"
+#include "logger/logger_set.hpp"
+#include "parser.hpp"
+#include "converter/file_to_string.hpp"
+
+namespace smtp::file::settings
+{
+
+ //
+ //Constructors
+ //
+
+ FileDecorator::FileDecorator( std::string const& path_file )
+ : mPathFile( path_file )
+ {
+
+ }
+
+ //
+ //Public methods
+ //
+
+ manage::SettingsFileDataType FileDecorator::Read() const
+ {
+ static const std::string METHOD_NAME = "Read settings";
+
+ std::ifstream settings_file{mPathFile, std::fstream::in};
+ if( !settings_file.is_open() )
+ {
+ logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Unable to open file to read " + mPathFile );
+ return {};
+ }
+ auto result = GetDataFromFile( settings_file );
+
+ settings_file.close();
+ return result;
+ }
+
+ bool FileDecorator::Write( manage::SettingsFileDataType const& data ) const
+ {
+ static const std::string METHOD_NAME = "Write settings";
+
+ std::ofstream settings_file{mPathFile, std::fstream::out | std::fstream::trunc};
+ if( !settings_file.is_open())
+ {
+ logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Unable to open file to write " + mPathFile );
+ return false;
+ }
+ auto settings_as_list = converter::FileToString{}.Convert(data);
+ for( const auto& settings_as_string : settings_as_list )
+ {
+ settings_file << settings_as_string << "\n";
+ }
+ settings_file.close();
+ return true;
+ }
+
+ //
+ //Private methods
+ //
+
+ manage::SettingsFileDataType FileDecorator::GetDataFromFile( std::ifstream& settings_file ) const
+ {
+ std::string line{};
+ manage::SettingsFileDataType result;
+ parser::Settings parser;
+
+ while( std::getline( settings_file, line ))
+ {
+ auto parsed_data = parser.Parse( line );
+ result.insert( parsed_data );
+ }
+ return result;
+ }
+}
diff --git a/src/file/settings/file_decorator.hpp b/src/file/settings/file_decorator.hpp
new file mode 100644
index 0000000..5896aed
--- /dev/null
+++ b/src/file/settings/file_decorator.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "management/general.hpp"
+#include "types/ifile_manipulator.hpp"
+#include "message/builder/types/idecorator.hpp"
+
+namespace smtp::file::settings
+{
+ class FileDecorator : public smtp::message::builder::types::IDecorator< types::IFileManipulator>
+ {
+ public:
+ explicit FileDecorator( std::string const& path_file );
+ ~FileDecorator() = default;
+
+ manage::SettingsFileDataType Read() const override;
+ bool Write( manage::SettingsFileDataType const& data ) const override;
+ private:
+ manage::SettingsFileDataType GetDataFromFile( std::ifstream& settings_file ) const;
+
+ std::string mPathFile;
+ };
+}
diff --git a/src/file/parser/settings.cpp b/src/file/settings/parser.cpp
index 590ed72..b692ac3 100644
--- a/src/file/parser/settings.cpp
+++ b/src/file/settings/parser.cpp
@@ -1,4 +1,4 @@
-#include "settings.hpp"
+#include "parser.hpp"
namespace smtp::file::parser
{
diff --git a/src/file/parser/settings.hpp b/src/file/settings/parser.hpp
index e7de2f6..e7de2f6 100644
--- a/src/file/parser/settings.hpp
+++ b/src/file/settings/parser.hpp
diff --git a/src/file/settings/settings.cpp b/src/file/settings/settings.cpp
new file mode 100644
index 0000000..48232e6
--- /dev/null
+++ b/src/file/settings/settings.cpp
@@ -0,0 +1,31 @@
+#include <fstream>
+
+#include "settings.hpp"
+#include "logger/logger_set.hpp"
+#include "converter/file_to_struct.hpp"
+#include "converter/struct_to_file.hpp"
+
+namespace smtp::file::settings
+{
+
+ Settings::Settings( types::IFileManipulatorPtr const& file_manipulator)
+ : mFileManipulator( file_manipulator )
+ {
+
+ }
+ //
+ //Public methods
+ //
+
+ manage::SettingsFields Settings::Read() const
+ {
+ auto parsed_store = mFileManipulator->Read();
+ return converter::FileToStruct{}.Convert( parsed_store );
+ }
+
+ bool Settings::Write( manage::SettingsFields const& settings_fields ) const
+ {
+ auto parsed_data = converter::StructToFile{}.Convert( settings_fields );
+ return mFileManipulator->Write( parsed_data );
+ }
+}
diff --git a/src/file/settings.hpp b/src/file/settings/settings.hpp
index 32ce2f2..60634fe 100644
--- a/src/file/settings.hpp
+++ b/src/file/settings/settings.hpp
@@ -1,14 +1,14 @@
#pragma once
#include "management/general.hpp"
-#include "checker/registrator_settings.hpp"
+#include "types/ifile_manipulator.hpp"
-namespace smtp::file
+namespace smtp::file::settings
{
class Settings
{
public:
- explicit Settings( std::string const& path_file, checker::RegistratorSettings const& registrator_errors );
+ explicit Settings( types::IFileManipulatorPtr const& file_manipulator );
~Settings() = default;
manage::SettingsFields Read() const;
@@ -20,7 +20,6 @@ namespace smtp::file
std::string BuildParam( std::pair < std::string, std::string > const& data ) const;
std::string mPathFile;
- checker::RegistratorSettings mRegistratorErrors;
-
+ types::IFileManipulatorPtr mFileManipulator;
};
}
diff --git a/src/file/settings/types/ifile_manipulator.hpp b/src/file/settings/types/ifile_manipulator.hpp
new file mode 100644
index 0000000..6de0bf3
--- /dev/null
+++ b/src/file/settings/types/ifile_manipulator.hpp
@@ -0,0 +1,18 @@
+ #pragma once
+
+#include <memory>
+
+#include "management/general.hpp"
+
+namespace smtp::file::settings::types
+{
+ class IFileManipulator
+ {
+ public:
+ virtual ~IFileManipulator() = default;
+
+ virtual manage::SettingsFileDataType Read() const = 0;
+ virtual bool Write( manage::SettingsFileDataType const& data ) const = 0;
+ };
+ using IFileManipulatorPtr = std::shared_ptr<IFileManipulator>;
+}
diff --git a/src/management/builder/mail.cpp b/src/management/builder/mail.cpp
index a301f5b..a96fd33 100644
--- a/src/management/builder/mail.cpp
+++ b/src/management/builder/mail.cpp
@@ -1,19 +1,27 @@
#include "mail.hpp"
-#include "file/mail.hpp"
#include "checker/errors/mail/empty.hpp"
#include "checker/errors/mail/at_sign.hpp"
+#include "file/mail/file_decorator.hpp"
+#include "file/mail/checker_decorator.hpp"
+#include "file/mail/sort_decorator.hpp"
+
namespace smtp::manage::builder
{
smtp::manage::Mail Mail::Build() const
{
- static const std::string PATH = {"/var/lib/smtp/mails.txt"};
+ return smtp::manage::Mail{BuildFileManipulator()};
+ }
- auto registrator = BuildErrorRegistrator();
- file::Mail file_manipulator{PATH, registrator};
- return smtp::manage::Mail{file_manipulator};
- }
+ file::mail::types::IFileManipulatorPtr Mail::BuildFileManipulator() const
+ {
+ static const std::string PATH = {"/var/lib/smtp/mails.txt"};
+ auto result = std::make_shared<file::mail::SortDecorator>() ;
+ result->Apply(std::make_shared<file::mail::CheckerDecorator>( BuildErrorRegistrator() ))
+ .Apply(std::make_shared<file::mail::FileDecorator>( PATH ));
+ return result;
+ }
checker::RegistratorMails Mail::BuildErrorRegistrator() const
{
diff --git a/src/management/builder/mail.hpp b/src/management/builder/mail.hpp
index e735fd6..7cbb29d 100644
--- a/src/management/builder/mail.hpp
+++ b/src/management/builder/mail.hpp
@@ -2,6 +2,7 @@
#include "management/mail.hpp"
#include "checker/registrator_mails.hpp"
+#include "file/mail/types/ifile_manipulator.hpp"
namespace smtp::manage::builder
{
@@ -12,6 +13,8 @@ namespace smtp::manage::builder
~Mail() = default;
smtp::manage::Mail Build() const;
+ private:
+ file::mail::types::IFileManipulatorPtr BuildFileManipulator() const;
checker::RegistratorMails BuildErrorRegistrator() const;
};
diff --git a/src/management/builder/settings.cpp b/src/management/builder/settings.cpp
index 0b27bef..b682c49 100644
--- a/src/management/builder/settings.cpp
+++ b/src/management/builder/settings.cpp
@@ -1,23 +1,26 @@
#include "settings.hpp"
#include "checker/errors/settings/port_number.hpp"
#include "checker/errors/settings/server.hpp"
+#include "file/settings/settings.hpp"
+#include "file/settings/checker_decorator.hpp"
+#include "file/settings/file_decorator.hpp"
namespace smtp::manage::builder
{
-
smtp::manage::Settings Settings::Build() const
{
- auto file_manipulator = GetFileSettings();
- return smtp::manage::Settings{file_manipulator};
- }
-
- file::Settings Settings::GetFileSettings() const
- {
- static const std::string PATH = "/var/lib/smtp/settings.txt";
-
- auto registrator = BuildErrorRegistrator();
- return file::Settings{PATH, registrator};
- }
+ file::settings::Settings settings{ BuildFileManipulator() };
+ return smtp::manage::Settings{settings};
+ }
+
+ file::settings::types::IFileManipulatorPtr Settings::BuildFileManipulator() const
+ {
+ static const std::string PATH = "/var/lib/smtp/settings.txt";
+
+ auto result = std::make_shared<file::settings::CheckerDecorator>(BuildErrorRegistrator());
+ result->Apply(std::make_shared<file::settings::FileDecorator>(PATH));
+ return result;
+ }
checker::RegistratorSettings Settings::BuildErrorRegistrator() const
{
diff --git a/src/management/builder/settings.hpp b/src/management/builder/settings.hpp
index 64f9384..b7215e2 100644
--- a/src/management/builder/settings.hpp
+++ b/src/management/builder/settings.hpp
@@ -1,8 +1,8 @@
#pragma once
#include "management/settings.hpp"
-#include "file/settings.hpp"
#include "checker/registrator_settings.hpp"
+#include "file/settings/types/ifile_manipulator.hpp"
namespace smtp::manage::builder
{
@@ -14,7 +14,7 @@ namespace smtp::manage::builder
smtp::manage::Settings Build() const;
private:
- file::Settings GetFileSettings() const;
+ file::settings::types::IFileManipulatorPtr BuildFileManipulator()const;
checker::RegistratorSettings BuildErrorRegistrator() const;
};
diff --git a/src/management/mail.cpp b/src/management/mail.cpp
index 87ebb51..d569826 100644
--- a/src/management/mail.cpp
+++ b/src/management/mail.cpp
@@ -8,9 +8,9 @@ namespace smtp::manage
//Constructors
//
- Mail::Mail( file::Mail const& file_reader )
+ Mail::Mail( file::mail::types::IFileManipulatorPtr const& file_reader )
: mFileReader( file_reader )
- , mMails( mFileReader.Read() )
+ , mMails( mFileReader->Read() )
{
}
@@ -28,61 +28,59 @@ namespace smtp::manage
{
auto merged_mails = GetMergedMails( mails_to_add );
- return RefreshMails( mails_to_add );
+ return RefreshMails( merged_mails );
}
- bool Mail::DeleteMailToSend( MailsSet const& mail_to_send )
+ bool Mail::DeleteMailToSend( MailsSet const& mail_to_delete )
{
- auto mails_to_delete = GetItersectionMails( mail_to_send );
+ auto mails_to_delete = GetItersectionMails( mail_to_delete );
+
auto result_set_after_delete = GetMailsAfterDelete( mails_to_delete );
- return RefreshMails( mails_to_delete );
+ return RefreshMails( result_set_after_delete );
}
//
//Private methods
//
- MailsSet Mail::GetMergedMails( MailsSet const& mails_to_add )
+ MailsSet Mail::GetMergedMails( MailsSet const& mails_to_add )
{
- MailsSet result;
- auto sorted_mail_to_add = mails_to_add;
- sorted_mail_to_add.sort();
- mMails.sort();
+ auto result = mails_to_add;
+ result.merge( mMails );
- std::set_union( mMails.cbegin(), mMails.cend(),
- sorted_mail_to_add.cbegin(), sorted_mail_to_add.cend(),
- std::back_inserter( result ));
- return result;
- }
+ result.sort();
+ result.unique();
+
+ return result;
+ }
- MailsSet Mail::GetItersectionMails( MailsSet const& mail_to_send )
+ MailsSet Mail::GetItersectionMails( MailsSet const& mail_to_delete ) const
{
- MailsSet result;
+ MailsSet result;
- auto sorted_mail_to_send = mail_to_send;
+ auto sorted_mail_to_send = mail_to_delete;
sorted_mail_to_send.sort();
- mMails.sort();
std::set_intersection( mMails.cbegin(), mMails.cend(),
sorted_mail_to_send.cbegin(), sorted_mail_to_send.cend(),
std::back_inserter( result ) );
return result;
}
- MailsSet Mail::GetMailsAfterDelete( MailsSet const& result_set_after_delete )
- {
- auto result = mMails;
- for( const auto& element_to_delete : result_set_after_delete )
- {
- result.remove( element_to_delete );
- }
+ MailsSet Mail::GetMailsAfterDelete( MailsSet const& mails_to_delete )
+ {
+ auto result = mMails;
+ for( const auto& mail : mails_to_delete )
+ {
+ result.remove( mail );
+ }
return result;
}
bool Mail::RefreshMails( MailsSet const& new_mails )
{
- auto result = mFileReader.Write( new_mails );
- mMails = mFileReader.Read();
+ auto result = mFileReader->Write( new_mails );
+ mMails = mFileReader->Read();
return result;
}
}
diff --git a/src/management/mail.hpp b/src/management/mail.hpp
index 2a1182a..813a5b4 100644
--- a/src/management/mail.hpp
+++ b/src/management/mail.hpp
@@ -3,7 +3,7 @@
#include <set>
#include <string>
-#include "file/mail.hpp"
+#include "file/mail/types/ifile_manipulator.hpp"
#include "checker/registrator_mails.hpp"
namespace smtp::manage
@@ -11,19 +11,19 @@ namespace smtp::manage
class Mail
{
public:
- explicit Mail( file::Mail const& file_reader );
+ explicit Mail( file::mail::types::IFileManipulatorPtr const& file_reader );
~Mail() = default;
MailsSet GetMailToSend() const;
bool AddMailsToSend( MailsSet const& mails );
- bool DeleteMailToSend( MailsSet const& mail_to_send );
+ bool DeleteMailToSend( MailsSet const& mail_to_delete );
private:
- MailsSet GetMergedMails( MailsSet const& mails_to_add );
- MailsSet GetItersectionMails( MailsSet const& mail_to_send );
- MailsSet GetMailsAfterDelete( MailsSet const& result_set_after_delete );
+ MailsSet GetMergedMails( MailsSet const& mails_to_add );
+ MailsSet GetItersectionMails( MailsSet const& mail_to_delete ) const;
+ MailsSet GetMailsAfterDelete( MailsSet const& mails_to_delete );
bool RefreshMails( MailsSet const& new_mails );
- file::Mail mFileReader;
+ file::mail::types::IFileManipulatorPtr mFileReader;
MailsSet mMails;
};
diff --git a/src/management/settings.cpp b/src/management/settings.cpp
index b1f9410..20c38cb 100644
--- a/src/management/settings.cpp
+++ b/src/management/settings.cpp
@@ -3,7 +3,7 @@
namespace smtp::manage
{
- Settings::Settings( file::Settings const& file_reader )
+ Settings::Settings( file::settings::Settings const& file_reader )
: mFileReader( file_reader )
, mSettingsFields( mFileReader.Read() )
{
diff --git a/src/management/settings.hpp b/src/management/settings.hpp
index f173d0b..eb2aafb 100644
--- a/src/management/settings.hpp
+++ b/src/management/settings.hpp
@@ -2,7 +2,7 @@
#include <string>
-#include "file/settings.hpp"
+#include "file/settings/settings.hpp"
#include "management/general.hpp"
namespace smtp::manage
@@ -10,7 +10,7 @@ namespace smtp::manage
class Settings
{
public:
- explicit Settings( file::Settings const& file_reader );
+ explicit Settings( file::settings::Settings const& file_reader );
~Settings() = default;
bool SetSettings( manage::SettingsFields const& settings_fields );
@@ -24,7 +24,7 @@ namespace smtp::manage
std::string GetHost() const;
std::string GetPort() const;
private:
- file::Settings mFileReader;
+ file::settings::Settings mFileReader;
manage::SettingsFields mSettingsFields;
};
}
diff --git a/src/service/smtp.cpp b/src/service/smtp.cpp
index 7b1ca70..90e3acc 100644
--- a/src/service/smtp.cpp
+++ b/src/service/smtp.cpp
@@ -11,7 +11,7 @@ namespace smtp::service
:mSettingsStorage(settings), mMailTo(mail_to)
{
CreateService( connection );
- CreateMessengerInterface( connection );
+ CreateMessengerInterface( connection );
CreateSettingsManagerInterface( connection );
CreateMailManagerInterface( connection );
}