Add per-server nickname blacklists
This commit is contained in:
parent
78f2929dd9
commit
fa16526c44
3 changed files with 48 additions and 0 deletions
|
|
@ -80,6 +80,11 @@ server <host> [port] [ssl|tls]
|
||||||
An optional `name <display name>` line below `server` sets its label in the
|
An optional `name <display name>` line below `server` sets its label in the
|
||||||
channel tree. The label defaults to the hostname.
|
channel tree. The label defaults to the hostname.
|
||||||
|
|
||||||
|
Add `blacklist user1,user2,user3` below a `server` line to suppress incoming
|
||||||
|
channel messages, private messages, and notices from those nicknames on that
|
||||||
|
server. Matching is case-insensitive. You can add multiple blacklist lines
|
||||||
|
for the same server.
|
||||||
|
|
||||||
The port defaults to `6667`. The optional third token `ssl` or `tls` enables
|
The port defaults to `6667`. The optional third token `ssl` or `tls` enables
|
||||||
TLS; use port `6697` for Libera and OFTC. A `sasl <user> <pass>` line applies to
|
TLS; use port `6697` for Libera and OFTC. A `sasl <user> <pass>` line applies to
|
||||||
the most recent `server` line and enables SASL PLAIN for that server only. The
|
the most recent `server` line and enables SASL PLAIN for that server only. The
|
||||||
|
|
|
||||||
41
irc9.c
41
irc9.c
|
|
@ -104,6 +104,11 @@ typedef struct AutojoinChannel {
|
||||||
} AutojoinChannel;
|
} AutojoinChannel;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct BlacklistedNick {
|
||||||
|
char nick[NICKLEN];
|
||||||
|
struct BlacklistedNick *next;
|
||||||
|
} BlacklistedNick;
|
||||||
|
|
||||||
typedef struct Server {
|
typedef struct Server {
|
||||||
char host[HOSTLEN];
|
char host[HOSTLEN];
|
||||||
char *name;
|
char *name;
|
||||||
|
|
@ -125,6 +130,7 @@ typedef struct Server {
|
||||||
char sasl_user[NICKLEN];
|
char sasl_user[NICKLEN];
|
||||||
char sasl_pass[128];
|
char sasl_pass[128];
|
||||||
char *autocommand;
|
char *autocommand;
|
||||||
|
BlacklistedNick *blacklist;
|
||||||
int cap_state;
|
int cap_state;
|
||||||
char caps[512]; /* accumulated multi-line CAP LS reply */
|
char caps[512]; /* accumulated multi-line CAP LS reply */
|
||||||
char umode[32];
|
char umode[32];
|
||||||
|
|
@ -658,6 +664,27 @@ static int parse_port(const char *str)
|
||||||
return (int)v;
|
return (int)v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void load_blacklist(Server *s, char *list)
|
||||||
|
{
|
||||||
|
char *save = NULL;
|
||||||
|
for (char *nick = strtok_r(list, ",", &save); nick;
|
||||||
|
nick = strtok_r(NULL, ",", &save)) {
|
||||||
|
nick += strspn(nick, " \t");
|
||||||
|
size_t len = strlen(nick);
|
||||||
|
while (len && (nick[len - 1] == ' ' || nick[len - 1] == '\t'))
|
||||||
|
nick[--len] = 0;
|
||||||
|
if (!len) continue;
|
||||||
|
if (len >= NICKLEN || strpbrk(nick, " \t\r")) {
|
||||||
|
fprintf(stderr, "irc9: ignoring invalid blacklist nickname: %s\n", nick);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BlacklistedNick *entry = xmalloc(sizeof *entry);
|
||||||
|
strcpy(entry->nick, nick);
|
||||||
|
entry->next = s->blacklist;
|
||||||
|
s->blacklist = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void load_config(const char *path)
|
static void load_config(const char *path)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(path, "r");
|
FILE *f = fopen(path, "r");
|
||||||
|
|
@ -695,6 +722,13 @@ static void load_config(const char *path)
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (strcasecmp(key, "blacklist") == 0) {
|
||||||
|
if (last && save && *save)
|
||||||
|
load_blacklist(last, save);
|
||||||
|
else
|
||||||
|
fprintf(stderr, "irc9: blacklist requires a server and a list of nicknames\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (strcasecmp(key, "autocommand") == 0) {
|
if (strcasecmp(key, "autocommand") == 0) {
|
||||||
if (save) save += strspn(save, " \t");
|
if (save) save += strspn(save, " \t");
|
||||||
if (last && save && *save && strlen(save) <= MAXLINE - 2 &&
|
if (last && save && *save && strlen(save) <= MAXLINE - 2 &&
|
||||||
|
|
@ -1316,6 +1350,8 @@ static void handle_line(Server *s, char *line)
|
||||||
int notice = (strcasecmp(cmd, "NOTICE") == 0);
|
int notice = (strcasecmp(cmd, "NOTICE") == 0);
|
||||||
const char *text = narg > 1 ? arg[1] : "";
|
const char *text = narg > 1 ? arg[1] : "";
|
||||||
if (narg < 1) return;
|
if (narg < 1) return;
|
||||||
|
for (BlacklistedNick *entry = s->blacklist; entry; entry = entry->next)
|
||||||
|
if (strcasecmp(entry->nick, nick) == 0) return;
|
||||||
Window *w;
|
Window *w;
|
||||||
if (is_channel(arg[0]))
|
if (is_channel(arg[0]))
|
||||||
w = window_get(s, arg[0], W_CHANNEL);
|
w = window_get(s, arg[0], W_CHANNEL);
|
||||||
|
|
@ -3052,6 +3088,11 @@ int main(int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
free(s->name);
|
free(s->name);
|
||||||
free(s->autocommand);
|
free(s->autocommand);
|
||||||
|
while (s->blacklist) {
|
||||||
|
BlacklistedNick *entry = s->blacklist;
|
||||||
|
s->blacklist = entry->next;
|
||||||
|
free(entry);
|
||||||
|
}
|
||||||
free(s);
|
free(s);
|
||||||
s = sn;
|
s = sn;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ real Happy irc9 User
|
||||||
# libera
|
# libera
|
||||||
server irc.libera.chat 6697 ssl
|
server irc.libera.chat 6697 ssl
|
||||||
name Libera Chat
|
name Libera Chat
|
||||||
|
# Suppress incoming messages from these nicknames on this server.
|
||||||
|
# blacklist user1,user2,user3
|
||||||
# sasl irc9user my-sasl-password
|
# sasl irc9user my-sasl-password
|
||||||
# autocommand /msg NickServ IDENTIFY irc9user $PASSWORD
|
# autocommand /msg NickServ IDENTIFY irc9user $PASSWORD
|
||||||
# Build with make -B AUTOJOIN=1 and uncomment channel lines to join at startup.
|
# Build with make -B AUTOJOIN=1 and uncomment channel lines to join at startup.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue