mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 00:03:12 +02:00
scripts: fix function unhook_all, fix deletion of configuration files when script is unloaded (bug #36977)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
WeeChat ChangeLog
|
||||
=================
|
||||
Sébastien Helleu <flashcode@flashtux.org>
|
||||
v0.3.9-dev, 2012-07-27
|
||||
v0.3.9-dev, 2012-07-29
|
||||
|
||||
|
||||
Version 0.3.9 (under dev!)
|
||||
@@ -62,6 +62,10 @@ Version 0.3.9 (under dev!)
|
||||
* relay: fix freeze when writing on relay socket (use non-blocking sockets in
|
||||
relay for irc and weechat protocols) (bug #36655)
|
||||
* ruby: detect ruby version 1.9.3 in cmake and autotools
|
||||
* scripts: fix deletion of configuration files when script is unloaded
|
||||
(bug #36977)
|
||||
* scripts: fix function unhook_all: delete only callbacks of hooks and add
|
||||
missing call to unhook
|
||||
* scripts: ignore call to "register" (with a warning) if script is already
|
||||
registered
|
||||
|
||||
|
||||
@@ -3365,7 +3365,7 @@ weechat_guile_api_unhook_all ()
|
||||
{
|
||||
API_FUNC(1, "unhook_all", API_RETURN_ERROR);
|
||||
|
||||
script_api_unhook_all (guile_current_script);
|
||||
script_api_unhook_all (weechat_guile_plugin, guile_current_script);
|
||||
|
||||
API_RETURN_OK;
|
||||
}
|
||||
|
||||
@@ -3666,7 +3666,7 @@ weechat_lua_api_unhook_all (lua_State *L)
|
||||
{
|
||||
API_FUNC(1, "unhook_all", API_RETURN_ERROR);
|
||||
|
||||
script_api_unhook_all (lua_current_script);
|
||||
script_api_unhook_all (weechat_lua_plugin, lua_current_script);
|
||||
|
||||
API_RETURN_OK;
|
||||
}
|
||||
|
||||
@@ -3480,7 +3480,7 @@ XS (XS_weechat_api_unhook_all)
|
||||
|
||||
API_FUNC(1, "unhook_all", API_RETURN_ERROR);
|
||||
|
||||
script_api_unhook_all (perl_current_script);
|
||||
script_api_unhook_all (weechat_perl_plugin, perl_current_script);
|
||||
|
||||
API_RETURN_OK;
|
||||
}
|
||||
|
||||
@@ -3626,7 +3626,7 @@ weechat_python_api_unhook_all (PyObject *self, PyObject *args)
|
||||
|
||||
API_FUNC(1, "unhook_all", API_RETURN_ERROR);
|
||||
|
||||
script_api_unhook_all (python_current_script);
|
||||
script_api_unhook_all (weechat_python_plugin, python_current_script);
|
||||
|
||||
API_RETURN_OK;
|
||||
}
|
||||
|
||||
@@ -4106,7 +4106,7 @@ weechat_ruby_api_unhook_all (VALUE class)
|
||||
{
|
||||
API_FUNC(1, "unhook_all", API_RETURN_ERROR);
|
||||
|
||||
script_api_unhook_all (ruby_current_script);
|
||||
script_api_unhook_all (weechat_ruby_plugin, ruby_current_script);
|
||||
|
||||
API_RETURN_OK;
|
||||
}
|
||||
|
||||
+338
-692
File diff suppressed because it is too large
Load Diff
@@ -298,7 +298,8 @@ extern struct t_hook *script_api_hook_focus (struct t_weechat_plugin *weechat_pl
|
||||
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);
|
||||
extern void script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script);
|
||||
extern struct t_gui_buffer *script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *name,
|
||||
|
||||
@@ -59,36 +59,37 @@ script_callback_alloc ()
|
||||
}
|
||||
|
||||
/*
|
||||
* script_callback_init: initialize callback with script, function and data
|
||||
* script_callback_add: allocate a new callback, initialize it
|
||||
* (script/function/data) and add it to list
|
||||
* return pointer to new callback or NULL if error
|
||||
*/
|
||||
|
||||
void
|
||||
script_callback_init (struct t_script_callback *script_callback,
|
||||
struct t_plugin_script *script,
|
||||
const char *function,
|
||||
const char *data)
|
||||
{
|
||||
if (script_callback)
|
||||
{
|
||||
script_callback->script = script;
|
||||
script_callback->function = (function) ? strdup (function) : NULL;
|
||||
script_callback->data = (data) ? strdup (data) : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* script_callback_add: add a callback to list
|
||||
*/
|
||||
|
||||
void
|
||||
struct t_script_callback *
|
||||
script_callback_add (struct t_plugin_script *script,
|
||||
struct t_script_callback *callback)
|
||||
const char *function,
|
||||
const char *data)
|
||||
{
|
||||
struct t_script_callback *script_cb;
|
||||
if (!script)
|
||||
return NULL;
|
||||
|
||||
script_cb = script_callback_alloc ();
|
||||
if (!script_cb)
|
||||
return NULL;
|
||||
|
||||
/* initialize callback */
|
||||
script_cb->script = script;
|
||||
script_cb->function = (function) ? strdup (function) : NULL;
|
||||
script_cb->data = (data) ? strdup (data) : NULL;
|
||||
|
||||
/* add callback to list */
|
||||
if (script->callbacks)
|
||||
script->callbacks->prev_callback = callback;
|
||||
callback->prev_callback = NULL;
|
||||
callback->next_callback = script->callbacks;
|
||||
script->callbacks = callback;
|
||||
script->callbacks->prev_callback = script_cb;
|
||||
script_cb->prev_callback = NULL;
|
||||
script_cb->next_callback = script->callbacks;
|
||||
script->callbacks = script_cb;
|
||||
|
||||
return script_cb;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -100,7 +101,7 @@ script_callback_free_data (struct t_script_callback *script_callback)
|
||||
{
|
||||
if (script_callback->function)
|
||||
free (script_callback->function);
|
||||
if (script_callback->data)
|
||||
if (script_callback->data)
|
||||
free (script_callback->data);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,14 +36,9 @@ struct t_script_callback
|
||||
struct t_script_callback *next_callback; /* link to previous callback */
|
||||
};
|
||||
|
||||
extern struct t_script_callback *script_callback_alloc ();
|
||||
extern void script_callback_init (struct t_script_callback *script_callback,
|
||||
struct t_plugin_script *script,
|
||||
const char *function,
|
||||
const char *data);
|
||||
extern void script_callback_add (struct t_plugin_script *script,
|
||||
struct t_script_callback *callback);
|
||||
extern void script_callback_free_data (struct t_script_callback *script_callback);
|
||||
extern struct t_script_callback *script_callback_add (struct t_plugin_script *script,
|
||||
const char *function,
|
||||
const char *data);
|
||||
extern void script_callback_remove (struct t_plugin_script *script,
|
||||
struct t_script_callback *script_callback);
|
||||
extern void script_callback_remove_all (struct t_plugin_script *script);
|
||||
|
||||
@@ -563,6 +563,7 @@ script_add (struct t_weechat_plugin *weechat_plugin,
|
||||
strdup (shutdown_func) : NULL;
|
||||
new_script->charset = (charset) ? strdup (charset) : NULL;
|
||||
new_script->callbacks = NULL;
|
||||
new_script->unloading = 0;
|
||||
|
||||
script_insert_sorted (weechat_plugin, scripts, last_script, new_script);
|
||||
|
||||
@@ -594,11 +595,11 @@ script_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin,
|
||||
{
|
||||
struct t_infolist *infolist;
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
const char *script_name, *script_input_cb, *script_input_cb_data;
|
||||
const char *script_close_cb, *script_close_cb_data;
|
||||
const char *script_name, *str_script_input_cb, *str_script_input_cb_data;
|
||||
const char *str_script_close_cb, *str_script_close_cb_data;
|
||||
struct t_plugin_script *ptr_script;
|
||||
struct t_script_callback *new_script_callback_input;
|
||||
struct t_script_callback *new_script_callback_close;
|
||||
struct t_script_callback *script_cb_input;
|
||||
struct t_script_callback *script_cb_close;
|
||||
|
||||
infolist = weechat_infolist_get ("buffer", NULL, NULL);
|
||||
if (infolist)
|
||||
@@ -615,53 +616,45 @@ script_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin,
|
||||
script_name);
|
||||
if (ptr_script && (ptr_script == script))
|
||||
{
|
||||
script_input_cb = weechat_buffer_get_string (ptr_buffer,
|
||||
"localvar_script_input_cb");
|
||||
script_input_cb_data = weechat_buffer_get_string (ptr_buffer,
|
||||
"localvar_script_input_cb_data");
|
||||
script_close_cb = weechat_buffer_get_string (ptr_buffer,
|
||||
"localvar_script_close_cb");
|
||||
script_close_cb_data = weechat_buffer_get_string (ptr_buffer,
|
||||
"localvar_script_close_cb_data");
|
||||
str_script_input_cb = weechat_buffer_get_string (ptr_buffer,
|
||||
"localvar_script_input_cb");
|
||||
str_script_input_cb_data = weechat_buffer_get_string (ptr_buffer,
|
||||
"localvar_script_input_cb_data");
|
||||
str_script_close_cb = weechat_buffer_get_string (ptr_buffer,
|
||||
"localvar_script_close_cb");
|
||||
str_script_close_cb_data = weechat_buffer_get_string (ptr_buffer,
|
||||
"localvar_script_close_cb_data");
|
||||
|
||||
if (script_input_cb && script_input_cb[0])
|
||||
if (str_script_input_cb && str_script_input_cb[0])
|
||||
{
|
||||
new_script_callback_input = script_callback_alloc ();
|
||||
if (new_script_callback_input)
|
||||
script_cb_input = script_callback_add (ptr_script,
|
||||
str_script_input_cb,
|
||||
str_script_input_cb_data);
|
||||
if (script_cb_input)
|
||||
{
|
||||
script_callback_init (new_script_callback_input,
|
||||
ptr_script,
|
||||
script_input_cb,
|
||||
script_input_cb_data);
|
||||
new_script_callback_input->buffer = ptr_buffer;
|
||||
script_callback_add (ptr_script,
|
||||
new_script_callback_input);
|
||||
script_cb_input->buffer = ptr_buffer;
|
||||
weechat_buffer_set_pointer (ptr_buffer,
|
||||
"input_callback",
|
||||
callback_buffer_input);
|
||||
weechat_buffer_set_pointer (ptr_buffer,
|
||||
"input_callback_data",
|
||||
new_script_callback_input);
|
||||
script_cb_input);
|
||||
}
|
||||
}
|
||||
if (script_close_cb && script_close_cb[0])
|
||||
if (str_script_close_cb && str_script_close_cb[0])
|
||||
{
|
||||
new_script_callback_close = script_callback_alloc ();
|
||||
if (new_script_callback_close)
|
||||
script_cb_close = script_callback_add (ptr_script,
|
||||
str_script_close_cb,
|
||||
str_script_close_cb_data);
|
||||
if (script_cb_close)
|
||||
{
|
||||
script_callback_init (new_script_callback_close,
|
||||
ptr_script,
|
||||
script_close_cb,
|
||||
script_close_cb_data);
|
||||
new_script_callback_close->buffer = ptr_buffer;
|
||||
script_callback_add (ptr_script,
|
||||
new_script_callback_close);
|
||||
script_cb_close->buffer = ptr_buffer;
|
||||
weechat_buffer_set_pointer (ptr_buffer,
|
||||
"close_callback",
|
||||
callback_buffer_close);
|
||||
weechat_buffer_set_pointer (ptr_buffer,
|
||||
"close_callback_data",
|
||||
new_script_callback_close);
|
||||
script_cb_close);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -682,20 +675,27 @@ script_remove_buffer_callbacks (struct t_plugin_script *scripts,
|
||||
struct t_gui_buffer *buffer)
|
||||
{
|
||||
struct t_plugin_script *ptr_script;
|
||||
struct t_script_callback *ptr_script_callback, *next_script_callback;
|
||||
struct t_script_callback *ptr_script_cb, *next_script_cb;
|
||||
|
||||
for (ptr_script = scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
ptr_script_callback = ptr_script->callbacks;
|
||||
while (ptr_script_callback)
|
||||
/*
|
||||
* do not remove buffer callbacks if script is being unloaded
|
||||
* (because all callbacks will be removed anyway)
|
||||
*/
|
||||
if (!ptr_script->unloading)
|
||||
{
|
||||
next_script_callback = ptr_script_callback->next_callback;
|
||||
ptr_script_cb = ptr_script->callbacks;
|
||||
while (ptr_script_cb)
|
||||
{
|
||||
next_script_cb = ptr_script_cb->next_callback;
|
||||
|
||||
if (ptr_script_callback->buffer == buffer)
|
||||
script_callback_remove (ptr_script, ptr_script_callback);
|
||||
if (ptr_script_cb->buffer == buffer)
|
||||
script_callback_remove (ptr_script, ptr_script_cb);
|
||||
|
||||
ptr_script_callback = next_script_callback;
|
||||
ptr_script_cb = next_script_cb;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -710,51 +710,55 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script **last_script,
|
||||
struct t_plugin_script *script)
|
||||
{
|
||||
struct t_script_callback *ptr_script_callback, *next_script_callback;
|
||||
struct t_script_callback *ptr_script_cb, *ptr_script_cb2;
|
||||
|
||||
for (ptr_script_callback = script->callbacks; ptr_script_callback;
|
||||
ptr_script_callback = ptr_script_callback->next_callback)
|
||||
script->unloading = 1;
|
||||
|
||||
for (ptr_script_cb = script->callbacks; ptr_script_cb;
|
||||
ptr_script_cb = ptr_script_cb->next_callback)
|
||||
{
|
||||
/* unhook */
|
||||
if (ptr_script_callback->hook)
|
||||
{
|
||||
weechat_unhook (ptr_script_callback->hook);
|
||||
}
|
||||
}
|
||||
|
||||
ptr_script_callback = script->callbacks;
|
||||
while (ptr_script_callback)
|
||||
{
|
||||
next_script_callback = ptr_script_callback->next_callback;
|
||||
|
||||
/* free config file */
|
||||
if (ptr_script_callback->config_file
|
||||
&& !ptr_script_callback->config_section
|
||||
&& !ptr_script_callback->config_option)
|
||||
if (ptr_script_cb->config_file)
|
||||
{
|
||||
if (weechat_config_boolean (weechat_config_get ("weechat.plugin.save_config_on_unload")))
|
||||
weechat_config_write (ptr_script_callback->config_file);
|
||||
weechat_config_free (ptr_script_callback->config_file);
|
||||
weechat_config_write (ptr_script_cb->config_file);
|
||||
weechat_config_free (ptr_script_cb->config_file);
|
||||
}
|
||||
|
||||
/* unhook */
|
||||
if (ptr_script_cb->hook)
|
||||
weechat_unhook (ptr_script_cb->hook);
|
||||
|
||||
/* close buffer */
|
||||
if (ptr_script_cb->buffer)
|
||||
weechat_buffer_close (ptr_script_cb->buffer);
|
||||
|
||||
/* remove bar item */
|
||||
if (ptr_script_callback->bar_item)
|
||||
weechat_bar_item_remove (ptr_script_callback->bar_item);
|
||||
if (ptr_script_cb->bar_item)
|
||||
weechat_bar_item_remove (ptr_script_cb->bar_item);
|
||||
|
||||
/* remove buffer */
|
||||
if (ptr_script_callback->buffer)
|
||||
/*
|
||||
* remove same pointers in other callbacks
|
||||
* (to not free 2 times with same pointer!)
|
||||
*/
|
||||
for (ptr_script_cb2 = ptr_script_cb->next_callback; ptr_script_cb2;
|
||||
ptr_script_cb2 = ptr_script_cb2->next_callback)
|
||||
{
|
||||
for (next_script_callback = ptr_script_callback->next_callback;
|
||||
next_script_callback;
|
||||
next_script_callback = next_script_callback->next_callback)
|
||||
{
|
||||
if (next_script_callback->buffer != ptr_script_callback->buffer)
|
||||
break;
|
||||
}
|
||||
weechat_buffer_close (ptr_script_callback->buffer);
|
||||
if (ptr_script_cb2->config_file == ptr_script_cb->config_file)
|
||||
ptr_script_cb2->config_file = NULL;
|
||||
if (ptr_script_cb2->config_section == ptr_script_cb->config_section)
|
||||
ptr_script_cb2->config_section = NULL;
|
||||
if (ptr_script_cb2->config_option == ptr_script_cb->config_option)
|
||||
ptr_script_cb2->config_option = NULL;
|
||||
if (ptr_script_cb2->hook == ptr_script_cb->hook)
|
||||
ptr_script_cb2->hook = NULL;
|
||||
if (ptr_script_cb2->buffer == ptr_script_cb->buffer)
|
||||
ptr_script_cb2->buffer = NULL;
|
||||
if (ptr_script_cb2->bar_item == ptr_script_cb->bar_item)
|
||||
ptr_script_cb2->bar_item = NULL;
|
||||
if (ptr_script_cb2->upgrade_file == ptr_script_cb->upgrade_file)
|
||||
ptr_script_cb2->upgrade_file = NULL;
|
||||
}
|
||||
|
||||
ptr_script_callback = next_script_callback;
|
||||
}
|
||||
|
||||
/* remove all callbacks created by this script */
|
||||
@@ -1175,6 +1179,8 @@ script_add_to_infolist (struct t_weechat_plugin *weechat_plugin,
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "charset", script->charset))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "unloading", script->unloading))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1264,7 +1270,7 @@ script_print_log (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *scripts)
|
||||
{
|
||||
struct t_plugin_script *ptr_script;
|
||||
struct t_script_callback *ptr_script_callback;
|
||||
struct t_script_callback *ptr_script_cb;
|
||||
|
||||
weechat_log_printf ("");
|
||||
weechat_log_printf ("***** \"%s\" plugin dump *****",
|
||||
@@ -1285,13 +1291,14 @@ script_print_log (struct t_weechat_plugin *weechat_plugin,
|
||||
weechat_log_printf (" shutdown_func . . . : '%s'", ptr_script->shutdown_func);
|
||||
weechat_log_printf (" charset . . . . . . : '%s'", ptr_script->charset);
|
||||
weechat_log_printf (" callbacks . . . . . : 0x%lx", ptr_script->callbacks);
|
||||
weechat_log_printf (" unloading . . . . . : %d", ptr_script->unloading);
|
||||
weechat_log_printf (" prev_script . . . . : 0x%lx", ptr_script->prev_script);
|
||||
weechat_log_printf (" next_script . . . . : 0x%lx", ptr_script->next_script);
|
||||
|
||||
for (ptr_script_callback = ptr_script->callbacks; ptr_script_callback;
|
||||
ptr_script_callback = ptr_script_callback->next_callback)
|
||||
for (ptr_script_cb = ptr_script->callbacks; ptr_script_cb;
|
||||
ptr_script_cb = ptr_script_cb->next_callback)
|
||||
{
|
||||
script_callback_print_log (weechat_plugin, ptr_script_callback);
|
||||
script_callback_print_log (weechat_plugin, ptr_script_cb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,9 +61,8 @@ struct t_plugin_script
|
||||
char *description; /* plugin description */
|
||||
char *shutdown_func; /* function when script is unloaded*/
|
||||
char *charset; /* script charset */
|
||||
|
||||
struct t_script_callback *callbacks; /* callbacks for script */
|
||||
|
||||
int unloading; /* script is being unloaded */
|
||||
struct t_plugin_script *prev_script; /* link to previous script */
|
||||
struct t_plugin_script *next_script; /* link to next script */
|
||||
};
|
||||
|
||||
@@ -3981,7 +3981,7 @@ weechat_tcl_api_unhook_all (ClientData clientData, Tcl_Interp *interp,
|
||||
|
||||
API_FUNC(1, "unhook_all", API_RETURN_ERROR);
|
||||
|
||||
script_api_unhook_all (tcl_current_script);
|
||||
script_api_unhook_all (weechat_tcl_plugin, tcl_current_script);
|
||||
|
||||
API_RETURN_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user