summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/rest.c b/src/rest.c
index 4b85701..ec1dda6 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -1670,6 +1670,64 @@ static int og_cmd_post_client_server(json_t *element,
return 0;
}
+static int og_cmd_get_center_info(json_t *element,
+ struct og_msg_params *params,
+ char *buffer_reply)
+{
+ struct og_center center = {};
+ json_t *value, *root;
+ struct og_dbi *dbi;
+ const char *key;
+ int err = 0;
+
+ struct og_buffer og_buffer = {
+ .data = buffer_reply
+ };
+
+ json_object_foreach(element, key, value) {
+ if (!strcmp(key, "id")) {
+ err = og_json_parse_uint(value, &center.id);
+ params->flags |= OG_REST_PARAM_CENTER;
+ }
+ if (err < 0)
+ return err;
+ }
+ if (!og_msg_params_validate(params, OG_REST_PARAM_CENTER))
+ return -1;
+
+ dbi = og_dbi_open(&ogconfig.db);
+ if (!dbi) {
+ syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
+ __func__, __LINE__);
+ return -1;
+ }
+
+ if (og_dbi_get_center_info(dbi, &center)) {
+ og_dbi_close(dbi);
+ return -1;
+ }
+ og_dbi_close(dbi);
+
+ root = json_object();
+ if (!root)
+ return -1;
+
+ json_object_set_new(root, "comment",
+ json_string(center.comment));
+ json_object_set_new(root, "id",
+ json_integer(center.id));
+ json_object_set_new(root, "name",
+ json_string(center.name));
+
+ if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) {
+ json_decref(root);
+ return -1;
+ }
+
+ json_decref(root);
+ return 0;
+}
+
static int og_cmd_get_client_info(json_t *element,
struct og_msg_params *params,
char *buffer_reply)
@@ -7510,6 +7568,7 @@ struct {
[OG_URI_CENTER_ADD] = { "center/add", },
[OG_URI_CENTER_UPDATE] = { "center/update", },
[OG_URI_CENTER_DELETE] = { "center/delete", },
+ [OG_URI_CENTER_INFO] = { "center/info", },
[OG_URI_ROOM_ADD] = { "room/add", },
[OG_URI_ROOM_UPDATE] = { "room/update", },
[OG_URI_ROOM_DELETE] = { "room/delete", },
@@ -8222,6 +8281,20 @@ int og_client_state_process_payload_rest(struct og_client *cli)
goto err_process_rest_payload;
}
err = og_cmd_post_center_delete(root, &params);
+ } else if (!strncmp(cmd, "center/info",
+ strlen("center/info"))) {
+ if (method != OG_METHOD_GET) {
+ err = og_client_method_not_found(cli);
+ goto err_process_rest_payload;
+ }
+ if (!root) {
+ syslog(LOG_ERR,
+ "command client info with no payload\n");
+ err = og_client_bad_request(cli);
+ goto err_process_rest_payload;
+ }
+
+ err = og_cmd_get_center_info(root, &params, buf_reply);
} else if (!strncmp(cmd, "center/update", strlen("center/update"))) {
if (method != OG_METHOD_POST) {
err = og_client_method_not_found(cli);