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-2020 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 <string> 34 #include <json/json.h> 35 36 namespace Orthanc 37 { 38 class ORTHANC_PUBLIC WebServiceParameters 39 { 40 public: 41 typedef std::map<std::string, std::string> Dictionary; 42 43 private: 44 std::string url_; 45 std::string username_; 46 std::string password_; 47 std::string certificateFile_; 48 std::string certificateKeyFile_; 49 std::string certificateKeyPassword_; 50 bool pkcs11Enabled_; 51 Dictionary headers_; 52 Dictionary userProperties_; 53 54 void FromSimpleFormat(const Json::Value& peer); 55 56 void FromAdvancedFormat(const Json::Value& peer); 57 58 public: 59 WebServiceParameters(); 60 61 explicit WebServiceParameters(const Json::Value& serialized); 62 63 const std::string& GetUrl() const; 64 65 void SetUrl(const std::string& url); 66 67 void ClearCredentials(); 68 69 void SetCredentials(const std::string& username, 70 const std::string& password); 71 72 const std::string& GetUsername() const; 73 74 const std::string& GetPassword() const; 75 76 void ClearClientCertificate(); 77 78 void SetClientCertificate(const std::string& certificateFile, 79 const std::string& certificateKeyFile, 80 const std::string& certificateKeyPassword); 81 82 const std::string& GetCertificateFile() const; 83 84 const std::string& GetCertificateKeyFile() const; 85 86 const std::string& GetCertificateKeyPassword() const; 87 88 void SetPkcs11Enabled(bool enabled); 89 90 bool IsPkcs11Enabled() const; 91 92 void AddHttpHeader(const std::string& key, 93 const std::string& value); 94 95 void ClearHttpHeaders(); 96 97 const Dictionary& GetHttpHeaders() const; 98 99 void ListHttpHeaders(std::set<std::string>& target) const; 100 101 bool LookupHttpHeader(std::string& value, 102 const std::string& key) const; 103 104 void AddUserProperty(const std::string& key, 105 const std::string& value); 106 107 void ClearUserProperties(); 108 109 const Dictionary& GetUserProperties() const; 110 111 void ListUserProperties(std::set<std::string>& target) const; 112 113 bool LookupUserProperty(std::string& value, 114 const std::string& key) const; 115 116 bool GetBooleanUserProperty(const std::string& key, 117 bool defaultValue) const; 118 119 bool IsAdvancedFormatNeeded() const; 120 121 void Unserialize(const Json::Value& peer); 122 123 void Serialize(Json::Value& value, 124 bool forceAdvancedFormat, 125 bool includePasswords) const; 126 127 #if ORTHANC_SANDBOXED == 0 128 void CheckClientCertificate() const; 129 #endif 130 131 void FormatPublic(Json::Value& target) const; 132 }; 133 } 134