| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 | /*
 * This Source Code Form is subject to the terms of the Mozilla Public License,
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
 * obtain one at https://mozilla.org/MPL/2.0/.
 */
#include <stdbool.h>
#include <zephyr/dfu/flash_img.h>
#include <zephyr/logging/log.h>
#include <zephyr/net/http/server.h>
#include <zephyr/net/http/service.h>
#include <zephyr/net/http/status.h>
LOG_MODULE_REGISTER(update);
static int update_handler(
	struct http_client_ctx *client,
	enum http_data_status status,
	const struct http_request_ctx *request_ctx,
	struct http_response_ctx *response_ctx,
	void *user_data
) {
	static size_t processed;
	if (status == HTTP_SERVER_DATA_ABORTED) {
		LOG_WRN("Transaction aborted after %zd bytes.", processed);
		processed = 0;
		return 0;
	}
	processed += request_ctx->data_len;
	if (status == HTTP_SERVER_DATA_FINAL) {
		LOG_INF("Handled update request receiving %zd octets.", processed);
		processed = 0;
	}
	return 0;
}
static struct http_resource_detail_dynamic update_resource_detail = {
	.common = {
			.type = HTTP_RESOURCE_TYPE_DYNAMIC,
			.bitmask_of_supported_http_methods = BIT(HTTP_PUT),
		},
	.cb = update_handler,
	.user_data = NULL,
};
HTTP_RESOURCE_DEFINE(update_resource, http_service, "/update", &update_resource_detail);
 |