summaryrefslogtreecommitdiff
path: root/src/file
diff options
context:
space:
mode:
Diffstat (limited to 'src/file')
-rw-r--r--src/file/converter/file.cpp87
-rw-r--r--src/file/converter/file.hpp30
-rw-r--r--src/file/converter/full.cpp17
-rw-r--r--src/file/converter/full.hpp25
-rw-r--r--src/file/converter/settings.cpp65
-rw-r--r--src/file/converter/settings.hpp30
-rw-r--r--src/file/mail.cpp11
-rw-r--r--src/file/settings.cpp6
8 files changed, 10 insertions, 261 deletions
diff --git a/src/file/converter/file.cpp b/src/file/converter/file.cpp
deleted file mode 100644
index d0bb032..0000000
--- a/src/file/converter/file.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-#include "file.hpp"
-
-namespace smtp::file::converter
-{
- manage::SettingsFields File::Convert( manage::SettingsFileDataType const& from ) const
- {
- manage::SettingsFields result;
-
- ApplyAuth( result, from );
- ApplySsl( result, from );
- ApplyUsername( result, from );
- ApplyPassword( result, from );
- ApplyHost( result, from );
- ApplyPort( result, from );
-
- return result;
- }
-
- void File::ApplyAuth( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const
- {
- static const std::string FIELD = "need_auth";
-
- ApplyBool(from, FIELD, result.is_need_auth);
- }
-
- void File::ApplySsl( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const
- {
- static const std::string FIELD = "need_ssl";
-
- ApplyBool(from, FIELD, result.is_need_ssl);
- }
-
- void File::ApplyBool( manage::SettingsFileDataType const& from, std::string const& search_field, bool& field ) const
- {
- static const std::string TRUE_AS_STRING = "true";
- static const std::string FALSE_AS_STRING = "false";
-
- auto find = from.find( search_field );
- if( find == from.end() )
- {
- return;
- }
- if( find->second != TRUE_AS_STRING && find->second != FALSE_AS_STRING )
- {
- return;
- }
- field = ( find->second == TRUE_AS_STRING ) ? true : false;
- }
-
- void File::ApplyUsername( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const
- {
- static const std::string FIELD = "username";
-
- ApplyString( from, FIELD, result.username );
- }
-
- void File::ApplyPassword( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const
- {
- static const std::string FIELD = "password";
-
- ApplyString( from, FIELD, result.password );
- }
-
- void File::ApplyHost( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const
- {
- static const std::string FIELD = "host";
-
- ApplyString( from, FIELD, result.host );
- }
-
- void File::ApplyPort( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const
- {
- static const std::string FIELD = "port";
-
- ApplyString(from, FIELD, result.port);
- }
-
- void File::ApplyString( manage::SettingsFileDataType const& from, std::string const& search_field, std::string& field ) const
- {
- auto find = from.find( search_field );
- if( find == from.end() )
- {
- return;
- }
- field = find->second;
- }
-}
diff --git a/src/file/converter/file.hpp b/src/file/converter/file.hpp
deleted file mode 100644
index 63ff6dd..0000000
--- a/src/file/converter/file.hpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma once
-
-#include <unordered_map>
-#include <string>
-
-#include "managment/general.hpp"
-
-namespace smtp::file::converter
-{
- class File
- {
- public:
- File() = default;
- ~File() = default;
-
- manage::SettingsFields Convert( manage::SettingsFileDataType const& from ) const;
- private:
- void ApplyAuth( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const;
- void ApplySsl( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const;
- void ApplyBool( manage::SettingsFileDataType const& from, std::string const& search_field, bool& field ) const;
-
- void ApplyUsername( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const;
- void ApplyPassword( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const;
- void ApplyHost( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const;
- void ApplyPort( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const;
- void ApplyString( manage::SettingsFileDataType const& from, std::string const& search_field, std::string& field ) const;
- };
-}
-
-
diff --git a/src/file/converter/full.cpp b/src/file/converter/full.cpp
deleted file mode 100644
index 61f5a85..0000000
--- a/src/file/converter/full.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "full.hpp"
-#include "file.hpp"
-#include "settings.hpp"
-
-namespace smtp::file::converter
-{
- manage::SettingsFields Full::Convert( ParsedDataType const& from ) const
- {
- return File{}.Convert( from );
- }
-
- std::unordered_map<std::string, std::string> Full::Convert( manage::SettingsFields const& from ) const
- {
- return Settings{}.Convert( from );
-
- }
-}
diff --git a/src/file/converter/full.hpp b/src/file/converter/full.hpp
deleted file mode 100644
index 5ffccd4..0000000
--- a/src/file/converter/full.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-#include <unordered_map>
-#include <string>
-
-#include "managment/general.hpp"
-
-namespace smtp::file::converter
-{
- using ParsedDataType = std::unordered_map<std::string, std::string>;
-
- class Full
- {
- public:
- Full() = default;
- ~Full() = default;
-
- manage::SettingsFields Convert( std::unordered_map<std::string, std::string> const& from ) const;
- std::unordered_map<std::string, std::string> Convert( manage::SettingsFields const& from ) const;
- private:
-
- };
-}
-
-
diff --git a/src/file/converter/settings.cpp b/src/file/converter/settings.cpp
deleted file mode 100644
index 809eef8..0000000
--- a/src/file/converter/settings.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "settings.hpp"
-
-namespace smtp::file::converter
-{
-
- ParsedDataType Settings::Convert( manage::SettingsFields const& from ) const
- {
- ParsedDataType result;
-
- ApplyPort( from, result );
- ApplyHost( from, result );
- ApplyPassword( from, result );
- ApplyUsername( from, result );
- ApplySsl( from, result );
- ApplyAuth( from, result );
-
- return result;
- }
-
- void Settings::ApplyAuth( manage::SettingsFields const& from, ParsedDataType& result ) const
- {
- static const std::string FIELD = "need_auth";
- static const std::string TRUE_AS_STRING = "true";
- static const std::string FALSE_AS_STRING = "false";
-
- from.is_need_auth ? result.insert({FIELD, TRUE_AS_STRING}) : result.insert({FIELD, FALSE_AS_STRING});
- }
-
- void Settings::ApplySsl( manage::SettingsFields const& from, ParsedDataType& result ) const
- {
- static const std::string FIELD = "need_ssl";
- static const std::string TRUE_AS_STRING = "true";
- static const std::string FALSE_AS_STRING = "false";
-
- from.is_need_ssl ? result.insert({FIELD, TRUE_AS_STRING}) : result.insert({FIELD, FALSE_AS_STRING});
- }
-
- void Settings::ApplyUsername( manage::SettingsFields const& from, ParsedDataType& result ) const
- {
- static const std::string FIELD = "username";
-
- result.insert({FIELD, from.username});
- }
-
- void Settings::ApplyPassword( manage::SettingsFields const& from, ParsedDataType& result ) const
- {
- static const std::string FIELD = "password";
-
- result.insert({FIELD, from.password});
- }
-
- void Settings::ApplyHost( manage::SettingsFields const& from, ParsedDataType& result ) const
- {
- static const std::string FIELD = "host";
-
- result.insert({FIELD, from.host});
- }
-
- void Settings::ApplyPort( manage::SettingsFields const& from, ParsedDataType& result ) const
- {
- static const std::string FIELD = "port";
-
- result.insert({FIELD, from.port});
- }
-}
diff --git a/src/file/converter/settings.hpp b/src/file/converter/settings.hpp
deleted file mode 100644
index 8f94942..0000000
--- a/src/file/converter/settings.hpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma once
-
-#include <unordered_map>
-#include <string>
-
-#include "managment/general.hpp"
-
-namespace smtp::file::converter
-{
- using ParsedDataType = std::unordered_map<std::string, std::string>;;
-
- class Settings
- {
- public:
- Settings() = default;
- ~Settings() = default;
-
- std::unordered_map<std::string, std::string> Convert( manage::SettingsFields const& from ) const;
- private:
- void ApplyAuth( manage::SettingsFields const& from, ParsedDataType& result ) const;
- void ApplySsl( manage::SettingsFields const& from, ParsedDataType& result ) const;
-
- void ApplyUsername( manage::SettingsFields const& from, ParsedDataType& result ) const;
- void ApplyPassword( manage::SettingsFields const& from, ParsedDataType& result ) const;
- void ApplyHost( manage::SettingsFields const& from, ParsedDataType& result ) const;
- void ApplyPort( manage::SettingsFields const& from, ParsedDataType& result ) const;
- };
-}
-
-
diff --git a/src/file/mail.cpp b/src/file/mail.cpp
index 4da36c5..1516880 100644
--- a/src/file/mail.cpp
+++ b/src/file/mail.cpp
@@ -7,12 +7,11 @@ namespace smtp::file
Mail::Mail( std::string const& path_file )
: mPathFile( path_file )
{
-
}
manage::MailsSet Mail::Read() const
{
- std::ifstream mail_file{ mPathFile };
+ std::ifstream mail_file{ mPathFile, std::fstream::in };
if ( !mail_file.is_open() )
{
//TODO new file
@@ -29,13 +28,14 @@ namespace smtp::file
result.push_back( *parsed_data );
}
}
+ mail_file.close();
return result;
}
bool Mail::Write( manage::MailsSet const& data ) const
{
- std::ofstream settings_file{ mPathFile };
- if ( !settings_file.is_open() )
+ std::ofstream mail_file{ mPathFile, std::fstream::out | std::fstream::trunc };
+ if ( !mail_file.is_open() )
{
//TODO new file
// std::cerr << "Failed to open pcie_devices database \n";
@@ -43,8 +43,9 @@ namespace smtp::file
}
for( const auto& pair : data )
{
- settings_file << pair << "\n";
+ mail_file << pair << "\n";
}
+ mail_file.close();
return true;
}
diff --git a/src/file/settings.cpp b/src/file/settings.cpp
index 4691fda..df619c9 100644
--- a/src/file/settings.cpp
+++ b/src/file/settings.cpp
@@ -24,7 +24,7 @@ namespace smtp::file
ParsedStoreType Settings::GetParsedStore() const
{
- std::ifstream settings_file{ mPathFile };
+ std::ifstream settings_file{ mPathFile, std::fstream::in };
if ( !settings_file.is_open() )
{
//TODO new file
@@ -38,12 +38,13 @@ namespace smtp::file
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::ofstream settings_file{ mPathFile, std::fstream::out | std::fstream::trunc };
if ( !settings_file.is_open() )
{
//TODO new file
@@ -55,6 +56,7 @@ namespace smtp::file
auto line = BuildParam( data );
settings_file << line << "\n";
}
+ settings_file.close();
return true;
}