1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 02:03:13 +02:00

Added new return codes for plugin handlers, to discard messages for WeeChat, plugins, or both.

This commit is contained in:
Sebastien Helleu
2005-10-28 07:31:21 +00:00
parent 232b5684ca
commit e26772dcdb
28 changed files with 2750 additions and 2158 deletions
+43 -40
View File
@@ -62,52 +62,46 @@ plugin_find_buffer (char *server, char *channel)
ptr_channel = NULL;
ptr_buffer = NULL;
if (server && server[0])
{
ptr_server = server_search (server);
if (!ptr_server)
return NULL;
}
/* nothing given => print on current buffer */
if ((!server || !server[0]) && (!channel || !channel[0]))
ptr_buffer = gui_current_window->buffer;
else
{
ptr_server = SERVER(gui_current_window->buffer);
if (!ptr_server)
ptr_server = SERVER(gui_buffers);
}
if (channel && channel[0])
{
if (ptr_server)
if (server && server[0])
{
ptr_channel = channel_search (ptr_server, channel);
if (ptr_channel)
ptr_buffer = ptr_channel->buffer;
ptr_server = server_search (server);
if (!ptr_server)
return NULL;
}
}
else
{
if (!channel)
else
{
ptr_server = SERVER(gui_current_window->buffer);
if (!ptr_server)
ptr_server = SERVER(gui_buffers);
}
if (channel && channel[0])
{
if (ptr_server)
ptr_buffer = ptr_server->buffer;
else
{
ptr_buffer = gui_current_window->buffer;
if (ptr_buffer->dcc)
ptr_buffer = gui_buffers;
ptr_channel = channel_search (ptr_server, channel);
if (ptr_channel)
ptr_buffer = ptr_channel->buffer;
}
}
else
{
if (ptr_server)
ptr_buffer = ptr_server->buffer;
else
ptr_buffer = gui_current_window->buffer;
}
}
if (!ptr_buffer)
return NULL;
return (ptr_buffer->dcc) ? NULL : ptr_buffer;
return (ptr_buffer->dcc) ? gui_buffers : ptr_buffer;
}
/*
@@ -315,7 +309,8 @@ plugin_cmd_handler_add (t_weechat_plugin *plugin, char *command,
/*
* plugin_msg_handler_exec: execute a message handler
* return: number of handlers executed (0 means no handler found)
* return: code for informing WeeChat whether message
* should be ignored or not
*/
int
@@ -323,9 +318,10 @@ plugin_msg_handler_exec (char *server, char *irc_command, char *irc_message)
{
t_weechat_plugin *ptr_plugin;
t_plugin_handler *ptr_handler;
int count;
int return_code, final_return_code;
final_return_code = PLUGIN_RC_OK;
count = 0;
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
@@ -338,20 +334,27 @@ plugin_msg_handler_exec (char *server, char *irc_command, char *irc_message)
if (ptr_handler->running == 0)
{
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++;
return_code = ((int) (ptr_handler->handler) (ptr_plugin,
server,
irc_command,
irc_message,
ptr_handler->handler_args,
ptr_handler->handler_pointer));
ptr_handler->running = 0;
if (return_code >= 0)
{
if (return_code & PLUGIN_RC_OK_IGNORE_WEECHAT)
final_return_code = PLUGIN_RC_OK_IGNORE_WEECHAT;
if (return_code & PLUGIN_RC_OK_IGNORE_PLUGINS)
return final_return_code;
}
}
}
}
}
return count;
return final_return_code;
}
/*
@@ -385,7 +388,7 @@ plugin_cmd_handler_exec (char *server, char *command, char *arguments)
ptr_handler->handler_args,
ptr_handler->handler_pointer);
ptr_handler->running = 0;
return (return_code) ? 1 : 0;
return (return_code == PLUGIN_RC_KO) ? 0 : 1;
}
}
}
@@ -658,7 +661,7 @@ plugin_load (char *filename)
new_plugin->name, new_plugin->version);
/* init plugin */
if (!((t_weechat_init_func *)init_func) (new_plugin))
if (((t_weechat_init_func *)init_func) (new_plugin) < 0)
{
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
+6 -6
View File
@@ -77,7 +77,7 @@ weechat_perl_exec (t_weechat_plugin *plugin,
SPAGAIN;
sv = GvSV (gv_fetchpv ("@", TRUE, SVt_PV));
return_code = 1;
return_code = PLUGIN_RC_KO;
if (SvTRUE (sv))
{
plugin->printf_server (plugin, "Perl error: %s", SvPV (sv, count));
@@ -114,9 +114,8 @@ weechat_perl_handler (t_weechat_plugin *plugin,
/* make gcc happy */
(void) command;
weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
handler_args, server, arguments);
return 1;
return weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
handler_args, server, arguments);
}
/*
@@ -211,6 +210,8 @@ static XS (XS_weechat_print)
XSRETURN_NO;
}
message = SvPV (ST (0), integer);
channel_name = NULL;
server_name = NULL;
@@ -221,7 +222,6 @@ static XS (XS_weechat_print)
server_name = SvPV (ST (2), integer);
}
message = SvPV (ST (0), integer);
perl_plugin->printf (perl_plugin,
server_name, channel_name,
"%s", message);
@@ -1072,7 +1072,7 @@ weechat_plugin_init (t_weechat_plugin *plugin)
weechat_script_auto_load (plugin, "perl", weechat_perl_load);
/* init ok */
return 1;
return PLUGIN_RC_OK;
}
/*
+27 -17
View File
@@ -52,31 +52,41 @@ weechat_python_exec (t_weechat_plugin *plugin,
PyObject *evMain;
PyObject *evDict;
PyObject *evFunc;
PyObject *rc;
int ret;
PyThreadState_Swap (NULL);
PyEval_AcquireLock ();
PyThreadState_Swap (script->interpreter);
evMain = PyImport_AddModule ((char *) "__main__");
evDict = PyModule_GetDict (evMain);
evFunc = PyDict_GetItemString (evDict, function);
if ( !(evFunc && PyCallable_Check (evFunc)) )
{
plugin->printf_server (plugin,
"Python error: unable to run function \"%s\"",
function);
PyEval_ReleaseLock();
return 1;
return PLUGIN_RC_KO;
}
ret = -1;
rc = PyObject_CallFunction(evFunc, "ss", server == NULL ? "" : server, arguments == NULL ? "" : arguments);
if (rc)
{
ret = (int) PyInt_AsLong(rc);
Py_XDECREF(rc);
}
PyObject_CallFunction(evFunc, "ss", server == NULL ? "" : server, arguments == NULL ? "" : arguments);
PyEval_ReleaseLock();
return 0;
if (ret < 0)
return PLUGIN_RC_OK;
else
return ret;
}
/*
@@ -91,9 +101,8 @@ weechat_python_handler (t_weechat_plugin *plugin,
/* make gcc happy */
(void) command;
weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
handler_args, server, arguments);
return 1;
return weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
handler_args, server, arguments);
}
/*
@@ -1104,7 +1113,7 @@ weechat_plugin_init (t_weechat_plugin *plugin)
{
plugin->printf_server (plugin,
"Python error: unable to launch global interpreter");
return 0;
return PLUGIN_RC_KO;
}
PySys_SetArgv(1, argv);
@@ -1117,7 +1126,7 @@ weechat_plugin_init (t_weechat_plugin *plugin)
{
plugin->printf_server (plugin,
"Python error: unable to get current interpreter state");
return 0;
return PLUGIN_RC_KO;
}
PyEval_ReleaseLock ();
@@ -1134,7 +1143,8 @@ weechat_plugin_init (t_weechat_plugin *plugin)
weechat_script_auto_load (plugin, "python", weechat_python_load);
return 1;
/* init ok */
return PLUGIN_RC_OK;
}
/*
+5 -5
View File
@@ -57,7 +57,7 @@ weechat_ruby_exec (t_weechat_plugin *plugin,
(void) arguments;
/* TODO: exec Ruby script */
return 0;
return PLUGIN_RC_OK;
}
/*
@@ -72,9 +72,8 @@ weechat_ruby_handler (t_weechat_plugin *plugin,
/* make gcc happy */
(void) command;
weechat_ruby_exec (plugin, (t_plugin_script *)handler_pointer,
handler_args, server, arguments);
return 1;
return weechat_ruby_exec (plugin, (t_plugin_script *)handler_pointer,
handler_args, server, arguments);
}
/*
@@ -962,7 +961,8 @@ weechat_plugin_init (t_weechat_plugin *plugin)
weechat_script_auto_load (plugin, "ruby", weechat_ruby_load);
return 1;
/* init ok */
return PLUGIN_RC_OK;
}
/*
+12
View File
@@ -22,6 +22,18 @@
#ifndef __WEECHAT_WEECHAT_PLUGIN_H
#define __WEECHAT_WEECHAT_PLUGIN_H 1
/* return codes for init function and handlers */
#define PLUGIN_RC_KO -1 /* function/handler failed */
#define PLUGIN_RC_OK 0 /* function/handler ok */
/* return codes specific to message handlers: messages can be discarded for
WeeChat, for plugins, or both */
#define PLUGIN_RC_OK_IGNORE_WEECHAT 1 /* ignore WeeChat for this message */
#define PLUGIN_RC_OK_IGNORE_PLUGINS 2 /* ignore other plugins for this msg */
#define PLUGIN_RC_OK_IGNORE_ALL (PLUGIN_RC_DISCARD_WEECHAT \
| PLUGIN_RC_DISCARD_PLUGINS)
/* ignore WeeChat and other plugins */
typedef struct t_plugin_dcc_info t_plugin_dcc_info;
struct t_plugin_dcc_info