[Commits] [SCM] claws branch, master, updated. 3.11.1-57-g002986d

mones at claws-mail.org mones at claws-mail.org
Tue Jan 13 19:34:19 CET 2015


The branch, master has been updated
       via  002986de753fc0331f901620e3f09e521ad406ce (commit)
       via  4d7a53448434d63c9ea5f369c671de2b35894ed1 (commit)
       via  1d559b2de3bc4832936f462fb7a34f0252053518 (commit)
      from  d9b0f9d8937451a7f4e1e1041a17eaccf0d044d9 (commit)

Summary of changes:
 src/plugins/rssyl/libfeed/feed.c      |   54 +++++++++++++++++++++++
 src/plugins/rssyl/libfeed/feed.h      |   19 +++++++-
 src/plugins/rssyl/rssyl.c             |   58 +++++++++++++++++++++++++
 src/plugins/rssyl/rssyl.h             |    1 +
 src/plugins/rssyl/rssyl_feed_props.c  |   77 ++++++++++++++++++++++++++++++++-
 src/plugins/rssyl/rssyl_feed_props.h  |    3 ++
 src/plugins/rssyl/rssyl_update_feed.c |    4 ++
 7 files changed, 213 insertions(+), 3 deletions(-)


- Log -----------------------------------------------------------------
commit 002986de753fc0331f901620e3f09e521ad406ce
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sat Nov 15 12:39:18 2014 +0100

    Fix bug# 3098: add auth to context and handle error

diff --git a/src/plugins/rssyl/rssyl_update_feed.c b/src/plugins/rssyl/rssyl_update_feed.c
index 63b0c6f..51d6c97 100644
--- a/src/plugins/rssyl/rssyl_update_feed.c
+++ b/src/plugins/rssyl/rssyl_update_feed.c
@@ -96,6 +96,9 @@ void rssyl_fetch_feed(RFetchCtx *ctx, gboolean verbose)
 	} else if( ctx->response_code == FEED_ERR_FETCH ) {
 		debug_print("RSSyl: libfeed reports some other error from libcurl\n");
 		ctx->error = g_strdup(ctx->feed->fetcherr);
+	} else if( ctx->response_code == FEED_ERR_UNAUTH ) {
+		debug_print("RSSyl: URL authorization type is unknown\n");
+		ctx->error = g_strdup("Unknown value for URL authorization type");
 	} else if( ctx->response_code >= 400 && ctx->response_code < 500 ) {
 		switch( ctx->response_code ) {
 			case 401:
@@ -165,6 +168,7 @@ RFetchCtx *rssyl_prep_fetchctx_from_item(RFolderItem *ritem)
 	feed_set_timeout(ctx->feed, prefs_common.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);
+	feed_set_auth(ctx->feed, ritem->auth);
 
 	return ctx;
 }

commit 4d7a53448434d63c9ea5f369c671de2b35894ed1
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sat Nov 15 12:38:18 2014 +0100

    RSSyl: preferences for HTTP auth basic

diff --git a/src/plugins/rssyl/rssyl.c b/src/plugins/rssyl/rssyl.c
index 0f9ac06..3b2675a 100644
--- a/src/plugins/rssyl/rssyl.c
+++ b/src/plugins/rssyl/rssyl.c
@@ -272,6 +272,22 @@ static void rssyl_item_set_xml(Folder *folder, FolderItem *item, XMLTag *tag)
 			g_free(ritem->url);
 			ritem->url = g_strdup(attr->value);
 		}
