comparison Framework/MySQL/MySQLParameters.cpp @ 0:7cea966b6829

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 Jul 2018 08:16:29 +0200
parents
children 1e9bad493475
comparison
equal deleted inserted replaced
-1:000000000000 0:7cea966b6829
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "MySQLParameters.h"
23
24 #include <Core/Logging.h>
25 #include <Core/OrthancException.h>
26
27 namespace OrthancDatabases
28 {
29 void MySQLParameters::Reset()
30 {
31 host_ = "localhost";
32 username_.clear();
33 password_.clear();
34 database_.clear();
35 port_ = 3306;
36 unixSocket_ = "/var/run/mysqld/mysqld.sock";
37 lock_ = true;
38 }
39
40
41 MySQLParameters::MySQLParameters()
42 {
43 Reset();
44 }
45
46
47 MySQLParameters::MySQLParameters(const OrthancPlugins::OrthancConfiguration& configuration)
48 {
49 Reset();
50
51 std::string s;
52 if (configuration.LookupStringValue(s, "Host"))
53 {
54 SetHost(s);
55 }
56
57 if (configuration.LookupStringValue(s, "Username"))
58 {
59 SetUsername(s);
60 }
61
62 if (configuration.LookupStringValue(s, "Password"))
63 {
64 SetPassword(s);
65 }
66
67 if (configuration.LookupStringValue(s, "Database"))
68 {
69 SetDatabase(s);
70 }
71
72 unsigned int port;
73 if (configuration.LookupUnsignedIntegerValue(port, "Port"))
74 {
75 SetPort(port);
76 }
77
78 if (configuration.LookupStringValue(s, "UnixSocket"))
79 {
80 SetUnixSocket(s);
81 }
82
83 lock_ = configuration.GetBooleanValue("Lock", true); // Use locking by default
84 }
85
86
87 void MySQLParameters::SetHost(const std::string& host)
88 {
89 host_ = host;
90 }
91
92
93 void MySQLParameters::SetUsername(const std::string& username)
94 {
95 username_ = username;
96 }
97
98
99 void MySQLParameters::SetPassword(const std::string& password)
100 {
101 password_ = password;
102 }
103
104
105 void MySQLParameters::SetDatabase(const std::string& database)
106 {
107 database_ = database;
108 }
109
110
111 void MySQLParameters::SetPort(unsigned int port)
112 {
113 if (port >= 65535)
114 {
115 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
116 }
117 else
118 {
119 port_ = port;
120 }
121 }
122
123
124 void MySQLParameters::SetUnixSocket(const std::string& socket)
125 {
126 unixSocket_ = socket;
127 }
128 }