diff options
28 files changed, 568 insertions, 318 deletions
@@ -1,7 +1,7 @@ WeeChat ChangeLog ================= FlashCode <flashcode@flashtux.org> -v0.3.2-dev, 2010-03-25 +v0.3.2-dev, 2010-03-26 Version 0.3.2 (under dev!) @@ -22,6 +22,8 @@ Version 0.3.2 (under dev!) string_is_command_char and string_input_for_buffer in plugin and script API * core: add new option weechat.look.read_marker_always_show * core: use arguments for infolist "nicklist" to return only one nick or group +* core: fix bug with writing of configuration files when disk is full + (bug #29331) * gui: refresh screen when exiting WeeChat (to display messages printed after /quit) * gui: fix bug with global history, reset pointer to last entry after each user diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt index 540d590b8..87afffec9 100644 --- a/doc/en/weechat_plugin_api.en.txt +++ b/doc/en/weechat_plugin_api.en.txt @@ -2700,7 +2700,8 @@ my_section_write_cb (void *data, struct t_config_file *config_file, { /* ... */ - return WEECHAT_RC_OK; + return WEECHAT_CONFIG_WRITE_OK; + /* return WEECHAT_CONFIG_WRITE_ERROR; */ } int @@ -2709,7 +2710,8 @@ my_section_write_default_cb (void *data, struct t_config_file *config_file, { /* ... */ - return WEECHAT_RC_OK; + return WEECHAT_CONFIG_WRITE_OK; + /* return WEECHAT_CONFIG_WRITE_ERROR; */ } int @@ -2719,7 +2721,8 @@ my_section_create_option_cb (void *data, struct t_config_file *config_file, { /* ... */ - return WEECHAT_RC_OK; + return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + /* return WEECHAT_CONFIG_OPTION_SET_ERROR; */ } int @@ -2729,7 +2732,8 @@ my_section_delete_option_cb (void *data, struct t_config_file *config_file, { /* ... */ - return WEECHAT_RC_OK; + return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; + /* return WEECHAT_CONFIG_OPTION_UNSET_ERROR; */ } /* standard section, user can not add/delete options */ @@ -5369,7 +5373,7 @@ struct t_hook *weechat_hook_connect (const char *proxy, int (*callback)(void *data, int status, int gnutls_rc, - const char *errpr, + const char *error, const char *ip_address), void *callback_data); ---------------------------------------- @@ -5386,6 +5390,7 @@ Arguments: * 'gnutls_cb': GnuTLS callback (optional) * 'gnutls_dhkey_size': size of the key used during the Diffie-Hellman Key Exchange (GnuTLS) +* 'local_hostname': local hostname to use for connection (optional) * 'callback': function called when connection is ok or failed, arguments: ** 'void *data': pointer ** 'int status': connection status: @@ -6014,7 +6019,7 @@ Script (Python): [source,python] ---------------------------------------- # prototype -hook = weechat.hook_completion(completion_item, callback, callback_data) +hook = weechat.hook_completion(completion_item, description, callback, callback_data) # example def my_completion_cb(data, completion_item, buffer, completion): diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt index e92fda835..a664b3915 100644 --- a/doc/fr/weechat_plugin_api.fr.txt +++ b/doc/fr/weechat_plugin_api.fr.txt @@ -2735,7 +2735,8 @@ my_section_write_cb (void *data, struct t_config_file *config_file, { /* ... */ - return WEECHAT_RC_OK; + return WEECHAT_CONFIG_WRITE_OK; + /* return WEECHAT_CONFIG_WRITE_ERROR; */ } int @@ -2744,7 +2745,8 @@ my_section_write_default_cb (void *data, struct t_config_file *config_file, { /* ... */ - return WEECHAT_RC_OK; + return WEECHAT_CONFIG_WRITE_OK; + /* return WEECHAT_CONFIG_WRITE_ERROR; */ } int @@ -2754,7 +2756,8 @@ my_section_create_option_cb (void *data, struct t_config_file *config_file, { /* ... */ - return WEECHAT_RC_OK; + return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + /* return WEECHAT_CONFIG_OPTION_SET_ERROR; */ } int @@ -2764,7 +2767,8 @@ my_section_delete_option_cb (void *data, struct t_config_file *config_file, { /* ... */ - return WEECHAT_RC_OK; + return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; + /* return WEECHAT_CONFIG_OPTION_UNSET_ERROR; */ } /* section standard, l'utilisateur ne peut pas ajouter/supprimer des options */ @@ -5454,6 +5458,7 @@ Paramètres : * 'gnutls_cb' : callback pour GnuTLS (optionnel) * 'gnutls_dhkey_size': taille de clé utilisée pour l'échange de clé Diffie-Hellman (GnuTLS) +* 'local_hostname': nom de machine local à utiliser pour la connexion (optionnel) * 'callback' : fonction appelée lorsque la connexion est ok ou a échoué, paramètres : ** 'void *data' : pointeur @@ -6093,7 +6098,7 @@ Script (Python) : [source,python] ---------------------------------------- # prototype -hook = weechat.hook_completion(completion_item, callback, callback_data) +hook = weechat.hook_completion(completion_item, description, callback, callback_data) # exemple def my_completion_cb(data, completion_item, buffer, completion): diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt index 383793827..d62ec15d2 100644 --- a/doc/it/weechat_plugin_api.it.txt +++ b/doc/it/weechat_plugin_api.it.txt @@ -2741,7 +2741,7 @@ my_section_write_cb (void *data, struct t_config_file *config_file, /* ... */ return WEECHAT_CONFIG_WRITE_OK; - /* return WEECHAT_CONFIG_WRITE_ERROR; */ + /* return WEECHAT_CONFIG_WRITE_ERROR; */ } int @@ -2751,7 +2751,7 @@ my_section_write_default_cb (void *data, struct t_config_file *config_file, /* ... */ return WEECHAT_CONFIG_WRITE_OK; - /* return WEECHAT_CONFIG_WRITE_ERROR; */ + /* return WEECHAT_CONFIG_WRITE_ERROR; */ } int @@ -6981,7 +6981,7 @@ Argomenti: * 'buffer': puntatore al buffer * 'property': nome proprietà: ** 'plugin': nome del plugin che ha creato questo buffer ("core" - per il buffer principale di WeeChat) + per il buffer principale di WeeChat) ** 'name': nome del buffer ** 'short_name': nome breve del buffer ** 'tilte': titolo del buffer @@ -7115,14 +7115,14 @@ Argomenti: | notify | "0", "1", "2", "3" | set notify level for buffer: "0" = never add to hotlist, "1" = add for highlights only, "2" = add for highlights and messages, "3" = add for all - messages + messages | title | any string | set new title for buffer | time_for_each_line | "0" or "1" | "0" to hide time for all lines in buffer, "1" to see time for all lines - (default for a new buffer) + (default for a new buffer) | nicklist | "0" or "1" | "0" to remove nicklist for buffer, "1" to add nicklist for buffer @@ -7136,7 +7136,7 @@ Argomenti: | highlight_words | "-" or comma separated list of words | "-" is a special value to disable any highlight on this buffer, or comma separated list of words to highlight in this buffer, for example: - "abc,def,ghi" + "abc,def,ghi" | highlight_tags | comma separated list of tags | comma separated list of tags to highlight in this buffer @@ -8110,7 +8110,7 @@ Argomenti: ** 'vertical': gli elementi sono posizionati in verticale (nuova riga dopo ogni elemento) ** 'columns_horizontal': gli elementi sono posizionati in orizzontale, - visualizzati su colonne + visualizzati su colonne ** 'columns_vertical': gli elementi sono posizionati in verticale, visualizzati su colonne * 'size': dimensione della barra in caratteri @@ -8797,7 +8797,7 @@ Argomenti: * 'infolist_name': nome della lista info da leggere: include::autogen/plugin_api/infolists.txt[] -* 'pointer': puntatore ad un elemento, per ricevere solo questo +* 'pointer': puntatore ad un elemento, per ricevere solo questo elemento nella lista info (opzionale, può essere NULL) * 'arguments': argomenti per la lista info richiesta (opzionale, NULL se non è necessario alcun argomento) @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-25 10:20+0100\n" +"POT-Creation-Date: 2010-03-26 10:59+0100\n" "PO-Revision-Date: 2010-03-23 10:19+0100\n" "Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -2106,10 +2106,6 @@ msgid "%sError reading configuration" msgstr "%sChyba: čtení konfigurace" #, c-format -msgid "%sError: cannot create file \"%s\"" -msgstr "%sChyba: nemohu vytvořit soubor \"%s\"" - -#, c-format msgid "Writing configuration file %s %s" msgstr "Zapisuji soubor s nastavením %s %s" @@ -2117,6 +2113,14 @@ msgid "(default options)" msgstr "(výchozí volby)" #, c-format +msgid "%sError: cannot create file \"%s\"" +msgstr "%sChyba: nemohu vytvořit soubor \"%s\"" + +#, fuzzy, c-format +msgid "%sError writing configuration file \"%s\"" +msgstr "%s%s: chyba při vytváření konfiguračního souboru" + +#, c-format msgid "%sWarning: configuration file \"%s\" not found" msgstr "%sUpozornění: konfigurační soubor \"%s\" nenalezen" @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-25 10:20+0100\n" +"POT-Creation-Date: 2010-03-26 10:59+0100\n" "PO-Revision-Date: 2010-03-23 15:44+0100\n" "Last-Translator: Nils G <weechatter@arcor.de>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -2201,10 +2201,6 @@ msgid "%sError reading configuration" msgstr "%sFehler beim lesen der Konfiguration" #, c-format -msgid "%sError: cannot create file \"%s\"" -msgstr "%sFehler: kann die Datei \"%s\" nicht erstellen" - -#, c-format msgid "Writing configuration file %s %s" msgstr "speichere Konfigurationsdatei %s %s" @@ -2212,6 +2208,14 @@ msgid "(default options)" msgstr "(Standardoption)" #, c-format +msgid "%sError: cannot create file \"%s\"" +msgstr "%sFehler: kann die Datei \"%s\" nicht erstellen" + +#, fuzzy, c-format +msgid "%sError writing configuration file \"%s\"" +msgstr "%s%s: Fehler beim Erstellen einer Konfigurationsdatei" + +#, c-format msgid "%sWarning: configuration file \"%s\" not found" msgstr "%sWarnung: Konfigurationsdatei \"%s\" nicht gefunden." @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-25 10:20+0100\n" +"POT-Creation-Date: 2010-03-26 10:59+0100\n" "PO-Revision-Date: 2010-03-23 10:20+0100\n" "Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -2115,10 +2115,6 @@ msgid "%sError reading configuration" msgstr "%sError al leer la configuración" #, c-format -msgid "%sError: cannot create file \"%s\"" -msgstr "%sError: no es posible crear el archivo \"%s\"" - -#, c-format msgid "Writing configuration file %s %s" msgstr "Guardando archivo de configuración %s %s" @@ -2126,6 +2122,14 @@ msgid "(default options)" msgstr "(opciones por defecto)" #, c-format +msgid "%sError: cannot create file \"%s\"" +msgstr "%sError: no es posible crear el archivo \"%s\"" + +#, fuzzy, c-format +msgid "%sError writing configuration file \"%s\"" +msgstr "%s%s: error el crear el archivo de configuración" + +#, c-format msgid "%sWarning: configuration file \"%s\" not found" msgstr "%sAtención: archivo de configuración \"%s\" no encontrado." @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-25 10:20+0100\n" -"PO-Revision-Date: 2010-03-25 10:24+0100\n" +"POT-Creation-Date: 2010-03-26 10:59+0100\n" +"PO-Revision-Date: 2010-03-26 11:02+0100\n" "Last-Translator: FlashCode <flashcode@flashtux.org>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" "MIME-Version: 1.0\n" @@ -2185,10 +2185,6 @@ msgid "%sError reading configuration" msgstr "%sErreur de lecture de la configuration" #, c-format -msgid "%sError: cannot create file \"%s\"" -msgstr "%sErreur: impossible de créer le fichier \"%s\"" - -#, c-format msgid "Writing configuration file %s %s" msgstr "Ecriture du fichier de configuration %s %s" @@ -2196,6 +2192,14 @@ msgid "(default options)" msgstr "(options par défaut)" #, c-format +msgid "%sError: cannot create file \"%s\"" +msgstr "%sErreur: impossible de créer le fichier \"%s\"" + +#, c-format +msgid "%sError writing configuration file \"%s\"" +msgstr "%sErreur d'écriture du fichier de configuration \"%s\"" + +#, c-format msgid "%sWarning: configuration file \"%s\" not found" msgstr "%sAttention: fichier de configuration \"%s\" non trouvé" @@ -12,7 +12,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-25 10:20+0100\n" +"POT-Creation-Date: 2010-03-26 10:59+0100\n" "PO-Revision-Date: 2010-03-23 10:20+0100\n" "Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -1991,10 +1991,6 @@ msgid "%sError reading configuration" msgstr "szerver konfigurációs fájljának újraolvastatása" #, fuzzy, c-format -msgid "%sError: cannot create file \"%s\"" -msgstr "%s nem sikerült a \"%s\" fájlt létrehozni\n" - -#, fuzzy, c-format msgid "Writing configuration file %s %s" msgstr "beállítások mentése kilépéskor" @@ -2002,6 +1998,14 @@ msgid "(default options)" msgstr "" #, fuzzy, c-format +msgid "%sError: cannot create file \"%s\"" +msgstr "%s nem sikerült a \"%s\" fájlt létrehozni\n" + +#, fuzzy, c-format +msgid "%sError writing configuration file \"%s\"" +msgstr "szerver konfigurációs fájljának újraolvastatása" + +#, fuzzy, c-format msgid "%sWarning: configuration file \"%s\" not found" msgstr "%s a \"%s\" beállítófájl nem található.\n" @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Weechat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-25 10:20+0100\n" +"POT-Creation-Date: 2010-03-26 10:59+0100\n" "PO-Revision-Date: 2010-03-24 14:20+0100\n" "Last-Translator: Marco Paolone <marcopaolone@gmail.com>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -2158,10 +2158,6 @@ msgid "%sError reading configuration" msgstr "%sErrore nella lettura della configurazione" #, c-format -msgid "%sError: cannot create file \"%s\"" -msgstr "%sErrore: impossibile creare il file \"%s\"" - -#, c-format msgid "Writing configuration file %s %s" msgstr "Salvataggio del file di configurazione %s %s" @@ -2169,6 +2165,14 @@ msgid "(default options)" msgstr "(opzioni predefinite)" #, c-format +msgid "%sError: cannot create file \"%s\"" +msgstr "%sErrore: impossibile creare il file \"%s\"" + +#, fuzzy, c-format +msgid "%sError writing configuration file \"%s\"" +msgstr "%s%s: impossibile creare il file di configurazione" + +#, c-format msgid "%sWarning: configuration file \"%s\" not found" msgstr "%sAttenzione: file di configurazione \"%s\" non trovato" @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.0-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-25 10:20+0100\n" +"POT-Creation-Date: 2010-03-26 10:59+0100\n" "PO-Revision-Date: 2010-03-23 10:20+0100\n" "Last-Translator: Krzysztof Koroscik <soltys@szluug.org>\n" "Language-Team: Polish\n" @@ -2133,10 +2133,6 @@ msgid "%sError reading configuration" msgstr "%sBłąd podczas odczytu konfiguracji" #, c-format -msgid "%sError: cannot create file \"%s\"" -msgstr "%sBłąd: nie można utrorzyć pliku \"%s\"" - -#, c-format msgid "Writing configuration file %s %s" msgstr "Zapisuję plik konfiguracyjny %s %s" @@ -2144,6 +2140,14 @@ msgid "(default options)" msgstr "(domyślne opcje)" #, c-format +msgid "%sError: cannot create file \"%s\"" +msgstr "%sBłąd: nie można utrorzyć pliku \"%s\"" + +#, fuzzy, c-format +msgid "%sError writing configuration file \"%s\"" +msgstr "%s%s: błąd podczas tworzenia pliku konfiguracyjnego" + +#, c-format msgid "%sWarning: configuration file \"%s\" not found" msgstr "%sOstrzeżenie: nie znaleziono pliku konfiguracyjnego \"%s\"" @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-25 10:20+0100\n" +"POT-Creation-Date: 2010-03-26 10:59+0100\n" "PO-Revision-Date: 2010-03-23 10:20+0100\n" "Last-Translator: Pavel Shevchuk <stlwrt@gmail.com>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -1998,10 +1998,6 @@ msgid "%sError reading configuration" msgstr "перезагрузить конфигурационный файл сервера" #, fuzzy, c-format -msgid "%sError: cannot create file \"%s\"" -msgstr "%s не могу создать файл \"%s\"\n" - -#, fuzzy, c-format msgid "Writing configuration file %s %s" msgstr "сохранять конфигурационный файл при выходе" @@ -2009,6 +2005,14 @@ msgid "(default options)" msgstr "" #, fuzzy, c-format +msgid "%sError: cannot create file \"%s\"" +msgstr "%s не могу создать файл \"%s\"\n" + +#, fuzzy, c-format +msgid "%sError writing configuration file \"%s\"" +msgstr "перезагрузить конфигурационный файл сервера" + +#, fuzzy, c-format msgid "%sWarning: configuration file \"%s\" not found" msgstr "%s конфигурационынй файл \"%s\" не найден.\n" diff --git a/po/weechat.pot b/po/weechat.pot index c4d88f53a..7f08dd12a 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-25 10:20+0100\n" +"POT-Creation-Date: 2010-03-26 10:59+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -1694,14 +1694,18 @@ msgid "%sError reading configuration" msgstr "" #, c-format -msgid "%sError: cannot create file \"%s\"" +msgid "Writing configuration file %s %s" +msgstr "" + +msgid "(default options)" msgstr "" #, c-format -msgid "Writing configuration file %s %s" +msgid "%sError: cannot create file \"%s\"" msgstr "" -msgid "(default options)" +#, c-format +msgid "%sError writing configuration file \"%s\"" msgstr "" #, c-format diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index cd146bfb7..0f8305e9b 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -153,13 +153,13 @@ config_file_new_section (struct t_config_file *config_file, const char *name, const char *option_name, const char *value), void *callback_read_data, - void (*callback_write)(void *data, - struct t_config_file *config_file, - const char *section_name), + int (*callback_write)(void *data, + struct t_config_file *config_file, + const char *section_name), void *callback_write_data, - void (*callback_write_default)(void *data, - struct t_config_file *config_file, - const char *section_name), + int (*callback_write_default)(void *data, + struct t_config_file *config_file, + const char *section_name), void *callback_write_default_data, int (*callback_create_option)(void *data, struct t_config_file *config_file, @@ -1779,44 +1779,49 @@ config_file_option_color_default (struct t_config_option *option) /* * config_file_write_option: write an option in a configuration file + * return 1 if ok, 0 if error */ -void +int config_file_write_option (struct t_config_file *config_file, struct t_config_option *option) { + int rc; + if (!config_file || !config_file->file || !option) - return; - + return 0; + + rc = 1; + if (option->value) { switch (option->type) { case CONFIG_OPTION_TYPE_BOOLEAN: - string_iconv_fprintf (config_file->file, "%s = %s\n", - option->name, - (CONFIG_BOOLEAN(option) == CONFIG_BOOLEAN_TRUE) ? - "on" : "off"); + rc = string_iconv_fprintf (config_file->file, "%s = %s\n", + option->name, + (CONFIG_BOOLEAN(option) == 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[CONFIG_INTEGER(option)]); + rc = string_iconv_fprintf (config_file->file, "%s = %s\n", + option->name, + option->string_values[CONFIG_INTEGER(option)]); else - string_iconv_fprintf (config_file->file, "%s = %d\n", - option->name, - CONFIG_INTEGER(option)); + rc = string_iconv_fprintf (config_file->file, "%s = %d\n", + option->name, + CONFIG_INTEGER(option)); break; case CONFIG_OPTION_TYPE_STRING: - string_iconv_fprintf (config_file->file, "%s = \"%s\"\n", - option->name, - (char *)option->value); + rc = 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 (CONFIG_COLOR(option))); + rc = string_iconv_fprintf (config_file->file, "%s = %s\n", + option->name, + gui_color_get_name (CONFIG_COLOR(option))); break; case CONFIG_NUM_OPTION_TYPES: break; @@ -1824,17 +1829,20 @@ config_file_write_option (struct t_config_file *config_file, } else { - string_iconv_fprintf (config_file->file, "%s\n", - option->name); + rc = string_iconv_fprintf (config_file->file, "%s\n", + option->name); } + + return rc; } /* * config_file_write_line: write a line in a configuration file * if value is NULL, then write a section with [ ] around + * return 1 if ok, 0 if error */ -void +int config_file_write_line (struct t_config_file *config_file, const char *option_name, const char *value, ...) { @@ -1842,7 +1850,7 @@ config_file_write_line (struct t_config_file *config_file, va_list argptr; if (!config_file || !option_name) - return; + return 0; if (value && value[0]) { @@ -1852,14 +1860,13 @@ config_file_write_line (struct t_config_file *config_file, if (buf[0]) { - string_iconv_fprintf (config_file->file, "%s = %s\n", - option_name, buf); - return; + return (string_iconv_fprintf (config_file->file, "%s = %s\n", + option_name, buf)); } } - string_iconv_fprintf (config_file->file, "\n[%s]\n", - option_name); + return (string_iconv_fprintf (config_file->file, "\n[%s]\n", + option_name)); } /* @@ -1904,6 +1911,10 @@ config_file_write_internal (struct t_config_file *config_file, } snprintf (filename2, filename_length + 32, "%s.weechattmp", filename); + log_printf (_("Writing configuration file %s %s"), + config_file->filename, + (default_options) ? _("(default options)") : ""); + /* open temp file in write mode */ config_file->file = fopen (filename2, "w"); if (!config_file->file) @@ -1912,20 +1923,16 @@ config_file_write_internal (struct t_config_file *config_file, _("%sError: cannot create file \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], filename2); - free (filename); - free (filename2); - return WEECHAT_CONFIG_WRITE_ERROR; + goto error; } - log_printf (_("Writing configuration file %s %s"), - config_file->filename, - (default_options) ? _("(default options)") : ""); - /* write header with version and date */ - string_iconv_fprintf (config_file->file, "#\n"); - string_iconv_fprintf (config_file->file, - "# %s -- %s v%s\n#\n", - config_file->filename, PACKAGE_NAME, PACKAGE_VERSION); + if (!string_iconv_fprintf (config_file->file, "#\n")) + goto error; + if (!string_iconv_fprintf (config_file->file, + "# %s -- %s v%s\n#\n", + config_file->filename, PACKAGE_NAME, PACKAGE_VERSION)) + goto error; /* write all sections */ for (ptr_section = config_file->sections; ptr_section; @@ -1934,39 +1941,46 @@ config_file_write_internal (struct t_config_file *config_file, /* call write callback if defined for section */ if (default_options && ptr_section->callback_write_default) { - (void) (ptr_section->callback_write_default) (ptr_section->callback_write_default_data, - config_file, - ptr_section->name); + if ((ptr_section->callback_write_default) (ptr_section->callback_write_default_data, + config_file, + ptr_section->name) != WEECHAT_CONFIG_WRITE_OK) + goto error; } else if (!default_options && ptr_section->callback_write) { - (void) (ptr_section->callback_write) (ptr_section->callback_write_data, - config_file, - ptr_section->name); + if ((ptr_section->callback_write) (ptr_section->callback_write_data, + config_file, + ptr_section->name) != WEECHAT_CONFIG_WRITE_OK) + goto error; } else { /* write all options for section */ - string_iconv_fprintf (config_file->file, - "\n[%s]\n", ptr_section->name); + if (!string_iconv_fprintf (config_file->file, + "\n[%s]\n", ptr_section->name)) + goto error; for (ptr_option = ptr_section->options; ptr_option; ptr_option = ptr_option->next_option) { - config_file_write_option (config_file, ptr_option); + if (!config_file_write_option (config_file, ptr_option)) + goto error; } } } - + + if (fflush (config_file->file) != 0) + goto error; + /* close temp file */ fclose (config_file->file); config_file->file = NULL; - + /* update file mode */ chmod (filename2, 0600); - + /* remove target file */ unlink (filename); - + /* rename temp file to target file */ rc = rename (filename2, filename); @@ -1977,6 +1991,23 @@ config_file_write_internal (struct t_config_file *config_file, return WEECHAT_CONFIG_WRITE_ERROR; return WEECHAT_CONFIG_WRITE_OK; + +error: + gui_chat_printf (NULL, + _("%sError writing configuration file \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + filename); + log_printf (_("%sError writing configuration file \"%s\""), + "", config_file->filename); + if (config_file->file) + { + fclose (config_file->file); + config_file->file = NULL; + } + unlink (filename2); + free (filename); + free (filename2); + return WEECHAT_CONFIG_WRITE_ERROR; } /* diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h index ff0326219..75bfcb98a 100644 --- a/src/core/wee-config-file.h +++ b/src/core/wee-config-file.h @@ -70,12 +70,12 @@ struct t_config_section const char *option_name, const char *value); void *callback_read_data; /* data sent to read callback */ - void (*callback_write) /* called to write options */ + int (*callback_write) /* called to write options */ (void *data, /* in config file (only for some */ struct t_config_file *config_file, /* special sections) */ const char *section_name); void *callback_write_data; /* data sent to write callback */ - void (*callback_write_default) /* called to write default */ + int (*callback_write_default) /* called to write default */ (void *data, /* options in config file */ struct t_config_file *config_file, const char *section_name); @@ -158,13 +158,13 @@ extern struct t_config_section *config_file_new_section (struct t_config_file *c const char *option_name, const char *value), void *callback_read_data, - void (*callback_write)(void *data, - struct t_config_file *config_file, - const char *section_name), + int (*callback_write)(void *data, + struct t_config_file *config_file, + const char *section_name), void *callback_write_data, - void (*callback_write_default)(void *data, - struct t_config_file *config_file, - const char *section_name), + int (*callback_write_default)(void *data, + struct t_config_file *config_file, + const char *section_name), void *callback_write_default_data, int (*callback_create_option)(void *data, struct t_config_file *config_file, @@ -234,10 +234,10 @@ 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_option (struct t_config_file *config_file, + struct t_config_option *option); +extern int 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); extern int config_file_read (struct t_config_file *config_file); extern int config_file_reload (struct t_config_file *config_file); diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 1b43c62cf..e7006f996 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -807,33 +807,44 @@ config_weechat_layout_read_cb (void *data, struct t_config_file *config_file, * config_weechat_layout_write: write windows layout in configuration file */ -void +int config_weechat_layout_write_tree (struct t_config_file *config_file, struct t_gui_layout_window *layout_window) { - config_file_write_line (config_file, "window", "\"%d;%d;%d;%d;%s;%s\"", - layout_window->internal_id, - (layout_window->parent_node) ? - layout_window->parent_node->internal_id : 0, - layout_window->split_pct, - layout_window->split_horiz, - (layout_window->plugin_name) ? - layout_window->plugin_name : "-", - (layout_window->buffer_name) ? - layout_window->buffer_name : "-"); + if (!config_file_write_line (config_file, "window", "\"%d;%d;%d;%d;%s;%s\"", + layout_window->internal_id, + (layout_window->parent_node) ? + layout_window->parent_node->internal_id : 0, + layout_window->split_pct, + layout_window->split_horiz, + (layout_window->plugin_name) ? + layout_window->plugin_name : "-", + (layout_window->buffer_name) ? + layout_window->buffer_name : "-")) + return WEECHAT_CONFIG_WRITE_ERROR; if (layout_window->child1) - config_weechat_layout_write_tree (config_file, layout_window->child1); + { + if (config_weechat_layout_write_tree (config_file, + layout_window->child1) != WEECHAT_CONFIG_WRITE_OK) + return WEECHAT_CONFIG_WRITE_ERROR; + } if (layout_window->child2) - config_weechat_layout_write_tree (config_file, layout_window->child2); + { + if (config_weechat_layout_write_tree (config_file, + layout_window->child2) != WEECHAT_CONFIG_WRITE_OK) + return WEECHAT_CONFIG_WRITE_ERROR; + } + + return WEECHAT_CONFIG_WRITE_OK; } /* * config_weechat_layout_write_cb: write layout section in configuration file */ -void +int config_weechat_layout_write_cb (void *data, struct t_config_file *config_file, const char *section_name) { @@ -842,19 +853,27 @@ config_weechat_layout_write_cb (void *data, struct t_config_file *config_file, /* make C compiler happy */ (void) data; - config_file_write_line (config_file, section_name, NULL); + if (!config_file_write_line (config_file, section_name, NULL)) + return WEECHAT_CONFIG_WRITE_ERROR; for (ptr_layout_buffer = gui_layout_buffers; ptr_layout_buffer; ptr_layout_buffer = ptr_layout_buffer->next_layout) { - config_file_write_line (config_file, "buffer", "\"%s;%s;%d\"", - ptr_layout_buffer->plugin_name, - ptr_layout_buffer->buffer_name, - ptr_layout_buffer->number); + if (!config_file_write_line (config_file, "buffer", "\"%s;%s;%d\"", + ptr_layout_buffer->plugin_name, + ptr_layout_buffer->buffer_name, + ptr_layout_buffer->number)) + return WEECHAT_CONFIG_WRITE_ERROR; } if (gui_layout_windows) - config_weechat_layout_write_tree (config_file, gui_layout_windows); + { + if (config_weechat_layout_write_tree (config_file, + gui_layout_windows) != WEECHAT_CONFIG_WRITE_OK) + return WEECHAT_CONFIG_WRITE_ERROR; + } + + return WEECHAT_CONFIG_WRITE_OK; } /* @@ -1042,7 +1061,7 @@ config_weechat_filter_read_cb (void *data, * config_weechat_filter_write_cb: write filter section in configuration file */ -void +int config_weechat_filter_write_cb (void *data, struct t_config_file *config_file, const char *section_name) { @@ -1051,21 +1070,25 @@ config_weechat_filter_write_cb (void *data, struct t_config_file *config_file, /* make C compiler happy */ (void) data; - config_file_write_line (config_file, section_name, NULL); + if (!config_file_write_line (config_file, section_name, NULL)) + return WEECHAT_CONFIG_WRITE_ERROR; for (ptr_filter = gui_filters; ptr_filter; ptr_filter = ptr_filter->next_filter) { - config_file_write_line (config_file, - ptr_filter->name, - "%s;%s%s%s;%s;%s", - (ptr_filter->enabled) ? "on" : "off", - (ptr_filter->plugin_name) ? ptr_filter->plugin_name : "", - (ptr_filter->plugin_name) ? "." : "", - ptr_filter->buffer_name, - ptr_filter->tags, - ptr_filter->regex); + if (!config_file_write_line (config_file, + ptr_filter->name, + "%s;%s%s%s;%s;%s", + (ptr_filter->enabled) ? "on" : "off", + (ptr_filter->plugin_name) ? ptr_filter->plugin_name : "", + (ptr_filter->plugin_name) ? "." : "", + ptr_filter->buffer_name, + ptr_filter->tags, + ptr_filter->regex)) + return WEECHAT_CONFIG_WRITE_ERROR; } + + return WEECHAT_CONFIG_WRITE_OK; } /* @@ -1103,31 +1126,37 @@ config_weechat_key_read_cb (void *data, struct t_config_file *config_file, * config_weechat_key_write_cb: write key section in configuration file */ -void +int 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; + int rc; /* make C compiler happy */ (void) data; - config_file_write_line (config_file, section_name, NULL); + if (!config_file_write_line (config_file, section_name, NULL)) + return WEECHAT_CONFIG_WRITE_ERROR; for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key) { expanded_name = gui_keyboard_get_expanded_name (ptr_key->key); if (expanded_name) { - config_file_write_line (config_file, - (expanded_name) ? - expanded_name : ptr_key->key, - "\"%s\"", - ptr_key->command); + rc = config_file_write_line (config_file, + (expanded_name) ? + expanded_name : ptr_key->key, + "\"%s\"", + ptr_key->command); free (expanded_name); + if (!rc) + return WEECHAT_CONFIG_WRITE_ERROR; } } + + return WEECHAT_CONFIG_WRITE_OK; } /* diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 8747d9ee5..b213e2d6a 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -1217,28 +1217,34 @@ string_iconv_from_internal (const char *charset, const char *string) /* * string_iconv_fprintf: encode to terminal charset, then call fprintf on a file + * return 1 if ok, 0 if error */ -void +int string_iconv_fprintf (FILE *file, const char *data, ...) { va_list argptr; char *buf, *buf2; - + int rc, num_written; + buf = malloc (128 * 1024); if (!buf) - return; + return 0; va_start (argptr, data); vsnprintf (buf, 128 * 1024, data, argptr); va_end (argptr); buf2 = string_iconv_from_internal (NULL, buf); - fprintf (file, "%s", (buf2) ? buf2 : buf); + num_written = fprintf (file, "%s", (buf2) ? buf2 : buf); + + rc = (num_written == (int)strlen ((buf2) ? buf2 : buf)) ? 1 : 0; free (buf); if (buf2) free (buf2); + + return rc; } /* diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 477d86e4c..19b0d0bb0 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -54,7 +54,7 @@ extern char *string_iconv (int from_utf8, const char *from_code, extern char *string_iconv_to_internal (const char *charset, const char *string); extern char *string_iconv_from_internal (const char *charset, const char *string); -extern void string_iconv_fprintf (FILE *file, const char *data, ...); +extern int string_iconv_fprintf (FILE *file, const char *data, ...); extern char *string_format_size (unsigned long size); extern void string_encode_base64 (const char *from, int length, char *to); extern int string_decode_base64 (const char *from, char *to); diff --git a/src/plugins/alias/alias-config.c b/src/plugins/alias/alias-config.c index 4657a7d1c..75719c5c7 100644 --- a/src/plugins/alias/alias-config.c +++ b/src/plugins/alias/alias-config.c @@ -144,7 +144,7 @@ alias_config_reload (void *data, struct t_config_file *config_file) * file in section "cmd" (command) */ -void +int alias_config_cmd_write_default_cb (void *data, struct t_config_file *config_file, const char *section_name) @@ -152,38 +152,71 @@ alias_config_cmd_write_default_cb (void *data, /* make C compiler happy */ (void) data; - weechat_config_write_line (config_file, section_name, NULL); + if (!weechat_config_write_line (config_file, section_name, NULL)) + return WEECHAT_CONFIG_WRITE_ERROR; + + if (!weechat_config_write_line (config_file, "AAWAY", "%s", "\"allserv /away\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "AME", "%s", "\"allchan /me\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "AMSG", "%s", "\"allchan /msg *\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "ANICK", "%s", "\"allserv /nick\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "BYE", "%s", "\"quit\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "C", "%s", "\"buffer clear\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "CL", "%s", "\"buffer clear\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "CLOSE", "%s", "\"buffer close\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "CHAT", "%s", "\"dcc chat\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "EXIT", "%s", "\"quit\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "IG", "%s", "\"ignore\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "J", "%s", "\"join\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "K", "%s", "\"kick\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "KB", "%s", "\"kickban\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "LEAVE", "%s", "\"part\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "M", "%s", "\"msg\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "MUB", "%s", "\"unban *\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "N", "%s", "\"names\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "Q", "%s", "\"query\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "REDRAW", "%s", "\"window refresh\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "SAY", "%s", "\"msg *\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "SIGNOFF", "%s", "\"quit\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "T", "%s", "\"topic\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "UB", "%s", "\"unban\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "V", "%s", "\"command core version\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "W", "%s", "\"who\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "WC", "%s", "\"window merge\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "WI", "%s", "\"whois\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "WII", "%s", "\"whois $1 $1\"")) + return WEECHAT_CONFIG_WRITE_ERROR; + if (!weechat_config_write_line (config_file, "WW", "%s", "\"whowas\"")) + return WEECHAT_CONFIG_WRITE_ERROR; - weechat_config_write_line (config_file, "AAWAY", "%s", "\"allserv /away\""); - weechat_config_write_line (config_file, "AME", "%s", "\"allchan /me\""); - weechat_config_write_line (config_file, "AMSG", "%s", "\"allchan /msg *\""); - weechat_config_write_line (config_file, "ANICK", "%s", "\"allserv /nick\""); - weechat_config_write_line (config_file, "BYE", "%s", "\"quit\""); - weechat_config_write_line (config_file, "C", "%s", "\"buffer clear\""); - weechat_config_write_line (config_file, "CL", "%s", "\"buffer clear\""); - weechat_config_write_line (config_file, "CLOSE", "%s", "\"buffer close\""); - weechat_config_write_line (config_file, "CHAT", "%s", "\"dcc chat\""); - weechat_config_write_line (config_file, "EXIT", "%s", "\"quit\""); - weechat_config_write_line (config_file, "IG", "%s", "\"ignore\""); - weechat_config_write_line (config_file, "J", "%s", "\"join\""); - weechat_config_write_line (config_file, "K", "%s", "\"kick\""); - weechat_config_write_line (config_file, "KB", "%s", "\"kickban\""); - weechat_config_write_line (config_file, "LEAVE", "%s", "\"part\""); - weechat_config_write_line (config_file, "M", "%s", "\"msg\""); - weechat_config_write_line (config_file, "MUB", "%s", "\"unban *\""); - weechat_config_write_line (config_file, "N", "%s", "\"names\""); - weechat_config_write_line (config_file, "Q", "%s", "\"query\""); - weechat_config_write_line (config_file, "REDRAW", "%s", "\"window refresh\""); - weechat_config_write_line (config_file, "SAY", "%s", "\"msg *\""); - weechat_config_write_line (config_file, "SIGNOFF", "%s", "\"quit\""); - weechat_config_write_line (config_file, "T", "%s", "\"topic\""); - weechat_config_write_line (config_file, "UB", "%s", "\"unban\""); - weechat_config_write_line (config_file, "V", "%s", "\"command core version\""); - weechat_config_write_line (config_file, "W", "%s", "\"who\""); - weechat_config_write_line (config_file, "WC", "%s", "\"window merge\""); - weechat_config_write_line (config_file, "WI", "%s", "\"whois\""); - weechat_config_write_line (config_file, "WII", "%s", "\"whois $1 $1\""); - weechat_config_write_line (config_file, "WW", "%s", "\"whowas\""); + return WEECHAT_CONFIG_WRITE_OK; } /* diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 5665ec60a..404130a80 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -744,15 +744,15 @@ irc_config_ctcp_create_option (void *data, struct t_config_file *config_file, } /* - * irc_config_ignore_read: read ignore option from configuration file - * return 1 if ok, 0 if error + * irc_config_ignore_read_cb: read ignore option from configuration file + * return 1 if ok, 0 if error */ int -irc_config_ignore_read (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) +irc_config_ignore_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; @@ -783,30 +783,34 @@ irc_config_ignore_read (void *data, } /* - * irc_config_ignore_write: write ignore section in configuration file + * irc_config_ignore_write_cb: write ignore section in configuration file */ -void -irc_config_ignore_write (void *data, struct t_config_file *config_file, - const char *section_name) +int +irc_config_ignore_write_cb (void *data, struct t_config_file *config_file, + const char *section_name) { struct t_irc_ignore *ptr_ignore; /* make C compiler happy */ (void) data; - weechat_config_write_line (config_file, section_name, NULL); + if (!weechat_config_write_line (config_file, section_name, NULL)) + return WEECHAT_CONFIG_WRITE_ERROR; for (ptr_ignore = irc_ignore_list; ptr_ignore; ptr_ignore = ptr_ignore->next_ignore) { - weechat_config_write_line (config_file, - "ignore", - "%s;%s;%s", - (ptr_ignore->server) ? ptr_ignore->server : "*", - (ptr_ignore->channel) ? ptr_ignore->channel : "*", - ptr_ignore->mask); + if (!weechat_config_write_line (config_file, + "ignore", + "%s;%s;%s", + (ptr_ignore->server) ? ptr_ignore->server : "*", + (ptr_ignore->channel) ? ptr_ignore->channel : "*", + ptr_ignore->mask)) + return WEECHAT_CONFIG_WRITE_ERROR; } + + return WEECHAT_CONFIG_WRITE_OK; } /* @@ -814,7 +818,7 @@ irc_config_ignore_write (void *data, struct t_config_file *config_file, * configuration file */ -void +int irc_config_server_write_default_cb (void *data, struct t_config_file *config_file, const char *section_name) @@ -825,7 +829,8 @@ irc_config_server_write_default_cb (void *data, /* make C compiler happy */ (void) data; - weechat_config_write_line (config_file, section_name, NULL); + if (!weechat_config_write_line (config_file, section_name, NULL)) + return WEECHAT_CONFIG_WRITE_ERROR; for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) { @@ -835,17 +840,21 @@ irc_config_server_write_default_cb (void *data, switch (i) { case IRC_SERVER_OPTION_ADDRESSES: - weechat_config_write_line (config_file, - option_name, - "%s", "\"chat.freenode.net/6667\""); + if (!weechat_config_write_line (config_file, + option_name, + "%s", "\"chat.freenode.net/6667\"")) + return WEECHAT_CONFIG_WRITE_ERROR; break; default: - weechat_config_write_line (config_file, - option_name, - WEECHAT_CONFIG_OPTION_NULL); + if (!weechat_config_write_line (config_file, + option_name, + WEECHAT_CONFIG_OPTION_NULL)) + return WEECHAT_CONFIG_WRITE_ERROR; break; } } + + return WEECHAT_CONFIG_WRITE_OK; } /* @@ -1251,7 +1260,7 @@ irc_config_server_read_cb (void *data, struct t_config_file *config_file, * irc_config_server_write_cb: write server section in configuration file */ -void +int irc_config_server_write_cb (void *data, struct t_config_file *config_file, const char *section_name) { @@ -1261,7 +1270,8 @@ irc_config_server_write_cb (void *data, struct t_config_file *config_file, /* make C compiler happy */ (void) data; - weechat_config_write_line (config_file, section_name, NULL); + if (!weechat_config_write_line (config_file, section_name, NULL)) + return WEECHAT_CONFIG_WRITE_ERROR; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) @@ -1270,11 +1280,14 @@ irc_config_server_write_cb (void *data, struct t_config_file *config_file, { for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) { - weechat_config_write_option (config_file, - ptr_server->options[i]); + if (!weechat_config_write_option (config_file, + ptr_server->options[i])) + return WEECHAT_CONFIG_WRITE_ERROR; } } } + + return WEECHAT_CONFIG_WRITE_OK; } /* @@ -1741,9 +1754,9 @@ irc_config_init () /* ignore */ ptr_section = weechat_config_new_section (irc_config_file, "ignore", 0, 0, - &irc_config_ignore_read, NULL, - &irc_config_ignore_write, NULL, - &irc_config_ignore_write, NULL, + &irc_config_ignore_read_cb, NULL, + &irc_config_ignore_write_cb, NULL, + &irc_config_ignore_write_cb, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 3c124282b..1a0de8ee6 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -1345,14 +1345,14 @@ weechat_lua_api_config_read_cb (void *data, * weechat_lua_api_config_section_write_cb: callback for writing section */ -void +int weechat_lua_api_config_section_write_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_script_callback *script_callback; char *lua_argv[4], empty_arg[1] = { '\0' }; - int *rc; + int *rc, ret; script_callback = (struct t_script_callback *)data; @@ -1368,11 +1368,20 @@ weechat_lua_api_config_section_write_cb (void *data, script_callback->function, lua_argv); - if (rc) + if (!rc) + ret = WEECHAT_CONFIG_WRITE_ERROR; + else + { + ret = *rc; free (rc); + } if (lua_argv[1]) free (lua_argv[1]); + + return ret; } + + return WEECHAT_CONFIG_WRITE_ERROR; } /* @@ -1380,14 +1389,14 @@ weechat_lua_api_config_section_write_cb (void *data, * default values for section */ -void +int weechat_lua_api_config_section_write_default_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_script_callback *script_callback; char *lua_argv[4], empty_arg[1] = { '\0' }; - int *rc; + int *rc, ret; script_callback = (struct t_script_callback *)data; @@ -1403,11 +1412,20 @@ weechat_lua_api_config_section_write_default_cb (void *data, script_callback->function, lua_argv); - if (rc) + if (!rc) + ret = WEECHAT_CONFIG_WRITE_ERROR; + else + { + ret = *rc; free (rc); + } if (lua_argv[1]) free (lua_argv[1]); + + return ret; } + + return WEECHAT_CONFIG_WRITE_ERROR; } /* diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index 9d48b32c0..b4e08ad42 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -1119,14 +1119,14 @@ weechat_perl_api_config_section_read_cb (void *data, * weechat_perl_api_config_section_write_cb: callback for writing section */ -void +int weechat_perl_api_config_section_write_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_script_callback *script_callback; char *perl_argv[4], empty_arg[1] = { '\0' }; - int *rc; + int *rc, ret; script_callback = (struct t_script_callback *)data; @@ -1142,11 +1142,20 @@ weechat_perl_api_config_section_write_cb (void *data, script_callback->function, perl_argv); - if (rc) + if (!rc) + ret = WEECHAT_CONFIG_WRITE_ERROR; + else + { + ret = *rc; free (rc); + } if (perl_argv[1]) free (perl_argv[1]); + + return ret; } + + return WEECHAT_CONFIG_WRITE_ERROR; } /* @@ -1154,17 +1163,17 @@ weechat_perl_api_config_section_write_cb (void *data, * default values for section */ -void +int weechat_perl_api_config_section_write_default_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_script_callback *script_callback; char *perl_argv[4], empty_arg[1] = { '\0' }; - int *rc; + int *rc, ret; script_callback = (struct t_script_callback *)data; - + if (script_callback && script_callback->function && script_callback->function[0]) { perl_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; @@ -1176,12 +1185,21 @@ weechat_perl_api_config_section_write_default_cb (void *data, WEECHAT_SCRIPT_EXEC_INT, script_callback->function, perl_argv); - - if (rc) + + if (!rc) + ret = WEECHAT_CONFIG_WRITE_ERROR; + else + { + ret = *rc; free (rc); + } if (perl_argv[1]) free (perl_argv[1]); + + return ret; } + + return WEECHAT_CONFIG_WRITE_ERROR; } /* diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 8c98a99b4..dd7ec0f0a 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -1184,14 +1184,14 @@ weechat_python_api_config_read_cb (void *data, * weechat_python_api_config_section_write_cb: callback for writing section */ -void +int weechat_python_api_config_section_write_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_script_callback *script_callback; char *python_argv[4], empty_arg[1] = { '\0' }; - int *rc; + int *rc, ret; script_callback = (struct t_script_callback *)data; @@ -1207,11 +1207,20 @@ weechat_python_api_config_section_write_cb (void *data, script_callback->function, python_argv); - if (rc) + if (!rc) + ret = WEECHAT_CONFIG_WRITE_ERROR; + else + { + ret = *rc; free (rc); + } if (python_argv[1]) free (python_argv[1]); + + return ret; } + + return WEECHAT_CONFIG_WRITE_ERROR; } /* @@ -1219,14 +1228,14 @@ weechat_python_api_config_section_write_cb (void *data, * default values for section */ -void +int weechat_python_api_config_section_write_default_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_script_callback *script_callback; char *python_argv[4], empty_arg[1] = { '\0' }; - int *rc; + int *rc, ret; script_callback = (struct t_script_callback *)data; @@ -1242,11 +1251,20 @@ weechat_python_api_config_section_write_default_cb (void *data, script_callback->function, python_argv); - if (rc) + if (!rc) + ret = WEECHAT_CONFIG_WRITE_ERROR; + else + { + ret = *rc; free (rc); + } if (python_argv[1]) free (python_argv[1]); + + return ret; } + + return WEECHAT_CONFIG_WRITE_ERROR; } /* diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index 5ee74aa54..0fd26943c 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -1353,14 +1353,14 @@ weechat_ruby_api_config_read_cb (void *data, * weechat_ruby_api_config_section_write_cb: callback for writing section */ -void +int weechat_ruby_api_config_section_write_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_script_callback *script_callback; char *ruby_argv[4], empty_arg[1] = { '\0' }; - int *rc; + int *rc, ret; script_callback = (struct t_script_callback *)data; @@ -1376,11 +1376,20 @@ weechat_ruby_api_config_section_write_cb (void *data, script_callback->function, ruby_argv); - if (rc) + if (!rc) + ret = WEECHAT_CONFIG_WRITE_ERROR; + else + { + ret = *rc; free (rc); + } if (ruby_argv[1]) free (ruby_argv[1]); + + return ret; } + + return WEECHAT_CONFIG_WRITE_ERROR; } /* @@ -1388,17 +1397,17 @@ weechat_ruby_api_config_section_write_cb (void *data, * default values for section */ -void +int weechat_ruby_api_config_section_write_default_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_script_callback *script_callback; char *ruby_argv[4], empty_arg[1] = { '\0' }; - int *rc; + int *rc, ret; script_callback = (struct t_script_callback *)data; - + if (script_callback && script_callback->function && script_callback->function[0]) { ruby_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; @@ -1411,11 +1420,20 @@ weechat_ruby_api_config_section_write_default_cb (void *data, script_callback->function, ruby_argv); - if (rc) + if (!rc) + ret = WEECHAT_CONFIG_WRITE_ERROR; + else + { + ret = *rc; free (rc); + } if (ruby_argv[1]) free (ruby_argv[1]); + + return ret; } + + return WEECHAT_CONFIG_WRITE_ERROR; } /* diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index 879e5bb97..c5e2ef2a4 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -108,14 +108,14 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin, const char *value), const char *function_read, const char *data_read, - void (*callback_write)(void *data, - struct t_config_file *config_file, - const char *section_name), + int (*callback_write)(void *data, + struct t_config_file *config_file, + const char *section_name), const char *function_write, const char *data_write, - void (*callback_write_default)(void *data, - struct t_config_file *config_file, - const char *section_name), + int (*callback_write_default)(void *data, + struct t_config_file *config_file, + const char *section_name), const char *function_write_default, const char *data_write_default, int (*callback_create_option)(void *data, diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h index 2f99b819e..fab902e2a 100644 --- a/src/plugins/scripts/script-api.h +++ b/src/plugins/scripts/script-api.h @@ -41,12 +41,12 @@ extern struct t_config_section *script_api_config_new_section (struct t_weechat_ const char *value), const char *function_read, const char *data_read, - void (*callback_write)(void *data, + int (*callback_write)(void *data, struct t_config_file *config_file, const char *section_name), const char *function_write, const char *data_write, - void (*callback_write_default)(void *data, + int (*callback_write_default)(void *data, struct t_config_file *config_file, const char *section_name), const char *function_write_default, diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index a9d84a962..8f34c5cb9 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -1352,34 +1352,43 @@ weechat_tcl_api_config_section_read_cb (void *data, * weechat_tcl_api_config_section_write_cb: callback for writing section */ -void +int weechat_tcl_api_config_section_write_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_script_callback *script_callback; char *tcl_argv[4], empty_arg[1] = { '\0' }; - int *rc; + int *rc, ret; script_callback = (struct t_script_callback *)data; - + if (script_callback && script_callback->function && script_callback->function[0]) { tcl_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; tcl_argv[1] = script_ptr2str (config_file); tcl_argv[2] = (section_name) ? (char *)section_name : empty_arg; tcl_argv[3] = NULL; - + rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - tcl_argv); + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + tcl_argv); - if (rc) + if (!rc) + ret = WEECHAT_CONFIG_WRITE_ERROR; + else + { + ret = *rc; free (rc); + } if (tcl_argv[1]) free (tcl_argv[1]); + + return ret; } + + return WEECHAT_CONFIG_WRITE_ERROR; } /* @@ -1387,17 +1396,17 @@ weechat_tcl_api_config_section_write_cb (void *data, * default values for section */ -void +int weechat_tcl_api_config_section_write_default_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_script_callback *script_callback; char *tcl_argv[4], empty_arg[1] = { '\0' }; - int *rc; + int *rc, ret; script_callback = (struct t_script_callback *)data; - + if (script_callback && script_callback->function && script_callback->function[0]) { tcl_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; @@ -1406,15 +1415,24 @@ weechat_tcl_api_config_section_write_default_cb (void *data, tcl_argv[3] = NULL; rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - tcl_argv); + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + tcl_argv); - if (rc) + if (!rc) + ret = WEECHAT_CONFIG_WRITE_ERROR; + else + { + ret = *rc; free (rc); + } if (tcl_argv[1]) free (tcl_argv[1]); + + return ret; } + + return WEECHAT_CONFIG_WRITE_ERROR; } /* @@ -1445,9 +1463,9 @@ weechat_tcl_api_config_section_create_option_cb (void *data, tcl_argv[5] = NULL; rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - tcl_argv); + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + tcl_argv); if (!rc) ret = WEECHAT_CONFIG_OPTION_SET_ERROR; @@ -1493,9 +1511,9 @@ weechat_tcl_api_config_section_delete_option_cb (void *data, tcl_argv[4] = NULL; rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - tcl_argv); + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + tcl_argv); if (!rc) ret = WEECHAT_CONFIG_OPTION_UNSET_ERROR; @@ -1654,9 +1672,9 @@ weechat_tcl_api_config_option_check_value_cb (void *data, tcl_argv[3] = NULL; rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - tcl_argv); + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + tcl_argv); if (!rc) ret = 0; @@ -1695,9 +1713,9 @@ weechat_tcl_api_config_option_change_cb (void *data, tcl_argv[2] = NULL; rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - tcl_argv); + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + tcl_argv); if (tcl_argv[1]) free (tcl_argv[1]); @@ -1728,9 +1746,9 @@ weechat_tcl_api_config_option_delete_cb (void *data, tcl_argv[2] = NULL; rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - tcl_argv); + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + tcl_argv); if (tcl_argv[1]) free (tcl_argv[1]); diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 1600f886d..43e70ff8b 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -248,13 +248,13 @@ struct t_weechat_plugin const char *option_name, const char *value), void *callback_read_data, - void (*callback_write)(void *data, - struct t_config_file *config_file, - const char *section_name), + int (*callback_write)(void *data, + struct t_config_file *config_file, + const char *section_name), void *callback_write_data, - void (*callback_write_default)(void *data, - struct t_config_file *config_file, - const char *section_name), + int (*callback_write_default)(void *data, + struct t_config_file *config_file, + const char *section_name), void *callback_write_default_data, int (*callback_create_option)(void *data, struct t_config_file *config_file, @@ -325,11 +325,11 @@ struct t_weechat_plugin 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, ...); + int (*config_write_option) (struct t_config_file *config_file, + struct t_config_option *option); + int (*config_write_line) (struct t_config_file *config_file, + const char *option_name, + const char *value, ...); int (*config_write) (struct t_config_file *config_file); int (*config_read) (struct t_config_file *config_file); int (*config_reload) (struct t_config_file *config_file); |