1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Handle simple execution

Tested with ping from biboumi
This commit is contained in:
Paul Fariello 2018-03-22 22:21:15 +02:20
parent c9f6a78f57
commit 925cd488c1
6 changed files with 60 additions and 4 deletions

View File

@ -7509,9 +7509,9 @@ cmd_command_exec(ProfWin *window, const char *const command, gchar **args)
ProfMucWin *mucwin = (ProfMucWin*)window;
iq_command_exec(mucwin->roomjid, args[0]);
iq_command_exec(mucwin->roomjid, args[1]);
cons_show("Execute %s...", args[0]);
cons_show("Execute %s...", args[1]);
return TRUE;
}

View File

@ -379,6 +379,7 @@ char* win_get_tab_identifier(ProfWin *window);
char* win_to_string(ProfWin *window);
void win_command_list_error(ProfWin *window, const char *const error);
void win_handle_command_list(ProfWin *window, GSList *cmds);
void win_handle_command_exec_result_note(ProfWin *window, const char *const type, const char *const value);
// desktop notifications
void notifier_initialise(void);

View File

@ -1752,3 +1752,10 @@ win_handle_command_list(ProfWin *window, GSList *cmds)
win_println(window, THEME_DEFAULT, '!', "");
}
}
void
win_handle_command_exec_result_note(ProfWin *window, const char *const type, const char *const value)
{
assert(window != NULL);
win_println(window, THEME_DEFAULT, '!', value);
}

View File

@ -1095,7 +1095,54 @@ _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)
{
cons_show("%s", NULL, __func__);
const char *id = xmpp_stanza_get_id(stanza);
const char *type = xmpp_stanza_get_type(stanza);
char *from = strdup(xmpp_stanza_get_from(stanza));
const char *const command = userdata;
if (id) {
log_debug("IQ command exec response handler fired, id: %s.", id);
} else {
log_debug("IQ command exec response handler fired.");
}
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
log_debug("Error executing command %s for %s: %s", command, 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;
}
xmpp_stanza_t *cmd = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_COMMAND);
if (!cmd) {
/* TODO */
}
ProfWin *win = wins_get_by_string(from);
const char *status = xmpp_stanza_get_attribute(cmd, STANZA_ATTR_STATUS);
if (g_strcmp0(status, "completed") == 0) {
if (win) {
xmpp_stanza_t *note = xmpp_stanza_get_child_by_name(cmd, "note");
if (note) {
const char *type = xmpp_stanza_get_attribute(note, "type");
const char *value = xmpp_stanza_get_text(note);
win_handle_command_exec_result_note(win, type, value);
}
}
} else if (g_strcmp0(status, "executing") == 0) {
} else if (g_strcmp0(status, "canceled") == 0) {
} else {
/* TODO */
}
free(from);
return 0;
}

View File

@ -2045,7 +2045,7 @@ xmpp_stanza_t*
stanza_create_command_exec_iq(xmpp_ctx_t *ctx, const char *const target,
const char *const node)
{
char *id = create_unique_id("command");
char *id = connection_create_stanza_id("cmdexec");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
xmpp_stanza_set_to(iq, target);

View File

@ -157,6 +157,7 @@
#define STANZA_ATTR_REASON "reason"
#define STANZA_ATTR_AUTOJOIN "autojoin"
#define STANZA_ATTR_PASSWORD "password"
#define STANZA_ATTR_STATUS "status"
#define STANZA_TEXT_AWAY "away"
#define STANZA_TEXT_DND "dnd"