@@ -69,6 +69,18 @@ struct http_service_runtime_data {
69
69
int num_clients ;
70
70
};
71
71
72
+ struct http_service_desc ;
73
+
74
+ /** Custom socket creation function type */
75
+ typedef int (* http_socket_create_fn )(const struct http_service_desc * svc , int af , int proto );
76
+
77
+ /** HTTP service configuration */
78
+ struct http_service_config {
79
+ /** Custom socket creation for the service if needed */
80
+ http_socket_create_fn socket_create ;
81
+ /* If any more service-specific configuration is needed, it can be added here. */
82
+ };
83
+
72
84
struct http_service_desc {
73
85
const char * host ;
74
86
uint16_t * port ;
@@ -80,14 +92,15 @@ struct http_service_desc {
80
92
struct http_resource_desc * res_begin ;
81
93
struct http_resource_desc * res_end ;
82
94
struct http_resource_detail * res_fallback ;
95
+ const struct http_service_config * config ;
83
96
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS )
84
97
const sec_tag_t * sec_tag_list ;
85
98
size_t sec_tag_list_size ;
86
99
#endif
87
100
};
88
101
89
102
#define __z_http_service_define (_name , _host , _port , _concurrent , _backlog , _detail , \
90
- _res_fallback , _res_begin , _res_end , ...) \
103
+ _res_fallback , _res_begin , _res_end , _config , ...) \
91
104
BUILD_ASSERT(_concurrent <= CONFIG_HTTP_SERVER_MAX_CLIENTS, \
92
105
"can't accept more then MAX_CLIENTS"); \
93
106
BUILD_ASSERT(_backlog > 0, "backlog can't be 0"); \
@@ -104,6 +117,7 @@ struct http_service_desc {
104
117
.res_begin = (_res_begin), \
105
118
.res_end = (_res_end), \
106
119
.res_fallback = (_res_fallback), \
120
+ .config = (_config), \
107
121
COND_CODE_1(CONFIG_NET_SOCKETS_SOCKOPT_TLS, \
108
122
(.sec_tag_list = COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (NULL), \
109
123
(GET_ARG_N(1, __VA_ARGS__))),), ()) \
@@ -133,11 +147,12 @@ struct http_service_desc {
133
147
* @param _backlog Maximum number of queued connections. (min. 1)
134
148
* @param _detail User-defined detail associated with the service.
135
149
* @param _res_fallback Fallback resource to be served if no other resource matches path
150
+ * @param _config Pointer to http_service_config structure (can be NULL for default behavior)
136
151
*/
137
152
#define HTTP_SERVICE_DEFINE_EMPTY (_name , _host , _port , _concurrent , _backlog , _detail , \
138
- _res_fallback ) \
153
+ _res_fallback , _config ) \
139
154
__z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
140
- _res_fallback, NULL, NULL)
155
+ _res_fallback, NULL, NULL, _config )
141
156
142
157
/**
143
158
* @brief Define an HTTPS service without static resources.
@@ -158,13 +173,14 @@ struct http_service_desc {
158
173
* @param _backlog Maximum number of queued connections. (min. 1)
159
174
* @param _detail User-defined detail associated with the service.
160
175
* @param _res_fallback Fallback resource to be served if no other resource matches path
176
+ * @param _config Pointer to http_service_config structure (can be NULL for default behavior)
161
177
* @param _sec_tag_list TLS security tag list used to setup a HTTPS socket.
162
178
* @param _sec_tag_list_size TLS security tag list size used to setup a HTTPS socket.
163
179
*/
164
180
#define HTTPS_SERVICE_DEFINE_EMPTY (_name , _host , _port , _concurrent , _backlog , _detail , \
165
- _res_fallback , _sec_tag_list , _sec_tag_list_size ) \
181
+ _res_fallback , _config , _sec_tag_list , _sec_tag_list_size ) \
166
182
__z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
167
- _res_fallback, NULL, NULL, \
183
+ _res_fallback, NULL, NULL, _config, \
168
184
_sec_tag_list, _sec_tag_list_size); \
169
185
BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
170
186
"TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
@@ -188,14 +204,16 @@ struct http_service_desc {
188
204
* @param _backlog Maximum number of queued connections. (min. 1)
189
205
* @param _detail User-defined detail associated with the service.
190
206
* @param _res_fallback Fallback resource to be served if no other resource matches path
207
+ * @param _config Pointer to http_service_config structure (can be NULL for default behavior)
191
208
*/
192
- #define HTTP_SERVICE_DEFINE (_name , _host , _port , _concurrent , _backlog , _detail , _res_fallback ) \
209
+ #define HTTP_SERVICE_DEFINE (_name , _host , _port , _concurrent , _backlog , _detail , _res_fallback , \
210
+ _config ) \
193
211
extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
194
212
extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
195
213
__z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
196
214
_res_fallback, \
197
215
&_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
198
- &_CONCAT(_http_resource_desc_##_name, _list_end)[0]);
216
+ &_CONCAT(_http_resource_desc_##_name, _list_end)[0], _config );
199
217
200
218
/**
201
219
* @brief Define an HTTPS service with static resources.
@@ -216,17 +234,18 @@ struct http_service_desc {
216
234
* @param _backlog Maximum number of queued connections. (min. 1)
217
235
* @param _detail User-defined detail associated with the service.
218
236
* @param _res_fallback Fallback resource to be served if no other resource matches path
237
+ * @param _config Pointer to http_service_config structure (can be NULL for default behavior)
219
238
* @param _sec_tag_list TLS security tag list used to setup a HTTPS socket.
220
239
* @param _sec_tag_list_size TLS security tag list size used to setup a HTTPS socket.
221
240
*/
222
241
#define HTTPS_SERVICE_DEFINE (_name , _host , _port , _concurrent , _backlog , _detail , \
223
- _res_fallback , _sec_tag_list , _sec_tag_list_size ) \
242
+ _res_fallback , _config , _sec_tag_list , _sec_tag_list_size ) \
224
243
extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \
225
244
extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \
226
245
__z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \
227
246
_res_fallback, \
228
247
&_CONCAT(_http_resource_desc_##_name, _list_start)[0], \
229
- &_CONCAT(_http_resource_desc_##_name, _list_end)[0], \
248
+ &_CONCAT(_http_resource_desc_##_name, _list_end)[0], _config, \
230
249
_sec_tag_list, _sec_tag_list_size); \
231
250
BUILD_ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), \
232
251
"TLS is required for HTTP secure (CONFIG_NET_SOCKETS_SOCKOPT_TLS)")
0 commit comments