Skip to content

Commit

Permalink
irc: add structure with context sent as unique parameter to IRC proto…
Browse files Browse the repository at this point in the history
…col callbacks (issue #989)
  • Loading branch information
flashcode committed Oct 15, 2023
1 parent aed5c54 commit 3898449
Show file tree
Hide file tree
Showing 7 changed files with 1,833 additions and 1,885 deletions.
13 changes: 9 additions & 4 deletions src/plugins/irc/irc-channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1454,10 +1454,15 @@ irc_channel_display_nick_back_in_pv (struct t_irc_server *server,
const char *nickname)
{
struct t_irc_channel *ptr_channel;
struct t_irc_protocol_ctxt ctxt;

if (!server || (!nick && !nickname))
return;

memset (&ctxt, 0, sizeof (ctxt));
ctxt.server = server;
ctxt.command = strdup ("nick_back");

for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
Expand All @@ -1471,10 +1476,8 @@ irc_channel_display_nick_back_in_pv (struct t_irc_server *server,
ptr_channel->buffer,
0,
irc_protocol_tags (
server,
"nick_back",
NULL,
NULL,
&ctxt,
NULL, /* extra_tags */
(nick) ? nick->name : NULL,
(nick) ? nick->host : NULL),
_("%s%s%s %s(%s%s%s)%s is back on server"),
Expand All @@ -1490,6 +1493,8 @@ irc_channel_display_nick_back_in_pv (struct t_irc_server *server,
ptr_channel->has_quit_server = 0;
}
}

free (ctxt.command);
}

/*
Expand Down
288 changes: 134 additions & 154 deletions src/plugins/irc/irc-ctcp.c

Large diffs are not rendered by default.

18 changes: 6 additions & 12 deletions src/plugins/irc/irc-ctcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

struct t_irc_server;
struct t_irc_channel;
struct t_irc_protocol_ctxt;

struct t_irc_ctcp_reply
{
Expand All @@ -37,21 +38,14 @@ extern char *irc_ctcp_convert_legacy_format (const char *format);
extern const char *irc_ctcp_get_default_reply (const char *ctcp);
extern const char *irc_ctcp_get_reply (struct t_irc_server *server,
const char *ctcp);
extern void irc_ctcp_display_reply_from_nick (struct t_irc_server *server,
time_t date,
struct t_hashtable *tags,
const char *command,
const char *nick,
const char *address,
extern void irc_ctcp_display_reply_from_nick (struct t_irc_protocol_ctxt *ctxt,
const char *arguments);
extern char *irc_ctcp_eval_reply (struct t_irc_server *server,
const char *format);
extern void irc_ctcp_recv (struct t_irc_server *server, time_t date,
struct t_hashtable *tags, const char *command,
struct t_irc_channel *channel, const char *target,
const char *address, const char *nick,
const char *remote_nick, const char *arguments,
const char *message);
extern void irc_ctcp_recv (struct t_irc_protocol_ctxt *ctxt,
struct t_irc_channel *channel,
const char *remote_nick,
const char *arguments);
extern void irc_ctcp_send (struct t_irc_server *server,
const char *target, const char *type,
const char *args);
Expand Down
62 changes: 27 additions & 35 deletions src/plugins/irc/irc-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ irc_input_user_message_display (struct t_irc_server *server,
struct t_irc_channel *ptr_channel;
struct t_gui_buffer *ptr_buffer;
struct t_irc_nick *ptr_nick;
struct t_irc_protocol_ctxt ctxt;
const char *ptr_target;
char *text2, *text_decoded, str_tags[256], *str_color;
const char *ptr_text;
Expand All @@ -82,6 +83,12 @@ irc_input_user_message_display (struct t_irc_server *server,
if (!server || !target)
return;

memset (&ctxt, 0, sizeof (ctxt));
ctxt.server = server;
ctxt.date = date;
ctxt.address = (char *)address;
ctxt.command = (char *)command;

is_notice = (weechat_strcasecmp (command, "notice") == 0);
is_action = (ctcp_type && (weechat_strcasecmp (ctcp_type, "action") == 0));

Expand Down Expand Up @@ -165,13 +172,10 @@ irc_input_user_message_display (struct t_irc_server *server,
weechat_printf_date_tags (
ptr_buffer,
date,
irc_protocol_tags (
server,
command,
NULL,
str_tags,
(ptr_nick) ? ptr_nick->name : server->nick,
address),
irc_protocol_tags (&ctxt,
str_tags,
(ptr_nick) ? ptr_nick->name : server->nick,
address),
"%s%s -> %s%s%s: %s%s%s%s%s%s",
weechat_prefix ("network"),
/* TRANSLATORS: "Action" is an IRC CTCP "ACTION" sent with /me or /action */
Expand All @@ -192,13 +196,10 @@ irc_input_user_message_display (struct t_irc_server *server,
weechat_printf_date_tags (
ptr_buffer,
date,
irc_protocol_tags (
server,
command,
NULL,
str_tags,
(ptr_nick) ? ptr_nick->name : server->nick,
address),
irc_protocol_tags (&ctxt,
str_tags,
(ptr_nick) ? ptr_nick->name : server->nick,
address),
"%s%s%s%s%s%s%s",
weechat_prefix ("action"),
irc_nick_mode_for_display (server, ptr_nick, 0),
Expand All @@ -214,13 +215,10 @@ irc_input_user_message_display (struct t_irc_server *server,
weechat_printf_date_tags (
ptr_buffer,
date,
irc_protocol_tags (
server,
command,
NULL,
str_tags,
(ptr_nick) ? ptr_nick->name : server->nick,
address),
irc_protocol_tags (&ctxt,
str_tags,
(ptr_nick) ? ptr_nick->name : server->nick,
address),
_("%sCTCP query to %s%s%s: %s%s%s%s%s"),
weechat_prefix ("network"),
(is_channel) ?
Expand All @@ -238,13 +236,10 @@ irc_input_user_message_display (struct t_irc_server *server,
weechat_printf_date_tags (
ptr_buffer,
date,
irc_protocol_tags (
server,
command,
NULL,
str_tags,
(ptr_nick) ? ptr_nick->name : server->nick,
address),
irc_protocol_tags (&ctxt,
str_tags,
(ptr_nick) ? ptr_nick->name : server->nick,
address),
"%s%s%s%s%s(%s%s%s%s)%s -> %s%s%s: %s",
weechat_prefix ("network"),
(is_notice) ? IRC_COLOR_NOTICE : "",
Expand All @@ -270,13 +265,10 @@ irc_input_user_message_display (struct t_irc_server *server,
weechat_printf_date_tags (
ptr_buffer,
date,
irc_protocol_tags (
server,
command,
NULL,
str_tags,
(ptr_nick) ? ptr_nick->name : server->nick,
address),
irc_protocol_tags (&ctxt,
str_tags,
(ptr_nick) ? ptr_nick->name : server->nick,
address),
"%s%s",
irc_nick_as_prefix (
server,
Expand Down

0 comments on commit 3898449

Please sign in to comment.