Zephyr API Documentation
4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
service.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2022 Meta
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef ZEPHYR_INCLUDE_NET_HTTP_SERVICE_H_
8
#define ZEPHYR_INCLUDE_NET_HTTP_SERVICE_H_
9
22
#include "
zephyr/net/http/server.h
"
23
#include <
stdint.h
>
24
#include <stddef.h>
25
26
#include <
zephyr/sys/util_macro.h
>
27
#include <
zephyr/sys/iterable_sections.h
>
28
#include <
zephyr/net/tls_credentials.h
>
29
30
#ifdef __cplusplus
31
extern
"C"
{
32
#endif
33
35
struct
http_resource_desc
{
37
const
char
*
resource
;
39
void
*
detail
;
40
};
41
59
#define HTTP_RESOURCE_DEFINE(_name, _service, _resource, _detail) \
60
const STRUCT_SECTION_ITERABLE_ALTERNATE(http_resource_desc_##_service, http_resource_desc, \
61
_name) = { \
62
.resource = _resource, \
63
.detail = (void *)(_detail), \
64
}
65
68
struct
http_service_runtime_data {
69
int
num_clients;
70
};
71
72
struct
http_service_desc {
73
const
char
*host;
74
uint16_t
*port;
75
int
*fd;
76
void
*detail;
77
size_t
concurrent;
78
size_t
backlog;
79
struct
http_service_runtime_data *
data
;
80
struct
http_resource_desc
*res_begin;
81
struct
http_resource_desc
*res_end;
82
struct
http_resource_detail
*res_fallback;
83
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
84
const
sec_tag_t
*sec_tag_list;
85
size_t
sec_tag_list_size;
86
#endif
87
};
88
89
#define __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
90
_res_fallback, _res_begin, _res_end, ...) \
91
BUILD_ASSERT(_concurrent <= CONFIG_HTTP_SERVER_MAX_CLIENTS, \
92
"can't accept more then MAX_CLIENTS"); \
93
BUILD_ASSERT(_backlog > 0, "backlog can't be 0"); \
94
static int _name##_fd = -1; \
95
static struct http_service_runtime_data _name##_data = {0}; \
96
const STRUCT_SECTION_ITERABLE(http_service_desc, _name) = { \
97
.host = _host, \
98
.port = (uint16_t *)(_port), \
99
.fd = &_name##_fd, \
100
.detail = (void *)(_detail), \
101
.concurrent = (_concurrent), \
102
.data = &_name##_data, \
103
.backlog = (_backlog), \
104
.res_begin = (_res_begin), \
105
.res_end = (_res_end), \
106
.res_fallback = (_res_fallback), \
107
COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
108
(.sec_tag_list = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (NULL), \
109
(GET_ARG_N(1, __VA_ARGS__))),), ()) \
110
COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
111
(.sec_tag_list_size = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (0),\
112
(GET_ARG_N(1, GET_ARGS_LESS_N(1, __VA_ARGS__))))), ())\
113
}
114
137
#define HTTP_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail, \
138
_res_fallback) \
139
__z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
140
_res_fallback, NULL, NULL)
141
164
#define HTTPS_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail, \
165
_res_fallback, _sec_tag_list, _sec_tag_list_size) \
166
__z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
167
_res_fallback, NULL, NULL, \
168
_sec_tag_list, _sec_tag_list_size); \
169
BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
170
"TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
171
192
#define HTTP_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail, _res_fallback) \
193
extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
194
extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
195
__z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
196
_res_fallback, \
197
&_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
198
&_CONCAT(_http_resource_desc_##_name, _list_end)[0]);
199
222
#define HTTPS_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail, \
223
_res_fallback, _sec_tag_list, _sec_tag_list_size) \
224
extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
225
extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
226
__z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
227
_res_fallback, \
228
&_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
229
&_CONCAT(_http_resource_desc_##_name, _list_end)[0], \
230
_sec_tag_list, _sec_tag_list_size); \
231
BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
232
"TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
233
239
#define HTTP_SERVICE_COUNT(_dst) STRUCT_SECTION_COUNT(http_service_desc, _dst)
240
246
#define HTTP_SERVICE_RESOURCE_COUNT(_service) ((_service)->res_end - (_service)->res_begin)
247
253
#define HTTP_SERVICE_FOREACH(_it) STRUCT_SECTION_FOREACH(http_service_desc, _it)
254
263
#define HTTP_RESOURCE_FOREACH(_service, _it) \
264
STRUCT_SECTION_FOREACH_ALTERNATE(http_resource_desc_##_service, http_resource_desc, _it)
265
275
#define HTTP_SERVICE_FOREACH_RESOURCE(_service, _it) \
276
for (struct http_resource_desc *_it = (_service)->res_begin; ({ \
277
__ASSERT(_it <= (_service)->res_end, "unexpected list end location"); \
278
_it < (_service)->res_end; \
279
}); \
280
_it++)
281
282
#ifdef __cplusplus
283
}
284
#endif
285
290
#endif
/* ZEPHYR_INCLUDE_NET_HTTP_SERVICE_H_ */
sec_tag_t
int sec_tag_t
Secure tag, a reference to TLS credential.
Definition
tls_credentials.h:78
server.h
HTTP server API.
stdint.h
uint16_t
__UINT16_TYPE__ uint16_t
Definition
stdint.h:89
http_resource_desc
HTTP resource description.
Definition
service.h:35
http_resource_desc::resource
const char * resource
Resource name.
Definition
service.h:37
http_resource_desc::detail
void * detail
Detail associated with this resource.
Definition
service.h:39
http_resource_detail
Representation of a server resource, common for all resource types.
Definition
server.h:88
iterable_sections.h
data
static fdata_t data[2]
Definition
test_fifo_contexts.c:15
tls_credentials.h
TLS credentials management.
util_macro.h
Macro utilities.
zephyr
net
http
service.h
Generated on Mon Apr 21 2025 11:55:49 for Zephyr API Documentation by
1.12.0