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 23:40:36 +0100
committerJames Booth <boothj5@gmail.com>2014-10-04 23:40:36 +0100
commit0b78a9a57e3d1a39cd2826c073eb69d6954ad32b (patch)
tree228244d26c59816f888993c17966f9cb4faac643 /src/xmpp
parent719dbfaacc79fe56da8dcf1d9c9711c0de26f2bf (diff)
downloadprofani-tty-0b78a9a57e3d1a39cd2826c073eb69d6954ad32b.tar.gz
Implemented setting affiliation and listing affiliations
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/iq.c13
-rw-r--r--src/xmpp/stanza.c30
-rw-r--r--src/xmpp/stanza.h8
-rw-r--r--src/xmpp/xmpp.h5
4 files changed, 22 insertions, 34 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 4e5a757b..d960761a 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -276,21 +276,22 @@ _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)
+_iq_room_affiliation_list(const char * const room, const char * const affiliation)
 {
     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_stanza_t *iq = stanza_create_room_affiliation_list_iq(ctx, room, affiliation);
     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)
+_iq_room_affiliation_set(const char * const room, const char * const jid, const char * const affiliation,
+    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_stanza_t *iq = stanza_create_room_affiliation_set_iq(ctx, room, jid, affiliation, reason);
     xmpp_send(conn, iq);
     xmpp_stanza_release(iq);
 }
@@ -997,6 +998,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;
+    iq_room_affiliation_set = _iq_room_affiliation_set;
+    iq_room_affiliation_list = _iq_room_affiliation_list;
 }
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 4e2c829d..e17ed86e 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -529,14 +529,13 @@ 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)
+stanza_create_room_affiliation_list_iq(xmpp_ctx_t *ctx, const char * const room, const char * const affiliation)
 {
     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_type(iq, STANZA_TYPE_GET);
     xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room);
-    char *id = create_unique_id("owner_add");
+    char *id = create_unique_id("affiliation_get");
     xmpp_stanza_set_id(iq, id);
     free(id);
 
@@ -546,20 +545,7 @@ stanza_create_room_owner_add_iq(xmpp_ctx_t *ctx, const char * const room, const
 
     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_set_attribute(item, "affiliation", affiliation);
 
     xmpp_stanza_add_child(query, item);
     xmpp_stanza_release(item);
@@ -570,14 +556,14 @@ stanza_create_room_owner_add_iq(xmpp_ctx_t *ctx, const char * const room, const
 }
 
 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)
+stanza_create_room_affiliation_set_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
+    const char * const affiliation, 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");
+    char *id = create_unique_id("affiliation_set");
     xmpp_stanza_set_id(iq, id);
     free(id);
 
@@ -587,7 +573,7 @@ stanza_create_room_owner_remove_iq(xmpp_ctx_t *ctx, const char * const room, con
 
     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, "affiliation", affiliation);
     xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid);
 
     if (reason) {
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index d2e8c2cf..cf2dc482 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -205,10 +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);
+xmpp_stanza_t* stanza_create_room_affiliation_list_iq(xmpp_ctx_t *ctx, const char * const room,
+    const char * const affiliation);
+xmpp_stanza_t* stanza_create_room_affiliation_set_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
+    const char * const affiliation, 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 176e7a7b..3e0c38db 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -192,8 +192,9 @@ 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);
+void (*iq_room_affiliation_list)(const char * const room, const char * const affiliation);
+void (*iq_room_affiliation_set)(const char * const room, const char * const jid, const char * const affiliation,
+    const char * const reason);
 
 // caps functions
 Capabilities* (*caps_lookup)(const char * const jid);