From 33b0c6f694c3365e6280b01d9253aefa892075e9 Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Mon, 6 Jul 2020 17:26:40 +0200 Subject: Add POST /modes REST request This patch implements HTTP POST /modes request which can change the mode of any particular scope. Request: POST /modes { "scope": {"id": 1, "type": "computer"}, "mode": "pxe" } Response: 200 OK --- src/json.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/json.c') diff --git a/src/json.c b/src/json.c index b76a3b7..078dfb7 100644 --- a/src/json.c +++ b/src/json.c @@ -39,6 +39,35 @@ int og_json_parse_bool(json_t *element, bool *value) return 0; } +int og_json_parse_scope(json_t *element, struct og_scope *scope, + const uint64_t required_flags) +{ + uint64_t flags = 0UL; + const char *key; + json_t *value; + int err = 0; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "id")) { + err = og_json_parse_uint(value, &scope->id); + flags |= OG_PARAM_SCOPE_ID; + } else if (!strcmp(key, "type")) { + err = og_json_parse_string(value, &scope->type); + flags |= OG_PARAM_SCOPE_TYPE; + } else { + err = -1; + } + + if (err < 0) + return err; + } + + if (flags != required_flags) + return -1; + + return err; +} + int og_json_parse_partition(json_t *element, struct og_partition *part, uint64_t required_flags) { -- cgit v1.2.3-18-g5258