summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/plugins-interface.c40
-rw-r--r--src/plugins/plugins.c265
-rw-r--r--src/plugins/plugins.h9
-rw-r--r--src/plugins/scripts/lua/weechat-lua.c195
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c105
-rw-r--r--src/plugins/scripts/python/weechat-python.c106
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby.c124
-rw-r--r--src/plugins/scripts/weechat-script.c53
-rw-r--r--src/plugins/scripts/weechat-script.h3
-rw-r--r--src/plugins/weechat-plugin.h76
10 files changed, 899 insertions, 77 deletions
diff --git a/src/plugins/plugins-interface.c b/src/plugins/plugins-interface.c
index a45ec7480..f9298cee6 100644
--- a/src/plugins/plugins-interface.c
+++ b/src/plugins/plugins-interface.c
@@ -357,6 +357,46 @@ weechat_plugin_handler_remove_all (t_weechat_plugin *plugin)
}
/*
+ * weechat_plugin_modifier_add: add a IRC message modifier
+ */
+
+t_plugin_modifier *
+weechat_plugin_modifier_add (t_weechat_plugin *plugin,
+ char *type, char *message,
+ t_plugin_modifier_func *modifier_func,
+ char *modifier_args, void *modifier_pointer)
+{
+ if (plugin && type && modifier_func)
+ return plugin_modifier_add (plugin, type, message, modifier_func,
+ modifier_args, modifier_pointer);
+
+ return NULL;
+}
+
+/*
+ * weechat_plugin_modifier_remove: remove a WeeChat modifier
+ */
+
+void
+weechat_plugin_modifier_remove (t_weechat_plugin *plugin,
+ t_plugin_modifier *modifier)
+{
+ if (plugin && modifier)
+ plugin_modifier_remove (plugin, modifier);
+}
+
+/*
+ * weechat_plugin_modifier_remove_all: remove all WeeChat modifiers
+ */
+
+void
+weechat_plugin_modifier_remove_all (t_weechat_plugin *plugin)
+{
+ if (plugin)
+ plugin_modifier_remove_all (plugin);
+}
+
+/*
* weechat_plugin_exec_command: execute a command (simulate user entry)
*/
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
index 7639c6aba..469800e2a 100644
--- a/src/plugins/plugins.c
+++ b/src/plugins/plugins.c
@@ -180,7 +180,7 @@ plugin_cmd_handler_search (char *command)
for (ptr_handler = ptr_plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_COMMAND)
+ if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
&& (ascii_strcasecmp (ptr_handler->command, command) == 0))
return ptr_handler;
}
@@ -212,7 +212,7 @@ plugin_msg_handler_add (t_weechat_plugin *plugin, char *irc_command,
new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
if (new_handler)
{
- new_handler->type = HANDLER_MESSAGE;
+ new_handler->type = PLUGIN_HANDLER_MESSAGE;
new_handler->irc_command = strdup (irc_command);
new_handler->command = NULL;
new_handler->description = NULL;
@@ -295,7 +295,7 @@ plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
if (new_handler)
{
- new_handler->type = HANDLER_COMMAND;
+ new_handler->type = PLUGIN_HANDLER_COMMAND;
new_handler->irc_command = NULL;
new_handler->command = strdup (command);
new_handler->description = (description) ? strdup (description) : NULL;
@@ -355,7 +355,7 @@ plugin_timer_handler_add (t_weechat_plugin *plugin, int interval,
new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
if (new_handler)
{
- new_handler->type = HANDLER_TIMER;
+ new_handler->type = PLUGIN_HANDLER_TIMER;
new_handler->irc_command = NULL;
new_handler->command = NULL;
new_handler->description = NULL;
@@ -411,7 +411,7 @@ plugin_keyboard_handler_add (t_weechat_plugin *plugin,
new_handler = (t_plugin_handler *)malloc (sizeof (t_plugin_handler));
if (new_handler)
{
- new_handler->type = HANDLER_KEYBOARD;
+ new_handler->type = PLUGIN_HANDLER_KEYBOARD;
new_handler->irc_command = NULL;
new_handler->command = NULL;
new_handler->description = NULL;
@@ -471,7 +471,7 @@ plugin_msg_handler_exec (char *server, char *irc_command, char *irc_message)
for (ptr_handler = ptr_plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_MESSAGE)
+ if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
&& (ascii_strcasecmp (ptr_handler->irc_command, irc_command) == 0))
{
if (ptr_handler->running == 0)
@@ -523,7 +523,7 @@ plugin_cmd_handler_exec (char *server, char *command, char *arguments)
for (ptr_handler = ptr_plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_COMMAND)
+ if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
&& (ascii_strcasecmp (ptr_handler->command, command) == 0))
{
if (ptr_handler->running == 0)
@@ -564,7 +564,7 @@ plugin_timer_handler_exec ()
for (ptr_handler = ptr_plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if (ptr_handler->type == HANDLER_TIMER)
+ if (ptr_handler->type == PLUGIN_HANDLER_TIMER)
{
ptr_handler->remaining--;
if (ptr_handler->remaining <= 0)
@@ -610,7 +610,7 @@ plugin_keyboard_handler_exec (char *key, char *input_before, char *input_after)
for (ptr_handler = ptr_plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if (ptr_handler->type == HANDLER_KEYBOARD)
+ if (ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
{
return_code = ((int) (ptr_handler->handler) (ptr_plugin,
3, argv,
@@ -650,7 +650,7 @@ plugin_handler_remove (t_weechat_plugin *plugin,
(handler->next_handler)->prev_handler = handler->prev_handler;
/* remove command from WeeChat command list, if command handler */
- if (handler->type == HANDLER_COMMAND)
+ if (handler->type == PLUGIN_HANDLER_COMMAND)
weelist_remove (&index_commands, &last_index_command,
weelist_search (index_commands, handler->command));
@@ -683,6 +683,199 @@ plugin_handler_remove_all (t_weechat_plugin *plugin)
}
/*
+ * plugin_modifier_add: add a IRC handler
+ * arguments:
+ * 1. the plugin pointer
+ * 2. type of modifier
+ * 3. message ("*" means all)
+ * 4. the modifier function
+ * 5. modifier args: a string given to
+ * modifier when called (used by scripts)
+ * 6. modifier pointer: a pointer given to
+ * modifier when called (used by scripts)
+ */
+
+t_plugin_modifier *
+plugin_modifier_add (t_weechat_plugin *plugin, char *type, char *command,
+ t_plugin_modifier_func *modifier_func,
+ char *modifier_args, void *modifier_pointer)
+{
+ t_plugin_modifier *new_modifier;
+ int type_int;
+
+ if (ascii_strcasecmp (type, PLUGIN_MODIFIER_IRC_IN_STR) == 0)
+ type_int = PLUGIN_MODIFIER_IRC_IN;
+ else if (ascii_strcasecmp (type, PLUGIN_MODIFIER_IRC_USER_STR) == 0)
+ type_int = PLUGIN_MODIFIER_IRC_USER;
+ else if (ascii_strcasecmp (type, PLUGIN_MODIFIER_IRC_OUT_STR) == 0)
+ type_int = PLUGIN_MODIFIER_IRC_OUT;
+ else
+ return NULL;
+
+ new_modifier = (t_plugin_modifier *)malloc (sizeof (t_plugin_modifier));
+ if (new_modifier)
+ {
+ new_modifier->type = type_int;
+ new_modifier->command = (command) ? strdup (command) : strdup ("*");
+ new_modifier->modifier = modifier_func;
+ new_modifier->modifier_args = (modifier_args) ? strdup (modifier_args) : NULL;
+ new_modifier->modifier_pointer = modifier_pointer;
+ new_modifier->running = 0;
+
+ /* add new modifier to list */
+ new_modifier->prev_modifier = plugin->last_modifier;
+ new_modifier->next_modifier = NULL;
+ if (plugin->modifiers)
+ (plugin->last_modifier)->next_modifier = new_modifier;
+ else
+ plugin->modifiers = new_modifier;
+ plugin->last_modifier = new_modifier;
+ }
+ else
+ {
+ irc_display_prefix (NULL, NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s plugin %s: unable to add modifier (not enough memory)\n"),
+ WEECHAT_ERROR, plugin->name);
+ return NULL;
+ }
+ return new_modifier;
+}
+
+/*
+ * plugin_modifier_exec: execute a modifier
+ * return: NULL if no modifier was applied on message
+ * "" (empty string) if message has been dropped by a modifier
+ * other string if message has been modified
+ */
+
+char *
+plugin_modifier_exec (t_plugin_modifier_type type,
+ char *server, char *message)
+{
+ t_weechat_plugin *ptr_plugin;
+ t_plugin_modifier *ptr_modifier;
+ char *argv[2] = { NULL, NULL };
+ char *new_msg, *pos, *command;
+ int length_command;
+
+ argv[0] = server;
+ argv[1] = message;
+
+ command = NULL;
+ length_command = 0;
+ if ((type == PLUGIN_MODIFIER_IRC_IN) || (type == PLUGIN_MODIFIER_IRC_OUT))
+ {
+ /* look for command in message */
+ if (message[0] == ':')
+ {
+ pos = strchr (message, ' ');
+ if (pos)
+ {
+ while (pos[0] == ' ')
+ pos++;
+ command = pos;
+ }
+ }
+ else
+ command = message;
+ if (command)
+ {
+ pos = strchr (command, ' ');
+ if (pos)
+ length_command = pos - command;
+ else
+ length_command = strlen (command);
+ }
+ }
+
+ new_msg = NULL;
+
+ for (ptr_plugin = weechat_plugins; ptr_plugin;
+ ptr_plugin = ptr_plugin->next_plugin)
+ {
+ for (ptr_modifier = ptr_plugin->modifiers;
+ ptr_modifier; ptr_modifier = ptr_modifier->next_modifier)
+ {
+ if (ptr_modifier->type == type)
+ {
+ if (ptr_modifier->running == 0)
+ {
+ if (((type != PLUGIN_MODIFIER_IRC_IN) && (type != PLUGIN_MODIFIER_IRC_OUT))
+ || (ascii_strcasecmp (ptr_modifier->command, "*") == 0)
+ || (command && (ascii_strncasecmp (ptr_modifier->command, command, length_command) == 0)))
+ {
+ ptr_modifier->running = 1;
+ new_msg = ((char *) (ptr_modifier->modifier) (ptr_plugin,
+ 2, argv,
+ ptr_modifier->modifier_args,
+ ptr_modifier->modifier_pointer));
+ ptr_modifier->running = 0;
+
+ /* message dropped? */
+ if (new_msg && !new_msg[0])
+ return new_msg;
+
+ /* new message => keep it as base for next modifier */
+ if (new_msg)
+ {
+ /* free any new message allocated before by another modifier */
+ if (argv[1] != message)
+ free (argv[1]);
+ argv[1] = new_msg;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return new_msg;
+}
+
+/*
+ * plugin_modifier_remove: remove a modifier for a plugin
+ */
+
+void
+plugin_modifier_remove (t_weechat_plugin *plugin,
+ t_plugin_modifier *modifier)
+{
+ t_plugin_modifier *new_modifiers;
+
+ /* remove modifier from list */
+ if (plugin->last_modifier == modifier)
+ plugin->last_modifier = modifier->prev_modifier;
+ if (modifier->prev_modifier)
+ {
+ (modifier->prev_modifier)->next_modifier = modifier->next_modifier;
+ new_modifiers = plugin->modifiers;
+ }
+ else
+ new_modifiers = modifier->next_modifier;
+
+ if (modifier->next_modifier)
+ (modifier->next_modifier)->prev_modifier = modifier->prev_modifier;
+
+ /* free data */
+ if (modifier->command)
+ free (modifier->command);
+
+ plugin->modifiers = new_modifiers;
+}
+
+/*
+ * plugin_modifier_remove_all: remove all modifiers for a plugin
+ */
+
+void
+plugin_modifier_remove_all (t_weechat_plugin *plugin)
+{
+ while (plugin->modifiers)
+ plugin_modifier_remove (plugin, plugin->modifiers);
+}
+
+/*
* plugin_search_full_name: search the full name of a file with a part of name
* and look in WeeChat user's dir, then WeeChat global lib dir
*/
@@ -857,6 +1050,9 @@ plugin_load (char *filename)
new_plugin->keyboard_handler_add = &weechat_plugin_keyboard_handler_add;
new_plugin->handler_remove = &weechat_plugin_handler_remove;
new_plugin->handler_remove_all = &weechat_plugin_handler_remove_all;
+ new_plugin->modifier_add = &weechat_plugin_modifier_add;
+ new_plugin->modifier_remove = &weechat_plugin_modifier_remove;
+ new_plugin->modifier_remove_all = &weechat_plugin_modifier_remove_all;
new_plugin->print = &weechat_plugin_print;
new_plugin->print_server = &weechat_plugin_print_server;
new_plugin->print_infobar = &weechat_plugin_print_infobar;
@@ -889,6 +1085,10 @@ plugin_load (char *filename)
new_plugin->handlers = NULL;
new_plugin->last_handler = NULL;
+ /* modifiers */
+ new_plugin->modifiers = NULL;
+ new_plugin->last_modifier = NULL;
+
/* add new plugin to list */
new_plugin->prev_plugin = last_weechat_plugin;
new_plugin->next_plugin = NULL;
@@ -936,11 +1136,12 @@ plugin_load (char *filename)
}
/*
- * plugin_auto_load_file: load a file found by plugin_aut_load,
+ * plugin_auto_load_file: load a file found by plugin_auto_load,
* but only it this is really a dynamic library
*/
-int plugin_auto_load_file (t_weechat_plugin *plugin, char *filename)
+int
+plugin_auto_load_file (t_weechat_plugin *plugin, char *filename)
{
char *pos;
@@ -965,7 +1166,8 @@ int plugin_auto_load_file (t_weechat_plugin *plugin, char *filename)
* plugin_auto_load: auto-load WeeChat plugins
*/
-void plugin_auto_load ()
+void
+plugin_auto_load ()
{
char *ptr_home, *dir_name, *plugins_path, *plugins_path2;
char *list_plugins, *pos, *pos2;
@@ -1049,8 +1251,11 @@ plugin_remove (t_weechat_plugin *plugin)
if (plugin->next_plugin)
(plugin->next_plugin)->prev_plugin = plugin->prev_plugin;
- /* free data */
+ /* remove all handlers and modifiers */
plugin_handler_remove_all (plugin);
+ plugin_modifier_remove_all (plugin);
+
+ /* free data */
if (plugin->filename)
free (plugin->filename);
dlclose (plugin->handle);
@@ -1117,6 +1322,38 @@ plugin_unload_all ()
}
/*
+ * plugin_reload_name: reload a WeeChat plugin by name
+ */
+
+void
+plugin_reload_name (char *name)
+{
+ t_weechat_plugin *ptr_plugin;
+ char *filename;
+
+ ptr_plugin = plugin_search (name);
+ if (ptr_plugin)
+ {
+ filename = strdup (ptr_plugin->filename);
+ if (filename)
+ {
+ plugin_unload (ptr_plugin);
+ irc_display_prefix (NULL, NULL, PREFIX_PLUGIN);
+ gui_printf (NULL, _("Plugin \"%s\" unloaded.\n"), name);
+ plugin_load (filename);
+ free (filename);
+ }
+ }
+ else
+ {
+ irc_display_prefix (NULL, NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s plugin \"%s\" not found\n"),
+ WEECHAT_ERROR, name);
+ }
+}
+
+/*
* plugin_init: init plugin support
*/
diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h
index 1ea028129..ffa81408c 100644
--- a/src/plugins/plugins.h
+++ b/src/plugins/plugins.h
@@ -68,12 +68,21 @@ extern int plugin_keyboard_handler_exec (char *, char *, char *);
extern void plugin_handler_remove (t_weechat_plugin *,
t_plugin_handler *);
extern void plugin_handler_remove_all (t_weechat_plugin *);
+extern t_plugin_modifier *plugin_modifier_add (t_weechat_plugin *,
+ char *, char *,
+ t_plugin_modifier_func *,
+ char *, void *);
+extern char *plugin_modifier_exec (t_plugin_modifier_type, char *, char *);
+extern void plugin_modifier_remove (t_weechat_plugin *,
+ t_plugin_modifier *);
+extern void plugin_modifier_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 *);
extern void plugin_unload_all ();
+extern void plugin_reload_name (char *);
extern void plugin_init (int);
extern void plugin_end ();
diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c
index 950baf90e..fce16b30a 100644
--- a/src/plugins/scripts/lua/weechat-lua.c
+++ b/src/plugins/scripts/lua/weechat-lua.c
@@ -142,6 +142,23 @@ weechat_lua_keyboard_handler (t_weechat_plugin *plugin,
}
/*
+ * weechat_lua_modifier: general modifier for Lua
+ */
+
+char *
+weechat_lua_modifier (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *modifier_args, void *modifier_pointer)
+{
+ /*if (argc >= 2)
+ return weechat_lua_exec (plugin, (t_plugin_script *)modifier_pointer,
+ modifier_args, argv[0], argv[1], NULL);
+ else
+ return NULL;*/
+ return NULL;
+}
+
+/*
* weechat_lua_register: startup function for all WeeChat Lua scripts
*/
@@ -876,6 +893,108 @@ weechat_lua_remove_keyboard_handler (lua_State *L)
}
/*
+ * weechat_lua_add_modifier: add a modifier
+ */
+
+static int
+weechat_lua_add_modifier (lua_State *L)
+{
+ const char *type, *command, *function;
+ int n;
+
+ /* make gcc happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: unable to add modifier, "
+ "script not initialized");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
+ }
+
+ type = NULL;
+ command = NULL;
+ function = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n != 3)
+ {
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: wrong parameters for "
+ "\"add_modifier\" function");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
+ }
+
+ type = lua_tostring (lua_current_interpreter, -3);
+ command = lua_tostring (lua_current_interpreter, -2);
+ function = lua_tostring (lua_current_interpreter, -1);
+
+ if (!lua_plugin->modifier_add (lua_plugin, (char *)type, (char *)command,
+ weechat_lua_modifier,
+ (char *)function,
+ (void *)lua_current_script))
+ {
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
+ }
+
+ lua_pushnumber (lua_current_interpreter, 1);
+ return 1;
+}
+
+/*
+ * weechat_lua_remove_modifier: remove a modifier
+ */
+
+static int
+weechat_lua_remove_modifier (lua_State *L)
+{
+ const char *type, *command, *function;
+ int n;
+
+ /* make gcc happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: unable to remove modifier, "
+ "script not initialized");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
+ }
+
+ command = NULL;
+ function = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n != 2)
+ {
+ lua_plugin->print_server (lua_plugin,
+ "Lua error: wrong parameters for "
+ "\"remove_modifier\" function");
+ lua_pushnumber (lua_current_interpreter, 0);
+ return 1;
+ }
+
+ type = lua_tostring (lua_current_interpreter, -3);
+ command = lua_tostring (lua_current_interpreter, -2);
+ function = lua_tostring (lua_current_interpreter, -1);
+
+ weechat_script_remove_modifier (lua_plugin, lua_current_script,
+ (char *)type, (char *)command,
+ (char *)function);
+
+ lua_pushnumber (lua_current_interpreter, 1);
+ return 1;
+}
+
+/*
* weechat_lua_get_info: get various infos
*/
@@ -1882,40 +2001,42 @@ weechat_lua_constant_plugin_rc_ok_ignore_all (lua_State *L)
static
const struct luaL_reg weechat_lua_funcs[] = {
- { "register", weechat_lua_register},
- { "print", weechat_lua_print},
- { "print_server", weechat_lua_print_server},
- { "print_infobar", weechat_lua_print_infobar},
- { "remove_infobar", weechat_lua_remove_infobar},
- { "log", weechat_lua_log},
- { "command", weechat_lua_command},
- { "add_message_handler", weechat_lua_add_message_handler},
- { "add_command_handler", weechat_lua_add_command_handler},
- { "add_timer_handler", weechat_lua_add_timer_handler},
- { "add_keyboard_handler", weechat_lua_add_keyboard_handler},
- { "remove_handler", weechat_lua_remove_handler},
- { "remove_timer_handler", weechat_lua_remove_timer_handler},
- { "remove_keyboard_handler", weechat_lua_remove_keyboard_handler},
- { "get_info", weechat_lua_get_info},
- { "get_dcc_info", weechat_lua_get_dcc_info},
- { "get_config", weechat_lua_get_config},
- { "set_config", weechat_lua_set_config},
- { "get_plugin_config", weechat_lua_get_plugin_config},
- { "set_plugin_config", weechat_lua_set_plugin_config},
- { "get_server_info", weechat_lua_get_server_info},
- { "get_channel_info", weechat_lua_get_channel_info},
- { "get_nick_info", weechat_lua_get_nick_info},
- { "get_irc_color", weechat_lua_get_irc_color},
- { "get_window_info", weechat_lua_get_window_info},
- { "get_buffer_info", weechat_lua_get_buffer_info},
- { "get_buffer_data", weechat_lua_get_buffer_data},
+ { "register", weechat_lua_register },
+ { "print", weechat_lua_print },
+ { "print_server", weechat_lua_print_server },
+ { "print_infobar", weechat_lua_print_infobar },
+ { "remove_infobar", weechat_lua_remove_infobar },
+ { "log", weechat_lua_log },
+ { "command", weechat_lua_command },
+ { "add_message_handler", weechat_lua_add_message_handler },
+ { "add_command_handler", weechat_lua_add_command_handler },
+ { "add_timer_handler", weechat_lua_add_timer_handler },
+ { "add_keyboard_handler", weechat_lua_add_keyboard_handler },
+ { "remove_handler", weechat_lua_remove_handler },
+ { "remove_timer_handler", weechat_lua_remove_timer_handler },
+ { "remove_keyboard_handler", weechat_lua_remove_keyboard_handler },
+ { "add_modifier", weechat_lua_add_modifier },
+ { "remove_modifier", weechat_lua_remove_modifier },
+ { "get_info", weechat_lua_get_info },
+ { "get_dcc_info", weechat_lua_get_dcc_info },
+ { "get_config", weechat_lua_get_config },
+ { "set_config", weechat_lua_set_config },
+ { "get_plugin_config", weechat_lua_get_plugin_config },
+ { "set_plugin_config", weechat_lua_set_plugin_config },
+ { "get_server_info", weechat_lua_get_server_info },
+ { "get_channel_info", weechat_lua_get_channel_info },
+ { "get_nick_info", weechat_lua_get_nick_info },
+ { "get_irc_color", weechat_lua_get_irc_color },
+ { "get_window_info", weechat_lua_get_window_info },
+ { "get_buffer_info", weechat_lua_get_buffer_info },
+ { "get_buffer_data", weechat_lua_get_buffer_data },
/* define constants as function which returns values */
- { "PLUGIN_RC_OK", weechat_lua_constant_plugin_rc_ok},
- { "PLUGIN_RC_KO", weechat_lua_constant_plugin_rc_ko},
- { "PLUGIN_RC_OK_IGNORE_WEECHAT", weechat_lua_constant_plugin_rc_ok_ignore_weechat},
- { "PLUGIN_RC_OK_IGNORE_PLUGINS", weechat_lua_constant_plugin_rc_ok_ignore_plugins},
- { "PLUGIN_RC_OK_IGNORE_ALL", weechat_lua_constant_plugin_rc_ok_ignore_all},
- { NULL, NULL}
+ { "PLUGIN_RC_OK", weechat_lua_constant_plugin_rc_ok },
+ { "PLUGIN_RC_KO", weechat_lua_constant_plugin_rc_ko },
+ { "PLUGIN_RC_OK_IGNORE_WEECHAT", weechat_lua_constant_plugin_rc_ok_ignore_weechat },
+ { "PLUGIN_RC_OK_IGNORE_PLUGINS", weechat_lua_constant_plugin_rc_ok_ignore_plugins },
+ { "PLUGIN_RC_OK_IGNORE_ALL", weechat_lua_constant_plugin_rc_ok_ignore_all },
+ { NULL, NULL }
};
int
@@ -2142,7 +2263,7 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_MESSAGE)
+ if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -2161,7 +2282,7 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_COMMAND)
+ if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -2180,7 +2301,7 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_TIMER)
+ if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -2199,7 +2320,7 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_KEYBOARD)
+ if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
&& (ptr_handler->handler_args))
{
handler_found = 1;
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index c89b8c5a7..72c933dce 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -247,6 +247,23 @@ weechat_perl_keyboard_handler (t_weechat_plugin *plugin,
}
/*
+ * weechat_perl_modifier: general modifier for Perl
+ */
+
+char *
+weechat_perl_modifier (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *modifier_args, void *modifier_pointer)
+{
+ /*if (argc >= 2)
+ return weechat_perl_exec (plugin, (t_plugin_script *)modifier_pointer,
+ modifier_args, argv[0], argv[1], NULL);
+ else
+ return NULL;*/
+ return NULL;
+}
+
+/*
* weechat::register: startup function for all WeeChat Perl scripts
*/
@@ -819,6 +836,84 @@ static XS (XS_weechat_remove_keyboard_handler)
}
/*
+ * weechat::add_modifier: add a modifier
+ */
+
+static XS (XS_weechat_add_modifier)
+{
+ char *type, *command, *function;
+ dXSARGS;
+
+ /* make gcc happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ perl_plugin->print_server (perl_plugin,
+ "Perl error: unable to add modifier, "
+ "script not initialized");
+ XSRETURN_NO;
+ }
+
+ if (items < 3)
+ {
+ perl_plugin->print_server (perl_plugin,
+ "Perl error: wrong parameters for "
+ "\"add_modifier\" function");
+ XSRETURN_NO;
+ }
+
+ type = SvPV (ST (0), PL_na);
+ command = SvPV (ST (1), PL_na);
+ function = SvPV (ST (2), PL_na);
+
+ if (perl_plugin->modifier_add (perl_plugin, type, command,
+ weechat_perl_modifier, function,
+ (void *)perl_current_script))
+ XSRETURN_YES;
+
+ XSRETURN_NO;
+}
+
+/*
+ * weechat::remove_modifier: remove a modifier
+ */
+
+static XS (XS_weechat_remove_modifier)
+{
+ char *type, *command, *function;
+ dXSARGS;
+
+ /* make gcc happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ perl_plugin->print_server (perl_plugin,
+ "Perl error: unable to remove modifier, "
+ "script not initialized");
+ XSRETURN_NO;
+ }
+
+ if (items < 2)
+ {
+ perl_plugin->print_server (perl_plugin,
+ "Perl error: wrong parameters for "
+ "\"remove_modifier\" function");
+ XSRETURN_NO;
+ }
+
+ type = SvPV (ST (0), PL_na);
+ command = SvPV (ST (1), PL_na);
+ function = SvPV (ST (2), PL_na);
+
+ weechat_script_remove_modifier (perl_plugin, perl_current_script,
+ type, command, function);
+
+ XSRETURN_YES;
+}
+
+/*
* weechat::get_info: get various infos
*/
@@ -1599,6 +1694,8 @@ weechat_perl_xs_init (pTHX)
newXS ("weechat::remove_handler", XS_weechat_remove_handler, "weechat");
newXS ("weechat::remove_timer_handler", XS_weechat_remove_timer_handler, "weechat");
newXS ("weechat::remove_keyboard_handler", XS_weechat_remove_keyboard_handler, "weechat");
+ newXS ("weechat::add_modifier", XS_weechat_add_modifier, "weechat");
+ newXS ("weechat::remove_modifier", XS_weechat_remove_modifier, "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");
@@ -1869,7 +1966,7 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_MESSAGE)
+ if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -1888,7 +1985,7 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_COMMAND)
+ if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -1907,7 +2004,7 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_TIMER)
+ if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -1926,7 +2023,7 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_KEYBOARD)
+ if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
&& (ptr_handler->handler_args))
{
handler_found = 1;
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c
index a894f82b0..1b34d20b2 100644
--- a/src/plugins/scripts/python/weechat-python.c
+++ b/src/plugins/scripts/python/weechat-python.c
@@ -173,6 +173,23 @@ weechat_python_keyboard_handler (t_weechat_plugin *plugin,
}
/*
+ * weechat_python_modifier: general modifier for Python
+ */
+
+char *
+weechat_python_modifier (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *modifier_args, void *modifier_pointer)
+{
+ /*if (argc >= 2)
+ return weechat_python_exec (plugin, (t_plugin_script *)modifier_pointer,
+ modifier_args, argv[0], argv[1], NULL);
+ else
+ return NULL;*/
+ return NULL;
+}
+
+/*
* weechat_python_register: startup function for all WeeChat Python scripts
*/
@@ -736,6 +753,85 @@ weechat_python_remove_keyboard_handler (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_add_modifier: add a modifier
+ */
+
+static PyObject *
+weechat_python_add_modifier (PyObject *self, PyObject *args)
+{
+ char *type, *command, *function;
+
+ /* make gcc happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ python_plugin->print_server (python_plugin,
+ "Python error: unable to add modifier, "
+ "script not initialized");
+ return Py_BuildValue ("i", 0);
+ }
+
+ type = NULL;
+ command = NULL;
+ function = NULL;
+
+ if (!PyArg_ParseTuple (args, "sss", &type, &command, &function))
+ {
+ python_plugin->print_server (python_plugin,
+ "Python error: wrong parameters for "
+ "\"add_modifier\" function");
+ return Py_BuildValue ("i", 0);
+ }
+
+ if (python_plugin->modifier_add (python_plugin, type, command,
+ weechat_python_modifier,
+ function,
+ (void *)python_current_script))
+ return Py_BuildValue ("i", 1);
+
+ return Py_BuildValue ("i", 0);
+}
+
+/*
+ * weechat_python_remove_modifier: remove a modifier
+ */
+
+static PyObject *
+weechat_python_remove_modifier (PyObject *self, PyObject *args)
+{
+ char *type, *command, *function;
+
+ /* make gcc happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ python_plugin->print_server (python_plugin,
+ "Python error: unable to remove modifier, "
+ "script not initialized");
+ return Py_BuildValue ("i", 0);
+ }
+
+ type = NULL;
+ command = NULL;
+ function = NULL;
+
+ if (!PyArg_ParseTuple (args, "sss", &type, &command, &function))
+ {
+ python_plugin->print_server (python_plugin,
+ "Python error: wrong parameters for "
+ "\"remove_modifier\" function");
+ return Py_BuildValue ("i", 0);
+ }
+
+ weechat_script_remove_modifier (python_plugin, python_current_script,
+ type, command, function);
+
+ return Py_BuildValue ("i", 1);
+}
+
+/*
* weechat_python_get_info: get various infos
*/
@@ -1520,6 +1616,8 @@ PyMethodDef weechat_python_funcs[] = {
{ "remove_handler", weechat_python_remove_handler, METH_VARARGS, "" },
{ "remove_timer_handler", weechat_python_remove_timer_handler, METH_VARARGS, "" },
{ "remove_keyboard_handler", weechat_python_remove_keyboard_handler, METH_VARARGS, "" },
+ { "add_modifier", weechat_python_add_modifier, METH_VARARGS, "" },
+ { "remove_modifier", weechat_python_remove_modifier, 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, "" },
@@ -1815,7 +1913,7 @@ weechat_python_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_MESSAGE)
+ if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -1834,7 +1932,7 @@ weechat_python_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_COMMAND)
+ if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -1853,7 +1951,7 @@ weechat_python_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_TIMER)
+ if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -1872,7 +1970,7 @@ weechat_python_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_KEYBOARD)
+ if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
&& (ptr_handler->handler_args))
{
handler_found = 1;
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c
index 4e2cebf90..b5d6ad93e 100644
--- a/src/plugins/scripts/ruby/weechat-ruby.c
+++ b/src/plugins/scripts/ruby/weechat-ruby.c
@@ -79,7 +79,7 @@ protect_funcall0(VALUE arg)
*/
VALUE
-rb_protect_funcall(VALUE recv, ID mid, int *state, int argc, ...)
+rb_protect_funcall (VALUE recv, ID mid, int *state, int argc, ...)
{
va_list ap;
VALUE *argv;
@@ -219,6 +219,23 @@ weechat_ruby_keyboard_handler (t_weechat_plugin *plugin,
}
/*
+ * weechat_ruby_modifier: general modifier for Ruby
+ */
+
+char *
+weechat_ruby_modifier (t_weechat_plugin *plugin,
+ int argc, char **argv,
+ char *modifier_args, void *modifier_pointer)
+{
+ /*if (argc >= 2)
+ return weechat_ruby_exec (plugin, (t_plugin_script *)modifier_pointer,
+ modifier_args, argv[0], argv[1], NULL);
+ else
+ return NULL;*/
+ return NULL;
+}
+
+/*
* weechat_ruby_register: startup function for all WeeChat Ruby scripts
*/
@@ -931,6 +948,101 @@ weechat_ruby_remove_keyboard_handler (VALUE class, VALUE function)
}
/*
+ * weechat_ruby_add_modifier: add a modifier
+ */
+
+static VALUE
+weechat_ruby_add_modifier (VALUE class, VALUE type, VALUE message, VALUE function)
+{
+ char *c_type, *c_message, *c_function;
+
+ /* make gcc happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ ruby_plugin->print_server (ruby_plugin,
+ "Ruby error: unable to add modifier, "
+ "script not initialized");
+ return INT2FIX (0);
+ }
+
+ c_type = NULL;
+ c_message = NULL;
+ c_function = NULL;
+
+ if (NIL_P (type) || NIL_P (message) || NIL_P (function))
+ {
+ ruby_plugin->print_server (ruby_plugin,
+ "Ruby error: wrong parameters for "
+ "\"add_modifier\" function");
+ return INT2FIX (0);
+ }
+
+ Check_Type (type, T_STRING);
+ Check_Type (message, T_STRING);
+ Check_Type (function, T_STRING);
+
+ c_type = STR2CSTR (type);
+ c_message = STR2CSTR (message);
+ c_function = STR2CSTR (function);
+
+ if (ruby_plugin->modifier_add (ruby_plugin, c_type, c_message,
+ weechat_ruby_modifier,
+ c_function,
+ (void *)ruby_current_script))
+ return INT2FIX (1);
+
+ return INT2FIX (0);
+}
+
+/*
+ * weechat_ruby_remove_modifier: remove a modifier
+ */
+
+static VALUE
+weechat_ruby_remove_modifier (VALUE class, VALUE type, VALUE command, VALUE function)
+{
+ char *c_type, *c_command, *c_function;
+
+ /* make gcc happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ ruby_plugin->print_server (ruby_plugin,
+ "Ruby error: unable to remove modifier, "
+ "script not initialized");
+ return INT2FIX (0);
+ }
+
+ c_type = NULL;
+ c_command = NULL;
+ c_function = NULL;
+
+ if (NIL_P (type) || NIL_P (command) || NIL_P (function))
+ {
+ ruby_plugin->print_server (ruby_plugin,
+ "Ruby error: wrong parameters for "
+ "\"remove_modifier\" function");
+ return INT2FIX (0);
+ }
+
+ Check_Type (type, T_STRING);
+ Check_Type (command, T_STRING);
+ Check_Type (function, T_STRING);
+
+ c_type = STR2CSTR (type);
+ c_command = STR2CSTR (command);
+ c_function = STR2CSTR (function);
+
+ weechat_script_remove_modifier (ruby_plugin, ruby_current_script,
+ c_type, c_command, c_function);
+
+ return INT2FIX (1);
+}
+
+/*
* weechat_ruby_get_info: get various infos
*/
@@ -2022,7 +2134,7 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_MESSAGE)
+ if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -2041,7 +2153,7 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_COMMAND)
+ if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -2060,7 +2172,7 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_TIMER)
+ if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -2079,7 +2191,7 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
for (ptr_handler = plugin->handlers;
ptr_handler; ptr_handler = ptr_handler->next_handler)
{
- if ((ptr_handler->type == HANDLER_KEYBOARD)
+ if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
&& (ptr_handler->handler_args))
{
handler_found = 1;
@@ -2212,6 +2324,8 @@ weechat_plugin_init (t_weechat_plugin *plugin)
rb_define_module_function (ruby_mWeechat, "remove_handler", weechat_ruby_remove_handler, 2);
rb_define_module_function (ruby_mWeechat, "remove_timer_handler", weechat_ruby_remove_timer_handler, 1);
rb_define_module_function (ruby_mWeechat, "remove_keyboard_handler", weechat_ruby_remove_keyboard_handler, 1);
+ rb_define_module_function (ruby_mWeechat, "add_modifier", weechat_ruby_add_modifier, 3);
+ rb_define_module_function (ruby_mWeechat, "remove_modifier", weechat_ruby_remove_modifier, 3);
rb_define_module_function (ruby_mWeechat, "get_info", weechat_ruby_get_info, -1);
rb_define_module_function (ruby_mWeechat, "get_dcc_info", weechat_ruby_get_dcc_info, 0);
rb_define_module_function (ruby_mWeechat, "get_config", weechat_ruby_get_config, 1);
diff --git a/src/plugins/scripts/weechat-script.c b/src/plugins/scripts/weechat-script.c
index 148f0f4c8..8163fc054 100644
--- a/src/plugins/scripts/weechat-script.c
+++ b/src/plugins/scripts/weechat-script.c
@@ -293,9 +293,9 @@ weechat_script_remove_handler (t_weechat_plugin *plugin,
while (ptr_handler)
{
ptr_arg1 = NULL;
- if (ptr_handler->type == HANDLER_MESSAGE)
+ if (ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
ptr_arg1 = ptr_handler->irc_command;
- else if (ptr_handler->type == HANDLER_COMMAND)
+ else if (ptr_handler->type == PLUGIN_HANDLER_COMMAND)
ptr_arg1 = ptr_handler->command;
if ((ptr_arg1)
@@ -327,7 +327,7 @@ weechat_script_remove_timer_handler (t_weechat_plugin *plugin,
ptr_handler = plugin->handlers;
while (ptr_handler)
{
- if ((ptr_handler->type == HANDLER_TIMER)
+ if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
&& ((t_plugin_script *)ptr_handler->handler_pointer == script)
&& (plugin->ascii_strcasecmp (plugin, ptr_handler->handler_args, function) == 0))
{
@@ -355,7 +355,7 @@ weechat_script_remove_keyboard_handler (t_weechat_plugin *plugin,
ptr_handler = plugin->handlers;
while (ptr_handler)
{
- if ((ptr_handler->type == HANDLER_KEYBOARD)
+ if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
&& ((t_plugin_script *)ptr_handler->handler_pointer == script)
&& (plugin->ascii_strcasecmp (plugin, ptr_handler->handler_args, function) == 0))
{
@@ -369,6 +369,51 @@ weechat_script_remove_keyboard_handler (t_weechat_plugin *plugin,
}
/*
+ * weechat_script_remove_modifier: remove a modifier
+ * arg1=type, arg2=command, arg3=function
+ */
+
+void
+weechat_script_remove_modifier (t_weechat_plugin *plugin,
+ t_plugin_script *script,
+ char *arg1, char *arg2, char *arg3)
+{
+ t_plugin_modifier *ptr_modifier, *next_modifier;
+ t_plugin_modifier_type type;
+ char *ptr_arg2;
+
+ if (strcasecmp (arg1, PLUGIN_MODIFIER_IRC_IN_STR) == 0)
+ type = PLUGIN_MODIFIER_IRC_IN;
+ else if (strcasecmp (arg1, PLUGIN_MODIFIER_IRC_USER_STR) == 0)
+ type = PLUGIN_MODIFIER_IRC_USER;
+ else if (strcasecmp (arg1, PLUGIN_MODIFIER_IRC_OUT_STR) == 0)
+ type = PLUGIN_MODIFIER_IRC_OUT;
+ else
+ return;
+
+ /* search and remove modifiers */
+ ptr_modifier = plugin->modifiers;
+ while (ptr_modifier)
+ {
+ ptr_arg2 = NULL;
+ if (ptr_modifier->type == type)
+ ptr_arg2 = ptr_modifier->command;
+
+ if ((ptr_arg2)
+ && ((t_plugin_script *)ptr_modifier->modifier_pointer == script)
+ && (plugin->ascii_strcasecmp (plugin, ptr_arg2, arg2) == 0)
+ && (plugin->ascii_strcasecmp (plugin, ptr_modifier->modifier_args, arg3) == 0))
+ {
+ next_modifier = ptr_modifier->next_modifier;
+ plugin->modifier_remove (plugin, ptr_modifier);
+ ptr_modifier = next_modifier;
+ }
+ else
+ ptr_modifier = ptr_modifier->next_modifier;
+ }
+}
+
+/*
* weechat_script_get_plugin_config: get a value of a script option
* format in file is: plugin.script.option=value
*/
diff --git a/src/plugins/scripts/weechat-script.h b/src/plugins/scripts/weechat-script.h
index 922eaab7f..e18bfe37c 100644
--- a/src/plugins/scripts/weechat-script.h
+++ b/src/plugins/scripts/weechat-script.h
@@ -59,6 +59,9 @@ extern void weechat_script_remove_timer_handler (t_weechat_plugin *,
extern void weechat_script_remove_keyboard_handler (t_weechat_plugin *,
t_plugin_script *,
char *);
+extern void weechat_script_remove_modifier (t_weechat_plugin *,
+ t_plugin_script *,
+ char *, char *, char *);
extern char *weechat_script_get_plugin_config (t_weechat_plugin *,
t_plugin_script *,
char *);
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 3658a2c4b..1b9901f3e 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -183,25 +183,25 @@ struct t_plugin_buffer_line
typedef struct t_weechat_plugin t_weechat_plugin;
-typedef int (t_plugin_handler_func) (t_weechat_plugin *, int, char **, char *, void *);
-
/* handlers */
-typedef enum t_handler_type t_handler_type;
+typedef int (t_plugin_handler_func) (t_weechat_plugin *, int, char **, char *, void *);
+
+typedef enum t_plugin_handler_type t_plugin_handler_type;
-enum t_handler_type
+enum t_plugin_handler_type
{
- HANDLER_MESSAGE = 0, /* IRC message handler */
- HANDLER_COMMAND, /* command handler */
- HANDLER_TIMER, /* timer handler */
- HANDLER_KEYBOARD /* keyboard handler */
+ PLUGIN_HANDLER_MESSAGE = 0, /* IRC message handler */
+ PLUGIN_HANDLER_COMMAND, /* command handler */
+ PLUGIN_HANDLER_TIMER, /* timer handler */
+ PLUGIN_HANDLER_KEYBOARD /* keyboard handler */
};
typedef struct t_plugin_handler t_plugin_handler;
struct t_plugin_handler
{
- t_handler_type type; /* handler type */
+ t_plugin_handler_type type; /* handler type */
/* data for message handler */
char *irc_command; /* name of IRC command (PRIVMSG, ..) */
@@ -229,6 +229,46 @@ struct t_plugin_handler
t_plugin_handler *next_handler; /* link to next handler */
};
+/* modifiers */
+
+typedef char * (t_plugin_modifier_func) (t_weechat_plugin *, int, char **, char *, void *);
+
+typedef enum t_plugin_modifier_type t_plugin_modifier_type;
+
+enum t_plugin_modifier_type
+{
+ PLUGIN_MODIFIER_IRC_IN = 0, /* incoming IRC msg (server > user) */
+ PLUGIN_MODIFIER_IRC_USER, /* outgoing IRC msg (user > server) */
+ /* after user input (before 'out' mod.) */
+ PLUGIN_MODIFIER_IRC_OUT /* outgoing IRC msg (user > server) */
+ /* immediately before sending to server */
+};
+
+#define PLUGIN_MODIFIER_IRC_IN_STR "irc_in"
+#define PLUGIN_MODIFIER_IRC_USER_STR "irc_user"
+#define PLUGIN_MODIFIER_IRC_OUT_STR "irc_out"
+
+typedef struct t_plugin_modifier t_plugin_modifier;
+
+struct t_plugin_modifier
+{
+ t_plugin_modifier_type type; /* modifier type */
+
+ /* data for IRC modifier */
+ char *command; /* IRC command */
+
+ /* data common to all modifiers */
+ t_plugin_modifier_func *modifier; /* pointer to modifier */
+ char *modifier_args; /* arguments sent to modifier */
+ void *modifier_pointer; /* pointer sent to modifier */
+
+ /* for internal use */
+ int running; /* 1 if currently running */
+ /* (used to prevent circular call) */
+ t_plugin_modifier *prev_modifier; /* link to previous modifier */
+ t_plugin_modifier *next_modifier; /* link to next modifier */
+};
+
/* plugin, a WeeChat plugin, which is a dynamic library */
struct t_weechat_plugin
@@ -243,6 +283,10 @@ struct t_weechat_plugin
/* plugin handlers */
t_plugin_handler *handlers; /* pointer to first handler */
t_plugin_handler *last_handler; /* pointer to last handler */
+
+ /* plugin modifiers */
+ t_plugin_modifier *modifiers; /* pointer to first modifier */
+ t_plugin_modifier *last_modifier; /* pointer to last modifier */
/* links to previous/next plugins */
t_weechat_plugin *prev_plugin; /* link to previous plugin */
@@ -283,6 +327,12 @@ struct t_weechat_plugin
char *, void *);
void (*handler_remove) (t_weechat_plugin *, t_plugin_handler *);
void (*handler_remove_all) (t_weechat_plugin *);
+
+ t_plugin_modifier *(*modifier_add) (t_weechat_plugin *, char *, char *,
+ t_plugin_modifier_func *,
+ char *, void *);
+ void (*modifier_remove) (t_weechat_plugin *, t_plugin_modifier *);
+ void (*modifier_remove_all) (t_weechat_plugin *);
void (*exec_command) (t_weechat_plugin *, char *, char *, char *);
char *(*get_info) (t_weechat_plugin *, char *, char *);
@@ -351,6 +401,14 @@ extern t_plugin_handler *weechat_plugin_keyboard_handler_add (t_weechat_plugin *
extern void weechat_plugin_handler_remove (t_weechat_plugin *, t_plugin_handler *);
extern void weechat_plugin_handler_remove_all (t_weechat_plugin *);
+/* modifier functions */
+extern t_plugin_modifier *weechat_plugin_modifier_add (t_weechat_plugin *,
+ char *, char *,
+ t_plugin_modifier_func *,
+ char *, void *);
+extern void weechat_plugin_modifier_remove (t_weechat_plugin *, t_plugin_modifier *);
+extern void weechat_plugin_modifier_remove_all (t_weechat_plugin *);
+
/* other functions */
extern void weechat_plugin_exec_command (t_weechat_plugin *, char *, char *, char *);
extern char *weechat_plugin_get_info (t_weechat_plugin *, char *, char *);