17 changes: 6 additions & 11 deletions po/de.po
Expand Up @@ -24,8 +24,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"PO-Revision-Date: 2019-02-23 23:18+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-02-28 20:18+0100\n"
"Last-Translator: Nils Görs <weechatter@arcor.de>\n"
"Language-Team: German <kde-i18n-de@kde.org>\n"
"Language: de\n"
Expand Down Expand Up @@ -4981,6 +4981,10 @@ msgstr "%sFehler beim Versenden des Signals %d an pid %d: %s"
msgid "%sYou can not write text in this buffer"
msgstr "%sIn diesen Buffer kann nicht geschrieben werden"

#, fuzzy, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr "%sBefehl \"/%s eval\" ist zur Zeit noch nicht implementiert"

#, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr ""
Expand Down Expand Up @@ -14801,12 +14805,3 @@ msgstr "%s%s: Zeitüberschreitung für \"%s\" mit %s"
msgid "%s%s: unable to connect: unexpected error (%d)"
msgstr ""
"%s%s: Verbindung konnte nicht hergestellt werden: unerwarteter Fehler (%d)"

#~ msgid "a filter with same name already exists"
#~ msgstr "es existiert bereits ein Filter mit dem selben Namen"

#~ msgid "Aspell enabled"
#~ msgstr "Aspell wurde aktiviert"

#~ msgid "Aspell disabled"
#~ msgstr "Aspell wurde deaktiviert"
18 changes: 6 additions & 12 deletions po/es.po
Expand Up @@ -22,8 +22,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"PO-Revision-Date: 2019-01-29 21:02+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-02-28 20:18+0100\n"
"Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: es\n"
Expand Down Expand Up @@ -4323,6 +4323,10 @@ msgstr ""
msgid "%sYou can not write text in this buffer"
msgstr "%sNo es posible escribir texto en este buffer"

#, fuzzy, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr "%sColor \"%s\" no está definido en la paleta"

#, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr "%sError: comando \"%s\" desconocido (use /help para ver la ayuda)"
Expand Down Expand Up @@ -12964,13 +12968,3 @@ msgstr "%s%s: tiempo de espera máximo para \"%s\" con %s"
#, fuzzy, c-format
msgid "%s%s: unable to connect: unexpected error (%d)"
msgstr "%s%s: no es posible conectarse al transmisor"

#, fuzzy
#~ msgid "a filter with same name already exists"
#~ msgstr "%sError: un buffer con el mismo nombre (%s) ya existe"

#~ msgid "Aspell enabled"
#~ msgstr "Aspell activado"

#~ msgid "Aspell disabled"
#~ msgstr "Aspell desactivado"
17 changes: 6 additions & 11 deletions po/fr.po
Expand Up @@ -21,8 +21,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"PO-Revision-Date: 2019-02-23 13:40+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-02-28 20:18+0100\n"
"Last-Translator: Sébastien Helleu <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: fr\n"
Expand Down Expand Up @@ -4852,6 +4852,10 @@ msgstr "%sErreur d'envoi du signal %d au pid %d : %s"
msgid "%sYou can not write text in this buffer"
msgstr "%sVous ne pouvez pas écrire de texte dans ce tampon"

#, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr "debug : la commande \"%s\" n'est pas autorisée dans ce contexte"

#, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr "%sErreur : commande \"%s\" inconnue (tapez /help pour l'aide)"
Expand Down Expand Up @@ -14499,12 +14503,3 @@ msgstr "%s%s : délai d'attente dépassé pour \"%s\" avec %s"
#, c-format
msgid "%s%s: unable to connect: unexpected error (%d)"
msgstr "%s%s : impossible de se connecter : erreur inattendue (%d)"

#~ msgid "a filter with same name already exists"
#~ msgstr "un filtre avec le même nom existe déjà"

#~ msgid "Aspell enabled"
#~ msgstr "Aspell activé"

#~ msgid "Aspell disabled"
#~ msgstr "Aspell désactivé"
21 changes: 6 additions & 15 deletions po/hu.po
Expand Up @@ -20,8 +20,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"PO-Revision-Date: 2018-11-17 10:36+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-02-28 20:18+0100\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: hu\n"
Expand Down Expand Up @@ -3697,6 +3697,10 @@ msgstr ""
msgid "%sYou can not write text in this buffer"
msgstr "%s az utolsó puffert nem lehet bezárni\n"

#, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr ""

#, fuzzy, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr "%s a \"%s\" aliasz vagy parancs nem található\n"
Expand Down Expand Up @@ -11951,16 +11955,3 @@ msgstr "%s hiányzó argumentum a(z) \"%s\" opciónak\n"
#, fuzzy, c-format
msgid "%s%s: unable to connect: unexpected error (%d)"
msgstr "%s DCC: nem sikerült kapcsolódni a küldőhöz\n"

#, fuzzy
#~ msgid "a filter with same name already exists"
#~ msgstr ""
#~ "%s nem sikerült a \"%s\" modult betölteni: már van ilyen nevű modul\n"

#, fuzzy
#~ msgid "Aspell enabled"
#~ msgstr "a felhasználók le lettek tiltva"

#, fuzzy
#~ msgid "Aspell disabled"
#~ msgstr "Nincs aliasz definiálva.\n"
18 changes: 6 additions & 12 deletions po/it.po
Expand Up @@ -20,8 +20,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"PO-Revision-Date: 2019-01-29 21:03+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-02-28 20:18+0100\n"
"Last-Translator: Esteban I. Ruiz Moreno <exio4.com@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: it\n"
Expand Down Expand Up @@ -4438,6 +4438,10 @@ msgstr ""
msgid "%sYou can not write text in this buffer"
msgstr "%sNon è possibile scrivere del testo in questo buffer"

#, fuzzy, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr "%sColore \"%s\" non definito nella tavolozza"

#, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr "%sErrore: comando \"%s\" sconosciuto (digita /help per l'aiuto)"
Expand Down Expand Up @@ -13181,13 +13185,3 @@ msgstr "%s%s: timeout per \"%s\" con %s"
#, fuzzy, c-format
msgid "%s%s: unable to connect: unexpected error (%d)"
msgstr "%s%s: impossibile connettersi al mittente"

#, fuzzy
#~ msgid "a filter with same name already exists"
#~ msgstr "%sErrore: un buffer con lo stesso nome (%s) esiste già"

#~ msgid "Aspell enabled"
#~ msgstr "Aspell abilitato"

#~ msgid "Aspell disabled"
#~ msgstr "Aspell disabilitato"
17 changes: 6 additions & 11 deletions po/ja.po
Expand Up @@ -20,8 +20,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"PO-Revision-Date: 2019-02-03 19:01+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-02-28 20:18+0100\n"
"Last-Translator: AYANOKOUZI, Ryuunosuke <i38w7i3@yahoo.co.jp>\n"
"Language-Team: Japanese <https://github.com/l/weechat/tree/master/"
"translation/ja_JP>\n"
Expand Down Expand Up @@ -4642,6 +4642,10 @@ msgstr "%sシグナル %d を pid %d に送信中にエラー: %s"
msgid "%sYou can not write text in this buffer"
msgstr "%sこのバッファに書き込むことは出来ません"

#, fuzzy, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr "%sコマンド \"/%s eval\" はまだ実装されていません"

#, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr "%sエラー: 未定義のコマンド \"%s\" (ヘルプを見るには /help を入力)"
Expand Down Expand Up @@ -13967,12 +13971,3 @@ msgstr "%s%s: \"%s\" のタイムアウト %s"
#, c-format
msgid "%s%s: unable to connect: unexpected error (%d)"
msgstr "%s%s: 接続できません: 未定義のエラー (%d)"

#~ msgid "a filter with same name already exists"
#~ msgstr "同名のフィルタが既に存在します"

#~ msgid "Aspell enabled"
#~ msgstr "Aspell が有効化されています"

