diff options
author | James Booth <boothj5@gmail.com> | 2014-10-05 03:52:55 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-10-05 03:52:55 +0100 |
commit | ac7bc02c63a5aed8decfcbbdc5582e9e5b389030 (patch) | |
tree | 302fa5fcd1ea72e67071d2043051eef3fef12ea1 /src/xmpp | |
parent | 7584ddaa62033f876b78a4de8b32d8e1e90e0619 (diff) | |
download | profani-tty-ac7bc02c63a5aed8decfcbbdc5582e9e5b389030.tar.gz |
Added /room kick command
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/iq.c | 48 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 41 | ||||
-rw-r--r-- | src/xmpp/stanza.h | 2 | ||||
-rw-r--r-- | src/xmpp/xmpp.h | 1 |
4 files changed, 91 insertions, 1 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index ed21f5aa..4be3d97f 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -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; +} \ No newline at end of file diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index b1bb51d8..eb5f857c 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -620,6 +620,47 @@ stanza_create_room_affiliation_set_iq(xmpp_ctx_t *ctx, const char * const room, } 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) { xmpp_stanza_t *presence = xmpp_stanza_new(ctx); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index d9f82929..fefa47b6 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -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); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 37c916f4..fc75a7ec 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -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); |