summaryrefslogtreecommitdiff
path: root/src/plugins/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/scripts')
-rw-r--r--src/plugins/scripts/lua/weechat-lua-api.c211
-rw-r--r--src/plugins/scripts/perl/weechat-perl-api.c184
-rw-r--r--src/plugins/scripts/python/weechat-python-api.c190
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby-api.c211
-rw-r--r--src/plugins/scripts/script-api.c45
-rw-r--r--src/plugins/scripts/script-api.h8
-rw-r--r--src/plugins/scripts/script-callback.c2
-rw-r--r--src/plugins/scripts/script-callback.h1
-rw-r--r--src/plugins/scripts/tcl/weechat-tcl-api.c213
9 files changed, 1060 insertions, 5 deletions
diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c
index 2b0284e5b..9393dd0a4 100644
--- a/src/plugins/scripts/lua/weechat-lua-api.c
+++ b/src/plugins/scripts/lua/weechat-lua-api.c
@@ -6145,6 +6145,213 @@ weechat_lua_api_infolist_free (lua_State *L)
}
/*
+ * weechat_lua_api_config_new: create a new configuration file
+ */
+
+static int
+weechat_lua_api_upgrade_new (lua_State *L)
+{
+ const char *filename;
+ char *result;
+ int n, write;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_new");
+ LUA_RETURN_EMPTY;
+ }
+
+ filename = NULL;
+ write = 0;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_new");
+ LUA_RETURN_EMPTY;
+ }
+
+ filename = lua_tostring (lua_current_interpreter, -2);
+ write = lua_tonumber (lua_current_interpreter, -1);
+
+ result = script_ptr2str (weechat_upgrade_new (filename, write));
+
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_upgrade_write_object: write object in upgrade file
+ */
+
+static int
+weechat_lua_api_upgrade_write_object (lua_State *L)
+{
+ const char *upgrade_file, *infolist;
+ int n, object_id, rc;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_write_object");
+ LUA_RETURN_INT(0);
+ }
+
+ upgrade_file = NULL;
+ object_id = 0;
+ infolist = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_write_object");
+ LUA_RETURN_INT(0);
+ }
+
+ upgrade_file = lua_tostring (lua_current_interpreter, -3);
+ object_id = lua_tonumber (lua_current_interpreter, -2);
+ infolist = lua_tostring (lua_current_interpreter, -1);
+
+ rc = weechat_upgrade_write_object (script_str2ptr (upgrade_file),
+ object_id,
+ script_str2ptr (infolist));
+
+ LUA_RETURN_INT(rc);
+}
+
+/*
+ * weechat_lua_api_upgrade_read_cb: callback for reading object in upgrade file
+ */
+
+int
+weechat_lua_api_upgrade_read_cb (void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist)
+{
+ struct t_script_callback *script_callback;
+ char *lua_argv[4], str_object_id[32];
+ int *rc, ret;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback && script_callback->function && script_callback->function[0])
+ {
+ snprintf (str_object_id, sizeof (str_object_id), "%d", object_id);
+
+ lua_argv[0] = script_ptr2str (upgrade_file);
+ lua_argv[1] = str_object_id;
+ lua_argv[2] = script_ptr2str (infolist);
+ lua_argv[3] = 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]);
+ if (lua_argv[2])
+ free (lua_argv[2]);
+
+ return ret;
+ }
+
+ return WEECHAT_RC_ERROR;
+}
+
+/*
+ * weechat_lua_api_upgrade_read: read upgrade file
+ */
+
+static int
+weechat_lua_api_upgrade_read (lua_State *L)
+{
+ const char *upgrade_file, *function_read;
+ int n, rc;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_read");
+ LUA_RETURN_EMPTY;
+ }
+
+ upgrade_file = NULL;
+ function_read = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_read");
+ LUA_RETURN_EMPTY;
+ }
+
+ upgrade_file = lua_tostring (lua_current_interpreter, -2);
+ function_read = lua_tostring (lua_current_interpreter, -1);
+
+ rc = script_api_upgrade_read (weechat_lua_plugin,
+ lua_current_script,
+ script_str2ptr (upgrade_file),
+ &weechat_lua_api_upgrade_read_cb,
+ function_read);
+
+ LUA_RETURN_INT(rc);
+}
+
+/*
+ * weechat_lua_api_upgrade_close: close upgrade file
+ */
+
+static int
+weechat_lua_api_upgrade_close (lua_State *L)
+{
+ const char *upgrade_file;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_close");
+ LUA_RETURN_ERROR;
+ }
+
+ upgrade_file = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_close");
+ LUA_RETURN_INT(0);
+ }
+
+ upgrade_file = lua_tostring (lua_current_interpreter, -1);
+
+ weechat_upgrade_close (script_str2ptr (upgrade_file));
+
+ LUA_RETURN_OK;
+}
+
+/*
* Lua constant as functions
*/
@@ -6639,6 +6846,10 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "infolist_pointer", &weechat_lua_api_infolist_pointer },
{ "infolist_time", &weechat_lua_api_infolist_time },
{ "infolist_free", &weechat_lua_api_infolist_free },
+ { "upgrade_new", &weechat_lua_api_upgrade_new },
+ { "upgrade_write_object", &weechat_lua_api_upgrade_write_object },
+ { "upgrade_read", &weechat_lua_api_upgrade_read },
+ { "upgrade_close", &weechat_lua_api_upgrade_close },
/* define constants as function which returns values */
diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c
index 33cfe9c41..1c4f08e90 100644
--- a/src/plugins/scripts/perl/weechat-perl-api.c
+++ b/src/plugins/scripts/perl/weechat-perl-api.c
@@ -5134,6 +5134,186 @@ static XS (XS_weechat_api_infolist_free)
}
/*
+ * weechat::upgrade_new: create an upgrade file
+ */
+
+static XS (XS_weechat_api_upgrade_new)
+{
+ char *result, *filename;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_new");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_new");
+ PERL_RETURN_EMPTY;
+ }
+
+ filename = SvPV (ST (0), PL_na);
+ result = script_ptr2str (weechat_upgrade_new (filename,
+ SvIV (ST (1)))); /* write */
+
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::upgrade_write_object: write object in upgrade file
+ */
+
+static XS (XS_weechat_api_upgrade_write_object)
+{
+ char *upgrade_file, *infolist;
+ int rc;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_write_object");
+ PERL_RETURN_INT(0);
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_write_object");
+ PERL_RETURN_INT(0);
+ }
+
+ upgrade_file = SvPV (ST (0), PL_na);
+ infolist = SvPV (ST (2), PL_na);
+ rc = weechat_upgrade_write_object (script_str2ptr (upgrade_file),
+ SvIV (ST (1)), /* object_id */
+ script_str2ptr (infolist));
+
+ PERL_RETURN_INT(rc);
+}
+
+/*
+ * weechat_perl_api_upgrade_read_cb: callback for reading object in upgrade file
+ */
+
+int
+weechat_perl_api_upgrade_read_cb (void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist)
+{
+ struct t_script_callback *script_callback;
+ char *perl_argv[4], str_object_id[32];
+ int *rc, ret;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback && script_callback->function && script_callback->function[0])
+ {
+ snprintf (str_object_id, sizeof (str_object_id), "%d", object_id);
+
+ perl_argv[0] = script_ptr2str (upgrade_file);
+ perl_argv[1] = str_object_id;
+ perl_argv[2] = script_ptr2str (infolist);
+ perl_argv[3] = 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]);
+ if (perl_argv[2])
+ free (perl_argv[2]);
+
+ return ret;
+ }
+
+ return WEECHAT_RC_ERROR;
+}
+
+/*
+ * weechat::config_upgrade_read: read upgrade file
+ */
+
+static XS (XS_weechat_api_upgrade_read)
+{
+ char *upgrade_file, *function_read;
+ int rc;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_read");
+ PERL_RETURN_INT(0);
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_read");
+ PERL_RETURN_INT(0);
+ }
+
+ upgrade_file = SvPV (ST (0), PL_na);
+ function_read = SvPV (ST (1), PL_na);
+ rc = script_api_upgrade_read (weechat_perl_plugin,
+ perl_current_script,
+ script_str2ptr (upgrade_file),
+ &weechat_perl_api_upgrade_read_cb,
+ function_read);
+
+ PERL_RETURN_INT(rc);
+}
+
+/*
+ * weechat::upgrade_close: close upgrade file
+ */
+
+static XS (XS_weechat_api_upgrade_close)
+{
+ char *upgrade_file;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_close");
+ PERL_RETURN_ERROR;
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_close");
+ PERL_RETURN_ERROR;
+ }
+
+ upgrade_file = SvPV (ST (0), PL_na);
+
+ weechat_upgrade_close (script_str2ptr (upgrade_file));
+
+ PERL_RETURN_OK;
+}
+
+/*
* weechat_perl_api_init: initialize subroutines
*/
@@ -5271,6 +5451,10 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::infolist_pointer", XS_weechat_api_infolist_pointer, "weechat");
newXS ("weechat::infolist_time", XS_weechat_api_infolist_time, "weechat");
newXS ("weechat::infolist_free", XS_weechat_api_infolist_free, "weechat");
+ newXS ("weechat::upgrade_new", XS_weechat_api_upgrade_new, "weechat");
+ newXS ("weechat::upgrade_write_object", XS_weechat_api_upgrade_write_object, "weechat");
+ newXS ("weechat::upgrade_read", XS_weechat_api_upgrade_read, "weechat");
+ newXS ("weechat::upgrade_close", XS_weechat_api_upgrade_close, "weechat");
/* interface constants */
stash = gv_stashpv ("weechat", TRUE);
diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c
index eba98086c..265304ef5 100644
--- a/src/plugins/scripts/python/weechat-python-api.c
+++ b/src/plugins/scripts/python/weechat-python-api.c
@@ -5463,6 +5463,192 @@ weechat_python_api_infolist_free (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_api_upgrade_new: create an upgrade file
+ */
+
+static PyObject *
+weechat_python_api_upgrade_new (PyObject *self, PyObject *args)
+{
+ char *filename, *result;
+ int write;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_new");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ filename = NULL;
+ write = 0;
+
+ if (!PyArg_ParseTuple (args, "si", &filename, &write))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_new");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_upgrade_new (filename, write));
+
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_upgrade_write_object: write object in upgrade file
+ */
+
+static PyObject *
+weechat_python_api_upgrade_write_object (PyObject *self, PyObject *args)
+{
+ char *upgrade_file, *infolist;
+ int object_id, rc;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_write_object");
+ PYTHON_RETURN_INT(0);
+ }
+
+ upgrade_file = NULL;
+ object_id = 0;
+ infolist = NULL;
+
+ if (!PyArg_ParseTuple (args, "sis", &upgrade_file, &object_id, &infolist))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_write_object");
+ PYTHON_RETURN_INT(0);
+ }
+
+ rc = weechat_upgrade_write_object (script_str2ptr (upgrade_file),
+ object_id,
+ script_str2ptr (infolist));
+
+ PYTHON_RETURN_INT(rc);
+}
+
+/*
+ * weechat_python_api_upgrade_read_cb: callback for reading object in upgrade file
+ */
+
+int
+weechat_python_api_upgrade_read_cb (void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist)
+{
+ struct t_script_callback *script_callback;
+ char *python_argv[4], str_object_id[32];
+ int *rc, ret;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback && script_callback->function && script_callback->function[0])
+ {
+ snprintf (str_object_id, sizeof (str_object_id), "%d", object_id);
+
+ python_argv[0] = script_ptr2str (upgrade_file);
+ python_argv[1] = str_object_id;
+ python_argv[2] = script_ptr2str (infolist);
+ python_argv[3] = NULL;
+
+ rc = (int *) weechat_python_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ python_argv);
+
+ if (!rc)
+ ret = WEECHAT_RC_ERROR;
+ else
+ {
+ ret = *rc;
+ free (rc);
+ }
+ if (python_argv[0])
+ free (python_argv[0]);
+ if (python_argv[2])
+ free (python_argv[2]);
+
+ return ret;
+ }
+
+ return WEECHAT_RC_ERROR;
+}
+
+/*
+ * weechat_python_api_upgrade_read: read upgrade file
+ */
+
+static PyObject *
+weechat_python_api_upgrade_read (PyObject *self, PyObject *args)
+{
+ char *upgrade_file, *function_read;
+ int rc;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_read");
+ PYTHON_RETURN_INT(0);
+ }
+
+ upgrade_file = NULL;
+ function_read = NULL;
+
+ if (!PyArg_ParseTuple (args, "ss", &upgrade_file, &function_read))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_read");
+ PYTHON_RETURN_INT(0);
+ }
+
+ rc = script_api_upgrade_read (weechat_python_plugin,
+ python_current_script,
+ script_str2ptr (upgrade_file),
+ &weechat_python_api_upgrade_read_cb,
+ function_read);
+
+ PYTHON_RETURN_INT(rc);
+}
+
+/*
+ * weechat_python_api_upgrade_close: close upgrade file
+ */
+
+static PyObject *
+weechat_python_api_upgrade_close (PyObject *self, PyObject *args)
+{
+ char *upgrade_file;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_close");
+ PYTHON_RETURN_ERROR;
+ }
+
+ upgrade_file = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &upgrade_file))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_close");
+ PYTHON_RETURN_ERROR;
+ }
+
+ weechat_upgrade_close (script_str2ptr (upgrade_file));
+
+ PYTHON_RETURN_OK;
+}
+
+/*
* Python subroutines
*/
@@ -5594,5 +5780,9 @@ PyMethodDef weechat_python_funcs[] =
{ "infolist_pointer", &weechat_python_api_infolist_pointer, METH_VARARGS, "" },
{ "infolist_time", &weechat_python_api_infolist_time, METH_VARARGS, "" },
{ "infolist_free", &weechat_python_api_infolist_free, METH_VARARGS, "" },
+ { "upgrade_new", &weechat_python_api_upgrade_new, METH_VARARGS, "" },
+ { "upgrade_write_object", &weechat_python_api_upgrade_write_object, METH_VARARGS, "" },
+ { "upgrade_read", &weechat_python_api_upgrade_read, METH_VARARGS, "" },
+ { "upgrade_close", &weechat_python_api_upgrade_close, METH_VARARGS, "" },
{ NULL, NULL, 0, NULL }
};
diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c
index 0b884aa90..8c795e3cb 100644
--- a/src/plugins/scripts/ruby/weechat-ruby-api.c
+++ b/src/plugins/scripts/ruby/weechat-ruby-api.c
@@ -6215,6 +6215,213 @@ weechat_ruby_api_infolist_free (VALUE class, VALUE infolist)
}
/*
+ * weechat_ruby_api_upgrade_new: create an upgrade file
+ */
+
+static VALUE
+weechat_ruby_api_upgrade_new (VALUE class, VALUE filename, VALUE write)
+{
+ char *c_filename, *result;
+ int c_write;
+ VALUE return_value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_new");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_filename = NULL;
+ c_write = 0;
+
+ if (NIL_P (filename) || NIL_P (write))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_new");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (filename, T_STRING);
+ Check_Type (write, T_FIXNUM);
+
+ c_filename = STR2CSTR (filename);
+ c_write = FIX2INT (write);
+
+ result = script_ptr2str (weechat_upgrade_new (c_filename,
+ c_write));
+
+ RUBY_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_ruby_api_upgrade_write_object: write object in upgrade file
+ */
+
+static VALUE
+weechat_ruby_api_upgrade_write_object (VALUE class, VALUE upgrade_file,
+ VALUE object_id, VALUE infolist)
+{
+ char *c_upgrade_file, *c_infolist;
+ int c_object_id, rc;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_write_object");
+ RUBY_RETURN_INT(0);
+ }
+
+ if (NIL_P (upgrade_file) || NIL_P (object_id) || NIL_P (infolist))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_write_object");
+ RUBY_RETURN_INT(0);
+ }
+
+ Check_Type (upgrade_file, T_STRING);
+ Check_Type (object_id, T_FIXNUM);
+ Check_Type (infolist, T_STRING);
+
+ c_upgrade_file = STR2CSTR (upgrade_file);
+ c_object_id = FIX2INT (object_id);
+ c_infolist = STR2CSTR (infolist);
+
+ rc = weechat_upgrade_write_object (script_str2ptr (c_upgrade_file),
+ c_object_id,
+ script_str2ptr (c_infolist));
+
+ RUBY_RETURN_INT(rc);
+}
+
+/*
+ * weechat_ruby_api_upgrade_read_cb: callback for reading object in upgrade file
+ */
+
+int
+weechat_ruby_api_upgrade_read_cb (void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist)
+{
+ struct t_script_callback *script_callback;
+ char *ruby_argv[4], str_object_id[32];
+ int *rc, ret;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback && script_callback->function && script_callback->function[0])
+ {
+ snprintf (str_object_id, sizeof (str_object_id), "%d", object_id);
+
+ ruby_argv[0] = script_ptr2str (upgrade_file);
+ ruby_argv[1] = str_object_id;
+ ruby_argv[2] = script_ptr2str (infolist);
+ ruby_argv[3] = 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]);
+ if (ruby_argv[2])
+ free (ruby_argv[2]);
+
+ return ret;
+ }
+
+ return WEECHAT_RC_ERROR;
+}
+
+/*
+ * weechat_ruby_api_upgrade_read: read upgrade file
+ */
+
+static VALUE
+weechat_ruby_api_upgrade_read (VALUE class, VALUE upgrade_file,
+ VALUE function_read)
+{
+ char *c_upgrade_file, *c_function_read;
+ int rc;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_read");
+ RUBY_RETURN_INT(0);
+ }
+
+ c_upgrade_file = NULL;
+ c_function_read = NULL;
+
+ if (NIL_P (upgrade_file) || NIL_P (function_read))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_read");
+ RUBY_RETURN_INT(0);
+ }
+
+ Check_Type (upgrade_file, T_STRING);
+ Check_Type (function_read, T_STRING);
+
+ c_upgrade_file = STR2CSTR (upgrade_file);
+ c_function_read = STR2CSTR (function_read);
+
+ rc = script_api_upgrade_read (weechat_ruby_plugin,
+ ruby_current_script,
+ script_str2ptr (c_upgrade_file),
+ &weechat_ruby_api_upgrade_read_cb,
+ c_function_read);
+
+ RUBY_RETURN_INT(rc);
+}
+
+/*
+ * weechat_ruby_api_upgrade_close: close upgrade file
+ */
+
+static VALUE
+weechat_ruby_api_upgrade_close (VALUE class, VALUE upgrade_file)
+{
+ char *c_upgrade_file;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_close");
+ RUBY_RETURN_ERROR;
+ }
+
+ if (NIL_P (upgrade_file))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_close");
+ RUBY_RETURN_ERROR;
+ }
+
+ Check_Type (upgrade_file, T_STRING);
+
+ c_upgrade_file = STR2CSTR (upgrade_file);
+
+ weechat_upgrade_close (script_str2ptr (c_upgrade_file));
+
+ RUBY_RETURN_OK;
+}
+
+/*
* weechat_ruby_api_init: init Ruby API: add variables and functions
*/
@@ -6389,4 +6596,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "infolist_pointer", &weechat_ruby_api_infolist_pointer, 2);
rb_define_module_function (ruby_mWeechat, "infolist_time", &weechat_ruby_api_infolist_time, 2);
rb_define_module_function (ruby_mWeechat, "infolist_free", &weechat_ruby_api_infolist_free, 1);
+ rb_define_module_function (ruby_mWeechat, "upgrade_new", &weechat_ruby_api_upgrade_new, 2);
+ rb_define_module_function (ruby_mWeechat, "upgrade_write_object", &weechat_ruby_api_upgrade_write_object, 3);
+ rb_define_module_function (ruby_mWeechat, "upgrade_read", &weechat_ruby_api_upgrade_read, 2);
+ rb_define_module_function (ruby_mWeechat, "upgrade_close", &weechat_ruby_api_upgrade_close, 1);
}
diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c
index 994db733b..e43cc50f0 100644
--- a/src/plugins/scripts/script-api.c
+++ b/src/plugins/scripts/script-api.c
@@ -105,15 +105,15 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
struct t_config_section *section,
const char *option_name,
const char *value),
- char *function_read,
+ const char *function_read,
void (*callback_write)(void *data,
struct t_config_file *config_file,
const char *section_name),
- char *function_write,
+ const char *function_write,
void (*callback_write_default)(void *data,
struct t_config_file *config_file,
const char *section_name),
- char *function_write_default,
+ const char *function_write_default,
int (*callback_create_option)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
@@ -1521,3 +1521,42 @@ script_api_config_unset_plugin (struct t_weechat_plugin *weechat_plugin,
return return_code;
}
+
+/*
+ * script_api_upgrade_read: read upgrade file
+ * return 1 if ok, 0 if error
+ */
+
+int
+script_api_upgrade_read (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_upgrade_file *upgrade_file,
+ int (*callback_read)(void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist),
+ const char *function_read)
+{
+ struct t_script_callback *script_callback;
+ int rc;
+
+ if (!function_read || !function_read[0])
+ return 0;
+
+ script_callback = script_callback_alloc ();
+ if (!script_callback)
+ return 0;
+
+ script_callback->script = script;
+ script_callback->function = strdup (function_read);
+ script_callback->upgrade_file = upgrade_file;
+ script_callback_add (script, script_callback);
+
+ rc = weechat_upgrade_read (upgrade_file,
+ callback_read,
+ script_callback);
+
+ script_callback_remove (script, script_callback);
+
+ return rc;
+}
diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h
index 6375e4ded..37e3c6ca3 100644
--- a/src/plugins/scripts/script-api.h
+++ b/src/plugins/scripts/script-api.h
@@ -254,5 +254,13 @@ extern int script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin
extern int script_api_config_unset_plugin (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *option);
+extern int script_api_upgrade_read (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_upgrade_file *upgrade_file,
+ int (*callback_read)(void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist),
+ const char *function_read);
#endif /* script-api.h */
diff --git a/src/plugins/scripts/script-callback.c b/src/plugins/scripts/script-callback.c
index 2adeacb46..6fd7134f3 100644
--- a/src/plugins/scripts/script-callback.c
+++ b/src/plugins/scripts/script-callback.c
@@ -47,6 +47,7 @@ script_callback_alloc ()
new_script_callback->hook = NULL;
new_script_callback->buffer = NULL;
new_script_callback->bar_item = NULL;
+ new_script_callback->upgrade_file = NULL;
return new_script_callback;
}
@@ -133,6 +134,7 @@ script_callback_print_log (struct t_weechat_plugin *weechat_plugin,
weechat_log_printf (" hook. . . . . . . . : 0x%lx", script_callback->hook);
weechat_log_printf (" buffer. . . . . . . : 0x%lx", script_callback->buffer);
weechat_log_printf (" bar_item. . . . . . : 0x%lx", script_callback->bar_item);
+ weechat_log_printf (" upgrade_file. . . . : 0x%lx", script_callback->upgrade_file);
weechat_log_printf (" prev_callback . . . : 0x%lx", script_callback->prev_callback);
weechat_log_printf (" next_callback . . . : 0x%lx", script_callback->next_callback);
}
diff --git a/src/plugins/scripts/script-callback.h b/src/plugins/scripts/script-callback.h
index 2e7013d94..a37beec19 100644
--- a/src/plugins/scripts/script-callback.h
+++ b/src/plugins/scripts/script-callback.h
@@ -29,6 +29,7 @@ struct t_script_callback
struct t_hook *hook; /* not NULL for hook */
struct t_gui_buffer *buffer; /* not NULL for buffer */
struct t_gui_bar_item *bar_item; /* not NULL for bar item */
+ struct t_upgrade_file *upgrade_file; /* not NULL for upgrade file */
struct t_script_callback *prev_callback; /* link to next callback */
struct t_script_callback *next_callback; /* link to previous callback */
};
diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c
index 7ef405f74..56efc436a 100644
--- a/src/plugins/scripts/tcl/weechat-tcl-api.c
+++ b/src/plugins/scripts/tcl/weechat-tcl-api.c
@@ -5324,7 +5324,7 @@ weechat_tcl_api_infolist_new_var_integer (ClientData clientData, Tcl_Interp *int
if (Tcl_GetIntFromObj (interp, objv[3], &value) != TCL_OK)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolits_new_var_integer");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_new_var_integer");
TCL_RETURN_EMPTY;
}
@@ -5433,7 +5433,7 @@ weechat_tcl_api_infolist_new_var_time (ClientData clientData, Tcl_Interp *interp
if (Tcl_GetIntFromObj (interp, objv[3], &value) != TCL_OK)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolits_new_var_time");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_new_var_time");
TCL_RETURN_EMPTY;
}
@@ -5754,7 +5754,208 @@ weechat_tcl_api_infolist_free (ClientData clientData, Tcl_Interp *interp,
TCL_RETURN_OK;
}
+/*
+ * weechat_tcl_api_upgrade_new: create an upgrade file
+ */
+
+static int
+weechat_tcl_api_upgrade_new (ClientData clientData, Tcl_Interp *interp,
+ int objc, Tcl_Obj *CONST objv[])
+{
+ Tcl_Obj* objp;
+ char *result, *filename;
+ int i, write;
+
+ /* make C compiler happy */
+ (void) clientData;
+
+ if (!tcl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_new");
+ TCL_RETURN_EMPTY;
+ }
+
+ if (objc < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_new");
+ TCL_RETURN_EMPTY;
+ }
+
+ if (Tcl_GetIntFromObj (interp, objv[2], &write) != TCL_OK)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_new");
+ TCL_RETURN_EMPTY;
+ }
+
+ filename = Tcl_GetStringFromObj (objv[1], &i);
+ result = script_ptr2str (weechat_upgrade_new (filename, write));
+
+ TCL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_tcl_api_upgrade_write_object: write object in upgrade file
+ */
+
+static int
+weechat_tcl_api_upgrade_write_object (ClientData clientData, Tcl_Interp *interp,
+ int objc, Tcl_Obj *CONST objv[])
+{
+ Tcl_Obj *objp;
+ char *upgrade_file, *infolist;
+ int rc, i, object_id;
+
+ /* make C compiler happy */
+ (void) clientData;
+
+ if (!tcl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_write_object");
+ TCL_RETURN_INT(0);
+ }
+
+ if (objc < 4)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_write_object");
+ TCL_RETURN_INT(0);
+ }
+
+ if (Tcl_GetIntFromObj (interp, objv[2], &object_id) != TCL_OK)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_write_object");
+ TCL_RETURN_EMPTY;
+ }
+
+ upgrade_file = Tcl_GetStringFromObj (objv[1], &i);
+ infolist = Tcl_GetStringFromObj (objv[3], &i);
+
+ rc = weechat_upgrade_write_object (script_str2ptr (upgrade_file),
+ object_id,
+ script_str2ptr (infolist));
+
+ TCL_RETURN_INT(rc);
+}
+
+/*
+ * weechat_tcl_api_upgrade_read_cb: callback for reading an object in upgrade file
+ */
+int
+weechat_tcl_api_upgrade_read_cb (void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist)
+{
+ struct t_script_callback *script_callback;
+ char *tcl_argv[4], str_object_id[32];
+ int *rc, ret;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback && script_callback->function && script_callback->function[0])
+ {
+ snprintf (str_object_id, sizeof (str_object_id), "%d", object_id);
+
+ tcl_argv[0] = script_ptr2str (upgrade_file);
+ tcl_argv[1] = str_object_id;
+ tcl_argv[2] = script_ptr2str (infolist);
+ tcl_argv[3] = NULL;
+
+ rc = (int *) weechat_tcl_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ tcl_argv);
+
+ if (!rc)
+ ret = WEECHAT_RC_ERROR;
+ else
+ {
+ ret = *rc;
+ free (rc);
+ }
+ if (tcl_argv[0])
+ free (tcl_argv[0]);
+ if (tcl_argv[2])
+ free (tcl_argv[2]);
+
+ return ret;
+ }
+
+ return WEECHAT_RC_ERROR;
+}
+
+/*
+ * weechat_tcl_api_upgrade_read: read upgrade file
+ */
+
+static int
+weechat_tcl_api_upgrade_read (ClientData clientData, Tcl_Interp *interp,
+ int objc, Tcl_Obj *CONST objv[])
+{
+ Tcl_Obj* objp;
+ char *upgrade_file, *function_read;
+ int i, rc;
+
+ /* make C compiler happy */
+ (void) clientData;
+
+ if (!tcl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_read");
+ TCL_RETURN_EMPTY;
+ }
+
+ if (objc < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_read");
+ TCL_RETURN_EMPTY;
+ }
+
+ upgrade_file = Tcl_GetStringFromObj (objv[1], &i);
+ function_read = Tcl_GetStringFromObj (objv[2], &i);
+
+ rc = script_api_upgrade_read (weechat_tcl_plugin,
+ tcl_current_script,
+ script_str2ptr (upgrade_file),
+ &weechat_tcl_api_upgrade_read_cb,
+ function_read);
+
+ TCL_RETURN_INT(rc);
+}
+
+/*
+ * weechat_tcl_api_upgrade_close: close upgrade file
+ */
+
+static int
+weechat_tcl_api_upgrade_close (ClientData clientData, Tcl_Interp *interp,
+ int objc, Tcl_Obj *CONST objv[])
+{
+ Tcl_Obj *objp;
+ char *upgrade_file;
+ int i;
+
+ /* make C compiler happy */
+ (void) clientData;
+
+ if (!tcl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("upgrade_close");
+ TCL_RETURN_ERROR;
+ }
+
+ if (objc < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("upgrade_close");
+ TCL_RETURN_INT(0);
+ }
+
+ upgrade_file = Tcl_GetStringFromObj (objv[1], &i);
+
+ weechat_upgrade_close (script_str2ptr (upgrade_file));
+
+ TCL_RETURN_OK;
+}
/*
* weechat_tcl_api_init: initialize subroutines
@@ -6110,4 +6311,12 @@ void weechat_tcl_api_init (Tcl_Interp *interp) {
weechat_tcl_api_infolist_time, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::infolist_free",
weechat_tcl_api_infolist_free, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ Tcl_CreateObjCommand (interp,"weechat::upgrade_new",
+ weechat_tcl_api_upgrade_new, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ Tcl_CreateObjCommand (interp,"weechat::upgrade_write_object",
+ weechat_tcl_api_upgrade_write_object, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ Tcl_CreateObjCommand (interp,"weechat::upgrade_read",
+ weechat_tcl_api_upgrade_read, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ Tcl_CreateObjCommand (interp,"weechat::upgrade_close",
+ weechat_tcl_api_upgrade_close, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
}