feat: CalDAV foundation — HTTP methods and XML parser

Add PROPFIND and REPORT to HttpMethod enum for CalDAV protocol support.
Implement minimal XML parser (caldav_xml.hpp) for CalDAV response parsing:
namespaced tags, attributes, CDATA, entity references, self-closing elements.
Bounded by max depth and size to prevent allocation bombs.
This commit is contained in:
2026-07-23 19:48:38 +01:00
parent 3b73badf5d
commit 2dab5b97b6
6 changed files with 514 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
#pragma once
#include <cstddef>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
namespace nocal::sync {
// A parsed XML element.
struct XmlElement {
std::string tag;
std::vector<std::pair<std::string, std::string>> attributes;
std::string text;
std::string cdata;
std::vector<XmlElement> children;
};
// Parse an XML document string into a tree of XmlElement.
// Returns the root element. Throws std::runtime_error on parse failure.
// Bounded by max_size to prevent allocation bombs.
[[nodiscard]] XmlElement parse_xml(
std::string_view document, std::size_t max_size = 4 * 1024 * 1024);
// Find all children with the given tag name.
[[nodiscard]] std::vector<const XmlElement*> find_children(
const XmlElement& parent, std::string_view tag);
// Get first child text or empty string.
[[nodiscard]] std::string_view get_child_text(
const XmlElement& parent, std::string_view tag);
// Get attribute value or empty string.
[[nodiscard]] std::string_view get_attribute(
const XmlElement& elem, std::string_view name);
} // namespace nocal::sync

View File

@@ -5,7 +5,7 @@
namespace nocal::sync {
enum class HttpMethod { get, post, put, patch, delete_ };
enum class HttpMethod { get, post, put, patch, delete_, propfind, report };
struct HttpHeader {
std::string name;