#~ msgid "Aspell disabled"
#~ msgstr "Aspell が無効化されています"
17 changes: 6 additions & 11 deletions po/pl.po
Expand Up @@ -22,8 +22,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"PO-Revision-Date: 2019-02-09 21:00+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-02-28 20:19+0100\n"
"Last-Translator: Krzysztof Korościk <soltys@soltys.info>\n"
"Language-Team: Polish <kde-i18n-doc@kde.org>\n"
"Language: pl\n"
Expand Down Expand Up @@ -4750,6 +4750,10 @@ msgstr "%sBłąd wysyłania sygnału %d do pid %d: %s"
msgid "%sYou can not write text in this buffer"
msgstr "%s nie możesz nic pisać w tym buforze"

#, fuzzy, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr "%sKomenda \"/%s eval\" nie jest jeszcze zaimplementowana"

#, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr "%sBłąd: nieznana komenda \"%s\" (wpisz /help , aby uzyskać pomoc)"
Expand Down Expand Up @@ -14187,12 +14191,3 @@ msgstr "%s%s: przekroczono czas na \"%s\" z %s"
#, c-format
msgid "%s%s: unable to connect: unexpected error (%d)"
msgstr "%s%s: nie można połączyć: niespodziewany błąd (%d)"

#~ msgid "a filter with same name already exists"
#~ msgstr "filtr o tej nazwie już istnieje"

#~ msgid "Aspell enabled"
#~ msgstr "Aspell włączony"

#~ msgid "Aspell disabled"
#~ msgstr "Aspell wyłączony"
17 changes: 6 additions & 11 deletions po/pt.po
Expand Up @@ -20,8 +20,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"PO-Revision-Date: 2019-02-03 19:01+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-02-28 20:19+0100\n"
"Last-Translator: Vasco Almeida <vascomalmeida@sapo.pt>\n"
"Language-Team: Portuguese <>\n"
"Language: pt\n"
Expand Down Expand Up @@ -4690,6 +4690,10 @@ msgstr "%sErro ao enviar o sinal %d ao pid %d: %s"
msgid "%sYou can not write text in this buffer"
msgstr "%sNão pode escrever texto neste buffer"

#, fuzzy, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr "%sA cor \"%s\" não está definida na paleta"

#, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr "%sErro: comando desconhecido: \"%s\" (escreva /help para obter ajuda)"
Expand Down Expand Up @@ -13846,12 +13850,3 @@ msgstr "%s%s: tempo limite de \"%s\" com %s"
#, c-format
msgid "%s%s: unable to connect: unexpected error (%d)"
msgstr "%s%s: não foi possível conectar: erro inesperado (%d)"

#~ msgid "a filter with same name already exists"
#~ msgstr "já existe um filtro com o mesmo nome"

#~ msgid "Aspell enabled"
#~ msgstr "Aspell ativado"

#~ msgid "Aspell disabled"
#~ msgstr "Aspell desativado"
20 changes: 6 additions & 14 deletions po/pt_BR.po
Expand Up @@ -21,8 +21,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"PO-Revision-Date: 2019-01-29 21:05+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-02-28 20:19+0100\n"
"Last-Translator: Eduardo Elias <camponez@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: pt_BR\n"
Expand Down Expand Up @@ -4320,6 +4320,10 @@ msgstr ""
msgid "%sYou can not write text in this buffer"
msgstr ""

#, fuzzy, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr "%sCor \"%s\" não está definida na palheta"

#, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr ""
Expand Down Expand Up @@ -12418,15 +12422,3 @@ msgstr "%s%s: tempo esgotado para \"%s\" com %s"
#, fuzzy, c-format
msgid "%s%s: unable to connect: unexpected error (%d)"
msgstr "%s%s: não foi possível conectar ao remetente"

#, fuzzy
#~ msgid "a filter with same name already exists"
#~ msgstr "%sErro: um buffer com o mesmo nome (%s) já existe"

#, fuzzy
#~ msgid "Aspell enabled"
#~ msgstr "Mouse habilitado"

#, fuzzy
#~ msgid "Aspell disabled"
#~ msgstr "Mouse desabilitado"
21 changes: 6 additions & 15 deletions po/ru.po
Expand Up @@ -21,8 +21,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"PO-Revision-Date: 2018-11-17 10:36+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-02-28 20:19+0100\n"
"Last-Translator: Aleksey V Zapparov AKA ixti <ixti@member.fsf.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: ru\n"
Expand Down Expand Up @@ -3726,6 +3726,10 @@ msgstr ""
msgid "%sYou can not write text in this buffer"
msgstr "%s невозможно закрыть единственный буфер\n"

