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;
126struct http_service_desc {
140 struct http_service_runtime_data *data;
145#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
147 size_t sec_tag_list_size;
151#define __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
152 _res_fallback, _res_begin, _res_end, _config, ...) \
153 BUILD_ASSERT(_concurrent <= CONFIG_HTTP_SERVER_MAX_CLIENTS, \
154 "can't accept more then MAX_CLIENTS"); \
155 BUILD_ASSERT(_backlog > 0, "backlog can't be 0"); \
156 static int _name##_fd = -1; \
157 IF_ENABLED(CONFIG_HTTP_SERVER_VERSION_3, (static int _name##_fd_h3 = -1;)) \
158 static struct http_service_runtime_data _name##_data = {0}; \
159 const STRUCT_SECTION_ITERABLE(http_service_desc, _name) = { \
161 .port = (uint16_t *)(_port), \
163 IF_ENABLED(CONFIG_HTTP_SERVER_VERSION_3, (.fd_h3 = &_name##_fd_h3,)) \
164 .detail = (void *)(_detail), \
165 .concurrent = (_concurrent), \
166 .backlog = (_backlog), \
167 .data = &_name##_data, \
168 .res_begin = (_res_begin), \
169 .res_end = (_res_end), \
170 .res_fallback = (_res_fallback), \
171 .config = (_config), \
172 COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
173 (.sec_tag_list = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (NULL), \
174 (GET_ARG_N(1, __VA_ARGS__))),), ()) \
175 COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
176 (.sec_tag_list_size = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (0),\
177 (GET_ARG_N(1, GET_ARGS_LESS_N(1, __VA_ARGS__))))), ())\
203#define HTTP_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail, \
204 _res_fallback, _config) \
205 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
206 _res_fallback, NULL, NULL, _config)
231#define HTTPS_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail, \
232 _res_fallback, _config, _sec_tag_list, _sec_tag_list_size) \
233 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
234 _res_fallback, NULL, NULL, _config, \
235 _sec_tag_list, _sec_tag_list_size); \
236 BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
237 "TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
260#define HTTP_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail, _res_fallback, \
262 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
263 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
264 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
266 &_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
267 &_CONCAT(_http_resource_desc_##_name, _list_end)[0], _config);
292#define HTTPS_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail, \
293 _res_fallback, _config, _sec_tag_list, _sec_tag_list_size) \
294 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
295 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
296 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
298 &_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
299 &_CONCAT(_http_resource_desc_##_name, _list_end)[0], _config, \
300 _sec_tag_list, _sec_tag_list_size); \
301 BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
302 "TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
309#define HTTP_SERVICE_COUNT(_dst) STRUCT_SECTION_COUNT(http_service_desc, _dst)
316#define HTTP_SERVICE_RESOURCE_COUNT(_service) ((_service)->res_end - (_service)->res_begin)
323#define HTTP_SERVICE_FOREACH(_it) STRUCT_SECTION_FOREACH(http_service_desc, _it)
333#define HTTP_RESOURCE_FOREACH(_service, _it) \
334 STRUCT_SECTION_FOREACH_ALTERNATE(http_resource_desc_##_service, http_resource_desc, _it)
345#define HTTP_SERVICE_FOREACH_RESOURCE(_service, _it) \
346 for (struct http_resource_desc *_it = (_service)->res_begin; ({ \
347 __ASSERT(_it <= (_service)->res_end, "unexpected list end location"); \
348 _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:78
__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:113
enum http_h3_alt_svc_policy h3_alt_svc_policy
HTTP/3 Alt-Svc advertisement policy for the service.
Definition service.h:119
http_socket_create_fn socket_create
Custom socket creation for the service if needed.
Definition service.h:115
enum http_version http_ver
What HTTP version to use for the service.
Definition service.h:117
TLS credentials management.