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

Add missing config functions in script plugin API to free sections and options

This commit is contained in:
Sebastien Helleu
2009-02-21 21:31:46 +01:00
parent afdee2d919
commit a708f9f813
10 changed files with 648 additions and 14 deletions
+12 -8
View File
@@ -171,6 +171,7 @@ config_file_new_section (struct t_config_file *config_file, const char *name,
new_section = malloc (sizeof (*new_section));
if (new_section)
{
new_section->config_file = config_file;
new_section->name = strdup (name);
new_section->user_can_add_options = user_can_add_options;
new_section->user_can_delete_options = user_can_delete_options;
@@ -2245,21 +2246,23 @@ config_file_section_free_options (struct t_config_section *section)
*/
void
config_file_section_free (struct t_config_file *config_file,
struct t_config_section *section)
config_file_section_free (struct t_config_section *section)
{
struct t_config_file *ptr_config;
struct t_config_section *new_sections;
if (!config_file || !section)
if (!section)
return;
ptr_config = section->config_file;
/* remove section */
if (config_file->last_section == section)
config_file->last_section = section->prev_section;
if (ptr_config->last_section == section)
ptr_config->last_section = section->prev_section;
if (section->prev_section)
{
(section->prev_section)->next_section = section->next_section;
new_sections = config_file->sections;
new_sections = ptr_config->sections;
}
else
new_sections = section->next_section;
@@ -2274,7 +2277,7 @@ config_file_section_free (struct t_config_file *config_file,
free (section);
config_file->sections = new_sections;
ptr_config->sections = new_sections;
}
/*
@@ -2306,7 +2309,7 @@ config_file_free (struct t_config_file *config_file)
/* free data */
while (config_file->sections)
{
config_file_section_free (config_file, config_file->sections);
config_file_section_free (config_file->sections);
}
if (config_file->name)
free (config_file->name);
@@ -2689,6 +2692,7 @@ config_file_print_log ()
{
log_printf ("");
log_printf (" [section (addr:0x%lx)]", ptr_section);
log_printf (" config_file. . . . . . . . : 0x%lx", ptr_section->config_file);
log_printf (" name . . . . . . . . . . . : '%s'", ptr_section->name);
log_printf (" callback_read. . . . . . . : 0x%lx", ptr_section->callback_read);
log_printf (" callback_read_data . . . . : 0x%lx", ptr_section->callback_read_data);
+2 -2
View File
@@ -59,6 +59,7 @@ struct t_config_file
struct t_config_section
{
struct t_config_file *config_file; /* configuration file */
char *name; /* section name */
int user_can_add_options; /* user can add with /set ? */
int user_can_delete_options; /* user can del with /unset ? */
@@ -242,8 +243,7 @@ extern int config_file_read (struct t_config_file *config_file);
extern int config_file_reload (struct t_config_file *config_file);
extern void config_file_option_free (struct t_config_option *option);
extern void config_file_section_free_options (struct t_config_section *section);
extern void config_file_section_free (struct t_config_file *config_file,
struct t_config_section *section);
extern void config_file_section_free (struct t_config_section *section);
extern void config_file_free (struct t_config_file *config_file);
extern void config_file_free_all ();
extern void config_file_free_all_plugin (struct t_weechat_plugin *plugin);
+118
View File
@@ -2273,6 +2273,121 @@ weechat_lua_api_config_reload (lua_State *L)
LUA_RETURN_INT(rc);
}
/*
* weechat_lua_api_config_option_free: free an option in configuration file
*/
static int
weechat_lua_api_config_option_free (lua_State *L)
{
const char *option;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_free");
LUA_RETURN_ERROR;
}
option = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_free");
LUA_RETURN_ERROR;
}
option = lua_tostring (lua_current_interpreter, -1);
script_api_config_option_free (weechat_lua_plugin,
lua_current_script,
script_str2ptr (option));
LUA_RETURN_OK;
}
/*
* weechat_lua_api_config_section_free_options: free all options of a section
* in configuration file
*/
static int
weechat_lua_api_config_section_free_options (lua_State *L)
{
const char *section;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_section_free_options");
LUA_RETURN_ERROR;
}
section = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_section_free_options");
LUA_RETURN_ERROR;
}
section = lua_tostring (lua_current_interpreter, -1);
script_api_config_section_free_options (weechat_lua_plugin,
lua_current_script,
script_str2ptr (section));
LUA_RETURN_OK;
}
/*
* weechat_lua_api_config_section_free: free section in configuration file
*/
static int
weechat_lua_api_config_section_free (lua_State *L)
{
const char *section;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_section_free");
LUA_RETURN_ERROR;
}
section = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_section_free");
LUA_RETURN_ERROR;
}
section = lua_tostring (lua_current_interpreter, -1);
script_api_config_section_free (weechat_lua_plugin,
lua_current_script,
script_str2ptr (section));
LUA_RETURN_OK;
}
/*
* weechat_lua_api_config_free: free configuration file
*/
@@ -6300,6 +6415,9 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "config_write", &weechat_lua_api_config_write },
{ "config_read", &weechat_lua_api_config_read },
{ "config_reload", &weechat_lua_api_config_reload },
{ "config_option_free", &weechat_lua_api_config_option_free },
{ "config_section_free_options", &weechat_lua_api_config_section_free_options },
{ "config_section_free", &weechat_lua_api_config_section_free },
{ "config_free", &weechat_lua_api_config_free },
{ "config_get", &weechat_lua_api_config_get },
{ "config_get_plugin", &weechat_lua_api_config_get_plugin },
@@ -1903,6 +1903,97 @@ static XS (XS_weechat_api_config_reload)
PERL_RETURN_INT(rc);
}
/*
* weechat::config_option_free: free an option in configuration file
*/
static XS (XS_weechat_api_config_option_free)
{
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_free");
PERL_RETURN_ERROR;
}
if (items < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_free");
PERL_RETURN_ERROR;
}
script_api_config_option_free (weechat_perl_plugin,
perl_current_script,
script_str2ptr (SvPV (ST (0), PL_na))); /* option */
PERL_RETURN_OK;
}
/*
* weechat::config_section_free_options: free options of a section in
* configuration file
*/
static XS (XS_weechat_api_config_section_free_options)
{
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_section_free_options");
PERL_RETURN_ERROR;
}
if (items < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_section_free_options");
PERL_RETURN_ERROR;
}
script_api_config_section_free_options (weechat_perl_plugin,
perl_current_script,
script_str2ptr (SvPV (ST (0), PL_na))); /* section */
PERL_RETURN_OK;
}
/*
* weechat::config_section_free: free section in configuration file
*/
static XS (XS_weechat_api_config_section_free)
{
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_section_free");
PERL_RETURN_ERROR;
}
if (items < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_section_free");
PERL_RETURN_ERROR;
}
script_api_config_section_free (weechat_perl_plugin,
perl_current_script,
script_str2ptr (SvPV (ST (0), PL_na))); /* section */
PERL_RETURN_OK;
}
/*
* weechat::config_free: free configuration file
*/
@@ -4984,6 +5075,9 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::config_write", XS_weechat_api_config_write, "weechat");
newXS ("weechat::config_read", XS_weechat_api_config_read, "weechat");
newXS ("weechat::config_reload", XS_weechat_api_config_reload, "weechat");
newXS ("weechat::config_option_free", XS_weechat_api_config_option_free, "weechat");
newXS ("weechat::config_section_free_options", XS_weechat_api_config_section_free_options, "weechat");
newXS ("weechat::config_section_free", XS_weechat_api_config_section_free, "weechat");
newXS ("weechat::config_free", XS_weechat_api_config_free, "weechat");
newXS ("weechat::config_get", XS_weechat_api_config_get, "weechat");
newXS ("weechat::config_get_plugin", XS_weechat_api_config_get_plugin, "weechat");
@@ -2022,6 +2022,106 @@ weechat_python_api_config_reload (PyObject *self, PyObject *args)
PYTHON_RETURN_INT(rc);
}
/*
* weechat_python_api_config_option_free: free an option in configuration file
*/
static PyObject *
weechat_python_api_config_option_free (PyObject *self, PyObject *args)
{
char *option;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_free");
PYTHON_RETURN_ERROR;
}
option = NULL;
if (!PyArg_ParseTuple (args, "s", &option))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_free");
PYTHON_RETURN_ERROR;
}
script_api_config_option_free (weechat_python_plugin,
python_current_script,
script_str2ptr (option));
PYTHON_RETURN_OK;
}
/*
* weechat_python_api_config_section_free_options: free all options of a section
* in configuration file
*/
static PyObject *
weechat_python_api_config_section_free_options (PyObject *self, PyObject *args)
{
char *section;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_section_free_options");
PYTHON_RETURN_ERROR;
}
section = NULL;
if (!PyArg_ParseTuple (args, "s", &section))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_section_free_options");
PYTHON_RETURN_ERROR;
}
script_api_config_section_free_options (weechat_python_plugin,
python_current_script,
script_str2ptr (section));
PYTHON_RETURN_OK;
}
/*
* weechat_python_api_config_section_free: free section in configuration file
*/
static PyObject *
weechat_python_api_config_section_free (PyObject *self, PyObject *args)
{
char *section;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_section_free");
PYTHON_RETURN_ERROR;
}
section = NULL;
if (!PyArg_ParseTuple (args, "s", &section))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_section_free");
PYTHON_RETURN_ERROR;
}
script_api_config_section_free (weechat_python_plugin,
python_current_script,
script_str2ptr (section));
PYTHON_RETURN_OK;
}
/*
* weechat_python_api_config_free: free configuration file
*/
@@ -5286,6 +5386,9 @@ PyMethodDef weechat_python_funcs[] =
{ "config_write", &weechat_python_api_config_write, METH_VARARGS, "" },
{ "config_read", &weechat_python_api_config_read, METH_VARARGS, "" },
{ "config_reload", &weechat_python_api_config_reload, METH_VARARGS, "" },
{ "config_option_free", &weechat_python_api_config_option_free, METH_VARARGS, "" },
{ "config_section_free_options", &weechat_python_api_config_section_free_options, METH_VARARGS, "" },
{ "config_section_free", &weechat_python_api_config_section_free, METH_VARARGS, "" },
{ "config_free", &weechat_python_api_config_free, METH_VARARGS, "" },
{ "config_get", &weechat_python_api_config_get, METH_VARARGS, "" },
{ "config_get_plugin", &weechat_python_api_config_get_plugin, METH_VARARGS, "" },
+115
View File
@@ -2326,6 +2326,118 @@ weechat_ruby_api_config_reload (VALUE class, VALUE config_file)
RUBY_RETURN_INT(rc);
}
/*
* weechat_ruby_api_config_option_free: free an option in configuration file
*/
static VALUE
weechat_ruby_api_config_option_free (VALUE class, VALUE option)
{
char *c_option;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_free");
RUBY_RETURN_ERROR;
}
c_option = NULL;
if (NIL_P (option))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_free");
RUBY_RETURN_ERROR;
}
Check_Type (option, T_STRING);
c_option = STR2CSTR (option);
script_api_config_option_free (weechat_ruby_plugin,
ruby_current_script,
script_str2ptr (c_option));
RUBY_RETURN_OK;
}
/*
* weechat_ruby_api_config_section_free_options: free all options of a section
* in configuration file
*/
static VALUE
weechat_ruby_api_config_section_free_options (VALUE class, VALUE section)
{
char *c_section;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_section_free_options");
RUBY_RETURN_ERROR;
}
c_section = NULL;
if (NIL_P (section))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_section_free_options");
RUBY_RETURN_ERROR;
}
Check_Type (section, T_STRING);
c_section = STR2CSTR (section);
script_api_config_section_free_options (weechat_ruby_plugin,
ruby_current_script,
script_str2ptr (c_section));
RUBY_RETURN_OK;
}
/*
* weechat_ruby_api_config_section_free: free section in configuration file
*/
static VALUE
weechat_ruby_api_config_section_free (VALUE class, VALUE section)
{
char *c_section;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_section_free");
RUBY_RETURN_ERROR;
}
c_section = NULL;
if (NIL_P (section))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_section_free");
RUBY_RETURN_ERROR;
}
Check_Type (section, T_STRING);
c_section = STR2CSTR (section);
script_api_config_section_free (weechat_ruby_plugin,
ruby_current_script,
script_str2ptr (c_section));
RUBY_RETURN_OK;
}
/*
* weechat_ruby_api_config_free: free configuration file
*/
@@ -6053,6 +6165,9 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "config_write", &weechat_ruby_api_config_write, 1);
rb_define_module_function (ruby_mWeechat, "config_read", &weechat_ruby_api_config_read, 1);
rb_define_module_function (ruby_mWeechat, "config_reload", &weechat_ruby_api_config_reload, 1);
rb_define_module_function (ruby_mWeechat, "config_option_free", &weechat_ruby_api_config_option_free, 1);
rb_define_module_function (ruby_mWeechat, "config_section_free_options", &weechat_ruby_api_config_section_free_options, 1);
rb_define_module_function (ruby_mWeechat, "config_section_free", &weechat_ruby_api_config_section_free, 1);
rb_define_module_function (ruby_mWeechat, "config_free", &weechat_ruby_api_config_free, 1);
rb_define_module_function (ruby_mWeechat, "config_get", &weechat_ruby_api_config_get, 1);
rb_define_module_function (ruby_mWeechat, "config_get_plugin", &weechat_ruby_api_config_get_plugin, 1);
+86
View File
@@ -475,6 +475,92 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
return new_option;
}
/*
* script_api_config_option_free: free an option in configuration file
*/
void
script_api_config_option_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_option *option)
{
struct t_script_callback *ptr_script_callback, *next_callback;
if (!weechat_plugin || !script || !option)
return;
weechat_config_option_free (option);
ptr_script_callback = script->callbacks;
while (ptr_script_callback)
{
next_callback = ptr_script_callback->next_callback;
if (ptr_script_callback->config_option == option)
script_callback_remove (script, ptr_script_callback);
ptr_script_callback = next_callback;
}
}
/*
* script_api_config_section_free_options: free all options of a section in
* configuration file
*/
void
script_api_config_section_free_options (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_section *section)
{
struct t_script_callback *ptr_script_callback, *next_callback;
if (!weechat_plugin || !script || !section)
return;
weechat_config_section_free_options (section);
ptr_script_callback = script->callbacks;
while (ptr_script_callback)
{
next_callback = ptr_script_callback->next_callback;
if ((ptr_script_callback->config_section == section)
&& ptr_script_callback->config_option)
script_callback_remove (script, ptr_script_callback);
ptr_script_callback = next_callback;
}
}
/*
* script_api_config_section_free: free a section in configuration file
*/
void
script_api_config_section_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_section *section)
{
struct t_script_callback *ptr_script_callback, *next_callback;
if (!weechat_plugin || !script || !section)
return;
weechat_config_section_free (section);
ptr_script_callback = script->callbacks;
while (ptr_script_callback)
{
next_callback = ptr_script_callback->next_callback;
if (ptr_script_callback->config_section == section)
script_callback_remove (script, ptr_script_callback);
ptr_script_callback = next_callback;
}
}
/*
* script_api_config_free: free configuration file
*/
+9
View File
@@ -80,6 +80,15 @@ extern struct t_config_option *script_api_config_new_option (struct t_weechat_pl
void (*callback_delete)(void *data,
struct t_config_option *option),
const char *function_delete);
extern void script_api_config_option_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_option *option);
extern void script_api_config_section_free_options (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_section *section);
extern void script_api_config_section_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_section *section);
extern void script_api_config_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file);
+106
View File
@@ -2205,6 +2205,106 @@ weechat_tcl_api_config_reload (ClientData clientData, Tcl_Interp *interp,
TCL_RETURN_INT(rc);
}
/*
* weechat_tcl_api_config_option_free: free an option in configuration file
*/
static int
weechat_tcl_api_config_option_free (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *objp;
int i;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_free");
TCL_RETURN_ERROR;
}
if (objc < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_free");
TCL_RETURN_ERROR;
}
script_api_config_option_free (weechat_tcl_plugin,
tcl_current_script,
script_str2ptr (Tcl_GetStringFromObj (objv[1], &i))); /* option */
TCL_RETURN_OK;
}
/*
* weechat_tcl_api_config_section_free_options: free all options of a section
* in configuration file
*/
static int
weechat_tcl_api_config_section_free_options (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *objp;
int i;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_section_free_options");
TCL_RETURN_ERROR;
}
if (objc < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_section_free_options");
TCL_RETURN_ERROR;
}
script_api_config_section_free_options (weechat_tcl_plugin,
tcl_current_script,
script_str2ptr (Tcl_GetStringFromObj (objv[1], &i))); /* section */
TCL_RETURN_OK;
}
/*
* weechat_tcl_api_config_section_free: free section in configuration file
*/
static int
weechat_tcl_api_config_section_free (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *objp;
int i;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_section_free");
TCL_RETURN_ERROR;
}
if (objc < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_section_free");
TCL_RETURN_ERROR;
}
script_api_config_section_free (weechat_tcl_plugin,
tcl_current_script,
script_str2ptr (Tcl_GetStringFromObj (objv[1], &i))); /* section */
TCL_RETURN_OK;
}
/*
* weechat_tcl_api_config_free: free configuration file
*/
@@ -5724,6 +5824,12 @@ void weechat_tcl_api_init (Tcl_Interp *interp) {
weechat_tcl_api_config_read, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::config_reload",
weechat_tcl_api_config_reload, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::config_option_free",
weechat_tcl_api_config_option_free, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::config_section_free_options",
weechat_tcl_api_config_section_free_options, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::config_section_free",
weechat_tcl_api_config_section_free, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::config_free",
weechat_tcl_api_config_free, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::config_get",
+3 -4
View File
@@ -315,8 +315,7 @@ struct t_weechat_plugin
int (*config_reload) (struct t_config_file *config_file);
void (*config_option_free) (struct t_config_option *option);
void (*config_section_free_options) (struct t_config_section *section);
void (*config_section_free) (struct t_config_file *config_file,
struct t_config_section *section);
void (*config_section_free) (struct t_config_section *section);
void (*config_free) (struct t_config_file *config_file);
struct t_config_option *(*config_get) (const char *option_name);
const char *(*config_get_plugin) (struct t_weechat_plugin *plugin,
@@ -867,8 +866,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->config_option_free(__option)
#define weechat_config_section_free_options(__section) \
weechat_plugin->config_section_free_options(__section)
#define weechat_config_section_free(__config, __section) \
weechat_plugin->config_section_free(__config, __section)
#define weechat_config_section_free(__section) \
weechat_plugin->config_section_free(__section)
#define weechat_config_free(__config) \
weechat_plugin->config_free(__config)
#define weechat_config_get(__option) \