#, fuzzy, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr "%sЦвет \"%s\" не определён в палитре"

#, fuzzy, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr "%s сокращение или команда \"%s\" не найдены\n"
Expand Down Expand Up @@ -11982,16 +11986,3 @@ msgstr "%s нет аргумента для параметра \"%s\"\n"
#, fuzzy, c-format
msgid "%s%s: unable to connect: unexpected error (%d)"
msgstr "%s DCC: не могу соединиться с отправителем\n"

#, fuzzy
#~ msgid "a filter with same name already exists"
#~ msgstr ""
#~ "%s не могу загрузить plugin \"%s\": одноимённый plugin уже существует\n"

#, fuzzy
#~ msgid "Aspell enabled"
#~ msgstr "команда users отключена"

#, fuzzy
#~ msgid "Aspell disabled"
#~ msgstr "Сокращения не заданы.\n"
6 changes: 5 additions & 1 deletion po/tr.po
Expand Up @@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2019-01-29 21:05+0100\n"
"Last-Translator: Hasan Kiran <sunder67@hotmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
Expand Down Expand Up @@ -3353,6 +3353,10 @@ msgstr ""
msgid "%sYou can not write text in this buffer"
msgstr ""

#, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr ""

#, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr ""
Expand Down
6 changes: 5 additions & 1 deletion po/weechat.pot
Expand Up @@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2019-02-23 13:36+0100\n"
"POT-Creation-Date: 2019-02-28 20:16+0100\n"
"PO-Revision-Date: 2014-08-16 10:27+0200\n"
"Last-Translator: Sébastien Helleu <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
Expand Down Expand Up @@ -3343,6 +3343,10 @@ msgstr ""
msgid "%sYou can not write text in this buffer"
msgstr ""

#, c-format
msgid "debug: command \"%s\" is not allowed in this context"
msgstr ""

#, c-format
msgid "%sError: unknown command \"%s\" (type /help for help)"
msgstr ""
Expand Down
23 changes: 22 additions & 1 deletion src/core/wee-input.c
Expand Up @@ -39,6 +39,9 @@
#include "../plugins/plugin.h"


char **input_commands_allowed = NULL;


/*
* Sends data to buffer input callback.
*/
Expand Down Expand Up @@ -103,8 +106,25 @@ input_exec_command (struct t_gui_buffer *buffer,
return WEECHAT_RC_ERROR;
}

/* execute command */
rc = WEECHAT_RC_OK;

/* check if command is allowed */
if (input_commands_allowed
&& !string_match_list (command_name + 1,
(const char **)input_commands_allowed, 0))
{
if (weechat_debug_core >= 1)
{
gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
_("debug: command \"%s\" is not "
"allowed in this context"),
command_name);
}
rc = WEECHAT_RC_ERROR;
goto end;
}

/* execute command */
switch (hook_command_exec (buffer, any_plugin, plugin, command))
{
case HOOK_COMMAND_EXEC_OK:
Expand Down Expand Up @@ -171,6 +191,7 @@ input_exec_command (struct t_gui_buffer *buffer,
break;
}

end:
free (command);
free (command_name);

Expand Down
2 changes: 2 additions & 0 deletions src/core/wee-input.h
Expand Up @@ -23,6 +23,8 @@
struct t_gui_buffer;
struct t_weechat_plugin;

extern char **input_commands_allowed;

extern int input_exec_command (struct t_gui_buffer *buffer,
int any_plugin,
struct t_weechat_plugin *plugin,
Expand Down
29 changes: 29 additions & 0 deletions src/plugins/guile/weechat-guile-api.c
Expand Up @@ -4076,6 +4076,34 @@ weechat_guile_api_command (SCM buffer, SCM command)
API_RETURN_INT(rc);
}

SCM
weechat_guile_api_command_options (SCM buffer, SCM command, SCM options)
{
struct t_hashtable *c_options;
int rc;

API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
if (!scm_is_string (buffer) || !scm_is_string (command)
|| !scm_list_p (options))
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));

c_options = weechat_guile_alist_to_hashtable (options,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);

