diff options
Diffstat (limited to 'src/management')
-rw-r--r-- | src/management/builder/mail.cpp | 23 | ||||
-rw-r--r-- | src/management/builder/mail.hpp | 18 | ||||
-rw-r--r-- | src/management/builder/settings.cpp | 29 | ||||
-rw-r--r-- | src/management/builder/settings.hpp | 21 | ||||
-rw-r--r-- | src/management/general.hpp | 21 | ||||
-rw-r--r-- | src/management/logger.cpp | 12 | ||||
-rw-r--r-- | src/management/logger.hpp | 13 | ||||
-rw-r--r-- | src/management/mail.cpp | 71 | ||||
-rw-r--r-- | src/management/mail.hpp | 30 | ||||
-rw-r--r-- | src/management/settings.cpp | 57 | ||||
-rw-r--r-- | src/management/settings.hpp | 30 |
11 files changed, 325 insertions, 0 deletions
diff --git a/src/management/builder/mail.cpp b/src/management/builder/mail.cpp new file mode 100644 index 0000000..f72803f --- /dev/null +++ b/src/management/builder/mail.cpp @@ -0,0 +1,23 @@ +#include "mail.hpp" +#include "file/mail.hpp" + +namespace smtp::manage::builder +{ + smtp::manage::Mail Mail::Build() const + { + static const std::string PATH = {"/var/lib/smtp/mails.txt"}; + + auto registrator = BuildErrorRegistrator(); + file::Mail file_manipulator{PATH, registrator}; + return smtp::manage::Mail{file_manipulator}; + } + + checker::RegistratorMails Mail::BuildErrorRegistrator() const + { + checker::RegistratorMails result; + + + return result; + } + +} diff --git a/src/management/builder/mail.hpp b/src/management/builder/mail.hpp new file mode 100644 index 0000000..ad1de36 --- /dev/null +++ b/src/management/builder/mail.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "managment/mail.hpp" +#include "checker/registrator_mails.hpp" + +namespace smtp::manage::builder +{ + class Mail + { + public: + Mail() = default; + ~Mail() = default; + + smtp::manage::Mail Build() const; + checker::RegistratorMails BuildErrorRegistrator() const; + }; + +} diff --git a/src/management/builder/settings.cpp b/src/management/builder/settings.cpp new file mode 100644 index 0000000..d5a5e3b --- /dev/null +++ b/src/management/builder/settings.cpp @@ -0,0 +1,29 @@ +#include "settings.hpp" +#include "checker/errors/settings/host_number.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}; + } + + checker::RegistratorSettings Settings::BuildErrorRegistrator() const + { + checker::RegistratorSettings result; + + result.Add( std::make_shared < checker::errors::settings::HostNumber >()); + return result; + } + +} diff --git a/src/management/builder/settings.hpp b/src/management/builder/settings.hpp new file mode 100644 index 0000000..67b7481 --- /dev/null +++ b/src/management/builder/settings.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "managment/settings.hpp" +#include "file/settings.hpp" +#include "checker/registrator_settings.hpp" + +namespace smtp::manage::builder +{ + class Settings + { + public: + Settings() = default; + ~Settings() = default; + + smtp::manage::Settings Build() const; + private: + file::Settings GetFileSettings() const; + checker::RegistratorSettings BuildErrorRegistrator() const; + }; + +} diff --git a/src/management/general.hpp b/src/management/general.hpp new file mode 100644 index 0000000..ed1a789 --- /dev/null +++ b/src/management/general.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include <unordered_map> +#include <string> +#include <list> + +namespace smtp::manage +{ + using SettingsFileDataType = std::unordered_map<std::string, std::string>; + using MailsSet = std::list<std::string>; + + struct SettingsFields + { + bool is_need_auth; + bool is_need_ssl; + std::string username; + std::string password; + std::string host; + std::string port; + }; +} diff --git a/src/management/logger.cpp b/src/management/logger.cpp new file mode 100644 index 0000000..0c55394 --- /dev/null +++ b/src/management/logger.cpp @@ -0,0 +1,12 @@ +#include <iostream> + +#include "logger.hpp" + +namespace smtp::manage +{ + void Logger::LogError( std::string const& message ) + { + std::cout << message << std::endl; + } + +} diff --git a/src/management/logger.hpp b/src/management/logger.hpp new file mode 100644 index 0000000..315e17e --- /dev/null +++ b/src/management/logger.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include <string> + +namespace smtp::manage +{ + class Logger + { + public: + Logger() = default; + static void LogError( std::string const& message ); + }; +} diff --git a/src/management/mail.cpp b/src/management/mail.cpp new file mode 100644 index 0000000..5c3c276 --- /dev/null +++ b/src/management/mail.cpp @@ -0,0 +1,71 @@ +#include <algorithm> + +#include "mail.hpp" + +namespace smtp::manage +{ + Mail::Mail( file::Mail const& file_reader ) + : mFileReader( file_reader ) + { + mMails = mFileReader.Read(); + } + + MailsSet Mail::GetMailToSend() const + { + return mMails; + } + + bool Mail::AddMailsToSend( MailsSet const& mails_to_add ) + { + auto merged_mails = GetMergedMails( mails_to_add ); + + auto result = mFileReader.Write( merged_mails ); + if( result ) + { + mMails = merged_mails; + } + return result; + } + + bool Mail::DeleteMailToSend( MailsSet const& mail_to_send ) + { + auto mails_to_delete = GetItersectionMails( mail_to_send ); + auto result_set_after_delete = GetMailsAfterDelete( mails_to_delete ); + auto result_of_delete = mFileReader.Write( result_set_after_delete ); + if( result_of_delete ) + { + mMails = result_set_after_delete; + } + return result_of_delete; + } + + MailsSet Mail::GetMergedMails( MailsSet const& mails_to_add ) + { + auto result = mails_to_add; + result.merge( mMails ); + return result; + } + + MailsSet Mail::GetItersectionMails( MailsSet const& mail_to_send ) + { + MailsSet result; + + auto sorted_mail_to_send = mail_to_send; + 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 ); + } + return result; + } +} diff --git a/src/management/mail.hpp b/src/management/mail.hpp new file mode 100644 index 0000000..12b79ab --- /dev/null +++ b/src/management/mail.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include <set> +#include <string> + +#include "file/mail.hpp" +#include "checker/registrator_mails.hpp" + +namespace smtp::manage +{ + class Mail + { + public: + explicit Mail( file::Mail const& file_reader ); + ~Mail() = default; + + MailsSet GetMailToSend() const; + bool AddMailsToSend( MailsSet const& mails ); + bool DeleteMailToSend( MailsSet const& mail_to_send ); + private: + MailsSet GetMergedMails( MailsSet const& mails_to_add ); + MailsSet GetItersectionMails( MailsSet const& mail_to_send ); + MailsSet GetMailsAfterDelete( MailsSet const& result_set_after_delete ); + + MailsSet mMails; + file::Mail mFileReader; + + }; + +} diff --git a/src/management/settings.cpp b/src/management/settings.cpp new file mode 100644 index 0000000..65888aa --- /dev/null +++ b/src/management/settings.cpp @@ -0,0 +1,57 @@ +#include "settings.hpp" +#include "converter/string.hpp" + +namespace smtp::manage +{ + Settings::Settings( file::Settings const& file_reader ) + : mFileReader( file_reader ) + { + ReloadSettings(); + } + + bool Settings::SetSettings( manage::SettingsFields const& settings_fields )const + { + return mFileReader.Write( settings_fields ); + } + + std::string Settings::GetSettings() + { + ReloadSettings(); + return converter::String{}.Convert(mSettingsFields); + } + + void Settings::ReloadSettings() + { + mSettingsFields = mFileReader.Read(); + } + + bool Settings::IsNeedAuth() const noexcept + { + return mSettingsFields.is_need_auth; + } + + bool Settings::IsNeedSsl() const noexcept + { + return mSettingsFields.is_need_ssl; + } + + std::string Settings::GetUserName() const + { + return mSettingsFields.username; + } + + std::string Settings::GetPassword() const + { + return mSettingsFields.password; + } + + std::string Settings::GetHost() const + { + return mSettingsFields.host; + } + + std::string Settings::GetPort() const + { + return mSettingsFields.port; + } +} diff --git a/src/management/settings.hpp b/src/management/settings.hpp new file mode 100644 index 0000000..3c0a15d --- /dev/null +++ b/src/management/settings.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include <string> + +#include "file/settings.hpp" +#include "managment/general.hpp" +namespace smtp::manage +{ + class Settings + { + public: + explicit Settings( file::Settings const& file_reader ); + ~Settings() = default; + + bool SetSettings( manage::SettingsFields const& settings_fields ) const; + std::string GetSettings(); + void ReloadSettings(); + + bool IsNeedAuth() const noexcept; + bool IsNeedSsl() const noexcept; + + std::string GetUserName() const; + std::string GetPassword() const; + std::string GetHost() const; + std::string GetPort() const; + private: + file::Settings mFileReader; + manage::SettingsFields mSettingsFields; + }; +} |