ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
protocore_internal.h File Reference

Library-private declarations shared between protocore.cpp and the src/server/*.cpp request-handler translation units it is split into (WebDAV, file serving, ...). More...

#include "protocore.h"
#include <time.h>

Go to the source code of this file.

Classes

struct  ChunkSend
 
struct  SendCtx
 

Functions

const char * status_text (int code)
 Reason phrase for an HTTP status code (e.g. 404 -> "Not Found").
 
void fill_route_base (Route *r, const char *path)
 Initialize the common fields (path, flags) of a route-table entry from its pattern.
 
void http_rfc1123 (time_t t, char *out, size_t cap)
 Format t as an RFC 1123 GMT date into out (cap bytes); out is emptied for t <= 0.
 
bool req_is_head (uint8_t slot_id)
 True if the request in slot slot_id used the HEAD method (send headers, no body).
 
bool regex_match (const char *pattern, const char *path)
 Whole-path regex match (anchored both ends; bounded by RE_MAX_STEPS, fails closed). Defined in server/regex.cpp, called by the route dispatcher for on_regex() routes.
 

Variables

const char PC_RESP_HDR_OVERFLOW []
 The fixed reply sent when a response's own headers will not fit RESP_HDR_BUF_SIZE.
 
const size_t PC_RESP_HDR_OVERFLOW_LEN
 Length of PC_RESP_HDR_OVERFLOW, taken with sizeof where the array bound is still visible.
 
SendCtx s_send
 

Detailed Description

Library-private declarations shared between protocore.cpp and the src/server/*.cpp request-handler translation units it is split into (WebDAV, file serving, ...).

These are NOT part of the public API - they are the handful of protocore.cpp file-scope helpers that a split-out handler still needs, promoted from static to external linkage so the pieces link together. Everything else a handler needs is either a public PC method (declared in protocore.h) or already an extern in the transport headers (e.g. conn_pool in tcp.h).

Definition in file protocore_internal.h.

Function Documentation

◆ status_text()

const char * status_text ( int  code)

Reason phrase for an HTTP status code (e.g. 404 -> "Not Found").

Reason phrase for an HTTP status code (e.g. 404 -> "Not Found").

Covers the 18 codes that arise in typical REST micro-server usage. Unknown codes produce "Unknown" so callers never receive a null pointer.

Parameters
codeHTTP status integer.
Returns
Pointer to a string-literal reason phrase; never null.

Definition at line 119 of file protocore.cpp.

Referenced by PC::redirect(), PC::send(), PC::send_chunked(), PC::send_empty(), and PC::send_template().

◆ fill_route_base()

void fill_route_base ( Route r,
const char *  path 
)

Initialize the common fields (path, flags) of a route-table entry from its pattern.

Initialize the common fields (path, flags) of a route-table entry from its pattern.

Paths are stored null-terminated and truncated to MAX_PATH_LEN. The trailing character of the stored path is inspected to detect wildcard routes: any path ending in * is treated as a prefix match.

Registrations beyond MAX_ROUTES are silently ignored - callers should verify return values if overflow is a concern.

Parameters
pathURL path to match, e.g. "/api/*".
methodHTTP method that triggers this route.
callbackHandler invoked with (slot_id, request).

Definition at line 886 of file protocore.cpp.

References Route::iface_filter, Route::is_active, Route::is_param, Route::is_regex, Route::is_wildcard, MAX_PATH_LEN, Route::path, and PC_IFACE_ANY.

Referenced by PC::on(), PC::on(), and PC::on_regex().

◆ http_rfc1123()

void http_rfc1123 ( time_t  t,
char *  out,
size_t  cap 
)

Format t as an RFC 1123 GMT date into out (cap bytes); out is emptied for t <= 0.

◆ req_is_head()

bool req_is_head ( uint8_t  slot_id)

True if the request in slot slot_id used the HEAD method (send headers, no body).

Definition at line 1463 of file protocore.cpp.

References http_pool.

Referenced by PC::send(), PC::send_chunked(), and PC::send_template().

◆ regex_match()

bool regex_match ( const char *  pattern,
const char *  path 
)

Whole-path regex match (anchored both ends; bounded by RE_MAX_STEPS, fails closed). Defined in server/regex.cpp, called by the route dispatcher for on_regex() routes.

Definition at line 226 of file regex.cpp.

References ReCtx::max_steps, RE_MAX_STEPS, and ReCtx::steps.

Variable Documentation

◆ PC_RESP_HDR_OVERFLOW

const char PC_RESP_HDR_OVERFLOW[]
extern

The fixed reply sent when a response's own headers will not fit RESP_HDR_BUF_SIZE.

A header block cut short has no terminating CRLF, so the peer keeps reading the body as headers and the connection desynchronizes - which is why truncating is not an option and this always- fitting reply goes out instead. Connection: close, because the request is not recoverable.

Definition at line 440 of file protocore.cpp.

Referenced by PC::send().

◆ PC_RESP_HDR_OVERFLOW_LEN

const size_t PC_RESP_HDR_OVERFLOW_LEN
extern

Length of PC_RESP_HDR_OVERFLOW, taken with sizeof where the array bound is still visible.

Definition at line 446 of file protocore.cpp.

Referenced by PC::send().

◆ s_send

SendCtx s_send
extern

Definition at line 104 of file protocore.cpp.

Referenced by PC::http_poll_slot(), and PC::send_chunked().