about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/ui/win_types.h1
-rw-r--r--src/ui/window.c3
-rw-r--r--src/ui/window_list.c4
-rw-r--r--src/ui/window_list.h2
-rw-r--r--src/xmpp/iq.c44
-rw-r--r--src/xmpp/stanza.c25
-rw-r--r--src/xmpp/stanza.h1
8 files changed, 74 insertions, 8 deletions
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 1bcc20fc..136a5e98 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -346,7 +346,7 @@ ProfWin* win_create_console(void);
 ProfWin* win_create_xmlconsole(void);
 ProfWin* win_create_chat(const char *const barejid);
 ProfWin* win_create_muc(const char *const roomjid);
-ProfWin* win_create_config(const char *const title, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel);
+ProfWin* win_create_config(const char *const title, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel, const void *userdata);
 ProfWin* win_create_private(const char *const fulljid);
 ProfWin* win_create_plugin(const char *const plugin_name, const char *const tag);
 void win_update_virtual(ProfWin *window);
diff --git a/src/ui/win_types.h b/src/ui/win_types.h
index c9dc623b..eb453cd0 100644
--- a/src/ui/win_types.h
+++ b/src/ui/win_types.h
@@ -182,6 +182,7 @@ struct prof_conf_win_t {
     unsigned long memcheck;
     ProfConfWinCallback submit;
     ProfConfWinCallback cancel;
+    const void *userdata;
 };
 
 typedef struct prof_private_win_t {
diff --git a/src/ui/window.c b/src/ui/window.c
index f34e354e..5ad354f2 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -203,7 +203,7 @@ win_create_muc(const char *const roomjid)
 }
 
 ProfWin*
-win_create_config(const char *const roomjid, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel)
+win_create_config(const char *const roomjid, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel, const void *userdata)
 {
     ProfConfWin *new_win = malloc(sizeof(ProfConfWin));
     new_win->window.type = WIN_CONFIG;
@@ -212,6 +212,7 @@ win_create_config(const char *const roomjid, DataForm *form, ProfConfWinCallback
     new_win->form = form;
     new_win->submit = submit;
     new_win->cancel = cancel;
+    new_win->userdata = userdata;
 
     new_win->memcheck = PROFCONFWIN_MEMCHECK;
 
diff --git a/src/ui/window_list.c b/src/ui/window_list.c
index 8f886b54..a12dc7cb 100644
--- a/src/ui/window_list.c
+++ b/src/ui/window_list.c
@@ -657,12 +657,12 @@ wins_new_muc(const char *const roomjid)
 }
 
 ProfWin*
-wins_new_config(const char *const roomjid, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel)
+wins_new_config(const char *const roomjid, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel, const void *userdata)
 {
     GList *keys = g_hash_table_get_keys(windows);
     int result = _wins_get_next_available_num(keys);
     g_list_free(keys);
-    ProfWin *newwin = win_create_config(roomjid, form, submit, cancel);
+    ProfWin *newwin = win_create_config(roomjid, form, submit, cancel, userdata);
     g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
     return newwin;
 }
diff --git a/src/ui/window_list.h b/src/ui/window_list.h
index f427a6d7..b47ee79f 100644
--- a/src/ui/window_list.h
+++ b/src/ui/window_list.h
@@ -42,7 +42,7 @@ void wins_init(void);
 ProfWin* wins_new_xmlconsole(void);
 ProfWin* wins_new_chat(const char *const barejid);
 ProfWin* wins_new_muc(const char *const roomjid);
-ProfWin* wins_new_config(const char *const roomjid, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel);
+ProfWin* wins_new_config(const char *const roomjid, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel, const void *userdata);
 ProfWin* wins_new_private(const char *const fulljid);
 ProfWin* wins_new_plugin(const char *const plugin_name, const char *const tag);
 
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 8e7ecc0b..337701bc 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -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;
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 537fbf96..68919710 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -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)
 {
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 5f8203a2..696f60da 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -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);