Package: irssi-plugin-xmpp / 0.54-3

ailin-nemui-0002-Add-MUC-destroy-command.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
From 50e20df5830e9715be8f308dfc0d4383e867c30f Mon Sep 17 00:00:00 2001
From: Paul Fariello <paul@fariello.eu>
Date: Thu, 21 Nov 2013 08:13:26 +0100
Subject: [PATCH 02/44] Add MUC destroy command

---
 src/core/xep/muc-commands.c | 25 +++++++++++++++++++++++++
 src/core/xep/muc.c          | 36 ++++++++++++++++++++++++++++++++++++
 src/core/xep/muc.h          |  1 +
 3 files changed, 62 insertions(+)

diff --git a/src/core/xep/muc-commands.c b/src/core/xep/muc-commands.c
index 0a06dfb..2976b71 100644
--- a/src/core/xep/muc-commands.c
+++ b/src/core/xep/muc-commands.c
@@ -149,6 +149,29 @@ cmd_topic(const char *data, XMPP_SERVER_REC *server, WI_ITEM_REC *item)
 	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)
+{
+	MUC_REC *channel;
+	LmMessage *lmsg;
+	char *channame, *reason, *alternate;
+	void *free_arg;
+
+	CMD_XMPP_SERVER(server);
+	if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTCHAN |
+	    PARAM_FLAG_GETREST, item, &channame, &alternate, &reason))
+		return;
+	if ((channel = muc_find(server, channame)) == NULL)
+		cmd_param_error(CMDERR_NOT_JOINED);
+	if (*alternate == '\0')
+		alternate = NULL;
+	if (*reason == '\0')
+		reason = NULL;
+	muc_destroy(server, channel, alternate, reason);
+	cmd_params_free(free_arg);
+}
+
 void
 muc_commands_init(void)
 {
@@ -157,6 +180,7 @@ muc_commands_init(void)
 	command_bind_xmpp("part", NULL, (SIGNAL_FUNC)cmd_part);
 	command_bind_xmpp("nick", NULL, (SIGNAL_FUNC)cmd_nick);
 	command_bind_xmpp("topic", NULL, (SIGNAL_FUNC)cmd_topic);
+	command_bind_xmpp("destroy", NULL, (SIGNAL_FUNC)cmd_destroy);
 }
 
 void
@@ -166,4 +190,5 @@ muc_commands_deinit(void)
 	command_unbind("part", (SIGNAL_FUNC)cmd_part);
 	command_unbind("nick", (SIGNAL_FUNC)cmd_nick);
 	command_unbind("topic", (SIGNAL_FUNC)cmd_topic);
+	command_unbind("destroy", (SIGNAL_FUNC)cmd_destroy);
 }
diff --git a/src/core/xep/muc.c b/src/core/xep/muc.c
index 113820e..67f399d 100644
--- a/src/core/xep/muc.c
+++ b/src/core/xep/muc.c
@@ -186,6 +186,42 @@ muc_part(MUC_REC *channel, const char *reason)
 	channel_destroy(CHANNEL(channel));
 }
 
+void
+muc_destroy(XMPP_SERVER_REC *server ,MUC_REC *channel, const char *alternate,
+		const char *reason)
+{
+	LmMessage *lmsg;
+	LmMessageNode *query, *destroy;
+	char *recoded, *str;
+
+	g_return_if_fail(IS_MUC(channel));
+	g_return_if_fail(IS_XMPP_SERVER(server));
+	if (!channel->server->connected)
+		return;
+
+	lmsg = lm_message_new_with_sub_type(channel->name, LM_MESSAGE_TYPE_IQ,
+	    LM_MESSAGE_SUB_TYPE_SET);
+	recoded = xmpp_recode_out(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);
+	destroy = lm_message_node_add_child(query, "destroy", NULL);
+	if (alternate != NULL) {
+		recoded = xmpp_recode_out(alternate);
+		lm_message_node_set_attribute(destroy, "jid", recoded);
+		g_free(recoded);
+	}
+	if (reason != NULL) {
+		recoded = xmpp_recode_out(reason);
+		lm_message_node_add_child(destroy, "reason", recoded);
+		g_free(recoded);
+	}
+	signal_emit("xmpp send iq", 2, channel->server, lmsg);
+	lm_message_unref(lmsg);
+
+}
+
 static void
 sig_features(XMPP_SERVER_REC *server, const char *name, GSList *list)
 {
diff --git a/src/core/xep/muc.h b/src/core/xep/muc.h
index f5bb0af..f9557e7 100644
--- a/src/core/xep/muc.h
+++ b/src/core/xep/muc.h
@@ -8,6 +8,7 @@
 
 #define XMLNS_MUC	"http://jabber.org/protocol/muc"
 #define XMLNS_MUC_USER	"http://jabber.org/protocol/muc#user"
+#define XMLNS_MUC_OWNER	"http://jabber.org/protocol/muc#owner"
 
 #define muc_extract_nick(jid)						\
 	xmpp_extract_resource(jid)
-- 
2.14.2