Mercurial > hg > orthanc
annotate Core/HttpClient.cpp @ 3001:7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Dec 2018 18:36:38 +0100 |
parents | d924f9bb61cc |
children | 4e43e67f8ecf |
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 |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
80 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
81 "Orthanc was compiled without SSL support, " |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
82 "cannot make HTTPS request"); |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
83 #endif |
1533
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 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
86 |
0 | 87 |
88 | |
60
77aec9be0a51
renaming of cppclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
57
diff
changeset
|
89 namespace Orthanc |
0 | 90 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
91 class HttpClient::GlobalParameters |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
92 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
93 private: |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
94 boost::mutex mutex_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
95 bool httpsVerifyPeers_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
96 std::string httpsCACertificates_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
97 std::string proxy_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
98 long timeout_; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
99 bool verbose_; |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
100 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
101 GlobalParameters() : |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
102 httpsVerifyPeers_(true), |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
103 timeout_(0), |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
104 verbose_(false) |
1987
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
108 public: |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
109 // Singleton pattern |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
110 static GlobalParameters& GetInstance() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
111 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
112 static GlobalParameters parameters; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
113 return parameters; |
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
116 void ConfigureSsl(bool httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
117 const std::string& httpsCACertificates) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
118 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
119 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
120 httpsVerifyPeers_ = httpsVerifyPeers; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
121 httpsCACertificates_ = httpsCACertificates; |
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
124 void GetSslConfiguration(bool& httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
125 std::string& httpsCACertificates) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
126 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
127 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
128 httpsVerifyPeers = httpsVerifyPeers_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
129 httpsCACertificates = httpsCACertificates_; |
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
132 void SetDefaultProxy(const std::string& proxy) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
133 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
134 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
|
135 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
136 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
137 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
138 proxy_ = proxy; |
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
142 void GetDefaultProxy(std::string& target) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
143 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
144 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
145 target = proxy_; |
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
148 void SetDefaultTimeout(long seconds) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
149 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
150 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
|
151 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
152 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
153 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
154 timeout_ = seconds; |
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
158 long GetDefaultTimeout() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
159 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
160 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
161 return timeout_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
162 } |
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
|
163 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
164 #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
|
165 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
|
166 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
167 boost::mutex::scoped_lock lock(mutex_); |
2025 | 168 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
|
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 |
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 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
|
172 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
|
173 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
|
174 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
175 boost::mutex::scoped_lock lock(mutex_); |
2025 | 176 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
|
177 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
178 #endif |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
179 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
180 bool IsDefaultVerbose() const |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
181 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
182 return verbose_; |
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 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
185 void SetDefaultVerbose(bool verbose) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
186 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
187 verbose_ = verbose; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
188 } |
1987
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
191 |
0 | 192 struct HttpClient::PImpl |
193 { | |
194 CURL* curl_; | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
195 struct curl_slist *defaultPostHeaders_; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
196 struct curl_slist *userHeaders_; |
0 | 197 }; |
198 | |
199 | |
2787
ad2c32082653
Fix OrthancPluginHttpClient() to return the HTTP status on errors
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2677
diff
changeset
|
200 void HttpClient::ThrowException(HttpStatus status) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
201 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
202 switch (status) |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
203 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
204 case HttpStatus_400_BadRequest: |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
205 throw OrthancException(ErrorCode_BadRequest); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
206 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
207 case HttpStatus_401_Unauthorized: |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
208 case HttpStatus_403_Forbidden: |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
209 throw OrthancException(ErrorCode_Unauthorized); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
210 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
211 case HttpStatus_404_NotFound: |
2044 | 212 throw OrthancException(ErrorCode_UnknownResource); |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
213 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
214 default: |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
215 throw OrthancException(ErrorCode_NetworkProtocol); |
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 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
219 |
0 | 220 static CURLcode CheckCode(CURLcode code) |
221 { | |
2025 | 222 if (code == CURLE_NOT_BUILT_IN) |
223 { | |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
224 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
225 "Your libcurl does not contain a required feature, " |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
226 "please recompile Orthanc with -DUSE_SYSTEM_CURL=OFF"); |
2025 | 227 } |
228 | |
0 | 229 if (code != CURLE_OK) |
230 { | |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
231 throw OrthancException(ErrorCode_NetworkProtocol, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
232 "libCURL error: " + std::string(curl_easy_strerror(code))); |
0 | 233 } |
234 | |
235 return code; | |
236 } | |
237 | |
238 | |
2023 | 239 static size_t CurlBodyCallback(void *buffer, size_t size, size_t nmemb, void *payload) |
0 | 240 { |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
241 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
|
242 |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
243 size_t length = size * nmemb; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
244 if (length == 0) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
245 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
246 return 0; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
247 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
248 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
249 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
250 target.AddChunk(buffer, length); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
251 return length; |
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 |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
255 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
256 /*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
|
257 curl_infotype type, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
258 char *data, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
259 size_t size, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
260 void *userptr) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
261 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
262 switch (type) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
263 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
264 case CURLINFO_TEXT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
265 case CURLINFO_HEADER_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
266 case CURLINFO_HEADER_OUT: |
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_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
268 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
|
269 case CURLINFO_END: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
270 case CURLINFO_DATA_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
271 case CURLINFO_DATA_OUT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
272 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
273 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
|
274 LOG(INFO) << "libcurl: " << s; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
275 break; |
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 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
278 default: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
279 break; |
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 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
282 return 0; |
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 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
285 |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
286 struct CurlHeaderParameters |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
287 { |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
288 bool lowerCase_; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
289 HttpClient::HttpHeaders* headers_; |
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 |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
292 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
293 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
|
294 { |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
295 CurlHeaderParameters& parameters = *(static_cast<CurlHeaderParameters*>(payload)); |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
296 assert(parameters.headers_ != NULL); |
0 | 297 |
298 size_t length = size * nmemb; | |
299 if (length == 0) | |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
300 { |
0 | 301 return 0; |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
302 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
303 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
304 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
305 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
|
306 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
|
307 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
|
308 if (colon != std::string::npos && |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
309 eol != std::string::npos) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
310 { |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
311 std::string tmp(s.substr(0, colon)); |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
312 |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
313 if (parameters.lowerCase_) |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
314 { |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
315 Toolbox::ToLowerCase(tmp); |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
316 } |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
317 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
318 std::string key = Toolbox::StripSpaces(tmp); |
0 | 319 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
320 if (!key.empty()) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
321 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
322 std::string value = Toolbox::StripSpaces(s.substr(colon + 1, eol)); |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
323 (*parameters.headers_) [key] = value; |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
324 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
325 } |
0 | 326 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
327 return length; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
328 } |
0 | 329 } |
330 | |
331 | |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
332 void HttpClient::Setup() |
0 | 333 { |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
334 pimpl_->userHeaders_ = NULL; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
335 pimpl_->defaultPostHeaders_ = NULL; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
336 if ((pimpl_->defaultPostHeaders_ = curl_slist_append(pimpl_->defaultPostHeaders_, "Expect:")) == NULL) |
0 | 337 { |
475
72cca077abf8
removal of HttpException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
473
diff
changeset
|
338 throw OrthancException(ErrorCode_NotEnoughMemory); |
0 | 339 } |
340 | |
341 pimpl_->curl_ = curl_easy_init(); | |
342 if (!pimpl_->curl_) | |
343 { | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
344 curl_slist_free_all(pimpl_->defaultPostHeaders_); |
475
72cca077abf8
removal of HttpException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
473
diff
changeset
|
345 throw OrthancException(ErrorCode_NotEnoughMemory); |
0 | 346 } |
347 | |
2023 | 348 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEFUNCTION, &CurlBodyCallback)); |
0 | 349 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADER, 0)); |
350 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1)); | |
351 | |
456 | 352 // This fixes the "longjmp causes uninitialized stack frame" crash |
353 // that happens on modern Linux versions. | |
354 // http://stackoverflow.com/questions/9191668/error-longjmp-causes-uninitialized-stack-frame | |
355 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1)); | |
356 | |
0 | 357 url_ = ""; |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
358 method_ = HttpMethod_Get; |
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
359 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
|
360 SetVerbose(GlobalParameters::GetInstance().IsDefaultVerbose()); |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
361 timeout_ = GlobalParameters::GetInstance().GetDefaultTimeout(); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
362 GlobalParameters::GetInstance().GetDefaultProxy(proxy_); |
2219
262fcab24024
fix for HttpsCACertificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
363 GlobalParameters::GetInstance().GetSslConfiguration(verifyPeers_, caCertificates_); |
0 | 364 } |
365 | |
366 | |
2020 | 367 HttpClient::HttpClient() : |
368 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
|
369 verifyPeers_(true), |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
370 pkcs11Enabled_(false), |
2107 | 371 headersToLowerCase_(true), |
372 redirectionFollowed_(true) | |
2020 | 373 { |
374 Setup(); | |
375 } | |
376 | |
377 | |
378 HttpClient::HttpClient(const WebServiceParameters& service, | |
379 const std::string& uri) : | |
380 pimpl_(new PImpl), | |
2049 | 381 verifyPeers_(true), |
2107 | 382 headersToLowerCase_(true), |
383 redirectionFollowed_(true) | |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
384 { |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
385 Setup(); |
2020 | 386 |
387 if (service.GetUsername().size() != 0 && | |
388 service.GetPassword().size() != 0) | |
389 { | |
390 SetCredentials(service.GetUsername().c_str(), | |
391 service.GetPassword().c_str()); | |
392 } | |
393 | |
394 if (!service.GetCertificateFile().empty()) | |
395 { | |
396 SetClientCertificate(service.GetCertificateFile(), | |
397 service.GetCertificateKeyFile(), | |
398 service.GetCertificateKeyPassword()); | |
399 } | |
400 | |
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
|
401 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
|
402 |
2020 | 403 SetUrl(service.GetUrl() + uri); |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
404 |
2823
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
405 for (WebServiceParameters::Dictionary::const_iterator |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
406 it = service.GetHttpHeaders().begin(); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
407 it != service.GetHttpHeaders().end(); ++it) |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
408 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
409 AddHeader(it->first, it->second); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
410 } |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
411 } |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
412 |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
413 |
0 | 414 HttpClient::~HttpClient() |
415 { | |
416 curl_easy_cleanup(pimpl_->curl_); | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
417 curl_slist_free_all(pimpl_->defaultPostHeaders_); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
418 ClearHeaders(); |
0 | 419 } |
420 | |
421 | |
422 void HttpClient::SetVerbose(bool isVerbose) | |
423 { | |
424 isVerbose_ = isVerbose; | |
425 | |
426 if (isVerbose_) | |
427 { | |
428 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
|
429 //CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_DEBUGFUNCTION, &CurlDebugCallback)); |
0 | 430 } |
431 else | |
432 { | |
433 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 0)); | |
434 } | |
435 } | |
436 | |
437 | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
438 void HttpClient::AddHeader(const std::string& key, |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
439 const std::string& value) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
440 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
441 if (key.empty()) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
442 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
443 throw OrthancException(ErrorCode_ParameterOutOfRange); |
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 std::string s = key + ": " + value; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
447 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
448 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
|
449 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
450 throw OrthancException(ErrorCode_NotEnoughMemory); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
451 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
452 } |
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 void HttpClient::ClearHeaders() |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
456 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
457 if (pimpl_->userHeaders_ != NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
458 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
459 curl_slist_free_all(pimpl_->userHeaders_); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
460 pimpl_->userHeaders_ = NULL; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
461 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
462 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
463 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
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 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
|
466 HttpHeaders* answerHeaders) |
0 | 467 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
468 answerBody.clear(); |
0 | 469 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
|
470 |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
471 CurlHeaderParameters headerParameters; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
472 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
473 if (answerHeaders == NULL) |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
474 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
475 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
|
476 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
|
477 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
478 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
479 { |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
480 headerParameters.lowerCase_ = headersToLowerCase_; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
481 headerParameters.headers_ = answerHeaders; |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
482 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, &CurlHeaderCallback)); |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
483 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
|
484 } |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
485 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
486 #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
|
487 // 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
|
488 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
489 if (verifyPeers_) |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
490 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
491 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
|
492 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
|
493 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
|
494 } |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
495 else |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
496 { |
1973
7bd4cb780feb
Option "HttpsVerifyPeers" can be used to connect against self-signed HTTPS certificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
497 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
|
498 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
|
499 } |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
500 #endif |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
501 |
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
|
502 // 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
|
503 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
|
504 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
|
505 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
506 throw OrthancException(ErrorCode_ParameterOutOfRange, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
507 "Cannot enable both client certificates and PKCS#11 authentication"); |
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 } |
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 |
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 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
|
511 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
512 #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
|
513 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
|
514 { |
2025 | 515 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
|
516 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
|
517 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
|
518 } |
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 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
|
520 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
521 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
522 "Cannot use PKCS#11 for a HTTPS request, " |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
523 "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
|
524 } |
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 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
526 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
527 "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
|
528 #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
|
529 } |
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 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
|
531 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
532 #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
|
533 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
|
534 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
|
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 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
|
537 { |
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 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
|
539 } |
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 |
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 // 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
|
542 // 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
|
543 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
|
544 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
545 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
|
546 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
|
547 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
548 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
549 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
550 "This version of Orthanc is compiled without OpenSSL support, " |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
551 "cannot use HTTPS client authentication"); |
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
|
552 #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
|
553 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
554 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
555 // Reset the parameters from previous calls to Apply() |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
556 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
|
557 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
558 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
559 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
560 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, NULL)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
561 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, NULL)); |
2104
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
562 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
|
563 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PROXY, NULL)); |
0 | 564 |
2104
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
565 if (redirectionFollowed_) |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
566 { |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
567 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1L)); |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
568 } |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
569 else |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
570 { |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
571 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 0L)); |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
572 } |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
573 |
1186
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
574 // Set timeouts |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
575 if (timeout_ <= 0) |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
576 { |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
577 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
|
578 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
|
579 } |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
580 else |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
581 { |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
582 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
|
583 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
|
584 } |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
585 |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
586 if (credentials_.size() != 0) |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
587 { |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
588 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
|
589 } |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
590 |
1273
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
591 if (proxy_.size() != 0) |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
592 { |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
593 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
|
594 } |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
595 |
0 | 596 switch (method_) |
597 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
598 case HttpMethod_Get: |
0 | 599 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); |
600 break; | |
601 | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
602 case HttpMethod_Post: |
0 | 603 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
|
604 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
605 if (pimpl_->userHeaders_ == NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
606 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
607 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
|
608 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
609 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
610 break; |
0 | 611 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
612 case HttpMethod_Delete: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
613 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
614 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
615 break; |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
616 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
617 case HttpMethod_Put: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
618 // http://stackoverflow.com/a/7570281/881731: Don't use |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
619 // CURLOPT_PUT if there is a body |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
620 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
621 // CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
622 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
623 curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "PUT"); /* !!! */ |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
624 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
625 if (pimpl_->userHeaders_ == NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
626 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
627 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
|
628 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
629 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
630 break; |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
631 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
632 default: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
633 throw OrthancException(ErrorCode_InternalError); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
634 } |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
635 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
636 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
637 if (method_ == HttpMethod_Post || |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
638 method_ == HttpMethod_Put) |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
639 { |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
640 if (body_.size() > 0) |
0 | 641 { |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
642 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
|
643 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, body_.size())); |
0 | 644 } |
645 else | |
646 { | |
647 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, NULL)); | |
648 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0)); | |
649 } | |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
650 } |
0 | 651 |
652 | |
653 // Do the actual request | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
654 CURLcode code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
655 long status = 0; |
0 | 656 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
657 ChunkedBuffer buffer; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
658 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
|
659 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
660 if (boost::starts_with(url_, "https://")) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
661 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
662 code = OrthancHttpClientPerformSSL(pimpl_->curl_, &status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
663 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
664 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
665 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
666 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
667 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
668 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
669 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
|
670 << 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
|
671 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
672 if (isVerbose_) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
673 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
674 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
|
675 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
676 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
677 CheckCode(code); |
0 | 678 |
679 if (status == 0) | |
680 { | |
681 // 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
|
682 lastStatus_ = HttpStatus_500_InternalServerError; |
0 | 683 } |
684 else | |
685 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
686 lastStatus_ = static_cast<HttpStatus>(status); |
0 | 687 } |
688 | |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
689 bool success = (status >= 200 && status < 300); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
690 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
691 if (success) |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
692 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
693 buffer.Flatten(answerBody); |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
694 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
695 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
696 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
697 answerBody.clear(); |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
698 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
|
699 << " (" << EnumerationToString(lastStatus_) << ")"; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
700 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
701 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
702 return success; |
0 | 703 } |
704 | |
705 | |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
706 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
|
707 HttpClient::HttpHeaders* answerHeaders) |
0 | 708 { |
709 std::string s; | |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
710 if (ApplyInternal(s, answerHeaders)) |
0 | 711 { |
712 Json::Reader reader; | |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
713 return reader.parse(s, answerBody); |
0 | 714 } |
715 else | |
716 { | |
717 return false; | |
718 } | |
719 } | |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
720 |
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
721 |
468
456b9d2e9af4
rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
722 void HttpClient::SetCredentials(const char* username, |
456b9d2e9af4
rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
723 const char* password) |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
724 { |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
725 credentials_ = std::string(username) + ":" + std::string(password); |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
726 } |
457 | 727 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
728 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
729 void HttpClient::ConfigureSsl(bool httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
730 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
|
731 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
732 #if ORTHANC_ENABLE_SSL == 1 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
733 if (httpsVerifyPeers) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
734 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
735 if (httpsVerifyCertificates.empty()) |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
736 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
737 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
|
738 << "set \"HttpsCACertificates\" if you need to do HTTPS requests"; |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
739 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
740 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
741 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
742 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
|
743 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
744 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
745 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
746 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
747 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
|
748 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
749 #endif |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
750 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
751 GlobalParameters::GetInstance().ConfigureSsl(httpsVerifyPeers, httpsVerifyCertificates); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
752 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
753 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
754 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
755 void HttpClient::GlobalInitialize() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
756 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
757 #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
|
758 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
|
759 #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
|
760 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
|
761 #endif |
457 | 762 } |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
763 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
764 |
457 | 765 void HttpClient::GlobalFinalize() |
766 { | |
767 curl_global_cleanup(); | |
2025 | 768 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
769 #if ORTHANC_ENABLE_PKCS11 == 1 |
2025 | 770 Pkcs11::Finalize(); |
771 #endif | |
457 | 772 } |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
773 |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
774 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
775 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
|
776 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
777 GlobalParameters::GetInstance().SetDefaultVerbose(verbose); |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
778 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
779 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
780 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
781 void HttpClient::SetDefaultProxy(const std::string& proxy) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
782 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
783 GlobalParameters::GetInstance().SetDefaultProxy(proxy); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
784 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
785 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
786 |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
787 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
|
788 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
789 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
|
790 } |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
791 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
792 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
793 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
|
794 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
795 if (!Apply(answerBody)) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
796 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
797 ThrowException(GetLastStatus()); |
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 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
802 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
|
803 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
804 if (!Apply(answerBody)) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
805 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
806 ThrowException(GetLastStatus()); |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
807 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
808 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
809 |
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(std::string& answerBody, |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
812 HttpHeaders& answerHeaders) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
813 { |
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 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
819 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
820 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
821 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
|
822 HttpHeaders& answerHeaders) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
823 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
824 if (!Apply(answerBody, answerHeaders)) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
825 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
826 ThrowException(GetLastStatus()); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
827 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
828 } |
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
|
829 |
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
|
830 |
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 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
|
832 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
|
833 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
|
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 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
|
836 { |
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
|
837 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
|
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 |
2140 | 840 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
|
841 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
842 throw OrthancException(ErrorCode_InexistentFile, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
843 "Cannot open certificate file: " + 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
|
844 } |
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 |
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 if (!certificateKeyFile.empty() && |
2140 | 847 !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
|
848 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
849 throw OrthancException(ErrorCode_InexistentFile, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
850 "Cannot open key file: " + 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
|
851 } |
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
|
852 |
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
|
853 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
|
854 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
|
855 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
|
856 } |
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
|
857 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
858 |
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 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
|
860 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
|
861 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
|
862 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
863 #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
|
864 LOG(INFO) << "Initializing PKCS#11 using " << module |
2024 | 865 << (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
|
866 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
|
867 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
868 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
869 "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
|
870 #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
|
871 } |
0 | 872 } |