mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-26 22:56:21 +00:00
Allow adding and removing room owners
This commit is contained in:
@@ -275,6 +275,26 @@ _iq_room_config_cancel(const char * const room_jid)
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -528,6 +528,88 @@ stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx, const char * const room_jid
|
||||
return iq;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user