about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-03 20:29:17 +0100
committerJames Booth <boothj5@gmail.com>2014-09-03 20:29:17 +0100
commitaa9f1dfa06038ba095c5410805a26d957fda1cf9 (patch)
tree3162126ba7615a4deb60d526f7dfee65d435ac0f /src
parent09c10f62f20bafc599c12038170383853e4dc52e (diff)
downloadprofani-tty-aa9f1dfa06038ba095c5410805a26d957fda1cf9.tar.gz
Send room destroy iq on /room config cancel
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c2
-rw-r--r--src/xmpp/iq.c11
-rw-r--r--src/xmpp/stanza.c27
-rw-r--r--src/xmpp/stanza.h3
-rw-r--r--src/xmpp/xmpp.h1
5 files changed, 44 insertions, 0 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 857427c6..d18f747c 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1803,6 +1803,8 @@ cmd_room(gchar **args, struct cmd_help_t help)
 
     } else if (g_strcmp0(args[1], "cancel") == 0) {
         // check that we're in room, we're owner and room requires configuration
+        char *room = ui_current_recipient();
+        iq_destroy_instant_room(room);
 
     } else {
         cons_show("Usage: %s", help.usage);
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index d03e635c..bcadbdce 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -168,6 +168,16 @@ _iq_create_instant_room(const char * const room_jid)
     xmpp_stanza_release(iq);
 }
 
+static void
+_iq_destroy_instant_room(const char * const room_jid)
+{
+    xmpp_conn_t * const conn = connection_get_conn();
+    xmpp_ctx_t * const ctx = connection_get_ctx();
+    xmpp_stanza_t *iq = stanza_create_instant_room_destroy_iq(ctx, room_jid);
+    xmpp_send(conn, iq);
+    xmpp_stanza_release(iq);
+}
+
 static int
 _error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
     void * const userdata)
@@ -678,4 +688,5 @@ iq_init_module(void)
     iq_send_software_version = _iq_send_software_version;
     iq_set_autoping = _iq_set_autoping;
     iq_create_instant_room = _iq_create_instant_room;
+    iq_destroy_instant_room = _iq_destroy_instant_room;
 }
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index ac8f0dc1..51e63ccc 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -453,6 +453,33 @@ stanza_create_instant_room_request_iq(xmpp_ctx_t *ctx, const char * const room_j
 }
 
 xmpp_stanza_t *
+stanza_create_instant_room_destroy_iq(xmpp_ctx_t *ctx, const char * const room_jid)
+{
+    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
+    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
+    xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room_jid);
+    char *id = create_unique_id("leave");
+    xmpp_stanza_set_id(iq, id);
+    free(id);
+
+    xmpp_stanza_t *query = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
+    xmpp_stanza_set_ns(query, STANZA_NS_MUC_OWNER);
+
+    xmpp_stanza_t *destroy = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(destroy, STANZA_NAME_DESTROY);
+
+    xmpp_stanza_add_child(query, destroy);
+    xmpp_stanza_release(destroy);
+
+    xmpp_stanza_add_child(iq, query);
+    xmpp_stanza_release(query);
+
+    return iq;
+}
+
+xmpp_stanza_t *
 stanza_create_presence(xmpp_ctx_t * const ctx)
 {
     xmpp_stanza_t *presence = xmpp_stanza_new(ctx);
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 7afea8e5..eb309e19 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -74,6 +74,7 @@
 #define STANZA_NAME_PASSWORD "password"
 #define STANZA_NAME_CONFERENCE "conference"
 #define STANZA_NAME_VALUE "value"
+#define STANZA_NAME_DESTROY "destroy"
 
 // error conditions
 #define STANZA_NAME_BAD_REQUEST "bad-request"
@@ -204,6 +205,8 @@ gboolean stanza_muc_requires_config(xmpp_stanza_t * const stanza);
 char * stanza_get_new_nick(xmpp_stanza_t * const stanza);
 xmpp_stanza_t* stanza_create_instant_room_request_iq(xmpp_ctx_t *ctx,
     const char * const room_jid);
+xmpp_stanza_t* stanza_create_instant_room_destroy_iq(xmpp_ctx_t *ctx,
+    const char * const room_jid);
 
 int stanza_get_idle_time(xmpp_stanza_t * const stanza);
 char * stanza_get_caps_str(xmpp_stanza_t * const stanza);
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index cd28ddd2..cc587872 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -140,6 +140,7 @@ void (*iq_disco_info_request)(gchar *jid);
 void (*iq_disco_items_request)(gchar *jid);
 void (*iq_set_autoping)(int seconds);
 void (*iq_create_instant_room)(const char * const room_jid);
+void (*iq_destroy_instant_room)(const char * const room_jid);
 
 // caps functions
 Capabilities* (*caps_get)(const char * const caps_str);