Zephyr API Documentation  3.6.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
20#include <stdint.h>
21#include <stddef.h>
22
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
34 const char *resource;
36 void *detail;
37};
38
56#define HTTP_RESOURCE_DEFINE(_name, _service, _resource, _detail) \
57 const STRUCT_SECTION_ITERABLE_ALTERNATE(http_resource_desc_##_service, http_resource_desc, \
58 _name) = { \
59 .resource = _resource, \
60 .detail = (void *)(_detail), \
61 }
62
65struct http_service_desc {
66 const char *host;
67 uint16_t *port;
68 void *detail;
69 size_t concurrent;
70 size_t backlog;
71 struct http_resource_desc *res_begin;
72 struct http_resource_desc *res_end;
73#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
74 const sec_tag_t *sec_tag_list;
75 size_t sec_tag_list_size;
76#endif
77};
78
79#define __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, _res_begin, \
80 _res_end, ...) \
81 static const STRUCT_SECTION_ITERABLE(http_service_desc, _name) = { \
82 .host = _host, \
83 .port = (uint16_t *)(_port), \
84 .detail = (void *)(_detail), \
85 .concurrent = (_concurrent), \
86 .backlog = (_backlog), \
87 .res_begin = (_res_begin), \
88 .res_end = (_res_end), \
89 COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
90 (.sec_tag_list = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (NULL), \
91 (GET_ARG_N(1, __VA_ARGS__))),), ()) \
92 COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
93 (.sec_tag_list_size = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (0),\
94 (GET_ARG_N(1, GET_ARGS_LESS_N(1, __VA_ARGS__))))), ())\
95 }
96
117#define HTTP_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail) \
118 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, NULL, NULL)
119
140#define HTTPS_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail, \
141 _sec_tag_list, _sec_tag_list_size) \
142 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, NULL, NULL, \
143 _sec_tag_list, _sec_tag_list_size); \
144 BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
145 "TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
146
165#define HTTP_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail) \
166 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
167 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
168 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
169 &_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
170 &_CONCAT(_http_resource_desc_##_name, _list_end)[0])
171
192#define HTTPS_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail, \
193 _sec_tag_list, _sec_tag_list_size) \
194 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
195 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
196 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
197 &_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
198 &_CONCAT(_http_resource_desc_##_name, _list_end)[0], \
199 _sec_tag_list, _sec_tag_list_size); \
200 BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
201 "TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
202
208#define HTTP_SERVICE_COUNT(_dst) STRUCT_SECTION_COUNT(http_service_desc, _dst)
209
215#define HTTP_SERVICE_RESOURCE_COUNT(_service) ((_service)->res_end - (_service)->res_begin)
216
222#define HTTP_SERVICE_FOREACH(_it) STRUCT_SECTION_FOREACH(http_service_desc, _it)
223
232#define HTTP_RESOURCE_FOREACH(_service, _it) \
233 STRUCT_SECTION_FOREACH_ALTERNATE(http_resource_desc_##_service, http_resource_desc, _it)
234
244#define HTTP_SERVICE_FOREACH_RESOURCE(_service, _it) \
245 for (struct http_resource_desc *_it = (_service)->res_begin; ({ \
246 __ASSERT(_it <= (_service)->res_end, "unexpected list end location"); \
247 _it < (_service)->res_end; \
248 }); \
249 _it++)
250
251#ifdef __cplusplus
252}
253#endif
254
259#endif /* ZEPHYR_INCLUDE_NET_HTTP_SERVICE_H_ */
int sec_tag_t
Secure tag, a reference to TLS credential.
Definition: tls_credentials.h:72
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
HTTP resource description.
Definition: service.h:32
const char * resource
Resource name.
Definition: service.h:34
void * detail
Detail associated with this resource.
Definition: service.h:36
TLS credentials management.
Macro utilities.