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-2021 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 Lesser 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  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this program. If not, see
19  * <http://www.gnu.org/licenses/>.
20  **/
21 
22 
23 #pragma once
24 
25 #include "OrthancFramework.h"
26 
27 #if !defined(ORTHANC_SANDBOXED)
28 #  error The macro ORTHANC_SANDBOXED must be defined
29 #endif
30 
31 #include <map>
32 #include <set>
33 #include <stdint.h>
34 #include <string>
35 #include <json/value.h>
36 
37 namespace Orthanc
38 {
39   class ORTHANC_PUBLIC WebServiceParameters
40   {
41   public:
42     typedef std::map<std::string, std::string>  Dictionary;
43 
44   private:
45     std::string  url_;
46     std::string  username_;
47     std::string  password_;
48     std::string  certificateFile_;
49     std::string  certificateKeyFile_;
50     std::string  certificateKeyPassword_;
51     bool         pkcs11Enabled_;
52     Dictionary   headers_;
53     Dictionary   userProperties_;
54     unsigned int timeout_;
55 
56     void FromSimpleFormat(const Json::Value& peer);
57 
58     void FromAdvancedFormat(const Json::Value& peer);
59 
60   public:
61     WebServiceParameters();
62 
63     explicit WebServiceParameters(const Json::Value& serialized);
64 
65     const std::string& GetUrl() const;
66 
67     void SetUrl(const std::string& url);
68 
69     void ClearCredentials();
70 
71     void SetCredentials(const std::string& username,
72                         const std::string& password);
73 
74     const std::string& GetUsername() const;
75 
76     const std::string& GetPassword() const;
77 
78     void ClearClientCertificate();
79 
80     void SetClientCertificate(const std::string& certificateFile,
81                               const std::string& certificateKeyFile,
82                               const std::string& certificateKeyPassword);
83 
84     const std::string& GetCertificateFile() const;
85 
86     const std::string& GetCertificateKeyFile() const;
87 
88     const std::string& GetCertificateKeyPassword() const;
89 
90     void SetPkcs11Enabled(bool enabled);
91 
92     bool IsPkcs11Enabled() const;
93 
94     void AddHttpHeader(const std::string& key,
95                        const std::string& value);
96 
97     void ClearHttpHeaders();
98 
99     const Dictionary& GetHttpHeaders() const;
100 
101     void ListHttpHeaders(std::set<std::string>& target) const;
102 
103     bool LookupHttpHeader(std::string& value,
104                           const std::string& key) const;
105 
106     void AddUserProperty(const std::string& key,
107                          const std::string& value);
108 
109     void ClearUserProperties();
110 
111     const Dictionary& GetUserProperties() const;
112 
113     void ListUserProperties(std::set<std::string>& target) const;
114 
115     bool LookupUserProperty(std::string& value,
116                             const std::string& key) const;
117 
118     bool GetBooleanUserProperty(const std::string& key,
119                                 bool defaultValue) const;
120 
121     bool IsAdvancedFormatNeeded() const;
122 
123     void Unserialize(const Json::Value& peer);
124 
125     void Serialize(Json::Value& value,
126                    bool forceAdvancedFormat,
127                    bool includePasswords) const;
128 
129 #if ORTHANC_SANDBOXED == 0
130     void CheckClientCertificate() const;
131 #endif
132 
133     void FormatPublic(Json::Value& target) const;
134 
135     // Setting it to "0" will use "HttpClient::SetDefaultTimeout()"
136     void SetTimeout(uint32_t seconds);
137 
138     uint32_t GetTimeout() const;
139 
140     bool HasTimeout() const;
141   };
142 }
143