diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/plugin-api.c | 25 | ||||
-rw-r--r-- | src/plugins/plugin-api.h | 5 | ||||
-rw-r--r-- | src/plugins/plugin.c | 1 | ||||
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua-api.c | 56 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl-api.c | 52 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python-api.c | 51 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby-api.c | 53 | ||||
-rw-r--r-- | src/plugins/scripts/script-api.c | 32 | ||||
-rw-r--r-- | src/plugins/scripts/script-api.h | 3 | ||||
-rw-r--r-- | src/plugins/scripts/tcl/weechat-tcl-api.c | 58 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 4 |
11 files changed, 289 insertions, 51 deletions
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 6dcb6d296..f0f310e73 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -133,12 +133,29 @@ plugin_api_config_set_plugin (struct t_weechat_plugin *plugin, const char *option_name, const char *value) { if (!plugin || !option_name) - return 0; + return WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND; - if (plugin_config_set (plugin->name, option_name, value)) - return 1; + return plugin_config_set (plugin->name, option_name, value); +} + +/* + * plugin_api_config_unset_plugin: unset plugin config option + */ + +int +plugin_api_config_unset_plugin (struct t_weechat_plugin *plugin, + const char *option_name) +{ + struct t_config_option *ptr_option; + + if (!plugin || !option_name) + return WEECHAT_CONFIG_OPTION_UNSET_ERROR; + + ptr_option = plugin_config_search (plugin->name, option_name); + if (!ptr_option) + return WEECHAT_CONFIG_OPTION_UNSET_ERROR; - return 0; + return config_file_option_unset (ptr_option); } /* diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h index 4e4353d02..df1ba31dd 100644 --- a/src/plugins/plugin-api.h +++ b/src/plugins/plugin-api.h @@ -32,7 +32,10 @@ extern struct t_config_option *plugin_api_config_get (const char *option_name); extern const char *plugin_api_config_get_plugin (struct t_weechat_plugin *plugin, const char *option_name); extern int plugin_api_config_set_plugin (struct t_weechat_plugin *plugin, - const char *option_name, const char *value); + const char *option_name, + const char *value); +extern int plugin_api_config_unset_plugin (struct t_weechat_plugin *plugin, + const char *option_name); /* display */ extern const char *plugin_api_prefix (const char *prefix); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 557561d4a..636734722 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -426,6 +426,7 @@ plugin_load (const char *filename) new_plugin->config_get = &plugin_api_config_get; new_plugin->config_get_plugin = &plugin_api_config_get_plugin; new_plugin->config_set_plugin = &plugin_api_config_set_plugin; + new_plugin->config_unset_plugin = &plugin_api_config_unset_plugin; new_plugin->prefix = &plugin_api_prefix; new_plugin->color = &plugin_api_color; diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 31fef65ca..be63780d3 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -2336,7 +2336,7 @@ static int weechat_lua_api_config_set_plugin (lua_State *L) { const char *option, *value; - int n; + int n, rc; /* make C compiler happy */ (void) L; @@ -2344,7 +2344,7 @@ weechat_lua_api_config_set_plugin (lua_State *L) if (!lua_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_set_plugin"); - LUA_RETURN_ERROR; + LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } option = NULL; @@ -2355,19 +2355,56 @@ weechat_lua_api_config_set_plugin (lua_State *L) if (n < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_set_plugin"); - LUA_RETURN_ERROR; + LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } option = lua_tostring (lua_current_interpreter, -2); value = lua_tostring (lua_current_interpreter, -1); - if (script_api_config_set_plugin (weechat_lua_plugin, - lua_current_script, - option, - value)) - LUA_RETURN_OK; + rc = script_api_config_set_plugin (weechat_lua_plugin, + lua_current_script, + option, + value); - LUA_RETURN_ERROR; + LUA_RETURN_INT(rc); +} + +/* + * weechat_lua_api_config_unset_plugin: unset plugin option + */ + +static int +weechat_lua_api_config_unset_plugin (lua_State *L) +{ + const char *option; + int n, rc; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_unset_plugin"); + LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); + } + + option = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_unset_plugin"); + LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); + } + + option = lua_tostring (lua_current_interpreter, -1); + + rc = script_api_config_unset_plugin (weechat_lua_plugin, + lua_current_script, + option); + + LUA_RETURN_INT(rc); } /* @@ -6053,6 +6090,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = { { "config_get", &weechat_lua_api_config_get }, { "config_get_plugin", &weechat_lua_api_config_get_plugin }, { "config_set_plugin", &weechat_lua_api_config_set_plugin }, + { "config_unset_plugin", &weechat_lua_api_config_unset_plugin }, { "prefix", &weechat_lua_api_prefix }, { "color", &weechat_lua_api_color }, { "print", &weechat_lua_api_print }, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index 0f393b04a..faca5fcec 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -1948,6 +1948,7 @@ static XS (XS_weechat_api_config_get_plugin) static XS (XS_weechat_api_config_set_plugin) { char *option, *value; + int rc; dXSARGS; /* make C compiler happy */ @@ -1956,24 +1957,56 @@ static XS (XS_weechat_api_config_set_plugin) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_set_plugin"); - PERL_RETURN_ERROR; + PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } if (items < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_set_plugin"); - PERL_RETURN_ERROR; + PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } - + option = SvPV (ST (0), PL_na); value = SvPV (ST (1), PL_na); - if (script_api_config_set_plugin (weechat_perl_plugin, - perl_current_script, - option, - value)) - PERL_RETURN_OK; + rc = script_api_config_set_plugin (weechat_perl_plugin, + perl_current_script, + option, + value); - PERL_RETURN_ERROR; + PERL_RETURN_INT(rc); +} + +/* + * weechat::config_unset_plugin: unset a plugin option + */ + +static XS (XS_weechat_api_config_unset_plugin) +{ + char *option; + int rc; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_unset_plugin"); + PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_unset_plugin"); + PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); + } + + option = SvPV (ST (0), PL_na); + rc = script_api_config_unset_plugin (weechat_perl_plugin, + perl_current_script, + option); + + PERL_RETURN_INT(rc); } /* @@ -4766,6 +4799,7 @@ weechat_perl_api_init (pTHX) newXS ("weechat::config_get", XS_weechat_api_config_get, "weechat"); newXS ("weechat::config_get_plugin", XS_weechat_api_config_get_plugin, "weechat"); newXS ("weechat::config_set_plugin", XS_weechat_api_config_set_plugin, "weechat"); + newXS ("weechat::config_unset_plugin", XS_weechat_api_config_unset_plugin, "weechat"); newXS ("weechat::prefix", XS_weechat_api_prefix, "weechat"); newXS ("weechat::color", XS_weechat_api_color, "weechat"); newXS ("weechat::print", XS_weechat_api_print, "weechat"); diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index c400e0997..bd9cfad00 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -2076,6 +2076,7 @@ static PyObject * weechat_python_api_config_set_plugin (PyObject *self, PyObject *args) { char *option, *value; + int rc; /* make C compiler happy */ (void) self; @@ -2083,7 +2084,7 @@ weechat_python_api_config_set_plugin (PyObject *self, PyObject *args) if (!python_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_set_plugin"); - PYTHON_RETURN_ERROR; + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } option = NULL; @@ -2092,16 +2093,49 @@ weechat_python_api_config_set_plugin (PyObject *self, PyObject *args) if (!PyArg_ParseTuple (args, "ss", &option, &value)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_set_plugin"); - PYTHON_RETURN_ERROR; + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } - if (script_api_config_set_plugin (weechat_python_plugin, - python_current_script, - option, - value)) - PYTHON_RETURN_OK; + rc = script_api_config_set_plugin (weechat_python_plugin, + python_current_script, + option, + value); - PYTHON_RETURN_ERROR; + PYTHON_RETURN_INT(rc); +} + +/* + * weechat_python_api_config_unset_plugin: unset plugin option + */ + +static PyObject * +weechat_python_api_config_unset_plugin (PyObject *self, PyObject *args) +{ + char *option; + int rc; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_unset_plugin"); + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); + } + + option = NULL; + + if (!PyArg_ParseTuple (args, "s", &option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_unset_plugin"); + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); + } + + rc = script_api_config_unset_plugin (weechat_python_plugin, + python_current_script, + option); + + PYTHON_RETURN_INT(rc); } /* @@ -5064,6 +5098,7 @@ PyMethodDef weechat_python_funcs[] = { "config_get", &weechat_python_api_config_get, METH_VARARGS, "" }, { "config_get_plugin", &weechat_python_api_config_get_plugin, METH_VARARGS, "" }, { "config_set_plugin", &weechat_python_api_config_set_plugin, METH_VARARGS, "" }, + { "config_unset_plugin", &weechat_python_api_config_unset_plugin, METH_VARARGS, "" }, { "prefix", &weechat_python_api_prefix, METH_VARARGS, "" }, { "color", &weechat_python_api_color, METH_VARARGS, "" }, { "prnt", &weechat_python_api_prnt, METH_VARARGS, "" }, diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index 0f6037489..636a3bda4 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -2384,6 +2384,7 @@ static VALUE weechat_ruby_api_config_set_plugin (VALUE class, VALUE option, VALUE value) { char *c_option, *c_value; + int rc; /* make C compiler happy */ (void) class; @@ -2391,13 +2392,13 @@ weechat_ruby_api_config_set_plugin (VALUE class, VALUE option, VALUE value) if (!ruby_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_set_plugin"); - RUBY_RETURN_ERROR; + RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } if (NIL_P (option) || NIL_P (value)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_set_plugin"); - RUBY_RETURN_ERROR; + RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } Check_Type (option, T_STRING); @@ -2406,13 +2407,48 @@ weechat_ruby_api_config_set_plugin (VALUE class, VALUE option, VALUE value) c_option = STR2CSTR (option); c_value = STR2CSTR (value); - if (script_api_config_set_plugin (weechat_ruby_plugin, - ruby_current_script, - c_option, - c_value)) - RUBY_RETURN_OK; + rc = script_api_config_set_plugin (weechat_ruby_plugin, + ruby_current_script, + c_option, + c_value); - RUBY_RETURN_ERROR; + RUBY_RETURN_INT(rc); +} + +/* + * weechat_ruby_api_config_unset_plugin: unset plugin option + */ + +static VALUE +weechat_ruby_api_config_unset_plugin (VALUE class, VALUE option) +{ + char *c_option; + int rc; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_unset_plugin"); + RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); + } + + if (NIL_P (option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_unset_plugin"); + RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); + } + + Check_Type (option, T_STRING); + + c_option = STR2CSTR (option); + + rc = script_api_config_unset_plugin (weechat_ruby_plugin, + ruby_current_script, + c_option); + + RUBY_RETURN_INT(rc); } /* @@ -5817,6 +5853,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) 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); rb_define_module_function (ruby_mWeechat, "config_set_plugin", &weechat_ruby_api_config_set_plugin, 2); + rb_define_module_function (ruby_mWeechat, "config_unset_plugin", &weechat_ruby_api_config_unset_plugin, 1); rb_define_module_function (ruby_mWeechat, "prefix", &weechat_ruby_api_prefix, 1); rb_define_module_function (ruby_mWeechat, "color", &weechat_ruby_api_color, 1); rb_define_module_function (ruby_mWeechat, "print", &weechat_ruby_api_print, 2); diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index d0fabb10a..911f1acb0 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -1314,7 +1314,7 @@ script_api_command (struct t_weechat_plugin *weechat_plugin, /* * script_api_config_get_plugin: get a value of a script option - * format in file is: plugin.script.option = value + * format in file is "plugin.script.option" */ const char * @@ -1342,7 +1342,7 @@ script_api_config_get_plugin (struct t_weechat_plugin *weechat_plugin, /* * script_api_config_set_plugin: set value of a script config option - * format in file is: plugin.script.option = value + * format in file is "plugin.script.option" */ int @@ -1367,3 +1367,31 @@ script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin, return return_code; } + +/* + * script_api_config_unset_plugin: unset script config option + * format in file is "plugin.script.option" + */ + +int +script_api_config_unset_plugin (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + const char *option) +{ + char *option_fullname; + int return_code; + + option_fullname = malloc ((strlen (script->name) + + strlen (option) + 2)); + if (!option_fullname) + return 0; + + strcpy (option_fullname, script->name); + strcat (option_fullname, "."); + strcat (option_fullname, option); + + return_code = weechat_config_unset_plugin (option_fullname); + free (option_fullname); + + return return_code; +} diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h index 871481305..f6f04caad 100644 --- a/src/plugins/scripts/script-api.h +++ b/src/plugins/scripts/script-api.h @@ -236,5 +236,8 @@ extern const char *script_api_config_get_plugin (struct t_weechat_plugin *weecha extern int script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, const char *option, const char *value); +extern int script_api_config_unset_plugin (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + const char *option); #endif /* script-api.h */ diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index f4216a70a..711be2e16 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -2260,7 +2260,7 @@ weechat_tcl_api_config_set_plugin (ClientData clientData, Tcl_Interp *interp, { Tcl_Obj *objp; char *option, *value; - int i; + int i, rc; /* make C compiler happy */ (void) clientData; @@ -2268,24 +2268,60 @@ weechat_tcl_api_config_set_plugin (ClientData clientData, Tcl_Interp *interp, if (!tcl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_set_plugin"); - TCL_RETURN_ERROR; + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } if (objc < 3) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_set_plugin"); - TCL_RETURN_ERROR; + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } - + option = Tcl_GetStringFromObj (objv[1], &i); value = Tcl_GetStringFromObj (objv[2], &i); - if (script_api_config_set_plugin (weechat_tcl_plugin, - tcl_current_script, - option, - value)) - TCL_RETURN_OK; - TCL_RETURN_ERROR; + rc = script_api_config_set_plugin (weechat_tcl_plugin, + tcl_current_script, + option, + value); + + TCL_RETURN_INT(rc); +} + +/* + * weechat_tcl_api_config_set_plugin: unset plugin option + */ + +static int +weechat_tcl_api_config_unset_plugin (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj *objp; + char *option; + int i, rc; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_unset_plugin"); + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); + } + + if (objc < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_unset_plugin"); + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); + } + + option = Tcl_GetStringFromObj (objv[1], &i); + + rc = script_api_config_unset_plugin (weechat_tcl_plugin, + tcl_current_script, + option); + + TCL_RETURN_INT(rc); } /* @@ -5499,6 +5535,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) { weechat_tcl_api_config_get_plugin, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::config_set_plugin", weechat_tcl_api_config_set_plugin, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp,"weechat::config_unset_plugin", + weechat_tcl_api_config_unset_plugin, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::prefix", weechat_tcl_api_prefix, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::color", diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index feba82a5b..e3b0bb8e5 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -321,6 +321,8 @@ struct t_weechat_plugin const char *option_name); int (*config_set_plugin) (struct t_weechat_plugin *plugin, const char *option_name, const char *value); + int (*config_unset_plugin) (struct t_weechat_plugin *plugin, + const char *option_name); /* display */ const char *(*prefix) (const char *prefix); @@ -866,6 +868,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); #define weechat_config_set_plugin(__option, __value) \ weechat_plugin->config_set_plugin(weechat_plugin, __option, \ __value) +#define weechat_config_unset_plugin(__option) \ + weechat_plugin->config_unset_plugin(weechat_plugin, __option) /* display */ #define weechat_prefix(__prefix) \ |