comparison Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h @ 405:1938ba8fba35

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 15 Apr 2023 13:49:53 +0200
parents 1280b40d6696
children c1b0f3c4e1f5
comparison
equal deleted inserted replaced
394:2fd272ea8f00 405:1938ba8fba35
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium 6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 * 7 *
8 * This program is free software: you can redistribute it and/or 8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as 9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, either version 3 of the 10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version. 11 * License, or (at your option) any later version.
113 # define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 1 113 # define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 1
114 #else 114 #else
115 # define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 0 115 # define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 0
116 #endif 116 #endif
117 117
118 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2)
119 # define HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API 1
120 #else
121 # define HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API 0
122 #endif
123
124 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 10, 1)
125 # define HAS_ORTHANC_PLUGIN_WEBDAV 1
126 #else
127 # define HAS_ORTHANC_PLUGIN_WEBDAV 0
128 #endif
129
118 130
119 131
120 namespace OrthancPlugins 132 namespace OrthancPlugins
121 { 133 {
122 typedef void (*RestCallback) (OrthancPluginRestOutput* output, 134 typedef void (*RestCallback) (OrthancPluginRestOutput* output,
216 228
217 bool RestApiPost(const std::string& uri, 229 bool RestApiPost(const std::string& uri,
218 const Json::Value& body, 230 const Json::Value& body,
219 bool applyPlugins); 231 bool applyPlugins);
220 232
233 #if HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API == 1
234 bool RestApiPost(const std::string& uri,
235 const Json::Value& body,
236 const std::map<std::string, std::string>& httpHeaders,
237 bool applyPlugins);
238
239 bool RestApiPost(const std::string& uri,
240 const void* body,
241 size_t bodySize,
242 const std::map<std::string, std::string>& httpHeaders,
243 bool applyPlugins);
244 #endif
245
221 bool RestApiPut(const std::string& uri, 246 bool RestApiPut(const std::string& uri,
222 const Json::Value& body, 247 const Json::Value& body,
223 bool applyPlugins); 248 bool applyPlugins);
224 249
225 bool RestApiPost(const std::string& uri, 250 bool RestApiPost(const std::string& uri,
295 const char* GetContent() const 320 const char* GetContent() const
296 { 321 {
297 return str_; 322 return str_;
298 } 323 }
299 324
325 bool IsNullOrEmpty() const
326 {
327 return str_ == NULL || str_[0] == 0;
328 }
329
300 void ToString(std::string& target) const; 330 void ToString(std::string& target) const;
301 331
302 void ToJson(Json::Value& target) const; 332 void ToJson(Json::Value& target) const;
303 }; 333
334 void ToJsonWithoutComments(Json::Value& target) const;
335 };
304 336
305 337
306 class OrthancConfiguration : public boost::noncopyable 338 class OrthancConfiguration : public boost::noncopyable
307 { 339 {
308 private: 340 private:
312 std::string GetPath(const std::string& key) const; 344 std::string GetPath(const std::string& key) const;
313 345
314 void LoadConfiguration(); 346 void LoadConfiguration();
315 347
316 public: 348 public:
317 OrthancConfiguration(); 349 OrthancConfiguration(); // loads the full Orthanc configuration
318 350
319 explicit OrthancConfiguration(bool load); 351 explicit OrthancConfiguration(bool load);
352
353 explicit OrthancConfiguration(const Json::Value& configuration, const std::string& path); // e.g. to load a section from a default json content
320 354
321 const Json::Value& GetJson() const 355 const Json::Value& GetJson() const
322 { 356 {
323 return configuration_; 357 return configuration_;
324 } 358 }
499 533
500 bool RestApiGet(Json::Value& result, 534 bool RestApiGet(Json::Value& result,
501 const std::string& uri, 535 const std::string& uri,
502 bool applyPlugins); 536 bool applyPlugins);
503 537
538 bool RestApiGet(Json::Value& result,
539 const std::string& uri,
540 const std::map<std::string, std::string>& httpHeaders,
541 bool applyPlugins);
542
504 bool RestApiGetString(std::string& result, 543 bool RestApiGetString(std::string& result,
505 const std::string& uri, 544 const std::string& uri,
506 bool applyPlugins); 545 bool applyPlugins);
507 546
508 bool RestApiGetString(std::string& result, 547 bool RestApiGetString(std::string& result,
519 bool RestApiPost(Json::Value& result, 558 bool RestApiPost(Json::Value& result,
520 const std::string& uri, 559 const std::string& uri,
521 const void* body, 560 const void* body,
522 size_t bodySize, 561 size_t bodySize,
523 bool applyPlugins); 562 bool applyPlugins);
563
564 #if HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API == 1
565 bool RestApiPost(Json::Value& result,
566 const std::string& uri,
567 const Json::Value& body,
568 const std::map<std::string, std::string>& httpHeaders,
569 bool applyPlugins);
570 #endif
524 571
525 bool RestApiPost(Json::Value& result, 572 bool RestApiPost(Json::Value& result,
526 const std::string& uri, 573 const std::string& uri,
527 const Json::Value& body, 574 const Json::Value& body,
528 bool applyPlugins); 575 bool applyPlugins);
600 647
601 bool CheckMinimalOrthancVersion(unsigned int major, 648 bool CheckMinimalOrthancVersion(unsigned int major,
602 unsigned int minor, 649 unsigned int minor,
603 unsigned int revision); 650 unsigned int revision);
604 651
652 bool CheckMinimalVersion(const char* version,
653 unsigned int major,
654 unsigned int minor,
655 unsigned int revision);
605 656
606 namespace Internals 657 namespace Internals
607 { 658 {
608 template <RestCallback Callback> 659 template <RestCallback Callback>
609 static OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output, 660 static OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output,
709 const std::string& peer, 760 const std::string& peer,
710 const std::string& key) const; 761 const std::string& key) const;
711 762
712 bool DoGet(MemoryBuffer& target, 763 bool DoGet(MemoryBuffer& target,
713 size_t index, 764 size_t index,
714 const std::string& uri) const; 765 const std::string& uri,
766 const std::map<std::string, std::string>& headers) const;
715 767
716 bool DoGet(MemoryBuffer& target, 768 bool DoGet(MemoryBuffer& target,
717 const std::string& name, 769 const std::string& name,
718 const std::string& uri) const; 770 const std::string& uri,
771 const std::map<std::string, std::string>& headers) const;
719 772
720 bool DoGet(Json::Value& target, 773 bool DoGet(Json::Value& target,
721 size_t index, 774 size_t index,
722 const std::string& uri) const; 775 const std::string& uri,
776 const std::map<std::string, std::string>& headers) const;
723 777
724 bool DoGet(Json::Value& target, 778 bool DoGet(Json::Value& target,
725 const std::string& name, 779 const std::string& name,
726 const std::string& uri) const; 780 const std::string& uri,
781 const std::map<std::string, std::string>& headers) const;
727 782
728 bool DoPost(MemoryBuffer& target, 783 bool DoPost(MemoryBuffer& target,
729 size_t index, 784 size_t index,
730 const std::string& uri, 785 const std::string& uri,
731 const std::string& body) const; 786 const std::string& body,
787 const std::map<std::string, std::string>& headers) const;
732 788
733 bool DoPost(MemoryBuffer& target, 789 bool DoPost(MemoryBuffer& target,
734 const std::string& name, 790 const std::string& name,
735 const std::string& uri, 791 const std::string& uri,
736 const std::string& body) const; 792 const std::string& body,
793 const std::map<std::string, std::string>& headers) const;
737 794
738 bool DoPost(Json::Value& target, 795 bool DoPost(Json::Value& target,
739 size_t index, 796 size_t index,
740 const std::string& uri, 797 const std::string& uri,
741 const std::string& body) const; 798 const std::string& body,
799 const std::map<std::string, std::string>& headers) const;
742 800
743 bool DoPost(Json::Value& target, 801 bool DoPost(Json::Value& target,
744 const std::string& name, 802 const std::string& name,
745 const std::string& uri, 803 const std::string& uri,
746 const std::string& body) const; 804 const std::string& body,
805 const std::map<std::string, std::string>& headers) const;
747 806
748 bool DoPut(size_t index, 807 bool DoPut(size_t index,
749 const std::string& uri, 808 const std::string& uri,
750 const std::string& body) const; 809 const std::string& body,
810 const std::map<std::string, std::string>& headers) const;
751 811
752 bool DoPut(const std::string& name, 812 bool DoPut(const std::string& name,
753 const std::string& uri, 813 const std::string& uri,
754 const std::string& body) const; 814 const std::string& body,
815 const std::map<std::string, std::string>& headers) const;
755 816
756 bool DoDelete(size_t index, 817 bool DoDelete(size_t index,
757 const std::string& uri) const; 818 const std::string& uri,
819 const std::map<std::string, std::string>& headers) const;
758 820
759 bool DoDelete(const std::string& name, 821 bool DoDelete(const std::string& name,
760 const std::string& uri) const; 822 const std::string& uri,
823 const std::map<std::string, std::string>& headers) const;
761 }; 824 };
762 #endif 825 #endif
763 826
764 827
765 828
775 838
776 static void CallbackFinalize(void* job); 839 static void CallbackFinalize(void* job);
777 840
778 static float CallbackGetProgress(void* job); 841 static float CallbackGetProgress(void* job);
779 842
843 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3)
844 static OrthancPluginErrorCode CallbackGetContent(OrthancPluginMemoryBuffer* target,
845 void* job);
846 #else
780 static const char* CallbackGetContent(void* job); 847 static const char* CallbackGetContent(void* job);
781 848 #endif
849
850 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3)
851 static int32_t CallbackGetSerialized(OrthancPluginMemoryBuffer* target,
852 void* job);
853 #else
782 static const char* CallbackGetSerialized(void* job); 854 static const char* CallbackGetSerialized(void* job);
855 #endif
783 856
784 static OrthancPluginJobStepStatus CallbackStep(void* job); 857 static OrthancPluginJobStepStatus CallbackStep(void* job);
785 858
786 static OrthancPluginErrorCode CallbackStop(void* job, 859 static OrthancPluginErrorCode CallbackStop(void* job,
787 OrthancPluginJobStopReason reason); 860 OrthancPluginJobStopReason reason);
1244 static DicomInstance* Transcode(const void* buffer, 1317 static DicomInstance* Transcode(const void* buffer,
1245 size_t size, 1318 size_t size,
1246 const std::string& transferSyntax); 1319 const std::string& transferSyntax);
1247 #endif 1320 #endif
1248 }; 1321 };
1322
1323 // helper method to convert Http headers from the plugin SDK to a std::map
1324 void GetHttpHeaders(std::map<std::string, std::string>& result, const OrthancPluginHttpRequest* request);
1325
1326 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
1327 class IWebDavCollection : public boost::noncopyable
1328 {
1329 public:
1330 class FileInfo
1331 {
1332 private:
1333 std::string name_;
1334 uint64_t contentSize_;
1335 std::string mime_;
1336 std::string dateTime_;
1337
1338 public:
1339 FileInfo(const std::string& name,
1340 uint64_t contentSize,
1341 const std::string& dateTime) :
1342 name_(name),
1343 contentSize_(contentSize),
1344 dateTime_(dateTime)
1345 {
1346 }
1347
1348 const std::string& GetName() const
1349 {
1350 return name_;
1351 }
1352
1353 uint64_t GetContentSize() const
1354 {
1355 return contentSize_;
1356 }
1357
1358 void SetMimeType(const std::string& mime)
1359 {
1360 mime_ = mime;
1361 }
1362
1363 const std::string& GetMimeType() const
1364 {
1365 return mime_;
1366 }
1367
1368 const std::string& GetDateTime() const
1369 {
1370 return dateTime_;
1371 }
1372 };
1373
1374 class FolderInfo
1375 {
1376 private:
1377 std::string name_;
1378 std::string dateTime_;
1379
1380 public:
1381 FolderInfo(const std::string& name,
1382 const std::string& dateTime) :
1383 name_(name),
1384 dateTime_(dateTime)
1385 {
1386 }
1387
1388 const std::string& GetName() const
1389 {
1390 return name_;
1391 }
1392
1393 const std::string& GetDateTime() const
1394 {
1395 return dateTime_;
1396 }
1397 };
1398
1399 virtual ~IWebDavCollection()
1400 {
1401 }
1402
1403 virtual bool IsExistingFolder(const std::vector<std::string>& path) = 0;
1404
1405 virtual bool ListFolder(std::list<FileInfo>& files,
1406 std::list<FolderInfo>& subfolders,
1407 const std::vector<std::string>& path) = 0;
1408
1409 virtual bool GetFile(std::string& content /* out */,
1410 std::string& mime /* out */,
1411 std::string& dateTime /* out */,
1412 const std::vector<std::string>& path) = 0;
1413
1414 virtual bool StoreFile(const std::vector<std::string>& path,
1415 const void* data,
1416 size_t size) = 0;
1417
1418 virtual bool CreateFolder(const std::vector<std::string>& path) = 0;
1419
1420 virtual bool DeleteItem(const std::vector<std::string>& path) = 0;
1421
1422 static void Register(const std::string& uri,
1423 IWebDavCollection& collection);
1424 };
1425 #endif
1249 } 1426 }