summaryrefslogtreecommitdiff
path: root/src/file
diff options
context:
space:
mode:
Diffstat (limited to 'src/file')
-rw-r--r--src/file/mail.cpp91
-rw-r--r--src/file/mail.hpp8
-rw-r--r--src/file/settings.cpp97
-rw-r--r--src/file/settings.hpp39
4 files changed, 123 insertions, 112 deletions
diff --git a/src/file/mail.cpp b/src/file/mail.cpp
index 1453535..cf5fe26 100644
--- a/src/file/mail.cpp
+++ b/src/file/mail.cpp
@@ -5,59 +5,50 @@
namespace smtp::file
{
- Mail::Mail( std::string const& path_file )
- : mPathFile( path_file )
- {
- }
+ Mail::Mail( std::string const& path_file, checker::RegistratorMails const& registrator_errors )
+ : mPathFile( path_file )
+ , mRegistratorErrors( registrator_errors )
+ {
+ }
- manage::MailsSet Mail::Read() const
- {
- std::ifstream mail_file{mPathFile, std::fstream::in};
- if( !mail_file.is_open())
- {
- logger::LoggerSet::GetInstance()->LogError( "Unable to open file to read " + mPathFile );
- return {};
- }
- std::string line{};
- manage::MailsSet result;
+ manage::MailsSet Mail::Read() const
+ {
+ std::ifstream mail_file{ mPathFile, std::fstream::in };
+ if ( !mail_file.is_open() )
+ {
+ manage::Logger::LogError( "Unable to open file to read " + mPathFile );
+ return {};
+ }
+ std::string line{};
+ manage::MailsSet result;
- while( std::getline( mail_file, line ))
- {
- auto parsed_data = GetMailFromLine( line );
- if( parsed_data )
+ while ( std::getline( mail_file, line ) )
+ {
+ if( mRegistratorErrors.Check( line ) )
{
- result.push_back( *parsed_data );
+ result.push_back( line );
}
- }
- mail_file.close();
- return result;
- }
-
- bool Mail::Write( manage::MailsSet const& data ) const
- {
- std::ofstream mail_file{mPathFile, std::fstream::out | std::fstream::trunc};
- if( !mail_file.is_open())
- {
- logger::LoggerSet::GetInstance()->LogError( "Unable to open file to write " + mPathFile );
- return false;
- }
- for( const auto& pair: data )
- {
- mail_file << pair << "\n";
- }
- mail_file.close();
- return true;
- }
-
- std::optional < std::string > Mail::GetMailFromLine( std::string const& line ) const
- {
- //TODO registrator if checking parsing
- auto pos = line.find( '@' );
- if( pos == std::string::npos )
- {
- return {};
- }
- return line;
- }
+ }
+ mail_file.close();
+ return result;
+ }
+ bool Mail::Write( manage::MailsSet const& data ) const
+ {
+ std::ofstream mail_file{ mPathFile, std::fstream::out | std::fstream::trunc };
+ if ( !mail_file.is_open() )
+ {
+ manage::Logger::LogError( "Unable to open file to write " + mPathFile );
+ return false;
+ }
+ for( const auto& mail : data )
+ {
+ if( mRegistratorErrors.Check( mail ) )
+ {
+ mail_file << mail << "\n";
+ }
+ }
+ mail_file.close();
+ return true;
+ }
}
diff --git a/src/file/mail.hpp b/src/file/mail.hpp
index 34050bf..148aa11 100644
--- a/src/file/mail.hpp
+++ b/src/file/mail.hpp
@@ -3,22 +3,22 @@
#include <string>
#include <optional>
-#include "managment/general.hpp"
+#include "management/general.hpp"
+#include "checker/registrator_mails.hpp"
namespace smtp::file
{
class Mail
{
public:
- explicit Mail( std::string const& path_file );
+ explicit Mail( std::string const& path_file, checker::RegistratorMails const& registrator_errors );
~Mail() = default;
manage::MailsSet Read() const;
bool Write( manage::MailsSet const& data ) const;
private:
- std::optional<std::string> GetMailFromLine( std::string const& line ) const;
-
std::string mPathFile;
+ checker::RegistratorMails mRegistratorErrors;
};
}
diff --git a/src/file/settings.cpp b/src/file/settings.cpp
index 445cb5e..83f8322 100644
--- a/src/file/settings.cpp
+++ b/src/file/settings.cpp
@@ -5,60 +5,77 @@
namespace smtp::file
{
- Settings::Settings( std::string const& path_file )
- : mPathFile( path_file )
- {
+ //
+ //Constructors
+ //
+ Settings::Settings( std::string const& path_file, checker::RegistratorSettings const& registrator_errors )
+ : mPathFile( path_file )
+ , mRegistratorErrors( registrator_errors )
+ {
- }
+ }
- manage::SettingsFields Settings::Read() const
- {
- auto parsed_store = GetParsedStore();
- return converter::Full{}.Convert( parsed_store );
- }
+ //
+ //Public methods
+ //
+ manage::SettingsFields Settings::Read() const
+ {
+ auto parsed_store = GetParsedStore();
+ return converter::Full{}.Convert( parsed_store );
+ }
- bool Settings::Write( manage::SettingsFields const& settings_fields ) const
- {
- auto parsed_data = converter::Full{}.Convert( settings_fields );
- return SetParsedData( parsed_data );
- }
+ bool Settings::Write( manage::SettingsFields const& settings_fields ) const
+ {
+ auto parsed_data = converter::Full{}.Convert( settings_fields );
+ return mRegistratorErrors.Check( parsed_data ) && SetParsedData( parsed_data );
+ }
+
+ //
+ //Private methods
+ //
+ manage::SettingsFileDataType Settings::GetParsedStore() const
+ {
+ std::ifstream settings_file{ mPathFile, std::fstream::in };
+ if ( !settings_file.is_open() )
+ {
+ manage::Logger::LogError( "Unable to open file to read " + mPathFile );
+ return {};
+ }
+ auto result = GetDataFromFile( settings_file );
- ParsedStoreType Settings::GetParsedStore() const
+ settings_file.close();
+ return mRegistratorErrors.Check(result) ? result : manage::SettingsFileDataType{};
+ }
+
+ manage::SettingsFileDataType Settings::GetDataFromFile( std::ifstream& settings_file ) const
{
- std::ifstream settings_file{mPathFile, std::fstream::in};
- if( !settings_file.is_open())
- {
- logger::LoggerSet::GetInstance()->LogError( "Unable to open file to read " + mPathFile );
- return {};
- }
std::string line{};
- ParsedStoreType result;
+ manage::SettingsFileDataType result;
- while( std::getline( settings_file, line ))
+ while ( std::getline( settings_file, line ) )
{
auto parsed_data = parser::Settings{}.Parse( line );
result.insert( parsed_data );
}
- settings_file.close();
return result;
}
- bool Settings::SetParsedData( ParsedStoreType const& parsed_data ) const
- {
- std::ofstream settings_file{mPathFile, std::fstream::out | std::fstream::trunc};
- if( !settings_file.is_open())
- {
- logger::LoggerSet::GetInstance()->LogError( "Unable to open file to write " + mPathFile );
- return false;
- }
- for( const auto& data: parsed_data )
- {
- auto line = BuildParam( data );
- settings_file << line << "\n";
- }
- settings_file.close();
- return true;
- }
+ bool Settings::SetParsedData( manage::SettingsFileDataType const& parsed_data ) const
+ {
+ std::ofstream settings_file{ mPathFile, std::fstream::out | std::fstream::trunc };
+ if ( !settings_file.is_open() )
+ {
+ manage::Logger::LogError( "Unable to open file to write " + mPathFile );
+ return false;
+ }
+ for( const auto& data : parsed_data )
+ {
+ auto line = BuildParam( data );
+ settings_file << line << "\n";
+ }
+ settings_file.close();
+ return true;
+ }
std::string Settings::BuildParam( std::pair < std::string, std::string > const& data ) const
{
diff --git a/src/file/settings.hpp b/src/file/settings.hpp
index fb77b1e..0882ac3 100644
--- a/src/file/settings.hpp
+++ b/src/file/settings.hpp
@@ -5,26 +5,29 @@
#include "converter/full.hpp"
#include "parser/settings.hpp"
-#include "managment/general.hpp"
+#include "management/general.hpp"
+#include "checker/registrator_settings.hpp"
namespace smtp::file
{
- using ParsedStoreType = std::unordered_map<std::string, std::string>;
-
- class Settings
- {
- public:
- explicit Settings( std::string const& path_file );
- ~Settings() = default;
-
- manage::SettingsFields Read() const;
- bool Write( manage::SettingsFields const& settings_fields ) const;
- private:
- ParsedStoreType GetParsedStore() const;
- bool SetParsedData( ParsedStoreType const& parsed_data ) const;
- std::string BuildParam( std::pair<std::string, std::string> const& data ) const;
-
- std::string mPathFile;
- };
+
+
+ class Settings
+ {
+ public:
+ explicit Settings( std::string const& path_file, checker::RegistratorSettings const& registrator_errors );
+ ~Settings() = default;
+
+ manage::SettingsFields Read() const;
+ bool Write( manage::SettingsFields const& settings_fields ) const;
+ private:
+ manage::SettingsFileDataType GetParsedStore() const;
+ bool SetParsedData( manage::SettingsFileDataType const& parsed_data ) const;
+ std::string BuildParam( std::pair < std::string, std::string > const& data ) const;
+
+ std::string mPathFile;
+ checker::RegistratorSettings mRegistratorErrors;
+ manage::SettingsFileDataType GetDataFromFile( std::ifstream& settings_file ) const;
+ };
}