diff options
-rw-r--r-- | src/command/cmd_funcs.c | 4 | ||||
-rw-r--r-- | src/ui/ui.h | 1 | ||||
-rw-r--r-- | src/ui/window.c | 7 | ||||
-rw-r--r-- | src/xmpp/iq.c | 49 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 2 | ||||
-rw-r--r-- | src/xmpp/stanza.h | 1 |
6 files changed, 60 insertions, 4 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 2e606ef5..dc112d85 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -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; } diff --git a/src/ui/ui.h b/src/ui/ui.h index f1d8161f..fa8f948a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -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); diff --git a/src/ui/window.c b/src/ui/window.c index 3ba6b387..f38127d7 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -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); +} diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index ad7ef54d..8702d1a1 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -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; } diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index cc842ff6..537fbf96 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -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); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index a3cf2c4c..5f8203a2 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -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" |