diff options
author | eportnov <eportnov@ibs.ru> | 2022-10-03 11:37:47 +0300 |
---|---|---|
committer | eportnov <eportnov@ibs.ru> | 2022-10-03 11:37:47 +0300 |
commit | e41b247e61ce4d4cc96badab3a14bf413e4f46f2 (patch) | |
tree | f68d57d9b472cbe1186f235034b97a1be75cac08 | |
parent | 7e2843c706c1a6e033662c45957a76e01d167438 (diff) | |
download | obmc-sila-smtp-e41b247e61ce4d4cc96badab3a14bf413e4f46f2.tar.xz |
refactoring
27 files changed, 143 insertions, 144 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b8e15b..270cfb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,14 +134,12 @@ set(SRC_FILES ${FILE_DIR}/settings.hpp ${FILE_DIR}/settings.cpp - ${CONVERTER_DIR}/full.hpp - ${CONVERTER_DIR}/full.cpp - ${CONVERTER_DIR}/settings.hpp - ${CONVERTER_DIR}/settings.cpp - ${CONVERTER_DIR}/file.hpp - ${CONVERTER_DIR}/file.cpp - ${CONVERTER_DIR}/string.hpp - ${CONVERTER_DIR}/string.cpp + ${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}/struct_to_string.hpp + ${CONVERTER_DIR}/struct_to_string.cpp ${PARSER_DIR}/settings.hpp ${PARSER_DIR}/settings.cpp diff --git a/src/checker/errors/mail/at_sign.cpp b/src/checker/errors/mail/at_sign.cpp index f9dde08..0acb470 100644 --- a/src/checker/errors/mail/at_sign.cpp +++ b/src/checker/errors/mail/at_sign.cpp @@ -3,13 +3,14 @@ #include "at_sign.hpp" #include "logger/logger_set.hpp" -namespace smtp::checker::errors::settings +namespace smtp::checker::errors::mail { bool AtSign::Check( std::string const& line ) const { std::string mask = R"([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))"; + auto result = std::regex_search( line, std::regex{mask} ); - if(!result) + if( !result ) { logger::LoggerSet::GetInstance()->LogError( GetMethodName(), "Error in mail note" ); } diff --git a/src/checker/errors/mail/at_sign.hpp b/src/checker/errors/mail/at_sign.hpp index 2f72871..38a7d96 100644 --- a/src/checker/errors/mail/at_sign.hpp +++ b/src/checker/errors/mail/at_sign.hpp @@ -2,7 +2,7 @@ #include "checker/errors/types/imails_error.hpp" -namespace smtp::checker::errors::settings +namespace smtp::checker::errors::mail { class AtSign : public types::IErrorMails { diff --git a/src/checker/errors/mail/empty.cpp b/src/checker/errors/mail/empty.cpp index 1c39e78..8a1591e 100644 --- a/src/checker/errors/mail/empty.cpp +++ b/src/checker/errors/mail/empty.cpp @@ -1,12 +1,12 @@ #include "empty.hpp" #include "logger/logger_set.hpp" -namespace smtp::checker::errors::settings +namespace smtp::checker::errors::mail { bool Empty::Check( std::string const& line ) const { auto result = !line.empty() && line != " "; - if(!result) + if( !result ) { logger::LoggerSet::GetInstance()->LogError( GetMethodName(), "Mails are empty" ); } diff --git a/src/checker/errors/mail/empty.hpp b/src/checker/errors/mail/empty.hpp index 945650e..880f5c1 100644 --- a/src/checker/errors/mail/empty.hpp +++ b/src/checker/errors/mail/empty.hpp @@ -2,7 +2,7 @@ #include "checker/errors/types/imails_error.hpp" -namespace smtp::checker::errors::settings +namespace smtp::checker::errors::mail { class Empty : public types::IErrorMails { diff --git a/src/checker/errors/settings/port_number.cpp b/src/checker/errors/settings/port_number.cpp index 485b4c7..b0d9661 100644 --- a/src/checker/errors/settings/port_number.cpp +++ b/src/checker/errors/settings/port_number.cpp @@ -5,7 +5,7 @@ namespace smtp::checker::errors::settings { - bool PortNumber::Check( const manage::SettingsFileDataType& line ) const + bool PortNumber::Check( manage::SettingsFileDataType const& line ) const { static const std::string PORT_FIELD = "port"; static constexpr int MIN_PORT_NUMBER = 0; @@ -23,6 +23,7 @@ namespace smtp::checker::errors::settings { return true; } + int host_as_int{}; try { @@ -43,6 +44,11 @@ namespace smtp::checker::errors::settings logger::LoggerSet::GetInstance()->LogError( GetMethodName(), "Port doesn't entered by numbers" ); return false; } - return host_as_int >= MIN_PORT_NUMBER && host_as_int <= MAX_PORT_NUMBER; + auto result = host_as_int >= MIN_PORT_NUMBER && host_as_int <= MAX_PORT_NUMBER; + if( !result ) + { + logger::LoggerSet::GetInstance()->LogError( GetMethodName(), "Port doesn't entered by numbers" ); + } + return result; } } diff --git a/src/checker/errors/settings/server.cpp b/src/checker/errors/settings/server.cpp index c3f29af..d25bc9a 100644 --- a/src/checker/errors/settings/server.cpp +++ b/src/checker/errors/settings/server.cpp @@ -18,7 +18,12 @@ namespace smtp::checker::errors::settings logger::LoggerSet::GetInstance()->LogError( GetMethodName(), "Host doesn't found" ); return false; } - return IsNormalName( find->second ) || IsIpName( find->second ); + auto result = IsNormalName( find->second ) || IsIpName( find->second ); + if( !result ) + { + logger::LoggerSet::GetInstance()->LogError( GetMethodName(), "Host set incorrectly" ); + } + return result; } // diff --git a/src/checker/registrator_mails.cpp b/src/checker/registrator_mails.cpp index b2352c7..3141e80 100644 --- a/src/checker/registrator_mails.cpp +++ b/src/checker/registrator_mails.cpp @@ -2,7 +2,7 @@ namespace smtp::checker { - void RegistratorMails::Add(errors::types::IErrorMailsPtr const& error ) + void RegistratorMails::Add( errors::types::IErrorMailsPtr const& error ) { mErrors.push_back( error ); } @@ -18,5 +18,4 @@ namespace smtp::checker } return true; } - -} // namespace smtp::checker +} diff --git a/src/checker/registrator_mails.hpp b/src/checker/registrator_mails.hpp index 2514a10..b87cd87 100644 --- a/src/checker/registrator_mails.hpp +++ b/src/checker/registrator_mails.hpp @@ -1,8 +1,9 @@ #pragma once -#include "errors/types/imails_error.hpp" #include <list> +#include "errors/types/imails_error.hpp" + namespace smtp::checker { class RegistratorMails @@ -16,4 +17,4 @@ namespace smtp::checker private: std::list<errors::types::IErrorMailsPtr> mErrors; }; -} // namespace smtp::checker +} diff --git a/src/checker/registrator_settings.hpp b/src/checker/registrator_settings.hpp index fbd12f5..78854d2 100644 --- a/src/checker/registrator_settings.hpp +++ b/src/checker/registrator_settings.hpp @@ -1,8 +1,9 @@ #pragma once -#include "errors/types/isettings_error.hpp" #include <list> +#include "errors/types/isettings_error.hpp" + namespace smtp::checker { class RegistratorSettings diff --git a/src/converter/file.cpp b/src/converter/file_to_struct.cpp index a33381f..4c4bec8 100644 --- a/src/converter/file.cpp +++ b/src/converter/file_to_struct.cpp @@ -1,8 +1,8 @@ -#include "file.hpp" +#include "file_to_struct.hpp" namespace smtp::converter { - manage::SettingsFields File::Convert( manage::SettingsFileDataType const& from ) const + manage::SettingsFields FileToStruct::Convert( manage::SettingsFileDataType const& from ) const { manage::SettingsFields result; @@ -16,21 +16,21 @@ namespace smtp::converter return result; } - void File::ApplyAuth( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + void FileToStruct::ApplyAuth( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "is_need_auth"; ApplyBool(from, FIELD, result.is_need_auth); } - void File::ApplySsl( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + void FileToStruct::ApplySsl( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "is_need_ssl"; ApplyBool(from, FIELD, result.is_need_ssl); } - void File::ApplyBool( manage::SettingsFileDataType const& from, std::string const& search_field, bool& field ) const + void FileToStruct::ApplyBool( manage::SettingsFileDataType const& from, std::string const& search_field, bool& field ) const { static const std::string TRUE_AS_STRING = "true"; static const std::string FALSE_AS_STRING = "false"; @@ -47,35 +47,35 @@ namespace smtp::converter field = (find->second == TRUE_AS_STRING); } - void File::ApplyUsername( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + void FileToStruct::ApplyUsername( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "username"; ApplyString( from, FIELD, result.username ); } - void File::ApplyPassword( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + void FileToStruct::ApplyPassword( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "password"; ApplyString( from, FIELD, result.password ); } - void File::ApplyHost( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + void FileToStruct::ApplyHost( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "host"; ApplyString( from, FIELD, result.host ); } - void File::ApplyPort( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const + void FileToStruct::ApplyPort( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "port"; ApplyString(from, FIELD, result.port); } - void File::ApplyString( manage::SettingsFileDataType const& from, std::string const& search_field, std::string& field ) const + void FileToStruct::ApplyString( manage::SettingsFileDataType const& from, std::string const& search_field, std::string& field ) const { auto find = from.find( search_field ); if( find == from.end() ) diff --git a/src/converter/file.hpp b/src/converter/file_to_struct.hpp index daa35fd..1eb7fce 100644 --- a/src/converter/file.hpp +++ b/src/converter/file_to_struct.hpp @@ -7,11 +7,11 @@ namespace smtp::converter { - class File + class FileToStruct { public: - File() = default; - ~File() = default; + FileToStruct() = default; + ~FileToStruct() = default; manage::SettingsFields Convert( manage::SettingsFileDataType const& from ) const; private: diff --git a/src/converter/full.cpp b/src/converter/full.cpp deleted file mode 100644 index 91a9816..0000000 --- a/src/converter/full.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "full.hpp" -#include "file.hpp" -#include "settings.hpp" - -namespace smtp::converter -{ - manage::SettingsFields Full::Convert( manage::SettingsFileDataType const& from ) const - { - return File{}.Convert( from ); - } - - std::unordered_map<std::string, std::string> Full::Convert( manage::SettingsFields const& from ) const - { - return Settings{}.Convert( from ); - - } -} diff --git a/src/converter/full.hpp b/src/converter/full.hpp deleted file mode 100644 index dac7499..0000000 --- a/src/converter/full.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include <unordered_map> -#include <string> - -#include "management/general.hpp" - -namespace smtp::converter -{ - class Full - { - public: - Full() = default; - ~Full() = default; - - manage::SettingsFields Convert( manage::SettingsFileDataType const& from ) const; - std::unordered_map<std::string, std::string> Convert( manage::SettingsFields const& from ) const; - private: - - }; -} - - diff --git a/src/converter/settings.cpp b/src/converter/struct_to_file.cpp index 10ed310..f21cffb 100644 --- a/src/converter/settings.cpp +++ b/src/converter/struct_to_file.cpp @@ -1,9 +1,9 @@ -#include "settings.hpp" +#include "struct_to_file.hpp" namespace smtp::converter { - manage::SettingsFileDataType Settings::Convert( manage::SettingsFields const& from ) const + manage::SettingsFileDataType StructToFile::Convert( manage::SettingsFields const& from ) const { manage::SettingsFileDataType result; @@ -17,7 +17,7 @@ namespace smtp::converter return result; } - void Settings::ApplyAuth( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + void StructToFile::ApplyAuth( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const { static const std::string FIELD = "is_need_auth"; static const std::string TRUE_AS_STRING = "true"; @@ -26,7 +26,7 @@ namespace smtp::converter from.is_need_auth ? result.insert({FIELD, TRUE_AS_STRING}) : result.insert({FIELD, FALSE_AS_STRING}); } - void Settings::ApplySsl( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + void StructToFile::ApplySsl( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const { static const std::string FIELD = "is_need_ssl"; static const std::string TRUE_AS_STRING = "true"; @@ -35,28 +35,28 @@ namespace smtp::converter from.is_need_ssl ? result.insert({FIELD, TRUE_AS_STRING}) : result.insert({FIELD, FALSE_AS_STRING}); } - void Settings::ApplyUsername( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + void StructToFile::ApplyUsername( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const { static const std::string FIELD = "username"; result.insert({FIELD, from.username}); } - void Settings::ApplyPassword( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + void StructToFile::ApplyPassword( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const { static const std::string FIELD = "password"; result.insert({FIELD, from.password}); } - void Settings::ApplyHost( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + void StructToFile::ApplyHost( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const { static const std::string FIELD = "host"; result.insert({FIELD, from.host}); } - void Settings::ApplyPort( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const + void StructToFile::ApplyPort( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const { static const std::string FIELD = "port"; diff --git a/src/converter/settings.hpp b/src/converter/struct_to_file.hpp index 5278b16..22f7260 100644 --- a/src/converter/settings.hpp +++ b/src/converter/struct_to_file.hpp @@ -7,11 +7,11 @@ namespace smtp::converter { - class Settings + class StructToFile { public: - Settings() = default; - ~Settings() = default; + StructToFile() = default; + ~StructToFile() = default; std::unordered_map<std::string, std::string> Convert( manage::SettingsFields const& from ) const; private: diff --git a/src/converter/string.cpp b/src/converter/struct_to_string.cpp index 149d8b6..c86a6c8 100644 --- a/src/converter/string.cpp +++ b/src/converter/struct_to_string.cpp @@ -1,8 +1,8 @@ -#include "string.hpp" +#include "struct_to_string.hpp" namespace smtp::converter { - std::string String::Convert( manage::SettingsFields const& from ) const + std::string StructToString::Convert( manage::SettingsFields const& from ) const { std::string result; @@ -16,49 +16,49 @@ namespace smtp::converter return result; } - void String::ApplyAuth( manage::SettingsFields const& from, std::string& result ) const + void StructToString::ApplyAuth( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "is_need_auth"; result += GetBoolParam( FIELD, from.is_need_auth); } - void String::ApplySsl( manage::SettingsFields const& from, std::string& result ) const + void StructToString::ApplySsl( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "is_need_ssl"; result += GetBoolParam( FIELD, from.is_need_ssl); } - void String::ApplyUsername( manage::SettingsFields const& from, std::string& result ) const + void StructToString::ApplyUsername( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "username"; result += GetStringParam( FIELD, from.username ); } - void String::ApplyPassword( manage::SettingsFields const& from, std::string& result ) const + void StructToString::ApplyPassword( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "password"; result += GetStringParam( FIELD, from.password ); } - void String::ApplyHost( manage::SettingsFields const& from, std::string& result ) const + void StructToString::ApplyHost( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "host"; result += GetStringParam( FIELD, from.host ); } - void String::ApplyPort( manage::SettingsFields const& from, std::string& result ) const + void StructToString::ApplyPort( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "port"; result += GetStringParam( FIELD, from.port ); } - std::string String::GetStringParam(const std::string &field, const std::string ¶m) const + std::string StructToString::GetStringParam(const std::string &field, const std::string ¶m) const { std::string result; result += field; @@ -68,7 +68,7 @@ namespace smtp::converter return result; } - std::string String::GetBoolParam(const std::string &field, bool param) const + std::string StructToString::GetBoolParam(const std::string &field, bool param) const { std::string result; diff --git a/src/converter/string.hpp b/src/converter/struct_to_string.hpp index 555e04b..0a08327 100644 --- a/src/converter/string.hpp +++ b/src/converter/struct_to_string.hpp @@ -7,11 +7,11 @@ namespace smtp::converter { - class String + class StructToString { public: - String() = default; - ~String() = default; + StructToString() = default; + ~StructToString() = default; std::string Convert( manage::SettingsFields const& from ) const; private: diff --git a/src/file/mail.cpp b/src/file/mail.cpp index 403ed84..a7e30ea 100644 --- a/src/file/mail.cpp +++ b/src/file/mail.cpp @@ -5,12 +5,21 @@ namespace smtp::file { + + // + //Constructors + // + Mail::Mail( std::string const& path_file, checker::RegistratorMails const& registrator_errors ) : mPathFile( path_file ) , mRegistratorErrors( registrator_errors ) { } + // + //Public methods + // + manage::MailsSet Mail::Read() const { static const std::string METHOD_NAME = "Read mails"; @@ -21,16 +30,9 @@ namespace smtp::file logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Unable to open file to read " + mPathFile ); return {}; } - std::string line{}; - manage::MailsSet result; - while ( std::getline( mail_file, line ) ) - { - if( mRegistratorErrors.Check( line ) ) - { - result.push_back( line ); - } - } + auto result = ReadFile( mail_file ); + mail_file.close(); return result; } @@ -40,25 +42,53 @@ namespace smtp::file static const std::string METHOD_NAME = "Write mails"; std::ofstream mail_file{ mPathFile, std::fstream::out | std::fstream::trunc }; - bool result = true; + if ( !mail_file.is_open() ) { logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Unable to open file to write " + mPathFile ); return false; } + + auto result = WriteFile( mail_file, data ); + + mail_file.close(); + return result; + } + + // + //Private methods + // + + manage::MailsSet Mail::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 ); + } + } + return result; + } + + bool Mail::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"; - } + if( mRegistratorErrors.Check( mail ) ) + { + mail_file << mail << "\n"; + } else { result = false; } } - mail_file.close(); return result; } } diff --git a/src/file/mail.hpp b/src/file/mail.hpp index 148aa11..b68049b 100644 --- a/src/file/mail.hpp +++ b/src/file/mail.hpp @@ -17,6 +17,9 @@ namespace smtp::file 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/settings.cpp b/src/file/settings.cpp index 70f3cf7..eb8ed5d 100644 --- a/src/file/settings.cpp +++ b/src/file/settings.cpp @@ -2,12 +2,17 @@ #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 ) @@ -18,27 +23,29 @@ namespace smtp::file // //Public methods // + manage::SettingsFields Settings::Read() const { auto parsed_store = GetParsedStore(); - return converter::Full{}.Convert( parsed_store ); + return converter::FileToStruct{}.Convert( parsed_store ); } bool Settings::Write( manage::SettingsFields const& settings_fields ) const { - auto parsed_data = converter::Full{}.Convert( settings_fields ); + 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()) + if( !settings_file.is_open() ) { logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Unable to open file to read " + mPathFile ); return {}; @@ -72,7 +79,7 @@ namespace smtp::file logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Unable to open file to write " + mPathFile ); return false; } - for( const auto& data: parsed_data ) + for( const auto& data : parsed_data ) { auto line = BuildParam( data ); settings_file << line << "\n"; diff --git a/src/file/settings.hpp b/src/file/settings.hpp index 0882ac3..32ce2f2 100644 --- a/src/file/settings.hpp +++ b/src/file/settings.hpp @@ -1,17 +1,10 @@ #pragma once -#include <list> -#include <string> - -#include "converter/full.hpp" -#include "parser/settings.hpp" #include "management/general.hpp" #include "checker/registrator_settings.hpp" namespace smtp::file { - - class Settings { public: @@ -22,12 +15,12 @@ namespace smtp::file bool Write( manage::SettingsFields const& settings_fields ) const; private: manage::SettingsFileDataType GetParsedStore() const; + manage::SettingsFileDataType GetDataFromFile( std::ifstream& settings_file ) const; bool SetParsedData( manage::SettingsFileDataType const& parsed_data ) const; std::string BuildParam( std::pair < std::string, std::string > const& data ) const; std::string mPathFile; checker::RegistratorSettings mRegistratorErrors; - manage::SettingsFileDataType GetDataFromFile( std::ifstream& settings_file ) const; - }; + }; } diff --git a/src/management/builder/mail.cpp b/src/management/builder/mail.cpp index 3a87f8b..a301f5b 100644 --- a/src/management/builder/mail.cpp +++ b/src/management/builder/mail.cpp @@ -18,8 +18,8 @@ namespace smtp::manage::builder checker::RegistratorMails Mail::BuildErrorRegistrator() const { checker::RegistratorMails result; - result.Add( std::make_shared < checker::errors::settings::Empty >()); - result.Add( std::make_shared < checker::errors::settings::AtSign >()); + result.Add( std::make_shared < checker::errors::mail::Empty >()); + result.Add( std::make_shared < checker::errors::mail::AtSign >()); return result; } diff --git a/src/management/mail.cpp b/src/management/mail.cpp index 738c150..ac8d58f 100644 --- a/src/management/mail.cpp +++ b/src/management/mail.cpp @@ -76,7 +76,7 @@ namespace smtp::manage MailsSet Mail::GetMailsAfterDelete( MailsSet const& result_set_after_delete ) { auto result = mMails; - for( const auto& element_to_delete: result_set_after_delete ) + for( const auto& element_to_delete : result_set_after_delete ) { result.remove( element_to_delete ); } diff --git a/src/management/settings.cpp b/src/management/settings.cpp index 65888aa..0f5b326 100644 --- a/src/management/settings.cpp +++ b/src/management/settings.cpp @@ -1,28 +1,25 @@ #include "settings.hpp" -#include "converter/string.hpp" +#include "converter/struct_to_string.hpp" namespace smtp::manage { Settings::Settings( file::Settings const& file_reader ) : mFileReader( file_reader ) { - ReloadSettings(); + mSettingsFields = mFileReader.Read(); } - bool Settings::SetSettings( manage::SettingsFields const& settings_fields )const + bool Settings::SetSettings( manage::SettingsFields const& settings_fields ) { - return mFileReader.Write( settings_fields ); + auto result = mFileReader.Write( settings_fields ); + mSettingsFields = mFileReader.Read(); + return result; } std::string Settings::GetSettings() { - ReloadSettings(); - return converter::String{}.Convert(mSettingsFields); - } - - void Settings::ReloadSettings() - { mSettingsFields = mFileReader.Read(); + return converter::StructToString{}.Convert(mSettingsFields); } bool Settings::IsNeedAuth() const noexcept diff --git a/src/management/settings.hpp b/src/management/settings.hpp index 650f966..f173d0b 100644 --- a/src/management/settings.hpp +++ b/src/management/settings.hpp @@ -13,9 +13,8 @@ namespace smtp::manage explicit Settings( file::Settings const& file_reader ); ~Settings() = default; - bool SetSettings( manage::SettingsFields const& settings_fields ) const; + bool SetSettings( manage::SettingsFields const& settings_fields ); std::string GetSettings(); - void ReloadSettings(); bool IsNeedAuth() const noexcept; bool IsNeedSsl() const noexcept; diff --git a/src/message/sender.cpp b/src/message/sender.cpp index a7e3128..30073a8 100644 --- a/src/message/sender.cpp +++ b/src/message/sender.cpp @@ -37,7 +37,6 @@ namespace smtp::message auto curl = curl_easy_init(); //TODO сделать инициализацию через регистратор инициализаторов - mSettingsStorage.ReloadSettings(); if( !InitCurl( curl, upload_ctx, mail_from )) { logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Error to initializate message service" ); |