4#ifndef PROTOCORE_WEBDAV_H
5#define PROTOCORE_WEBDAV_H
40#define PROTOCORE_DAV_DEPTH_INFINITY 0x7fffffff
43#define PROTOCORE_DAV_LOCK_MAX 8
46#define PROTOCORE_DAV_LOCK_PATH_MAX 128
49#define PROTOCORE_DAV_LOCK_TOKEN_MAX 48
52EMBED_ENUM_BYTE(WebDavMethod, DAV_M_OPTIONS, DAV_M_GET, DAV_M_HEAD, DAV_M_PUT, DAV_M_DELETE, DAV_M_PROPFIND,
53 DAV_M_PROPPATCH, DAV_M_MKCOL, DAV_M_COPY, DAV_M_MOVE, DAV_M_LOCK, DAV_M_UNLOCK,
77 WebDavMethod (*
method)(
const uint8_t *,
const char *);
78 int (*
depth)(
const uint8_t *,
const char *, int);
79 size_t (*
xml_escape)(
const uint8_t *,
char *, size_t,
const char *);
80 embed_bool (*
dest_path)(
const uint8_t *,
const char *,
char *, size_t);
81 size_t (*
ms_begin)(
const uint8_t *,
char *, size_t, size_t);
82 size_t (*
ms_entry)(
const uint8_t *,
char *, size_t, size_t,
const char *, embed_bool, uint32_t,
const char *,
84 size_t (*
ms_end)(
const uint8_t *,
char *, size_t, size_t);
85 size_t (*
proppatch_ms)(
const uint8_t *,
char *, size_t,
const char *,
const char *, size_t);
87 const DavLock *(*lock_acquire)(
const uint8_t *,
DavLockTable *,
const char *,
const char *, embed_bool, embed_bool,
94 embed_bool (*
if_token)(
const uint8_t *,
const char *,
char *, size_t);
96PROTOCORE_NS_LAYOUT(
WebdavNs, method, depth, xml_escape, dest_path, ms_begin, ms_entry, ms_end, proppatch_ms, lock_init,
97 lock_acquire, lock_sweep, lock_refresh, lock_find, lock_release, lock_can_write, if_token);
155 embed_bool is_collection, uint32_t size,
const char *rfc1123_mtime,
156 const char *content_type);
196 embed_bool exclusive, embed_bool depth_infinity, uint32_t expiry_s);
214 uint32_t new_expiry_s);
240 const char *presented_token);
#define PROTOCORE_UNUSED
Suppress the unused warning. Every module ends in a namespace most callers only partly use.
#define PROTOCORE_NS_LAYOUT(T,...)
Pin every dispatch slot of a table that is nothing but function pointers.
#define PROTOCORE_NS
Storage for a dispatch table. The const is load bearing.
The server-global lock table (one instance, not per-connection).
DavLock locks[PROTOCORE_DAV_LOCK_MAX]
One active lock (RFC 4918 §6.4).
embed_bool exclusive
exclusive-write (true) or shared (false)
uint32_t expiry_s
monotonic second the lock expires (0 = no timeout); swept by _sweep
embed_bool active
false = free slot
embed_bool depth_infinity
the lock covers the whole subtree (Depth: infinity) vs just the resource
char path[PROTOCORE_DAV_LOCK_PATH_MAX]
the locked resource path (trailing slash normalized off)
char token[PROTOCORE_DAV_LOCK_TOKEN_MAX]
the lock token (an opaquelocktoken URI)
Dispatch table. Addressed by offset, so the layout is asserted below.
size_t(* ms_entry)(const uint8_t *, char *, size_t, size_t, const char *, embed_bool, uint32_t, const char *, const char *)
int(* depth)(const uint8_t *, const char *, int)
size_t(* ms_end)(const uint8_t *, char *, size_t, size_t)
embed_bool(* dest_path)(const uint8_t *, const char *, char *, size_t)
size_t(* proppatch_ms)(const uint8_t *, char *, size_t, const char *, const char *, size_t)
size_t(* xml_escape)(const uint8_t *, char *, size_t, const char *)
embed_bool(* if_token)(const uint8_t *, const char *, char *, size_t)
embed_bool(* lock_can_write)(const uint8_t *, const DavLockTable *, const char *, const char *)
WebDavMethod(* method)(const uint8_t *, const char *)
void(* lock_init)(const uint8_t *, DavLockTable *)
embed_bool(* lock_release)(const uint8_t *, DavLockTable *, const char *)
size_t(* ms_begin)(const uint8_t *, char *, size_t, size_t)
size_t(* lock_sweep)(const uint8_t *, DavLockTable *, uint32_t)
size_t protocore_webdav_lock_sweep(const uint8_t *work, DavLockTable *t, uint32_t now_s)
Expire and drop every lock whose timeout passed (RFC 4918 .
size_t protocore_webdav_ms_end(const uint8_t *work, char *buf, size_t cap, size_t len)
Close the <multistatus> element.
const DavLock * protocore_webdav_lock_find(const uint8_t *work, const DavLockTable *t, const char *path)
Find a lock covering path: one on path itself, or a Depth-infinity .
const DavLock * protocore_webdav_lock_refresh(const uint8_t *work, DavLockTable *t, const char *token, uint32_t new_expiry_s)
Refresh a held lock's timeout to new_expiry_s, keyed by token (a .
int protocore_webdav_depth(const uint8_t *work, const char *depth_hdr, int dflt)
Parse a Depth header value ("0", "1", or "infinity").
size_t protocore_webdav_ms_begin(const uint8_t *work, char *buf, size_t cap, size_t len)
Write the XML prolog and the open <multistatus> element.
#define PROTOCORE_DAV_LOCK_PATH_MAX
Maximum locked-path length, including the NUL.
embed_bool protocore_webdav_lock_can_write(const uint8_t *work, const DavLockTable *t, const char *path, const char *presented_token)
May a write to path proceed given the token the request presented .
WebDavMethod protocore_webdav_method(const uint8_t *work, const char *m)
Classify an HTTP method token (e.g. "PROPFIND") into a WebDavMethod.
embed_bool protocore_webdav_if_token(const uint8_t *work, const char *if_header, char *out, size_t cap)
Extract the first lock token from an If header value (RFC 4918 .
embed_bool protocore_webdav_dest_path(const uint8_t *work, const char *destination, char *out, size_t cap)
Extract and percent-decode the path of a Destination header. .
#define PROTOCORE_DAV_LOCK_TOKEN_MAX
Maximum lock-token length, including the NUL (e.g. "opaquelocktoken:xxxxxxxx-pc").
size_t protocore_webdav_xml_escape(const uint8_t *work, char *dst, size_t cap, const char *src)
XML-escape src into dst (&, <, >, ", ').
EMBED_ENUM_BYTE(WebDavMethod, DAV_M_OPTIONS, DAV_M_GET, DAV_M_HEAD, DAV_M_PUT, DAV_M_DELETE, DAV_M_PROPFIND, DAV_M_PROPPATCH, DAV_M_MKCOL, DAV_M_COPY, DAV_M_MOVE, DAV_M_LOCK, DAV_M_UNLOCK, DAV_M_UNSUPPORTED)
WebDAV request methods recognized by the server.
#define PROTOCORE_DAV_LOCK_MAX
Maximum concurrent locks (fixed - a small structural bound, not a per-board tunable).
size_t protocore_webdav_proppatch_ms(const uint8_t *work, char *buf, size_t cap, const char *href, const char *body, size_t body_len)
Build a complete 207 Multi-Status body answering a PROPPATCH. The .
void protocore_webdav_lock_init(const uint8_t *work, DavLockTable *t)
Reset a lock table (no locks held).
size_t protocore_webdav_ms_entry(const uint8_t *work, char *buf, size_t cap, size_t len, const char *href, embed_bool is_collection, uint32_t size, const char *rfc1123_mtime, const char *content_type)
Append one <response> describing a resource.
embed_bool protocore_webdav_lock_release(const uint8_t *work, DavLockTable *t, const char *token)
Release the lock whose token equals token (UNLOCK). true if one was .
const DavLock * protocore_webdav_lock_acquire(const uint8_t *work, DavLockTable *t, const char *path, const char *token, embed_bool exclusive, embed_bool depth_infinity, uint32_t expiry_s)
Acquire a lock on path with the caller-supplied token (RFC 4918 .