mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Implemented getting affiliation list, and setting affiliation
This commit is contained in:
parent
fd5326b40b
commit
2026ab4b6e
@ -307,7 +307,7 @@ static struct cmd_t command_defs[] =
|
|||||||
NULL } } },
|
NULL } } },
|
||||||
|
|
||||||
{ "/room",
|
{ "/room",
|
||||||
cmd_room, parse_args, 1, 4, NULL,
|
cmd_room, parse_args_with_freetext, 1, 5, NULL,
|
||||||
{ "/room accept|destroy|config|info", "Room configuration.",
|
{ "/room accept|destroy|config|info", "Room configuration.",
|
||||||
{ "/room accept|destroy|config|info",
|
{ "/room accept|destroy|config|info",
|
||||||
"--------------------------------",
|
"--------------------------------",
|
||||||
@ -1257,7 +1257,6 @@ cmd_init(void)
|
|||||||
autocomplete_add(room_affiliation_ac, "admin");
|
autocomplete_add(room_affiliation_ac, "admin");
|
||||||
autocomplete_add(room_affiliation_ac, "member");
|
autocomplete_add(room_affiliation_ac, "member");
|
||||||
autocomplete_add(room_affiliation_ac, "outcast");
|
autocomplete_add(room_affiliation_ac, "outcast");
|
||||||
autocomplete_add(room_affiliation_ac, "none");
|
|
||||||
|
|
||||||
room_role_ac = autocomplete_new();
|
room_role_ac = autocomplete_new();
|
||||||
autocomplete_add(room_role_ac, "moderator");
|
autocomplete_add(room_role_ac, "moderator");
|
||||||
|
@ -2159,8 +2159,7 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
if ((g_strcmp0(affiliation, "owner") != 0) &&
|
if ((g_strcmp0(affiliation, "owner") != 0) &&
|
||||||
(g_strcmp0(affiliation, "admin") != 0) &&
|
(g_strcmp0(affiliation, "admin") != 0) &&
|
||||||
(g_strcmp0(affiliation, "member") != 0) &&
|
(g_strcmp0(affiliation, "member") != 0) &&
|
||||||
(g_strcmp0(affiliation, "outcast") != 0) &&
|
(g_strcmp0(affiliation, "outcast") != 0)) {
|
||||||
(g_strcmp0(affiliation, "none") != 0)) {
|
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -182,6 +182,34 @@ handle_room_list(GSList *rooms, const char *conference_node)
|
|||||||
cons_show_room_list(rooms, conference_node);
|
cons_show_room_list(rooms, conference_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handle_room_affiliation_list_result_error(const char * const room, const char * const affiliation,
|
||||||
|
const char * const error)
|
||||||
|
{
|
||||||
|
log_debug("Error retrieving %s list for room %s: %s", affiliation, room, error);
|
||||||
|
ui_handle_room_affiliation_list_error(room, affiliation, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handle_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids)
|
||||||
|
{
|
||||||
|
ui_handle_room_affiliation_list(room, affiliation, jids);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handle_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation,
|
||||||
|
const char * const error)
|
||||||
|
{
|
||||||
|
log_debug("Error setting affiliation %s list for room %s, user %s: %s", affiliation, room, jid, error);
|
||||||
|
ui_handle_room_affiliation_set_error(room, jid, affiliation, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handle_room_affiliation_set(const char * const room, const char * const jid, const char * const affiliation)
|
||||||
|
{
|
||||||
|
ui_handle_room_affiliation_set(room, jid, affiliation);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_disco_items(GSList *items, const char *jid)
|
handle_disco_items(GSList *items, const char *jid)
|
||||||
{
|
{
|
||||||
|
@ -59,6 +59,12 @@ void handle_room_message(const char * const room_jid, const char * const nick,
|
|||||||
void handle_room_join_error(const char * const room, const char * const err);
|
void handle_room_join_error(const char * const room, const char * const err);
|
||||||
void handle_room_info_error(const char * const room, const char * const error);
|
void handle_room_info_error(const char * const room, const char * const error);
|
||||||
void handle_room_disco_info(const char * const room, GSList *identities, GSList *features);
|
void handle_room_disco_info(const char * const room, GSList *identities, GSList *features);
|
||||||
|
void handle_room_affiliation_list_result_error(const char * const room, const char * const affiliation,
|
||||||
|
const char * const error);
|
||||||
|
void handle_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids);
|
||||||
|
void handle_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation,
|
||||||
|
const char * const error);
|
||||||
|
void handle_room_affiliation_set(const char * const room, const char * const jid, const char * const affiliation);
|
||||||
void handle_duck_result(const char * const result);
|
void handle_duck_result(const char * const result);
|
||||||
void handle_incoming_message(char *from, char *message, gboolean priv);
|
void handle_incoming_message(char *from, char *message, gboolean priv);
|
||||||
void handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
void handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
||||||
|
@ -1749,6 +1749,55 @@ _ui_room_broadcast(const char * const room_jid, const char * const message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ui_handle_room_affiliation_list_error(const char * const room, const char * const affiliation,
|
||||||
|
const char * const error)
|
||||||
|
{
|
||||||
|
ProfWin *window = wins_get_by_recipient(room);
|
||||||
|
if (window) {
|
||||||
|
win_save_vprint(window, '!', NULL, 0, COLOUR_ERROR, "", "Error retrieving %s list: %s", affiliation, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ui_handle_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids)
|
||||||
|
{
|
||||||
|
ProfWin *window = wins_get_by_recipient(room);
|
||||||
|
if (window) {
|
||||||
|
if (jids) {
|
||||||
|
win_save_vprint(window, '!', NULL, 0, 0, "", "Affiliation: %s", affiliation);
|
||||||
|
GSList *curr_jid = jids;
|
||||||
|
while (curr_jid) {
|
||||||
|
char *jid = curr_jid->data;
|
||||||
|
win_save_vprint(window, '!', NULL, 0, 0, "", " %s", jid);
|
||||||
|
curr_jid = g_slist_next(curr_jid);
|
||||||
|
}
|
||||||
|
win_save_print(window, '!', NULL, 0, 0, "", "");
|
||||||
|
} else {
|
||||||
|
win_save_vprint(window, '!', NULL, 0, 0, "", "No users found with affiliation: %s", affiliation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ui_handle_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation,
|
||||||
|
const char * const error)
|
||||||
|
{
|
||||||
|
ProfWin *window = wins_get_by_recipient(room);
|
||||||
|
if (window) {
|
||||||
|
win_save_vprint(window, '!', NULL, 0, COLOUR_ERROR, "", "Error setting %s affiliation for %s: %s", affiliation, jid, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ui_handle_room_affiliation_set(const char * const room, const char * const jid, const char * const affiliation)
|
||||||
|
{
|
||||||
|
ProfWin *window = wins_get_by_recipient(room);
|
||||||
|
if (window) {
|
||||||
|
win_save_vprint(window, '!', NULL, 0, 0, "", "Affiliation for %s set: %s", jid, affiliation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ui_status(void)
|
_ui_status(void)
|
||||||
{
|
{
|
||||||
@ -2698,4 +2747,9 @@ ui_init_module(void)
|
|||||||
ui_show_room_affiliation_list = _ui_show_room_affiliation_list;
|
ui_show_room_affiliation_list = _ui_show_room_affiliation_list;
|
||||||
ui_handle_room_info_error = _ui_handle_room_info_error;
|
ui_handle_room_info_error = _ui_handle_room_info_error;
|
||||||
ui_show_room_disco_info = _ui_show_room_disco_info;
|
ui_show_room_disco_info = _ui_show_room_disco_info;
|
||||||
|
ui_handle_room_affiliation_list_error = _ui_handle_room_affiliation_list_error;
|
||||||
|
ui_handle_room_affiliation_list =_ui_handle_room_affiliation_list;
|
||||||
|
ui_handle_room_affiliation_set_error =_ui_handle_room_affiliation_set_error;
|
||||||
|
ui_handle_room_affiliation_set = _ui_handle_room_affiliation_set;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -170,6 +170,12 @@ void (*ui_handle_room_configuration)(const char * const room, DataForm *form);
|
|||||||
void (*ui_handle_room_configuration_form_error)(const char * const room, const char * const message);
|
void (*ui_handle_room_configuration_form_error)(const char * const room, const char * const message);
|
||||||
void (*ui_handle_room_config_submit_result)(const char * const room);
|
void (*ui_handle_room_config_submit_result)(const char * const room);
|
||||||
void (*ui_handle_room_config_submit_result_error)(const char * const room, const char * const message);
|
void (*ui_handle_room_config_submit_result_error)(const char * const room, const char * const message);
|
||||||
|
void (*ui_handle_room_affiliation_list_error)(const char * const room, const char * const affiliation,
|
||||||
|
const char * const error);
|
||||||
|
void (*ui_handle_room_affiliation_list)(const char * const room, const char * const affiliation, GSList *jids);
|
||||||
|
void (*ui_handle_room_affiliation_set_error)(const char * const room, const char * const jid,
|
||||||
|
const char * const affiliation, const char * const error);
|
||||||
|
void (*ui_handle_room_affiliation_set)(const char * const room, const char * const jid, const char * const affiliation);
|
||||||
void (*ui_show_form)(ProfWin *window, const char * const room, DataForm *form);
|
void (*ui_show_form)(ProfWin *window, const char * const room, DataForm *form);
|
||||||
void (*ui_show_form_field)(ProfWin *window, DataForm *form, char *tag);
|
void (*ui_show_form_field)(ProfWin *window, DataForm *form, char *tag);
|
||||||
void (*ui_show_form_help)(ProfWin *window, DataForm *form);
|
void (*ui_show_form_help)(ProfWin *window, DataForm *form);
|
||||||
|
101
src/xmpp/iq.c
101
src/xmpp/iq.c
@ -80,6 +80,10 @@ static int _room_config_handler(xmpp_conn_t * const conn,
|
|||||||
xmpp_stanza_t * const stanza, void * const userdata);
|
xmpp_stanza_t * const stanza, void * const userdata);
|
||||||
static int _room_config_submit_handler(xmpp_conn_t * const conn,
|
static int _room_config_submit_handler(xmpp_conn_t * const conn,
|
||||||
xmpp_stanza_t * const stanza, void * const userdata);
|
xmpp_stanza_t * const stanza, void * const userdata);
|
||||||
|
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 _manual_pong_handler(xmpp_conn_t *const conn,
|
static int _manual_pong_handler(xmpp_conn_t *const conn,
|
||||||
xmpp_stanza_t * const stanza, void * const userdata);
|
xmpp_stanza_t * const stanza, void * const userdata);
|
||||||
static int _ping_timed_handler(xmpp_conn_t * const conn,
|
static int _ping_timed_handler(xmpp_conn_t * const conn,
|
||||||
@ -276,22 +280,40 @@ _iq_room_config_cancel(const char * const room_jid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_iq_room_affiliation_list(const char * const room, const char * const affiliation)
|
_iq_room_affiliation_list(const char * const room, char *affiliation)
|
||||||
{
|
{
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *iq = stanza_create_room_affiliation_list_iq(ctx, room, affiliation);
|
xmpp_stanza_t *iq = stanza_create_room_affiliation_list_iq(ctx, room, affiliation);
|
||||||
|
|
||||||
|
char *id = xmpp_stanza_get_id(iq);
|
||||||
|
xmpp_id_handler_add(conn, _room_affiliation_list_result_handler, id, strdup(affiliation));
|
||||||
|
|
||||||
xmpp_send(conn, iq);
|
xmpp_send(conn, iq);
|
||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct affiliation_set_t {
|
||||||
|
char *jid;
|
||||||
|
char *affiliation;
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_iq_room_affiliation_set(const char * const room, const char * const jid, const char * const affiliation,
|
_iq_room_affiliation_set(const char * const room, const char * const jid, char *affiliation,
|
||||||
const char * const reason)
|
const char * const reason)
|
||||||
{
|
{
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *iq = stanza_create_room_affiliation_set_iq(ctx, room, jid, affiliation, reason);
|
xmpp_stanza_t *iq = stanza_create_room_affiliation_set_iq(ctx, room, jid, affiliation, reason);
|
||||||
|
|
||||||
|
char *id = xmpp_stanza_get_id(iq);
|
||||||
|
|
||||||
|
struct affiliation_set_t *affiliation_set = malloc(sizeof(struct affiliation_set_t));
|
||||||
|
affiliation_set->jid = strdup(jid);
|
||||||
|
affiliation_set->affiliation = strdup(affiliation);
|
||||||
|
|
||||||
|
xmpp_id_handler_add(conn, _room_affiliation_set_result_handler, id, affiliation_set);
|
||||||
|
|
||||||
xmpp_send(conn, iq);
|
xmpp_send(conn, iq);
|
||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
}
|
}
|
||||||
@ -797,6 +819,81 @@ _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _room_affiliation_set_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);
|
||||||
|
struct affiliation_set_t *affiliation_set = (struct affiliation_set_t *)userdata;
|
||||||
|
|
||||||
|
if (id != NULL) {
|
||||||
|
log_debug("IQ affiliation set handler fired, id: %s.", id);
|
||||||
|
} else {
|
||||||
|
log_debug("IQ affiliation set handler fired.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle error responses
|
||||||
|
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||||
|
char *error_message = stanza_get_error_message(stanza);
|
||||||
|
handle_room_affiliation_set_error(from, affiliation_set->jid, affiliation_set->affiliation, error_message);
|
||||||
|
free(error_message);
|
||||||
|
} else {
|
||||||
|
handle_room_affiliation_set(from, affiliation_set->jid, affiliation_set->affiliation);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(affiliation_set->jid);
|
||||||
|
free(affiliation_set->affiliation);
|
||||||
|
free(affiliation_set);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_room_affiliation_list_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 *affiliation = (char *)userdata;
|
||||||
|
|
||||||
|
if (id != NULL) {
|
||||||
|
log_debug("IQ affiliation list result handler fired, id: %s.", id);
|
||||||
|
} else {
|
||||||
|
log_debug("IQ affiliation list result handler fired.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle error responses
|
||||||
|
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||||
|
char *error_message = stanza_get_error_message(stanza);
|
||||||
|
handle_room_affiliation_list_result_error(from, affiliation, error_message);
|
||||||
|
free(error_message);
|
||||||
|
free(affiliation);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
GSList *jids = NULL;
|
||||||
|
|
||||||
|
xmpp_stanza_t *query = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_ADMIN);
|
||||||
|
if (query) {
|
||||||
|
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
|
||||||
|
while (child) {
|
||||||
|
char *name = xmpp_stanza_get_name(child);
|
||||||
|
if (g_strcmp0(name, "item") == 0) {
|
||||||
|
char *jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
|
||||||
|
if (jid) {
|
||||||
|
jids = g_slist_insert_sorted(jids, jid, (GCompareFunc)g_strcmp0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
child = xmpp_stanza_get_next(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_room_affiliation_list(from, affiliation, jids);
|
||||||
|
free(affiliation);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
_room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
void * const userdata)
|
void * const userdata)
|
||||||
|
@ -192,8 +192,8 @@ void (*iq_send_ping)(const char * const target);
|
|||||||
void (*iq_send_caps_request)(const char * const to, const char * const id,
|
void (*iq_send_caps_request)(const char * const to, const char * const id,
|
||||||
const char * const node, const char * const ver);
|
const char * const node, const char * const ver);
|
||||||
void (*iq_room_info_request)(gchar *room);
|
void (*iq_room_info_request)(gchar *room);
|
||||||
void (*iq_room_affiliation_list)(const char * const room, const char * const affiliation);
|
void (*iq_room_affiliation_list)(const char * const room, char *affiliation);
|
||||||
void (*iq_room_affiliation_set)(const char * const room, const char * const jid, const char * const affiliation,
|
void (*iq_room_affiliation_set)(const char * const room, const char * const jid, char *affiliation,
|
||||||
const char * const reason);
|
const char * const reason);
|
||||||
|
|
||||||
// caps functions
|
// caps functions
|
||||||
|
Loading…
Reference in New Issue
Block a user