summaryrefslogtreecommitdiff
path: root/fw/app/src/http.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/app/src/http.c')
-rw-r--r--fw/app/src/http.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/fw/app/src/http.c b/fw/app/src/http.c
index 1c24490..f9016c1 100644
--- a/fw/app/src/http.c
+++ b/fw/app/src/http.c
@@ -100,26 +100,31 @@ static int settings_handler(
struct http_response_ctx *response_ctx,
void *user_data
) {
- static char buffer[100];
+ static char buffer[SETTINGS_JSON_MAX_LEN];
- int ret = settings_to_json(buffer, sizeof(buffer) - 1);
+ int ret = settings_to_json(buffer, sizeof(buffer));
if (ret < 0) {
LOG_ERR("Could not serialize payload for settings request");
return ret;
}
size_t len = strnlen(buffer, sizeof(buffer));
- if (len + 2 > sizeof(buffer)) {
- LOG_ERR("Settings JSON requires %d octets but buffer has only %d",
- len + 2, sizeof(buffer));
+ if (len >= sizeof(buffer)) {
+ LOG_ERR("End of settings JSON string not found (strnlen returned %d)",
+ sizeof(buffer));
return -ENOMEM;
}
- buffer[len] = '\n';
+ if (sizeof(buffer) < len + 2) {
+ LOG_ERR("Settings JSON buffer too small to hold \\n and \\0");
+ return -ENOMEM;
+ }
+ buffer[len + 0] = '\n';
buffer[len + 1] = '\0';
+ len += 1;
response_ctx->body = (const uint8_t *)buffer;
- response_ctx->body_len = len + 1;
+ response_ctx->body_len = len;
response_ctx->final_chunk = true;
response_ctx->status = HTTP_200_OK;
@@ -130,6 +135,7 @@ static struct http_resource_detail_dynamic settings_resource_detail = {
.common = {
.type = HTTP_RESOURCE_TYPE_DYNAMIC,
.bitmask_of_supported_http_methods = BIT(HTTP_GET),
+ .content_type = "text/json",
},
.cb = settings_handler,
.user_data = NULL,