comparison Core/WebServiceParameters.h @ 2800:dc7330089736

"OrthancPeers" configuration option now allows to specify HTTP headers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 23 Aug 2018 13:11:48 +0200
parents d67298eec14e
children 807169f85ba9
comparison
equal deleted inserted replaced
2799:6e3a60b85da6 2800:dc7330089736
35 35
36 #if !defined(ORTHANC_SANDBOXED) 36 #if !defined(ORTHANC_SANDBOXED)
37 # error The macro ORTHANC_SANDBOXED must be defined 37 # error The macro ORTHANC_SANDBOXED must be defined
38 #endif 38 #endif
39 39
40 #include <map>
41 #include <set>
40 #include <string> 42 #include <string>
41 #include <json/json.h> 43 #include <json/json.h>
42 44
43 namespace Orthanc 45 namespace Orthanc
44 { 46 {
45 class WebServiceParameters 47 class WebServiceParameters
46 { 48 {
49 public:
50 typedef std::map<std::string, std::string> HttpHeaders;
51
47 private: 52 private:
48 bool advancedFormat_; 53 std::string url_;
49 std::string url_; 54 std::string username_;
50 std::string username_; 55 std::string password_;
51 std::string password_; 56 std::string certificateFile_;
52 std::string certificateFile_; 57 std::string certificateKeyFile_;
53 std::string certificateKeyFile_; 58 std::string certificateKeyPassword_;
54 std::string certificateKeyPassword_; 59 bool pkcs11Enabled_;
55 bool pkcs11Enabled_; 60 HttpHeaders headers_;
56 61
57 void FromJsonArray(const Json::Value& peer); 62 void FromSimpleFormat(const Json::Value& peer);
58 63
59 void FromJsonObject(const Json::Value& peer); 64 void FromAdvancedFormat(const Json::Value& peer);
60 65
61 public: 66 public:
62 WebServiceParameters(); 67 WebServiceParameters();
63 68
64 #if ORTHANC_SANDBOXED == 0 69 WebServiceParameters(const Json::Value& serialized)
65 WebServiceParameters(const Json::Value& serialized); 70 {
66 #endif 71 Unserialize(serialized);
72 }
67 73
68 const std::string& GetUrl() const 74 const std::string& GetUrl() const
69 { 75 {
70 return url_; 76 return url_;
71 } 77 }
72 78
73 void SetUrl(const std::string& url) 79 void SetUrl(const std::string& url);
74 {
75 url_ = url;
76 }
77 80
81 void ClearCredentials();
82
83 void SetCredentials(const std::string& username,
84 const std::string& password);
85
78 const std::string& GetUsername() const 86 const std::string& GetUsername() const
79 { 87 {
80 return username_; 88 return username_;
81 } 89 }
82 90
83 void SetUsername(const std::string& username)
84 {
85 username_ = username;
86 }
87
88 const std::string& GetPassword() const 91 const std::string& GetPassword() const
89 { 92 {
90 return password_; 93 return password_;
91 } 94 }
92 95
93 void SetPassword(const std::string& password)
94 {
95 password_ = password;
96 }
97
98 void ClearClientCertificate(); 96 void ClearClientCertificate();
99 97
100 #if ORTHANC_SANDBOXED == 0
101 void SetClientCertificate(const std::string& certificateFile, 98 void SetClientCertificate(const std::string& certificateFile,
102 const std::string& certificateKeyFile, 99 const std::string& certificateKeyFile,
103 const std::string& certificateKeyPassword); 100 const std::string& certificateKeyPassword);
104 #endif
105 101
106 const std::string& GetCertificateFile() const 102 const std::string& GetCertificateFile() const
107 { 103 {
108 return certificateFile_; 104 return certificateFile_;
109 } 105 }
116 const std::string& GetCertificateKeyPassword() const 112 const std::string& GetCertificateKeyPassword() const
117 { 113 {
118 return certificateKeyPassword_; 114 return certificateKeyPassword_;
119 } 115 }
120 116
121 void SetPkcs11Enabled(bool pkcs11Enabled) 117 void SetPkcs11Enabled(bool enabled)
122 { 118 {
123 pkcs11Enabled_ = pkcs11Enabled; 119 pkcs11Enabled_ = enabled;
124 } 120 }
125 121
126 bool IsPkcs11Enabled() const 122 bool IsPkcs11Enabled() const
127 { 123 {
128 return pkcs11Enabled_; 124 return pkcs11Enabled_;
129 } 125 }
130 126
131 void FromJson(const Json::Value& peer); 127 void AddHttpHeader(const std::string& key,
128 const std::string& value)
129 {
130 headers_[key] = value;
131 }
132 132
133 void ToJson(Json::Value& value, 133 void ClearHttpHeaders()
134 bool includePasswords) const; 134 {
135 headers_.clear();
136 }
135 137
136 void Serialize(Json::Value& target) const; 138 const HttpHeaders& GetHttpHeaders() const
139 {
140 return headers_;
141 }
142
143 void ListHttpHeaders(std::set<std::string>& target) const;
144
145 bool LookupHttpHeader(std::string& value,
146 const std::string& key) const;
147
148 bool IsAdvancedFormatNeeded() const;
149
150 void Unserialize(const Json::Value& peer);
151
152 void Serialize(Json::Value& value,
153 bool forceAdvancedFormat,
154 bool includePasswords) const;
155
156 #if ORTHANC_SANDBOXED == 0
157 void CheckClientCertificate() const;
158 #endif
137 }; 159 };
138 } 160 }