mirror of
https://github.com/weechat/weechat.git
synced 2026-06-26 12:56:37 +02:00
- Added options for /plugin command: autoload, reload, unload
- Added new plugin functions, for C plugins and scripts: set_config, get_plugin_config, set_plugin_config - Added new script function: remove_handler
This commit is contained in:
@@ -139,7 +139,6 @@ static XS (XS_weechat_register)
|
||||
"Perl error: wrong parameters for "
|
||||
"\"register\" function");
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
@@ -156,7 +155,6 @@ static XS (XS_weechat_register)
|
||||
"already exists with this name)",
|
||||
name);
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* register script */
|
||||
@@ -179,8 +177,8 @@ static XS (XS_weechat_register)
|
||||
"\"%s\" (not enough memory)",
|
||||
name);
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
@@ -197,13 +195,20 @@ static XS (XS_weechat_print)
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to print message, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"print\" function");
|
||||
XSRETURN_NO;
|
||||
return;
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
channel_name = NULL;
|
||||
@@ -220,7 +225,8 @@ static XS (XS_weechat_print)
|
||||
perl_plugin->printf (perl_plugin,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
XSRETURN_YES;
|
||||
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -235,18 +241,27 @@ static XS (XS_weechat_print_infobar)
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to print infobar message, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"print_infobar\" function");
|
||||
XSRETURN_NO;
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
perl_plugin->infobar_printf (perl_plugin,
|
||||
SvIV (ST (0)),
|
||||
SvPV (ST (1), integer));
|
||||
XSRETURN_YES;
|
||||
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -262,13 +277,20 @@ static XS (XS_weechat_command)
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to run command, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"command\" function");
|
||||
XSRETURN_NO;
|
||||
return;
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
channel_name = NULL;
|
||||
@@ -284,7 +306,8 @@ static XS (XS_weechat_command)
|
||||
perl_plugin->exec_command (perl_plugin,
|
||||
server_name, channel_name,
|
||||
SvPV (ST (0), integer));
|
||||
XSRETURN_YES;
|
||||
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -293,37 +316,38 @@ static XS (XS_weechat_command)
|
||||
|
||||
static XS (XS_weechat_add_message_handler)
|
||||
{
|
||||
char *name, *function;
|
||||
char *irc_command, *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to add message handler, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"add_message_handler\" function");
|
||||
XSRETURN_NO;
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
irc_command = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
|
||||
if (perl_current_script)
|
||||
perl_plugin->msg_handler_add (perl_plugin, name,
|
||||
weechat_perl_handler, function,
|
||||
(void *)perl_current_script);
|
||||
else
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to add message handler, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
if (perl_plugin->msg_handler_add (perl_plugin, irc_command,
|
||||
weechat_perl_handler, function,
|
||||
(void *)perl_current_script))
|
||||
XSRETURN (1);
|
||||
|
||||
XSRETURN_YES;
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -339,12 +363,20 @@ static XS (XS_weechat_add_command_handler)
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to add command handler, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
if (items < 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"add_command_handler\" function");
|
||||
XSRETURN_NO;
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
command = SvPV (ST (0), integer);
|
||||
@@ -353,24 +385,55 @@ static XS (XS_weechat_add_command_handler)
|
||||
arguments = (items >= 4) ? SvPV (ST (3), integer) : NULL;
|
||||
arguments_description = (items >= 5) ? SvPV (ST (4), integer) : NULL;
|
||||
|
||||
if (perl_current_script)
|
||||
perl_plugin->cmd_handler_add (perl_plugin,
|
||||
command,
|
||||
description,
|
||||
arguments,
|
||||
arguments_description,
|
||||
weechat_perl_handler,
|
||||
function,
|
||||
(void *)perl_current_script);
|
||||
else
|
||||
if (perl_plugin->cmd_handler_add (perl_plugin,
|
||||
command,
|
||||
description,
|
||||
arguments,
|
||||
arguments_description,
|
||||
weechat_perl_handler,
|
||||
function,
|
||||
(void *)perl_current_script))
|
||||
XSRETURN (1);
|
||||
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::remove_handler: remove a handler
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_remove_handler)
|
||||
{
|
||||
char *command, *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to add command handler, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
"Perl error: unable to remove handler, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
XSRETURN_YES;
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"remove_handler\" function");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
command = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
|
||||
weechat_script_remove_handler (perl_plugin, perl_current_script,
|
||||
command, function);
|
||||
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -386,12 +449,20 @@ static XS (XS_weechat_get_info)
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to get info, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
if ((items < 1) || (items > 3))
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_info\" function");
|
||||
XSRETURN_NO;
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
server_name = NULL;
|
||||
@@ -411,12 +482,11 @@ static XS (XS_weechat_get_info)
|
||||
{
|
||||
XST_mPV (0, info);
|
||||
free (info);
|
||||
return;
|
||||
}
|
||||
else
|
||||
XST_mPV (0, "");
|
||||
}
|
||||
|
||||
XSRETURN (1);
|
||||
XST_mPV (0, "");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -433,14 +503,19 @@ static XS (XS_weechat_get_dcc_info)
|
||||
(void) cv;
|
||||
(void) items;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to get DCC info, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
dcc_info = perl_plugin->get_dcc_info (perl_plugin);
|
||||
dcc_count = 0;
|
||||
|
||||
if (!dcc_info)
|
||||
{
|
||||
XSRETURN (0);
|
||||
return;
|
||||
}
|
||||
|
||||
for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
|
||||
{
|
||||
@@ -473,10 +548,56 @@ static XS (XS_weechat_get_dcc_info)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_config: get value of a config option
|
||||
* weechat::get_config: get value of a WeeChat config option
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_config)
|
||||
{
|
||||
char *option, *return_value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to get config option, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
if (items != 1)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_config\" function");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
|
||||
if (option)
|
||||
{
|
||||
return_value = perl_plugin->get_config (perl_plugin, option);
|
||||
|
||||
if (return_value)
|
||||
{
|
||||
XST_mPV (0, return_value);
|
||||
free (return_value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
XST_mPV (0, "");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::set_config: set value of a WeeChat config option
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_set_config)
|
||||
{
|
||||
char *option, *value;
|
||||
unsigned int integer;
|
||||
@@ -485,29 +606,123 @@ static XS (XS_weechat_get_config)
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to set config option, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
if (items != 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"set_config\" function");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
value = SvPV (ST (1), integer);
|
||||
|
||||
if (option && value)
|
||||
{
|
||||
if (perl_plugin->set_config (perl_plugin, option, value))
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_plugin_config: get value of a plugin config option
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_plugin_config)
|
||||
{
|
||||
char *option, *return_value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to get plugin config option, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
if (items != 1)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_config\" function");
|
||||
XSRETURN_NO;
|
||||
"\"get_plugin_config\" function");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
|
||||
if (option)
|
||||
{
|
||||
value = perl_plugin->get_config (perl_plugin, option);
|
||||
return_value = weechat_script_get_plugin_config (perl_plugin,
|
||||
perl_current_script,
|
||||
option);
|
||||
|
||||
if (value)
|
||||
if (return_value)
|
||||
{
|
||||
XST_mPV (0, value);
|
||||
free (value);
|
||||
XST_mPV (0, return_value);
|
||||
free (return_value);
|
||||
return;
|
||||
}
|
||||
else
|
||||
XST_mPV (0, "");
|
||||
}
|
||||
|
||||
XST_mPV (0, "");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::set_plugin_config: set value of a WeeChat config option
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_set_plugin_config)
|
||||
{
|
||||
char *option, *value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: unable to set plugin config option, "
|
||||
"script not initialized");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
XSRETURN (1);
|
||||
if (items != 2)
|
||||
{
|
||||
perl_plugin->printf_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"set_plugin_config\" function");
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
value = SvPV (ST (1), integer);
|
||||
|
||||
if (option && value)
|
||||
{
|
||||
if (weechat_script_set_plugin_config (perl_plugin,
|
||||
perl_current_script,
|
||||
option, value))
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
XSRETURN (0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -525,13 +740,17 @@ weechat_perl_xs_init (pTHX)
|
||||
newXS ("weechat::command", XS_weechat_command, "weechat");
|
||||
newXS ("weechat::add_message_handler", XS_weechat_add_message_handler, "weechat");
|
||||
newXS ("weechat::add_command_handler", XS_weechat_add_command_handler, "weechat");
|
||||
newXS ("weechat::remove_handler", XS_weechat_remove_handler, "weechat");
|
||||
newXS ("weechat::get_info", XS_weechat_get_info, "weechat");
|
||||
newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat");
|
||||
newXS ("weechat::get_config", XS_weechat_get_config, "weechat");
|
||||
newXS ("weechat::set_config", XS_weechat_set_config, "weechat");
|
||||
newXS ("weechat::get_plugin_config", XS_weechat_get_plugin_config, "weechat");
|
||||
newXS ("weechat::set_plugin_config", XS_weechat_set_plugin_config, "weechat");
|
||||
}
|
||||
|
||||
/*
|
||||
* wee_perl_load: load a Perl script
|
||||
* weechat_perl_load: load a Perl script
|
||||
*/
|
||||
|
||||
int
|
||||
@@ -689,9 +908,8 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
|
||||
{
|
||||
int argc, path_length, handler_found;
|
||||
char **argv, *path_script, *dir_home;
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_msg_handler *ptr_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
t_plugin_script *ptr_script;
|
||||
t_plugin_handler *ptr_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
@@ -715,14 +933,14 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
|
||||
plugin->printf_server (plugin, "Registered Perl scripts:");
|
||||
if (perl_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = perl_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
for (ptr_script = perl_scripts;
|
||||
ptr_script; ptr_script = ptr_script->next_script)
|
||||
{
|
||||
plugin->printf_server (plugin, " %s v%s%s%s",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
ptr_script->name,
|
||||
ptr_script->version,
|
||||
(ptr_script->description[0]) ? " - " : "",
|
||||
ptr_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -732,15 +950,16 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Perl message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_msg_handler = plugin->msg_handlers; ptr_msg_handler;
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler)
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if (ptr_msg_handler->msg_handler_args)
|
||||
if ((ptr_handler->type == HANDLER_MESSAGE)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " IRC(%s) => Perl(%s)",
|
||||
ptr_msg_handler->irc_command,
|
||||
ptr_msg_handler->msg_handler_args);
|
||||
ptr_handler->irc_command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
@@ -750,15 +969,16 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Perl command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_cmd_handler = plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if (ptr_cmd_handler->cmd_handler_args)
|
||||
if ((ptr_handler->type == HANDLER_COMMAND)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " /%s => Perl(%s)",
|
||||
ptr_cmd_handler->command,
|
||||
ptr_cmd_handler->cmd_handler_args);
|
||||
ptr_handler->command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
|
||||
@@ -118,7 +118,7 @@ weechat_python_register (PyObject *self, PyObject *args)
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"register\" function");
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
if (weechat_script_search (python_plugin, &python_scripts, name))
|
||||
@@ -129,7 +129,7 @@ weechat_python_register (PyObject *self, PyObject *args)
|
||||
"\"%s\" script (another script "
|
||||
"already exists with this name)",
|
||||
name);
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
/* register script */
|
||||
@@ -152,11 +152,10 @@ weechat_python_register (PyObject *self, PyObject *args)
|
||||
"Python error: unable to load script "
|
||||
"\"%s\" (not enough memory)",
|
||||
name);
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -171,6 +170,14 @@ weechat_python_print (PyObject *self, PyObject *args)
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to print message, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
message = NULL;
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
@@ -180,12 +187,13 @@ weechat_python_print (PyObject *self, PyObject *args)
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"print\" function");
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
python_plugin->printf (python_plugin,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
@@ -202,6 +210,14 @@ weechat_python_print_infobar (PyObject *self, PyObject *args)
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to print infobar message, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
delay = 1;
|
||||
message = NULL;
|
||||
|
||||
@@ -210,13 +226,12 @@ weechat_python_print_infobar (PyObject *self, PyObject *args)
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"print_infobar\" function");
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
python_plugin->infobar_printf (python_plugin, delay, message);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -231,6 +246,14 @@ weechat_python_command (PyObject *self, PyObject *args)
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to run command, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
command = NULL;
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
@@ -240,12 +263,13 @@ weechat_python_command (PyObject *self, PyObject *args)
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"command\" function");
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
python_plugin->exec_command (python_plugin,
|
||||
server_name, channel_name,
|
||||
command);
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
@@ -256,36 +280,36 @@ weechat_python_command (PyObject *self, PyObject *args)
|
||||
static PyObject *
|
||||
weechat_python_add_message_handler (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *message, *function;
|
||||
char *irc_command, *function;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
message = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &message, &function))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"add_message_handler\" function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (python_current_script)
|
||||
python_plugin->msg_handler_add (python_plugin, message,
|
||||
weechat_python_handler, function,
|
||||
(void *)python_current_script);
|
||||
else
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to add message handler, "
|
||||
"script not initialized");
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
irc_command = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &irc_command, &function))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"add_message_handler\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
if (python_plugin->msg_handler_add (python_plugin, irc_command,
|
||||
weechat_python_handler, function,
|
||||
(void *)python_current_script))
|
||||
return Py_BuildValue ("i", 1);
|
||||
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -299,7 +323,15 @@ weechat_python_add_command_handler (PyObject *self, PyObject *args)
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to add command handler, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
command = NULL;
|
||||
function = NULL;
|
||||
description = NULL;
|
||||
@@ -312,28 +344,57 @@ weechat_python_add_command_handler (PyObject *self, PyObject *args)
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"add_command_handler\" function");
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
if (python_current_script)
|
||||
python_plugin->cmd_handler_add (python_plugin,
|
||||
if (python_plugin->cmd_handler_add (python_plugin,
|
||||
command,
|
||||
description,
|
||||
arguments,
|
||||
arguments_description,
|
||||
weechat_python_handler,
|
||||
function,
|
||||
(void *)python_current_script);
|
||||
else
|
||||
(void *)python_current_script))
|
||||
return Py_BuildValue ("i", 1);
|
||||
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.remove_handler: remove a handler
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_remove_handler (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *command, *function;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to add command handler, "
|
||||
"Python error: unable to remove handler, "
|
||||
"script not initialized");
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
command = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &command, &function))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"remove_handler\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
weechat_script_remove_handler (python_plugin, python_current_script,
|
||||
command, function);
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -349,6 +410,14 @@ weechat_python_get_info (PyObject *self, PyObject *args)
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to get info, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
arg = NULL;
|
||||
server_name = NULL;
|
||||
channel_name = NULL;
|
||||
@@ -358,7 +427,7 @@ weechat_python_get_info (PyObject *self, PyObject *args)
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_info\" function");
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
if (arg)
|
||||
@@ -371,11 +440,9 @@ weechat_python_get_info (PyObject *self, PyObject *args)
|
||||
free (info);
|
||||
return object;
|
||||
}
|
||||
else
|
||||
return Py_BuildValue ("s", "");
|
||||
}
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
return Py_BuildValue ("s", "");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -393,11 +460,19 @@ weechat_python_get_dcc_info (PyObject *self, PyObject *args)
|
||||
(void) self;
|
||||
(void) args;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to get DCC info, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
dcc_info = python_plugin->get_dcc_info (python_plugin);
|
||||
dcc_count = 0;
|
||||
|
||||
if (!dcc_info)
|
||||
return Py_None;
|
||||
return Py_BuildValue ("i", 0);
|
||||
|
||||
for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
|
||||
{
|
||||
@@ -409,7 +484,7 @@ weechat_python_get_dcc_info (PyObject *self, PyObject *args)
|
||||
if (!list)
|
||||
{
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
dcc_count = 0;
|
||||
@@ -440,14 +515,14 @@ weechat_python_get_dcc_info (PyObject *self, PyObject *args)
|
||||
PyMem_Free (listvalue);
|
||||
PyMem_Free (list);
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
PyMem_Free (listvalue);
|
||||
}
|
||||
else
|
||||
{
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
dcc_count++;
|
||||
}
|
||||
@@ -458,18 +533,26 @@ weechat_python_get_dcc_info (PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.get_config: get value of a config option
|
||||
* weechat.get_config: get value of a WeeChat config option
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_config (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *option, *value;
|
||||
PyObject *object;
|
||||
char *option, *return_value;
|
||||
PyObject *python_return_value;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to get config option, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
option = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &option))
|
||||
@@ -477,26 +560,150 @@ weechat_python_get_config (PyObject *self, PyObject *args)
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_config\" function");
|
||||
return NULL;
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
if (option)
|
||||
{
|
||||
value = python_plugin->get_config (python_plugin, option);
|
||||
return_value = python_plugin->get_config (python_plugin, option);
|
||||
|
||||
if (value)
|
||||
if (return_value)
|
||||
{
|
||||
object = Py_BuildValue ("s", value);
|
||||
free (value);
|
||||
return object;
|
||||
python_return_value = Py_BuildValue ("s", return_value);
|
||||
free (return_value);
|
||||
return python_return_value;
|
||||
}
|
||||
else
|
||||
return Py_BuildValue ("s", "");
|
||||
}
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
return Py_BuildValue ("s", "");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.set_config: set value of a WeeChat config option
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_set_config (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *option, *value;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to set config option, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
option = NULL;
|
||||
value = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &option, &value))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"set_config\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
if (option && value)
|
||||
{
|
||||
if (python_plugin->set_config (python_plugin, option, value))
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.get_plugin_config: get value of a plugin config option
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_plugin_config (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *option, *return_value;
|
||||
PyObject *python_return_value;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to get plugin config option, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
option = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &option))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_plugin_config\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
if (option)
|
||||
{
|
||||
return_value = python_plugin->get_config (python_plugin, option);
|
||||
|
||||
if (return_value)
|
||||
{
|
||||
python_return_value = Py_BuildValue ("s", return_value);
|
||||
free (return_value);
|
||||
return python_return_value;
|
||||
}
|
||||
}
|
||||
|
||||
return Py_BuildValue ("s", "");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat.set_plugin_config: set value of a plugin config option
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_set_plugin_config (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *option, *value;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to set plugin config option, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
option = NULL;
|
||||
value = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &option, &value))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"set_plugin_config\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
if (option && value)
|
||||
{
|
||||
if (python_plugin->set_config (python_plugin, option, value))
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Python subroutines
|
||||
*/
|
||||
@@ -509,9 +716,13 @@ PyMethodDef weechat_python_funcs[] = {
|
||||
{ "command", weechat_python_command, METH_VARARGS, "" },
|
||||
{ "add_message_handler", weechat_python_add_message_handler, METH_VARARGS, "" },
|
||||
{ "add_command_handler", weechat_python_add_command_handler, METH_VARARGS, "" },
|
||||
{ "remove_handler", weechat_python_remove_handler, METH_VARARGS, "" },
|
||||
{ "get_info", weechat_python_get_info, METH_VARARGS, "" },
|
||||
{ "get_dcc_info", weechat_python_get_dcc_info, METH_VARARGS, "" },
|
||||
{ "get_config", weechat_python_get_config, METH_VARARGS, "" },
|
||||
{ "set_config", weechat_python_set_config, METH_VARARGS, "" },
|
||||
{ "get_plugin_config", weechat_python_get_plugin_config, METH_VARARGS, "" },
|
||||
{ "set_plugin_config", weechat_python_set_plugin_config, METH_VARARGS, "" },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
@@ -738,9 +949,8 @@ weechat_python_cmd (t_weechat_plugin *plugin,
|
||||
{
|
||||
int argc, path_length, handler_found;
|
||||
char **argv, *path_script, *dir_home;
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_msg_handler *ptr_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
t_plugin_script *ptr_script;
|
||||
t_plugin_handler *ptr_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
@@ -764,14 +974,14 @@ weechat_python_cmd (t_weechat_plugin *plugin,
|
||||
plugin->printf_server (plugin, "Registered Python scripts:");
|
||||
if (python_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = python_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
for (ptr_script = python_scripts;
|
||||
ptr_script; ptr_script = ptr_script->next_script)
|
||||
{
|
||||
plugin->printf_server (plugin, " %s v%s%s%s",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
ptr_script->name,
|
||||
ptr_script->version,
|
||||
(ptr_script->description[0]) ? " - " : "",
|
||||
ptr_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -781,15 +991,16 @@ weechat_python_cmd (t_weechat_plugin *plugin,
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Python message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_msg_handler = plugin->msg_handlers; ptr_msg_handler;
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler)
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if (ptr_msg_handler->msg_handler_args)
|
||||
if ((ptr_handler->type == HANDLER_MESSAGE)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " IRC(%s) => Python(%s)",
|
||||
ptr_msg_handler->irc_command,
|
||||
ptr_msg_handler->msg_handler_args);
|
||||
ptr_handler->irc_command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
@@ -799,15 +1010,16 @@ weechat_python_cmd (t_weechat_plugin *plugin,
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Python command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_cmd_handler = plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if (ptr_cmd_handler->cmd_handler_args)
|
||||
if ((ptr_handler->type == HANDLER_COMMAND)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " /%s => Python(%s)",
|
||||
ptr_cmd_handler->command,
|
||||
ptr_cmd_handler->cmd_handler_args);
|
||||
ptr_handler->command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
|
||||
@@ -95,7 +95,7 @@ weechat_ruby_register (VALUE class, VALUE name, VALUE version,
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"register\" function");
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (name, T_STRING);
|
||||
@@ -116,7 +116,7 @@ weechat_ruby_register (VALUE class, VALUE name, VALUE version,
|
||||
"\"%s\" script (another script "
|
||||
"already exists with this name)",
|
||||
c_name);
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/* register script */
|
||||
@@ -139,7 +139,7 @@ weechat_ruby_register (VALUE class, VALUE name, VALUE version,
|
||||
"Ruby error: unable to load script "
|
||||
"\"%s\" (not enough memory)",
|
||||
c_name);
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
return INT2FIX (1);
|
||||
@@ -158,6 +158,14 @@ weechat_ruby_print (VALUE class, VALUE message, VALUE channel_name,
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to print message, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_message = NULL;
|
||||
c_channel_name = NULL;
|
||||
c_server_name = NULL;
|
||||
@@ -167,7 +175,7 @@ weechat_ruby_print (VALUE class, VALUE message, VALUE channel_name,
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"print\" function");
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (message, T_STRING);
|
||||
@@ -202,6 +210,14 @@ weechat_ruby_print_infobar (VALUE class, VALUE delay, VALUE message)
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to print infobar message, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_delay = 1;
|
||||
c_message = NULL;
|
||||
|
||||
@@ -210,7 +226,7 @@ weechat_ruby_print_infobar (VALUE class, VALUE delay, VALUE message)
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"print_infobar\" function");
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (delay, T_FIXNUM);
|
||||
@@ -237,6 +253,14 @@ weechat_ruby_command (VALUE class, VALUE command, VALUE channel_name,
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to run command, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_command = NULL;
|
||||
c_channel_name = NULL;
|
||||
c_server_name = NULL;
|
||||
@@ -246,7 +270,7 @@ weechat_ruby_command (VALUE class, VALUE command, VALUE channel_name,
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"command\" function");
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (command, T_STRING);
|
||||
@@ -264,7 +288,7 @@ weechat_ruby_command (VALUE class, VALUE command, VALUE channel_name,
|
||||
ruby_plugin->exec_command (ruby_plugin,
|
||||
c_server_name, c_channel_name,
|
||||
c_command);
|
||||
|
||||
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
@@ -280,6 +304,14 @@ weechat_ruby_add_message_handler (VALUE class, VALUE message, VALUE function)
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to add message handler, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_message = NULL;
|
||||
c_function = NULL;
|
||||
|
||||
@@ -288,7 +320,7 @@ weechat_ruby_add_message_handler (VALUE class, VALUE message, VALUE function)
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"add_message_handler\" function");
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (message, T_STRING);
|
||||
@@ -297,19 +329,12 @@ weechat_ruby_add_message_handler (VALUE class, VALUE message, VALUE function)
|
||||
c_message = STR2CSTR (message);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
if (ruby_current_script)
|
||||
ruby_plugin->msg_handler_add (ruby_plugin, c_message,
|
||||
if (ruby_plugin->msg_handler_add (ruby_plugin, c_message,
|
||||
weechat_ruby_handler, c_function,
|
||||
(void *)ruby_current_script);
|
||||
else
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to add message handler, "
|
||||
"script not initialized");
|
||||
return Qnil;
|
||||
}
|
||||
(void *)ruby_current_script))
|
||||
return INT2FIX (1);
|
||||
|
||||
return INT2FIX (1);
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -321,12 +346,20 @@ weechat_ruby_add_command_handler (VALUE class, VALUE command, VALUE function,
|
||||
VALUE description, VALUE arguments,
|
||||
VALUE arguments_description)
|
||||
{
|
||||
char *c_command, *c_function,*c_description, *c_arguments;
|
||||
char *c_command, *c_function, *c_description, *c_arguments;
|
||||
char *c_arguments_description;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to add command handler, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_command = NULL;
|
||||
c_function = NULL;
|
||||
c_description = NULL;
|
||||
@@ -338,7 +371,7 @@ weechat_ruby_add_command_handler (VALUE class, VALUE command, VALUE function,
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"add_command_handler\" function");
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (command, T_STRING);
|
||||
@@ -359,23 +392,59 @@ weechat_ruby_add_command_handler (VALUE class, VALUE command, VALUE function,
|
||||
if (!NIL_P (arguments_description))
|
||||
c_arguments_description = STR2CSTR (arguments_description);
|
||||
|
||||
if (ruby_current_script)
|
||||
ruby_plugin->cmd_handler_add (ruby_plugin,
|
||||
if (ruby_plugin->cmd_handler_add (ruby_plugin,
|
||||
c_command,
|
||||
c_description,
|
||||
c_arguments,
|
||||
c_arguments_description,
|
||||
weechat_ruby_handler,
|
||||
c_function,
|
||||
(void *)ruby_current_script);
|
||||
else
|
||||
(void *)ruby_current_script))
|
||||
return INT2FIX (1);
|
||||
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_remove_handler: remove a handler
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_remove_handler (VALUE class, VALUE command, VALUE function)
|
||||
{
|
||||
char *c_command, *c_function;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to add command handler, "
|
||||
"Ruby error: unable to remove handler, "
|
||||
"script not initialized");
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_command = NULL;
|
||||
c_function = NULL;
|
||||
|
||||
if (NIL_P (command) || NIL_P (function))
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"remove_handler\" function");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (command, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_command = STR2CSTR (command);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
weechat_script_remove_handler (ruby_plugin, ruby_current_script,
|
||||
c_command, c_function);
|
||||
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
@@ -393,6 +462,14 @@ weechat_ruby_get_info (VALUE class, VALUE arg, VALUE server_name,
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to get info, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_arg = NULL;
|
||||
c_server_name = NULL;
|
||||
c_channel_name = NULL;
|
||||
@@ -402,7 +479,7 @@ weechat_ruby_get_info (VALUE class, VALUE arg, VALUE server_name,
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"get_info\" function");
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (arg, T_STRING);
|
||||
@@ -428,11 +505,9 @@ weechat_ruby_get_info (VALUE class, VALUE arg, VALUE server_name,
|
||||
free (info);
|
||||
return return_value;
|
||||
}
|
||||
else
|
||||
return rb_str_new2 ("");
|
||||
}
|
||||
|
||||
return INT2FIX (1);
|
||||
return rb_str_new2 ("");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -445,23 +520,39 @@ weechat_ruby_get_dcc_info (VALUE class)
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to get DCC info, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/* TODO: get dcc info for Ruby */
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_get_config: get value of a config option
|
||||
* weechat_ruby_get_config: get value of a WeeChat config option
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_get_config (VALUE class, VALUE option)
|
||||
{
|
||||
char *c_option, *value;
|
||||
VALUE return_value;
|
||||
char *c_option, *return_value;
|
||||
VALUE ruby_return_value;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to get config option, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_option = NULL;
|
||||
|
||||
if (NIL_P (option))
|
||||
@@ -469,7 +560,7 @@ weechat_ruby_get_config (VALUE class, VALUE option)
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"get_config\" function");
|
||||
return Qnil;
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (option, T_STRING);
|
||||
@@ -477,19 +568,162 @@ weechat_ruby_get_config (VALUE class, VALUE option)
|
||||
|
||||
if (c_option)
|
||||
{
|
||||
value = ruby_plugin->get_config (ruby_plugin, c_option);
|
||||
return_value = ruby_plugin->get_config (ruby_plugin, c_option);
|
||||
|
||||
if (value)
|
||||
if (return_value)
|
||||
{
|
||||
return_value = rb_str_new2 (value);
|
||||
free (value);
|
||||
return return_value;
|
||||
ruby_return_value = rb_str_new2 (return_value);
|
||||
free (return_value);
|
||||
return ruby_return_value;
|
||||
}
|
||||
else
|
||||
return rb_str_new2 ("");
|
||||
}
|
||||
|
||||
return INT2FIX (1);
|
||||
return rb_str_new2 ("");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_set_config: set value of a WeeChat config option
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_set_config (VALUE class, VALUE option, VALUE value)
|
||||
{
|
||||
char *c_option, *c_value;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to set config option, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_option = NULL;
|
||||
c_value = NULL;
|
||||
|
||||
if (NIL_P (option))
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"set_config\" function");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (option, T_STRING);
|
||||
Check_Type (value, T_STRING);
|
||||
|
||||
c_option = STR2CSTR (option);
|
||||
c_value = STR2CSTR (value);
|
||||
|
||||
if (c_option && c_value)
|
||||
{
|
||||
if (ruby_plugin->set_config (ruby_plugin, c_option, c_value))
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_get_plugin_config: get value of a plugin config option
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_get_plugin_config (VALUE class, VALUE option)
|
||||
{
|
||||
char *c_option, *return_value;
|
||||
VALUE ruby_return_value;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to get plugin config option, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_option = NULL;
|
||||
|
||||
if (NIL_P (option))
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"get_plugin_config\" function");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (option, T_STRING);
|
||||
c_option = STR2CSTR (option);
|
||||
|
||||
if (c_option)
|
||||
{
|
||||
return_value = weechat_script_get_plugin_config (ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_option);
|
||||
|
||||
if (return_value)
|
||||
{
|
||||
ruby_return_value = rb_str_new2 (return_value);
|
||||
free (return_value);
|
||||
return ruby_return_value;
|
||||
}
|
||||
}
|
||||
|
||||
return rb_str_new2 ("");
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_set_plugin_config: set value of a plugin config option
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_set_plugin_config (VALUE class, VALUE option, VALUE value)
|
||||
{
|
||||
char *c_option, *c_value;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to set plugin config option, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_option = NULL;
|
||||
c_value = NULL;
|
||||
|
||||
if (NIL_P (option))
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"set_plugin_config\" function");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (option, T_STRING);
|
||||
Check_Type (value, T_STRING);
|
||||
|
||||
c_option = STR2CSTR (option);
|
||||
c_value = STR2CSTR (value);
|
||||
|
||||
if (c_option && c_value)
|
||||
{
|
||||
if (weechat_script_set_plugin_config (ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_option, c_value))
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -565,9 +799,8 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
|
||||
{
|
||||
int argc, path_length, handler_found;
|
||||
char **argv, *path_script, *dir_home;
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_msg_handler *ptr_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler;
|
||||
t_plugin_script *ptr_script;
|
||||
t_plugin_handler *ptr_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
@@ -591,14 +824,14 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
|
||||
plugin->printf_server (plugin, "Registered Ruby scripts:");
|
||||
if (ruby_scripts)
|
||||
{
|
||||
for (ptr_plugin_script = ruby_scripts; ptr_plugin_script;
|
||||
ptr_plugin_script = ptr_plugin_script->next_script)
|
||||
for (ptr_script = ruby_scripts;
|
||||
ptr_script; ptr_script = ptr_script->next_script)
|
||||
{
|
||||
plugin->printf_server (plugin, " %s v%s%s%s",
|
||||
ptr_plugin_script->name,
|
||||
ptr_plugin_script->version,
|
||||
(ptr_plugin_script->description[0]) ? " - " : "",
|
||||
ptr_plugin_script->description);
|
||||
ptr_script->name,
|
||||
ptr_script->version,
|
||||
(ptr_script->description[0]) ? " - " : "",
|
||||
ptr_script->description);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -608,15 +841,16 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Ruby message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_msg_handler = plugin->msg_handlers; ptr_msg_handler;
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler)
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if (ptr_msg_handler->msg_handler_args)
|
||||
if ((ptr_handler->type == HANDLER_MESSAGE)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " IRC(%s) => Ruby(%s)",
|
||||
ptr_msg_handler->irc_command,
|
||||
ptr_msg_handler->msg_handler_args);
|
||||
ptr_handler->irc_command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
@@ -626,15 +860,16 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
|
||||
plugin->printf_server (plugin, "");
|
||||
plugin->printf_server (plugin, "Ruby command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_cmd_handler = plugin->cmd_handlers; ptr_cmd_handler;
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler)
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if (ptr_cmd_handler->cmd_handler_args)
|
||||
if ((ptr_handler->type == HANDLER_COMMAND)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->printf_server (plugin, " /%s => Ruby(%s)",
|
||||
ptr_cmd_handler->command,
|
||||
ptr_cmd_handler->cmd_handler_args);
|
||||
ptr_handler->command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
|
||||
@@ -130,38 +130,20 @@ void
|
||||
weechat_script_remove (t_weechat_plugin *plugin,
|
||||
t_plugin_script **script_list, t_plugin_script *script)
|
||||
{
|
||||
t_plugin_msg_handler *ptr_msg_handler, *next_msg_handler;
|
||||
t_plugin_cmd_handler *ptr_cmd_handler, *next_cmd_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) plugin;
|
||||
t_plugin_handler *ptr_handler, *next_handler;
|
||||
|
||||
/* remove message handlers */
|
||||
ptr_msg_handler = plugin->msg_handlers;
|
||||
while (ptr_msg_handler)
|
||||
/* remove all handlers pointing to script */
|
||||
ptr_handler = plugin->handlers;
|
||||
while (ptr_handler)
|
||||
{
|
||||
if ((t_plugin_script *)ptr_msg_handler->msg_handler_pointer == script)
|
||||
if ((t_plugin_script *)ptr_handler->handler_pointer == script)
|
||||
{
|
||||
next_msg_handler = ptr_msg_handler->next_handler;
|
||||
plugin->msg_handler_remove (plugin, ptr_msg_handler);
|
||||
ptr_msg_handler = next_msg_handler;
|
||||
next_handler = ptr_handler->next_handler;
|
||||
plugin->handler_remove (plugin, ptr_handler);
|
||||
ptr_handler = next_handler;
|
||||
}
|
||||
else
|
||||
ptr_msg_handler = ptr_msg_handler->next_handler;
|
||||
}
|
||||
|
||||
/* remove command handlers */
|
||||
ptr_cmd_handler = plugin->cmd_handlers;
|
||||
while (ptr_cmd_handler)
|
||||
{
|
||||
if ((t_plugin_script *)ptr_cmd_handler->cmd_handler_pointer == script)
|
||||
{
|
||||
next_cmd_handler = ptr_cmd_handler->next_handler;
|
||||
plugin->cmd_handler_remove (plugin, ptr_cmd_handler);
|
||||
ptr_cmd_handler = next_cmd_handler;
|
||||
}
|
||||
else
|
||||
ptr_cmd_handler = ptr_cmd_handler->next_handler;
|
||||
ptr_handler = ptr_handler->next_handler;
|
||||
}
|
||||
|
||||
/* free data */
|
||||
@@ -187,3 +169,96 @@ weechat_script_remove (t_weechat_plugin *plugin,
|
||||
/* free script */
|
||||
free (script);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_remove_handler: remove a handler for a script
|
||||
* for a msg handler, arg1=irc command, arg2=function
|
||||
* for a cmd handler, arg1=command, arg2=function
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_remove_handler (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *arg1, char *arg2)
|
||||
{
|
||||
t_plugin_handler *ptr_handler, *next_handler;
|
||||
char *ptr_arg1;
|
||||
|
||||
/* search and remove message handlers */
|
||||
ptr_handler = plugin->handlers;
|
||||
while (ptr_handler)
|
||||
{
|
||||
ptr_arg1 = NULL;
|
||||
if (ptr_handler->type == HANDLER_MESSAGE)
|
||||
ptr_arg1 = ptr_handler->irc_command;
|
||||
else if (ptr_handler->type == HANDLER_COMMAND)
|
||||
ptr_arg1 = ptr_handler->command;
|
||||
|
||||
if ((ptr_arg1)
|
||||
&& ((t_plugin_script *)ptr_handler->handler_pointer == script)
|
||||
&& (plugin->ascii_strcasecmp (plugin, ptr_arg1, arg1) == 0)
|
||||
&& (plugin->ascii_strcasecmp (plugin, ptr_handler->handler_args, arg2) == 0))
|
||||
{
|
||||
next_handler = ptr_handler->next_handler;
|
||||
plugin->handler_remove (plugin, ptr_handler);
|
||||
ptr_handler = next_handler;
|
||||
}
|
||||
else
|
||||
ptr_handler = ptr_handler->next_handler;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_get_plugin_config: get a value of a script option
|
||||
* format in file is: plugin.script.option=value
|
||||
*/
|
||||
|
||||
char *
|
||||
weechat_script_get_plugin_config (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *option)
|
||||
{
|
||||
char *option_fullname, *return_value;
|
||||
|
||||
option_fullname = (char *)malloc (strlen (script->name) +
|
||||
strlen (option) + 2);
|
||||
if (!option_fullname)
|
||||
return NULL;
|
||||
|
||||
strcpy (option_fullname, script->name);
|
||||
strcat (option_fullname, ".");
|
||||
strcat (option_fullname, option);
|
||||
|
||||
return_value = plugin->get_plugin_config (plugin, option_fullname);
|
||||
free (option_fullname);
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_set_plugin_config: set value of a script config option
|
||||
* format in file is: plugin.script.option=value
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_script_set_plugin_config (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *option, char *value)
|
||||
{
|
||||
char *option_fullname;
|
||||
int return_code;
|
||||
|
||||
option_fullname = (char *)malloc (strlen (script->name) +
|
||||
strlen (option) + 2);
|
||||
if (!option_fullname)
|
||||
return 0;
|
||||
|
||||
strcpy (option_fullname, script->name);
|
||||
strcat (option_fullname, ".");
|
||||
strcat (option_fullname, option);
|
||||
|
||||
return_code = plugin->set_plugin_config (plugin, option_fullname, value);
|
||||
free (option_fullname);
|
||||
|
||||
return return_code;
|
||||
}
|
||||
|
||||
@@ -48,5 +48,14 @@ extern t_plugin_script *weechat_script_add (t_weechat_plugin *,
|
||||
char *, char *, char *);
|
||||
extern void weechat_script_remove (t_weechat_plugin *,
|
||||
t_plugin_script **, t_plugin_script *);
|
||||
extern void weechat_script_remove_handler (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *, char *);
|
||||
extern char *weechat_script_get_plugin_config (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *);
|
||||
extern int weechat_script_set_plugin_config (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *, char *);
|
||||
|
||||
#endif /* weechat-script.h */
|
||||
|
||||
Reference in New Issue
Block a user