ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
webdav.h File Reference

WebDAV wire format (RFC 4918): method classification, header parsing, and the 207 Multi-Status XML builder. More...

#include "protocore_config.h"

Go to the source code of this file.

Classes

struct  DavLock
 One active lock (RFC 4918 §6.4). More...
struct  DavLockTable
 The server-global lock table (one instance, not per-connection). More...
struct  WebdavNs
 Dispatch table. Addressed by offset, so the layout is asserted below. More...

Macros

#define PROTOCORE_DAV_DEPTH_INFINITY   0x7fffffff
 Depth: infinity sentinel (a lone constant).
#define PROTOCORE_DAV_LOCK_MAX   8
 Maximum concurrent locks (fixed - a small structural bound, not a per-board tunable).
#define PROTOCORE_DAV_LOCK_PATH_MAX   128
 Maximum locked-path length, including the NUL.
#define PROTOCORE_DAV_LOCK_TOKEN_MAX   48
 Maximum lock-token length, including the NUL (e.g. "opaquelocktoken:xxxxxxxx-pc").

Functions

 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.
 PROTOCORE_NS_LAYOUT (WebdavNs, method, depth, xml_escape, dest_path, ms_begin, ms_entry, ms_end, proppatch_ms, lock_init, lock_acquire, lock_sweep, lock_refresh, lock_find, lock_release, lock_can_write, if_token)
WebDavMethod protocore_webdav_method (const uint8_t *work, const char *m)
 Classify an HTTP method token (e.g. "PROPFIND") into a WebDavMethod.
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_xml_escape (const uint8_t *work, char *dst, size_t cap, const char *src)
 XML-escape src into dst (&, <, >, ", ').
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. .
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.
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.
size_t protocore_webdav_ms_end (const uint8_t *work, char *buf, size_t cap, size_t len)
 Close the <multistatus> element.
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).
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 .
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 .
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 .
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 .
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 .
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 .
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 .

Variables

PROTOCORE_NS WebdavNs Webdav PROTOCORE_UNUSED
 Module namespace.

Detailed Description

WebDAV wire format (RFC 4918): method classification, header parsing, and the 207 Multi-Status XML builder.

Mirrors the CoAP/SNMP split: this header declares the pure, host-testable core (no sockets, no filesystem - unit-tested in env:native_webdav). The filesystem-backed request handling (PROPFIND directory walk, PUT/MKCOL/DELETE/ COPY/MOVE, GET via the file-serving path) lives in server/io/webdav_handler.h and runs only on a build with a real filesystem.

