RSSyl: preferences for HTTP auth basic
authorRicardo Mones <ricardo@mones.org>
Sat, 15 Nov 2014 11:38:18 +0000 (12:38 +0100)
committerRicardo Mones <ricardo@mones.org>
Tue, 13 Jan 2015 18:33:47 +0000 (19:33 +0100)
src/plugins/rssyl/rssyl.c
src/plugins/rssyl/rssyl.h
src/plugins/rssyl/rssyl_feed_props.c
src/plugins/rssyl/rssyl_feed_props.h

index 0f9ac06379e9d3b8238013148cfe1cc9914a7f38..3b2675afb405701a89206bf586ccf80654ce745d 100644 (file)
@@ -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);
                }
                        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);
                /* (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));
        /* (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));
        /* (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;
        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;
        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);
        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);
 
        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);
        }
 
                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);
        if (olditem->official_title != NULL) {
                g_free(newitem->official_title);
                newitem->official_title = g_strdup(olditem->official_title);
index 7b1b169c227be2e1526cc0f001d354027303a387..6ded09977d02af5a0f8033668555c1900692dbcc 100644 (file)
@@ -25,6 +25,7 @@
 struct _RFolderItem {
        FolderItem item;
        gchar *url;
 struct _RFolderItem {
        FolderItem item;
        gchar *url;
+       FeedAuth *auth;
        gchar *official_title;
        gchar *source_id;
 
        gchar *official_title;
        gchar *source_id;
 
index e7edcf67bf6f37d33c79007852beda2c34f30e8b..b702a03d76d2d0cb13b392788ffd1b28f818a423 100644 (file)
@@ -41,7 +41,7 @@
 
 static void rssyl_gtk_prop_store(RFolderItem *ritem)
 {
 
 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;
        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->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;
        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;
 }
 
        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)
 
 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,
        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;
                                                *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);
 
        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"));
        /* "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);
 
        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_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);
 
        /* Table for remaining properties */
        table = gtk_table_new(11, 2, FALSE);
index 5aa45394631606c48a613fbb5982e4533ab9e947..d1e088b2bc35e4fbf53d4bd93edee9684f32bfbf 100644 (file)
@@ -17,6 +17,9 @@ struct _RFeedProp {
        GtkWidget *write_heading;
        GtkWidget *ignore_title_rename;
        GtkWidget *ssl_verify_peer;
        GtkWidget *write_heading;
        GtkWidget *ignore_title_rename;
        GtkWidget *ssl_verify_peer;
+       GtkWidget *auth_type;
+       GtkWidget *auth_username;
+       GtkWidget *auth_password;
 };
 
 typedef struct _RFeedProp RFeedProp;
 };
 
 typedef struct _RFeedProp RFeedProp;