Fix a Coverity warning caused by previous commits.
[claws.git] / src / prefs_gtk.c
index 4eb554eac535896e8890d64de5a88a83440e45fa..44b6f4facf1ab24895171741ab7e272fceb07bc7 100644 (file)
@@ -40,7 +40,7 @@
 #include "prefs_common.h"
 #include "utils.h"
 #include "gtkutils.h"
-#include "passcrypt.h"
+#include "password.h"
 #include "codeconv.h"
 
 #define CL(x)  (((gulong) (x) >> (gulong) 8) & 0xFFUL)
@@ -80,7 +80,7 @@ void prefs_read_config(PrefParam *param, const gchar *label,
        cm_return_if_fail(rcfile != NULL);
 
        if (encoding != NULL)
-               g_warning("Encoding is ignored\n");
+               g_warning("Encoding is ignored");
 
        debug_print("Reading configuration...\n");
 
@@ -169,6 +169,7 @@ static void prefs_config_parse_one_line(PrefParam *param, const gchar *buf)
 
                switch (param[i].type) {
                case P_STRING:
+               case P_PASSWORD:
                {
                        gchar *tmp = NULL;
 
@@ -216,23 +217,6 @@ static void prefs_config_parse_one_line(PrefParam *param, const gchar *buf)
                                /* be compatible and accept ints */
                                *((gulong *)param[i].data) = strtoul(value, 0, 10); 
                        break;
-               case P_PASSWORD:
-                       g_free(*((gchar **)param[i].data));
-                       if (value[0] == '!') {
-                               gchar *tmp;
-                               gsize len;
-
-                               tmp = g_base64_decode(&value[1], &len);
-                               passcrypt_decrypt(tmp, len);
-
-                               *((gchar **)param[i].data) =
-                                       *tmp ? g_strdup(tmp) : NULL;
-                               g_free(tmp);
-                       } else {
-                               *((gchar **)param[i].data) =
-                                       *value ? g_strdup(value) : NULL;
-                       }
-                       break;
                default:
                        break;
                }
@@ -242,7 +226,7 @@ static void prefs_config_parse_one_line(PrefParam *param, const gchar *buf)
 #define TRY(func) \
 if (!(func)) \
 { \
-       g_warning("Failed to write configuration to file\n"); \
+       g_warning("Failed to write configuration to file"); \
        if (orig_fp) fclose(orig_fp); \
        prefs_file_close_revert(pfile); \
        g_free(rcpath); \
@@ -270,7 +254,7 @@ void prefs_write_config(PrefParam *param, const gchar *label,
        }
 
        if ((pfile = prefs_write_open(rcpath)) == NULL) {
-               g_warning("Failed to write configuration to file\n");
+               g_warning("Failed to write configuration to file");
                if (orig_fp) fclose(orig_fp);
                g_free(rcpath);
                return;
@@ -326,7 +310,7 @@ void prefs_write_config(PrefParam *param, const gchar *label,
 
        if (orig_fp) fclose(orig_fp);
        if (prefs_file_close(pfile) < 0)
-               g_warning("Failed to write configuration to file\n");
+               g_warning("Failed to write configuration to file");
        g_free(rcpath);
 
        debug_print("Configuration is saved.\n");
@@ -361,6 +345,8 @@ gint prefs_write_param(PrefParam *param, FILE *fp)
                        g_free(tmp);
                        break;
                }
+               case P_PASSWORD:
+                       return 0; /* Passwords are written to password store. */
                case P_INT:
                        g_snprintf(buf, sizeof(buf), "%s=%d\n", param[i].name,
                                   *((gint *)param[i].data));
@@ -381,27 +367,6 @@ gint prefs_write_param(PrefParam *param, FILE *fp)
                        g_snprintf(buf, sizeof buf,  "%s=#%6.6lx\n", param[i].name,
                                   *((gulong *) param[i].data));
                        break;
-               case P_PASSWORD:
-                       {
-                               gchar *tmp = NULL, *tmp2 = NULL;
-
-                               tmp = *((gchar **)param[i].data);
-                               if (tmp) {
-                                       gint len;
-
-                                       tmp = g_strdup(tmp);
-                                       len = strlen(tmp);
-                                       passcrypt_encrypt(tmp, len);
-                                       tmp2 = g_base64_encode(tmp, len);
-                                       g_free(tmp);
-                                       tmp = tmp2;
-                               }
-                               g_snprintf(buf, sizeof(buf), "%s=!%s\n", param[i].name,
-                                          tmp ?
-                                          tmp : "");
-                               g_free(tmp);
-                       }
-                       break;
                default:
                        /* unrecognized, fail */
                        debug_print("Unrecognized parameter type\n");
@@ -662,11 +627,12 @@ void prefs_set_data_from_entry(PrefParam *pparam)
 
        switch (pparam->type) {
        case P_STRING:
-       case P_PASSWORD:
                str = (gchar **)pparam->data;
                g_free(*str);
                *str = entry_str[0] ? g_strdup(entry_str) : NULL;
                break;
+       case P_PASSWORD:
+               break;
        case P_USHORT:
                *((gushort *)pparam->data) = atoi(entry_str);
                break;
@@ -674,7 +640,7 @@ void prefs_set_data_from_entry(PrefParam *pparam)
                *((gint *)pparam->data) = atoi(entry_str);
                break;
        default:
-               g_warning("Invalid PrefType for GtkEntry widget: %d\n",
+               g_warning("Invalid PrefType for GtkEntry widget: %d",
                          pparam->type);
        }
 }
@@ -692,7 +658,7 @@ void prefs_set_escaped_data_from_entry(PrefParam *pparam)
                *str = pref_get_pref_from_entry(GTK_ENTRY(*pparam->widget));
                break;
        default:
-               g_warning("Invalid escaped PrefType for GtkEntry widget: %d\n",
+               g_warning("Invalid escaped PrefType for GtkEntry widget: %d",
                          pparam->type);
        }
 }
@@ -700,12 +666,10 @@ void prefs_set_escaped_data_from_entry(PrefParam *pparam)
 void prefs_set_entry(PrefParam *pparam)
 {
        gchar **str;
-
        cm_return_if_fail(*pparam->widget != NULL);
 
        switch (pparam->type) {
        case P_STRING:
-       case P_PASSWORD:
                str = (gchar **)pparam->data;
                gtk_entry_set_text(GTK_ENTRY(*pparam->widget),
                                   *str ? *str : "");
@@ -719,7 +683,7 @@ void prefs_set_entry(PrefParam *pparam)
                                   itos(*((gushort *)pparam->data)));
                break;
        default:
-               g_warning("Invalid PrefType for GtkEntry widget: %d\n",
+               g_warning("Invalid PrefType for GtkEntry widget: %d",
                          pparam->type);
        }
 }
@@ -737,7 +701,7 @@ void prefs_set_entry_from_escaped(PrefParam *pparam)
                                   *str ? *str : "");
                break;
        default:
-               g_warning("Invalid escaped PrefType for GtkEntry widget: %d\n",
+               g_warning("Invalid escaped PrefType for GtkEntry widget: %d",
                          pparam->type);
        }
 }
@@ -752,7 +716,6 @@ void prefs_set_data_from_text(PrefParam *pparam)
 
        switch (pparam->type) {
        case P_STRING:
-       case P_PASSWORD:
                str = (gchar **)pparam->data;
                g_free(*str);
                if (GTK_IS_EDITABLE(*pparam->widget)) {   /* need? */
@@ -790,7 +753,7 @@ void prefs_set_data_from_text(PrefParam *pparam)
                g_free(text);
                break;
        default:
-               g_warning("Invalid PrefType for GtkText widget: %d\n",
+               g_warning("Invalid PrefType for GtkText widget: %d",
                          pparam->type);
        }
 }
@@ -808,7 +771,7 @@ void prefs_set_escaped_data_from_text(PrefParam *pparam)
                *str = pref_get_pref_from_textview(GTK_TEXT_VIEW(*pparam->widget));
                break;
        default:
-               g_warning("Invalid escaped PrefType for GtkText widget: %d\n",
+               g_warning("Invalid escaped PrefType for GtkText widget: %d",
                          pparam->type);
        }
 }
@@ -825,7 +788,6 @@ void prefs_set_text(PrefParam *pparam)
 
        switch (pparam->type) {
        case P_STRING:
-       case P_PASSWORD:
                str = (gchar **)pparam->data;
                if (*str) {
                        bufp = buf = alloca(strlen(*str) + 1);
@@ -851,7 +813,7 @@ void prefs_set_text(PrefParam *pparam)
                gtk_text_buffer_insert(buffer, &iter, buf, -1);
                break;
        default:
-               g_warning("Invalid PrefType for GtkTextView widget: %d\n",
+               g_warning("Invalid PrefType for GtkTextView widget: %d",
                          pparam->type);
        }
 }
@@ -869,7 +831,7 @@ void prefs_set_text_from_escaped(PrefParam *pparam)
                                 *str ? *str : "");
                break;
        default:
-               g_warning("Invalid escaped PrefType for GtkTextView widget: %d\n",
+               g_warning("Invalid escaped PrefType for GtkTextView widget: %d",
                          pparam->type);
        }
 }
