comparison OrthancServer/Plugins/Engine/OrthancPlugins.cpp @ 4330:a01b1c9cbef4

moving generic type definitions from IHttpHandler to HttpToolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Nov 2020 14:39:10 +0100
parents 9dc0e42f868b
children e1e918e790e8
comparison
equal deleted inserted replaced
4329:9dc0e42f868b 4330:a01b1c9cbef4
1493 } 1493 }
1494 1494
1495 1495
1496 static void ArgumentsToPlugin(std::vector<const char*>& keys, 1496 static void ArgumentsToPlugin(std::vector<const char*>& keys,
1497 std::vector<const char*>& values, 1497 std::vector<const char*>& values,
1498 const IHttpHandler::Arguments& arguments) 1498 const HttpToolbox::Arguments& arguments)
1499 { 1499 {
1500 keys.resize(arguments.size()); 1500 keys.resize(arguments.size());
1501 values.resize(arguments.size()); 1501 values.resize(arguments.size());
1502 1502
1503 size_t pos = 0; 1503 size_t pos = 0;
1504 for (IHttpHandler::Arguments::const_iterator 1504 for (HttpToolbox::Arguments::const_iterator
1505 it = arguments.begin(); it != arguments.end(); ++it) 1505 it = arguments.begin(); it != arguments.end(); ++it)
1506 { 1506 {
1507 keys[pos] = it->first.c_str(); 1507 keys[pos] = it->first.c_str();
1508 values[pos] = it->second.c_str(); 1508 values[pos] = it->second.c_str();
1509 pos++; 1509 pos++;
1511 } 1511 }
1512 1512
1513 1513
1514 static void ArgumentsToPlugin(std::vector<const char*>& keys, 1514 static void ArgumentsToPlugin(std::vector<const char*>& keys,
1515 std::vector<const char*>& values, 1515 std::vector<const char*>& values,
1516 const IHttpHandler::GetArguments& arguments) 1516 const HttpToolbox::GetArguments& arguments)
1517 { 1517 {
1518 keys.resize(arguments.size()); 1518 keys.resize(arguments.size());
1519 values.resize(arguments.size()); 1519 values.resize(arguments.size());
1520 1520
1521 for (size_t i = 0; i < arguments.size(); i++) 1521 for (size_t i = 0; i < arguments.size(); i++)
1599 OrthancPluginHttpRequest converted_; 1599 OrthancPluginHttpRequest converted_;
1600 1600
1601 public: 1601 public:
1602 HttpRequestConverter(const RestCallbackMatcher& matcher, 1602 HttpRequestConverter(const RestCallbackMatcher& matcher,
1603 HttpMethod method, 1603 HttpMethod method,
1604 const IHttpHandler::Arguments& headers) 1604 const HttpToolbox::Arguments& headers)
1605 { 1605 {
1606 memset(&converted_, 0, sizeof(OrthancPluginHttpRequest)); 1606 memset(&converted_, 0, sizeof(OrthancPluginHttpRequest));
1607 1607
1608 ArgumentsToPlugin(headersKeys_, headersValues_, headers); 1608 ArgumentsToPlugin(headersKeys_, headersValues_, headers);
1609 assert(headersKeys_.size() == headersValues_.size()); 1609 assert(headersKeys_.size() == headersValues_.size());
1644 converted_.headersKeys = &headersKeys_[0]; 1644 converted_.headersKeys = &headersKeys_[0];
1645 converted_.headersValues = &headersValues_[0]; 1645 converted_.headersValues = &headersValues_[0];
1646 } 1646 }
1647 } 1647 }
1648 1648
1649 void SetGetArguments(const IHttpHandler::GetArguments& getArguments) 1649 void SetGetArguments(const HttpToolbox::GetArguments& getArguments)
1650 { 1650 {
1651 ArgumentsToPlugin(getKeys_, getValues_, getArguments); 1651 ArgumentsToPlugin(getKeys_, getValues_, getArguments);
1652 assert(getKeys_.size() == getValues_.size()); 1652 assert(getKeys_.size() == getValues_.size());
1653 1653
1654 converted_.getCount = getArguments.size(); 1654 converted_.getCount = getArguments.size();
1712 1712
1713 1713
1714 bool OrthancPlugins::HandleChunkedGetDelete(HttpOutput& output, 1714 bool OrthancPlugins::HandleChunkedGetDelete(HttpOutput& output,
1715 HttpMethod method, 1715 HttpMethod method,
1716 const UriComponents& uri, 1716 const UriComponents& uri,
1717 const Arguments& headers, 1717 const HttpToolbox::Arguments& headers,
1718 const GetArguments& getArguments) 1718 const HttpToolbox::GetArguments& getArguments)
1719 { 1719 {
1720 RestCallbackMatcher matcher(uri); 1720 RestCallbackMatcher matcher(uri);
1721 1721
1722 PImpl::ChunkedRestCallback* callback = NULL; 1722 PImpl::ChunkedRestCallback* callback = NULL;
1723 1723
1784 RequestOrigin /*origin*/, 1784 RequestOrigin /*origin*/,
1785 const char* /*remoteIp*/, 1785 const char* /*remoteIp*/,
1786 const char* /*username*/, 1786 const char* /*username*/,
1787 HttpMethod method, 1787 HttpMethod method,
1788 const UriComponents& uri, 1788 const UriComponents& uri,
1789 const Arguments& headers, 1789 const HttpToolbox::Arguments& headers,
1790 const GetArguments& getArguments, 1790 const HttpToolbox::GetArguments& getArguments,
1791 const void* bodyData, 1791 const void* bodyData,
1792 size_t bodySize) 1792 size_t bodySize)
1793 { 1793 {
1794 RestCallbackMatcher matcher(uri); 1794 RestCallbackMatcher matcher(uri);
1795 1795
2415 *reinterpret_cast<const _OrthancPluginRestApiGet2*>(parameters); 2415 *reinterpret_cast<const _OrthancPluginRestApiGet2*>(parameters);
2416 2416
2417 CLOG(INFO, PLUGINS) << "Plugin making REST GET call on URI " << p.uri 2417 CLOG(INFO, PLUGINS) << "Plugin making REST GET call on URI " << p.uri
2418 << (p.afterPlugins ? " (after plugins)" : " (built-in API)"); 2418 << (p.afterPlugins ? " (after plugins)" : " (built-in API)");
2419 2419
2420 IHttpHandler::Arguments headers; 2420 HttpToolbox::Arguments headers;
2421 2421
2422 for (uint32_t i = 0; i < p.headersCount; i++) 2422 for (uint32_t i = 0; i < p.headersCount; i++)
2423 { 2423 {
2424 std::string name(p.headersKeys[i]); 2424 std::string name(p.headersKeys[i]);
2425 std::transform(name.begin(), name.end(), name.begin(), ::tolower); 2425 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
4899 4899
4900 bool OrthancPlugins::IsAllowed(HttpMethod method, 4900 bool OrthancPlugins::IsAllowed(HttpMethod method,
4901 const char* uri, 4901 const char* uri,
4902 const char* ip, 4902 const char* ip,
4903 const char* username, 4903 const char* username,
4904 const IHttpHandler::Arguments& httpHeaders, 4904 const HttpToolbox::Arguments& httpHeaders,
4905 const IHttpHandler::GetArguments& getArguments) 4905 const HttpToolbox::GetArguments& getArguments)
4906 { 4906 {
4907 OrthancPluginHttpMethod cMethod = Plugins::Convert(method); 4907 OrthancPluginHttpMethod cMethod = Plugins::Convert(method);
4908 4908
4909 std::vector<const char*> httpKeys(httpHeaders.size()); 4909 std::vector<const char*> httpKeys(httpHeaders.size());
4910 std::vector<const char*> httpValues(httpHeaders.size()); 4910 std::vector<const char*> httpValues(httpHeaders.size());
4911 4911
4912 size_t pos = 0; 4912 size_t pos = 0;
4913 for (IHttpHandler::Arguments::const_iterator 4913 for (HttpToolbox::Arguments::const_iterator
4914 it = httpHeaders.begin(); it != httpHeaders.end(); ++it, pos++) 4914 it = httpHeaders.begin(); it != httpHeaders.end(); ++it, pos++)
4915 { 4915 {
4916 httpKeys[pos] = it->first.c_str(); 4916 httpKeys[pos] = it->first.c_str();
4917 httpValues[pos] = it->second.c_str(); 4917 httpValues[pos] = it->second.c_str();
4918 } 4918 }
5069 RequestOrigin origin, 5069 RequestOrigin origin,
5070 const char* remoteIp, 5070 const char* remoteIp,
5071 const char* username, 5071 const char* username,
5072 HttpMethod method, 5072 HttpMethod method,
5073 const UriComponents& uri, 5073 const UriComponents& uri,
5074 const Arguments& headers) 5074 const HttpToolbox::Arguments& headers)
5075 { 5075 {
5076 if (method != HttpMethod_Post && 5076 if (method != HttpMethod_Post &&
5077 method != HttpMethod_Put) 5077 method != HttpMethod_Put)
5078 { 5078 {
5079 throw OrthancException(ErrorCode_InternalError); 5079 throw OrthancException(ErrorCode_InternalError);