summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/wee-upgrade-file.c22
-rw-r--r--src/core/wee-upgrade-file.h16
-rw-r--r--src/core/wee-upgrade.c14
-rw-r--r--src/plugins/irc/irc-upgrade.c14
-rw-r--r--src/plugins/jabber/jabber-upgrade.c14
-rw-r--r--src/plugins/plugin.c2
-rw-r--r--src/plugins/relay/relay-upgrade.c15
-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
-rw-r--r--src/plugins/weechat-plugin.h21
-rw-r--r--src/plugins/xfer/xfer-upgrade.c13
18 files changed, 1149 insertions, 47 deletions
diff --git a/src/core/wee-upgrade-file.c b/src/core/wee-upgrade-file.c
index 96226433b..52f6d9e7a 100644
--- a/src/core/wee-upgrade-file.c
+++ b/src/core/wee-upgrade-file.c
@@ -164,13 +164,13 @@ upgrade_file_write_buffer (struct t_upgrade_file *upgrade_file, void *pointer,
}
/*
- * upgrade_file_create: create an upgrade file
- * if write == 1 then it's opened in write mode, otherwise
- * read mode
+ * upgrade_file_new: create an upgrade file
+ * if write == 1 then it's opened in write mode, otherwise
+ * read mode
*/
struct t_upgrade_file *
-upgrade_file_create (const char *filename, int write)
+upgrade_file_new (const char *filename, int write)
{
int length;
struct t_upgrade_file *new_upgrade_file;
@@ -661,7 +661,10 @@ upgrade_file_read_object (struct t_upgrade_file *upgrade_file)
if (upgrade_file->callback_read)
{
- if ((int)(upgrade_file->callback_read) (object_id, infolist) == WEECHAT_RC_ERROR)
+ if ((int)(upgrade_file->callback_read) (upgrade_file->callback_read_data,
+ upgrade_file,
+ object_id,
+ infolist) == WEECHAT_RC_ERROR)
rc = 0;
}
@@ -680,16 +683,21 @@ upgrade_file_read_object (struct t_upgrade_file *upgrade_file)
/*
* upgrade_file_read: read an upgrade file
+ * return 1 if ok, 0 if error
*/
int
upgrade_file_read (struct t_upgrade_file *upgrade_file,
- int (*callback_read)(int object_id,
- struct t_infolist *infolist))
+ int (*callback_read)(void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist),
+ void *callback_read_data)
{
char *signature;
upgrade_file->callback_read = callback_read;
+ upgrade_file->callback_read_data = callback_read_data;
signature = NULL;
if (!upgrade_file_read_string (upgrade_file, &signature))
diff --git a/src/core/wee-upgrade-file.h b/src/core/wee-upgrade-file.h
index 266195b5d..ff865ca05 100644
--- a/src/core/wee-upgrade-file.h
+++ b/src/core/wee-upgrade-file.h
@@ -41,20 +41,26 @@ struct t_upgrade_file
long last_read_pos; /* last read position */
int last_read_length; /* last read length */
int (*callback_read) /* callback called when reading */
- (int object_id, /* file */
+ (void *data, /* file */
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
struct t_infolist *infolist);
+ void *callback_read_data; /* data sent to callback */
struct t_upgrade_file *prev_upgrade; /* link to previous upgrade file */
struct t_upgrade_file *next_upgrade; /* link to next upgrade file */
};
-extern struct t_upgrade_file *upgrade_file_create (const char *filename,
- int write);
+extern struct t_upgrade_file *upgrade_file_new (const char *filename,
+ int write);
extern int upgrade_file_write_object (struct t_upgrade_file *upgrade_file,
int object_id,
struct t_infolist *infolist);
extern int upgrade_file_read (struct t_upgrade_file *upgrade_file,
- int (*callback_read)(int object_id,
- struct t_infolist *infolist));
+ int (*callback_read)(void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist),
+ void *callback_read_data);
extern void upgrade_file_close (struct t_upgrade_file *upgrade_file);
#endif /* wee-upgrade-file.h */
diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c
index cf5c49345..4cc32d722 100644
--- a/src/core/wee-upgrade.c
+++ b/src/core/wee-upgrade.c
@@ -257,7 +257,7 @@ upgrade_weechat_save ()
int rc;
struct t_upgrade_file *upgrade_file;
- upgrade_file = upgrade_file_create (WEECHAT_UPGRADE_FILENAME, 1);
+ upgrade_file = upgrade_file_new (WEECHAT_UPGRADE_FILENAME, 1);
if (!upgrade_file)
return 0;
@@ -277,7 +277,9 @@ upgrade_weechat_save ()
*/
int
-upgrade_weechat_read_cb (int object_id,
+upgrade_weechat_read_cb (void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
struct t_infolist *infolist)
{
const char *key, *var_name, *type, *name, *group_name;
@@ -289,6 +291,10 @@ upgrade_weechat_read_cb (int object_id,
void *buf;
int size, index, length;
+ /* make C compiler happy */
+ (void) data;
+ (void) upgrade_file;
+
infolist_reset_item_cursor (infolist);
while (infolist_next (infolist))
{
@@ -534,8 +540,8 @@ upgrade_weechat_load ()
int rc;
struct t_upgrade_file *upgrade_file;
- upgrade_file = upgrade_file_create (WEECHAT_UPGRADE_FILENAME, 0);
- rc = upgrade_file_read (upgrade_file, &upgrade_weechat_read_cb);
+ upgrade_file = upgrade_file_new (WEECHAT_UPGRADE_FILENAME, 0);
+ rc = upgrade_file_read (upgrade_file, &upgrade_weechat_read_cb, NULL);
if (!hotlist_reset)
gui_hotlist_clear ();
diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c
index 5ce1cc4d2..096f2839c 100644
--- a/src/plugins/irc/irc-upgrade.c
+++ b/src/plugins/irc/irc-upgrade.c
@@ -124,7 +124,7 @@ irc_upgrade_save ()
int rc;
struct t_upgrade_file *upgrade_file;
- upgrade_file = weechat_upgrade_create (IRC_UPGRADE_FILENAME, 1);
+ upgrade_file = weechat_upgrade_new (IRC_UPGRADE_FILENAME, 1);
if (!upgrade_file)
return 0;
@@ -166,7 +166,9 @@ irc_upgrade_set_buffer_callbacks ()
*/
int
-irc_upgrade_read_cb (int object_id,
+irc_upgrade_read_cb (void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
struct t_infolist *infolist)
{
int flags, sock, size, i, index;
@@ -175,6 +177,10 @@ irc_upgrade_read_cb (int object_id,
struct t_irc_nick *ptr_nick;
struct t_gui_buffer *ptr_buffer;
+ /* make C compiler happy */
+ (void) data;
+ (void) upgrade_file;
+
weechat_infolist_reset_item_cursor (infolist);
while (weechat_infolist_next (infolist))
{
@@ -351,8 +357,8 @@ irc_upgrade_load ()
irc_upgrade_set_buffer_callbacks ();
- upgrade_file = weechat_upgrade_create (IRC_UPGRADE_FILENAME, 0);
- rc = weechat_upgrade_read (upgrade_file, &irc_upgrade_read_cb);
+ upgrade_file = weechat_upgrade_new (IRC_UPGRADE_FILENAME, 0);
+ rc = weechat_upgrade_read (upgrade_file, &irc_upgrade_read_cb, NULL);
return rc;
}
diff --git a/src/plugins/jabber/jabber-upgrade.c b/src/plugins/jabber/jabber-upgrade.c
index 05942c734..75229a6e6 100644
--- a/src/plugins/jabber/jabber-upgrade.c
+++ b/src/plugins/jabber/jabber-upgrade.c
@@ -125,7 +125,7 @@ jabber_upgrade_save ()
int rc;
struct t_upgrade_file *upgrade_file;
- upgrade_file = weechat_upgrade_create (JABBER_UPGRADE_FILENAME, 1);
+ upgrade_file = weechat_upgrade_new (JABBER_UPGRADE_FILENAME, 1);
if (!upgrade_file)
return 0;
@@ -168,7 +168,9 @@ jabber_upgrade_set_buffer_callbacks ()
*/
int
-jabber_upgrade_read_cb (int object_id,
+jabber_upgrade_read_cb (void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
struct t_infolist *infolist)
{
int flags, size, i, index;
@@ -177,6 +179,10 @@ jabber_upgrade_read_cb (int object_id,
struct t_jabber_buddy *ptr_buddy;
struct t_gui_buffer *ptr_buffer;
+ /* make C compiler happy */
+ (void) data;
+ (void) upgrade_file;
+
weechat_infolist_reset_item_cursor (infolist);
while (weechat_infolist_next (infolist))
{
@@ -322,8 +328,8 @@ jabber_upgrade_load ()
jabber_upgrade_set_buffer_callbacks ();
- upgrade_file = weechat_upgrade_create (JABBER_UPGRADE_FILENAME, 0);
- rc = weechat_upgrade_read (upgrade_file, &jabber_upgrade_read_cb);
+ upgrade_file = weechat_upgrade_new (JABBER_UPGRADE_FILENAME, 0);
+ rc = weechat_upgrade_read (upgrade_file, &jabber_upgrade_read_cb, NULL);
return rc;
}
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 277283a13..26588ff5b 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -512,7 +512,7 @@ plugin_load (const char *filename)
new_plugin->infolist_time = &plugin_api_infolist_time;
new_plugin->infolist_free = &plugin_api_infolist_free;
- new_plugin->upgrade_create = &upgrade_file_create;
+ new_plugin->upgrade_new = &upgrade_file_new;
new_plugin->upgrade_write_object = &upgrade_file_write_object;
new_plugin->upgrade_read = &upgrade_file_read;
new_plugin->upgrade_close = &upgrade_file_close;
diff --git a/src/plugins/relay/relay-upgrade.c b/src/plugins/relay/relay-upgrade.c
index 3fcb0e332..2fd43b189 100644
--- a/src/plugins/relay/relay-upgrade.c
+++ b/src/plugins/relay/relay-upgrade.c
@@ -50,7 +50,7 @@ relay_upgrade_save ()
int rc;
struct t_upgrade_file *upgrade_file;
- upgrade_file = weechat_upgrade_create (RELAY_UPGRADE_FILENAME, 1);
+ upgrade_file = weechat_upgrade_new (RELAY_UPGRADE_FILENAME, 1);
if (!upgrade_file)
return 0;
@@ -92,12 +92,17 @@ relay_upgrade_set_buffer_callbacks ()
*/
int
-relay_upgrade_read_cb (int object_id,
- struct t_infolist *infolist)
+relay_upgrade_read_cb (void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist)
{
/* TODO: write relay read cb */
+ (void) data;
+ (void) upgrade_file;
(void) object_id;
(void) infolist;
+
return WEECHAT_RC_OK;
}
@@ -114,8 +119,8 @@ relay_upgrade_load ()
relay_upgrade_set_buffer_callbacks ();
- upgrade_file = weechat_upgrade_create (RELAY_UPGRADE_FILENAME, 0);
- rc = weechat_upgrade_read (upgrade_file, &relay_upgrade_read_cb);
+ upgrade_file = weechat_upgrade_new (RELAY_UPGRADE_FILENAME, 0);
+ rc = weechat_upgrade_read (upgrade_file, &relay_upgrade_read_cb, NULL);
return rc;
}
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);
}
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index d5d4ac4e9..a5bc6ff72 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -588,14 +588,17 @@ struct t_weechat_plugin
void (*infolist_free) (struct t_infolist *infolist);
/* upgrade */
- struct t_upgrade_file *(*upgrade_create) (const char *filename,
- int write);
+ struct t_upgrade_file *(*upgrade_new) (const char *filename,
+ int write);
int (*upgrade_write_object) (struct t_upgrade_file *upgrade_file,
int object_id,
struct t_infolist *infolist);
int (*upgrade_read) (struct t_upgrade_file *upgrade_file,
- int (*callback_read)(int object_id,
- struct t_infolist *infolist));
+ int (*callback_read)(void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
+ struct t_infolist *infolist),
+ void *callback_read_data);
void (*upgrade_close) (struct t_upgrade_file *upgrade_file);
/* WeeChat developers: ALWAYS add new functions at the end */
@@ -1120,14 +1123,16 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->infolist_free(__list)
/* upgrade */
-#define weechat_upgrade_create(__filename, __write) \
- weechat_plugin->upgrade_create(__filename, __write)
+#define weechat_upgrade_new(__filename, __write) \
+ weechat_plugin->upgrade_new(__filename, __write)
#define weechat_upgrade_write_object(__upgrade_file, __object_id, \
__infolist) \
weechat_plugin->upgrade_write_object(__upgrade_file, __object_id, \
__infolist)
-#define weechat_upgrade_read(__upgrade_file, __callback) \
- weechat_plugin->upgrade_read(__upgrade_file, __callback)
+#define weechat_upgrade_read(__upgrade_file, __callback_read, \
+ __callback_read_data) \
+ weechat_plugin->upgrade_read(__upgrade_file, __callback_read, \
+ __callback_read_data)
#define weechat_upgrade_close(__upgrade_file) \
weechat_plugin->upgrade_close(__upgrade_file)
diff --git a/src/plugins/xfer/xfer-upgrade.c b/src/plugins/xfer/xfer-upgrade.c
index 36e4cb145..1e156baa9 100644
--- a/src/plugins/xfer/xfer-upgrade.c
+++ b/src/plugins/xfer/xfer-upgrade.c
@@ -51,7 +51,7 @@ xfer_upgrade_save ()
int rc;
struct t_upgrade_file *upgrade_file;
- upgrade_file = weechat_upgrade_create (XFER_UPGRADE_FILENAME, 1);
+ upgrade_file = weechat_upgrade_new (XFER_UPGRADE_FILENAME, 1);
if (!upgrade_file)
return 0;
@@ -93,12 +93,17 @@ xfer_upgrade_set_buffer_callbacks ()
*/
int
-xfer_upgrade_read_cb (int object_id,
+xfer_upgrade_read_cb (void *data,
+ struct t_upgrade_file *upgrade_file,
+ int object_id,
struct t_infolist *infolist)
{
/* TODO: write xfer read cb */
+ (void) data;
+ (void) upgrade_file;
(void) object_id;
(void) infolist;
+
return WEECHAT_RC_OK;
}
@@ -115,8 +120,8 @@ xfer_upgrade_load ()
xfer_upgrade_set_buffer_callbacks ();
- upgrade_file = weechat_upgrade_create (XFER_UPGRADE_FILENAME, 0);
- rc = weechat_upgrade_read (upgrade_file, &xfer_upgrade_read_cb);
+ upgrade_file = weechat_upgrade_new (XFER_UPGRADE_FILENAME, 0);
+ rc = weechat_upgrade_read (upgrade_file, &xfer_upgrade_read_cb, NULL);
return rc;
}