Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/Core/WebServiceParameters.h Wed Aug 22 16:55:07 2018 +0200 +++ b/Core/WebServiceParameters.h Thu Aug 23 13:11:48 2018 +0200 @@ -37,6 +37,8 @@ # error The macro ORTHANC_SANDBOXED must be defined #endif +#include <map> +#include <set> #include <string> #include <json/json.h> @@ -44,64 +46,58 @@ { class WebServiceParameters { + public: + typedef std::map<std::string, std::string> HttpHeaders; + private: - bool advancedFormat_; - std::string url_; - std::string username_; - std::string password_; - std::string certificateFile_; - std::string certificateKeyFile_; - std::string certificateKeyPassword_; - bool pkcs11Enabled_; + std::string url_; + std::string username_; + std::string password_; + std::string certificateFile_; + std::string certificateKeyFile_; + std::string certificateKeyPassword_; + bool pkcs11Enabled_; + HttpHeaders headers_; - void FromJsonArray(const Json::Value& peer); + void FromSimpleFormat(const Json::Value& peer); - void FromJsonObject(const Json::Value& peer); + void FromAdvancedFormat(const Json::Value& peer); public: WebServiceParameters(); -#if ORTHANC_SANDBOXED == 0 - WebServiceParameters(const Json::Value& serialized); -#endif + WebServiceParameters(const Json::Value& serialized) + { + Unserialize(serialized); + } const std::string& GetUrl() const { return url_; } - void SetUrl(const std::string& url) - { - url_ = url; - } + void SetUrl(const std::string& url); + + void ClearCredentials(); + void SetCredentials(const std::string& username, + const std::string& password); + const std::string& GetUsername() const { return username_; } - void SetUsername(const std::string& username) - { - username_ = username; - } - const std::string& GetPassword() const { return password_; } - void SetPassword(const std::string& password) - { - password_ = password; - } - void ClearClientCertificate(); -#if ORTHANC_SANDBOXED == 0 void SetClientCertificate(const std::string& certificateFile, const std::string& certificateKeyFile, const std::string& certificateKeyPassword); -#endif const std::string& GetCertificateFile() const { @@ -118,9 +114,9 @@ return certificateKeyPassword_; } - void SetPkcs11Enabled(bool pkcs11Enabled) + void SetPkcs11Enabled(bool enabled) { - pkcs11Enabled_ = pkcs11Enabled; + pkcs11Enabled_ = enabled; } bool IsPkcs11Enabled() const @@ -128,11 +124,37 @@ return pkcs11Enabled_; } - void FromJson(const Json::Value& peer); + void AddHttpHeader(const std::string& key, + const std::string& value) + { + headers_[key] = value; + } + + void ClearHttpHeaders() + { + headers_.clear(); + } + + const HttpHeaders& GetHttpHeaders() const + { + return headers_; + } - void ToJson(Json::Value& value, - bool includePasswords) const; + void ListHttpHeaders(std::set<std::string>& target) const; + + bool LookupHttpHeader(std::string& value, + const std::string& key) const; + + bool IsAdvancedFormatNeeded() const; - void Serialize(Json::Value& target) const; + void Unserialize(const Json::Value& peer); + + void Serialize(Json::Value& value, + bool forceAdvancedFormat, + bool includePasswords) const; + +#if ORTHANC_SANDBOXED == 0 + void CheckClientCertificate() const; +#endif }; }