summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreportnov <eportnov@ibs.ru>2022-09-13 17:30:47 +0300
committereportnov <eportnov@ibs.ru>2022-09-14 09:33:30 +0300
commit942b22b2ef5ba188ea077dd545c5f240a043cf6f (patch)
tree0c7b4585ba47af057db150f6226ffcdeca66c7ba
parentbab12f829beb53feb6f48db7a0ef33574740989c (diff)
downloadobmc-sila-smtp-feature/add_new_interfaces.tar.xz
add new interfacesfeature/add_new_interfaces
-rw-r--r--CMakeLists.txt17
-rw-r--r--src/converter/file.cpp (renamed from src/file/converter/file.cpp)2
-rw-r--r--src/converter/file.hpp (renamed from src/file/converter/file.hpp)2
-rw-r--r--src/converter/full.cpp (renamed from src/file/converter/full.cpp)4
-rw-r--r--src/converter/full.hpp (renamed from src/file/converter/full.hpp)4
-rw-r--r--src/converter/settings.cpp (renamed from src/file/converter/settings.cpp)18
-rw-r--r--src/converter/settings.hpp28
-rw-r--r--src/converter/string.cpp82
-rw-r--r--src/converter/string.hpp31
-rw-r--r--src/file/converter/settings.hpp30
-rw-r--r--src/file/mail.cpp11
-rw-r--r--src/file/settings.cpp6
-rw-r--r--src/managment/builder/mail.cpp2
-rw-r--r--src/managment/builder/settings.cpp2
-rw-r--r--src/managment/settings.cpp6
-rw-r--r--src/managment/settings.hpp1
-rw-r--r--src/service/smtp.cpp116
-rw-r--r--src/service/smtp.hpp14
18 files changed, 256 insertions, 120 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 12ba97a..e894480 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -82,7 +82,8 @@ set(MANAGMENT_DIR src/managment)
set(FILE_DIR src/file)
set(PARSER_DIR src/file/parser)
set(MANAGER_BUILDER_DIR src/managment/builder)
-set(FILE_CONVERTER_DIR src/file/converter)
+set(CONVERTER_DIR src/converter)
+
set(SRC_FILES
${SRC_DIR}/main.cpp
@@ -118,12 +119,14 @@ set(SRC_FILES
${FILE_DIR}/settings.hpp
${FILE_DIR}/settings.cpp
- ${FILE_CONVERTER_DIR}/full.hpp
- ${FILE_CONVERTER_DIR}/full.cpp
- ${FILE_CONVERTER_DIR}/settings.hpp
- ${FILE_CONVERTER_DIR}/settings.cpp
- ${FILE_CONVERTER_DIR}/file.hpp
- ${FILE_CONVERTER_DIR}/file.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
${PARSER_DIR}/settings.hpp
${PARSER_DIR}/settings.cpp
diff --git a/src/file/converter/file.cpp b/src/converter/file.cpp
index d0bb032..203cca9 100644
--- a/src/file/converter/file.cpp
+++ b/src/converter/file.cpp
@@ -1,6 +1,6 @@
#include "file.hpp"
-namespace smtp::file::converter
+namespace smtp::converter
{
manage::SettingsFields File::Convert( manage::SettingsFileDataType const& from ) const
{
diff --git a/src/file/converter/file.hpp b/src/converter/file.hpp
index 63ff6dd..64ef152 100644
--- a/src/file/converter/file.hpp
+++ b/src/converter/file.hpp
@@ -5,7 +5,7 @@
#include "managment/general.hpp"
-namespace smtp::file::converter
+namespace smtp::converter
{
class File
{
diff --git a/src/file/converter/full.cpp b/src/converter/full.cpp
index 61f5a85..91a9816 100644
--- a/src/file/converter/full.cpp
+++ b/src/converter/full.cpp
@@ -2,9 +2,9 @@
#include "file.hpp"
#include "settings.hpp"
-namespace smtp::file::converter
+namespace smtp::converter
{
- manage::SettingsFields Full::Convert( ParsedDataType const& from ) const
+ manage::SettingsFields Full::Convert( manage::SettingsFileDataType const& from ) const
{
return File{}.Convert( from );
}
diff --git a/src/file/converter/full.hpp b/src/converter/full.hpp
index 5ffccd4..7025324 100644
--- a/src/file/converter/full.hpp
+++ b/src/converter/full.hpp
@@ -5,10 +5,8 @@
#include "managment/general.hpp"
-namespace smtp::file::converter
+namespace smtp::converter
{
- using ParsedDataType = std::unordered_map<std::string, std::string>;
-
class Full
{
public:
diff --git a/src/file/converter/settings.cpp b/src/converter/settings.cpp
index 809eef8..7aa2106 100644
--- a/src/file/converter/settings.cpp
+++ b/src/converter/settings.cpp
@@ -1,11 +1,11 @@
#include "settings.hpp"
-namespace smtp::file::converter
+namespace smtp::converter
{
- ParsedDataType Settings::Convert( manage::SettingsFields const& from ) const
+ manage::SettingsFileDataType Settings::Convert( manage::SettingsFields const& from ) const
{
- ParsedDataType result;
+ manage::SettingsFileDataType result;
ApplyPort( from, result );
ApplyHost( from, result );
@@ -17,7 +17,7 @@ namespace smtp::file::converter
return result;
}
- void Settings::ApplyAuth( manage::SettingsFields const& from, ParsedDataType& result ) const
+ void Settings::ApplyAuth( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const
{
static const std::string FIELD = "need_auth";
static const std::string TRUE_AS_STRING = "true";
@@ -26,7 +26,7 @@ namespace smtp::file::converter
from.is_need_auth ? result.insert({FIELD, TRUE_AS_STRING}) : result.insert({FIELD, FALSE_AS_STRING});
}
- void Settings::ApplySsl( manage::SettingsFields const& from, ParsedDataType& result ) const
+ void Settings::ApplySsl( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const
{
static const std::string FIELD = "need_ssl";
static const std::string TRUE_AS_STRING = "true";
@@ -35,28 +35,28 @@ namespace smtp::file::converter
from.is_need_ssl ? result.insert({FIELD, TRUE_AS_STRING}) : result.insert({FIELD, FALSE_AS_STRING});
}
- void Settings::ApplyUsername( manage::SettingsFields const& from, ParsedDataType& result ) const
+ void Settings::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, ParsedDataType& result ) const
+ void Settings::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, ParsedDataType& result ) const
+ void Settings::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, ParsedDataType& result ) const
+ void Settings::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/settings.hpp
new file mode 100644
index 0000000..d25a550
--- /dev/null
+++ b/src/converter/settings.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <unordered_map>
+#include <string>
+
+#include "managment/general.hpp"
+
+namespace smtp::converter
+{
+ class Settings
+ {
+ public:
+ Settings() = default;
+ ~Settings() = default;
+
+ std::unordered_map<std::string, std::string> 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;
+
+ void ApplyUsername( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const;
+ void ApplyPassword( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const;
+ void ApplyHost( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const;
+ void ApplyPort( manage::SettingsFields const& from, manage::SettingsFileDataType& result ) const;
+ };
+}
+
+
diff --git a/src/converter/string.cpp b/src/converter/string.cpp
new file mode 100644
index 0000000..cbdc544
--- /dev/null
+++ b/src/converter/string.cpp
@@ -0,0 +1,82 @@
+#include "string.hpp"
+
+namespace smtp::converter
+{
+ std::string String::Convert( manage::SettingsFields const& from ) const
+ {
+ std::string result;
+
+ ApplyPort( from, result );
+ ApplyHost( from, result );
+ ApplyPassword( from, result );
+ ApplyUsername( from, result );
+ ApplySsl( from, result );
+ ApplyAuth( from, result );
+
+ return result;
+ }
+
+ void String::ApplyAuth( manage::SettingsFields const& from, std::string& result ) const
+ {
+ static const std::string FIELD = "need_auth";
+
+ result += GetBoolParam( FIELD, from.is_need_auth);
+ }
+
+ void String::ApplySsl( manage::SettingsFields const& from, std::string& result ) const
+ {
+ static const std::string FIELD = "need_ssl";
+
+ result += GetBoolParam( FIELD, from.is_need_ssl);
+ }
+
+ void String::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
+ {
+ static const std::string FIELD = "password";
+
+ result += GetStringParam( FIELD, from.password );
+ }
+
+ void String::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
+ {
+ static const std::string FIELD = "port";
+
+ result += GetStringParam( FIELD, from.port );
+ }
+
+ std::string String::GetStringParam(const std::string &field, const std::string &param) const
+ {
+ std::string result;
+ result += field;
+ result += '=';
+ result += param;
+ result += '&';
+ return result;
+ }
+
+ std::string String::GetBoolParam(const std::string &field, bool param) const
+ {
+ std::string result;
+
+ result += field;
+ result += '=';
+ result += param ? "true" : "false";
+ result += '&';
+
+ return result;
+ }
+}
diff --git a/src/converter/string.hpp b/src/converter/string.hpp
new file mode 100644
index 0000000..f1752ad
--- /dev/null
+++ b/src/converter/string.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <unordered_map>
+#include <string>
+
+#include "managment/general.hpp"
+
+namespace smtp::converter
+{
+ class String
+ {
+ public:
+ String() = default;
+ ~String() = default;
+
+ std::string Convert( manage::SettingsFields const& from ) const;
+ private:
+ void ApplyAuth( manage::SettingsFields const& from, std::string& result ) const;
+ void ApplySsl( manage::SettingsFields const& from, std::string& result ) const;
+
+ void ApplyUsername( manage::SettingsFields const& from, std::string& result ) const;
+ void ApplyPassword( manage::SettingsFields const& from, std::string& result ) const;
+ void ApplyHost( manage::SettingsFields const& from, std::string& result ) const;
+ void ApplyPort( manage::SettingsFields const& from, std::string& result ) const;
+
+ std::string GetStringParam( std::string const& field, std::string const& param ) const;
+ std::string GetBoolParam( std::string const& field, bool param ) const;
+ };
+}
+
+
diff --git a/src/file/converter/settings.hpp b/src/file/converter/settings.hpp
deleted file mode 100644
index 8f94942..0000000
--- a/src/file/converter/settings.hpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma once
-
-#include <unordered_map>
-#include <string>
-
-#include "managment/general.hpp"
-
-namespace smtp::file::converter
-{
- using ParsedDataType = std::unordered_map<std::string, std::string>;;
-
- class Settings
- {
- public:
- Settings() = default;
- ~Settings() = default;
-
- std::unordered_map<std::string, std::string> Convert( manage::SettingsFields const& from ) const;
- private:
- void ApplyAuth( manage::SettingsFields const& from, ParsedDataType& result ) const;
- void ApplySsl( manage::SettingsFields const& from, ParsedDataType& result ) const;
-
- void ApplyUsername( manage::SettingsFields const& from, ParsedDataType& result ) const;
- void ApplyPassword( manage::SettingsFields const& from, ParsedDataType& result ) const;
- void ApplyHost( manage::SettingsFields const& from, ParsedDataType& result ) const;
- void ApplyPort( manage::SettingsFields const& from, ParsedDataType& result ) const;
- };
-}
-
-
diff --git a/src/file/mail.cpp b/src/file/mail.cpp
index 4da36c5..1516880 100644
--- a/src/file/mail.cpp
+++ b/src/file/mail.cpp
@@ -7,12 +7,11 @@ namespace smtp::file
Mail::Mail( std::string const& path_file )
: mPathFile( path_file )
{
-
}
manage::MailsSet Mail::Read() const
{
- std::ifstream mail_file{ mPathFile };
+ std::ifstream mail_file{ mPathFile, std::fstream::in };
if ( !mail_file.is_open() )
{
//TODO new file
@@ -29,13 +28,14 @@ namespace smtp::file
result.push_back( *parsed_data );
}
}
+ mail_file.close();
return result;
}
bool Mail::Write( manage::MailsSet const& data ) const
{
- std::ofstream settings_file{ mPathFile };
- if ( !settings_file.is_open() )
+ std::ofstream mail_file{ mPathFile, std::fstream::out | std::fstream::trunc };
+ if ( !mail_file.is_open() )
{
//TODO new file
// std::cerr << "Failed to open pcie_devices database \n";
@@ -43,8 +43,9 @@ namespace smtp::file
}
for( const auto& pair : data )
{
- settings_file << pair << "\n";
+ mail_file << pair << "\n";
}
+ mail_file.close();
return true;
}
diff --git a/src/file/settings.cpp b/src/file/settings.cpp
index 4691fda..df619c9 100644
--- a/src/file/settings.cpp
+++ b/src/file/settings.cpp
@@ -24,7 +24,7 @@ namespace smtp::file
ParsedStoreType Settings::GetParsedStore() const
{
- std::ifstream settings_file{ mPathFile };
+ std::ifstream settings_file{ mPathFile, std::fstream::in };
if ( !settings_file.is_open() )
{
//TODO new file
@@ -38,12 +38,13 @@ namespace smtp::file
auto parsed_data = parser::Settings{}.Parse(line);
result.insert( parsed_data );
}
+ settings_file.close();
return result;
}
bool Settings::SetParsedData( ParsedStoreType const& parsed_data ) const
{
- std::ofstream settings_file{ mPathFile };
+ std::ofstream settings_file{ mPathFile, std::fstream::out | std::fstream::trunc };
if ( !settings_file.is_open() )
{
//TODO new file
@@ -55,6 +56,7 @@ namespace smtp::file
auto line = BuildParam( data );
settings_file << line << "\n";
}
+ settings_file.close();
return true;
}
diff --git a/src/managment/builder/mail.cpp b/src/managment/builder/mail.cpp
index d8413d1..fb56462 100644
--- a/src/managment/builder/mail.cpp
+++ b/src/managment/builder/mail.cpp
@@ -5,7 +5,7 @@ namespace smtp::manage::builder
{
smtp::manage::Mail Mail::Build() const
{
- static const std::string PATH = {"/home/eportnov/work/openbmc/build/cp2-5422/workspace/sources/smtp/mails.txt"};
+ static const std::string PATH = {"/var/lib/smtp/conf/mails.txt"};
file::Mail file_manipulator{PATH};
return smtp::manage::Mail{ file_manipulator };
diff --git a/src/managment/builder/settings.cpp b/src/managment/builder/settings.cpp
index bfa8fb2..02439fd 100644
--- a/src/managment/builder/settings.cpp
+++ b/src/managment/builder/settings.cpp
@@ -11,7 +11,7 @@ namespace smtp::manage::builder
file::Settings Settings::GetFileSettings() const
{
- static const std::string PATH = {"/home/eportnov/work/openbmc/build/cp2-5422/workspace/sources/smtp/settings.txt"};
+ static const std::string PATH = {"/var/lib/smtp/conf/settings.txt"};
return file::Settings{PATH};
}
diff --git a/src/managment/settings.cpp b/src/managment/settings.cpp
index 1f597c2..08a8a15 100644
--- a/src/managment/settings.cpp
+++ b/src/managment/settings.cpp
@@ -1,4 +1,5 @@
#include "settings.hpp"
+#include "converter/string.hpp"
namespace smtp::manage
{
@@ -13,6 +14,11 @@ namespace smtp::manage
return mFileReader.Write( settings_fields );
}
+ std::string Settings::GetSettings() const
+ {
+ return converter::String{}.Convert(mSettingsFields);
+ }
+
bool Settings::IsNeedAuth() const noexcept
{
return mSettingsFields.is_need_auth;
diff --git a/src/managment/settings.hpp b/src/managment/settings.hpp
index ff78af6..9b34c2c 100644
--- a/src/managment/settings.hpp
+++ b/src/managment/settings.hpp
@@ -13,6 +13,7 @@ namespace smtp::manage
~Settings() = default;
bool SetSettings( manage::SettingsFields const& settings_fields ) const;
+ std::string GetSettings() const;
bool IsNeedAuth() const noexcept;
bool IsNeedSsl() const noexcept;
diff --git a/src/service/smtp.cpp b/src/service/smtp.cpp
index cf3dc45..96bee38 100644
--- a/src/service/smtp.cpp
+++ b/src/service/smtp.cpp
@@ -3,10 +3,6 @@
#include <iostream>
namespace smtp::service
{
- static constexpr char HOST_PROPERTY[] = "Host";
- static constexpr char USER_PROPERTY[] = "User";
- static constexpr char PORT_PROPERTY[] = "Port";
-
//
// Constructors
//
@@ -14,21 +10,10 @@ namespace smtp::service
Smtp::Smtp( ConnectionPtr connection, manage::Settings const& settings, manage::Mail const& mail_to )
:mSettingsStorage(settings), mMailTo(mail_to)
{
-// std::string from{"claiff@mail.ru"};
-// std::string to{"claiff1990@gmail.com"};
-// std::list<std::string> cc{"claiff@mail.ru"};
-// std::string subject{"subject"};
-// std::string text{"text"};
-
- // mSettingsStorage.CheckAndSetSettings({true, true, "claiff@mail.ru","nZZbXq7FbwWAqpPpy3YL", "smtp.mail.ru", "" });
- //message::Sender{ mSettingsStorage, mMailTo }.Send( "claiff@mail.ru", "subject", "text" );
- //settings.SetSettings(manage::SettingsFields{false,false,"claiff@mail.ru","nZZbXq7FbwWAqpPpy3YL","smtp.mail.ru",""});
- manage::MailsSet add_mail{"gfdgdf@fd.ru"};
- //mMailTo.AddMailsToSend( add_mail );
- mMailTo.DeleteMailToSend({"gfdgdf@fd.ru", "rwer", "fedsfsd"});
-
-// CreateService( connection );
-// CreateInterface( connection );
+ CreateService( connection );
+ CreateMessagerInterface( connection );
+ CreateSettingsManagerInterface( connection );
+ CreateMailManagerInterface( connection );
}
//
@@ -42,61 +27,82 @@ namespace smtp::service
connection->request_name( SMTP_BUS_NAME );
}
- void Smtp::CreateInterface( ConnectionPtr connection )
+ void Smtp::CreateMessagerInterface( ConnectionPtr connection )
{
- static constexpr char SMTP_OBJECT_NAME[] = "/xyz/openbmc_project/SMTP";
- static constexpr char SMTP_INTERFACE_NAME[] = "xyz.openbmc_project.SMTP";
+ static constexpr char SMTP_OBJECT_NAME[] = "/xyz/openbmc_project/SMTP/Messenger";
+ static constexpr char SMTP_INTERFACE_NAME[] = "xyz.openbmc_project.Messenger";
mObjectServer = std::make_shared<sdbusplus::asio::object_server>( connection );
- mInterface = mObjectServer->add_interface( SMTP_OBJECT_NAME, SMTP_INTERFACE_NAME );
+ mMessagerInterface = mObjectServer->add_interface( SMTP_OBJECT_NAME, SMTP_INTERFACE_NAME );
- AddProperties();
- AddMethods();
+ AddMessagerMethods();
- mInterface->initialize();
+ mMessagerInterface->initialize();
}
- void Smtp::AddProperties()
+ void Smtp::CreateSettingsManagerInterface(ConnectionPtr connection)
{
- mInterface->register_property( HOST_PROPERTY, mSettingsStorage.GetHost(), sdbusplus::asio::PropertyPermission::readOnly );
- mInterface->register_property( USER_PROPERTY, mSettingsStorage.GetUserName(), sdbusplus::asio::PropertyPermission::readOnly );
- mInterface->register_property( PORT_PROPERTY, mSettingsStorage.GetPort(), sdbusplus::asio::PropertyPermission::readOnly );
+ static constexpr char SMTP_MANAGER_OBJECT_NAME[] = "/xyz/openbmc_project/Manager";
+ static constexpr char SMTP_SETTINGS_MANAGER_INTERFACE_NAME[] = "xyz.openbmc_project.SettingsManager";
+
+ mObjectServer = std::make_shared<sdbusplus::asio::object_server>( connection );
+ mManagerSettingsInterface = mObjectServer->add_interface( SMTP_MANAGER_OBJECT_NAME, SMTP_SETTINGS_MANAGER_INTERFACE_NAME );
+
+ AddSettingsManagerMethods();
+
+ mManagerSettingsInterface->initialize();
}
- void Smtp::AddMethods()
+ void Smtp::CreateMailManagerInterface(ConnectionPtr connection)
+ {
+ static constexpr char SMTP_MANAGER_OBJECT_NAME[] = "/xyz/openbmc_project/SMTP/Manager";
+ static constexpr char SMTP_MAIL_MANAGER_INTERFACE_NAME[] = "xyz.openbmc_project.MailManager";
+
+ mObjectServer = std::make_shared<sdbusplus::asio::object_server>( connection );
+ mManagerMailInterface = mObjectServer->add_interface( SMTP_MANAGER_OBJECT_NAME, SMTP_MAIL_MANAGER_INTERFACE_NAME );
+
+ AddMailManagerMethods();
+
+ mManagerMailInterface->initialize();
+ }
+
+ void Smtp::AddMessagerMethods()
{
static constexpr char SMTP_SEND_MESSAGE_METHOD_NAME[] = "SendMail";
- static constexpr char SMTP_CHANGE_PARAMETERS_METHOD_NAME[] = "ChangeParameters";
- mInterface->register_method(SMTP_SEND_MESSAGE_METHOD_NAME, [this]( std::string const& mail_from,
+ mMessagerInterface->register_method(SMTP_SEND_MESSAGE_METHOD_NAME, [this]( std::string const& mail_from,
std::string const& theme,
std::string const& text )
{ return message::Sender{ mSettingsStorage, mMailTo }.Send( mail_from, theme, text );});
+ }
-
- mInterface->register_method(SMTP_CHANGE_PARAMETERS_METHOD_NAME, [this]( bool is_need_auth,
- bool is_need_ssl,
- std::string const& user,
- std::string const& password,
- std::string const& host,
- std::string const& port )
- { return RefreshSettings( is_need_auth, is_need_ssl, user, password, host, port);});
+ void Smtp::AddSettingsManagerMethods()
+ {
+ static constexpr char SMTP_SET_SETTINGS_METHOD_NAME[] = "SetSettings";
+ static constexpr char SMTP_GET_SETTINGS_METHOD_NAME[] = "GetSettings";
+
+ mManagerSettingsInterface->register_method(SMTP_SET_SETTINGS_METHOD_NAME, [this]( bool is_need_auth,
+ bool is_need_ssl,
+ std::string const& user,
+ std::string const& password,
+ std::string const& host,
+ std::string const& port )
+ { mSettingsStorage.SetSettings({ is_need_auth, is_need_ssl,
+ user, password, host, port});});
+
+ mManagerSettingsInterface->register_method(SMTP_GET_SETTINGS_METHOD_NAME, [this](){ return mSettingsStorage.GetSettings();});
}
- bool Smtp::RefreshSettings( bool is_need_auth, bool is_need_ssl,
- std::string const& user, std::string const& password,
- std::string const& host, std::string const& port )
+ void Smtp::AddMailManagerMethods()
{
- auto is_settings_norm = mSettingsStorage.SetSettings({is_need_auth, is_need_ssl,
- user, password, host, port});
- if(!is_settings_norm)
- {
- return false;
- }
-
- mInterface->set_property(HOST_PROPERTY, host);
- mInterface->set_property(USER_PROPERTY, user);
- mInterface->set_property(PORT_PROPERTY, port);
- return true;
+ static constexpr char SMTP_GET_MAILS_TO_SEND_METHOD_NAME[] = "GetMailsToSend";
+ static constexpr char SMTP_ADD_MAILS_TO_SEND_METHOD_NAME[] = "AddMailsToSend";
+ static constexpr char SMTP_DELETE_MAILS_METHOD_NAME[] = "DeleteMailsToSend";
+
+ mManagerMailInterface->register_method( SMTP_GET_MAILS_TO_SEND_METHOD_NAME, [this]()
+ { return mMailTo.GetMailToSend();});
+
+ mManagerMailInterface->register_method( SMTP_ADD_MAILS_TO_SEND_METHOD_NAME, [this](manage::MailsSet const& mails){ return mMailTo.AddMailsToSend(mails);});
+ mManagerMailInterface->register_method( SMTP_DELETE_MAILS_METHOD_NAME, [this](manage::MailsSet const& mails_to_delete){ return mMailTo.DeleteMailToSend(mails_to_delete);});
}
}
diff --git a/src/service/smtp.hpp b/src/service/smtp.hpp
index 0284f42..a52c9c0 100644
--- a/src/service/smtp.hpp
+++ b/src/service/smtp.hpp
@@ -22,14 +22,22 @@ namespace smtp::service
private:
void FillStorageByDefault();
void CreateService( ConnectionPtr bus );
- void CreateInterface( ConnectionPtr connection );
+ void CreateMessagerInterface( ConnectionPtr connection );
+ void CreateSettingsManagerInterface( ConnectionPtr connection );
+ void CreateMailManagerInterface( ConnectionPtr connection );
void AddProperties();
- void AddMethods();
+ void AddMessagerMethods();
+ void AddSettingsManagerMethods();
+ void AddMailManagerMethods();
+
bool RefreshSettings( bool is_need_auth, bool is_need_ssl,
std::string const& user, std::string const& password,
std::string const& host, std::string const& port );
- InterfacePtr mInterface;
+ InterfacePtr mMessagerInterface;
+ InterfacePtr mManagerSettingsInterface;
+ InterfacePtr mManagerMailInterface;
+
ObjectServerPtr mObjectServer;
manage::Settings mSettingsStorage;
manage::Mail mMailTo;