Leosac  0.7.0
OpenSourceAccessControl
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 }
static std::string serialize(const SMTPServerInfo &in, const SecurityContext &sc)
static void unserialize(SMTPServerInfo &out, const std::string &in, const SecurityContext &sc)
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
static void unserialize(SMTPServerInfo &out, const json &in, const SecurityContext &sc)
bool enabled
Should this server be used to send email ?
Definition: SMTPConfig.hpp:64
This is the header file for a generated source file, GitSHA1.cpp.
static json serialize(const SMTPServerInfo &in, const SecurityContext &sc)
All modules that provides features to Leosac shall be in this namespace.
A SecurityContext is used to query permission while doing an operation.
nlohmann::json json
Definition: SMTPModule.hpp:41
int ms_timeout
Timeout in millisecond for an operation against this server.
Definition: SMTPConfig.hpp:55