rc = plugin_script_api_command_options (weechat_guile_plugin,
guile_current_script,
API_STR2PTR(API_SCM_TO_STRING(buffer)),
API_SCM_TO_STRING(command),
c_options);

if (c_options)
weechat_hashtable_free (c_options);

API_RETURN_INT(rc);
}

SCM
weechat_guile_api_info_get (SCM info_name, SCM arguments)
{
Expand Down Expand Up @@ -5016,6 +5044,7 @@ weechat_guile_api_module_init (void *data)
API_DEF_FUNC(bar_update, 1);
API_DEF_FUNC(bar_remove, 1);
API_DEF_FUNC(command, 2);
API_DEF_FUNC(command_options, 3);
API_DEF_FUNC(info_get, 2);
API_DEF_FUNC(info_get_hashtable, 2);
API_DEF_FUNC(infolist_new, 0);
Expand Down
28 changes: 28 additions & 0 deletions src/plugins/javascript/weechat-js-api.cpp
Expand Up @@ -3976,6 +3976,33 @@ API_FUNC(command)
API_RETURN_INT(rc);
}

API_FUNC(command_options)
{
struct t_hashtable *options;
int rc;

API_INIT_FUNC(1, "command_options", "ssh", API_RETURN_INT(WEECHAT_RC_ERROR));

v8::String::Utf8Value buffer(args[0]);
v8::String::Utf8Value command(args[1]);
options = weechat_js_object_to_hashtable (
args[2]->ToObject(),
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);

rc = plugin_script_api_command_options (weechat_js_plugin,
js_current_script,
(struct t_gui_buffer *)API_STR2PTR(*buffer),
*command,
options);

if (options)
weechat_hashtable_free (options);

API_RETURN_INT(rc);
}

API_FUNC(info_get)
{
const char *result;
Expand Down Expand Up @@ -4967,6 +4994,7 @@ WeechatJsV8::loadLibs()
API_DEF_FUNC(bar_update);
API_DEF_FUNC(bar_remove);
API_DEF_FUNC(command);
API_DEF_FUNC(command_options);
API_DEF_FUNC(info_get);
API_DEF_FUNC(info_get_hashtable);
API_DEF_FUNC(infolist_new);
Expand Down
30 changes: 30 additions & 0 deletions src/plugins/lua/weechat-lua-api.c
Expand Up @@ -4312,6 +4312,35 @@ API_FUNC(command)
API_RETURN_INT(rc);
}

API_FUNC(command_options)
{
const char *buffer, *command;
struct t_hashtable *options;
int rc;

API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
if (lua_gettop (L) < 3)
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));

buffer = lua_tostring (L, -3);
command = lua_tostring (L, -2);
options = weechat_lua_tohashtable (L, -1,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);

rc = plugin_script_api_command_options (weechat_lua_plugin,
lua_current_script,
API_STR2PTR(buffer),
command,
options);

if (options)
weechat_hashtable_free (options);

API_RETURN_INT(rc);
}

API_FUNC(info_get)
{
const char *info_name, *arguments, *result;
Expand Down Expand Up @@ -5318,6 +5347,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(bar_update),
API_DEF_FUNC(bar_remove),
API_DEF_FUNC(command),
API_DEF_FUNC(command_options),
API_DEF_FUNC(info_get),
API_DEF_FUNC(info_get_hashtable),
API_DEF_FUNC(infolist_new),
Expand Down
30 changes: 30 additions & 0 deletions src/plugins/perl/weechat-perl-api.c
Expand Up @@ -4233,6 +4233,35 @@ API_FUNC(command)
API_RETURN_INT(rc);
}

API_FUNC(command_options)
{
char *buffer, *command;
struct t_hashtable *options;
int rc;
dXSARGS;

API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
if (items < 3)
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));

buffer = SvPV_nolen (ST (0));
command = SvPV_nolen (ST (1));
options = weechat_perl_hash_to_hashtable (ST (2),
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);

rc = plugin_script_api_command_options (weechat_perl_plugin,
perl_current_script,
API_STR2PTR(buffer),
command,
options);
if (options)
weechat_hashtable_free (options);

