ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
proto_builtins.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file proto_builtins.cpp
6 * @brief Layer 5 (Session) - the built-in protocol registry (policy, not mechanism).
7 *
8 * The session dispatcher (session.cpp) is pure mechanism: it routes events to whatever
9 * ProtoHandler is registered for a connection's ConnProto and names no protocol. This
10 * file is the one place that knows which protocols the build includes. Each built-in's
11 * handler + callbacks live in its own module and are exposed by a pure `*_proto_handler()`
12 * accessor (no session dependency); here we install each behind the matching feature flag.
13 * Adding a protocol means writing its module and adding one guarded line here - never editing
14 * the dispatcher.
15 *
16 * (The SSH remote-forward listener, ConnProto::PROTO_SSH_RFWD, is intentionally NOT here: it is a
17 * runtime opt-in that self-registers from pc_ssh_forward_begin().)
18 */
19
20#include "proto_handler.h"
21
22#include "network_drivers/presentation/presentation.h" // http_proto_handler()
23#if PC_ENABLE_TELNET
25#endif
26#if PC_ENABLE_SSH
28#endif
29#if PC_NEED_MODBUS
31#endif
32#if PC_ENABLE_OPCUA
34#endif
35
36// Register @p h for @p proto only if the module actually supplied one (modbus / opcua return nullptr
37// on host builds, where there is no TCP transport handler).
38static inline void register_if(ConnProto proto, const ProtoHandler *h)
39{
40 if (h) // GCOVR_EXCL_BR_LINE null half needs modbus/opcua compiled in alongside this file; no env does
41 {
42 proto_register(proto, h);
43 }
44}
45
47{
48 register_if(ConnProto::PROTO_HTTP, http_proto_handler()); // always present (the core request/response protocol)
49#if PC_ENABLE_TELNET
50 register_if(ConnProto::PROTO_TELNET, pc_telnet_proto_handler());
51#endif
52#if PC_ENABLE_SSH
53 // GCOVR_EXCL_START no coverage env combines PC_ENABLE_SSH with a proto_register_builtins() call:
54 // the SSH env tests the handler directly and the session/accept-gate envs keep SSH off (they reuse
55 // the SSH proto slot). Device-reachable on any SSH firmware via session init; same gap as line 40.
57 // GCOVR_EXCL_STOP
58#endif
59#if PC_NEED_MODBUS
60 register_if(ConnProto::PROTO_MODBUS, pc_modbus_proto_handler());
61#endif
62#if PC_ENABLE_OPCUA
63 register_if(ConnProto::PROTO_OPCUA, pc_opcua_proto_handler());
64#endif
65}
Zero-heap Modbus TCP slave/server (Modbus Application Protocol v1.1b3).
OPC UA Binary server: handshake + SecureChannel + Session + Read/Write + Browse (PC_ENABLE_OPCUA).
const ProtoHandler * http_proto_handler(void)
Layer 6 (Presentation) - wires the transport ring buffer to the HTTP parser.
void proto_register_builtins(void)
Register every built-in protocol's handler (the policy list).
Layer 5 (Session) - per-protocol connection handler dispatch table.
void proto_register(ConnProto proto, const ProtoHandler *h)
Register h for protocol proto (replaces any previous handler).
Definition session.cpp:38
ConnProto
Application protocol spoken on a listener port or connection slot.
@ PROTO_HTTP
HTTP/1.1 with optional WS and SSE upgrades.
@ PROTO_OPCUA
OPC UA Binary (UA-TCP) server.
@ PROTO_TELNET
Telnet (RFC 854).
@ PROTO_MODBUS
Modbus TCP slave (Modbus Application Protocol).
@ PROTO_SSH
SSH (RFC 4253/4252/4254).
const ProtoHandler * ssh_proto_handler(void)
Definition ssh_conn.cpp:106
Glue between the TCP transport (conn_pool) and the SSH protocol stack.
Per-protocol connection event/poll callbacks (Layer 5 dispatch vtable).
Layer 6/7 - minimal RFC 854 Telnet server (PC_ENABLE_TELNET).