summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-02-21 07:06:01 +0100
committerSébastien Helleu <flashcode@flashtux.org>2023-03-16 20:42:18 +0100
commit66571a0b634ef28307f6d6ceef1ba29c091ca524 (patch)
tree08cc8a4eb2968952307dbfc394f51383f5dfc45e /src/plugins
parent7b8e5b36c0e894df40642b3ce993767844edc16b (diff)
downloadweechat-66571a0b634ef28307f6d6ceef1ba29c091ca524.zip
core: add configuration version, add API function config_set_version
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/guile/weechat-guile-api.c57
-rw-r--r--src/plugins/javascript/weechat-js-api.cpp58
-rw-r--r--src/plugins/lua/weechat-lua-api.c60
-rw-r--r--src/plugins/perl/weechat-perl-api.c66
-rw-r--r--src/plugins/php/weechat-php-api.c52
-rw-r--r--src/plugins/php/weechat-php-api.h1
-rw-r--r--src/plugins/php/weechat-php.c1
-rw-r--r--src/plugins/php/weechat-php.stub.php1
-rw-r--r--src/plugins/php/weechat-php_arginfo.h9
-rw-r--r--src/plugins/php/weechat-php_legacy_arginfo.h6
-rw-r--r--src/plugins/plugin-script-api.c48
-rw-r--r--src/plugins/plugin-script-api.h11
-rw-r--r--src/plugins/plugin.c1
-rw-r--r--src/plugins/python/weechat-python-api.c59
-rw-r--r--src/plugins/python/weechat.pyi47
-rw-r--r--src/plugins/ruby/weechat-ruby-api.c69
-rw-r--r--src/plugins/tcl/weechat-tcl-api.c70
-rw-r--r--src/plugins/weechat-plugin.h19
18 files changed, 620 insertions, 15 deletions
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c
index d5678e41e..bb7fb6689 100644
--- a/src/plugins/guile/weechat-guile-api.c
+++ b/src/plugins/guile/weechat-guile-api.c
@@ -902,6 +902,62 @@ weechat_guile_api_config_new (SCM name, SCM function, SCM data)
API_RETURN_STRING(result);
}
+struct t_hashtable *
+weechat_guile_api_config_update_cb (const void *pointer, void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read)
+{
+ struct t_plugin_script *script;
+ void *func_argv[4];
+ char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
+ struct t_hashtable *ret_hashtable;
+
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
+
+ if (ptr_function && ptr_function[0])
+ {
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
+ func_argv[1] = (char *)API_PTR2STR(config_file);
+ func_argv[2] = &version_read;
+ func_argv[3] = data_read;
+
+ ret_hashtable = weechat_guile_exec (script,
+ WEECHAT_SCRIPT_EXEC_HASHTABLE,
+ ptr_function,
+ "ssih", func_argv);
+
+ return ret_hashtable;
+ }
+
+ return NULL;
+}
+
+SCM
+weechat_guile_api_config_set_version (SCM config_file, SCM version,
+ SCM function, SCM data)
+{
+ int rc;
+
+ API_INIT_FUNC(1, "config_set_version", API_RETURN_INT(0));
+ if (!scm_is_string (config_file) || !scm_is_integer (version)
+ || !scm_is_string (function) || !scm_is_string (data))
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ rc = plugin_script_api_config_set_version (
+ weechat_guile_plugin,
+ guile_current_script,
+ API_STR2PTR(API_SCM_TO_STRING(config_file)),
+ scm_to_int (version),
+ &weechat_guile_api_config_update_cb,
+ API_SCM_TO_STRING(function),
+ API_SCM_TO_STRING(data));
+
+ API_RETURN_INT(rc);
+}
+
int
weechat_guile_api_config_read_cb (const void *pointer, void *data,
struct t_config_file *config_file,
@@ -5150,6 +5206,7 @@ weechat_guile_api_module_init (void *data)
API_DEF_FUNC(list_remove_all, 1);
API_DEF_FUNC(list_free, 1);
API_DEF_FUNC(config_new, 3);
+ API_DEF_FUNC(config_set_version, 4);
API_DEF_FUNC(config_new_section, 1);
API_DEF_FUNC(config_search_section, 2);
API_DEF_FUNC(config_new_option, 1);
diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp
index e05419048..c6aabe0fe 100644
--- a/src/plugins/javascript/weechat-js-api.cpp
+++ b/src/plugins/javascript/weechat-js-api.cpp
@@ -835,6 +835,63 @@ API_FUNC(config_new)
API_RETURN_STRING(result);
}
+struct t_hashtable *
+weechat_js_api_config_update_cb (const void *pointer, void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read)
+{
+ struct t_plugin_script *script;
+ void *func_argv[4];
+ char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
+ struct t_hashtable *ret_hashtable;
+
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
+
+ if (ptr_function && ptr_function[0])
+ {
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
+ func_argv[1] = (char *)API_PTR2STR(config_file);
+ func_argv[2] = &version_read;
+ func_argv[3] = data_read;
+
+ ret_hashtable = (struct t_hashtable *)weechat_js_exec (
+ script,
+ WEECHAT_SCRIPT_EXEC_HASHTABLE,
+ ptr_function,
+ "ssih", func_argv);
+
+ return ret_hashtable;
+ }
+
+ return NULL;
+}
+
+API_FUNC(config_set_version)
+{
+ int rc, version;
+
+ API_INIT_FUNC(1, "config_set_version", "siss", API_RETURN_INT(0));
+
+ v8::String::Utf8Value config_file(args[0]);
+ version = args[1]->IntegerValue();
+ v8::String::Utf8Value function(args[2]);
+ v8::String::Utf8Value data(args[3]);
+
+ rc = plugin_script_api_config_set_version (
+ weechat_js_plugin,
+ js_current_script,
+ (struct t_config_file *)API_STR2PTR(*config_file),
+ version,
+ &weechat_js_api_config_update_cb,
+ *function,
+ *data);
+
+ API_RETURN_INT(rc);
+}
+
int
weechat_js_api_config_read_cb (const void *pointer, void *data,
struct t_config_file *config_file,
@@ -5092,6 +5149,7 @@ WeechatJsV8::loadLibs()
API_DEF_FUNC(list_remove_all);
API_DEF_FUNC(list_free);
API_DEF_FUNC(config_new);
+ API_DEF_FUNC(config_set_version);
API_DEF_FUNC(config_new_section);
API_DEF_FUNC(config_search_section);
API_DEF_FUNC(config_new_option);
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index 69ef607e5..b22014c90 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -940,6 +940,65 @@ API_FUNC(config_new)
API_RETURN_STRING(result);
}
+struct t_hashtable *
+weechat_lua_api_config_update_cb (const void *pointer, void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read)
+{
+ struct t_plugin_script *script;
+ void *func_argv[4];
+ char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
+ struct t_hashtable *ret_hashtable;
+
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
+
+ if (ptr_function && ptr_function[0])
+ {
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
+ func_argv[1] = (char *)API_PTR2STR(config_file);
+ func_argv[2] = &version_read;
+ func_argv[3] = data_read;
+
+ ret_hashtable = weechat_lua_exec (script,
+ WEECHAT_SCRIPT_EXEC_HASHTABLE,
+ ptr_function,
+ "ssih", func_argv);
+
+ return ret_hashtable;
+ }
+
+ return NULL;
+}
+
+API_FUNC(config_set_version)
+{
+ const char *config_file, *function, *data;
+ int rc, version;
+
+ API_INIT_FUNC(1, "config_set_version", API_RETURN_INT(0));
+ if (lua_gettop (L) < 4)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ config_file = lua_tostring (L, -4);
+ version = lua_tonumber (L, -3);
+ function = lua_tostring (L, -2);
+ data = lua_tostring (L, -1);
+
+ rc = plugin_script_api_config_set_version (
+ weechat_lua_plugin,
+ lua_current_script,
+ API_STR2PTR(config_file),
+ version,
+ &weechat_lua_api_config_update_cb,
+ function,
+ data);
+
+ API_RETURN_INT(rc);
+}
+
int
weechat_lua_api_config_read_cb (const void *pointer, void *data,
struct t_config_file *config_file,
@@ -5451,6 +5510,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(list_remove_all),
API_DEF_FUNC(list_free),
API_DEF_FUNC(config_new),
+ API_DEF_FUNC(config_set_version),
API_DEF_FUNC(config_new_section),
API_DEF_FUNC(config_search_section),
API_DEF_FUNC(config_new_option),
diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c
index b8b0dac13..6a4e074d2 100644
--- a/src/plugins/perl/weechat-perl-api.c
+++ b/src/plugins/perl/weechat-perl-api.c
@@ -881,6 +881,65 @@ API_FUNC(config_new)
API_RETURN_STRING(result);
}
+struct t_hashtable *
+weechat_perl_api_config_update_cb (const void *pointer, void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read)
+{
+ struct t_plugin_script *script;
+ void *func_argv[4];
+ char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
+ struct t_hashtable *ret_hashtable;
+
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
+
+ if (ptr_function && ptr_function[0])
+ {
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
+ func_argv[1] = (char *)API_PTR2STR(config_file);
+ func_argv[2] = &version_read;
+ func_argv[3] = data_read;
+
+ ret_hashtable = weechat_perl_exec (script,
+ WEECHAT_SCRIPT_EXEC_HASHTABLE,
+ ptr_function,
+ "ssih", func_argv);
+
+ return ret_hashtable;
+ }
+
+ return NULL;
+}
+
+API_FUNC(config_set_version)
+{
+ char *config_file, *function, *data;
+ int rc;
+ dXSARGS;
+
+ API_INIT_FUNC(1, "config_set_version", API_RETURN_INT(0));
+ if (items < 4)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ config_file = SvPV_nolen (ST (0));
+ function = SvPV_nolen (ST (2));
+ data = SvPV_nolen (ST (3));
+
+ rc = plugin_script_api_config_set_version (
+ weechat_perl_plugin,
+ perl_current_script,
+ API_STR2PTR(config_file),
+ SvIV (ST (1)), /* version */
+ &weechat_perl_api_config_update_cb,
+ function,
+ data);
+
+ API_RETURN_INT(rc);
+}
+
int
weechat_perl_api_config_section_read_cb (const void *pointer, void *data,
struct t_config_file *config_file,
@@ -1088,7 +1147,7 @@ weechat_perl_api_config_section_delete_option_cb (const void *pointer, void *dat
API_FUNC(config_new_section)
{
- char *cfg_file, *name, *function_read, *data_read;
+ char *config_file, *name, *function_read, *data_read;
char *function_write, *data_write, *function_write_default;
char *data_write_default, *function_create_option, *data_create_option;
char *function_delete_option, *data_delete_option;
@@ -1100,7 +1159,7 @@ API_FUNC(config_new_section)
if (items < 14)
API_WRONG_ARGS(API_RETURN_EMPTY);
- cfg_file = SvPV_nolen (ST (0));
+ config_file = SvPV_nolen (ST (0));
name = SvPV_nolen (ST (1));
function_read = SvPV_nolen (ST (4));
data_read = SvPV_nolen (ST (5));
@@ -1117,7 +1176,7 @@ API_FUNC(config_new_section)
plugin_script_api_config_new_section (
weechat_perl_plugin,
perl_current_script,
- API_STR2PTR(cfg_file),
+ API_STR2PTR(config_file),
name,
SvIV (ST (2)), /* user_can_add_options */
SvIV (ST (3)), /* user_can_delete_options */
@@ -5400,6 +5459,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(list_remove_all);
API_DEF_FUNC(list_free);
API_DEF_FUNC(config_new);
+ API_DEF_FUNC(config_set_version);
API_DEF_FUNC(config_new_section);
API_DEF_FUNC(config_search_section);
API_DEF_FUNC(config_new_option);
diff --git a/src/plugins/php/weechat-php-api.c b/src/plugins/php/weechat-php-api.c
index 112af9709..7b1b918f8 100644
--- a/src/plugins/php/weechat-php-api.c
+++ b/src/plugins/php/weechat-php-api.c
@@ -1072,6 +1072,58 @@ API_FUNC(config_new)
API_RETURN_STRING(result);
}
+struct t_hashtable *
+weechat_php_api_config_update_cb (const void *pointer, void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read)
+{
+ struct t_hashtable *rc;
+ void *func_argv[4];
+
+ func_argv[1] = (char *)API_PTR2STR(config_file);
+ func_argv[2] = &version_read;
+ func_argv[3] = data_read;
+
+ weechat_php_cb (pointer, data, func_argv, "ssih",
+ WEECHAT_SCRIPT_EXEC_HASHTABLE, &rc);
+
+ return rc;
+}
+
+API_FUNC(config_set_version)
+{
+ zend_string *z_config_file;
+ zend_long z_version;
+ zval *z_callback_update;
+ zend_string *z_data;
+ struct t_config_file *config_file;
+ char *data;
+ int rc, version;
+
+ API_INIT_FUNC(1, "config_set_version", API_RETURN_INT(0));
+ if (zend_parse_parameters (ZEND_NUM_ARGS(), "SlzS", &z_config_file,
+ &z_version, &z_callback_update,
+ &z_data) == FAILURE)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ config_file = (struct t_config_file *)API_STR2PTR(ZSTR_VAL(z_config_file));
+ version = (int)z_version;
+ weechat_php_get_function_name (z_callback_update, callback_update_name);
+ data = ZSTR_VAL(z_data);
+
+ rc = plugin_script_api_config_set_version (
+ weechat_php_plugin,
+ php_current_script,
+ config_file,
+ version,
+ &weechat_php_api_config_update_cb,
+ (const char *)callback_update_name,
+ (const char *)data);
+
+ API_RETURN_INT(rc);
+}
+
static int
weechat_php_api_config_section_read_cb (const void *pointer, void *data,
struct t_config_file *config_file,
diff --git a/src/plugins/php/weechat-php-api.h b/src/plugins/php/weechat-php-api.h
index 4cb737553..8b1d9b1a4 100644
--- a/src/plugins/php/weechat-php-api.h
+++ b/src/plugins/php/weechat-php-api.h
@@ -85,6 +85,7 @@ PHP_FUNCTION(weechat_list_remove);
PHP_FUNCTION(weechat_list_remove_all);
PHP_FUNCTION(weechat_list_free);
PHP_FUNCTION(weechat_config_new);
+PHP_FUNCTION(weechat_config_set_version);
PHP_FUNCTION(weechat_config_new_section);
PHP_FUNCTION(weechat_config_search_section);
PHP_FUNCTION(weechat_config_new_option);
diff --git a/src/plugins/php/weechat-php.c b/src/plugins/php/weechat-php.c
index 3f85b06fd..07f3da4a1 100644
--- a/src/plugins/php/weechat-php.c
+++ b/src/plugins/php/weechat-php.c
@@ -143,6 +143,7 @@ const zend_function_entry weechat_functions[] = {
PHP_FE(weechat_list_remove_all, arginfo_weechat_list_remove_all)
PHP_FE(weechat_list_free, arginfo_weechat_list_free)
PHP_FE(weechat_config_new, arginfo_weechat_config_new)
+ PHP_FE(weechat_config_set_version, arginfo_weechat_config_set_version)
PHP_FE(weechat_config_new_section, arginfo_weechat_config_new_section)
PHP_FE(weechat_config_search_section, arginfo_weechat_config_search_section)
PHP_FE(weechat_config_new_option, arginfo_weechat_config_new_option)
diff --git a/src/plugins/php/weechat-php.stub.php b/src/plugins/php/weechat-php.stub.php
index 50c836268..a82e6aa27 100644
--- a/src/plugins/php/weechat-php.stub.php
+++ b/src/plugins/php/weechat-php.stub.php
@@ -51,6 +51,7 @@ function weechat_list_remove(string $p0, string $p1): int {}
function weechat_list_remove_all(string $p0): int {}
function weechat_list_free(string $p0): int {}
function weechat_config_new(string $p0, mixed $p1, string $p2): string {}
+function weechat_config_set_version(string $p0, int $p1, mixed $p2, string $p3): int {}
function weechat_config_new_section(): string {}
function weechat_config_search_section(string $p0, string $p1): string {}
function weechat_config_new_option(): string {}
diff --git a/src/plugins/php/weechat-php_arginfo.h b/src/plugins/php/weechat-php_arginfo.h
index 4f81116e9..cfdb257a3 100644
--- a/src/plugins/php/weechat-php_arginfo.h
+++ b/src/plugins/php/weechat-php_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: a89a2f8dfa145afbf1c86bf246715c88babebb07 */
+ * Stub hash: 5c460494eac0e2ed6729ab210df6679f990070d6 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_weechat_register, 0, 7, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, p0, IS_STRING, 0)
@@ -130,6 +130,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_weechat_config_new, 0, 3, IS_STR
ZEND_ARG_TYPE_INFO(0, p2, IS_STRING, 0)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_weechat_config_set_version, 0, 4, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO(0, p0, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO(0, p1, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO(0, p2, IS_MIXED, 0)
+ ZEND_ARG_TYPE_INFO(0, p3, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
#define arginfo_weechat_config_new_section arginfo_weechat_list_new
#define arginfo_weechat_config_search_section arginfo_weechat_iconv_to_internal
diff --git a/src/plugins/php/weechat-php_legacy_arginfo.h b/src/plugins/php/weechat-php_legacy_arginfo.h
index a55f8aa0a..24993b583 100644
--- a/src/plugins/php/weechat-php_legacy_arginfo.h
+++ b/src/plugins/php/weechat-php_legacy_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: a89a2f8dfa145afbf1c86bf246715c88babebb07 */
+ * Stub hash: 5c460494eac0e2ed6729ab210df6679f990070d6 */
ZEND_BEGIN_ARG_INFO_EX(arginfo_weechat_register, 0, 0, 7)
ZEND_ARG_INFO(0, p0)
@@ -46,7 +46,7 @@ ZEND_END_ARG_INFO()
#define arginfo_weechat_string_format_size arginfo_weechat_plugin_get_name
-#define arginfo_weechat_string_parse_size arginfo_weechat_charset_set
+#define arginfo_weechat_string_parse_size arginfo_weechat_plugin_get_name
#define arginfo_weechat_string_color_code_size arginfo_weechat_plugin_get_name
@@ -104,6 +104,8 @@ ZEND_END_ARG_INFO()
#define arginfo_weechat_config_new arginfo_weechat_ngettext
+#define arginfo_weechat_config_set_version arginfo_weechat_string_eval_expression
+
#define arginfo_weechat_config_new_section arginfo_weechat_list_new
#define arginfo_weechat_config_search_section arginfo_weechat_iconv_to_internal
diff --git a/src/plugins/plugin-script-api.c b/src/plugins/plugin-script-api.c
index 368edc4f8..c85244840 100644
--- a/src/plugins/plugin-script-api.c
+++ b/src/plugins/plugin-script-api.c
@@ -110,16 +110,54 @@ plugin_script_api_config_new (struct t_weechat_plugin *weechat_plugin,
script,
function_and_data);
- if (!new_config_file)
- {
- if (function_and_data)
- free (function_and_data);
- }
+ if (!new_config_file && function_and_data)
+ free (function_and_data);
return new_config_file;
}
/*
+ * Sets configuration file version and a callback to update config
+ * sections/options on-the-fly when the config is read.
+ *
+ * Returns pointer to new configuration file, NULL if error.
+ */
+
+int
+plugin_script_api_config_set_version (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_config_file *config_file,
+ int version,
+ struct t_hashtable *(*callback_update)(const void *pointer,
+ void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read),
+ const char *function,
+ const char *data)
+{
+ char *function_and_data;
+ int rc;
+
+ if (!script)
+ return 0;
+
+ function_and_data = plugin_script_build_function_and_data (function, data);
+
+ rc = weechat_config_set_version (
+ config_file,
+ version,
+ (function_and_data) ? callback_update : NULL,
+ script,
+ function_and_data);
+
+ if (!rc && function_and_data)
+ free (function_and_data);
+
+ return rc;
+}
+
+/*
* Creates a new section in configuration file.
*
* Returns pointer to new section, NULL if error.
diff --git a/src/plugins/plugin-script-api.h b/src/plugins/plugin-script-api.h
index b87ba76da..44cf8c179 100644
--- a/src/plugins/plugin-script-api.h
+++ b/src/plugins/plugin-script-api.h
@@ -37,6 +37,17 @@ extern struct t_config_file *plugin_script_api_config_new (struct t_weechat_plug
struct t_config_file *config_file),
const char *function,
const char *data);
+extern int plugin_script_api_config_set_version (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_config_file *config_file,
+ int version,
+ struct t_hashtable *(*callback_update)(const void *pointer,
+ void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read),
+ const char *function,
+ const char *data);
extern struct t_config_section *plugin_script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 1e9040bba..f816ecd6e 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -736,6 +736,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->hashtable_free = &hashtable_free;
new_plugin->config_new = &config_file_new;
+ new_plugin->config_set_version = &config_file_set_version;
new_plugin->config_new_section = &config_file_new_section;
new_plugin->config_search_section = &config_file_search_section;
new_plugin->config_new_option = &config_file_new_option;
diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c
index a54c024e6..12cebcfcf 100644
--- a/src/plugins/python/weechat-python-api.c
+++ b/src/plugins/python/weechat-python-api.c
@@ -869,6 +869,64 @@ API_FUNC(config_new)
API_RETURN_STRING(result);
}
+struct t_hashtable *
+weechat_python_api_config_update_cb (const void *pointer, void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read)
+{
+ struct t_plugin_script *script;
+ void *func_argv[4];
+ char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
+ struct t_hashtable *ret_hashtable;
+
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
+
+ if (ptr_function && ptr_function[0])
+ {
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
+ func_argv[1] = (char *)API_PTR2STR(config_file);
+ func_argv[2] = &version_read;
+ func_argv[3] = data_read;
+
+ ret_hashtable = weechat_python_exec (script,
+ WEECHAT_SCRIPT_EXEC_HASHTABLE,
+ ptr_function,
+ "ssih", func_argv);
+
+ return ret_hashtable;
+ }
+
+ return NULL;
+}
+
+API_FUNC(config_set_version)
+{
+ char *config_file, *function, *data;
+ int rc, version;
+
+ API_INIT_FUNC(1, "config_set_version", API_RETURN_INT(0));
+ config_file = NULL;
+ version = 0;
+ function = NULL;
+ data = NULL;
+ if (!PyArg_ParseTuple (args, "siss", &config_file, &version, &function, &data))
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ rc = plugin_script_api_config_set_version (
+ weechat_python_plugin,
+ python_current_script,
+ API_STR2PTR(config_file),
+ version,
+ &weechat_python_api_config_update_cb,
+ function,
+ data);
+
+ API_RETURN_INT(rc);
+}
+
int
weechat_python_api_config_read_cb (const void *pointer, void *data,
struct t_config_file *config_file,
@@ -5315,6 +5373,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(list_remove_all),
API_DEF_FUNC(list_free),
API_DEF_FUNC(config_new),
+ API_DEF_FUNC(config_set_version),
API_DEF_FUNC(config_new_section),
API_DEF_FUNC(config_search_section),
API_DEF_FUNC(config_new_option),
diff --git a/src/plugins/python/weechat.pyi b/src/plugins/python/weechat.pyi
index 86b7e33d8..97b306df8 100644
--- a/src/plugins/python/weechat.pyi
+++ b/src/plugins/python/weechat.pyi
@@ -481,6 +481,53 @@ def config_new(name: str, callback_reload: str, callback_reload_data: str) -> st
...
+def config_set_version(config_file: str, version: int, callback_update: str, callback_update_data: str) -> int:
+ """`config_set_version in WeeChat plugin API reference <https://weechat.org/doc/api/#_config_set_version>`_
+ ::
+
+ # example
+ def my_config_update_cb(data: str, config_file: str, version_read: int, data_read: Dict[str, str]) -> Dict[str, str]:
+ # return now if version is already up-to-date
+ if version_read >= 2:
+ return {}
+
+ section = data_read.get("section")
+ option = data_read.get("option")
+
+ # rename section "abc" to "def"
+ if section and not option and section == "abc":
+ data_read["section"] = "def"
+ return data_read
+
+ # limit other changes to section "test"
+ if not section or not option or section != "test":
+ return {}
+
+ # rename option "test1" to "test2"
+ if option == "test1":
+ data_read["option"] = "test2"
+ return data_read
+
+ # set value to "xxx" for option "test"
+ if option == "test":
+ data_read["value"] = "xxx"
+ return data_read
+
+ # set value to NULL for option "test_null"
+ if option == "test_null":
+ data_read["value_null"] = "1"
+ return data_read
+
+ # no changes
+ return {}
+
+ config_file = weechat.config_new("test", "", "")
+ weechat.config_set_version(config_file, 2, "my_config_update_cb", "")
+ weechat.config_read(config_file)
+ """
+ ...
+
+
def config_new_section(config_file: str, name: str,
user_can_add_options: int, user_can_delete_options: int,
callback_read: str, callback_read_data: str,
diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c
index fccec5063..4db4d3326 100644
--- a/src/plugins/ruby/weechat-ruby-api.c
+++ b/src/plugins/ruby/weechat-ruby-api.c
@@ -1077,6 +1077,74 @@ weechat_ruby_api_config_new (VALUE class, VALUE name, VALUE function,
API_RETURN_STRING(result);
}
+struct t_hashtable *
+weechat_ruby_api_config_update_cb (const void *pointer, void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read)
+{
+ struct t_plugin_script *script;
+ void *func_argv[4];
+ char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
+ struct t_hashtable *ret_hashtable;
+
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
+
+ if (ptr_function && ptr_function[0])
+ {
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
+ func_argv[1] = (char *)API_PTR2STR(config_file);
+ func_argv[2] = &version_read;
+ func_argv[3] = data_read;
+
+ ret_hashtable = weechat_ruby_exec (script,
+ WEECHAT_SCRIPT_EXEC_HASHTABLE,
+ ptr_function,
+ "ssih", func_argv);
+
+ return ret_hashtable;
+ }
+
+ return NULL;
+}
+
+static VALUE
+weechat_ruby_api_config_set_version (VALUE class, VALUE config_file,
+ VALUE version, VALUE function,
+ VALUE data)
+{
+ char *c_config_file, *c_function, *c_data;
+ int rc, c_version;
+
+ API_INIT_FUNC(1, "config_set_version", API_RETURN_INT(0));
+ if (NIL_P (config_file) || NIL_P (version) || NIL_P (function)
+ || NIL_P (data))
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ Check_Type (config_file, T_STRING);
+ CHECK_INTEGER(version);
+ Check_Type (function, T_STRING);
+ Check_Type (data, T_STRING);
+
+ c_config_file = StringValuePtr (config_file);
+ c_version = NUM2INT (version);
+ c_function = StringValuePtr (function);
+ c_data = StringValuePtr (data);
+
+ rc = plugin_script_api_config_set_version (
+ weechat_ruby_plugin,
+ ruby_current_script,
+ API_STR2PTR(c_config_file),
+ c_version,
+ &weechat_ruby_api_config_update_cb,
+ c_function,
+ c_data);
+
+ API_RETURN_INT(rc);
+}
+
int
weechat_ruby_api_config_read_cb (const void *pointer, void *data,
struct t_config_file *config_file,
@@ -6600,6 +6668,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(list_remove_all, 1);
API_DEF_FUNC(list_free, 1);
API_DEF_FUNC(config_new, 3);
+ API_DEF_FUNC(config_set_version, 4);
API_DEF_FUNC(config_new_section, 14);
API_DEF_FUNC(config_search_section, 2);
API_DEF_FUNC(config_new_option, 12);
diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c
index c73cf2caa..7be25196a 100644
--- a/src/plugins/tcl/weechat-tcl-api.c
+++ b/src/plugins/tcl/weechat-tcl-api.c
@@ -1080,6 +1080,69 @@ API_FUNC(config_new)
API_RETURN_STRING(result);
}
+struct t_hashtable *
+weechat_tcl_api_config_update_cb (const void *pointer, void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read)
+{
+ struct t_plugin_script *script;
+ void *func_argv[4];
+ char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
+ struct t_hashtable *ret_hashtable;
+
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
+
+
+ if (ptr_function && ptr_function[0])
+ {
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
+ func_argv[1] = (char *)API_PTR2STR(config_file);
+ func_argv[2] = &version_read;
+ func_argv[3] = data_read;
+
+ ret_hashtable = weechat_tcl_exec (script,
+ WEECHAT_SCRIPT_EXEC_HASHTABLE,
+ ptr_function,
+ "ssih", func_argv);
+
+ return ret_hashtable;
+ }
+
+ return NULL;
+}
+
+API_FUNC(config_set_version)
+{
+ Tcl_Obj *objp;
+ char *config_file, *function, *data;
+ int i, rc, version;
+
+ API_INIT_FUNC(1, "config_set_version", API_RETURN_INT(0));
+ if (objc < 5)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ if (Tcl_GetIntFromObj (interp, objv[2], &version) != TCL_OK)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ config_file = Tcl_GetStringFromObj (objv[1], &i);
+ function = Tcl_GetStringFromObj (objv[3], &i);
+ data = Tcl_GetStringFromObj (objv[4], &i);
+
+ rc = plugin_script_api_config_set_version (
+ weechat_tcl_plugin,
+ tcl_current_script,
+ API_STR2PTR(config_file),
+ version,
+ &weechat_tcl_api_config_update_cb,
+ function,
+ data);
+
+ API_RETURN_INT(rc);
+}
+
int
weechat_tcl_api_config_section_read_cb (const void *pointer, void *data,
struct t_config_file *config_file,
@@ -1287,7 +1350,7 @@ weechat_tcl_api_config_section_delete_option_cb (const void *pointer, void *data
API_FUNC(config_new_section)
{
Tcl_Obj *objp;
- char *cfg_file, *name, *function_read, *data_read;
+ char *config_file, *name, *function_read, *data_read;
char *function_write, *data_write, *function_write_default;
char *data_write_default, *function_create_option, *data_create_option;
char *function_delete_option, *data_delete_option;
@@ -1305,7 +1368,7 @@ API_FUNC(config_new_section)
|| (Tcl_GetIntFromObj (interp, objv[4], &can_delete) != TCL_OK))
API_WRONG_ARGS(API_RETURN_EMPTY);
- cfg_file = Tcl_GetStringFromObj (objv[1], &i);
+ config_file = Tcl_GetStringFromObj (objv[1], &i);
name = Tcl_GetStringFromObj (objv[2], &i);
function_read = Tcl_GetStringFromObj (objv[5], &i);
data_read = Tcl_GetStringFromObj (objv[6], &i);
@@ -1322,7 +1385,7 @@ API_FUNC(config_new_section)
plugin_script_api_config_new_section (
weechat_tcl_plugin,
tcl_current_script,
- API_STR2PTR(cfg_file),
+ API_STR2PTR(config_file),
name,
can_add, /* user_can_add_options */
can_delete, /* user_can_delete_options */
@@ -5904,6 +5967,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(list_remove_all);
API_DEF_FUNC(list_free);
API_DEF_FUNC(config_new);
+ API_DEF_FUNC(config_set_version);
API_DEF_FUNC(config_new_section);
API_DEF_FUNC(config_search_section);
API_DEF_FUNC(config_new_option);
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 72c55ec35..f0f8cae49 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -68,7 +68,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
-#define WEECHAT_PLUGIN_API_VERSION "20221224-02"
+#define WEECHAT_PLUGIN_API_VERSION "20230220-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -529,6 +529,15 @@ struct t_weechat_plugin
struct t_config_file *config_file),
const void *callback_reload_pointer,
void *callback_reload_data);
+ int (*config_set_version) (struct t_config_file *config_file,
+ int version,
+ struct t_hashtable *(*callback_update)(const void *pointer,
+ void *data,
+ struct t_config_file *config_file,
+ int version_read,
+ struct t_hashtable *data_read),
+ const void *callback_update_pointer,
+ void *callback_update_data);
struct t_config_section *(*config_new_section) (struct t_config_file *config_file,
const char *name,
int user_can_add_options,
@@ -1573,6 +1582,14 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
__callback_reload, \
__callback_reload_pointer, \
__callback_reload_data)
+#define weechat_config_set_version(__config, __version, \
+ __callback_update, \
+ __callback_update_pointer, \
+ __callback_update_data) \
+ (weechat_plugin->config_set_version)(__config, __version, \
+ __callback_update, \
+ __callback_update_pointer, \
+ __callback_update_data)
#define weechat_config_new_section(__config, __name, \
__user_can_add_options, \
__user_can_delete_options, \