mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-19 05:26:21 +00:00
Allow adding and removing room owners
This commit is contained in:
@@ -88,6 +88,7 @@ static char * _alias_autocomplete(char *input, int *size);
|
||||
static char * _join_autocomplete(char *input, int *size);
|
||||
static char * _log_autocomplete(char *input, int *size);
|
||||
static char * _form_autocomplete(char *input, int *size);
|
||||
static char * _room_autocomplete(char *input, int *size);
|
||||
|
||||
GHashTable *commands = NULL;
|
||||
|
||||
@@ -306,7 +307,7 @@ static struct cmd_t command_defs[] =
|
||||
NULL } } },
|
||||
|
||||
{ "/room",
|
||||
cmd_room, parse_args, 1, 1, NULL,
|
||||
cmd_room, parse_args, 1, 4, NULL,
|
||||
{ "/room accept|destroy|config|info", "Room configuration.",
|
||||
{ "/room accept|destroy|config|info",
|
||||
"--------------------------------",
|
||||
@@ -1670,8 +1671,8 @@ _cmd_complete_parameters(char *input, int *size)
|
||||
}
|
||||
}
|
||||
|
||||
gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/room" };
|
||||
Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, room_ac };
|
||||
gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins" };
|
||||
Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac };
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
|
||||
result = autocomplete_param_with_ac(input, size, cmds[i], completers[i], TRUE);
|
||||
@@ -1700,6 +1701,7 @@ _cmd_complete_parameters(char *input, int *size)
|
||||
g_hash_table_insert(ac_funcs, "/alias", _alias_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/join", _join_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/form", _form_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/room", _room_autocomplete);
|
||||
|
||||
char parsed[*size+1];
|
||||
i = 0;
|
||||
@@ -2213,6 +2215,19 @@ _form_autocomplete(char *input, int *size)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *
|
||||
_room_autocomplete(char *input, int *size)
|
||||
{
|
||||
char *result = NULL;
|
||||
|
||||
result = autocomplete_param_with_ac(input, size, "/room", room_ac, TRUE);
|
||||
if (result != NULL) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *
|
||||
_statuses_autocomplete(char *input, int *size)
|
||||
{
|
||||
|
||||
@@ -2100,8 +2100,50 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "owners") == 0) {
|
||||
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OWNER);
|
||||
return TRUE;
|
||||
if ((g_strcmp0(args[1], "add") == 0) || (g_strcmp0(args[1], "remove") == 0)) {
|
||||
char *nick = args[2];
|
||||
if (!nick) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
Occupant *occupant = muc_roster_item(room, nick);
|
||||
if (!occupant) {
|
||||
win_save_vprint(window, '!', NULL, 0, 0, "", "Could not find occupant: ", nick);
|
||||
return TRUE;
|
||||
}
|
||||
if (!occupant->jid) {
|
||||
win_save_vprint(window, '!', NULL, 0, 0, "", "Could not find JID for occupant: ", nick);
|
||||
return TRUE;
|
||||
}
|
||||
Jid *jidp = jid_create(occupant->jid);
|
||||
if (!jidp->barejid) {
|
||||
win_save_vprint(window, '!', NULL, 0, 0, "", "Could not find bare JID for occupant:", nick);
|
||||
jid_destroy(jidp);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *reason = args[3];
|
||||
if (g_strcmp0(args[1], "add") == 0) {
|
||||
if (occupant->affiliation == MUC_AFFILIATION_OWNER) {
|
||||
win_save_vprint(window, '!', NULL, 0, 0, "", "%s already has owner affiliation", nick);
|
||||
} else {
|
||||
iq_room_owner_add(room, jidp->barejid, reason);
|
||||
}
|
||||
} else {
|
||||
if (occupant->affiliation != MUC_AFFILIATION_OWNER) {
|
||||
const char *affiliation_str = muc_occupant_affiliation_str(occupant);
|
||||
win_save_vprint(window, '!', NULL, 0, 0, "",
|
||||
"%s does not have owner affiliation, current affiliation:", nick, affiliation_str);
|
||||
} else {
|
||||
iq_room_owner_remove(room, jidp->barejid, reason);
|
||||
}
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
return TRUE;
|
||||
} else {
|
||||
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OWNER);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (g_strcmp0(args[0], "admins") == 0) {
|
||||
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_ADMIN);
|
||||
@@ -2120,12 +2162,12 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
||||
if (g_strcmp0(args[0], "accept") == 0) {
|
||||
gboolean requires_config = muc_requires_config(room);
|
||||
if (!requires_config) {
|
||||
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Current room does not require configuration.");
|
||||
win_save_print(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Current room does not require configuration.");
|
||||
return TRUE;
|
||||
} else {
|
||||
iq_confirm_instant_room(room);
|
||||
muc_set_requires_config(room, FALSE);
|
||||
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room unlocked.");
|
||||
win_save_print(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room unlocked.");
|
||||
cons_show("Room unlocked: %s (%d)", room, ui_index);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -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