Package: irssi-plugin-xmpp / 0.54-3

ailin-nemui-0009-Add-support-for-mode-change-in-MUC.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
From 918982bc5cf76b8ca9edea1cd9a818f3e76fb3f1 Mon Sep 17 00:00:00 2001
From: Paul Fariello <pfariello@arkoon.dev>
Date: Tue, 24 Jan 2017 18:22:45 +0100
Subject: [PATCH 09/44] Add support for mode change in MUC

---
 config.mk                   |  2 +-
 docs/MUC                    |  9 +++++++-
 src/core/xep/muc-commands.c | 25 ++++++++++++++++++++
 src/core/xep/muc.c          | 56 +++++++++++++++++++++++++++++++++++++++++++++
 src/core/xep/muc.h          |  1 +
 5 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/config.mk b/config.mk
index b8705d6..034e9db 100644
--- a/config.mk
+++ b/config.mk
@@ -22,7 +22,7 @@ INCS =	${LIB_INCS} \
 LIBS =	${LIB_LIBS}
 
 # flags
-CFLAGS += -fPIC -DUOFF_T_LONG
+CFLAGS += -fPIC -DUOFF_T_LONG -O0 -g
 LDFLAGS += -shared
 
 # debug
diff --git a/docs/MUC b/docs/MUC
index 9670d35..a260669 100644
--- a/docs/MUC
+++ b/docs/MUC
@@ -35,7 +35,7 @@ Administration commands:
 /ROLE [<channel>] <type>
     List all user having a specific role, if you have the right to do it.
 
-/ROLE [<channel>] <type> <nick> [<reason>]*/
+/ROLE [<channel>] <type> <nick> [<reason>]
     Give nick a specific role, if you have the right to do it.
 
 /KICK [<channel>] <nick> [<reason>]
@@ -51,3 +51,10 @@ Administration commands:
 /BAN [<channel>] <jid> [<reason>]
     Ban a specific jid, if you have the right to do it.
     Equivalent to /AFFILIATION outcast <jid>.
+
+/MODE [<channel>] <mode>
+    Set channel mode.
+    Available mode are Mmkpu.
+
+/MODE [<channel>] [<mode>]
+    Get channel mode.
diff --git a/src/core/xep/muc-commands.c b/src/core/xep/muc-commands.c
index fc6fd80..eff0a43 100644
--- a/src/core/xep/muc-commands.c
+++ b/src/core/xep/muc-commands.c
@@ -27,6 +27,7 @@
 #include "tools.h"
 #include "rosters-tools.h"
 #include "muc.h"
+#include "disco.h"
 
 /* SYNTAX: INVITE <jid>[/<resource>]|<name> [<channame>] */
 static void
@@ -250,6 +251,28 @@ cmd_kick(const char *data, XMPP_SERVER_REC *server, WI_ITEM_REC *item)
 	cmd_params_free(free_arg);
 }
 
+/* SYNTAX: MODE [<channel>] [<mode>] */
+static void
+cmd_mode(const char *data, XMPP_SERVER_REC *server, WI_ITEM_REC *item)
+{
+	MUC_REC *channel;
+	LmMessage *lmsg;
+	char *channame, *mode;
+	void *free_arg;
+
+	CMD_XMPP_SERVER(server);
+	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN |
+	    PARAM_FLAG_GETREST, item, &channame, &mode))
+		return;
+	if ((channel = muc_find(server, channame)) == NULL)
+		cmd_param_error(CMDERR_NOT_JOINED);
+	if (*mode == '\0')
+		disco_request(server, channel->name);
+	else
+		muc_set_mode(server, channel, mode);
+	cmd_params_free(free_arg);
+}
+
 /* SYNTAX: DESTROY [<channel>] [<alternate>] [<reason>]*/
 static void
 cmd_destroy(const char *data, XMPP_SERVER_REC *server, WI_ITEM_REC *item)
@@ -285,6 +308,7 @@ muc_commands_init(void)
 	command_bind_xmpp("ban", NULL, (SIGNAL_FUNC)cmd_ban);
 	command_bind_xmpp("role", NULL, (SIGNAL_FUNC)cmd_role);
 	command_bind_xmpp("kick", NULL, (SIGNAL_FUNC)cmd_kick);
+	command_bind_xmpp("mode", NULL, (SIGNAL_FUNC)cmd_mode);
 	command_bind_xmpp("destroy", NULL, (SIGNAL_FUNC)cmd_destroy);
 }
 
