1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 13:56:37 +02:00

New "close callback" for buffers, use of this callback in IRC plugin to leave channel or disconnect from server when buffer is closed

This commit is contained in:
Sebastien Helleu
2008-02-01 18:56:12 +01:00
parent d15c1956b5
commit 184700e597
23 changed files with 442 additions and 194 deletions
+54 -12
View File
@@ -1164,7 +1164,7 @@ weechat_lua_api_config_option_change_cb (void *data)
if (script_callback->function && script_callback->function[0])
{
lua_argv[1] = NULL;
lua_argv[0] = NULL;
rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
@@ -2016,11 +2016,13 @@ int
weechat_lua_api_hook_timer_cb (void *data)
{
struct t_script_callback *script_callback;
char *lua_argv[1] = { NULL };
char *lua_argv[1];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
lua_argv[0] = NULL;
rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
@@ -2093,11 +2095,13 @@ int
weechat_lua_api_hook_fd_cb (void *data)
{
struct t_script_callback *script_callback;
char *lua_argv[1] = { NULL };
char *lua_argv[1];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
lua_argv[0] = NULL;
rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
@@ -2749,8 +2753,42 @@ weechat_lua_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
script_callback = (struct t_script_callback *)data;
lua_argv[0] = script_ptr2str (buffer);
lua_argv[2] = input_data;
lua_argv[3] = NULL;
lua_argv[1] = input_data;
lua_argv[2] = NULL;
rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
lua_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
if (lua_argv[0])
free (lua_argv[0]);
return ret;
}
/*
* weechat_lua_api_close_cb: callback for buffer closed
*/
int
weechat_lua_api_close_cb (void *data, struct t_gui_buffer *buffer)
{
struct t_script_callback *script_callback;
char *lua_argv[2];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
lua_argv[0] = script_ptr2str (buffer);
lua_argv[1] = NULL;
rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
@@ -2777,7 +2815,7 @@ weechat_lua_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
static int
weechat_lua_api_buffer_new (lua_State *L)
{
const char *category, *name, *function;
const char *category, *name, *function_input, *function_close;
char *result;
int n;
@@ -2792,26 +2830,30 @@ weechat_lua_api_buffer_new (lua_State *L)
category = NULL;
name = NULL;
function = NULL;
function_input = NULL;
function_close = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 3)
if (n < 4)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_new");
LUA_RETURN_EMPTY;
}
category = lua_tostring (lua_current_interpreter, -3);
name = lua_tostring (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
category = lua_tostring (lua_current_interpreter, -4);
name = lua_tostring (lua_current_interpreter, -3);
function_input = lua_tostring (lua_current_interpreter, -2);
function_close = lua_tostring (lua_current_interpreter, -1);
result = script_ptr2str (script_api_buffer_new (weechat_lua_plugin,
lua_current_script,
(char *)category,
(char *)name,
&weechat_lua_api_input_data_cb,
(char *)function));
(char *)function_input,
&weechat_lua_api_close_cb,
(char *)function_close));
LUA_RETURN_STRING_FREE(result);
}
+43 -4
View File
@@ -1601,11 +1601,13 @@ int
weechat_perl_api_hook_timer_cb (void *data)
{
struct t_script_callback *script_callback;
char *perl_argv[1] = { NULL };
char *perl_argv[1];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
perl_argv[0] = NULL;
rc = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
@@ -1664,11 +1666,13 @@ int
weechat_perl_api_hook_fd_cb (void *data)
{
struct t_script_callback *script_callback;
char *perl_argv[1] = { NULL };
char *perl_argv[1];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
perl_argv[0] = NULL;
rc = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
@@ -2247,6 +2251,39 @@ weechat_perl_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
return ret;
}
/*
* weechat_perl_api_close_cb: callback for buffer closed
*/
int
weechat_perl_api_close_cb (void *data, struct t_gui_buffer *buffer)
{
struct t_script_callback *script_callback;
char *perl_argv[2];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
perl_argv[0] = script_ptr2str (buffer);
perl_argv[1] = NULL;
rc = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
perl_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
if (perl_argv[0])
free (perl_argv[0]);
return ret;
}
/*
* weechat::buffer_new: create a new buffer
*/
@@ -2265,7 +2302,7 @@ static XS (XS_weechat_buffer_new)
PERL_RETURN_EMPTY;
}
if (items < 3)
if (items < 4)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_new");
PERL_RETURN_EMPTY;
@@ -2276,7 +2313,9 @@ static XS (XS_weechat_buffer_new)
SvPV (ST (0), PL_na), /* category */
SvPV (ST (1), PL_na), /* name */
&weechat_perl_api_input_data_cb,
SvPV (ST (2), PL_na))); /* perl function */
SvPV (ST (2), PL_na), /* function input */
&weechat_perl_api_close_cb,
SvPV (ST (3), PL_na))); /* function close */
PERL_RETURN_STRING_FREE(result);
}
@@ -1762,11 +1762,13 @@ int
weechat_python_api_hook_timer_cb (void *data)
{
struct t_script_callback *script_callback;
char *python_argv[1] = { NULL };
char *python_argv[1];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
python_argv[0] = NULL;
rc = (int *) weechat_python_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
@@ -1833,11 +1835,13 @@ int
weechat_python_api_hook_fd_cb (void *data)
{
struct t_script_callback *script_callback;
char *python_argv[1] = { NULL };
char *python_argv[1];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
python_argv[0] = NULL;
rc = (int *) weechat_python_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
@@ -2457,6 +2461,39 @@ weechat_python_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
return ret;
}
/*
* weechat_python_api_close_cb: callback for buffer closed
*/
int
weechat_python_api_close_cb (void *data, struct t_gui_buffer *buffer)
{
struct t_script_callback *script_callback;
char *python_argv[2];
int *r, ret;
script_callback = (struct t_script_callback *)data;
python_argv[0] = script_ptr2str (buffer);
python_argv[1] = NULL;
r = (int *) weechat_python_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
python_argv);
if (!r)
ret = WEECHAT_RC_ERROR;
else
{
ret = *r;
free (r);
}
if (python_argv[0])
free (python_argv[0]);
return ret;
}
/*
* weechat_python_api_buffer_new: create a new buffer
*/
@@ -2464,7 +2501,7 @@ weechat_python_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
static PyObject *
weechat_python_api_buffer_new (PyObject *self, PyObject *args)
{
char *category, *name, *function, *result;
char *category, *name, *function_input, *function_close, *result;
PyObject *object;
/* make C compiler happy */
@@ -2478,9 +2515,11 @@ weechat_python_api_buffer_new (PyObject *self, PyObject *args)
category = NULL;
name = NULL;
function = NULL;
function_input = NULL;
function_close = NULL;
if (!PyArg_ParseTuple (args, "sss", &category, &name, &function))
if (!PyArg_ParseTuple (args, "ssss", &category, &name, &function_input,
&function_close))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_new");
PYTHON_RETURN_EMPTY;
@@ -2491,7 +2530,9 @@ weechat_python_api_buffer_new (PyObject *self, PyObject *args)
category,
name,
&weechat_python_api_input_data_cb,
function));
function_input,
&weechat_python_api_close_cb,
function_close));
PYTHON_RETURN_STRING_FREE(result);
}
+55 -11
View File
@@ -1163,7 +1163,7 @@ weechat_ruby_api_config_option_change_cb (void *data)
if (script_callback->function && script_callback->function[0])
{
ruby_argv[1] = NULL;
ruby_argv[0] = NULL;
rc = (int *) weechat_ruby_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
@@ -2042,11 +2042,13 @@ int
weechat_ruby_api_hook_timer_cb (void *data)
{
struct t_script_callback *script_callback;
char *ruby_argv[1] = { NULL };
char *ruby_argv[1];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
ruby_argv[0] = NULL;
rc = (int *) weechat_ruby_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
@@ -2124,11 +2126,13 @@ int
weechat_ruby_api_hook_fd_cb (void *data)
{
struct t_script_callback *script_callback;
char *ruby_argv[1] = { NULL };
char *ruby_argv[1];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
ruby_argv[0] = NULL;
rc = (int *) weechat_ruby_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
@@ -2821,15 +2825,49 @@ weechat_ruby_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
return ret;
}
/*
* weechat_ruby_api_close_cb: callback for closed buffer
*/
int
weechat_ruby_api_close_cb (void *data, struct t_gui_buffer *buffer)
{
struct t_script_callback *script_callback;
char *ruby_argv[2];
int *rc, ret;
script_callback = (struct t_script_callback *)data;
ruby_argv[0] = script_ptr2str (buffer);
ruby_argv[1] = NULL;
rc = (int *) weechat_ruby_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
ruby_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
if (ruby_argv[0])
free (ruby_argv[0]);
return ret;
}
/*
* weechat_ruby_api_buffer_new: create a new buffer
*/
static VALUE
weechat_ruby_api_buffer_new (VALUE class, VALUE category, VALUE name,
VALUE function)
VALUE function_input, VALUE function_close)
{
char *c_category, *c_name, *c_function, *result;
char *c_category, *c_name, *c_function_input, *c_function_close, *result;
VALUE return_value;
/* make C compiler happy */
@@ -2843,9 +2881,11 @@ weechat_ruby_api_buffer_new (VALUE class, VALUE category, VALUE name,
c_category = NULL;
c_name = NULL;
c_function = NULL;
c_function_input = NULL;
c_function_close = NULL;
if (NIL_P (category) || NIL_P (name) || NIL_P (function))
if (NIL_P (category) || NIL_P (name) || NIL_P (function_input)
|| NIL_P (function_close))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_new");
RUBY_RETURN_EMPTY;
@@ -2853,18 +2893,22 @@ weechat_ruby_api_buffer_new (VALUE class, VALUE category, VALUE name,
Check_Type (category, T_STRING);
Check_Type (name, T_STRING);
Check_Type (function, T_STRING);
Check_Type (function_input, T_STRING);
Check_Type (function_close, T_STRING);
c_category = STR2CSTR (category);
c_name = STR2CSTR (name);
c_function = STR2CSTR (function);
c_function_input = STR2CSTR (function_input);
c_function_close = STR2CSTR (function_close);
result = script_ptr2str (script_api_buffer_new (weechat_ruby_plugin,
ruby_current_script,
c_category,
c_name,
&weechat_ruby_api_input_data_cb,
c_function));
c_function_input,
&weechat_ruby_api_close_cb,
c_function_close));
RUBY_RETURN_STRING_FREE(result);
}
@@ -3489,7 +3533,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "hook_modifier_exec", &weechat_ruby_api_hook_modifier_exec, 3);
rb_define_module_function (ruby_mWeechat, "unhook", &weechat_ruby_api_unhook, 1);
rb_define_module_function (ruby_mWeechat, "unhook_all", &weechat_ruby_api_unhook_all, 0);
rb_define_module_function (ruby_mWeechat, "buffer_new", &weechat_ruby_api_buffer_new, 3);
rb_define_module_function (ruby_mWeechat, "buffer_new", &weechat_ruby_api_buffer_new, 4);
rb_define_module_function (ruby_mWeechat, "buffer_search", &weechat_ruby_api_buffer_search, 2);
rb_define_module_function (ruby_mWeechat, "buffer_close", &weechat_ruby_api_buffer_close, 1);
rb_define_module_function (ruby_mWeechat, "buffer_get", &weechat_ruby_api_buffer_get, 2);
+61 -19
View File
@@ -710,34 +710,76 @@ struct t_gui_buffer *
script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *category, char *name,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
char *input_data),
char *function)
int (*input_callback)(void *data,
struct t_gui_buffer *buffer,
char *input_data),
char *function_input,
int (*close_callback)(void *data,
struct t_gui_buffer *buffer),
char *function_close)
{
struct t_script_callback *new_script_callback;
struct t_script_callback *new_script_callback_input;
struct t_script_callback *new_script_callback_close;
struct t_gui_buffer *new_buffer;
if (!function || !function[0])
return weechat_buffer_new (category, name, NULL, NULL);
if ((!function_input || !function_input[0])
&& (!function_close || !function_close[0]))
return weechat_buffer_new (category, name, NULL, NULL, NULL, NULL);
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
new_script_callback_input = NULL;
new_script_callback_close = NULL;
new_buffer = weechat_buffer_new (category, name,
callback, new_script_callback);
if (!new_buffer)
if (function_input && function_input[0])
{
free (new_script_callback);
return NULL;
new_script_callback_input = script_callback_alloc ();
if (!new_script_callback_input)
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
new_script_callback->buffer = new_buffer;
if (function_close && function_close[0])
{
new_script_callback_close = script_callback_alloc ();
if (!new_script_callback_close)
{
if (new_script_callback_input)
free (new_script_callback_input);
return NULL;
}
}
script_callback_add (script, new_script_callback);
new_buffer = weechat_buffer_new (category, name,
(new_script_callback_input) ?
input_callback : NULL,
(new_script_callback_input) ?
function_input : NULL,
(new_script_callback_close) ?
close_callback : NULL,
(new_script_callback_close) ?
function_close : NULL);
if (!new_buffer)
{
if (new_script_callback_input)
free (new_script_callback_input);
if (new_script_callback_close)
free (new_script_callback_close);
return NULL;
}
if (new_script_callback_input)
{
new_script_callback_input->script = script;
new_script_callback_input->function = strdup (function_input);
new_script_callback_input->buffer = new_buffer;
script_callback_add (script, new_script_callback_input);
}
if (new_script_callback_close)
{
new_script_callback_close->script = script;
new_script_callback_close->function = strdup (function_close);
new_script_callback_close->buffer = new_buffer;
script_callback_add (script, new_script_callback_close);
}
return new_buffer;
}
+10 -7
View File
@@ -137,13 +137,16 @@ extern void script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook);
extern void script_api_unhook_all (struct t_plugin_script *script);
struct t_gui_buffer *script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *category, char *name,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
char *input_data),
char *function);
extern struct t_gui_buffer *script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *category, char *name,
int (*input_callback)(void *data,
struct t_gui_buffer *buffer,
char *input_data),
char *function_input,
int (*close_callback)(void *data,
struct t_gui_buffer *buffer),
char *function_close);
extern void script_api_buffer_close (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,