diff --git a/Src/IACore/imp/cpp/HttpClient.cpp b/Src/IACore/imp/cpp/HttpClient.cpp index 1597969..d304d85 100644 --- a/Src/IACore/imp/cpp/HttpClient.cpp +++ b/Src/IACore/imp/cpp/HttpClient.cpp @@ -27,10 +27,9 @@ namespace IACore for (const auto &h : headers) { - std::string key = HttpClient::HeaderTypeToString(h.first); - out.emplace(key, h.second); + out.emplace(h.first, h.second); - if (h.first == HttpClient::EHeaderType::CONTENT_TYPE) + if (h.first == HttpClient::HeaderTypeToString(HttpClient::EHeaderType::CONTENT_TYPE)) hasContentType = true; } @@ -132,11 +131,6 @@ namespace IACore namespace IACore { - HttpClient::Header HttpClient::CreateHeader(IN EHeaderType key, IN CONST String &value) - { - return std::make_pair(key, value); - } - String HttpClient::UrlEncode(IN CONST String &value) { std::stringstream escaped; diff --git a/Src/IACore/imp/cpp/XML.cpp b/Src/IACore/imp/cpp/XML.cpp new file mode 100644 index 0000000..6f16c26 --- /dev/null +++ b/Src/IACore/imp/cpp/XML.cpp @@ -0,0 +1,51 @@ +// IACore-OSS; The Core Library for All IA Open Source Projects +// Copyright (C) 2025 IAS (ias@iasoft.dev) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +namespace IACore +{ + Expected XML::ParseFromString(IN CONST String &data) + { + Document doc; + const auto parseResult = doc.load_string(data.data()); + if (!parseResult) + return MakeUnexpected(std::format("Failed to parse XML: {}", parseResult.description())); + return IA_MOVE(doc); + } + + Expected XML::ParseFromFile(IN CONST FilePath &path) + { + Document doc; + const auto parseResult = doc.load_file(path.string().c_str()); + if (!parseResult) + return MakeUnexpected(std::format("Failed to parse XML: {}", parseResult.description())); + return IA_MOVE(doc); + } + + String XML::SerializeToString(IN CONST Node &node) + { + std::ostringstream oss; + node.print(oss); + return oss.str(); + } + + String XML::SerializeToString(IN CONST Document &doc) + { + std::ostringstream oss; + doc.save(oss); + return oss.str(); + } +} // namespace IACore \ No newline at end of file diff --git a/Src/IACore/inc/IACore/HttpClient.hpp b/Src/IACore/inc/IACore/HttpClient.hpp index 684c3fe..20dfee0 100644 --- a/Src/IACore/inc/IACore/HttpClient.hpp +++ b/Src/IACore/inc/IACore/HttpClient.hpp @@ -127,7 +127,7 @@ namespace IACore NETWORK_AUTHENTICATION_REQUIRED = 511 }; - using Header = KeyValuePair; + using Header = KeyValuePair; public: HttpClient(IN CONST String &host); @@ -151,7 +151,9 @@ namespace IACore STATIC String UrlDecode(IN CONST String &value); STATIC String HeaderTypeToString(IN EHeaderType type); - STATIC Header CreateHeader(IN EHeaderType key, IN CONST String &value); + + STATIC INLINE Header CreateHeader(IN EHeaderType key, IN CONST String &value); + STATIC INLINE Header CreateHeader(IN CONST String &key, IN CONST String &value); STATIC BOOL IsSuccessResponseCode(IN EResponseCode code); @@ -192,4 +194,14 @@ namespace IACore return MakeUnexpected(std::format("Server responded with code {}", (INT32) LastResponseCode())); return JSON::ParseToStruct<_response_type>(*rawResponse); } + + HttpClient::Header HttpClient::CreateHeader(IN EHeaderType key, IN CONST String &value) + { + return std::make_pair(HeaderTypeToString(key), value); + } + + HttpClient::Header HttpClient::CreateHeader(IN CONST String &key, IN CONST String &value) + { + return std::make_pair(key, value); + } } // namespace IACore \ No newline at end of file diff --git a/Src/IACore/inc/IACore/XML.hpp b/Src/IACore/inc/IACore/XML.hpp new file mode 100644 index 0000000..bff6c05 --- /dev/null +++ b/Src/IACore/inc/IACore/XML.hpp @@ -0,0 +1,37 @@ +// IACore-OSS; The Core Library for All IA Open Source Projects +// Copyright (C) 2025 IAS (ias@iasoft.dev) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include + +namespace IACore +{ + class XML + { + public: + using Node = pugi::xml_node; + using Document = pugi::xml_document; + + public: + STATIC Expected ParseFromString(IN CONST String &data); + STATIC Expected ParseFromFile(IN CONST FilePath &path); + + STATIC String SerializeToString(IN CONST Node &node); + STATIC String SerializeToString(IN CONST Document &doc); + }; +} // namespace IACore \ No newline at end of file