ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
upload_service.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4#ifndef PROTOCORE_UPLOAD_SERVICE_H
5#define PROTOCORE_UPLOAD_SERVICE_H
6
7#include "protocore_config.h" // the entry point: protocore_types.h for the widths
8
10
11/**
12 * @file upload_service.h
13 * @brief Streaming file upload to an Arduino FS (PROTOCORE_ENABLE_UPLOAD).
14 *
15 * Registers a POST route whose request body is streamed straight into a file on
16 * a filesystem (LittleFS / SPIFFS / SD) in FILE_CHUNK_SIZE pieces - the upload
17 * never has to fit in RAM. Reuses the parser's streaming-body hook (the same
18 * mechanism OTA uses), so it is zero-heap and bounded.
19 *
20 * One upload at a time (the device runs a single loop task). Only one streaming
21 * sink can be installed, so PROTOCORE_ENABLE_UPLOAD and PROTOCORE_ENABLE_OTA share the
22 * parser hook - register whichever you need (not both on the same build).
23 *
24 * @c work is PROTOCORE_UPLOAD_SERVICE_BORROW bytes the CALLER took, at an address it knows. It is not held past the
25 * call, so nothing here aliases it. How those bytes are carved is this module's and is never named here.
26 */
27
28/** @brief Dispatch table. Addressed by offset, so the layout is asserted below. */
29typedef struct
30{
31 void (*begin)(uint8_t *, const char *, const char *);
32 size_t (*last_size)(uint8_t *);
35
36/**
37 * @brief Register a streaming-upload endpoint. A `POST path` request streams .
38 * @param work PROTOCORE_UPLOAD_SERVICE_BORROW bytes the caller took. Not held past the call.
39 * @param path the upload URL (e.g. "/upload")
40 * @param dest_path destination file path (e.g. "/uploads/data.bin")
41 */
42void protocore_upload_service_begin(uint8_t *work, const char *path, const char *dest_path);
43/**
44 * @brief Bytes written by the most recent upload (for handlers / tests).
45 * @param work PROTOCORE_UPLOAD_SERVICE_BORROW bytes the caller took. Not held past the call.
46 * @return The size_t.
47 */
49
50/**
51 * @brief The PROTOCORE_UPLOAD_SERVICE_BORROW bytes this module's state lives in.
52 *
53 * Stated beside the namespace rather than on it: an entry takes a borrow, and this is where
54 * that borrow comes from. Taken once from the end of the pool, which no mark and no release
55 * walks, so the state lasts the life of the program.
56 *
57 * @return the span.
58 */
60
61/** @brief Module namespace. */
64
66
67#endif // PROTOCORE_UPLOAD_SERVICE_H
#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.
Dispatch table. Addressed by offset, so the layout is asserted below.
void(* begin)(uint8_t *, const char *, const char *)
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
#define PROTOCORE_END_DECLS
Definition types.h:97
uint8_t * protocore_upload_service_span(void)
The PROTOCORE_UPLOAD_SERVICE_BORROW bytes this module's state lives in.
void protocore_upload_service_begin(uint8_t *work, const char *path, const char *dest_path)
Register a streaming-upload endpoint. A POST path request streams .
PROTOCORE_NS UploadServiceNs UploadService PROTOCORE_UNUSED
Module namespace.
size_t protocore_upload_service_last_size(uint8_t *work)
Bytes written by the most recent upload (for handlers / tests).