1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 17:53:13 +02:00

relay/api: add buffer keys in GET /api/buffers (issue #2066)

This commit is contained in:
Sébastien Helleu
2024-05-01 13:51:32 +02:00
parent c5268bc5f9
commit afe037c579
6 changed files with 81 additions and 4 deletions
+55
View File
@@ -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)
{
@@ -426,6 +429,58 @@ relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer,
return json;
}
/*
* 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.
*/
+5 -3
View File
@@ -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,
+2
View File
@@ -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");
+1
View File
@@ -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;
+1
View File
@@ -49,6 +49,7 @@ struct t_gui_bar_window;
struct t_gui_buffer;
struct t_gui_completion;
struct t_gui_hotlist;
struct t_gui_key;
struct t_gui_line;
struct t_gui_line_data;
struct t_gui_lines;