mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-26 09:36:21 +00:00
Add command subcommands: list and exec
Also handle list result
This commit is contained in:
@@ -120,7 +120,8 @@ static int _caps_response_for_jid_id_handler(xmpp_stanza_t *const stanza, void *
|
||||
static int _caps_response_legacy_id_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _auto_pong_id_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _room_list_id_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _command_response_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _command_list_result_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static int _command_exec_response_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
|
||||
static void _iq_free_room_data(ProfRoomInfoData *roominfo);
|
||||
static void _iq_free_affiliation_set(ProfPrivilegeSet *affiliation_set);
|
||||
@@ -320,7 +321,7 @@ iq_room_list_request(gchar *conferencejid, gchar *filter)
|
||||
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
char *id = connection_create_stanza_id("confreq");
|
||||
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, id, conferencejid);
|
||||
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, id, conferencejid, NULL);
|
||||
|
||||
iq_id_handler_add(id, _room_list_id_handler, NULL, filter);
|
||||
|
||||
@@ -522,7 +523,7 @@ void
|
||||
iq_disco_items_request(gchar *jid)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "discoitemsreq", jid);
|
||||
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "discoitemsreq", jid, NULL);
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
@@ -531,7 +532,7 @@ void
|
||||
iq_disco_items_request_onconnect(gchar *jid)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "discoitemsreq_onconnect", jid);
|
||||
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "discoitemsreq_onconnect", jid, NULL);
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
@@ -698,13 +699,26 @@ iq_send_ping(const char *const target)
|
||||
}
|
||||
|
||||
void
|
||||
iq_send_command(const char *const target, const char *const command)
|
||||
iq_command_list(const char *const target)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_command_iq(ctx, target, command);
|
||||
const char *id = connection_create_stanza_id("cmdlist");
|
||||
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, id, target, STANZA_NS_COMMAND);
|
||||
|
||||
iq_id_handler_add(id, _command_list_result_handler, NULL, NULL);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
void
|
||||
iq_command_exec(const char *const target, const char *const command)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_command_exec_iq(ctx, target, command);
|
||||
const char *id = xmpp_stanza_get_id(iq);
|
||||
|
||||
iq_id_handler_add(id, _command_response_handler, free, strdup(command));
|
||||
iq_id_handler_add(id, _command_exec_response_handler, free, strdup(command));
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
@@ -1026,9 +1040,62 @@ _room_list_id_handler(xmpp_stanza_t *const stanza, void *const userdata)
|
||||
}
|
||||
|
||||
static int
|
||||
_command_response_handler(xmpp_stanza_t *const stanza, void *const userdata)
|
||||
_command_list_result_handler(xmpp_stanza_t *const stanza, void *const userdata)
|
||||
{
|
||||
cons_show("Plop", NULL);
|
||||
const char *id = xmpp_stanza_get_id(stanza);
|
||||
const char *type = xmpp_stanza_get_type(stanza);
|
||||
char *from = strdup(xmpp_stanza_get_from(stanza));
|
||||
|
||||
if (id) {
|
||||
log_debug("IQ command list result handler fired, id: %s.", id);
|
||||
} else {
|
||||
log_debug("IQ command list result handler fired.");
|
||||
}
|
||||
|
||||
// handle error responses
|
||||
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||
char *error_message = stanza_get_error_message(stanza);
|
||||
log_debug("Error retrieving command list for %s: %s", from, error_message);
|
||||
ProfWin *win = wins_get_by_string(from);
|
||||
if (win) {
|
||||
win_command_list_error(win, error_message);
|
||||
}
|
||||
free(error_message);
|
||||
free(from);
|
||||
return 0;
|
||||
}
|
||||
|
||||
GSList *cmds = NULL;
|
||||
|
||||
xmpp_stanza_t *query = xmpp_stanza_get_child_by_ns(stanza, XMPP_NS_DISCO_ITEMS);
|
||||
if (query) {
|
||||
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
|
||||
while (child) {
|
||||
const char *name = xmpp_stanza_get_name(child);
|
||||
if (g_strcmp0(name, "item") == 0) {
|
||||
const char *node = xmpp_stanza_get_attribute(child, STANZA_ATTR_NODE);
|
||||
if (node) {
|
||||
cmds = g_slist_insert_sorted(cmds, (gpointer)node, (GCompareFunc)g_strcmp0);
|
||||
}
|
||||
}
|
||||
child = xmpp_stanza_get_next(child);
|
||||
}
|
||||
}
|
||||
|
||||
ProfWin *win = wins_get_by_string(from);
|
||||
if (win) {
|
||||
win_handle_command_list(win, cmds);
|
||||
}
|
||||
g_slist_free(cmds);
|
||||
free(from);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_command_exec_response_handler(xmpp_stanza_t *const stanza, void *const userdata)
|
||||
{
|
||||
cons_show("%s", NULL, __func__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -924,7 +924,7 @@ stanza_create_disco_info_iq(xmpp_ctx_t *ctx, const char *const id, const char *c
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char *const id,
|
||||
const char *const jid)
|
||||
const char *const jid, const char *const node)
|
||||
{
|
||||
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
|
||||
xmpp_stanza_set_to(iq, jid);
|
||||
@@ -932,6 +932,9 @@ stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char *const id,
|
||||
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
|
||||
xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS);
|
||||
if (node) {
|
||||
xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node);
|
||||
}
|
||||
|
||||
xmpp_stanza_add_child(iq, query);
|
||||
xmpp_stanza_release(query);
|
||||
@@ -2039,7 +2042,7 @@ stanza_parse_presence(xmpp_stanza_t *stanza, int *err)
|
||||
}
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_create_command_iq(xmpp_ctx_t *ctx, const char *const target,
|
||||
stanza_create_command_exec_iq(xmpp_ctx_t *ctx, const char *const target,
|
||||
const char *const node)
|
||||
{
|
||||
char *id = create_unique_id("command");
|
||||
|
||||
@@ -280,7 +280,7 @@ xmpp_stanza_t* stanza_create_room_subject_message(xmpp_ctx_t *ctx, const char *c
|
||||
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* stanza_create_command_iq(xmpp_ctx_t *ctx, const char *const target, const char *const node);
|
||||
xmpp_stanza_t* stanza_create_command_exec_iq(xmpp_ctx_t *ctx, const char *const target, const char *const node);
|
||||
|
||||
int stanza_get_idle_time(xmpp_stanza_t *const stanza);
|
||||
|
||||
@@ -296,7 +296,7 @@ EntityCapabilities* stanza_create_caps_from_query_element(xmpp_stanza_t *query);
|
||||
|
||||
const char* stanza_get_presence_string_from_type(resource_presence_t presence_type);
|
||||
xmpp_stanza_t* stanza_create_software_version_iq(xmpp_ctx_t *ctx, const char *const fulljid);
|
||||
xmpp_stanza_t* stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char *const id, const char *const jid);
|
||||
xmpp_stanza_t* stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char *const id, const char *const jid, const char *const node);
|
||||
|
||||
char* stanza_get_status(xmpp_stanza_t *stanza, char *def);
|
||||
char* stanza_get_show(xmpp_stanza_t *stanza, char *def);
|
||||
|
||||
@@ -183,7 +183,8 @@ void iq_room_role_set(const char *const room, const char *const nick, char *role
|
||||
void iq_room_role_list(const char * const room, char *role);
|
||||
void iq_autoping_check(void);
|
||||
void iq_http_upload_request(HTTPUpload *upload);
|
||||
void iq_send_command(const char *const target, const char *const command);
|
||||
void iq_command_list(const char *const target);
|
||||
void iq_command_exec(const char *const target, const char *const command);
|
||||
|
||||
EntityCapabilities* caps_lookup(const char *const jid);
|
||||
void caps_close(void);
|
||||
|
||||
Reference in New Issue
Block a user