Package: irssi-plugin-xmpp / 0.54-3

ailin-nemui-0003-Handle-muc-destroy-error.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
From 4e0984391c02d79ff7fd26701db34f06577e4b49 Mon Sep 17 00:00:00 2001
From: Paul Fariello <paul@fariello.eu>
Date: Sun, 24 Nov 2013 23:09:50 +0100
Subject: [PATCH 03/44] Handle muc destroy error

---
 src/core/xep/muc-events.c      | 51 ++++++++++++++++++++++++++++++++++++++++++
 src/fe-common/module-formats.c |  1 +
 src/fe-common/module-formats.h |  1 +
 src/fe-common/xep/fe-muc.c     | 10 +++++++++
 4 files changed, 63 insertions(+)

--- a/src/core/xep/muc-events.c
+++ b/src/core/xep/muc-events.c
@@ -278,6 +278,19 @@
 }
 
 static void
+error_destroy(MUC_REC *channel, const char *code, const char *reason)
+{
+	int error;
+
+	error = code != NULL ? atoi(code) : MUC_ERROR_UNKNOWN;
+	switch (error) {
+	case 403:
+		signal_emit("xmpp muc destroyerror", 2, channel, reason);
+		break;
+	}
+}
+
+static void
 available(MUC_REC *channel, const char *from, LmMessage *lmsg)
 {
 	LmMessageNode *node;
@@ -538,11 +551,48 @@
 	g_free(nick);
 }
 
+static void
+sig_recv_iq(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
+    const char *id, const char *from, const char *to)
+{
+	MUC_REC *channel;
+	LmMessageNode *node, *error, *text, *query;
+	const char *code;
+	char *reason = NULL;
+
+	if ((channel = get_muc(server, from)) == NULL)
+		goto out;
+
+	switch (type) {
+	case LM_MESSAGE_SUB_TYPE_ERROR:
+		error = lm_message_node_get_child(lmsg->node, "error");
+		if (error == NULL)
+			goto out;
+		code = lm_message_node_get_attribute(error, "code");
+
+		query = lm_find_node(lmsg->node, "query", XMLNS, XMLNS_MUC_OWNER);
+		if (query == NULL)
+			goto out;
+		for (node = query->children; node != NULL; node = node->next) {
+			if (strcmp(node->name, "destroy") == 0) {
+				text = lm_message_node_get_child(error, "text");
+				reason = xmpp_recode_in(text->value);
+				error_destroy(channel, code, reason);
+			}
+		}
+		break;
+	}
+
+out:
+	g_free(reason);
+}
+
 void
 muc_events_init(void)
 {
 	signal_add("xmpp recv message", sig_recv_message);
 	signal_add("xmpp recv presence", sig_recv_presence);
+	signal_add("xmpp recv iq", sig_recv_iq);
 }
 
 void
@@ -550,4 +600,5 @@
 {
 	signal_remove("xmpp recv message", sig_recv_message);
 	signal_remove("xmpp recv presence", sig_recv_presence);
+	signal_remove("xmpp recv iq", sig_recv_iq);
 }
--- a/src/fe-common/module-formats.c
+++ b/src/fe-common/module-formats.c
@@ -65,6 +65,7 @@
 	{ NULL, "Channel", 0, { 0 } },
 
 	{ "joinerror", "Cannot join to room {channel $0} {comment $1}", 2, { 0, 0 } },
+	{ "destroyerror", "Cannot destroy room {channel $0} {comment $1}", 2, { 0, 0 } },
 
 	/* ---- */
 	{ NULL, "Presence", 0, { 0 } },
--- a/src/fe-common/module-formats.h
+++ b/src/fe-common/module-formats.h
@@ -41,6 +41,7 @@
 	XMPPTXT_FILL_6,
 
 	XMPPTXT_CHANNEL_JOINERROR,
+	XMPPTXT_CHANNEL_DESTROYERROR,
 
 	XMPPTXT_FILL_7,
 
--- a/src/fe-common/xep/fe-muc.c
+++ b/src/fe-common/xep/fe-muc.c
@@ -82,6 +82,14 @@
 }
 
 static void
+sig_destroyerror(MUC_REC *channel, const char *reason)
+{
+	printformat_module(MODULE_NAME, channel->server, NULL,
+	    MSGLEVEL_CRAP, XMPPTXT_CHANNEL_DESTROYERROR,
+	    channel->name, reason);
+}
+
+static void
 sig_nick(MUC_REC *channel, NICK_REC *nick, const char *oldnick)
 {
 	g_return_if_fail(IS_MUC(channel));
@@ -227,6 +235,7 @@
 {
 	signal_add("xmpp invite", sig_invite);
 	signal_add("xmpp muc joinerror", sig_joinerror);
+	signal_add("xmpp muc destroyerror", sig_destroyerror);
 	signal_add("message xmpp muc nick", sig_nick);
 	signal_add("message xmpp muc own_nick", sig_own_nick);
 	signal_add("message xmpp muc nick in use", sig_nick_in_use);
@@ -239,6 +248,7 @@
 {
 	signal_remove("xmpp invite", sig_invite);
 	signal_remove("xmpp muc joinerror", sig_joinerror);
+	signal_remove("xmpp muc destroyerror", sig_destroyerror);
 	signal_remove("message xmpp muc nick", sig_nick);
 	signal_remove("message xmpp muc own_nick", sig_own_nick);
 	signal_remove("message xmpp muc nick in use", sig_nick_in_use);