summaryrefslogtreecommitdiff
path: root/src/plugins/scripts
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-01-27 10:48:29 +0100
committerSebastien Helleu <flashcode@flashtux.org>2008-01-27 10:48:29 +0100
commitad414865430d2d073689f849283a10b06711f1b8 (patch)
tree46c12eff476081782dc6322068bc7630ba4e94a9 /src/plugins/scripts
parented26a0389c06250f02329fa477d2cffe7df59b5e (diff)
downloadweechat-ad414865430d2d073689f849283a10b06711f1b8.zip
Added config file functions in plugins API, improved /reload and /save commands (now possible to reload/save some files only), fixed completion bug
Diffstat (limited to 'src/plugins/scripts')
-rw-r--r--src/plugins/scripts/lua/weechat-lua-api.c1757
-rw-r--r--src/plugins/scripts/lua/weechat-lua.c3
-rw-r--r--src/plugins/scripts/perl/weechat-perl-api.c1429
-rw-r--r--src/plugins/scripts/python/weechat-python-api.c1744
-rw-r--r--src/plugins/scripts/python/weechat-python.c4
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby-api.c1661
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby.c4
-rw-r--r--src/plugins/scripts/script-api.c269
-rw-r--r--src/plugins/scripts/script-api.h47
-rw-r--r--src/plugins/scripts/script-callback.c13
-rw-r--r--src/plugins/scripts/script-callback.h17
-rw-r--r--src/plugins/scripts/script.c21
12 files changed, 3449 insertions, 3520 deletions
diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c
index a5ad609f0..b4cb6c488 100644
--- a/src/plugins/scripts/lua/weechat-lua-api.c
+++ b/src/plugins/scripts/lua/weechat-lua-api.c
@@ -874,6 +874,821 @@ weechat_lua_api_list_free (lua_State *L)
}
/*
+ * weechat_lua_api_config_reload_cb: callback for ccnfig reload
+ */
+
+int
+weechat_lua_api_config_reload_cb (void *data,
+ struct t_config_file *config_file)
+{
+ struct t_script_callback *script_callback;
+ char *lua_argv[2];
+ int *rc, ret;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ lua_argv[0] = script_ptr2str (config_file);
+ lua_argv[1] = 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]);
+
+ return ret;
+ }
+
+ return 0;
+}
+
+/*
+ * weechat_lua_api_config_new: create a new configuration file
+ */
+
+static int
+weechat_lua_api_config_new (lua_State *L)
+{
+ const char *filename, *function;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new");
+ LUA_RETURN_EMPTY;
+ }
+
+ filename = NULL;
+ function = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new");
+ LUA_RETURN_EMPTY;
+ }
+
+ filename = lua_tostring (lua_current_interpreter, -2);
+ function = lua_tostring (lua_current_interpreter, -1);
+
+ result = script_ptr2str (script_api_config_new (weechat_lua_plugin,
+ lua_current_script,
+ (char *)filename,
+ &weechat_lua_api_config_reload_cb,
+ (char *)function));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_config_read_cb: callback for reading option in section
+ */
+
+void
+weechat_lua_api_config_read_cb (void *data,
+ struct t_config_file *config_file,
+ char *option_name, char *value)
+{
+ struct t_script_callback *script_callback;
+ char *lua_argv[4];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ lua_argv[0] = script_ptr2str (config_file);
+ lua_argv[1] = option_name;
+ lua_argv[2] = value;
+ lua_argv[3] = NULL;
+
+ rc = (int *) weechat_lua_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ lua_argv);
+
+ if (rc)
+ free (rc);
+ if (lua_argv[0])
+ free (lua_argv[0]);
+ }
+}
+
+/*
+ * weechat_lua_api_config_section_write_cb: callback for writing section
+ */
+
+void
+weechat_lua_api_config_section_write_cb (void *data,
+ struct t_config_file *config_file,
+ char *section_name)
+{
+ struct t_script_callback *script_callback;
+ char *lua_argv[3];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ lua_argv[0] = script_ptr2str (config_file);
+ lua_argv[1] = section_name;
+ lua_argv[2] = NULL;
+
+ rc = (int *) weechat_lua_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ lua_argv);
+
+ if (rc)
+ free (rc);
+ if (lua_argv[0])
+ free (lua_argv[0]);
+ }
+}
+
+/*
+ * weechat_lua_api_config_section_write_default_cb: callback for writing
+ * default values for section
+ */
+
+void
+weechat_lua_api_config_section_write_default_cb (void *data,
+ struct t_config_file *config_file,
+ char *section_name)
+{
+ struct t_script_callback *script_callback;
+ char *lua_argv[3];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ lua_argv[0] = script_ptr2str (config_file);
+ lua_argv[1] = section_name;
+ lua_argv[2] = NULL;
+
+ rc = (int *) weechat_lua_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ lua_argv);
+
+ if (rc)
+ free (rc);
+ if (lua_argv[0])
+ free (lua_argv[0]);
+ }
+}
+
+/*
+ * weechat_lua_api_config_new_section: create a new section in configuration file
+ */
+
+static int
+weechat_lua_api_config_new_section (lua_State *L)
+{
+ const char *config_file, *name, *function_read, *function_write;
+ const char *function_write_default;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new_section");
+ LUA_RETURN_EMPTY;
+ }
+
+ config_file = NULL;
+ name = NULL;
+ function_read = NULL;
+ function_write = NULL;
+ function_write_default = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 5)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section");
+ LUA_RETURN_EMPTY;
+ }
+
+ config_file = lua_tostring (lua_current_interpreter, -5);
+ name = lua_tostring (lua_current_interpreter, -4);
+ function_read = lua_tostring (lua_current_interpreter, -3);
+ function_write = lua_tostring (lua_current_interpreter, -2);
+ function_write_default = lua_tostring (lua_current_interpreter, -1);
+
+ result = script_ptr2str (script_api_config_new_section (weechat_lua_plugin,
+ lua_current_script,
+ script_str2ptr ((char *)config_file),
+ (char *)name,
+ &weechat_lua_api_config_read_cb,
+ (char *)function_read,
+ &weechat_lua_api_config_section_write_cb,
+ (char *)function_write,
+ &weechat_lua_api_config_section_write_cb,
+ (char *)function_write_default));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_config_search_section: search a section in configuration file
+ */
+
+static int
+weechat_lua_api_config_search_section (lua_State *L)
+{
+ const char *config_file, *section_name;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_search_section");
+ LUA_RETURN_EMPTY;
+ }
+
+ config_file = NULL;
+ section_name = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_search_section");
+ LUA_RETURN_EMPTY;
+ }
+
+ config_file = lua_tostring (lua_current_interpreter, -2);
+ section_name = lua_tostring (lua_current_interpreter, -1);
+
+ result = script_ptr2str (weechat_config_search_section (script_str2ptr ((char *)config_file),
+ (char *)section_name));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_config_option_change_cb: callback for option changed
+ */
+
+void
+weechat_lua_api_config_option_change_cb (void *data)
+{
+ struct t_script_callback *script_callback;
+ char *lua_argv[1];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ lua_argv[1] = NULL;
+
+ rc = (int *) weechat_lua_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ lua_argv);
+
+ if (rc)
+ free (rc);
+ }
+}
+
+/*
+ * weechat_lua_api_config_new_option: create a new option in section
+ */
+
+static int
+weechat_lua_api_config_new_option (lua_State *L)
+{
+ const char *config_file, *section, *name, *type, *description;
+ const char *string_values, *default_value, *function;
+ char *result;
+ int n, min, max;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new_option");
+ LUA_RETURN_EMPTY;
+ }
+
+ config_file = NULL;
+ section = NULL;
+ name = NULL;
+ type = NULL;
+ description = NULL;
+ string_values = NULL;
+ min = 0;
+ max = 0;
+ default_value = NULL;
+ function = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 10)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option");
+ LUA_RETURN_EMPTY;
+ }
+
+ config_file = lua_tostring (lua_current_interpreter, -10);
+ section = lua_tostring (lua_current_interpreter, -9);
+ name = lua_tostring (lua_current_interpreter, -8);
+ type = lua_tostring (lua_current_interpreter, -7);
+ description = lua_tostring (lua_current_interpreter, -6);
+ string_values = lua_tostring (lua_current_interpreter, -5);
+ min = lua_tonumber (lua_current_interpreter, -4);
+ max = lua_tonumber (lua_current_interpreter, -3);
+ default_value = lua_tostring (lua_current_interpreter, -2);
+ function = lua_tostring (lua_current_interpreter, -1);
+
+ result = script_ptr2str (script_api_config_new_option (weechat_lua_plugin,
+ lua_current_script,
+ script_str2ptr ((char *)config_file),
+ script_str2ptr ((char *)section),
+ (char *)name,
+ (char *)type,
+ (char *)description,
+ (char *)string_values,
+ min,
+ max,
+ (char *)default_value,
+ &weechat_lua_api_config_option_change_cb,
+ (char *)function));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_config_search_option: search option in configuration file or section
+ */
+
+static int
+weechat_lua_api_config_search_option (lua_State *L)
+{
+ const char *config_file, *section, *option_name;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_search_option");
+ LUA_RETURN_EMPTY;
+ }
+
+ config_file = NULL;
+ section = NULL;
+ option_name = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_search_option");
+ LUA_RETURN_EMPTY;
+ }
+
+ config_file = lua_tostring (lua_current_interpreter, -3);
+ section = lua_tostring (lua_current_interpreter, -2);
+ option_name = lua_tostring (lua_current_interpreter, -1);
+
+ result = script_ptr2str (weechat_config_search_option (script_str2ptr ((char *)config_file),
+ script_str2ptr ((char *)section),
+ (char *)option_name));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_config_string_to_boolean: return boolean value of a string
+ */
+
+static int
+weechat_lua_api_config_string_to_boolean (lua_State *L)
+{
+ const char *text;
+ int n, value;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_string_to_boolean");
+ LUA_RETURN_INT(0);
+ }
+
+ text = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_string_to_boolean");
+ LUA_RETURN_INT(0);
+ }
+
+ text = lua_tostring (lua_current_interpreter, -1);
+
+ value = weechat_config_string_to_boolean ((char *)text);
+ LUA_RETURN_INT(value);
+}
+
+/*
+ * weechat_lua_api_config_option_set: set new value for option
+ */
+
+static int
+weechat_lua_api_config_option_set (lua_State *L)
+{
+ const char *option, *new_value;
+ int n, run_callback, rc;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set");
+ LUA_RETURN_INT(0);
+ }
+
+ option = NULL;
+ new_value = NULL;
+ run_callback = 0;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set");
+ LUA_RETURN_INT(0);
+ }
+
+ option = lua_tostring (lua_current_interpreter, -3);
+ new_value = lua_tostring (lua_current_interpreter, -2);
+ run_callback = lua_tonumber (lua_current_interpreter, -1);
+
+ rc = weechat_config_option_set (script_str2ptr ((char *)option),
+ (char *)new_value,
+ run_callback);
+ LUA_RETURN_INT(rc);
+}
+
+/*
+ * weechat_lua_api_config_boolean: return boolean value of option
+ */
+
+static int
+weechat_lua_api_config_boolean (lua_State *L)
+{
+ const char *option;
+ int n, value;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_boolean");
+ LUA_RETURN_INT(0);
+ }
+
+ option = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_boolean");
+ LUA_RETURN_INT(0);
+ }
+
+ option = lua_tostring (lua_current_interpreter, -1);
+
+ value = weechat_config_boolean (script_str2ptr ((char *)option));
+ LUA_RETURN_INT(value);
+}
+
+/*
+ * weechat_lua_api_config_integer: return integer value of option
+ */
+
+static int
+weechat_lua_api_config_integer (lua_State *L)
+{
+ const char *option;
+ int n, value;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_integer");
+ LUA_RETURN_INT(0);
+ }
+
+ option = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_integer");
+ LUA_RETURN_INT(0);
+ }
+
+ option = lua_tostring (lua_current_interpreter, -1);
+
+ value = weechat_config_integer (script_str2ptr ((char *)option));
+ LUA_RETURN_INT(value);
+}
+
+/*
+ * weechat_lua_api_config_string: return string value of option
+ */
+
+static int
+weechat_lua_api_config_string (lua_State *L)
+{
+ const char *option;
+ char *value;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_string");
+ LUA_RETURN_EMPTY;
+ }
+
+ option = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_string");
+ LUA_RETURN_INT(0);
+ }
+
+ option = lua_tostring (lua_current_interpreter, -1);
+
+ value = weechat_config_string (script_str2ptr ((char *)option));
+ LUA_RETURN_STRING(value);
+}
+
+/*
+ * weechat_lua_api_config_color: return color value of option
+ */
+
+static int
+weechat_lua_api_config_color (lua_State *L)
+{
+ const char *option;
+ int n, value;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_color");
+ LUA_RETURN_INT(0);
+ }
+
+ option = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_color");
+ LUA_RETURN_INT(0);
+ }
+
+ option = lua_tostring (lua_current_interpreter, -1);
+
+ value = weechat_config_color (script_str2ptr ((char *)option));
+ LUA_RETURN_INT(value);
+}
+
+/*
+ * weechat_lua_api_config_write_line: write a line in configuration file
+ */
+
+static int
+weechat_lua_api_config_write_line (lua_State *L)
+{
+ const char *config_file, *option_name, *value;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write_line");
+ LUA_RETURN_ERROR;
+ }
+
+ config_file = NULL;
+ option_name = NULL;
+ value = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write_line");
+ LUA_RETURN_ERROR;
+ }
+
+ config_file = lua_tostring (lua_current_interpreter, -3);
+ option_name = lua_tostring (lua_current_interpreter, -2);
+ value = lua_tostring (lua_current_interpreter, -1);
+
+ weechat_config_write_line (script_str2ptr ((char *)config_file),
+ (char *)option_name,
+ "%s",
+ (char *)value);
+
+ LUA_RETURN_OK;
+}
+
+/*
+ * weechat_lua_api_config_write: write configuration file
+ */
+
+static int
+weechat_lua_api_config_write (lua_State *L)
+{
+ const char *config_file;
+ int n, rc;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write");
+ LUA_RETURN_INT(-1);
+ }
+
+ config_file = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write");
+ LUA_RETURN_INT(-1);
+ }
+
+ config_file = lua_tostring (lua_current_interpreter, -1);
+
+ rc = weechat_config_write (script_str2ptr ((char *)config_file));
+ LUA_RETURN_INT(rc);
+}
+
+/*
+ * weechat_lua_api_config_read: read configuration file
+ */
+
+static int
+weechat_lua_api_config_read (lua_State *L)
+{
+ const char *config_file;
+ int n, rc;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_read");
+ LUA_RETURN_INT(-1);
+ }
+
+ config_file = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_read");
+ LUA_RETURN_INT(-1);
+ }
+
+ config_file = lua_tostring (lua_current_interpreter, -1);
+
+ rc = weechat_config_read (script_str2ptr ((char *)config_file));
+ LUA_RETURN_INT(rc);
+}
+
+/*
+ * weechat_lua_api_config_reload: reload configuration file
+ */
+
+static int
+weechat_lua_api_config_reload (lua_State *L)
+{
+ const char *config_file;
+ int n, rc;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_reload");
+ LUA_RETURN_INT(-1);
+ }
+
+ config_file = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_reload");
+ LUA_RETURN_INT(-1);
+ }
+
+ config_file = lua_tostring (lua_current_interpreter, -1);
+
+ rc = weechat_config_reload (script_str2ptr ((char *)config_file));
+ LUA_RETURN_INT(rc);
+}
+
+/*
+ * weechat_lua_api_config_free: free configuration file
+ */
+
+static int
+weechat_lua_api_config_free (lua_State *L)
+{
+ const char *config_file;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_free");
+ LUA_RETURN_ERROR;
+ }
+
+ config_file = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_free");
+ LUA_RETURN_ERROR;
+ }
+
+ config_file = lua_tostring (lua_current_interpreter, -1);
+
+ script_api_config_free (weechat_lua_plugin,
+ lua_current_script,
+ script_str2ptr ((char *)config_file));
+
+ LUA_RETURN_OK;
+}
+
+/*
* weechat_lua_api_prefix: get a prefix, used for display
*/
@@ -1891,12 +2706,11 @@ weechat_lua_api_unhook (lua_State *L)
hook = lua_tostring (lua_current_interpreter, -1);
- if (script_api_unhook (weechat_lua_plugin,
- lua_current_script,
- script_str2ptr ((char *)hook)))
- LUA_RETURN_OK;
-
- LUA_RETURN_ERROR;
+ script_api_unhook (weechat_lua_plugin,
+ lua_current_script,
+ script_str2ptr ((char *)hook));
+
+ LUA_RETURN_OK;
}
/*
@@ -1915,8 +2729,7 @@ weechat_lua_api_unhook_all (lua_State *L)
LUA_RETURN_ERROR;
}
- script_api_unhook_all (weechat_lua_plugin,
- lua_current_script);
+ script_api_unhook_all (lua_current_script);
LUA_RETURN_OK;
}
@@ -2544,906 +3357,6 @@ weechat_lua_api_info_get (lua_State *L)
}
/*
- * weechat_lua_api_get_dcc_info: get infos about DCC
- */
-
-/*
-static int
-weechat_lua_api_get_dcc_info (lua_State *L)
-{
- t_plugin_dcc_info *dcc_info, *ptr_dcc;
- char timebuffer1[64];
- char timebuffer2[64];
- struct in_addr in;
- int i;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to get DCC info, "
- "script not initialized");
- lua_pushnil (lua_current_interpreter);
- return 1;
- }
-
- dcc_info = lua_plugin->get_dcc_info (lua_plugin);
- if (!dcc_info)
- {
- lua_pushboolean (lua_current_interpreter, 0);
- return 1;
- }
-
- lua_newtable (lua_current_interpreter);
-
- for (i = 0, ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc, i++)
- {
- strftime(timebuffer1, sizeof(timebuffer1), "%F %T",
- localtime(&ptr_dcc->start_time));
- strftime(timebuffer2, sizeof(timebuffer2), "%F %T",
- localtime(&ptr_dcc->start_transfer));
- in.s_addr = htonl(ptr_dcc->addr);
-
- lua_pushnumber (lua_current_interpreter, i);
- lua_newtable (lua_current_interpreter);
-
- lua_pushstring (lua_current_interpreter, "server");
- lua_pushstring (lua_current_interpreter, ptr_dcc->server);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "channel");
- lua_pushstring (lua_current_interpreter, ptr_dcc->channel);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "type");
- lua_pushnumber (lua_current_interpreter, ptr_dcc->type);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "status");
- lua_pushnumber (lua_current_interpreter, ptr_dcc->status);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "start_time");
- lua_pushstring (lua_current_interpreter, timebuffer1);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "start_transfer");
- lua_pushstring (lua_current_interpreter, timebuffer2);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "address");
- lua_pushstring (lua_current_interpreter, inet_ntoa(in));
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "port");
- lua_pushnumber (lua_current_interpreter, ptr_dcc->port);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "nick");
- lua_pushstring (lua_current_interpreter, ptr_dcc->nick);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "remote_file");
- lua_pushstring (lua_current_interpreter, ptr_dcc->filename);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "local_file");
- lua_pushstring (lua_current_interpreter, ptr_dcc->local_filename);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "filename_suffix");
- lua_pushnumber (lua_current_interpreter, ptr_dcc->filename_suffix);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "size");
- lua_pushnumber (lua_current_interpreter, ptr_dcc->size);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "pos");
- lua_pushnumber (lua_current_interpreter, ptr_dcc->pos);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "start_resume");
- lua_pushnumber (lua_current_interpreter, ptr_dcc->start_resume);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "cps");
- lua_pushnumber (lua_current_interpreter, ptr_dcc->bytes_per_sec);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_rawset (lua_current_interpreter, -3);
- }
-
- lua_plugin->free_dcc_info (lua_plugin, dcc_info);
-
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_get_config: get value of a WeeChat config option
- */
-
-/*
-static int
-weechat_lua_api_get_config (lua_State *L)
-{
- const char *option;
- char *return_value;
- int n;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to get config option, "
- "script not initialized");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
- }
-
- option = NULL;
-
- n = lua_gettop (lua_current_interpreter);
-
- if (n != 1)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"get_config\" function");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
- }
-
- option = lua_tostring (lua_current_interpreter, -1);
-
- return_value = lua_plugin->get_config (lua_plugin, (char *) option);
- if (return_value)
- lua_pushstring (lua_current_interpreter, return_value);
- else
- lua_pushstring (lua_current_interpreter, "");
-
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_set_config: set value of a WeeChat config option
- */
-
-/*
-static int
-weechat_lua_api_set_config (lua_State *L)
-{
- const char *option, *value;
- int n;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to set config option, "
- "script not initialized");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
- }
-
- option = NULL;
- value = NULL;
-
- n = lua_gettop (lua_current_interpreter);
-
- if (n != 2)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"set_config\" function");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
- }
-
- option = lua_tostring (lua_current_interpreter, -2);
- value = lua_tostring (lua_current_interpreter, -1);
-
- if (lua_plugin->set_config (lua_plugin, (char *) option, (char *) value))
- lua_pushnumber (lua_current_interpreter, 1);
- else
- lua_pushnumber (lua_current_interpreter, 0);
-
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_get_plugin_config: get value of a plugin config option
- */
-
-/*
-static int
-weechat_lua_api_get_plugin_config (lua_State *L)
-{
- const char *option;
- char *return_value;
- int n;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to get plugin config option, "
- "script not initialized");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
- }
-
- option = NULL;
-
- n = lua_gettop (lua_current_interpreter);
-
- if (n != 1)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"get_plugin_config\" function");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
- }
-
- option = lua_tostring (lua_current_interpreter, -1);
-
- return_value = weechat_script_get_plugin_config (lua_plugin,
- lua_current_script,
- (char *) option);
- if (return_value)
- lua_pushstring (lua_current_interpreter, return_value);
- else
- lua_pushstring (lua_current_interpreter, "");
-
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_set_plugin_config: set value of a plugin config option
- */
-
-/*
-static int
-weechat_lua_api_set_plugin_config (lua_State *L)
-{
- const char *option, *value;
- int n;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to set plugin config option, "
- "script not initialized");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
- }
-
- option = NULL;
- value = NULL;
-
- n = lua_gettop (lua_current_interpreter);
-
- if (n != 2)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"set_plugin_config\" function");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
- }
-
- option = lua_tostring (lua_current_interpreter, -2);
- value = lua_tostring (lua_current_interpreter, -1);
-
- if (weechat_script_set_plugin_config (lua_plugin,
- lua_current_script,
- (char *) option, (char *) value))
- lua_pushnumber (lua_current_interpreter, 1);
- else
- lua_pushnumber (lua_current_interpreter, 0);
-
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_get_server_info: get infos about servers
- */
-
-/*
-static int
-weechat_lua_api_get_server_info (lua_State *L)
-{
- t_plugin_server_info *server_info, *ptr_server;
- char timebuffer[64];
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to get server infos, "
- "script not initialized");
- lua_pushnil (lua_current_interpreter);
- return 1;
- }
-
- server_info = lua_plugin->get_server_info (lua_plugin);
- if (!server_info) {
- lua_pushboolean (lua_current_interpreter, 0);
- return 1;
- }
-
- lua_newtable (lua_current_interpreter);
-
- for (ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server)
- {
- strftime(timebuffer, sizeof(timebuffer), "%F %T",
- localtime(&ptr_server->away_time));
-
- lua_pushstring (lua_current_interpreter, ptr_server->name);
- lua_newtable (lua_current_interpreter);
-
- lua_pushstring (lua_current_interpreter, "autoconnect");
- lua_pushnumber (lua_current_interpreter, ptr_server->autoconnect);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "autoreconnect");
- lua_pushnumber (lua_current_interpreter, ptr_server->autoreconnect);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "autoreconnect_delay");
- lua_pushnumber (lua_current_interpreter, ptr_server->autoreconnect_delay);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "temp_server");
- lua_pushnumber (lua_current_interpreter, ptr_server->temp_server);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "address");
- lua_pushstring (lua_current_interpreter, ptr_server->address);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "port");
- lua_pushnumber (lua_current_interpreter, ptr_server->port);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "ipv6");
- lua_pushnumber (lua_current_interpreter, ptr_server->ipv6);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "ssl");
- lua_pushnumber (lua_current_interpreter, ptr_server->ssl);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "password");
- lua_pushstring (lua_current_interpreter, ptr_server->password);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "nick1");
- lua_pushstring (lua_current_interpreter, ptr_server->nick1);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "nick2");
- lua_pushstring (lua_current_interpreter, ptr_server->nick2);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "nick3");
- lua_pushstring (lua_current_interpreter, ptr_server->nick3);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "username");
- lua_pushstring (lua_current_interpreter, ptr_server->username);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "realname");
- lua_pushstring (lua_current_interpreter, ptr_server->realname);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "command");
- lua_pushstring (lua_current_interpreter, ptr_server->command);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "command_delay");
- lua_pushnumber (lua_current_interpreter, ptr_server->command_delay);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "autojoin");
- lua_pushstring (lua_current_interpreter, ptr_server->autojoin);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "autorejoin");
- lua_pushnumber (lua_current_interpreter, ptr_server->autorejoin);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "notify_levels");
- lua_pushstring (lua_current_interpreter, ptr_server->notify_levels);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "is_connected");
- lua_pushnumber (lua_current_interpreter, ptr_server->is_connected);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "ssl_connected");
- lua_pushnumber (lua_current_interpreter, ptr_server->ssl_connected);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "nick");
- lua_pushstring (lua_current_interpreter, ptr_server->nick);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "nick_modes");
- lua_pushstring (lua_current_interpreter, ptr_server->nick_modes);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "away_time");
- lua_pushstring (lua_current_interpreter, timebuffer);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "lag");
- lua_pushnumber (lua_current_interpreter, ptr_server->lag);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_rawset (lua_current_interpreter, -3);
- }
-
- lua_plugin->free_server_info(lua_plugin, server_info);
-
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_get_channel_info: get infos about channels
- */
-
-/*
-static int
-weechat_lua_api_get_channel_info (lua_State *L)
-{
- t_plugin_channel_info *channel_info, *ptr_channel;
- const char *server;
- int n;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to get channel infos, "
- "script not initialized");
- lua_pushnil (lua_current_interpreter);
- return 1;
- }
-
- server = NULL;
-
- n = lua_gettop (lua_current_interpreter);
-
- if (n != 1)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"get_channel_info\" function");
- lua_pushnil (lua_current_interpreter);
- return 1;
- }
-
- server = lua_tostring (lua_current_interpreter, -1);
-
- channel_info = lua_plugin->get_channel_info (lua_plugin, (char *) server);
- if (!channel_info)
- {
- lua_pushboolean (lua_current_interpreter, 0);
- return 1;
- }
-
- lua_newtable (lua_current_interpreter);
-
- for (ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel)
- {
- lua_pushstring (lua_current_interpreter, ptr_channel->name);
- lua_newtable (lua_current_interpreter);
-
- lua_pushstring (lua_current_interpreter, "type");
- lua_pushnumber (lua_current_interpreter, ptr_channel->type);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "topic");
- lua_pushstring (lua_current_interpreter, ptr_channel->topic);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "modes");
- lua_pushstring (lua_current_interpreter, ptr_channel->modes);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "limit");
- lua_pushnumber (lua_current_interpreter, ptr_channel->limit);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "key");
- lua_pushstring (lua_current_interpreter, ptr_channel->key);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "nicks_count");
- lua_pushnumber (lua_current_interpreter, ptr_channel->nicks_count);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_rawset (lua_current_interpreter, -3);
- }
-
- lua_plugin->free_channel_info(lua_plugin, channel_info);
-
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_get_nick_info: get infos about nicks
- */
-
-/*
-static int
-weechat_lua_api_get_nick_info (lua_State *L)
-{
- t_plugin_nick_info *nick_info, *ptr_nick;
- const char *server, *channel;
- int n;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to get nick infos, "
- "script not initialized");
- lua_pushnil (lua_current_interpreter);
- return 1;
- }
-
- server = NULL;
- channel = NULL;
-
- n = lua_gettop (lua_current_interpreter);
-
- if (n != 2)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"get_nick_info\" function");
- lua_pushnil (lua_current_interpreter);
- return 1;
- }
-
- server = lua_tostring (lua_current_interpreter, -2);
- channel = lua_tostring (lua_current_interpreter, -1);
-
- nick_info = lua_plugin->get_nick_info (lua_plugin, (char *) server, (char *) channel);
- if (!nick_info)
- {
- lua_pushboolean (lua_current_interpreter, 0);
- return 1;
- }
-
- lua_newtable (lua_current_interpreter);
-
- for(ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick)
- {
- lua_pushstring (lua_current_interpreter, ptr_nick->nick);
- lua_newtable (lua_current_interpreter);
-
- lua_pushstring (lua_current_interpreter, "flags");
- lua_pushnumber (lua_current_interpreter, ptr_nick->flags);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "host");
- lua_pushstring (lua_current_interpreter,
- ptr_nick->host ? ptr_nick->host : "");
- lua_rawset (lua_current_interpreter, -3);
-
- lua_rawset (lua_current_interpreter, -3);
- }
-
- lua_plugin->free_nick_info(lua_plugin, nick_info);
-
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_get_irc_color:
- * get the numeric value which identify an irc color by its name
- */
-
-/*
-static int
-weechat_lua_api_get_irc_color (lua_State *L)
-{
- const char *color;
- int n;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to get irc color, "
- "script not initialized");
- lua_pushnumber (lua_current_interpreter, -1);
- return 1;
- }
-
- color = NULL;
-
- n = lua_gettop (lua_current_interpreter);
-
- if (n != 1)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"get_irc_color\" function");
- lua_pushnumber (lua_current_interpreter, -1);
- return 1;
- }
-
- color = lua_tostring (lua_current_interpreter, -1);
-
- lua_pushnumber (lua_current_interpreter,
- lua_plugin->get_irc_color (lua_plugin, (char *) color));
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_get_window_info: get infos about windows
- */
-
-/*
-static int
-weechat_lua_api_get_window_info (lua_State *L)
-{
- t_plugin_window_info *window_info, *ptr_win;
- int i;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to get window info, "
- "script not initialized");
- lua_pushnil (lua_current_interpreter);
- return 1;
- }
-
- window_info = lua_plugin->get_window_info (lua_plugin);
- if (!window_info)
- {
- lua_pushboolean (lua_current_interpreter, 0);
- return 1;
- }
-
- lua_newtable (lua_current_interpreter);
-
- i = 0;
- for (ptr_win = window_info; ptr_win; ptr_win = ptr_win->next_window)
- {
- lua_pushnumber (lua_current_interpreter, i);
- lua_newtable (lua_current_interpreter);
-
- lua_pushstring (lua_current_interpreter, "num_buffer");
- lua_pushnumber (lua_current_interpreter, ptr_win->num_buffer);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "win_x");
- lua_pushnumber (lua_current_interpreter, ptr_win->win_x);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "win_y");
- lua_pushnumber (lua_current_interpreter, ptr_win->win_y);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "win_width");
- lua_pushnumber (lua_current_interpreter, ptr_win->win_width);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "win_height");
- lua_pushnumber (lua_current_interpreter, ptr_win->win_height);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "win_width_pct");
- lua_pushnumber (lua_current_interpreter, ptr_win->win_width_pct);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "win_height_pct");
- lua_pushnumber (lua_current_interpreter, ptr_win->win_height_pct);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_rawset (lua_current_interpreter, -3);
-
- i++;
- }
-
- lua_plugin->free_window_info (lua_plugin, window_info);
-
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_get_buffer_info: get infos about buffers
- */
-
-/*
-static int
-weechat_lua_api_get_buffer_info (lua_State *L)
-{
- t_plugin_buffer_info *buffer_info, *ptr_buffer;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to get buffer info, "
- "script not initialized");
- lua_pushnil (lua_current_interpreter);
- return 1;
- }
-
- buffer_info = lua_plugin->get_buffer_info (lua_plugin);
- if (!buffer_info) {
- lua_pushboolean (lua_current_interpreter, 0);
- return 1;
- }
-
- lua_newtable (lua_current_interpreter);
-
- for (ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
- {
- lua_pushnumber (lua_current_interpreter, ptr_buffer->number);
- lua_newtable (lua_current_interpreter);
-
- lua_pushstring (lua_current_interpreter, "type");
- lua_pushnumber (lua_current_interpreter, ptr_buffer->type);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "num_displayed");
- lua_pushnumber (lua_current_interpreter, ptr_buffer->num_displayed);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "server");
- lua_pushstring (lua_current_interpreter,
- ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "channel");
- lua_pushstring (lua_current_interpreter,
- ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "notify_level");
- lua_pushnumber (lua_current_interpreter, ptr_buffer->notify_level);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "log_filename");
- lua_pushstring (lua_current_interpreter,
- ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_rawset (lua_current_interpreter, -3);
- }
-
- lua_plugin->free_buffer_info(lua_plugin, buffer_info);
-
- return 1;
-}
-*/
-
-/*
- * weechat_lua_api_get_buffer_data: get buffer content
- */
-
-/*
-static int
-weechat_lua_api_get_buffer_data (lua_State *L)
-{
- t_plugin_buffer_line *buffer_data, *ptr_data;
- const char *server, *channel;
- char timebuffer[64];
- int i, n;
-
- // make C compiler happy
- (void) L;
-
- if (!lua_current_script)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: unable to get buffer data, "
- "script not initialized");
- lua_pushnil (lua_current_interpreter);
- return 1;
- }
-
- server = NULL;
- channel = NULL;
-
- n = lua_gettop (lua_current_interpreter);
- if (n != 2)
- {
- lua_plugin->print_server (lua_plugin,
- "Lua error: wrong parameters for "
- "\"get_buffer_data\" function");
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
- }
-
- server = lua_tostring (lua_current_interpreter, -2);
- channel = lua_tostring (lua_current_interpreter, -1);
-
- buffer_data = lua_plugin->get_buffer_data (lua_plugin, (char *) server, (char *) channel);
- if (!buffer_data)
- {
- lua_pushboolean (lua_current_interpreter, 0);
- return 1;
- }
-
- lua_newtable (lua_current_interpreter);
-
- for (i = 0, ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line, i++)
- {
- lua_pushnumber (lua_current_interpreter, i);
- lua_newtable (lua_current_interpreter);
-
- strftime(timebuffer, sizeof(timebuffer), "%F %T",
- localtime(&ptr_data->date));
-
- lua_pushstring (lua_current_interpreter, "date");
- lua_pushstring (lua_current_interpreter, timebuffer);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "nick");
- lua_pushstring (lua_current_interpreter,
- ptr_data->nick == NULL ? "" : ptr_data->nick);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_pushstring (lua_current_interpreter, "data");
- lua_pushstring (lua_current_interpreter,
- ptr_data->data == NULL ? "" : ptr_data->data);
- lua_rawset (lua_current_interpreter, -3);
-
- lua_rawset (lua_current_interpreter, -3);
- }
-
- lua_plugin->free_buffer_data (lua_plugin, buffer_data);
-
- return 1;
-}
-*/
-
-/*
* Lua constant as functions
*/
@@ -3633,6 +3546,22 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "list_remove", &weechat_lua_api_list_remove },
{ "list_remove_all", &weechat_lua_api_list_remove_all },
{ "list_free", &weechat_lua_api_list_free },
+ { "config_new", &weechat_lua_api_config_new },
+ { "config_new_section", &weechat_lua_api_config_new_section },
+ { "config_search_section", &weechat_lua_api_config_search_section },
+ { "config_new_option", &weechat_lua_api_config_new_option },
+ { "config_search_option", &weechat_lua_api_config_search_option },
+ { "config_string_to_boolean", &weechat_lua_api_config_string_to_boolean },
+ { "config_option_set", &weechat_lua_api_config_option_set },
+ { "config_boolean", &weechat_lua_api_config_boolean },
+ { "config_integer", &weechat_lua_api_config_integer },
+ { "config_string", &weechat_lua_api_config_string },
+ { "config_color", &weechat_lua_api_config_color },
+ { "config_write_line", &weechat_lua_api_config_write_line },
+ { "config_write", &weechat_lua_api_config_write },
+ { "config_read", &weechat_lua_api_config_read },
+ { "config_reload", &weechat_lua_api_config_reload },
+ { "config_free", &weechat_lua_api_config_free },
{ "prefix", &weechat_lua_api_prefix },
{ "color", &weechat_lua_api_color },
{ "print", &weechat_lua_api_print },
@@ -3665,18 +3594,6 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "nicklist_remove_all", &weechat_lua_api_nicklist_remove_all },
{ "command", &weechat_lua_api_command },
{ "info_get", &weechat_lua_api_info_get },
- //{ "get_dcc_info", &weechat_lua_api_get_dcc_info },
- //{ "get_config", &weechat_lua_api_get_config },
- //{ "set_config", &weechat_lua_api_set_config },
- //{ "get_plugin_config", &weechat_lua_api_get_plugin_config },
- //{ "set_plugin_config", &weechat_lua_api_set_plugin_config },
- //{ "get_server_info", &weechat_lua_api_get_server_info },
- //{ "get_channel_info", &weechat_lua_api_get_channel_info },
- //{ "get_nick_info", &weechat_lua_api_get_nick_info },
- //{ "get_irc_color", &weechat_lua_api_get_irc_color },
- //{ "get_window_info", &weechat_lua_api_get_window_info },
- //{ "get_buffer_info", &weechat_lua_api_get_buffer_info },
- //{ "get_buffer_data", &weechat_lua_api_get_buffer_data },
/* define constants as function which returns values */
{ "WEECHAT_RC_OK", &weechat_lua_api_constant_weechat_rc_ok },
{ "WEECHAT_RC_ERROR", &weechat_lua_api_constant_weechat_rc_error },
diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c
index 00b77283b..44967c82b 100644
--- a/src/plugins/scripts/lua/weechat-lua.c
+++ b/src/plugins/scripts/lua/weechat-lua.c
@@ -213,7 +213,8 @@ weechat_lua_load (char *filename)
fclose (fp);
/* if script was registered, removing from list */
if (lua_current_script)
- script_remove (weechat_lua_plugin, &lua_scripts, lua_current_script);
+ script_remove (weechat_lua_plugin, &lua_scripts,
+ lua_current_script);
return 0;
}
fclose (fp);
diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c
index 23b5a56cc..ddce8a7f6 100644
--- a/src/plugins/scripts/perl/weechat-perl-api.c
+++ b/src/plugins/scripts/perl/weechat-perl-api.c
@@ -696,6 +696,657 @@ static XS (XS_weechat_list_free)
}
/*
+ * weechat_perl_api_config_reload_cb: callback for config reload
+ */
+
+int
+weechat_perl_api_config_reload_cb (void *data,
+ struct t_config_file *config_file)
+{
+ struct t_script_callback *script_callback;
+ char *perl_argv[2];
+ int *rc, ret;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ perl_argv[0] = script_ptr2str (config_file);
+ perl_argv[1] = 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]);
+
+ return ret;
+ }
+
+ return 0;
+}
+
+/*
+ * weechat::config_new: create a new configuration file
+ */
+
+static XS (XS_weechat_config_new)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (script_api_config_new (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* filename */
+ &weechat_perl_api_config_reload_cb,
+ SvPV (ST (1), PL_na))); /* perl function */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_perl_api_config_section_read_cb: callback for reading option in section
+ */
+
+void
+weechat_perl_api_config_section_read_cb (void *data,
+ struct t_config_file *config_file,
+ char *option_name, char *value)
+{
+ struct t_script_callback *script_callback;
+ char *perl_argv[4];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ perl_argv[0] = script_ptr2str (config_file);
+ perl_argv[1] = option_name;
+ perl_argv[2] = value;
+ perl_argv[3] = NULL;
+
+ rc = (int *) weechat_perl_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ perl_argv);
+
+ if (rc)
+ free (rc);
+ if (perl_argv[0])
+ free (perl_argv[0]);
+ }
+}
+
+/*
+ * weechat_perl_api_config_section_write_cb: callback for writing section
+ */
+
+void
+weechat_perl_api_config_section_write_cb (void *data,
+ struct t_config_file *config_file,
+ char *section_name)
+{
+ struct t_script_callback *script_callback;
+ char *perl_argv[3];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ perl_argv[0] = script_ptr2str (config_file);
+ perl_argv[1] = section_name;
+ perl_argv[2] = NULL;
+
+ rc = (int *) weechat_perl_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ perl_argv);
+
+ if (rc)
+ free (rc);
+ if (perl_argv[0])
+ free (perl_argv[0]);
+ }
+}
+
+/*
+ * weechat_perl_api_config_section_write_default_cb: callback for writing
+ * default values for section
+ */
+
+void
+weechat_perl_api_config_section_write_default_cb (void *data,
+ struct t_config_file *config_file,
+ char *section_name)
+{
+ struct t_script_callback *script_callback;
+ char *perl_argv[3];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ perl_argv[0] = script_ptr2str (config_file);
+ perl_argv[1] = section_name;
+ perl_argv[2] = NULL;
+
+ rc = (int *) weechat_perl_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ perl_argv);
+
+ if (rc)
+ free (rc);
+ if (perl_argv[0])
+ free (perl_argv[0]);
+ }
+}
+
+/*
+ * weechat::config_new_section: create a new section in configuration file
+ */
+
+static XS (XS_weechat_config_new_section)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new_section");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 5)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (script_api_config_new_section (weechat_perl_plugin,
+ perl_current_script,
+ script_str2ptr (SvPV (ST (0), PL_na)), /* config_file */
+ SvPV (ST (1), PL_na), /* name */
+ &weechat_perl_api_config_section_read_cb,
+ SvPV (ST (2), PL_na), /* perl function (read cb) */
+ &weechat_perl_api_config_section_write_cb,
+ SvPV (ST (3), PL_na), /* perl function (write cb) */
+ &weechat_perl_api_config_section_write_default_cb,
+ SvPV (ST (4), PL_na))); /* perl function (write default cb) */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::config_search_section: search section in configuration file
+ */
+
+static XS (XS_weechat_config_search_section)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_search_section");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_search_section");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_config_search_section (script_str2ptr (SvPV (ST (0), PL_na)), /* config_file */
+ SvPV (ST (1), PL_na))); /* section_name */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_perl_api_config_option_change_cb: callback for option changed
+ */
+
+void
+weechat_perl_api_config_option_change_cb (void *data)
+{
+ struct t_script_callback *script_callback;
+ char *perl_argv[1];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ perl_argv[0] = NULL;
+
+ rc = (int *) weechat_perl_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ perl_argv);
+
+ if (rc)
+ free (rc);
+ }
+}
+
+/*
+ * weechat::config_new_option: create a new option in section
+ */
+
+static XS (XS_weechat_config_new_option)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new_option");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 10)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (script_api_config_new_option (weechat_perl_plugin,
+ perl_current_script,
+ script_str2ptr (SvPV (ST (0), PL_na)), /* config_file */
+ script_str2ptr (SvPV (ST (1), PL_na)), /* section */
+ SvPV (ST (2), PL_na), /* name */
+ SvPV (ST (3), PL_na), /* type */
+ SvPV (ST (4), PL_na), /* description */
+ SvPV (ST (5), PL_na), /* string_values */
+ SvIV (ST (6)), /* min */
+ SvIV (ST (7)), /* max */
+ SvPV (ST (8), PL_na), /* default_value */
+ &weechat_perl_api_config_option_change_cb,
+ SvPV (ST (9), PL_na))); /* perl function */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::config_search_option: search option in configuration file or section
+ */
+
+static XS (XS_weechat_config_search_option)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_search_option");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_search_option");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_config_search_option (script_str2ptr (SvPV (ST (0), PL_na)), /* config_file */
+ script_str2ptr (SvPV (ST (1), PL_na)), /* section */
+ SvPV (ST (2), PL_na))); /* option_name */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::config_string_to_boolean: return boolean value of a string
+ */
+
+static XS (XS_weechat_config_string_to_boolean)
+{
+ int value;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_string_to_boolean");
+ PERL_RETURN_INT(0);
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_string_to_boolean");
+ PERL_RETURN_INT(0);
+ }
+
+ value = weechat_config_string_to_boolean (SvPV (ST (0), PL_na)); /* text */
+ PERL_RETURN_INT(value);
+}
+
+/*
+ * weechat::config_option_set: set new value for option
+ */
+
+static XS (XS_weechat_config_option_set)
+{
+ int rc;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set");
+ PERL_RETURN_INT(0);
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set");
+ PERL_RETURN_INT(0);
+ }
+
+ rc = weechat_config_option_set (script_str2ptr (SvPV (ST (0), PL_na)), /* option */
+ SvPV (ST (1), PL_na), /* new_value */
+ SvIV (ST (2))); /* run_callback */
+ PERL_RETURN_INT(rc);
+}
+
+/*
+ * weechat::config_boolean: return boolean value of option
+ */
+
+static XS (XS_weechat_config_boolean)
+{
+ int value;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_boolean");
+ PERL_RETURN_INT(0);
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_boolean");
+ PERL_RETURN_INT(0);
+ }
+
+ value = weechat_config_boolean (script_str2ptr (SvPV (ST (0), PL_na))); /* option */
+ PERL_RETURN_INT(value);
+}
+
+/*
+ * weechat::config_integer: return integer value of option
+ */
+
+static XS (XS_weechat_config_integer)
+{
+ int value;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_integer");
+ PERL_RETURN_INT(0);
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_integer");
+ PERL_RETURN_INT(0);
+ }
+
+ value = weechat_config_integer (script_str2ptr (SvPV (ST (0), PL_na))); /* option */
+ PERL_RETURN_INT(value);
+}
+
+/*
+ * weechat::config_string: return string value of option
+ */
+
+static XS (XS_weechat_config_string)
+{
+ char *value;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_string");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_string");
+ PERL_RETURN_EMPTY;
+ }
+
+ value = weechat_config_string (script_str2ptr (SvPV (ST (0), PL_na))); /* option */
+ PERL_RETURN_STRING(value);
+}
+
+/*
+ * weechat::config_color: return color value of option
+ */
+
+static XS (XS_weechat_config_color)
+{
+ int value;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_color");
+ PERL_RETURN_INT(0);
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_color");
+ PERL_RETURN_INT(0);
+ }
+
+ value = weechat_config_color (script_str2ptr (SvPV (ST (0), PL_na))); /* option */
+ PERL_RETURN_INT(value);
+}
+
+/*
+ * weechat::config_write_line: write a line in configuration file
+ */
+
+static XS (XS_weechat_config_write_line)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write_line");
+ PERL_RETURN_ERROR;
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write_line");
+ PERL_RETURN_ERROR;
+ }
+
+ weechat_config_write_line (script_str2ptr (SvPV (ST (0), PL_na)), /* config_file */
+ SvPV (ST (1), PL_na), /* option_name */
+ "%s",
+ SvPV (ST (2), PL_na)); /* value */
+
+ PERL_RETURN_OK;
+}
+
+/*
+ * weechat::config_write: write configuration file
+ */
+
+static XS (XS_weechat_config_write)
+{
+ int rc;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write");
+ PERL_RETURN_INT(-1);
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write");
+ PERL_RETURN_INT(-1);
+ }
+
+ rc = weechat_config_write (script_str2ptr (SvPV (ST (0), PL_na))); /* config_file */
+ PERL_RETURN_INT(rc);
+}
+
+/*
+ * weechat::config_read: read configuration file
+ */
+
+static XS (XS_weechat_config_read)
+{
+ int rc;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_read");
+ PERL_RETURN_INT(-1);
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_read");
+ PERL_RETURN_INT(-1);
+ }
+
+ rc = weechat_config_read (script_str2ptr (SvPV (ST (0), PL_na))); /* config_file */
+ PERL_RETURN_INT(rc);
+}
+
+/*
+ * weechat::config_reload: reload configuration file
+ */
+
+static XS (XS_weechat_config_reload)
+{
+ int rc;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_reload");
+ PERL_RETURN_INT(-1);
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_reload");
+ PERL_RETURN_INT(-1);
+ }
+
+ rc = weechat_config_reload (script_str2ptr (SvPV (ST (0), PL_na))); /* config_file */
+ PERL_RETURN_INT(rc);
+}
+
+/*
+ * weechat::config_free: free configuration file
+ */
+
+static XS (XS_weechat_config_free)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_free");
+ PERL_RETURN_ERROR;
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_free");
+ PERL_RETURN_ERROR;
+ }
+
+ script_api_config_free (weechat_perl_plugin,
+ perl_current_script,
+ script_str2ptr (SvPV (ST (0), PL_na))); /* config_file */
+
+ PERL_RETURN_OK;
+}
+
+/*
* weechat::prefix: get a prefix, used for display
*/
@@ -1531,12 +2182,11 @@ static XS (XS_weechat_unhook)
PERL_RETURN_ERROR;
}
- if (script_api_unhook (weechat_perl_plugin,
- perl_current_script,
- script_str2ptr (SvPV (ST (0), PL_na))))
- PERL_RETURN_OK;
+ script_api_unhook (weechat_perl_plugin,
+ perl_current_script,
+ script_str2ptr (SvPV (ST (0), PL_na)));
- PERL_RETURN_ERROR;
+ PERL_RETURN_OK;
}
/*
@@ -1557,8 +2207,7 @@ static XS (XS_weechat_unhook_all)
PERL_RETURN_ERROR;
}
- script_api_unhook_all (weechat_perl_plugin,
- perl_current_script);
+ script_api_unhook_all (perl_current_script);
PERL_RETURN_OK;
}
@@ -2028,741 +2677,6 @@ static XS (XS_weechat_info_get)
}
/*
- * weechat::get_dcc_info: get infos about DCC
- */
-
-/*
-static XS (XS_weechat_get_dcc_info)
-{
- t_plugin_dcc_info *dcc_info, *ptr_dcc;
- int count;
- char timebuffer1[64];
- char timebuffer2[64];
- struct in_addr in;
- HV *dcc_hash_member;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
- (void) items;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to get DCC info, "
- "script not initialized");
- PERL_RETURN_EMPTY;
- }
-
- dcc_info = weechat_perl_plugin->get_dcc_info (weechat_perl_plugin);
- count = 0;
- if (!dcc_info)
- PERL_RETURN_EMPTY;
-
- for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
- {
- strftime(timebuffer1, sizeof(timebuffer1), "%F %T",
- localtime(&ptr_dcc->start_time));
- strftime(timebuffer2, sizeof(timebuffer2), "%F %T",
- localtime(&ptr_dcc->start_transfer));
- in.s_addr = htonl(ptr_dcc->addr);
-
- dcc_hash_member = (HV *) sv_2mortal ((SV *) newHV());
-
- hv_store (dcc_hash_member, "server", 6, newSVpv (ptr_dcc->server, 0), 0);
- hv_store (dcc_hash_member, "channel", 7, newSVpv (ptr_dcc->channel, 0), 0);
- hv_store (dcc_hash_member, "type", 4, newSViv (ptr_dcc->type), 0);
- hv_store (dcc_hash_member, "status", 6, newSViv (ptr_dcc->status), 0);
- hv_store (dcc_hash_member, "start_time", 10, newSVpv (timebuffer1, 0), 0);
- hv_store (dcc_hash_member, "start_transfer", 14, newSVpv (timebuffer2, 0), 0);
- hv_store (dcc_hash_member, "address", 7, newSVpv (inet_ntoa(in), 0), 0);
- hv_store (dcc_hash_member, "port", 4, newSViv (ptr_dcc->port), 0);
- hv_store (dcc_hash_member, "nick", 4, newSVpv (ptr_dcc->nick, 0), 0);
- hv_store (dcc_hash_member, "remote_file", 11, newSVpv (ptr_dcc->filename, 0), 0);
- hv_store (dcc_hash_member, "local_file", 10, newSVpv (ptr_dcc->local_filename, 0), 0);
- hv_store (dcc_hash_member, "filename_suffix", 15, newSViv (ptr_dcc->filename_suffix), 0);
- hv_store (dcc_hash_member, "size", 4, newSVnv (ptr_dcc->size), 0);
- hv_store (dcc_hash_member, "pos", 3, newSVnv (ptr_dcc->pos), 0);
- hv_store (dcc_hash_member, "start_resume", 12, newSVnv (ptr_dcc->start_resume), 0);
- hv_store (dcc_hash_member, "cps", 3, newSViv (ptr_dcc->bytes_per_sec), 0);
-
- XPUSHs(newRV_inc((SV *) dcc_hash_member));
- count++;
- }
- weechat_perl_plugin->free_dcc_info (weechat_perl_plugin, dcc_info);
-
- XSRETURN (count);
-}
-*/
-
-/*
- * weechat::config_get_weechat: get value of a WeeChat config option
- */
-
- /*
-static XS (XS_weechat_config_get_weechat)
-{
- char *option;
- struct t_config_option *value;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
-
- if (!perl_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_get_weechat");
- PERL_RETURN_EMPTY;
- }
-
- if (items < 1)
- {
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_get_weechat");
- PERL_RETURN_EMPTY;
- }
-
- option = SvPV (ST (0), PL_na);
-
- if (option)
- {
- value = weechat_config_get_weechat (option);
-
- if (return_value)
- {
- XST_mPV (0, return_value);
- free (return_value);
- XSRETURN (1);
- }
- }
-
- XST_mPV (0, "");
- XSRETURN (1);
-}
-*/
-
-/*
- * weechat::set_config: set value of a WeeChat config option
- */
-
-/*
-static XS (XS_weechat_set_config)
-{
- char *option, *value;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to set config option, "
- "script not initialized");
- PERL_RETURN_ERROR;
- }
-
- if (items < 2)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: wrong parameters for "
- "\"set_config\" function");
- PERL_RETURN_ERROR;
- }
-
- option = SvPV (ST (0), PL_na);
- value = SvPV (ST (1), PL_na);
-
- if (option && value)
- {
- if (weechat_perl_plugin->set_config (weechat_perl_plugin, option, value))
- PERL_RETURN_OK;
- }
-
- PERL_RETURN_ERROR;
-}
-*/
-
-/*
- * weechat::get_plugin_config: get value of a plugin config option
- */
-
-/*
-static XS (XS_weechat_get_plugin_config)
-{
- char *option, *return_value;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to get plugin config option, "
- "script not initialized");
- PERL_RETURN_EMPTY;
- }
-
- if (items < 1)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: wrong parameters for "
- "\"get_plugin_config\" function");
- PERL_RETURN_EMPTY;
- }
-
- option = SvPV (ST (0), PL_na);
-
- if (option)
- {
- return_value = weechat_script_get_plugin_config (weechat_perl_plugin,
- perl_current_script,
- option);
-
- if (return_value)
- {
- XST_mPV (0, return_value);
- free (return_value);
- XSRETURN (1);
- }
- }
-
- XST_mPV (0, "");
- XSRETURN (1);
-}
-*/
-
-/*
- * weechat::set_plugin_config: set value of a WeeChat config option
- */
-
-/*
-static XS (XS_weechat_set_plugin_config)
-{
- char *option, *value;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to set plugin config option, "
- "script not initialized");
- PERL_RETURN_ERROR;
- }
-
- if (items < 2)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: wrong parameters for "
- "\"set_plugin_config\" function");
- PERL_RETURN_ERROR;
- }
-
- option = SvPV (ST (0), PL_na);
- value = SvPV (ST (1), PL_na);
-
- if (option && value)
- {
- if (weechat_script_set_plugin_config (weechat_perl_plugin,
- perl_current_script,
- option, value))
- PERL_RETURN_OK;
- }
-
- PERL_RETURN_ERROR;
-}
-*/
-
-/*
- * weechat::get_server_info: get infos about servers
- */
-
-/*
-static XS (XS_weechat_get_server_info)
-{
- t_plugin_server_info *server_info, *ptr_server;
- char timebuffer[64];
- HV *server_hash, *server_hash_member;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
- (void) items;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to get server info, "
- "script not initialized");
- PERL_RETURN_EMPTY;
- }
-
- server_info = weechat_perl_plugin->get_server_info (weechat_perl_plugin);
- if (!server_info)
- {
- PERL_RETURN_EMPTY;
- }
-
- server_hash = (HV *) sv_2mortal((SV *) newHV());
- if (!server_hash)
- {
- weechat_perl_plugin->free_server_info (weechat_perl_plugin, server_info);
- PERL_RETURN_EMPTY;
- }
-
- for (ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server)
- {
- strftime(timebuffer, sizeof(timebuffer), "%F %T",
- localtime(&ptr_server->away_time));
-
- server_hash_member = (HV *) sv_2mortal((SV *) newHV());
-
- hv_store (server_hash_member, "autoconnect", 11, newSViv (ptr_server->autoconnect), 0);
- hv_store (server_hash_member, "autoreconnect", 13, newSViv (ptr_server->autoreconnect), 0);
- hv_store (server_hash_member, "autoreconnect_delay", 19, newSViv (ptr_server->autoreconnect_delay), 0);
- hv_store (server_hash_member, "temp_server", 11, newSViv (ptr_server->temp_server), 0);
- hv_store (server_hash_member, "address", 7, newSVpv (ptr_server->address, 0), 0);
- hv_store (server_hash_member, "port", 4, newSViv (ptr_server->port), 0);
- hv_store (server_hash_member, "ipv6", 4, newSViv (ptr_server->ipv6), 0);
- hv_store (server_hash_member, "ssl", 3, newSViv (ptr_server->ssl), 0);
- hv_store (server_hash_member, "password", 8, newSVpv (ptr_server->password, 0), 0);
- hv_store (server_hash_member, "nick1", 5, newSVpv (ptr_server->nick1, 0), 0);
- hv_store (server_hash_member, "nick2", 5, newSVpv (ptr_server->nick2, 0), 0);
- hv_store (server_hash_member, "nick3", 5, newSVpv (ptr_server->nick3, 0), 0);
- hv_store (server_hash_member, "username", 8, newSVpv (ptr_server->username, 0), 0);
- hv_store (server_hash_member, "realname", 8, newSVpv (ptr_server->realname, 0), 0);
- hv_store (server_hash_member, "command", 7, newSVpv (ptr_server->command, 0), 0);
- hv_store (server_hash_member, "command_delay", 13, newSViv (ptr_server->command_delay), 0);
- hv_store (server_hash_member, "autojoin", 8, newSVpv (ptr_server->autojoin, 0), 0);
- hv_store (server_hash_member, "autorejoin", 10, newSViv (ptr_server->autorejoin), 0);
- hv_store (server_hash_member, "notify_levels", 13, newSVpv (ptr_server->notify_levels, 0), 0);
- hv_store (server_hash_member, "is_connected", 12, newSViv (ptr_server->is_connected), 0);
- hv_store (server_hash_member, "ssl_connected", 13, newSViv (ptr_server->ssl_connected), 0);
- hv_store (server_hash_member, "nick", 4, newSVpv (ptr_server->nick, 0), 0);
- hv_store (server_hash_member, "nick_modes", 10, newSVpv (ptr_server->nick_modes, 0), 0);
- hv_store (server_hash_member, "away_time", 9, newSVpv (timebuffer, 0), 0);
- hv_store (server_hash_member, "lag", 3, newSViv (ptr_server->lag), 0);
-
- hv_store (server_hash, ptr_server->name, strlen(ptr_server->name), newRV_inc((SV *) server_hash_member), 0);
- }
- weechat_perl_plugin->free_server_info (weechat_perl_plugin, server_info);
-
- ST (0) = newRV_inc((SV *) server_hash);
- if (SvREFCNT(ST(0))) sv_2mortal(ST(0));
-
- XSRETURN (1);
-}
-*/
-
-/*
- * weechat::get_channel_info: get infos about channels
- */
-
-/*
-static XS (XS_weechat_get_channel_info)
-{
- t_plugin_channel_info *channel_info, *ptr_channel;
- char *server;
- HV *channel_hash, *channel_hash_member;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to get channel info, "
- "script not initialized");
- PERL_RETURN_EMPTY;
- }
-
- if (items != 1)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: wrong parameters for "
- "\"get_channel_info\" function");
- PERL_RETURN_EMPTY;
- }
-
- server = SvPV (ST (0), PL_na);
- if (!server)
- PERL_RETURN_EMPTY;
-
- channel_info = weechat_perl_plugin->get_channel_info (weechat_perl_plugin, server);
- if (!channel_info)
- {
- PERL_RETURN_EMPTY;
- }
-
- channel_hash = (HV *) sv_2mortal((SV *) newHV());
- if (!channel_hash)
- {
- weechat_perl_plugin->free_channel_info (weechat_perl_plugin, channel_info);
- PERL_RETURN_EMPTY;
- }
-
- for (ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel)
- {
- channel_hash_member = (HV *) sv_2mortal((SV *) newHV());
-
- hv_store (channel_hash_member, "type", 4, newSViv (ptr_channel->type), 0);
- hv_store (channel_hash_member, "topic", 5, newSVpv (ptr_channel->topic, 0), 0);
- hv_store (channel_hash_member, "modes", 5, newSVpv (ptr_channel->modes, 0), 0);
- hv_store (channel_hash_member, "limit", 5, newSViv (ptr_channel->limit), 0);
- hv_store (channel_hash_member, "key", 3, newSVpv (ptr_channel->key, 0), 0);
- hv_store (channel_hash_member, "nicks_count", 11, newSViv (ptr_channel->nicks_count), 0);
-
- hv_store (channel_hash, ptr_channel->name, strlen(ptr_channel->name), newRV_inc((SV *) channel_hash_member), 0);
- }
- weechat_perl_plugin->free_channel_info (weechat_perl_plugin, channel_info);
-
- ST (0) = newRV_inc((SV *) channel_hash);
- if (SvREFCNT(ST(0))) sv_2mortal(ST(0));
-
- XSRETURN (1);
-}
-*/
-
-/*
- * weechat::get_nick_info: get infos about nicks
- */
-
-/*
-static XS (XS_weechat_get_nick_info)
-{
- t_plugin_nick_info *nick_info, *ptr_nick;
- char *server, *channel;
- HV *nick_hash;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to get nick info, "
- "script not initialized");
- PERL_RETURN_EMPTY;
- }
-
- if (items != 2)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: wrong parameters for "
- "\"get_nick_info\" function");
- PERL_RETURN_EMPTY;
- }
-
- server = SvPV (ST (0), PL_na);
- channel = SvPV (ST (1), PL_na);
- if (!server || !channel)
- PERL_RETURN_EMPTY;
-
- nick_info = weechat_perl_plugin->get_nick_info (weechat_perl_plugin, server, channel);
- if (!nick_info)
- {
- PERL_RETURN_EMPTY;
- }
-
- nick_hash = (HV *) sv_2mortal((SV *) newHV());
- if (!nick_hash)
- {
- weechat_perl_plugin->free_nick_info (weechat_perl_plugin, nick_info);
- PERL_RETURN_EMPTY;
- }
-
- for (ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick)
- {
- HV *nick_hash_member = (HV *) sv_2mortal((SV *) newHV());
-
- hv_store (nick_hash_member, "flags", 5, newSViv (ptr_nick->flags), 0);
- hv_store (nick_hash_member, "host", 4, newSVpv (
- ptr_nick->host ? ptr_nick->host : "", 0), 0);
-
- hv_store (nick_hash, ptr_nick->nick, strlen(ptr_nick->nick), newRV_inc((SV *) nick_hash_member), 0);
- }
- weechat_perl_plugin->free_nick_info (weechat_perl_plugin, nick_info);
-
- ST (0) = newRV_inc((SV *) nick_hash);
- if (SvREFCNT(ST(0))) sv_2mortal(ST(0));
-
- XSRETURN (1);
-}
-*/
-
-/*
- * weechat::color_input: add color in input buffer
- */
-
-/*
-static XS (XS_weechat_input_color)
-{
- int color, start, length;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to colorize input, "
- "script not initialized");
- PERL_RETURN_ERROR;
- }
-
- if (items < 3)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: wrong parameters for "
- "\"color_input\" function");
- PERL_RETURN_ERROR;
- }
-
- color = SvIV (ST (0));
- start = SvIV (ST (1));
- length = SvIV (ST (2));
-
- weechat_perl_plugin->input_color (weechat_perl_plugin, color, start, length);
-
- PERL_RETURN_OK;
-}
-*/
-
-/*
- * weechat::get_irc_color:
- * get the numeric value which identify an irc color by its name
- */
-
-/*
-static XS (XS_weechat_get_irc_color)
-{
- char *color;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to get irc color, "
- "script not initialized");
- XST_mIV (0, -1);
- XSRETURN (1);
- }
-
- if (items != 1)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: wrong parameters for "
- "\"get_irc_info\" function");
- XST_mIV (0, -1);
- XSRETURN (1);
- }
-
- color = SvPV (ST (0), PL_na);
- if (color)
- {
- XST_mIV (0, weechat_perl_plugin->get_irc_color (weechat_perl_plugin, color));
- XSRETURN (1);
- }
-
- XST_mIV (0, -1);
- XSRETURN (-1);
-}
-*/
-
-/*
- * weechat::get_window_info: get infos about windows
- */
-
-/*
-static XS (XS_weechat_get_window_info)
-{
- t_plugin_window_info *window_info, *ptr_win;
- int count;
- HV *window_hash_member;
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
- (void) items;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to get window info, "
- "script not initialized");
- PERL_RETURN_EMPTY;
- }
-
- window_info = weechat_perl_plugin->get_window_info (weechat_perl_plugin);
- count = 0;
- if (!window_info)
- PERL_RETURN_EMPTY;
-
- for (ptr_win = window_info; ptr_win; ptr_win = ptr_win->next_window)
- {
- window_hash_member = (HV *) sv_2mortal((SV *) newHV());
-
- hv_store (window_hash_member, "num_buffer", 10, newSViv (ptr_win->num_buffer), 0);
- hv_store (window_hash_member, "win_x", 5, newSViv (ptr_win->win_x), 0);
- hv_store (window_hash_member, "win_y", 5, newSViv (ptr_win->win_y), 0);
- hv_store (window_hash_member, "win_width", 9, newSViv (ptr_win->win_width), 0);
- hv_store (window_hash_member, "win_height", 10, newSViv (ptr_win->win_height), 0);
- hv_store (window_hash_member, "win_width_pct", 13, newSViv (ptr_win->win_width_pct), 0);
- hv_store (window_hash_member, "win_height_pct", 14, newSViv (ptr_win->win_height_pct), 0);
-
- XPUSHs(newRV_inc((SV *) window_hash_member));
- count++;
- }
- weechat_perl_plugin->free_window_info (weechat_perl_plugin, window_info);
-
- XSRETURN (count);
-}
-*/
-
-/*
- * weechat::get_buffer_info: get infos about buffers
- */
-
-/*
-static XS (XS_weechat_get_buffer_info)
-{
- t_plugin_buffer_info *buffer_info, *ptr_buffer;
- HV *buffer_hash, *buffer_hash_member;
- char conv[8];
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
- (void) items;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to get buffer info, "
- "script not initialized");
- PERL_RETURN_EMPTY;
- }
-
- buffer_info = weechat_perl_plugin->get_buffer_info (weechat_perl_plugin);
- if (!buffer_info)
- {
- PERL_RETURN_EMPTY;
- }
-
- buffer_hash = (HV *) sv_2mortal((SV *) newHV());
- if (!buffer_hash)
- {
- weechat_perl_plugin->free_buffer_info (weechat_perl_plugin, buffer_info);
- PERL_RETURN_EMPTY;
- }
-
- for (ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
- {
- buffer_hash_member = (HV *) sv_2mortal((SV *) newHV());
-
- hv_store (buffer_hash_member, "type", 4, newSViv (ptr_buffer->type), 0);
- hv_store (buffer_hash_member, "num_displayed", 13, newSViv (ptr_buffer->num_displayed), 0);
- hv_store (buffer_hash_member, "server", 6,
- newSVpv ((ptr_buffer->server_name == NULL) ? "" : ptr_buffer->server_name, 0), 0);
- hv_store (buffer_hash_member, "channel", 7,
- newSVpv ((ptr_buffer->channel_name == NULL) ? "" : ptr_buffer->channel_name, 0), 0);
- hv_store (buffer_hash_member, "notify_level", 12, newSViv (ptr_buffer->notify_level), 0);
- hv_store (buffer_hash_member, "log_filename", 12,
- newSVpv ((ptr_buffer->log_filename == NULL) ? "" : ptr_buffer->log_filename, 0), 0);
- snprintf(conv, sizeof(conv), "%d", ptr_buffer->number);
- hv_store (buffer_hash, conv, strlen(conv), newRV_inc((SV *) buffer_hash_member), 0);
- }
- weechat_perl_plugin->free_buffer_info (weechat_perl_plugin, buffer_info);
-
- ST (0) = newRV_inc((SV *) buffer_hash);
- if (SvREFCNT(ST(0))) sv_2mortal(ST(0));
-
- XSRETURN (1);
-}
-*/
-
-/*
- * weechat::get_buffer_data: get buffer content
- */
-
-/*
-static XS (XS_weechat_get_buffer_data)
-{
- t_plugin_buffer_line *buffer_data, *ptr_data;
- HV *data_list_member;
- char *server, *channel;
- char timebuffer[64];
- int count;
-
- dXSARGS;
-
- // make C compiler happy
- (void) cv;
- (void) items;
-
- if (!perl_current_script)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: unable to get buffer data, "
- "script not initialized");
- PERL_RETURN_EMPTY;
- }
-
- if (items != 2)
- {
- weechat_perl_plugin->print_server (weechat_perl_plugin,
- "Perl error: wrong parameters for "
- "\"get_buffer_data\" function");
- PERL_RETURN_EMPTY;
- }
-
- channel = NULL;
- server = NULL;
-
- if (items >= 1)
- server = SvPV (ST (0), PL_na);
- if (items >= 2)
- channel = SvPV (ST (1), PL_na);
-
- SP -= items;
-
- buffer_data = weechat_perl_plugin->get_buffer_data (weechat_perl_plugin, server, channel);
- count = 0;
- if (!buffer_data)
- PERL_RETURN_EMPTY;
-
- for (ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line)
- {
- data_list_member = (HV *) sv_2mortal((SV *) newHV());
-
- strftime(timebuffer, sizeof(timebuffer), "%F %T",
- localtime(&ptr_data->date));
-
- hv_store (data_list_member, "date", 4, newSVpv (timebuffer, 0), 0);
- hv_store (data_list_member, "nick", 4,
- newSVpv ((ptr_data->nick == NULL) ? "" : ptr_data->nick, 0), 0);
- hv_store (data_list_member, "data", 4,
- newSVpv ((ptr_data->data == NULL) ? "" : ptr_data->data, 0), 0);
-
- XPUSHs(newRV_inc((SV *) data_list_member));
- count++;
- }
- weechat_perl_plugin->free_buffer_data (weechat_perl_plugin, buffer_data);
-
- XSRETURN (count);
-}
-*/
-
-/*
* weechat_perl_xs_init: initialize subroutines
*/
@@ -2795,6 +2709,22 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::list_remove", XS_weechat_list_remove, "weechat");
newXS ("weechat::list_remove_all", XS_weechat_list_remove_all, "weechat");
newXS ("weechat::list_free", XS_weechat_list_free, "weechat");
+ newXS ("weechat::config_new", XS_weechat_config_new, "weechat");
+ newXS ("weechat::config_new_section", XS_weechat_config_new_section, "weechat");
+ newXS ("weechat::config_search_section", XS_weechat_config_search_section, "weechat");
+ newXS ("weechat::config_new_option", XS_weechat_config_new_option, "weechat");
+ newXS ("weechat::config_search_option", XS_weechat_config_search_option, "weechat");
+ newXS ("weechat::config_string_to_boolean", XS_weechat_config_string_to_boolean, "weechat");
+ newXS ("weechat::config_option_set", XS_weechat_config_option_set, "weechat");
+ newXS ("weechat::config_boolean", XS_weechat_config_boolean, "weechat");
+ newXS ("weechat::config_integer", XS_weechat_config_integer, "weechat");
+ newXS ("weechat::config_string", XS_weechat_config_string, "weechat");
+ newXS ("weechat::config_color", XS_weechat_config_color, "weechat");
+ newXS ("weechat::config_write_line", XS_weechat_config_write_line, "weechat");
+ newXS ("weechat::config_write", XS_weechat_config_write, "weechat");
+ newXS ("weechat::config_read", XS_weechat_config_read, "weechat");
+ newXS ("weechat::config_reload", XS_weechat_config_reload, "weechat");
+ newXS ("weechat::config_free", XS_weechat_config_free, "weechat");
newXS ("weechat::prefix", XS_weechat_prefix, "weechat");
newXS ("weechat::color", XS_weechat_color, "weechat");
newXS ("weechat::print", XS_weechat_print, "weechat");
@@ -2827,20 +2757,7 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::nicklist_remove_all", XS_weechat_nicklist_remove_all, "weechat");
newXS ("weechat::command", XS_weechat_command, "weechat");
newXS ("weechat::info_get", XS_weechat_info_get, "weechat");
- //newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat");
- //newXS ("weechat::get_config", XS_weechat_get_config, "weechat");
- //newXS ("weechat::set_config", XS_weechat_set_config, "weechat");
- //newXS ("weechat::get_plugin_config", XS_weechat_get_plugin_config, "weechat");
- //newXS ("weechat::set_plugin_config", XS_weechat_set_plugin_config, "weechat");
- //newXS ("weechat::get_server_info", XS_weechat_get_server_info, "weechat");
- //newXS ("weechat::get_channel_info", XS_weechat_get_channel_info, "weechat");
- //newXS ("weechat::get_nick_info", XS_weechat_get_nick_info, "weechat");
- //newXS ("weechat::input_color", XS_weechat_input_color, "weechat");
- //newXS ("weechat::get_irc_color", XS_weechat_get_irc_color, "weechat");
- //newXS ("weechat::get_window_info", XS_weechat_get_window_info, "weechat");
- //newXS ("weechat::get_buffer_info", XS_weechat_get_buffer_info, "weechat");
- //newXS ("weechat::get_buffer_data", XS_weechat_get_buffer_data, "weechat");
-
+
/* interface constants */
stash = gv_stashpv ("weechat", TRUE);
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK", newSViv (WEECHAT_RC_OK));
diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c
index dc8dda300..1a183f8c0 100644
--- a/src/plugins/scripts/python/weechat-python-api.c
+++ b/src/plugins/scripts/python/weechat-python-api.c
@@ -753,6 +753,729 @@ weechat_python_api_list_free (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_api_config_reload_cb: callback for config reload
+ */
+
+int
+weechat_python_api_config_reload_cb (void *data,
+ struct t_config_file *config_file)
+{
+ struct t_script_callback *script_callback;
+ char *python_argv[2];
+ int *rc, ret;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ python_argv[0] = script_ptr2str (config_file);
+ python_argv[1] = 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]);
+
+ return ret;
+ }
+
+ return 0;
+}
+
+/*
+ * weechat_python_api_config_new: create a new configuration file
+ */
+
+static PyObject *
+weechat_python_api_config_new (PyObject *self, PyObject *args)
+{
+ char *filename, *function, *result;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ filename = NULL;
+ function = NULL;
+
+ if (!PyArg_ParseTuple (args, "ss", &filename, &function))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (script_api_config_new (weechat_python_plugin,
+ python_current_script,
+ filename,
+ &weechat_python_api_config_reload_cb,
+ function));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_config_read_cb: callback for reading option in section
+ */
+
+void
+weechat_python_api_config_read_cb (void *data,
+ struct t_config_file *config_file,
+ char *option_name, char *value)
+{
+ struct t_script_callback *script_callback;
+ char *python_argv[4];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ python_argv[0] = script_ptr2str (config_file);
+ python_argv[1] = option_name;
+ python_argv[2] = value;
+ python_argv[3] = NULL;
+
+ rc = (int *) weechat_python_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ python_argv);
+
+ if (rc)
+ free (rc);
+ if (python_argv[0])
+ free (python_argv[0]);
+ }
+}
+
+/*
+ * weechat_python_api_config_section_write_cb: callback for writing section
+ */
+
+void
+weechat_python_api_config_section_write_cb (void *data,
+ struct t_config_file *config_file,
+ char *section_name)
+{
+ struct t_script_callback *script_callback;
+ char *python_argv[3];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ python_argv[0] = script_ptr2str (config_file);
+ python_argv[1] = section_name;
+ python_argv[2] = NULL;
+
+ rc = (int *) weechat_python_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ python_argv);
+
+ if (rc)
+ free (rc);
+ if (python_argv[0])
+ free (python_argv[0]);
+ }
+}
+
+/*
+ * weechat_python_api_config_section_write_default_cb: callback for writing
+ * default values for section
+ */
+
+void
+weechat_python_api_config_section_write_default_cb (void *data,
+ struct t_config_file *config_file,
+ char *section_name)
+{
+ struct t_script_callback *script_callback;
+ char *python_argv[3];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ python_argv[0] = script_ptr2str (config_file);
+ python_argv[1] = section_name;
+ python_argv[2] = NULL;
+
+ rc = (int *) weechat_python_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ python_argv);
+
+ if (rc)
+ free (rc);
+ if (python_argv[0])
+ free (python_argv[0]);
+ }
+}
+
+/*
+ * weechat_python_api_config_new_section: create a new section in configuration file
+ */
+
+static PyObject *
+weechat_python_api_config_new_section (PyObject *self, PyObject *args)
+{
+ char *config_file, *name, *function_read, *function_write;
+ char *function_write_default, *result;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new_section");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ config_file = NULL;
+ name = NULL;
+ function_read = NULL;
+ function_write = NULL;
+ function_write_default = NULL;
+
+ if (!PyArg_ParseTuple (args, "sssss", &config_file, &name, &function_read,
+ &function_write, &function_write_default))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (script_api_config_new_section (weechat_python_plugin,
+ python_current_script,
+ script_str2ptr (config_file),
+ name,
+ &weechat_python_api_config_read_cb,
+ function_read,
+ &weechat_python_api_config_section_write_cb,
+ function_write,
+ &weechat_python_api_config_section_write_default_cb,
+ function_write_default));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_config_search_section: search section in configuration file
+ */
+
+static PyObject *
+weechat_python_api_config_search_section (PyObject *self, PyObject *args)
+{
+ char *config_file, *section_name, *result;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_search_section");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ config_file = NULL;
+ section_name = NULL;
+
+ if (!PyArg_ParseTuple (args, "ss", &config_file, &section_name))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_search_section");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_config_search_section (script_str2ptr (config_file),
+ section_name));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_config_option_change_cb: callback for option changed
+ */
+
+void
+weechat_python_api_config_option_change_cb (void *data)
+{
+ struct t_script_callback *script_callback;
+ char *python_argv[1];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ python_argv[0] = NULL;
+
+ rc = (int *) weechat_python_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ python_argv);
+
+ if (rc)
+ free (rc);
+ }
+}
+
+/*
+ * weechat_python_api_config_new_option: create a new option in section
+ */
+
+static PyObject *
+weechat_python_api_config_new_option (PyObject *self, PyObject *args)
+{
+ char *config_file, *section, *name, *type, *description, *string_values;
+ char *default_value, *function, *result;
+ int min, max;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new_option");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ config_file = NULL;
+ section = NULL;
+ name = NULL;
+ type = NULL;
+ description = NULL;
+ string_values = NULL;
+ default_value = NULL;
+ function = NULL;
+
+ if (!PyArg_ParseTuple (args, "ssssssiiss", &config_file, &section, &name,
+ &type, &description, &string_values, &min, &max,
+ &default_value, &function))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (script_api_config_new_option (weechat_python_plugin,
+ python_current_script,
+ script_str2ptr (config_file),
+ script_str2ptr (section),
+ name,
+ type,
+ description,
+ string_values,
+ min,
+ max,
+ default_value,
+ &weechat_python_api_config_option_change_cb,
+ function));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_config_search_option: search option in configuration file or section
+ */
+
+static PyObject *
+weechat_python_api_config_search_option (PyObject *self, PyObject *args)
+{
+ char *config_file, *section, *option_name, *result;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_search_option");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ config_file = NULL;
+ section = NULL;
+ option_name = NULL;
+
+ if (!PyArg_ParseTuple (args, "sss", &config_file, &section, &option_name))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_search_option");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_config_search_option (script_str2ptr (config_file),
+ script_str2ptr (section),
+ option_name));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_config_string_to_boolean: return boolean value of a string
+ */
+
+static PyObject *
+weechat_python_api_config_string_to_boolean (PyObject *self, PyObject *args)
+{
+ char *text;
+ int value;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_string_to_boolean");
+ PYTHON_RETURN_INT(0);
+ }
+
+ text = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &text))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_string_to_boolean");
+ PYTHON_RETURN_INT(0);
+ }
+
+ value = weechat_config_string_to_boolean (text);
+ PYTHON_RETURN_INT(value);
+}
+
+/*
+ * weechat_python_api_config_option_set: set new value for option
+ */
+
+static PyObject *
+weechat_python_api_config_option_set (PyObject *self, PyObject *args)
+{
+ char *option, *new_value;
+ int run_callback, rc;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set");
+ PYTHON_RETURN_INT(0);
+ }
+
+ option = NULL;
+ new_value = NULL;
+ run_callback = 0;
+
+ if (!PyArg_ParseTuple (args, "ssi", &option, &new_value, &run_callback))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set");
+ PYTHON_RETURN_INT(0);
+ }
+
+ rc = weechat_config_option_set (script_str2ptr (option),
+ new_value,
+ run_callback);
+ PYTHON_RETURN_INT(rc);
+}
+
+/*
+ * weechat_python_api_config_boolean: return boolean value of option
+ */
+
+static PyObject *
+weechat_python_api_config_boolean (PyObject *self, PyObject *args)
+{
+ char *option;
+ int value;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_boolean");
+ PYTHON_RETURN_INT(0);
+ }
+
+ option = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &option))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_boolean");
+ PYTHON_RETURN_INT(0);
+ }
+
+ value = weechat_config_boolean (script_str2ptr (option));
+ PYTHON_RETURN_INT(value);
+}
+
+/*
+ * weechat_python_api_config_integer: return integer value of option
+ */
+
+static PyObject *
+weechat_python_api_config_integer (PyObject *self, PyObject *args)
+{
+ char *option;
+ int value;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_integer");
+ PYTHON_RETURN_INT(0);
+ }
+
+ option = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &option))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_integer");
+ PYTHON_RETURN_INT(0);
+ }
+
+ value = weechat_config_integer (script_str2ptr (option));
+ PYTHON_RETURN_INT(value);
+}
+
+/*
+ * weechat_python_api_config_string: return string value of option
+ */
+
+static PyObject *
+weechat_python_api_config_string (PyObject *self, PyObject *args)
+{
+ char *option, *value;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_string");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ option = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &option))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_string");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ value = weechat_config_string (script_str2ptr (option));
+ PYTHON_RETURN_STRING(value);
+}
+
+/*
+ * weechat_python_api_config_color: return color value of option
+ */
+
+static PyObject *
+weechat_python_api_config_color (PyObject *self, PyObject *args)
+{
+ char *option;
+ int value;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_color");
+ PYTHON_RETURN_INT(0);
+ }
+
+ option = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &option))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_color");
+ PYTHON_RETURN_INT(0);
+ }
+
+ value = weechat_config_color (script_str2ptr (option));
+ PYTHON_RETURN_INT(value);
+}
+
+/*
+ * weechat_python_api_config_write_line: write a line in configuration file
+ */
+
+static PyObject *
+weechat_python_api_config_write_line (PyObject *self, PyObject *args)
+{
+ char *config_file, *option_name, *value;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write_line");
+ PYTHON_RETURN_ERROR;
+ }
+
+ config_file = NULL;
+ option_name = NULL;
+ value = NULL;
+
+ if (!PyArg_ParseTuple (args, "sss", &config_file, &option_name, &value))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write_line");
+ PYTHON_RETURN_ERROR;
+ }
+
+ weechat_config_write_line (script_str2ptr (config_file),
+ option_name,
+ "%s",
+ value);
+
+ PYTHON_RETURN_OK;
+}
+
+/*
+ * weechat_python_api_config_write: write configuration file
+ */
+
+static PyObject *
+weechat_python_api_config_write (PyObject *self, PyObject *args)
+{
+ char *config_file;
+ int rc;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write");
+ PYTHON_RETURN_INT(-1);
+ }
+
+ config_file = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &config_file))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write");
+ PYTHON_RETURN_INT(-1);
+ }
+
+ rc = weechat_config_write (script_str2ptr (config_file));
+ PYTHON_RETURN_INT(rc);
+}
+
+/*
+ * weechat_python_api_config_read: read configuration file
+ */
+
+static PyObject *
+weechat_python_api_config_read (PyObject *self, PyObject *args)
+{
+ char *config_file;
+ int rc;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_read");
+ PYTHON_RETURN_INT(-1);
+ }
+
+ config_file = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &config_file))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_read");
+ PYTHON_RETURN_INT(-1);
+ }
+
+ rc = weechat_config_read (script_str2ptr (config_file));
+ PYTHON_RETURN_INT(rc);
+}
+
+/*
+ * weechat_python_api_config_reload: reload configuration file
+ */
+
+static PyObject *
+weechat_python_api_config_reload (PyObject *self, PyObject *args)
+{
+ char *config_file;
+ int rc;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_reload");
+ PYTHON_RETURN_INT(-1);
+ }
+
+ config_file = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &config_file))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_reload");
+ PYTHON_RETURN_INT(-1);
+ }
+
+ rc = weechat_config_reload (script_str2ptr (config_file));
+ PYTHON_RETURN_INT(rc);
+}
+
+/*
+ * weechat_python_api_config_free: free configuration file
+ */
+
+static PyObject *
+weechat_python_api_config_free (PyObject *self, PyObject *args)
+{
+ char *config_file;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_free");
+ PYTHON_RETURN_ERROR;
+ }
+
+ config_file = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &config_file))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_free");
+ PYTHON_RETURN_ERROR;
+ }
+
+ script_api_config_free (weechat_python_plugin,
+ python_current_script,
+ script_str2ptr (config_file));
+
+ PYTHON_RETURN_OK;
+}
+
+/*
* weechat_python_api_prefix: get a prefix, used for display
*/
@@ -1670,12 +2393,11 @@ weechat_python_api_unhook (PyObject *self, PyObject *args)
PYTHON_RETURN_ERROR;
}
- if (script_api_unhook (weechat_python_plugin,
- python_current_script,
- script_str2ptr (hook)))
- PYTHON_RETURN_OK;
+ script_api_unhook (weechat_python_plugin,
+ python_current_script,
+ script_str2ptr (hook));
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_OK;
}
/*
@@ -1695,8 +2417,7 @@ weechat_python_api_unhook_all (PyObject *self, PyObject *args)
PYTHON_RETURN_ERROR;
}
- script_api_unhook_all (weechat_python_plugin,
- python_current_script);
+ script_api_unhook_all (python_current_script);
PYTHON_RETURN_OK;
}
@@ -2234,985 +2955,6 @@ weechat_python_api_info_get (PyObject *self, PyObject *args)
}
/*
- * weechat_python_api_get_dcc_info: get infos about DCC
- */
-
-/*
-static PyObject *
-weechat_python_api_get_dcc_info (PyObject *self, PyObject *args)
-{
- t_plugin_dcc_info *dcc_info, *ptr_dcc;
- PyObject *dcc_list, *dcc_list_member, *key, *value;
- char timebuffer1[64];
- char timebuffer2[64];
- struct in_addr in;
-
- // make C compiler happy
- (void) self;
- (void) args;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- dcc_list = PyList_New (0);
- if (!dcc_list)
- {
- PYTHON_RETURN_EMPTY;
- }
-
- dcc_info = python_plugin->get_dcc_info (python_plugin);
- if (!dcc_info)
- return dcc_list;
-
- for(ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
- {
- strftime(timebuffer1, sizeof(timebuffer1), "%F %T",
- localtime(&ptr_dcc->start_time));
- strftime(timebuffer2, sizeof(timebuffer2), "%F %T",
- localtime(&ptr_dcc->start_transfer));
- in.s_addr = htonl(ptr_dcc->addr);
-
- dcc_list_member= PyDict_New();
-
- if (dcc_list_member)
- {
- key = Py_BuildValue("s", "server");
- value = Py_BuildValue("s", ptr_dcc->server);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "channel");
- value = Py_BuildValue("s", ptr_dcc->channel);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "type");
- value = Py_BuildValue("i", ptr_dcc->type);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "status");
- value = Py_BuildValue("i", ptr_dcc->status);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "start_time");
- value = Py_BuildValue("s", timebuffer1);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "start_transfer");
- value = Py_BuildValue("s", timebuffer2);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "address");
- value = Py_BuildValue("s", inet_ntoa(in));
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "port");
- value = Py_BuildValue("i", ptr_dcc->port);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "nick");
- value = Py_BuildValue("s", ptr_dcc->nick);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "remote_file");
- value = Py_BuildValue("s", ptr_dcc->filename);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "local_file");
- value = Py_BuildValue("s", ptr_dcc->local_filename);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "filename_suffix");
- value = Py_BuildValue("i", ptr_dcc->filename_suffix);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "size");
- value = Py_BuildValue("k", ptr_dcc->size);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "pos");
- value = Py_BuildValue("k", ptr_dcc->pos);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "start_resume");
- value = Py_BuildValue("k", ptr_dcc->start_resume);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "cps");
- value = Py_BuildValue("k", ptr_dcc->bytes_per_sec);
- PyDict_SetItem(dcc_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- PyList_Append(dcc_list, dcc_list_member);
- Py_DECREF (dcc_list_member);
- }
- }
-
- python_plugin->free_dcc_info (python_plugin, dcc_info);
-
- return dcc_list;
-}
-*/
-
-/*
- * weechat_python_api_get_config: get value of a WeeChat config option
- */
-
-/*
-static PyObject *
-weechat_python_api_get_config (PyObject *self, PyObject *args)
-{
- char *option, *return_value;
- PyObject *python_return_value;
-
- // make C compiler happy
- (void) self;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- option = NULL;
-
- if (!PyArg_ParseTuple (args, "s", &option))
- {
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- if (option)
- {
- return_value = python_plugin->get_config (python_plugin, option);
-
- if (return_value)
- {
- python_return_value = Py_BuildValue ("s", return_value);
- free (return_value);
- return python_return_value;
- }
- }
-
- return Py_BuildValue ("s", "");
-}
-*/
-
-/*
- * weechat_python_api_set_config: set value of a WeeChat config option
- */
-
-/*
-static PyObject *
-weechat_python_api_set_config (PyObject *self, PyObject *args)
-{
- char *option, *value;
-
- // make C compiler happy
- (void) self;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_ERROR;
- }
-
- option = NULL;
- value = NULL;
-
- if (!PyArg_ParseTuple (args, "ss", &option, &value))
- {
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print");
- PYTHON_RETURN_ERROR;
- }
-
- if (option && value)
- {
- if (python_plugin->set_config (python_plugin, option, value))
- PYTHON_RETURN_OK;
- }
-
- PYTHON_RETURN_ERROR;
-}
-*/
-
-/*
- * weechat_python_api_get_plugin_config: get value of a plugin config option
- */
-
-/*
-static PyObject *
-weechat_python_api_get_plugin_config (PyObject *self, PyObject *args)
-{
- char *option, *return_value;
- PyObject *python_return_value;
-
- // make C compiler happy
- (void) self;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- option = NULL;
-
- if (!PyArg_ParseTuple (args, "s", &option))
- {
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- if (option)
- {
- return_value = weechat_script_get_plugin_config (python_plugin,
- python_current_script,
- option);
-
- if (return_value)
- {
- python_return_value = Py_BuildValue ("s", return_value);
- free (return_value);
- return python_return_value;
- }
- }
-
- return Py_BuildValue ("s", "");
-}
-*/
-
-/*
- * weechat_python_api_set_plugin_config: set value of a plugin config option
- */
-
- /*
-static PyObject *
-weechat_python_api_set_plugin_config (PyObject *self, PyObject *args)
-{
- char *option, *value;
-
- // make C compiler happy
- (void) self;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_ERROR;
- }
-
- option = NULL;
- value = NULL;
-
- if (!PyArg_ParseTuple (args, "ss", &option, &value))
- {
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print");
- PYTHON_RETURN_ERROR;
- }
-
- if (option && value)
- {
- if (weechat_script_set_plugin_config (python_plugin,
- python_current_script,
- option, value))
- PYTHON_RETURN_OK;
- }
-
- PYTHON_RETURN_ERROR;
-}
-*/
-
-/*
- * weechat_python_api_get_server_info: get infos about servers
- */
-
-/*
-static PyObject *
-weechat_python_api_get_server_info (PyObject *self, PyObject *args)
-{
- t_plugin_server_info *server_info, *ptr_server;
- PyObject *server_hash, *server_hash_member, *key, *value;
- char timebuffer[64];
-
- // make C compiler happy
- (void) self;
- (void) args;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- server_hash = PyDict_New ();
- if (!server_hash)
- {
- PYTHON_RETURN_EMPTY;
- }
-
- server_info = python_plugin->get_server_info (python_plugin);
- if (!server_info)
- return server_hash;
-
- for(ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server)
- {
- strftime(timebuffer, sizeof(timebuffer), "%F %T",
- localtime(&ptr_server->away_time));
-
- server_hash_member = PyDict_New();
-
- if (server_hash_member)
- {
- key = Py_BuildValue("s", "autoconnect");
- value = Py_BuildValue("i", ptr_server->autoconnect);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "autoreconnect");
- value = Py_BuildValue("i", ptr_server->autoreconnect);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "autoreconnect_delay");
- value = Py_BuildValue("i", ptr_server->autoreconnect_delay);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "temp_server");
- value = Py_BuildValue("i", ptr_server->temp_server);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "address");
- value = Py_BuildValue("s", ptr_server->address);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "port");
- value = Py_BuildValue("i", ptr_server->port);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "ipv6");
- value = Py_BuildValue("i", ptr_server->ipv6);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "ssl");
- value = Py_BuildValue("i", ptr_server->ssl);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "password");
- value = Py_BuildValue("s", ptr_server->password);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "nick1");
- value = Py_BuildValue("s", ptr_server->nick1);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "nick2");
- value = Py_BuildValue("s", ptr_server->nick2);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "nick3");
- value = Py_BuildValue("s", ptr_server->nick3);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "username");
- value = Py_BuildValue("s", ptr_server->username);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "realname");
- value = Py_BuildValue("s", ptr_server->realname);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "command");
- value = Py_BuildValue("s", ptr_server->command);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "command_delay");
- value = Py_BuildValue("i", ptr_server->command_delay);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "autojoin");
- value = Py_BuildValue("s", ptr_server->autojoin);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "autorejoin");
- value = Py_BuildValue("i", ptr_server->autorejoin);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "notify_levels");
- value = Py_BuildValue("s", ptr_server->notify_levels);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "is_connected");
- value = Py_BuildValue("i", ptr_server->is_connected);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "ssl_connected");
- value = Py_BuildValue("i", ptr_server->ssl_connected);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "nick");
- value = Py_BuildValue("s", ptr_server->nick);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "nick_modes");
- value = Py_BuildValue("s", ptr_server->nick_modes);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "away_time");
- value = Py_BuildValue("s", timebuffer);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "lag");
- value = Py_BuildValue("i", ptr_server->lag);
- PyDict_SetItem(server_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", ptr_server->name);
- PyDict_SetItem(server_hash, key, server_hash_member);
- Py_DECREF (key);
- Py_DECREF (server_hash_member);
- }
- }
-
- python_plugin->free_server_info(python_plugin, server_info);
-
- return server_hash;
-}
-*/
-
-/*
- * weechat_python_api_get_channel_info: get infos about channels
- */
-
-/*
-static PyObject *
-weechat_python_api_get_channel_info (PyObject *self, PyObject *args)
-{
- t_plugin_channel_info *channel_info, *ptr_channel;
- PyObject *channel_hash, *channel_hash_member, *key, *value;
- char *server;
-
- // make C compiler happy
- (void) self;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- server = NULL;
- if (!PyArg_ParseTuple (args, "s", &server))
- {
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- channel_hash = PyDict_New ();
- if (!channel_hash)
- {
- PYTHON_RETURN_EMPTY;
- }
-
- channel_info = python_plugin->get_channel_info (python_plugin, server);
- if (!channel_info)
- return channel_hash;
-
- for(ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel)
- {
- channel_hash_member = PyDict_New();
-
- if (channel_hash_member)
- {
- key = Py_BuildValue("s", "type");
- value = Py_BuildValue("i", ptr_channel->type);
- PyDict_SetItem(channel_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "topic");
- value = Py_BuildValue("s", ptr_channel->topic);
- PyDict_SetItem(channel_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "modes");
- value = Py_BuildValue("s", ptr_channel->modes);
- PyDict_SetItem(channel_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "limit");
- value = Py_BuildValue("i", ptr_channel->limit);
- PyDict_SetItem(channel_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "key");
- value = Py_BuildValue("s", ptr_channel->key);
- PyDict_SetItem(channel_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "nicks_count");
- value = Py_BuildValue("i", ptr_channel->nicks_count);
- PyDict_SetItem(channel_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", ptr_channel->name);
- PyDict_SetItem(channel_hash, key, channel_hash_member);
- Py_DECREF (key);
- Py_DECREF (channel_hash_member);
- }
- }
-
- python_plugin->free_channel_info(python_plugin, channel_info);
-
- return channel_hash;
-}
-*/
-
-/*
- * weechat_python_api_get_nick_info: get infos about nicks
- */
-
-/*
-static PyObject *
-weechat_python_api_get_nick_info (PyObject *self, PyObject *args)
-{
- t_plugin_nick_info *nick_info, *ptr_nick;
- PyObject *nick_hash, *nick_hash_member, *key, *value;
- char *server, *channel;
-
- // make C compiler happy
- (void) self;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- server = NULL;
- channel = NULL;
- if (!PyArg_ParseTuple (args, "ss", &server, &channel))
- {
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- nick_hash = PyDict_New ();
- if (!nick_hash)
- {
- PYTHON_RETURN_EMPTY;
- }
-
- nick_info = python_plugin->get_nick_info (python_plugin, server, channel);
- if (!nick_info)
- return nick_hash;
-
- for(ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick)
- {
- nick_hash_member = PyDict_New();
-
- if (nick_hash_member)
- {
- key = Py_BuildValue("s", "flags");
- value = Py_BuildValue("i", ptr_nick->flags);
- PyDict_SetItem(nick_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "host");
- value = Py_BuildValue("s", ptr_nick->host ? ptr_nick->host : "");
- PyDict_SetItem(nick_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", ptr_nick->nick);
- PyDict_SetItem(nick_hash, key, nick_hash_member);
- Py_DECREF (key);
- Py_DECREF (nick_hash_member);
- }
- }
-
- python_plugin->free_nick_info(python_plugin, nick_info);
-
- return nick_hash;
-}
-*/
-
-/*
- * weechat_python_api_get_irc_color: get the numeric value which identify an
- * irc color by its name
- */
-
-/*
-static PyObject *
-weechat_python_api_get_irc_color (PyObject *self, PyObject *args)
-{
- char *color;
-
- // make C compiler happy
- (void) self;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- return Py_BuildValue ("i", -1);
- }
-
- color = NULL;
-
- if (!PyArg_ParseTuple (args, "s", &color))
- {
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print");
- return Py_BuildValue ("i", -1);
- }
-
- if (color)
- return Py_BuildValue ("i", python_plugin->get_irc_color (python_plugin, color));
-
- return Py_BuildValue ("i", -1);
-}
-*/
-
-/*
- * weechat_python_api_get_window_info: get infos about windows
- */
-
-/*
-static PyObject *
-weechat_python_api_get_window_info (PyObject *self, PyObject *args)
-{
- t_plugin_window_info *window_info, *ptr_win;
- PyObject *window_list, *window_list_member, *key, *value;
-
- // make C compiler happy
- (void) self;
- (void) args;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- window_list = PyList_New (0);
- if (!window_list)
- {
- PYTHON_RETURN_EMPTY;
- }
-
- window_info = python_plugin->get_window_info (python_plugin);
- if (!window_info)
- return window_list;
-
- for (ptr_win = window_info; ptr_win; ptr_win = ptr_win->next_window)
- {
- window_list_member = PyDict_New();
-
- if (window_list_member)
- {
- key = Py_BuildValue("s", "num_buffer");
- value = Py_BuildValue("i", ptr_win->num_buffer);
- PyDict_SetItem(window_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "win_x");
- value = Py_BuildValue("i", ptr_win->win_x);
- PyDict_SetItem(window_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "win_y");
- value = Py_BuildValue("i", ptr_win->win_y);
- PyDict_SetItem(window_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "win_width");
- value = Py_BuildValue("i", ptr_win->win_width);
- PyDict_SetItem(window_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "win_height");
- value = Py_BuildValue("i", ptr_win->win_height);
- PyDict_SetItem(window_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "win_width_pct");
- value = Py_BuildValue("i", ptr_win->win_width_pct);
- PyDict_SetItem(window_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "win_height_pct");
- value = Py_BuildValue("i", ptr_win->win_height_pct);
- PyDict_SetItem(window_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- PyList_Append(window_list, window_list_member);
- Py_DECREF (window_list_member);
- }
- }
-
- python_plugin->free_window_info(python_plugin, window_info);
-
- return window_list;
-}
-*/
-
-/*
- * weechat_python_api_get_buffer_info: get infos about buffers
- */
-
-/*
-static PyObject *
-weechat_python_api_get_buffer_info (PyObject *self, PyObject *args)
-{
- t_plugin_buffer_info *buffer_info, *ptr_buffer;
- PyObject *buffer_hash, *buffer_hash_member, *key, *value;
-
- // make C compiler happy
- (void) self;
- (void) args;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- buffer_hash = PyDict_New ();
- if (!buffer_hash)
- {
- PYTHON_RETURN_EMPTY;
- }
-
- buffer_info = python_plugin->get_buffer_info (python_plugin);
- if (!buffer_info)
- return buffer_hash;
-
- for(ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
- {
- buffer_hash_member = PyDict_New();
-
- if (buffer_hash_member)
- {
-
- key = Py_BuildValue("s", "type");
- value = Py_BuildValue("i", ptr_buffer->type);
- PyDict_SetItem(buffer_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "num_displayed");
- value = Py_BuildValue("i", ptr_buffer->num_displayed);
- PyDict_SetItem(buffer_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "server");
- value = Py_BuildValue("s", ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name);
- PyDict_SetItem(buffer_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "channel");
- value = Py_BuildValue("s", ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name);
- PyDict_SetItem(buffer_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "notify_level");
- value = Py_BuildValue("i", ptr_buffer->notify_level);
- PyDict_SetItem(buffer_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "log_filename");
- value = Py_BuildValue("s", ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename);
- PyDict_SetItem(buffer_hash_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("i", ptr_buffer->number);
- PyDict_SetItem(buffer_hash, key, buffer_hash_member);
- Py_DECREF (key);
- Py_DECREF (buffer_hash_member);
- }
- }
- python_plugin->free_buffer_info(python_plugin, buffer_info);
-
- return buffer_hash;
-}
-*/
-
-/*
- * weechat_python_api_get_buffer_data: get buffer content
- */
-
-/*
-static PyObject *
-weechat_python_api_get_buffer_data (PyObject *self, PyObject *args)
-{
- t_plugin_buffer_line *buffer_data, *ptr_data;
- PyObject *data_list, *data_list_member, *key, *value;
- char *server, *channel;
- char timebuffer[64];
-
- // make C compiler happy
- (void) self;
- (void) args;
-
- if (!python_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- server = NULL;
- channel = NULL;
-
- if (!PyArg_ParseTuple (args, "ss|", &server, &channel))
- {
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print");
- PYTHON_RETURN_EMPTY;
- }
-
- data_list = PyList_New (0);
- if (!data_list)
- {
- PYTHON_RETURN_EMPTY;
- }
-
- buffer_data = python_plugin->get_buffer_data (python_plugin, server, channel);
- if (!buffer_data)
- return data_list;
-
- for(ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line)
- {
- data_list_member= PyDict_New();
-
- if (data_list_member)
- {
- strftime(timebuffer, sizeof(timebuffer), "%F %T",
- localtime(&ptr_data->date));
-
- key = Py_BuildValue("s", "date");
- value = Py_BuildValue("s", timebuffer);
- PyDict_SetItem(data_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "nick");
- value = Py_BuildValue("s", ptr_data->nick == NULL ? "" : ptr_data->nick);
- PyDict_SetItem(data_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- key = Py_BuildValue("s", "data");
- value = Py_BuildValue("s", ptr_data->data == NULL ? "" : ptr_data->data);
- PyDict_SetItem(data_list_member, key, value);
- Py_DECREF (key);
- Py_DECREF (value);
-
- PyList_Append(data_list, data_list_member);
- Py_DECREF (data_list_member);
- }
- }
-
- python_plugin->free_buffer_data (python_plugin, buffer_data);
-
- return data_list;
-}
-*/
-
-/*
* Python subroutines
*/
@@ -3239,6 +2981,22 @@ PyMethodDef weechat_python_funcs[] =
{ "list_remove", &weechat_python_api_list_remove, METH_VARARGS, "" },
{ "list_remove_all", &weechat_python_api_list_remove_all, METH_VARARGS, "" },
{ "list_free", &weechat_python_api_list_free, METH_VARARGS, "" },
+ { "config_new", &weechat_python_api_config_new, METH_VARARGS, "" },
+ { "config_new_section", &weechat_python_api_config_new_section, METH_VARARGS, "" },
+ { "config_search_section", &weechat_python_api_config_search_section, METH_VARARGS, "" },
+ { "config_new_option", &weechat_python_api_config_new_option, METH_VARARGS, "" },
+ { "config_search_option", &weechat_python_api_config_search_option, METH_VARARGS, "" },
+ { "config_string_to_boolean", &weechat_python_api_config_string_to_boolean, METH_VARARGS, "" },
+ { "config_option_set", &weechat_python_api_config_option_set, METH_VARARGS, "" },
+ { "config_boolean", &weechat_python_api_config_boolean, METH_VARARGS, "" },
+ { "config_integer", &weechat_python_api_config_integer, METH_VARARGS, "" },
+ { "config_string", &weechat_python_api_config_string, METH_VARARGS, "" },
+ { "config_color", &weechat_python_api_config_color, METH_VARARGS, "" },
+ { "config_write_line", &weechat_python_api_config_write_line, METH_VARARGS, "" },
+ { "config_write", &weechat_python_api_config_write, METH_VARARGS, "" },
+ { "config_read", &weechat_python_api_config_read, METH_VARARGS, "" },
+ { "config_reload", &weechat_python_api_config_reload, METH_VARARGS, "" },
+ { "config_free", &weechat_python_api_config_free, METH_VARARGS, "" },
{ "prefix", &weechat_python_api_prefix, METH_VARARGS, "" },
{ "color", &weechat_python_api_color, METH_VARARGS, "" },
{ "prnt", &weechat_python_api_prnt, METH_VARARGS, "" },
@@ -3271,19 +3029,5 @@ PyMethodDef weechat_python_funcs[] =
{ "nicklist_remove_all", &weechat_python_api_nicklist_remove_all, METH_VARARGS, "" },
{ "command", &weechat_python_api_command, METH_VARARGS, "" },
{ "info_get", &weechat_python_api_info_get, METH_VARARGS, "" },
- /*
- { "get_dcc_info", weechat_python_get_dcc_info, METH_VARARGS, "" },
- { "get_config", weechat_python_get_config, METH_VARARGS, "" },
- { "set_config", weechat_python_set_config, METH_VARARGS, "" },
- { "get_plugin_config", weechat_python_get_plugin_config, METH_VARARGS, "" },
- { "set_plugin_config", weechat_python_set_plugin_config, METH_VARARGS, "" },
- { "get_server_info", weechat_python_get_server_info, METH_VARARGS, "" },
- { "get_channel_info", weechat_python_get_channel_info, METH_VARARGS, "" },
- { "get_nick_info", weechat_python_get_nick_info, METH_VARARGS, "" },
- { "get_irc_color", weechat_python_get_irc_color, METH_VARARGS, "" },
- { "get_window_info", weechat_python_get_window_info, METH_VARARGS, "" },
- { "get_buffer_info", weechat_python_get_buffer_info, METH_VARARGS, "" },
- { "get_buffer_data", weechat_python_get_buffer_data, METH_VARARGS, "" },
- */
{ NULL, NULL, 0, NULL }
};
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c
index 4d3919725..76c71859b 100644
--- a/src/plugins/scripts/python/weechat-python.c
+++ b/src/plugins/scripts/python/weechat-python.c
@@ -370,8 +370,8 @@ weechat_python_load (char *filename)
/* if script was registered, removing from list */
if (python_current_script != NULL)
{
- script_remove (weechat_python_plugin,
- &python_scripts, python_current_script);
+ script_remove (weechat_python_plugin, &python_scripts,
+ python_current_script);
}
return 0;
}
diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c
index cbccb43a1..4ec76134e 100644
--- a/src/plugins/scripts/ruby/weechat-ruby-api.c
+++ b/src/plugins/scripts/ruby/weechat-ruby-api.c
@@ -865,6 +865,848 @@ weechat_ruby_api_list_free (VALUE class, VALUE weelist)
}
/*
+ * weechat_ruby_api_config_reload_cb: callback for config reload
+ */
+
+int
+weechat_ruby_api_config_reload_cb (void *data,
+ struct t_config_file *config_file)
+{
+ struct t_script_callback *script_callback;
+ char *ruby_argv[2];
+ int *rc, ret;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ ruby_argv[0] = script_ptr2str (config_file);
+ ruby_argv[1] = 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]);
+
+ return ret;
+ }
+
+ return 0;
+}
+
+/*
+ * weechat_ruby_api_config_new: create a new configuration file
+ */
+
+static VALUE
+weechat_ruby_api_config_new (VALUE class, VALUE filename, VALUE function)
+{
+ char *c_filename, *c_function, *result;
+ VALUE return_value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_filename = NULL;
+ c_function = NULL;
+
+ if (NIL_P (filename) || NIL_P (function))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (filename, T_STRING);
+ Check_Type (function, T_STRING);
+
+ c_filename = STR2CSTR (filename);
+ c_function = STR2CSTR (function);
+
+ result = script_ptr2str (script_api_config_new (weechat_ruby_plugin,
+ ruby_current_script,
+ c_filename,
+ &weechat_ruby_api_config_reload_cb,
+ c_function));
+ RUBY_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_ruby_api_config_read_cb: callback for reading option in section
+ */
+
+void
+weechat_ruby_api_config_read_cb (void *data,
+ struct t_config_file *config_file,
+ char *option_name, char *value)
+{
+ struct t_script_callback *script_callback;
+ char *ruby_argv[4];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ ruby_argv[0] = script_ptr2str (config_file);
+ ruby_argv[1] = option_name;
+ ruby_argv[2] = value;
+ ruby_argv[3] = NULL;
+
+ rc = (int *) weechat_ruby_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ ruby_argv);
+
+ if (rc)
+ free (rc);
+ if (ruby_argv[0])
+ free (ruby_argv[0]);
+ }
+}
+
+/*
+ * weechat_ruby_api_config_section_write_cb: callback for writing section
+ */
+
+void
+weechat_ruby_api_config_section_write_cb (void *data,
+ struct t_config_file *config_file,
+ char *section_name)
+{
+ struct t_script_callback *script_callback;
+ char *ruby_argv[3];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ ruby_argv[0] = script_ptr2str (config_file);
+ ruby_argv[1] = section_name;
+ ruby_argv[2] = NULL;
+
+ rc = (int *) weechat_ruby_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ ruby_argv);
+
+ if (rc)
+ free (rc);
+ if (ruby_argv[0])
+ free (ruby_argv[0]);
+ }
+}
+
+/*
+ * weechat_ruby_api_config_section_write_default_cb: callback for writing
+ * default values for section
+ */
+
+void
+weechat_ruby_api_config_section_write_default_cb (void *data,
+ struct t_config_file *config_file,
+ char *section_name)
+{
+ struct t_script_callback *script_callback;
+ char *ruby_argv[3];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ ruby_argv[0] = script_ptr2str (config_file);
+ ruby_argv[1] = section_name;
+ ruby_argv[2] = NULL;
+
+ rc = (int *) weechat_ruby_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ ruby_argv);
+
+ if (rc)
+ free (rc);
+ if (ruby_argv[0])
+ free (ruby_argv[0]);
+ }
+}
+
+/*
+ * weechat_ruby_api_config_new_section: create a new section in configuration file
+ */
+
+static VALUE
+weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
+ VALUE name, VALUE function_read,
+ VALUE function_write,
+ VALUE function_write_default)
+{
+ char *c_config_file, *c_name, *c_function_read, *c_function_write;
+ char *c_function_write_default, *result;
+ VALUE return_value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new_section");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_config_file = NULL;
+ c_name = NULL;
+ c_function_read = NULL;
+ c_function_write = NULL;
+ c_function_write_default = NULL;
+
+ if (NIL_P (config_file) || NIL_P (name) || NIL_P (function_read)
+ || NIL_P (function_write) || NIL_P (function_write_default))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (config_file, T_STRING);
+ Check_Type (name, T_STRING);
+ Check_Type (function_read, T_STRING);
+ Check_Type (function_write, T_STRING);
+ Check_Type (function_write_default, T_STRING);
+
+ c_config_file = STR2CSTR (config_file);
+ c_name = STR2CSTR (name);
+ c_function_read = STR2CSTR (function_read);
+ c_function_write = STR2CSTR (function_write);
+ c_function_write_default = STR2CSTR (function_write_default);
+
+ result = script_ptr2str (script_api_config_new_section (weechat_ruby_plugin,
+ ruby_current_script,
+ script_str2ptr (c_config_file),
+ c_name,
+ &weechat_ruby_api_config_read_cb,
+ c_function_read,
+ &weechat_ruby_api_config_section_write_cb,
+ c_function_write,
+ &weechat_ruby_api_config_section_write_default_cb,
+ c_function_write_default));
+ RUBY_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_ruby_api_config_search_section: search section in configuration file
+ */
+
+static VALUE
+weechat_ruby_api_config_search_section (VALUE class, VALUE config_file,
+ VALUE section_name)
+{
+ char *c_config_file, *c_section_name, *result;
+ VALUE return_value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_search_section");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_config_file = NULL;
+ c_section_name = NULL;
+
+ if (NIL_P (config_file) || NIL_P (section_name))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_search_section");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (config_file, T_STRING);
+ Check_Type (section_name, T_STRING);
+
+ c_config_file = STR2CSTR (config_file);
+ c_section_name = STR2CSTR (section_name);
+
+ result = script_ptr2str (weechat_config_search_section (script_str2ptr (c_config_file),
+ c_section_name));
+ RUBY_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_ruby_api_config_option_change_cb: callback for option changed
+ */
+
+void
+weechat_ruby_api_config_option_change_cb (void *data)
+{
+ struct t_script_callback *script_callback;
+ char *ruby_argv[1];
+ int *rc;
+
+ script_callback = (struct t_script_callback *)data;
+
+ if (script_callback->function && script_callback->function[0])
+ {
+ ruby_argv[1] = NULL;
+
+ rc = (int *) weechat_ruby_exec (script_callback->script,
+ WEECHAT_SCRIPT_EXEC_INT,
+ script_callback->function,
+ ruby_argv);
+
+ if (rc)
+ free (rc);
+ }
+}
+
+/*
+ * weechat_ruby_api_config_new_option: create a new option in section
+ */
+
+static VALUE
+weechat_ruby_api_config_new_option (VALUE class, VALUE config_file,
+ VALUE section, VALUE name, VALUE type,
+ VALUE description, VALUE string_values,
+ VALUE min, VALUE max, VALUE default_value,
+ VALUE function)
+{
+ char *c_config_file, *c_section, *c_name, *c_type, *c_description;
+ char *c_string_values, *c_default_value, *c_function, *result;
+ int c_min, c_max;
+ VALUE return_value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_new_option");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_config_file = NULL;
+ c_section = NULL;
+ c_name = NULL;
+ c_type = NULL;
+ c_description = NULL;
+ c_string_values = NULL;
+ c_min = 0;
+ c_max = 0;
+ c_default_value = NULL;
+ c_function = NULL;
+
+ if (NIL_P (config_file) || NIL_P (section) || NIL_P (name) || NIL_P (type)
+ || NIL_P (description) || NIL_P (string_values)
+ || NIL_P (default_value) || NIL_P (function))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (config_file, T_STRING);
+ Check_Type (section, T_STRING);
+ Check_Type (name, T_STRING);
+ Check_Type (type, T_STRING);
+ Check_Type (description, T_STRING);
+ Check_Type (string_values, T_STRING);
+ Check_Type (min, T_FIXNUM);
+ Check_Type (max, T_FIXNUM);
+ Check_Type (default_value, T_STRING);
+ Check_Type (function, T_STRING);
+
+ c_config_file = STR2CSTR (config_file);
+ c_section = STR2CSTR (section);
+ c_name = STR2CSTR (name);
+ c_type = STR2CSTR (type);
+ c_description = STR2CSTR (description);
+ c_string_values = STR2CSTR (string_values);
+ c_min = FIX2INT (min);
+ c_max = FIX2INT (max);
+ c_default_value = STR2CSTR (default_value);
+ c_function = STR2CSTR (function);
+
+ result = script_ptr2str (script_api_config_new_option (weechat_ruby_plugin,
+ ruby_current_script,
+ script_str2ptr (c_config_file),
+ script_str2ptr (c_section),
+ c_name,
+ c_type,
+ c_description,
+ c_string_values,
+ c_min,
+ c_max,
+ c_default_value,
+ &weechat_ruby_api_config_option_change_cb,
+ c_function));
+ RUBY_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_ruby_api_config_search_option: search option in configuration file or section
+ */
+
+static VALUE
+weechat_ruby_api_config_search_option (VALUE class, VALUE config_file,
+ VALUE section, VALUE option_name)
+{
+ char *c_config_file, *c_section, *c_option_name, *result;
+ VALUE return_value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_search_option");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_config_file = NULL;
+ c_section = NULL;
+ c_option_name = NULL;
+
+ if (NIL_P (config_file) || NIL_P (section) || NIL_P (option_name))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_search_option");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (config_file, T_STRING);
+ Check_Type (section, T_STRING);
+ Check_Type (option_name, T_STRING);
+
+ c_config_file = STR2CSTR (config_file);
+ c_section = STR2CSTR (section);
+ c_option_name = STR2CSTR (option_name);
+
+ result = script_ptr2str (weechat_config_search_option (script_str2ptr (c_config_file),
+ script_str2ptr (c_section),
+ c_option_name));
+ RUBY_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_ruby_api_config_string_to_boolean: return boolean value of a string
+ */
+
+static VALUE
+weechat_ruby_api_config_string_to_boolean (VALUE class, VALUE text)
+{
+ char *c_text;
+ int value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_string_to_boolean");
+ RUBY_RETURN_INT(0);
+ }
+
+ c_text = NULL;
+
+ if (NIL_P (text))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_string_to_boolean");
+ RUBY_RETURN_INT(0);
+ }
+
+ Check_Type (text, T_STRING);
+
+ c_text = STR2CSTR (text);
+
+ value = weechat_config_string_to_boolean (c_text);
+ RUBY_RETURN_INT(value);
+}
+
+/*
+ * weechat_ruby_api_config_option_set: set new value for option
+ */
+
+static VALUE
+weechat_ruby_api_config_option_set (VALUE class, VALUE option, VALUE new_value,
+ VALUE run_callback)
+{
+ char *c_option, *c_new_value;
+ int c_run_callback, rc;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set");
+ RUBY_RETURN_INT(0);
+ }
+
+ c_option = NULL;
+ c_new_value = NULL;
+ c_run_callback = 0;
+
+ if (NIL_P (option) || NIL_P (new_value) || NIL_P (run_callback))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set");
+ RUBY_RETURN_INT(0);
+ }
+
+ Check_Type (option, T_STRING);
+ Check_Type (new_value, T_STRING);
+ Check_Type (run_callback, T_FIXNUM);
+
+ c_option = STR2CSTR (option);
+ c_new_value = STR2CSTR (new_value);
+ c_run_callback = FIX2INT (run_callback);
+
+ rc = weechat_config_option_set (script_str2ptr (c_option),
+ c_new_value,
+ c_run_callback);
+ RUBY_RETURN_INT(rc);
+}
+
+/*
+ * weechat_ruby_api_config_boolean: return boolean value of option
+ */
+
+static VALUE
+weechat_ruby_api_config_boolean (VALUE class, VALUE option)
+{
+ char *c_option;
+ int value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_boolean");
+ RUBY_RETURN_INT(0);
+ }
+
+ c_option = NULL;
+
+ if (NIL_P (option))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_boolean");
+ RUBY_RETURN_INT(0);
+ }
+
+ Check_Type (option, T_STRING);
+
+ c_option = STR2CSTR (option);
+
+ value = weechat_config_boolean (script_str2ptr (c_option));
+ RUBY_RETURN_INT(value);
+}
+
+/*
+ * weechat_ruby_api_config_integer: return integer value of option
+ */
+
+static VALUE
+weechat_ruby_api_config_integer (VALUE class, VALUE option)
+{
+ char *c_option;
+ int value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_integer");
+ RUBY_RETURN_INT(0);
+ }
+
+ c_option = NULL;
+
+ if (NIL_P (option))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_integer");
+ RUBY_RETURN_INT(0);
+ }
+
+ Check_Type (option, T_STRING);
+
+ c_option = STR2CSTR (option);
+
+ value = weechat_config_integer (script_str2ptr (c_option));
+ RUBY_RETURN_INT(value);
+}
+
+/*
+ * weechat_ruby_api_config_string: return string value of option
+ */
+
+static VALUE
+weechat_ruby_api_config_string (VALUE class, VALUE option)
+{
+ char *c_option, *value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_string");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_option = NULL;
+
+ if (NIL_P (option))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_string");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (option, T_STRING);
+
+ c_option = STR2CSTR (option);
+
+ value = weechat_config_string (script_str2ptr (c_option));
+ RUBY_RETURN_STRING(value);
+}
+
+/*
+ * weechat_ruby_api_config_color: return color value of option
+ */
+
+static VALUE
+weechat_ruby_api_config_color (VALUE class, VALUE option)
+{
+ char *c_option;
+ int value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_color");
+ RUBY_RETURN_INT(0);
+ }
+
+ c_option = NULL;
+
+ if (NIL_P (option))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_color");
+ RUBY_RETURN_INT(0);
+ }
+
+ Check_Type (option, T_STRING);
+
+ c_option = STR2CSTR (option);
+
+ value = weechat_config_color (script_str2ptr (c_option));
+ RUBY_RETURN_INT(value);
+}
+
+/*
+ * weechat_ruby_api_config_write_line: write a line in configuration file
+ */
+
+static VALUE
+weechat_ruby_api_config_write_line (VALUE class, VALUE config_file,
+ VALUE option_name, VALUE value)
+{
+ char *c_config_file, *c_option_name, *c_value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write_line");
+ RUBY_RETURN_ERROR;
+ }
+
+ c_config_file = NULL;
+ c_option_name = NULL;
+ c_value = NULL;
+
+ if (NIL_P (config_file) || NIL_P (option_name) || NIL_P (value))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write_line");
+ RUBY_RETURN_ERROR;
+ }
+
+ Check_Type (config_file, T_STRING);
+ Check_Type (option_name, T_STRING);
+ Check_Type (value, T_STRING);
+
+ c_config_file = STR2CSTR (config_file);
+ c_option_name = STR2CSTR (option_name);
+ c_value = STR2CSTR (value);
+
+ weechat_config_write_line (script_str2ptr (c_config_file),
+ c_option_name,
+ "%s",
+ c_value);
+
+ RUBY_RETURN_OK;
+}
+
+/*
+ * weechat_ruby_api_config_write: write configuration file
+ */
+
+static VALUE
+weechat_ruby_api_config_write (VALUE class, VALUE config_file)
+{
+ char *c_config_file;
+ int rc;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write");
+ RUBY_RETURN_INT(-1);
+ }
+
+ c_config_file = NULL;
+
+ if (NIL_P (config_file))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write");
+ RUBY_RETURN_INT(-1);
+ }
+
+ Check_Type (config_file, T_STRING);
+
+ c_config_file = STR2CSTR (config_file);
+
+ rc = weechat_config_write (script_str2ptr (c_config_file));
+ RUBY_RETURN_INT(rc);
+}
+
+/*
+ * weechat_ruby_api_config_read: read configuration file
+ */
+
+static VALUE
+weechat_ruby_api_config_read (VALUE class, VALUE config_file)
+{
+ char *c_config_file;
+ int rc;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_read");
+ RUBY_RETURN_INT(-1);
+ }
+
+ c_config_file = NULL;
+
+ if (NIL_P (config_file))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_read");
+ RUBY_RETURN_INT(-1);
+ }
+
+ Check_Type (config_file, T_STRING);
+
+ c_config_file = STR2CSTR (config_file);
+
+ rc = weechat_config_read (script_str2ptr (c_config_file));
+ RUBY_RETURN_INT(rc);
+}
+
+/*
+ * weechat_ruby_api_config_reload: reload configuration file
+ */
+
+static VALUE
+weechat_ruby_api_config_reload (VALUE class, VALUE config_file)
+{
+ char *c_config_file;
+ int rc;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_reload");
+ RUBY_RETURN_INT(-1);
+ }
+
+ c_config_file = NULL;
+
+ if (NIL_P (config_file))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_reload");
+ RUBY_RETURN_INT(-1);
+ }
+
+ Check_Type (config_file, T_STRING);
+
+ c_config_file = STR2CSTR (config_file);
+
+ rc = weechat_config_reload (script_str2ptr (c_config_file));
+ RUBY_RETURN_INT(rc);
+}
+
+/*
+ * weechat_ruby_api_config_free: free configuration file
+ */
+
+static VALUE
+weechat_ruby_api_config_free (VALUE class, VALUE config_file)
+{
+ char *c_config_file;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_free");
+ RUBY_RETURN_ERROR;
+ }
+
+ c_config_file = NULL;
+
+ if (NIL_P (config_file))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_free");
+ RUBY_RETURN_ERROR;
+ }
+
+ Check_Type (config_file, T_STRING);
+
+ c_config_file = STR2CSTR (config_file);
+
+ script_api_config_free (weechat_ruby_plugin,
+ ruby_current_script,
+ script_str2ptr (c_config_file));
+
+ RUBY_RETURN_OK;
+}
+
+/*
* weechat_ruby_api_prefix: get a prefix, used for display
*/
@@ -1915,12 +2757,11 @@ weechat_ruby_api_unhook (VALUE class, VALUE hook)
c_hook = STR2CSTR (hook);
- if (script_api_unhook (weechat_ruby_plugin,
- ruby_current_script,
- script_str2ptr (c_hook)))
- RUBY_RETURN_OK;
+ script_api_unhook (weechat_ruby_plugin,
+ ruby_current_script,
+ script_str2ptr (c_hook));
- RUBY_RETURN_ERROR;
+ RUBY_RETURN_OK;
}
/*
@@ -1939,8 +2780,7 @@ weechat_ruby_api_unhook_all (VALUE class)
RUBY_RETURN_ERROR;
}
- script_api_unhook_all (weechat_ruby_plugin,
- ruby_current_script);
+ script_api_unhook_all (ruby_current_script);
RUBY_RETURN_OK;
}
@@ -2572,785 +3412,6 @@ weechat_ruby_api_info_get (VALUE class, VALUE info)
}
/*
- * weechat_ruby_api_get_dcc_info: get infos about DCC
- */
-
-/*
-static VALUE
-weechat_ruby_api_get_dcc_info (VALUE class)
-{
- t_plugin_dcc_info *dcc_info, *ptr_dcc;
- VALUE dcc_list, dcc_list_member;
- char timebuffer1[64];
- char timebuffer2[64];
- struct in_addr in;
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("charset_set");
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to get DCC info, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- dcc_list = rb_ary_new();
-
- if (NIL_P (dcc_list))
- return Qnil;
-
- dcc_info = ruby_plugin->get_dcc_info (ruby_plugin);
- if (!dcc_info)
- return dcc_list;
-
- for(ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
- {
- strftime(timebuffer1, sizeof(timebuffer1), "%F %T",
- localtime(&ptr_dcc->start_time));
- strftime(timebuffer2, sizeof(timebuffer2), "%F %T",
- localtime(&ptr_dcc->start_transfer));
- in.s_addr = htonl(ptr_dcc->addr);
-
- dcc_list_member = rb_hash_new ();
-
- if (!NIL_P (dcc_list_member))
- {
- rb_hash_aset (dcc_list_member, rb_str_new2("server"),
- rb_str_new2(ptr_dcc->server));
- rb_hash_aset (dcc_list_member, rb_str_new2("channel"),
- rb_str_new2(ptr_dcc->channel));
- rb_hash_aset (dcc_list_member, rb_str_new2("type"),
- INT2FIX(ptr_dcc->type));
- rb_hash_aset (dcc_list_member, rb_str_new2("status"),
- INT2FIX(ptr_dcc->status));
- rb_hash_aset (dcc_list_member, rb_str_new2("start_time"),
- rb_str_new2(timebuffer1));
- rb_hash_aset (dcc_list_member, rb_str_new2("start_transfer"),
- rb_str_new2(timebuffer2));
- rb_hash_aset (dcc_list_member, rb_str_new2("address"),
- rb_str_new2(inet_ntoa(in)));
- rb_hash_aset (dcc_list_member, rb_str_new2("port"),
- INT2FIX(ptr_dcc->port));
- rb_hash_aset (dcc_list_member, rb_str_new2("nick"),
- rb_str_new2(ptr_dcc->nick));
- rb_hash_aset (dcc_list_member, rb_str_new2("remote_file"),
- rb_str_new2(ptr_dcc->filename));
- rb_hash_aset (dcc_list_member, rb_str_new2("local_file"),
- rb_str_new2(ptr_dcc->local_filename));
- rb_hash_aset (dcc_list_member, rb_str_new2("filename_suffix"),
- INT2FIX(ptr_dcc->filename_suffix));
- rb_hash_aset (dcc_list_member, rb_str_new2("size"),
- INT2FIX(ptr_dcc->size));
- rb_hash_aset (dcc_list_member, rb_str_new2("pos"),
- INT2FIX(ptr_dcc->pos));
- rb_hash_aset (dcc_list_member, rb_str_new2("start_resume"),
- INT2FIX(ptr_dcc->start_resume));
- rb_hash_aset (dcc_list_member, rb_str_new2("cps"),
- INT2FIX(ptr_dcc->bytes_per_sec));
-
- rb_ary_push (dcc_list, dcc_list_member);
- }
- }
-
- ruby_plugin->free_dcc_info (ruby_plugin, dcc_info);
-
- return dcc_list;
-}
-*/
-
-/*
- * weechat_ruby_api_get_config: get value of a WeeChat config option
- */
-
-/*
-static VALUE
-weechat_ruby_api_get_config (VALUE class, VALUE option)
-{
- char *c_option, *return_value;
- VALUE ruby_return_value;
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("charset_set");
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to get config option, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- c_option = NULL;
-
- if (NIL_P (option))
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: wrong parameters for "
- "\"get_config\" function");
- return INT2FIX (0);
- }
-
- Check_Type (option, T_STRING);
- c_option = STR2CSTR (option);
-
- if (c_option)
- {
- return_value = ruby_plugin->get_config (ruby_plugin, c_option);
-
- if (return_value)
- {
- ruby_return_value = rb_str_new2 (return_value);
- free (return_value);
- return ruby_return_value;
- }
- }
-
- return rb_str_new2 ("");
-}
-*/
-
-/*
- * weechat_ruby_api_set_config: set value of a WeeChat config option
- */
-
-/*
-static VALUE
-weechat_ruby_api_set_config (VALUE class, VALUE option, VALUE value)
-{
- char *c_option, *c_value;
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to set config option, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- c_option = NULL;
- c_value = NULL;
-
- if (NIL_P (option))
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: wrong parameters for "
- "\"set_config\" function");
- return INT2FIX (0);
- }
-
- Check_Type (option, T_STRING);
- Check_Type (value, T_STRING);
-
- c_option = STR2CSTR (option);
- c_value = STR2CSTR (value);
-
- if (c_option && c_value)
- {
- if (ruby_plugin->set_config (ruby_plugin, c_option, c_value))
- return INT2FIX (1);
- }
-
- return INT2FIX (0);
-}
-*/
-
-/*
- * weechat_ruby_api_get_plugin_config: get value of a plugin config option
- */
-
-/*
-static VALUE
-weechat_ruby_api_get_plugin_config (VALUE class, VALUE option)
-{
- char *c_option, *return_value;
- VALUE ruby_return_value;
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to get plugin config option, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- c_option = NULL;
-
- if (NIL_P (option))
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: wrong parameters for "
- "\"get_plugin_config\" function");
- return INT2FIX (0);
- }
-
- Check_Type (option, T_STRING);
- c_option = STR2CSTR (option);
-
- if (c_option)
- {
- return_value = script_get_plugin_config (ruby_plugin,
- ruby_current_script,
- c_option);
-
- if (return_value)
- {
- ruby_return_value = rb_str_new2 (return_value);
- free (return_value);
- return ruby_return_value;
- }
- }
-
- return rb_str_new2 ("");
-}
-*/
-
-/*
- * weechat_ruby_api_set_plugin_config: set value of a plugin config option
- */
-
-/*
-static VALUE
-weechat_ruby_api_set_plugin_config (VALUE class, VALUE option, VALUE value)
-{
- char *c_option, *c_value;
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to set plugin config option, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- c_option = NULL;
- c_value = NULL;
-
- if (NIL_P (option))
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: wrong parameters for "
- "\"set_plugin_config\" function");
- return INT2FIX (0);
- }
-
- Check_Type (option, T_STRING);
- Check_Type (value, T_STRING);
-
- c_option = STR2CSTR (option);
- c_value = STR2CSTR (value);
-
- if (c_option && c_value)
- {
- if (script_set_plugin_config (ruby_plugin,
- ruby_current_script,
- c_option, c_value))
- RUBY_RETURN_OK;
- }
-
- RUBY_RETURN_ERROR;
-}
-*/
-
-/*
- * weechat_ruby_api_get_server_info: get infos about servers
- */
-
-/*
-static VALUE
-weechat_ruby_api_get_server_info (VALUE class)
-{
- t_plugin_server_info *server_info, *ptr_server;
- VALUE server_hash, server_hash_member;
- char timebuffer[64];
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to get server infos, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- server_hash = rb_hash_new ();
- if (!server_hash)
- return Qnil;
-
- server_info = ruby_plugin->get_server_info (ruby_plugin);
- if (!server_info)
- return server_hash;
-
- for(ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server)
- {
- strftime(timebuffer, sizeof(timebuffer), "%F %T",
- localtime(&ptr_server->away_time));
-
- server_hash_member = rb_hash_new ();
-
- if (server_hash_member)
- {
- rb_hash_aset (server_hash_member, rb_str_new2("autoconnect"),
- INT2FIX(ptr_server->autoconnect));
- rb_hash_aset (server_hash_member, rb_str_new2("autoreconnect"),
- INT2FIX(ptr_server->autoreconnect));
- rb_hash_aset (server_hash_member, rb_str_new2("autoreconnect_delay"),
- INT2FIX(ptr_server->autoreconnect_delay));
- rb_hash_aset (server_hash_member, rb_str_new2("temp_server"),
- INT2FIX(ptr_server->temp_server));
- rb_hash_aset (server_hash_member, rb_str_new2("address"),
- rb_str_new2(ptr_server->address));
- rb_hash_aset (server_hash_member, rb_str_new2("port"),
- INT2FIX(ptr_server->port));
- rb_hash_aset (server_hash_member, rb_str_new2("ipv6"),
- INT2FIX(ptr_server->ipv6));
- rb_hash_aset (server_hash_member, rb_str_new2("ssl"),
- INT2FIX(ptr_server->ssl));
- rb_hash_aset (server_hash_member, rb_str_new2("password"),
- rb_str_new2(ptr_server->password));
- rb_hash_aset (server_hash_member, rb_str_new2("nick1"),
- rb_str_new2(ptr_server->nick1));
- rb_hash_aset (server_hash_member, rb_str_new2("nick2"),
- rb_str_new2(ptr_server->nick2));
- rb_hash_aset (server_hash_member, rb_str_new2("nick3"),
- rb_str_new2(ptr_server->nick3));
- rb_hash_aset (server_hash_member, rb_str_new2("username"),
- rb_str_new2(ptr_server->username));
- rb_hash_aset (server_hash_member, rb_str_new2("realname"),
- rb_str_new2(ptr_server->realname));
- rb_hash_aset (server_hash_member, rb_str_new2("command"),
- rb_str_new2(ptr_server->command));
- rb_hash_aset (server_hash_member, rb_str_new2("command_delay"),
- INT2FIX(ptr_server->command_delay));
- rb_hash_aset (server_hash_member, rb_str_new2("autojoin"),
- rb_str_new2(ptr_server->autojoin));
- rb_hash_aset (server_hash_member, rb_str_new2("autorejoin"),
- INT2FIX(ptr_server->autorejoin));
- rb_hash_aset (server_hash_member, rb_str_new2("notify_levels"),
- rb_str_new2(ptr_server->notify_levels));
- rb_hash_aset (server_hash_member, rb_str_new2("is_connected"),
- INT2FIX(ptr_server->is_connected));
- rb_hash_aset (server_hash_member, rb_str_new2("ssl_connected"),
- INT2FIX(ptr_server->ssl_connected));
- rb_hash_aset (server_hash_member, rb_str_new2("nick"),
- rb_str_new2(ptr_server->nick));
- rb_hash_aset (server_hash_member, rb_str_new2("nick_modes"),
- rb_str_new2(ptr_server->nick_modes));
- rb_hash_aset (server_hash_member, rb_str_new2("away_time"),
- rb_str_new2(timebuffer));
- rb_hash_aset (server_hash_member, rb_str_new2("lag"),
- INT2FIX(ptr_server->lag));
-
- rb_hash_aset (server_hash, rb_str_new2(ptr_server->name), server_hash_member);
- }
- }
-
- ruby_plugin->free_server_info(ruby_plugin, server_info);
-
- return server_hash;
-}
-*/
-
-/*
- * weechat_ruby_api_get_channel_info: get infos about channels
- */
-
-/*
-static VALUE
-weechat_ruby_api_get_channel_info (VALUE class, VALUE server)
-{
- t_plugin_channel_info *channel_info, *ptr_channel;
- VALUE channel_hash, channel_hash_member;
- char *c_server;
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to get channel infos, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- c_server = NULL;
- if (NIL_P (server))
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: wrong parameters for "
- "\"get_channel_info\" function");
- return INT2FIX (0);
- }
-
- Check_Type (server, T_STRING);
- c_server = STR2CSTR (server);
-
- if (!c_server)
- return INT2FIX (0);
-
- channel_hash = rb_hash_new ();
- if (!channel_hash)
- return Qnil;
-
- channel_info = ruby_plugin->get_channel_info (ruby_plugin, c_server);
- if (!channel_info)
- return channel_hash;
-
- for(ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel)
- {
- channel_hash_member = rb_hash_new ();
-
- if (channel_hash_member)
- {
- rb_hash_aset (channel_hash_member, rb_str_new2("type"),
- INT2FIX(ptr_channel->type));
- rb_hash_aset (channel_hash_member, rb_str_new2("topic"),
- rb_str_new2(ptr_channel->topic));
- rb_hash_aset (channel_hash_member, rb_str_new2("modes"),
- rb_str_new2(ptr_channel->modes));
- rb_hash_aset (channel_hash_member, rb_str_new2("limit"),
- INT2FIX(ptr_channel->limit));
- rb_hash_aset (channel_hash_member, rb_str_new2("key"),
- rb_str_new2(ptr_channel->key));
- rb_hash_aset (channel_hash_member, rb_str_new2("nicks_count"),
- INT2FIX(ptr_channel->nicks_count));
-
- rb_hash_aset (channel_hash, rb_str_new2(ptr_channel->name), channel_hash_member);
- }
- }
-
- ruby_plugin->free_channel_info(ruby_plugin, channel_info);
-
- return channel_hash;
-}
-*/
-
-/*
- * weechat_ruby_api_get_nick_info: get infos about nicks
- */
-
-/*
-static VALUE
-weechat_ruby_api_get_nick_info (VALUE class, VALUE server, VALUE channel)
-{
- t_plugin_nick_info *nick_info, *ptr_nick;
- VALUE nick_hash, nick_hash_member;
- char *c_server, *c_channel;
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to get channel infos, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- c_server = NULL;
- c_channel = NULL;
- if (NIL_P (server) || NIL_P (channel))
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: wrong parameters for "
- "\"get_nick_info\" function");
- return INT2FIX (0);
- }
-
- Check_Type (server, T_STRING);
- Check_Type (channel, T_STRING);
-
- c_server = STR2CSTR (server);
- c_channel = STR2CSTR (channel);
-
- if (!c_server || !c_channel)
- return INT2FIX (0);
-
- nick_hash = rb_hash_new ();
- if (!nick_hash)
- return Qnil;
-
- nick_info = ruby_plugin->get_nick_info (ruby_plugin, c_server, c_channel);
- if (!nick_info)
- return nick_hash;
-
- for(ptr_nick = nick_info; ptr_nick; ptr_nick = ptr_nick->next_nick)
- {
- nick_hash_member = rb_hash_new ();
-
- if (nick_hash_member)
- {
- rb_hash_aset (nick_hash_member, rb_str_new2("flags"),
- INT2FIX(ptr_nick->flags));
- rb_hash_aset (nick_hash_member, rb_str_new2("host"),
- rb_str_new2(ptr_nick->host ? ptr_nick->host : ""));
-
- rb_hash_aset (nick_hash, rb_str_new2(ptr_nick->nick), nick_hash_member);
- }
- }
-
- ruby_plugin->free_nick_info(ruby_plugin, nick_info);
-
- return nick_hash;
-}
-*/
-
-/*
- * weechat_ruby_api_get_irc_color:
- * get the numeric value which identify an irc color by its name
- */
-
-/*
-static VALUE
-weechat_ruby_api_get_irc_color (VALUE class, VALUE color)
-{
- char *c_color;
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to get irc color, "
- "script not initialized");
- return INT2FIX (-1);
- }
-
- c_color = NULL;
-
- if (NIL_P (color))
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: wrong parameters for "
- "\"get_irc_color\" function");
- return INT2FIX (-1);
- }
-
- Check_Type (color, T_STRING);
-
- c_color = STR2CSTR (color);
-
- return INT2FIX (ruby_plugin->get_irc_color (ruby_plugin, c_color));
-}
-*/
-
-/*
- * weechat_ruby_api_get_window_info: get infos about windows
- */
-
-/*
-static VALUE
-weechat_ruby_api_get_window_info (VALUE class)
-{
- t_plugin_window_info *window_info, *ptr_win;
- VALUE window_list, window_list_member;
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to get window info, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- window_list = rb_ary_new();
-
- if (NIL_P (window_list))
- return Qnil;
-
- window_info = ruby_plugin->get_window_info (ruby_plugin);
- if (!window_info)
- return window_list;
-
- for (ptr_win = window_info; ptr_win; ptr_win = ptr_win->next_window)
- {
- window_list_member = rb_hash_new ();
-
- if (!NIL_P (window_list_member))
- {
- rb_hash_aset (window_list_member, rb_str_new2("num_buffer"),
- INT2FIX(ptr_win->num_buffer));
- rb_hash_aset (window_list_member, rb_str_new2("win_x"),
- INT2FIX(ptr_win->win_x));
- rb_hash_aset (window_list_member, rb_str_new2("win_y"),
- INT2FIX(ptr_win->win_y));
- rb_hash_aset (window_list_member, rb_str_new2("win_width"),
- INT2FIX(ptr_win->win_width));
- rb_hash_aset (window_list_member, rb_str_new2("win_height"),
- INT2FIX(ptr_win->win_height));
- rb_hash_aset (window_list_member, rb_str_new2("win_width_pct"),
- INT2FIX(ptr_win->win_width_pct));
- rb_hash_aset (window_list_member, rb_str_new2("win_height_pct"),
- INT2FIX(ptr_win->win_height_pct));
-
- rb_ary_push (window_list, window_list_member);
- }
- }
-
- ruby_plugin->free_window_info (ruby_plugin, window_info);
-
- return window_list;
-}
-*/
-
-/*
- * weechat_ruby_api_get_buffer_info: get infos about buffers
- */
-
-/*
-static VALUE
-weechat_ruby_api_get_buffer_info (VALUE class)
-{
- t_plugin_buffer_info *buffer_info, *ptr_buffer;
- VALUE buffer_hash, buffer_hash_member;
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to get buffer info, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- buffer_hash = rb_hash_new ();
- if (!buffer_hash)
- return Qnil;
-
- buffer_info = ruby_plugin->get_buffer_info (ruby_plugin);
- if (!buffer_info)
- return buffer_hash;
-
- for(ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
- {
- buffer_hash_member = rb_hash_new ();
-
- if (buffer_hash_member)
- {
- rb_hash_aset (buffer_hash_member, rb_str_new2("type"),
- INT2FIX(ptr_buffer->type));
- rb_hash_aset (buffer_hash_member, rb_str_new2("num_displayed"),
- INT2FIX(ptr_buffer->num_displayed));
- rb_hash_aset (buffer_hash_member, rb_str_new2("server"),
- rb_str_new2(ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name));
- rb_hash_aset (buffer_hash_member, rb_str_new2("channel"),
- rb_str_new2(ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name));
- rb_hash_aset (buffer_hash_member, rb_str_new2("notify_level"),
- INT2FIX(ptr_buffer->notify_level));
- rb_hash_aset (buffer_hash_member, rb_str_new2("log_filename"),
- rb_str_new2(ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename));
-
- rb_hash_aset (buffer_hash, INT2FIX(ptr_buffer->number), buffer_hash_member);
- }
- }
-
- ruby_plugin->free_buffer_info(ruby_plugin, buffer_info);
-
- return buffer_hash;
-}
-*/
-
-/*
- * weechat_ruby_api_get_buffer_data: get buffer content
- */
-
-/*
-static VALUE
-weechat_ruby_api_get_buffer_data (VALUE class, VALUE server, VALUE channel)
-{
- t_plugin_buffer_line *buffer_data, *ptr_data;
- VALUE data_list, data_list_member;
- char *c_server, *c_channel;
- char timebuffer[64];
-
- // make C compiler happy
- (void) class;
-
- if (!ruby_current_script)
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: unable to get buffer data, "
- "script not initialized");
- return INT2FIX (0);
- }
-
- c_server = NULL;
- c_channel = NULL;
-
- if (NIL_P (server) || NIL_P (channel))
- {
- ruby_plugin->print_server (ruby_plugin,
- "Ruby error: wrong parameters for "
- "\"get_buffer_data\" function");
- return INT2FIX (0);
- }
-
- Check_Type (server, T_STRING);
- Check_Type (channel, T_STRING);
-
- c_server = STR2CSTR (server);
- c_channel = STR2CSTR (channel);
-
- if (!c_server || !c_channel)
- return INT2FIX (0);
-
- data_list = rb_ary_new();
- if (NIL_P (data_list))
- return Qnil;
-
- buffer_data = ruby_plugin->get_buffer_data (ruby_plugin, c_server, c_channel);
- if (!buffer_data)
- return data_list;
-
- for(ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line)
- {
- data_list_member = rb_hash_new ();
-
- if (!NIL_P (data_list_member))
- {
- strftime(timebuffer, sizeof(timebuffer), "%F %T",
- localtime(&ptr_data->date));
-
- rb_hash_aset (data_list_member, rb_str_new2("date"),
- rb_str_new2(timebuffer));
- rb_hash_aset (data_list_member, rb_str_new2("nick"),
- rb_str_new2(ptr_data->nick == NULL ? "" : ptr_data->nick));
- rb_hash_aset (data_list_member, rb_str_new2("data"),
- rb_str_new2(ptr_data->data == NULL ? "" : ptr_data->data));
-
- rb_ary_push (data_list, data_list_member);
- }
- }
-
- ruby_plugin->free_buffer_data (ruby_plugin, buffer_data);
-
- return data_list;
-}
-*/
-
-/*
* weechat_ruby_api_init: init Ruby API: add variables and functions
*/
@@ -3394,6 +3455,22 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "list_remove", &weechat_ruby_api_list_remove, 2);
rb_define_module_function (ruby_mWeechat, "list_remove_all", &weechat_ruby_api_list_remove_all, 1);
rb_define_module_function (ruby_mWeechat, "list_free", &weechat_ruby_api_list_free, 1);
+ rb_define_module_function (ruby_mWeechat, "config_new", &weechat_ruby_api_config_new, 2);
+ rb_define_module_function (ruby_mWeechat, "config_new_section", &weechat_ruby_api_config_new_section, 5);
+ rb_define_module_function (ruby_mWeechat, "config_search_section", &weechat_ruby_api_config_search_section, 2);
+ rb_define_module_function (ruby_mWeechat, "config_new_option", &weechat_ruby_api_config_new_option, 10);
+ rb_define_module_function (ruby_mWeechat, "config_search_option", &weechat_ruby_api_config_search_option, 3);
+ rb_define_module_function (ruby_mWeechat, "config_string_to_boolean", &weechat_ruby_api_config_string_to_boolean, 1);
+ rb_define_module_function (ruby_mWeechat, "config_option_set", &weechat_ruby_api_config_option_set, 3);
+ rb_define_module_function (ruby_mWeechat, "config_boolean", &weechat_ruby_api_config_boolean, 1);
+ rb_define_module_function (ruby_mWeechat, "config_integer", &weechat_ruby_api_config_integer, 1);
+ rb_define_module_function (ruby_mWeechat, "config_string", &weechat_ruby_api_config_string, 1);
+ rb_define_module_function (ruby_mWeechat, "config_color", &weechat_ruby_api_config_color, 1);
+ rb_define_module_function (ruby_mWeechat, "config_write_line", &weechat_ruby_api_config_write_line, 3);
+ rb_define_module_function (ruby_mWeechat, "config_write", &weechat_ruby_api_config_write, 1);
+ rb_define_module_function (ruby_mWeechat, "config_read", &weechat_ruby_api_config_read, 1);
+ rb_define_module_function (ruby_mWeechat, "config_reload", &weechat_ruby_api_config_reload, 1);
+ rb_define_module_function (ruby_mWeechat, "config_free", &weechat_ruby_api_config_free, 1);
rb_define_module_function (ruby_mWeechat, "prefix", &weechat_ruby_api_prefix, 1);
rb_define_module_function (ruby_mWeechat, "color", &weechat_ruby_api_color, 1);
rb_define_module_function (ruby_mWeechat, "print", &weechat_ruby_api_print, 2);
@@ -3426,16 +3503,4 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "nicklist_remove_all", &weechat_ruby_api_nicklist_remove_all, 1);
rb_define_module_function (ruby_mWeechat, "command", &weechat_ruby_api_command, 2);
rb_define_module_function (ruby_mWeechat, "info_get", &weechat_ruby_api_info_get, 1);
- //rb_define_module_function (ruby_mWeechat, "get_dcc_info", &weechat_ruby_api_get_dcc_info, 0);
- //rb_define_module_function (ruby_mWeechat, "get_config", &weechat_ruby_api_get_config, 1);
- //rb_define_module_function (ruby_mWeechat, "set_config", &weechat_ruby_api_set_config, 2);
- //rb_define_module_function (ruby_mWeechat, "get_plugin_config", &weechat_ruby_api_get_plugin_config, 1);
- //rb_define_module_function (ruby_mWeechat, "set_plugin_config", &weechat_ruby_api_set_plugin_config, 2);
- //rb_define_module_function (ruby_mWeechat, "get_server_info", &weechat_ruby_api_get_server_info, 0);
- //rb_define_module_function (ruby_mWeechat, "get_channel_info", &weechat_ruby_api_get_channel_info, 1);
- //rb_define_module_function (ruby_mWeechat, "get_nick_info", &weechat_ruby_api_get_nick_info, 2);
- //rb_define_module_function (ruby_mWeechat, "get_irc_color", &weechat_ruby_api_get_irc_color, 1);
- //rb_define_module_function (ruby_mWeechat, "get_window_info", &weechat_ruby_api_get_window_info, 0);
- //rb_define_module_function (ruby_mWeechat, "get_buffer_info", &weechat_ruby_api_get_buffer_info, 0);
- //rb_define_module_function (ruby_mWeechat, "get_buffer_data", &weechat_ruby_api_get_buffer_data, 2);
}
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c
index bdbd62f7e..c9b90e2ce 100644
--- a/src/plugins/scripts/ruby/weechat-ruby.c
+++ b/src/plugins/scripts/ruby/weechat-ruby.c
@@ -376,8 +376,8 @@ weechat_ruby_load (char *filename)
if (ruby_current_script != NULL)
{
- script_remove (weechat_ruby_plugin,
- &ruby_scripts, ruby_current_script);
+ script_remove (weechat_ruby_plugin, &ruby_scripts,
+ ruby_current_script);
}
return 0;
diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c
index 73a34e7be..db93927d5 100644
--- a/src/plugins/scripts/script-api.c
+++ b/src/plugins/scripts/script-api.c
@@ -44,6 +44,247 @@ script_api_charset_set (struct t_plugin_script *script,
}
/*
+ * script_api_config_new: create a new configuration file
+ * return new configuration file, NULL if error
+ */
+
+struct t_config_file *
+script_api_config_new (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *filename,
+ int (*callback_reload)(void *data,
+ struct t_config_file *config_file),
+ char *function)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_config_file *new_config_file;
+
+ if (function && function[0])
+ {
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return NULL;
+
+ new_config_file = weechat_config_new (filename, callback_reload,
+ new_script_callback);
+ if (!new_config_file)
+ {
+ free (new_script_callback);
+ return NULL;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = strdup (function);
+ new_script_callback->config_file = new_config_file;
+
+ script_callback_add (script, new_script_callback);
+ }
+ else
+ {
+ new_config_file = weechat_config_new (filename, NULL, NULL);
+ }
+
+ return new_config_file;
+}
+
+/*
+ * script_api_config_new_section: create a new section in configuration file
+ * return new section, NULL if error
+ */
+
+struct t_config_section *
+script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_config_file *config_file,
+ char *name,
+ void (*callback_read)(void *data,
+ struct t_config_file *config_file,
+ char *option_name,
+ char *value),
+ char *function_read,
+ void (*callback_write)(void *data,
+ struct t_config_file *config_file,
+ char *section_name),
+ char *function_write,
+ void (*callback_write_default)(void *data,
+ struct t_config_file *config_file,
+ char *section_name),
+ char *function_write_default)
+{
+ struct t_script_callback *new_script_callback1, *new_script_callback2;
+ struct t_script_callback *new_script_callback3;
+ struct t_config_section *new_section;
+ void *callback1, *callback2, *callback3;
+
+ new_script_callback1 = NULL;
+ new_script_callback2 = NULL;
+ new_script_callback3 = NULL;
+ callback1 = NULL;
+ callback2 = NULL;
+ callback3 = NULL;
+
+ if (function_read && function_read[0])
+ {
+ new_script_callback1 = script_callback_alloc ();
+ if (!new_script_callback1)
+ return NULL;
+ callback1 = callback_read;
+ }
+
+ if (function_write && function_write[0])
+ {
+ new_script_callback2 = script_callback_alloc ();
+ if (!new_script_callback2)
+ {
+ if (new_script_callback1)
+ free (new_script_callback1);
+ return NULL;
+ }
+ callback2 = callback_write;
+ }
+
+ if (function_write_default && function_write_default[0])
+ {
+ new_script_callback3 = script_callback_alloc ();
+ if (!new_script_callback3)
+ {
+ if (new_script_callback1)
+ free (new_script_callback1);
+ if (new_script_callback2)
+ free (new_script_callback2);
+ return NULL;
+ }
+ callback3 = callback_write_default;
+ }
+
+ new_section = weechat_config_new_section (config_file,
+ name,
+ callback1,
+ new_script_callback1,
+ callback2,
+ new_script_callback2,
+ callback3,
+ new_script_callback3);
+ if (!new_section)
+ {
+ if (new_script_callback1)
+ free (new_script_callback1);
+ if (new_script_callback2)
+ free (new_script_callback2);
+ if (new_script_callback3)
+ free (new_script_callback3);
+ return NULL;
+ }
+
+ if (new_script_callback1)
+ {
+ new_script_callback1->script = script;
+ new_script_callback1->function = strdup (function_read);
+ new_script_callback1->config_file = config_file;
+ new_script_callback1->config_section = new_section;
+ script_callback_add (script, new_script_callback1);
+ }
+
+ if (new_script_callback2)
+ {
+ new_script_callback2->script = script;
+ new_script_callback2->function = strdup (function_write);
+ new_script_callback2->config_file = config_file;
+ new_script_callback2->config_section = new_section;
+ script_callback_add (script, new_script_callback2);
+ }
+
+ if (new_script_callback3)
+ {
+ new_script_callback3->script = script;
+ new_script_callback3->function = strdup (function_write_default);
+ new_script_callback3->config_file = config_file;
+ new_script_callback3->config_section = new_section;
+ script_callback_add (script, new_script_callback3);
+ }
+
+ return new_section;
+}
+
+/*
+ * script_api_config_new_option: create a new option in section
+ * return new option, NULL if error
+ */
+
+struct t_config_option *
+script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_config_file *config_file,
+ struct t_config_section *section,
+ char *name, char *type,
+ char *description, char *string_values,
+ int min, int max, char *default_value,
+ void (*callback_change)(void *data),
+ char *function)
+{
+ struct t_script_callback *new_script_callback;
+ struct t_config_option *new_option;
+
+ if (function && function[0])
+ {
+ new_script_callback = script_callback_alloc ();
+ if (!new_script_callback)
+ return NULL;
+
+ new_option = weechat_config_new_option (config_file, section, name, type,
+ description, string_values, min,
+ max, default_value,
+ callback_change,
+ new_script_callback);
+ if (!new_option)
+ {
+ free (new_script_callback);
+ return NULL;
+ }
+
+ new_script_callback->script = script;
+ new_script_callback->function = strdup (function);
+ new_script_callback->config_file = config_file;
+ new_script_callback->config_section = section;
+ new_script_callback->config_option = new_option;
+
+ script_callback_add (script, new_script_callback);
+ }
+ else
+ {
+ new_option = weechat_config_new_option (config_file, section, name, type,
+ description, string_values, min,
+ max, default_value, NULL, NULL);
+ }
+
+ return new_option;
+}
+
+/*
+ * script_api_config_free: free configuration file
+ */
+
+void
+script_api_config_free (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_config_file *config_file)
+{
+ struct t_script_callback *ptr_script_callback;
+
+ if (!weechat_plugin || !script || !config_file)
+ return;
+
+ weechat_config_free (config_file);
+
+ for (ptr_script_callback = script->callbacks; ptr_script_callback;
+ ptr_script_callback = ptr_script_callback->next_callback)
+ {
+ if (ptr_script_callback->config_file == config_file)
+ script_callback_remove (script, ptr_script_callback);
+ }
+}
+
+/*
* script_api_printf: print a message
*/
@@ -140,10 +381,6 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin,
if (!new_script_callback)
return NULL;
- new_script_callback->script = NULL;
- new_script_callback->function = NULL;
- new_script_callback->hook = NULL;
-
new_hook = weechat_hook_command (command, description, args,
args_description, completion,
callback, new_script_callback);
@@ -423,10 +660,9 @@ script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
/*
* script_api_unhook: unhook something
- * return 1 if ok, 0 if error
*/
-int
+void
script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook)
@@ -434,22 +670,16 @@ script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_script_callback *ptr_script_callback;
if (!weechat_plugin || !script || !hook)
- return 0;
+ return;
+
+ weechat_unhook (hook);
for (ptr_script_callback = script->callbacks; ptr_script_callback;
ptr_script_callback = ptr_script_callback->next_callback)
{
if (ptr_script_callback->hook == hook)
- break;
+ script_callback_remove (script, ptr_script_callback);
}
-
- if (ptr_script_callback)
- {
- script_callback_remove (weechat_plugin, script, ptr_script_callback);
- return 1;
- }
-
- return 0;
}
/*
@@ -457,8 +687,7 @@ script_api_unhook (struct t_weechat_plugin *weechat_plugin,
*/
void
-script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script)
+script_api_unhook_all (struct t_plugin_script *script)
{
struct t_script_callback *ptr_callback, *next_callback;
@@ -467,7 +696,7 @@ script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
{
next_callback = ptr_callback->next_callback;
- script_callback_remove (weechat_plugin, script, ptr_callback);
+ script_callback_remove (script, ptr_callback);
ptr_callback = next_callback;
}
@@ -539,7 +768,7 @@ script_api_buffer_close (struct t_weechat_plugin *weechat_plugin,
if (ptr_script_callback)
{
- script_callback_remove (weechat_plugin, script, ptr_script_callback);
+ script_callback_remove (script, ptr_script_callback);
}
}
diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h
index f4c3a9a29..4a970d8ba 100644
--- a/src/plugins/scripts/script-api.h
+++ b/src/plugins/scripts/script-api.h
@@ -21,6 +21,44 @@
extern void script_api_charset_set (struct t_plugin_script *script,
char *charset);
+extern struct t_config_file *script_api_config_new (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ char *filename,
+ int (*callback_reload)(void *data,
+ struct t_config_file *config_file),
+ char *function);
+extern struct t_config_section *script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_config_file *config_file,
+ char *name,
+ void (*callback_read)(void *data,
+ struct t_config_file *config_file,
+ char *option_name,
+ char *value),
+ char *function_read,
+ void (*callback_write)(void *data,
+ struct t_config_file *config_file,
+ char *section_name),
+ char *function_write,
+ void (*callback_write_default)(void *data,
+ struct t_config_file *config_file,
+ char *section_name),
+ char *function_write_default);
+extern struct t_config_option *script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_config_file *config_file,
+ struct t_config_section *section,
+ char *name,
+ char *type,
+ char *description,
+ char *string_values,
+ int min, int max,
+ char *default_value,
+ void (*callback_change)(void *data),
+ char *function);
+extern void script_api_config_free (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_config_file *config_file);
extern void script_api_printf (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
@@ -95,11 +133,10 @@ extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat
char *modifier_data,
char *string),
char *function);
-extern int script_api_unhook (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
- struct t_hook *hook);
-extern void script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script);
+extern void script_api_unhook (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_hook *hook);
+extern void script_api_unhook_all (struct t_plugin_script *script);
struct t_gui_buffer *script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *category, char *name,
diff --git a/src/plugins/scripts/script-callback.c b/src/plugins/scripts/script-callback.c
index 3c44c1ccf..18b7039b7 100644
--- a/src/plugins/scripts/script-callback.c
+++ b/src/plugins/scripts/script-callback.c
@@ -41,6 +41,9 @@ script_callback_alloc ()
{
new_script_callback->script = NULL;
new_script_callback->function = NULL;
+ new_script_callback->config_file = NULL;
+ new_script_callback->config_section = NULL;
+ new_script_callback->config_option = NULL;
new_script_callback->hook = NULL;
new_script_callback->buffer = NULL;
return new_script_callback;
@@ -69,8 +72,7 @@ script_callback_add (struct t_plugin_script *script,
*/
void
-script_callback_remove (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
+script_callback_remove (struct t_plugin_script *script,
struct t_script_callback *script_callback)
{
/* remove callback from list */
@@ -86,8 +88,6 @@ script_callback_remove (struct t_weechat_plugin *weechat_plugin,
/* unhook and free data */
if (script_callback->function)
free (script_callback->function);
- if (script_callback->hook)
- weechat_unhook (script_callback->hook);
free (script_callback);
}
@@ -97,12 +97,11 @@ script_callback_remove (struct t_weechat_plugin *weechat_plugin,
*/
void
-script_callback_remove_all (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script)
+script_callback_remove_all (struct t_plugin_script *script)
{
while (script->callbacks)
{
- script_callback_remove (weechat_plugin, script, script->callbacks);
+ script_callback_remove (script, script->callbacks);
}
}
diff --git a/src/plugins/scripts/script-callback.h b/src/plugins/scripts/script-callback.h
index bad00325f..0ca67806b 100644
--- a/src/plugins/scripts/script-callback.h
+++ b/src/plugins/scripts/script-callback.h
@@ -21,10 +21,13 @@
struct t_script_callback
{
- void *script; /* pointer to script */
- char *function; /* script function called */
- struct t_hook *hook; /* not NULL if hook */
- struct t_gui_buffer *buffer; /* not NULL if buffer callback */
+ void *script; /* pointer to script */
+ char *function; /* script function called */
+ struct t_config_file *config_file; /* not NULL for config file */
+ struct t_config_section *config_section; /* not NULL for config section */
+ struct t_config_option *config_option; /* not NULL for config option */
+ struct t_hook *hook; /* not NULL for hook */
+ struct t_gui_buffer *buffer; /* not NULL for buffer callback*/
struct t_script_callback *prev_callback; /* link to next callback */
struct t_script_callback *next_callback; /* link to previous callback */
};
@@ -32,11 +35,9 @@ struct t_script_callback
extern struct t_script_callback *script_callback_alloc ();
extern void script_callback_add (struct t_plugin_script *script,
struct t_script_callback *callback);
-extern void script_callback_remove (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script,
+extern void script_callback_remove (struct t_plugin_script *script,
struct t_script_callback *script_callback);
-extern void script_callback_remove_all (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script *script);
+extern void script_callback_remove_all (struct t_plugin_script *script);
extern void script_callback_print_log (struct t_weechat_plugin *weechat_plugin,
struct t_script_callback *script_callback);
diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c
index b264b2aea..1cf7e4f09 100644
--- a/src/plugins/scripts/script.c
+++ b/src/plugins/scripts/script.c
@@ -411,8 +411,27 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script **scripts,
struct t_plugin_script *script)
{
+ struct t_script_callback *ptr_script_callback;
+
+ for (ptr_script_callback = script->callbacks; ptr_script_callback;
+ ptr_script_callback = ptr_script_callback->next_callback)
+ {
+ if (ptr_script_callback->hook)
+ {
+ weechat_unhook (ptr_script_callback->hook);
+ }
+ if (ptr_script_callback->config_file
+ && !ptr_script_callback->config_section
+ && !ptr_script_callback->config_option)
+ {
+ if (weechat_config_boolean (weechat_config_get_weechat ("plugins_save_config_on_unload")))
+ weechat_config_write (ptr_script_callback->config_file);
+ weechat_config_free (ptr_script_callback->config_file);
+ }
+ }
+
/* remove all callbacks created by this script */
- script_callback_remove_all (weechat_plugin, script);
+ script_callback_remove_all (script);
/* free data */
if (script->filename)