API_RETURN_INT(rc);
}

API_FUNC(info_get)
{
char *info_name, *arguments;
Expand Down Expand Up @@ -5277,6 +5306,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(bar_update);
API_DEF_FUNC(bar_remove);
API_DEF_FUNC(command);
API_DEF_FUNC(command_options);
API_DEF_FUNC(info_get);
API_DEF_FUNC(info_get_hashtable);
API_DEF_FUNC(infolist_new);
Expand Down
34 changes: 34 additions & 0 deletions src/plugins/php/weechat-php-api.c
Expand Up @@ -4144,6 +4144,40 @@ API_FUNC(command)
API_RETURN_INT(result);
}

API_FUNC(command_options)
{
zend_string *z_buffer, *z_command;
zval *z_options;
struct t_gui_buffer *buffer;
char *command;
struct t_hashtable *options;
int result;

API_INIT_FUNC(1, "command", API_RETURN_INT(WEECHAT_RC_ERROR));
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSa", &z_buffer,
&z_command, &z_options) == FAILURE)
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));

buffer = (struct t_gui_buffer *)API_STR2PTR(ZSTR_VAL(z_buffer));
command = ZSTR_VAL(z_command);
options = weechat_php_array_to_hashtable (
z_options,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);

result = plugin_script_api_command_options (weechat_php_plugin,
php_current_script,
buffer,
(const char *)command,
options);

if (options)
weechat_hashtable_free (options);

API_RETURN_INT(result);
}

API_FUNC(info_get)
{
zend_string *z_info_name, *z_arguments;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/php/weechat-php-api.h
Expand Up @@ -197,6 +197,7 @@ PHP_FUNCTION(weechat_bar_set);
PHP_FUNCTION(weechat_bar_update);
PHP_FUNCTION(weechat_bar_remove);
PHP_FUNCTION(weechat_command);
PHP_FUNCTION(weechat_command_options);
PHP_FUNCTION(weechat_info_get);
PHP_FUNCTION(weechat_info_get_hashtable);
PHP_FUNCTION(weechat_infolist_new);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/php/weechat-php.c
Expand Up @@ -251,6 +251,7 @@ const zend_function_entry weechat_functions[] = {
PHP_FE(weechat_bar_update, NULL)
PHP_FE(weechat_bar_remove, NULL)
PHP_FE(weechat_command, NULL)
PHP_FE(weechat_command_options, NULL)
PHP_FE(weechat_info_get, NULL)
PHP_FE(weechat_info_get_hashtable, NULL)
PHP_FE(weechat_infolist_new, NULL)
Expand Down
40 changes: 36 additions & 4 deletions src/plugins/plugin-api.c
Expand Up @@ -28,6 +28,7 @@

#include "../core/weechat.h"
#include "../core/wee-config.h"
#include "../core/wee-hashtable.h"
#include "../core/wee-hook.h"
#include "../core/wee-infolist.h"
#include "../core/wee-input.h"
Expand Down Expand Up @@ -294,29 +295,60 @@ plugin_api_color (const char *color_name)
}

/*
* Executes a command on a buffer (simulates user entry).
* Executes a command on a buffer (simulates user entry) with options.
*/

int
plugin_api_command (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command)
plugin_api_command_options (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command,
struct t_hashtable *options)
{
char *command2;
char *command2, **old_commands_allowed, **new_commands_allowed;
const char *ptr_commands;
int rc;

if (!plugin || !command)
return WEECHAT_RC_ERROR;

old_commands_allowed = input_commands_allowed;
new_commands_allowed = NULL;

if (options)
{
ptr_commands = hashtable_get (options, "commands");
if (ptr_commands)
{
new_commands_allowed = string_split (ptr_commands, ",", 0, 0,
NULL);
input_commands_allowed = new_commands_allowed;
}
}

command2 = string_iconv_to_internal (plugin->charset, command);
if (!buffer)
buffer = gui_current_window->buffer;
rc = input_data (buffer, (command2) ? command2 : command);
if (command2)
free (command2);

if (new_commands_allowed)
string_free_split (new_commands_allowed);
input_commands_allowed = old_commands_allowed;

return rc;
}

/*
* Executes a command on a buffer (simulates user entry).
*/

int
plugin_api_command (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command)
{
return plugin_api_command_options (plugin, buffer, command, NULL);
}

/*
* Modifier to decode ANSI colors.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/plugin-api.h
Expand Up @@ -54,6 +54,10 @@ extern const char *plugin_api_prefix (const char *prefix);
extern const char *plugin_api_color (const char *color_name);

/* command */
extern int plugin_api_command_options (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer,
const char *command,
struct t_hashtable *options);
extern int plugin_api_command (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer,
const char *command);
Expand Down
27 changes: 22 additions & 5 deletions src/plugins/plugin-script-api.c
Expand Up @@ -1279,28 +1279,45 @@ plugin_script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin,
}

