Mercurial > hg > orthanc
comparison OrthancFramework/Sources/WebServiceParameters.cpp @ 4522:017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 23 Feb 2021 11:28:28 +0100 |
parents | d9473bd5ed43 |
children | 7053502fbf97 |
comparison
equal
deleted
inserted
replaced
4521:60e4f94ec30f | 4522:017ab543e6ef |
---|---|
44 static const char* KEY_PASSWORD = "Password"; | 44 static const char* KEY_PASSWORD = "Password"; |
45 static const char* KEY_PKCS11 = "Pkcs11"; | 45 static const char* KEY_PKCS11 = "Pkcs11"; |
46 static const char* KEY_URL = "Url"; | 46 static const char* KEY_URL = "Url"; |
47 static const char* KEY_URL_2 = "URL"; | 47 static const char* KEY_URL_2 = "URL"; |
48 static const char* KEY_USERNAME = "Username"; | 48 static const char* KEY_USERNAME = "Username"; |
49 static const char* KEY_TIMEOUT = "Timeout"; | |
49 | 50 |
50 | 51 |
51 static bool IsReservedKey(const std::string& key) | 52 static bool IsReservedKey(const std::string& key) |
52 { | 53 { |
53 return (key == KEY_CERTIFICATE_FILE || | 54 return (key == KEY_CERTIFICATE_FILE || |
56 key == KEY_HTTP_HEADERS || | 57 key == KEY_HTTP_HEADERS || |
57 key == KEY_PASSWORD || | 58 key == KEY_PASSWORD || |
58 key == KEY_PKCS11 || | 59 key == KEY_PKCS11 || |
59 key == KEY_URL || | 60 key == KEY_URL || |
60 key == KEY_URL_2 || | 61 key == KEY_URL_2 || |
61 key == KEY_USERNAME); | 62 key == KEY_USERNAME || |
63 key == KEY_TIMEOUT); | |
62 } | 64 } |
63 | 65 |
64 | 66 |
65 WebServiceParameters::WebServiceParameters() : | 67 WebServiceParameters::WebServiceParameters() : |
66 pkcs11Enabled_(false) | 68 pkcs11Enabled_(false), |
69 timeout_(0) | |
67 { | 70 { |
68 SetUrl("http://127.0.0.1:8042/"); | 71 SetUrl("http://127.0.0.1:8042/"); |
69 } | 72 } |
70 | 73 |
71 WebServiceParameters::WebServiceParameters(const Json::Value &serialized) | 74 WebServiceParameters::WebServiceParameters(const Json::Value &serialized) |
212 void WebServiceParameters::FromSimpleFormat(const Json::Value& peer) | 215 void WebServiceParameters::FromSimpleFormat(const Json::Value& peer) |
213 { | 216 { |
214 assert(peer.isArray()); | 217 assert(peer.isArray()); |
215 | 218 |
216 pkcs11Enabled_ = false; | 219 pkcs11Enabled_ = false; |
220 timeout_ = 0; | |
217 ClearClientCertificate(); | 221 ClearClientCertificate(); |
218 | 222 |
219 if (peer.size() != 1 && | 223 if (peer.size() != 1 && |
220 peer.size() != 3) | 224 peer.size() != 3) |
221 { | 225 { |
364 throw OrthancException(ErrorCode_BadFileFormat, | 368 throw OrthancException(ErrorCode_BadFileFormat, |
365 "User-defined properties associated with a Web service must be strings: " + *it); | 369 "User-defined properties associated with a Web service must be strings: " + *it); |
366 } | 370 } |
367 } | 371 } |
368 } | 372 } |
373 | |
374 | |
375 if (peer.isMember(KEY_TIMEOUT)) | |
376 { | |
377 timeout_ = SerializationToolbox::ReadUnsignedInteger(peer, KEY_TIMEOUT); | |
378 } | |
379 else | |
380 { | |
381 timeout_ = 0; | |
382 } | |
369 } | 383 } |
370 | 384 |
371 | 385 |
372 void WebServiceParameters::Unserialize(const Json::Value& peer) | 386 void WebServiceParameters::Unserialize(const Json::Value& peer) |
373 { | 387 { |
513 return (!certificateFile_.empty() || | 527 return (!certificateFile_.empty() || |
514 !certificateKeyFile_.empty() || | 528 !certificateKeyFile_.empty() || |
515 !certificateKeyPassword_.empty() || | 529 !certificateKeyPassword_.empty() || |
516 pkcs11Enabled_ || | 530 pkcs11Enabled_ || |
517 !headers_.empty() || | 531 !headers_.empty() || |
518 !userProperties_.empty()); | 532 !userProperties_.empty() || |
533 timeout_ != 0); | |
519 } | 534 } |
520 | 535 |
521 | 536 |
522 void WebServiceParameters::Serialize(Json::Value& value, | 537 void WebServiceParameters::Serialize(Json::Value& value, |
523 bool forceAdvancedFormat, | 538 bool forceAdvancedFormat, |
555 { | 570 { |
556 value[KEY_CERTIFICATE_KEY_PASSWORD] = certificateKeyPassword_; | 571 value[KEY_CERTIFICATE_KEY_PASSWORD] = certificateKeyPassword_; |
557 } | 572 } |
558 | 573 |
559 value[KEY_PKCS11] = pkcs11Enabled_; | 574 value[KEY_PKCS11] = pkcs11Enabled_; |
575 value[KEY_TIMEOUT] = timeout_; | |
560 | 576 |
561 value[KEY_HTTP_HEADERS] = Json::objectValue; | 577 value[KEY_HTTP_HEADERS] = Json::objectValue; |
562 for (Dictionary::const_iterator it = headers_.begin(); | 578 for (Dictionary::const_iterator it = headers_.begin(); |
563 it != headers_.end(); ++it) | 579 it != headers_.end(); ++it) |
564 { | 580 { |
629 target[KEY_CERTIFICATE_KEY_FILE] = Json::nullValue; | 645 target[KEY_CERTIFICATE_KEY_FILE] = Json::nullValue; |
630 target[KEY_CERTIFICATE_KEY_PASSWORD] = Json::nullValue; | 646 target[KEY_CERTIFICATE_KEY_PASSWORD] = Json::nullValue; |
631 } | 647 } |
632 | 648 |
633 target[KEY_PKCS11] = pkcs11Enabled_; | 649 target[KEY_PKCS11] = pkcs11Enabled_; |
650 target[KEY_TIMEOUT] = timeout_; | |
634 | 651 |
635 Json::Value headers = Json::arrayValue; | 652 Json::Value headers = Json::arrayValue; |
636 | 653 |
637 for (Dictionary::const_iterator it = headers_.begin(); | 654 for (Dictionary::const_iterator it = headers_.begin(); |
638 it != headers_.end(); ++it) | 655 it != headers_.end(); ++it) |
647 it != userProperties_.end(); ++it) | 664 it != userProperties_.end(); ++it) |
648 { | 665 { |
649 target[it->first] = it->second; | 666 target[it->first] = it->second; |
650 } | 667 } |
651 } | 668 } |
669 | |
670 | |
671 void WebServiceParameters::SetTimeout(uint32_t seconds) | |
672 { | |
673 timeout_ = seconds; | |
674 } | |
675 | |
676 uint32_t WebServiceParameters::GetTimeout() const | |
677 { | |
678 return timeout_; | |
679 } | |
680 | |
681 bool WebServiceParameters::HasTimeout() const | |
682 { | |
683 return (timeout_ != 0); | |
684 } | |
652 } | 685 } |