#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( 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 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; } }