From 403e7c323b3069c8c70088ded30de3096a216e3f Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Wed, 23 Sep 2020 11:01:22 +0200 Subject: #1004 Add GET /images This commit adds GET /images to the ogServer REST API. This call returns information of all the images in ogServer. Example response: { "images": [ { "filename": "ubuntu.img", "datasize": 2150400000, "size": 613476223, "modified": "Wed Sep 23 10:37:36 2020", "permissions": "744" }, { "filename": "test.img", "datasize": 2150400000, "size": 613236475, "modified": "Tue Sep 29 08:57:47 2020", "permissions": "744" } ], "disk": { "total": 52573995008, "free": 39624544256 } } --- src/cfg.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/cfg.c') diff --git a/src/cfg.c b/src/cfg.c index fa88fc1..f4361ec 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -88,9 +88,28 @@ static int parse_json_wol(struct og_server_cfg *cfg, json_t *element) return 0; } +static int parse_json_repo(struct og_server_cfg *cfg, json_t *element) +{ + const char *key; + json_t *value; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "directory")) { + if (og_json_parse_string(value, &cfg->repo.dir) < 0) + return -1; + } else { + syslog(LOG_ERR, "unknown key `%s' in repo\n", key); + return -1; + } + } + + return 0; +} + #define OG_SERVER_CFG_REST (1 << 0) #define OG_SERVER_CFG_DB (1 << 1) #define OG_SERVER_CFG_WOL (1 << 2) +#define OG_SERVER_CFG_REPO (1 << 3) int parse_json_config(const char *filename, struct og_server_cfg *cfg) { @@ -138,6 +157,11 @@ int parse_json_config(const char *filename, struct og_server_cfg *cfg) break; } flags |= OG_SERVER_CFG_DB; + } else if (!strcmp(key, "repository")) { + if (parse_json_repo(cfg, value) < 0) + return -1; + + flags |= OG_SERVER_CFG_REPO; } else { syslog(LOG_ERR, "unknown key `%s' in %s\n", key, filename); @@ -150,7 +174,8 @@ int parse_json_config(const char *filename, struct og_server_cfg *cfg) if ((flags & OG_SERVER_CFG_REST) && (flags & OG_SERVER_CFG_DB) && - (flags & OG_SERVER_CFG_WOL)) { + (flags & OG_SERVER_CFG_WOL) && + (flags & OG_SERVER_CFG_REPO)) { ret = 0; } else { syslog(LOG_ERR, "Missing attributes in json file"); -- cgit v1.2.3-18-g5258