summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclaiff <claiff@mail.ru>2022-10-20 13:51:56 +0300
committerclaiff <claiff@mail.ru>2022-10-20 13:51:56 +0300
commit811e3a8312f3adb55320081ef93a9c2fa1af176a (patch)
tree66d720d5f5c0e07e4ca6b523f479dce48df06811
parent6e7f337d4d52debc0211cb5e083a27cd97a8ba4b (diff)
downloadobmc-sila-smtp-811e3a8312f3adb55320081ef93a9c2fa1af176a.tar.xz
if auth is disabled, for field is hostname
-rw-r--r--src/main.cpp1
-rw-r--r--src/message/queue_sender.cpp36
-rw-r--r--src/message/queue_sender.hpp6
-rw-r--r--src/service/smtp.cpp2
4 files changed, 39 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp
index cc92f3f..5833ba5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,5 +1,4 @@
#include <sdbusplus/asio/connection.hpp>
-
#include "service/smtp.hpp"
#include "management/builder/mail.hpp"
#include "management/builder/settings.hpp"
diff --git a/src/message/queue_sender.cpp b/src/message/queue_sender.cpp
index 8f0172a..9dbc8eb 100644
--- a/src/message/queue_sender.cpp
+++ b/src/message/queue_sender.cpp
@@ -5,12 +5,13 @@ namespace smtp::message
{
QueueSender::QueueSender( manage::Settings const& settings_storage,
manage::Mail& mail_to,
- thread::Queue& message_queue)
+ thread::Queue& message_queue,
+ std::shared_ptr<sdbusplus::asio::connection> connection )
: mSettingsStorage( settings_storage )
, mMailTo( mail_to )
, mMessageQueue( message_queue )
+ , mConnection( connection )
{
-
}
void QueueSender::SendMessages()
@@ -33,7 +34,36 @@ namespace smtp::message
std::string QueueSender::GetDefaultMailfrom() const
{
- return "cp2-5422";
+ static const std::string SERVICE_NAME = "org.freedesktop.hostname1";
+ static const std::string PATH_NAME = "/org/freedesktop/hostname1";
+ static const std::string INTERFACE_NAME = "org.freedesktop.hostname1";
+ static const std::string FUNCTION_NAME = "Hostname";
+ static const std::string PROPERTIES_INTERFACE = "org.freedesktop.DBus.Properties";
+ static const std::string PROPERTIES_GETTER_NAME = "Get";
+ static const std::string DEFAULT_HOST = "cp2-5422";
+
+ std::string result = DEFAULT_HOST;
+
+ mConnection->async_method_call(
+ [&result]( const boost::system::error_code& error_code, std::variant<std::monostate, std::string>& host_name) mutable{
+ if (error_code.value() == EBADR ||
+ error_code == boost::system::errc::host_unreachable)
+ {
+ return;
+ }
+ if (error_code)
+ {
+ return;
+ }
+ auto host_as_string = std::get_if<std::string>(&host_name);
+ if(host_as_string)
+ {
+ result = *host_as_string;
+ }
+ },
+ SERVICE_NAME, PATH_NAME, PROPERTIES_INTERFACE, PROPERTIES_GETTER_NAME, INTERFACE_NAME,
+ FUNCTION_NAME);
+ return result;
}
}
diff --git a/src/message/queue_sender.hpp b/src/message/queue_sender.hpp
index 170ebfc..a5724fb 100644
--- a/src/message/queue_sender.hpp
+++ b/src/message/queue_sender.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <sdbusplus/asio/connection.hpp>
+
#include "management/settings.hpp"
#include "management/mail.hpp"
#include "thread/queue.hpp"
@@ -11,7 +13,8 @@ namespace smtp::message
public:
QueueSender( manage::Settings const& settings_storage,
manage::Mail& mail_to,
- thread::Queue& message_queue );
+ thread::Queue& message_queue,
+ std::shared_ptr<sdbusplus::asio::connection> connection );
~QueueSender() = default;
void SendMessages();
@@ -22,5 +25,6 @@ namespace smtp::message
manage::Settings const& mSettingsStorage;
manage::Mail& mMailTo;
thread::Queue& mMessageQueue;
+ std::shared_ptr<sdbusplus::asio::connection> mConnection;
};
}
diff --git a/src/service/smtp.cpp b/src/service/smtp.cpp
index 81a3f0d..3c70856 100644
--- a/src/service/smtp.cpp
+++ b/src/service/smtp.cpp
@@ -15,7 +15,7 @@ namespace smtp::service
CreateSettingsManagerInterface( connection );
CreateMailManagerInterface( connection );
- message::QueueSender sender{ mSettingsStorage, mMailTo, mMessageQueue };
+ message::QueueSender sender{ mSettingsStorage, mMailTo, mMessageQueue, connection };
std::thread sender_message( &message::QueueSender::SendMessages, std::move(sender) );
sender_message.detach();
}