diff options
Diffstat (limited to 'src/service/smtp.cpp')
-rw-r--r-- | src/service/smtp.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/service/smtp.cpp b/src/service/smtp.cpp new file mode 100644 index 0000000..818a4de --- /dev/null +++ b/src/service/smtp.cpp @@ -0,0 +1,99 @@ +#include "smtp.hpp" +#include "message/sender.hpp" + +namespace smtp::service +{ + static constexpr char HOST_PROPERTY[] = "Host"; + static constexpr char USER_PROPERTY[] = "User"; + static constexpr char PORT_PROPERTY[] = "Port"; + + // + // Constructors + // + + Smtp::Smtp( ConnectionPtr connection ) + { + 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 }.Send( "claiff@mail.ru", "claiff1990@gmail.com", {"claiff@mail.ru"}, "subject", "text" ); + +// CreateService( connection ); +// CreateInterface( connection ); + } + + // + // Private methods + // + + void Smtp::CreateService( ConnectionPtr connection ) + { + static constexpr char SMTP_BUS_NAME[] = "xyz.openbmc_project.SMTP"; + + connection->request_name( SMTP_BUS_NAME ); + } + + void Smtp::CreateInterface( ConnectionPtr connection ) + { + static constexpr char SMTP_OBJECT_NAME[] = "/xyz/openbmc_project/SMTP"; + static constexpr char SMTP_INTERFACE_NAME[] = "xyz.openbmc_project.SMTP"; + + mObjectServer = std::make_shared<sdbusplus::asio::object_server>( connection ); + mInterface = mObjectServer->add_interface( SMTP_OBJECT_NAME, SMTP_INTERFACE_NAME ); + + AddProperties(); + AddMethods(); + + mInterface->initialize(); + } + + void Smtp::AddProperties() + { + 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 ); + } + + void Smtp::AddMethods() + { + 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, + std::string const& mail_to, + std::list<std::string> const& cc, + std::string const& theme, + std::string const& text ) + { return message::Sender{ mSettingsStorage }.Send( mail_from, mail_to, cc, 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);}); + } + + 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 ) + { + auto is_settings_norm = mSettingsStorage.CheckAndSetSettings({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; + } +} |