/*
* Executes a command on a buffer (simulates user entry).
* Executes a command on a buffer (simulates user entry) with options.
*/

int
plugin_script_api_command (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer, const char *command)
plugin_script_api_command_options (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
const char *command,
struct t_hashtable *options)
{
char *command2;
int rc;

command2 = (script && script->charset && script->charset[0]) ?
weechat_iconv_to_internal (script->charset, command) : NULL;

rc = weechat_command (buffer, (command2) ? command2 : command);
rc = weechat_command_options (buffer,
(command2) ? command2 : command,
options);

if (command2)
free (command2);

return rc;
}

/*
* Executes a command on a buffer (simulates user entry).
*/

int
plugin_script_api_command (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer, const char *command)
{
return plugin_script_api_command_options (weechat_plugin, script, buffer,
command, NULL);
}

/*
* Gets value of a script option (format in file is "plugin.script.option").
*/
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/plugin-script-api.h
Expand Up @@ -353,6 +353,11 @@ extern struct t_gui_bar_item *plugin_script_api_bar_item_new (struct t_weechat_p
struct t_hashtable *extra_info),
const char *function,
const char *data);
extern int plugin_script_api_command_options (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
const char *command,
struct t_hashtable *options);
extern int plugin_script_api_command (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
Expand Down
1 change: 1 addition & 0 deletions src/plugins/plugin.c
Expand Up @@ -828,6 +828,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->bar_remove = &gui_bar_free;

new_plugin->command = &plugin_api_command;
new_plugin->command_options = &plugin_api_command_options;

new_plugin->network_pass_proxy = &network_pass_proxy;
new_plugin->network_connect_to = &network_connect_to;
Expand Down
30 changes: 30 additions & 0 deletions src/plugins/python/weechat-python-api.c
Expand Up @@ -4247,6 +4247,35 @@ API_FUNC(command)
API_RETURN_INT(rc);
}

API_FUNC(command_options)
{
char *buffer, *command;
struct t_hashtable *options;
int rc;
PyObject *dict;

API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
buffer = NULL;
command = NULL;
options = NULL;
if (!PyArg_ParseTuple (args, "ssO", &buffer, &command, &dict))
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));

options = weechat_python_dict_to_hashtable (dict,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
rc = plugin_script_api_command_options (weechat_python_plugin,
python_current_script,
API_STR2PTR(buffer),
command,
options);
if (options)
weechat_hashtable_free (options);

API_RETURN_INT(rc);
}

API_FUNC(info_get)
{
char *info_name, *arguments;
Expand Down Expand Up @@ -5227,6 +5256,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(bar_update),
API_DEF_FUNC(bar_remove),
API_DEF_FUNC(command),
API_DEF_FUNC(command_options),
API_DEF_FUNC(info_get),
API_DEF_FUNC(info_get_hashtable),
API_DEF_FUNC(infolist_new),
Expand Down
36 changes: 36 additions & 0 deletions src/plugins/ruby/weechat-ruby-api.c
Expand Up @@ -5118,6 +5118,41 @@ weechat_ruby_api_command (VALUE class, VALUE buffer, VALUE command)
API_RETURN_INT(rc);
}

static VALUE
weechat_ruby_api_command_options (VALUE class, VALUE buffer, VALUE command,
VALUE options)
{
char *c_buffer, *c_command;
struct t_hashtable *c_options;
int rc;

API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
if (NIL_P (buffer) || NIL_P (command) || NIL_P (options))
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));

