diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-01-27 10:48:29 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-01-27 10:48:29 +0100 |
commit | ad414865430d2d073689f849283a10b06711f1b8 (patch) | |
tree | 46c12eff476081782dc6322068bc7630ba4e94a9 /src | |
parent | ed26a0389c06250f02329fa477d2cffe7df59b5e (diff) | |
download | weechat-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')
23 files changed, 4414 insertions, 4036 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 98bf6697f..1f8bbe1a1 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -1153,6 +1153,30 @@ command_quit (void *data, struct t_gui_buffer *buffer, } /* + * command_reload_file: reload a configuration file + */ + +void +command_reload_file (struct t_config_file *config_file) +{ + if ((int) (config_file->callback_reload) (config_file->callback_reload_data, + config_file) == 0) + { + gui_chat_printf (NULL, + _("%sOptions reloaded from %s"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + config_file->filename); + } + else + { + gui_chat_printf (NULL, + _("%sError: failed to reload options from %s"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + config_file->filename); + } +} + +/* * command_reload: reload WeeChat and plugins options from disk */ @@ -1161,31 +1185,39 @@ command_reload (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_config_file *ptr_config_file; + int i; /* make C compiler happy */ (void) data; (void) buffer; - (void) argc; - (void) argv; (void) argv_eol; - for (ptr_config_file = config_files; ptr_config_file; - ptr_config_file = ptr_config_file->next_config) + if (argc > 1) { - if (ptr_config_file->callback_reload) + for (i = 1; i < argc; i++) { - if ((int) (ptr_config_file->callback_reload) (ptr_config_file) == 0) + ptr_config_file = config_file_search (argv[i]); + if (ptr_config_file) { - gui_chat_printf (NULL, _("%sOptions reloaded from %s"), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - ptr_config_file->filename); + command_reload_file (ptr_config_file); } else { gui_chat_printf (NULL, - _("%sError: failed to reload options from %s"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - ptr_config_file->filename); + _("%sUnknown configuration file \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + argv[i]); + } + } + } + else + { + for (ptr_config_file = config_files; ptr_config_file; + ptr_config_file = ptr_config_file->next_config) + { + if (ptr_config_file->callback_reload) + { + command_reload_file (ptr_config_file); } } } @@ -1194,6 +1226,29 @@ command_reload (void *data, struct t_gui_buffer *buffer, } /* + * command_save_file: save a configuration file + */ + +void +command_save_file (struct t_config_file *config_file) +{ + if (config_file_write (config_file) == 0) + { + gui_chat_printf (NULL, + _("%sOptions saved to %s"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + config_file->filename); + } + else + { + gui_chat_printf (NULL, + _("%sError: failed to save options to %s"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + config_file->filename); + } +} + +/* * command_save: save WeeChat and plugins options to disk */ @@ -1202,29 +1257,37 @@ command_save (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_config_file *ptr_config_file; + int i; /* make C compiler happy */ (void) data; (void) buffer; - (void) argc; - (void) argv; (void) argv_eol; - - for (ptr_config_file = config_files; ptr_config_file; - ptr_config_file = ptr_config_file->next_config) + + if (argc > 1) { - if (config_file_write (ptr_config_file) == 0) + for (i = 1; i < argc; i++) { - gui_chat_printf (NULL, _("%sOptions saved to %s"), - gui_chat_prefix[GUI_CHAT_PREFIX_INFO], - ptr_config_file->filename); + ptr_config_file = config_file_search (argv[i]); + if (ptr_config_file) + { + command_save_file (ptr_config_file); + } + else + { + gui_chat_printf (NULL, + _("%sUnknown configuration file \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + argv[i]); + } } - else + } + else + { + for (ptr_config_file = config_files; ptr_config_file; + ptr_config_file = ptr_config_file->next_config) { - gui_chat_printf (NULL, - _("%sError: failed to save options to %s"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - ptr_config_file->filename); + command_save_file (ptr_config_file); } } @@ -1433,7 +1496,10 @@ command_set (void *data, struct t_gui_buffer *buffer, gui_chat_prefix[GUI_CHAT_PREFIX_INFO], _("Option changed: ")); if ((rc == 2) && (ptr_option->callback_change)) - (void) (ptr_option->callback_change) (); + { + (void) (ptr_option->callback_change) + (ptr_option->callback_change_data); + } } else { @@ -1998,15 +2064,20 @@ command_init () "%q", command_quit, NULL); hook_command (NULL, "reload", - N_("reload WeeChat and plugins configuration files from " - "disk"), - "", "", - NULL, + N_("reload configuration files from disk"), + N_("[file [file...]]"), + N_("file: configuration file to reload\n\n" + "Without argument, all files (WeeChat and plugins) are " + "reloaded."), + "%C|%*", command_reload, NULL); hook_command (NULL, "save", - N_("save WeeChat and plugins configuration files to disk"), - "", "", - NULL, + N_("save configuration files to disk"), + N_("[file [file...]]"), + N_("file: configuration file to save\n\n" + "Without argument, all files (WeeChat and plugins) are " + "saved."), + "%C|%*", command_save, NULL); hook_command (NULL, "set", N_("set config options"), diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 7cc16fe4b..82f94c04c 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -52,7 +52,10 @@ struct t_config_file * config_file_search (char *filename) { struct t_config_file *ptr_config; - + + if (!filename) + return NULL; + for (ptr_config = config_files; ptr_config; ptr_config = ptr_config->next_config) { @@ -70,7 +73,9 @@ config_file_search (char *filename) struct t_config_file * config_file_new (struct t_weechat_plugin *plugin, char *filename, - int (*callback_reload)(struct t_config_file *config_file)) + int (*callback_reload)(void *data, + struct t_config_file *config_file), + void *callback_reload_data) { struct t_config_file *new_config_file; @@ -88,6 +93,7 @@ config_file_new (struct t_weechat_plugin *plugin, char *filename, new_config_file->filename = strdup (filename); new_config_file->file = NULL; new_config_file->callback_reload = callback_reload; + new_config_file->callback_reload_data = callback_reload_data; new_config_file->sections = NULL; new_config_file->last_section = NULL; @@ -133,12 +139,18 @@ config_file_valid_for_plugin (struct t_weechat_plugin *plugin, struct t_config_section * config_file_new_section (struct t_config_file *config_file, char *name, - void (*callback_read)(struct t_config_file *config_file, + void (*callback_read)(void *data, + struct t_config_file *config_file, char *option_name, char *value), - void (*callback_write)(struct t_config_file *config_file, + void *callback_read_data, + void (*callback_write)(void *data, + struct t_config_file *config_file, char *section_name), - void (*callback_write_default)(struct t_config_file *, - char *section_name)) + void *callback_write_data, + void (*callback_write_default)(void *data, + struct t_config_file *config_file, + char *section_name), + void *callback_write_default_data) { struct t_config_section *new_section; @@ -150,8 +162,11 @@ config_file_new_section (struct t_config_file *config_file, char *name, { new_section->name = strdup (name); new_section->callback_read = callback_read; + new_section->callback_read_data = callback_read_data; new_section->callback_write = callback_write; + new_section->callback_write_data = callback_write_data; new_section->callback_write_default = callback_write_default; + new_section->callback_write_default_data = callback_write_default_data; new_section->options = NULL; new_section->last_option = NULL; @@ -177,6 +192,9 @@ config_file_search_section (struct t_config_file *config_file, { struct t_config_section *ptr_section; + if (!config_file || !section_name) + return NULL; + for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) { @@ -224,17 +242,19 @@ config_file_section_valid_for_plugin (struct t_weechat_plugin *plugin, */ struct t_config_option * -config_file_new_option (struct t_config_section *section, char *name, +config_file_new_option (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 (*callback_change)(), + void *callback_change_data) { struct t_config_option *new_option; int var_type, int_value, argc, i, index_value; long number; char *error; - if (!section || !name) + if (!config_file || !section || !name) return NULL; var_type = -1; @@ -332,6 +352,7 @@ config_file_new_option (struct t_config_section *section, char *name, break; } new_option->callback_change = callback_change; + new_option->callback_change_data = callback_change_data; new_option->loaded = 0; new_option->prev_option = section->last_option; @@ -430,6 +451,9 @@ config_file_string_boolean_is_valid (char *text) { int i; + if (!text) + return 0; + for (i = 0; config_boolean_true[i]; i++) { if (string_strcasecmp (text, config_boolean_true[i]) == 0) @@ -456,6 +480,9 @@ config_file_string_to_boolean (char *text) { int i; + if (!text) + return CONFIG_BOOLEAN_FALSE; + for (i = 0; config_boolean_true[i]; i++) { if (string_strcasecmp (text, config_boolean_true[i]) == 0) @@ -495,7 +522,10 @@ config_file_option_set (struct t_config_option *option, char *new_value, return 1; *((int *)option->value) = new_value_int; if (run_callback && option->callback_change) - (void) (option->callback_change) (); + { + (void) (option->callback_change) + (option->callback_change_data); + } return 2; case CONFIG_OPTION_INTEGER: if (!new_value) @@ -518,7 +548,10 @@ config_file_option_set (struct t_config_option *option, char *new_value, return 1; *((int *)option->value) = new_value_int; if (run_callback && option->callback_change) - (void) (option->callback_change) (); + { + (void) (option->callback_change) + (option->callback_change_data); + } return 2; } else @@ -531,7 +564,10 @@ config_file_option_set (struct t_config_option *option, char *new_value, return 1; *((int *)option->value) = number; if (run_callback && option->callback_change) - (void) (option->callback_change) (); + { + (void) (option->callback_change) + (option->callback_change_data); + } return 2; } } @@ -553,7 +589,10 @@ config_file_option_set (struct t_config_option *option, char *new_value, else option->value = NULL; if (run_callback && (rc == 2) && option->callback_change) - (void) (option->callback_change) (); + { + (void) (option->callback_change) + (option->callback_change_data); + } return rc; case CONFIG_OPTION_COLOR: if (!gui_color_assign (&new_value_int, new_value)) @@ -562,7 +601,10 @@ config_file_option_set (struct t_config_option *option, char *new_value, return 1; *((int *)option->value) = new_value_int; if (run_callback && option->callback_change) - (void) (option->callback_change) (); + { + (void) (option->callback_change) + (option->callback_change_data); + } return 2; } @@ -631,6 +673,9 @@ config_file_option_reset (struct t_config_option *option) int config_file_option_boolean (struct t_config_option *option) { + if (!option) + return 0; + if (option->type == CONFIG_OPTION_BOOLEAN) return CONFIG_BOOLEAN(option); else @@ -644,6 +689,9 @@ config_file_option_boolean (struct t_config_option *option) int config_file_option_integer (struct t_config_option *option) { + if (!option) + return 0; + switch (option->type) { case CONFIG_OPTION_BOOLEAN: @@ -667,6 +715,9 @@ config_file_option_integer (struct t_config_option *option) char * config_file_option_string (struct t_config_option *option) { + if (!option) + return NULL; + switch (option->type) { case CONFIG_OPTION_STRING: @@ -688,6 +739,9 @@ config_file_option_string (struct t_config_option *option) int config_file_option_color (struct t_config_option *option) { + if (!option) + return 0; + if (option->type == CONFIG_OPTION_COLOR) return CONFIG_COLOR(option); else @@ -752,7 +806,10 @@ config_file_write_line (struct t_config_file *config_file, { char buf[4096]; va_list argptr; - + + if (!config_file || !option_name) + return; + va_start (argptr, value); vsnprintf (buf, sizeof (buf) - 1, value, argptr); va_end (argptr); @@ -776,7 +833,8 @@ config_file_write_line (struct t_config_file *config_file, */ int -config_file_write_internal (struct t_config_file *config_file, int default_options) +config_file_write_internal (struct t_config_file *config_file, + int default_options) { int filename_length, rc; char *filename, *filename2; @@ -828,12 +886,14 @@ config_file_write_internal (struct t_config_file *config_file, int default_optio /* call write callback if defined for section */ if (default_options && ptr_section->callback_write_default) { - (void) (ptr_section->callback_write_default) (config_file, + (void) (ptr_section->callback_write_default) (ptr_section->callback_write_default_data, + config_file, ptr_section->name); } else if (!default_options && ptr_section->callback_write) { - (void) (ptr_section->callback_write) (config_file, + (void) (ptr_section->callback_write) (ptr_section->callback_write_data, + config_file, ptr_section->name); } else @@ -959,7 +1019,8 @@ config_file_read (struct t_config_file *config_file) { if (ptr_section->callback_read) { - (void) (ptr_section->callback_read) (config_file, + (void) (ptr_section->callback_read) (ptr_section->callback_read_data, + config_file, NULL, NULL); } } @@ -1036,7 +1097,8 @@ config_file_read (struct t_config_file *config_file) if (ptr_section && ptr_section->callback_read) { ptr_option = NULL; - (void) (ptr_section->callback_read) (config_file, + (void) (ptr_section->callback_read) (ptr_section->callback_read_data, + config_file, line, pos); rc = 1; } @@ -1109,7 +1171,10 @@ config_file_reload (struct t_config_file *config_file) struct t_config_section *ptr_section; struct t_config_option *ptr_option; int rc; - + + if (!config_file) + return -1; + /* init "loaded" flag for all options */ for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) @@ -1141,7 +1206,10 @@ config_file_reload (struct t_config_file *config_file) if (config_file_option_reset (ptr_option) == 2) { if (ptr_option->callback_change) - (void) (ptr_option->callback_change) (); + { + (void) (ptr_option->callback_change) + (ptr_option->callback_change_data); + } } } } @@ -1161,6 +1229,9 @@ config_file_option_free (struct t_config_section *section, { struct t_config_option *new_options; + if (!section || !option) + return; + /* remove option */ if (section->last_option == option) section->last_option = option->prev_option; @@ -1200,6 +1271,9 @@ config_file_section_free (struct t_config_file *config_file, { struct t_config_section *new_sections; + if (!config_file || !section) + return; + /* remove section */ if (config_file->last_section == section) config_file->last_section = section->prev_section; @@ -1234,6 +1308,9 @@ config_file_free (struct t_config_file *config_file) { struct t_config_file *new_config_files; + if (!config_file) + return; + /* remove config file */ if (last_config_file == config_file) last_config_file = config_file->prev_config; diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h index 87e4743f2..df21e2909 100644 --- a/src/core/wee-config-file.h +++ b/src/core/wee-config-file.h @@ -41,7 +41,9 @@ struct t_config_file char *filename; /* config filename (without path)*/ FILE *file; /* file pointer */ int (*callback_reload) /* callback for reloading file */ - (struct t_config_file *config_file); + (void *data, + struct t_config_file *config_file); + void *callback_reload_data; /* data sent to callback */ struct t_config_section *sections; /* config sections */ struct t_config_section *last_section; /* last config section */ struct t_config_file *prev_config; /* link to previous config file */ @@ -52,14 +54,20 @@ struct t_config_section { char *name; /* section name */ void (*callback_read) /* called when unknown option */ - (struct t_config_file *config_file, /* is read from config file */ - char *option_name, char *value); + (void *data, /* is read from config file */ + struct t_config_file *config_file, + char *option_name, char *value); + void *callback_read_data; /* data sent to read callback */ void (*callback_write) /* called to write special */ - (struct t_config_file *config_file, /* options in config file */ + (void *data, /* options in config file */ + struct t_config_file *config_file, char *section_name); + void *callback_write_data; /* data sent to write callback */ void (*callback_write_default) /* called to write default */ - (struct t_config_file *config_file, /* options in config file */ + (void *data, /* options in config file */ + struct t_config_file *config_file, char *section_name); + void *callback_write_default_data; /* data sent to write def. callb.*/ struct t_config_option *options; /* options in section */ struct t_config_option *last_option; /* last option in section */ struct t_config_section *prev_section; /* link to previous section */ @@ -83,7 +91,8 @@ struct t_config_option int min, max; /* min and max for value */ void *default_value; /* default value */ void *value; /* value */ - void (*callback_change)(); /* called when value is changed */ + void (*callback_change)(void *data); /* called when value is changed */ + void *callback_change_data; /* data sent to change callback */ int loaded; /* 1 if opt was found in config */ struct t_config_option *prev_option; /* link to previous option */ struct t_config_option *next_option; /* link to next option */ @@ -92,31 +101,42 @@ struct t_config_option extern struct t_config_file *config_files; extern struct t_config_file *last_config_file; +extern struct t_config_file *config_file_search (char *filename); extern struct t_config_file *config_file_new (struct t_weechat_plugin *plugin, char *filename, - int (*callback_reload)(struct t_config_file *config_file)); + int (*callback_reload)(void *data, + struct t_config_file *config_file), + void *callback_data); extern int config_file_valid_for_plugin (struct t_weechat_plugin *plugin, struct t_config_file *config_file); extern struct t_config_section *config_file_new_section (struct t_config_file *config_file, char *name, - void (*callback_read)(struct t_config_file *config_file, + void (*callback_read)(void *data, + struct t_config_file *config_file, char *option_name, char *value), - void (*callback_write)(struct t_config_file *config_file, + void *callback_read_data, + void (*callback_write)(void *data, + struct t_config_file *config_file, char *section_name), - void (*callback_write_default)(struct t_config_file *config_file, - char *section_name)); + void *callback_write_data, + void (*callback_write_default)(void *data, + struct t_config_file *config_file, + char *section_name), + void *callback_write_default_data); extern struct t_config_section *config_file_search_section (struct t_config_file *config_file, char *section_name); extern int config_file_section_valid_for_plugin (struct t_weechat_plugin *plugin, struct t_config_section *); -extern struct t_config_option *config_file_new_option (struct t_config_section *section, +extern struct t_config_option *config_file_new_option (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 (*callback_change)(void *data), + void *callback_change_data); extern struct t_config_option *config_file_search_option (struct t_config_file *config_file, struct t_config_section *section, char *option_name); diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 9058774b6..a486f9701 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -184,6 +184,7 @@ struct t_config_option *config_proxy_password; struct t_config_option *config_plugins_path; struct t_config_option *config_plugins_autoload; struct t_config_option *config_plugins_extension; +struct t_config_option *config_plugins_save_config_on_unload; /* hooks */ @@ -422,9 +423,10 @@ config_change_day_change () */ int -config_weechat_reload (struct t_config_file *config_file) +config_weechat_reload (void *data, struct t_config_file *config_file) { /* make C compiler happy */ + (void) data; (void) config_file; /* remove all keys */ @@ -438,10 +440,11 @@ config_weechat_reload (struct t_config_file *config_file) */ void -config_weechat_read_key (struct t_config_file *config_file, +config_weechat_read_key (void *data, struct t_config_file *config_file, char *option_name, char *value) { /* make C compiler happy */ + (void) data; (void) config_file; if (option_name) @@ -466,12 +469,15 @@ config_weechat_read_key (struct t_config_file *config_file, */ void -config_weechat_write_keys (struct t_config_file *config_file, +config_weechat_write_keys (void *data, struct t_config_file *config_file, char *section_name) { t_gui_key *ptr_key; char *expanded_name, *function_name; + /* make C compiler happy */ + (void) data; + config_file_write_line (config_file, section_name, NULL); for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key) @@ -515,13 +521,13 @@ config_weechat_init () struct t_config_section *ptr_section; weechat_config_file = config_file_new (NULL, WEECHAT_CONFIG_FILENAME, - &config_weechat_reload); + &config_weechat_reload, NULL); if (!weechat_config_file) return 0; /* look */ ptr_section = config_file_new_section (weechat_config_file, "look", - NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -529,200 +535,242 @@ config_weechat_init () } config_look_color_real_white = config_file_new_option ( - ptr_section, "look_color_real_white", "boolean", + weechat_config_file, ptr_section, + "look_color_real_white", "boolean", N_("if set, uses real white color, disabled by default " "for terms with white background (if you never use " "white background, you should turn on this option to " "see real white instead of default term foreground " "color)"), - NULL, 0, 0, "off", &config_change_color); + NULL, 0, 0, "off", &config_change_color, NULL); config_look_save_on_exit = config_file_new_option ( - ptr_section, "look_save_on_exit", "boolean", + weechat_config_file, ptr_section, + "look_save_on_exit", "boolean", N_("save configuration file on exit"), - NULL, 0, 0, "on", &config_change_save_on_exit); + NULL, 0, 0, "on", &config_change_save_on_exit, NULL); config_look_set_title = config_file_new_option ( - ptr_section, "look_set_title", "boolean", + weechat_config_file, ptr_section, + "look_set_title", "boolean", N_("set title for window (terminal for Curses GUI) with " "name and version"), - NULL, 0, 0, "on", &config_change_title); + NULL, 0, 0, "on", &config_change_title, NULL); config_look_startup_logo = config_file_new_option ( - ptr_section, "look_startup_logo", "boolean", + weechat_config_file, ptr_section, + "look_startup_logo", "boolean", N_("display WeeChat logo at startup"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); config_look_startup_version = config_file_new_option ( - ptr_section, "look_startup_version", "boolean", + weechat_config_file, ptr_section, + "look_startup_version", "boolean", N_("display WeeChat version at startup"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); config_look_weechat_slogan = config_file_new_option ( - ptr_section, "look_weechat_slogan", "string", + weechat_config_file, ptr_section, + "look_weechat_slogan", "string", N_("WeeChat slogan (if empty, slogan is not used)"), - NULL, 0, 0, "the geekest IRC client!", NULL); + NULL, 0, 0, "the geekest IRC client!", NULL, NULL); config_look_scroll_amount = config_file_new_option ( - ptr_section, "look_scroll_amount", "integer", + weechat_config_file, ptr_section, + "look_scroll_amount", "integer", N_("how many lines to scroll by with scroll_up and " "scroll_down"), - NULL, 1, INT_MAX, "3", &config_change_buffer_content); + NULL, 1, INT_MAX, "3", &config_change_buffer_content, NULL); config_look_buffer_time_format = config_file_new_option ( - ptr_section, "look_buffer_time_format", "string", + weechat_config_file, ptr_section, + "look_buffer_time_format", "string", N_("time format for buffers"), - NULL, 0, 0, "[%H:%M:%S]", &config_change_buffer_time_format); + NULL, 0, 0, "[%H:%M:%S]", &config_change_buffer_time_format, NULL); config_look_color_nicks_number = config_file_new_option ( - ptr_section, "look_color_nicks_number", "integer", + weechat_config_file, ptr_section, + "look_color_nicks_number", "integer", N_("number of colors to use for nicks colors"), - NULL, 1, 10, "10", &config_change_nicks_colors); + NULL, 1, 10, "10", &config_change_nicks_colors, NULL); config_look_nicklist = config_file_new_option ( - ptr_section, "look_nicklist", "boolean", + weechat_config_file, ptr_section, + "look_nicklist", "boolean", N_("display nicklist (on buffers with nicklist enabled)"), - NULL, 0, 0, "on", &config_change_buffers); + NULL, 0, 0, "on", &config_change_buffers, NULL); config_look_nicklist_position = config_file_new_option ( - ptr_section, "look_nicklist_position", "integer", + weechat_config_file, ptr_section, + "look_nicklist_position", "integer", N_("nicklist position (top, left, right (default), " "bottom)"), - "left|right|top|bottom", 0, 0, "right", &config_change_buffers); + "left|right|top|bottom", 0, 0, "right", &config_change_buffers, NULL); config_look_nicklist_min_size = config_file_new_option ( - ptr_section, "look_nicklist_min_size", "integer", + weechat_config_file, ptr_section, + "look_nicklist_min_size", "integer", N_("min size for nicklist (width or height, depending on " "look_nicklist_position (0 = no min size))"), - NULL, 0, 100, "0", &config_change_buffers); + NULL, 0, 100, "0", &config_change_buffers, NULL); config_look_nicklist_max_size = config_file_new_option ( - ptr_section, "look_nicklist_max_size", "integer", + weechat_config_file, ptr_section, + "look_nicklist_max_size", "integer", N_("max size for nicklist (width or height, depending on " "look_nicklist_position (0 = no max size; if min = max " "and > 0, then size is fixed))"), - NULL, 0, 100, "0", &config_change_buffers); + NULL, 0, 100, "0", &config_change_buffers, NULL); config_look_nicklist_separator = config_file_new_option ( - ptr_section, "look_nicklist_separator", "boolean", + weechat_config_file, ptr_section, + "look_nicklist_separator", "boolean", N_("separator between chat and nicklist"), - NULL, 0, 0, "on", &config_change_buffers); + NULL, 0, 0, "on", &config_change_buffers, NULL); config_look_nickmode = config_file_new_option ( - ptr_section, "look_nickmode", "boolean", + weechat_config_file, ptr_section, + "look_nickmode", "boolean", N_("display nick mode ((half)op/voice) before each nick"), - NULL, 0, 0, "on", &config_change_buffers); + NULL, 0, 0, "on", &config_change_buffers, NULL); config_look_nickmode_empty = config_file_new_option ( - ptr_section, "look_nickmode_empty", "boolean", + weechat_config_file, ptr_section, + "look_nickmode_empty", "boolean", N_("display space if nick mode is not (half)op/voice"), - NULL, 0, 0, "off", &config_change_buffers); + NULL, 0, 0, "off", &config_change_buffers, NULL); config_look_prefix[GUI_CHAT_PREFIX_INFO] = config_file_new_option ( - ptr_section, "look_prefix_info", "string", + weechat_config_file, ptr_section, + "look_prefix_info", "string", N_("prefix for info messages"), - NULL, 0, 0, "-=-", &config_change_prefix); + NULL, 0, 0, "-=-", &config_change_prefix, NULL); config_look_prefix[GUI_CHAT_PREFIX_ERROR] = config_file_new_option ( - ptr_section, "look_prefix_error", "string", + weechat_config_file, ptr_section, + "look_prefix_error", "string", N_("prefix for error messages"), - NULL, 0, 0, "=!=", &config_change_prefix); + NULL, 0, 0, "=!=", &config_change_prefix, NULL); config_look_prefix[GUI_CHAT_PREFIX_NETWORK] = config_file_new_option ( - ptr_section, "look_prefix_network", "string", + weechat_config_file, ptr_section, + "look_prefix_network", "string", N_("prefix for network messages"), - NULL, 0, 0, "-@-", &config_change_prefix); + NULL, 0, 0, "-@-", &config_change_prefix, NULL); config_look_prefix[GUI_CHAT_PREFIX_ACTION] = config_file_new_option ( - ptr_section, "look_prefix_action", "string", + weechat_config_file, ptr_section, + "look_prefix_action", "string", N_("prefix for action messages"), - NULL, 0, 0, "-*-", &config_change_prefix); + NULL, 0, 0, "-*-", &config_change_prefix, NULL); config_look_prefix[GUI_CHAT_PREFIX_JOIN] = config_file_new_option ( - ptr_section, "look_prefix_join", "string", + weechat_config_file, ptr_section, + "look_prefix_join", "string", N_("prefix for join messages"), - NULL, 0, 0, "-->", &config_change_prefix); + NULL, 0, 0, "-->", &config_change_prefix, NULL); config_look_prefix[GUI_CHAT_PREFIX_QUIT] = config_file_new_option ( - ptr_section, "look_prefix_quit", "string", + weechat_config_file, ptr_section, + "look_prefix_quit", "string", N_("prefix for quit messages"), - NULL, 0, 0, "<--", &config_change_prefix); + NULL, 0, 0, "<--", &config_change_prefix, NULL); config_look_prefix_align = config_file_new_option ( - ptr_section, "look_prefix_align", "integer", + weechat_config_file, ptr_section, + "look_prefix_align", "integer", N_("prefix alignment (none, left, right (default))"), - "none|left|right", 0, 0, "right", &config_change_buffers); + "none|left|right", 0, 0, "right", &config_change_buffers, NULL); config_look_prefix_align_max = config_file_new_option ( - ptr_section, "look_prefix_align_max", "integer", + weechat_config_file, ptr_section, + "look_prefix_align_max", "integer", N_("max size for prefix (0 = no max size)"), - NULL, 0, 64, "0", &config_change_buffers); + NULL, 0, 64, "0", &config_change_buffers, NULL); config_look_prefix_suffix = config_file_new_option ( - ptr_section, "look_prefix_suffix", "string", + weechat_config_file, ptr_section, + "look_prefix_suffix", "string", N_("string displayed after prefix"), - NULL, 0, 0, "|", &config_change_buffers); + NULL, 0, 0, "|", &config_change_buffers, NULL); config_look_nick_completor = config_file_new_option ( - ptr_section, "look_nick_completor", "string", + weechat_config_file, ptr_section, + "look_nick_completor", "string", N_("string inserted after nick completion"), - NULL, 0, 0, ":", NULL); + NULL, 0, 0, ":", NULL, NULL); config_look_nick_completion_ignore = config_file_new_option ( - ptr_section, "look_nick_completion_ignore", "string", + weechat_config_file, ptr_section, + "look_nick_completion_ignore", "string", N_("chars ignored for nick completion"), - NULL, 0, 0, "[]-^", NULL); + NULL, 0, 0, "[]-^", NULL, NULL); config_look_nick_complete_first = config_file_new_option ( - ptr_section, "look_nick_complete_first", "boolean", + weechat_config_file, ptr_section, + "look_nick_complete_first", "boolean", N_("complete only with first nick found"), - NULL, 0, 0, "off", NULL); + NULL, 0, 0, "off", NULL, NULL); config_look_infobar = config_file_new_option ( - ptr_section, "look_infobar", "boolean", + weechat_config_file, ptr_section, + "look_infobar", "boolean", N_("enable info bar"), - NULL, 0, 0, "on", &config_change_buffers); + NULL, 0, 0, "on", &config_change_buffers, NULL); config_look_infobar_time_format = config_file_new_option ( - ptr_section, "look_infobar_time_format", "string", + weechat_config_file, ptr_section, + "look_infobar_time_format", "string", N_("time format for time in infobar"), - NULL, 0, 0, "%B, %A %d %Y", &config_change_buffer_content); + NULL, 0, 0, "%B, %A %d %Y", &config_change_buffer_content, NULL); config_look_infobar_seconds = config_file_new_option ( - ptr_section, "look_infobar_seconds", "boolean", + weechat_config_file, ptr_section, + "look_infobar_seconds", "boolean", N_("display seconds in infobar time"), - NULL, 0, 0, "on", &config_change_infobar_seconds); + NULL, 0, 0, "on", &config_change_infobar_seconds, NULL); config_look_infobar_delay_highlight = config_file_new_option ( - ptr_section, "look_infobar_delay_highlight", "integer", + weechat_config_file, ptr_section, + "look_infobar_delay_highlight", "integer", N_("delay (in seconds) for highlight messages in " "infobar (0 = disable highlight notifications in " "infobar)"), - NULL, 0, INT_MAX, "7", NULL); + NULL, 0, INT_MAX, "7", NULL, NULL); config_look_hotlist_names_count = config_file_new_option ( - ptr_section, "look_hotlist_names_count", "integer", + weechat_config_file, ptr_section, + "look_hotlist_names_count", "integer", N_("max number of names in hotlist (0 = no name " "displayed, only buffer numbers)"), - NULL, 0, 32, "3", &config_change_buffer_content); + NULL, 0, 32, "3", &config_change_buffer_content, NULL); config_look_hotlist_names_level = config_file_new_option ( - ptr_section, "look_hotlist_names_level", "integer", + weechat_config_file, ptr_section, + "look_hotlist_names_level", "integer", N_("level for displaying names in hotlist (combination " "of: 1=join/part, 2=message, 4=private, 8=highlight, " "for example: 12=private+highlight)"), - NULL, 1, 15, "12", &config_change_buffer_content); + NULL, 1, 15, "12", &config_change_buffer_content, NULL); config_look_hotlist_names_length = config_file_new_option ( - ptr_section, "look_hotlist_names_length", "integer", + weechat_config_file, ptr_section, + "look_hotlist_names_length", "integer", N_("max length of names in hotlist (0 = no limit)"), - NULL, 0, 32, "0", &config_change_buffer_content); + NULL, 0, 32, "0", &config_change_buffer_content, NULL); config_look_hotlist_sort = config_file_new_option ( - ptr_section, "look_hotlist_sort", "integer", + weechat_config_file, ptr_section, + "look_hotlist_sort", "integer", N_("hotlist sort type (group_time_asc (default), " "group_time_desc, group_number_asc, group_number_desc, " "number_asc, number_desc)"), "group_time_asc|group_time_desc|group_number_asc|" "group_number_desc|number_asc|number_desc", - 0, 0, "group_time_asc", &config_change_hotlist); + 0, 0, "group_time_asc", &config_change_hotlist, NULL); config_look_day_change = config_file_new_option ( - ptr_section, "look_day_change", "boolean", + weechat_config_file, ptr_section, + "look_day_change", "boolean", N_("display special message when day changes"), - NULL, 0, 0, "on", &config_change_day_change); + NULL, 0, 0, "on", &config_change_day_change, NULL); config_look_day_change_time_format = config_file_new_option ( - ptr_section, "look_day_change_time_format", "string", + weechat_config_file, ptr_section, + "look_day_change_time_format", "string", N_("time format for date displayed when day changed"), - NULL, 0, 0, "%a, %d %b %Y", NULL); + NULL, 0, 0, "%a, %d %b %Y", NULL, NULL); config_look_read_marker = config_file_new_option ( - ptr_section, "look_read_marker", "string", + weechat_config_file, ptr_section, + "look_read_marker", "string", N_("use a marker on servers/channels to show first unread " "line"), - NULL, 0, 1, " ", &config_change_read_marker); + NULL, 0, 1, " ", &config_change_read_marker, NULL); config_look_input_format = config_file_new_option ( - ptr_section, "look_input_format", "string", + weechat_config_file, ptr_section, + "look_input_format", "string", N_("format for input prompt ('%c' is replaced by channel " "or server, '%n' by nick and '%m' by nick modes)"), - NULL, 0, 0, "[%n(%m)] ", &config_change_buffer_content); + NULL, 0, 0, "[%n(%m)] ", &config_change_buffer_content, NULL); config_look_paste_max_lines = config_file_new_option ( - ptr_section, "look_paste_max_lines", "integer", + weechat_config_file, ptr_section, + "look_paste_max_lines", "integer", N_("max number of lines for paste without asking user " "(0 = disable this feature)"), - NULL, 0, INT_MAX, "3", NULL); + NULL, 0, INT_MAX, "3", NULL, NULL); config_look_default_msg_quit = config_file_new_option ( - ptr_section, "look_default_msg_quit", "string", + weechat_config_file, ptr_section, + "look_default_msg_quit", "string", N_("default quit message ('%v' will be replaced by WeeChat version in " "string)"), - NULL, 0, 0, "WeeChat %v", NULL); + NULL, 0, 0, "WeeChat %v", NULL, NULL); /* colors */ ptr_section = config_file_new_section (weechat_config_file, "colors", - NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -731,325 +779,401 @@ config_weechat_init () /* general color settings */ config_color_separator = config_file_new_option ( - ptr_section, "color_separator", "color", + weechat_config_file, ptr_section, "color_separator", "color", N_("background color for window separators (when splited)"), - NULL, GUI_COLOR_SEPARATOR, 0, "blue", &config_change_color); + NULL, GUI_COLOR_SEPARATOR, 0, "blue", &config_change_color, NULL); /* title window */ config_color_title = config_file_new_option ( - ptr_section, "color_title", "color", + weechat_config_file, ptr_section, + "color_title", "color", N_("text color for title bar"), - NULL, GUI_COLOR_TITLE, 0, "default", &config_change_color); + NULL, GUI_COLOR_TITLE, 0, "default", &config_change_color, NULL); config_color_title_bg = config_file_new_option ( - ptr_section, "color_title_bg", "color", + weechat_config_file, ptr_section, + "color_title_bg", "color", N_("background color for title bar"), - NULL, -1, 0, "blue", &config_change_color); + NULL, -1, 0, "blue", &config_change_color, NULL); config_color_title_more = config_file_new_option ( - ptr_section, "color_title_more", "color", + weechat_config_file, ptr_section, + "color_title_more", "color", N_("text color for '+' when scrolling title"), - NULL, GUI_COLOR_TITLE_MORE, 0, "lightmagenta", &config_change_color); + NULL, GUI_COLOR_TITLE_MORE, 0, "lightmagenta", &config_change_color, NULL); /* chat window */ config_color_chat = config_file_new_option ( - ptr_section, "color_chat", "color", + weechat_config_file, ptr_section, + "color_chat", "color", N_("text color for chat"), - NULL, GUI_COLOR_CHAT, 0, "default", &config_change_color); + NULL, GUI_COLOR_CHAT, 0, "default", &config_change_color, NULL); config_color_chat_bg = config_file_new_option ( - ptr_section, "color_chat_bg", "color", + weechat_config_file, ptr_section, + "color_chat_bg", "color", N_("background color for chat"), - NULL, -1, 0, "default", &config_change_color); + NULL, -1, 0, "default", &config_change_color, NULL); config_color_chat_time = config_file_new_option ( - ptr_section, "color_chat_time", "color", + weechat_config_file, ptr_section, + "color_chat_time", "color", N_("text color for time in chat window"), - NULL, GUI_COLOR_CHAT_TIME, 0, "default", &config_change_color); + NULL, GUI_COLOR_CHAT_TIME, 0, "default", &config_change_color, NULL); config_color_chat_time_delimiters = config_file_new_option ( - ptr_section, "color_chat_time_delimiters", "color", + weechat_config_file, ptr_section, + "color_chat_time_delimiters", "color", N_("text color for time delimiters"), - NULL, GUI_COLOR_CHAT_TIME_DELIMITERS, 0, "brown", &config_change_color); + NULL, GUI_COLOR_CHAT_TIME_DELIMITERS, 0, "brown", &config_change_color, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_INFO] = config_file_new_option ( - ptr_section, "color_chat_prefix_info", "color", + weechat_config_file, ptr_section, + "color_chat_prefix_info", "color", N_("text color for info prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_INFO, 0, "lightcyan", &config_change_color); + NULL, GUI_COLOR_CHAT_PREFIX_INFO, 0, "lightcyan", &config_change_color, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_ERROR] = config_file_new_option ( - ptr_section, "color_chat_prefix_error", "color", + weechat_config_file, ptr_section, + "color_chat_prefix_error", "color", N_("text color for error prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_ERROR, 0, "yellow", &config_change_color); + NULL, GUI_COLOR_CHAT_PREFIX_ERROR, 0, "yellow", &config_change_color, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_NETWORK] = config_file_new_option ( - ptr_section, "color_chat_prefix_network", "color", + weechat_config_file, ptr_section, + "color_chat_prefix_network", "color", N_("text color for network prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_NETWORK, 0, "lightmagenta", &config_change_color); + NULL, GUI_COLOR_CHAT_PREFIX_NETWORK, 0, "lightmagenta", &config_change_color, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_ACTION] = config_file_new_option ( - ptr_section, "color_chat_prefix_action", "color", + weechat_config_file, ptr_section, + "color_chat_prefix_action", "color", N_("text color for action prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_ACTION, 0, "white", &config_change_color); + NULL, GUI_COLOR_CHAT_PREFIX_ACTION, 0, "white", &config_change_color, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_JOIN] = config_file_new_option ( - ptr_section, "color_chat_prefix_join", "color", + weechat_config_file, ptr_section, + "color_chat_prefix_join", "color", N_("text color for join prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_JOIN, 0, "lightgreen", &config_change_color); + NULL, GUI_COLOR_CHAT_PREFIX_JOIN, 0, "lightgreen", &config_change_color, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_QUIT] = config_file_new_option ( - ptr_section, "color_chat_prefix_quit", "color", + weechat_config_file, ptr_section, + "color_chat_prefix_quit", "color", N_("text color for quit prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_QUIT, 0, "lightred", &config_change_color); + NULL, GUI_COLOR_CHAT_PREFIX_QUIT, 0, "lightred", &config_change_color, NULL); config_color_chat_prefix_more = config_file_new_option ( - ptr_section, "color_chat_prefix_more", "color", + weechat_config_file, ptr_section, + "color_chat_prefix_more", "color", N_("text color for '+' when prefix is too long"), - NULL, GUI_COLOR_CHAT_PREFIX_MORE, 0, "lightmagenta", &config_change_color); + NULL, GUI_COLOR_CHAT_PREFIX_MORE, 0, "lightmagenta", &config_change_color, NULL); config_color_chat_prefix_suffix = config_file_new_option ( - ptr_section, "color_chat_prefix_suffix", "color", + weechat_config_file, ptr_section, + "color_chat_prefix_suffix", "color", N_("text color for suffix (after prefix)"), - NULL, GUI_COLOR_CHAT_PREFIX_SUFFIX, 0, "green", &config_change_color); + NULL, GUI_COLOR_CHAT_PREFIX_SUFFIX, 0, "green", &config_change_color, NULL); config_color_chat_buffer = config_file_new_option ( - ptr_section, "color_chat_buffer", "color", + weechat_config_file, ptr_section, + "color_chat_buffer", "color", N_("text color for buffer names"), - NULL, GUI_COLOR_CHAT_BUFFER, 0, "white", &config_change_color); + NULL, GUI_COLOR_CHAT_BUFFER, 0, "white", &config_change_color, NULL); config_color_chat_server = config_file_new_option ( - ptr_section, "color_chat_server", "color", + weechat_config_file, ptr_section, + "color_chat_server", "color", N_("text color for server names"), - NULL, GUI_COLOR_CHAT_SERVER, 0, "brown", &config_change_color); + NULL, GUI_COLOR_CHAT_SERVER, 0, "brown", &config_change_color, NULL); config_color_chat_channel = config_file_new_option ( - ptr_section, "color_chat_channel", "color", + weechat_config_file, ptr_section, + "color_chat_channel", "color", N_("text color for channel names"), - NULL, GUI_COLOR_CHAT_CHANNEL, 0, "white", &config_change_color); + NULL, GUI_COLOR_CHAT_CHANNEL, 0, "white", &config_change_color, NULL); config_color_chat_nick = config_file_new_option ( - ptr_section, "color_chat_nick", "color", + weechat_config_file, ptr_section, + "color_chat_nick", "color", N_("text color for nicks in chat window"), - NULL, GUI_COLOR_CHAT_NICK, 0, "lightcyan", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK, 0, "lightcyan", &config_change_color, NULL); config_color_chat_nick_self = config_file_new_option ( - ptr_section, "color_chat_nick_self", "color", + weechat_config_file, ptr_section, + "color_chat_nick_self", "color", N_("text color for local nick in chat window"), - NULL, GUI_COLOR_CHAT_NICK_SELF, 0, "white", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK_SELF, 0, "white", &config_change_color, NULL); config_color_chat_nick_other = config_file_new_option ( - ptr_section, "color_chat_nick_other", "color", + weechat_config_file, ptr_section, + "color_chat_nick_other", "color", N_("text color for other nick in private buffer"), - NULL, GUI_COLOR_CHAT_NICK_OTHER, 0, "default", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK_OTHER, 0, "default", &config_change_color, NULL); config_color_chat_nick_colors[0] = config_file_new_option ( - ptr_section, "color_chat_nick_color1", "color", + weechat_config_file, ptr_section, + "color_chat_nick_color1", "color", N_("text color #1 for nick"), - NULL, GUI_COLOR_CHAT_NICK1, 0, "cyan", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK1, 0, "cyan", &config_change_color, NULL); config_color_chat_nick_colors[1] = config_file_new_option ( - ptr_section, "color_chat_nick_color2", "color", + weechat_config_file, ptr_section, + "color_chat_nick_color2", "color", N_("text color #2 for nick"), - NULL, GUI_COLOR_CHAT_NICK2, 0, "magenta", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK2, 0, "magenta", &config_change_color, NULL); config_color_chat_nick_colors[2] = config_file_new_option ( - ptr_section, "color_chat_nick_color3", "color", + weechat_config_file, ptr_section, + "color_chat_nick_color3", "color", N_("text color #3 for nick"), - NULL, GUI_COLOR_CHAT_NICK3, 0, "green", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK3, 0, "green", &config_change_color, NULL); config_color_chat_nick_colors[3] = config_file_new_option ( - ptr_section, "color_chat_nick_color4", "color", + weechat_config_file, ptr_section, + "color_chat_nick_color4", "color", N_("text color #4 for nick"), - NULL, GUI_COLOR_CHAT_NICK4, 0, "brown", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK4, 0, "brown", &config_change_color, NULL); config_color_chat_nick_colors[4] = config_file_new_option ( - ptr_section, "color_chat_nick_color5", "color", + weechat_config_file, ptr_section, + "color_chat_nick_color5", "color", N_("text color #5 for nick"), - NULL, GUI_COLOR_CHAT_NICK5, 0, "lightblue", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK5, 0, "lightblue", &config_change_color, NULL); config_color_chat_nick_colors[5] = config_file_new_option ( - ptr_section, "color_chat_nick_color6", "color", + weechat_config_file, ptr_section, + "color_chat_nick_color6", "color", N_("text color #6 for nick"), - NULL, GUI_COLOR_CHAT_NICK6, 0, "default", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK6, 0, "default", &config_change_color, NULL); config_color_chat_nick_colors[6] = config_file_new_option ( - ptr_section, "color_chat_nick_color7", "color", + weechat_config_file, ptr_section, + "color_chat_nick_color7", "color", N_("text color #7 for nick"), - NULL, GUI_COLOR_CHAT_NICK7, 0, "lightcyan", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK7, 0, "lightcyan", &config_change_color, NULL); config_color_chat_nick_colors[7] = config_file_new_option ( - ptr_section, "color_chat_nick_color8", "color", + weechat_config_file, ptr_section, + "color_chat_nick_color8", "color", N_("text color #8 for nick"), - NULL, GUI_COLOR_CHAT_NICK8, 0, "lightmagenta", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK8, 0, "lightmagenta", &config_change_color, NULL); config_color_chat_nick_colors[8] = config_file_new_option ( - ptr_section, "color_chat_nick_color9", "color", + weechat_config_file, ptr_section, + "color_chat_nick_color9", "color", N_("text color #9 for nick"), - NULL, GUI_COLOR_CHAT_NICK9, 0, "lightgreen", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK9, 0, "lightgreen", &config_change_color, NULL); config_color_chat_nick_colors[9] = config_file_new_option ( - ptr_section, "color_chat_nick_color10", "color", + weechat_config_file, ptr_section, + "color_chat_nick_color10", "color", N_("text color #10 for nick"), - NULL, GUI_COLOR_CHAT_NICK10, 0, "blue", &config_change_color); + NULL, GUI_COLOR_CHAT_NICK10, 0, "blue", &config_change_color, NULL); config_color_chat_host = config_file_new_option ( - ptr_section, "color_chat_host", "color", + weechat_config_file, ptr_section, + "color_chat_host", "color", N_("text color for hostnames"), - NULL, GUI_COLOR_CHAT_HOST, 0, "cyan", &config_change_color); + NULL, GUI_COLOR_CHAT_HOST, 0, "cyan", &config_change_color, NULL); config_color_chat_delimiters = config_file_new_option ( - ptr_section, "color_chat_delimiters", "color", + weechat_config_file, ptr_section, + "color_chat_delimiters", "color", N_("text color for delimiters"), - NULL, GUI_COLOR_CHAT_DELIMITERS, 0, "green", &config_change_color); + NULL, GUI_COLOR_CHAT_DELIMITERS, 0, "green", &config_change_color, NULL); config_color_chat_highlight = config_file_new_option ( - ptr_section, "color_chat_highlight", "color", + weechat_config_file, ptr_section, + "color_chat_highlight", "color", N_("text color for highlighted nick"), - NULL, GUI_COLOR_CHAT_HIGHLIGHT, 0, "yellow", &config_change_color); + NULL, GUI_COLOR_CHAT_HIGHLIGHT, 0, "yellow", &config_change_color, NULL); config_color_chat_read_marker = config_file_new_option ( - ptr_section, "color_chat_read_marker", "color", + weechat_config_file, ptr_section, + "color_chat_read_marker", "color", N_("text color for unread data marker"), - NULL, GUI_COLOR_CHAT_READ_MARKER, 0, "yellow", &config_change_color); + NULL, GUI_COLOR_CHAT_READ_MARKER, 0, "yellow", &config_change_color, NULL); config_color_chat_read_marker_bg = config_file_new_option ( - ptr_section, "color_chat_read_marker_bg", "color", + weechat_config_file, ptr_section, + "color_chat_read_marker_bg", "color", N_("background color for unread data marker"), - NULL, -1, 0, "magenta", &config_change_color); + NULL, -1, 0, "magenta", &config_change_color, NULL); /* status window */ config_color_status = config_file_new_option ( - ptr_section, "color_status", "color", + weechat_config_file, ptr_section, + "color_status", "color", N_("text color for status bar"), - NULL, GUI_COLOR_STATUS, 0, "default", &config_change_color); + NULL, GUI_COLOR_STATUS, 0, "default", &config_change_color, NULL); config_color_status_bg = config_file_new_option ( - ptr_section, "color_status_bg", "color", + weechat_config_file, ptr_section, + "color_status_bg", "color", N_("background color for status bar"), - NULL, -1, 0, "blue", &config_change_color); + NULL, -1, 0, "blue", &config_change_color, NULL); config_color_status_delimiters = config_file_new_option ( - ptr_section, "color_status_delimiters", "color", + weechat_config_file, ptr_section, + "color_status_delimiters", "color", N_("text color for status bar delimiters"), - NULL, GUI_COLOR_STATUS_DELIMITERS, 0, "cyan", &config_change_color); + NULL, GUI_COLOR_STATUS_DELIMITERS, 0, "cyan", &config_change_color, NULL); config_color_status_channel = config_file_new_option ( - ptr_section, "color_status_channel", "color", + weechat_config_file, ptr_section, + "color_status_channel", "color", N_("text color for current channel in status bar"), - NULL, GUI_COLOR_STATUS_CHANNEL, 0, "white", &config_change_color); + NULL, GUI_COLOR_STATUS_CHANNEL, 0, "white", &config_change_color, NULL); config_color_status_data_msg = config_file_new_option ( - ptr_section, "color_status_data_msg", "color", + weechat_config_file, ptr_section, + "color_status_data_msg", "color", N_("text color for buffer with new messages (status bar)"), - NULL, GUI_COLOR_STATUS_DATA_MSG, 0, "yellow", &config_change_color); + NULL, GUI_COLOR_STATUS_DATA_MSG, 0, "yellow", &config_change_color, NULL); config_color_status_data_private = config_file_new_option ( - ptr_section, "color_status_data_private", "color", + weechat_config_file, ptr_section, + "color_status_data_private", "color", N_("text color for buffer with private message (status bar)"), - NULL, GUI_COLOR_STATUS_DATA_PRIVATE, 0, "lightgreen", &config_change_color); + NULL, GUI_COLOR_STATUS_DATA_PRIVATE, 0, "lightgreen", &config_change_color, NULL); config_color_status_data_highlight = config_file_new_option ( - ptr_section, "color_status_data_highlight", "color", + weechat_config_file, ptr_section, + "color_status_data_highlight", "color", N_("text color for buffer with highlight (status bar)"), - NULL, GUI_COLOR_STATUS_DATA_HIGHLIGHT, 0, "lightmagenta", &config_change_color); + NULL, GUI_COLOR_STATUS_DATA_HIGHLIGHT, 0, "lightmagenta", &config_change_color, NULL); config_color_status_data_other = config_file_new_option ( - ptr_section, "color_status_data_other", "color", + weechat_config_file, ptr_section, + "color_status_data_other", "color", N_("text color for buffer with new data (not messages) " "(status bar)"), - NULL, GUI_COLOR_STATUS_DATA_OTHER, 0, "default", &config_change_color); + NULL, GUI_COLOR_STATUS_DATA_OTHER, 0, "default", &config_change_color, NULL); config_color_status_more = config_file_new_option ( - ptr_section, "color_status_more", "color", + weechat_config_file, ptr_section, + "color_status_more", "color", N_("text color for buffer with new data (status bar)"), - NULL, GUI_COLOR_STATUS_MORE, 0, "white", &config_change_color); + NULL, GUI_COLOR_STATUS_MORE, 0, "white", &config_change_color, NULL); /* infobar window */ config_color_infobar = config_file_new_option ( - ptr_section, "color_infobar", "color", + weechat_config_file, ptr_section, + "color_infobar", "color", N_("text color for infobar"), - NULL, GUI_COLOR_INFOBAR, 0, "black", &config_change_color); + NULL, GUI_COLOR_INFOBAR, 0, "black", &config_change_color, NULL); config_color_infobar_bg = config_file_new_option ( - ptr_section, "color_infobar_bg", "color", + weechat_config_file, ptr_section, + "color_infobar_bg", "color", N_("background color for infobar"), - NULL, -1, 0, "cyan", &config_change_color); + NULL, -1, 0, "cyan", &config_change_color, NULL); config_color_infobar_delimiters = config_file_new_option ( - ptr_section, "color_infobar_delimiters", "color", + weechat_config_file, ptr_section, + "color_infobar_delimiters", "color", N_("text color for infobar delimiters"), - NULL, GUI_COLOR_INFOBAR_DELIMITERS, 0, "blue", &config_change_color); + NULL, GUI_COLOR_INFOBAR_DELIMITERS, 0, "blue", &config_change_color, NULL); config_color_infobar_highlight = config_file_new_option ( - ptr_section, "color_infobar_highlight", "color", + weechat_config_file, ptr_section, + "color_infobar_highlight", "color", N_("text color for infobar highlight notification"), - NULL, GUI_COLOR_INFOBAR_HIGHLIGHT, 0, "white", &config_change_color); + NULL, GUI_COLOR_INFOBAR_HIGHLIGHT, 0, "white", &config_change_color, NULL); /* input window */ config_color_input = config_file_new_option ( - ptr_section, "color_input", "color", + weechat_config_file, ptr_section, + "color_input", "color", N_("text color for input line"), - NULL, GUI_COLOR_INPUT, 0, "default", &config_change_color); + NULL, GUI_COLOR_INPUT, 0, "default", &config_change_color, NULL); config_color_input_bg = config_file_new_option ( - ptr_section, "color_input_bg", "color", + weechat_config_file, ptr_section, + "color_input_bg", "color", N_("background color for input line"), - NULL, -1, 0, "default", &config_change_color); + NULL, -1, 0, "default", &config_change_color, NULL); config_color_input_server = config_file_new_option ( - ptr_section, "color_input_server", "color", + weechat_config_file, ptr_section, + "color_input_server", "color", N_("text color for server name in input line"), - NULL, GUI_COLOR_INPUT_SERVER, 0, "brown", &config_change_color); + NULL, GUI_COLOR_INPUT_SERVER, 0, "brown", &config_change_color, NULL); config_color_input_channel = config_file_new_option ( - ptr_section, "color_input_channel", "color", + weechat_config_file, ptr_section, + "color_input_channel", "color", N_("text color for channel name in input line"), - NULL, GUI_COLOR_INPUT_CHANNEL, 0, "white", &config_change_color); + NULL, GUI_COLOR_INPUT_CHANNEL, 0, "white", &config_change_color, NULL); config_color_input_nick = config_file_new_option ( - ptr_section, "color_input_nick", "color", + weechat_config_file, ptr_section, + "color_input_nick", "color", N_("text color for nick name in input line"), - NULL, GUI_COLOR_INPUT_NICK, 0, "lightcyan", &config_change_color); + NULL, GUI_COLOR_INPUT_NICK, 0, "lightcyan", &config_change_color, NULL); config_color_input_delimiters = config_file_new_option ( - ptr_section, "color_input_delimiters", "color", + weechat_config_file, ptr_section, + "color_input_delimiters", "color", N_("text color for delimiters in input line"), - NULL, GUI_COLOR_INPUT_DELIMITERS, 0, "cyan", &config_change_color); + NULL, GUI_COLOR_INPUT_DELIMITERS, 0, "cyan", &config_change_color, NULL); config_color_input_text_not_found = config_file_new_option ( - ptr_section, "color_input_text_not_found", "color", + weechat_config_file, ptr_section, + "color_input_text_not_found", "color", N_("text color for unsucessful text search in input line"), - NULL, GUI_COLOR_INPUT_TEXT_NOT_FOUND, 0, "red", &config_change_color); + NULL, GUI_COLOR_INPUT_TEXT_NOT_FOUND, 0, "red", &config_change_color, NULL); config_color_input_actions = config_file_new_option ( - ptr_section, "color_input_actions", "color", + weechat_config_file, ptr_section, + "color_input_actions", "color", N_("text color for actions in input line"), - NULL, GUI_COLOR_INPUT_ACTIONS, 0, "lightgreen", &config_change_color); + NULL, GUI_COLOR_INPUT_ACTIONS, 0, "lightgreen", &config_change_color, NULL); /* nicklist window */ config_color_nicklist = config_file_new_option ( - ptr_section, "color_nicklist", "color", + weechat_config_file, ptr_section, + "color_nicklist", "color", N_("text color for nicklist"), - NULL, GUI_COLOR_NICKLIST, 0, "default", &config_change_color); + NULL, GUI_COLOR_NICKLIST, 0, "default", &config_change_color, NULL); config_color_nicklist_bg = config_file_new_option ( - ptr_section, "color_nicklist_bg", "color", + weechat_config_file, ptr_section, + "color_nicklist_bg", "color", N_("background color for nicklist"), - NULL, -1, 0, "default", &config_change_color); + NULL, -1, 0, "default", &config_change_color, NULL); config_color_nicklist_group = config_file_new_option ( - ptr_section, "color_nicklist_group", "color", + weechat_config_file, ptr_section, + "color_nicklist_group", "color", N_("text color for groups in nicklist"), - NULL, GUI_COLOR_NICKLIST_GROUP, 0, "green", &config_change_color); + NULL, GUI_COLOR_NICKLIST_GROUP, 0, "green", &config_change_color, NULL); config_color_nicklist_away = config_file_new_option ( - ptr_section, "color_nicklist_away", "color", + weechat_config_file, ptr_section, + "color_nicklist_away", "color", N_("text color for away nicknames"), - NULL, GUI_COLOR_NICKLIST_AWAY, 0, "cyan", &config_change_color); + NULL, GUI_COLOR_NICKLIST_AWAY, 0, "cyan", &config_change_color, NULL); config_color_nicklist_prefix1 = config_file_new_option ( - ptr_section, "color_nicklist_prefix1", "color", + weechat_config_file, ptr_section, + "color_nicklist_prefix1", "color", N_("text color for prefix #1 in nicklist"), - NULL, GUI_COLOR_NICKLIST_PREFIX1, 0, "lightgreen", &config_change_color); + NULL, GUI_COLOR_NICKLIST_PREFIX1, 0, "lightgreen", &config_change_color, NULL); config_color_nicklist_prefix2 = config_file_new_option ( - ptr_section, "color_nicklist_prefix2", "color", + weechat_config_file, ptr_section, + "color_nicklist_prefix2", "color", N_("text color for prefix #2 in nicklist"), - NULL, GUI_COLOR_NICKLIST_PREFIX2, 0, "lightmagenta", &config_change_color); + NULL, GUI_COLOR_NICKLIST_PREFIX2, 0, "lightmagenta", &config_change_color, NULL); config_color_nicklist_prefix3 = config_file_new_option ( - ptr_section, "color_nicklist_prefix3", "color", + weechat_config_file, ptr_section, + "color_nicklist_prefix3", "color", N_("text color for prefix #3 in nicklist"), - NULL, GUI_COLOR_NICKLIST_PREFIX3, 0, "yellow", &config_change_color); + NULL, GUI_COLOR_NICKLIST_PREFIX3, 0, "yellow", &config_change_color, NULL); config_color_nicklist_prefix4 = config_file_new_option ( - ptr_section, "color_nicklist_prefix4", "color", + weechat_config_file, ptr_section, + "color_nicklist_prefix4", "color", N_("text color for prefix #4 in nicklist"), - NULL, GUI_COLOR_NICKLIST_PREFIX4, 0, "blue", &config_change_color); + NULL, GUI_COLOR_NICKLIST_PREFIX4, 0, "blue", &config_change_color, NULL); config_color_nicklist_prefix5 = config_file_new_option ( - ptr_section, "color_nicklist_prefix5", "color", + weechat_config_file, ptr_section, + "color_nicklist_prefix5", "color", N_("text color for prefix #5 in nicklist"), - NULL, GUI_COLOR_NICKLIST_PREFIX5, 0, "brown", &config_change_color); + NULL, GUI_COLOR_NICKLIST_PREFIX5, 0, "brown", &config_change_color, NULL); config_color_nicklist_more = config_file_new_option ( - ptr_section, "color_nicklist_more", "color", + weechat_config_file, ptr_section, + "color_nicklist_more", "color", N_("text color for '+' when scrolling nicks in nicklist"), - NULL, GUI_COLOR_NICKLIST_MORE, 0, "lightmagenta", &config_change_color); + NULL, GUI_COLOR_NICKLIST_MORE, 0, "lightmagenta", &config_change_color, NULL); config_color_nicklist_separator = config_file_new_option ( - ptr_section, "color_nicklist_separator", "color", + weechat_config_file, ptr_section, + "color_nicklist_separator", "color", N_("text color for nicklist separator"), - NULL, GUI_COLOR_NICKLIST_SEPARATOR, 0, "blue", &config_change_color); + NULL, GUI_COLOR_NICKLIST_SEPARATOR, 0, "blue", &config_change_color, NULL); /* status info */ config_color_info = config_file_new_option ( - ptr_section, "color_info", "color", + weechat_config_file, ptr_section, + "color_info", "color", N_("text color for status info"), - NULL, GUI_COLOR_INFO, 0, "default", &config_change_color); + NULL, GUI_COLOR_INFO, 0, "default", &config_change_color, NULL); config_color_info_bg = config_file_new_option ( - ptr_section, "color_info_bg", "color", + weechat_config_file, ptr_section, + "color_info_bg", "color", N_("background color for status info"), - NULL, -1, 0, "default", &config_change_color); + NULL, -1, 0, "default", &config_change_color, NULL); config_color_info_waiting = config_file_new_option ( - ptr_section, "color_info_waiting", "color", + weechat_config_file, ptr_section, + "color_info_waiting", "color", N_("text color for \"waiting\" status info"), - NULL, GUI_COLOR_INFO_WAITING, 0, "lightcyan", &config_change_color); + NULL, GUI_COLOR_INFO_WAITING, 0, "lightcyan", &config_change_color, NULL); config_color_info_connecting = config_file_new_option ( - ptr_section, "color_info_connecting", "color", + weechat_config_file, ptr_section, + "color_info_connecting", "color", N_("text color for \"connecting\" status info"), - NULL, GUI_COLOR_INFO_CONNECTING, 0, "yellow", &config_change_color); + NULL, GUI_COLOR_INFO_CONNECTING, 0, "yellow", &config_change_color, NULL); config_color_info_active = config_file_new_option ( - ptr_section, "color_info_active", "color", + weechat_config_file, ptr_section, + "color_info_active", "color", N_("text color for \"active\" status info"), - NULL, GUI_COLOR_INFO_ACTIVE, 0, "lightblue", &config_change_color); + NULL, GUI_COLOR_INFO_ACTIVE, 0, "lightblue", &config_change_color, NULL); config_color_info_done = config_file_new_option ( - ptr_section, "color_info_done", "color", + weechat_config_file, ptr_section, + "color_info_done", "color", N_("text color for \"done\" status info"), - NULL, GUI_COLOR_INFO_DONE, 0, "lightgreen", &config_change_color); + NULL, GUI_COLOR_INFO_DONE, 0, "lightgreen", &config_change_color, NULL); config_color_info_failed = config_file_new_option ( - ptr_section, "color_info_failed", "color", + weechat_config_file, ptr_section, + "color_info_failed", "color", N_("text color for \"failed\" status info"), - NULL, GUI_COLOR_INFO_FAILED, 0, "lightred", &config_change_color); + NULL, GUI_COLOR_INFO_FAILED, 0, "lightred", &config_change_color, NULL); config_color_info_aborted = config_file_new_option ( - ptr_section, "color_info_aborted", "color", + weechat_config_file, ptr_section, + "color_info_aborted", "color", N_("text color for \"aborted\" status info"), - NULL, GUI_COLOR_INFO_ABORTED, 0, "lightred", &config_change_color); + NULL, GUI_COLOR_INFO_ABORTED, 0, "lightred", &config_change_color, NULL); /* history */ ptr_section = config_file_new_section (weechat_config_file, "history", - NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1057,24 +1181,27 @@ config_weechat_init () } config_history_max_lines = config_file_new_option ( - ptr_section, "history_max_lines", "integer", + weechat_config_file, ptr_section, + "history_max_lines", "integer", N_("maximum number of lines in history per buffer " "(0 = unlimited)"), - NULL, 0, INT_MAX, "4096", NULL); + NULL, 0, INT_MAX, "4096", NULL, NULL); config_history_max_commands = config_file_new_option ( - ptr_section, "history_max_commands", "integer", + weechat_config_file, ptr_section, + "history_max_commands", "integer", N_("maximum number of user commands in history (0 = " "unlimited)"), - NULL, 0, INT_MAX, "100", NULL); + NULL, 0, INT_MAX, "100", NULL, NULL); config_history_display_default = config_file_new_option ( - ptr_section, "history_display_default", "integer", + weechat_config_file, ptr_section, + "history_display_default", "integer", N_("maximum number of commands to display by default in " "history listing (0 = unlimited)"), - NULL, 0, INT_MAX, "5", NULL); + NULL, 0, INT_MAX, "5", NULL, NULL); /* proxy */ ptr_section = config_file_new_section (weechat_config_file, "proxy", - NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1082,37 +1209,44 @@ config_weechat_init () } config_proxy_use = config_file_new_option ( - ptr_section, "proxy_use", "boolean", + weechat_config_file, ptr_section, + "proxy_use", "boolean", N_("use a proxy server"), - NULL, 0, 0, "off", NULL); + NULL, 0, 0, "off", NULL, NULL); config_proxy_type = config_file_new_option ( - ptr_section, "proxy_type", "integer", + weechat_config_file, ptr_section, + "proxy_type", "integer", N_("proxy type (http (default), socks4, socks5)"), - "http|socks4|socks5", 0, 0, "http", NULL); + "http|socks4|socks5", 0, 0, "http", NULL, NULL); config_proxy_ipv6 = config_file_new_option ( - ptr_section, "proxy_ipv6", "boolean", + weechat_config_file, ptr_section, + "proxy_ipv6", "boolean", N_("connect to proxy using ipv6"), - NULL, 0, 0, "off", NULL); + NULL, 0, 0, "off", NULL, NULL); config_proxy_address = config_file_new_option ( - ptr_section, "proxy_address", "string", + weechat_config_file, ptr_section, + "proxy_address", "string", N_("proxy server address (IP or hostname)"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); config_proxy_port = config_file_new_option ( - ptr_section, "proxy_port", "integer", + weechat_config_file, ptr_section, + "proxy_port", "integer", N_("port for connecting to proxy server"), - NULL, 0, 65535, "3128", NULL); + NULL, 0, 65535, "3128", NULL, NULL); config_proxy_username = config_file_new_option ( - ptr_section, "proxy_username", "string", + weechat_config_file, ptr_section, + "proxy_username", "string", N_("username for proxy server"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); config_proxy_password = config_file_new_option ( - ptr_section, "proxy_password", "string", + weechat_config_file, ptr_section, + "proxy_password", "string", N_("password for proxy server"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); /* plugins */ ptr_section = config_file_new_section (weechat_config_file, "plugins", - NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1120,19 +1254,22 @@ config_weechat_init () } config_plugins_path = config_file_new_option ( - ptr_section, "plugins_path", "string", + weechat_config_file, ptr_section, + "plugins_path", "string", N_("path for searching plugins ('%h' will be replaced by " "WeeChat home, ~/.weechat by default)"), - NULL, 0, 0, "%h/plugins", NULL); + NULL, 0, 0, "%h/plugins", NULL, NULL); config_plugins_autoload = config_file_new_option ( - ptr_section, "plugins_autoload", "string", + weechat_config_file, ptr_section, + "plugins_autoload", "string", N_("comma separated list of plugins to load automatically " "at startup, \"*\" means all plugins found (names may " "be partial, for example \"perl\" is ok for " "\"perl.so\")"), - NULL, 0, 0, "*", NULL); + NULL, 0, 0, "*", NULL, NULL); config_plugins_extension = config_file_new_option ( - ptr_section, "plugins_extension", "string", + weechat_config_file, ptr_section, + "plugins_extension", "string", N_("standard plugins extension in filename (for example " "\".so\" under Linux or \".dll\" under Microsoft Windows)"), NULL, 0, 0, @@ -1141,13 +1278,21 @@ config_weechat_init () #else ".so", #endif - NULL); + NULL, NULL); + config_plugins_save_config_on_unload = config_file_new_option ( + weechat_config_file, ptr_section, + "plugins_save_config_on_unload", "boolean", + N_("save configuration files when unloading plugins"), + NULL, 0, 0, "on", NULL, NULL); /* keys */ ptr_section = config_file_new_section (weechat_config_file, "keys", &config_weechat_read_key, + NULL, + &config_weechat_write_keys, + NULL, &config_weechat_write_keys, - &config_weechat_write_keys); + NULL); if (!ptr_section) { config_file_free (weechat_config_file); diff --git a/src/core/wee-config.h b/src/core/wee-config.h index 5d6476af6..3be894daa 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -164,6 +164,7 @@ extern struct t_config_option *config_proxy_password; extern struct t_config_option *config_plugins_path; extern struct t_config_option *config_plugins_autoload; extern struct t_config_option *config_plugins_extension; +extern struct t_config_option *config_plugins_save_config_on_unload; extern int config_weechat_init (); extern int config_weechat_read (); diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index 20bec9132..15990ea57 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -279,6 +279,23 @@ gui_completion_list_add_buffers_categories (struct t_gui_completion *completion) } /* + * gui_completion_list_add_config_files: add config files to completion list + */ + +void +gui_completion_list_add_config_files (struct t_gui_completion *completion) +{ + struct t_config_file *ptr_config_file; + + for (ptr_config_file = config_files; ptr_config_file; + ptr_config_file = ptr_config_file->next_config) + { + gui_completion_list_add (completion, ptr_config_file->filename, + 0, WEECHAT_LIST_POS_SORT); + } +} + +/* * gui_completion_list_add_filename: add filename to completion list */ @@ -670,6 +687,9 @@ gui_completion_build_list_template (struct t_gui_completion *completion, case 'c': /* buffers categories */ gui_completion_list_add_buffers_categories (completion); break; + case 'C': /* config files */ + gui_completion_list_add_config_files (completion); + break; case 'f': /* filename */ gui_completion_list_add_filename (completion); break; @@ -745,7 +765,7 @@ void gui_completion_build_list (struct t_gui_completion *completion) { struct t_hook *ptr_hook; - char *template, *pos_template, *pos_space; + char *pos_template, *pos_space; int repeat_last, i, length; repeat_last = 0; @@ -789,10 +809,11 @@ gui_completion_build_list (struct t_gui_completion *completion) } if (repeat_last) { - pos_space = rindex (template, ' '); + pos_space = rindex (HOOK_COMMAND(ptr_hook, completion), ' '); gui_completion_build_list_template (completion, (pos_space) ? - pos_space + 1 : template, + pos_space + 1 : HOOK_COMMAND(ptr_hook, + completion), ptr_hook->plugin); } } diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index 9267f5d7a..8655b5519 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -420,9 +420,10 @@ alias_free_all () */ int -alias_config_reload (struct t_config_file *config_file) +alias_config_reload (void *data, struct t_config_file *config_file) { /* make C compiler happy */ + (void) data; (void) config_file; alias_free_all (); @@ -434,10 +435,11 @@ alias_config_reload (struct t_config_file *config_file) */ void -alias_config_read_line (struct t_config_file *config_file, char *option_name, - char *value) +alias_config_read_line (void *data, struct t_config_file *config_file, + char *option_name, char *value) { /* make C compiler happy */ + (void) data; (void) config_file; if (option_name && value) @@ -460,11 +462,14 @@ alias_config_read_line (struct t_config_file *config_file, char *option_name, */ void -alias_config_write_section (struct t_config_file *config_file, +alias_config_write_section (void *data, struct t_config_file *config_file, char *section_name) { struct t_alias *ptr_alias; + /* make C compiler happy */ + (void) data; + weechat_config_write_line (config_file, section_name, NULL); for (ptr_alias = alias_list; ptr_alias; @@ -482,9 +487,13 @@ alias_config_write_section (struct t_config_file *config_file, */ void -alias_config_write_default_aliases (struct t_config_file *config_file, +alias_config_write_default_aliases (void *data, + struct t_config_file *config_file, char *section_name) { + /* make C compiler happy */ + (void) data; + weechat_config_write_line (config_file, section_name, NULL); weechat_config_write_line (config_file, "SAY", "%s", "\"msg *\""); @@ -524,14 +533,17 @@ alias_config_init () struct t_config_section *ptr_section; alias_config_file = weechat_config_new (ALIAS_CONFIG_FILENAME, - &alias_config_reload); + &alias_config_reload, NULL); if (!alias_config_file) return 0; ptr_section = weechat_config_new_section (alias_config_file, "alias", - alias_config_read_line, - alias_config_write_section, - alias_config_write_default_aliases); + &alias_config_read_line, + NULL, + &alias_config_write_section, + NULL, + &alias_config_write_default_aliases, + NULL); if (!ptr_section) { weechat_config_free (alias_config_file); diff --git a/src/plugins/charset/charset.c b/src/plugins/charset/charset.c index 10a71af87..521292b81 100644 --- a/src/plugins/charset/charset.c +++ b/src/plugins/charset/charset.c @@ -172,9 +172,10 @@ charset_free_all () */ int -charset_config_reload (struct t_config_file *config_file) +charset_config_reload (void *data, struct t_config_file *config_file) { /* make C compiler happy */ + (void) data; (void) config_file; charset_free_all (); @@ -186,10 +187,11 @@ charset_config_reload (struct t_config_file *config_file) */ void -charset_config_read_line (struct t_config_file *config_file, char *option_name, - char *value) +charset_config_read_line (void *data, struct t_config_file *config_file, + char *option_name, char *value) { /* make C compiler happy */ + (void) data; (void) config_file; if (option_name && value) @@ -212,11 +214,14 @@ charset_config_read_line (struct t_config_file *config_file, char *option_name, */ void -charset_config_write_section (struct t_config_file *config_file, +charset_config_write_section (void *data, struct t_config_file *config_file, char *section_name) { struct t_charset *ptr_charset; + /* make C compiler happy */ + (void) data; + weechat_config_write_line (config_file, section_name, NULL); for (ptr_charset = charset_list; ptr_charset; @@ -234,9 +239,13 @@ charset_config_write_section (struct t_config_file *config_file, */ void -charset_config_write_default_charsets (struct t_config_file *config_file, +charset_config_write_default_charsets (void *data, + struct t_config_file *config_file, char *section_name) { + /* make C compiler happy */ + (void) data; + weechat_config_write_line (config_file, section_name, NULL); if (charset_terminal && charset_internal @@ -258,14 +267,17 @@ charset_config_init () struct t_config_section *ptr_section; charset_config_file = weechat_config_new (CHARSET_CONFIG_FILENAME, - &charset_config_reload); + &charset_config_reload, NULL); if (!charset_config_file) return 0; ptr_section = weechat_config_new_section (charset_config_file, "charset", - charset_config_read_line, - charset_config_write_section, - charset_config_write_default_charsets); + &charset_config_read_line, + NULL, + &charset_config_write_section, + NULL, + &charset_config_write_default_charsets, + NULL); if (!ptr_section) { weechat_config_free (charset_config_file); diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index ff56751be..02c6416a7 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -212,12 +212,13 @@ irc_config_change_notify_levels () */ int -irc_config_reload (struct t_config_file *config_file) +irc_config_reload (void *data, struct t_config_file *config_file) { struct t_irc_server *ptr_server, *next_server; int rc; /* make C compiler happy */ + (void) data; (void) config_file; irc_config_server = NULL; @@ -270,13 +271,14 @@ irc_config_reload (struct t_config_file *config_file) */ void -irc_config_read_server_line (struct t_config_file *config_file, +irc_config_read_server_line (void *data, struct t_config_file *config_file, char *option_name, char *value) { struct t_config_option *ptr_option; int rc; /* make C compiler happy */ + (void) data; (void) config_file; if (option_name && value) @@ -339,11 +341,14 @@ irc_config_read_server_line (struct t_config_file *config_file, */ void -irc_config_write_servers (struct t_config_file *config_file, +irc_config_write_servers (void *data, struct t_config_file *config_file, char *section_name) { struct t_irc_server *ptr_server; + /* make C compiler happy */ + (void) data; + for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { @@ -397,12 +402,15 @@ irc_config_write_servers (struct t_config_file *config_file, */ void -irc_config_write_server_default (struct t_config_file *config_file, +irc_config_write_server_default (void *data, struct t_config_file *config_file, char *section_name) { struct passwd *my_passwd; char *realname, *pos; + /* make C compiler happy */ + (void) data; + weechat_config_write_line (config_file, section_name, NULL); weechat_config_write_line (config_file, "server_name", "%s", "\"freenode\""); @@ -469,12 +477,14 @@ irc_config_init () struct t_config_section *ptr_section; irc_config_file = weechat_config_new (IRC_CONFIG_FILENAME, - &irc_config_reload); + &irc_config_reload, NULL); if (!irc_config_file) return 0; ptr_section = weechat_config_new_section (irc_config_file, "irc", - NULL, NULL, NULL); + NULL, NULL, + NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (irc_config_file); @@ -482,93 +492,114 @@ irc_config_init () } irc_config_irc_one_server_buffer = weechat_config_new_option ( - ptr_section, "irc_one_server_buffer", "boolean", + irc_config_file, ptr_section, + "irc_one_server_buffer", "boolean", N_("use same buffer for all servers"), - NULL, 0, 0, "off", &irc_config_change_one_server_buffer); + NULL, 0, 0, "off", &irc_config_change_one_server_buffer, NULL); irc_config_irc_open_near_server = weechat_config_new_option ( - ptr_section, "irc_open_near_server", "boolean", + irc_config_file, ptr_section, + "irc_open_near_server", "boolean", N_("open new channels/privates near server"), - NULL, 0, 0, "off", NULL); + NULL, 0, 0, "off", NULL, NULL); irc_config_irc_nick_prefix = weechat_config_new_option ( - ptr_section, "irc_nick_prefix", "string", + irc_config_file, ptr_section, + "irc_nick_prefix", "string", N_("text to display before nick in chat window"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_irc_nick_suffix = weechat_config_new_option ( - ptr_section, "irc_nick_suffix", "string", + irc_config_file, ptr_section, + "irc_nick_suffix", "string", N_("text to display after nick in chat window"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_irc_nick_completion_smart = weechat_config_new_option ( - ptr_section, "irc_nick_completion_smart", "boolean", + irc_config_file, ptr_section, + "irc_nick_completion_smart", "boolean", N_("smart completion for nicks (completes with last speakers first)"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_irc_display_away = weechat_config_new_option ( - ptr_section, "irc_display_away", "integer", + irc_config_file, ptr_section, + "irc_display_away", "integer", N_("display message when (un)marking as away"), - "off|local|channel", 0, 0, "local", NULL); + "off|local|channel", 0, 0, "local", NULL, NULL); irc_config_irc_show_away_once = weechat_config_new_option ( - ptr_section, "irc_show_away_once", "boolean", + irc_config_file, ptr_section, + "irc_show_away_once", "boolean", N_("show remote away message only once in private"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_irc_default_msg_part = weechat_config_new_option ( - ptr_section, "irc_default_msg_part", "string", + irc_config_file, ptr_section, + "irc_default_msg_part", "string", N_("default part message (leaving channel) ('%v' will be replaced by " "WeeChat version in string)"), - NULL, 0, 0, "WeeChat %v", NULL); + NULL, 0, 0, "WeeChat %v", NULL, NULL); irc_config_irc_notice_as_pv = weechat_config_new_option ( - ptr_section, "irc_notice_as_pv", "boolean", + irc_config_file, ptr_section, + "irc_notice_as_pv", "boolean", N_("display notices as private messages"), - NULL, 0, 0, "off", NULL); + NULL, 0, 0, "off", NULL, NULL); irc_config_irc_away_check = weechat_config_new_option ( - ptr_section, "irc_away_check", "integer", + irc_config_file, ptr_section, + "irc_away_check", "integer", N_("interval between two checks for away (in minutes, 0 = never " "check)"), - NULL, 0, INT_MAX, "0", &irc_config_change_away_check); + NULL, 0, INT_MAX, "0", &irc_config_change_away_check, NULL); irc_config_irc_away_check_max_nicks = weechat_config_new_option ( - ptr_section, "irc_away_check_max_nicks", "integer", + irc_config_file, ptr_section, + "irc_away_check_max_nicks", "integer", N_("do not check away nicks on channels with high number of nicks " "(0 = unlimited)"), - NULL, 0, INT_MAX, "0", &irc_config_change_away_check); + NULL, 0, INT_MAX, "0", &irc_config_change_away_check, NULL); irc_config_irc_lag_check = weechat_config_new_option ( - ptr_section, "irc_lag_check", "integer", + irc_config_file, ptr_section, + "irc_lag_check", "integer", N_("interval between two checks for lag (in seconds, 0 = never " "check)"), - NULL, 0, INT_MAX, "60", NULL); + NULL, 0, INT_MAX, "60", NULL, NULL); irc_config_irc_lag_min_show = weechat_config_new_option ( - ptr_section, "irc_lag_min_show", "integer", + irc_config_file, ptr_section, + "irc_lag_min_show", "integer", N_("minimum lag to show (in seconds)"), - NULL, 0, INT_MAX, "1", NULL); + NULL, 0, INT_MAX, "1", NULL, NULL); irc_config_irc_lag_disconnect = weechat_config_new_option ( - ptr_section, "irc_lag_disconnect", "integer", + irc_config_file, ptr_section, + "irc_lag_disconnect", "integer", N_("disconnect after important lag (in minutes, 0 = never " "disconnect)"), - NULL, 0, INT_MAX, "5", NULL); + NULL, 0, INT_MAX, "5", NULL, NULL); irc_config_irc_anti_flood = weechat_config_new_option ( - ptr_section, "irc_anti_flood", "integer", + irc_config_file, ptr_section, + "irc_anti_flood", "integer", N_("anti-flood: # seconds between two user messages (0 = no " "anti-flood)"), - NULL, 0, 5, "2", NULL); + NULL, 0, 5, "2", NULL, NULL); irc_config_irc_highlight = weechat_config_new_option ( - ptr_section, "irc_highlight", "string", + irc_config_file, ptr_section, + "irc_highlight", "string", N_("comma separated list of words to highlight (case insensitive " "comparison, words may begin or end with \"*\" for partial match)"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_irc_colors_receive = weechat_config_new_option ( - ptr_section, "irc_colors_receive", "boolean", + irc_config_file, ptr_section, + "irc_colors_receive", "boolean", N_("when off, colors codes are ignored in incoming messages"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_irc_colors_send = weechat_config_new_option ( - ptr_section, "irc_colors_send", "boolean", + irc_config_file, ptr_section, + "irc_colors_send", "boolean", N_("allow user to send colors with special codes (^Cb=bold, " "^Ccxx=color, ^Ccxx,yy=color+background, ^Cu=underline, " "^Cr=reverse)"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_irc_send_unknown_commands = weechat_config_new_option ( - ptr_section, "irc_send_unknown_commands", "boolean", + irc_config_file, ptr_section, + "irc_send_unknown_commands", "boolean", N_("send unknown commands to IRC server"), - NULL, 0, 0, "off", NULL); + NULL, 0, 0, "off", NULL, NULL); ptr_section = weechat_config_new_section (irc_config_file, "dcc", - NULL, NULL, NULL); + NULL, NULL, + NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (irc_config_file); @@ -576,62 +607,76 @@ irc_config_init () } irc_config_dcc_auto_accept_files = weechat_config_new_option ( - ptr_section, "dcc_auto_accept_files", "boolean", + irc_config_file, ptr_section, + "dcc_auto_accept_files", "boolean", N_("automatically accept incoming dcc files (use carefully!)"), - NULL, 0, 0, "off", NULL); + NULL, 0, 0, "off", NULL, NULL); irc_config_dcc_auto_accept_chats = weechat_config_new_option ( - ptr_section, "dcc_auto_accept_chats", "boolean", + irc_config_file, ptr_section, + "dcc_auto_accept_chats", "boolean", N_("automatically accept dcc chats (use carefully!)"), - NULL, 0, 0, "off", NULL); + NULL, 0, 0, "off", NULL, NULL); irc_config_dcc_timeout = weechat_config_new_option ( - ptr_section, "dcc_timeout", "integer", + irc_config_file, ptr_section, + "dcc_timeout", "integer", N_("timeout for dcc request (in seconds)"), - NULL, 5, INT_MAX, "300", NULL); + NULL, 5, INT_MAX, "300", NULL, NULL); irc_config_dcc_blocksize = weechat_config_new_option ( - ptr_section, "dcc_blocksize", "integer", + irc_config_file, ptr_section, + "dcc_blocksize", "integer", N_("block size for dcc packets in bytes"), NULL, IRC_DCC_MIN_BLOCKSIZE, IRC_DCC_MAX_BLOCKSIZE, "65536", - NULL); + NULL, NULL); irc_config_dcc_fast_send = weechat_config_new_option ( - ptr_section, "dcc_fast_send", "boolean", + irc_config_file, ptr_section, + "dcc_fast_send", "boolean", N_("does not wait for ACK when sending file"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_dcc_port_range = weechat_config_new_option ( - ptr_section, "dcc_port_range", "string", + irc_config_file, ptr_section, + "dcc_port_range", "string", N_("restricts outgoing dcc to use only ports in the given range " "(useful for NAT) (syntax: a single port, ie. 5000 or a port " "range, ie. 5000-5015, empty value means any port)"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_dcc_own_ip = weechat_config_new_option ( - ptr_section, "dcc_own_ip", "string", + irc_config_file, ptr_section, + "dcc_own_ip", "string", N_("IP or DNS address used for outgoing dcc " "(if empty, local interface IP is used)"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_dcc_download_path = weechat_config_new_option ( - ptr_section, "dcc_download_path", "string", + irc_config_file, ptr_section, + "dcc_download_path", "string", N_("path for writing incoming files with dcc"), - NULL, 0, 0, "%h/dcc", NULL); + NULL, 0, 0, "%h/dcc", NULL, NULL); irc_config_dcc_upload_path = weechat_config_new_option ( - ptr_section, "dcc_upload_path", "string", + irc_config_file, ptr_section, + "dcc_upload_path", "string", N_("path for reading files when sending thru dcc (when no path is " "specified)"), - NULL, 0, 0, "~", NULL); + NULL, 0, 0, "~", NULL, NULL); irc_config_dcc_convert_spaces = weechat_config_new_option ( - ptr_section, "dcc_convert_spaces", "boolean", + irc_config_file, ptr_section, + "dcc_convert_spaces", "boolean", N_("convert spaces to underscores when sending files"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_dcc_auto_rename = weechat_config_new_option ( - ptr_section, "dcc_auto_rename", "boolean", + irc_config_file, ptr_section, + "dcc_auto_rename", "boolean", N_("rename incoming files if already exists (add '.1', '.2', ...)"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_dcc_auto_resume = weechat_config_new_option ( - ptr_section, "dcc_auto_resume", "boolean", + irc_config_file, ptr_section, + "dcc_auto_resume", "boolean", N_("automatically resume dcc transfer if connection with remote host " "is loosed"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); ptr_section = weechat_config_new_section (irc_config_file, "log", - NULL, NULL, NULL); + NULL, NULL, + NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (irc_config_file); @@ -639,26 +684,33 @@ irc_config_init () } irc_config_log_auto_server = weechat_config_new_option ( - ptr_section, "log_auto_server", "boolean", + irc_config_file, ptr_section, + "log_auto_server", "boolean", N_("automatically log server messages"), - NULL, 0, 0, "off", &irc_config_change_log); + NULL, 0, 0, "off", &irc_config_change_log, NULL); irc_config_log_auto_channel = weechat_config_new_option ( - ptr_section, "log_auto_channel", "boolean", + irc_config_file, ptr_section, + "log_auto_channel", "boolean", N_("automatically log channel chats"), - NULL, 0, 0, "off", &irc_config_change_log); + NULL, 0, 0, "off", &irc_config_change_log, NULL); irc_config_log_auto_private = weechat_config_new_option ( - ptr_section, "log_auto_private", "boolean", + irc_config_file, ptr_section, + "log_auto_private", "boolean", N_("automatically log private chats"), - NULL, 0, 0, "off", &irc_config_change_log); + NULL, 0, 0, "off", &irc_config_change_log, NULL); irc_config_log_hide_nickserv_pwd = weechat_config_new_option ( - ptr_section, "log_hide_nickserv_pwd", "boolean", + irc_config_file, ptr_section, + "log_hide_nickserv_pwd", "boolean", N_("hide password displayed by nickserv"), - NULL, 0, 0, "on", &irc_config_change_log); + NULL, 0, 0, "on", &irc_config_change_log, NULL); ptr_section = weechat_config_new_section (irc_config_file, "server", - irc_config_read_server_line, - irc_config_write_servers, - irc_config_write_server_default); + &irc_config_read_server_line, + NULL, + &irc_config_write_servers, + NULL, + &irc_config_write_server_default, + NULL); if (!ptr_section) { weechat_config_free (irc_config_file); @@ -668,94 +720,112 @@ irc_config_init () irc_config_section_server = ptr_section; irc_config_server_name = weechat_config_new_option ( - ptr_section, "server_name", "string", + irc_config_file, ptr_section, + "server_name", "string", N_("name associated to IRC server (for display only)"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_autoconnect = weechat_config_new_option ( - ptr_section, "server_autoconnect", "boolean", + irc_config_file, ptr_section, + "server_autoconnect", "boolean", N_("automatically connect to server when WeeChat is starting"), - NULL, 0, 0, "off", NULL); + NULL, 0, 0, "off", NULL, NULL); irc_config_server_autoreconnect = weechat_config_new_option ( - ptr_section, "server_autoreconnect", "boolean", + irc_config_file, ptr_section, + "server_autoreconnect", "boolean", N_("automatically reconnect to server when disconnected"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_server_autoreconnect_delay = weechat_config_new_option ( - ptr_section, "server_autoreconnect_delay", "integer", + irc_config_file, ptr_section, + "server_autoreconnect_delay", "integer", N_("delay (in seconds) before trying again to reconnect to server"), - NULL, 0, 65535, "30", NULL); + NULL, 0, 65535, "30", NULL, NULL); irc_config_server_address = weechat_config_new_option ( - ptr_section, "server_address", "string", + irc_config_file, ptr_section, + "server_address", "string", N_("IP address or hostname of IRC server"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_port = weechat_config_new_option ( - ptr_section, "server_port", "integer", + irc_config_file, ptr_section, + "server_port", "integer", N_("port for connecting to server"), - NULL, 0, 65535, "6667", NULL); + NULL, 0, 65535, "6667", NULL, NULL); irc_config_server_ipv6 = weechat_config_new_option ( - ptr_section, "server_ipv6", "boolean", + irc_config_file, ptr_section, + "server_ipv6", "boolean", N_("use IPv6 protocol for server communication"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_server_ssl = weechat_config_new_option ( - ptr_section, "server_ssl", "boolean", + irc_config_file, ptr_section, + "server_ssl", "boolean", N_("use SSL for server communication"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_server_password = weechat_config_new_option ( - ptr_section, "server_password", "string", + irc_config_file, ptr_section, + "server_password", "string", N_("password for IRC server"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_nick1 = weechat_config_new_option ( - ptr_section, "server_nick1", "string", + irc_config_file, ptr_section, + "server_nick1", "string", N_("nickname to use on IRC server"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_nick2 = weechat_config_new_option ( - ptr_section, "server_nick2", "string", + irc_config_file, ptr_section, + "server_nick2", "string", N_("alternate nickname to use on IRC server (if nickname is already " "used)"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_nick3 = weechat_config_new_option ( - ptr_section, "server_nick3", "string", + irc_config_file, ptr_section, "server_nick3", "string", N_("2nd alternate nickname to use on IRC server (if alternate " "nickname is already used)"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_username = weechat_config_new_option ( - ptr_section, "server_username", "string", + irc_config_file, ptr_section, "server_username", "string", N_("user name to use on IRC server"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_realname = weechat_config_new_option ( - ptr_section, "server_realname", "string", + irc_config_file, ptr_section, + "server_realname", "string", N_("real name to use on IRC server"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_hostname = weechat_config_new_option ( - ptr_section, "server_hostname", "string", + irc_config_file, ptr_section, + "server_hostname", "string", N_("custom hostname/IP for server (optional, if empty local hostname " "is used)"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_command = weechat_config_new_option ( - ptr_section, "server_command", "string", + irc_config_file, ptr_section, + "server_command", "string", N_("command(s) to run when connected to server (many commands should " "be separated by ';', use '\\;' for a semicolon, special variables " "$nick, $channel and $server are replaced by their value)"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_command_delay = weechat_config_new_option ( - ptr_section, "server_command_delay", "integer", + irc_config_file, ptr_section, + "server_command_delay", "integer", N_("delay (in seconds) after command was executed (example: give some " "time for authentication)"), - NULL, 0, 3600, "0", NULL); + NULL, 0, 3600, "0", NULL, NULL); irc_config_server_autojoin = weechat_config_new_option ( - ptr_section, "server_autojoin", "string", + irc_config_file, ptr_section, + "server_autojoin", "string", N_("comma separated list of channels to join when connected to server " "(example: \"#chan1,#chan2,#chan3 key1,key2\")"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); irc_config_server_autorejoin = weechat_config_new_option ( - ptr_section, "server_autorejoin", "string", + irc_config_file, ptr_section, + "server_autorejoin", "string", N_("automatically rejoin channels when kicked"), - NULL, 0, 0, "on", NULL); + NULL, 0, 0, "on", NULL, NULL); irc_config_server_notify_levels = weechat_config_new_option ( - ptr_section, "server_notify_levels", "string", + irc_config_file, ptr_section, + "server_notify_levels", "string", N_("comma separated list of notify levels for channels of this server " "(format: #channel:1,..), a channel name '*' is reserved for " "server default notify level"), - NULL, 0, 0, "", NULL); + NULL, 0, 0, "", NULL, NULL); return 1; } diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c index 1cd131223..95c6b8c7a 100644 --- a/src/plugins/plugin-config.c +++ b/src/plugins/plugin-config.c @@ -289,9 +289,10 @@ plugin_config_free_all () */ int -plugin_config_reload (struct t_config_file *config_file) +plugin_config_reload (void *data, struct t_config_file *config_file) { /* make C compiler happy */ + (void) data; (void) config_file; /* remove all plugin options */ @@ -309,12 +310,13 @@ plugin_config_reload (struct t_config_file *config_file) */ void -plugin_config_read_option (struct t_config_file *config_file, +plugin_config_read_option (void *data, struct t_config_file *config_file, char *option_name, char *value) { char *value2; /* make C compiler happy */ + (void) data; (void) config_file; if (option_name && value) @@ -332,11 +334,14 @@ plugin_config_read_option (struct t_config_file *config_file, */ void -plugin_config_write_options (struct t_config_file *config_file, +plugin_config_write_options (void *data, struct t_config_file *config_file, char *section_name) { struct t_config_option *ptr_option; + /* make C compiler happy */ + (void) data; + config_file_write_line (config_file, section_name, NULL); for (ptr_option = plugin_options; ptr_option; @@ -356,13 +361,13 @@ void plugin_config_init () { plugin_config = config_file_new (NULL, PLUGIN_CONFIG_FILENAME, - &plugin_config_reload); + &plugin_config_reload, NULL); if (plugin_config) { config_file_new_section (plugin_config, "plugins", - &plugin_config_read_option, - &plugin_config_write_options, - NULL); + &plugin_config_read_option, NULL, + &plugin_config_write_options, NULL, + NULL, NULL); } } 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, §ion_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, §ion, &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, §ion, &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) diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index df41fc5b9..e4d201e44 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -157,28 +157,35 @@ struct t_weechat_plugin /* config files */ struct t_config_file *(*config_new) (struct t_weechat_plugin *plugin, char *filename, - int (*callback_reload)(struct t_config_file *config_file)); + int (*callback_reload)(void *data, + struct t_config_file *config_file), + void *callback_reload_data); struct t_config_section *(*config_new_section) (struct t_config_file *config_file, char *name, - void (*callback_read) - (struct t_config_file *config_file, - char *option_name, - char *value), - void (*callback_write) - (struct t_config_file *config_file, - char *section_name), - void (*callback_write_default) - (struct t_config_file *config_file, - char *section_name)); + void (*callback_read)(void *data, + struct t_config_file *config_file, + char *option_name, + char *value), + void *callback_read_data, + void (*callback_write)(void *data, + struct t_config_file *config_file, + char *section_name), + void *callback_write_data, + void (*callback_write_default)(void *data, + struct t_config_file *config_file, + char *section_name), + void *callback_write_default_data); struct t_config_section *(*config_search_section) (struct t_config_file *config_file, char *section_name); - struct t_config_option *(*config_new_option) (struct t_config_section *config_file, + struct t_config_option *(*config_new_option) (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 (*callback_change)(void *data), + void *callback_change_data); struct t_config_option *(*config_search_option) (struct t_config_file *config_file, struct t_config_section *section, char *option_name); @@ -449,22 +456,30 @@ struct t_weechat_plugin weechat_plugin->list_free(__list) /* config files */ -#define weechat_config_new(__filename, __callback_reload) \ - weechat_plugin->config_new(weechat_plugin, __filename, \ - __callback_reload) +#define weechat_config_new(__filename, __callback_reload, \ + __callback_reload_data) \ + weechat_plugin->config_new(weechat_plugin, __filename, \ + __callback_reload, \ + __callback_reload_data) #define weechat_config_new_section(__config, __name, __cb_read, \ - __cb_write_std, __cb_write_def) \ + __cb_read_data, __cb_write_std, \ + __cb_write_std_data, __cb_write_def, \ + __cb_write_def_data) \ weechat_plugin->config_new_section(__config, __name, __cb_read, \ - __cb_write_std, __cb_write_def) + __cb_read_data, __cb_write_std, \ + __cb_write_std_data,\ + __cb_write_def, \ + __cb_write_def_data) #define weechat_config_search_section(__config, __name) \ weechat_plugin->config_search_section(__config, __name) -#define weechat_config_new_option(__section, __name, __type, __desc, \ - __string_values, __min, __max, \ - __default, __callback) \ - weechat_plugin->config_new_option(__section, __name, __type, \ - __desc, __string_values, \ +#define weechat_config_new_option(__config, __section, __name, __type, \ + __desc, __string_values, __min, \ + __max, __default, __callback, \ + __callback_data) \ + weechat_plugin->config_new_option(__config, __section, __name, \ + __type, __desc, __string_values, \ __min, __max, __default, \ - __callback) + __callback, __callback_data) #define weechat_config_search_option(__config, __section, __name) \ weechat_plugin->config_search_option(__config, __section, __name) #define weechat_config_string_to_boolean(__string) \ |