Merge pull request #991 from paulfariello/feature/xep-0050

Add support for xep 0050 ad-hoc commands, without multi-step
This commit is contained in:
Michael Vetter
2018-09-27 17:27:37 +02:00
committed by GitHub
38 changed files with 695 additions and 190 deletions

View File

@@ -664,7 +664,7 @@ cmd_ac_init(void)
autocomplete_add(time_ac, "console");
autocomplete_add(time_ac, "chat");
autocomplete_add(time_ac, "muc");
autocomplete_add(time_ac, "mucconfig");
autocomplete_add(time_ac, "config");
autocomplete_add(time_ac, "private");
autocomplete_add(time_ac, "xml");
autocomplete_add(time_ac, "statusbar");
@@ -1107,8 +1107,8 @@ cmd_ac_reset(ProfWin *window)
muc_jid_autocomplete_reset(mucwin->roomjid);
}
if (window->type == WIN_MUC_CONFIG) {
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
if (window->type == WIN_CONFIG) {
ProfConfWin *confwin = (ProfConfWin*)window;
assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
if (confwin->form) {
form_reset_autocompleters(confwin->form);
@@ -2349,13 +2349,13 @@ _inpblock_autocomplete(ProfWin *window, const char *const input, gboolean previo
static char*
_form_autocomplete(ProfWin *window, const char *const input, gboolean previous)
{
if (window->type != WIN_MUC_CONFIG) {
if (window->type != WIN_CONFIG) {
return NULL;
}
char *found = NULL;
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
ProfConfWin *confwin = (ProfConfWin*)window;
DataForm *form = confwin->form;
if (form) {
found = autocomplete_param_with_ac(input, "/form help", form->tag_ac, TRUE, previous);
@@ -2375,13 +2375,13 @@ _form_autocomplete(ProfWin *window, const char *const input, gboolean previous)
static char*
_form_field_autocomplete(ProfWin *window, const char *const input, gboolean previous)
{
if (window->type != WIN_MUC_CONFIG) {
if (window->type != WIN_CONFIG) {
return NULL;
}
char *found = NULL;
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
ProfConfWin *confwin = (ProfConfWin*)window;
DataForm *form = confwin->form;
if (form == NULL) {
return NULL;
@@ -2510,7 +2510,7 @@ _time_autocomplete(ProfWin *window, const char *const input, gboolean previous)
return found;
}
found = autocomplete_param_with_ac(input, "/time mucconfig", time_format_ac, TRUE, previous);
found = autocomplete_param_with_ac(input, "/time config", time_format_ac, TRUE, previous);
if (found) {
return found;
}

View File

@@ -1265,8 +1265,8 @@ static struct cmd_t command_defs[] =
CMD_TAGS(
CMD_TAG_UI)
CMD_SYN(
"/time console|chat|muc|mucconfig|private|xml set <format>",
"/time console|chat|muc|mucconfig|private|xml off",
"/time console|chat|muc|config|private|xml set <format>",
"/time console|chat|muc|config|private|xml off",
"/time statusbar set <format>",
"/time statusbar off",
"/time lastactivity set <format>")
@@ -1283,8 +1283,8 @@ static struct cmd_t command_defs[] =
{ "chat off", "Do not show time in chat windows." },
{ "muc set <format>", "Set time format for chat room windows." },
{ "muc off", "Do not show time in chat room windows." },
{ "mucconfig set <format>", "Set time format for chat room config windows." },
{ "mucconfig off", "Do not show time in chat room config windows." },
{ "config set <format>", "Set time format for config windows." },
{ "config off", "Do not show time in config windows." },
{ "private set <format>", "Set time format for private chat windows." },
{ "private off", "Do not show time in private chat windows." },
{ "xml set <format>", "Set time format for XML console window." },
@@ -2306,6 +2306,26 @@ static struct cmd_t command_defs[] =
CMD_EXAMPLES(
"/export /path/to/output.csv",
"/export ~/contacts.csv")
},
{ "/cmd",
parse_args, 1, 3, NULL,
CMD_SUBFUNCS(
{ "list", cmd_command_list },
{ "exec", cmd_command_exec })
CMD_NOMAINFUNC
CMD_NOTAGS
CMD_SYN(
"/cmd list [<jid>]",
"/cmd exec <command> [<jid>]")
CMD_DESC(
"Execute ad hoc commands.")
CMD_ARGS(
{ "list", "List supported ad hoc commands." },
{ "exec <command>", "Execute a command." })
CMD_EXAMPLES(
"/cmd list",
"/cmd exec ping")
}
};

View File

@@ -70,6 +70,7 @@
#include "ui/ui.h"
#include "ui/window_list.h"
#include "xmpp/xmpp.h"
#include "xmpp/connection.h"
#include "xmpp/contact.h"
#include "xmpp/roster_list.h"
#include "xmpp/jid.h"
@@ -204,7 +205,7 @@ cmd_tls_trust(ProfWin *window, const char *const command, gchar **args)
#ifdef HAVE_LIBMESODE
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
cons_show("You are currently not connected.");
return TRUE;
}
if (!connection_is_secured()) {
@@ -3632,11 +3633,11 @@ cmd_decline(ProfWin *window, const char *const command, gchar **args)
gboolean
cmd_form_field(ProfWin *window, char *tag, gchar **args)
{
if (window->type != WIN_MUC_CONFIG) {
if (window->type != WIN_CONFIG) {
return TRUE;
}
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
ProfConfWin *confwin = (ProfConfWin*)window;
DataForm *form = confwin->form;
if (form) {
if (!form_tag_exists(form, tag)) {
@@ -3657,14 +3658,14 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
if (g_strcmp0(value, "on") == 0) {
form_set_value(form, tag, "1");
win_println(window, THEME_DEFAULT, '-', "Field updated...");
mucconfwin_show_form_field(confwin, form, tag);
confwin_show_form_field(confwin, form, tag);
} else if (g_strcmp0(value, "off") == 0) {
form_set_value(form, tag, "0");
win_println(window, THEME_DEFAULT, '-', "Field updated...");
mucconfwin_show_form_field(confwin, form, tag);
confwin_show_form_field(confwin, form, tag);
} else {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
}
break;
@@ -3675,24 +3676,24 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
value = args[0];
if (value == NULL) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
} else {
form_set_value(form, tag, value);
win_println(window, THEME_DEFAULT, '-', "Field updated...");
mucconfwin_show_form_field(confwin, form, tag);
confwin_show_form_field(confwin, form, tag);
}
break;
case FIELD_LIST_SINGLE:
value = args[0];
if ((value == NULL) || !form_field_contains_option(form, tag, value)) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
} else {
form_set_value(form, tag, value);
win_println(window, THEME_DEFAULT, '-', "Field updated...");
mucconfwin_show_form_field(confwin, form, tag);
confwin_show_form_field(confwin, form, tag);
}
break;
@@ -3703,32 +3704,32 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
}
if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
break;
}
if (value == NULL) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
break;
}
if (g_strcmp0(cmd, "add") == 0) {
form_add_value(form, tag, value);
win_println(window, THEME_DEFAULT, '-', "Field updated...");
mucconfwin_show_form_field(confwin, form, tag);
confwin_show_form_field(confwin, form, tag);
break;
}
if (g_strcmp0(args[0], "remove") == 0) {
if (!g_str_has_prefix(value, "val")) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
break;
}
if (strlen(value) < 4) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
break;
}
@@ -3736,7 +3737,7 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
int index = strtol(&value[3], NULL, 10);
if ((index < 1) || (index > form_get_value_count(form, tag))) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
break;
}
@@ -3744,7 +3745,7 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
removed = form_remove_text_multi_value(form, tag, index);
if (removed) {
win_println(window, THEME_DEFAULT, '-', "Field updated...");
mucconfwin_show_form_field(confwin, form, tag);
confwin_show_form_field(confwin, form, tag);
} else {
win_println(window, THEME_DEFAULT, '-', "Could not remove %s from %s", value, tag);
}
@@ -3757,13 +3758,13 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
}
if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
break;
}
if (value == NULL) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
break;
}
@@ -3773,13 +3774,13 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
added = form_add_unique_value(form, tag, value);
if (added) {
win_println(window, THEME_DEFAULT, '-', "Field updated...");
mucconfwin_show_form_field(confwin, form, tag);
confwin_show_form_field(confwin, form, tag);
} else {
win_println(window, THEME_DEFAULT, '-', "Value %s already selected for %s", value, tag);
}
} else {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
}
break;
@@ -3790,13 +3791,13 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
removed = form_remove_value(form, tag, value);
if (removed) {
win_println(window, THEME_DEFAULT, '-', "Field updated...");
mucconfwin_show_form_field(confwin, form, tag);
confwin_show_form_field(confwin, form, tag);
} else {
win_println(window, THEME_DEFAULT, '-', "Value %s is not currently set for %s", value, tag);
}
} else {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
}
}
@@ -3808,13 +3809,13 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
}
if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
break;
}
if (value == NULL) {
win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:");
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
win_println(window, THEME_DEFAULT, '-', "");
break;
}
@@ -3822,7 +3823,7 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
added = form_add_unique_value(form, tag, value);
if (added) {
win_println(window, THEME_DEFAULT, '-', "Field updated...");
mucconfwin_show_form_field(confwin, form, tag);
confwin_show_form_field(confwin, form, tag);
} else {
win_println(window, THEME_DEFAULT, '-', "JID %s already exists in %s", value, tag);
}
@@ -3832,7 +3833,7 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args)
removed = form_remove_value(form, tag, value);
if (removed) {
win_println(window, THEME_DEFAULT, '-', "Field updated...");
mucconfwin_show_form_field(confwin, form, tag);
confwin_show_form_field(confwin, form, tag);
} else {
win_println(window, THEME_DEFAULT, '-', "Field %s does not contain %s", tag, value);
}
@@ -3857,7 +3858,7 @@ cmd_form(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
if (window->type != WIN_MUC_CONFIG) {
if (window->type != WIN_CONFIG) {
cons_show("Command '/form' does not apply to this window.");
return TRUE;
}
@@ -3870,20 +3871,20 @@ cmd_form(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
ProfConfWin *confwin = (ProfConfWin*)window;
assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
if (g_strcmp0(args[0], "show") == 0) {
mucconfwin_show_form(confwin);
confwin_show_form(confwin);
return TRUE;
}
if (g_strcmp0(args[0], "help") == 0) {
char *tag = args[1];
if (tag) {
mucconfwin_field_help(confwin, tag);
confwin_field_help(confwin, tag);
} else {
mucconfwin_form_help(confwin);
confwin_form_help(confwin);
gchar **help_text = NULL;
Command *command = cmd_get("/form");
@@ -3898,12 +3899,12 @@ cmd_form(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
if (g_strcmp0(args[0], "submit") == 0) {
iq_submit_room_config(confwin->roomjid, confwin->form);
if (g_strcmp0(args[0], "submit") == 0 && confwin->submit != NULL) {
confwin->submit(confwin);
}
if (g_strcmp0(args[0], "cancel") == 0) {
iq_room_config_cancel(confwin->roomjid);
if (g_strcmp0(args[0], "cancel") == 0 && confwin->cancel != NULL) {
confwin->cancel(confwin);
}
if ((g_strcmp0(args[0], "submit") == 0) || (g_strcmp0(args[0], "cancel") == 0)) {
@@ -4264,7 +4265,7 @@ cmd_room(ProfWin *window, const char *const command, gchar **args)
}
if (g_strcmp0(args[0], "config") == 0) {
ProfMucConfWin *confwin = wins_get_muc_conf(mucwin->roomjid);
ProfConfWin *confwin = wins_get_conf(mucwin->roomjid);
if (confwin) {
ui_focus_win((ProfWin*)confwin);
@@ -5159,20 +5160,20 @@ cmd_time(ProfWin *window, const char *const command, gchar **args)
cons_bad_cmd_usage(command);
return TRUE;
}
} else if (g_strcmp0(args[0], "mucconfig") == 0) {
} else if (g_strcmp0(args[0], "config") == 0) {
if (args[1] == NULL) {
char *format = prefs_get_string(PREF_TIME_MUCCONFIG);
cons_show("MUC config time format: '%s'.", format);
char *format = prefs_get_string(PREF_TIME_CONFIG);
cons_show("config time format: '%s'.", format);
prefs_free_string(format);
return TRUE;
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
prefs_set_string(PREF_TIME_MUCCONFIG, args[2]);
cons_show("MUC config time format set to '%s'.", args[2]);
prefs_set_string(PREF_TIME_CONFIG, args[2]);
cons_show("config time format set to '%s'.", args[2]);
wins_resize_all();
return TRUE;
} else if (g_strcmp0(args[1], "off") == 0) {
prefs_set_string(PREF_TIME_MUCCONFIG, "off");
cons_show("MUC config time display disabled.");
prefs_set_string(PREF_TIME_CONFIG, "off");
cons_show("config time display disabled.");
wins_resize_all();
return TRUE;
} else {
@@ -7552,10 +7553,122 @@ cmd_encwarn(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
gboolean
cmd_command_list(ProfWin *window, const char *const command, gchar **args)
{
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
return TRUE;
}
if (connection_supports(XMPP_FEATURE_COMMANDS) == FALSE) {
cons_show("Server does not support ad hoc commands.");
return TRUE;
}
char *jid = args[1];
if (jid == NULL) {
switch (window->type) {
case WIN_MUC:
{
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
jid = mucwin->roomjid;
break;
}
case WIN_CHAT:
{
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
jid = chatwin->barejid;
break;
}
case WIN_PRIVATE:
{
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
jid = privatewin->fulljid;
break;
}
case WIN_CONSOLE:
{
jid = connection_get_domain();
break;
}
default:
cons_show("Cannot send ad hoc commands.");
return TRUE;
}
}
iq_command_list(jid);
cons_show("List available ad hoc commands");
return TRUE;
}
gboolean
cmd_command_exec(ProfWin *window, const char *const command, gchar **args)
{
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
return TRUE;
}
if (connection_supports(XMPP_FEATURE_COMMANDS) == FALSE) {
cons_show("Server does not support ad hoc commands.");
return TRUE;
}
char *jid = args[2];
if (jid == NULL) {
switch (window->type) {
case WIN_MUC:
{
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
jid = mucwin->roomjid;
break;
}
case WIN_CHAT:
{
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
jid = chatwin->barejid;
break;
}
case WIN_PRIVATE:
{
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
jid = privatewin->fulljid;
break;
}
case WIN_CONSOLE:
{
jid = connection_get_domain();
break;
}
default:
cons_show("Cannot send ad hoc commands.");
return TRUE;
}
}
iq_command_exec(jid, args[1]);
cons_show("Execute %s...", args[1]);
return TRUE;
}
static gboolean
_cmd_execute(ProfWin *window, const char *const command, const char *const inp)
{
if (g_str_has_prefix(command, "/field") && window->type == WIN_MUC_CONFIG) {
if (g_str_has_prefix(command, "/field") && window->type == WIN_CONFIG) {
gboolean result = FALSE;
gchar **args = parse_args_with_freetext(inp, 1, 2, &result);
if (!result) {

View File

@@ -158,6 +158,8 @@ gboolean cmd_script(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_export(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_charset(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_console(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_command_list(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_command_exec(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_plugins(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_plugins_sourcepath(ProfWin *window, const char *const command, gchar **args);