Added /room kick command

This commit is contained in:
James Booth
2014-10-05 03:52:55 +01:00
parent 7584ddaa62
commit ac7bc02c63
10 changed files with 157 additions and 2 deletions

View File

@@ -84,6 +84,8 @@ static int _room_affiliation_list_result_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _room_affiliation_set_result_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _room_kick_result_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _manual_pong_handler(xmpp_conn_t *const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _ping_timed_handler(xmpp_conn_t * const conn,
@@ -293,6 +295,20 @@ _iq_room_affiliation_list(const char * const room, char *affiliation)
xmpp_stanza_release(iq);
}
static void
_iq_room_kick_occupant(const char * const room, const char * const nick, 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_kick_iq(ctx, room, nick, reason);
char *id = xmpp_stanza_get_id(iq);
xmpp_id_handler_add(conn, _room_kick_result_handler, id, strdup(nick));
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
struct affiliation_set_t {
char *jid;
char *affiliation;
@@ -921,6 +937,35 @@ _room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
return 0;
}
static int
_room_kick_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *type = xmpp_stanza_get_type(stanza);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *nick = (char *)userdata;
if (id != NULL) {
log_debug("IQ kick result handler fired, id: %s.", id);
} else {
log_debug("IQ kick result handler fired.");
}
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
handle_room_kick_result_error(from, nick, error_message);
free(error_message);
free(nick);
return 0;
}
handle_room_kick(from, nick);
free(nick);
return 0;
}
static void
_identity_destroy(DiscoIdentity *identity)
{
@@ -1097,4 +1142,5 @@ iq_init_module(void)
iq_room_info_request = _iq_room_info_request;
iq_room_affiliation_set = _iq_room_affiliation_set;
iq_room_affiliation_list = _iq_room_affiliation_list;
}
iq_room_kick_occupant = _iq_room_kick_occupant;
}

View File

@@ -619,6 +619,47 @@ stanza_create_room_affiliation_set_iq(xmpp_ctx_t *ctx, const char * const room,
return iq;
}
xmpp_stanza_t *
stanza_create_room_kick_iq(xmpp_ctx_t * const ctx, const char * const room, const char * const nick,
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("room_kick");
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, STANZA_ATTR_NICK, nick);
xmpp_stanza_set_attribute(item, "role", "none");
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)
{

View File

@@ -210,6 +210,8 @@ xmpp_stanza_t* stanza_create_room_affiliation_list_iq(xmpp_ctx_t *ctx, const cha
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);
xmpp_stanza_t* stanza_create_room_subject_message(xmpp_ctx_t *ctx, const char * const room, const char * const subject);
xmpp_stanza_t* stanza_create_room_kick_iq(xmpp_ctx_t * const ctx, const char * const room, const char * const nick,
const char * const reason);
int stanza_get_idle_time(xmpp_stanza_t * const stanza);
char * stanza_get_caps_str(xmpp_stanza_t * const stanza);

View File

@@ -197,6 +197,7 @@ void (*iq_room_info_request)(gchar *room);
void (*iq_room_affiliation_list)(const char * const room, char *affiliation);
void (*iq_room_affiliation_set)(const char * const room, const char * const jid, char *affiliation,
const char * const reason);
void (*iq_room_kick_occupant)(const char * const room, const char * const nick, const char * const reason);
// caps functions
Capabilities* (*caps_lookup)(const char * const jid);