Check_Type (buffer, T_STRING);
Check_Type (command, T_STRING);
Check_Type (options, T_HASH);

c_buffer = StringValuePtr (buffer);
c_command = StringValuePtr (command);
c_options = weechat_ruby_hash_to_hashtable (options,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);

rc = plugin_script_api_command_options (weechat_ruby_plugin,
ruby_current_script,
API_STR2PTR(c_buffer),
c_command,
c_options);

if (c_options)
weechat_hashtable_free (c_options);

API_RETURN_INT(rc);
}

static VALUE
weechat_ruby_api_info_get (VALUE class, VALUE info_name, VALUE arguments)
{
Expand Down Expand Up @@ -6388,6 +6423,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(bar_update, 1);
API_DEF_FUNC(bar_remove, 1);
API_DEF_FUNC(command, 2);
API_DEF_FUNC(command_options, 3);
API_DEF_FUNC(info_get, 2);
API_DEF_FUNC(info_get_hashtable, 2);
API_DEF_FUNC(infolist_new, 0);
Expand Down
31 changes: 31 additions & 0 deletions src/plugins/tcl/weechat-tcl-api.c
Expand Up @@ -4598,6 +4598,36 @@ API_FUNC(command)
API_RETURN_INT(rc);
}

API_FUNC(command_options)
{
Tcl_Obj *objp;
char *buffer, *command;
struct t_hashtable *options;
int i, rc;

API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
if (objc < 4)
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));

buffer = Tcl_GetStringFromObj (objv[1], &i);
command = Tcl_GetStringFromObj (objv[2], &i);
options = weechat_tcl_dict_to_hashtable (interp, objv[3],
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);

rc = plugin_script_api_command_options (weechat_tcl_plugin,
tcl_current_script,
API_STR2PTR(buffer),
command,
options);

if (options)
weechat_hashtable_free (options);

API_RETURN_INT(rc);
}

API_FUNC(info_get)
{
Tcl_Obj *objp;
Expand Down Expand Up @@ -5753,6 +5783,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(bar_update);
API_DEF_FUNC(bar_remove);
API_DEF_FUNC(command);
API_DEF_FUNC(command_options);
API_DEF_FUNC(info_get);
API_DEF_FUNC(info_get_hashtable);
API_DEF_FUNC(infolist_new);
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/weechat-plugin.h
Expand Up @@ -67,7 +67,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
#define WEECHAT_PLUGIN_API_VERSION "20190226-01"
#define WEECHAT_PLUGIN_API_VERSION "20190228-01"

/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
Expand Down Expand Up @@ -985,6 +985,9 @@ struct t_weechat_plugin
/* command */
int (*command) (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command);
int (*command_options) (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command,
struct t_hashtable *options);

/* network */
int (*network_pass_proxy) (const char *proxy, int sock,
Expand Down Expand Up @@ -1899,6 +1902,9 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
/* command */
#define weechat_command(__buffer, __command) \
(weechat_plugin->command)(weechat_plugin, __buffer, __command)
#define weechat_command_options(__buffer, __command, __options) \
(weechat_plugin->command_options)(weechat_plugin, __buffer, \
__command, __options)

/* network */
#define weechat_network_pass_proxy(__proxy, __sock, __address, __port) \
Expand Down
8 changes: 8 additions & 0 deletions tests/scripts/python/testapi.py
Expand Up @@ -200,6 +200,13 @@ def test_hooks():
weechat.unhook(hook_cmplt)


def test_command():
"""Test command functions."""
check(weechat.command('', '/mute') == 0)
check(weechat.command_options('', '/mute', {'commands': '*,!print'}) == 0)
check(weechat.command_options('', '/mute', {'commands': '*,!mute'}) == -1)


def infolist_cb(data, infolist_name, pointer, arguments):
"""Infolist callback."""
infolist = weechat.infolist_new()
Expand Down Expand Up @@ -244,6 +251,7 @@ def cmd_test_cb(data, buf, args):
test_key()
test_display()
test_hooks()
test_command()
test_infolist()
weechat.prnt('', ' > TESTS END')
return weechat.WEECHAT_RC_OK
Expand Down