+		/* (int) URL auth */
+		if (!strcmp(attr->name, "auth")) {
+			ritem->auth->type = atoi(attr->value);
+		}
+		/* (str) Auth user */
+		if (!strcmp(attr->name, "auth_user")) {
+			g_free(ritem->auth->username);
+			ritem->auth->username = g_strdup(attr->value);
+		}
+		/* (str) Auth pass */
+		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;
+		}
 		/* (str) Official title */
 		if( !strcmp(attr->name, "official_title")) {
 			g_free(ritem->official_title);
@@ -318,6 +334,19 @@ static XMLTag *rssyl_item_get_xml(Folder *folder, FolderItem *item)
 	/* (str) URL */
 	if( ri->url != NULL )
 		xml_tag_add_attr(tag, xml_attr_new("uri", ri->url));
+	/* (int) Auth */
+	tmp = g_strdup_printf("%d", ri->auth->type);
+	xml_tag_add_attr(tag, xml_attr_new("auth", tmp));
+	g_free(tmp);
+	/* (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));
@@ -396,6 +425,10 @@ static FolderItem *rssyl_item_new(Folder *folder)
 	RFolderItem *ritem = g_new0(RFolderItem, 1);
 
 	ritem->url = NULL;
+	ritem->auth = g_new0(FeedAuth, 1);
+	ritem->auth->type = FEED_AUTH_NONE;
+	ritem->auth->username = NULL;
+	ritem->auth->password = NULL;
 	ritem->official_title = NULL;
 	ritem->source_id = NULL;
 	ritem->items = NULL;
@@ -420,6 +453,11 @@ static void rssyl_item_destroy(Folder *folder, FolderItem *item)
 	g_return_if_fail(ritem != NULL);
 
 	g_free(ritem->url);
+	if (ritem->auth->username)
+		g_free(ritem->auth->username);
+	if (ritem->auth->password)
+		g_free(ritem->auth->password);
+	g_free(ritem->auth);
 	g_free(ritem->official_title);
 	g_slist_free(ritem->items);
 
@@ -842,6 +880,26 @@ static void rssyl_copy_private_data(Folder *folder, FolderItem *oldi,
 		newitem->url = g_strdup(olditem->url);
 	}
 
+	if (olditem->auth != NULL) {
+		if (newitem->auth != NULL) {
+			if (newitem->auth->username != NULL) {
+				g_free(newitem->auth->username);
+				newitem->auth->username = NULL;
+			}
+			if (newitem->auth->password != NULL) {
+				g_free(newitem->auth->password);
+				newitem->auth->password = NULL;
+			}
+			g_free(newitem->auth);
+		}
+		newitem->auth = g_new0(FeedAuth, 1);
+		newitem->auth->type = olditem->auth->type;
+		if (olditem->auth->username != NULL)
+			newitem->auth->username = g_strdup(olditem->auth->username);
+		if (olditem->auth->password != NULL)
+			newitem->auth->password = g_strdup(olditem->auth->password);
+	}
+
 	if (olditem->official_title != NULL) {
 		g_free(newitem->official_title);
 		newitem->official_title = g_strdup(olditem->official_title);
diff --git a/src/plugins/rssyl/rssyl.h b/src/plugins/rssyl/rssyl.h
index 7b1b169..6ded099 100644
--- a/src/plugins/rssyl/rssyl.h
+++ b/src/plugins/rssyl/rssyl.h
@@ -25,6 +25,7 @@
 struct _RFolderItem {
 	FolderItem item;
 	gchar *url;
+	FeedAuth *auth;
 	gchar *official_title;
 	gchar *source_id;
 
diff --git a/src/plugins/rssyl/rssyl_feed_props.c b/src/plugins/rssyl/rssyl_feed_props.c
index e7edcf6..b702a03 100644
--- a/src/plugins/rssyl/rssyl_feed_props.c
+++ b/src/plugins/rssyl/rssyl_feed_props.c
@@ -41,7 +41,7 @@
 
 static void rssyl_gtk_prop_store(RFolderItem *ritem)
 {
-	gchar *url;
+	gchar *url, *auth_user, *auth_pass;
 	gint x, old_ri, old_fetch_comments;
 	gboolean use_default_ri = FALSE, keep_old = FALSE;
 	FolderItem *item;
@@ -58,6 +58,24 @@ static void rssyl_gtk_prop_store(RFolderItem *ritem)
 		ritem->url = g_strdup(url);
 	}
 
+	ritem->auth->type = gtk_combo_box_get_active(GTK_COMBO_BOX(ritem->feedprop->auth_type));
+
+	auth_user = (gchar *)gtk_entry_get_text(GTK_ENTRY(ritem->feedprop->auth_username));
+	if (auth_user != NULL) {
+		if (ritem->auth->username) {
+			g_free(ritem->auth->username);
+		}
+		ritem->auth->username = g_strdup(auth_user);
+	}
+
+	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);
+	}
+
 	use_default_ri = gtk_toggle_button_get_active(
 			GTK_TOGGLE_BUTTON(ritem->feedprop->default_refresh_interval));
 	ritem->default_refresh_interval = use_default_ri;
@@ -140,6 +158,14 @@ rssyl_feedprop_togglebutton_toggled_cb(GtkToggleButton *tb,
 	return FALSE;
 }
 
+static void
+rssyl_feedprop_auth_type_changed_cb(GtkComboBox *cb, gpointer data)
+{
+	RFeedProp *feedprop = (RFeedProp *)data;
+	gboolean enable = (FEED_AUTH_NONE != gtk_combo_box_get_active(cb));
+	gtk_widget_set_sensitive(GTK_WIDGET(feedprop->auth_username), enable);
+	gtk_widget_set_sensitive(GTK_WIDGET(feedprop->auth_password), enable);
+}
 
 static gboolean
 rssyl_props_cancel_cb(GtkWidget *widget, gpointer data)
@@ -210,6 +236,7 @@ void rssyl_gtk_prop(RFolderItem *ritem)
 	MainWindow *mainwin = mainwindow_get_mainwindow();
 	RFeedProp *feedprop;
 	GtkWidget *vbox, *urllabel, *urlframe, *urlalign, *table, *label,
+		*inner_vbox, *auth_hbox, *auth_user_label, *auth_pass_label,
 						*hsep, *sep, *bbox, *cancel_button, *cancel_align,
 						*cancel_hbox, *cancel_image, *cancel_label, *ok_button, *ok_align,
 						*ok_hbox, *ok_image, *ok_label, *trim_button, *silent_update_label;
@@ -238,6 +265,35 @@ void rssyl_gtk_prop(RFolderItem *ritem)
 	feedprop->url = gtk_entry_new();
 	gtk_entry_set_text(GTK_ENTRY(feedprop->url), ritem->url);
 
+	/* URL auth type combo */
+#if !GTK_CHECK_VERSION(2, 24, 0)
+	feedprop->auth_type = gtk_combo_box_new_text();
+	gtk_combo_box_append_text(GTK_COMBO_BOX(feedprop->auth_type),
+#else
+	feedprop->auth_type = gtk_combo_box_text_new();
+	gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(feedprop->auth_type),
+#endif
+			_("No authentication"));
+#if !GTK_CHECK_VERSION(2, 24, 0)
+	gtk_combo_box_append_text(GTK_COMBO_BOX(feedprop->auth_type),
+#else
+	gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(feedprop->auth_type),
+#endif
+			_("HTTP Basic authentication"));
+	gtk_combo_box_set_active(GTK_COMBO_BOX(feedprop->auth_type),
+			ritem->auth->type);
+
+	/* Auth username */
+	feedprop->auth_username = gtk_entry_new();
+	gtk_entry_set_text(GTK_ENTRY(feedprop->auth_username),
+			ritem->auth->username);
+
+	/* 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);
+
 	/* "Use default refresh interval" checkbutton */
 	feedprop->default_refresh_interval = gtk_check_button_new_with_mnemonic(
 			_("Use default refresh interval"));
@@ -357,8 +413,25 @@ void rssyl_gtk_prop(RFolderItem *ritem)
 	gtk_alignment_set_padding(GTK_ALIGNMENT(urlalign), 5, 5, 5, 5);
 	gtk_container_add(GTK_CONTAINER(urlframe), urlalign);
 
+	inner_vbox = gtk_vbox_new(FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(inner_vbox), feedprop->url, FALSE, FALSE, 0);
 	gtk_entry_set_activates_default(GTK_ENTRY(feedprop->url), TRUE);
-	gtk_container_add(GTK_CONTAINER(urlalign), feedprop->url);
+	gtk_container_add(GTK_CONTAINER(urlalign), inner_vbox);
+
+	/* Auth combo + user (label + entry) + pass (label + entry) */
+	auth_hbox = gtk_hbox_new(FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(auth_hbox), feedprop->auth_type, FALSE, FALSE, 0);
+	g_signal_connect(G_OBJECT(feedprop->auth_type), "changed",
+			G_CALLBACK(rssyl_feedprop_auth_type_changed_cb),
+			(gpointer) feedprop);
+	g_signal_emit_by_name(G_OBJECT(feedprop->auth_type), "changed");
+	auth_user_label = gtk_label_new(_("User name"));
+	gtk_box_pack_start(GTK_BOX(auth_hbox), auth_user_label, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(auth_hbox), feedprop->auth_username, FALSE, FALSE, 0);
+	auth_pass_label = gtk_label_new(_("Password"));
+	gtk_box_pack_start(GTK_BOX(auth_hbox), auth_pass_label, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(auth_hbox), feedprop->auth_password, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(inner_vbox), auth_hbox, FALSE, FALSE, 0);
 
 	/* Table for remaining properties */
 	table = gtk_table_new(11, 2, FALSE);
diff --git a/src/plugins/rssyl/rssyl_feed_props.h b/src/plugins/rssyl/rssyl_feed_props.h
index 5aa4539..d1e088b 100644
--- a/src/plugins/rssyl/rssyl_feed_props.h
+++ b/src/plugins/rssyl/rssyl_feed_props.h
@@ -17,6 +17,9 @@ struct _RFeedProp {
 	GtkWidget *write_heading;
 	GtkWidget *ignore_title_rename;
 	GtkWidget *ssl_verify_peer;
+	GtkWidget *auth_type;
+	GtkWidget *auth_username;
+	GtkWidget *auth_password;
 };
 
 typedef struct _RFeedProp RFeedProp;

commit 1d559b2de3bc4832936f462fb7a34f0252053518
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sat Nov 15 12:30:14 2014 +0100

    RSSyl: support HTTP basic auth in libfeed

diff --git a/src/plugins/rssyl/libfeed/feed.c b/src/plugins/rssyl/libfeed/feed.c
index ca048eb..cd50704 100644
--- a/src/plugins/rssyl/libfeed/feed.c
+++ b/src/plugins/rssyl/libfeed/feed.c
@@ -40,6 +40,7 @@ Feed *feed_new(gchar *url)
 
 	feed->timeout = FEED_DEFAULT_TIMEOUT;
 	feed->url = g_strdup(url);
+	feed->auth = NULL;
 	feed->title = NULL;
 	feed->description = NULL;
 	feed->language = NULL;
@@ -59,12 +60,28 @@ static void _free_items(gpointer item, gpointer nada)
 	feed_item_free(item);
 }
 
