summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2018-04-24 13:58:04 +0200
committerGitHub <noreply@github.com>2018-04-24 13:58:04 +0200
commit13b2f349b68bbef2550238c62519ab2acf013855 (patch)
tree5f0c7d22ab01be67f947fe621cb211dd35da4d8d
parent68302f2d1fb1908ccac56b50ddf70abdb02f9aa5 (diff)
parentd0151fd5a21cf026afa67239ad79f23bc26f0a10 (diff)
downloadirssi-13b2f349b68bbef2550238c62519ab2acf013855.zip
Merge pull request #870 from dequis/fe-cap
Add fe-cap to show messages for CAP-related events in the UI
-rw-r--r--docs/signals.txt1
-rw-r--r--src/fe-common/irc/Makefile.am1
-rw-r--r--src/fe-common/irc/fe-cap.c84
-rw-r--r--src/fe-common/irc/fe-common-irc.c5
-rw-r--r--src/fe-common/irc/module-formats.c7
-rw-r--r--src/fe-common/irc/module-formats.h7
-rw-r--r--src/irc/core/irc-cap.c14
7 files changed, 116 insertions, 3 deletions
diff --git a/docs/signals.txt b/docs/signals.txt
index 4dbfb2e2..270315b8 100644
--- a/docs/signals.txt
+++ b/docs/signals.txt
@@ -135,6 +135,7 @@ irc-cap.c
"server cap new "<cmd>, SERVER_REC
"server cap delete "<cmd>, SERVER_REC
"server cap end", SERVER_REC
+ "server cap req", SERVER_REC, char *caps
sasl.c
"server sasl failure", SERVER_REC, char *reason
diff --git a/src/fe-common/irc/Makefile.am b/src/fe-common/irc/Makefile.am
index bf88f5cd..a5e95885 100644
--- a/src/fe-common/irc/Makefile.am
+++ b/src/fe-common/irc/Makefile.am
@@ -27,6 +27,7 @@ real_sources = \
fe-common-irc.c \
fe-whois.c \
fe-sasl.c \
+ fe-cap.c \
irc-completion.c \
module-formats.c
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);
+}
diff --git a/src/fe-common/irc/fe-common-irc.c b/src/fe-common/irc/fe-common-irc.c
index 4a3ef1d3..b1bfb525 100644
--- a/src/fe-common/irc/fe-common-irc.c
+++ b/src/fe-common/irc/fe-common-irc.c
@@ -72,6 +72,9 @@ void fe_whois_deinit(void);
void fe_sasl_init(void);
void fe_sasl_deinit(void);
+void fe_cap_init(void);
+void fe_cap_deinit(void);
+
void irc_completion_init(void);
void irc_completion_deinit(void);
@@ -95,6 +98,7 @@ void fe_common_irc_init(void)
fe_netjoin_init();
fe_whois_init();
fe_sasl_init();
+ fe_cap_init();
irc_completion_init();
settings_check();
@@ -121,6 +125,7 @@ void fe_common_irc_deinit(void)
fe_netjoin_deinit();
fe_whois_deinit();
fe_sasl_deinit();
+ fe_cap_deinit();
irc_completion_deinit();
theme_unregister();
diff --git a/src/fe-common/irc/module-formats.c b/src/fe-common/irc/module-formats.c
index f7b074ec..722aed73 100644
--- a/src/fe-common/irc/module-formats.c
+++ b/src/fe-common/irc/module-formats.c
@@ -46,6 +46,13 @@ FORMAT_REC fecommon_irc_formats[] = {
{ "setupserver_footer", "", 0 },
{ "sasl_success", "SASL authentication succeeded", 0 },
{ "sasl_error", "Cannot authenticate via SASL ($0)", 1, { 0 } },
+ { "cap_req", "Capabilities requested: $0", 1, { 0 } },
+ { "cap_ls", "Capabilities supported: $0", 1, { 0 } },
+ { "cap_ack", "Capabilities acknowledged: $0", 1, { 0 } },
+ { "cap_nak", "Capabilities refused: $0", 1, { 0 } },
+ { "cap_list", "Capabilities currently enabled: $0", 1, { 0 } },
+ { "cap_new", "Capabilities now available: $0", 1, { 0 } },
+ { "cap_del", "Capabilities removed: $0", 1, { 0 } },
/* ---- */
{ NULL, "Channels", 0 },
diff --git a/src/fe-common/irc/module-formats.h b/src/fe-common/irc/module-formats.h
index c45f4562..7969b5ac 100644
--- a/src/fe-common/irc/module-formats.h
+++ b/src/fe-common/irc/module-formats.h
@@ -24,6 +24,13 @@ enum {
IRCTXT_SETUPSERVER_FOOTER,
IRCTXT_SASL_SUCCESS,
IRCTXT_SASL_ERROR,
+ IRCTXT_CAP_REQ,
+ IRCTXT_CAP_LS,
+ IRCTXT_CAP_ACK,
+ IRCTXT_CAP_NAK,
+ IRCTXT_CAP_LIST,
+ IRCTXT_CAP_NEW,
+ IRCTXT_CAP_DEL,
IRCTXT_FILL_2,
diff --git a/src/irc/core/irc-cap.c b/src/irc/core/irc-cap.c
index 1a60d99b..bcaeb10d 100644
--- a/src/irc/core/irc-cap.c
+++ b/src/irc/core/irc-cap.c
@@ -48,11 +48,17 @@ int cap_toggle (IRC_SERVER_REC *server, char *cap, int enable)
if (!g_hash_table_lookup_extended(server->cap_supported, cap, NULL, NULL))
return FALSE;
+ signal_emit("server cap req", 2, server, cap);
irc_send_cmdv(server, "CAP REQ %s", cap);
return TRUE;
}
else if (!enable && gslist_find_string(server->cap_active, cap)) {
- irc_send_cmdv(server, "CAP REQ -%s", cap);
+ char *negcap = g_strdup_printf("-%s", cap);
+
+ signal_emit("server cap req", 2, server, negcap);
+ irc_send_cmdv(server, "CAP REQ %s", negcap);
+
+ g_free(negcap);
return TRUE;
}
@@ -194,10 +200,12 @@ static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *add
server->cap_queue = NULL;
/* If the server doesn't support any cap we requested close the negotiation here */
- if (avail_caps > 0)
+ if (avail_caps > 0) {
+ signal_emit("server cap req", 2, server, cmd->str + sizeof("CAP REQ :") - 1);
irc_send_cmd_now(server, cmd->str);
- else
+ } else {
cap_finish_negotiation(server);
+ }
g_string_free(cmd, TRUE);
}