Scope: class 1 (PROPFIND Depth 0/1, PROPPATCH, PUT, DELETE, MKCOL, COPY, MOVE) plus OPTIONS and class 2 LOCK/UNLOCK, now enforced by a small lock table (see the lock manager below): a locked resource rejects a write that does not present the matching token in its If header (423 Locked). PROPPATCH is answered 207 with every requested property refused 403 (read-only live properties, no dead-property store). The filesystem-backed handler streams a PUT body straight to the file (PC's stream-body hook), so uploads are not bounded by BODY_BUF_SIZE.

work is bytes the CALLER holds. This module reads none of them: it carries nothing between calls, so there is no state to keep and nothing to wipe. The parameter is there so a caller drives every namespace the same way.

Definition in file webdav.h.

Macro Definition Documentation

◆ PROTOCORE_DAV_DEPTH_INFINITY

#define PROTOCORE_DAV_DEPTH_INFINITY   0x7fffffff

Depth: infinity sentinel (a lone constant).

Definition at line 40 of file webdav.h.

◆ PROTOCORE_DAV_LOCK_MAX

#define PROTOCORE_DAV_LOCK_MAX   8

Maximum concurrent locks (fixed - a small structural bound, not a per-board tunable).

Definition at line 43 of file webdav.h.

◆ PROTOCORE_DAV_LOCK_PATH_MAX

#define PROTOCORE_DAV_LOCK_PATH_MAX   128

Maximum locked-path length, including the NUL.

Definition at line 46 of file webdav.h.

◆ PROTOCORE_DAV_LOCK_TOKEN_MAX

#define PROTOCORE_DAV_LOCK_TOKEN_MAX   48

Maximum lock-token length, including the NUL (e.g. "opaquelocktoken:xxxxxxxx-pc").

Definition at line 49 of file webdav.h.

Function Documentation

◆ EMBED_ENUM_BYTE()

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.

◆ PROTOCORE_NS_LAYOUT()

PROTOCORE_NS_LAYOUT ( WebdavNs ,
method ,
depth ,
xml_escape ,
dest_path ,
ms_begin ,
ms_entry ,
ms_end ,
proppatch_ms ,
lock_init ,
lock_acquire ,
lock_sweep ,
lock_refresh ,
lock_find ,
lock_release ,
lock_can_write ,
if_token  )

◆ protocore_webdav_method()

WebDavMethod protocore_webdav_method ( const uint8_t * work,
const char * m )

Classify an HTTP method token (e.g. "PROPFIND") into a WebDavMethod.

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
mM
Returns
The WebDavMethod.

◆ protocore_webdav_depth()

int protocore_webdav_depth ( const uint8_t * work,
const char * depth_hdr,
int dflt )

Parse a Depth header value ("0", "1", or "infinity").

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
depth_hdrDepth hdr
dfltDflt
Returns
The int.

◆ protocore_webdav_xml_escape()

size_t protocore_webdav_xml_escape ( const uint8_t * work,
char * dst,
size_t cap,
const char * src )

XML-escape src into dst (&, <, >, ", ').

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
dstDst
capCap
srcSrc
Returns
The size_t.

◆ protocore_webdav_dest_path()

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. .

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
destinationDestination
outOut
capCap
Returns
EMBED_TRUE on success.

◆ protocore_webdav_ms_begin()

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.

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
lenLen
Returns
The size_t.

◆ protocore_webdav_ms_entry()

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.

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
lenLen
hrefthe resource's URL path (XML-escaped here)
is_collectiontrue for a directory (emits <collection>)
sizecontent length (files only)
rfc1123_mtimeLast-Modified string, or "" to omit
content_typeMIME type (files only), or "" to omit
Returns
The size_t.

◆ protocore_webdav_ms_end()

size_t protocore_webdav_ms_end ( const uint8_t * work,
char * buf,
size_t cap,
size_t len )

Close the <multistatus> element.

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
bufBuf
capCap
lenLen
Returns
The size_t.

◆ protocore_webdav_proppatch_ms()

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 .

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
bufdestination buffer (whole document, NUL-terminated)
capbuffer capacity
hrefthe resource path (XML-escaped here)
bodythe PROPPATCH request body (not required to be NUL-terminated)
body_lenlength of body
Returns
The size_t.

◆ protocore_webdav_lock_init()

void protocore_webdav_lock_init ( const uint8_t * work,
DavLockTable * t )

Reset a lock table (no locks held).

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
tT

◆ protocore_webdav_lock_acquire()

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 .

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
tT
pathPath
tokenToken
exclusiveExclusive
depth_infinityDepth infinity
expiry_sthe monotonic second the lock expires (0 = no timeout); protocore_dav_lock_sweep drops a
Returns
The const DavLock *.

◆ protocore_webdav_lock_sweep()

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 .

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
tT
now_sthe caller's current monotonic second
Returns
The size_t.

◆ protocore_webdav_lock_refresh()

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 .

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
tT
tokenToken
new_expiry_sNew expiry s
Returns
The const DavLock *.

◆ protocore_webdav_lock_find()

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 .

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
tT
pathPath
Returns
The const DavLock *.

◆ protocore_webdav_lock_release()

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 .

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
tT
tokenToken
Returns
EMBED_TRUE on success.

◆ protocore_webdav_lock_can_write()

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 .

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
tT
pathPath
presented_tokenPresented token
Returns
EMBED_TRUE on success.

◆ protocore_webdav_if_token()

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 .

Parameters
workPROTOCORE_WEBDAV_BORROW bytes the caller took. Not held past the call.
if_headerIf header
outOut
capCap
Returns
EMBED_TRUE on success.

Variable Documentation

◆ PROTOCORE_UNUSED

PROTOCORE_NS WebdavNs Webdav PROTOCORE_UNUSED
Initial value:
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.
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. .
size_t protocore_webdav_xml_escape(const uint8_t *work, char *dst, size_t cap, const char *src)
XML-escape src into dst (&, <, >, ", ').
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 .

Module namespace.

Definition at line 252 of file webdav.h.