From b04e1ffd275936a1e8b4ec77898b6609d45c056f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Thu, 27 Jun 2024 07:12:31 +0200 Subject: [PATCH] relay: fix read of one buffer line in API protocol --- CHANGELOG.md | 1 + src/plugins/relay/api/relay-api-protocol.c | 29 +++++++++++++++++++--- src/plugins/relay/api/relay-api.h | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63b80b4fc..f18ed8645 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ - core, plugins: return "0x0" instead of "(nil)" for pointers formatted in strings - php: fix return value of function hdata_longlong - tcl: fix return value of function hdata_longlong ([#2119](https://github.com/weechat/weechat/issues/2119)) +- relay: fix read of one buffer line in API protocol - relay: fix websocket permessage-deflate extension when the client doesn't send the max window bits parameters ([#1549](https://github.com/weechat/weechat/issues/1549)) - relay: fix allocation and reinit of field "client_context_takeover" in websocket deflate structure ([#1549](https://github.com/weechat/weechat/issues/1549)) - core: fix completion of command `/item refresh` diff --git a/src/plugins/relay/api/relay-api-protocol.c b/src/plugins/relay/api/relay-api-protocol.c index cb95d54a4..0d596dfb8 100644 --- a/src/plugins/relay/api/relay-api-protocol.c +++ b/src/plugins/relay/api/relay-api-protocol.c @@ -507,8 +507,11 @@ RELAY_API_PROTOCOL_CALLBACK(buffers) { cJSON *json; struct t_gui_buffer *ptr_buffer; - long lines, lines_free; + struct t_gui_line *ptr_line; + struct t_gui_line_data *ptr_line_data; + long lines, lines_free, line_id; int nicks; + char *error; enum t_relay_api_colors colors; ptr_buffer = NULL; @@ -534,8 +537,28 @@ 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", LONG_MAX); - json = relay_api_msg_lines_to_json (ptr_buffer, lines, colors); + if (client->http_req->num_path_items > 4) + { + line_id = strtol (client->http_req->path_items[4], &error, 10); + ptr_line = (error && !error[0]) ? + weechat_line_search_by_id (ptr_buffer, line_id) : NULL; + ptr_line_data = (ptr_line) ? + weechat_hdata_pointer (relay_hdata_line, ptr_line, "data") : NULL; + if (!ptr_line_data) + { + relay_api_msg_send_error_json (client, RELAY_HTTP_404_NOT_FOUND, NULL, + "Line \"%s\" not found in buffer \"%s\"", + client->http_req->path_items[4], + client->http_req->path_items[2]); + return RELAY_API_PROTOCOL_RC_OK; + } + json = relay_api_msg_line_data_to_json (ptr_line_data, colors); + } + else + { + 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) { diff --git a/src/plugins/relay/api/relay-api.h b/src/plugins/relay/api/relay-api.h index ab92d1fa7..05a262f18 100644 --- a/src/plugins/relay/api/relay-api.h +++ b/src/plugins/relay/api/relay-api.h @@ -24,7 +24,7 @@ struct t_relay_client; enum t_relay_status; #define RELAY_API_VERSION_MAJOR 0 -#define RELAY_API_VERSION_MINOR 1 +#define RELAY_API_VERSION_MINOR 2 #define RELAY_API_VERSION_PATCH 0 #define RELAY_API_VERSION_NUMBER \ ((RELAY_API_VERSION_MAJOR << 16) \