about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/commands.c4
-rw-r--r--src/xmpp/iq.c11
-rw-r--r--src/xmpp/stanza.c29
-rw-r--r--src/xmpp/stanza.h3
-rw-r--r--src/xmpp/xmpp.h1
5 files changed, 47 insertions, 1 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 541a3e3e..857427c6 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1797,7 +1797,9 @@ cmd_room(gchar **args, struct cmd_help_t help)
     }
 
     if (g_strcmp0(args[1], "accept") == 0) {
-        // check that we're in room, we're owner and room requires configuration
+        // TODO check that we're in room, we're owner and room requires configuration
+        char *room = ui_current_recipient();
+        iq_create_instant_room(room);
 
     } else if (g_strcmp0(args[1], "cancel") == 0) {
         // check that we're in room, we're owner and room requires configuration
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 96c94cd3..d03e635c 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -158,6 +158,16 @@ _iq_send_software_version(const char * const fulljid)
     xmpp_stanza_release(iq);
 }
 
+static void
+_iq_create_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_request_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)
@@ -667,4 +677,5 @@ iq_init_module(void)
     iq_disco_items_request = _iq_disco_items_request;
     iq_send_software_version = _iq_send_software_version;
     iq_set_autoping = _iq_set_autoping;
+    iq_create_instant_room = _iq_create_instant_room;
 }
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 6d3dcc54..ac8f0dc1 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -424,6 +424,35 @@ stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char * const room,
 }
 
 xmpp_stanza_t *
+stanza_create_instant_room_request_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 *x = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(x, STANZA_NAME_X);
+    xmpp_stanza_set_type(x, "submit");
+    xmpp_stanza_set_ns(x, STANZA_NS_DATA);
+
+    xmpp_stanza_add_child(query, x);
+    xmpp_stanza_release(x);
+
+    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 93b584f5..7afea8e5 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -141,6 +141,7 @@
 #define STANZA_NS_CHATSTATES "http://jabber.org/protocol/chatstates"
 #define STANZA_NS_MUC "http://jabber.org/protocol/muc"
 #define STANZA_NS_MUC_USER "http://jabber.org/protocol/muc#user"
+#define STANZA_NS_MUC_OWNER "http://jabber.org/protocol/muc#owner"
 #define STANZA_NS_CAPS "http://jabber.org/protocol/caps"
 #define STANZA_NS_PING "urn:xmpp:ping"
 #define STANZA_NS_LASTACTIVITY "jabber:iq:last"
@@ -201,6 +202,8 @@ gboolean stanza_is_room_nick_change(xmpp_stanza_t * const stanza);
 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);
 
 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 22f550e3..cd28ddd2 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -139,6 +139,7 @@ void (*iq_room_list_request)(gchar *conferencejid);
 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);
 
 // caps functions
 Capabilities* (*caps_get)(const char * const caps_str);