summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/plugins-interface.c43
-rw-r--r--src/plugins/plugins.c276
-rw-r--r--src/plugins/plugins.h24
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c378
-rw-r--r--src/plugins/scripts/python/weechat-python.c364
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby.c359
-rw-r--r--src/plugins/scripts/weechat-script.c129
-rw-r--r--src/plugins/scripts/weechat-script.h9
-rw-r--r--src/plugins/weechat-plugin.h89
9 files changed, 1177 insertions, 494 deletions
diff --git a/src/plugins/plugins-interface.c b/src/plugins/plugins-interface.c
index 07a2ae1ed..e02a388b7 100644
--- a/src/plugins/plugins-interface.c
+++ b/src/plugins/plugins-interface.c
@@ -216,7 +216,7 @@ weechat_plugin_infobar_printf (t_weechat_plugin *plugin, int time_displayed, cha
* weechat_plugin_msg_handler_add: add a message handler
*/
-t_plugin_msg_handler *
+t_plugin_handler *
weechat_plugin_msg_handler_add (t_weechat_plugin *plugin, char *message,
t_plugin_handler_func *handler_func,
char *handler_args, void *handler_pointer)
@@ -229,33 +229,10 @@ weechat_plugin_msg_handler_add (t_weechat_plugin *plugin, char *message,
}
/*
- * weechat_plugin_msg_handler_remove: remove a WeeChat message handler
- */
-
-void
-weechat_plugin_msg_handler_remove (t_weechat_plugin *plugin,
- t_plugin_msg_handler *msg_handler)
-{
- if (plugin && msg_handler)
- plugin_msg_handler_remove (plugin, msg_handler);
-}
-
-/*
- * weechat_plugin_msg_handler_remove_all: remove all WeeChat message handlers
- */
-
-void
-weechat_plugin_msg_handler_remove_all (t_weechat_plugin *plugin)
-{
- if (plugin)
- plugin_msg_handler_remove_all (plugin);
-}
-
-/*
* weechat_plugin_cmd_handler_add: add a command handler
*/
-t_plugin_cmd_handler *
+t_plugin_handler *
weechat_plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
char *description, char *arguments,
char *arguments_description,
@@ -272,26 +249,26 @@ weechat_plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
}
/*
- * weechat_cmd_plugin_handler_remove: remove a WeeChat command handler
+ * weechat_plugin_handler_remove: remove a WeeChat handler
*/
void
-weechat_plugin_cmd_handler_remove (t_weechat_plugin *plugin,
- t_plugin_cmd_handler *cmd_handler)
+weechat_plugin_handler_remove (t_weechat_plugin *plugin,
+ t_plugin_handler *handler)
{
- if (plugin && cmd_handler)
- plugin_cmd_handler_remove (plugin, cmd_handler);
+ if (plugin && handler)
+ plugin_handler_remove (plugin, handler);
}
/*
- * weechat_plugin_cmd_handler_remove_all: remove all WeeChat command handlers
+ * weechat_plugin_handler_remove_all: remove all WeeChat handlers
*/
void
-weechat_plugin_cmd_handler_remove_all (t_weechat_plugin *plugin)
+weechat_plugin_handler_remove_all (t_weechat_plugin *plugin)
{
if (plugin)
- plugin_cmd_handler_remove_all (plugin);
+ plugin_handler_remove_all (plugin);
}
/*
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
index d153dd597..faa3545c7 100644
--- a/src/plugins/plugins.c
+++ b/src/plugins/plugins.c
@@ -33,6 +33,7 @@
#include <sys/stat.h>
#include <dirent.h>
#include <dlfcn.h>
+
#include "../common/weechat.h"
#include "plugins.h"
#include "plugins-config.h"
@@ -160,21 +161,21 @@ plugin_search (char *name)
* return: pointer to handler, NULL if not found
*/
-t_plugin_cmd_handler *
+t_plugin_handler *
plugin_cmd_handler_search (char *command)
{
t_weechat_plugin *ptr_plugin;
- t_plugin_cmd_handler *ptr_plugin_cmd_handler;
+ t_plugin_handler *ptr_handler;
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
- for (ptr_plugin_cmd_handler = ptr_plugin->cmd_handlers;
- ptr_plugin_cmd_handler;
- ptr_plugin_cmd_handler = ptr_plugin_cmd_handler->next_handler)
+ for (ptr_handler = ptr_plugin->handlers;
+ ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if (ascii_strcasecmp (ptr_plugin_cmd_handler->command, command) == 0)
- return ptr_plugin_cmd_handler;
+ if ((ptr_handler->type == HANDLER_COMMAND)
+ && (ascii_strcasecmp (ptr_handler->command, command) == 0))
+ return ptr_handler;
}
}
@@ -194,30 +195,35 @@ plugin_cmd_handler_search (char *command)
* handler when called (used by scripts)
*/
-t_plugin_msg_handler *
+t_plugin_handler *
plugin_msg_handler_add (t_weechat_plugin *plugin, char *irc_command,
t_plugin_handler_func *handler_func,
char *handler_args, void *handler_pointer)
{
- t_plugin_msg_handler *new_plugin_msg_handler;
-
- new_plugin_msg_handler = (t_plugin_msg_handler *)malloc (sizeof (t_plugin_msg_handler));
- if (new_plugin_msg_handler)
- {
- new_plugin_msg_handler->irc_command = strdup (irc_command);
- new_plugin_msg_handler->msg_handler = handler_func;
- new_plugin_msg_handler->msg_handler_args = (handler_args) ? strdup (handler_args) : NULL;
- new_plugin_msg_handler->msg_handler_pointer = handler_pointer;
- new_plugin_msg_handler->running = 0;
+ t_plugin_handler *new_handler;
+
+ new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
+ if (new_handler)
+ {
+ new_handler->type = HANDLER_MESSAGE;
+ new_handler->irc_command = strdup (irc_command);
+ new_handler->command = NULL;
+ new_handler->description = NULL;
+ new_handler->arguments = NULL;
+ new_handler->arguments_description = NULL;
+ new_handler->handler = handler_func;
+ new_handler->handler_args = (handler_args) ? strdup (handler_args) : NULL;
+ new_handler->handler_pointer = handler_pointer;
+ new_handler->running = 0;
/* add new handler to list */
- new_plugin_msg_handler->prev_handler = plugin->last_msg_handler;
- new_plugin_msg_handler->next_handler = NULL;
- if (plugin->msg_handlers)
- (plugin->last_msg_handler)->next_handler = new_plugin_msg_handler;
+ new_handler->prev_handler = plugin->last_handler;
+ new_handler->next_handler = NULL;
+ if (plugin->handlers)
+ (plugin->last_handler)->next_handler = new_handler;
else
- plugin->msg_handlers = new_plugin_msg_handler;
- plugin->last_msg_handler = new_plugin_msg_handler;
+ plugin->handlers = new_handler;
+ plugin->last_handler = new_handler;
}
else
{
@@ -227,7 +233,7 @@ plugin_msg_handler_add (t_weechat_plugin *plugin, char *irc_command,
WEECHAT_ERROR, plugin->name, irc_command);
return NULL;
}
- return new_plugin_msg_handler;
+ return new_handler;
}
/*
@@ -245,14 +251,14 @@ plugin_msg_handler_add (t_weechat_plugin *plugin, char *irc_command,
* handler when called (used by scripts)
*/
-t_plugin_cmd_handler *
+t_plugin_handler *
plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
char *description, char *arguments,
char *arguments_description,
t_plugin_handler_func *handler_func,
char *handler_args, void *handler_pointer)
{
- t_plugin_cmd_handler *new_plugin_cmd_handler;
+ t_plugin_handler *new_handler;
if (plugin_cmd_handler_search (command))
{
@@ -264,26 +270,28 @@ plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
return NULL;
}
- new_plugin_cmd_handler = (t_plugin_cmd_handler *)malloc (sizeof (t_plugin_cmd_handler));
- if (new_plugin_cmd_handler)
- {
- new_plugin_cmd_handler->command = strdup (command);
- new_plugin_cmd_handler->description = (description) ? strdup (description) : NULL;
- new_plugin_cmd_handler->arguments = (arguments) ? strdup (arguments) : NULL;
- new_plugin_cmd_handler->arguments_description = (arguments_description) ? strdup (arguments_description) : NULL;
- new_plugin_cmd_handler->cmd_handler = handler_func;
- new_plugin_cmd_handler->cmd_handler_args = (handler_args) ? strdup (handler_args) : NULL;
- new_plugin_cmd_handler->cmd_handler_pointer = handler_pointer;
- new_plugin_cmd_handler->running = 0;
+ new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
+ if (new_handler)
+ {
+ new_handler->type = HANDLER_COMMAND;
+ new_handler->irc_command = NULL;
+ new_handler->command = strdup (command);
+ new_handler->description = (description) ? strdup (description) : NULL;
+ new_handler->arguments = (arguments) ? strdup (arguments) : NULL;
+ new_handler->arguments_description = (arguments_description) ? strdup (arguments_description) : NULL;
+ new_handler->handler = handler_func;
+ new_handler->handler_args = (handler_args) ? strdup (handler_args) : NULL;
+ new_handler->handler_pointer = handler_pointer;
+ new_handler->running = 0;
/* add new handler to list */
- new_plugin_cmd_handler->prev_handler = plugin->last_cmd_handler;
- new_plugin_cmd_handler->next_handler = NULL;
- if (plugin->cmd_handlers)
- (plugin->last_cmd_handler)->next_handler = new_plugin_cmd_handler;
+ new_handler->prev_handler = plugin->last_handler;
+ new_handler->next_handler = NULL;
+ if (plugin->handlers)
+ (plugin->last_handler)->next_handler = new_handler;
else
- plugin->cmd_handlers = new_plugin_cmd_handler;
- plugin->last_cmd_handler = new_plugin_cmd_handler;
+ plugin->handlers = new_handler;
+ plugin->last_handler = new_handler;
/* add command to WeeChat commands list */
if (!weelist_search (index_commands, command))
@@ -297,7 +305,7 @@ plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
WEECHAT_ERROR, plugin->name, command);
return NULL;
}
- return new_plugin_cmd_handler;
+ return new_handler;
}
/*
@@ -309,30 +317,30 @@ int
plugin_msg_handler_exec (char *server, char *irc_command, char *irc_message)
{
t_weechat_plugin *ptr_plugin;
- t_plugin_msg_handler *ptr_plugin_msg_handler;
+ t_plugin_handler *ptr_handler;
int count;
count = 0;
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
- for (ptr_plugin_msg_handler = ptr_plugin->msg_handlers;
- ptr_plugin_msg_handler;
- ptr_plugin_msg_handler = ptr_plugin_msg_handler->next_handler)
+ for (ptr_handler = ptr_plugin->handlers;
+ ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if (ascii_strcasecmp (ptr_plugin_msg_handler->irc_command, irc_command) == 0)
+ if ((ptr_handler->type == HANDLER_MESSAGE)
+ && (ascii_strcasecmp (ptr_handler->irc_command, irc_command) == 0))
{
- if (ptr_plugin_msg_handler->running == 0)
+ if (ptr_handler->running == 0)
{
- ptr_plugin_msg_handler->running = 1;
- if ((int) (ptr_plugin_msg_handler->msg_handler) (ptr_plugin,
- server,
- irc_command,
- irc_message,
- ptr_plugin_msg_handler->msg_handler_args,
- ptr_plugin_msg_handler->msg_handler_pointer))
+ ptr_handler->running = 1;
+ if ((int) (ptr_handler->handler) (ptr_plugin,
+ server,
+ irc_command,
+ irc_message,
+ ptr_handler->handler_args,
+ ptr_handler->handler_pointer))
count++;
- ptr_plugin_msg_handler->running = 0;
+ ptr_handler->running = 0;
}
}
}
@@ -350,28 +358,28 @@ int
plugin_cmd_handler_exec (char *server, char *command, char *arguments)
{
t_weechat_plugin *ptr_plugin;
- t_plugin_cmd_handler *ptr_plugin_cmd_handler;
+ t_plugin_handler *ptr_handler;
int return_code;
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
- for (ptr_plugin_cmd_handler = ptr_plugin->cmd_handlers;
- ptr_plugin_cmd_handler;
- ptr_plugin_cmd_handler = ptr_plugin_cmd_handler->next_handler)
+ for (ptr_handler = ptr_plugin->handlers;
+ ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if (ascii_strcasecmp (ptr_plugin_cmd_handler->command, command) == 0)
+ if ((ptr_handler->type == HANDLER_COMMAND)
+ && (ascii_strcasecmp (ptr_handler->command, command) == 0))
{
- if (ptr_plugin_cmd_handler->running == 0)
+ if (ptr_handler->running == 0)
{
- ptr_plugin_cmd_handler->running = 1;
- return_code = (int) (ptr_plugin_cmd_handler->cmd_handler) (ptr_plugin,
- server,
- command,
- arguments,
- ptr_plugin_cmd_handler->cmd_handler_args,
- ptr_plugin_cmd_handler->cmd_handler_pointer);
- ptr_plugin_cmd_handler->running = 0;
+ ptr_handler->running = 1;
+ return_code = (int) (ptr_handler->handler) (ptr_plugin,
+ server,
+ command,
+ arguments,
+ ptr_handler->handler_args,
+ ptr_handler->handler_pointer);
+ ptr_handler->running = 0;
return (return_code) ? 1 : 0;
}
}
@@ -382,99 +390,60 @@ plugin_cmd_handler_exec (char *server, char *command, char *arguments)
}
/*
- * plugin_msg_handler_remove: remove a message handler for a plugin
+ * plugin_handler_remove: remove a handler for a plugin
*/
void
-plugin_msg_handler_remove (t_weechat_plugin *plugin,
- t_plugin_msg_handler *plugin_msg_handler)
+plugin_handler_remove (t_weechat_plugin *plugin,
+ t_plugin_handler *handler)
{
- t_plugin_msg_handler *new_plugin_msg_handlers;
+ t_plugin_handler *new_handlers;
/* remove handler from list */
- if (plugin->last_msg_handler == plugin_msg_handler)
- plugin->last_msg_handler = plugin_msg_handler->prev_handler;
- if (plugin_msg_handler->prev_handler)
+ if (plugin->last_handler == handler)
+ plugin->last_handler = handler->prev_handler;
+ if (handler->prev_handler)
{
- (plugin_msg_handler->prev_handler)->next_handler = plugin_msg_handler->next_handler;
- new_plugin_msg_handlers = plugin->msg_handlers;
+ (handler->prev_handler)->next_handler = handler->next_handler;
+ new_handlers = plugin->handlers;
}
else
- new_plugin_msg_handlers = plugin_msg_handler->next_handler;
+ new_handlers = handler->next_handler;
- if (plugin_msg_handler->next_handler)
- (plugin_msg_handler->next_handler)->prev_handler = plugin_msg_handler->prev_handler;
-
- /* free data */
- if (plugin_msg_handler->irc_command)
- free (plugin_msg_handler->irc_command);
- if (plugin_msg_handler->msg_handler_args)
- free (plugin_msg_handler->msg_handler_args);
- plugin->msg_handlers = new_plugin_msg_handlers;
-}
-
-/*
- * plugin_cmd_handler_remove: remove a command handler for a plugin
- */
-
-void
-plugin_cmd_handler_remove (t_weechat_plugin *plugin,
- t_plugin_cmd_handler *plugin_cmd_handler)
-{
- t_plugin_cmd_handler *new_plugin_cmd_handlers;
+ if (handler->next_handler)
+ (handler->next_handler)->prev_handler = handler->prev_handler;
- /* remove handler from list */
- if (plugin->last_cmd_handler == plugin_cmd_handler)
- plugin->last_cmd_handler = plugin_cmd_handler->prev_handler;
- if (plugin_cmd_handler->prev_handler)
- {
- (plugin_cmd_handler->prev_handler)->next_handler = plugin_cmd_handler->next_handler;
- new_plugin_cmd_handlers = plugin->cmd_handlers;
- }
- else
- new_plugin_cmd_handlers = plugin_cmd_handler->next_handler;
-
- if (plugin_cmd_handler->next_handler)
- (plugin_cmd_handler->next_handler)->prev_handler = plugin_cmd_handler->prev_handler;
-
- /* remove command from WeeChat command list */
- weelist_remove (&index_commands, &last_index_command,
- weelist_search (index_commands, plugin_cmd_handler->command));
+ /* remove command from WeeChat command list, if command handler */
+ if (handler->type == HANDLER_COMMAND)
+ weelist_remove (&index_commands, &last_index_command,
+ weelist_search (index_commands, handler->command));
/* free data */
- if (plugin_cmd_handler->command)
- free (plugin_cmd_handler->command);
- if (plugin_cmd_handler->description)
- free (plugin_cmd_handler->description);
- if (plugin_cmd_handler->arguments)
- free (plugin_cmd_handler->arguments);
- if (plugin_cmd_handler->arguments_description)
- free (plugin_cmd_handler->arguments_description);
- if (plugin_cmd_handler->cmd_handler_args)
- free (plugin_cmd_handler->cmd_handler_args);
- plugin->cmd_handlers = new_plugin_cmd_handlers;
-}
-
-/*
- * plugin_msg_handler_remove_all: remove all message handlers for a plugin
- */
-
-void
-plugin_msg_handler_remove_all (t_weechat_plugin *plugin)
-{
- while (plugin->msg_handlers)
- plugin_msg_handler_remove (plugin, plugin->msg_handlers);
+ if (handler->irc_command)
+ free (handler->irc_command);
+ if (handler->command)
+ free (handler->command);
+ if (handler->description)
+ free (handler->description);
+ if (handler->arguments)
+ free (handler->arguments);
+ if (handler->arguments_description)
+ free (handler->arguments_description);
+ if (handler->handler_args)
+ free (handler->handler_args);
+
+ plugin->handlers = new_handlers;
}
/*
- * plugin_cmd_handler_remove_all: remove all command handlers for a plugin
+ * plugin_handler_remove_all: remove all handlers for a plugin
*/
void
-plugin_cmd_handler_remove_all (t_weechat_plugin *plugin)
+plugin_handler_remove_all (t_weechat_plugin *plugin)
{
- while (plugin->cmd_handlers)
- plugin_cmd_handler_remove (plugin, plugin->cmd_handlers);
+ while (plugin->handlers)
+ plugin_handler_remove (plugin, plugin->handlers);
}
/*
@@ -650,11 +619,9 @@ plugin_load (char *filename)
new_plugin->mkdir_home = &weechat_plugin_mkdir_home;
new_plugin->exec_on_files = &weechat_plugin_exec_on_files;
new_plugin->msg_handler_add = &weechat_plugin_msg_handler_add;
- new_plugin->msg_handler_remove = &weechat_plugin_msg_handler_remove;
- new_plugin->msg_handler_remove_all = &weechat_plugin_msg_handler_remove_all;
new_plugin->cmd_handler_add = &weechat_plugin_cmd_handler_add;
- new_plugin->cmd_handler_remove = &weechat_plugin_cmd_handler_remove;
- new_plugin->cmd_handler_remove_all = &weechat_plugin_cmd_handler_remove_all;
+ new_plugin->handler_remove = &weechat_plugin_handler_remove;
+ new_plugin->handler_remove_all = &weechat_plugin_handler_remove_all;
new_plugin->printf = &weechat_plugin_printf;
new_plugin->printf_server = &weechat_plugin_printf_server;
new_plugin->infobar_printf = &weechat_plugin_infobar_printf;
@@ -668,10 +635,8 @@ plugin_load (char *filename)
new_plugin->set_plugin_config = &weechat_plugin_set_plugin_config;
/* handlers */
- new_plugin->msg_handlers = NULL;
- new_plugin->last_msg_handler = NULL;
- new_plugin->cmd_handlers = NULL;
- new_plugin->last_cmd_handler = NULL;
+ new_plugin->handlers = NULL;
+ new_plugin->last_handler = NULL;
/* add new plugin to list */
new_plugin->prev_plugin = last_weechat_plugin;
@@ -807,8 +772,7 @@ plugin_remove (t_weechat_plugin *plugin)
(plugin->next_plugin)->prev_plugin = plugin->prev_plugin;
/* free data */
- plugin_msg_handler_remove_all (plugin);
- plugin_cmd_handler_remove_all (plugin);
+ plugin_handler_remove_all (plugin);
if (plugin->filename)
free (plugin->filename);
dlclose (plugin->handle);
diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h
index 99274460e..25bb2f1e1 100644
--- a/src/plugins/plugins.h
+++ b/src/plugins/plugins.h
@@ -34,22 +34,20 @@ extern t_gui_buffer *plugin_find_buffer (char *, char *);
extern void plugin_exec_on_files (t_weechat_plugin *, char *,
int (*)(t_weechat_plugin *, char *));
extern t_weechat_plugin *plugin_search (char *);
-extern t_plugin_msg_handler *plugin_msg_handler_add (t_weechat_plugin *, char *,
- t_plugin_handler_func *,
- char *, void *);
-extern t_plugin_cmd_handler *plugin_cmd_handler_add (t_weechat_plugin *, char *,
- char *, char *, char *,
- t_plugin_handler_func *,
- char *, void *);
+extern t_plugin_handler *plugin_msg_handler_add (t_weechat_plugin *, char *,
+ t_plugin_handler_func *,
+ char *, void *);
+extern t_plugin_handler *plugin_cmd_handler_add (t_weechat_plugin *, char *,
+ char *, char *, char *,
+ t_plugin_handler_func *,
+ char *, void *);
extern int plugin_msg_handler_exec (char *, char *, char *);
extern int plugin_cmd_handler_exec (char *, char *, char *);
-extern void plugin_msg_handler_remove (t_weechat_plugin *,
- t_plugin_msg_handler *);
-extern void plugin_cmd_handler_remove (t_weechat_plugin *,
- t_plugin_cmd_handler *);
-extern void plugin_msg_handler_remove_all (t_weechat_plugin *);
-extern void plugin_cmd_handler_remove_all (t_weechat_plugin *);
+extern void plugin_handler_remove (t_weechat_plugin *,
+ t_plugin_handler *);
+extern void plugin_handler_remove_all (t_weechat_plugin *);
extern t_weechat_plugin *plugin_load (char *);
+extern void plugin_auto_load ();
extern void plugin_remove (t_weechat_plugin *);
extern void plugin_unload (t_weechat_plugin *);
extern void plugin_unload_name (char *);
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index 7bba1c4b2..683c6470c 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -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,41 +548,181 @@ 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, *value;
+ 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_NO;
+ XSRETURN (0);
}
option = SvPV (ST (0), integer);
+
if (option)
{
- value = perl_plugin->get_config (perl_plugin, option);
+ return_value = perl_plugin->get_config (perl_plugin, 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, "");
}
- XSRETURN (1);
+ 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;
+ dXSARGS;
+
+ /* 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_plugin_config\" function");
+ XSRETURN (0);
+ }
+
+ option = SvPV (ST (0), integer);
+
+ if (option)
+ {
+ return_value = weechat_script_get_plugin_config (perl_plugin,
+ perl_current_script,
+ option);
+
+ if (return_value)
+ {
+ XST_mPV (0, return_value);
+ free (return_value);
+ return;
+ }
+ }
+
+ 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);
+ }
+
+ 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)
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c
index 1f83c2af0..dec287550 100644
--- a/src/plugins/scripts/python/weechat-python.c
+++ b/src/plugins/scripts/python/weechat-python.c
@@ -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;
+ if (!python_current_script)
+ {
+ python_plugin->printf_server (python_plugin,
+ "Python error: unable to add message handler, "
+ "script not initialized");
+ return Py_BuildValue ("i", 0);
+ }
+
+ irc_command = NULL;
function = NULL;
- if (!PyArg_ParseTuple (args, "ss", &message, &function))
+ if (!PyArg_ParseTuple (args, "ss", &irc_command, &function))
{
python_plugin->printf_server (python_plugin,
"Python error: wrong parameters for "
"\"add_message_handler\" function");
- return NULL;
+ return Py_BuildValue ("i", 0);
}
- if (python_current_script)
- python_plugin->msg_handler_add (python_plugin, message,
+ if (python_plugin->msg_handler_add (python_plugin, irc_command,
weechat_python_handler, function,
- (void *)python_current_script);
- else
- {
- python_plugin->printf_server (python_plugin,
- "Python error: unable to add message handler, "
- "script not initialized");
- return NULL;
- }
+ (void *)python_current_script))
+ return Py_BuildValue ("i", 1);
- Py_INCREF (Py_None);
- return Py_None;
+ 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)
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c
index e11f9cc96..52d7b77d0 100644
--- a/src/plugins/scripts/ruby/weechat-ruby.c
+++ b/src/plugins/scripts/ruby/weechat-ruby.c
@@ -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)
diff --git a/src/plugins/scripts/weechat-script.c b/src/plugins/scripts/weechat-script.c
index ae2555184..04374c366 100644
--- a/src/plugins/scripts/weechat-script.c
+++ b/src/plugins/scripts/weechat-script.c
@@ -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;
+}
diff --git a/src/plugins/scripts/weechat-script.h b/src/plugins/scripts/weechat-script.h
index 496a126e5..b42a75059 100644
--- a/src/plugins/scripts/weechat-script.h
+++ b/src/plugins/scripts/weechat-script.h
@@ -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 */
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index d0afaafe2..d5add59ea 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -52,40 +52,39 @@ typedef int (t_plugin_handler_func) (t_weechat_plugin *, char *, char *, char *,
/* message handler, called when an IRC messages is received */
-typedef struct t_plugin_msg_handler t_plugin_msg_handler;
+typedef enum t_handler_type t_handler_type;
-struct t_plugin_msg_handler
+enum t_handler_type
{
- char *irc_command; /* name of IRC command (PRIVMSG, ..) */
- t_plugin_handler_func *msg_handler; /* pointer to message handler */
- char *msg_handler_args; /* arguments sent to message handler */
- void *msg_handler_pointer; /* pointer sent to message handler */
-
- int running; /* 1 if currently running */
- /* (used to prevent circular call) */
- t_plugin_msg_handler *prev_handler; /* link to previous handler */
- t_plugin_msg_handler *next_handler; /* link to next handler */
+ HANDLER_MESSAGE,
+ HANDLER_COMMAND
};
-/* command handler, to add new commands to WeeChat */
-
-typedef struct t_plugin_cmd_handler t_plugin_cmd_handler;
+typedef struct t_plugin_handler t_plugin_handler;
-struct t_plugin_cmd_handler
+struct t_plugin_handler
{
+ t_handler_type type; /* handler type */
+
+ /* data for message handler */
+ char *irc_command; /* name of IRC command (PRIVMSG, ..) */
+
+ /* data for command handler */
char *command; /* name of command (without first '/') */
char *description; /* (for /help) short cmd description */
char *arguments; /* (for /help) command arguments */
char *arguments_description; /* (for /help) args long description */
- /* command handler */
- t_plugin_handler_func *cmd_handler; /* pointer to command handler */
- char *cmd_handler_args; /* arguments sent to command handler */
- void *cmd_handler_pointer; /* pointer sent to command handler */
+ /* data common to all handlers */
+ t_plugin_handler_func *handler; /* pointer to handler */
+ char *handler_args; /* arguments sent to handler */
+ void *handler_pointer; /* pointer sent to handler */
+
+ /* for internal use */
int running; /* 1 if currently running */
/* (used to prevent circular call) */
- t_plugin_cmd_handler *prev_handler; /* link to previous handler */
- t_plugin_cmd_handler *next_handler; /* link to next handler */
+ t_plugin_handler *prev_handler; /* link to previous handler */
+ t_plugin_handler *next_handler; /* link to next handler */
};
/* plugin, a WeeChat plugin, which is a dynamic library */
@@ -100,11 +99,9 @@ struct t_weechat_plugin
char *version; /* plugin version */
/* plugin handlers */
- t_plugin_msg_handler *msg_handlers; /* IRC message handlers */
- t_plugin_msg_handler *last_msg_handler;
- t_plugin_cmd_handler *cmd_handlers; /* command handlers */
- t_plugin_cmd_handler *last_cmd_handler;
-
+ t_plugin_handler *handlers; /* pointer to first handler */
+ t_plugin_handler *last_handler; /* pointer to last handler */
+
/* links to previous/next plugins */
t_weechat_plugin *prev_plugin; /* link to previous plugin */
t_weechat_plugin *next_plugin; /* link to next plugin */
@@ -127,17 +124,15 @@ struct t_weechat_plugin
void (*printf_server) (t_weechat_plugin *, char *, ...);
void (*infobar_printf) (t_weechat_plugin *, int, char *, ...);
- t_plugin_msg_handler *(*msg_handler_add) (t_weechat_plugin *, char *,
- t_plugin_handler_func *,
- char *, void *);
- void (*msg_handler_remove) (t_weechat_plugin *, t_plugin_msg_handler *);
- void (*msg_handler_remove_all) (t_weechat_plugin *);
- t_plugin_cmd_handler *(*cmd_handler_add) (t_weechat_plugin *, char *,
- char *, char *, char *,
- t_plugin_handler_func *,
- char *, void *);
- void (*cmd_handler_remove) (t_weechat_plugin *, t_plugin_cmd_handler *);
- void (*cmd_handler_remove_all) (t_weechat_plugin *);
+ t_plugin_handler *(*msg_handler_add) (t_weechat_plugin *, char *,
+ t_plugin_handler_func *,
+ char *, void *);
+ t_plugin_handler *(*cmd_handler_add) (t_weechat_plugin *, char *,
+ char *, char *, char *,
+ t_plugin_handler_func *,
+ char *, void *);
+ void (*handler_remove) (t_weechat_plugin *, t_plugin_handler *);
+ void (*handler_remove_all) (t_weechat_plugin *);
void (*exec_command) (t_weechat_plugin *, char *, char *, char *);
char *(*get_info) (t_weechat_plugin *, char *, char *, char *);
@@ -166,17 +161,15 @@ extern void weechat_plugin_printf_server (t_weechat_plugin *, char *, ...);
extern void weechat_plugin_infobar_printf (t_weechat_plugin *, int, char *, ...);
/* handler functions */
-extern t_plugin_msg_handler *weechat_plugin_msg_handler_add (t_weechat_plugin *, char *,
- t_plugin_handler_func *,
- char *, void *);
-extern void weechat_plugin_msg_handler_remove (t_weechat_plugin *, t_plugin_msg_handler *);
-extern void weechat_plugin_msg_handler_remove_all (t_weechat_plugin *);
-extern t_plugin_cmd_handler *weechat_plugin_cmd_handler_add (t_weechat_plugin *, char *,
- char *, char *, char *,
- t_plugin_handler_func *,
- char *, void *);
-extern void weechat_plugin_cmd_handler_remove (t_weechat_plugin *, t_plugin_cmd_handler *);
-extern void weechat_plugin_cmd_handler_remove_all (t_weechat_plugin *);
+extern t_plugin_handler *weechat_plugin_msg_handler_add (t_weechat_plugin *, char *,
+ t_plugin_handler_func *,
+ char *, void *);
+extern t_plugin_handler *weechat_plugin_cmd_handler_add (t_weechat_plugin *, char *,
+ char *, char *, char *,
+ t_plugin_handler_func *,
+ char *, void *);
+extern void weechat_plugin_handler_remove (t_weechat_plugin *, t_plugin_handler *);
+extern void weechat_plugin_handler_remove_all (t_weechat_plugin *);
/* other functions */
extern void weechat_plugin_exec_command (t_weechat_plugin *, char *, char *, char *);