From 08ed4047b275f8ad702fb964a5218e95d66ea821 Mon Sep 17 00:00:00 2001 From: Andrej Kacian Date: Sat, 2 Apr 2016 17:00:43 +0200 Subject: [PATCH] Make RSSyl plugin use the password store. --- src/plugins/rssyl/rssyl.c | 11 ++--------- src/plugins/rssyl/rssyl.h | 6 ++++++ src/plugins/rssyl/rssyl_feed_props.c | 15 +++++++-------- src/plugins/rssyl/rssyl_update_feed.c | 8 ++++++++ 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/plugins/rssyl/rssyl.c b/src/plugins/rssyl/rssyl.c index b60bffe17..22f2260b6 100644 --- a/src/plugins/rssyl/rssyl.c +++ b/src/plugins/rssyl/rssyl.c @@ -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)); diff --git a/src/plugins/rssyl/rssyl.h b/src/plugins/rssyl/rssyl.h index 5b890bd6c..3a9e25dfe 100644 --- a/src/plugins/rssyl/rssyl.h +++ b/src/plugins/rssyl/rssyl.h @@ -4,6 +4,7 @@ #include #include +#include #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 */ diff --git a/src/plugins/rssyl/rssyl_feed_props.c b/src/plugins/rssyl/rssyl_feed_props.c index 1f5e67317..7145e0249 100644 --- a/src/plugins/rssyl/rssyl_feed_props.c +++ b/src/plugins/rssyl/rssyl_feed_props.c @@ -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( diff --git a/src/plugins/rssyl/rssyl_update_feed.c b/src/plugins/rssyl/rssyl_update_feed.c index eef5753fd..1cf651ba4 100644 --- a/src/plugins/rssyl/rssyl_update_feed.c +++ b/src/plugins/rssyl/rssyl_update_feed.c @@ -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"); -- 2.25.1