Zephyr API Documentation 4.0.0-rc3
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 <stdint.h>
23#include <stddef.h>
24
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
36 const char *resource;
38 void *detail;
39};
40
58#define HTTP_RESOURCE_DEFINE(_name, _service, _resource, _detail) \
59 const STRUCT_SECTION_ITERABLE_ALTERNATE(http_resource_desc_##_service, http_resource_desc, \
60 _name) = { \
61 .resource = _resource, \
62 .detail = (void *)(_detail), \
63 }
64
67struct http_service_desc {
68 const char *host;
69 uint16_t *port;
70 void *detail;
71 size_t concurrent;
72 size_t backlog;
73 struct http_resource_desc *res_begin;
74 struct http_resource_desc *res_end;
75#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
76 const sec_tag_t *sec_tag_list;
77 size_t sec_tag_list_size;
78#endif
79};
80
81#define __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, _res_begin, \
82 _res_end, ...) \
83 static const STRUCT_SECTION_ITERABLE(http_service_desc, _name) = { \
84 .host = _host, \
85 .port = (uint16_t *)(_port), \
86 .detail = (void *)(_detail), \
87 .concurrent = (_concurrent), \
88 .backlog = (_backlog), \
89 .res_begin = (_res_begin), \
90 .res_end = (_res_end), \
91 COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
92 (.sec_tag_list = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (NULL), \
93 (GET_ARG_N(1, __VA_ARGS__))),), ()) \
94 COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
95 (.sec_tag_list_size = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (0),\
96 (GET_ARG_N(1, GET_ARGS_LESS_N(1, __VA_ARGS__))))), ())\
97 }
98
120#define HTTP_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail) \
121 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, NULL, NULL)
122
144#define HTTPS_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail, \
145 _sec_tag_list, _sec_tag_list_size) \
146 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, NULL, NULL, \
147 _sec_tag_list, _sec_tag_list_size); \
148 BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
149 "TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
150
170#define HTTP_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail) \
171 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
172 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
173 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
174 &_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
175 &_CONCAT(_http_resource_desc_##_name, _list_end)[0])
176
198#define HTTPS_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail, \
199 _sec_tag_list, _sec_tag_list_size) \
200 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
201 extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
202 __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
203 &_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
204 &_CONCAT(_http_resource_desc_##_name, _list_end)[0], \
205 _sec_tag_list, _sec_tag_list_size); \
206 BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
207 "TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
208
214#define HTTP_SERVICE_COUNT(_dst) STRUCT_SECTION_COUNT(http_service_desc, _dst)
215
221#define HTTP_SERVICE_RESOURCE_COUNT(_service) ((_service)->res_end - (_service)->res_begin)
222
228#define HTTP_SERVICE_FOREACH(_it) STRUCT_SECTION_FOREACH(http_service_desc, _it)
229
238#define HTTP_RESOURCE_FOREACH(_service, _it) \
239 STRUCT_SECTION_FOREACH_ALTERNATE(http_resource_desc_##_service, http_resource_desc, _it)
240
250#define HTTP_SERVICE_FOREACH_RESOURCE(_service, _it) \
251 for (struct http_resource_desc *_it = (_service)->res_begin; ({ \
252 __ASSERT(_it <= (_service)->res_end, "unexpected list end location"); \
253 _it < (_service)->res_end; \
254 }); \
255 _it++)
256
257#ifdef __cplusplus
258}
259#endif
260
265#endif /* ZEPHYR_INCLUDE_NET_HTTP_SERVICE_H_ */
int sec_tag_t
Secure tag, a reference to TLS credential.
Definition tls_credentials.h:74
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
HTTP resource description.
Definition service.h:34
const char * resource
Resource name.
Definition service.h:36
void * detail
Detail associated with this resource.
Definition service.h:38
TLS credentials management.
Macro utilities.