Make RSSyl plugin use the password store.
authorAndrej Kacian <ticho@claws-mail.org>
Sat, 2 Apr 2016 15:00:43 +0000 (17:00 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Sat, 2 Apr 2016 15:01:44 +0000 (17:01 +0200)
src/plugins/rssyl/rssyl.c
src/plugins/rssyl/rssyl.h
src/plugins/rssyl/rssyl_feed_props.c
src/plugins/rssyl/rssyl_update_feed.c

index b60bffe..22f2260 100644 (file)
@@ -286,12 +286,11 @@ static void rssyl_item_set_xml(Folder *folder, FolderItem *item, XMLTag *tag)
                        g_free(ritem->auth->username);
                        ritem->auth->username = g_strdup(attr->value);
                }
-               /* (str) Auth pass */
+               /* (str) Auth pass - save directly to password store */
                if (!strcmp(attr->name, "auth_pass")) {
                        gsize len = 0;
                        guchar *pwd = g_base64_decode(attr->value, &len);
-                       g_free(ritem->auth->password);
-                       ritem->auth->password = (gchar *)pwd;
+                       rssyl_passwd_set(ritem, (gchar *)pwd);
                }
                /* (str) Official title */
                if( !strcmp(attr->name, "official_title")) {
@@ -346,12 +345,6 @@ static XMLTag *rssyl_item_get_xml(Folder *folder, FolderItem *item)
        /* (str) Auth user */
        if (ri->auth->username != NULL)
                xml_tag_add_attr(tag, xml_attr_new("auth_user", ri->auth->username));
-       /* (str) Auth pass */
-       if (ri->auth->password != NULL) {
-               gchar *pwd = g_base64_encode(ri->auth->password, strlen(ri->auth->password));
-               xml_tag_add_attr(tag, xml_attr_new("auth_pass", pwd));
-               g_free(pwd);
-       }
        /* (str) Official title */
        if( ri->official_title != NULL )
                xml_tag_add_attr(tag, xml_attr_new("official_title", ri->official_title));
index 5b890bd..3a9e25d 100644 (file)
@@ -4,6 +4,7 @@
 #include <glib.h>
 
 #include <folder.h>
+#include <passwordstore.h>
 
 #include "libfeed/feed.h"
 
@@ -99,4 +100,9 @@ FolderItem *rssyl_get_root_folderitem(FolderItem *item);
 #define IS_RSSYL_FOLDER_ITEM(item) \
        (item->folder->klass == rssyl_folder_get_class())
 
+#define rssyl_passwd_set(ritem, pwd) \
+       passwd_store_set(PWS_PLUGIN, PLUGIN_NAME, ritem->url, pwd, FALSE)
+#define rssyl_passwd_get(ritem) \
+       passwd_store_get(PWS_PLUGIN, PLUGIN_NAME, ritem->url)
+
 #endif /* __RSSYL_H */
index 1f5e673..7145e02 100644 (file)
@@ -70,12 +70,7 @@ static void rssyl_gtk_prop_store(RFolderItem *ritem)
        }
 
        auth_pass = (gchar *)gtk_entry_get_text(GTK_ENTRY(ritem->feedprop->auth_password));
-       if (auth_pass != NULL) {
-               if (ritem->auth->password) {
-                       g_free(ritem->auth->password);
-               }
-               ritem->auth->password = g_strdup(auth_pass);
-       }
+       rssyl_passwd_set(ritem, auth_pass);
 
        use_default_ri = gtk_toggle_button_get_active(
                        GTK_TOGGLE_BUTTON(ritem->feedprop->default_refresh_interval));
@@ -282,8 +277,12 @@ void rssyl_gtk_prop(RFolderItem *ritem)
        /* Auth password */
        feedprop->auth_password = gtk_entry_new();
        gtk_entry_set_visibility(GTK_ENTRY(feedprop->auth_password), FALSE);
-       gtk_entry_set_text(GTK_ENTRY(feedprop->auth_password),
-                       ritem->auth->password);
+       gchar *pwd = rssyl_passwd_get(ritem);
+       gtk_entry_set_text(GTK_ENTRY(feedprop->auth_password), pwd);
+       if (pwd != NULL) {
+               memset(pwd, 0, strlen(pwd));
+               g_free(pwd);
+       }
 
        /* "Use default refresh interval" checkbutton */
        feedprop->default_refresh_interval = gtk_check_button_new_with_mnemonic(
index eef5753..1cf651b 100644 (file)
@@ -169,6 +169,9 @@ RFetchCtx *rssyl_prep_fetchctx_from_item(RFolderItem *ritem)
        ctx->success = TRUE;
        ctx->ready = FALSE;
 
+       if (ritem->auth->type != FEED_AUTH_NONE)
+               ritem->auth->password = rssyl_passwd_get(ritem);
+
        feed_set_timeout(ctx->feed, prefs_common_get_prefs()->io_timeout_secs);
        feed_set_cookies_path(ctx->feed, rssyl_prefs_get()->cookies_path);
        feed_set_ssl_verify_peer(ctx->feed, ritem->ssl_verify_peer);
@@ -238,6 +241,11 @@ gboolean rssyl_update_feed(RFolderItem *ritem, gboolean verbose)
        /* Fetch the feed file */
        rssyl_fetch_feed(ctx, verbose);
 
+       if (ritem->auth != NULL && ritem->auth->password != NULL) {
+               memset(ritem->auth->password, 0, strlen(ritem->auth->password));
+               g_free(ritem->auth->password);
+       }
+
        debug_print("RSSyl: fetch done; success == %s\n",
                        ctx->success ? "TRUE" : "FALSE");