diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-01 13:51:32 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-01 13:53:58 +0200 |
commit | afe037c579b541bb86657916abef23a7ab8907bb (patch) | |
tree | 432e1b6fa950f00002314c638a4b7735b923467c /src/plugins/relay | |
parent | c5268bc5f9df20ae3de45776cee68e66035bd885 (diff) | |
download | weechat-afe037c579b541bb86657916abef23a7ab8907bb.zip |
relay/api: add buffer keys in GET /api/buffers (issue #2066)
Diffstat (limited to 'src/plugins/relay')
-rw-r--r-- | src/plugins/relay/api/relay-api-msg.c | 55 | ||||
-rw-r--r-- | src/plugins/relay/api/relay-api-msg.h | 8 | ||||
-rw-r--r-- | src/plugins/relay/relay.c | 2 | ||||
-rw-r--r-- | src/plugins/relay/relay.h | 1 |
4 files changed, 63 insertions, 3 deletions
diff --git a/src/plugins/relay/api/relay-api-msg.c b/src/plugins/relay/api/relay-api-msg.c index 929428469..2bcd5bc95 100644 --- a/src/plugins/relay/api/relay-api-msg.c +++ b/src/plugins/relay/api/relay-api-msg.c @@ -405,6 +405,9 @@ relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer, cJSON_AddItemToObject (json, "local_variables", json_local_vars); } + /* keys local to buffer */ + cJSON_AddItemToObject (json, "keys", relay_api_msg_keys_to_json (buffer)); + /* lines */ if (lines != 0) { @@ -427,6 +430,58 @@ relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer, } /* + * Creates a JSON object with a buffer key. + */ + +cJSON * +relay_api_msg_key_to_json (struct t_gui_key *key) +{ + struct t_hdata *hdata; + struct t_gui_key *pointer; + cJSON *json; + const char *ptr_string; + + hdata = relay_hdata_key; + pointer = key; + + json = cJSON_CreateObject (); + if (!json) + return NULL; + + if (!key) + return json; + + MSG_ADD_HDATA_STR("key", "key"); + MSG_ADD_HDATA_STR("command", "command"); + + return json; +} + +/* + * Creates a JSON object with an array of buffer keys. + */ + +cJSON * +relay_api_msg_keys_to_json (struct t_gui_buffer *buffer) +{ + cJSON *json; + struct t_gui_key *ptr_key; + + json = cJSON_CreateArray (); + if (!json) + return NULL; + + ptr_key = weechat_hdata_pointer (relay_hdata_buffer, buffer, "keys"); + while (ptr_key) + { + cJSON_AddItemToArray (json, relay_api_msg_key_to_json (ptr_key)); + ptr_key = weechat_hdata_move (relay_hdata_key, ptr_key, 1); + } + + return json; +} + +/* * Creates a JSON object with a buffer line data. */ diff --git a/src/plugins/relay/api/relay-api-msg.h b/src/plugins/relay/api/relay-api-msg.h index 16516b4f4..f28f3b642 100644 --- a/src/plugins/relay/api/relay-api-msg.h +++ b/src/plugins/relay/api/relay-api-msg.h @@ -41,11 +41,13 @@ extern cJSON *relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer, long lines, int nicks, enum t_relay_api_colors colors); -extern cJSON *relay_api_msg_lines_to_json (struct t_gui_buffer *pointer, - long lines, - enum t_relay_api_colors colors); +extern cJSON *relay_api_msg_key_to_json (struct t_gui_key *key); +extern cJSON *relay_api_msg_keys_to_json (struct t_gui_buffer *buffer); extern cJSON *relay_api_msg_line_data_to_json (struct t_gui_line_data *line_data, enum t_relay_api_colors colors); +extern cJSON *relay_api_msg_lines_to_json (struct t_gui_buffer *buffer, + long lines, + enum t_relay_api_colors colors); extern cJSON *relay_api_msg_nick_to_json (struct t_gui_nick *nick, enum t_relay_api_colors colors); extern cJSON *relay_api_msg_nick_group_to_json (struct t_gui_nick_group *nick_group, diff --git a/src/plugins/relay/relay.c b/src/plugins/relay/relay.c index f643ec860..b81d08ac7 100644 --- a/src/plugins/relay/relay.c +++ b/src/plugins/relay/relay.c @@ -62,6 +62,7 @@ char *relay_msg_type_string[] = /* prefix in raw buffer for msg */ { "", "[PING]\n", "[PONG]\n", "[CLOSE]\n" }; struct t_hdata *relay_hdata_buffer = NULL; +struct t_hdata *relay_hdata_key = NULL; struct t_hdata *relay_hdata_lines = NULL; struct t_hdata *relay_hdata_line = NULL; struct t_hdata *relay_hdata_line_data = NULL; @@ -251,6 +252,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_plugin = plugin; relay_hdata_buffer = weechat_hdata_get ("buffer"); + relay_hdata_key = weechat_hdata_get ("key"); relay_hdata_lines = weechat_hdata_get ("lines"); relay_hdata_line = weechat_hdata_get ("line"); relay_hdata_line_data = weechat_hdata_get ("line_data"); diff --git a/src/plugins/relay/relay.h b/src/plugins/relay/relay.h index c78efea74..f30a5c054 100644 --- a/src/plugins/relay/relay.h +++ b/src/plugins/relay/relay.h @@ -27,6 +27,7 @@ extern struct t_weechat_plugin *weechat_relay_plugin; extern struct t_hdata *relay_hdata_buffer; +extern struct t_hdata *relay_hdata_key; extern struct t_hdata *relay_hdata_lines; extern struct t_hdata *relay_hdata_line; extern struct t_hdata *relay_hdata_line_data; |