@@ -299,5 +323,6 @@ muc_commands_deinit(void)
 	command_unbind("ban", (SIGNAL_FUNC)cmd_ban);
 	command_unbind("role", (SIGNAL_FUNC)cmd_role);
 	command_unbind("kick", (SIGNAL_FUNC)cmd_kick);
+	command_unbind("mode", (SIGNAL_FUNC)cmd_mode);
 	command_unbind("destroy", (SIGNAL_FUNC)cmd_destroy);
 }
diff --git a/src/core/xep/muc.c b/src/core/xep/muc.c
index bcf88e2..546ca5c 100644
--- a/src/core/xep/muc.c
+++ b/src/core/xep/muc.c
@@ -37,6 +37,9 @@
 #include "muc-role.h"
 #include "muc-reconnect.h"
 
+#define XMLNS_DATA_X "jabber:x:data"
+#define XMLNS_MUC_CONFIG "http://jabber.org/protocol/muc#roomconfig"
+
 static char *
 get_join_data(MUC_REC *channel)
 {
@@ -314,6 +317,59 @@ muc_set_role(XMPP_SERVER_REC *server, MUC_REC *channel, const char *type,
 	lm_message_unref(lmsg);
 }
 
+void
+muc_set_mode(XMPP_SERVER_REC *server ,MUC_REC *channel, const char *mode)
+{
+	LmMessage *lmsg;
+	LmMessageNode *query, *x, *field, *value;
+	char *recoded, *new_value, *feature;
+
+	lmsg = lm_message_new_with_sub_type(channel->name, LM_MESSAGE_TYPE_IQ,
+	    LM_MESSAGE_SUB_TYPE_SET);
+	recoded = xmpp_recode_out(channel->server->jid);
+	lm_message_node_set_attribute(lmsg->node, "from", recoded);
+	g_free(recoded);
+	query = lm_message_node_add_child(lmsg->node, "query", NULL);
+	lm_message_node_set_attribute(query, XMLNS, XMLNS_MUC_OWNER);
+	x = lm_message_node_add_child(query, "x", NULL);
+	lm_message_node_set_attribute(x, XMLNS, XMLNS_DATA_X);
+	lm_message_node_set_attribute(x, "type", "submit");
+
+	field = lm_message_node_add_child(x, "field", NULL);
+	lm_message_node_set_attribute(field, "var", "FORM_TYPE");
+	value = lm_message_node_add_child(field, "value", XMLNS_MUC_CONFIG);
+
+	new_value = mode[0] == '+' ? "1" : "0";
+
+	for (int i = 1; i < strlen(mode); i++) {
+		field = lm_message_node_add_child(x, "field", NULL);
+		switch (mode[i]) {
+		case 'm':
+			feature = "muc#roomconfig_membersonly";
+			break;
+		case 'M':
+			feature = "muc#roomconfig_moderatedroom";
+			break;
+		case 'k':
+			feature = "muc#roomconfig_passwordprotectedroom";
+			break;
+		case 'p':
+			feature = "muc#roomconfig_persistentroom";
+			break;
+		case 'u':
+			feature = "muc#roomconfig_publicroom";
+			break;
+		default:
+			continue;
+		}
+		lm_message_node_set_attribute(field, "var", feature);
+		value = lm_message_node_add_child(field, "value", new_value);
+	}
+
+	signal_emit("xmpp send iq", 2, channel->server, lmsg);
+	lm_message_unref(lmsg);
+}
+
 void
 muc_destroy(XMPP_SERVER_REC *server ,MUC_REC *channel, const char *alternate,
 		const char *reason)
diff --git a/src/core/xep/muc.h b/src/core/xep/muc.h
index 38f30df..50440f8 100644
--- a/src/core/xep/muc.h
+++ b/src/core/xep/muc.h
@@ -63,6 +63,7 @@ void muc_set_affiliation(XMPP_SERVER_REC *, MUC_REC *, const char *,
 void muc_get_role(XMPP_SERVER_REC *, MUC_REC *, const char *);
 void muc_set_role(XMPP_SERVER_REC *, MUC_REC *, const char *,
 		const char *, const char *);
+void muc_set_mode(XMPP_SERVER_REC *, MUC_REC *, const char *);
 MUC_REC	*get_muc(XMPP_SERVER_REC *, const char *);
 
 void muc_init(void);
-- 
2.14.2