Mercurial > hg > orthanc-transfers
comparison Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 44:f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 19 Oct 2022 21:12:57 +0200 |
parents | 1256194e1c08 |
children | 5915547fa6f2 |
comparison
equal
deleted
inserted
replaced
43:c3fefbb11321 | 44:f4e828607f02 |
---|---|
1883 } | 1883 } |
1884 | 1884 |
1885 | 1885 |
1886 bool OrthancPeers::DoGet(MemoryBuffer& target, | 1886 bool OrthancPeers::DoGet(MemoryBuffer& target, |
1887 size_t index, | 1887 size_t index, |
1888 const std::string& uri) const | 1888 const std::string& uri, |
1889 const std::map<std::string, std::string>& headers) const | |
1889 { | 1890 { |
1890 if (index >= index_.size()) | 1891 if (index >= index_.size()) |
1891 { | 1892 { |
1892 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | 1893 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
1893 } | 1894 } |
1894 | 1895 |
1895 OrthancPlugins::MemoryBuffer answer; | 1896 OrthancPlugins::MemoryBuffer answer; |
1896 uint16_t status; | 1897 uint16_t status; |
1898 PluginHttpHeaders pluginHeaders(headers); | |
1899 | |
1897 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 1900 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
1898 (GetGlobalContext(), *answer, NULL, &status, peers_, | 1901 (GetGlobalContext(), *answer, NULL, &status, peers_, |
1899 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(), | 1902 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(), |
1900 0, NULL, NULL, NULL, 0, timeout_); | 1903 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), NULL, 0, timeout_); |
1901 | 1904 |
1902 if (code == OrthancPluginErrorCode_Success) | 1905 if (code == OrthancPluginErrorCode_Success) |
1903 { | 1906 { |
1904 target.Swap(answer); | 1907 target.Swap(answer); |
1905 return (status == 200); | 1908 return (status == 200); |
1911 } | 1914 } |
1912 | 1915 |
1913 | 1916 |
1914 bool OrthancPeers::DoGet(MemoryBuffer& target, | 1917 bool OrthancPeers::DoGet(MemoryBuffer& target, |
1915 const std::string& name, | 1918 const std::string& name, |
1916 const std::string& uri) const | 1919 const std::string& uri, |
1920 const std::map<std::string, std::string>& headers) const | |
1917 { | 1921 { |
1918 size_t index; | 1922 size_t index; |
1919 return (LookupName(index, name) && | 1923 return (LookupName(index, name) && |
1920 DoGet(target, index, uri)); | 1924 DoGet(target, index, uri, headers)); |
1921 } | 1925 } |
1922 | 1926 |
1923 | 1927 |
1924 bool OrthancPeers::DoGet(Json::Value& target, | 1928 bool OrthancPeers::DoGet(Json::Value& target, |
1925 size_t index, | 1929 size_t index, |
1926 const std::string& uri) const | 1930 const std::string& uri, |
1931 const std::map<std::string, std::string>& headers) const | |
1927 { | 1932 { |
1928 MemoryBuffer buffer; | 1933 MemoryBuffer buffer; |
1929 | 1934 |
1930 if (DoGet(buffer, index, uri)) | 1935 if (DoGet(buffer, index, uri, headers)) |
1931 { | 1936 { |
1932 buffer.ToJson(target); | 1937 buffer.ToJson(target); |
1933 return true; | 1938 return true; |
1934 } | 1939 } |
1935 else | 1940 else |
1939 } | 1944 } |
1940 | 1945 |
1941 | 1946 |
1942 bool OrthancPeers::DoGet(Json::Value& target, | 1947 bool OrthancPeers::DoGet(Json::Value& target, |
1943 const std::string& name, | 1948 const std::string& name, |
1944 const std::string& uri) const | 1949 const std::string& uri, |
1950 const std::map<std::string, std::string>& headers) const | |
1945 { | 1951 { |
1946 MemoryBuffer buffer; | 1952 MemoryBuffer buffer; |
1947 | 1953 |
1948 if (DoGet(buffer, name, uri)) | 1954 if (DoGet(buffer, name, uri, headers)) |
1949 { | 1955 { |
1950 buffer.ToJson(target); | 1956 buffer.ToJson(target); |
1951 return true; | 1957 return true; |
1952 } | 1958 } |
1953 else | 1959 else |
1958 | 1964 |
1959 | 1965 |
1960 bool OrthancPeers::DoPost(MemoryBuffer& target, | 1966 bool OrthancPeers::DoPost(MemoryBuffer& target, |
1961 const std::string& name, | 1967 const std::string& name, |
1962 const std::string& uri, | 1968 const std::string& uri, |
1963 const std::string& body) const | 1969 const std::string& body, |
1970 const std::map<std::string, std::string>& headers) const | |
1964 { | 1971 { |
1965 size_t index; | 1972 size_t index; |
1966 return (LookupName(index, name) && | 1973 return (LookupName(index, name) && |
1967 DoPost(target, index, uri, body)); | 1974 DoPost(target, index, uri, body, headers)); |
1968 } | 1975 } |
1969 | 1976 |
1970 | 1977 |
1971 bool OrthancPeers::DoPost(Json::Value& target, | 1978 bool OrthancPeers::DoPost(Json::Value& target, |
1972 size_t index, | 1979 size_t index, |
1973 const std::string& uri, | 1980 const std::string& uri, |
1974 const std::string& body) const | 1981 const std::string& body, |
1982 const std::map<std::string, std::string>& headers) const | |
1975 { | 1983 { |
1976 MemoryBuffer buffer; | 1984 MemoryBuffer buffer; |
1977 | 1985 |
1978 if (DoPost(buffer, index, uri, body)) | 1986 if (DoPost(buffer, index, uri, body, headers)) |
1979 { | 1987 { |
1980 buffer.ToJson(target); | 1988 buffer.ToJson(target); |
1981 return true; | 1989 return true; |
1982 } | 1990 } |
1983 else | 1991 else |
1988 | 1996 |
1989 | 1997 |
1990 bool OrthancPeers::DoPost(Json::Value& target, | 1998 bool OrthancPeers::DoPost(Json::Value& target, |
1991 const std::string& name, | 1999 const std::string& name, |
1992 const std::string& uri, | 2000 const std::string& uri, |
1993 const std::string& body) const | 2001 const std::string& body, |
2002 const std::map<std::string, std::string>& headers) const | |
1994 { | 2003 { |
1995 MemoryBuffer buffer; | 2004 MemoryBuffer buffer; |
1996 | 2005 |
1997 if (DoPost(buffer, name, uri, body)) | 2006 if (DoPost(buffer, name, uri, body, headers)) |
1998 { | 2007 { |
1999 buffer.ToJson(target); | 2008 buffer.ToJson(target); |
2000 return true; | 2009 return true; |
2001 } | 2010 } |
2002 else | 2011 else |
2007 | 2016 |
2008 | 2017 |
2009 bool OrthancPeers::DoPost(MemoryBuffer& target, | 2018 bool OrthancPeers::DoPost(MemoryBuffer& target, |
2010 size_t index, | 2019 size_t index, |
2011 const std::string& uri, | 2020 const std::string& uri, |
2012 const std::string& body) const | 2021 const std::string& body, |
2022 const std::map<std::string, std::string>& headers) const | |
2013 { | 2023 { |
2014 if (index >= index_.size()) | 2024 if (index >= index_.size()) |
2015 { | 2025 { |
2016 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | 2026 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
2017 } | 2027 } |
2022 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | 2032 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
2023 } | 2033 } |
2024 | 2034 |
2025 OrthancPlugins::MemoryBuffer answer; | 2035 OrthancPlugins::MemoryBuffer answer; |
2026 uint16_t status; | 2036 uint16_t status; |
2037 PluginHttpHeaders pluginHeaders(headers); | |
2038 | |
2027 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 2039 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
2028 (GetGlobalContext(), *answer, NULL, &status, peers_, | 2040 (GetGlobalContext(), *answer, NULL, &status, peers_, |
2029 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(), | 2041 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(), |
2030 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); | 2042 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
2031 | 2043 |
2032 if (code == OrthancPluginErrorCode_Success) | 2044 if (code == OrthancPluginErrorCode_Success) |
2033 { | 2045 { |
2034 target.Swap(answer); | 2046 target.Swap(answer); |
2035 return (status == 200); | 2047 return (status == 200); |
2041 } | 2053 } |
2042 | 2054 |
2043 | 2055 |
2044 bool OrthancPeers::DoPut(size_t index, | 2056 bool OrthancPeers::DoPut(size_t index, |
2045 const std::string& uri, | 2057 const std::string& uri, |
2046 const std::string& body) const | 2058 const std::string& body, |
2059 const std::map<std::string, std::string>& headers) const | |
2047 { | 2060 { |
2048 if (index >= index_.size()) | 2061 if (index >= index_.size()) |
2049 { | 2062 { |
2050 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | 2063 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
2051 } | 2064 } |
2056 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | 2069 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
2057 } | 2070 } |
2058 | 2071 |
2059 OrthancPlugins::MemoryBuffer answer; | 2072 OrthancPlugins::MemoryBuffer answer; |
2060 uint16_t status; | 2073 uint16_t status; |
2074 PluginHttpHeaders pluginHeaders(headers); | |
2075 | |
2061 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 2076 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
2062 (GetGlobalContext(), *answer, NULL, &status, peers_, | 2077 (GetGlobalContext(), *answer, NULL, &status, peers_, |
2063 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), | 2078 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), |
2064 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); | 2079 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
2065 | 2080 |
2066 if (code == OrthancPluginErrorCode_Success) | 2081 if (code == OrthancPluginErrorCode_Success) |
2067 { | 2082 { |
2068 return (status == 200); | 2083 return (status == 200); |
2069 } | 2084 } |
2074 } | 2089 } |
2075 | 2090 |
2076 | 2091 |
2077 bool OrthancPeers::DoPut(const std::string& name, | 2092 bool OrthancPeers::DoPut(const std::string& name, |
2078 const std::string& uri, | 2093 const std::string& uri, |
2079 const std::string& body) const | 2094 const std::string& body, |
2095 const std::map<std::string, std::string>& headers) const | |
2080 { | 2096 { |
2081 size_t index; | 2097 size_t index; |
2082 return (LookupName(index, name) && | 2098 return (LookupName(index, name) && |
2083 DoPut(index, uri, body)); | 2099 DoPut(index, uri, body, headers)); |
2084 } | 2100 } |
2085 | 2101 |
2086 | 2102 |
2087 bool OrthancPeers::DoDelete(size_t index, | 2103 bool OrthancPeers::DoDelete(size_t index, |
2088 const std::string& uri) const | 2104 const std::string& uri, |
2105 const std::map<std::string, std::string>& headers) const | |
2089 { | 2106 { |
2090 if (index >= index_.size()) | 2107 if (index >= index_.size()) |
2091 { | 2108 { |
2092 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | 2109 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
2093 } | 2110 } |
2094 | 2111 |
2095 OrthancPlugins::MemoryBuffer answer; | 2112 OrthancPlugins::MemoryBuffer answer; |
2096 uint16_t status; | 2113 uint16_t status; |
2114 PluginHttpHeaders pluginHeaders(headers); | |
2115 | |
2097 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | 2116 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
2098 (GetGlobalContext(), *answer, NULL, &status, peers_, | 2117 (GetGlobalContext(), *answer, NULL, &status, peers_, |
2099 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(), | 2118 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(), |
2100 0, NULL, NULL, NULL, 0, timeout_); | 2119 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), NULL, 0, timeout_); |
2101 | 2120 |
2102 if (code == OrthancPluginErrorCode_Success) | 2121 if (code == OrthancPluginErrorCode_Success) |
2103 { | 2122 { |
2104 return (status == 200); | 2123 return (status == 200); |
2105 } | 2124 } |
2109 } | 2128 } |
2110 } | 2129 } |
2111 | 2130 |
2112 | 2131 |
2113 bool OrthancPeers::DoDelete(const std::string& name, | 2132 bool OrthancPeers::DoDelete(const std::string& name, |
2114 const std::string& uri) const | 2133 const std::string& uri, |
2134 const std::map<std::string, std::string>& headers) const | |
2115 { | 2135 { |
2116 size_t index; | 2136 size_t index; |
2117 return (LookupName(index, name) && | 2137 return (LookupName(index, name) && |
2118 DoDelete(index, uri)); | 2138 DoDelete(index, uri, headers)); |
2119 } | 2139 } |
2120 #endif | 2140 #endif |
2121 | 2141 |
2122 | 2142 |
2123 | 2143 |