diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-01-02 23:05:23 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-01-02 23:05:23 +0100 |
commit | e7e2da5a9c469aa4291d4630adb75d1e62cccbd5 (patch) | |
tree | 60a03d40f47c8ee7b44c0d50dcdb70224592cde2 /src | |
parent | e9b7d2bc465260a06142223968db674e028ce110 (diff) | |
download | weechat-e7e2da5a9c469aa4291d4630adb75d1e62cccbd5.zip |
Add null values for options, new syntax for /set, reintroduce temporary IRC server feature, improve IRC server options, new functions in API
Diffstat (limited to 'src')
34 files changed, 3218 insertions, 2125 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index dd66b640d..fb2c1d936 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -1352,15 +1352,33 @@ command_help (void *data, struct t_gui_buffer *buffer, _("type"), _("boolean")); gui_chat_printf (NULL, " %s: on, off", _("values")); - gui_chat_printf (NULL, " %s: %s", - _("default value"), - (CONFIG_BOOLEAN_DEFAULT(ptr_option) == CONFIG_BOOLEAN_TRUE) ? - "on" : "off"); - gui_chat_printf (NULL, " %s: %s%s", - _("current value"), - GUI_COLOR(GUI_COLOR_CHAT_HOST), - (CONFIG_BOOLEAN(ptr_option) == CONFIG_BOOLEAN_TRUE) ? - "on" : "off"); + if (ptr_option->default_value) + { + gui_chat_printf (NULL, " %s: %s", + _("default value"), + (CONFIG_BOOLEAN_DEFAULT(ptr_option) == CONFIG_BOOLEAN_TRUE) ? + "on" : "off"); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("default value"), + _("(undefined)")); + } + if (ptr_option->value) + { + gui_chat_printf (NULL, " %s: %s%s", + _("current value"), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + (CONFIG_BOOLEAN(ptr_option) == CONFIG_BOOLEAN_TRUE) ? + "on" : "off"); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("current value"), + _("(undefined)")); + } break; case CONFIG_OPTION_TYPE_INTEGER: if (ptr_option->string_values) @@ -1390,15 +1408,34 @@ command_help (void *data, struct t_gui_buffer *buffer, _("type"), _("string")); gui_chat_printf (NULL, " %s: %s", _("values"), string); - gui_chat_printf (NULL, " %s: \"%s\"", - _("default value"), - ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)]); - gui_chat_printf (NULL, - " %s: \"%s%s%s\"", - _("current value"), - GUI_COLOR(GUI_COLOR_CHAT_HOST), - ptr_option->string_values[CONFIG_INTEGER(ptr_option)], - GUI_COLOR(GUI_COLOR_CHAT)); + if (ptr_option->default_value) + { + gui_chat_printf (NULL, " %s: \"%s\"", + _("default value"), + ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)]); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("default value"), + _("(undefined)")); + } + if (ptr_option->value) + { + gui_chat_printf (NULL, + " %s: \"%s%s%s\"", + _("current value"), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + ptr_option->string_values[CONFIG_INTEGER(ptr_option)], + GUI_COLOR(GUI_COLOR_CHAT)); + } + else + { + gui_chat_printf (NULL, + " %s: %s", + _("current value"), + _("(undefined)")); + } free (string); } } @@ -1409,13 +1446,31 @@ command_help (void *data, struct t_gui_buffer *buffer, gui_chat_printf (NULL, " %s: %d .. %d", _("values"), ptr_option->min, ptr_option->max); - gui_chat_printf (NULL, " %s: %d", - _("default value"), - CONFIG_INTEGER_DEFAULT(ptr_option)); - gui_chat_printf (NULL, " %s: %s%d", - _("current value"), - GUI_COLOR(GUI_COLOR_CHAT_HOST), - CONFIG_INTEGER(ptr_option)); + if (ptr_option->default_value) + { + gui_chat_printf (NULL, " %s: %d", + _("default value"), + CONFIG_INTEGER_DEFAULT(ptr_option)); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("default value"), + _("(undefined)")); + } + if (ptr_option->value) + { + gui_chat_printf (NULL, " %s: %s%d", + _("current value"), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + CONFIG_INTEGER(ptr_option)); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("current value"), + _("(undefined)")); + } } break; case CONFIG_OPTION_TYPE_STRING: @@ -1442,27 +1497,63 @@ command_help (void *data, struct t_gui_buffer *buffer, ptr_option->max); break; } - gui_chat_printf (NULL, " %s: \"%s\"", - _("default value"), - CONFIG_STRING_DEFAULT(ptr_option)); - gui_chat_printf (NULL, " %s: \"%s%s%s\"", - _("current value"), - GUI_COLOR(GUI_COLOR_CHAT_HOST), - CONFIG_STRING(ptr_option), - GUI_COLOR(GUI_COLOR_CHAT)); + if (ptr_option->default_value) + { + gui_chat_printf (NULL, " %s: \"%s\"", + _("default value"), + CONFIG_STRING_DEFAULT(ptr_option)); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("default value"), + _("(undefined)")); + } + if (ptr_option->value) + { + gui_chat_printf (NULL, " %s: \"%s%s%s\"", + _("current value"), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + CONFIG_STRING(ptr_option), + GUI_COLOR(GUI_COLOR_CHAT)); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("current value"), + _("(undefined)")); + } break; case CONFIG_OPTION_TYPE_COLOR: gui_chat_printf (NULL, " %s: %s", _("type"), _("color")); gui_chat_printf (NULL, " %s: %s", _("values"), _("a color name")); - gui_chat_printf (NULL, " %s: %s", - _("default value"), - gui_color_get_name (CONFIG_COLOR_DEFAULT(ptr_option))); - gui_chat_printf (NULL, " %s: %s%s", - _("current value"), - GUI_COLOR(GUI_COLOR_CHAT_HOST), - gui_color_get_name (CONFIG_COLOR(ptr_option))); + if (ptr_option->default_value) + { + gui_chat_printf (NULL, " %s: %s", + _("default value"), + gui_color_get_name (CONFIG_COLOR_DEFAULT(ptr_option))); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("default value"), + _("(undefined)")); + } + if (ptr_option->value) + { + gui_chat_printf (NULL, " %s: %s%s", + _("current value"), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + gui_color_get_name (CONFIG_COLOR(ptr_option))); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("current value"), + _("(undefined)")); + } break; case CONFIG_NUM_OPTION_TYPES: break; @@ -2634,23 +2725,12 @@ command_set_display_option (struct t_config_option *option, const char *message) { const char *color_name; - - switch (option->type) + + if (option->value) { - case CONFIG_OPTION_TYPE_BOOLEAN: - gui_chat_printf (NULL, "%s%s.%s.%s%s = %s%s", - (message) ? message : " ", - option->config_file->name, - option->section->name, - option->name, - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), - GUI_COLOR(GUI_COLOR_CHAT_HOST), - (CONFIG_BOOLEAN(option) == CONFIG_BOOLEAN_TRUE) ? - "on" : "off"); - break; - case CONFIG_OPTION_TYPE_INTEGER: - if (option->string_values) - { + switch (option->type) + { + case CONFIG_OPTION_TYPE_BOOLEAN: gui_chat_printf (NULL, "%s%s.%s.%s%s = %s%s", (message) ? message : " ", option->config_file->name, @@ -2658,45 +2738,67 @@ command_set_display_option (struct t_config_option *option, option->name, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT_HOST), - option->string_values[CONFIG_INTEGER(option)]); - } - else - { - gui_chat_printf (NULL, "%s%s.%s.%s%s = %s%d", + (CONFIG_BOOLEAN(option) == CONFIG_BOOLEAN_TRUE) ? + "on" : "off"); + break; + case CONFIG_OPTION_TYPE_INTEGER: + if (option->string_values) + { + gui_chat_printf (NULL, "%s%s.%s.%s%s = %s%s", + (message) ? message : " ", + option->config_file->name, + option->section->name, + option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + option->string_values[CONFIG_INTEGER(option)]); + } + else + { + gui_chat_printf (NULL, "%s%s.%s.%s%s = %s%d", + (message) ? message : " ", + option->config_file->name, + option->section->name, + option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + CONFIG_INTEGER(option)); + } + break; + case CONFIG_OPTION_TYPE_STRING: + gui_chat_printf (NULL, "%s%s.%s.%s%s = \"%s%s%s\"", (message) ? message : " ", option->config_file->name, option->section->name, option->name, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT_HOST), - CONFIG_INTEGER(option)); - } - break; - case CONFIG_OPTION_TYPE_STRING: - gui_chat_printf (NULL, "%s%s.%s.%s%s = \"%s%s%s\"", - (message) ? message : " ", - option->config_file->name, - option->section->name, - option->name, - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), - GUI_COLOR(GUI_COLOR_CHAT_HOST), - (option->value) ? CONFIG_STRING(option) : "", - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); - break; - case CONFIG_OPTION_TYPE_COLOR: - color_name = gui_color_get_name (CONFIG_COLOR(option)); - gui_chat_printf (NULL, "%s%s.%s.%s%s = %s%s", - (message) ? message : " ", - option->config_file->name, - option->section->name, - option->name, - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), - GUI_COLOR(GUI_COLOR_CHAT_HOST), - (color_name) ? color_name : _("(unknown)")); - break; - case CONFIG_NUM_OPTION_TYPES: - /* make C compiler happy */ - break; + CONFIG_STRING(option), + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); + break; + case CONFIG_OPTION_TYPE_COLOR: + color_name = gui_color_get_name (CONFIG_COLOR(option)); + gui_chat_printf (NULL, "%s%s.%s.%s%s = %s%s", + (message) ? message : " ", + option->config_file->name, + option->section->name, + option->name, + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT_HOST), + (color_name) ? color_name : _("(unknown)")); + break; + case CONFIG_NUM_OPTION_TYPES: + /* make C compiler happy */ + break; + } + } + else + { + gui_chat_printf (NULL, "%s%s.%s.%s", + (message) ? message : " ", + option->config_file->name, + option->section->name, + option->name); } } @@ -2823,38 +2925,35 @@ command_set (void *data, struct t_gui_buffer *buffer, } /* set option value */ - if ((argc >= 4) && (string_strcasecmp (argv[2], "=") == 0)) - { - value = string_remove_quotes (argv_eol[3], "'\""); - rc = config_file_option_set_with_string (argv[1], - (value) ? value : argv_eol[3]); - if (value) - free (value); - switch (rc) - { - case WEECHAT_CONFIG_OPTION_SET_ERROR: - gui_chat_printf (NULL, - _("%sError: failed to set option \"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[1]); - return WEECHAT_RC_ERROR; - case WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND: - gui_chat_printf (NULL, - _("%sError: configuration option \"%s\" not " - "found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[1]); - return WEECHAT_RC_ERROR; - default: - config_file_search_with_string (argv[1], NULL, NULL, - &ptr_option, NULL); - if (ptr_option) - command_set_display_option (ptr_option, - _("Option changed: ")); - else - gui_chat_printf (NULL, _("Option changed")); - break; - } + value =(string_strcasecmp (argv_eol[2], WEECHAT_CONFIG_OPTION_NULL) == 0) ? + NULL : string_remove_quotes (argv_eol[2], "'\""); + rc = config_file_option_set_with_string (argv[1], value); + if (value) + free (value); + switch (rc) + { + case WEECHAT_CONFIG_OPTION_SET_ERROR: + gui_chat_printf (NULL, + _("%sError: failed to set option \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[1]); + return WEECHAT_RC_ERROR; + case WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND: + gui_chat_printf (NULL, + _("%sError: configuration option \"%s\" not " + "found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[1]); + return WEECHAT_RC_ERROR; + default: + config_file_search_with_string (argv[1], NULL, NULL, + &ptr_option, NULL); + if (ptr_option) + command_set_display_option (ptr_option, + _("Option changed: ")); + else + gui_chat_printf (NULL, _("Option changed")); + break; } return WEECHAT_RC_OK; @@ -3659,10 +3758,18 @@ command_init () &command_save, NULL); hook_command (NULL, "set", N_("set config options"), - N_("[option [ = value]]"), + N_("[option [value]]"), N_("option: name of an option\n" - " value: value for option"), - "%o = %v", + " value: new value for option\n\n" + "New value can be, according to variable type:\n" + " boolean: on, off ou toggle\n" + " integer: number, ++number ou --number" + " string : any string (\"\" for empty string)\n" + " color : color name, ++number ou --number\n\n" + "For all types, you can use null to remove " + "option value (undefined value). This works only " + "for some special plugin variables."), + "%o %v", &command_set, NULL); hook_command (NULL, "unset", N_("unset/reset config options"), diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 676429ce2..b770dc66e 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* wee-config-file.c: manages options in config files */ +/* wee-config-file.c: manages options in configuration files */ #ifdef HAVE_CONFIG_H @@ -74,7 +74,7 @@ config_file_search (const char *name) } /* - * config_file_new: create new config options structure + * config_file_new: create new configuration options structure */ struct t_config_file * @@ -90,7 +90,7 @@ config_file_new (struct t_weechat_plugin *plugin, const char *name, if (!name) return NULL; - /* it's NOT authorized to create two config files with same filename */ + /* it's NOT authorized to create two configuration files with same filename */ if (config_file_search (name)) return NULL; @@ -224,7 +224,7 @@ config_file_new_section (struct t_config_file *config_file, const char *name, } /* - * config_file_search_section: search a section in a config structure + * config_file_search_section: search a section in a configuration structure */ struct t_config_section * @@ -357,6 +357,7 @@ config_file_new_option (struct t_config_file *config_file, const char *string_values, int min, int max, const char *default_value, const char *value, + int null_value_allowed, int (*callback_check_value)(void *data, struct t_config_option *option, const char *value), @@ -397,10 +398,15 @@ config_file_new_option (struct t_config_file *config_file, return NULL; } - if (default_value && !value) - value = default_value; - else if (!default_value && value) - default_value = value; + if (!null_value_allowed) + { + if (default_value && !value) + value = default_value; + else if (!default_value && value) + default_value = value; + if (!default_value || !value) + return NULL; + } new_option = malloc (sizeof (*new_option)); if (new_option) @@ -410,6 +416,8 @@ config_file_new_option (struct t_config_file *config_file, new_option->name = strdup (name); new_option->type = var_type; new_option->description = (description) ? strdup (description) : NULL; + new_option->default_value = NULL; + new_option->value = NULL; argc = 0; switch (var_type) { @@ -417,12 +425,18 @@ config_file_new_option (struct t_config_file *config_file, new_option->string_values = NULL; new_option->min = CONFIG_BOOLEAN_FALSE; new_option->max = CONFIG_BOOLEAN_TRUE; - int_value = config_file_string_to_boolean (default_value); - new_option->default_value = malloc (sizeof (int)); - *((int *)new_option->default_value) = int_value; - int_value = config_file_string_to_boolean (value); - new_option->value = malloc (sizeof (int)); - *((int *)new_option->value) = int_value; + if (default_value) + { + int_value = config_file_string_to_boolean (default_value); + new_option->default_value = malloc (sizeof (int)); + *((int *)new_option->default_value) = int_value; + } + if (value) + { + int_value = config_file_string_to_boolean (value); + new_option->value = malloc (sizeof (int)); + *((int *)new_option->value) = int_value; + } break; case CONFIG_OPTION_TYPE_INTEGER: new_option->string_values = (string_values) ? @@ -431,81 +445,106 @@ config_file_new_option (struct t_config_file *config_file, { new_option->min = 0; new_option->max = (argc == 0) ? 0 : argc - 1; - index_value = 0; - for (i = 0; i < argc; i++) + if (default_value) { - if (string_strcasecmp (new_option->string_values[i], - default_value) == 0) + index_value = 0; + for (i = 0; i < argc; i++) { - index_value = i; - break; + if (string_strcasecmp (new_option->string_values[i], + default_value) == 0) + { + index_value = i; + break; + } } + new_option->default_value = malloc (sizeof (int)); + *((int *)new_option->default_value) = index_value; } - new_option->default_value = malloc (sizeof (int)); - *((int *)new_option->default_value) = index_value; - index_value = 0; - for (i = 0; i < argc; i++) + if (value) { - if (string_strcasecmp (new_option->string_values[i], - value) == 0) + index_value = 0; + for (i = 0; i < argc; i++) { - index_value = i; - break; + if (string_strcasecmp (new_option->string_values[i], + value) == 0) + { + index_value = i; + break; + } } + new_option->value = malloc (sizeof (int)); + *((int *)new_option->value) = index_value; } - new_option->value = malloc (sizeof (int)); - *((int *)new_option->value) = index_value; } else { new_option->string_values = NULL; new_option->min = min; new_option->max = max; - error = NULL; - number = strtol (default_value, &error, 10); - if (!error || error[0]) - number = 0; - if (number < min) - number = min; - else if (number > max) - number = max; - new_option->default_value = malloc (sizeof (int)); - *((int *)new_option->default_value) = number; - error = NULL; - number = strtol (value, &error, 10); - if (!error || error[0]) - number = 0; - if (number < min) - number = min; - else if (number > max) - number = max; - new_option->value = malloc (sizeof (int)); - *((int *)new_option->value) = number; + if (default_value) + { + error = NULL; + number = strtol (default_value, &error, 10); + if (!error || error[0]) + number = 0; + if (number < min) + number = min; + else if (number > max) + number = max; + new_option->default_value = malloc (sizeof (int)); + *((int *)new_option->default_value) = number; + } + if (value) + { + error = NULL; + number = strtol (value, &error, 10); + if (!error || error[0]) + number = 0; + if (number < min) + number = min; + else if (number > max) + number = max; + new_option->value = malloc (sizeof (int)); + *((int *)new_option->value) = number; + } } break; case CONFIG_OPTION_TYPE_STRING: new_option->string_values = NULL; new_option->min = min; new_option->max = max; - new_option->default_value = (default_value) ? - strdup (default_value) : NULL; - new_option->value = (value) ? - strdup (value) : NULL; + if (default_value) + { + new_option->default_value = (default_value) ? + strdup (default_value) : NULL; + } + if (value) + { + new_option->value = (value) ? + strdup (value) : NULL; + } break; case CONFIG_OPTION_TYPE_COLOR: new_option->string_values = NULL; new_option->min = min; new_option->max = gui_color_get_number () - 1; - new_option->default_value = malloc (sizeof (int)); - if (!gui_color_assign (new_option->default_value, default_value)) - *((int *)new_option->default_value) = 0; - new_option->value = malloc (sizeof (int)); - if (!gui_color_assign (new_option->value, value)) - *((int *)new_option->value) = 0; + if (default_value) + { + new_option->default_value = malloc (sizeof (int)); + if (!gui_color_assign (new_option->default_value, default_value)) + *((int *)new_option->default_value) = 0; + } + if (value) + { + new_option->value = malloc (sizeof (int)); + if (!gui_color_assign (new_option->value, value)) + *((int *)new_option->value) = 0; + } break; case CONFIG_NUM_OPTION_TYPES: break; } + new_option->null_value_allowed = null_value_allowed; new_option->callback_check_value = callback_check_value; new_option->callback_check_value_data = callback_check_value_data; new_option->callback_change = callback_change; @@ -554,7 +593,7 @@ config_file_option_full_name (struct t_config_option *option) } /* - * config_file_search_option: search an option in a config or section + * config_file_search_option: search an option in a configuration file or section */ struct t_config_option * @@ -593,8 +632,8 @@ config_file_search_option (struct t_config_file *config_file, } /* - * config_file_search_section_option: search an option in a config or section - * and return section/option + * config_file_search_section_option: search an option in a configuration file + * or section and return section/option */ void @@ -813,7 +852,7 @@ config_file_string_to_boolean (const char *text) int config_file_option_reset (struct t_config_option *option, int run_callback) { - int rc; + int rc, old_value_was_null; char value[256], *option_full_name; if (!option) @@ -821,43 +860,63 @@ config_file_option_reset (struct t_config_option *option, int run_callback) rc = WEECHAT_CONFIG_OPTION_SET_ERROR; value[0] = '\0'; - - switch (option->type) + + if (option->default_value) { - case CONFIG_OPTION_TYPE_BOOLEAN: - if (CONFIG_BOOLEAN(option) == CONFIG_BOOLEAN_DEFAULT(option)) - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - else - { - CONFIG_BOOLEAN(option) = CONFIG_BOOLEAN_DEFAULT(option); - snprintf (value, sizeof (value), "%s", - CONFIG_BOOLEAN(option) ? - config_boolean_true[0] : config_boolean_false[0]); - rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; - } - break; - case CONFIG_OPTION_TYPE_INTEGER: - if (CONFIG_INTEGER(option) == CONFIG_INTEGER_DEFAULT(option)) + old_value_was_null = (option->value == NULL); + switch (option->type) + { + case CONFIG_OPTION_TYPE_BOOLEAN: + if (!option->value) + { + option->value = malloc (sizeof (int)); + CONFIG_BOOLEAN(option) = CONFIG_BOOLEAN_DEFAULT(option); + snprintf (value, sizeof (value), "%s", + CONFIG_BOOLEAN(option) ? + config_boolean_true[0] : config_boolean_false[0]); + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + else + { + if (CONFIG_BOOLEAN(option) == CONFIG_BOOLEAN_DEFAULT(option)) + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + else + { + CONFIG_BOOLEAN(option) = CONFIG_BOOLEAN_DEFAULT(option); + snprintf (value, sizeof (value), "%s", + CONFIG_BOOLEAN(option) ? + config_boolean_true[0] : config_boolean_false[0]); + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + } + break; + case CONFIG_OPTION_TYPE_INTEGER: + if (!option->value) + { + option->value = malloc (sizeof (int)); + CONFIG_INTEGER(option) = 0; + } + if (CONFIG_INTEGER(option) == CONFIG_INTEGER_DEFAULT(option)) + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + else + { + CONFIG_INTEGER(option) = CONFIG_INTEGER_DEFAULT(option); + snprintf (value, sizeof (value), "%d", + CONFIG_INTEGER(option)); + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + break; + case CONFIG_OPTION_TYPE_STRING: rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - else - { - CONFIG_INTEGER(option) = CONFIG_INTEGER_DEFAULT(option); - snprintf (value, sizeof (value), "%d", - CONFIG_INTEGER(option)); - rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; - } - break; - case CONFIG_OPTION_TYPE_STRING: - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - if ((!option->value && option->default_value) - || (option->value && !option->default_value) - || (strcmp ((char *)option->value, - (char *)option->default_value) != 0)) - rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; - if (option->value) - free (option->value); - if (option->default_value) - { + if (!option->value + || (strcmp ((char *)option->value, + (char *)option->default_value) != 0)) + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + if (option->value) + { + free (option->value); + option->value = NULL; + } option->value = strdup ((char *)option->default_value); if (option->value) { @@ -866,23 +925,42 @@ config_file_option_reset (struct t_config_option *option, int run_callback) } else rc = WEECHAT_CONFIG_OPTION_SET_ERROR; - } - else - option->value = NULL; - break; - case CONFIG_OPTION_TYPE_COLOR: - if (CONFIG_COLOR(option) == CONFIG_COLOR_DEFAULT(option)) - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - else + break; + case CONFIG_OPTION_TYPE_COLOR: + if (!option->value) + { + option->value = malloc (sizeof (int)); + CONFIG_INTEGER(option) = 0; + } + if (CONFIG_COLOR(option) == CONFIG_COLOR_DEFAULT(option)) + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + else + { + CONFIG_COLOR(option) = CONFIG_COLOR_DEFAULT(option); + snprintf (value, sizeof (value), "%d", + CONFIG_COLOR(option)); + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + break; + case CONFIG_NUM_OPTION_TYPES: + break; + } + if (old_value_was_null && option->value) + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + else + { + if (option->null_value_allowed) + { + if (option->value) { - CONFIG_COLOR(option) = CONFIG_COLOR_DEFAULT(option); - snprintf (value, sizeof (value), "%d", - CONFIG_COLOR(option)); + free (option->value); + option->value = NULL; rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } - break; - case CONFIG_NUM_OPTION_TYPES: - break; + else + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } } if ((rc == WEECHAT_CONFIG_OPTION_SET_OK_CHANGED) @@ -909,7 +987,6 @@ config_file_option_reset (struct t_config_option *option, int run_callback) /* * config_file_option_set: set value for an option - * if value is NULL, then default value for option is set * return one of these values: * WEECHAT_CONFIG_OPTION_SET_OK_CHANGED * WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE @@ -920,7 +997,7 @@ int config_file_option_set (struct t_config_option *option, const char *value, int run_callback) { - int value_int, i, rc, new_value_ok; + int value_int, i, rc, new_value_ok, old_value_was_null; long number; char *error, *option_full_name; @@ -929,7 +1006,7 @@ config_file_option_set (struct t_config_option *option, const char *value, rc = WEECHAT_CONFIG_OPTION_SET_ERROR; - if (value && option->callback_check_value) + if (option->callback_check_value) { if (!(int)(option->callback_check_value) (option->callback_check_value_data, @@ -938,37 +1015,58 @@ config_file_option_set (struct t_config_option *option, const char *value, return WEECHAT_CONFIG_OPTION_SET_ERROR; } - switch (option->type) + if (value) { - case CONFIG_OPTION_TYPE_BOOLEAN: - if (value) - { - if (string_strcasecmp (value, "toggle") == 0) + old_value_was_null = (option->value == NULL); + switch (option->type) + { + case CONFIG_OPTION_TYPE_BOOLEAN: + if (!option->value) { - *((int *)option->value) = - (*((int *)option->value) == CONFIG_BOOLEAN_TRUE) ? - CONFIG_BOOLEAN_FALSE : CONFIG_BOOLEAN_TRUE; + option->value = malloc (sizeof (int)); + if (string_strcasecmp (value, "toggle") == 0) + CONFIG_BOOLEAN(option) = CONFIG_BOOLEAN_TRUE; + else + { + if (config_file_string_boolean_is_valid (value)) + { + value_int = config_file_string_to_boolean (value); + CONFIG_BOOLEAN(option) = value_int; + } + } rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } else { - if (config_file_string_boolean_is_valid (value)) + if (string_strcasecmp (value, "toggle") == 0) { - value_int = config_file_string_to_boolean (value); - if (value_int == *((int *)option->value)) - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - else + CONFIG_BOOLEAN(option) = + (CONFIG_BOOLEAN(option) == CONFIG_BOOLEAN_TRUE) ? + CONFIG_BOOLEAN_FALSE : CONFIG_BOOLEAN_TRUE; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + else + { + if (config_file_string_boolean_is_valid (value)) { - *((int *)option->value) = value_int; - rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + value_int = config_file_string_to_boolean (value); + if (value_int == CONFIG_BOOLEAN(option)) + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + else + { + CONFIG_BOOLEAN(option) = value_int; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } } } } - } - break; - case CONFIG_OPTION_TYPE_INTEGER: - if (value) - { + break; + case CONFIG_OPTION_TYPE_INTEGER: + if (!option->value) + { + option->value = malloc (sizeof (int)); + CONFIG_INTEGER(option) = 0; + } if (option->string_values) { value_int = -1; @@ -979,7 +1077,7 @@ config_file_option_set (struct t_config_option *option, const char *value, if (error && !error[0]) { number = number % (option->max + 1); - value_int = (*((int *)option->value) + number) % + value_int = (CONFIG_INTEGER(option) + number) % (option->max + 1); } } @@ -990,7 +1088,7 @@ config_file_option_set (struct t_config_option *option, const char *value, if (error && !error[0]) { number = number % (option->max + 1); - value_int = (*((int *)option->value) + (option->max + 1) - number) % + value_int = (CONFIG_INTEGER(option) + (option->max + 1) - number) % (option->max + 1); } } @@ -1008,11 +1106,11 @@ config_file_option_set (struct t_config_option *option, const char *value, } if (value_int >= 0) { - if (value_int == *((int *)option->value)) + if (value_int == CONFIG_INTEGER(option)) rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; else { - *((int *)option->value) = value_int; + CONFIG_INTEGER(option) = value_int; rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } } @@ -1026,7 +1124,7 @@ config_file_option_set (struct t_config_option *option, const char *value, number = strtol (value + 2, &error, 10); if (error && !error[0]) { - value_int = *((int *)option->value) + number; + value_int = CONFIG_INTEGER(option) + number; if (value_int <= option->max) new_value_ok = 1; } @@ -1037,7 +1135,7 @@ config_file_option_set (struct t_config_option *option, const char *value, number = strtol (value + 2, &error, 10); if (error && !error[0]) { - value_int = *((int *)option->value) - number; + value_int = CONFIG_INTEGER(option) - number; if (value_int >= option->min) new_value_ok = 1; } @@ -1056,83 +1154,100 @@ config_file_option_set (struct t_config_option *option, const char *value, } if (new_value_ok) { - if (value_int == *((int *)option->value)) + if (value_int == CONFIG_INTEGER(option)) rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; else { - *((int *)option->value) = value_int; + CONFIG_INTEGER(option) = value_int; rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } } } - } - break; - case CONFIG_OPTION_TYPE_STRING: - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - if ((!option->value && value) - || (option->value && !value) - || (strcmp ((char *)option->value, value) != 0)) - rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; - if (option->value) - free (option->value); - if (value) - { + break; + case CONFIG_OPTION_TYPE_STRING: + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + if (!option->value + || (strcmp (CONFIG_STRING(option), value) != 0)) + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + if (option->value) + { + free (option->value); + option->value = NULL; + } option->value = strdup (value); if (!option->value) rc = WEECHAT_CONFIG_OPTION_SET_ERROR; - } - else - option->value = NULL; - break; - case CONFIG_OPTION_TYPE_COLOR: - value_int = -1; - if (strncmp (value, "++", 2) == 0) - { - error = NULL; - number = strtol (value + 2, &error, 10); - if (error && !error[0]) + break; + case CONFIG_OPTION_TYPE_COLOR: + if (!option->value) { - number = number % (option->max + 1); - value_int = (*((int *)option->value) + number) % - (option->max + 1); + option->value = malloc (sizeof (int)); + CONFIG_COLOR(option) = 0; } - } - else if (strncmp (value, "--", 2) == 0) - { - error = NULL; - number = strtol (value + 2, &error, 10); - if (error && !error[0]) + value_int = -1; + if (strncmp (value, "++", 2) == 0) { - number = number % (option->max + 1); - value_int = (*((int *)option->value) + (option->max + 1) - number) % - (option->max + 1); + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + number = number % (option->max + 1); + value_int = (CONFIG_COLOR(option) + number) % + (option->max + 1); + } + } + else if (strncmp (value, "--", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + number = number % (option->max + 1); + value_int = (CONFIG_COLOR(option) + (option->max + 1) - number) % + (option->max + 1); + } } - } - else - { - gui_color_assign (&value_int, value); - } - if (value_int >= 0) - { - if (value_int == *((int *)option->value)) - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; else { - *((int *)option->value) = value_int; - rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + gui_color_assign (&value_int, value); } - } - break; - case CONFIG_NUM_OPTION_TYPES: - break; + if (value_int >= 0) + { + if (value_int == CONFIG_COLOR(option)) + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + else + { + CONFIG_COLOR(option) = value_int; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + } + break; + case CONFIG_NUM_OPTION_TYPES: + break; + } + if (old_value_was_null && option->value) + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + else + { + if (option->null_value_allowed && option->value) + { + free (option->value); + option->value = NULL; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + else + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } + /* run callback if asked and value was changed */ if ((rc == WEECHAT_CONFIG_OPTION_SET_OK_CHANGED) && run_callback && option->callback_change) { (void)(option->callback_change)(option->callback_change_data, option); } + /* run config hook(s) */ if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR) { if (option->config_file && option->section) @@ -1150,6 +1265,61 @@ config_file_option_set (struct t_config_option *option, const char *value, } /* + * config_file_option_set_null: set null (undefined) value for an option + * return one of these values: + * WEECHAT_CONFIG_OPTION_SET_OK_CHANGED + * WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE + * WEECHAT_CONFIG_OPTION_SET_ERROR + */ + +int +config_file_option_set_null (struct t_config_option *option, int run_callback) +{ + int rc; + char *option_full_name; + + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; + + /* null value is authorized only if it's allowed in option */ + if (option->null_value_allowed) + { + /* option was already null: do nothing */ + if (!option->value) + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + else + { + /* set option to null */ + free (option->value); + option->value = NULL; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + } + + /* run callback if asked and value was changed */ + if ((rc == WEECHAT_CONFIG_OPTION_SET_OK_CHANGED) + && run_callback && option->callback_change) + { + (void)(option->callback_change)(option->callback_change_data, option); + } + + /* run config hook(s) */ + if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR) + { + if (option->config_file && option->section) + { + option_full_name = config_file_option_full_name (option); + if (option_full_name) + { + hook_config_exec (option_full_name, NULL); + free (option_full_name); + } + } + } + + return rc; +} + +/* * config_file_option_unset: unset/reset option * return one of these values: * WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET @@ -1226,7 +1396,8 @@ void config_file_option_rename (struct t_config_option *option, const char *new_name) { - if (!new_name || !new_name[0]) + if (!new_name || !new_name[0] + || config_file_search_option (option->config_file, option->section, new_name)) return; /* remove option from list */ @@ -1289,6 +1460,34 @@ config_file_option_get_pointer (struct t_config_option *option, } /* + * config_file_option_is_null: return 1 if value of option is null + * 0 if it is not null + */ + +int +config_file_option_is_null (struct t_config_option *option) +{ + if (!option) + return 1; + + return (option->value) ? 0 : 1; +} + +/* + * config_file_option_default_is_null: return 1 if default value of option is null + * 0 if it is not null + */ + +int +config_file_option_default_is_null (struct t_config_option *option) +{ + if (!option) + return 1; + + return (option->default_value) ? 0 : 1; +} + +/* * config_file_option_set_with_string: set value for an option (with a string * for name of option) * return one of these values: @@ -1315,7 +1514,11 @@ config_file_option_set_with_string (const char *option_name, const char *value) if (ptr_config && ptr_section) { if (ptr_option) - rc = config_file_option_set (ptr_option, value, 1); + { + rc = (value) ? + config_file_option_set (ptr_option, value, 1) : + config_file_option_set_null (ptr_option, 1); + } else { if (ptr_section->user_can_add_options @@ -1381,6 +1584,22 @@ config_file_option_boolean (struct t_config_option *option) } /* + * config_file_option_boolean_default: return default boolean value of an option + */ + +int +config_file_option_boolean_default (struct t_config_option *option) +{ + if (!option) + return 0; + + if (option->type == CONFIG_OPTION_TYPE_BOOLEAN) + return CONFIG_BOOLEAN_DEFAULT(option); + else + return 0; +} + +/* * config_file_option_integer: return integer value of an option */ @@ -1409,6 +1628,34 @@ config_file_option_integer (struct t_config_option *option) } /* + * config_file_option_integer_default: return default integer value of an option + */ + +int +config_file_option_integer_default (struct t_config_option *option) +{ + if (!option) + return 0; + + switch (option->type) + { + case CONFIG_OPTION_TYPE_BOOLEAN: + if (CONFIG_BOOLEAN_DEFAULT(option) == CONFIG_BOOLEAN_TRUE) + return 1; + else + return 0; + case CONFIG_OPTION_TYPE_INTEGER: + case CONFIG_OPTION_TYPE_COLOR: + return CONFIG_INTEGER_DEFAULT(option); + case CONFIG_OPTION_TYPE_STRING: + return 0; + case CONFIG_NUM_OPTION_TYPES: + break; + } + return 0; +} + +/* * config_file_option_string: return string value of an option */ @@ -1440,6 +1687,37 @@ config_file_option_string (struct t_config_option *option) } /* + * config_file_option_string_default: return default string value of an option + */ + +const char * +config_file_option_string_default (struct t_config_option *option) +{ + if (!option) + return NULL; + + switch (option->type) + { + case CONFIG_OPTION_TYPE_BOOLEAN: + if (CONFIG_BOOLEAN_DEFAULT(option)) + return config_boolean_true[0]; + else + return config_boolean_false[0]; + case CONFIG_OPTION_TYPE_INTEGER: + if (option->string_values) + return option->string_values[CONFIG_INTEGER_DEFAULT(option)]; + return NULL; + case CONFIG_OPTION_TYPE_STRING: + return CONFIG_STRING_DEFAULT(option); + case CONFIG_OPTION_TYPE_COLOR: + return gui_color_get_name (CONFIG_COLOR_DEFAULT(option)); + case CONFIG_NUM_OPTION_TYPES: + return NULL; + } + return NULL; +} + +/* * config_file_option_color: return color value of an option */ @@ -1453,7 +1731,20 @@ config_file_option_color (struct t_config_option *option) } /* - * config_file_write_option: write an option in a config file + * config_file_option_color_default: return default color value of an option + */ + +const char * +config_file_option_color_default (struct t_config_option *option) +{ + if (!option) + return NULL; + + return gui_color_get_name (CONFIG_COLOR_DEFAULT(option)); +} + +/* + * config_file_write_option: write an option in a configuration file */ void @@ -1462,42 +1753,50 @@ config_file_write_option (struct t_config_file *config_file, { if (!config_file || !config_file->file || !option) return; - - switch (option->type) + + if (option->value) { - case CONFIG_OPTION_TYPE_BOOLEAN: - string_iconv_fprintf (config_file->file, "%s = %s\n", - option->name, - (*((int *)option->value)) == CONFIG_BOOLEAN_TRUE ? - "on" : "off"); - break; - case CONFIG_OPTION_TYPE_INTEGER: - if (option->string_values) + switch (option->type) + { + case CONFIG_OPTION_TYPE_BOOLEAN: string_iconv_fprintf (config_file->file, "%s = %s\n", option->name, - option->string_values[*((int *)option->value)]); - else - string_iconv_fprintf (config_file->file, "%s = %d\n", + (*((int *)option->value)) == CONFIG_BOOLEAN_TRUE ? + "on" : "off"); + break; + case CONFIG_OPTION_TYPE_INTEGER: + if (option->string_values) + string_iconv_fprintf (config_file->file, "%s = %s\n", + option->name, + option->string_values[*((int *)option->value)]); + else + string_iconv_fprintf (config_file->file, "%s = %d\n", + option->name, + *((int *)option->value)); + break; + case CONFIG_OPTION_TYPE_STRING: + string_iconv_fprintf (config_file->file, "%s = \"%s\"\n", option->name, - *((int *)option->value)); - break; - case CONFIG_OPTION_TYPE_STRING: - string_iconv_fprintf (config_file->file, "%s = \"%s\"\n", - option->name, - (char *)option->value); - break; - case CONFIG_OPTION_TYPE_COLOR: - string_iconv_fprintf (config_file->file, "%s = %s\n", - option->name, - gui_color_get_name (*((int *)option->value))); - break; - case CONFIG_NUM_OPTION_TYPES: - break; + (char *)option->value); + break; + case CONFIG_OPTION_TYPE_COLOR: + string_iconv_fprintf (config_file->file, "%s = %s\n", + option->name, + gui_color_get_name (*((int *)option->value))); + break; + case CONFIG_NUM_OPTION_TYPES: + break; + } + } + else + { + string_iconv_fprintf (config_file->file, "%s\n", + option->name); } } /* - * config_file_write_line: write a line in a config file + * config_file_write_line: write a line in a configuration file * if value is NULL, then write a section with [ ] around */ @@ -1670,7 +1969,7 @@ config_file_write (struct t_config_file *config_file) int config_file_read_internal (struct t_config_file *config_file, int reload) { - int filename_length, line_number, rc; + int filename_length, line_number, rc, undefined_value; char *filename; struct t_config_section *ptr_section; struct t_config_option *ptr_option; @@ -1694,7 +1993,7 @@ config_file_read_internal (struct t_config_file *config_file, int reload) if (!config_file->file) { gui_chat_printf (NULL, - _("%sWarning: config file \"%s\" not found"), + _("%sWarning: configuration file \"%s\" not found"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], filename); free (filename); @@ -1760,22 +2059,24 @@ config_file_read_internal (struct t_config_file *config_file, int reload) } else { - pos = strstr (line, " = "); - if (!pos) - { - gui_chat_printf (NULL, - _("%sWarning: %s, line %d: invalid " - "syntax, missing \"=\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - filename, line_number); - } - else + undefined_value = 1; + + /* remove CR/LF */ + pos = strchr (line, '\r'); + if (pos != NULL) + pos[0] = '\0'; + pos = strchr (line, '\n'); + if (pos != NULL) + pos[0] = '\0'; + + pos = strstr (line, " ="); + if (pos) { pos[0] = '\0'; - pos += 3; + pos += 2; /* remove spaces before '=' */ - pos2 = pos - 4; + pos2 = pos - 3; while ((pos2 > line) && (pos2[0] == ' ')) { pos2[0] = '\0'; @@ -1788,101 +2089,100 @@ config_file_read_internal (struct t_config_file *config_file, int reload) pos++; } - /* remove CR/LF */ - pos2 = strchr (pos, '\r'); - if (pos2 != NULL) - pos2[0] = '\0'; - pos2 = strchr (pos, '\n'); - if (pos2 != NULL) - pos2[0] = '\0'; - - /* remove simple or double quotes - and spaces at the end */ - if (strlen(pos) > 1) + if (pos[0] + && string_strcasecmp (pos, WEECHAT_CONFIG_OPTION_NULL) != 0) { - pos2 = pos + strlen (pos) - 1; - while ((pos2 > pos) && (pos2[0] == ' ')) - { - pos2[0] = '\0'; - pos2--; - } - pos2 = pos + strlen (pos) - 1; - if (((pos[0] == '\'') && - (pos2[0] == '\'')) || - ((pos[0] == '"') && - (pos2[0] == '"'))) + undefined_value = 0; + /* remove simple or double quotes and spaces at the end */ + if (strlen(pos) > 1) { - pos2[0] = '\0'; - pos++; + pos2 = pos + strlen (pos) - 1; + while ((pos2 > pos) && (pos2[0] == ' ')) + { + pos2[0] = '\0'; + pos2--; + } + pos2 = pos + strlen (pos) - 1; + if (((pos[0] == '\'') && + (pos2[0] == '\'')) || + ((pos[0] == '"') && + (pos2[0] == '"'))) + { + pos2[0] = '\0'; + pos++; + } } } - - if (ptr_section && ptr_section->callback_read) + } + + if (ptr_section && ptr_section->callback_read) + { + ptr_option = NULL; + rc = (ptr_section->callback_read) + (ptr_section->callback_read_data, + config_file, + ptr_section, + line, + (undefined_value) ? NULL : pos); + } + else + { + rc = WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND; + ptr_option = config_file_search_option (config_file, + ptr_section, + line); + if (ptr_option) { - ptr_option = NULL; - rc = (ptr_section->callback_read) - (ptr_section->callback_read_data, - config_file, - ptr_section, - line, - pos); + rc = config_file_option_set (ptr_option, + (undefined_value) ? + NULL : pos, + 1); + ptr_option->loaded = 1; } else { - rc = WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND; - ptr_option = config_file_search_option (config_file, - ptr_section, - line); - if (ptr_option) + if (ptr_section + && ptr_section->callback_create_option) { - rc = config_file_option_set (ptr_option, pos, 1); - ptr_option->loaded = 1; - } - else - { - if (ptr_section - && ptr_section->callback_create_option) - { - rc = (int)(ptr_section->callback_create_option) - (ptr_section->callback_create_option_data, - config_file, - ptr_section, - line, - pos); - } + rc = (int)(ptr_section->callback_create_option) + (ptr_section->callback_create_option_data, + config_file, + ptr_section, + line, + (undefined_value) ? NULL : pos); } } - - switch (rc) - { - case WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND: - if (ptr_section) - gui_chat_printf (NULL, - _("%sWarning: %s, line %d: " - "option \"%s\" " - "unknown for " - "section \"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - filename, line_number, - line, ptr_section->name); - else - gui_chat_printf (NULL, - _("%sWarning: %s, line %d: " - "unknown option \"%s\" " - "(outside a section)"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - filename, line_number, - line); - break; - case WEECHAT_CONFIG_OPTION_SET_ERROR: + } + + switch (rc) + { + case WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND: + if (ptr_section) gui_chat_printf (NULL, _("%sWarning: %s, line %d: " - "invalid value for option " - "\"%s\""), + "option \"%s\" " + "unknown for " + "section \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - filename, line_number, line); - break; - } + filename, line_number, + line, ptr_section->name); + else + gui_chat_printf (NULL, + _("%sWarning: %s, line %d: " + "unknown option \"%s\" " + "(outside a section)"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + filename, line_number, + line); + break; + case WEECHAT_CONFIG_OPTION_SET_ERROR: + gui_chat_printf (NULL, + _("%sWarning: %s, line %d: " + "invalid value for option " + "\"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + filename, line_number, line); + break; } } } @@ -1934,10 +2234,13 @@ config_file_reload (struct t_config_file *config_file) for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) { - for (ptr_option = ptr_section->options; ptr_option; - ptr_option = ptr_option->next_option) + if (!ptr_section->callback_read) { - ptr_option->loaded = 0; + for (ptr_option = ptr_section->options; ptr_option; + ptr_option = ptr_option->next_option) + { + ptr_option->loaded = 0; + } } } @@ -1948,11 +2251,14 @@ config_file_reload (struct t_config_file *config_file) for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) { - for (ptr_option = ptr_section->options; ptr_option; - ptr_option = ptr_option->next_option) + if (!ptr_section->callback_read) { - if (!ptr_option->loaded) - config_file_option_reset (ptr_option, 1); + for (ptr_option = ptr_section->options; ptr_option; + ptr_option = ptr_option->next_option) + { + if (!ptr_option->loaded) + config_file_option_reset (ptr_option, 1); + } } } @@ -2083,7 +2389,7 @@ config_file_free (struct t_config_file *config_file) if (!config_file) return; - /* remove config file */ + /* remove configuration file */ if (last_config_file == config_file) last_config_file = config_file->prev_config; if (config_file->prev_config) @@ -2147,7 +2453,7 @@ config_file_free_all_plugin (struct t_weechat_plugin *plugin) } /* - * config_file_add_to_infolist: add config options in an infolist + * config_file_add_to_infolist: add configuration options in an infolist * return 1 if ok, 0 if error */ @@ -2264,6 +2570,22 @@ config_file_add_to_infolist (struct t_infolist *infolist, free (option_full_name); return 0; } + if (!infolist_new_var_integer (ptr_item, + "value_is_null", + (ptr_option->value) ? + 0 : 1)) + { + free (option_full_name); + return 0; + } + if (!infolist_new_var_integer (ptr_item, + "default_value_is_null", + (ptr_option->default_value) ? + 0 : 1)) + { + free (option_full_name); + return 0; + } switch (ptr_option->type) { case CONFIG_OPTION_TYPE_BOOLEAN: @@ -2274,27 +2596,33 @@ config_file_add_to_infolist (struct t_infolist *infolist, free (option_full_name); return 0; } - if (CONFIG_BOOLEAN(ptr_option) == CONFIG_BOOLEAN_TRUE) - snprintf (value, sizeof (value), "on"); - else - snprintf (value, sizeof (value), "off"); - if (!infolist_new_var_string (ptr_item, - "value", - value)) + if (ptr_option->value) { - free (option_full_name); - return 0; + if (CONFIG_BOOLEAN(ptr_option) == CONFIG_BOOLEAN_TRUE) + snprintf (value, sizeof (value), "on"); + else + snprintf (value, sizeof (value), "off"); + if (!infolist_new_var_string (ptr_item, + "value", + value)) + { + free (option_full_name); + return 0; + } } - if (CONFIG_BOOLEAN_DEFAULT(ptr_option) == CONFIG_BOOLEAN_TRUE) - snprintf (value, sizeof (value), "on"); - else - snprintf (value, sizeof (value), "off"); - if (!infolist_new_var_string (ptr_item, - "default_value", - value)) + if (ptr_option->default_value) { - free (option_full_name); - return 0; + if (CONFIG_BOOLEAN_DEFAULT(ptr_option) == CONFIG_BOOLEAN_TRUE) + snprintf (value, sizeof (value), "on"); + else + snprintf (value, sizeof (value), "off"); + if (!infolist_new_var_string (ptr_item, + "default_value", + value)) + { + free (option_full_name); + return 0; + } } break; case CONFIG_OPTION_TYPE_INTEGER: @@ -2307,40 +2635,52 @@ config_file_add_to_infolist (struct t_infolist *infolist, } if (ptr_option->string_values) { - if (!infolist_new_var_string (ptr_item, - "value", - ptr_option->string_values[CONFIG_INTEGER(ptr_option)])) + if (ptr_option->value) { - free (option_full_name); - return 0; + if (!infolist_new_var_string (ptr_item, + "value", + ptr_option->string_values[CONFIG_INTEGER(ptr_option)])) + { + free (option_full_name); + return 0; + } } - if (!infolist_new_var_string (ptr_item, - "default_value", - ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)])) + if (ptr_option->default_value) { - free (option_full_name); - return 0; + if (!infolist_new_var_string (ptr_item, + "default_value", + ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)])) + { + free (option_full_name); + return 0; + } } } else { - snprintf (value, sizeof (value), "%d", - CONFIG_INTEGER(ptr_option)); - if (!infolist_new_var_string (ptr_item, - "value", - value)) + if (ptr_option->value) { - free (option_full_name); - return 0; + snprintf (value, sizeof (value), "%d", + CONFIG_INTEGER(ptr_option)); + if (!infolist_new_var_string (ptr_item, + "value", + value)) + { + free (option_full_name); + return 0; + } } - snprintf (value, sizeof (value), "%d", - CONFIG_INTEGER_DEFAULT(ptr_option)); - if (!infolist_new_var_string (ptr_item, - "default_value", - value)) + if (ptr_option->default_value) { - free (option_full_name); - return 0; + snprintf (value, sizeof (value), "%d", + CONFIG_INTEGER_DEFAULT(ptr_option)); + if (!infolist_new_var_string (ptr_item, + "default_value", + value)) + { + free (option_full_name); + return 0; + } } } break; @@ -2352,19 +2692,25 @@ config_file_add_to_infolist (struct t_infolist *infolist, free (option_full_name); return 0; } - if (!infolist_new_var_string (ptr_item, - "value", - CONFIG_STRING(ptr_option))) + if (ptr_option->value) { - free (option_full_name); - return 0; + if (!infolist_new_var_string (ptr_item, + "value", + CONFIG_STRING(ptr_option))) + { + free (option_full_name); + return 0; + } } - if (!infolist_new_var_string (ptr_item, - "default_value", - CONFIG_STRING_DEFAULT(ptr_option))) + if (ptr_option->default_value) { - free (option_full_name); - return 0; + if (!infolist_new_var_string (ptr_item, + "default_value", + CONFIG_STRING_DEFAULT(ptr_option))) + { + free (option_full_name); + return 0; + } } break; case CONFIG_OPTION_TYPE_COLOR: @@ -2375,19 +2721,25 @@ config_file_add_to_infolist (struct t_infolist *infolist, free (option_full_name); return 0; } - if (!infolist_new_var_string (ptr_item, - "value", - gui_color_get_name (CONFIG_COLOR(ptr_option)))) + if (ptr_option->value) { - free (option_full_name); - return 0; + if (!infolist_new_var_string (ptr_item, + "value", + gui_color_get_name (CONFIG_COLOR(ptr_option)))) + { + free (option_full_name); + return 0; + } } - if (!infolist_new_var_string (ptr_item, - "default_value", - gui_color_get_name (CONFIG_COLOR_DEFAULT(ptr_option)))) + if (ptr_option->value) { - free (option_full_name); - return 0; + if (!infolist_new_var_string (ptr_item, + "default_value", + gui_color_get_name (CONFIG_COLOR_DEFAULT(ptr_option)))) + { + free (option_full_name); + return 0; + } } break; case CONFIG_NUM_OPTION_TYPES: @@ -2404,102 +2756,7 @@ config_file_add_to_infolist (struct t_infolist *infolist, } /* - * config_file_print_stdout: print options on standard output - */ - -void -config_file_print_stdout (struct t_config_file *config_file) -{ - struct t_config_section *ptr_section; - struct t_config_option *ptr_option; - const char *color_name; - int i; - - for (ptr_section = config_file->sections; ptr_section; - ptr_section = ptr_section->next_section) - { - for (ptr_option = ptr_section->options; ptr_option; - ptr_option = ptr_option->next_option) - { - string_iconv_fprintf (stdout, - "* %s:\n", - ptr_option->name); - switch (ptr_option->type) - { - case CONFIG_OPTION_TYPE_BOOLEAN: - string_iconv_fprintf (stdout, _(" . type: boolean\n")); - string_iconv_fprintf (stdout, _(" . values: \"on\" or \"off\"\n")); - string_iconv_fprintf (stdout, _(" . default value: \"%s\"\n"), - (CONFIG_BOOLEAN_DEFAULT(ptr_option) == CONFIG_BOOLEAN_TRUE) ? - "on" : "off"); - break; - case CONFIG_OPTION_TYPE_INTEGER: - if (ptr_option->string_values) - { - string_iconv_fprintf (stdout, _(" . type: string\n")); - string_iconv_fprintf (stdout, _(" . values: ")); - i = 0; - while (ptr_option->string_values[i]) - { - string_iconv_fprintf (stdout, "\"%s\"", - ptr_option->string_values[i]); - if (ptr_option->string_values[i + 1]) - string_iconv_fprintf (stdout, ", "); - i++; - } - string_iconv_fprintf (stdout, "\n"); - string_iconv_fprintf (stdout, _(" . default value: \"%s\"\n"), - ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)]); - } - else - { - string_iconv_fprintf (stdout, _(" . type: integer\n")); - string_iconv_fprintf (stdout, _(" . values: between %d and %d\n"), - ptr_option->min, - ptr_option->max); - string_iconv_fprintf (stdout, _(" . default value: %d\n"), - CONFIG_INTEGER_DEFAULT(ptr_option)); - } - break; - case CONFIG_OPTION_TYPE_STRING: - switch (ptr_option->max) - { - case 0: - string_iconv_fprintf (stdout, _(" . type: string\n")); - string_iconv_fprintf (stdout, _(" . values: any string\n")); - break; - case 1: - string_iconv_fprintf (stdout, _(" . type: char\n")); - string_iconv_fprintf (stdout, _(" . values: any char\n")); - break; - default: - string_iconv_fprintf (stdout, _(" . type: string\n")); - string_iconv_fprintf (stdout, _(" . values: any string (limit: %d chars)\n"), - ptr_option->max); - break; - } - string_iconv_fprintf (stdout, _(" . default value: \"%s\"\n"), - CONFIG_STRING_DEFAULT(ptr_option)); - break; - case CONFIG_OPTION_TYPE_COLOR: - color_name = gui_color_get_name (CONFIG_COLOR_DEFAULT(ptr_option)); - string_iconv_fprintf (stdout, _(" . type: color\n")); - string_iconv_fprintf (stdout, _(" . values: color (depends on GUI used)\n")); - string_iconv_fprintf (stdout, _(" . default value: \"%s\"\n"), - color_name); - break; - case CONFIG_NUM_OPTION_TYPES: - break; - } - string_iconv_fprintf (stdout, _(" . description: %s\n"), - _(ptr_option->description)); - string_iconv_fprintf (stdout, "\n"); - } - } -} - -/* - * config_file_print_log: print config in log (usually for crash dump) + * config_file_print_log: print configuration in log (usually for crash dump) */ void @@ -2565,45 +2822,68 @@ config_file_print_log () { case CONFIG_OPTION_TYPE_BOOLEAN: log_printf (" default value. . . . : %s", - (CONFIG_BOOLEAN_DEFAULT(ptr_option) == CONFIG_BOOLEAN_TRUE) ? - "on" : "off"); + (ptr_option->default_value) ? + ((CONFIG_BOOLEAN_DEFAULT(ptr_option) == CONFIG_BOOLEAN_TRUE) ? + "on" : "off") : "null"); log_printf (" value (boolean). . . : %s", - (CONFIG_BOOLEAN(ptr_option) == CONFIG_BOOLEAN_TRUE) ? - "on" : "off"); + (ptr_option->value) ? + ((CONFIG_BOOLEAN(ptr_option) == CONFIG_BOOLEAN_TRUE) ? + "on" : "off") : "null"); break; case CONFIG_OPTION_TYPE_INTEGER: if (ptr_option->string_values) { log_printf (" default value. . . . : '%s'", - ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)]); + (ptr_option->default_value) ? + ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)] : "null"); log_printf (" value (integer/str). : '%s'", - ptr_option->string_values[CONFIG_INTEGER(ptr_option)]); + (ptr_option->value) ? + ptr_option->string_values[CONFIG_INTEGER(ptr_option)] : "null"); } else { - log_printf (" default value. . . . : %d", - CONFIG_INTEGER_DEFAULT(ptr_option)); - log_printf (" value (integer). . . : %d", - CONFIG_INTEGER(ptr_option)); + if (ptr_option->default_value) + log_printf (" default value. . . . : %d", + CONFIG_INTEGER_DEFAULT(ptr_option)); + else + log_printf (" default value. . . . : null"); + if (ptr_option->value) + log_printf (" value (integer). . . : %d", + CONFIG_INTEGER(ptr_option)); + else + log_printf (" value (integer). . . : null"); } break; case CONFIG_OPTION_TYPE_STRING: - log_printf (" default value. . . . : '%s'", - CONFIG_STRING_DEFAULT(ptr_option)); - log_printf (" value (string) . . . : '%s'", - CONFIG_STRING(ptr_option)); + if (ptr_option->default_value) + log_printf (" default value. . . . : '%s'", + CONFIG_STRING_DEFAULT(ptr_option)); + else + log_printf (" default value. . . . : null"); + if (ptr_option->value) + log_printf (" value (string) . . . : '%s'", + CONFIG_STRING(ptr_option)); + else + log_printf (" value (string) . . . : null"); break; case CONFIG_OPTION_TYPE_COLOR: - log_printf (" default value. . . . : %d ('%s')", - CONFIG_COLOR_DEFAULT(ptr_option), - gui_color_get_name (CONFIG_COLOR_DEFAULT(ptr_option))); - log_printf (" value (color). . . . : %d ('%s')", - CONFIG_COLOR(ptr_option), - gui_color_get_name (CONFIG_COLOR(ptr_option))); + if (ptr_option->default_value) + log_printf (" default value. . . . : %d ('%s')", + CONFIG_COLOR_DEFAULT(ptr_option), + gui_color_get_name (CONFIG_COLOR_DEFAULT(ptr_option))); + else + log_printf (" default value. . . . : null"); + if (ptr_option->value) + log_printf (" value (color). . . . : %d ('%s')", + CONFIG_COLOR(ptr_option), + gui_color_get_name (CONFIG_COLOR(ptr_option))); + else + log_printf (" value (color). . . . : null"); break; case CONFIG_NUM_OPTION_TYPES: break; } + log_printf (" null_value_allowed . : %d", ptr_option->null_value_allowed); log_printf (" callback_change. . . : 0x%lx", ptr_option->callback_change); log_printf (" loaded . . . . . . . : %d", ptr_option->loaded); log_printf (" prev_option. . . . . : 0x%lx", ptr_option->prev_option); diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h index 493b907d1..57da164ce 100644 --- a/src/core/wee-config-file.h +++ b/src/core/wee-config-file.h @@ -119,6 +119,7 @@ struct t_config_option int min, max; /* min and max for value */ void *default_value; /* default value */ void *value; /* value */ + int null_value_allowed; /* null value allowed ? */ int (*callback_check_value) /* called to check value before */ (void *data, /* assiging new value */ struct t_config_option *option, @@ -189,6 +190,7 @@ extern struct t_config_option *config_file_new_option (struct t_config_file *con int min, int max, const char *default_value, const char *value, + int null_value_allowed, int (*callback_check_value)(void *data, struct t_config_option *option, const char *value), @@ -219,18 +221,27 @@ extern int config_file_option_reset (struct t_config_option *option, int run_callback); extern int config_file_option_set (struct t_config_option *option, const char *value, int run_callback); +extern int config_file_option_set_null (struct t_config_option *option, + int run_callback); extern int config_file_option_unset (struct t_config_option *option); extern void config_file_option_rename (struct t_config_option *option, const char *new_name); extern void *config_file_option_get_pointer (struct t_config_option *option, const char *property); +extern int config_file_option_is_null (struct t_config_option *option); +extern int config_file_option_default_is_null (struct t_config_option *option); extern int config_file_option_set_with_string (const char *option_name, const char *value); extern int config_file_option_unset_with_string (const char *option_name); extern int config_file_option_boolean (struct t_config_option *option); +extern int config_file_option_boolean_default (struct t_config_option *option); extern int config_file_option_integer (struct t_config_option *option); +extern int config_file_option_integer_default (struct t_config_option *option); extern const char *config_file_option_string (struct t_config_option *option); +extern const char *config_file_option_string_default (struct t_config_option *option); extern const char *config_file_option_color (struct t_config_option *option); - +extern const char *config_file_option_color_default (struct t_config_option *option); +extern void config_file_write_option (struct t_config_file *config_file, + struct t_config_option *option); extern void config_file_write_line (struct t_config_file *config_file, const char *option_name, const char *value, ...); extern int config_file_write (struct t_config_file *config_files); @@ -245,7 +256,6 @@ extern void config_file_free_all (); extern void config_file_free_all_plugin (struct t_weechat_plugin *plugin); extern int config_file_add_to_infolist (struct t_infolist *infolist, const char *option_name); -extern void config_file_print_stdout (struct t_config_file *config_file); extern void config_file_print_log (); #endif /* wee-config-file.h */ diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 4cf3c801b..9348181ba 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -524,7 +524,7 @@ config_weechat_debug_create_option (void *data, config_file, section, option_name, "integer", _("debug level for plugin (\"core\" for WeeChat core)"), - NULL, 0, 32, "0", value, NULL, NULL, + NULL, 0, 32, "0", value, 0, NULL, NULL, &config_weechat_debug_change, NULL, NULL, NULL); rc = (ptr_option) ? @@ -578,13 +578,13 @@ config_weechat_debug_set (const char *plugin_name, const char *value) } /* - * config_weechat_proxy_read: read proxy option in config file + * config_weechat_proxy_read_cb: read proxy option in config file */ int -config_weechat_proxy_read (void *data, struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) +config_weechat_proxy_read_cb (void *data, struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, const char *value) { char *pos_option, *proxy_name; struct t_proxy *ptr_temp_proxy; @@ -647,13 +647,13 @@ config_weechat_proxy_read (void *data, struct t_config_file *config_file, } /* - * config_weechat_bar_read: read bar option in config file + * config_weechat_bar_read_cb: read bar option in config file */ int -config_weechat_bar_read (void *data, struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) +config_weechat_bar_read_cb (void *data, struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, const char *value) { char *pos_option, *bar_name; struct t_gui_bar *ptr_temp_bar; @@ -716,13 +716,13 @@ config_weechat_bar_read (void *data, struct t_config_file *config_file, } /* - * config_weechat_layout_read: read layout option in config file + * config_weechat_layout_read_cb: read layout option in config file */ int -config_weechat_layout_read (void *data, struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) +config_weechat_layout_read_cb (void *data, struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, const char *value) { int argc; char **argv, *error1, *error2, *error3, *error4; @@ -817,12 +817,12 @@ config_weechat_layout_write_tree (struct t_config_file *config_file, } /* - * config_weechat_layout_write: write layout section in configuration file + * config_weechat_layout_write_cb: write layout section in configuration file */ void -config_weechat_layout_write (void *data, struct t_config_file *config_file, - const char *section_name) +config_weechat_layout_write_cb (void *data, struct t_config_file *config_file, + const char *section_name) { struct t_gui_layout_buffer *ptr_layout_buffer; @@ -845,14 +845,14 @@ config_weechat_layout_write (void *data, struct t_config_file *config_file, } /* - * config_weechat_filter_read: read filter option from config file + * config_weechat_filter_read_cb: read filter option from config file */ int -config_weechat_filter_read (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) +config_weechat_filter_read_cb (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, const char *value) { char **argv, **argv_eol; int argc; @@ -881,12 +881,12 @@ config_weechat_filter_read (void *data, } /* - * config_weechat_filter_write: write filter section in configuration file + * config_weechat_filter_write_cb: write filter section in configuration file */ void -config_weechat_filter_write (void *data, struct t_config_file *config_file, - const char *section_name) +config_weechat_filter_write_cb (void *data, struct t_config_file *config_file, + const char *section_name) { struct t_gui_filter *ptr_filter; @@ -909,13 +909,13 @@ config_weechat_filter_write (void *data, struct t_config_file *config_file, } /* - * config_weechat_key_read: read key option in config file + * config_weechat_key_read_cb: read key option in config file */ int -config_weechat_key_read (void *data, struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) +config_weechat_key_read_cb (void *data, struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, const char *value) { /* make C compiler happy */ (void) data; @@ -940,12 +940,12 @@ config_weechat_key_read (void *data, struct t_config_file *config_file, } /* - * config_weechat_key_write: write key section in configuration file + * config_weechat_key_write_cb: write key section in configuration file */ void -config_weechat_key_write (void *data, struct t_config_file *config_file, - const char *section_name) +config_weechat_key_write_cb (void *data, struct t_config_file *config_file, + const char *section_name) { struct t_gui_key *ptr_key; char *expanded_name; @@ -1013,27 +1013,27 @@ config_weechat_init () weechat_config_file, ptr_section, "command_after_plugins", "string", N_("command executed when WeeChat starts, after loading plugins"), - NULL, 0, 0, "", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_startup_command_before_plugins = config_file_new_option ( weechat_config_file, ptr_section, "command_before_plugins", "string", N_("command executed when WeeChat starts, before loading plugins"), - NULL, 0, 0, "", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_startup_display_logo = config_file_new_option ( weechat_config_file, ptr_section, "display_logo", "boolean", N_("display WeeChat logo at startup"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_startup_display_version = config_file_new_option ( weechat_config_file, ptr_section, "display_version", "boolean", N_("display WeeChat version at startup"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_startup_weechat_slogan = config_file_new_option ( weechat_config_file, ptr_section, "weechat_slogan", "string", N_("WeeChat slogan (if empty, slogan is not used)"), - NULL, 0, 0, _("the geekiest chat client!"), NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, _("the geekiest chat client!"), NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); /* look */ ptr_section = config_file_new_section (weechat_config_file, "look", @@ -1052,18 +1052,18 @@ config_weechat_init () N_("default notify level for buffers (used to tell WeeChat if buffer " "must be displayed in hotlist or not, according to importance " "of message)"), - "none|highlight|message|all", 0, 0, "all", NULL, + "none|highlight|message|all", 0, 0, "all", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_look_buffer_time_format = config_file_new_option ( weechat_config_file, ptr_section, "buffer_time_format", "string", N_("time format for buffers"), - NULL, 0, 0, "%H:%M:%S", NULL, NULL, NULL, &config_change_buffer_time_format, NULL, NULL, NULL); + NULL, 0, 0, "%H:%M:%S", NULL, 0, NULL, NULL, &config_change_buffer_time_format, NULL, NULL, NULL); config_look_color_nicks_number = config_file_new_option ( weechat_config_file, ptr_section, "color_nicks_number", "integer", N_("number of colors to use for nicks colors"), - NULL, 1, 10, "10", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 1, 10, "10", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_look_color_real_white = config_file_new_option ( weechat_config_file, ptr_section, "color_real_white", "boolean", @@ -1072,47 +1072,47 @@ config_weechat_init () "white background, you should turn on this option to " "see real white instead of default term foreground " "color)"), - NULL, 0, 0, "off", NULL, NULL, NULL, &config_change_color, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_look_day_change = config_file_new_option ( weechat_config_file, ptr_section, "day_change", "boolean", N_("display special message when day changes"), - NULL, 0, 0, "on", NULL, NULL, NULL, &config_change_day_change, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, &config_change_day_change, NULL, NULL, NULL); config_look_day_change_time_format = config_file_new_option ( weechat_config_file, ptr_section, "day_change_time_format", "string", N_("time format for date displayed when day changed"), - NULL, 0, 0, "%a, %d %b %Y", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "%a, %d %b %Y", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_look_highlight = config_file_new_option ( weechat_config_file, ptr_section, "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, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_look_hotlist_names_count = config_file_new_option ( weechat_config_file, ptr_section, "hotlist_names_count", "integer", N_("max number of names in hotlist (0 = no name " "displayed, only buffer numbers)"), - NULL, 0, 32, "3", NULL, NULL, NULL, &config_change_buffer_content, NULL, NULL, NULL); + NULL, 0, 32, "3", NULL, 0, NULL, NULL, &config_change_buffer_content, NULL, NULL, NULL); config_look_hotlist_names_length = config_file_new_option ( weechat_config_file, ptr_section, "hotlist_names_length", "integer", N_("max length of names in hotlist (0 = no limit)"), - NULL, 0, 32, "0", NULL, NULL, NULL, &config_change_buffer_content, NULL, NULL, NULL); + NULL, 0, 32, "0", NULL, 0, NULL, NULL, &config_change_buffer_content, NULL, NULL, NULL); config_look_hotlist_names_level = config_file_new_option ( weechat_config_file, ptr_section, "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", NULL, NULL, NULL, &config_change_buffer_content, NULL, NULL, NULL); + NULL, 1, 15, "12", NULL, 0, NULL, NULL, &config_change_buffer_content, NULL, NULL, NULL); config_look_hotlist_short_names = config_file_new_option ( weechat_config_file, ptr_section, "hotlist_short_names", "boolean", N_("if set, uses short names to display buffer names in hotlist (start " "after first '.' in name)"), - NULL, 0, 0, "on", NULL, NULL, NULL, &config_change_buffer_content, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, &config_change_buffer_content, NULL, NULL, NULL); config_look_hotlist_sort = config_file_new_option ( weechat_config_file, ptr_section, "hotlist_sort", "integer", @@ -1121,102 +1121,102 @@ config_weechat_init () "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", NULL, NULL, NULL, &config_change_hotlist, NULL, NULL, NULL); + 0, 0, "group_time_asc", NULL, 0, NULL, NULL, &config_change_hotlist, NULL, NULL, NULL); config_look_item_time_format = config_file_new_option ( weechat_config_file, ptr_section, "item_time_format", "string", N_("time format for \"time\" bar item"), - NULL, 0, 0, "%H:%M", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "%H:%M", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_look_nickmode = config_file_new_option ( weechat_config_file, ptr_section, "nickmode", "boolean", N_("display nick mode ((half)op/voice) before each nick"), - NULL, 0, 0, "on", NULL, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); config_look_nickmode_empty = config_file_new_option ( weechat_config_file, ptr_section, "nickmode_empty", "boolean", N_("display space if nick mode is not (half)op/voice"), - NULL, 0, 0, "off", NULL, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); config_look_paste_max_lines = config_file_new_option ( weechat_config_file, ptr_section, "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, NULL, NULL, NULL, NULL, NULL); + NULL, 0, INT_MAX, "3", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_look_prefix[GUI_CHAT_PREFIX_ERROR] = config_file_new_option ( weechat_config_file, ptr_section, "prefix_error", "string", N_("prefix for error messages"), - NULL, 0, 0, "=!=", NULL, NULL, NULL, &config_change_prefix, NULL, NULL, NULL); + NULL, 0, 0, "=!=", NULL, 0, NULL, NULL, &config_change_prefix, NULL, NULL, NULL); config_look_prefix[GUI_CHAT_PREFIX_NETWORK] = config_file_new_option ( weechat_config_file, ptr_section, "prefix_network", "string", N_("prefix for network messages"), - NULL, 0, 0, "--", NULL, NULL, NULL, &config_change_prefix, NULL, NULL, NULL); + NULL, 0, 0, "--", NULL, 0, NULL, NULL, &config_change_prefix, NULL, NULL, NULL); config_look_prefix[GUI_CHAT_PREFIX_ACTION] = config_file_new_option ( weechat_config_file, ptr_section, "prefix_action", "string", N_("prefix for action messages"), - NULL, 0, 0, " *", NULL, NULL, NULL, &config_change_prefix, NULL, NULL, NULL); + NULL, 0, 0, " *", NULL, 0, NULL, NULL, &config_change_prefix, NULL, NULL, NULL); config_look_prefix[GUI_CHAT_PREFIX_JOIN] = config_file_new_option ( weechat_config_file, ptr_section, "prefix_join", "string", N_("prefix for join messages"), - NULL, 0, 0, "-->", NULL, NULL, NULL, &config_change_prefix, NULL, NULL, NULL); + NULL, 0, 0, "-->", NULL, 0, NULL, NULL, &config_change_prefix, NULL, NULL, NULL); config_look_prefix[GUI_CHAT_PREFIX_QUIT] = config_file_new_option ( weechat_config_file, ptr_section, "prefix_quit", "string", N_("prefix for quit messages"), - NULL, 0, 0, "<--", NULL, NULL, NULL, &config_change_prefix, NULL, NULL, NULL); + NULL, 0, 0, "<--", NULL, 0, NULL, NULL, &config_change_prefix, NULL, NULL, NULL); config_look_prefix_align = config_file_new_option ( weechat_config_file, ptr_section, "prefix_align", "integer", N_("prefix alignment (none, left, right (default))"), - "none|left|right", 0, 0, "right", NULL, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); + "none|left|right", 0, 0, "right", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); config_look_prefix_align_max = config_file_new_option ( weechat_config_file, ptr_section, "prefix_align_max", "integer", N_("max size for prefix (0 = no max size)"), - NULL, 0, 64, "0", NULL, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); + NULL, 0, 64, "0", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); config_look_prefix_suffix = config_file_new_option ( weechat_config_file, ptr_section, "prefix_suffix", "string", N_("string displayed after prefix"), - NULL, 0, 0, "|", NULL, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); + NULL, 0, 0, "|", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); config_look_read_marker = config_file_new_option ( weechat_config_file, ptr_section, "read_marker", "integer", N_("use a marker (line or char) on buffers to show first unread line"), "none|line|dotted-line|char", - 0, 0, "dotted-line", NULL, NULL, NULL, &config_change_read_marker, NULL, NULL, NULL); + 0, 0, "dotted-line", NULL, 0, NULL, NULL, &config_change_read_marker, NULL, NULL, NULL); config_look_save_config_on_exit = config_file_new_option ( weechat_config_file, ptr_section, "save_config_on_exit", "boolean", N_("save configuration file on exit"), - NULL, 0, 0, "on", NULL, NULL, NULL, &config_change_save_config_on_exit, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, &config_change_save_config_on_exit, NULL, NULL, NULL); config_look_save_layout_on_exit = config_file_new_option ( weechat_config_file, ptr_section, "save_layout_on_exit", "integer", N_("save layout on exit (buffers, windows, or both)"), - "none|buffers|windows|all", 0, 0, "all", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + "none|buffers|windows|all", 0, 0, "all", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_look_scroll_amount = config_file_new_option ( weechat_config_file, ptr_section, "scroll_amount", "integer", N_("how many lines to scroll by with scroll_up and " "scroll_down"), - NULL, 1, INT_MAX, "3", NULL, NULL, NULL, &config_change_buffer_content, NULL, NULL, NULL); + NULL, 1, INT_MAX, "3", NULL, 0, NULL, NULL, &config_change_buffer_content, NULL, NULL, NULL); config_look_scroll_page_percent = config_file_new_option ( weechat_config_file, ptr_section, "scroll_page_percent", "integer", N_("percent of screen to scroll when scrolling one page up or down " "(for example 100 means one page, 50 half-page)"), - NULL, 1, 100, "100", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 1, 100, "100", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_look_set_title = config_file_new_option ( weechat_config_file, ptr_section, "set_title", "boolean", N_("set title for window (terminal for Curses GUI) with " "name and version"), - NULL, 0, 0, "on", NULL, NULL, NULL, &config_change_title, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, &config_change_title, NULL, NULL, NULL); /* colors */ ptr_section = config_file_new_section (weechat_config_file, "color", @@ -1234,343 +1234,343 @@ config_weechat_init () weechat_config_file, ptr_section, "separator", "color", N_("background color for window separators (when splitted)"), - NULL, GUI_COLOR_SEPARATOR, 0, "blue", NULL, + NULL, GUI_COLOR_SEPARATOR, 0, "blue", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); /* bar colors */ config_color_bar_more = config_file_new_option ( weechat_config_file, ptr_section, "bar_more", "color", N_("text color for '+' when scrolling bars"), - NULL, -1, 0, "lightmagenta", NULL, + NULL, -1, 0, "lightmagenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); /* chat window */ config_color_chat = config_file_new_option ( weechat_config_file, ptr_section, "chat", "color", N_("text color for chat"), - NULL, GUI_COLOR_CHAT, 0, "default", NULL, + NULL, GUI_COLOR_CHAT, 0, "default", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_bg = config_file_new_option ( weechat_config_file, ptr_section, "chat_bg", "color", N_("background color for chat"), - NULL, -1, 0, "default", NULL, + NULL, -1, 0, "default", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_time = config_file_new_option ( weechat_config_file, ptr_section, "chat_time", "color", N_("text color for time in chat window"), - NULL, GUI_COLOR_CHAT_TIME, 0, "default", NULL, + NULL, GUI_COLOR_CHAT_TIME, 0, "default", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_time_delimiters = config_file_new_option ( weechat_config_file, ptr_section, "chat_time_delimiters", "color", N_("text color for time delimiters"), - NULL, GUI_COLOR_CHAT_TIME_DELIMITERS, 0, "brown", NULL, + NULL, GUI_COLOR_CHAT_TIME_DELIMITERS, 0, "brown", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_ERROR] = config_file_new_option ( weechat_config_file, ptr_section, "chat_prefix_error", "color", N_("text color for error prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_ERROR, 0, "yellow", NULL, + NULL, GUI_COLOR_CHAT_PREFIX_ERROR, 0, "yellow", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_NETWORK] = config_file_new_option ( weechat_config_file, ptr_section, "chat_prefix_network", "color", N_("text color for network prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_NETWORK, 0, "magenta", NULL, + NULL, GUI_COLOR_CHAT_PREFIX_NETWORK, 0, "magenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_ACTION] = config_file_new_option ( weechat_config_file, ptr_section, "chat_prefix_action", "color", N_("text color for action prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_ACTION, 0, "white", NULL, + NULL, GUI_COLOR_CHAT_PREFIX_ACTION, 0, "white", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_JOIN] = config_file_new_option ( weechat_config_file, ptr_section, "chat_prefix_join", "color", N_("text color for join prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_JOIN, 0, "lightgreen", NULL, + NULL, GUI_COLOR_CHAT_PREFIX_JOIN, 0, "lightgreen", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_prefix[GUI_CHAT_PREFIX_QUIT] = config_file_new_option ( weechat_config_file, ptr_section, "chat_prefix_quit", "color", N_("text color for quit prefix"), - NULL, GUI_COLOR_CHAT_PREFIX_QUIT, 0, "lightred", NULL, + NULL, GUI_COLOR_CHAT_PREFIX_QUIT, 0, "lightred", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_prefix_more = config_file_new_option ( weechat_config_file, ptr_section, "chat_prefix_more", "color", N_("text color for '+' when prefix is too long"), - NULL, GUI_COLOR_CHAT_PREFIX_MORE, 0, "lightmagenta", NULL, + NULL, GUI_COLOR_CHAT_PREFIX_MORE, 0, "lightmagenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_prefix_suffix = config_file_new_option ( weechat_config_file, ptr_section, "chat_prefix_suffix", "color", N_("text color for suffix (after prefix)"), - NULL, GUI_COLOR_CHAT_PREFIX_SUFFIX, 0, "green", NULL, + NULL, GUI_COLOR_CHAT_PREFIX_SUFFIX, 0, "green", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_buffer = config_file_new_option ( weechat_config_file, ptr_section, "chat_buffer", "color", N_("text color for buffer names"), - NULL, GUI_COLOR_CHAT_BUFFER, 0, "white", NULL, + NULL, GUI_COLOR_CHAT_BUFFER, 0, "white", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_server = config_file_new_option ( weechat_config_file, ptr_section, "chat_server", "color", N_("text color for server names"), - NULL, GUI_COLOR_CHAT_SERVER, 0, "brown", NULL, + NULL, GUI_COLOR_CHAT_SERVER, 0, "brown", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_channel = config_file_new_option ( weechat_config_file, ptr_section, "chat_channel", "color", N_("text color for channel names"), - NULL, GUI_COLOR_CHAT_CHANNEL, 0, "white", NULL, + NULL, GUI_COLOR_CHAT_CHANNEL, 0, "white", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick", "color", N_("text color for nicks in chat window"), - NULL, GUI_COLOR_CHAT_NICK, 0, "lightcyan", NULL, + NULL, GUI_COLOR_CHAT_NICK, 0, "lightcyan", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_self = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_self", "color", N_("text color for local nick in chat window"), - NULL, GUI_COLOR_CHAT_NICK_SELF, 0, "white", NULL, + NULL, GUI_COLOR_CHAT_NICK_SELF, 0, "white", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_other = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_other", "color", N_("text color for other nick in private buffer"), - NULL, GUI_COLOR_CHAT_NICK_OTHER, 0, "cyan", NULL, + NULL, GUI_COLOR_CHAT_NICK_OTHER, 0, "cyan", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_colors[0] = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_color01", "color", N_("text color #1 for nick"), - NULL, GUI_COLOR_CHAT_NICK1, 0, "cyan", NULL, + NULL, GUI_COLOR_CHAT_NICK1, 0, "cyan", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_colors[1] = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_color02", "color", N_("text color #2 for nick"), - NULL, GUI_COLOR_CHAT_NICK2, 0, "magenta", NULL, + NULL, GUI_COLOR_CHAT_NICK2, 0, "magenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_colors[2] = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_color03", "color", N_("text color #3 for nick"), - NULL, GUI_COLOR_CHAT_NICK3, 0, "green", NULL, + NULL, GUI_COLOR_CHAT_NICK3, 0, "green", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_colors[3] = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_color04", "color", N_("text color #4 for nick"), - NULL, GUI_COLOR_CHAT_NICK4, 0, "brown", NULL, + NULL, GUI_COLOR_CHAT_NICK4, 0, "brown", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_colors[4] = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_color05", "color", N_("text color #5 for nick"), - NULL, GUI_COLOR_CHAT_NICK5, 0, "lightblue", NULL, + NULL, GUI_COLOR_CHAT_NICK5, 0, "lightblue", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_colors[5] = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_color06", "color", N_("text color #6 for nick"), - NULL, GUI_COLOR_CHAT_NICK6, 0, "default", NULL, + NULL, GUI_COLOR_CHAT_NICK6, 0, "default", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_colors[6] = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_color07", "color", N_("text color #7 for nick"), - NULL, GUI_COLOR_CHAT_NICK7, 0, "lightcyan", NULL, + NULL, GUI_COLOR_CHAT_NICK7, 0, "lightcyan", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_colors[7] = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_color08", "color", N_("text color #8 for nick"), - NULL, GUI_COLOR_CHAT_NICK8, 0, "lightmagenta", NULL, + NULL, GUI_COLOR_CHAT_NICK8, 0, "lightmagenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_colors[8] = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_color09", "color", N_("text color #9 for nick"), - NULL, GUI_COLOR_CHAT_NICK9, 0, "lightgreen", NULL, + NULL, GUI_COLOR_CHAT_NICK9, 0, "lightgreen", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_nick_colors[9] = config_file_new_option ( weechat_config_file, ptr_section, "chat_nick_color10", "color", N_("text color #10 for nick"), - NULL, GUI_COLOR_CHAT_NICK10, 0, "blue", NULL, + NULL, GUI_COLOR_CHAT_NICK10, 0, "blue", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_host = config_file_new_option ( weechat_config_file, ptr_section, "chat_host", "color", N_("text color for hostnames"), - NULL, GUI_COLOR_CHAT_HOST, 0, "cyan", NULL, + NULL, GUI_COLOR_CHAT_HOST, 0, "cyan", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_delimiters = config_file_new_option ( weechat_config_file, ptr_section, "chat_delimiters", "color", N_("text color for delimiters"), - NULL, GUI_COLOR_CHAT_DELIMITERS, 0, "green", NULL, + NULL, GUI_COLOR_CHAT_DELIMITERS, 0, "green", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_highlight = config_file_new_option ( weechat_config_file, ptr_section, "chat_highlight", "color", N_("text color for highlighted prefix"), - NULL, GUI_COLOR_CHAT_HIGHLIGHT, 0, "yellow", NULL, + NULL, GUI_COLOR_CHAT_HIGHLIGHT, 0, "yellow", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_highlight_bg = config_file_new_option ( weechat_config_file, ptr_section, "chat_highlight_bg", "color", N_("background color for highlighted prefix"), - NULL, -1, 0, "magenta", NULL, + NULL, -1, 0, "magenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_read_marker = config_file_new_option ( weechat_config_file, ptr_section, "chat_read_marker", "color", N_("text color for unread data marker"), - NULL, GUI_COLOR_CHAT_READ_MARKER, 0, "magenta", NULL, + NULL, GUI_COLOR_CHAT_READ_MARKER, 0, "magenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_read_marker_bg = config_file_new_option ( weechat_config_file, ptr_section, "chat_read_marker_bg", "color", N_("background color for unread data marker"), - NULL, -1, 0, "default", NULL, + NULL, -1, 0, "default", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_text_found = config_file_new_option ( weechat_config_file, ptr_section, "chat_text_found", "color", N_("text color for marker on lines where text sought is found"), - NULL, GUI_COLOR_CHAT_TEXT_FOUND, 0, "yellow", NULL, + NULL, GUI_COLOR_CHAT_TEXT_FOUND, 0, "yellow", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_text_found_bg = config_file_new_option ( weechat_config_file, ptr_section, "chat_text_found_bg", "color", N_("background color for marker on lines where text sought is found"), - NULL, -1, 0, "lightmagenta", NULL, + NULL, -1, 0, "lightmagenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); /* status window */ config_color_status_number = config_file_new_option ( weechat_config_file, ptr_section, "status_number", "color", N_("text color for current buffer number in status bar"), - NULL, -1, 0, "yellow", NULL, + NULL, -1, 0, "yellow", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_status_name = config_file_new_option ( weechat_config_file, ptr_section, "status_name", "color", N_("text color for current buffer name in status bar"), - NULL, -1, 0, "white", NULL, + NULL, -1, 0, "white", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_status_data_msg = config_file_new_option ( weechat_config_file, ptr_section, "status_data_msg", "color", N_("text color for buffer with new messages (status bar)"), - NULL, -1, 0, "yellow", NULL, + NULL, -1, 0, "yellow", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_status_data_private = config_file_new_option ( weechat_config_file, ptr_section, "status_data_private", "color", N_("text color for buffer with private message (status bar)"), - NULL, -1, 0, "lightgreen", NULL, + NULL, -1, 0, "lightgreen", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_status_data_highlight = config_file_new_option ( weechat_config_file, ptr_section, "status_data_highlight", "color", N_("text color for buffer with highlight (status bar)"), - NULL, -1, 0, "lightmagenta", NULL, + NULL, -1, 0, "lightmagenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_status_data_other = config_file_new_option ( weechat_config_file, ptr_section, "status_data_other", "color", N_("text color for buffer with new data (not messages) " "(status bar)"), - NULL, -1, 0, "default", NULL, + NULL, -1, 0, "default", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_status_more = config_file_new_option ( weechat_config_file, ptr_section, "status_more", "color", N_("text color for buffer with new data (status bar)"), - NULL, -1, 0, "yellow", NULL, + NULL, -1, 0, "yellow", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); /* input window */ config_color_input_nick = config_file_new_option ( weechat_config_file, ptr_section, "input_nick", "color", N_("text color for nick name in input line"), - NULL, -1, 0, "lightcyan", NULL, + NULL, -1, 0, "lightcyan", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_input_text_not_found = config_file_new_option ( weechat_config_file, ptr_section, "input_text_not_found", "color", N_("text color for unsucessful text search in input line"), - NULL, -1, 0, "red", NULL, + NULL, -1, 0, "red", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_input_actions = config_file_new_option ( weechat_config_file, ptr_section, "input_actions", "color", N_("text color for actions in input line"), - NULL, -1, 0, "lightgreen", NULL, + NULL, -1, 0, "lightgreen", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); /* nicklist window */ config_color_nicklist_group = config_file_new_option ( weechat_config_file, ptr_section, "nicklist_group", "color", N_("text color for groups in nicklist"), - NULL, -1, 0, "green", NULL, + NULL, -1, 0, "green", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_nicklist_away = config_file_new_option ( weechat_config_file, ptr_section, "nicklist_away", "color", N_("text color for away nicknames"), - NULL, -1, 0, "cyan", NULL, + NULL, -1, 0, "cyan", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_nicklist_prefix1 = config_file_new_option ( weechat_config_file, ptr_section, "nicklist_prefix1", "color", N_("text color for prefix #1 in nicklist"), - NULL, -1, 0, "lightgreen", NULL, + NULL, -1, 0, "lightgreen", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_nicklist_prefix2 = config_file_new_option ( weechat_config_file, ptr_section, "nicklist_prefix2", "color", N_("text color for prefix #2 in nicklist"), - NULL, -1, 0, "lightmagenta", NULL, + NULL, -1, 0, "lightmagenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_nicklist_prefix3 = config_file_new_option ( weechat_config_file, ptr_section, "nicklist_prefix3", "color", N_("text color for prefix #3 in nicklist"), - NULL, -1, 0, "yellow", NULL, + NULL, -1, 0, "yellow", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_nicklist_prefix4 = config_file_new_option ( weechat_config_file, ptr_section, "nicklist_prefix4", "color", N_("text color for prefix #4 in nicklist"), - NULL, -1, 0, "blue", NULL, + NULL, -1, 0, "blue", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_nicklist_prefix5 = config_file_new_option ( weechat_config_file, ptr_section, "nicklist_prefix5", "color", N_("text color for prefix #5 in nicklist"), - NULL, -1, 0, "brown", NULL, + NULL, -1, 0, "brown", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_nicklist_more = config_file_new_option ( weechat_config_file, ptr_section, "nicklist_more", "color", N_("text color for '+' when scrolling nicks in nicklist"), - NULL, -1, 0, "lightmagenta", NULL, + NULL, -1, 0, "lightmagenta", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_nicklist_separator = config_file_new_option ( weechat_config_file, ptr_section, "nicklist_separator", "color", N_("text color for nicklist separator"), - NULL, -1, 0, "blue", NULL, + NULL, -1, 0, "blue", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); /* completion */ @@ -1588,45 +1588,45 @@ config_weechat_init () weechat_config_file, ptr_section, "nick_completor", "string", N_("string inserted after nick completion"), - NULL, 0, 0, ":", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, ":", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_completion_nick_first_only = config_file_new_option ( weechat_config_file, ptr_section, "nick_first_only", "boolean", N_("complete only with first nick found"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_completion_nick_ignore_chars = config_file_new_option ( weechat_config_file, ptr_section, "nick_ignore_chars", "string", N_("chars ignored for nick completion"), - NULL, 0, 0, "[]-^", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "[]-^", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_completion_partial_completion_alert = config_file_new_option ( weechat_config_file, ptr_section, "partial_completion_alert", "boolean", N_("alert user when a partial completion occurs"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_completion_partial_completion_nick = config_file_new_option ( weechat_config_file, ptr_section, "partial_completion_nick", "boolean", N_("partially complete nicks (stop when many nicks found begin with " "same letters)"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_completion_partial_completion_command = config_file_new_option ( weechat_config_file, ptr_section, "partial_completion_command", "boolean", N_("partially complete command names (stop when many commands found " "begin with same letters)"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_completion_partial_completion_command_arg = config_file_new_option ( weechat_config_file, ptr_section, "partial_completion_command_arg", "boolean", N_("partially complete command arguments (stop when many arguments " "found begin with same prefix)"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_completion_partial_completion_count = config_file_new_option ( weechat_config_file, ptr_section, "partial_completion_count", "boolean", N_("display count for each partial completion in bar item"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); /* history */ ptr_section = config_file_new_section (weechat_config_file, "history", @@ -1644,24 +1644,24 @@ config_weechat_init () "max_lines", "integer", N_("maximum number of lines in history per buffer " "(0 = unlimited)"), - NULL, 0, INT_MAX, "4096", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, INT_MAX, "4096", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_history_max_commands = config_file_new_option ( weechat_config_file, ptr_section, "max_commands", "integer", N_("maximum number of user commands in history (0 = " "unlimited)"), - NULL, 0, INT_MAX, "100", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, INT_MAX, "100", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_history_display_default = config_file_new_option ( weechat_config_file, ptr_section, "display_default", "integer", N_("maximum number of commands to display by default in " "history listing (0 = unlimited)"), - NULL, 0, INT_MAX, "5", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, INT_MAX, "5", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); /* proxies */ ptr_section = config_file_new_section (weechat_config_file, "proxy", 0, 0, - &config_weechat_proxy_read, NULL, + &config_weechat_proxy_read_cb, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) @@ -1690,13 +1690,13 @@ config_weechat_init () "at startup, \"*\" means all plugins found (names may " "be partial, for example \"perl\" is ok for " "\"perl.so\")"), - NULL, 0, 0, "*", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "*", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_plugin_debug = config_file_new_option ( weechat_config_file, ptr_section, "debug", "boolean", N_("enable debug messages by default in all plugins (option disabled " "by default, which is highly recommended)"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_plugin_extension = config_file_new_option ( weechat_config_file, ptr_section, "extension", "string", @@ -1708,23 +1708,23 @@ config_weechat_init () #else ".so", #endif - NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_plugin_path = config_file_new_option ( weechat_config_file, ptr_section, "path", "string", N_("path for searching plugins ('%h' will be replaced by " "WeeChat home, ~/.weechat by default)"), - NULL, 0, 0, "%h/plugins", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "%h/plugins", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_plugin_save_config_on_unload = config_file_new_option ( weechat_config_file, ptr_section, "save_config_on_unload", "boolean", N_("save configuration files when unloading plugins"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); /* bars */ ptr_section = config_file_new_section (weechat_config_file, "bar", 0, 0, - &config_weechat_bar_read, NULL, + &config_weechat_bar_read_cb, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) @@ -1738,8 +1738,8 @@ config_weechat_init () /* layout */ ptr_section = config_file_new_section (weechat_config_file, "layout", 0, 0, - &config_weechat_layout_read, NULL, - &config_weechat_layout_write, NULL, + &config_weechat_layout_read_cb, NULL, + &config_weechat_layout_write_cb, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { @@ -1750,9 +1750,9 @@ config_weechat_init () /* filters */ ptr_section = config_file_new_section (weechat_config_file, "filter", 0, 0, - &config_weechat_filter_read, NULL, - &config_weechat_filter_write, NULL, - &config_weechat_filter_write, NULL, + &config_weechat_filter_read_cb, NULL, + &config_weechat_filter_write_cb, NULL, + &config_weechat_filter_write_cb, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { @@ -1763,9 +1763,9 @@ config_weechat_init () /* keys */ ptr_section = config_file_new_section (weechat_config_file, "key", 0, 0, - &config_weechat_key_read, NULL, - &config_weechat_key_write, NULL, - &config_weechat_key_write, NULL, + &config_weechat_key_read_cb, NULL, + &config_weechat_key_write_cb, NULL, + &config_weechat_key_write_cb, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { diff --git a/src/core/wee-proxy.c b/src/core/wee-proxy.c index 5c25c3431..de01fba7c 100644 --- a/src/core/wee-proxy.c +++ b/src/core/wee-proxy.c @@ -264,7 +264,7 @@ proxy_create_option (const char *proxy_name, int index_option, weechat_config_file, weechat_config_section_proxy, option_name, "integer", N_("proxy type (http (default), socks4, socks5)"), - "http|socks4|socks5", 0, 0, value, NULL, + "http|socks4|socks5", 0, 0, value, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); break; case PROXY_OPTION_IPV6: @@ -272,7 +272,7 @@ proxy_create_option (const char *proxy_name, int index_option, weechat_config_file, weechat_config_section_proxy, option_name, "boolean", N_("connect to proxy using ipv6"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); break; case PROXY_OPTION_ADDRESS: @@ -280,7 +280,7 @@ proxy_create_option (const char *proxy_name, int index_option, weechat_config_file, weechat_config_section_proxy, option_name, "string", N_("proxy server address (IP or hostname)"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); break; case PROXY_OPTION_PORT: @@ -288,7 +288,7 @@ proxy_create_option (const char *proxy_name, int index_option, weechat_config_file, weechat_config_section_proxy, option_name, "integer", N_("port for connecting to proxy server"), - NULL, 0, 65535, value, NULL, + NULL, 0, 65535, value, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); break; case PROXY_OPTION_USERNAME: @@ -296,7 +296,7 @@ proxy_create_option (const char *proxy_name, int index_option, weechat_config_file, weechat_config_section_proxy, option_name, "string", N_("username for proxy server"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); break; case PROXY_OPTION_PASSWORD: @@ -304,7 +304,7 @@ proxy_create_option (const char *proxy_name, int index_option, weechat_config_file, weechat_config_section_proxy, option_name, "string", N_("password for proxy server"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); break; case PROXY_NUM_OPTIONS: diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c index 8dc03df39..8f6823ac0 100644 --- a/src/gui/gui-bar.c +++ b/src/gui/gui-bar.c @@ -1300,7 +1300,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "boolean", N_("true if bar is hidden, false if it is displayed"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, &gui_bar_config_change_hidden, NULL, NULL, NULL); break; case GUI_BAR_OPTION_PRIORITY: @@ -1308,7 +1308,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "integer", N_("bar priority (high number means bar displayed first)"), - NULL, 0, INT_MAX, value, NULL, + NULL, 0, INT_MAX, value, NULL, 0, NULL, NULL, &gui_bar_config_change_priority, NULL, NULL, NULL); break; case GUI_BAR_OPTION_TYPE: @@ -1316,7 +1316,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "integer", N_("bar type (root, window, window_active, window_inactive)"), - "root|window|window_active|window_inactive", 0, 0, value, NULL, + "root|window|window_active|window_inactive", 0, 0, value, NULL, 0, &gui_bar_config_check_type, NULL, NULL, NULL, NULL, NULL); break; case GUI_BAR_OPTION_CONDITIONS: @@ -1325,7 +1325,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value option_name, "string", N_("condition(s) for displaying bar (for bars of type " "\"window\")"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, &gui_bar_config_change_conditions, NULL, NULL, NULL); break; case GUI_BAR_OPTION_POSITION: @@ -1333,7 +1333,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "integer", N_("bar position (bottom, top, left, right)"), - "bottom|top|left|right", 0, 0, value, NULL, + "bottom|top|left|right", 0, 0, value, NULL, 0, NULL, NULL, &gui_bar_config_change_position, NULL, NULL, NULL); break; case GUI_BAR_OPTION_FILLING_TOP_BOTTOM: @@ -1344,7 +1344,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value "right) or \"vertical\" (from top to bottom)) when bar " "position is top or bottom"), "horizontal|vertical|columns_horizontal|columns_vertical", - 0, 0, value, NULL, + 0, 0, value, NULL, 0, NULL, NULL, &gui_bar_config_change_filling, NULL, NULL, NULL); break; case GUI_BAR_OPTION_FILLING_LEFT_RIGHT: @@ -1355,7 +1355,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value "right) or \"vertical\" (from top to bottom)) when bar " "position is left or right"), "horizontal|vertical|columns_horizontal|columns_vertical", - 0, 0, value, NULL, + 0, 0, value, NULL, 0, NULL, NULL, &gui_bar_config_change_filling, NULL, NULL, NULL); break; case GUI_BAR_OPTION_SIZE: @@ -1363,7 +1363,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "integer", N_("bar size in chars (0 = auto size)"), - NULL, 0, INT_MAX, value, NULL, + NULL, 0, INT_MAX, value, NULL, 0, &gui_bar_config_check_size, NULL, &gui_bar_config_change_size, NULL, NULL, NULL); @@ -1373,7 +1373,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "integer", N_("max bar size in chars (0 = no limit)"), - NULL, 0, INT_MAX, value, NULL, + NULL, 0, INT_MAX, value, NULL, 0, NULL, NULL, &gui_bar_config_change_size_max, NULL, NULL, NULL); @@ -1383,7 +1383,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "color", N_("default text color for bar"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, &gui_bar_config_change_color, NULL, NULL, NULL); @@ -1393,7 +1393,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "color", N_("default delimiter color for bar"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, &gui_bar_config_change_color, NULL, NULL, NULL); @@ -1403,7 +1403,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "color", N_("default background color for bar"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, &gui_bar_config_change_color, NULL, NULL, NULL); @@ -1413,7 +1413,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "boolean", N_("separator line between bar and other bars/windows"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, &gui_bar_config_change_separator, NULL, NULL, NULL); break; case GUI_BAR_OPTION_ITEMS: @@ -1421,7 +1421,7 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value weechat_config_file, weechat_config_section_bar, option_name, "string", N_("items of bar"), - NULL, 0, 0, value, NULL, + NULL, 0, 0, value, NULL, 0, NULL, NULL, &gui_bar_config_change_items, NULL, NULL, NULL); break; case GUI_BAR_NUM_OPTIONS: diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index fd09dd4ef..9fe2d8a9d 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -760,66 +760,101 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion) 0, WEECHAT_LIST_POS_SORT); gui_completion_list_add (completion, "toggle", 0, WEECHAT_LIST_POS_END); - if (CONFIG_BOOLEAN(option_found) == CONFIG_BOOLEAN_TRUE) - gui_completion_list_add (completion, "on", - 0, WEECHAT_LIST_POS_BEGINNING); + if (option_found->value) + { + if (CONFIG_BOOLEAN(option_found) == CONFIG_BOOLEAN_TRUE) + gui_completion_list_add (completion, "on", + 0, WEECHAT_LIST_POS_BEGINNING); + else + gui_completion_list_add (completion, "off", + 0, WEECHAT_LIST_POS_BEGINNING); + } else - gui_completion_list_add (completion, "off", + { + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, 0, WEECHAT_LIST_POS_BEGINNING); + } break; case CONFIG_OPTION_TYPE_INTEGER: - length = 64; - value_string = malloc (length); - if (value_string) + if (option_found->string_values) { - if (option_found->string_values) + for (i = 0; option_found->string_values[i]; i++) { - for (i = 0; option_found->string_values[i]; i++) + gui_completion_list_add (completion, + option_found->string_values[i], + 0, WEECHAT_LIST_POS_SORT); + } + gui_completion_list_add (completion, "++1", + 0, WEECHAT_LIST_POS_END); + gui_completion_list_add (completion, "--1", + 0, WEECHAT_LIST_POS_END); + if (option_found->value) + { + gui_completion_list_add (completion, + option_found->string_values[CONFIG_INTEGER(option_found)], + 0, WEECHAT_LIST_POS_BEGINNING); + } + else + { + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, + 0, WEECHAT_LIST_POS_BEGINNING); + } + } + else + { + if (option_found->value && CONFIG_INTEGER(option_found) > option_found->min) + gui_completion_list_add (completion, "--1", + 0, WEECHAT_LIST_POS_BEGINNING); + if (option_found->value && CONFIG_INTEGER(option_found) < option_found->max) + gui_completion_list_add (completion, "++1", + 0, WEECHAT_LIST_POS_BEGINNING); + if (option_found->value) + { + value_string = malloc (64); + if (value_string) { + snprintf (value_string, length, + "%d", CONFIG_INTEGER(option_found)); gui_completion_list_add (completion, - option_found->string_values[i], - 0, WEECHAT_LIST_POS_SORT); + value_string, + 0, WEECHAT_LIST_POS_BEGINNING); + free (value_string); } - gui_completion_list_add (completion, "++1", - 0, WEECHAT_LIST_POS_END); - gui_completion_list_add (completion, "--1", - 0, WEECHAT_LIST_POS_END); - snprintf (value_string, length, - "%s", - option_found->string_values[CONFIG_INTEGER(option_found)]); } else { - if (CONFIG_INTEGER(option_found) > option_found->min) - gui_completion_list_add (completion, "--1", - 0, WEECHAT_LIST_POS_BEGINNING); - if (CONFIG_INTEGER(option_found) < option_found->max) - gui_completion_list_add (completion, "++1", - 0, WEECHAT_LIST_POS_BEGINNING); - snprintf (value_string, length, - "%d", CONFIG_INTEGER(option_found)); + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, + 0, WEECHAT_LIST_POS_BEGINNING); } - gui_completion_list_add (completion, - value_string, - 0, WEECHAT_LIST_POS_BEGINNING); - free (value_string); } break; case CONFIG_OPTION_TYPE_STRING: gui_completion_list_add (completion, "\"\"", 0, WEECHAT_LIST_POS_BEGINNING); - length = strlen (CONFIG_STRING(option_found)) + 2 + 1; - value_string = malloc (length); - if (value_string) + if (option_found->value) + { + length = strlen (CONFIG_STRING(option_found)) + 2 + 1; + value_string = malloc (length); + if (value_string) + { + snprintf (value_string, length, + "\"%s\"", + CONFIG_STRING(option_found)); + gui_completion_list_add (completion, + value_string, + 0, WEECHAT_LIST_POS_BEGINNING); + free (value_string); + } + } + else { - snprintf (value_string, length, - "\"%s\"", - CONFIG_STRING(option_found)); gui_completion_list_add (completion, - value_string, + WEECHAT_CONFIG_OPTION_NULL, 0, WEECHAT_LIST_POS_BEGINNING); - free (value_string); } break; case CONFIG_OPTION_TYPE_COLOR: @@ -836,17 +871,34 @@ gui_completion_list_add_option_value (struct t_gui_completion *completion) 0, WEECHAT_LIST_POS_END); gui_completion_list_add (completion, "--1", 0, WEECHAT_LIST_POS_END); - color_name = gui_color_get_name (CONFIG_INTEGER(option_found)); - if (color_name) + if (option_found->value) + { + color_name = gui_color_get_name (CONFIG_INTEGER(option_found)); + if (color_name) + { + gui_completion_list_add (completion, + color_name, + 0, WEECHAT_LIST_POS_BEGINNING); + } + } + else { gui_completion_list_add (completion, - color_name, + WEECHAT_CONFIG_OPTION_NULL, 0, WEECHAT_LIST_POS_BEGINNING); } break; case CONFIG_NUM_OPTION_TYPES: break; } + if (option_found->value + && option_found->null_value_allowed) + { + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, + 0, + WEECHAT_LIST_POS_END); + } } } } diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index f40f9e3e7..da75862a4 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -631,7 +631,8 @@ alias_config_create_option (void *data, struct t_config_file *config_file, weechat_config_new_option ( config_file, section, option_name, "string", NULL, - NULL, 0, 0, "", value, NULL, NULL, + NULL, 0, 0, "", value, 0, + NULL, NULL, &alias_config_change_cb, NULL, &alias_config_delete_cb, NULL); @@ -750,7 +751,8 @@ alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc, weechat_config_new_option ( alias_config_file, alias_config_section_cmd, alias_name, "string", NULL, - NULL, 0, 0, "", argv_eol[2], NULL, NULL, + NULL, 0, 0, "", argv_eol[2], 0, + NULL, NULL, &alias_config_change_cb, NULL, &alias_config_delete_cb, NULL); diff --git a/src/plugins/aspell/weechat-aspell-config.c b/src/plugins/aspell/weechat-aspell-config.c index 92c254533..a4c94562a 100644 --- a/src/plugins/aspell/weechat-aspell-config.c +++ b/src/plugins/aspell/weechat-aspell-config.c @@ -191,7 +191,8 @@ weechat_aspell_config_dict_create_option (void *data, config_file, section, option_name, "string", _("comma separated list of dictionaries to use on this buffer"), - NULL, 0, 0, "", value, NULL, NULL, + NULL, 0, 0, "", value, 0, + NULL, NULL, &weechat_aspell_config_dict_change, NULL, NULL, NULL); rc = (ptr_option) ? @@ -272,7 +273,7 @@ weechat_aspell_config_init () weechat_aspell_config_file, ptr_section, "color", "color", N_("color used for mispelled words"), - NULL, 0, 0, "lightred", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "lightred", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); /* check */ ptr_section = weechat_config_new_section (weechat_aspell_config_file, "check", @@ -293,7 +294,7 @@ weechat_aspell_config_init () "enabled (spell checking is disabled for all other commands)"), NULL, 0, 0, "ame,amsg,away,command,cycle,kick,kickban,me,msg,notice,part,query," - "quit,topic", NULL, + "quit,topic", NULL, 0, NULL, NULL, &weechat_aspell_config_change_commands, NULL, NULL, NULL); weechat_aspell_config_check_default_dict = weechat_config_new_option ( weechat_aspell_config_file, ptr_section, @@ -301,19 +302,19 @@ weechat_aspell_config_init () N_("default dictionary (or comma separated list of dictionaries) to " "use when buffer has no dictionary defined (leave blank to disable " "aspell on buffers for which you didn't explicitely enabled it)"), - NULL, 0, 0, "", NULL, + NULL, 0, 0, "", NULL, 0, NULL, NULL, &weechat_aspell_config_change_default_dict, NULL, NULL, NULL); weechat_aspell_config_check_word_min_length = weechat_config_new_option ( weechat_aspell_config_file, ptr_section, "word_min_length", "integer", N_("minimum length for a word to be spell checked (use 0 to check all " "words)"), - NULL, 0, INT_MAX, "2", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, INT_MAX, "2", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); weechat_aspell_config_check_during_search = weechat_config_new_option ( weechat_aspell_config_file, ptr_section, "during_search", "boolean", N_("check words during text search in buffer"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); /* dict */ ptr_section = weechat_config_new_section (weechat_aspell_config_file, "dict", diff --git a/src/plugins/charset/charset.c b/src/plugins/charset/charset.c index 487fec0ab..78a002ce1 100644 --- a/src/plugins/charset/charset.c +++ b/src/plugins/charset/charset.c @@ -109,7 +109,8 @@ charset_config_create_option (void *data, struct t_config_file *config_file, ptr_option = weechat_config_new_option ( config_file, section, option_name, "string", NULL, - NULL, 0, 0, "", value, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", value, 0, + NULL, NULL, NULL, NULL, NULL, NULL); rc = (ptr_option) ? WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; } @@ -163,13 +164,13 @@ charset_config_init () (charset_terminal && charset_internal && (strcasecmp (charset_terminal, charset_internal) != 0)) ? - charset_terminal : "iso-8859-1", NULL, + charset_terminal : "iso-8859-1", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); charset_default_encode = weechat_config_new_option ( charset_config_file, ptr_section, "encode", "string", N_("global encoding charset"), - NULL, 0, 0, "", NULL, + NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); ptr_section = weechat_config_new_section (charset_config_file, "decode", diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index f6cf3abeb..d1ffcf617 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -530,10 +530,8 @@ int irc_command_connect (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { - struct t_irc_server server_tmp; int i, nb_connect, connect_ok, all_servers, no_join, port, ipv6, ssl; - int default_ipv6, default_ssl; - char *error, value[16]; + char *name, *error; long number; IRC_GET_SERVER(buffer); @@ -606,65 +604,21 @@ irc_command_connect (void *data, struct t_gui_buffer *buffer, int argc, } else { - irc_server_init (&server_tmp); - - default_ipv6 = server_tmp.ipv6; - default_ssl = server_tmp.ssl; - - server_tmp.name = irc_server_get_name_without_port (argv[i]); - server_tmp.addresses = strdup (argv[i]); - server_tmp.ipv6 = ipv6; - server_tmp.ssl = ssl; - - ptr_server = irc_server_new (server_tmp.name, - server_tmp.autoconnect, - server_tmp.autoreconnect, - server_tmp.autoreconnect_delay, - server_tmp.proxy, - server_tmp.addresses, - server_tmp.ipv6, - server_tmp.ssl, - server_tmp.password, - server_tmp.nicks, - server_tmp.username, - server_tmp.realname, - server_tmp.local_hostname, - server_tmp.command, - 1, /* command_delay */ - server_tmp.autojoin, - 1); /* autorejoin */ + name = irc_server_get_name_without_port (argv[i]); + ptr_server = irc_server_alloc ((name) ? name : argv[i]); + if (name) + free (name); if (ptr_server) { + ptr_server->temp_server = 1; + weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES], + argv[i], 1); weechat_printf (NULL, - _("%s: server %s%s%s created"), + _("%s: server %s%s%s created (temporary server, NOT SAVED!)"), IRC_PLUGIN_NAME, IRC_COLOR_CHAT_SERVER, - server_tmp.name, + ptr_server->name, IRC_COLOR_CHAT); - - /* create server options */ - irc_server_new_option (&server_tmp, - IRC_CONFIG_SERVER_ADDRESSES, - server_tmp.addresses); - if (default_ipv6 != server_tmp.ipv6) - { - snprintf (value, sizeof (value), - "%s", - (server_tmp.ipv6) ? "on" : "off"); - irc_server_new_option (&server_tmp, - IRC_CONFIG_SERVER_IPV6, - value); - } - if (default_ssl != server_tmp.ssl) - { - snprintf (value, sizeof (value), - "%s", - (server_tmp.ssl) ? "on" : "off"); - irc_server_new_option (&server_tmp, - IRC_CONFIG_SERVER_SSL, - value); - } - if (!irc_command_connect_one_server (ptr_server, 0)) connect_ok = 0; } @@ -2776,12 +2730,9 @@ int irc_command_server (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { - int i, detailed_list, one_server_found, length; - int default_autoconnect, default_ipv6, default_ssl; - struct t_irc_server server_tmp, *ptr_server2, *server_found, *new_server; - char *server_name, *mask, value[16], charset_modifier[256]; - struct t_infolist *infolist; - struct t_config_option *ptr_option; + int i, detailed_list, one_server_found; + struct t_irc_server *ptr_server2, *server_found, *new_server; + char *server_name, charset_modifier[256]; IRC_GET_SERVER_CHANNEL(buffer); @@ -2852,11 +2803,80 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc, return WEECHAT_RC_OK; } - if (weechat_strcasecmp (argv[1], "rename") == 0) + if (weechat_strcasecmp (argv[1], "add") == 0) { if (argc < 4) { - IRC_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server rename"); + IRC_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server add"); + } + if (irc_server_search (argv[2])) + { + weechat_printf (NULL, + _("%s%s: server \"%s\" already exists, " + "can't create it!"), + weechat_prefix ("error"), IRC_PLUGIN_NAME, + argv[2]); + return WEECHAT_RC_ERROR; + } + + new_server = irc_server_alloc (argv[2]); + if (!new_server) + { + weechat_printf (NULL, + _("%s%s: unable to create server"), + weechat_prefix ("error"), IRC_PLUGIN_NAME); + return WEECHAT_RC_ERROR; + } + + weechat_config_option_set (new_server->options[IRC_SERVER_OPTION_ADDRESSES], + argv[3], 1); + + /* parse arguments */ + for (i = 4; i < argc; i++) + { + if (argv[i][0] == '-') + { + if (weechat_strcasecmp (argv[i], "-auto") == 0) + { + weechat_config_option_set (new_server->options[IRC_SERVER_OPTION_AUTOCONNECT], + "on", 1); + } + if (weechat_strcasecmp (argv[i], "-noauto") == 0) + { + weechat_config_option_set (new_server->options[IRC_SERVER_OPTION_AUTOCONNECT], + "off", 1); + } + if (weechat_strcasecmp (argv[i], "-ipv6") == 0) + { + weechat_config_option_set (new_server->options[IRC_SERVER_OPTION_IPV6], + "on", 1); + } + if (weechat_strcasecmp (argv[i], "-ssl") == 0) + { + weechat_config_option_set (new_server->options[IRC_SERVER_OPTION_SSL], + "on", 1); + } + } + } + + weechat_printf (NULL, + _("%s: server %s%s%s created"), + IRC_PLUGIN_NAME, + IRC_COLOR_CHAT_SERVER, + new_server->name, + IRC_COLOR_CHAT); + + if (IRC_SERVER_OPTION_BOOLEAN(new_server, IRC_SERVER_OPTION_AUTOCONNECT)) + irc_server_connect (new_server, 0); + + return WEECHAT_RC_OK; + } + + if (weechat_strcasecmp (argv[1], "copy") == 0) + { + if (argc < 4) + { + IRC_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server copy"); } /* look for server by name */ @@ -2867,7 +2887,7 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc, _("%s%s: server \"%s\" not found for " "\"%s\" command"), weechat_prefix ("error"), IRC_PLUGIN_NAME, - argv[2], "server rename"); + argv[2], "server copy"); return WEECHAT_RC_ERROR; } @@ -2878,15 +2898,16 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc, _("%s%s: server \"%s\" already exists for " "\"%s\" command"), weechat_prefix ("error"), IRC_PLUGIN_NAME, - argv[3], "server rename"); + argv[3], "server copy"); return WEECHAT_RC_ERROR; } - /* rename server */ - if (irc_server_rename (server_found, argv[3])) + /* copy server */ + new_server = irc_server_copy (server_found, argv[3]); + if (new_server) { weechat_printf (NULL, - _("%s: server %s%s%s has been renamed to " + _("%s: server %s%s%s has been copied to " "%s%s"), IRC_PLUGIN_NAME, IRC_COLOR_CHAT_SERVER, @@ -2899,130 +2920,60 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc, return WEECHAT_RC_ERROR; } - - if (weechat_strcasecmp (argv[1], "add") == 0) + + if (weechat_strcasecmp (argv[1], "rename") == 0) { if (argc < 4) { - IRC_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server add"); + IRC_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server rename"); } - if (irc_server_search (argv[2])) + + /* look for server by name */ + server_found = irc_server_search (argv[2]); + if (!server_found) { weechat_printf (NULL, - _("%s%s: server \"%s\" already exists, " - "can't create it!"), + _("%s%s: server \"%s\" not found for " + "\"%s\" command"), weechat_prefix ("error"), IRC_PLUGIN_NAME, - argv[2]); + argv[2], "server rename"); return WEECHAT_RC_ERROR; } - /* init server struct */ - irc_server_init (&server_tmp); - - default_autoconnect = server_tmp.autoconnect; - default_ipv6 = server_tmp.ipv6; - default_ssl = server_tmp.ssl; - - server_tmp.name = strdup (argv[2]); - server_tmp.addresses = strdup (argv[3]); - - /* parse arguments */ - for (i = 4; i < argc; i++) + /* check if target name already exists */ + if (irc_server_search (argv[3])) { - if (argv[i][0] == '-') - { - if (weechat_strcasecmp (argv[i], "-auto") == 0) - server_tmp.autoconnect = 1; - if (weechat_strcasecmp (argv[i], "-noauto") == 0) - server_tmp.autoconnect = 0; - if (weechat_strcasecmp (argv[i], "-ipv6") == 0) - server_tmp.ipv6 = 1; - if (weechat_strcasecmp (argv[i], "-ssl") == 0) - server_tmp.ssl = 1; - } + weechat_printf (NULL, + _("%s%s: server \"%s\" already exists for " + "\"%s\" command"), + weechat_prefix ("error"), IRC_PLUGIN_NAME, + argv[3], "server rename"); + return WEECHAT_RC_ERROR; } - /* create new server */ - new_server = irc_server_new (server_tmp.name, - server_tmp.autoconnect, - server_tmp.autoreconnect, - server_tmp.autoreconnect_delay, - server_tmp.proxy, - server_tmp.addresses, - server_tmp.ipv6, - server_tmp.ssl, - server_tmp.password, - server_tmp.nicks, - server_tmp.username, - server_tmp.realname, - server_tmp.local_hostname, - server_tmp.command, - 1, /* command_delay */ - server_tmp.autojoin, - 1); /* autorejoin */ - if (new_server) + /* rename server */ + if (irc_server_rename (server_found, argv[3])) { weechat_printf (NULL, - _("%s: server %s%s%s created"), + _("%s: server %s%s%s has been renamed to " + "%s%s"), IRC_PLUGIN_NAME, IRC_COLOR_CHAT_SERVER, - server_tmp.name, - IRC_COLOR_CHAT); - - /* create server options */ - irc_server_new_option (&server_tmp, - IRC_CONFIG_SERVER_ADDRESSES, - server_tmp.addresses); - if (default_autoconnect != server_tmp.autoconnect) - { - snprintf (value, sizeof (value), - "%s", - (server_tmp.autoconnect) ? "on" : "off"); - irc_server_new_option (&server_tmp, - IRC_CONFIG_SERVER_AUTOCONNECT, - value); - } - if (default_ipv6 != server_tmp.ipv6) - { - snprintf (value, sizeof (value), - "%s", - (server_tmp.ipv6) ? "on" : "off"); - irc_server_new_option (&server_tmp, - IRC_CONFIG_SERVER_IPV6, - value); - } - if (default_ssl != server_tmp.ssl) - { - snprintf (value, sizeof (value), - "%s", - (server_tmp.ssl) ? "on" : "off"); - irc_server_new_option (&server_tmp, - IRC_CONFIG_SERVER_SSL, - value); - } - } - else - { - weechat_printf (NULL, - _("%s%s: unable to create server"), - weechat_prefix ("error"), IRC_PLUGIN_NAME); - irc_server_free_data (&server_tmp); - return WEECHAT_RC_ERROR; + argv[2], + IRC_COLOR_CHAT, + IRC_COLOR_CHAT_SERVER, + argv[3]); + return WEECHAT_RC_OK; } - if (new_server->autoconnect) - irc_server_connect (new_server, 0); - - irc_server_free_data (&server_tmp); - - return WEECHAT_RC_OK; + return WEECHAT_RC_ERROR; } - if (weechat_strcasecmp (argv[1], "copy") == 0) + if (weechat_strcasecmp (argv[1], "keep") == 0) { - if (argc < 4) + if (argc < 3) { - IRC_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server copy"); + IRC_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server keep"); } /* look for server by name */ @@ -3033,38 +2984,31 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc, _("%s%s: server \"%s\" not found for " "\"%s\" command"), weechat_prefix ("error"), IRC_PLUGIN_NAME, - argv[2], "server copy"); + argv[2], "server keep"); return WEECHAT_RC_ERROR; } - /* check if target name already exists */ - if (irc_server_search (argv[3])) + /* check that is it temporary server */ + if (!server_found->temp_server) { weechat_printf (NULL, - _("%s%s: server \"%s\" already exists for " - "\"%s\" command"), + _("%s%s: server \"%s\" is not a temporary server"), weechat_prefix ("error"), IRC_PLUGIN_NAME, - argv[3], "server copy"); + argv[2], "server keep"); return WEECHAT_RC_ERROR; } - /* duplicate server */ - new_server = irc_server_duplicate (server_found, argv[3]); - if (new_server) - { - weechat_printf (NULL, - _("%s: server %s%s%s has been copied to " - "%s%s"), - IRC_PLUGIN_NAME, - IRC_COLOR_CHAT_SERVER, - argv[2], - IRC_COLOR_CHAT, - IRC_COLOR_CHAT_SERVER, - argv[3]); - return WEECHAT_RC_OK; - } + /* remove temporary flag on server */ + server_found->temp_server = 0; - return WEECHAT_RC_ERROR; + weechat_printf (NULL, + _("%s: server %s%s%s is not temporary any more"), + IRC_PLUGIN_NAME, + IRC_COLOR_CHAT_SERVER, + argv[2], + IRC_COLOR_CHAT); + + return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[1], "del") == 0) @@ -3097,27 +3041,7 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc, } server_name = strdup (server_found->name); - - /* remove all options (server will be removed when last option is removed) */ - length = 32 + strlen (server_found->name) + 1; - mask = malloc (length); - if (mask) - { - snprintf (mask, length, "irc.server.%s.*", server_found->name); - infolist = weechat_infolist_get ("option", NULL, mask); - free (mask); - while (weechat_infolist_next (infolist)) - { - weechat_config_search_with_string (weechat_infolist_string (infolist, - "full_name"), - NULL, NULL, &ptr_option, - NULL); - if (ptr_option) - weechat_config_option_unset (ptr_option); - } - weechat_infolist_free (infolist); - } - + irc_server_free (server_found); weechat_printf (NULL, _("%s: Server %s%s%s has been deleted"), IRC_PLUGIN_NAME, @@ -4114,7 +4038,8 @@ irc_command_init () "[-auto | -noauto] [-ipv6] [-ssl]] | " "[copy servername newservername] | " "[rename servername newservername] | " - "[del servername] | [deloutq] | [switch]"), + "[keep servername] | [del servername] | " + "[deloutq] | [switch]"), N_(" list: list servers (no parameter implies " "this list)\n" " listfull: list servers with detailed info for " @@ -4132,6 +4057,8 @@ irc_command_init () " ssl: use SSL protocol\n" " copy: duplicate a server\n" " rename: rename a server\n" + " keep: keep server in config file (for " + "temporary servers only)\n" " del: delete a server\n" " deloutq: delete messages out queue for all " "servers (all messages WeeChat is currently " @@ -4150,7 +4077,7 @@ irc_command_init () " /server del freenode\n" " /server deloutq\n" " /server switch"), - "add|copy|rename|del|deloutq|list|listfull|switch " + "add|copy|rename|keep|del|deloutq|list|listfull|switch " "%(irc_servers) %(irc_servers)", &irc_command_server, NULL); weechat_hook_command ("servlist", diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index e00a2fe0a..8bf10aa81 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -36,16 +36,6 @@ #include "irc-channel.h" -char *irc_config_server_option_string[IRC_CONFIG_NUM_SERVER_OPTIONS] = -{ "autoconnect", "autoreconnect", "autoreconnect_delay", "proxy", "addresses", - "ipv6", "ssl", "password", "nicks", "username", "realname", "local_hostname", - "command", "command_delay", "autojoin", "autorejoin" -}; -char *irc_config_server_option_default[IRC_CONFIG_NUM_SERVER_OPTIONS] = -{ "off", "on", "30", "", "", "off", "off", "", "", "", "", "", "", "0", "", - "off", "" -}; - struct t_config_file *irc_config_file = NULL; struct t_config_section *irc_config_section_server_default = NULL; struct t_config_section *irc_config_section_server = NULL; @@ -89,36 +79,12 @@ struct t_config_option *irc_config_network_send_unknown_commands; /* IRC config, server section */ -struct t_config_option *irc_config_server_default[IRC_CONFIG_NUM_SERVER_OPTIONS]; +struct t_config_option *irc_config_server_default[IRC_SERVER_NUM_OPTIONS]; struct t_hook *hook_config_color_nicks_number = NULL; +int irc_config_write_temp_servers = 0; -/* - * irc_config_search_server_option: search a server option name - * return index of option in array - * "irc_config_server_option_str", or -1 if - * not found - */ - -int -irc_config_search_server_option (const char *option_name) -{ - int i; - - if (!option_name) - return -1; - - for (i = 0; i < IRC_CONFIG_NUM_SERVER_OPTIONS; i++) - { - if (weechat_strcasecmp (irc_config_server_option_string[i], - option_name) == 0) - return i; - } - - /* server option not found */ - return -1; -} struct t_irc_server * irc_config_get_server_from_option_name (const char *name) @@ -365,32 +331,28 @@ irc_config_change_network_send_unknown_commands (void *data, void irc_config_server_default_change_cb (void *data, struct t_config_option *option) { - int index_option, length; - char *option_full_name; + int index_option; struct t_irc_server *ptr_server; - struct t_config_option *ptr_option; - index_option = irc_config_search_server_option (data); + index_option = irc_server_search_option (data); if (index_option >= 0) { for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { - length = strlen (ptr_server->name) + 1 + strlen (data) + 1; - option_full_name = malloc (length); - if (option_full_name) + if (weechat_config_option_is_null (ptr_server->options[index_option])) { - ptr_option = weechat_config_search_option (irc_config_file, - irc_config_section_server, - option_full_name); - if (!ptr_option) + switch (index_option) { - /* option does not exist for server, so we change value - with default value */ - irc_server_set_with_option (ptr_server, index_option, - option); + case IRC_SERVER_OPTION_ADDRESSES: + irc_server_set_addresses (ptr_server, + weechat_config_string (option)); + break; + case IRC_SERVER_OPTION_NICKS: + irc_server_set_nicks (ptr_server, + weechat_config_string (option)); + break; } - free (option_full_name); } } } @@ -407,155 +369,28 @@ irc_config_server_change_cb (void *data, struct t_config_option *option) char *name; struct t_irc_server *ptr_server; - index_option = irc_config_search_server_option (data); + index_option = irc_server_search_option (data); if (index_option >= 0) { name = weechat_config_option_get_pointer (option, "name"); ptr_server = irc_config_get_server_from_option_name (name); if (ptr_server) { - irc_server_set_with_option (ptr_server, index_option, option); - } - } -} - -/* - * irc_config_server_delete_cb: callback called when a server option is deleted - */ - -void -irc_config_server_delete_cb (void *data, struct t_config_option *option) -{ - int i, index_option, length; - char *name, *mask; - struct t_irc_server *ptr_server; - struct t_infolist *infolist; - - index_option = irc_config_search_server_option (data); - if (index_option >= 0) - { - name = weechat_config_option_get_pointer (option, "name"); - ptr_server = irc_config_get_server_from_option_name (name); - if (ptr_server) - { - irc_server_set_with_option (ptr_server, index_option, - irc_config_server_default[index_option]); - - /* look if we should remove server (no more option for server) */ - if (!ptr_server->is_connected) + switch (index_option) { - length = strlen (ptr_server->name) + 64; - mask = malloc (length); - if (mask) - { - snprintf (mask, length, "irc.server.%s.*", - ptr_server->name); - infolist = weechat_infolist_get ("option", NULL, mask); - i = 0; - while (weechat_infolist_next (infolist)) - { - i++; - } - if (i <= 1) - irc_server_free (ptr_server); - weechat_infolist_free (infolist); - free (mask); - } - } - } - } -} - -/* - * irc_config_reload_servers_from_config: create/update servers from options - * read in config file - */ - -void -irc_config_reload_servers_from_config () -{ - struct t_infolist *infolist; - struct t_irc_server *ptr_server; - struct t_config_option *ptr_option; - const char *full_name, *option_name; - char *server_name, *pos_option; - int i, index_option; - - infolist = weechat_infolist_get ("option", NULL, "irc.server.*"); - while (weechat_infolist_next (infolist)) - { - full_name = weechat_infolist_string (infolist, "full_name"); - option_name = weechat_infolist_string (infolist, "option_name"); - if (full_name && option_name) - { - pos_option = strrchr (option_name, '.'); - if (pos_option) - { - server_name = weechat_strndup (option_name, - pos_option - option_name); - if (server_name) - { - pos_option++; - ptr_server = irc_server_search (server_name); - if (!ptr_server) - { - /* create server, it's first time we see it */ - ptr_server = irc_server_alloc (server_name); - if (!ptr_server) - { - weechat_printf (NULL, - _("%s%s: error creating server " - "\"%s\""), - weechat_prefix ("error"), - IRC_PLUGIN_NAME, server_name); - } - } - if (ptr_server) - { - index_option = irc_config_search_server_option (pos_option); - if (index_option >= 0) - { - if (!ptr_server->reloaded_from_config) - { - /* it's first time we see server, and we are - reloading config, then initialize server - with default values (will be overwritten - by config later in this function - */ - for (i = 0; i < IRC_CONFIG_NUM_SERVER_OPTIONS; i++) - { - irc_server_set_with_option (ptr_server, - i, - irc_config_server_default[i]); - } - ptr_server->reloaded_from_config = 1; - } - weechat_config_search_with_string (full_name, NULL, - NULL, &ptr_option, - NULL); - if (ptr_option) - { - irc_server_set_with_option (ptr_server, - index_option, - ptr_option); - } - } - } - else - { - weechat_printf (NULL, - _("%s%s: error creating option " - "\"%s\" for server \"%s\" (server " - "not found)"), - weechat_prefix ("error"), IRC_PLUGIN_NAME, - pos_option, server_name); - } - free (server_name); - } + case IRC_SERVER_OPTION_ADDRESSES: + irc_server_set_addresses (ptr_server, + IRC_SERVER_OPTION_STRING(ptr_server, + IRC_SERVER_OPTION_ADDRESSES)); + break; + case IRC_SERVER_OPTION_NICKS: + irc_server_set_nicks (ptr_server, + IRC_SERVER_OPTION_STRING(ptr_server, + IRC_SERVER_OPTION_NICKS)); + break; } } } - weechat_infolist_free (infolist); } /* @@ -571,11 +406,10 @@ irc_config_reload (void *data, struct t_config_file *config_file) /* make C compiler happy */ (void) data; - weechat_config_section_free_options (irc_config_section_server); - for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { + ptr_server->reloading_from_config = 1; ptr_server->reloaded_from_config = 0; } @@ -583,9 +417,6 @@ irc_config_reload (void *data, struct t_config_file *config_file) rc = weechat_config_reload (config_file); - if (rc == WEECHAT_CONFIG_READ_OK) - irc_config_reload_servers_from_config (1); - ptr_server = irc_servers; while (ptr_server) { @@ -601,9 +432,6 @@ irc_config_reload (void *data, struct t_config_file *config_file) "memory because it's currently used"), weechat_prefix ("error"), IRC_PLUGIN_NAME, ptr_server->name); - /* TODO: create options for server in section (options that - are not default one */ - // ... } else irc_server_free (ptr_server); @@ -616,7 +444,7 @@ irc_config_reload (void *data, struct t_config_file *config_file) } /* - * irc_config_ignore_read: read ignore option from config file + * irc_config_ignore_read: read ignore option from configuration file * return 1 if ok, 0 if error */ @@ -682,20 +510,42 @@ irc_config_ignore_write (void *data, struct t_config_file *config_file, } /* - * irc_config_server_write_default: write default server section in configuration file + * irc_config_server_write_default_cb: write default server section in + * configuration file */ void -irc_config_server_write_default (void *data, struct t_config_file *config_file, - const char *section_name) +irc_config_server_write_default_cb (void *data, + struct t_config_file *config_file, + const char *section_name) { + int i; + char option_name[128]; + /* make C compiler happy */ (void) data; weechat_config_write_line (config_file, section_name, NULL); - weechat_config_write_line (config_file, "freenode.addresses", - "%s", "\"chat.freenode.net/6667\""); + for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) + { + snprintf (option_name, sizeof (option_name), + "freenode.%s", + irc_server_option_string[i]); + switch (i) + { + case IRC_SERVER_OPTION_ADDRESSES: + weechat_config_write_line (config_file, + option_name, + "%s", "\"chat.freenode.net/6667\""); + break; + default: + weechat_config_write_line (config_file, + option_name, + WEECHAT_CONFIG_OPTION_NULL); + break; + } + } } /* @@ -707,11 +557,11 @@ irc_config_server_new_option (struct t_config_file *config_file, struct t_config_section *section, int index_option, const char *option_name, + const char *default_value, const char *value, + int null_value_allowed, void *callback_change, - void *callback_change_data, - void *callback_delete, - void *callback_delete_data) + void *callback_change_data) { struct t_config_option *new_option; @@ -719,140 +569,152 @@ irc_config_server_new_option (struct t_config_file *config_file, switch (index_option) { - case IRC_CONFIG_SERVER_AUTOCONNECT: + case IRC_SERVER_OPTION_AUTOCONNECT: new_option = weechat_config_new_option ( config_file, section, option_name, "boolean", N_("automatically connect to server when WeeChat is starting"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_AUTORECONNECT: + case IRC_SERVER_OPTION_AUTORECONNECT: new_option = weechat_config_new_option ( config_file, section, option_name, "boolean", N_("automatically reconnect to server when disconnected"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_AUTORECONNECT_DELAY: + case IRC_SERVER_OPTION_AUTORECONNECT_DELAY: new_option = weechat_config_new_option ( config_file, section, option_name, "integer", N_("delay (in seconds) before trying again to reconnect to server"), NULL, 0, 65535, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_PROXY: + case IRC_SERVER_OPTION_PROXY: new_option = weechat_config_new_option ( config_file, section, option_name, "string", N_("proxy used for this server (optional)"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_ADDRESSES: + case IRC_SERVER_OPTION_ADDRESSES: new_option = weechat_config_new_option ( config_file, section, option_name, "string", N_("list of IP/port or hostname/port for server (separated by comma)"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_IPV6: + case IRC_SERVER_OPTION_IPV6: new_option = weechat_config_new_option ( config_file, section, option_name, "boolean", N_("use IPv6 protocol for server communication"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_SSL: + case IRC_SERVER_OPTION_SSL: new_option = weechat_config_new_option ( config_file, section, option_name, "boolean", N_("use SSL for server communication"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_PASSWORD: + case IRC_SERVER_OPTION_PASSWORD: new_option = weechat_config_new_option ( config_file, section, option_name, "string", N_("password for IRC server"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_NICKS: + case IRC_SERVER_OPTION_NICKS: new_option = weechat_config_new_option ( config_file, section, option_name, "string", N_("nicknames to use on IRC server (separated by comma)"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_USERNAME: + case IRC_SERVER_OPTION_USERNAME: new_option = weechat_config_new_option ( config_file, section, option_name, "string", N_("user name to use on IRC server"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_REALNAME: + case IRC_SERVER_OPTION_REALNAME: new_option = weechat_config_new_option ( config_file, section, option_name, "string", N_("real name to use on IRC server"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_LOCAL_HOSTNAME: + case IRC_SERVER_OPTION_LOCAL_HOSTNAME: new_option = weechat_config_new_option ( config_file, section, option_name, "string", N_("custom local hostname/IP for server (optional, if empty " "local hostname is used)"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_COMMAND: + case IRC_SERVER_OPTION_COMMAND: new_option = weechat_config_new_option ( config_file, section, option_name, "string", @@ -860,47 +722,51 @@ irc_config_server_new_option (struct t_config_file *config_file, "be separated by ';', use '\\;' for a semicolon, special variables " "$nick, $channel and $server are replaced by their value)"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_COMMAND_DELAY: + case IRC_SERVER_OPTION_COMMAND_DELAY: new_option = weechat_config_new_option ( config_file, section, option_name, "integer", N_("delay (in seconds) after command was executed (example: give some " "time for authentication)"), NULL, 0, 3600, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_AUTOJOIN: + case IRC_SERVER_OPTION_AUTOJOIN: new_option = weechat_config_new_option ( config_file, section, option_name, "string", N_("comma separated list of channels to join when connected to server " "(example: \"#chan1,#chan2,#chan3 key1,key2\")"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_SERVER_AUTOREJOIN: + case IRC_SERVER_OPTION_AUTOREJOIN: new_option = weechat_config_new_option ( config_file, section, option_name, "boolean", N_("automatically rejoin channels when kicked"), NULL, 0, 0, - irc_config_server_option_default[index_option], value, + default_value, value, + null_value_allowed, NULL, NULL, callback_change, callback_change_data, - callback_delete, callback_delete_data); + NULL, NULL); break; - case IRC_CONFIG_NUM_SERVER_OPTIONS: + case IRC_SERVER_NUM_OPTIONS: break; } @@ -908,21 +774,22 @@ irc_config_server_new_option (struct t_config_file *config_file, } /* - * irc_config_server_create_option: create a server option + * irc_config_server_read_cb: read server option in configuration file */ int -irc_config_server_create_option (void *data, struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) +irc_config_server_read_cb (void *data, struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, const char *value) { - struct t_config_option *ptr_option; struct t_irc_server *ptr_server; - int rc, index_option; + int index_option, rc, i; char *pos_option, *server_name; /* make C compiler happy */ (void) data; + (void) config_file; + (void) section; rc = WEECHAT_CONFIG_OPTION_SET_ERROR; @@ -936,13 +803,28 @@ irc_config_server_create_option (void *data, struct t_config_file *config_file, pos_option++; if (server_name) { - index_option = irc_config_search_server_option (pos_option); + index_option = irc_server_search_option (pos_option); if (index_option >= 0) { ptr_server = irc_server_search (server_name); if (!ptr_server) ptr_server = irc_server_alloc (server_name); - if (!ptr_server) + if (ptr_server) + { + if (ptr_server->reloading_from_config + && !ptr_server->reloaded_from_config) + { + for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) + { + weechat_config_option_set (ptr_server->options[i], + NULL, 1); + } + ptr_server->reloaded_from_config = 1; + } + rc = weechat_config_option_set (ptr_server->options[index_option], + value, 1); + } + else { weechat_printf (NULL, _("%s%s: error creating server " @@ -950,39 +832,6 @@ irc_config_server_create_option (void *data, struct t_config_file *config_file, weechat_prefix ("error"), IRC_PLUGIN_NAME, server_name); } - ptr_option = weechat_config_search_option (config_file, - section, - option_name); - if (ptr_option) - { - rc = weechat_config_option_set (ptr_option, value, 1); - } - else - { - if (value && value[0] && (index_option >= 0)) - { - ptr_option = irc_config_server_new_option (config_file, - section, - index_option, - option_name, - value, - &irc_config_server_change_cb, - irc_config_server_option_string[index_option], - &irc_config_server_delete_cb, - irc_config_server_option_string[index_option]); - - if (ptr_option) - { - if (ptr_server) - { - irc_server_set_with_option (ptr_server, - index_option, - ptr_option); - } - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - } - } - } } free (server_name); } @@ -1001,6 +850,36 @@ irc_config_server_create_option (void *data, struct t_config_file *config_file, } /* + * irc_config_server_write_cb: write server section in configuration file + */ + +void +irc_config_server_write_cb (void *data, struct t_config_file *config_file, + const char *section_name) +{ + struct t_irc_server *ptr_server; + int i; + + /* make C compiler happy */ + (void) data; + + weechat_config_write_line (config_file, section_name, NULL); + + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (!ptr_server->temp_server || irc_config_write_temp_servers) + { + for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) + { + weechat_config_write_option (config_file, + ptr_server->options[i]); + } + } + } +} + +/* * irc_config_server_create_default_options: create default options for servers */ @@ -1051,28 +930,34 @@ irc_config_server_create_default_options (struct t_config_section *section) realname = strdup ("weechat"); } - for (i = 0; i < IRC_CONFIG_NUM_SERVER_OPTIONS; i++) + for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) { default_value = NULL; - if (i == IRC_CONFIG_SERVER_NICKS) - default_value = nicks; - else if (i == IRC_CONFIG_SERVER_USERNAME) - default_value = username; - else if (i == IRC_CONFIG_SERVER_REALNAME) - default_value = realname; + switch (i) + { + case IRC_SERVER_OPTION_NICKS: + default_value = nicks; + break; + case IRC_SERVER_OPTION_USERNAME: + default_value = username; + break; + case IRC_SERVER_OPTION_REALNAME: + default_value = realname; + break; + } if (!default_value) - default_value = irc_config_server_option_default[i]; + default_value = irc_server_option_default[i]; irc_config_server_default[i] = irc_config_server_new_option ( irc_config_file, section, i, - irc_config_server_option_string[i], + irc_server_option_string[i], + irc_server_option_default[i], default_value, + 0, &irc_config_server_default_change_cb, - irc_config_server_option_string[i], - NULL, - NULL); + irc_server_option_string[i]); } if (nicks) @@ -1114,80 +999,80 @@ irc_config_init () irc_config_file, ptr_section, "color_nicks_in_server_messages", "boolean", N_("use nick color in messages from server"), - NULL, 0, 0, "on", NULL, NULL, NULL, + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_one_server_buffer = weechat_config_new_option ( irc_config_file, ptr_section, "one_server_buffer", "boolean", N_("use same buffer for all servers"), - NULL, 0, 0, "off", NULL, NULL, NULL, + NULL, 0, 0, "off", NULL, 0, NULL, NULL, &irc_config_change_look_one_server_buffer, NULL, NULL, NULL); irc_config_look_open_near_server = weechat_config_new_option ( irc_config_file, ptr_section, "open_near_server", "boolean", N_("open new channels/privates near server"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_nick_prefix = weechat_config_new_option ( irc_config_file, ptr_section, "nick_prefix", "string", N_("text to display before nick in chat window"), - NULL, 0, 0, "", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_nick_suffix = weechat_config_new_option ( irc_config_file, ptr_section, "nick_suffix", "string", N_("text to display after nick in chat window"), - NULL, 0, 0, "", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_nick_completion_smart = weechat_config_new_option ( irc_config_file, ptr_section, "nick_completion_smart", "boolean", N_("smart completion for nicks (completes with last speakers first)"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_display_away = weechat_config_new_option ( irc_config_file, ptr_section, "display_away", "integer", N_("display message when (un)marking as away"), - "off|local|channel", 0, 0, "local", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + "off|local|channel", 0, 0, "local", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_display_channel_modes = weechat_config_new_option ( irc_config_file, ptr_section, "display_channel_modes", "boolean", N_("display channel modes in \"buffer_name\" bar item"), - NULL, 0, 0, "on", NULL, NULL, NULL, + NULL, 0, 0, "on", NULL, 0, NULL, NULL, &irc_config_change_look_display_channel_modes, NULL, NULL, NULL); irc_config_look_hide_nickserv_pwd = weechat_config_new_option ( irc_config_file, ptr_section, "hide_nickserv_pwd", "boolean", N_("hide password displayed by nickserv"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_highlight_tags = weechat_config_new_option ( irc_config_file, ptr_section, "highlight_tags", "string", N_("comma separated list of tags for messages that may produce " "highlight (usually any message from another user, not server " "messages,..)"), - NULL, 0, 0, "irc_privmsg,irc_notice", NULL, NULL, NULL, + NULL, 0, 0, "irc_privmsg,irc_notice", NULL, 0, NULL, NULL, &irc_config_change_look_highlight_tags, NULL, NULL, NULL); irc_config_look_show_away_once = weechat_config_new_option ( irc_config_file, ptr_section, "show_away_once", "boolean", N_("show remote away message only once in private"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_smart_filter = weechat_config_new_option ( irc_config_file, ptr_section, "smart_filter", "boolean", N_("filter join/part/quit messages for a nick if not speaking for " "some minutes on channel (you must create a filter on tag " "\"irc_smart_filter\")"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_smart_filter_delay = weechat_config_new_option ( irc_config_file, ptr_section, "smart_filter_delay", "integer", N_("delay for filtering join/part/quit messages (in minutes)"), - NULL, 1, 60*24*7, "5", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 1, 60*24*7, "5", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_notice_as_pv = weechat_config_new_option ( irc_config_file, ptr_section, "notice_as_pv", "boolean", N_("display notices as private messages"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); /* color */ ptr_section = weechat_config_new_section (irc_config_file, "color", @@ -1205,19 +1090,19 @@ irc_config_init () irc_config_file, ptr_section, "message_join", "color", N_("color for text in join messages"), - NULL, -1, 0, "green", NULL, NULL, NULL, + NULL, -1, 0, "green", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_color_message_quit = weechat_config_new_option ( irc_config_file, ptr_section, "message_quit", "color", N_("color for text in part/quit messages"), - NULL, -1, 0, "red", NULL, NULL, NULL, + NULL, -1, 0, "red", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_color_input_nick = weechat_config_new_option ( irc_config_file, ptr_section, "input_nick", "color", N_("color for nick in input bar"), - NULL, -1, 0, "lightcyan", NULL, NULL, NULL, + NULL, -1, 0, "lightcyan", NULL, 0, NULL, NULL, &irc_config_change_color_input_nick, NULL, NULL, NULL); /* network */ @@ -1237,70 +1122,70 @@ irc_config_init () "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, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "WeeChat %v", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_network_default_msg_quit = weechat_config_new_option ( irc_config_file, ptr_section, "default_msg_quit", "string", N_("default quit message (disconnecting from server) ('%v' will be " "replaced by WeeChat version in string)"), - NULL, 0, 0, "WeeChat %v", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "WeeChat %v", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_network_away_check = weechat_config_new_option ( irc_config_file, ptr_section, "away_check", "integer", N_("interval between two checks for away (in minutes, 0 = never " "check)"), - NULL, 0, INT_MAX, "0", NULL, NULL, NULL, + NULL, 0, INT_MAX, "0", NULL, 0, NULL, NULL, &irc_config_change_network_away_check, NULL, NULL, NULL); irc_config_network_away_check_max_nicks = weechat_config_new_option ( irc_config_file, ptr_section, "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", NULL, NULL, NULL, + NULL, 0, INT_MAX, "0", NULL, 0, NULL, NULL, &irc_config_change_network_away_check, NULL, NULL, NULL); irc_config_network_lag_check = weechat_config_new_option ( irc_config_file, ptr_section, "lag_check", "integer", N_("interval between two checks for lag (in seconds, 0 = never " "check)"), - NULL, 0, INT_MAX, "60", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, INT_MAX, "60", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_network_lag_min_show = weechat_config_new_option ( irc_config_file, ptr_section, "lag_min_show", "integer", N_("minimum lag to show (in seconds)"), - NULL, 0, INT_MAX, "1", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, INT_MAX, "1", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_network_lag_disconnect = weechat_config_new_option ( irc_config_file, ptr_section, "lag_disconnect", "integer", N_("disconnect after important lag (in minutes, 0 = never " "disconnect)"), - NULL, 0, INT_MAX, "5", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, INT_MAX, "5", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_network_anti_flood = weechat_config_new_option ( irc_config_file, ptr_section, "anti_flood", "integer", N_("anti-flood: # seconds between two user messages (0 = no " "anti-flood)"), - NULL, 0, 5, "2", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 5, "2", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_network_colors_receive = weechat_config_new_option ( irc_config_file, ptr_section, "colors_receive", "boolean", N_("when off, colors codes are ignored in incoming messages"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_network_colors_send = weechat_config_new_option ( irc_config_file, ptr_section, "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, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_network_send_unknown_commands = weechat_config_new_option ( irc_config_file, ptr_section, "send_unknown_commands", "boolean", N_("send unknown commands to IRC server"), - NULL, 0, 0, "off", NULL, NULL, NULL, + NULL, 0, 0, "off", NULL, 0, NULL, NULL, &irc_config_change_network_send_unknown_commands, NULL, NULL, NULL); - /* filters */ + /* ignore */ ptr_section = weechat_config_new_section (irc_config_file, "ignore", 0, 0, &irc_config_ignore_read, NULL, @@ -1331,11 +1216,11 @@ irc_config_init () /* server */ ptr_section = weechat_config_new_section (irc_config_file, "server", - 1, 1, - NULL, NULL, + 0, 0, + &irc_config_server_read_cb, NULL, + &irc_config_server_write_cb, NULL, + &irc_config_server_write_default_cb, NULL, NULL, NULL, - &irc_config_server_write_default, NULL, - &irc_config_server_create_option, NULL, NULL, NULL); if (!ptr_section) { @@ -1374,8 +1259,10 @@ irc_config_read () */ int -irc_config_write () +irc_config_write (int write_temp_servers) { + irc_config_write_temp_servers = write_temp_servers; + return weechat_config_write (irc_config_file); } diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index 71374071a..e08bf6ef1 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -26,29 +26,6 @@ #define IRC_CONFIG_DISPLAY_AWAY_LOCAL 1 #define IRC_CONFIG_DISPLAY_AWAY_CHANNEL 2 -enum t_irc_config_server_option -{ - IRC_CONFIG_SERVER_AUTOCONNECT = 0, - IRC_CONFIG_SERVER_AUTORECONNECT, - IRC_CONFIG_SERVER_AUTORECONNECT_DELAY, - IRC_CONFIG_SERVER_PROXY, - IRC_CONFIG_SERVER_ADDRESSES, - IRC_CONFIG_SERVER_IPV6, - IRC_CONFIG_SERVER_SSL, - IRC_CONFIG_SERVER_PASSWORD, - IRC_CONFIG_SERVER_NICKS, - IRC_CONFIG_SERVER_USERNAME, - IRC_CONFIG_SERVER_REALNAME, - IRC_CONFIG_SERVER_LOCAL_HOSTNAME, - IRC_CONFIG_SERVER_COMMAND, - IRC_CONFIG_SERVER_COMMAND_DELAY, - IRC_CONFIG_SERVER_AUTOJOIN, - IRC_CONFIG_SERVER_AUTOREJOIN, - IRC_CONFIG_SERVER_NOTIFY_LEVELS, - /* number of server options */ - IRC_CONFIG_NUM_SERVER_OPTIONS, -}; - #define IRC_CONFIG_SERVER_DEFAULT_AUTOCONNECT 0 #define IRC_CONFIG_SERVER_DEFAULT_AUTORECONNECT 1 #define IRC_CONFIG_SERVER_DEFAULT_AUTORECONNECT_DELAY 30 @@ -58,7 +35,6 @@ enum t_irc_config_server_option #define IRC_CONFIG_SERVER_DEFAULT_AUTOREJOIN 0 -extern char *irc_config_server_option_string[]; extern struct t_config_file *irc_config_file; extern struct t_config_section *irc_config_section_server_default; extern struct t_config_section *irc_config_section_server; @@ -96,7 +72,6 @@ extern struct t_config_option *irc_config_network_send_unknown_commands; extern struct t_config_option *irc_config_server_default[]; -extern int irc_config_search_server_option (const char *option_name); extern void irc_config_server_change_cb (void *data, struct t_config_option *option); extern void irc_config_server_delete_cb (void *data, @@ -105,14 +80,14 @@ struct t_config_option *irc_config_server_new_option (struct t_config_file *conf struct t_config_section *section, int index_option, const char *option_name, + const char *default_value, const char *value, + int null_value_allowed, void *callback_change, - void *callback_change_data, - void *callback_delete, - void *callback_delete_data); + void *callback_change_data); extern int irc_config_init (); extern int irc_config_read (); -extern int irc_config_write (); +extern int irc_config_write (int write_temp_servers); extern void irc_config_free (); #endif /* irc-config.h */ diff --git a/src/plugins/irc/irc-display.c b/src/plugins/irc/irc-display.c index c221f739e..936e07efb 100644 --- a/src/plugins/irc/irc-display.c +++ b/src/plugins/irc/irc-display.c @@ -152,11 +152,11 @@ irc_display_server (struct t_irc_server *server, int with_detail) { char *string; int num_channels, num_pv; - + if (with_detail) { weechat_printf (NULL, ""); - weechat_printf (NULL, _("%sServer: %s%s %s[%s%s%s]"), + weechat_printf (NULL, _("%sServer: %s%s %s[%s%s%s]%s%s"), IRC_COLOR_CHAT, IRC_COLOR_CHAT_SERVER, server->name, @@ -164,61 +164,150 @@ irc_display_server (struct t_irc_server *server, int with_detail) IRC_COLOR_CHAT, (server->is_connected) ? _("connected") : _("not connected"), - IRC_COLOR_CHAT_DELIMITERS); + IRC_COLOR_CHAT_DELIMITERS, + IRC_COLOR_CHAT, + (server->temp_server) ? _(" (temporary)") : ""); - weechat_printf (NULL, " autoconnect . . . . : %s", - (server->autoconnect) ? _("on") : _("off")); - weechat_printf (NULL, " autoreconnect . . . : %s", - (server->autoreconnect) ? _("on") : _("off")); - weechat_printf (NULL, " autoreconnect_delay : %d %s", - server->autoreconnect_delay, - NG_("second", "seconds", server->autoreconnect_delay)); - weechat_printf (NULL, " addresses . . . . . : %s", - (server->addresses && server->addresses[0]) ? - server->addresses : ""); - weechat_printf (NULL, " ipv6 . . . . . . . : %s", - (server->ipv6) ? _("on") : _("off")); - weechat_printf (NULL, " ssl . . . . . . . . : %s", - (server->ssl) ? _("on") : _("off")); - weechat_printf (NULL, " password . . . . . : %s", - (server->password && server->password[0]) ? - _("(hidden)") : ""); - weechat_printf (NULL, " nicks . . . . . . . : %s", - (server->nicks && server->nicks[0]) ? - server->nicks : ""); - weechat_printf (NULL, " username . . . . . : %s", - (server->username && server->username[0]) ? - server->username : ""); - weechat_printf (NULL, " realname . . . . . : %s", - (server->realname && server->realname[0]) ? - server->realname : ""); - weechat_printf (NULL, " local_hostname . . : %s", - (server->local_hostname && server->local_hostname[0]) ? - server->local_hostname : ""); - if (server->command && server->command[0]) - string = strdup (server->command); - else - string = NULL; - if (string) + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_ADDRESSES])) + weechat_printf (NULL, " addresses. . . . . . : ('%s')", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_ADDRESSES)); + else + weechat_printf (NULL, " addresses. . . . . . : %s'%s'", + IRC_COLOR_CHAT_HOST, + weechat_config_string (server->options[IRC_SERVER_OPTION_ADDRESSES])); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_PROXY])) + weechat_printf (NULL, " proxy. . . . . . . . : ('%s')", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY)); + else + weechat_printf (NULL, " proxy. . . . . . . . : %s'%s'", + IRC_COLOR_CHAT_HOST, + weechat_config_string (server->options[IRC_SERVER_OPTION_PROXY])); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_IPV6])) + weechat_printf (NULL, " ipv6 . . . . . . . . : (%s)", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? + _("on") : _("off")); + else + weechat_printf (NULL, " ipv6 . . . . . . . . : %s%s", + IRC_COLOR_CHAT_HOST, + weechat_config_boolean (server->options[IRC_SERVER_OPTION_IPV6]) ? + _("on") : _("off")); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_SSL])) + weechat_printf (NULL, " ssl. . . . . . . . . : (%s)", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? + _("on") : _("off")); + else + weechat_printf (NULL, " ssl. . . . . . . . . : %s%s", + IRC_COLOR_CHAT_HOST, + weechat_config_boolean (server->options[IRC_SERVER_OPTION_SSL]) ? + _("on") : _("off")); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_PASSWORD])) + weechat_printf (NULL, " password . . . . . . : %s", + _("(hidden)")); + else + weechat_printf (NULL, " password . . . . . . : %s%s", + IRC_COLOR_CHAT_HOST, + _("(hidden)")); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_AUTOCONNECT])) + weechat_printf (NULL, " autoconnect. . . . . : (%s)", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTOCONNECT)) ? + _("on") : _("off")); + else + weechat_printf (NULL, " autoconnect. . . . . : %s%s", + IRC_COLOR_CHAT_HOST, + weechat_config_boolean (server->options[IRC_SERVER_OPTION_AUTOCONNECT]) ? + _("on") : _("off")); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_AUTORECONNECT])) + weechat_printf (NULL, " autoreconnect. . . . : (%s)", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT)) ? + _("on") : _("off")); + else + weechat_printf (NULL, " autoreconnect. . . . : %s%s", + IRC_COLOR_CHAT_HOST, + weechat_config_boolean (server->options[IRC_SERVER_OPTION_AUTORECONNECT]) ? + _("on") : _("off")); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_AUTORECONNECT_DELAY])) + weechat_printf (NULL, " autoreconnect_delay. : (%d %s)", + IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY), + NG_("second", "seconds", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY))); + else + weechat_printf (NULL, " autoreconnect_delay. : %s%d %s", + IRC_COLOR_CHAT_HOST, + weechat_config_integer (server->options[IRC_SERVER_OPTION_AUTORECONNECT_DELAY]), + NG_("second", "seconds", weechat_config_integer (server->options[IRC_SERVER_OPTION_AUTORECONNECT_DELAY]))); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_NICKS])) + weechat_printf (NULL, " nicks. . . . . . . . : ('%s')", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_NICKS)); + else + weechat_printf (NULL, " nicks. . . . . . . . : %s'%s'", + IRC_COLOR_CHAT_HOST, + weechat_config_string (server->options[IRC_SERVER_OPTION_NICKS])); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_USERNAME])) + weechat_printf (NULL, " username . . . . . . : ('%s')", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_USERNAME)); + else + weechat_printf (NULL, " username . . . . . . : %s'%s'", + IRC_COLOR_CHAT_HOST, + weechat_config_string (server->options[IRC_SERVER_OPTION_USERNAME])); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_REALNAME])) + weechat_printf (NULL, " realname . . . . . . : ('%s')", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_REALNAME)); + else + weechat_printf (NULL, " realname . . . . . . : %s'%s'", + IRC_COLOR_CHAT_HOST, + weechat_config_string (server->options[IRC_SERVER_OPTION_REALNAME])); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_LOCAL_HOSTNAME])) + weechat_printf (NULL, " local_hostname . . . : ('%s')", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_LOCAL_HOSTNAME)); + else + weechat_printf (NULL, " local_hostname . . . : %s'%s'", + IRC_COLOR_CHAT_HOST, + weechat_config_string (server->options[IRC_SERVER_OPTION_LOCAL_HOSTNAME])); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_COMMAND])) { - if (weechat_config_boolean (irc_config_look_hide_nickserv_pwd)) + string = strdup (IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_COMMAND)); + if (string && weechat_config_boolean (irc_config_look_hide_nickserv_pwd)) irc_display_hide_password (string, 1); - weechat_printf (NULL, " command . . . . . . : %s", - string); - free (string); + weechat_printf (NULL, " command. . . . . . . : ('%s')", + (string) ? string : IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_COMMAND)); + if (string) + free (string); } else { - weechat_printf (NULL, " command . . . . . . : %s", - (server->command && server->command[0]) ? - server->command : ""); + string = strdup (weechat_config_string (server->options[IRC_SERVER_OPTION_COMMAND])); + if (string && weechat_config_boolean (irc_config_look_hide_nickserv_pwd)) + irc_display_hide_password (string, 1); + weechat_printf (NULL, " command. . . . . . . : %s'%s'", + IRC_COLOR_CHAT_HOST, + (string) ? string : weechat_config_string (server->options[IRC_SERVER_OPTION_COMMAND])); + if (string) + free (string); } - weechat_printf (NULL, " command_delay . . . : %d %s", - server->command_delay, - NG_("second", "seconds", server->command_delay)); - weechat_printf (NULL, " autojoin . . . . . : %s", - (server->autojoin && server->autojoin[0]) ? - server->autojoin : ""); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_COMMAND_DELAY])) + weechat_printf (NULL, " command_delay. . . . : (%d %s)", + IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY), + NG_("second", "seconds", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY))); + else + weechat_printf (NULL, " command_delay. . . . : %s%d %s", + IRC_COLOR_CHAT_HOST, + weechat_config_integer (server->options[IRC_SERVER_OPTION_COMMAND_DELAY]), + NG_("second", "seconds", weechat_config_integer (server->options[IRC_SERVER_OPTION_COMMAND_DELAY]))); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_AUTOJOIN])) + weechat_printf (NULL, " autojoin . . . . . . : ('%s')", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN)); + else + weechat_printf (NULL, " autojoin . . . . . . : %s'%s'", + IRC_COLOR_CHAT_HOST, + weechat_config_string (server->options[IRC_SERVER_OPTION_AUTOJOIN])); + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_AUTOREJOIN])) + weechat_printf (NULL, " autorejoin . . . . . : (%s)", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTOREJOIN)) ? + _("on") : _("off")); + else + weechat_printf (NULL, " autorejoin . . . . . : %s%s", + IRC_COLOR_CHAT_HOST, + weechat_config_boolean (server->options[IRC_SERVER_OPTION_AUTOREJOIN]) ? + _("on") : _("off")); } else { @@ -226,7 +315,7 @@ irc_display_server (struct t_irc_server *server, int with_detail) { num_channels = irc_server_get_channel_count (server); num_pv = irc_server_get_pv_count (server); - weechat_printf (NULL, " %s %s%s %s[%s%s%s]%s, %d %s, %d pv", + weechat_printf (NULL, " %s %s%s %s[%s%s%s]%s%s, %d %s, %d pv", (server->is_connected) ? "*" : " ", IRC_COLOR_CHAT_SERVER, server->name, @@ -236,16 +325,18 @@ irc_display_server (struct t_irc_server *server, int with_detail) _("connected") : _("not connected"), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT, + (server->temp_server) ? _(" (temporary)") : "", num_channels, NG_("channel", "channels", num_channels), num_pv); } else { - weechat_printf (NULL, " %s %s%s", - (server->is_connected) ? "*" : " ", + weechat_printf (NULL, " %s%s%s%s", IRC_COLOR_CHAT_SERVER, - server->name); + server->name, + IRC_COLOR_CHAT, + (server->temp_server) ? _(" (temporary)") : ""); } } } diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 54eb56ca9..ca329edf0 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -456,7 +456,7 @@ irc_protocol_cmd_kick (struct t_irc_server *server, const char *command, /* my nick was kicked => free all nicks, channel is not active any more */ irc_nick_free_all (ptr_channel); - if (server->autorejoin) + if (IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOREJOIN)) irc_command_join_server (server, ptr_channel->name); } else @@ -1589,7 +1589,8 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, weechat_infolist_new_var_string (item, "local_nick", server->nick); weechat_infolist_new_var_string (item, "filename", pos_file); weechat_infolist_new_var_string (item, "size", pos_size); - weechat_infolist_new_var_string (item, "proxy", server->proxy); + weechat_infolist_new_var_string (item, "proxy", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY)); weechat_infolist_new_var_string (item, "address", pos_addr); weechat_infolist_new_var_integer (item, "port", atoi (pos_port)); weechat_hook_signal_send ("xfer_add", @@ -1922,7 +1923,8 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, weechat_infolist_new_var_string (item, "type", "chat_recv"); weechat_infolist_new_var_string (item, "remote_nick", nick); weechat_infolist_new_var_string (item, "local_nick", server->nick); - weechat_infolist_new_var_string (item, "proxy", server->proxy); + weechat_infolist_new_var_string (item, "proxy", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY)); weechat_infolist_new_var_string (item, "address", pos_addr); weechat_infolist_new_var_integer (item, "port", atoi (pos_port)); weechat_hook_signal_send ("xfer_add", @@ -2382,6 +2384,7 @@ irc_protocol_cmd_001 (struct t_irc_server *server, const char *command, { char **commands, **ptr_cmd, *vars_replaced; char *away_msg; + const char *ptr_command; /* 001 message looks like: :server 001 mynick :Welcome to the dancer-ircd Network @@ -2416,10 +2419,11 @@ irc_protocol_cmd_001 (struct t_irc_server *server, const char *command, WEECHAT_HOOK_SIGNAL_STRING, server->name); /* execute command when connected */ - if (server->command && server->command[0]) + ptr_command = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_COMMAND); + if (ptr_command && ptr_command[0]) { /* splitting command on ';' which can be escaped with '\;' */ - commands = weechat_string_split_command (server->command, ';'); + commands = weechat_string_split_command (ptr_command, ';'); if (commands) { for (ptr_cmd = commands; *ptr_cmd; ptr_cmd++) @@ -2434,7 +2438,7 @@ irc_protocol_cmd_001 (struct t_irc_server *server, const char *command, weechat_string_free_splitted_command (commands); } - if (server->command_delay > 0) + if (IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY) > 0) server->command_time = time (NULL) + 1; else irc_server_autojoin_channels (server); diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index c71e650eb..ed6d10173 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -50,6 +50,17 @@ struct t_irc_server *irc_current_server = NULL; struct t_irc_message *irc_recv_msgq = NULL; struct t_irc_message *irc_msgq_last_msg = NULL; +char *irc_server_option_string[IRC_SERVER_NUM_OPTIONS] = +{ "addresses", "proxy", "ipv6", "ssl", "password", "autoconnect", + "autoreconnect", "autoreconnect_delay", "nicks", "username", "realname", + "local_hostname", "command", "command_delay", "autojoin", "autorejoin" +}; + +char *irc_server_option_default[IRC_SERVER_NUM_OPTIONS] = +{ "", "", "off", "off", "", "off", "on", "30", "", "", "", "", "", "0", "", + "off" +}; + /* * irc_server_valid: check if a server pointer exists @@ -77,6 +88,32 @@ irc_server_valid (struct t_irc_server *server) } /* + * irc_server_search_option: search a server option name + * return index of option in array + * "irc_server_option_string", or -1 if + * not found + */ + +int +irc_server_search_option (const char *option_name) +{ + int i; + + if (!option_name) + return -1; + + for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) + { + if (weechat_strcasecmp (irc_server_option_string[i], + option_name) == 0) + return i; + } + + /* server option not found */ + return -1; +} + +/* * irc_server_get_name_without_port: get name of server without port * (ends before first '/' if found) */ @@ -97,37 +134,6 @@ irc_server_get_name_without_port (const char *name) } /* - * irc_server_new_option: create option in configuration for a server option - */ - -void -irc_server_new_option (struct t_irc_server *server, int index_option, - const char *value) -{ - int length; - char *option_name; - - length = strlen (server->name) + 1 + - strlen (irc_config_server_option_string[index_option]) + 1; - option_name = malloc (length); - if (option_name) - { - snprintf (option_name, length, "%s.%s", - server->name, - irc_config_server_option_string[index_option]); - irc_config_server_new_option (irc_config_file, - irc_config_section_server, - index_option, - option_name, - value, - &irc_config_server_change_cb, - irc_config_server_option_string[index_option], - &irc_config_server_delete_cb, - irc_config_server_option_string[index_option]); - } -} - -/* * irc_server_set_addresses: set addresses for server */ @@ -139,11 +145,6 @@ irc_server_set_addresses (struct t_irc_server *server, const char *addresses) long number; /* free data */ - if (server->addresses) - { - free (server->addresses); - server->addresses = NULL; - } server->addresses_count = 0; if (server->addresses_array) { @@ -156,32 +157,28 @@ irc_server_set_addresses (struct t_irc_server *server, const char *addresses) server->ports_array = NULL; } - /* set new address */ + /* set new addresses/ports */ if (addresses && addresses[0]) { - server->addresses = strdup (addresses); - if (server->addresses) + server->addresses_array = weechat_string_explode (addresses, + ",", 0, 0, + &server->addresses_count); + server->ports_array = malloc (server->addresses_count * sizeof (server->ports_array[0])); + for (i = 0; i < server->addresses_count; i++) { - server->addresses_array = weechat_string_explode (server->addresses, - ",", 0, 0, - &server->addresses_count); - server->ports_array = malloc (server->addresses_count * sizeof (server->ports_array[0])); - for (i = 0; i < server->addresses_count; i++) + pos = strchr (server->addresses_array[i], '/'); + if (pos) { - pos = strchr (server->addresses_array[i], '/'); - if (pos) - { - pos[0] = 0; - pos++; - error = NULL; - number = strtol (pos, &error, 10); - server->ports_array[i] = (error && !error[0]) ? - number : IRC_SERVER_DEFAULT_PORT; - } - else - { - server->ports_array[i] = IRC_SERVER_DEFAULT_PORT; - } + pos[0] = 0; + pos++; + error = NULL; + number = strtol (pos, &error, 10); + server->ports_array[i] = (error && !error[0]) ? + number : IRC_SERVER_DEFAULT_PORT; + } + else + { + server->ports_array[i] = IRC_SERVER_DEFAULT_PORT; } } } @@ -195,11 +192,6 @@ void irc_server_set_nicks (struct t_irc_server *server, const char *nicks) { /* free data */ - if (server->nicks) - { - free (server->nicks); - server->nicks = NULL; - } server->nicks_count = 0; if (server->nicks_array) { @@ -208,94 +200,9 @@ irc_server_set_nicks (struct t_irc_server *server, const char *nicks) } /* set new nicks */ - server->nicks = strdup ((nicks) ? nicks : IRC_SERVER_DEFAULT_NICKS); - if (server->nicks) - { - server->nicks_array = weechat_string_explode (server->nicks, - ",", 0, 0, - &server->nicks_count); - } -} - -/* - * irc_server_set_with_option: set a server option with a config option - */ - -void -irc_server_set_with_option (struct t_irc_server *server, - int index_option, - struct t_config_option *option) -{ - if (!server || !option) - return; - - switch (index_option) - { - case IRC_CONFIG_SERVER_AUTOCONNECT: - server->autoconnect = weechat_config_integer (option); - break; - case IRC_CONFIG_SERVER_AUTORECONNECT: - server->autoreconnect = weechat_config_integer (option); - break; - case IRC_CONFIG_SERVER_AUTORECONNECT_DELAY: - server->autoreconnect_delay = weechat_config_integer (option); - break; - case IRC_CONFIG_SERVER_PROXY: - if (server->proxy) - free (server->proxy); - server->proxy = strdup (weechat_config_string (option)); - break; - case IRC_CONFIG_SERVER_ADDRESSES: - irc_server_set_addresses (server, weechat_config_string (option)); - break; - case IRC_CONFIG_SERVER_IPV6: - server->ipv6 = weechat_config_integer (option); - break; - case IRC_CONFIG_SERVER_SSL: - server->ssl = weechat_config_integer (option); - break; - case IRC_CONFIG_SERVER_PASSWORD: - if (server->password) - free (server->password); - server->password = strdup (weechat_config_string (option)); - break; - case IRC_CONFIG_SERVER_NICKS: - irc_server_set_nicks (server, weechat_config_string (option)); - break; - case IRC_CONFIG_SERVER_USERNAME: - if (server->username) - free (server->username); - server->username = strdup (weechat_config_string (option)); - break; - case IRC_CONFIG_SERVER_REALNAME: - if (server->realname) - free (server->realname); - server->realname = strdup (weechat_config_string (option)); - break; - case IRC_CONFIG_SERVER_LOCAL_HOSTNAME: - if (server->local_hostname) - free (server->local_hostname); - server->local_hostname = strdup (weechat_config_string (option)); - break; - case IRC_CONFIG_SERVER_COMMAND: - if (server->command) - free (server->command); - server->command = strdup (weechat_config_string (option)); - break; - case IRC_CONFIG_SERVER_COMMAND_DELAY: - server->command_delay = weechat_config_integer (option); - break; - case IRC_CONFIG_SERVER_AUTOJOIN: - if (server->autojoin) - free (server->autojoin); - server->autojoin = strdup (weechat_config_string (option)); - break; - case IRC_CONFIG_SERVER_AUTOREJOIN: - server->autorejoin = weechat_config_integer (option); - break; - case IRC_CONFIG_NUM_SERVER_OPTIONS: - break; - } + server->nicks_array = weechat_string_explode ((nicks) ? nicks : IRC_SERVER_DEFAULT_NICKS, + ",", 0, 0, + &server->nicks_count); } /* @@ -325,82 +232,6 @@ irc_server_set_nick (struct t_irc_server *server, const char *nick) } /* - * irc_server_init: init server struct with default values - */ - -void -irc_server_init (struct t_irc_server *server) -{ - int i; - - /* user choices */ - server->name = NULL; - server->autoconnect = IRC_CONFIG_SERVER_DEFAULT_AUTOCONNECT; - server->autoreconnect = IRC_CONFIG_SERVER_DEFAULT_AUTORECONNECT; - server->autoreconnect_delay = IRC_CONFIG_SERVER_DEFAULT_AUTORECONNECT_DELAY; - server->proxy = NULL; - server->addresses = NULL; - server->ipv6 = IRC_CONFIG_SERVER_DEFAULT_IPV6; - server->ssl = IRC_CONFIG_SERVER_DEFAULT_SSL; - server->password = NULL; - server->nicks = NULL; - server->username = NULL; - server->realname = NULL; - server->local_hostname = NULL; - server->command = NULL; - server->command_delay = IRC_CONFIG_SERVER_DEFAULT_COMMAND_DELAY; - server->autojoin = NULL; - server->autorejoin = IRC_CONFIG_SERVER_DEFAULT_AUTOREJOIN; - - /* internal vars */ - server->reloaded_from_config = 0; - server->addresses_count = 0; - server->addresses_array = NULL; - server->ports_array = NULL; - server->index_current_address = 0; - server->current_ip = NULL; - server->sock = -1; - server->hook_connect = NULL; - server->hook_fd = NULL; - server->is_connected = 0; - server->ssl_connected = 0; - server->unterminated_message = NULL; - server->nicks_count = 0; - server->nicks_array = NULL; - server->nick = NULL; - server->nick_modes = NULL; - server->prefix = NULL; - server->reconnect_start = 0; - server->command_time = 0; - server->reconnect_join = 0; - server->disable_autojoin = 0; - server->is_away = 0; - server->away_message = NULL; - server->away_time = 0; - server->lag = 0; - server->lag_check_time.tv_sec = 0; - server->lag_check_time.tv_usec = 0; - server->lag_next_check = time (NULL) + - weechat_config_integer (irc_config_network_lag_check); - server->cmd_list_regexp = NULL; - server->queue_msg = 0; - server->last_user_message = 0; - server->outqueue = NULL; - server->last_outqueue = NULL; - server->buffer = NULL; - server->buffer_as_string = NULL; - server->channels = NULL; - server->last_channel = NULL; - - /* init with default values from config */ - for (i = 0; i < IRC_CONFIG_NUM_SERVER_OPTIONS; i++) - { - irc_server_set_with_option (server, i, - irc_config_server_default[i]); - } -} - -/* * irc_server_alloc: allocate a new server and add it to the servers queue */ @@ -408,12 +239,15 @@ struct t_irc_server * irc_server_alloc (const char *name) { struct t_irc_server *new_server; - + int i, length; + char *option_name; + if (irc_server_search (name)) return NULL; /* alloc memory for new server */ - if ((new_server = malloc (sizeof (*new_server))) == NULL) + new_server = malloc (sizeof (*new_server)); + if (!new_server) { weechat_printf (NULL, _("%s%s: error when allocating new server"), @@ -421,12 +255,6 @@ irc_server_alloc (const char *name) return NULL; } - /* initialize new server */ - irc_server_init (new_server); - - /* set name */ - new_server->name = strdup (name); - /* add new server to queue */ new_server->prev_server = last_irc_server; new_server->next_server = NULL; @@ -435,8 +263,79 @@ irc_server_alloc (const char *name) else irc_servers = new_server; last_irc_server = new_server; - - /* all is ok, return address of new server */ + + /* set name */ + new_server->name = strdup (name); + + /* internal vars */ + new_server->temp_server = 0; + new_server->reloading_from_config = 0; + new_server->reloaded_from_config = 0; + new_server->addresses_count = 0; + new_server->addresses_array = NULL; + new_server->ports_array = NULL; + new_server->index_current_address = 0; + new_server->current_ip = NULL; + new_server->sock = -1; + new_server->hook_connect = NULL; + new_server->hook_fd = NULL; + new_server->is_connected = 0; + new_server->ssl_connected = 0; + new_server->unterminated_message = NULL; + new_server->nicks_count = 0; + new_server->nicks_array = NULL; + new_server->nick = NULL; + new_server->nick_modes = NULL; + new_server->prefix = NULL; + new_server->reconnect_start = 0; + new_server->command_time = 0; + new_server->reconnect_join = 0; + new_server->disable_autojoin = 0; + new_server->is_away = 0; + new_server->away_message = NULL; + new_server->away_time = 0; + new_server->lag = 0; + new_server->lag_check_time.tv_sec = 0; + new_server->lag_check_time.tv_usec = 0; + new_server->lag_next_check = time (NULL) + + weechat_config_integer (irc_config_network_lag_check); + new_server->cmd_list_regexp = NULL; + new_server->queue_msg = 0; + new_server->last_user_message = 0; + new_server->outqueue = NULL; + new_server->last_outqueue = NULL; + new_server->buffer = NULL; + new_server->buffer_as_string = NULL; + new_server->channels = NULL; + new_server->last_channel = NULL; + + /* create options with null value */ + for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) + { + length = strlen (new_server->name) + 1 + + strlen (irc_server_option_string[i]) + 1; + option_name = malloc (length); + if (option_name) + { + snprintf (option_name, length, "%s.%s", + new_server->name, + irc_server_option_string[i]); + new_server->options[i] = + irc_config_server_new_option (irc_config_file, + irc_config_section_server, + i, + option_name, + NULL, + NULL, + 1, + &irc_config_server_change_cb, + irc_server_option_string[i]); + irc_config_server_change_cb (irc_server_option_string[i], + new_server->options[i]); + free (option_name); + } + } + return new_server; } @@ -452,9 +351,8 @@ irc_server_alloc_with_url (const char *irc_url) { char *irc_url2, *url, *pos_server, *pos_channel, *pos, *pos2; char *password, *nick1, *nicks, *autojoin; - char *default_nicks, *default_password, *default_autojoin, value[16]; char *server_name; - int ipv6, ssl, default_ipv6, default_ssl, length; + int ipv6, ssl, length; struct t_irc_server *ptr_server; irc_url2 = strdup (irc_url); @@ -549,17 +447,16 @@ irc_server_alloc_with_url (const char *irc_url) if (ptr_server) { - irc_server_set_addresses (ptr_server, pos_server); - - default_ipv6 = ptr_server->ipv6; - default_ssl = ptr_server->ssl; - default_nicks = (ptr_server->nicks) ? strdup (ptr_server->nicks) : NULL; - default_password = (ptr_server->password) ? strdup (ptr_server->password) : NULL; - default_autojoin = (ptr_server->autojoin) ? strdup (ptr_server->autojoin) : NULL; - - ptr_server->ipv6 = ipv6; - ptr_server->ssl = ssl; - + ptr_server->temp_server = 1; + weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES], + pos_server, + 1); + weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_IPV6], + (ipv6) ? "on" : "off", + 1); + weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_SSL], + (ssl) ? "on" : "off", + 1); if (nick1) { length = ((strlen (nick1) + 2) * 5) + 1; @@ -569,57 +466,23 @@ irc_server_alloc_with_url (const char *irc_url) snprintf (nicks, length, "%s,%s1,%s2,%s3,%s4", nick1, nick1, nick1, nick1, nick1); - irc_server_set_nicks (ptr_server, nicks); + weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_NICKS], + nicks, + 1); free (nicks); } } - ptr_server->password = (password) ? strdup (password) : NULL; - ptr_server->autojoin = (autojoin) ? strdup (autojoin) : NULL; - ptr_server->autoconnect = 1; - - /* create server options */ - irc_server_new_option (ptr_server, - IRC_CONFIG_SERVER_ADDRESSES, - ptr_server->addresses); - if (default_ipv6 != ptr_server->ipv6) - { - snprintf (value, sizeof (value), - "%s", - (ptr_server->ipv6) ? "on" : "off"); - irc_server_new_option (ptr_server, - IRC_CONFIG_SERVER_IPV6, - value); - } - if (default_ssl != ptr_server->ssl) - { - snprintf (value, sizeof (value), - "%s", - (ptr_server->ssl) ? "on" : "off"); - irc_server_new_option (ptr_server, - IRC_CONFIG_SERVER_SSL, - value); - } - if (ptr_server->nicks - && (!default_nicks || strcmp (default_nicks, ptr_server->nicks) != 0)) - { - irc_server_new_option (ptr_server, - IRC_CONFIG_SERVER_NICKS, - ptr_server->nicks); - } - if (ptr_server->password - && (!default_password || strcmp (default_password, ptr_server->password) != 0)) - { - irc_server_new_option (ptr_server, - IRC_CONFIG_SERVER_PASSWORD, - ptr_server->password); - } - if (ptr_server->autojoin - && (!default_autojoin || strcmp (default_autojoin, ptr_server->autojoin) != 0)) - { - irc_server_new_option (ptr_server, - IRC_CONFIG_SERVER_AUTOJOIN, - ptr_server->autojoin); - } + if (password) + weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_PASSWORD], + password, + 1); + if (autojoin) + weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN], + autojoin, + 1); + weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT], + "on", + 1); } else { @@ -723,38 +586,25 @@ irc_server_outqueue_free_all (struct t_irc_server *server) void irc_server_free_data (struct t_irc_server *server) { + int i; + if (!server) return; /* free data */ - if (server->name) - free (server->name); - if (server->proxy) - free (server->proxy); - if (server->addresses) - free (server->addresses); + for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) + { + if (server->options[i]) + weechat_config_option_free (server->options[i]); + } if (server->addresses_array) weechat_string_free_exploded (server->addresses_array); if (server->ports_array) free (server->ports_array); if (server->current_ip) free (server->current_ip); - if (server->password) - free (server->password); - if (server->nicks) - free (server->nicks); if (server->nicks_array) weechat_string_free_exploded (server->nicks_array); - if (server->username) - free (server->username); - if (server->realname) - free (server->realname); - if (server->local_hostname) - free (server->local_hostname); - if (server->command) - free (server->command); - if (server->autojoin) - free (server->autojoin); if (server->unterminated_message) free (server->unterminated_message); if (server->nick) @@ -825,7 +675,7 @@ irc_server_free_all () /* * irc_server_new: creates a new server, and initialize it */ - +/* struct t_irc_server * irc_server_new (const char *name, int autoconnect, int autoreconnect, int autoreconnect_delay, const char *proxy, @@ -886,45 +736,26 @@ irc_server_new (const char *name, int autoconnect, int autoreconnect, return new_server; } - +*/ /* - * irc_server_duplicate: duplicate a server - * return: pointer to new server, NULL if error + * irc_server_copy: copy a server + * return: pointer to new server, NULL if error */ struct t_irc_server * -irc_server_duplicate (struct t_irc_server *server, const char *new_server_name) +irc_server_copy (struct t_irc_server *server, const char *new_name) { struct t_irc_server *new_server; - int length, index_option; - char *mask, *pos_option; - const char *option_name; - struct t_config_option *ptr_option; struct t_infolist *infolist; + char *mask, *pos; + const char *option_name; + int length, index_option; /* check if another server exists with this name */ - if (irc_server_search (new_server_name)) + if (irc_server_search (new_name)) return NULL; - /* duplicate server */ - new_server = irc_server_new (new_server_name, - server->autoconnect, - server->autoreconnect, - server->autoreconnect_delay, - server->proxy, - server->addresses, - server->ipv6, - server->ssl, - server->password, - server->nicks, - server->username, - server->realname, - server->local_hostname, - server->command, - server->command_delay, - server->autojoin, - server->autorejoin); - + new_server = irc_server_alloc (new_name); if (new_server) { /* duplicate options */ @@ -937,32 +768,22 @@ irc_server_duplicate (struct t_irc_server *server, const char *new_server_name) free (mask); while (weechat_infolist_next (infolist)) { - weechat_config_search_with_string (weechat_infolist_string (infolist, - "full_name"), - NULL, NULL, &ptr_option, - NULL); - if (ptr_option) + if (!weechat_infolist_integer (infolist, "value_is_null")) { option_name = weechat_infolist_string (infolist, "option_name"); - if (option_name) + pos = strrchr (option_name, '.'); + if (pos) { - pos_option = strrchr (option_name, '.'); - if (pos_option) + index_option = irc_server_search_option (pos + 1); + if (index_option >= 0) { - pos_option++; - - index_option = irc_config_search_server_option (pos_option); - if (index_option >= 0) - { - irc_server_new_option (new_server, - index_option, - weechat_infolist_string (infolist, "value")); - } + weechat_config_option_set (new_server->options[index_option], + weechat_infolist_string (infolist, "value"), + 1); } } } } - weechat_infolist_free (infolist); } return new_server; @@ -1805,7 +1626,8 @@ irc_server_timer_cb (void *data) /* check if reconnection is pending */ if ((!ptr_server->is_connected) && (ptr_server->reconnect_start > 0) - && (new_time >= (ptr_server->reconnect_start + ptr_server->autoreconnect_delay))) + && (new_time >= (ptr_server->reconnect_start + + IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY)))) irc_server_reconnect (ptr_server); else { @@ -1825,7 +1647,8 @@ irc_server_timer_cb (void *data) /* check if it's time to autojoin channels (after command delay) */ if ((ptr_server->command_time != 0) - && (new_time >= ptr_server->command_time + ptr_server->command_delay)) + && (new_time >= ptr_server->command_time + + IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_COMMAND_DELAY))) { irc_server_autojoin_channels (ptr_server); ptr_server->command_time = 0; @@ -1936,17 +1759,19 @@ irc_server_close_connection (struct t_irc_server *server) void irc_server_reconnect_schedule (struct t_irc_server *server) { + int delay; + server->index_current_address = 0; - if (server->autoreconnect) + if (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT)) { server->reconnect_start = time (NULL); + delay = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY); weechat_printf (server->buffer, _("%s%s: reconnecting to server in %d %s"), irc_buffer_get_server_prefix (server, NULL), IRC_PLUGIN_NAME, - server->autoreconnect_delay, - NG_("second", "seconds", - server->autoreconnect_delay)); + delay, + NG_("second", "seconds", delay)); } else server->reconnect_start = 0; @@ -1959,25 +1784,31 @@ irc_server_reconnect_schedule (struct t_irc_server *server) void irc_server_login (struct t_irc_server *server) { - if ((server->password) && (server->password[0])) - irc_server_sendf (server, "PASS %s", server->password); + const char *password, *username, *realname; + + password = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PASSWORD); + username = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_USERNAME); + realname = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_REALNAME); + + if (password && password[0]) + irc_server_sendf (server, "PASS %s", password); if (!server->nick) + { irc_server_set_nick (server, (server->nicks_array) ? server->nicks_array[0] : "weechat"); + } irc_server_sendf (server, "NICK %s\n" "USER %s %s %s :%s", server->nick, - (server->username && server->username[0]) ? - server->username : "weechat", - (server->username && server->username[0]) ? - server->username : "weechat", + (username && username[0]) ? username : "weechat", + (username && username[0]) ? username : "weechat", server->addresses_array[server->index_current_address], - (server->realname && server->realname[0]) ? - server->realname : "weechat"); + (realname && realname[0]) ? + realname : "weechat"); } /* @@ -2012,9 +1843,12 @@ int irc_server_connect_cb (void *arg_server, int status, const char *ip_address) { struct t_irc_server *server; + const char *proxy; server = (struct t_irc_server *)arg_server; + proxy = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY); + server->hook_connect = NULL; switch (status) @@ -2038,7 +1872,7 @@ irc_server_connect_cb (void *arg_server, int status, const char *ip_address) break; case WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND: weechat_printf (server->buffer, - (server->proxy && server->proxy[0]) ? + (proxy && proxy[0]) ? _("%s%s: proxy address \"%s\" not found") : _("%s%s: address \"%s\" not found"), irc_buffer_get_server_prefix (server, "error"), @@ -2049,7 +1883,7 @@ irc_server_connect_cb (void *arg_server, int status, const char *ip_address) break; case WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND: weechat_printf (server->buffer, - (server->proxy && server->proxy[0]) ? + (proxy && proxy[0]) ? _("%s%s: proxy IP address not found") : _("%s%s: IP address not found"), irc_buffer_get_server_prefix (server, "error"), @@ -2059,7 +1893,7 @@ irc_server_connect_cb (void *arg_server, int status, const char *ip_address) break; case WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED: weechat_printf (server->buffer, - (server->proxy && server->proxy[0]) ? + (proxy && proxy[0]) ? _("%s%s: proxy connection refused") : _("%s%s: connection refused"), irc_buffer_get_server_prefix (server, "error"), @@ -2219,7 +2053,7 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) int set, length; char *option_name, charset_modifier[256]; struct t_config_option *proxy_type, *proxy_ipv6, *proxy_address, *proxy_port; - const char *str_proxy_type, *str_proxy_address; + const char *proxy, *str_proxy_type, *str_proxy_address; proxy_type = NULL; proxy_ipv6 = NULL; @@ -2264,9 +2098,10 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) "/command irc /server switch"); } - if (server->proxy && server->proxy[0]) + proxy = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY); + if (proxy && proxy[0]) { - length = 32 + strlen (server->proxy) + 1; + length = 32 + strlen (proxy) + 1; option_name = malloc (length); if (!option_name) { @@ -2276,17 +2111,13 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) IRC_PLUGIN_NAME); return 0; } - snprintf (option_name, length, "weechat.proxy.%s.type", - server->proxy); + snprintf (option_name, length, "weechat.proxy.%s.type", proxy); proxy_type = weechat_config_get (option_name); - snprintf (option_name, length, "weechat.proxy.%s.ipv6", - server->proxy); + snprintf (option_name, length, "weechat.proxy.%s.ipv6", proxy); proxy_ipv6 = weechat_config_get (option_name); - snprintf (option_name, length, "weechat.proxy.%s.address", - server->proxy); + snprintf (option_name, length, "weechat.proxy.%s.address", proxy); proxy_address = weechat_config_get (option_name); - snprintf (option_name, length, "weechat.proxy.%s.port", - server->proxy); + snprintf (option_name, length, "weechat.proxy.%s.port", proxy); proxy_port = weechat_config_get (option_name); free (option_name); if (!proxy_type || !proxy_address) @@ -2295,7 +2126,7 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) _("%s%s: proxy \"%s\" not found for server " "\"%s\", cannot connect"), irc_buffer_get_server_prefix (server, "error"), - IRC_PLUGIN_NAME, server->proxy, server->name); + IRC_PLUGIN_NAME, proxy, server->name); return 0; } str_proxy_type = weechat_config_string (proxy_type); @@ -2307,12 +2138,12 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) _("%s%s: missing proxy settings, check options " "for proxy \"%s\""), irc_buffer_get_server_prefix (server, "error"), - IRC_PLUGIN_NAME, server->proxy); + IRC_PLUGIN_NAME, proxy); return 0; } } - if (!server->addresses || !server->addresses[0]) + if (!server->addresses_array) { weechat_printf (server->buffer, _("%s%s: addresses not defined for server \"%s\", " @@ -2322,7 +2153,7 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) return 0; } - if (!server->nicks || !server->nicks[0]) + if (!server->nicks_array) { weechat_printf (server->buffer, _("%s%s: nicks not defined for server \"%s\", " @@ -2333,7 +2164,7 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) } #ifndef HAVE_GNUTLS - if (server->ssl) + if (weechat_config_boolean (IRC_SERVER_OPTION(server, IRC_SERVER_OPTION_SSL))) { weechat_printf (server->buffer, _("%s%s: cannot connect with SSL since WeeChat " @@ -2352,8 +2183,10 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) IRC_PLUGIN_NAME, server->addresses_array[server->index_current_address], server->ports_array[server->index_current_address], - (server->ipv6) ? " (IPv6)" : "", - (server->ssl) ? " (SSL)" : "", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? + " (IPv6)" : "", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? + " (SSL)" : "", str_proxy_type, str_proxy_address, weechat_config_integer (proxy_port), @@ -2362,8 +2195,10 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) "%s/%d%s..."), server->addresses_array[server->index_current_address], server->ports_array[server->index_current_address], - (server->ipv6) ? " (IPv6)" : "", - (server->ssl) ? " (SSL)" : "", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? + " (IPv6)" : "", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? + " (SSL)" : "", str_proxy_type, str_proxy_address, weechat_config_integer (proxy_port), @@ -2377,15 +2212,19 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) IRC_PLUGIN_NAME, server->addresses_array[server->index_current_address], server->ports_array[server->index_current_address], - (server->ipv6) ? " (IPv6)" : "", - (server->ssl) ? " (SSL)" : ""); + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? + " (IPv6)" : "", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? + " (SSL)" : ""); weechat_log_printf (_("%s%s: connecting to server %s/%d%s%s..."), "", IRC_PLUGIN_NAME, server->addresses_array[server->index_current_address], server->ports_array[server->index_current_address], - (server->ipv6) ? " (IPv6)" : "", - (server->ssl) ? " (SSL)" : ""); + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? + " (IPv6)" : "", + (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? + " (SSL)" : ""); } /* close connection if open */ @@ -2400,7 +2239,9 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) } else { - server->sock = socket ((server->ipv6) ? AF_INET6 : AF_INET, SOCK_STREAM, 0); + server->sock = socket ((IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? + AF_INET6 : AF_INET, + SOCK_STREAM, 0); } if (server->sock == -1) { @@ -2438,23 +2279,23 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) /* init SSL if asked */ server->ssl_connected = 0; #ifdef HAVE_GNUTLS - if (server->ssl) + if (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) server->ssl_connected = 1; #endif server->disable_autojoin = disable_autojoin; - server->hook_connect = weechat_hook_connect (server->proxy, + server->hook_connect = weechat_hook_connect (proxy, server->addresses_array[server->index_current_address], server->ports_array[server->index_current_address], server->sock, - server->ipv6, + IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6), #ifdef HAVE_GNUTLS (server->ssl_connected) ? &server->gnutls_sess : NULL, #else NULL, #endif - server->local_hostname, + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_LOCAL_HOSTNAME), irc_server_connect_cb, server); @@ -2497,7 +2338,8 @@ irc_server_auto_connect (int auto_connect) for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { - if ((auto_connect) && (ptr_server->autoconnect)) + if (auto_connect + && IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTOCONNECT)) { if (!irc_server_connect (ptr_server, 0)) irc_server_reconnect_schedule (ptr_server); @@ -2556,7 +2398,8 @@ irc_server_disconnect (struct t_irc_server *server, int reconnect) server->lag_next_check = time (NULL) + weechat_config_integer (irc_config_network_lag_check); - if ((reconnect) && (server->autoreconnect)) + if (reconnect + && IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT)) irc_server_reconnect_schedule (server); else server->reconnect_start = 0; @@ -2596,6 +2439,7 @@ void irc_server_autojoin_channels (struct t_irc_server *server) { struct t_irc_channel *ptr_channel; + const char *autojoin; /* auto-join after disconnection (only rejoins opened channels) */ if (!server->disable_autojoin && server->reconnect_join && server->channels) @@ -2618,10 +2462,11 @@ irc_server_autojoin_channels (struct t_irc_server *server) else { /* auto-join when connecting to server for first time */ - if (!server->disable_autojoin && server->autojoin && server->autojoin[0]) - irc_command_join_server (server, server->autojoin); + autojoin = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN); + if (!server->disable_autojoin && autojoin && autojoin[0]) + irc_command_join_server (server, autojoin); } - + server->disable_autojoin = 0; } @@ -3035,39 +2880,56 @@ irc_server_add_to_infolist (struct t_infolist *infolist, && (irc_current_server != server)) ? 0 : 1)) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "autoconnect", server->autoconnect)) + if (!weechat_infolist_new_var_integer (ptr_item, "autoconnect", + IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTOCONNECT))) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect", server->autoreconnect)) + if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect", + IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT))) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect_delay", server->autoreconnect_delay)) + if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect_delay", + IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY))) return 0; - if (!weechat_infolist_new_var_string (ptr_item, "proxy", server->proxy)) + if (!weechat_infolist_new_var_string (ptr_item, "proxy", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY))) return 0; - if (!weechat_infolist_new_var_string (ptr_item, "addresses", server->addresses)) + if (!weechat_infolist_new_var_string (ptr_item, "addresses", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_ADDRESSES))) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "ipv6", server->ipv6)) + if (!weechat_infolist_new_var_integer (ptr_item, "ipv6", + IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6))) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "ssl", server->ssl)) + if (!weechat_infolist_new_var_integer (ptr_item, "ssl", + IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL))) return 0; - if (!weechat_infolist_new_var_string (ptr_item, "password", server->password)) + if (!weechat_infolist_new_var_string (ptr_item, "password", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PASSWORD))) return 0; - if (!weechat_infolist_new_var_string (ptr_item, "nicks", server->nicks)) + if (!weechat_infolist_new_var_string (ptr_item, "nicks", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_NICKS))) return 0; - if (!weechat_infolist_new_var_string (ptr_item, "username", server->username)) + if (!weechat_infolist_new_var_string (ptr_item, "username", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_USERNAME))) return 0; - if (!weechat_infolist_new_var_string (ptr_item, "realname", server->realname)) + if (!weechat_infolist_new_var_string (ptr_item, "realname", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_REALNAME))) return 0; - if (!weechat_infolist_new_var_string (ptr_item, "local_hostname", server->local_hostname)) + if (!weechat_infolist_new_var_string (ptr_item, "local_hostname", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_LOCAL_HOSTNAME))) return 0; - if (!weechat_infolist_new_var_string (ptr_item, "command", server->command)) + if (!weechat_infolist_new_var_string (ptr_item, "command", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_COMMAND))) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "command_delay", server->command_delay)) + if (!weechat_infolist_new_var_integer (ptr_item, "command_delay", + IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY))) return 0; - if (!weechat_infolist_new_var_string (ptr_item, "autojoin", server->autojoin)) + if (!weechat_infolist_new_var_string (ptr_item, "autojoin", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN))) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "autorejoin", server->autorejoin)) + if (!weechat_infolist_new_var_integer (ptr_item, "autorejoin", + IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTOREJOIN))) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "temp_server", server->temp_server)) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "index_current_address", server->index_current_address)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "sock", server->sock)) @@ -3126,61 +2988,147 @@ irc_server_print_log () ptr_server = ptr_server->next_server) { weechat_log_printf (""); - weechat_log_printf ("[server %s (addr:0x%lx)]", ptr_server->name, ptr_server); - weechat_log_printf (" autoconnect . . . . : %d", ptr_server->autoconnect); - weechat_log_printf (" autoreconnect . . . : %d", ptr_server->autoreconnect); - weechat_log_printf (" autoreconnect_delay : %d", ptr_server->autoreconnect_delay); - weechat_log_printf (" proxy . . . . . . . : '%s'", ptr_server->proxy); - weechat_log_printf (" addresses . . . . . : '%s'", ptr_server->addresses); - weechat_log_printf (" ipv6. . . . . . . . : %d", ptr_server->ipv6); - weechat_log_printf (" ssl . . . . . . . . : %d", ptr_server->ssl); - weechat_log_printf (" password. . . . . . : '%s'", - (ptr_server->password && ptr_server->password[0]) ? - "(hidden)" : ptr_server->password); - weechat_log_printf (" nicks . . . . . . . : '%s'", ptr_server->nicks); - weechat_log_printf (" username. . . . . . : '%s'", ptr_server->username); - weechat_log_printf (" realname. . . . . . : '%s'", ptr_server->realname); - weechat_log_printf (" command . . . . . . : '%s'", - (ptr_server->command && ptr_server->command[0]) ? - "(hidden)" : ptr_server->command); - weechat_log_printf (" command_delay . . . : %d", ptr_server->command_delay); - weechat_log_printf (" autojoin. . . . . . : '%s'", ptr_server->autojoin); - weechat_log_printf (" autorejoin. . . . . : %d", ptr_server->autorejoin); - weechat_log_printf (" reloaded_from_config: %d", ptr_server->reloaded_from_config); - weechat_log_printf (" addresses_count . . : %d", ptr_server->addresses_count); - weechat_log_printf (" addresses_array . . : 0x%lx", ptr_server->addresses_array); - weechat_log_printf (" ports_array . . . . : 0x%lx", ptr_server->ports_array); - weechat_log_printf (" sock. . . . . . . . : %d", ptr_server->sock); - weechat_log_printf (" hook_connect. . . . : 0x%lx", ptr_server->hook_connect); - weechat_log_printf (" hook_fd . . . . . . : 0x%lx", ptr_server->hook_fd); - weechat_log_printf (" is_connected. . . . : %d", ptr_server->is_connected); - weechat_log_printf (" ssl_connected . . . : %d", ptr_server->ssl_connected); - weechat_log_printf (" unterminated_message: '%s'", ptr_server->unterminated_message); - weechat_log_printf (" nicks_count . . . . : %d", ptr_server->nicks_count); - weechat_log_printf (" nicks_array . . . . : 0x%lx", ptr_server->nicks_array); - weechat_log_printf (" nick. . . . . . . . : '%s'", ptr_server->nick); - weechat_log_printf (" nick_modes. . . . . : '%s'", ptr_server->nick_modes); - weechat_log_printf (" prefix. . . . . . . : '%s'", ptr_server->prefix); - weechat_log_printf (" reconnect_start . . : %ld", ptr_server->reconnect_start); - weechat_log_printf (" command_time. . . . : %ld", ptr_server->command_time); - weechat_log_printf (" reconnect_join. . . : %d", ptr_server->reconnect_join); - weechat_log_printf (" disable_autojoin. . : %d", ptr_server->disable_autojoin); - weechat_log_printf (" is_away . . . . . . : %d", ptr_server->is_away); - weechat_log_printf (" away_message. . . . : '%s'", ptr_server->away_message); - weechat_log_printf (" away_time . . . . . : %ld", ptr_server->away_time); - weechat_log_printf (" lag . . . . . . . . : %d", ptr_server->lag); - weechat_log_printf (" lag_check_time. . . : tv_sec:%d, tv_usec:%d", + weechat_log_printf ("[server %s (addr:0x%lx)]", ptr_server->name, ptr_server); + + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES])) + weechat_log_printf (" addresses. . . . . . : null (%s)", + IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_ADDRESSES)); + else + weechat_log_printf (" addresses. . . . . . : '%s'", + weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES])); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_PROXY])) + weechat_log_printf (" proxy. . . . . . . . : null (%s)", + IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_PROXY)); + else + weechat_log_printf (" proxy. . . . . . . . : '%s'", + weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_PROXY])); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_IPV6])) + weechat_log_printf (" ipv6 . . . . . . . . : null (%s)", + (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_IPV6)) ? + "on" : "off"); + else + weechat_log_printf (" ipv6 . . . . . . . . : %s", + weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_IPV6]) ? + "on" : "off"); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SSL])) + weechat_log_printf (" ssl. . . . . . . . . : null (%s)", + (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_SSL)) ? + "on" : "off"); + else + weechat_log_printf (" ssl. . . . . . . . . : %s", + weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_SSL]) ? + "on" : "off"); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_PASSWORD])) + weechat_log_printf (" password . . . . . . : null"); + else + weechat_log_printf (" password . . . . . . : (hidden)"); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT])) + weechat_log_printf (" autoconnect. . . . . : null (%s)", + (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTOCONNECT)) ? + "on" : "off"); + else + weechat_log_printf (" autoconnect. . . . . : %s", + weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT]) ? + "on" : "off"); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT])) + weechat_log_printf (" autoreconnect. . . . : null (%s)", + (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT)) ? + "on" : "off"); + else + weechat_log_printf (" autoreconnect. . . . : %s", + weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT]) ? + "on" : "off"); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT_DELAY])) + weechat_log_printf (" autoreconnect_delay. : null (%d)", + IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY)); + else + weechat_log_printf (" autoreconnect_delay. : %d", + weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT_DELAY])); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_NICKS])) + weechat_log_printf (" nicks. . . . . . . . : null (%s)", + IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_NICKS)); + else + weechat_log_printf (" nicks. . . . . . . . : '%s'", + weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_NICKS])); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_USERNAME])) + weechat_log_printf (" username . . . . . . : null (%s)", + IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_USERNAME)); + else + weechat_log_printf (" username . . . . . . : '%s'", + weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_USERNAME])); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_REALNAME])) + weechat_log_printf (" realname . . . . . . : null (%s)", + IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_REALNAME)); + else + weechat_log_printf (" realname . . . . . . : '%s'", + weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_REALNAME])); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_LOCAL_HOSTNAME])) + weechat_log_printf (" local_hostname . . . : null (%s)", + IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_LOCAL_HOSTNAME)); + else + weechat_log_printf (" local_hostname . . . : '%s'", + weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_LOCAL_HOSTNAME])); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_COMMAND])) + weechat_log_printf (" command. . . . . . . : null"); + else + weechat_log_printf (" command. . . . . . . : (hidden)"); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_COMMAND_DELAY])) + weechat_log_printf (" command_delay. . . . : null (%d)", + IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_COMMAND_DELAY)); + else + weechat_log_printf (" command_delay. . . . : %d", + weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_COMMAND_DELAY])); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN])) + weechat_log_printf (" autojoin . . . . . . : null (%s)", + IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_AUTOJOIN)); + else + weechat_log_printf (" autojoin . . . . . . : '%s'", + weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN])); + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN])) + weechat_log_printf (" autorejoin . . . . . : null (%s)", + (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTOREJOIN)) ? + "on" : "off"); + else + weechat_log_printf (" autorejoin . . . . . : %s", + weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN]) ? + "on" : "off"); + weechat_log_printf (" temp_server. . . . . : %d", ptr_server->temp_server); + weechat_log_printf (" reloading_from_config: %d", ptr_server->reloaded_from_config); + weechat_log_printf (" reloaded_from_config : %d", ptr_server->reloaded_from_config); + weechat_log_printf (" addresses_count. . . : %d", ptr_server->addresses_count); + weechat_log_printf (" addresses_array. . . : 0x%lx", ptr_server->addresses_array); + weechat_log_printf (" ports_array. . . . . : 0x%lx", ptr_server->ports_array); + weechat_log_printf (" sock . . . . . . . . : %d", ptr_server->sock); + weechat_log_printf (" hook_connect . . . . : 0x%lx", ptr_server->hook_connect); + weechat_log_printf (" hook_fd. . . . . . . : 0x%lx", ptr_server->hook_fd); + weechat_log_printf (" is_connected . . . . : %d", ptr_server->is_connected); + weechat_log_printf (" ssl_connected. . . . : %d", ptr_server->ssl_connected); + weechat_log_printf (" unterminated_message : '%s'", ptr_server->unterminated_message); + weechat_log_printf (" nicks_count. . . . . : %d", ptr_server->nicks_count); + weechat_log_printf (" nicks_array. . . . . : 0x%lx", ptr_server->nicks_array); + weechat_log_printf (" nick . . . . . . . . : '%s'", ptr_server->nick); + weechat_log_printf (" nick_modes . . . . . : '%s'", ptr_server->nick_modes); + weechat_log_printf (" prefix . . . . . . . : '%s'", ptr_server->prefix); + weechat_log_printf (" reconnect_start. . . : %ld", ptr_server->reconnect_start); + weechat_log_printf (" command_time . . . . : %ld", ptr_server->command_time); + weechat_log_printf (" reconnect_join . . . : %d", ptr_server->reconnect_join); + weechat_log_printf (" disable_autojoin . . : %d", ptr_server->disable_autojoin); + weechat_log_printf (" is_away. . . . . . . : %d", ptr_server->is_away); + weechat_log_printf (" away_message . . . . : '%s'", ptr_server->away_message); + weechat_log_printf (" away_time. . . . . . : %ld", ptr_server->away_time); + weechat_log_printf (" lag. . . . . . . . . : %d", ptr_server->lag); + weechat_log_printf (" lag_check_time . . . : tv_sec:%d, tv_usec:%d", ptr_server->lag_check_time.tv_sec, ptr_server->lag_check_time.tv_usec); - weechat_log_printf (" lag_next_check. . . : %ld", ptr_server->lag_next_check); - weechat_log_printf (" last_user_message . : %ld", ptr_server->last_user_message); - weechat_log_printf (" outqueue. . . . . . : 0x%lx", ptr_server->outqueue); - weechat_log_printf (" last_outqueue . . . : 0x%lx", ptr_server->last_outqueue); - weechat_log_printf (" buffer. . . . . . . : 0x%lx", ptr_server->buffer); - weechat_log_printf (" channels. . . . . . : 0x%lx", ptr_server->channels); - weechat_log_printf (" last_channel. . . . : 0x%lx", ptr_server->last_channel); - weechat_log_printf (" prev_server . . . . : 0x%lx", ptr_server->prev_server); - weechat_log_printf (" next_server . . . . : 0x%lx", ptr_server->next_server); + weechat_log_printf (" lag_next_check . . . : %ld", ptr_server->lag_next_check); + weechat_log_printf (" last_user_message. . : %ld", ptr_server->last_user_message); + weechat_log_printf (" outqueue . . . . . . : 0x%lx", ptr_server->outqueue); + weechat_log_printf (" last_outqueue. . . . : 0x%lx", ptr_server->last_outqueue); + weechat_log_printf (" buffer . . . . . . . : 0x%lx", ptr_server->buffer); + weechat_log_printf (" channels . . . . . . : 0x%lx", ptr_server->channels); + weechat_log_printf (" last_channel . . . . : 0x%lx", ptr_server->last_channel); + weechat_log_printf (" prev_server. . . . . : 0x%lx", ptr_server->prev_server); + weechat_log_printf (" next_server. . . . . : 0x%lx", ptr_server->next_server); for (ptr_channel = ptr_server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 190ec3148..fbca12a44 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -31,6 +31,49 @@ #define NI_MAXHOST 256 #endif +enum t_irc_server_option +{ + IRC_SERVER_OPTION_ADDRESSES = 0, + IRC_SERVER_OPTION_PROXY, + IRC_SERVER_OPTION_IPV6, + IRC_SERVER_OPTION_SSL, + IRC_SERVER_OPTION_PASSWORD, + IRC_SERVER_OPTION_AUTOCONNECT, + IRC_SERVER_OPTION_AUTORECONNECT, + IRC_SERVER_OPTION_AUTORECONNECT_DELAY, + IRC_SERVER_OPTION_NICKS, + IRC_SERVER_OPTION_USERNAME, + IRC_SERVER_OPTION_REALNAME, + IRC_SERVER_OPTION_LOCAL_HOSTNAME, + IRC_SERVER_OPTION_COMMAND, + IRC_SERVER_OPTION_COMMAND_DELAY, + IRC_SERVER_OPTION_AUTOJOIN, + IRC_SERVER_OPTION_AUTOREJOIN, + /* number of server options */ + IRC_SERVER_NUM_OPTIONS, +}; + +#define IRC_SERVER_OPTION_BOOLEAN(__server, __index) \ + ((!weechat_config_option_is_null (__server->options[__index])) ? \ + weechat_config_boolean(__server->options[__index]) : \ + ((!weechat_config_option_is_null (irc_config_server_default[__index])) ? \ + weechat_config_boolean(irc_config_server_default[__index]) \ + : weechat_config_boolean_default(irc_config_server_default[__index]))) + +#define IRC_SERVER_OPTION_INTEGER(__server, __index) \ + ((!weechat_config_option_is_null (__server->options[__index])) ? \ + weechat_config_integer(__server->options[__index]) : \ + ((!weechat_config_option_is_null (irc_config_server_default[__index])) ? \ + weechat_config_integer(irc_config_server_default[__index]) \ + : weechat_config_integer_default(irc_config_server_default[__index]))) + +#define IRC_SERVER_OPTION_STRING(__server, __index) \ + ((!weechat_config_option_is_null (__server->options[__index])) ? \ + weechat_config_string(__server->options[__index]) : \ + ((!weechat_config_option_is_null (irc_config_server_default[__index])) ? \ + weechat_config_string(irc_config_server_default[__index]) \ + : weechat_config_string_default(irc_config_server_default[__index]))) + #define IRC_SERVER_DEFAULT_PORT 6667 #define IRC_SERVER_DEFAULT_PREFIXES_LIST "@%+~&!-" #define IRC_SERVER_DEFAULT_NICKS "weechat1,weechat2,weechat3," \ @@ -59,25 +102,12 @@ struct t_irc_outqueue struct t_irc_server { /* user choices */ - char *name; /* internal name of server */ - int autoconnect; /* = 1 if auto connect at startup */ - int autoreconnect; /* = 1 if auto reco when disconnected */ - int autoreconnect_delay; /* delay before trying again reconnect */ - char *proxy; /* proxy used for this server (optional) */ - char *addresses; /* server addresses (IP/name with port) */ - int ipv6; /* use IPv6 protocol */ - int ssl; /* SSL protocol */ - char *password; /* password for server */ - char *nicks; /* nicknames as one string */ - char *username; /* user name */ - char *realname; /* real name */ - char *local_hostname; /* custom local hostname */ - char *command; /* command to run once connected */ - int command_delay; /* delay after execution of command */ - char *autojoin; /* channels to automatically join */ - int autorejoin; /* auto rejoin channels when kicked */ + char *name; /* internal name of server */ + struct t_config_option *options[IRC_SERVER_NUM_OPTIONS]; /* internal vars */ + int temp_server; /* temporary server (not saved) */ + int reloading_from_config; /* 1 if reloading from config file */ int reloaded_from_config; /* 1 if reloaded from config file */ int addresses_count; /* number of addresses */ char **addresses_array; /* exploded addresses */ @@ -138,21 +168,16 @@ extern const int gnutls_cert_type_prio[]; extern const int gnutls_prot_prio[]; #endif extern struct t_irc_message *irc_recv_msgq, *irc_msgq_last_msg; - +extern char *irc_server_option_string[]; +extern char *irc_server_option_default[]; extern int irc_server_valid (struct t_irc_server *server); +extern int irc_server_search_option (const char *option_name); extern char *irc_server_get_name_without_port (const char *name); -extern void irc_server_new_option (struct t_irc_server *server, - int index_option, - const char *value); extern void irc_server_set_addresses (struct t_irc_server *server, const char *addresses); extern void irc_server_set_nicks (struct t_irc_server *server, const char *nicks); -extern void irc_server_set_with_option (struct t_irc_server *server, - int index_option, - struct t_config_option *option); extern void irc_server_set_nick (struct t_irc_server *server, const char *nick); -extern void irc_server_init (struct t_irc_server *server); extern struct t_irc_server *irc_server_alloc (const char *name); extern int irc_server_alloc_with_url (const char *irc_url); extern void irc_server_free_all (); @@ -172,8 +197,8 @@ extern struct t_irc_server *irc_server_new (const char *name, int autoconnect, int command_delay, const char *autojoin, int autorejoin); -extern struct t_irc_server *irc_server_duplicate (struct t_irc_server *server, - const char *new_name); +extern struct t_irc_server *irc_server_copy (struct t_irc_server *server, + const char *new_name); extern int irc_server_rename (struct t_irc_server *server, const char *new_name); extern void irc_server_send_signal (struct t_irc_server *server, const char *signal, const char *command, diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c index ec28e9774..cd56cafc9 100644 --- a/src/plugins/irc/irc-upgrade.c +++ b/src/plugins/irc/irc-upgrade.c @@ -184,6 +184,8 @@ irc_upgrade_read_cb (int object_id, irc_upgrade_current_server = irc_server_search (weechat_infolist_string (infolist, "name")); if (irc_upgrade_current_server) { + irc_upgrade_current_server->temp_server = + weechat_infolist_integer (infolist, "temp_server"); irc_upgrade_current_server->buffer = NULL; buffer_name = weechat_infolist_string (infolist, "buffer_name"); if (buffer_name && buffer_name[0]) diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index 9c7a85c39..0d0438e79 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -193,12 +193,16 @@ weechat_plugin_end (struct t_weechat_plugin *plugin) if (irc_hook_timer_check_away) weechat_unhook (irc_hook_timer_check_away); - irc_config_write (); - if (irc_signal_upgrade_received) + { + irc_config_write (1); irc_upgrade_save (); + } else + { + irc_config_write (0); irc_server_disconnect_all (); + } irc_server_free_all (); diff --git a/src/plugins/logger/logger-config.c b/src/plugins/logger/logger-config.c index 3183be4a5..b24bf746f 100644 --- a/src/plugins/logger/logger-config.c +++ b/src/plugins/logger/logger-config.c @@ -148,7 +148,7 @@ logger_config_level_create_option (void *data, option_name, "integer", _("logging level for this buffer (0 = logging disabled, " "1 = a few messages (most important) .. 9 = all messages)"), - NULL, 0, 9, "9", value, NULL, NULL, + NULL, 0, 9, "9", value, 0, NULL, NULL, &logger_config_level_change, NULL, NULL, NULL); rc = (ptr_option) ? @@ -275,7 +275,7 @@ logger_config_mask_create_option (void *data, option_name, "string", _("file mask for log file; local buffer variables are " "permitted"), - NULL, 0, 0, "", value, NULL, NULL, + NULL, 0, 0, "", value, 0, NULL, NULL, &logger_config_mask_change, NULL, NULL, NULL); rc = (ptr_option) ? @@ -339,7 +339,7 @@ logger_config_init () "backlog", "integer", N_("maximum number of lines to display from log file when creating " "new buffer (0 = no backlog)"), - NULL, 0, INT_MAX, "20", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, INT_MAX, "20", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); /* file */ ptr_section = weechat_config_new_section (logger_config_file, "file", @@ -358,19 +358,19 @@ logger_config_init () "auto_log", "boolean", N_("automatically save content of buffers to files (unless a buffer " "disables log)"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); logger_config_file_name_lower_case = weechat_config_new_option ( logger_config_file, ptr_section, "name_lower_case", "boolean", N_("use only lower case for log filenames"), - NULL, 0, 0, "on", NULL, NULL, NULL, + NULL, 0, 0, "on", NULL, 0, NULL, NULL, &logger_config_change_file_option_restart_log, NULL, NULL, NULL); logger_config_file_path = weechat_config_new_option ( logger_config_file, ptr_section, "path", "string", N_("path for WeeChat log files ('%h' will be replaced by WeeChat " "home, ~/.weechat by default)"), - NULL, 0, 0, "%h/logs/", NULL, NULL, NULL, + NULL, 0, 0, "%h/logs/", NULL, 0, NULL, NULL, &logger_config_change_file_option_restart_log, NULL, NULL, NULL); logger_config_file_mask = weechat_config_new_option ( logger_config_file, ptr_section, @@ -378,20 +378,20 @@ logger_config_init () N_("default file name mask for log files (format is 'directory/to/file' " "or 'file', without first '/' because 'path' option is used to " "build complete path to file); local buffer variables are permitted"), - NULL, 0, 0, "$plugin.$name.weechatlog", NULL, NULL, NULL, + NULL, 0, 0, "$plugin.$name.weechatlog", NULL, 0, NULL, NULL, &logger_config_change_file_option_restart_log, NULL, NULL, NULL); logger_config_file_info_lines = weechat_config_new_option ( logger_config_file, ptr_section, "info_lines", "boolean", N_("write information line in log file when log starts or ends for a " "buffer"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); logger_config_file_time_format = weechat_config_new_option ( logger_config_file, ptr_section, "time_format", "string", N_("timestamp used in log files (see man strftime for date/time " "specifiers)"), - NULL, 0, 0, "%Y-%m-%d %H:%M:%S", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "%Y-%m-%d %H:%M:%S", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); /* level */ ptr_section = weechat_config_new_section (logger_config_file, "level", diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index e8130e8b6..b8783758e 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -987,11 +987,11 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) " disable logging for current buffer:\n" " /logger disable\n\n" " set level to 3 for all IRC buffers:\n" - " /set logger.level.irc = 3\n" + " /set logger.level.irc 3\n" " disable logging for main WeeChat buffer:\n" - " /set logger.level.core.weechat = 0\n" + " /set logger.level.core.weechat 0\n" " use a directory per IRC server and a file per channel inside:\n" - " /set logger.mask.irc = $server/$channel.weechatlog\n\n" + " /set logger.mask.irc \"$server/$channel.weechatlog\"\n\n" "Log levels used by IRC plugin:\n" " 1: user message, notice, private\n" " 2: nick change\n" diff --git a/src/plugins/notify/notify.c b/src/plugins/notify/notify.c index 603e2bd7f..9334916b0 100644 --- a/src/plugins/notify/notify.c +++ b/src/plugins/notify/notify.c @@ -263,7 +263,7 @@ notify_config_create_option (void *data, struct t_config_file *config_file, config_file, section, option_name, "integer", NULL, "none|highlight|message|all", - 0, 0, "", value, NULL, NULL, NULL, NULL, NULL, NULL); + 0, 0, "", value, 0, NULL, NULL, NULL, NULL, NULL, NULL); rc = (ptr_option) ? WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; } diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c index bc0aa97ea..05a07f67a 100644 --- a/src/plugins/plugin-config.c +++ b/src/plugins/plugin-config.c @@ -96,7 +96,7 @@ plugin_config_set_internal (const char *option, const char *value) ptr_option = config_file_new_option ( plugin_config_file, plugin_config_section_var, option, "string", NULL, - NULL, 0, 0, "", value, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", value, 0, NULL, NULL, NULL, NULL, NULL, NULL); rc = (ptr_option) ? WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; } @@ -164,7 +164,7 @@ plugin_config_create_option (void *data, struct t_config_file *config_file, ptr_option = config_file_new_option ( config_file, section, option_name, "string", NULL, - NULL, 0, 0, "", value, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", value, 0, NULL, NULL, NULL, NULL, NULL, NULL); return (ptr_option) ? WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 4b1c9fe7b..e3c4eba97 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -397,13 +397,20 @@ plugin_load (const char *filename) new_plugin->config_string_to_boolean = &config_file_string_to_boolean; new_plugin->config_option_reset = &config_file_option_reset; new_plugin->config_option_set = &config_file_option_set; + new_plugin->config_option_set_null = &config_file_option_set_null; new_plugin->config_option_unset = &config_file_option_unset; new_plugin->config_option_rename = &config_file_option_rename; new_plugin->config_option_get_pointer = &config_file_option_get_pointer; + new_plugin->config_option_is_null = &config_file_option_is_null; new_plugin->config_boolean = &config_file_option_boolean; + new_plugin->config_boolean_default = &config_file_option_boolean_default; new_plugin->config_integer = &config_file_option_integer; + new_plugin->config_integer_default = &config_file_option_integer_default; new_plugin->config_string = &config_file_option_string; + new_plugin->config_string_default = &config_file_option_string_default; new_plugin->config_color = &config_file_option_color; + new_plugin->config_color_default = &config_file_option_color_default; + new_plugin->config_write_option = &config_file_write_option; new_plugin->config_write_line = &config_file_write_line; new_plugin->config_write = &config_file_write; new_plugin->config_read = &config_file_read; diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c index a8cd965a6..2889cbcbc 100644 --- a/src/plugins/relay/relay-config.c +++ b/src/plugins/relay/relay-config.c @@ -106,7 +106,7 @@ relay_config_init () relay_config_file, ptr_section, "auto_open_buffer", "boolean", N_("auto open relay buffer when a new client is connecting"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); ptr_section = weechat_config_new_section (relay_config_file, "color", 0, 0, @@ -123,49 +123,49 @@ relay_config_init () relay_config_file, ptr_section, "text", "color", N_("text color"), - NULL, 0, 0, "default", NULL, + NULL, 0, 0, "default", NULL, 0, NULL, NULL, &relay_config_refresh_cb, NULL, NULL, NULL); relay_config_color_text_bg = weechat_config_new_option ( relay_config_file, ptr_section, "text_bg", "color", N_("background color"), - NULL, 0, 0, "default", NULL, + NULL, 0, 0, "default", NULL, 0, NULL, NULL, &relay_config_refresh_cb, NULL, NULL, NULL); relay_config_color_text_selected = weechat_config_new_option ( relay_config_file, ptr_section, "text_selected", "color", N_("text color of selected client line"), - NULL, 0, 0, "white", NULL, + NULL, 0, 0, "white", NULL, 0, NULL, NULL, &relay_config_refresh_cb, NULL, NULL, NULL); relay_config_color_status[RELAY_STATUS_CONNECTING] = weechat_config_new_option ( relay_config_file, ptr_section, "status_connecting", "color", N_("text color for \"connecting\" status"), - NULL, 0, 0, "yellow", NULL, + NULL, 0, 0, "yellow", NULL, 0, NULL, NULL, &relay_config_refresh_cb, NULL, NULL, NULL); relay_config_color_status[RELAY_STATUS_WAITING_AUTH] = weechat_config_new_option ( relay_config_file, ptr_section, "status_waiting_auth", "color", N_("text color for \"waiting authentication\" status"), - NULL, 0, 0, "brown", NULL, + NULL, 0, 0, "brown", NULL, 0, NULL, NULL, &relay_config_refresh_cb, NULL, NULL, NULL); relay_config_color_status[RELAY_STATUS_CONNECTED] = weechat_config_new_option ( relay_config_file, ptr_section, "status_active", "color", N_("text color for \"connected\" status"), - NULL, 0, 0, "lightblue", NULL, + NULL, 0, 0, "lightblue", NULL, 0, NULL, NULL, &relay_config_refresh_cb, NULL, NULL, NULL); relay_config_color_status[RELAY_STATUS_AUTH_FAILED] = weechat_config_new_option ( relay_config_file, ptr_section, "status_auth_failed", "color", N_("text color for \"authentication failed\" status"), - NULL, 0, 0, "lightred", NULL, + NULL, 0, 0, "lightred", NULL, 0, NULL, NULL, &relay_config_refresh_cb, NULL, NULL, NULL); relay_config_color_status[RELAY_STATUS_DISCONNECTED] = weechat_config_new_option ( relay_config_file, ptr_section, "status_disconnected", "color", N_("text color for \"disconnected\" status"), - NULL, 0, 0, "lightred", NULL, + NULL, 0, 0, "lightred", NULL, 0, NULL, NULL, &relay_config_refresh_cb, NULL, NULL, NULL); ptr_section = weechat_config_new_section (relay_config_file, "network", @@ -185,7 +185,7 @@ relay_config_init () N_("port number (or range of ports) that relay plugin listens on " "(syntax: a single port, ie. 5000 or a port " "range, ie. 5000-5015)"), - NULL, 0, 0, "22373-22400", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "22373-22400", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); return 1; } diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 95d0eaefa..671db30dd 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -1461,7 +1461,7 @@ weechat_lua_api_config_new_option (lua_State *L) const char *string_values, *default_value, *value; const char *function_check_value, *function_change, *function_delete; char *result; - int n, min, max; + int n, min, max, null_value_allowed; /* make C compiler happy */ (void) L; @@ -1482,28 +1482,30 @@ weechat_lua_api_config_new_option (lua_State *L) max = 0; default_value = NULL; value = NULL; + null_value_allowed = 0; function_check_value = NULL; function_change = NULL; function_delete = NULL; n = lua_gettop (lua_current_interpreter); - if (n < 13) + if (n < 14) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option"); LUA_RETURN_EMPTY; } - config_file = lua_tostring (lua_current_interpreter, -13); - section = lua_tostring (lua_current_interpreter, -12); - name = lua_tostring (lua_current_interpreter, -11); - type = lua_tostring (lua_current_interpreter, -10); - description = lua_tostring (lua_current_interpreter, -9); - string_values = lua_tostring (lua_current_interpreter, -8); - min = lua_tonumber (lua_current_interpreter, -7); - max = lua_tonumber (lua_current_interpreter, -6); - default_value = lua_tostring (lua_current_interpreter, -5); - value = lua_tostring (lua_current_interpreter, -4); + config_file = lua_tostring (lua_current_interpreter, -14); + section = lua_tostring (lua_current_interpreter, -13); + name = lua_tostring (lua_current_interpreter, -12); + type = lua_tostring (lua_current_interpreter, -11); + description = lua_tostring (lua_current_interpreter, -10); + string_values = lua_tostring (lua_current_interpreter, -9); + min = lua_tonumber (lua_current_interpreter, -8); + max = lua_tonumber (lua_current_interpreter, -7); + default_value = lua_tostring (lua_current_interpreter, -6); + value = lua_tostring (lua_current_interpreter, -5); + null_value_allowed = lua_tonumber (lua_current_interpreter, -4); function_check_value = lua_tostring (lua_current_interpreter, -3); function_change = lua_tostring (lua_current_interpreter, -2); function_delete = lua_tostring (lua_current_interpreter, -1); @@ -1520,6 +1522,7 @@ weechat_lua_api_config_new_option (lua_State *L) max, default_value, value, + null_value_allowed, &weechat_lua_api_config_option_check_value_cb, function_check_value, &weechat_lua_api_config_option_change_cb, @@ -1664,7 +1667,7 @@ weechat_lua_api_config_option_set (lua_State *L) if (!lua_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set"); - LUA_RETURN_INT(0); + LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } option = NULL; @@ -1676,7 +1679,7 @@ weechat_lua_api_config_option_set (lua_State *L) if (n < 3) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set"); - LUA_RETURN_INT(0); + LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } option = lua_tostring (lua_current_interpreter, -3); @@ -1691,6 +1694,46 @@ weechat_lua_api_config_option_set (lua_State *L) } /* + * weechat_lua_api_config_option_set_null: set null (undefined) value for + * option + */ + +static int +weechat_lua_api_config_option_set_null (lua_State *L) +{ + const char *option; + int n, run_callback, rc; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set_null"); + LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + option = NULL; + run_callback = 0; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set_null"); + LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + option = lua_tostring (lua_current_interpreter, -2); + run_callback = lua_tonumber (lua_current_interpreter, -1); + + rc = weechat_config_option_set_null (script_str2ptr (option), + run_callback); + + LUA_RETURN_INT(rc); +} + +/* * weechat_lua_api_config_option_unset: unset an option */ @@ -1706,7 +1749,7 @@ weechat_lua_api_config_option_unset (lua_State *L) if (!lua_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_unset"); - LUA_RETURN_INT(0); + LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); } option = NULL; @@ -1716,7 +1759,7 @@ weechat_lua_api_config_option_unset (lua_State *L) if (n < 1) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_unset"); - LUA_RETURN_INT(0); + LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); } option = lua_tostring (lua_current_interpreter, -1); @@ -1741,7 +1784,7 @@ weechat_lua_api_config_option_rename (lua_State *L) if (!lua_current_script) { - WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_rename");; + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_rename"); LUA_RETURN_ERROR; } @@ -1766,6 +1809,79 @@ weechat_lua_api_config_option_rename (lua_State *L) } /* + * weechat_lua_api_config_option_is_null: return 1 if value of option is null + */ + +static int +weechat_lua_api_config_option_is_null (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_option_is_null"); + LUA_RETURN_INT(1); + } + + option = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_is_null"); + LUA_RETURN_INT(1); + } + + option = lua_tostring (lua_current_interpreter, -1); + + value = weechat_config_option_is_null (script_str2ptr (option)); + + LUA_RETURN_INT(value); +} + +/* + * weechat_lua_api_config_option_default_is_null: return 1 if default value of + * option is null + */ + +static int +weechat_lua_api_config_option_default_is_null (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_option_default_is_null"); + LUA_RETURN_INT(1); + } + + option = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_default_is_null"); + LUA_RETURN_INT(1); + } + + option = lua_tostring (lua_current_interpreter, -1); + + value = weechat_config_option_default_is_null (script_str2ptr (option)); + + LUA_RETURN_INT(value); +} + +/* * weechat_lua_api_config_boolean: return boolean value of option */ @@ -1910,6 +2026,45 @@ weechat_lua_api_config_color (lua_State *L) } /* + * weechat_lua_api_config_write_option: write an option in configuration file + */ + +static int +weechat_lua_api_config_write_option (lua_State *L) +{ + const char *config_file, *option; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write_option"); + LUA_RETURN_ERROR; + } + + config_file = NULL; + option = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write_option"); + LUA_RETURN_ERROR; + } + + config_file = lua_tostring (lua_current_interpreter, -2); + option = lua_tostring (lua_current_interpreter, -1); + + weechat_config_write_option (script_str2ptr (config_file), + script_str2ptr (option)); + + LUA_RETURN_OK; +} + +/* * weechat_lua_api_config_write_line: write a line in configuration file */ @@ -5880,12 +6035,16 @@ const struct luaL_reg weechat_lua_api_funcs[] = { { "config_string_to_boolean", &weechat_lua_api_config_string_to_boolean }, { "config_option_reset", &weechat_lua_api_config_option_reset }, { "config_option_set", &weechat_lua_api_config_option_set }, + { "config_option_set_null", &weechat_lua_api_config_option_set_null }, { "config_option_unset", &weechat_lua_api_config_option_unset }, { "config_option_rename", &weechat_lua_api_config_option_rename }, + { "config_option_is_null", &weechat_lua_api_config_option_is_null }, + { "config_option_default_is_null", &weechat_lua_api_config_option_default_is_null }, { "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_option", &weechat_lua_api_config_write_option }, { "config_write_line", &weechat_lua_api_config_write_line }, { "config_write", &weechat_lua_api_config_write }, { "config_read", &weechat_lua_api_config_read }, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index ab463c05d..396673b37 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -1260,7 +1260,7 @@ static XS (XS_weechat_api_config_new_option) PERL_RETURN_EMPTY; } - if (items < 13) + if (items < 14) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option"); PERL_RETURN_EMPTY; @@ -1274,9 +1274,9 @@ static XS (XS_weechat_api_config_new_option) string_values = SvPV (ST (5), PL_na); default_value = SvPV (ST (8), PL_na); value = SvPV (ST (9), PL_na); - function_check_value = SvPV (ST (10), PL_na); - function_change = SvPV (ST (11), PL_na); - function_delete = SvPV (ST (12), PL_na); + function_check_value = SvPV (ST (11), PL_na); + function_change = SvPV (ST (12), PL_na); + function_delete = SvPV (ST (13), PL_na); result = script_ptr2str (script_api_config_new_option (weechat_perl_plugin, perl_current_script, script_str2ptr (config_file), @@ -1289,6 +1289,7 @@ static XS (XS_weechat_api_config_new_option) SvIV (ST (7)), /* max */ default_value, value, + SvIV (ST (10)), /* null_value_allowed */ &weechat_perl_api_config_option_check_value_cb, function_check_value, &weechat_perl_api_config_option_change_cb, @@ -1410,13 +1411,13 @@ static XS (XS_weechat_api_config_option_set) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set"); - PERL_RETURN_INT(0); + PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } if (items < 3) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set"); - PERL_RETURN_INT(0); + PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } option = SvPV (ST (0), PL_na); @@ -1429,6 +1430,38 @@ static XS (XS_weechat_api_config_option_set) } /* + * weechat::config_option_set_null: set null (undefined) value for option + */ + +static XS (XS_weechat_api_config_option_set_null) +{ + int rc; + char *option; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set_null"); + PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set_null"); + PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + option = SvPV (ST (0), PL_na); + rc = weechat_config_option_set_null (script_str2ptr (option), + SvIV (ST (1))); /* run_callback */ + + PERL_RETURN_INT(rc); +} + +/* * weechat::config_option_unset: unset an option */ @@ -1444,13 +1477,13 @@ static XS (XS_weechat_api_config_option_unset) if (!perl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_unset"); - PERL_RETURN_INT(0); + PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); } if (items < 1) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_unset"); - PERL_RETURN_INT(0); + PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); } option = SvPV (ST (0), PL_na); @@ -1492,6 +1525,65 @@ static XS (XS_weechat_api_config_option_rename) } /* + * weechat::config_option_is_null: return 1 if value of option is null + */ + +static XS (XS_weechat_api_config_option_is_null) +{ + int value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_is_null"); + PERL_RETURN_INT(1); + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_is_null"); + PERL_RETURN_INT(1); + } + + value = weechat_config_option_is_null (script_str2ptr (SvPV (ST (0), PL_na))); /* option */ + + PERL_RETURN_INT(value); +} + +/* + * weechat::config_option_default_is_null: return 1 if default value of option + * is null + */ + +static XS (XS_weechat_api_config_option_default_is_null) +{ + int value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_default_is_null"); + PERL_RETURN_INT(1); + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_default_is_null"); + PERL_RETURN_INT(1); + } + + value = weechat_config_option_default_is_null (script_str2ptr (SvPV (ST (0), PL_na))); /* option */ + + PERL_RETURN_INT(value); +} + +/* * weechat::config_boolean: return boolean value of option */ @@ -1608,6 +1700,38 @@ static XS (XS_weechat_api_config_color) } /* + * weechat::config_write_option: write an option in configuration file + */ + +static XS (XS_weechat_api_config_write_option) +{ + char *config_file, *option; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write_option"); + PERL_RETURN_ERROR; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write_option"); + PERL_RETURN_ERROR; + } + + config_file = SvPV (ST (0), PL_na); + option = SvPV (ST (1), PL_na); + weechat_config_write_option (script_str2ptr (config_file), + script_str2ptr (option)); + + PERL_RETURN_OK; +} + +/* * weechat::config_write_line: write a line in configuration file */ @@ -4624,12 +4748,16 @@ weechat_perl_api_init (pTHX) newXS ("weechat::config_string_to_boolean", XS_weechat_api_config_string_to_boolean, "weechat"); newXS ("weechat::config_option_reset", XS_weechat_api_config_option_reset, "weechat"); newXS ("weechat::config_option_set", XS_weechat_api_config_option_set, "weechat"); + newXS ("weechat::config_option_set_null", XS_weechat_api_config_option_set_null, "weechat"); newXS ("weechat::config_option_unset", XS_weechat_api_config_option_unset, "weechat"); newXS ("weechat::config_option_rename", XS_weechat_api_config_option_rename, "weechat"); + newXS ("weechat::config_option_is_null", XS_weechat_api_config_option_is_null, "weechat"); + newXS ("weechat::config_option_default_is_null", XS_weechat_api_config_option_default_is_null, "weechat"); newXS ("weechat::config_boolean", XS_weechat_api_config_boolean, "weechat"); newXS ("weechat::config_integer", XS_weechat_api_config_integer, "weechat"); newXS ("weechat::config_string", XS_weechat_api_config_string, "weechat"); newXS ("weechat::config_color", XS_weechat_api_config_color, "weechat"); + newXS ("weechat::config_write_option", XS_weechat_api_config_write_option, "weechat"); newXS ("weechat::config_write_line", XS_weechat_api_config_write_line, "weechat"); newXS ("weechat::config_write", XS_weechat_api_config_write, "weechat"); newXS ("weechat::config_read", XS_weechat_api_config_read, "weechat"); diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 06459fb84..d4097b242 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -1316,7 +1316,7 @@ weechat_python_api_config_new_option (PyObject *self, PyObject *args) char *config_file, *section, *name, *type, *description, *string_values; char *default_value, *value, *result; char *function_check_value, *function_change, *function_delete; - int min, max; + int min, max, null_value_allowed; PyObject *object; /* make C compiler happy */ @@ -1340,10 +1340,11 @@ weechat_python_api_config_new_option (PyObject *self, PyObject *args) function_change = NULL; function_delete = NULL; - if (!PyArg_ParseTuple (args, "ssssssiisssss", &config_file, §ion, &name, + if (!PyArg_ParseTuple (args, "ssssssiississs", &config_file, §ion, &name, &type, &description, &string_values, &min, &max, - &default_value, &value, &function_check_value, - &function_change, &function_delete)) + &default_value, &value, &null_value_allowed, + &function_check_value, &function_change, + &function_delete)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option"); PYTHON_RETURN_EMPTY; @@ -1361,6 +1362,7 @@ weechat_python_api_config_new_option (PyObject *self, PyObject *args) max, default_value, value, + null_value_allowed, &weechat_python_api_config_option_check_value_cb, function_check_value, &weechat_python_api_config_option_change_cb, @@ -1489,7 +1491,7 @@ weechat_python_api_config_option_set (PyObject *self, PyObject *args) if (!python_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set"); - PYTHON_RETURN_INT(0); + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } option = NULL; @@ -1499,7 +1501,7 @@ weechat_python_api_config_option_set (PyObject *self, PyObject *args) if (!PyArg_ParseTuple (args, "ssi", &option, &new_value, &run_callback)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set"); - PYTHON_RETURN_INT(0); + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } rc = weechat_config_option_set (script_str2ptr (option), @@ -1510,6 +1512,41 @@ weechat_python_api_config_option_set (PyObject *self, PyObject *args) } /* + * weechat_python_api_config_option_set_null: set null (undefined) value for + * option + */ + +static PyObject * +weechat_python_api_config_option_set_null (PyObject *self, PyObject *args) +{ + char *option; + int run_callback, rc; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set_null"); + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + option = NULL; + run_callback = 0; + + if (!PyArg_ParseTuple (args, "si", &option, &run_callback)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set_null"); + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + rc = weechat_config_option_set_null (script_str2ptr (option), + run_callback); + + PYTHON_RETURN_INT(rc); +} + +/* * weechat_python_api_config_option_unset: unset an option */ @@ -1525,7 +1562,7 @@ weechat_python_api_config_option_unset (PyObject *self, PyObject *args) if (!python_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_unset"); - PYTHON_RETURN_INT(0); + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); } option = NULL; @@ -1533,7 +1570,7 @@ weechat_python_api_config_option_unset (PyObject *self, PyObject *args) if (!PyArg_ParseTuple (args, "s", &option)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_unset"); - PYTHON_RETURN_INT(0); + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); } rc = weechat_config_option_unset (script_str2ptr (option)); @@ -1575,6 +1612,71 @@ weechat_python_api_config_option_rename (PyObject *self, PyObject *args) } /* + * weechat_python_api_config_option_is_null: return 1 if value of option is null + */ + +static PyObject * +weechat_python_api_config_option_is_null (PyObject *self, PyObject *args) +{ + char *option; + int value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_is_null"); + PYTHON_RETURN_INT(1); + } + + option = NULL; + + if (!PyArg_ParseTuple (args, "s", &option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_is_null"); + PYTHON_RETURN_INT(1); + } + + value = weechat_config_option_is_null (script_str2ptr (option)); + + PYTHON_RETURN_INT(value); +} + +/* + * weechat_python_api_config_option_default_is_null: return 1 if default value + * of option is null + */ + +static PyObject * +weechat_python_api_config_option_default_is_null (PyObject *self, PyObject *args) +{ + char *option; + int value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_default_is_null"); + PYTHON_RETURN_INT(1); + } + + option = NULL; + + if (!PyArg_ParseTuple (args, "s", &option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_default_is_null"); + PYTHON_RETURN_INT(1); + } + + value = weechat_config_option_default_is_null (script_str2ptr (option)); + + PYTHON_RETURN_INT(value); +} + +/* * weechat_python_api_config_boolean: return boolean value of option */ @@ -1703,6 +1805,39 @@ weechat_python_api_config_color (PyObject *self, PyObject *args) } /* + * weechat_python_api_config_write_option: write an option in configuration file + */ + +static PyObject * +weechat_python_api_config_write_option (PyObject *self, PyObject *args) +{ + char *config_file, *option; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write_option"); + PYTHON_RETURN_ERROR; + } + + config_file = NULL; + option = NULL; + + if (!PyArg_ParseTuple (args, "ss", &config_file, &option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write_option"); + PYTHON_RETURN_ERROR; + } + + weechat_config_write_option (script_str2ptr (config_file), + script_str2ptr (option)); + + PYTHON_RETURN_OK; +} + +/* * weechat_python_api_config_write_line: write a line in configuration file */ @@ -4911,12 +5046,16 @@ PyMethodDef weechat_python_funcs[] = { "config_string_to_boolean", &weechat_python_api_config_string_to_boolean, METH_VARARGS, "" }, { "config_option_reset", &weechat_python_api_config_option_reset, METH_VARARGS, "" }, { "config_option_set", &weechat_python_api_config_option_set, METH_VARARGS, "" }, + { "config_option_set_null", &weechat_python_api_config_option_set_null, METH_VARARGS, "" }, { "config_option_unset", &weechat_python_api_config_option_unset, METH_VARARGS, "" }, { "config_option_rename", &weechat_python_api_config_option_rename, METH_VARARGS, "" }, + { "config_option_is_null", &weechat_python_api_config_option_is_null, METH_VARARGS, "" }, + { "config_option_default_is_null", &weechat_python_api_config_option_default_is_null, 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_option", &weechat_python_api_config_write_option, 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, "" }, diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index 8dc690f7e..28cd43ed4 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -1477,7 +1477,7 @@ 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 value, + VALUE value, VALUE null_value_allowed, VALUE function_check_value, VALUE function_change, VALUE function_delete) @@ -1485,7 +1485,7 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, char *c_config_file, *c_section, *c_name, *c_type, *c_description; char *c_string_values, *c_default_value, *c_value, *result; char *c_function_check_value, *c_function_change, *c_function_delete; - int c_min, c_max; + int c_min, c_max, c_null_value_allowed; VALUE return_value; /* make C compiler happy */ @@ -1507,13 +1507,14 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, c_max = 0; c_default_value = NULL; c_value = NULL; + c_null_value_allowed = 0; c_function_check_value = NULL; c_function_change = NULL; c_function_delete = 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 (value) + || NIL_P (default_value) || NIL_P (value) || NIL_P (null_value_allowed) || NIL_P (function_check_value) || NIL_P (function_change) || NIL_P (function_delete)) { @@ -1531,6 +1532,7 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, Check_Type (max, T_FIXNUM); Check_Type (default_value, T_STRING); Check_Type (value, T_STRING); + Check_Type (null_value_allowed, T_FIXNUM); Check_Type (function_check_value, T_STRING); Check_Type (function_change, T_STRING); Check_Type (function_delete, T_STRING); @@ -1545,6 +1547,7 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, c_max = FIX2INT (max); c_default_value = STR2CSTR (default_value); c_value = STR2CSTR (value); + c_null_value_allowed = FIX2INT (null_value_allowed); c_function_check_value = STR2CSTR (function_check_value); c_function_change = STR2CSTR (function_change); c_function_delete = STR2CSTR (function_delete); @@ -1561,6 +1564,7 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, c_max, c_default_value, c_value, + c_null_value_allowed, &weechat_ruby_api_config_option_check_value_cb, c_function_check_value, &weechat_ruby_api_config_option_change_cb, @@ -1710,7 +1714,7 @@ weechat_ruby_api_config_option_set (VALUE class, VALUE option, VALUE new_value, if (!ruby_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set"); - RUBY_RETURN_INT(0); + RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } c_option = NULL; @@ -1720,7 +1724,7 @@ weechat_ruby_api_config_option_set (VALUE class, VALUE option, VALUE new_value, if (NIL_P (option) || NIL_P (new_value) || NIL_P (run_callback)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set"); - RUBY_RETURN_INT(0); + RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } Check_Type (option, T_STRING); @@ -1739,6 +1743,48 @@ weechat_ruby_api_config_option_set (VALUE class, VALUE option, VALUE new_value, } /* + * weechat_ruby_api_config_option_set_null: set null (undefined) value for + * option + */ + +static VALUE +weechat_ruby_api_config_option_set_null (VALUE class, VALUE option, + VALUE run_callback) +{ + char *c_option; + int c_run_callback, rc; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set_null"); + RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + c_option = NULL; + c_run_callback = 0; + + if (NIL_P (option) || NIL_P (run_callback)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set_null"); + RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + Check_Type (option, T_STRING); + Check_Type (run_callback, T_FIXNUM); + + c_option = STR2CSTR (option); + c_run_callback = FIX2INT (run_callback); + + rc = weechat_config_option_set_null (script_str2ptr (c_option), + c_run_callback); + + RUBY_RETURN_INT(rc); +} + +/* * weechat_ruby_api_config_option_unset: unset an option */ @@ -1754,7 +1800,7 @@ weechat_ruby_api_config_option_unset (VALUE class, VALUE option) if (!ruby_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_unset"); - RUBY_RETURN_INT(0); + RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); } c_option = NULL; @@ -1762,7 +1808,7 @@ weechat_ruby_api_config_option_unset (VALUE class, VALUE option) if (NIL_P (option)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_unset"); - RUBY_RETURN_INT(0); + RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); } Check_Type (option, T_STRING); @@ -1815,6 +1861,78 @@ weechat_ruby_api_config_option_rename (VALUE class, VALUE option, } /* + * weechat_ruby_api_config_option_is_null: return 1 if value of option is null + */ + +static VALUE +weechat_ruby_api_config_option_is_null (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_option_is_null"); + RUBY_RETURN_INT(1); + } + + c_option = NULL; + + if (NIL_P (option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_is_null"); + RUBY_RETURN_INT(1); + } + + Check_Type (option, T_STRING); + + c_option = STR2CSTR (option); + + value = weechat_config_option_is_null (script_str2ptr (c_option)); + + RUBY_RETURN_INT(value); +} + +/* + * weechat_ruby_api_config_option_default_is_null: return 1 if value of option is null + */ + +static VALUE +weechat_ruby_api_config_option_default_is_null (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_option_default_is_null"); + RUBY_RETURN_INT(1); + } + + c_option = NULL; + + if (NIL_P (option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_default_is_null"); + RUBY_RETURN_INT(1); + } + + Check_Type (option, T_STRING); + + c_option = STR2CSTR (option); + + value = weechat_config_option_default_is_null (script_str2ptr (c_option)); + + RUBY_RETURN_INT(value); +} + +/* * weechat_ruby_api_config_boolean: return boolean value of option */ @@ -1959,6 +2077,46 @@ weechat_ruby_api_config_color (VALUE class, VALUE option) } /* + * weechat_ruby_api_config_write_option: write an option in configuration file + */ + +static VALUE +weechat_ruby_api_config_write_option (VALUE class, VALUE config_file, + VALUE option) +{ + char *c_config_file, *c_option; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write_option"); + RUBY_RETURN_ERROR; + } + + c_config_file = NULL; + c_option = NULL; + + if (NIL_P (config_file) || NIL_P (option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write_option"); + RUBY_RETURN_ERROR; + } + + Check_Type (config_file, T_STRING); + Check_Type (option, T_STRING); + + c_config_file = STR2CSTR (config_file); + c_option = STR2CSTR (option); + + weechat_config_write_option (script_str2ptr (c_config_file), + script_str2ptr (c_option)); + + RUBY_RETURN_OK; +} + +/* * weechat_ruby_api_config_write_line: write a line in configuration file */ @@ -5636,17 +5794,21 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) 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, 9); 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, 13); + rb_define_module_function (ruby_mWeechat, "config_new_option", &weechat_ruby_api_config_new_option, 14); 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_reset", &weechat_ruby_api_config_option_reset, 2); rb_define_module_function (ruby_mWeechat, "config_option_set", &weechat_ruby_api_config_option_set, 3); + rb_define_module_function (ruby_mWeechat, "config_option_set_null", &weechat_ruby_api_config_option_set_null, 2); rb_define_module_function (ruby_mWeechat, "config_option_unset", &weechat_ruby_api_config_option_unset, 1); rb_define_module_function (ruby_mWeechat, "config_option_rename", &weechat_ruby_api_config_option_rename, 2); + rb_define_module_function (ruby_mWeechat, "config_option_is_null", &weechat_ruby_api_config_option_is_null, 1); + rb_define_module_function (ruby_mWeechat, "config_option_default_is_null", &weechat_ruby_api_config_option_default_is_null, 1); 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_option", &weechat_ruby_api_config_write_option, 2); 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); diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index 0e07965f7..d810a4a77 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -347,6 +347,7 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin, int min, int max, const char *default_value, const char *value, + int null_value_allowed, void (*callback_check_value)(void *data, struct t_config_option *option, const char *value), @@ -416,6 +417,7 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin, new_option = weechat_config_new_option (config_file, section, name, type, description, string_values, min, max, default_value, value, + null_value_allowed, callback1, new_script_callback1, callback2, new_script_callback2, callback3, new_script_callback3); diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h index eff244667..d498b22e4 100644 --- a/src/plugins/scripts/script-api.h +++ b/src/plugins/scripts/script-api.h @@ -68,6 +68,7 @@ extern struct t_config_option *script_api_config_new_option (struct t_weechat_pl int min, int max, const char *default_value, const char *value, + int null_value_allowed, void (*callback_check_value)(void *data, struct t_config_option *option, const char *value), diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index fd6d83496..29a192d1f 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -1458,10 +1458,6 @@ weechat_tcl_api_config_option_delete_cb (void *data, } } - - - - /* * weechat_tcl_api_config_new_option: create a new option in section */ @@ -1474,7 +1470,7 @@ weechat_tcl_api_config_new_option (ClientData clientData, Tcl_Interp *interp, char *result, *config_file, *section, *name, *type; char *description, *string_values, *default_value, *value; char *function_check_value, *function_change, *function_delete; - int i,min,max; + int i, min, max, null_value_allowed; /* make C compiler happy */ (void) clientData; @@ -1485,14 +1481,15 @@ weechat_tcl_api_config_new_option (ClientData clientData, Tcl_Interp *interp, TCL_RETURN_EMPTY; } - if (objc < 14) + if (objc < 15) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option"); TCL_RETURN_EMPTY; } if ((Tcl_GetIntFromObj (interp, objv[7], &min) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[8], &max) != TCL_OK)) + || (Tcl_GetIntFromObj (interp, objv[8], &max) != TCL_OK) + || (Tcl_GetIntFromObj (interp, objv[11], &null_value_allowed) != TCL_OK)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option"); TCL_RETURN_EMPTY; @@ -1506,9 +1503,9 @@ weechat_tcl_api_config_new_option (ClientData clientData, Tcl_Interp *interp, string_values = Tcl_GetStringFromObj (objv[6], &i); default_value = Tcl_GetStringFromObj (objv[9], &i); value = Tcl_GetStringFromObj (objv[10], &i); - function_check_value = Tcl_GetStringFromObj (objv[11], &i); - function_change = Tcl_GetStringFromObj (objv[12], &i); - function_delete = Tcl_GetStringFromObj (objv[13], &i); + function_check_value = Tcl_GetStringFromObj (objv[12], &i); + function_change = Tcl_GetStringFromObj (objv[13], &i); + function_delete = Tcl_GetStringFromObj (objv[14], &i); result = script_ptr2str (script_api_config_new_option (weechat_tcl_plugin, tcl_current_script, @@ -1522,6 +1519,7 @@ weechat_tcl_api_config_new_option (ClientData clientData, Tcl_Interp *interp, max, default_value, value, + null_value_allowed, &weechat_tcl_api_config_option_check_value_cb, function_check_value, &weechat_tcl_api_config_option_change_cb, @@ -1653,7 +1651,7 @@ weechat_tcl_api_config_option_set (ClientData clientData, Tcl_Interp *interp, Tcl_Obj* objp; int rc; char *option, *new_value; - int i,run_cb; + int i, run_callback; /* make C compiler happy */ (void) clientData; @@ -1661,26 +1659,67 @@ weechat_tcl_api_config_option_set (ClientData clientData, Tcl_Interp *interp, if (!tcl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set"); - TCL_RETURN_INT(0); + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } if (objc < 4) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set"); - TCL_RETURN_INT(0); + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } - if (Tcl_GetIntFromObj (interp, objv[3], &run_cb) != TCL_OK) + if (Tcl_GetIntFromObj (interp, objv[3], &run_callback) != TCL_OK) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set"); - TCL_RETURN_INT(0); + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); } option = Tcl_GetStringFromObj (objv[1], &i); new_value = Tcl_GetStringFromObj (objv[2], &i); rc = weechat_config_option_set (script_str2ptr (option), new_value, - run_cb); /* run_callback */ + run_callback); + + TCL_RETURN_INT(rc); +} + +/* + * weechat_tcl_api_config_option_set_null: set null (undefined)value for option + */ + +static int +weechat_tcl_api_config_option_set_null (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj* objp; + int rc; + char *option; + int i, run_callback; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_set_null"); + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + if (objc < 3) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set_null"); + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + if (Tcl_GetIntFromObj (interp, objv[2], &run_callback) != TCL_OK) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_set_null"); + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + option = Tcl_GetStringFromObj (objv[1], &i); + rc = weechat_config_option_set_null (script_str2ptr (option), + run_callback); TCL_RETURN_INT(rc); } @@ -1704,13 +1743,13 @@ weechat_tcl_api_config_option_unset (ClientData clientData, Tcl_Interp *interp, if (!tcl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_unset"); - TCL_RETURN_INT(0); + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); } if (objc < 2) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_unset"); - TCL_RETURN_INT(0); + TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR); } option = Tcl_GetStringFromObj (objv[1], &i); @@ -1748,6 +1787,7 @@ weechat_tcl_api_config_option_rename (ClientData clientData, Tcl_Interp *interp, option = Tcl_GetStringFromObj (objv[1], &i); new_name = Tcl_GetStringFromObj (objv[2], &i); + weechat_config_option_rename (script_str2ptr (option), new_name); @@ -1755,6 +1795,70 @@ weechat_tcl_api_config_option_rename (ClientData clientData, Tcl_Interp *interp, } /* + * weechat_tcl_api_config_option_is_null: return 1 if value of option is null + */ + +static int +weechat_tcl_api_config_option_is_null (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj* objp; + int result, i; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_is_null"); + TCL_RETURN_INT(1); + } + + if (objc < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_is_null"); + TCL_RETURN_INT(1); + } + + result = weechat_config_option_is_null (script_str2ptr (Tcl_GetStringFromObj (objv[1], &i))); /* option */ + + TCL_RETURN_INT(result); +} + +/* + * weechat_tcl_api_config_option_default_is_null: return 1 if default value of + * option is null + */ + +static int +weechat_tcl_api_config_option_default_is_null (ClientData clientData, + Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj* objp; + int result, i; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_default_is_null"); + TCL_RETURN_INT(1); + } + + if (objc < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_default_is_null"); + TCL_RETURN_INT(1); + } + + result = weechat_config_option_default_is_null (script_str2ptr (Tcl_GetStringFromObj (objv[1], &i))); /* option */ + + TCL_RETURN_INT(result); +} + +/* * weechat_tcl_api_config_boolean: return boolean value of option */ @@ -1881,6 +1985,41 @@ weechat_tcl_api_config_color (ClientData clientData, Tcl_Interp *interp, } /* + * weechat_tcl_api_config_write_option: write an option in configuration file + */ + +static int +weechat_tcl_api_config_write_option (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj *objp; + char *config_file, *option; + int i; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_write_option"); + TCL_RETURN_ERROR; + } + + if (objc < 3) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_write_option"); + TCL_RETURN_ERROR; + } + + config_file = Tcl_GetStringFromObj (objv[1], &i); + option = Tcl_GetStringFromObj (objv[2], &i); + weechat_config_write_option (script_str2ptr (config_file), + script_str2ptr (option)); + + TCL_RETURN_OK; +} + +/* * weechat_tcl_api_config_write_line: write a line in configuration file */ @@ -5324,10 +5463,16 @@ void weechat_tcl_api_init (Tcl_Interp *interp) { weechat_tcl_api_config_option_reset, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::config_option_set", weechat_tcl_api_config_option_set, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp,"weechat::config_option_set_null", + weechat_tcl_api_config_option_set_null, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::config_option_unset", weechat_tcl_api_config_option_unset, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::config_option_rename", weechat_tcl_api_config_option_rename, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp,"weechat::config_option_is_null", + weechat_tcl_api_config_option_is_null, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp,"weechat::config_option_default_is_null", + weechat_tcl_api_config_option_default_is_null, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::config_boolean", weechat_tcl_api_config_boolean, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::config_integer", @@ -5336,6 +5481,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) { weechat_tcl_api_config_string, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::config_color", weechat_tcl_api_config_color, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp,"weechat::config_write_option", + weechat_tcl_api_config_write_option, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::config_write_line", weechat_tcl_api_config_write_line, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::config_write", diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 3513eca52..416a530c7 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -60,6 +60,9 @@ struct t_weelist; #define WEECHAT_CONFIG_WRITE_ERROR -1 #define WEECHAT_CONFIG_WRITE_MEMORY_ERROR -2 +/* null value for option */ +#define WEECHAT_CONFIG_OPTION_NULL "null" + /* return codes for config option set */ #define WEECHAT_CONFIG_OPTION_SET_OK_CHANGED 2 #define WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE 1 @@ -254,6 +257,7 @@ struct t_weechat_plugin int max, const char *default_value, const char *value, + int null_value_allowed, int (*callback_check_value)(void *data, struct t_config_option *option, const char *value), @@ -282,15 +286,25 @@ struct t_weechat_plugin int run_callback); int (*config_option_set) (struct t_config_option *option, const char *value, int run_callback); + int (*config_option_set_null) (struct t_config_option *option, + int run_callback); int (*config_option_unset) (struct t_config_option *option); void (*config_option_rename) (struct t_config_option *option, const char *new_name); void *(*config_option_get_pointer) (struct t_config_option *option, const char *property); + int (*config_option_is_null) (struct t_config_option *option); + int (*config_option_default_is_null) (struct t_config_option *option); int (*config_boolean) (struct t_config_option *option); + int (*config_boolean_default) (struct t_config_option *option); int (*config_integer) (struct t_config_option *option); + int (*config_integer_default) (struct t_config_option *option); const char *(*config_string) (struct t_config_option *option); + const char *(*config_string_default) (struct t_config_option *option); const char *(*config_color) (struct t_config_option *option); + const char *(*config_color_default) (struct t_config_option *option); + void (*config_write_option) (struct t_config_file *config_file, + struct t_config_option *option); void (*config_write_line) (struct t_config_file *config_file, const char *option_name, const char *value, ...); @@ -761,6 +775,7 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); #define weechat_config_new_option(__config, __section, __name, __type, \ __desc, __string_values, __min, \ __max, __default, __value, \ + __null_value_allowed, \ __callback_check, \ __callback_check_data, \ __callback_change, \ @@ -770,6 +785,7 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->config_new_option(__config, __section, __name, \ __type, __desc, __string_values, \ __min, __max, __default, __value, \ + __null_value_allowed, \ __callback_check, \ __callback_check_data, \ __callback_change, \ @@ -797,20 +813,36 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); #define weechat_config_option_set(__option, __value, __run_callback) \ weechat_plugin->config_option_set(__option, __value, \ __run_callback) +#define weechat_config_option_set_null(__option, __run_callback) \ + weechat_plugin->config_option_set_null(__option, __run_callback) #define weechat_config_option_unset(__option) \ weechat_plugin->config_option_unset(__option) #define weechat_config_option_rename(__option, __new_name) \ weechat_plugin->config_option_rename(__option, __new_name) #define weechat_config_option_get_pointer(__option, __property) \ weechat_plugin->config_option_get_pointer(__option, __property) +#define weechat_config_option_is_null(__option) \ + weechat_plugin->config_option_is_null(__option) +#define weechat_config_option_default_is_null(__option) \ + weechat_plugin->config_option_default_is_null(__option) #define weechat_config_boolean(__option) \ weechat_plugin->config_boolean(__option) +#define weechat_config_boolean_default(__option) \ + weechat_plugin->config_boolean_default(__option) #define weechat_config_integer(__option) \ weechat_plugin->config_integer(__option) +#define weechat_config_integer_default(__option) \ + weechat_plugin->config_integer_default(__option) #define weechat_config_string(__option) \ weechat_plugin->config_string(__option) +#define weechat_config_string_default(__option) \ + weechat_plugin->config_string_default(__option) #define weechat_config_color(__option) \ weechat_plugin->config_color(__option) +#define weechat_config_color_default(__option) \ + weechat_plugin->config_color_default(__option) +#define weechat_config_write_option(__config, __option) \ + weechat_plugin->config_write_option(__config, __option) #define weechat_config_write_line(__config, __option, __value...) \ weechat_plugin->config_write_line(__config, __option, ##__value) #define weechat_config_write(__config) \ diff --git a/src/plugins/xfer/xfer-config.c b/src/plugins/xfer/xfer-config.c index f4dcdfc45..8f9c15a17 100644 --- a/src/plugins/xfer/xfer-config.c +++ b/src/plugins/xfer/xfer-config.c @@ -124,12 +124,12 @@ xfer_config_init () "auto_open_buffer", "boolean", N_("auto open xfer buffer when a new xfer is added " "to list"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_look_progress_bar_size = weechat_config_new_option ( xfer_config_file, ptr_section, "progress_bar_size", "integer", N_("size of progress bar, in chars (if 0, progress bar is disabled)"), - NULL, 0, XFER_CONFIG_PROGRESS_BAR_MAX_SIZE, "20", NULL, + NULL, 0, XFER_CONFIG_PROGRESS_BAR_MAX_SIZE, "20", NULL, 0, NULL, NULL, &xfer_config_refresh_cb, NULL, NULL, NULL); ptr_section = weechat_config_new_section (xfer_config_file, "color", @@ -147,55 +147,55 @@ xfer_config_init () xfer_config_file, ptr_section, "text", "color", N_("text color"), - NULL, 0, 0, "default", NULL, + NULL, 0, 0, "default", NULL, 0, NULL, NULL, &xfer_config_refresh_cb, NULL, NULL, NULL); xfer_config_color_text_bg = weechat_config_new_option ( xfer_config_file, ptr_section, "text_bg", "color", N_("background color"), - NULL, 0, 0, "default", NULL, + NULL, 0, 0, "default", NULL, 0, NULL, NULL, &xfer_config_refresh_cb, NULL, NULL, NULL); xfer_config_color_text_selected = weechat_config_new_option ( xfer_config_file, ptr_section, "text_selected", "color", N_("text color of selected xfer line"), - NULL, 0, 0, "white", NULL, + NULL, 0, 0, "white", NULL, 0, NULL, NULL, &xfer_config_refresh_cb, NULL, NULL, NULL); xfer_config_color_status[XFER_STATUS_WAITING] = weechat_config_new_option ( xfer_config_file, ptr_section, "status_waiting", "color", N_("text color for \"waiting\" status"), - NULL, 0, 0, "lightcyan", NULL, + NULL, 0, 0, "lightcyan", NULL, 0, NULL, NULL, &xfer_config_refresh_cb, NULL, NULL, NULL); xfer_config_color_status[XFER_STATUS_CONNECTING] = weechat_config_new_option ( xfer_config_file, ptr_section, "status_connecting", "color", N_("text color for \"connecting\" status"), - NULL, 0, 0, "yellow", NULL, + NULL, 0, 0, "yellow", NULL, 0, NULL, NULL, &xfer_config_refresh_cb, NULL, NULL, NULL); xfer_config_color_status[XFER_STATUS_ACTIVE] = weechat_config_new_option ( xfer_config_file, ptr_section, "status_active", "color", N_("text color for \"active\" status"), - NULL, 0, 0, "lightblue", NULL, + NULL, 0, 0, "lightblue", NULL, 0, NULL, NULL, &xfer_config_refresh_cb, NULL, NULL, NULL); xfer_config_color_status[XFER_STATUS_DONE] = weechat_config_new_option ( xfer_config_file, ptr_section, "status_done", "color", N_("text color for \"done\" status"), - NULL, 0, 0, "lightgreen", NULL, + NULL, 0, 0, "lightgreen", NULL, 0, NULL, NULL, &xfer_config_refresh_cb, NULL, NULL, NULL); xfer_config_color_status[XFER_STATUS_FAILED] = weechat_config_new_option ( xfer_config_file, ptr_section, "status_failed", "color", N_("text color for \"failed\" status"), - NULL, 0, 0, "lightred", NULL, + NULL, 0, 0, "lightred", NULL, 0, NULL, NULL, &xfer_config_refresh_cb, NULL, NULL, NULL); xfer_config_color_status[XFER_STATUS_ABORTED] = weechat_config_new_option ( xfer_config_file, ptr_section, "status_aborted", "color", N_("text color for \"aborted\" status"), - NULL, 0, 0, "lightred", NULL, + NULL, 0, 0, "lightred", NULL, 0, NULL, NULL, &xfer_config_refresh_cb, NULL, NULL, NULL); ptr_section = weechat_config_new_section (xfer_config_file, "network", @@ -213,37 +213,37 @@ xfer_config_init () xfer_config_file, ptr_section, "timeout", "integer", N_("timeout for xfer request (in seconds)"), - NULL, 5, INT_MAX, "300", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 5, INT_MAX, "300", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_network_blocksize = weechat_config_new_option ( xfer_config_file, ptr_section, "blocksize", "integer", N_("block size for sending packets, in bytes"), - NULL, XFER_BLOCKSIZE_MIN, XFER_BLOCKSIZE_MAX, "65536", NULL, + NULL, XFER_BLOCKSIZE_MIN, XFER_BLOCKSIZE_MAX, "65536", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_network_fast_send = weechat_config_new_option ( xfer_config_file, ptr_section, "fast_send", "boolean", N_("does not wait for ACK when sending file"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_network_port_range = weechat_config_new_option ( xfer_config_file, ptr_section, "port_range", "string", N_("restricts outgoing files/chats 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, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_network_own_ip = weechat_config_new_option ( xfer_config_file, ptr_section, "own_ip", "string", N_("IP or DNS address used for sending files/chats " "(if empty, local interface IP is used)"), - NULL, 0, 0, "", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_network_speed_limit = weechat_config_new_option ( xfer_config_file, ptr_section, "speed_limit", "integer", N_("speed limit for sending files, in kilo-bytes by second (0 means " "no limit)"), - NULL, 0, INT_MAX, "0", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, INT_MAX, "0", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); ptr_section = weechat_config_new_section (xfer_config_file, "file", 0, 0, @@ -260,44 +260,44 @@ xfer_config_init () xfer_config_file, ptr_section, "download_path", "string", N_("path for writing incoming files"), - NULL, 0, 0, "%h/xfer", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "%h/xfer", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_file_upload_path = weechat_config_new_option ( xfer_config_file, ptr_section, "upload_path", "string", N_("path for reading files when sending (when no path is " "specified by user)"), - NULL, 0, 0, "~", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "~", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_file_use_nick_in_filename = weechat_config_new_option ( xfer_config_file, ptr_section, "use_nick_in_filename", "boolean", N_("use remote nick as prefix in local filename when receiving a file"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_file_convert_spaces = weechat_config_new_option ( xfer_config_file, ptr_section, "convert_spaces", "boolean", N_("convert spaces to underscores when sending files"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_file_auto_rename = weechat_config_new_option ( xfer_config_file, ptr_section, "auto_rename", "boolean", N_("rename incoming files if already exists (add '.1', '.2', ...)"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_file_auto_resume = weechat_config_new_option ( xfer_config_file, ptr_section, "auto_resume", "boolean", N_("automatically resume file transfer if connection with remote host " "is lost"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_file_auto_accept_files = weechat_config_new_option ( xfer_config_file, ptr_section, "auto_accept_files", "boolean", N_("automatically accept incoming files (use carefully!)"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_file_auto_accept_chats = weechat_config_new_option ( xfer_config_file, ptr_section, "auto_accept_chats", "boolean", N_("automatically accept chat requests (use carefully!)"), - NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); return 1; } |