talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 4d7a53448434d63c9ea5f369c671de2b35894ed1
parent 1d559b2de3bc4832936f462fb7a34f0252053518
Author: Ricardo Mones <ricardo@mones.org>
Date:   Sat, 15 Nov 2014 12:38:18 +0100

RSSyl: preferences for HTTP auth basic

Diffstat:
Msrc/plugins/rssyl/rssyl.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/plugins/rssyl/rssyl.h | 1+
Msrc/plugins/rssyl/rssyl_feed_props.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/plugins/rssyl/rssyl_feed_props.h | 3+++
4 files changed, 137 insertions(+), 2 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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;