summaryrefslogtreecommitdiff
path: root/src/plugins/relay/api
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2024-05-05 22:30:04 +0200
committerSébastien Helleu <flashcode@flashtux.org>2024-05-05 22:30:04 +0200
commit211cd11c2a310e336ecd8760d8f33fd04dc99590 (patch)
tree3e5be77b6ef0647339dcab2e292470229e3f3487 /src/plugins/relay/api
parent9ceea3697bf5f194d4a86e46dd9b04012dc0592c (diff)
downloadweechat-211cd11c2a310e336ecd8760d8f33fd04dc99590.zip
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.
Diffstat (limited to 'src/plugins/relay/api')
-rw-r--r--src/plugins/relay/api/relay-api-msg.c4
-rw-r--r--src/plugins/relay/api/relay-api-msg.h1
-rw-r--r--src/plugins/relay/api/relay-api-protocol.c23
3 files changed, 20 insertions, 8 deletions
diff --git a/src/plugins/relay/api/relay-api-msg.c b/src/plugins/relay/api/relay-api-msg.c
index d02868301..71b990b02 100644
--- a/src/plugins/relay/api/relay-api-msg.c
+++ b/src/plugins/relay/api/relay-api-msg.c
@@ -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");
diff --git a/src/plugins/relay/api/relay-api-msg.h b/src/plugins/relay/api/relay-api-msg.h
index 3dc72620c..8d171ef78 100644
--- a/src/plugins/relay/api/relay-api-msg.h
+++ b/src/plugins/relay/api/relay-api-msg.h
@@ -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);
diff --git a/src/plugins/relay/api/relay-api-protocol.c b/src/plugins/relay/api/relay-api-protocol.c
index d73001b28..a025db3cc 100644
--- a/src/plugins/relay/api/relay-api-protocol.c
+++ b/src/plugins/relay/api/relay-api-protocol.c
@@ -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);
}
}