Skip to content

Commit

Permalink
irc: add indexed ban list, add completion for /unban and /unquiet (cl…
Browse files Browse the repository at this point in the history
…oses #597, task #11374, task #10876)
  • Loading branch information
sim642 authored and flashcode committed Mar 24, 2018
1 parent b2f971d commit d77e1ea
Show file tree
Hide file tree
Showing 15 changed files with 1,160 additions and 20 deletions.
1 change: 1 addition & 0 deletions doc/en/weechat_dev.en.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ WeeChat "core" is located in following directories:
|       irc-input.c | Input of commands/text.
|       irc-message.c | Functions to manipulate IRC messages.
|       irc-mode.c | Functions about channel/nick modes.
| irc-modelist.c | IRC channel mode lists (+b, +e, +I)
|       irc-msgbuffer.c | Target buffer for IRC messages.
|       irc-nick.c | IRC nicks.
|       irc-notify.c | IRC notify lists.
Expand Down
1 change: 1 addition & 0 deletions src/plugins/irc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ irc-info.c irc-info.h
irc-input.c irc-input.h
irc-message.c irc-message.h
irc-mode.c irc-mode.h
irc-modelist.c irc-modelist.h
irc-msgbuffer.c irc-msgbuffer.h
irc-nick.c irc-nick.h
irc-notify.c irc-notify.h
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/irc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ irc_la_SOURCES = irc.c \
irc-message.h \
irc-mode.c \
irc-mode.h \
irc-modelist.c \
irc-modelist.h \
irc-msgbuffer.c \
irc-msgbuffer.h \
irc-nick.c \
Expand Down
18 changes: 18 additions & 0 deletions src/plugins/irc/irc-channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "irc-color.h"
#include "irc-command.h"
#include "irc-config.h"
#include "irc-modelist.h"
#include "irc-nick.h"
#include "irc-server.h"
#include "irc-input.h"
Expand Down Expand Up @@ -426,6 +427,7 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
{
struct t_irc_channel *new_channel;
struct t_gui_buffer *ptr_buffer;
const char *chanmodes;

/* create buffer for channel (or use existing one) */
ptr_buffer = irc_channel_create_buffer (server, channel_type,
Expand Down Expand Up @@ -479,6 +481,12 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
new_channel->nicks_speaking[1] = NULL;
new_channel->nicks_speaking_time = NULL;
new_channel->last_nick_speaking_time = NULL;
new_channel->modelists = NULL;
new_channel->last_modelist = NULL;
for (chanmodes = irc_server_get_chanmodes (server); chanmodes[0] && chanmodes[0] != ','; chanmodes++)
{
irc_modelist_new (new_channel, chanmodes[0]);
}
new_channel->join_smart_filtered = NULL;
new_channel->buffer = ptr_buffer;
new_channel->buffer_as_string = NULL;
Expand Down Expand Up @@ -1387,6 +1395,7 @@ irc_channel_free (struct t_irc_server *server, struct t_irc_channel *channel)

/* free linked lists */
irc_nick_free_all (server, channel);
irc_modelist_free_all (channel);

/* free channel data */
if (channel->name)
Expand Down Expand Up @@ -1472,6 +1481,8 @@ irc_channel_hdata_channel_cb (const void *pointer, void *data,
WEECHAT_HDATA_VAR(struct t_irc_channel, nicks_speaking, POINTER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, nicks_speaking_time, POINTER, 0, NULL, "irc_channel_speaking");
WEECHAT_HDATA_VAR(struct t_irc_channel, last_nick_speaking_time, POINTER, 0, NULL, "irc_channel_speaking");
WEECHAT_HDATA_VAR(struct t_irc_channel, modelists, POINTER, 0, NULL, "irc_modelist");
WEECHAT_HDATA_VAR(struct t_irc_channel, last_modelist, POINTER, 0, NULL, "irc_modelist");
WEECHAT_HDATA_VAR(struct t_irc_channel, join_smart_filtered, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, buffer, POINTER, 0, NULL, "buffer");
WEECHAT_HDATA_VAR(struct t_irc_channel, buffer_as_string, STRING, 0, NULL, NULL);
Expand Down Expand Up @@ -1629,6 +1640,7 @@ irc_channel_print_log (struct t_irc_channel *channel)
struct t_irc_channel_speaking *ptr_nick_speaking;
int i, index;
struct t_irc_nick *ptr_nick;
struct t_irc_modelist *ptr_modelist;

weechat_log_printf ("");
weechat_log_printf (" => channel %s (addr:0x%lx):", channel->name, channel);
Expand Down Expand Up @@ -1656,6 +1668,8 @@ irc_channel_print_log (struct t_irc_channel *channel)
weechat_log_printf (" nicks_speaking[1]. . . . : 0x%lx", channel->nicks_speaking[1]);
weechat_log_printf (" nicks_speaking_time. . . : 0x%lx", channel->nicks_speaking_time);
weechat_log_printf (" last_nick_speaking_time. : 0x%lx", channel->last_nick_speaking_time);
weechat_log_printf (" modelists. . . . . . . . : 0x%lx", channel->modelists);
weechat_log_printf (" last_modelist. . . . . . : 0x%lx", channel->last_modelist);
weechat_log_printf (" join_smart_filtered. . . : 0x%lx (hashtable: '%s')",
channel->join_smart_filtered,
weechat_hashtable_get_string (channel->join_smart_filtered,
Expand Down Expand Up @@ -1695,4 +1709,8 @@ irc_channel_print_log (struct t_irc_channel *channel)
{
irc_nick_print_log (ptr_nick);
}
for (ptr_modelist = channel->modelists; ptr_modelist; ptr_modelist = ptr_modelist->next_modelist)
{
irc_modelist_print_log (ptr_modelist);
}
}
3 changes: 3 additions & 0 deletions src/plugins/irc/irc-channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define IRC_CHANNEL_NICKS_SPEAKING_LIMIT 128

struct t_irc_server;
struct t_irc_modelist;

struct t_irc_channel_speaking
{
Expand Down Expand Up @@ -71,6 +72,8 @@ struct t_irc_channel
struct t_irc_channel_speaking *nicks_speaking_time; /* for smart filter */
/* of join/part/quit messages */
struct t_irc_channel_speaking *last_nick_speaking_time;
struct t_irc_modelist *modelists; /* modelists in the channel */
struct t_irc_modelist *last_modelist; /* last modelist in the channel */
struct t_hashtable *join_smart_filtered; /* smart filtered joins */
struct t_gui_buffer *buffer; /* buffer allocated for channel */
char *buffer_as_string; /* used to return buffer info */
Expand Down
32 changes: 26 additions & 6 deletions src/plugins/irc/irc-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "irc-input.h"
#include "irc-message.h"
#include "irc-mode.h"
#include "irc-modelist.h"
#include "irc-msgbuffer.h"
#include "irc-nick.h"
#include "irc-notify.h"
Expand Down Expand Up @@ -238,6 +239,10 @@ irc_command_mode_masks (struct t_irc_server *server,
char modes[128+1], masks[1024], *mask;
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
struct t_irc_modelist *ptr_modelist;
struct t_irc_modelist_item *ptr_item;
long number;
char *error;

if (irc_mode_get_chanmode_type (server, mode[0]) != 'A')
{
Expand Down Expand Up @@ -265,15 +270,30 @@ irc_command_mode_masks (struct t_irc_server *server,
masks[0] = '\0';

ptr_channel = irc_channel_search (server, channel_name);
ptr_modelist = irc_modelist_search (ptr_channel, mode[0]);

for (; argv[pos_masks]; pos_masks++)
{
mask = NULL;

/* use default_ban_mask for nick arguments */
if (ptr_channel)
{
if (!strchr (argv[pos_masks], '!')
/* use modelist item for number arguments */
if (set[0] == '-' && ptr_modelist)
{
error = NULL;
number = strtol (argv[pos_masks], &error, 10);
if (error && !error[0])
{
ptr_item = irc_modelist_item_number (ptr_modelist, number - 1);
if (ptr_item)
mask = strdup (ptr_item->mask);
}
}

/* use default_ban_mask for nick arguments */
if (!mask
&& !strchr (argv[pos_masks], '!')
&& !strchr (argv[pos_masks], '@'))
{
ptr_nick = irc_nick_search (server, ptr_channel,
Expand Down Expand Up @@ -6957,15 +6977,15 @@ irc_command_init ()
N_("unban nicks or hosts"),
N_("[<channel>] <nick> [<nick>...]"),
N_("channel: channel name\n"
" nick: nick or host"),
NULL, &irc_command_unban, NULL, NULL);
" nick: nick, host or ban number"),
"%(irc_modelist:b)", &irc_command_unban, NULL, NULL);
weechat_hook_command (
"unquiet",
N_("unquiet nicks or hosts"),
N_("[<channel>] <nick> [<nick>...]"),
N_("channel: channel name\n"
" nick: nick or host"),
"%(irc_channel_nicks_hosts)", &irc_command_unquiet, NULL, NULL);
" nick: nick, host or quiet number"),
"%(irc_modelist:q)", &irc_command_unquiet, NULL, NULL);
weechat_hook_command (
"userhost",
N_("return a list of information about nicks"),
Expand Down
46 changes: 46 additions & 0 deletions src/plugins/irc/irc-completion.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "irc-completion.h"
#include "irc-config.h"
#include "irc-ignore.h"
#include "irc-modelist.h"
#include "irc-nick.h"
#include "irc-notify.h"
#include "irc-server.h"
Expand Down Expand Up @@ -420,6 +421,47 @@ irc_completion_channel_nicks_hosts_cb (const void *pointer, void *data,
return WEECHAT_RC_OK;
}

/*
* Adds modelist masks current channel to completion list.
*/

int
irc_completion_modelist_cb (const void *pointer, void *data,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
char *pos;
struct t_irc_modelist *ptr_modelist;
struct t_irc_modelist_item *ptr_item;

IRC_BUFFER_GET_SERVER_CHANNEL(buffer);

/* make C compiler happy */
(void) pointer;
(void) data;

pos = strchr (completion_item, ':');
if (pos)
pos++;

if (pos && pos[0] && ptr_channel)
{
ptr_modelist = irc_modelist_search (ptr_channel, pos[0]);
if (ptr_modelist)
{
for (ptr_item = ptr_modelist->items; ptr_item; ptr_item = ptr_item->next_item)
{
weechat_hook_completion_list_add (completion,
ptr_item->mask,
0, WEECHAT_LIST_POS_END);
}
}
}

return WEECHAT_RC_OK;
}

/*
* Adds topic of current channel to completion list.
*/
Expand Down Expand Up @@ -758,6 +800,10 @@ irc_completion_init ()
weechat_hook_completion ("irc_channel_nicks_hosts",
N_("nicks and hostnames of current IRC channel"),
&irc_completion_channel_nicks_hosts_cb, NULL, NULL);
weechat_hook_completion ("irc_modelist",
N_("modelist masks of current IRC channel; "
"required argument: modelist mode"),
&irc_completion_modelist_cb, NULL, NULL);
weechat_hook_completion ("irc_channel_topic",
N_("topic of current IRC channel"),
&irc_completion_channel_topic_cb, NULL, NULL);
Expand Down
Loading

0 comments on commit d77e1ea

Please sign in to comment.