oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
net_httpd.h
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
9#ifndef OVE_NET_HTTPD_H
10#define OVE_NET_HTTPD_H
11
24#include "ove/types.h"
25#include "ove/net.h"
26#include "ove_config.h"
27
28#include <stddef.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#ifdef CONFIG_OVE_NET_HTTPD
35
37#define OVE_HTTPD_MAX_ROUTES 16
38
40#define OVE_HTTPD_MAX_SEGMENTS 8
41
43typedef struct ove_httpd_req ove_httpd_req_t;
44
46typedef struct ove_httpd_resp ove_httpd_resp_t;
47
52typedef int (*ove_httpd_handler_t)(ove_httpd_req_t *req,
53 ove_httpd_resp_t *resp);
54
58typedef struct {
59 uint16_t port;
60 int max_body_size;
61} ove_httpd_config_t;
62
72int ove_httpd_start(const ove_httpd_config_t *cfg);
73
77void ove_httpd_stop(void);
78
87int ove_httpd_route(const char *method, const char *path,
88 ove_httpd_handler_t handler);
89
95void ove_httpd_register_builtin_routes(void);
96
105void ove_httpd_set_netif(ove_netif_t netif);
106
107/* ── Optional module hooks ──────────────────────────────────── */
108
109#ifdef CONFIG_OVE_AUDIO
110struct ove_audio_graph;
112void ove_httpd_set_audio_graph(struct ove_audio_graph *g);
113#endif
114
115#ifdef CONFIG_OVE_INFER
117void ove_httpd_set_model(ove_model_t model);
118#endif
119
120/* ── Request accessors ───────────────────────────────────────── */
121
123const char *ove_httpd_req_method(ove_httpd_req_t *req);
124
126const char *ove_httpd_req_path(ove_httpd_req_t *req);
127
129const char *ove_httpd_req_query(ove_httpd_req_t *req);
130
132const char *ove_httpd_req_body(ove_httpd_req_t *req);
133
135size_t ove_httpd_req_body_len(ove_httpd_req_t *req);
136
146const char *ove_httpd_req_segment(ove_httpd_req_t *req, int idx);
147
148/* ── Response helpers ────────────────────────────────────────── */
149
151int ove_httpd_resp_json(ove_httpd_resp_t *resp, int status,
152 const char *json);
153
155int ove_httpd_resp_html(ove_httpd_resp_t *resp, int status,
156 const char *html, size_t len);
157
159int ove_httpd_resp_send(ove_httpd_resp_t *resp, int status,
160 const char *content_type,
161 const void *body, size_t len);
162
164int ove_httpd_resp_send_gz(ove_httpd_resp_t *resp, int status,
165 const char *content_type,
166 const void *body, size_t len);
167
169int ove_httpd_resp_error(ove_httpd_resp_t *resp, int status,
170 const char *message);
171
172/* ── WebSocket support ──────────────────────────────────────── */
173
174#ifdef CONFIG_OVE_NET_HTTPD_WS
175
177typedef struct ove_httpd_ws_conn ove_httpd_ws_conn_t;
178
185typedef void (*ove_httpd_ws_handler_t)(ove_httpd_ws_conn_t *conn,
186 const void *data, size_t len);
187
192typedef void (*ove_httpd_ws_close_handler_t)(ove_httpd_ws_conn_t *conn);
193
206int ove_httpd_ws_route(const char *path,
207 ove_httpd_ws_handler_t on_message,
208 ove_httpd_ws_close_handler_t on_close);
209
218int ove_httpd_ws_send(ove_httpd_ws_conn_t *conn,
219 const void *data, size_t len);
220
229int ove_httpd_ws_broadcast(const char *path,
230 const void *data, size_t len);
231
233int ove_httpd_ws_active_count(void);
234
235/* Internal — called by httpd accept loop */
236int ove_httpd_ws_is_upgrade(const char *headers);
237int ove_httpd_ws_handshake(const char *headers, size_t headers_len,
238 const char *path,
239 ove_socket_t sock,
240 ove_socket_storage_t *storage);
241void ove_httpd_ws_poll(void);
242
243#endif /* CONFIG_OVE_NET_HTTPD_WS */
244
245/* ── Log hook ────────────────────────────────────────────────── */
246
252void ove_httpd_log_append(const char *line);
253
254#else /* !CONFIG_OVE_NET_HTTPD */
255
257static inline int ove_httpd_start(const void *cfg) { (void)cfg; return OVE_ERR_NOT_SUPPORTED; }
258static inline void ove_httpd_stop(void) {}
259static inline void ove_httpd_register_builtin_routes(void) {}
260static inline void ove_httpd_log_append(const char *line) { (void)line; }
263#endif /* CONFIG_OVE_NET_HTTPD */
264
265#ifdef __cplusplus
266}
267#endif
268
271#endif /* OVE_NET_HTTPD_H */
#define OVE_ERR_NOT_SUPPORTED
The requested feature is not supported by the active backend.
Definition types.h:38
struct ove_netif * ove_netif_t
Opaque handle for a network interface.
Definition types.h:124
struct ove_socket * ove_socket_t
Opaque handle for a network socket.
Definition types.h:121
struct ove_model * ove_model_t
Opaque handle for an ML inference model session.
Definition types.h:118
Audio processing graph instance.
Definition audio.h:93