7#ifndef ZEPHYR_INCLUDE_NET_HTTP_SERVICE_H_
8#define ZEPHYR_INCLUDE_NET_HTTP_SERVICE_H_
59#define HTTP_RESOURCE_DEFINE(_name, _service, _resource, _detail) \
60 const STRUCT_SECTION_ITERABLE_ALTERNATE(http_resource_desc_##_service, http_resource_desc, \
62 .resource = _resource, \
63 .detail = (void *)(_detail), \
68struct http_service_runtime_data {
72struct http_service_desc;
142struct http_service_desc {
156 struct http_service_runtime_data *data;
161#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
163 size_t sec_tag_list_size;
167#define __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
168 _res_fallback, _res_begin, _res_end, _config, ...) \
169 BUILD_ASSERT(_concurrent <= CONFIG_HTTP_SERVER_MAX_CLIENTS, \
170 "can't accept more then MAX_CLIENTS"); \
171 BUILD_ASSERT(_backlog > 0, "backlog can't be 0"); \
172 static int _name##_fd = -1; \
173 IF_ENABLED(CONFIG_HTTP_SERVER_VERSION_3, (static int _name##_fd_h3 = -1;)) \
174 static struct http_service_runtime_data _name##_data = {0}; \
175 const STRUCT_SECTION_ITERABLE(http_service_desc, _name) = { \
177 .port = (uint16_t *)(_port), \
179 IF_ENABLED(CONFIG_HTTP_SERVER_VERSION_3, (.fd_h3 = &_name##_fd_h3,)) \
180 .detail = (void *)(_detail), \
181 .concurrent = (_concurrent), \
182 .backlog = (_backlog), \
183 .data = &_name##_data, \
184 .res_begin = (_res_begin), \
185 .res_end = (_res_end), \
186 .res_fallback = (_res_fallback), \
187 .config = (_config), \
188 COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
189 (.sec_tag_list = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (NULL), \
190 (GET_ARG_N(1, __VA_ARGS__))),), ()) \
191 COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
192 (.sec_tag_list_size = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (0),\
193 (GET_ARG_N(1, GET_ARGS_LESS_N(1, __VA_ARGS__))))), ())\
219#define HTTP_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail, \
220 _res_fallback, _config) \
221 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
222 _res_fallback, NULL, NULL, _config)
247#define HTTPS_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail, \
248 _res_fallback, _config, _sec_tag_list, _sec_tag_list_size) \
249 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
250 _res_fallback, NULL, NULL, _config, \
251 _sec_tag_list, _sec_tag_list_size); \
252 BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
253 "TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
276#define HTTP_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail, _res_fallback, \
278 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
279 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
280 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
282 &_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
283 &_CONCAT(_http_resource_desc_##_name, _list_end)[0], _config);
308#define HTTPS_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail, \
309 _res_fallback, _config, _sec_tag_list, _sec_tag_list_size) \
310 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
311 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
312 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
314 &_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
315 &_CONCAT(_http_resource_desc_##_name, _list_end)[0], _config, \
316 _sec_tag_list, _sec_tag_list_size); \
317 BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
318 "TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
325#define HTTP_SERVICE_COUNT(_dst) STRUCT_SECTION_COUNT(http_service_desc, _dst)
332#define HTTP_SERVICE_RESOURCE_COUNT(_service) ((_service)->res_end - (_service)->res_begin)
339#define HTTP_SERVICE_FOREACH(_it) STRUCT_SECTION_FOREACH(http_service_desc, _it)
349#define HTTP_RESOURCE_FOREACH(_service, _it) \
350 STRUCT_SECTION_FOREACH_ALTERNATE(http_resource_desc_##_service, http_resource_desc, _it)
361#define HTTP_SERVICE_FOREACH_RESOURCE(_service, _it) \
362 for (struct http_resource_desc *_it = (_service)->res_begin; ({ \
363 __ASSERT(_it <= (_service)->res_end, "unexpected list end location"); \
364 _it < (_service)->res_end; \
http_h3_alt_svc_policy
HTTP/3 Alt-Svc advertisement policy for this service.
Definition service.h:103
int(* http_socket_create_fn)(const struct http_service_desc *svc, int af, int proto)
Custom socket creation function type.
Definition service.h:88
http_version
Supported HTTP version for this service.
Definition service.h:95
@ HTTP_H3_ALT_SVC_ENABLE
Always advertise HTTP/3 via Alt-Svc for this service when available.
Definition service.h:109
@ HTTP_H3_ALT_SVC_DISABLE
Never advertise HTTP/3 via Alt-Svc for this service.
Definition service.h:107
@ HTTP_H3_ALT_SVC_DEFAULT
Use the global default policy configured in Kconfig.
Definition service.h:105
@ HTTP_VERSION_2
Support HTTP/2.
Definition service.h:98
@ HTTP_VERSION_1
Support HTTP/1.0 and HTTP/1.1.
Definition service.h:97
@ HTTP_VERSION_3
Support HTTP/3.
Definition service.h:99
@ HTTP_VERSION_ANY
Support any HTTP version configured in the system.
Definition service.h:96
int sec_tag_t
Secure tag, a reference to TLS credential.
Definition tls_credentials.h:90
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
HTTP resource description.
Definition service.h:35
const char * resource
Resource name.
Definition service.h:37
void * detail
Detail associated with this resource.
Definition service.h:39
Representation of a server resource, common for all resource types.
Definition server.h:88
HTTP service configuration.
Definition service.h:129
struct http_service_h3_config h3
HTTP/3-specific configuration.
Definition service.h:135
http_socket_create_fn socket_create
Custom socket creation for the service if needed.
Definition service.h:131
enum http_version http_ver
What HTTP version to use for the service.
Definition service.h:133
HTTP/3 configuration for a service.
Definition service.h:113
enum http_h3_alt_svc_policy alt_svc_policy
HTTP/3 Alt-Svc advertisement policy for the service.
Definition service.h:115
bool enable_session_tickets
Enable QUIC session tickets on the HTTP/3 listener for this service.
Definition service.h:117
uint32_t max_early_data_size
HTTP/3 listener early-data limit in bytes.
Definition service.h:125
Iterable sections helpers.
TLS credentials management.