Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Loaders/DicomSource.cpp @ 2161:e65fe2e50fde dicom-sr tip
integration mainline->dicom-sr
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Sep 2024 22:34:17 +0200 |
parents | 32bfccdc030f |
children |
comparison
equal
deleted
inserted
replaced
2152:f68f9a8d0d63 | 2161:e65fe2e50fde |
---|---|
23 | 23 |
24 #include "DicomSource.h" | 24 #include "DicomSource.h" |
25 | 25 |
26 #include "../Oracle/HttpCommand.h" | 26 #include "../Oracle/HttpCommand.h" |
27 #include "../Oracle/OrthancRestApiCommand.h" | 27 #include "../Oracle/OrthancRestApiCommand.h" |
28 #include "../Toolbox/StoneToolbox.h" | |
28 | 29 |
29 #include <OrthancException.h> | 30 #include <OrthancException.h> |
30 #include <Toolbox.h> | 31 #include <Toolbox.h> |
31 | 32 |
32 #include <boost/algorithm/string/predicate.hpp> | 33 #include <boost/algorithm/string/predicate.hpp> |
55 } | 56 } |
56 | 57 |
57 // TODO: Call Orthanc::Toolbox::UriEncode() ? | 58 // TODO: Call Orthanc::Toolbox::UriEncode() ? |
58 | 59 |
59 return s; | 60 return s; |
60 } | |
61 | |
62 | |
63 static std::string AddUriSuffix(const std::string& base, | |
64 const std::string& suffix) | |
65 { | |
66 if (base.empty()) | |
67 { | |
68 return suffix; | |
69 } | |
70 else if (suffix.empty()) | |
71 { | |
72 return base; | |
73 } | |
74 else | |
75 { | |
76 char lastBase = base[base.size() - 1]; | |
77 | |
78 if (lastBase == '/' && | |
79 suffix[0] == '/') | |
80 { | |
81 return base + suffix.substr(1); | |
82 } | |
83 else if (lastBase == '/' || | |
84 suffix[0] == '/') | |
85 { | |
86 return base + suffix; | |
87 } | |
88 else | |
89 { | |
90 return base + "/" + suffix; | |
91 } | |
92 } | |
93 } | 61 } |
94 | 62 |
95 | 63 |
96 void DicomSource::SetOrthancSource(const Orthanc::WebServiceParameters& parameters) | 64 void DicomSource::SetOrthancSource(const Orthanc::WebServiceParameters& parameters) |
97 { | 65 { |
227 case DicomSourceType_DicomWeb: | 195 case DicomSourceType_DicomWeb: |
228 { | 196 { |
229 std::unique_ptr<HttpCommand> command(new HttpCommand); | 197 std::unique_ptr<HttpCommand> command(new HttpCommand); |
230 | 198 |
231 command->SetMethod(Orthanc::HttpMethod_Get); | 199 command->SetMethod(Orthanc::HttpMethod_Get); |
232 command->SetUrl(AddUriSuffix(webService_.GetUrl(), uri + EncodeGetArguments(arguments))); | 200 command->SetUrl(StoneToolbox::JoinUrl(webService_.GetUrl(), uri + EncodeGetArguments(arguments))); |
233 command->SetHttpHeaders(webService_.GetHttpHeaders()); | 201 command->SetHttpHeaders(webService_.GetHttpHeaders()); |
234 | 202 |
235 for (std::map<std::string, std::string>::const_iterator | 203 for (std::map<std::string, std::string>::const_iterator |
236 it = headers.begin(); it != headers.end(); ++it) | 204 it = headers.begin(); it != headers.end(); ++it) |
237 { | 205 { |
272 body["Arguments"] = args; | 240 body["Arguments"] = args; |
273 body["HttpHeaders"] = h; | 241 body["HttpHeaders"] = h; |
274 | 242 |
275 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); | 243 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
276 command->SetMethod(Orthanc::HttpMethod_Post); | 244 command->SetMethod(Orthanc::HttpMethod_Post); |
277 command->SetUri(AddUriSuffix(orthancDicomWebRoot_, "/servers/" + serverName_ + "/get")); | 245 command->SetUri(StoneToolbox::JoinUrl(orthancDicomWebRoot_, "/servers/" + serverName_ + "/get")); |
278 command->SetBody(body); | 246 command->SetBody(body); |
279 | 247 |
280 if (protection.get()) | 248 if (protection.get()) |
281 { | 249 { |
282 command->AcquirePayload(protection.release()); | 250 command->AcquirePayload(protection.release()); |