summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2021-04-05 16:01:14 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-04-05 18:00:56 +0200
commit8015f85b04c30350acbea8ce939a98b1f4c51cd8 (patch)
tree551b3bc57095c9274c6838f0f8f8187adbd6f2ec /src/rest.c
parentd9e1521a16f4633d895f7b6734acc59565f5f8d0 (diff)
#915 Add GET /oglive/test REST API function
This function returns the installed and available ogLiveS in the server to be booted from. Request: GET /oglive/list NO BODY Response 200 OK { "oglive": [ { "distribution": "bionic", "kernel": "5.4.0-40-generic", "architecture": "amd64", "revision": "r20200629", "directory": "ogLive-5.4.0-r20200629", "iso": "ogLive-bionic-5.4.0-40-generic-amd64-r20200629.85eceaf.iso" }, { "distribution": "bionic", "kernel": "5.0.0-27-generic", "architecture": "amd64", "revision": "r20190830", "directory": "ogLive-5.0.0-r20190830", "iso": "ogLive-bionic-5.0.0-27-generic-amd64-r20190830.7208cc9.iso" } ], "default": 0 } This commit also adds tests for GET /oglive/test.
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/rest.c b/src/rest.c
index 39b0022..b134ba4 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -3770,6 +3770,29 @@ static int og_cmd_schedule_get(json_t *element, struct og_msg_params *params,
return err;
}
+#define OG_LIVE_JSON_FILE_PATH "/opt/opengnsys/etc/ogliveinfo.json"
+
+static int og_cmd_oglive_list(char *buffer_reply)
+{
+ struct og_buffer og_buffer = {
+ .data = buffer_reply
+ };
+ json_error_t json_err;
+ json_t *root;
+
+ root = json_load_file(OG_LIVE_JSON_FILE_PATH, 0, &json_err);
+ if (!root) {
+ syslog(LOG_ERR, "malformed json line %d: %s\n",
+ json_err.line, json_err.text);
+ return -1;
+ }
+
+ json_dump_callback(root, og_json_dump_clients, &og_buffer, 0);
+ json_decref(root);
+
+ return 0;
+}
+
static int og_client_method_not_found(struct og_client *cli)
{
/* To meet RFC 7231, this function MUST generate an Allow header field
@@ -4241,6 +4264,14 @@ int og_client_state_process_payload_rest(struct og_client *cli)
}
err = og_cmd_schedule_get(root, &params, buf_reply);
+ } else if (!strncmp(cmd, "oglive/list",
+ strlen("oglive/list"))) {
+ if (method != OG_METHOD_GET) {
+ err = og_client_method_not_found(cli);
+ goto err_process_rest_payload;
+ }
+
+ err = og_cmd_oglive_list(buf_reply);
} else {
syslog(LOG_ERR, "unknown command: %.32s ...\n", cmd);
err = og_client_not_found(cli);