Leosac  0.8.0
Open Source Access Control
SMTPServerInfoSerializer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
22 #include "tools/JSONUtils.hpp"
23 
24 using namespace Leosac;
25 using namespace Leosac::Module;
26 using namespace Leosac::Module::SMTP;
27 
29  const SecurityContext &)
30 {
31  json server_desc;
32  server_desc["url"] = in.url;
33  server_desc["from"] = in.from;
34  server_desc["username"] = in.username;
35  server_desc["password"] = in.password;
36 
37  server_desc["timeout"] = in.ms_timeout;
38  server_desc["verify_host"] = in.verify_host;
39  server_desc["verify_peer"] = in.verify_peer;
40 
41  server_desc["enabled"] = in.enabled;
42  return server_desc;
43 }
44 
46  const SecurityContext &)
47 {
48  using namespace JSONUtil;
49 
50  out.url = extract_with_default(in, "url", out.url);
51  out.from = extract_with_default(in, "from", out.from);
52  out.username = extract_with_default(in, "username", out.username);
53  out.password = extract_with_default(in, "password", out.password);
54 
55  out.ms_timeout = extract_with_default(in, "timeout", out.ms_timeout);
56  out.verify_peer = extract_with_default(in, "verify_peer", out.verify_peer);
57  out.verify_host = extract_with_default(in, "verify_host", out.verify_host);
58 
59  out.enabled = extract_with_default(in, "enabled", out.enabled);
60 }
61 
63  const SecurityContext &sc)
64 {
65  return SMTPServerInfoJSONSerializer::serialize(in, sc).dump(4);
66 }
67 
69  const std::string &in,
70  const SecurityContext &sc)
71 {
72  return SMTPServerInfoJSONSerializer::unserialize(out, json::parse(in), sc);
73 }
Leosac::Module::SMTP::SMTPServerInfoJSONStringSerializer::serialize
static std::string serialize(const SMTPServerInfo &in, const SecurityContext &sc)
Definition: SMTPServerInfoSerializer.cpp:62
Leosac::Module::SMTP::SMTPServerInfoJSONStringSerializer::unserialize
static void unserialize(SMTPServerInfo &out, const std::string &in, const SecurityContext &sc)
Definition: SMTPServerInfoSerializer.cpp:68
Leosac::JSONUtil::extract_with_default
std::chrono::system_clock::time_point extract_with_default(const nlohmann::json &obj, const std::string &key, const std::chrono::system_clock::time_point &tp)
Extract an ISO 8601 datetime string from a json object.
Definition: JSONUtils.cpp:45
Leosac::Module::SMTP::SMTPServerInfo::url
std::string url
Definition: SMTPConfig.hpp:46
Leosac::Module::SMTP
Definition: SMTPAudit.cpp:32
Leosac::Module::SMTP::SMTPServerInfo::verify_peer
bool verify_peer
Definition: SMTPConfig.hpp:58
Leosac::Module::SMTP::SMTPServerInfo::verify_host
bool verify_host
Definition: SMTPConfig.hpp:57
Leosac::Module
All modules that provides features to Leosac shall be in this namespace.
Leosac::Module::SMTP::SMTPServerInfo::username
std::string username
Definition: SMTPConfig.hpp:48
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
SMTPServerInfoSerializer.hpp
Leosac::Module::SMTP::SMTPServerInfo::enabled
bool enabled
Should this server be used to send email ?
Definition: SMTPConfig.hpp:64
Leosac::Module::SMTP::SMTPServerInfo
Definition: SMTPConfig.hpp:36
JSONUtils.hpp
Leosac::Module::SMTP::json
nlohmann::json json
Definition: SMTPModule.hpp:41
Leosac::Module::SMTP::SMTPServerInfo::ms_timeout
int ms_timeout
Timeout in millisecond for an operation against this server.
Definition: SMTPConfig.hpp:55
Leosac::Module::SMTP::SMTPServerInfoJSONSerializer::unserialize
static void unserialize(SMTPServerInfo &out, const json &in, const SecurityContext &sc)
Definition: SMTPServerInfoSerializer.cpp:45
SMTPConfig.hpp
Leosac::Module::SMTP::SMTPServerInfo::password
std::string password
Definition: SMTPConfig.hpp:49
Leosac::Module::SMTP::SMTPServerInfo::from
std::string from
Definition: SMTPConfig.hpp:47
Leosac::SecurityContext
A SecurityContext is used to query permission while doing an operation.
Definition: SecurityContext.hpp:40
Leosac::Module::SMTP::SMTPServerInfoJSONSerializer::serialize
static json serialize(const SMTPServerInfo &in, const SecurityContext &sc)
Definition: SMTPServerInfoSerializer.cpp:28