1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 07:16:37 +02:00

relay: add global relay hdata variables

This commit is contained in:
Sébastien Helleu
2024-01-06 09:55:30 +01:00
parent 57a206287a
commit 5df85c7a53
7 changed files with 136 additions and 134 deletions
+22 -31
View File
@@ -703,8 +703,7 @@ relay_irc_hsignal_irc_redir_cb (const void *pointer, void *data,
* - host
* - message (without colors).
*
* Arguments hdata_line_data and line_data must be non NULL, the other arguments
* can be NULL.
* Argument line_data must be non NULL, the other arguments can be NULL.
*
* Note: tags and message (if given and filled) must be freed after use.
*/
@@ -712,7 +711,7 @@ relay_irc_hsignal_irc_redir_cb (const void *pointer, void *data,
void
relay_irc_get_line_info (struct t_relay_client *client,
struct t_gui_buffer *buffer,
struct t_hdata *hdata_line_data, void *line_data,
struct t_gui_line_data *line_data,
int *irc_command, int *irc_action, time_t *date,
const char **nick, const char **nick1,
const char **nick2, const char **host,
@@ -744,10 +743,10 @@ relay_irc_get_line_info (struct t_relay_client *client,
if (message)
*message = NULL;
msg_date = weechat_hdata_time (hdata_line_data, line_data, "date");
num_tags = weechat_hdata_get_var_array_size (hdata_line_data, line_data,
msg_date = weechat_hdata_time (relay_hdata_line_data, line_data, "date");
num_tags = weechat_hdata_get_var_array_size (relay_hdata_line_data, line_data,
"tags_array");
ptr_message = weechat_hdata_pointer (hdata_line_data, line_data, "message");
ptr_message = weechat_hdata_pointer (relay_hdata_line_data, line_data, "message");
/* no tag found, or no message? just exit */
if ((num_tags <= 0) || !ptr_message)
@@ -764,7 +763,7 @@ relay_irc_get_line_info (struct t_relay_client *client,
for (i = 0; i < num_tags; i++)
{
snprintf (str_tag, sizeof (str_tag), "%d|tags_array", i);
ptr_tag = weechat_hdata_string (hdata_line_data, line_data, str_tag);
ptr_tag = weechat_hdata_string (relay_hdata_line_data, line_data, str_tag);
if (ptr_tag)
{
if (strcmp (ptr_tag, "irc_action") == 0)
@@ -885,35 +884,26 @@ relay_irc_send_channel_backlog (struct t_relay_client *client,
struct t_gui_buffer *buffer)
{
struct t_relay_server *ptr_server;
void *ptr_own_lines, *ptr_line, *ptr_line_data;
void *ptr_hdata_line, *ptr_hdata_line_data;
struct t_gui_lines *ptr_own_lines;
struct t_gui_line *ptr_line;
struct t_gui_line_data *ptr_line_data;
char *tags, *message;
const char *ptr_nick, *ptr_nick1, *ptr_nick2, *ptr_host, *localvar_nick;
int irc_command, irc_action, count, max_number, max_minutes;
time_t date_min, date_min2, date;
/* get pointer on "own_lines" in buffer */
ptr_own_lines = weechat_hdata_pointer (weechat_hdata_get ("buffer"),
ptr_own_lines = weechat_hdata_pointer (relay_hdata_buffer,
buffer, "own_lines");
if (!ptr_own_lines)
return;
/* get pointer on "last_line" in lines */
ptr_line = weechat_hdata_pointer (weechat_hdata_get ("lines"),
ptr_line = weechat_hdata_pointer (relay_hdata_lines,
ptr_own_lines, "last_line");
if (!ptr_line)
return;
/* get hdata "line" */
ptr_hdata_line = weechat_hdata_get ("line");
if (!ptr_hdata_line)
return;
/* get hdata "line_data" */
ptr_hdata_line_data = weechat_hdata_get ("line_data");
if (!ptr_hdata_line_data)
return;
localvar_nick = NULL;
if (weechat_config_boolean (relay_config_irc_backlog_since_last_message))
localvar_nick = weechat_buffer_get_string (buffer, "localvar_nick");
@@ -939,12 +929,13 @@ relay_irc_send_channel_backlog (struct t_relay_client *client,
count = 0;
while (ptr_line)
{
ptr_line_data = weechat_hdata_pointer (ptr_hdata_line,
ptr_line_data = weechat_hdata_pointer (relay_hdata_line,
ptr_line, "data");
if (ptr_line_data)
{
relay_irc_get_line_info (client, buffer,
ptr_hdata_line_data, ptr_line_data,
relay_irc_get_line_info (client,
buffer,
ptr_line_data,
&irc_command,
NULL, /* irc_action */
&date,
@@ -972,23 +963,23 @@ relay_irc_send_channel_backlog (struct t_relay_client *client,
* stop when we find a line sent by the current nick
* (and include this line)
*/
ptr_line = weechat_hdata_move (ptr_hdata_line, ptr_line, -1);
ptr_line = weechat_hdata_move (relay_hdata_line, ptr_line, -1);
break;
}
}
ptr_line = weechat_hdata_move (ptr_hdata_line, ptr_line, -1);
ptr_line = weechat_hdata_move (relay_hdata_line, ptr_line, -1);
}
if (!ptr_line)
{
/* if we have reached beginning of buffer, start from first line */
ptr_line = weechat_hdata_pointer (weechat_hdata_get ("lines"),
ptr_line = weechat_hdata_pointer (relay_hdata_lines,
ptr_own_lines, "first_line");
}
else
{
/* start from line + 1 (the current line must not be sent) */
ptr_line = weechat_hdata_move (ptr_hdata_line, ptr_line, 1);
ptr_line = weechat_hdata_move (relay_hdata_line, ptr_line, 1);
}
/*
@@ -997,12 +988,12 @@ relay_irc_send_channel_backlog (struct t_relay_client *client,
*/
while (ptr_line)
{
ptr_line_data = weechat_hdata_pointer (ptr_hdata_line,
ptr_line_data = weechat_hdata_pointer (relay_hdata_line,
ptr_line, "data");
if (ptr_line_data)
{
relay_irc_get_line_info (client, buffer,
ptr_hdata_line_data, ptr_line_data,
ptr_line_data,
&irc_command,
&irc_action,
&date,
@@ -1074,7 +1065,7 @@ relay_irc_send_channel_backlog (struct t_relay_client *client,
if (message)
free (message);
}
ptr_line = weechat_hdata_move (ptr_hdata_line, ptr_line, 1);
ptr_line = weechat_hdata_move (relay_hdata_line, ptr_line, 1);
}
}
+20 -2
View File
@@ -46,11 +46,20 @@ WEECHAT_PLUGIN_PRIORITY(RELAY_PLUGIN_PRIORITY);
struct t_weechat_plugin *weechat_relay_plugin = NULL;
int relay_signal_upgrade_received = 0; /* signal "upgrade" received ? */
char *relay_protocol_string[] = /* strings for protocols */
{ "weechat", "irc" };
struct t_hdata *relay_hdata_buffer = NULL;
struct t_hdata *relay_hdata_lines = NULL;
struct t_hdata *relay_hdata_line = NULL;
struct t_hdata *relay_hdata_line_data = NULL;
struct t_hdata *relay_hdata_nick_group = NULL;
struct t_hdata *relay_hdata_nick = NULL;
struct t_hdata *relay_hdata_completion = NULL;
struct t_hdata *relay_hdata_completion_word = NULL;
int relay_signal_upgrade_received = 0; /* signal "upgrade" received ? */
struct t_hook *relay_hook_timer = NULL;
@@ -203,6 +212,15 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_plugin = plugin;
relay_hdata_buffer = weechat_hdata_get ("buffer");
relay_hdata_lines = weechat_hdata_get ("lines");
relay_hdata_line = weechat_hdata_get ("line");
relay_hdata_line_data = weechat_hdata_get ("line_data");
relay_hdata_nick_group = weechat_hdata_get ("nick_group");
relay_hdata_nick = weechat_hdata_get ("nick");
relay_hdata_completion = weechat_hdata_get ("completion");
relay_hdata_completion_word = weechat_hdata_get ("completion_word");
relay_signal_upgrade_received = 0;
if (!relay_config_init ())
+9
View File
@@ -26,6 +26,15 @@
extern struct t_weechat_plugin *weechat_relay_plugin;
extern struct t_hdata *relay_hdata_buffer;
extern struct t_hdata *relay_hdata_lines;
extern struct t_hdata *relay_hdata_line;
extern struct t_hdata *relay_hdata_line_data;
extern struct t_hdata *relay_hdata_nick_group;
extern struct t_hdata *relay_hdata_nick;
extern struct t_hdata *relay_hdata_completion;
extern struct t_hdata *relay_hdata_completion_word;
extern int relay_signal_upgrade_received;
/* relay protocol */
+47 -44
View File
@@ -882,7 +882,6 @@ relay_weechat_msg_add_nicklist_buffer (struct t_relay_weechat_msg *msg,
struct t_relay_weechat_nicklist *nicklist)
{
int count, i;
struct t_hdata *ptr_hdata_group, *ptr_hdata_nick;
struct t_gui_nick_group *ptr_group;
struct t_gui_nick *ptr_nick;
@@ -909,9 +908,6 @@ relay_weechat_msg_add_nicklist_buffer (struct t_relay_weechat_msg *msg,
else
{
/* send full nicklist */
ptr_hdata_group = weechat_hdata_get ("nick_group");
ptr_hdata_nick = weechat_hdata_get ("nick");
ptr_group = NULL;
ptr_nick = NULL;
weechat_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick);
@@ -922,27 +918,32 @@ relay_weechat_msg_add_nicklist_buffer (struct t_relay_weechat_msg *msg,
relay_weechat_msg_add_pointer (msg, buffer);
relay_weechat_msg_add_pointer (msg, ptr_nick);
relay_weechat_msg_add_char (msg, 0); /* group */
relay_weechat_msg_add_char (msg,
(char)weechat_hdata_integer (ptr_hdata_nick,
ptr_nick,
"visible"));
relay_weechat_msg_add_char (
msg,
(char)weechat_hdata_integer (relay_hdata_nick,
ptr_nick,
"visible"));
relay_weechat_msg_add_int (msg, 0); /* level */
relay_weechat_msg_add_string (msg,
weechat_hdata_string (ptr_hdata_nick,
ptr_nick,
"name"));
relay_weechat_msg_add_string (msg,
weechat_hdata_string (ptr_hdata_nick,
ptr_nick,
"color"));
relay_weechat_msg_add_string (msg,
weechat_hdata_string (ptr_hdata_nick,
ptr_nick,
"prefix"));
relay_weechat_msg_add_string (msg,
weechat_hdata_string (ptr_hdata_nick,
ptr_nick,
"prefix_color"));
relay_weechat_msg_add_string (
msg,
weechat_hdata_string (relay_hdata_nick,
ptr_nick,
"name"));
relay_weechat_msg_add_string (
msg,
weechat_hdata_string (relay_hdata_nick,
ptr_nick,
"color"));
relay_weechat_msg_add_string (
msg,
weechat_hdata_string (relay_hdata_nick,
ptr_nick,
"prefix"));
relay_weechat_msg_add_string (
msg,
weechat_hdata_string (relay_hdata_nick,
ptr_nick,
"prefix_color"));
count++;
}
else
@@ -950,22 +951,26 @@ relay_weechat_msg_add_nicklist_buffer (struct t_relay_weechat_msg *msg,
relay_weechat_msg_add_pointer (msg, buffer);
relay_weechat_msg_add_pointer (msg, ptr_group);
relay_weechat_msg_add_char (msg, 1); /* group */
relay_weechat_msg_add_char (msg,
(char)weechat_hdata_integer (ptr_hdata_group,
ptr_group,
"visible"));
relay_weechat_msg_add_int (msg,
weechat_hdata_integer (ptr_hdata_group,
ptr_group,
"level"));
relay_weechat_msg_add_string (msg,
weechat_hdata_string (ptr_hdata_group,
ptr_group,
"name"));
relay_weechat_msg_add_string (msg,
weechat_hdata_string (ptr_hdata_group,
ptr_group,
"color"));
relay_weechat_msg_add_char (
msg,
(char)weechat_hdata_integer (relay_hdata_nick_group,
ptr_group,
"visible"));
relay_weechat_msg_add_int (
msg,
weechat_hdata_integer (relay_hdata_nick_group,
ptr_group,
"level"));
relay_weechat_msg_add_string (
msg,
weechat_hdata_string (relay_hdata_nick_group,
ptr_group,
"name"));
relay_weechat_msg_add_string (
msg,
weechat_hdata_string (relay_hdata_nick_group,
ptr_group,
"color"));
relay_weechat_msg_add_string (msg, NULL); /* prefix */
relay_weechat_msg_add_string (msg, NULL); /* prefix_color */
count++;
@@ -990,7 +995,6 @@ relay_weechat_msg_add_nicklist (struct t_relay_weechat_msg *msg,
struct t_relay_weechat_nicklist *nicklist)
{
char str_vars[512];
struct t_hdata *ptr_hdata;
struct t_gui_buffer *ptr_buffer;
int pos_count, count;
uint32_t count32;
@@ -1016,12 +1020,11 @@ relay_weechat_msg_add_nicklist (struct t_relay_weechat_msg *msg,
}
else
{
ptr_hdata = weechat_hdata_get ("buffer");
ptr_buffer = weechat_hdata_get_list (ptr_hdata, "gui_buffers");
ptr_buffer = weechat_hdata_get_list (relay_hdata_buffer, "gui_buffers");
while (ptr_buffer)
{
count += relay_weechat_msg_add_nicklist_buffer (msg, ptr_buffer, NULL);
ptr_buffer = weechat_hdata_move (ptr_hdata, ptr_buffer, 1);
ptr_buffer = weechat_hdata_move (relay_hdata_buffer, ptr_buffer, 1);
}
}
@@ -91,12 +91,12 @@ relay_weechat_nicklist_add_item (struct t_relay_weechat_nicklist *nicklist,
ptr_item = &(nicklist->items[nicklist->items_count]);
if (group)
{
hdata = weechat_hdata_get ("nick_group");
hdata = relay_hdata_nick_group;
ptr_item->pointer = group;
}
else
{
hdata = weechat_hdata_get ("nick");
hdata = relay_hdata_nick;
ptr_item->pointer = nick;
}
ptr_item->diff = diff;
@@ -51,7 +51,6 @@ relay_weechat_protocol_get_buffer (const char *arg)
struct t_gui_buffer *ptr_buffer;
unsigned long value;
int rc;
struct t_hdata *ptr_hdata;
ptr_buffer = NULL;
@@ -62,10 +61,10 @@ relay_weechat_protocol_get_buffer (const char *arg)
ptr_buffer = (struct t_gui_buffer *)value;
if (ptr_buffer)
{
ptr_hdata = weechat_hdata_get ("buffer");
if (!weechat_hdata_check_pointer (ptr_hdata,
weechat_hdata_get_list (ptr_hdata, "gui_buffers"),
ptr_buffer))
if (!weechat_hdata_check_pointer (
relay_hdata_buffer,
weechat_hdata_get_list (relay_hdata_buffer, "gui_buffers"),
ptr_buffer))
{
/* invalid pointer! */
ptr_buffer = NULL;
@@ -658,6 +657,7 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(input)
"commands",
weechat_config_string (relay_config_weechat_commands));
}
/*
* delay the execution of command after we go back in the WeeChat
* main loop (some commands like /upgrade executed now can cause
@@ -687,7 +687,6 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(completion)
struct t_gui_buffer *ptr_buffer;
struct t_gui_completion *completion;
struct t_gui_completion_word *word;
struct t_hdata *ptr_hdata_completion, *ptr_hdata_completion_word;
struct t_arraylist *ptr_list;
struct t_relay_weechat_msg *msg;
char *error, *pos_data;
@@ -740,15 +739,7 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(completion)
goto error;
}
ptr_hdata_completion = weechat_hdata_get ("completion");
if (!ptr_hdata_completion)
goto error;
ptr_hdata_completion_word = weechat_hdata_get ("completion_word");
if (!ptr_hdata_completion_word)
goto error;
ptr_list = weechat_hdata_pointer (ptr_hdata_completion, completion, "list");
ptr_list = weechat_hdata_pointer (relay_hdata_completion, completion, "list");
if (!ptr_list)
goto error;
@@ -767,7 +758,7 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(completion)
relay_weechat_msg_add_int (msg, 1); /* count */
relay_weechat_msg_add_pointer (msg, completion);
/* context */
context = weechat_hdata_integer (ptr_hdata_completion, completion,
context = weechat_hdata_integer (relay_hdata_completion, completion,
"context");
switch (context)
{
@@ -787,10 +778,10 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(completion)
/* base_word */
relay_weechat_msg_add_string (
msg,
weechat_hdata_string (ptr_hdata_completion,
weechat_hdata_string (relay_hdata_completion,
completion, "base_word"));
/* pos_start */
pos_start = weechat_hdata_integer (ptr_hdata_completion,
pos_start = weechat_hdata_integer (relay_hdata_completion,
completion, "position_replace");
relay_weechat_msg_add_int (msg, pos_start);
@@ -801,7 +792,7 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(completion)
/* add_space */
relay_weechat_msg_add_int (
msg,
weechat_hdata_integer (ptr_hdata_completion,
weechat_hdata_integer (relay_hdata_completion,
completion, "add_space"));
/* list */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
@@ -813,7 +804,7 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(completion)
ptr_list, i);
relay_weechat_msg_add_string (
msg,
weechat_hdata_string (ptr_hdata_completion_word, word, "word"));
weechat_hdata_string (relay_hdata_completion_word, word, "word"));
}
/* send message */
@@ -857,7 +848,6 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data,
{
struct t_relay_client *ptr_client;
struct t_gui_line *ptr_line;
struct t_hdata *ptr_hdata_line, *ptr_hdata_line_data;
struct t_gui_line_data *ptr_line_data;
struct t_gui_buffer *ptr_buffer;
struct t_relay_weechat_msg *msg;
@@ -1116,19 +1106,11 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data,
if (!ptr_line)
return WEECHAT_RC_OK;
ptr_hdata_line = weechat_hdata_get ("line");
if (!ptr_hdata_line)
return WEECHAT_RC_OK;
ptr_hdata_line_data = weechat_hdata_get ("line_data");
if (!ptr_hdata_line_data)
return WEECHAT_RC_OK;
ptr_line_data = weechat_hdata_pointer (ptr_hdata_line, ptr_line, "data");
ptr_line_data = weechat_hdata_pointer (relay_hdata_line, ptr_line, "data");
if (!ptr_line_data)
return WEECHAT_RC_OK;
ptr_buffer = weechat_hdata_pointer (ptr_hdata_line_data, ptr_line_data,
ptr_buffer = weechat_hdata_pointer (relay_hdata_line_data, ptr_line_data,
"buffer");
if (!ptr_buffer || relay_buffer_is_relay (ptr_buffer))
return WEECHAT_RC_OK;
@@ -1202,7 +1184,6 @@ relay_weechat_protocol_nicklist_map_cb (void *data,
struct t_relay_client *ptr_client;
struct t_gui_buffer *ptr_buffer;
struct t_relay_weechat_nicklist *ptr_nicklist;
struct t_hdata *ptr_hdata;
struct t_relay_weechat_msg *msg;
/* make C compiler happy */
@@ -1212,32 +1193,29 @@ relay_weechat_protocol_nicklist_map_cb (void *data,
ptr_buffer = (struct t_gui_buffer *)key;
ptr_nicklist = (struct t_relay_weechat_nicklist *)value;
ptr_hdata = weechat_hdata_get ("buffer");
if (ptr_hdata)
if (weechat_hdata_check_pointer (
relay_hdata_buffer,
weechat_hdata_get_list (relay_hdata_buffer, "gui_buffers"),
ptr_buffer))
{
if (weechat_hdata_check_pointer (ptr_hdata,
weechat_hdata_get_list (ptr_hdata, "gui_buffers"),
ptr_buffer))
/*
* if no diff at all, or if diffs are bigger than nicklist:
* send whole nicklist
*/
if (ptr_nicklist
&& ((ptr_nicklist->items_count == 0)
|| (ptr_nicklist->items_count >= weechat_buffer_get_integer (ptr_buffer, "nicklist_count") + 1)))
{
/*
* if no diff at all, or if diffs are bigger than nicklist:
* send whole nicklist
*/
if (ptr_nicklist
&& ((ptr_nicklist->items_count == 0)
|| (ptr_nicklist->items_count >= weechat_buffer_get_integer (ptr_buffer, "nicklist_count") + 1)))
{
ptr_nicklist = NULL;
}
ptr_nicklist = NULL;
}
/* send nicklist diffs or full nicklist */
msg = relay_weechat_msg_new ((ptr_nicklist) ? "_nicklist_diff" : "_nicklist");
if (msg)
{
relay_weechat_msg_add_nicklist (msg, ptr_buffer, ptr_nicklist);
relay_weechat_msg_send (ptr_client, msg);
relay_weechat_msg_free (msg);
}
/* send nicklist diffs or full nicklist */
msg = relay_weechat_msg_new ((ptr_nicklist) ? "_nicklist_diff" : "_nicklist");
if (msg)
{
relay_weechat_msg_add_nicklist (msg, ptr_buffer, ptr_nicklist);
relay_weechat_msg_send (ptr_client, msg);
relay_weechat_msg_free (msg);
}
}
}
+3
View File
@@ -42,6 +42,9 @@ struct t_config_section;
struct t_config_file;
struct t_gui_window;
struct t_gui_buffer;
struct t_gui_lines;
struct t_gui_line;
struct t_gui_line_data;
struct t_gui_bar;
struct t_gui_bar_item;
struct t_gui_bar_window;