@@ -908,7 +870,7 @@ void prefs_set_data_from_spinbtn(PrefParam *pparam)
                        (GTK_SPIN_BUTTON(*pparam->widget));
                break;
        default:
-               g_warning("Invalid PrefType for GtkSpinButton widget: %d\n",
+               g_warning("Invalid PrefType for GtkSpinButton widget: %d",
                          pparam->type);
        }
 }
@@ -927,7 +889,7 @@ void prefs_set_spinbtn(PrefParam *pparam)
                                          (gfloat)*((gushort *)pparam->data));
                break;
        default:
-               g_warning("Invalid PrefType for GtkSpinButton widget: %d\n",
+               g_warning("Invalid PrefType for GtkSpinButton widget: %d",
                          pparam->type);
        }
 }
@@ -947,7 +909,7 @@ void prefs_gtk_open(void)
 {
        prefswindow_open(_("Preferences"), prefs_pages, NULL,
                        &prefs_common.prefswin_width, &prefs_common.prefswin_height,
-                       NULL, prefs_gtk_window_closed_cb);
+                       NULL, prefs_gtk_window_closed_cb, prefs_gtk_window_closed_cb);
 }
 
 void prefs_gtk_register_page(PrefsPage *page)
@@ -1104,7 +1066,7 @@ static gboolean prefs_read_config_from_cache(PrefParam *param, const gchar *labe
        sections_table = g_hash_table_lookup(whole_cache, rcfile);
        
        if (sections_table == NULL) {
-               g_warning("Can't find %s in the whole cache\n", rcfile?rcfile:"(null)");
+               g_warning("Can't find %s in the whole cache", rcfile?rcfile:"(null)");
                return FALSE;
        }
        values_table = g_hash_table_lookup(sections_table, label);