comparison Applications/ApplicationToolbox.cpp @ 127:2cb9fabb529e

cleaning up options
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Feb 2018 17:50:42 +0100
parents 7a3f4d580625
children 788dd04b87f5
comparison
equal deleted inserted replaced
126:e7c049a61e9a 127:2cb9fabb529e
34 #include <boost/regex.hpp> 34 #include <boost/regex.hpp>
35 #include <boost/date_time/posix_time/posix_time.hpp> 35 #include <boost/date_time/posix_time/posix_time.hpp>
36 #include <cassert> 36 #include <cassert>
37 37
38 38
39 static const char* OPTION_URL = "orthanc";
40 static const char* OPTION_USERNAME = "username";
41 static const char* OPTION_PASSWORD = "password";
42 static const char* OPTION_TIMEOUT = "timeout";
43 static const char* OPTION_PROXY = "proxy";
44 static const char* OPTION_VERIFY_PEERS = "verify-peers";
45 static const char* OPTION_CA_CERTIFICATES = "ca-certificates";
46
47
48
39 static bool DisplayPerformanceWarning() 49 static bool DisplayPerformanceWarning()
40 { 50 {
41 (void) DisplayPerformanceWarning; // Disable warning about unused function 51 (void) DisplayPerformanceWarning; // Disable warning about unused function
42 LOG(WARNING) << "Performance warning in whole-slide imaging: " 52 LOG(WARNING) << "Performance warning in whole-slide imaging: "
43 << "Non-release build, runtime debug assertions are turned on"; 53 << "Non-release build, runtime debug assertions are turned on";
239 249
240 250
241 void AddRestApiOptions(boost::program_options::options_description& section) 251 void AddRestApiOptions(boost::program_options::options_description& section)
242 { 252 {
243 section.add_options() 253 section.add_options()
244 ("username", boost::program_options::value<std::string>(), "Username for the target Orthanc server") 254 (OPTION_USERNAME, boost::program_options::value<std::string>(),
245 ("password", boost::program_options::value<std::string>(), "Password for the target Orthanc server") 255 "Username for the target Orthanc server")
246 ("proxy", boost::program_options::value<std::string>(), "HTTP proxy to be used") 256 (OPTION_PASSWORD, boost::program_options::value<std::string>(),
247 ("timeout", boost::program_options::value<int>()->default_value(0), "HTTP timeout (in seconds, 0 means no timeout)") 257 "Password for the target Orthanc server")
248 ("verify-peers", boost::program_options::value<bool>()->default_value(true), "Enable the verification of the peers during HTTPS requests") 258 (OPTION_PROXY, boost::program_options::value<std::string>(),
249 ("ca-certificates", boost::program_options::value<std::string>()->default_value(""), "Path to the CA (certification authority) certificates to validate peers in HTTPS requests") 259 "HTTP proxy to be used")
260 (OPTION_TIMEOUT, boost::program_options::value<int>()->default_value(0),
261 "HTTP timeout (in seconds, 0 means no timeout)")
262 (OPTION_VERIFY_PEERS, boost::program_options::value<bool>()->default_value(true),
263 "Enable the verification of the peers during HTTPS requests")
264 (OPTION_CA_CERTIFICATES, boost::program_options::value<std::string>()->default_value(""),
265 "Path to the CA (certification authority) certificates to validate peers in HTTPS requests")
250 ; 266 ;
251 } 267 }
252 268
253 269
254 void SetupRestApi(Orthanc::WebServiceParameters& parameters, 270 void SetupRestApi(Orthanc::WebServiceParameters& parameters,
255 const boost::program_options::variables_map& options) 271 const boost::program_options::variables_map& options)
256 { 272 {
257 if (options.count("orthanc")) 273 if (options.count(OPTION_URL))
258 { 274 {
259 parameters.SetUrl(options["orthanc"].as<std::string>()); 275 parameters.SetUrl(options[OPTION_URL].as<std::string>());
260 } 276 }
261 277
262 if (options.count("username") && 278 if (options.count(OPTION_USERNAME) &&
263 options.count("password")) 279 options.count(OPTION_PASSWORD))
264 { 280 {
265 parameters.SetUsername(options["username"].as<std::string>()); 281 parameters.SetUsername(options[OPTION_USERNAME].as<std::string>());
266 parameters.SetPassword(options["password"].as<std::string>()); 282 parameters.SetPassword(options[OPTION_PASSWORD].as<std::string>());
267 } 283 }
268 284
269 if (options.count("timeout")) 285 if (options.count(OPTION_TIMEOUT))
270 { 286 {
271 int timeout = options["timeout"].as<int>(); 287 int timeout = options[OPTION_TIMEOUT].as<int>();
272 if (timeout < 0) 288 if (timeout < 0)
273 { 289 {
274 LOG(ERROR) << "Timeouts cannot be negative: " << timeout; 290 LOG(ERROR) << "Timeouts cannot be negative: " << timeout;
275 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 291 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
276 } 292 }
277 else 293 else
278 { 294 {
279 Orthanc::HttpClient::SetDefaultTimeout(timeout); 295 Orthanc::HttpClient::SetDefaultTimeout(timeout);
280 } 296 }
281 297
282 if (options.count("proxy")) 298 if (options.count(OPTION_PROXY))
283 { 299 {
284 Orthanc::HttpClient::SetDefaultProxy(options["proxy"].as<std::string>()); 300 Orthanc::HttpClient::SetDefaultProxy(options[OPTION_PROXY].as<std::string>());
285 } 301 }
286 } 302 }
287 303
288 #if ORTHANC_ENABLE_SSL == 1 304 #if ORTHANC_ENABLE_SSL == 1
289 if (options.count("verify-peers") || 305 if (options.count(OPTION_VERIFY_PEERS) ||
290 options.count("ca-certificates")) 306 options.count(OPTION_CA_CERTIFICATES))
291 { 307 {
292 Orthanc::HttpClient::ConfigureSsl(options["verify-peers"].as<bool>(), 308 Orthanc::HttpClient::ConfigureSsl(options[OPTION_VERIFY_PEERS].as<bool>(),
293 options["ca-certificates"].as<std::string>()); 309 options[OPTION_CA_CERTIFICATES].as<std::string>());
294 } 310 }
295 #endif 311 #endif
296 } 312 }
297 } 313 }
298 } 314 }