mirror of
https://github.com/weechat/weechat.git
synced 2026-07-04 00:33:13 +02:00
irc: add support of capability "batch" (closes #1292)
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
add_library(irc MODULE
|
||||
irc.c irc.h
|
||||
irc-bar-item.c irc-bar-item.h
|
||||
irc-batch.c irc-batch.h
|
||||
irc-buffer.c irc-buffer.h
|
||||
irc-channel.c irc-channel.h
|
||||
irc-color.c irc-color.h
|
||||
|
||||
@@ -0,0 +1,379 @@
|
||||
/*
|
||||
* irc-batch.c - functions for managing batched events
|
||||
*
|
||||
* Copyright (C) 2023 Sébastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "irc.h"
|
||||
#include "irc-batch.h"
|
||||
#include "irc-message.h"
|
||||
#include "irc-protocol.h"
|
||||
#include "irc-server.h"
|
||||
|
||||
|
||||
/*
|
||||
* Searches a batch reference.
|
||||
*
|
||||
* Returns pointer to batch, NULL if not found.
|
||||
*/
|
||||
|
||||
struct t_irc_batch *
|
||||
irc_batch_search (struct t_irc_server *server, const char *reference)
|
||||
{
|
||||
struct t_irc_batch *ptr_batch;
|
||||
|
||||
if (!server || !reference)
|
||||
return NULL;
|
||||
|
||||
for (ptr_batch = server->batches; ptr_batch;
|
||||
ptr_batch = ptr_batch->next_batch)
|
||||
{
|
||||
if (strcmp (ptr_batch->reference, reference) == 0)
|
||||
return ptr_batch;
|
||||
}
|
||||
|
||||
/* batch not found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds a batch to list of batched events.
|
||||
*/
|
||||
|
||||
void
|
||||
irc_batch_add_to_list (struct t_irc_server *server, struct t_irc_batch *batch)
|
||||
{
|
||||
if (server->last_batch)
|
||||
server->last_batch->next_batch = batch;
|
||||
else
|
||||
server->batches = batch;
|
||||
batch->prev_batch = server->last_batch;
|
||||
batch->next_batch = NULL;
|
||||
server->last_batch = batch;
|
||||
}
|
||||
|
||||
/*
|
||||
* Starts a batch.
|
||||
*
|
||||
* Returns pointer to new batch, NULL if error.
|
||||
*/
|
||||
|
||||
struct t_irc_batch *
|
||||
irc_batch_start_batch (struct t_irc_server *server, const char *reference,
|
||||
const char *parent_ref, const char *type,
|
||||
const char *parameters)
|
||||
{
|
||||
struct t_irc_batch *ptr_batch;
|
||||
|
||||
if (!server || !reference || !type)
|
||||
return NULL;
|
||||
|
||||
/* check if reference already exists */
|
||||
ptr_batch = irc_batch_search (server, reference);
|
||||
if (ptr_batch)
|
||||
return NULL;
|
||||
|
||||
ptr_batch = malloc (sizeof (*ptr_batch));
|
||||
if (!ptr_batch)
|
||||
return NULL;
|
||||
|
||||
ptr_batch->reference = strdup (reference);
|
||||
ptr_batch->parent_ref = (parent_ref) ? strdup (parent_ref) : NULL;
|
||||
ptr_batch->type = strdup (type);
|
||||
ptr_batch->parameters = (parameters) ? strdup (parameters) : NULL;
|
||||
ptr_batch->start_time = time (NULL);
|
||||
ptr_batch->messages = NULL;
|
||||
ptr_batch->end_received = 0;
|
||||
ptr_batch->messages_processed = 0;
|
||||
|
||||
irc_batch_add_to_list (server, ptr_batch);
|
||||
|
||||
return ptr_batch;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds an IRC message to a batch reference.
|
||||
*
|
||||
* Returns:
|
||||
* 1: OK, message added
|
||||
* 0: error, message not added
|
||||
*/
|
||||
|
||||
int
|
||||
irc_batch_add_message (struct t_irc_server *server, const char *reference,
|
||||
const char *irc_message)
|
||||
{
|
||||
struct t_irc_batch *ptr_batch;
|
||||
|
||||
if (!server || !reference || !irc_message)
|
||||
return 0;
|
||||
|
||||
ptr_batch = irc_batch_search (server, reference);
|
||||
if (!ptr_batch)
|
||||
return 0;
|
||||
|
||||
if (!ptr_batch->messages)
|
||||
ptr_batch->messages = weechat_string_dyn_alloc (256);
|
||||
if (!ptr_batch->messages)
|
||||
return 0;
|
||||
|
||||
if ((*(ptr_batch->messages))[0])
|
||||
weechat_string_dyn_concat (ptr_batch->messages, "\n", -1);
|
||||
weechat_string_dyn_concat (ptr_batch->messages, irc_message, -1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Frees a batch.
|
||||
*/
|
||||
|
||||
void
|
||||
irc_batch_free (struct t_irc_server *server, struct t_irc_batch *batch)
|
||||
{
|
||||
if (batch->reference)
|
||||
free (batch->reference);
|
||||
if (batch->parent_ref)
|
||||
free (batch->parent_ref);
|
||||
if (batch->type)
|
||||
free (batch->type);
|
||||
if (batch->parameters)
|
||||
free (batch->parameters);
|
||||
if (batch->messages)
|
||||
weechat_string_dyn_free (batch->messages, 1);
|
||||
|
||||
/* remove batch from list */
|
||||
if (batch->prev_batch)
|
||||
(batch->prev_batch)->next_batch = batch->next_batch;
|
||||
if (batch->next_batch)
|
||||
(batch->next_batch)->prev_batch = batch->prev_batch;
|
||||
if (server->batches == batch)
|
||||
server->batches = batch->next_batch;
|
||||
if (server->last_batch == batch)
|
||||
server->last_batch = batch->prev_batch;
|
||||
|
||||
free (batch);
|
||||
}
|
||||
|
||||
/*
|
||||
* Frees all batches from server.
|
||||
*/
|
||||
|
||||
void
|
||||
irc_batch_free_all (struct t_irc_server *server)
|
||||
{
|
||||
while (server->batches)
|
||||
{
|
||||
irc_batch_free (server, server->batches);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Processes messages in a batch.
|
||||
*/
|
||||
|
||||
void
|
||||
irc_batch_process_messages (struct t_irc_server *server,
|
||||
struct t_irc_batch *batch)
|
||||
{
|
||||
char **list_messages, *command, *channel, modifier_data[1024], *new_messages;
|
||||
int i, count_messages;
|
||||
|
||||
if (!batch || !batch->messages)
|
||||
return;
|
||||
|
||||
snprintf (modifier_data, sizeof (modifier_data),
|
||||
"%s,%s,%s",
|
||||
server->name,
|
||||
batch->type,
|
||||
batch->parameters);
|
||||
new_messages = weechat_hook_modifier_exec ("irc_batch", modifier_data,
|
||||
*(batch->messages));
|
||||
|
||||
/* no changes in new messages */
|
||||
if (new_messages && (strcmp (*(batch->messages), new_messages) == 0))
|
||||
{
|
||||
free (new_messages);
|
||||
new_messages = NULL;
|
||||
}
|
||||
|
||||
/* messages not dropped? */
|
||||
if (!new_messages || new_messages[0])
|
||||
{
|
||||
list_messages = weechat_string_split (
|
||||
(new_messages) ? new_messages : *(batch->messages),
|
||||
"\n", NULL, 0, 0, &count_messages);
|
||||
if (list_messages)
|
||||
{
|
||||
for (i = 0; i < count_messages; i++)
|
||||
{
|
||||
irc_message_parse (server,
|
||||
list_messages[i],
|
||||
NULL, /* tags */
|
||||
NULL, /* message_without_tags */
|
||||
NULL, /* nick */
|
||||
NULL, /* user */
|
||||
NULL, /* host */
|
||||
&command,
|
||||
&channel,
|
||||
NULL, /* arguments */
|
||||
NULL, /* text */
|
||||
NULL, /* params */
|
||||
NULL, /* num_params */
|
||||
NULL, /* pos_command */
|
||||
NULL, /* pos_arguments */
|
||||
NULL, /* pos_channel */
|
||||
NULL); /* pos_text */
|
||||
/* call receive callback, ignoring batch tags */
|
||||
irc_protocol_recv_command (server, list_messages[i], command,
|
||||
channel, 1);
|
||||
if (command)
|
||||
free (command);
|
||||
if (channel)
|
||||
free (channel);
|
||||
}
|
||||
weechat_string_free_split (list_messages);
|
||||
}
|
||||
}
|
||||
|
||||
if (new_messages)
|
||||
free (new_messages);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ends a batch reference.
|
||||
*/
|
||||
|
||||
void
|
||||
irc_batch_end_batch (struct t_irc_server *server, const char *reference)
|
||||
{
|
||||
struct t_irc_batch *ptr_batch, *ptr_next_batch, *ptr_parent_batch;
|
||||
int num_processed;
|
||||
|
||||
if (!server || !reference)
|
||||
return;
|
||||
|
||||
ptr_batch = irc_batch_search (server, reference);
|
||||
if (!ptr_batch)
|
||||
return;
|
||||
|
||||
ptr_batch->end_received = 1;
|
||||
|
||||
/*
|
||||
* process messages in all batches, if these conditions are met:
|
||||
* - end_received = 1
|
||||
* - no parent or the parent has messages_processed = 1
|
||||
*/
|
||||
while (1)
|
||||
{
|
||||
num_processed = 0;
|
||||
for (ptr_batch = server->batches; ptr_batch;
|
||||
ptr_batch = ptr_batch->next_batch)
|
||||
{
|
||||
if (!ptr_batch->end_received || ptr_batch->messages_processed)
|
||||
continue;
|
||||
ptr_parent_batch = irc_batch_search (server, ptr_batch->parent_ref);
|
||||
if (!ptr_parent_batch || ptr_parent_batch->messages_processed)
|
||||
{
|
||||
irc_batch_process_messages (server, ptr_batch);
|
||||
ptr_batch->messages_processed = 1;
|
||||
num_processed++;
|
||||
}
|
||||
}
|
||||
if (num_processed == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* remove all batches that are processed */
|
||||
ptr_batch = server->batches;
|
||||
while (ptr_batch)
|
||||
{
|
||||
ptr_next_batch = ptr_batch->next_batch;
|
||||
if (ptr_batch->messages_processed)
|
||||
irc_batch_free (server, ptr_batch);
|
||||
ptr_batch = ptr_next_batch;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns hdata for batch.
|
||||
*/
|
||||
|
||||
struct t_hdata *
|
||||
irc_batch_hdata_batch_cb (const void *pointer, void *data,
|
||||
const char *hdata_name)
|
||||
{
|
||||
struct t_hdata *hdata;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
|
||||
hdata = weechat_hdata_new (hdata_name, "prev_batch", "next_batch",
|
||||
0, 0, NULL, NULL);
|
||||
if (hdata)
|
||||
{
|
||||
WEECHAT_HDATA_VAR(struct t_irc_batch, reference, STRING, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_batch, parent_ref, STRING, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_batch, type, STRING, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_batch, parameters, STRING, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_batch, start_time, TIME, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_batch, messages, POINTER, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_batch, end_received, INTEGER, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_batch, messages_processed, INTEGER, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_batch, prev_batch, POINTER, 0, NULL, hdata_name);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_batch, next_batch, POINTER, 0, NULL, hdata_name);
|
||||
}
|
||||
return hdata;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints batch infos in WeeChat log file (usually for crash dump).
|
||||
*/
|
||||
|
||||
void
|
||||
irc_batch_print_log (struct t_irc_server *server)
|
||||
{
|
||||
struct t_irc_batch *ptr_batch;
|
||||
|
||||
for (ptr_batch = server->batches; ptr_batch;
|
||||
ptr_batch = ptr_batch->next_batch)
|
||||
{
|
||||
weechat_log_printf ("");
|
||||
weechat_log_printf (" => batch (addr:0x%lx):", ptr_batch);
|
||||
weechat_log_printf (" reference . . . . . : '%s'", ptr_batch->reference);
|
||||
weechat_log_printf (" parent_ref. . . . . : '%s'", ptr_batch->parent_ref);
|
||||
weechat_log_printf (" type. . . . . . . . : '%s'", ptr_batch->type);
|
||||
weechat_log_printf (" parameters. . . . . : '%s'", ptr_batch->parameters);
|
||||
weechat_log_printf (" start_time. . . . . : %lld", (long long)ptr_batch->start_time);
|
||||
weechat_log_printf (" message . . . . . . : 0x%lx ('%s')",
|
||||
ptr_batch->messages,
|
||||
(ptr_batch->messages) ? *(ptr_batch->messages) : NULL);
|
||||
weechat_log_printf (" end_received. . . . : %d", ptr_batch->end_received);
|
||||
weechat_log_printf (" messages_processed. : %d", ptr_batch->messages_processed);
|
||||
weechat_log_printf (" prev_batch. . . . . : 0x%lx", ptr_batch->prev_batch);
|
||||
weechat_log_printf (" next_batch. . . . . : 0x%lx", ptr_batch->next_batch);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Sébastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef WEECHAT_PLUGIN_IRC_BATCH_H
|
||||
#define WEECHAT_PLUGIN_IRC_BATCH_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
struct t_irc_server;
|
||||
|
||||
struct t_irc_batch
|
||||
{
|
||||
char *reference; /* batch reference */
|
||||
char *parent_ref; /* ref of parent batch (optional) */
|
||||
char *type; /* type */
|
||||
char *parameters; /* parameters */
|
||||
time_t start_time; /* start time (to auto-purge if */
|
||||
/* batch end is not received) */
|
||||
char **messages; /* messages separated by '\n' */
|
||||
int end_received; /* batch end reference received */
|
||||
int messages_processed; /* 1 if msgs have been processed */
|
||||
struct t_irc_batch *prev_batch; /* link to previous batch */
|
||||
struct t_irc_batch *next_batch; /* link to next batch */
|
||||
};
|
||||
|
||||
extern struct t_irc_batch *irc_batch_search (struct t_irc_server *server,
|
||||
const char *reference);
|
||||
extern struct t_irc_batch *irc_batch_start_batch (struct t_irc_server *server,
|
||||
const char *reference,
|
||||
const char *parent_ref,
|
||||
const char *type,
|
||||
const char *parameters);
|
||||
extern int irc_batch_add_message (struct t_irc_server *server,
|
||||
const char *reference,
|
||||
const char *irc_message);
|
||||
extern void irc_batch_end_batch (struct t_irc_server *server,
|
||||
const char *reference);
|
||||
extern void irc_batch_free (struct t_irc_server *server,
|
||||
struct t_irc_batch *batch);
|
||||
extern void irc_batch_free_all (struct t_irc_server *server);
|
||||
extern struct t_hdata *irc_batch_hdata_batch_cb (const void *pointer,
|
||||
void *data,
|
||||
const char *hdata_name);
|
||||
extern void irc_batch_print_log (struct t_irc_server *server);
|
||||
|
||||
#endif /* WEECHAT_PLUGIN_IRC_BATCH_H */
|
||||
@@ -1491,6 +1491,7 @@ irc_channel_display_nick_back_in_pv (struct t_irc_server *server,
|
||||
ptr_channel->buffer,
|
||||
0,
|
||||
irc_protocol_tags (
|
||||
server,
|
||||
"nick_back",
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
@@ -1078,7 +1078,8 @@ irc_command_me_channel_display (struct t_irc_server *server,
|
||||
weechat_printf_date_tags (
|
||||
channel->buffer,
|
||||
0,
|
||||
irc_protocol_tags ("privmsg",
|
||||
irc_protocol_tags (server,
|
||||
"privmsg",
|
||||
NULL,
|
||||
"irc_action,self_msg,notify_none,no_highlight",
|
||||
server->nick, NULL),
|
||||
@@ -1904,7 +1905,8 @@ IRC_COMMAND_CALLBACK(ctcp)
|
||||
irc_msgbuffer_get_target_buffer (
|
||||
ptr_server, ctcp_target, NULL, "ctcp", NULL),
|
||||
0,
|
||||
irc_protocol_tags ("privmsg",
|
||||
irc_protocol_tags (ptr_server,
|
||||
"privmsg",
|
||||
NULL,
|
||||
"irc_ctcp,self_msg,notify_none,no_highlight",
|
||||
NULL, NULL),
|
||||
@@ -3802,6 +3804,7 @@ IRC_COMMAND_CALLBACK(msg)
|
||||
ptr_server->buffer,
|
||||
0,
|
||||
irc_protocol_tags (
|
||||
ptr_server,
|
||||
"privmsg",
|
||||
NULL,
|
||||
"self_msg,notify_none,no_highlight",
|
||||
@@ -6953,9 +6956,9 @@ irc_command_init ()
|
||||
"Without argument, \"ls\" and \"list\" are sent.\n"
|
||||
"\n"
|
||||
"Capabilities supported by WeeChat are: "
|
||||
"account-notify, away-notify, cap-notify, chghost, extended-join, "
|
||||
"invite-notify, message-tags, multi-prefix, server-time, setname, "
|
||||
"userhost-in-names.\n"
|
||||
"account-notify, away-notify, batch, cap-notify, chghost, "
|
||||
"extended-join, invite-notify, message-tags, multi-prefix, "
|
||||
"server-time, setname, userhost-in-names.\n"
|
||||
"\n"
|
||||
"The capabilities to automatically enable on servers can be set "
|
||||
"in option irc.server_default.capabilities (or by server in "
|
||||
|
||||
@@ -54,10 +54,10 @@ struct t_irc_channel;
|
||||
}
|
||||
|
||||
/* list of supported capabilities (for completion in command /cap) */
|
||||
#define IRC_COMMAND_CAP_SUPPORTED_COMPLETION \
|
||||
"account-notify|away-notify|cap-notify|chghost|extended-join|" \
|
||||
"invite-notify|message-tags|multi-prefix|server-time|setname|" \
|
||||
"userhost-in-names"
|
||||
#define IRC_COMMAND_CAP_SUPPORTED_COMPLETION \
|
||||
"account-notify|away-notify|batch|cap-notify|chghost|" \
|
||||
"extended-join|invite-notify|message-tags|multi-prefix|" \
|
||||
"server-time|setname|userhost-in-names"
|
||||
|
||||
/* list of supported CTCPs (for completion in command /ctcp) */
|
||||
#define IRC_COMMAND_CTCP_SUPPORTED_COMPLETION \
|
||||
|
||||
@@ -143,7 +143,7 @@ irc_ctcp_display_request (struct t_irc_server *server,
|
||||
server, nick, NULL, "ctcp",
|
||||
(channel) ? channel->buffer : NULL),
|
||||
date,
|
||||
irc_protocol_tags (command, tags, "irc_ctcp", NULL, address),
|
||||
irc_protocol_tags (server, command, tags, "irc_ctcp", NULL, address),
|
||||
_("%sCTCP requested by %s%s%s: %s%s%s%s%s%s"),
|
||||
weechat_prefix ("network"),
|
||||
irc_nick_color_for_msg (server, 0, NULL, nick),
|
||||
@@ -211,7 +211,8 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
|
||||
irc_msgbuffer_get_target_buffer (
|
||||
server, nick, NULL, "ctcp", NULL),
|
||||
date,
|
||||
irc_protocol_tags (command, tags, "irc_ctcp", NULL, NULL),
|
||||
irc_protocol_tags (server, command, tags, "irc_ctcp",
|
||||
NULL, NULL),
|
||||
/* TRANSLATORS: %.3fs is a float number + "s" ("seconds") */
|
||||
_("%sCTCP reply from %s%s%s: %s%s%s %.3fs"),
|
||||
weechat_prefix ("network"),
|
||||
@@ -230,7 +231,8 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
|
||||
irc_msgbuffer_get_target_buffer (
|
||||
server, nick, NULL, "ctcp", NULL),
|
||||
date,
|
||||
irc_protocol_tags (command, tags, "irc_ctcp", NULL, address),
|
||||
irc_protocol_tags (server, command, tags, "irc_ctcp", NULL,
|
||||
address),
|
||||
_("%sCTCP reply from %s%s%s: %s%s%s%s%s"),
|
||||
weechat_prefix ("network"),
|
||||
irc_nick_color_for_msg (server, 0, NULL, nick),
|
||||
@@ -249,7 +251,7 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
|
||||
irc_msgbuffer_get_target_buffer (
|
||||
server, nick, NULL, "ctcp", NULL),
|
||||
date,
|
||||
irc_protocol_tags (command, tags, NULL, NULL, address),
|
||||
irc_protocol_tags (server, command, tags, NULL, NULL, address),
|
||||
_("%sCTCP reply from %s%s%s: %s%s%s%s%s"),
|
||||
weechat_prefix ("network"),
|
||||
irc_nick_color_for_msg (server, 0, NULL, nick),
|
||||
@@ -344,6 +346,7 @@ irc_ctcp_reply_to_nick (struct t_irc_server *server,
|
||||
(channel) ? channel->buffer : NULL),
|
||||
0,
|
||||
irc_protocol_tags (
|
||||
server,
|
||||
command,
|
||||
tags,
|
||||
"irc_ctcp,irc_ctcp_reply,self_msg,notify_none,"
|
||||
@@ -1101,6 +1104,7 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date,
|
||||
channel->buffer,
|
||||
date,
|
||||
irc_protocol_tags (
|
||||
server,
|
||||
command,
|
||||
tags,
|
||||
(nick_is_me) ?
|
||||
@@ -1144,6 +1148,7 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date,
|
||||
ptr_channel->buffer,
|
||||
date,
|
||||
irc_protocol_tags (
|
||||
server,
|
||||
command,
|
||||
tags,
|
||||
(nick_is_me) ?
|
||||
@@ -1227,8 +1232,8 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date,
|
||||
server, nick, NULL, "ctcp",
|
||||
(channel) ? channel->buffer : NULL),
|
||||
date,
|
||||
irc_protocol_tags (command, tags, "irc_ctcp", NULL,
|
||||
address),
|
||||
irc_protocol_tags (server, command, tags, "irc_ctcp",
|
||||
NULL, address),
|
||||
_("%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s"),
|
||||
weechat_prefix ("network"),
|
||||
irc_nick_color_for_msg (server, 0, NULL, nick),
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "irc.h"
|
||||
#include "irc-batch.h"
|
||||
#include "irc-channel.h"
|
||||
#include "irc-color.h"
|
||||
#include "irc-config.h"
|
||||
@@ -1294,4 +1295,7 @@ irc_info_init ()
|
||||
weechat_hook_hdata (
|
||||
"irc_server", N_("irc server"),
|
||||
&irc_server_hdata_server_cb, NULL, NULL);
|
||||
weechat_hook_hdata (
|
||||
"irc_batch", N_("irc batch"),
|
||||
&irc_batch_hdata_batch_cb, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ irc_input_user_message_display (struct t_gui_buffer *buffer, int action,
|
||||
buffer,
|
||||
0,
|
||||
irc_protocol_tags (
|
||||
ptr_server,
|
||||
"privmsg",
|
||||
NULL,
|
||||
str_tags,
|
||||
@@ -121,6 +122,7 @@ irc_input_user_message_display (struct t_gui_buffer *buffer, int action,
|
||||
buffer,
|
||||
0,
|
||||
irc_protocol_tags (
|
||||
ptr_server,
|
||||
"privmsg",
|
||||
NULL,
|
||||
str_tags,
|
||||
|
||||
+226
-119
File diff suppressed because it is too large
Load Diff
@@ -99,7 +99,8 @@ struct t_irc_protocol_msg
|
||||
t_irc_recv_func *recv_function; /* function called when msg is received */
|
||||
};
|
||||
|
||||
extern const char *irc_protocol_tags (const char *command,
|
||||
extern const char *irc_protocol_tags (struct t_irc_server *server,
|
||||
const char *command,
|
||||
struct t_hashtable *irc_msg_tags,
|
||||
const char *extra_tags,
|
||||
const char *nick,
|
||||
@@ -108,6 +109,7 @@ extern time_t irc_protocol_parse_time (const char *time);
|
||||
extern void irc_protocol_recv_command (struct t_irc_server *server,
|
||||
const char *irc_message,
|
||||
const char *msg_command,
|
||||
const char *msg_channel);
|
||||
const char *msg_channel,
|
||||
int ignore_batch_tag);
|
||||
|
||||
#endif /* WEECHAT_PLUGIN_IRC_PROTOCOL_H */
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include "irc.h"
|
||||
#include "irc-server.h"
|
||||
#include "irc-bar-item.h"
|
||||
#include "irc-batch.h"
|
||||
#include "irc-buffer.h"
|
||||
#include "irc-channel.h"
|
||||
#include "irc-color.h"
|
||||
@@ -1740,6 +1741,8 @@ irc_server_alloc (const char *name)
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_TIME,
|
||||
NULL, NULL);
|
||||
new_server->batches = NULL;
|
||||
new_server->last_batch = NULL;
|
||||
new_server->buffer = NULL;
|
||||
new_server->buffer_as_string = NULL;
|
||||
new_server->channels = NULL;
|
||||
@@ -2218,6 +2221,7 @@ irc_server_free_data (struct t_irc_server *server)
|
||||
irc_redirect_free_all (server);
|
||||
irc_notify_free_all (server);
|
||||
irc_channel_free_all (server);
|
||||
irc_batch_free_all (server);
|
||||
|
||||
/* free hashtables */
|
||||
weechat_hashtable_free (server->join_manual);
|
||||
@@ -3552,7 +3556,8 @@ irc_server_msgq_flush ()
|
||||
irc_recv_msgq->server,
|
||||
ptr_msg2,
|
||||
command,
|
||||
channel);
|
||||
channel,
|
||||
0); /* ignore_batch_tag */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3855,6 +3860,7 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls)
|
||||
struct t_irc_server *ptr_server;
|
||||
struct t_irc_channel *ptr_channel;
|
||||
struct t_irc_redirect *ptr_redirect, *ptr_next_redirect;
|
||||
struct t_irc_batch *ptr_batch, *ptr_next_batch;
|
||||
time_t current_time;
|
||||
static struct timeval tv;
|
||||
int away_check, refresh_lag;
|
||||
@@ -4024,6 +4030,17 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls)
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
ptr_batch = ptr_server->batches;
|
||||
while (ptr_batch)
|
||||
{
|
||||
ptr_next_batch = ptr_batch->next_batch;
|
||||
if (current_time > ptr_batch->start_time + (60 * 60))
|
||||
{
|
||||
/* batch expires after 1 hour if end not received */
|
||||
irc_batch_free (ptr_server, ptr_batch);
|
||||
}
|
||||
ptr_batch = ptr_next_batch;
|
||||
}
|
||||
ptr_server->last_data_purge = current_time;
|
||||
}
|
||||
}
|
||||
@@ -4115,6 +4132,9 @@ irc_server_close_connection (struct t_irc_server *server)
|
||||
/* remove all keys for joins without switch */
|
||||
weechat_hashtable_remove_all (server->join_noswitch);
|
||||
|
||||
/* remove all batched events pending */
|
||||
irc_batch_free_all (server);
|
||||
|
||||
/* server is now disconnected */
|
||||
server->authentication_method = IRC_SERVER_AUTH_METHOD_NONE;
|
||||
server->sasl_mechanism_used = -1;
|
||||
@@ -6319,6 +6339,8 @@ irc_server_hdata_server_cb (const void *pointer, void *data,
|
||||
WEECHAT_HDATA_VAR(struct t_irc_server, join_manual, HASHTABLE, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_server, join_channel_key, HASHTABLE, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_server, join_noswitch, HASHTABLE, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_server, batches, POINTER, 0, NULL, "irc_batch");
|
||||
WEECHAT_HDATA_VAR(struct t_irc_server, last_batch, POINTER, 0, NULL, "irc_batch");
|
||||
WEECHAT_HDATA_VAR(struct t_irc_server, buffer, POINTER, 0, NULL, "buffer");
|
||||
WEECHAT_HDATA_VAR(struct t_irc_server, buffer_as_string, STRING, 0, NULL, NULL);
|
||||
WEECHAT_HDATA_VAR(struct t_irc_server, channels, POINTER, 0, NULL, "irc_channel");
|
||||
@@ -7088,6 +7110,8 @@ irc_server_print_log ()
|
||||
weechat_log_printf (" join_noswitch . . . . . . : 0x%lx (hashtable: '%s')",
|
||||
ptr_server->join_noswitch,
|
||||
weechat_hashtable_get_string (ptr_server->join_noswitch, "keys_values"));
|
||||
weechat_log_printf (" batches . . . . . . . . . : 0x%lx", ptr_server->batches);
|
||||
weechat_log_printf (" last_batch. . . . . . . . : 0x%lx", ptr_server->last_batch);
|
||||
weechat_log_printf (" buffer. . . . . . . . . . : 0x%lx", ptr_server->buffer);
|
||||
weechat_log_printf (" buffer_as_string. . . . . : 0x%lx", ptr_server->buffer_as_string);
|
||||
weechat_log_printf (" channels. . . . . . . . . : 0x%lx", ptr_server->channels);
|
||||
@@ -7099,6 +7123,8 @@ irc_server_print_log ()
|
||||
|
||||
irc_notify_print_log (ptr_server);
|
||||
|
||||
irc_batch_print_log (ptr_server);
|
||||
|
||||
for (ptr_channel = ptr_server->channels; ptr_channel;
|
||||
ptr_channel = ptr_channel->next_channel)
|
||||
{
|
||||
|
||||
@@ -278,6 +278,8 @@ struct t_irc_server
|
||||
struct t_hashtable *join_manual; /* manual joins pending */
|
||||
struct t_hashtable *join_channel_key; /* keys pending for joins */
|
||||
struct t_hashtable *join_noswitch; /* joins w/o switch to buffer */
|
||||
struct t_irc_batch *batches; /* batched events (cap "batch") */
|
||||
struct t_irc_batch *last_batch; /* last batch */
|
||||
struct t_gui_buffer *buffer; /* GUI buffer allocated for server */
|
||||
char *buffer_as_string; /* used to return buffer info */
|
||||
struct t_irc_channel *channels; /* opened channels on server */
|
||||
|
||||
Reference in New Issue
Block a user