Add support for command config execution
This commit is contained in:
@@ -88,6 +88,11 @@ typedef struct privilege_set_t {
|
||||
char *privilege;
|
||||
} ProfPrivilegeSet;
|
||||
|
||||
typedef struct command_config_data_t {
|
||||
char *sessionid;
|
||||
char *command;
|
||||
} CommandConfigData;
|
||||
|
||||
static int _iq_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
|
||||
|
||||
static void _error_handler(xmpp_stanza_t *const stanza);
|
||||
@@ -724,6 +729,36 @@ iq_command_exec(const char *const target, const char *const command)
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
void
|
||||
iq_submit_command_config(ProfConfWin *confwin)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
CommandConfigData *data = (CommandConfigData *)confwin->userdata;
|
||||
xmpp_stanza_t *iq = stanza_create_command_config_submit_iq(ctx, confwin->roomjid, data->command, data->sessionid, confwin->form);
|
||||
|
||||
const char *id = xmpp_stanza_get_id(iq);
|
||||
iq_id_handler_add(id, _command_exec_response_handler, NULL, NULL);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
free(data->sessionid);
|
||||
free(data->command);
|
||||
free(data);
|
||||
}
|
||||
|
||||
void
|
||||
iq_cancel_command_config(ProfConfWin *confwin)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
CommandConfigData *data = (CommandConfigData *)confwin->userdata;
|
||||
xmpp_stanza_t *iq = stanza_create_room_config_cancel_iq(ctx, confwin->roomjid);
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
free(data->sessionid);
|
||||
free(data->command);
|
||||
free(data);
|
||||
}
|
||||
|
||||
static void
|
||||
_error_handler(xmpp_stanza_t *const stanza)
|
||||
{
|
||||
@@ -1098,7 +1133,7 @@ _command_exec_response_handler(xmpp_stanza_t *const stanza, void *const userdata
|
||||
const char *id = xmpp_stanza_get_id(stanza);
|
||||
const char *type = xmpp_stanza_get_type(stanza);
|
||||
const char *from = xmpp_stanza_get_from(stanza);
|
||||
const char *const command = userdata;
|
||||
char *command = userdata;
|
||||
|
||||
if (id) {
|
||||
log_debug("IQ command exec response handler fired, id: %s.", id);
|
||||
@@ -1156,7 +1191,10 @@ _command_exec_response_handler(xmpp_stanza_t *const stanza, void *const userdata
|
||||
}
|
||||
|
||||
DataForm *form = form_create(x);
|
||||
ProfConfWin *confwin = (ProfConfWin*)wins_new_config(from, form, NULL, NULL);
|
||||
CommandConfigData *data = malloc(sizeof(CommandConfigData));
|
||||
data->sessionid = strdup(xmpp_stanza_get_attribute(cmd, "sessionid"));
|
||||
data->command = command;
|
||||
ProfConfWin *confwin = (ProfConfWin*)wins_new_config(from, form, iq_submit_command_config, iq_cancel_command_config, data);
|
||||
confwin_handle_configuration(confwin, form);
|
||||
} else if (g_strcmp0(status, "canceled") == 0) {
|
||||
win_handle_command_exec_status(win, command, "canceled");
|
||||
@@ -1703,7 +1741,7 @@ _room_config_id_handler(xmpp_stanza_t *const stanza, void *const userdata)
|
||||
}
|
||||
|
||||
DataForm *form = form_create(x);
|
||||
ProfConfWin *confwin = (ProfConfWin*)wins_new_config(from, form, iq_submit_room_config, iq_room_config_cancel);
|
||||
ProfConfWin *confwin = (ProfConfWin*)wins_new_config(from, form, iq_submit_room_config, iq_room_config_cancel, NULL);
|
||||
confwin_handle_configuration(confwin, form);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -2063,6 +2063,31 @@ stanza_create_command_exec_iq(xmpp_ctx_t *ctx, const char *const target,
|
||||
return iq;
|
||||
}
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_create_command_config_submit_iq(xmpp_ctx_t *ctx, const char *const room,
|
||||
const char *const node, const char *const sessionid, DataForm *form)
|
||||
{
|
||||
char *id = connection_create_stanza_id("commandconf_submit");
|
||||
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
|
||||
free(id);
|
||||
xmpp_stanza_set_to(iq, room);
|
||||
|
||||
xmpp_stanza_t *command = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(command, STANZA_NAME_COMMAND);
|
||||
xmpp_stanza_set_ns(command, STANZA_NS_COMMAND);
|
||||
xmpp_stanza_set_attribute(command, "node", node);
|
||||
xmpp_stanza_set_attribute(command, "sessionid", sessionid);
|
||||
|
||||
xmpp_stanza_t *x = form_create_submission(form);
|
||||
xmpp_stanza_add_child(command, x);
|
||||
xmpp_stanza_release(x);
|
||||
|
||||
xmpp_stanza_add_child(iq, command);
|
||||
xmpp_stanza_release(command);
|
||||
|
||||
return iq;
|
||||
}
|
||||
|
||||
static void
|
||||
_stanza_add_unique_id(xmpp_stanza_t *stanza, char *prefix)
|
||||
{
|
||||
|
||||
@@ -282,6 +282,7 @@ xmpp_stanza_t* stanza_create_room_kick_iq(xmpp_ctx_t *const ctx, const char *con
|
||||
const char *const reason);
|
||||
|
||||
xmpp_stanza_t* stanza_create_command_exec_iq(xmpp_ctx_t *ctx, const char *const target, const char *const node);
|
||||
xmpp_stanza_t* stanza_create_command_config_submit_iq(xmpp_ctx_t *ctx, const char *const room, const char *const node, const char *const sessionid, DataForm *form);
|
||||
|
||||
int stanza_get_idle_time(xmpp_stanza_t *const stanza);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user