comparison Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 64:5fb01c588287

updated to Orthanc Framework 1.12.1
author Alain Mazy <am@osimis.io>
date Wed, 11 Oct 2023 15:58:27 +0200
parents 5915547fa6f2
children 1078942460cc
comparison
equal deleted inserted replaced
63:9789c6003e9d 64:5fb01c588287
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.
251 } 251 }
252 252
253 // helper class to convert std::map of headers to the plugin SDK C structure 253 // helper class to convert std::map of headers to the plugin SDK C structure
254 class PluginHttpHeaders 254 class PluginHttpHeaders
255 { 255 {
256 private:
256 std::vector<const char*> headersKeys_; 257 std::vector<const char*> headersKeys_;
257 std::vector<const char*> headersValues_; 258 std::vector<const char*> headersValues_;
259
258 public: 260 public:
259 261 explicit PluginHttpHeaders(const std::map<std::string, std::string>& httpHeaders)
260 PluginHttpHeaders(const std::map<std::string, std::string>& httpHeaders)
261 { 262 {
262 for (std::map<std::string, std::string>::const_iterator 263 for (std::map<std::string, std::string>::const_iterator
263 it = httpHeaders.begin(); it != httpHeaders.end(); it++) 264 it = httpHeaders.begin(); it != httpHeaders.end(); ++it)
264 { 265 {
265 headersKeys_.push_back(it->first.c_str()); 266 headersKeys_.push_back(it->first.c_str());
266 headersValues_.push_back(it->second.c_str()); 267 headersValues_.push_back(it->second.c_str());
267 } 268 }
268 } 269 }
748 { 749 {
749 configuration_ = Json::objectValue; 750 configuration_ = Json::objectValue;
750 } 751 }
751 } 752 }
752 753
754 OrthancConfiguration::OrthancConfiguration(const Json::Value& configuration, const std::string& path) :
755 configuration_(configuration),
756 path_(path)
757 {
758 }
759
753 760
754 std::string OrthancConfiguration::GetPath(const std::string& key) const 761 std::string OrthancConfiguration::GetPath(const std::string& key) const
755 { 762 {
756 if (path_.empty()) 763 if (path_.empty())
757 { 764 {
1103 } 1110 }
1104 1111
1105 if (configuration_[key].type() != Json::objectValue) 1112 if (configuration_[key].type() != Json::objectValue)
1106 { 1113 {
1107 LogError("The configuration option \"" + GetPath(key) + 1114 LogError("The configuration option \"" + GetPath(key) +
1108 "\" is not a string as expected"); 1115 "\" is not an object as expected");
1109 1116
1110 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 1117 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
1111 } 1118 }
1112 1119
1113 Json::Value::Members members = configuration_[key].getMemberNames(); 1120 Json::Value::Members members = configuration_[key].getMemberNames();
1448 answer.ToString(result); 1455 answer.ToString(result);
1449 return true; 1456 return true;
1450 } 1457 }
1451 } 1458 }
1452 1459
1460
1461 bool RestApiGet(Json::Value& result,
1462 const std::string& uri,
1463 const std::map<std::string, std::string>& httpHeaders,
1464 bool applyPlugins)
1465 {
1466 MemoryBuffer answer;
1467
1468 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins))
1469 {
1470 return false;
1471 }
1472 else
1473 {
1474 if (!answer.IsEmpty())
1475 {
1476 answer.ToJson(result);
1477 }
1478 return true;
1479 }
1480 }
1453 1481
1454 1482
1455 bool RestApiGet(Json::Value& result, 1483 bool RestApiGet(Json::Value& result,
1456 const std::string& uri, 1484 const std::string& uri,
1457 bool applyPlugins) 1485 bool applyPlugins)
1640 { 1668 {
1641 // Assume compatibility with the mainline 1669 // Assume compatibility with the mainline
1642 return true; 1670 return true;
1643 } 1671 }
1644 1672
1673 #ifdef _MSC_VER
1674 #define ORTHANC_SCANF sscanf_s
1675 #else
1676 #define ORTHANC_SCANF sscanf
1677 #endif
1678
1645 // Parse the version 1679 // Parse the version
1646 int aa, bb, cc; 1680 int aa, bb, cc = 0;
1647 if ( 1681 if ((ORTHANC_SCANF(version, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 &&
1648 #ifdef _MSC_VER 1682 ORTHANC_SCANF(version, "%4d.%4d", &aa, &bb) != 2) ||
1649 sscanf_s
1650 #else
1651 sscanf
1652 #endif
1653 (version, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 ||
1654 aa < 0 || 1683 aa < 0 ||
1655 bb < 0 || 1684 bb < 0 ||
1656 cc < 0) 1685 cc < 0)
1657 { 1686 {
1658 return false; 1687 return false;
3707 size_t size, 3736 size_t size,
3708 const std::string& transferSyntax) 3737 const std::string& transferSyntax)
3709 { 3738 {
3710 OrthancPluginDicomInstance* instance = OrthancPluginTranscodeDicomInstance( 3739 OrthancPluginDicomInstance* instance = OrthancPluginTranscodeDicomInstance(
3711 GetGlobalContext(), buffer, size, transferSyntax.c_str()); 3740 GetGlobalContext(), buffer, size, transferSyntax.c_str());
3741
3742 if (instance == NULL)
3743 {
3744 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
3745 }
3746 else
3747 {
3748 boost::movelib::unique_ptr<DicomInstance> result(new DicomInstance(instance));
3749 result->toFree_ = true;
3750 return result.release();
3751 }
3752 }
3753 #endif
3754
3755
3756 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 1)
3757 DicomInstance* DicomInstance::Load(const std::string& instanceId,
3758 OrthancPluginLoadDicomInstanceMode mode)
3759 {
3760 OrthancPluginDicomInstance* instance = OrthancPluginLoadDicomInstance(
3761 GetGlobalContext(), instanceId.c_str(), mode);
3712 3762
3713 if (instance == NULL) 3763 if (instance == NULL)
3714 { 3764 {
3715 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); 3765 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
3716 } 3766 }