Mercurial > hg > orthanc
annotate Core/HttpClient.cpp @ 2789:2a4ac74da1ed
Fix HTTPS requests to sites using a certificate encrypted with ECDSA
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 26 Jul 2018 14:02:20 +0200 |
parents | 959bd8857eb5 |
children | dc7330089736 |
rev | line source |
---|---|
0 | 1 /** |
60
77aec9be0a51
renaming of cppclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
57
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1273
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2270
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
0 | 6 * |
493
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
10 * License, or (at your option) any later version. |
0 | 11 * |
493
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
13 * program give permission to link the code of its release with the |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
22 * in the program, then also delete it here. |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
23 * |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
27 * General Public License for more details. |
0 | 28 * |
493
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 31 **/ |
32 | |
33 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
34 #include "PrecompiledHeaders.h" |
0 | 35 #include "HttpClient.h" |
36 | |
1404 | 37 #include "Toolbox.h" |
38 #include "OrthancException.h" | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
39 #include "Logging.h" |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
40 #include "ChunkedBuffer.h" |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
41 #include "SystemToolbox.h" |
475
72cca077abf8
removal of HttpException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
473
diff
changeset
|
42 |
0 | 43 #include <string.h> |
44 #include <curl/curl.h> | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
45 #include <boost/algorithm/string/predicate.hpp> |
1989 | 46 #include <boost/thread/mutex.hpp> |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
47 |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
48 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
49 #if ORTHANC_ENABLE_PKCS11 == 1 |
2025 | 50 # include "Pkcs11.h" |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
51 #endif |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
52 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
53 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
54 extern "C" |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
55 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
56 static CURLcode GetHttpStatus(CURLcode code, CURL* curl, long* status) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
57 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
58 if (code == CURLE_OK) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
59 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
60 code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
61 return code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
62 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
63 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
64 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
65 *status = 0; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
66 return code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
67 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
68 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
69 |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
70 // This is a dummy wrapper function to suppress any OpenSSL-related |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
71 // problem in valgrind. Inlining is prevented. |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
72 #if defined(__GNUC__) || defined(__clang__) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
73 __attribute__((noinline)) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
74 #endif |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
75 static CURLcode OrthancHttpClientPerformSSL(CURL* curl, long* status) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
76 { |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
77 #if ORTHANC_ENABLE_SSL == 1 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
78 return GetHttpStatus(curl_easy_perform(curl), curl, status); |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
79 #else |
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
80 LOG(ERROR) << "Orthanc was compiled without SSL support, cannot make HTTPS request"; |
2474 | 81 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
82 #endif |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
83 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
84 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
85 |
0 | 86 |
87 | |
60
77aec9be0a51
renaming of cppclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
57
diff
changeset
|
88 namespace Orthanc |
0 | 89 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
90 class HttpClient::GlobalParameters |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
91 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
92 private: |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
93 boost::mutex mutex_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
94 bool httpsVerifyPeers_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
95 std::string httpsCACertificates_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
96 std::string proxy_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
97 long timeout_; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
98 bool verbose_; |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
99 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
100 GlobalParameters() : |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
101 httpsVerifyPeers_(true), |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
102 timeout_(0), |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
103 verbose_(false) |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
104 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
105 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
106 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
107 public: |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
108 // Singleton pattern |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
109 static GlobalParameters& GetInstance() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
110 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
111 static GlobalParameters parameters; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
112 return parameters; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
113 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
114 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
115 void ConfigureSsl(bool httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
116 const std::string& httpsCACertificates) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
117 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
118 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
119 httpsVerifyPeers_ = httpsVerifyPeers; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
120 httpsCACertificates_ = httpsCACertificates; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
121 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
122 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
123 void GetSslConfiguration(bool& httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
124 std::string& httpsCACertificates) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
125 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
126 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
127 httpsVerifyPeers = httpsVerifyPeers_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
128 httpsCACertificates = httpsCACertificates_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
129 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
130 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
131 void SetDefaultProxy(const std::string& proxy) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
132 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
133 LOG(INFO) << "Setting the default proxy for HTTP client connections: " << proxy; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
134 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
135 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
136 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
137 proxy_ = proxy; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
138 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
139 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
140 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
141 void GetDefaultProxy(std::string& target) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
142 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
143 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
144 target = proxy_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
145 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
146 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
147 void SetDefaultTimeout(long seconds) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
148 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
149 LOG(INFO) << "Setting the default timeout for HTTP client connections: " << seconds << " seconds"; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
150 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
151 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
152 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
153 timeout_ = seconds; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
154 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
155 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
156 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
157 long GetDefaultTimeout() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
158 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
159 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
160 return timeout_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
161 } |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
162 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
163 #if ORTHANC_ENABLE_PKCS11 == 1 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
164 bool IsPkcs11Initialized() |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
165 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
166 boost::mutex::scoped_lock lock(mutex_); |
2025 | 167 return Pkcs11::IsInitialized(); |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
168 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
169 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
170 void InitializePkcs11(const std::string& module, |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
171 const std::string& pin, |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
172 bool verbose) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
173 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
174 boost::mutex::scoped_lock lock(mutex_); |
2025 | 175 Pkcs11::Initialize(module, pin, verbose); |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
176 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
177 #endif |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
178 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
179 bool IsDefaultVerbose() const |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
180 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
181 return verbose_; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
182 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
183 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
184 void SetDefaultVerbose(bool verbose) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
185 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
186 verbose_ = verbose; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
187 } |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
188 }; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
189 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
190 |
0 | 191 struct HttpClient::PImpl |
192 { | |
193 CURL* curl_; | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
194 struct curl_slist *defaultPostHeaders_; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
195 struct curl_slist *userHeaders_; |
0 | 196 }; |
197 | |
198 | |
2787
ad2c32082653
Fix OrthancPluginHttpClient() to return the HTTP status on errors
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2677
diff
changeset
|
199 void HttpClient::ThrowException(HttpStatus status) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
200 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
201 switch (status) |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
202 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
203 case HttpStatus_400_BadRequest: |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
204 throw OrthancException(ErrorCode_BadRequest); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
205 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
206 case HttpStatus_401_Unauthorized: |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
207 case HttpStatus_403_Forbidden: |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
208 throw OrthancException(ErrorCode_Unauthorized); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
209 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
210 case HttpStatus_404_NotFound: |
2044 | 211 throw OrthancException(ErrorCode_UnknownResource); |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
212 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
213 default: |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
214 throw OrthancException(ErrorCode_NetworkProtocol); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
215 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
216 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
217 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
218 |
0 | 219 static CURLcode CheckCode(CURLcode code) |
220 { | |
2025 | 221 if (code == CURLE_NOT_BUILT_IN) |
222 { | |
223 LOG(ERROR) << "Your libcurl does not contain a required feature, " | |
224 << "please recompile Orthanc with -DUSE_SYSTEM_CURL=OFF"; | |
225 throw OrthancException(ErrorCode_InternalError); | |
226 } | |
227 | |
0 | 228 if (code != CURLE_OK) |
229 { | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
230 LOG(ERROR) << "libCURL error: " + std::string(curl_easy_strerror(code)); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
231 throw OrthancException(ErrorCode_NetworkProtocol); |
0 | 232 } |
233 | |
234 return code; | |
235 } | |
236 | |
237 | |
2023 | 238 static size_t CurlBodyCallback(void *buffer, size_t size, size_t nmemb, void *payload) |
0 | 239 { |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
240 ChunkedBuffer& target = *(static_cast<ChunkedBuffer*>(payload)); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
241 |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
242 size_t length = size * nmemb; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
243 if (length == 0) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
244 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
245 return 0; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
246 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
247 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
248 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
249 target.AddChunk(buffer, length); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
250 return length; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
251 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
252 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
253 |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
254 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
255 /*static int CurlDebugCallback(CURL *handle, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
256 curl_infotype type, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
257 char *data, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
258 size_t size, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
259 void *userptr) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
260 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
261 switch (type) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
262 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
263 case CURLINFO_TEXT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
264 case CURLINFO_HEADER_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
265 case CURLINFO_HEADER_OUT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
266 case CURLINFO_SSL_DATA_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
267 case CURLINFO_SSL_DATA_OUT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
268 case CURLINFO_END: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
269 case CURLINFO_DATA_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
270 case CURLINFO_DATA_OUT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
271 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
272 std::string s(data, size); |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
273 LOG(INFO) << "libcurl: " << s; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
274 break; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
275 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
276 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
277 default: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
278 break; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
279 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
280 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
281 return 0; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
282 }*/ |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
283 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
284 |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
285 struct CurlHeaderParameters |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
286 { |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
287 bool lowerCase_; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
288 HttpClient::HttpHeaders* headers_; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
289 }; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
290 |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
291 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
292 static size_t CurlHeaderCallback(void *buffer, size_t size, size_t nmemb, void *payload) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
293 { |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
294 CurlHeaderParameters& parameters = *(static_cast<CurlHeaderParameters*>(payload)); |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
295 assert(parameters.headers_ != NULL); |
0 | 296 |
297 size_t length = size * nmemb; | |
298 if (length == 0) | |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
299 { |
0 | 300 return 0; |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
301 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
302 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
303 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
304 std::string s(reinterpret_cast<const char*>(buffer), length); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
305 std::size_t colon = s.find(':'); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
306 std::size_t eol = s.find("\r\n"); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
307 if (colon != std::string::npos && |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
308 eol != std::string::npos) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
309 { |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
310 std::string tmp(s.substr(0, colon)); |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
311 |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
312 if (parameters.lowerCase_) |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
313 { |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
314 Toolbox::ToLowerCase(tmp); |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
315 } |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
316 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
317 std::string key = Toolbox::StripSpaces(tmp); |
0 | 318 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
319 if (!key.empty()) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
320 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
321 std::string value = Toolbox::StripSpaces(s.substr(colon + 1, eol)); |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
322 (*parameters.headers_) [key] = value; |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
323 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
324 } |
0 | 325 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
326 return length; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
327 } |
0 | 328 } |
329 | |
330 | |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
331 void HttpClient::Setup() |
0 | 332 { |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
333 pimpl_->userHeaders_ = NULL; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
334 pimpl_->defaultPostHeaders_ = NULL; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
335 if ((pimpl_->defaultPostHeaders_ = curl_slist_append(pimpl_->defaultPostHeaders_, "Expect:")) == NULL) |
0 | 336 { |
475
72cca077abf8
removal of HttpException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
473
diff
changeset
|
337 throw OrthancException(ErrorCode_NotEnoughMemory); |
0 | 338 } |
339 | |
340 pimpl_->curl_ = curl_easy_init(); | |
341 if (!pimpl_->curl_) | |
342 { | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
343 curl_slist_free_all(pimpl_->defaultPostHeaders_); |
475
72cca077abf8
removal of HttpException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
473
diff
changeset
|
344 throw OrthancException(ErrorCode_NotEnoughMemory); |
0 | 345 } |
346 | |
2023 | 347 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEFUNCTION, &CurlBodyCallback)); |
0 | 348 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADER, 0)); |
349 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1)); | |
350 | |
456 | 351 // This fixes the "longjmp causes uninitialized stack frame" crash |
352 // that happens on modern Linux versions. | |
353 // http://stackoverflow.com/questions/9191668/error-longjmp-causes-uninitialized-stack-frame | |
354 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1)); | |
355 | |
0 | 356 url_ = ""; |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
357 method_ = HttpMethod_Get; |
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
358 lastStatus_ = HttpStatus_200_Ok; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
359 SetVerbose(GlobalParameters::GetInstance().IsDefaultVerbose()); |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
360 timeout_ = GlobalParameters::GetInstance().GetDefaultTimeout(); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
361 GlobalParameters::GetInstance().GetDefaultProxy(proxy_); |
2219
262fcab24024
fix for HttpsCACertificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
362 GlobalParameters::GetInstance().GetSslConfiguration(verifyPeers_, caCertificates_); |
0 | 363 } |
364 | |
365 | |
2020 | 366 HttpClient::HttpClient() : |
367 pimpl_(new PImpl), | |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
368 verifyPeers_(true), |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
369 pkcs11Enabled_(false), |
2107 | 370 headersToLowerCase_(true), |
371 redirectionFollowed_(true) | |
2020 | 372 { |
373 Setup(); | |
374 } | |
375 | |
376 | |
377 HttpClient::HttpClient(const WebServiceParameters& service, | |
378 const std::string& uri) : | |
379 pimpl_(new PImpl), | |
2049 | 380 verifyPeers_(true), |
2107 | 381 headersToLowerCase_(true), |
382 redirectionFollowed_(true) | |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
383 { |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
384 Setup(); |
2020 | 385 |
386 if (service.GetUsername().size() != 0 && | |
387 service.GetPassword().size() != 0) | |
388 { | |
389 SetCredentials(service.GetUsername().c_str(), | |
390 service.GetPassword().c_str()); | |
391 } | |
392 | |
393 if (!service.GetCertificateFile().empty()) | |
394 { | |
395 SetClientCertificate(service.GetCertificateFile(), | |
396 service.GetCertificateKeyFile(), | |
397 service.GetCertificateKeyPassword()); | |
398 } | |
399 | |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
400 SetPkcs11Enabled(service.IsPkcs11Enabled()); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
401 |
2020 | 402 SetUrl(service.GetUrl() + uri); |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
403 } |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
404 |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
405 |
0 | 406 HttpClient::~HttpClient() |
407 { | |
408 curl_easy_cleanup(pimpl_->curl_); | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
409 curl_slist_free_all(pimpl_->defaultPostHeaders_); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
410 ClearHeaders(); |
0 | 411 } |
412 | |
413 | |
414 void HttpClient::SetVerbose(bool isVerbose) | |
415 { | |
416 isVerbose_ = isVerbose; | |
417 | |
418 if (isVerbose_) | |
419 { | |
420 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 1)); | |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
421 //CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_DEBUGFUNCTION, &CurlDebugCallback)); |
0 | 422 } |
423 else | |
424 { | |
425 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 0)); | |
426 } | |
427 } | |
428 | |
429 | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
430 void HttpClient::AddHeader(const std::string& key, |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
431 const std::string& value) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
432 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
433 if (key.empty()) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
434 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
435 throw OrthancException(ErrorCode_ParameterOutOfRange); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
436 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
437 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
438 std::string s = key + ": " + value; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
439 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
440 if ((pimpl_->userHeaders_ = curl_slist_append(pimpl_->userHeaders_, s.c_str())) == NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
441 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
442 throw OrthancException(ErrorCode_NotEnoughMemory); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
443 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
444 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
445 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
446 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
447 void HttpClient::ClearHeaders() |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
448 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
449 if (pimpl_->userHeaders_ != NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
450 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
451 curl_slist_free_all(pimpl_->userHeaders_); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
452 pimpl_->userHeaders_ = NULL; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
453 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
454 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
455 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
456 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
457 bool HttpClient::ApplyInternal(std::string& answerBody, |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
458 HttpHeaders* answerHeaders) |
0 | 459 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
460 answerBody.clear(); |
0 | 461 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str())); |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
462 |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
463 CurlHeaderParameters headerParameters; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
464 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
465 if (answerHeaders == NULL) |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
466 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
467 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, NULL)); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
468 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, NULL)); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
469 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
470 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
471 { |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
472 headerParameters.lowerCase_ = headersToLowerCase_; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
473 headerParameters.headers_ = answerHeaders; |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
474 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, &CurlHeaderCallback)); |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
475 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, &headerParameters)); |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
476 } |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
477 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
478 #if ORTHANC_ENABLE_SSL == 1 |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
479 // Setup HTTPS-related options |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
480 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
481 if (verifyPeers_) |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
482 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
483 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CAINFO, caCertificates_.c_str())); |
1973
7bd4cb780feb
Option "HttpsVerifyPeers" can be used to connect against self-signed HTTPS certificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
484 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYHOST, 2)); // libcurl default is strict verifyhost |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
485 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYPEER, 1)); |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
486 } |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
487 else |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
488 { |
1973
7bd4cb780feb
Option "HttpsVerifyPeers" can be used to connect against self-signed HTTPS certificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
489 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYHOST, 0)); |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
490 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYPEER, 0)); |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
491 } |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
492 #endif |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
493 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
494 // Setup the HTTPS client certificate |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
495 if (!clientCertificateFile_.empty() && |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
496 pkcs11Enabled_) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
497 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
498 LOG(ERROR) << "Cannot enable both client certificates and PKCS#11 authentication"; |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
499 throw OrthancException(ErrorCode_ParameterOutOfRange); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
500 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
501 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
502 if (pkcs11Enabled_) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
503 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
504 #if ORTHANC_ENABLE_PKCS11 == 1 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
505 if (GlobalParameters::GetInstance().IsPkcs11Initialized()) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
506 { |
2025 | 507 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLENGINE, Pkcs11::GetEngineIdentifier())); |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
508 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLKEYTYPE, "ENG")); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
509 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLCERTTYPE, "ENG")); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
510 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
511 else |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
512 { |
2025 | 513 LOG(ERROR) << "Cannot use PKCS#11 for a HTTPS request, because it has not been initialized"; |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
514 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
515 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
516 #else |
2025 | 517 LOG(ERROR) << "This version of Orthanc is compiled without support for PKCS#11"; |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
518 throw OrthancException(ErrorCode_InternalError); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
519 #endif |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
520 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
521 else if (!clientCertificateFile_.empty()) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
522 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
523 #if ORTHANC_ENABLE_SSL == 1 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
524 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLCERTTYPE, "PEM")); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
525 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLCERT, clientCertificateFile_.c_str())); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
526 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
527 if (!clientCertificateKeyPassword_.empty()) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
528 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
529 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_KEYPASSWD, clientCertificateKeyPassword_.c_str())); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
530 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
531 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
532 // NB: If no "clientKeyFile_" is provided, the key must be |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
533 // prepended to the certificate file |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
534 if (!clientCertificateKeyFile_.empty()) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
535 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
536 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLKEYTYPE, "PEM")); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
537 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLKEY, clientCertificateKeyFile_.c_str())); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
538 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
539 #else |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
540 LOG(ERROR) << "This version of Orthanc is compiled without OpenSSL support, cannot use HTTPS client authentication"; |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
541 throw OrthancException(ErrorCode_InternalError); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
542 #endif |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
543 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
544 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
545 // Reset the parameters from previous calls to Apply() |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
546 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->userHeaders_)); |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
547 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
548 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
549 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
550 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, NULL)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
551 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, NULL)); |
2104
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
552 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0L)); |
1273
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
553 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PROXY, NULL)); |
0 | 554 |
2104
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
555 if (redirectionFollowed_) |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
556 { |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
557 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1L)); |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
558 } |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
559 else |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
560 { |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
561 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 0L)); |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
562 } |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
563 |
1186
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
564 // Set timeouts |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
565 if (timeout_ <= 0) |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
566 { |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
567 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_TIMEOUT, 10)); /* default: 10 seconds */ |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
568 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CONNECTTIMEOUT, 10)); /* default: 10 seconds */ |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
569 } |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
570 else |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
571 { |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
572 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_TIMEOUT, timeout_)); |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
573 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CONNECTTIMEOUT, timeout_)); |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
574 } |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
575 |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
576 if (credentials_.size() != 0) |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
577 { |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
578 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_USERPWD, credentials_.c_str())); |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
579 } |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
580 |
1273
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
581 if (proxy_.size() != 0) |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
582 { |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
583 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PROXY, proxy_.c_str())); |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
584 } |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
585 |
0 | 586 switch (method_) |
587 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
588 case HttpMethod_Get: |
0 | 589 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); |
590 break; | |
591 | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
592 case HttpMethod_Post: |
0 | 593 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
594 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
595 if (pimpl_->userHeaders_ == NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
596 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
597 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->defaultPostHeaders_)); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
598 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
599 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
600 break; |
0 | 601 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
602 case HttpMethod_Delete: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
603 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
604 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
605 break; |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
606 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
607 case HttpMethod_Put: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
608 // http://stackoverflow.com/a/7570281/881731: Don't use |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
609 // CURLOPT_PUT if there is a body |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
610 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
611 // CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
612 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
613 curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "PUT"); /* !!! */ |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
614 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
615 if (pimpl_->userHeaders_ == NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
616 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
617 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->defaultPostHeaders_)); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
618 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
619 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
620 break; |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
621 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
622 default: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
623 throw OrthancException(ErrorCode_InternalError); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
624 } |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
625 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
626 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
627 if (method_ == HttpMethod_Post || |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
628 method_ == HttpMethod_Put) |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
629 { |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
630 if (body_.size() > 0) |
0 | 631 { |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
632 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, body_.c_str())); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
633 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, body_.size())); |
0 | 634 } |
635 else | |
636 { | |
637 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, NULL)); | |
638 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0)); | |
639 } | |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
640 } |
0 | 641 |
642 | |
643 // Do the actual request | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
644 CURLcode code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
645 long status = 0; |
0 | 646 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
647 ChunkedBuffer buffer; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
648 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEDATA, &buffer)); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
649 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
650 if (boost::starts_with(url_, "https://")) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
651 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
652 code = OrthancHttpClientPerformSSL(pimpl_->curl_, &status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
653 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
654 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
655 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
656 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
657 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
658 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
659 LOG(INFO) << "HTTP status code " << status << " after " |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
660 << EnumerationToString(method_) << " request on: " << url_; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
661 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
662 if (isVerbose_) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
663 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
664 LOG(INFO) << "cURL status code: " << code; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
665 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
666 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
667 CheckCode(code); |
0 | 668 |
669 if (status == 0) | |
670 { | |
671 // This corresponds to a call to an inexistent host | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
672 lastStatus_ = HttpStatus_500_InternalServerError; |
0 | 673 } |
674 else | |
675 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
676 lastStatus_ = static_cast<HttpStatus>(status); |
0 | 677 } |
678 | |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
679 bool success = (status >= 200 && status < 300); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
680 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
681 if (success) |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
682 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
683 buffer.Flatten(answerBody); |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
684 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
685 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
686 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
687 answerBody.clear(); |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
688 LOG(INFO) << "Error in HTTP request, received HTTP status " << status |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
689 << " (" << EnumerationToString(lastStatus_) << ")"; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
690 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
691 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
692 return success; |
0 | 693 } |
694 | |
695 | |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
696 bool HttpClient::ApplyInternal(Json::Value& answerBody, |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
697 HttpClient::HttpHeaders* answerHeaders) |
0 | 698 { |
699 std::string s; | |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
700 if (ApplyInternal(s, answerHeaders)) |
0 | 701 { |
702 Json::Reader reader; | |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
703 return reader.parse(s, answerBody); |
0 | 704 } |
705 else | |
706 { | |
707 return false; | |
708 } | |
709 } | |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
710 |
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
711 |
468
456b9d2e9af4
rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
712 void HttpClient::SetCredentials(const char* username, |
456b9d2e9af4
rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
713 const char* password) |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
714 { |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
715 credentials_ = std::string(username) + ":" + std::string(password); |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
716 } |
457 | 717 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
718 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
719 void HttpClient::ConfigureSsl(bool httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
720 const std::string& httpsVerifyCertificates) |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
721 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
722 #if ORTHANC_ENABLE_SSL == 1 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
723 if (httpsVerifyPeers) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
724 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
725 if (httpsVerifyCertificates.empty()) |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
726 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
727 LOG(WARNING) << "No certificates are provided to validate peers, " |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
728 << "set \"HttpsCACertificates\" if you need to do HTTPS requests"; |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
729 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
730 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
731 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
732 LOG(WARNING) << "HTTPS will use the CA certificates from this file: " << httpsVerifyCertificates; |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
733 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
734 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
735 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
736 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
737 LOG(WARNING) << "The verification of the peers in HTTPS requests is disabled"; |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
738 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
739 #endif |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
740 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
741 GlobalParameters::GetInstance().ConfigureSsl(httpsVerifyPeers, httpsVerifyCertificates); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
742 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
743 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
744 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
745 void HttpClient::GlobalInitialize() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
746 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
747 #if ORTHANC_ENABLE_SSL == 1 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
748 CheckCode(curl_global_init(CURL_GLOBAL_ALL)); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
749 #else |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
750 CheckCode(curl_global_init(CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL)); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
751 #endif |
457 | 752 } |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
753 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
754 |
457 | 755 void HttpClient::GlobalFinalize() |
756 { | |
757 curl_global_cleanup(); | |
2025 | 758 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
759 #if ORTHANC_ENABLE_PKCS11 == 1 |
2025 | 760 Pkcs11::Finalize(); |
761 #endif | |
457 | 762 } |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
763 |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
764 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
765 void HttpClient::SetDefaultVerbose(bool verbose) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
766 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
767 GlobalParameters::GetInstance().SetDefaultVerbose(verbose); |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
768 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
769 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
770 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
771 void HttpClient::SetDefaultProxy(const std::string& proxy) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
772 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
773 GlobalParameters::GetInstance().SetDefaultProxy(proxy); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
774 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
775 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
776 |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
777 void HttpClient::SetDefaultTimeout(long timeout) |
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
778 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
779 GlobalParameters::GetInstance().SetDefaultTimeout(timeout); |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
780 } |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
781 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
782 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
783 void HttpClient::ApplyAndThrowException(std::string& answerBody) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
784 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
785 if (!Apply(answerBody)) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
786 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
787 ThrowException(GetLastStatus()); |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
788 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
789 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
790 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
791 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
792 void HttpClient::ApplyAndThrowException(Json::Value& answerBody) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
793 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
794 if (!Apply(answerBody)) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
795 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
796 ThrowException(GetLastStatus()); |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
797 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
798 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
799 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
800 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
801 void HttpClient::ApplyAndThrowException(std::string& answerBody, |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
802 HttpHeaders& answerHeaders) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
803 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
804 if (!Apply(answerBody, answerHeaders)) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
805 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
806 ThrowException(GetLastStatus()); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
807 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
808 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
809 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
810 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
811 void HttpClient::ApplyAndThrowException(Json::Value& answerBody, |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
812 HttpHeaders& answerHeaders) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
813 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
814 if (!Apply(answerBody, answerHeaders)) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
815 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
816 ThrowException(GetLastStatus()); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
817 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
818 } |
2019
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
819 |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
820 |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
821 void HttpClient::SetClientCertificate(const std::string& certificateFile, |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
822 const std::string& certificateKeyFile, |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
823 const std::string& certificateKeyPassword) |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
824 { |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
825 if (certificateFile.empty()) |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
826 { |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
827 throw OrthancException(ErrorCode_ParameterOutOfRange); |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
828 } |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
829 |
2140 | 830 if (!SystemToolbox::IsRegularFile(certificateFile)) |
2019
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
831 { |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
832 LOG(ERROR) << "Cannot open certificate file: " << certificateFile; |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
833 throw OrthancException(ErrorCode_InexistentFile); |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
834 } |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
835 |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
836 if (!certificateKeyFile.empty() && |
2140 | 837 !SystemToolbox::IsRegularFile(certificateKeyFile)) |
2019
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
838 { |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
839 LOG(ERROR) << "Cannot open key file: " << certificateKeyFile; |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
840 throw OrthancException(ErrorCode_InexistentFile); |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
841 } |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
842 |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
843 clientCertificateFile_ = certificateFile; |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
844 clientCertificateKeyFile_ = certificateKeyFile; |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
845 clientCertificateKeyPassword_ = certificateKeyPassword; |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
846 } |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
847 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
848 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
849 void HttpClient::InitializePkcs11(const std::string& module, |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
850 const std::string& pin, |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
851 bool verbose) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
852 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
853 #if ORTHANC_ENABLE_PKCS11 == 1 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
854 LOG(INFO) << "Initializing PKCS#11 using " << module |
2024 | 855 << (pin.empty() ? " (no PIN provided)" : " (PIN is provided)"); |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
856 GlobalParameters::GetInstance().InitializePkcs11(module, pin, verbose); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
857 #else |
2025 | 858 LOG(ERROR) << "This version of Orthanc is compiled without support for PKCS#11"; |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
859 throw OrthancException(ErrorCode_InternalError); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
860 #endif |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
861 } |
0 | 862 } |