+static void _free_auth(Feed *feed)
+{
+	if (feed == NULL)
+		return;
+
+	if (feed->auth != NULL) {
+                if (feed->auth->username != NULL)
+                        g_free(feed->auth->username);
+                if (feed->auth->password != NULL)
+                        g_free(feed->auth->password);
+                g_free(feed->auth);
+		feed->auth = NULL;
+        }
+}
+
 void feed_free(Feed *feed)
 {
 	if( feed == NULL )
 		return;	/* Return silently, without printing a glib error. */
 
 	g_free(feed->url);
+	_free_auth(feed);
 	g_free(feed->title);
 	g_free(feed->description);
 	g_free(feed->language);
@@ -128,6 +145,25 @@ gchar *feed_get_url(Feed *feed)
 	return feed->url;
 }
 
+/* Auth */
+void feed_set_auth(Feed *feed, FeedAuth *auth)
+{
+	g_return_if_fail(feed != NULL);
+	g_return_if_fail(auth != NULL);
+
+	_free_auth(feed);
+	feed->auth = g_new0(FeedAuth, 1);
+	feed->auth->type = auth->type;
+	feed->auth->username = g_strdup(auth->username);
+	feed->auth->password = g_strdup(auth->password);
+}
+
+FeedAuth *feed_get_auth(Feed *feed)
+{
+	g_return_val_if_fail(feed != NULL, NULL);
+	return feed->auth;
+}
+
 /* Title */
 gchar *feed_get_title(Feed *feed)
 {
@@ -272,6 +308,23 @@ guint feed_update(Feed *feed, time_t last_update)
 	if(feed->cookies_path != NULL)
 		curl_easy_setopt(eh, CURLOPT_COOKIEFILE, feed->cookies_path);
 
+	if (feed->auth != NULL) {
+		switch (feed->auth->type) {
+		case FEED_AUTH_NONE:
+			break;
+		case FEED_AUTH_BASIC:
+			curl_easy_setopt(eh, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
+			curl_easy_setopt(eh, CURLOPT_USERNAME,
+					 feed->auth->username);
+			curl_easy_setopt(eh, CURLOPT_PASSWORD,
+					 feed->auth->password);
+			break;
+		default:
+			response_code = FEED_ERR_UNAUTH; /* unknown auth */
+			goto cleanup;
+		}
+	}
+
 	res = curl_easy_perform(eh);
 	XML_Parse(feed_ctx->parser, "", 0, TRUE);
 
@@ -281,6 +334,7 @@ guint feed_update(Feed *feed, time_t last_update)
 	} else
 		curl_easy_getinfo(eh, CURLINFO_RESPONSE_CODE, &response_code);
 
+cleanup:
 	curl_easy_cleanup(eh);
 
 	/* Cleanup, we should be done. */
diff --git a/src/plugins/rssyl/libfeed/feed.h b/src/plugins/rssyl/libfeed/feed.h
index af9fc3b..5abde34 100644
--- a/src/plugins/rssyl/libfeed/feed.h
+++ b/src/plugins/rssyl/libfeed/feed.h
@@ -30,9 +30,22 @@
 typedef struct _Feed Feed;
 typedef struct _FeedItem FeedItem;
 typedef struct _FeedParserCtx FeedParserCtx;
+typedef struct _FeedAuth FeedAuth;
+
+typedef enum {
+	FEED_AUTH_NONE,
+	FEED_AUTH_BASIC
+} FeedAuthType;
+
+struct _FeedAuth {
+	FeedAuthType type;
+	gchar *username;
+	gchar *password;
+};
 	
 struct _Feed {
 	gchar *url;
+	FeedAuth *auth;
 	gchar *title;
 	gchar *description;
 	gchar *language;
@@ -66,7 +79,8 @@ typedef enum {
 	FEED_ERR_NOFEED,
 	FEED_ERR_NOURL,
 	FEED_ERR_INIT,
-	FEED_ERR_FETCH
+	FEED_ERR_FETCH,
+	FEED_ERR_UNAUTH
 } FeedErrCodes;
 
 /* ---------------- Prototypes */
@@ -82,6 +96,9 @@ guint feed_get_timeout(Feed *feed);
 void feed_set_url(Feed *feed, gchar *url);
 gchar *feed_get_url(Feed *feed);
 
+void feed_set_auth(Feed *feed, FeedAuth *auth);
+FeedAuth *feed_get_auth(Feed *feed);
+
 gchar *feed_get_title(Feed *feed);
 void feed_set_title(Feed *feed, gchar *new_title);
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list