summaryrefslogtreecommitdiff
path: root/src/smtp_service.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/smtp_service.cpp')
-rw-r--r--src/smtp_service.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/smtp_service.cpp b/src/smtp_service.cpp
new file mode 100644
index 0000000..6235e4c
--- /dev/null
+++ b/src/smtp_service.cpp
@@ -0,0 +1,96 @@
+#include "smtp_service.hpp"
+#include "message_sender.hpp"
+
+namespace smtp
+{
+ static constexpr char HOST_PROPERTY[] = "Host";
+ static constexpr char USER_PROPERTY[] = "User";
+ static constexpr char PORT_PROPERTY[] = "Port";
+
+ //
+ // Constructors
+ //
+
+ SmtpService::SmtpService( ConnectionPtr connection )
+ {
+ FillStorageByDefault();
+ CreateService( connection );
+ CreateInterface( connection );
+ }
+
+ //
+ // Private methods
+ //
+
+ void SmtpService::FillStorageByDefault()
+ {
+ mStorage.host = "";
+ mStorage.username = "";
+ mStorage.password = "";
+ mStorage.port = "";
+ }
+
+ void SmtpService::CreateService( ConnectionPtr connection )
+ {
+ static constexpr char SMTP_BUS_NAME[] = "xyz.openbmc_project.SMTP";
+
+ connection->request_name( SMTP_BUS_NAME );
+ }
+
+ void SmtpService::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 SmtpService::AddProperties()
+ {
+ mInterface->register_property( HOST_PROPERTY, mStorage.host, sdbusplus::asio::PropertyPermission::readOnly );
+ mInterface->register_property( USER_PROPERTY, mStorage.username, sdbusplus::asio::PropertyPermission::readOnly );
+ mInterface->register_property( PORT_PROPERTY, mStorage.port, sdbusplus::asio::PropertyPermission::readOnly );
+ }
+
+ void SmtpService::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 MessageSender{ mStorage }.Send( mail_from, mail_to, cc, theme, text );});
+
+
+ mInterface->register_method(SMTP_CHANGE_PARAMETERS_METHOD_NAME, [this]( std::string const& user,
+ std::string const& password,
+ std::string const& host,
+ std::string const& port )
+ { return RefreshSettings(user, password, host, port);});
+ }
+
+ bool SmtpService::RefreshSettings(std::string const& user,
+ std::string const& password,
+ std::string const& host,
+ std::string const& port)
+ {
+ mStorage.username = user;
+ mStorage.password = password;
+ mStorage.host = host;
+ mStorage.port = port;
+
+ mInterface->set_property(HOST_PROPERTY, host);
+ mInterface->set_property(USER_PROPERTY, user);
+ mInterface->set_property(PORT_PROPERTY, port);
+ return true;
+ }
+}