1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 14:26:39 +02:00

relay/api: add parameter "lines_free" in GET /api/buffers

This parameter is the number of lines to return for buffers with free content.

Its default value is `0` if "lines" is set to `0`, otherwise all buffer lines
are returned.
This commit is contained in:
Sébastien Helleu
2024-05-05 22:30:04 +02:00
parent 9ceea3697b
commit 211cd11c2a
4 changed files with 66 additions and 13 deletions
+4
View File
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <sys/time.h>
@@ -355,6 +356,7 @@ relay_api_msg_buffer_add_local_vars_cb (void *data,
cJSON *
relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer,
long lines,
long lines_free,
int nicks,
enum t_relay_api_colors colors)
{
@@ -379,6 +381,8 @@ relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer,
MSG_ADD_HDATA_STR("short_name", "short_name");
MSG_ADD_HDATA_VAR(Number, "number", integer, "number");
ptr_string = weechat_buffer_get_string (buffer, "type");
if (weechat_strcmp (ptr_string, "free") == 0)
lines = lines_free;
MSG_ADD_STR_PTR("type", ptr_string);
MSG_ADD_HDATA_STR_COLORS("title", "title");
MSG_ADD_HDATA_VAR(Bool, "nicklist", integer, "nicklist");
+1
View File
@@ -40,6 +40,7 @@ extern int relay_api_msg_send_event (struct t_relay_client *client,
cJSON *json_body);
extern cJSON *relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer,
long lines,
long lines_free,
int nicks,
enum t_relay_api_colors colors);
extern cJSON *relay_api_msg_key_to_json (struct t_gui_key *key);
+15 -8
View File
@@ -71,7 +71,7 @@ relay_api_protocol_signal_buffer_cb (const void *pointer, void *data,
struct t_gui_line *ptr_line;
struct t_gui_line_data *ptr_line_data;
cJSON *json;
long lines;
long lines, lines_free;
long long buffer_id;
int nicks;
const char *ptr_id;
@@ -142,18 +142,21 @@ relay_api_protocol_signal_buffer_cb (const void *pointer, void *data,
/* we get all lines and nicks when a buffer is opened, otherwise none */
if (strcmp (signal, "buffer_opened") == 0)
{
lines = LONG_MIN;
lines = LONG_MAX;
lines_free = LONG_MAX;
nicks = 1;
}
else
{
lines = 0;
lines_free = 0;
nicks = 0;
}
/* build body with buffer info */
json = relay_api_msg_buffer_to_json (
ptr_buffer, lines, nicks, RELAY_API_DATA(ptr_client, sync_colors));
ptr_buffer, lines, lines_free, nicks,
RELAY_API_DATA(ptr_client, sync_colors));
/* send to client */
if (json)
@@ -462,7 +465,7 @@ RELAY_API_PROTOCOL_CALLBACK(buffers)
{
cJSON *json;
struct t_gui_buffer *ptr_buffer;
long lines;
long lines, lines_free;
int nicks;
enum t_relay_api_colors colors;
@@ -489,7 +492,7 @@ RELAY_API_PROTOCOL_CALLBACK(buffers)
/* sub-resource of buffers */
if (strcmp (client->http_req->path_items[3], "lines") == 0)
{
lines = relay_http_get_param_long (client->http_req, "lines", -100L);
lines = relay_http_get_param_long (client->http_req, "lines", LONG_MAX);
json = relay_api_msg_lines_to_json (ptr_buffer, lines, colors);
}
else if (strcmp (client->http_req->path_items[3], "nicks") == 0)
@@ -511,9 +514,13 @@ RELAY_API_PROTOCOL_CALLBACK(buffers)
else
{
lines = relay_http_get_param_long (client->http_req, "lines", 0L);
lines_free = relay_http_get_param_long (client->http_req,
"lines_free",
(lines == 0) ? 0 : LONG_MAX);
if (ptr_buffer)
{
json = relay_api_msg_buffer_to_json (ptr_buffer, lines, nicks, colors);
json = relay_api_msg_buffer_to_json (ptr_buffer, lines, lines_free,
nicks, colors);
}
else
{
@@ -526,8 +533,8 @@ RELAY_API_PROTOCOL_CALLBACK(buffers)
{
cJSON_AddItemToArray (
json,
relay_api_msg_buffer_to_json (ptr_buffer,
lines, nicks, colors));
relay_api_msg_buffer_to_json (ptr_buffer, lines, lines_free,
nicks, colors));
ptr_buffer = weechat_hdata_move (relay_hdata_buffer, ptr_buffer, 1);
}
}