diff options
author | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2018-04-24 13:58:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-24 13:58:04 +0200 |
commit | 13b2f349b68bbef2550238c62519ab2acf013855 (patch) | |
tree | 5f0c7d22ab01be67f947fe621cb211dd35da4d8d /src/fe-common/irc/fe-cap.c | |
parent | 68302f2d1fb1908ccac56b50ddf70abdb02f9aa5 (diff) | |
parent | d0151fd5a21cf026afa67239ad79f23bc26f0a10 (diff) | |
download | irssi-13b2f349b68bbef2550238c62519ab2acf013855.zip |
Merge pull request #870 from dequis/fe-cap
Add fe-cap to show messages for CAP-related events in the UI
Diffstat (limited to 'src/fe-common/irc/fe-cap.c')
-rw-r--r-- | src/fe-common/irc/fe-cap.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/fe-common/irc/fe-cap.c b/src/fe-common/irc/fe-cap.c new file mode 100644 index 00000000..4f9d8ea9 --- /dev/null +++ b/src/fe-common/irc/fe-cap.c @@ -0,0 +1,84 @@ +/* + fe-cap.c : irssi + + Copyright (C) 2018 dequis + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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 this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "module.h" +#include "module-formats.h" +#include "signals.h" +#include "levels.h" +#include "misc.h" + +#include "irc-servers.h" + +#include "printtext.h" + +static const struct { + const char *command; + const int template; +} fe_cap_messages[] = { + {"LS", IRCTXT_CAP_LS}, + {"ACK", IRCTXT_CAP_ACK}, + {"NAK", IRCTXT_CAP_NAK}, + {"LIST", IRCTXT_CAP_LIST}, + {"NEW", IRCTXT_CAP_NEW}, + {"DEL", IRCTXT_CAP_DEL}, +}; + +static void event_cap(IRC_SERVER_REC *server, char *args, char *nick, char *address) +{ + int i; + char *params, *evt, *list, *star; + + params = event_get_params(args, 4, NULL, &evt, &star, &list); + + if (params == NULL) { + return; + } + + /* With multiline CAP LS, if the '*' parameter isn't present, + * adjust the parameter pointer to compensate for this */ + if (strcmp(star, "*") != 0 && list[0] == '\0') { + list = star; + } + + for (i = 0; i < G_N_ELEMENTS(fe_cap_messages); i++) { + if (!g_ascii_strcasecmp(evt, fe_cap_messages[i].command)) { + printformat(server, NULL, MSGLEVEL_CRAP, fe_cap_messages[i].template, list); + } + } + + g_free(params); +} + +static void sig_server_cap_req(IRC_SERVER_REC *server, char *caps) +{ + printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_CAP_REQ, caps); +} + +void fe_cap_init(void) +{ + signal_add("event cap", (SIGNAL_FUNC) event_cap); + signal_add("server cap req", (SIGNAL_FUNC) sig_server_cap_req); +} + +void fe_cap_deinit(void) +{ + signal_remove("event cap", (SIGNAL_FUNC) event_cap); + signal_remove("server cap req", (SIGNAL_FUNC) sig_server_cap_req); +} |