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:
38
include/nocal/sync/caldav_xml.hpp
Normal file
38
include/nocal/sync/caldav_xml.hpp
Normal 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
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user