|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Layer 7 (Application) - HTTP routing and request handler implementation. More...
#include "protocore.h"#include "server/protocore_internal.h"#include "network_drivers/presentation/presentation.h"#include "network_drivers/session/proto_handler.h"#include "network_drivers/session/worker.h"#include "network_drivers/tls/tls.h"#include "network_drivers/transport/listener.h"#include "shared_primitives/hex.h"#include "shared_primitives/strbuf.h"#include "shared_primitives/mime.h"#include <stdarg.h>#include <stdio.h>#include <string.h>Go to the source code of this file.
Classes | |
| struct | InstanceCtx |
Functions | |
| const char * | status_text (int code) |
| Convert an HTTP status code to its standard reason phrase. | |
| void | fill_route_base (Route *r, const char *path) |
| Register a route in the route table. | |
| bool | req_is_head (uint8_t slot_id) |
True if the request in slot slot_id used the HEAD method (send headers, no body). | |
Variables | |
| SendCtx | s_send |
| 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 = sizeof(PC_RESP_HDR_OVERFLOW) - 1 |
| Length of PC_RESP_HDR_OVERFLOW, taken with sizeof where the array bound is still visible. | |
Layer 7 (Application) - HTTP routing and request handler implementation.
Dispatch pipeline (called from PC::handle())
Route table Routes are stored in a fixed-size array of Route structs. Both exact and wildcard (suffix *) routes are supported; exact routes always take priority because the loop checks them in insertion order and returns on the first match.
PCB lifecycle / teardown ownership All TCP I/O and teardown go through the transport-layer connection API (pc_conn_send / pc_conn_flush / pc_conn_begin_close / pc_conn_close / pc_conn_abort_slot), so this layer never calls lwIP or touches the raw tcp_pcb directly. The transport owns the teardown order for every close: it detaches the pcb from its lwIP callbacks and sets the slot ConnState::CONN_FREE (pcb nulled) BEFORE the FIN/RST, on the captured pcb pointer. This means any lwIP error callback that fires mid-teardown sees the slot as already free and takes no action - preventing a double-free. L7 passes only the slot index: pc_conn_close(slot) for a graceful local close, pc_conn_abort_slot(slot) for a hard RST, pc_conn_begin_close(slot) for the drain-then-close dwell.
Definition in file protocore.cpp.
| const char * status_text | ( | int | code | ) |
Convert an HTTP status code to its standard reason phrase.
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.
| code | HTTP status integer. |
Definition at line 119 of file protocore.cpp.
Referenced by PC::redirect(), PC::send(), PC::send_chunked(), PC::send_empty(), and PC::send_template().
| void fill_route_base | ( | Route * | r, |
| const char * | path | ||
| ) |
Register a route in the route table.
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.
| path | URL path to match, e.g. "/api/*". |
| method | HTTP method that triggers this route. |
| callback | Handler 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().
| 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().
| SendCtx s_send |
Definition at line 104 of file protocore.cpp.
Referenced by PC::http_poll_slot(), and PC::send_chunked().
| const char PC_RESP_HDR_OVERFLOW[] |
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().
| const size_t PC_RESP_HDR_OVERFLOW_LEN = sizeof(PC_RESP_HDR_OVERFLOW) - 1 |
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().