From a282ae6418c85db1aae5a2823dd37d56e56e5249 Mon Sep 17 00:00:00 2001 From: claiff Date: Tue, 20 Sep 2022 16:05:35 +0300 Subject: temp --- CMakeLists.txt | 14 +++++++++----- src/logger/logger_set.cpp | 5 +++-- src/logger/phosphor.cpp | 6 +++++- src/message/sender.hpp | 48 +++++++++++++++++++++++------------------------ src/service/smtp.cpp | 18 +++++++++--------- src/service/smtp.hpp | 12 +++--------- 6 files changed, 53 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3e2153..56bc523 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,6 @@ else() find_package (PkgConfig REQUIRED) pkg_check_modules (LOGGING phosphor-logging REQUIRED) - endif() include_directories(src) @@ -169,10 +168,6 @@ endif() add_executable(${PROJECT_NAME} ${SRC_FILES} ${PHOSPHOR_LOGGING_FILES}) -target_compile_definitions ( - ${PROJECT_NAME} PRIVATE $<$: -DADD_JOURNAL_LOGGING> -) - if(NOT ${YOCTO_DEPENDENCIES}) add_dependencies(${PROJECT_NAME} sdbusplus-project) elseif(${ADD_PHOSPHOR_LOGGING}) @@ -187,3 +182,12 @@ target_link_libraries(${PROJECT_NAME} curl) install(TARGETS ${PROJECT_NAME} DESTINATION bin) install(FILES ${PROJECT_SOURCE_DIR}/xyz.openbmc_project.SMTP.service DESTINATION /lib/systemd/system/) + +target_compile_definitions ( + ${PROJECT_NAME} PRIVATE $<$: -DADD_JOURNAL_LOGGING> + +) + +target_compile_definitions ( + ${PROJECT_NAME} PRIVATE $<$: -DADD_PHOSPHOR_LOGGING> +) diff --git a/src/logger/logger_set.cpp b/src/logger/logger_set.cpp index 8a061ed..6ea6d58 100644 --- a/src/logger/logger_set.cpp +++ b/src/logger/logger_set.cpp @@ -1,6 +1,7 @@ #include "logger_set.hpp" #include "journal.hpp" - +#include "phosphor.hpp" +#include namespace smtp::logger { std::shared_ptr < LoggerSet > LoggerSet::mInstance = nullptr; @@ -27,7 +28,7 @@ namespace smtp::logger loggers.push_back( std::make_shared < Journal >()); #endif #ifdef ADD_PHOSPHOR_LOGGING - loggers.push_back( std::make_shared < Journal >()); + loggers.push_back( std::make_shared < Phosphor >()); #endif mInstance.reset( new LoggerSet( loggers )); } diff --git a/src/logger/phosphor.cpp b/src/logger/phosphor.cpp index 48bb49e..d3c81b0 100644 --- a/src/logger/phosphor.cpp +++ b/src/logger/phosphor.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "phosphor.hpp" @@ -6,6 +8,8 @@ namespace smtp::logger { void Phosphor::LogError( std::string const& message ) const { - phosphor::logging::log < phosphor::logging::level::ERR >( message.c_str()); + using InternalFailure = + sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; + phosphor::logging::commit(message); } } \ No newline at end of file diff --git a/src/message/sender.hpp b/src/message/sender.hpp index ca2c3ff..d19e209 100644 --- a/src/message/sender.hpp +++ b/src/message/sender.hpp @@ -7,32 +7,32 @@ #include "managment/settings.hpp" #include "managment/mail.hpp" + namespace smtp::message { - struct WriteThis - { - int counter; - }; - - class Sender - { - public: - Sender( manage::Settings& settings_storage, manage::Mail const& mail_to ); - ~Sender() = default; - - bool Send( std::string const& mail_from, std::string const& subject, std::string const& text ); - private: - void UpdateMailText( std::string const& mail_from, std::string const& subject, std::string const& textt ) const; - void InitSenders( std::string const& mail_from, std::list const& mail_to ); - void FillRecipients(CURL* curl, curl_slist* recipients ); - std::string GetHostPortData() const; - static size_t ReadCallBack( void *ptr, size_t size, size_t nmemb, void *userp ); - - manage::Settings& mSettingsStorage; - manage::Mail const& mMailTo; - - bool InitCurl( CURL* curl, WriteThis const& upload_ctx, std::string const& mail_from ); - }; + struct WriteThis + { + int counter; + }; + + class Sender + { + public: + Sender( manage::Settings& settings_storage, manage::Mail const& mail_to ); + ~Sender() = default; + + bool Send( std::string const& mail_from, std::string const& subject, std::string const& text ); + private: + void UpdateMailText( std::string const& mail_from, std::string const& subject, std::string const& textt ) const; + void FillRecipients( CURL* curl, curl_slist* recipients ); + std::string GetHostPortData() const; + static size_t ReadCallBack( void* ptr, size_t size, size_t nmemb, void* userp ); + + manage::Settings& mSettingsStorage; + manage::Mail const& mMailTo; + + bool InitCurl( CURL* curl, WriteThis const& upload_ctx, std::string const& mail_from ); + }; } diff --git a/src/service/smtp.cpp b/src/service/smtp.cpp index 702de2d..7b1ca70 100644 --- a/src/service/smtp.cpp +++ b/src/service/smtp.cpp @@ -11,7 +11,7 @@ namespace smtp::service :mSettingsStorage(settings), mMailTo(mail_to) { CreateService( connection ); - CreateMessagerInterface( connection ); + CreateMessengerInterface( connection ); CreateSettingsManagerInterface( connection ); CreateMailManagerInterface( connection ); } @@ -27,17 +27,17 @@ namespace smtp::service connection->request_name( SMTP_BUS_NAME ); } - void Smtp::CreateMessagerInterface( ConnectionPtr connection ) + void Smtp::CreateMessengerInterface( ConnectionPtr connection ) { 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( connection ); - mMessagerInterface = mObjectServer->add_interface( SMTP_OBJECT_NAME, SMTP_INTERFACE_NAME ); + mMessengerInterface = mObjectServer->add_interface( SMTP_OBJECT_NAME, SMTP_INTERFACE_NAME ); - AddMessagerMethods(); + AddMessengerMethods(); - mMessagerInterface->initialize(); + mMessengerInterface->initialize(); } void Smtp::CreateSettingsManagerInterface(ConnectionPtr connection) @@ -66,13 +66,13 @@ namespace smtp::service mManagerMailInterface->initialize(); } - void Smtp::AddMessagerMethods() + void Smtp::AddMessengerMethods() { static constexpr char SMTP_SEND_MESSAGE_METHOD_NAME[] = "SendMail"; - mMessagerInterface->register_method(SMTP_SEND_MESSAGE_METHOD_NAME, [this]( std::string const& mail_from, - std::string const& theme, - std::string const& text ) + mMessengerInterface->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 );}); } diff --git a/src/service/smtp.hpp b/src/service/smtp.hpp index a52c9c0..edf964e 100644 --- a/src/service/smtp.hpp +++ b/src/service/smtp.hpp @@ -20,21 +20,15 @@ namespace smtp::service Smtp( ConnectionPtr connection, manage::Settings const& settings, manage::Mail const& mail_to ); ~Smtp() = default; private: - void FillStorageByDefault(); void CreateService( ConnectionPtr bus ); - void CreateMessagerInterface( ConnectionPtr connection ); + void CreateMessengerInterface( ConnectionPtr connection ); void CreateSettingsManagerInterface( ConnectionPtr connection ); void CreateMailManagerInterface( ConnectionPtr connection ); - void AddProperties(); - void AddMessagerMethods(); + void AddMessengerMethods(); 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 mMessagerInterface; + InterfacePtr mMessengerInterface; InterfacePtr mManagerSettingsInterface; InterfacePtr mManagerMailInterface; -- cgit v1.2.3