about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-10-04 21:38:31 +0100
committerJames Booth <boothj5@gmail.com>2014-10-04 21:38:31 +0100
commit58fb89ad333c4fb37ee921823d28bab141250de3 (patch)
treeaee505cd5b6dcb81f14168adb34d20ab6a7defce /src/xmpp
parent7090f04a92cddb12af5d9c676c222abe5fd48f9d (diff)
downloadprofani-tty-58fb89ad333c4fb37ee921823d28bab141250de3.tar.gz
Allow adding and removing room owners
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/iq.c22
-rw-r--r--src/xmpp/stanza.c82
-rw-r--r--src/xmpp/stanza.h5
-rw-r--r--src/xmpp/xmpp.h2
4 files changed, 111 insertions, 0 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 83da7c9b..4e5a757b 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -276,6 +276,26 @@ _iq_room_config_cancel(const char * const room_jid)
 }
 
 static void
+_iq_room_owner_add(const char * const room, const char * const jid, const char * const reason)
+{
+    xmpp_conn_t * const conn = connection_get_conn();
+    xmpp_ctx_t * const ctx = connection_get_ctx();
+    xmpp_stanza_t *iq = stanza_create_room_owner_add_iq(ctx, room, jid, reason);
+    xmpp_send(conn, iq);
+    xmpp_stanza_release(iq);
+}
+
+static void
+_iq_room_owner_remove(const char * const room, const char * const jid, const char * const reason)
+{
+    xmpp_conn_t * const conn = connection_get_conn();
+    xmpp_ctx_t * const ctx = connection_get_ctx();
+    xmpp_stanza_t *iq = stanza_create_room_owner_remove_iq(ctx, room, jid, reason);
+    xmpp_send(conn, iq);
+    xmpp_stanza_release(iq);
+}
+
+static void
 _iq_send_ping(const char * const target)
 {
     xmpp_conn_t * const conn = connection_get_conn();
@@ -977,4 +997,6 @@ iq_init_module(void)
     iq_submit_room_config = _iq_submit_room_config;
     iq_send_caps_request = _iq_send_caps_request;
     iq_room_info_request = _iq_room_info_request;
+    iq_room_owner_add = _iq_room_owner_add;
+    iq_room_owner_remove = _iq_room_owner_remove;
 }
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index ff31bc65..4e2c829d 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -529,6 +529,88 @@ stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx, const char * const room_jid
 }
 
 xmpp_stanza_t *
+stanza_create_room_owner_add_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
+    const char * const reason)
+{
+    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);
+    char *id = create_unique_id("owner_add");
+    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_ADMIN);
+
+    xmpp_stanza_t *item = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
+    xmpp_stanza_set_attribute(item, "affiliation", "owner");
+    xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid);
+
+    if (reason) {
+        xmpp_stanza_t *reason_st = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_name(reason_st, STANZA_NAME_REASON);
+        xmpp_stanza_t *reason_text = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_text(reason_text, reason);
+        xmpp_stanza_add_child(reason_st, reason_text);
+        xmpp_stanza_release(reason_text);
+
+        xmpp_stanza_add_child(item, reason_st);
+        xmpp_stanza_release(reason_st);
+    }
+
+    xmpp_stanza_add_child(query, item);
+    xmpp_stanza_release(item);
+    xmpp_stanza_add_child(iq, query);
+    xmpp_stanza_release(query);
+
+    return iq;
+}
+
+xmpp_stanza_t *
+stanza_create_room_owner_remove_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
+    const char * const reason)
+{
+    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);
+    char *id = create_unique_id("owner_remove");
+    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_ADMIN);
+
+    xmpp_stanza_t *item = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
+    xmpp_stanza_set_attribute(item, "affiliation", "admin");
+    xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid);
+
+    if (reason) {
+        xmpp_stanza_t *reason_st = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_name(reason_st, STANZA_NAME_REASON);
+        xmpp_stanza_t *reason_text = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_text(reason_text, reason);
+        xmpp_stanza_add_child(reason_st, reason_text);
+        xmpp_stanza_release(reason_text);
+
+        xmpp_stanza_add_child(item, reason_st);
+        xmpp_stanza_release(reason_st);
+    }
+
+    xmpp_stanza_add_child(query, item);
+    xmpp_stanza_release(item);
+    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 a98c8c22..d2e8c2cf 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -144,6 +144,7 @@
 #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_MUC_ADMIN "http://jabber.org/protocol/muc#admin"
 #define STANZA_NS_CAPS "http://jabber.org/protocol/caps"
 #define STANZA_NS_PING "urn:xmpp:ping"
 #define STANZA_NS_LASTACTIVITY "jabber:iq:last"
@@ -204,6 +205,10 @@ xmpp_stanza_t* stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx,
     const char * const room_jid);
 xmpp_stanza_t* stanza_create_room_config_submit_iq(xmpp_ctx_t *ctx,
     const char * const room, DataForm *form);
+xmpp_stanza_t* stanza_create_room_owner_add_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
+    const char * const reason);
+xmpp_stanza_t* stanza_create_room_owner_remove_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
+    const char * const reason);
 
 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 58539479..176e7a7b 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -192,6 +192,8 @@ void (*iq_send_ping)(const char * const target);
 void (*iq_send_caps_request)(const char * const to, const char * const id,
     const char * const node, const char * const ver);
 void (*iq_room_info_request)(gchar *room);
+void (*iq_room_owner_add)(const char * const room, const char * const jid, const char * const reason);
+void (*iq_room_owner_remove)(const char * const room, const char * const jid, const char * const reason);
 
 // caps functions
 Capabilities* (*caps_lookup)(const char * const jid);