summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreportnov <eportnov@ibs.ru>2022-09-14 12:22:28 +0300
committereportnov <eportnov@ibs.ru>2022-09-14 12:33:40 +0300
commita2aeb219b8fa68ea05b79783c03b6f8ffc37558d (patch)
treefee97c3d1b032fa788412defb9c3d16b161d61f8
parent4a1c272dc8c5bbc4cc75ca4b68b04bd4d1089383 (diff)
downloadobmc-sila-smtp-a2aeb219b8fa68ea05b79783c03b6f8ffc37558d.tar.xz
add reload settings before readingdevtool-patcheddevtool-base
-rw-r--r--src/managment/settings.cpp9
-rw-r--r--src/managment/settings.hpp1
-rw-r--r--src/message/sender.cpp13
-rw-r--r--src/message/sender.hpp4
4 files changed, 21 insertions, 6 deletions
diff --git a/src/managment/settings.cpp b/src/managment/settings.cpp
index 860e7db..65888aa 100644
--- a/src/managment/settings.cpp
+++ b/src/managment/settings.cpp
@@ -6,7 +6,7 @@ namespace smtp::manage
Settings::Settings( file::Settings const& file_reader )
: mFileReader( file_reader )
{
- mSettingsFields = file_reader.Read();
+ ReloadSettings();
}
bool Settings::SetSettings( manage::SettingsFields const& settings_fields )const
@@ -16,10 +16,15 @@ namespace smtp::manage
std::string Settings::GetSettings()
{
- mSettingsFields = mFileReader.Read();
+ ReloadSettings();
return converter::String{}.Convert(mSettingsFields);
}
+ void Settings::ReloadSettings()
+ {
+ mSettingsFields = mFileReader.Read();
+ }
+
bool Settings::IsNeedAuth() const noexcept
{
return mSettingsFields.is_need_auth;
diff --git a/src/managment/settings.hpp b/src/managment/settings.hpp
index 3b72ec7..3c0a15d 100644
--- a/src/managment/settings.hpp
+++ b/src/managment/settings.hpp
@@ -14,6 +14,7 @@ namespace smtp::manage
bool SetSettings( manage::SettingsFields const& settings_fields ) const;
std::string GetSettings();
+ void ReloadSettings();
bool IsNeedAuth() const noexcept;
bool IsNeedSsl() const noexcept;
diff --git a/src/message/sender.cpp b/src/message/sender.cpp
index 4f903e8..5b3a421 100644
--- a/src/message/sender.cpp
+++ b/src/message/sender.cpp
@@ -16,7 +16,7 @@ namespace smtp::message
//
// Constructors/Destructors
//
- Sender::Sender( manage::Settings const& settings_storage, manage::Mail const& mail_to )
+ Sender::Sender( manage::Settings& settings_storage, manage::Mail const& mail_to )
: mSettingsStorage( settings_storage ),
mMailTo( mail_to )
{
@@ -33,12 +33,21 @@ namespace smtp::message
curl_slist *recipients = NULL;
WriteThis upload_ctx{};
auto curl = curl_easy_init();
+
//TODO сделать инициализацию через регистратор инициализаторов
+ mSettingsStorage.ReloadSettings();
if( !InitCurl( curl, upload_ctx, mail_from ) )
{
manage::Logger::LogError("Error to initializate curl");
return false;
}
+ //TODO раздать mail_to другим методам
+ auto mail_to = mMailTo.GetMailToSend();
+ if( mail_to.empty() )
+ {
+ manage::Logger::LogError("We haven't any mail to");
+ return false;
+ }
FillRecipients( curl, recipients );
UpdateMailText( mail_from, subject, text);
@@ -46,7 +55,7 @@ namespace smtp::message
if ( result != CURLE_OK )
{
- std::string message = "Error to send messge: " + std::to_string( *curl_easy_strerror( result ));
+ std::string message = "Error to send messge: " + std::string( curl_easy_strerror( result ));
manage::Logger::LogError(message);
return false;
}
diff --git a/src/message/sender.hpp b/src/message/sender.hpp
index 11afd6f..ca2c3ff 100644
--- a/src/message/sender.hpp
+++ b/src/message/sender.hpp
@@ -17,7 +17,7 @@ namespace smtp::message
class Sender
{
public:
- Sender( manage::Settings const& settings_storage, manage::Mail const& mail_to );
+ 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 );
@@ -28,7 +28,7 @@ namespace smtp::message
std::string GetHostPortData() const;
static size_t ReadCallBack( void *ptr, size_t size, size_t nmemb, void *userp );
- manage::Settings const& mSettingsStorage;
+ manage::Settings& mSettingsStorage;
manage::Mail const& mMailTo;
bool InitCurl( CURL* curl, WriteThis const& upload_ctx, std::string const& mail_from );