diff options
author | Alan F <ajf@eth0.org.uk> | 2014-03-11 21:40:00 +0000 |
---|---|---|
committer | Alan F <ajf@eth0.org.uk> | 2014-03-11 21:40:00 +0000 |
commit | 0ddde97414b63ab2830d0352ef1cd86cc9958cad (patch) | |
tree | b48a125cc0b11735a0bc5e7c5b6c37154f2ebea4 | |
parent | e22015c6d3e8860b1994a22919bdb1f6066fcbe9 (diff) |
support uTorrent style cookies on the end of the RSS feed URL
-rw-r--r-- | src/trg-client.c | 4 | ||||
-rw-r--r-- | src/trg-rss-model.c | 29 | ||||
-rw-r--r-- | src/trg-rss-model.h | 1 | ||||
-rw-r--r-- | src/trg-rss-window.c | 7 |
4 files changed, 31 insertions, 10 deletions
diff --git a/src/trg-client.c b/src/trg-client.c index c285c7b..48e3093 100644 --- a/src/trg-client.c +++ b/src/trg-client.c @@ -784,7 +784,9 @@ dispatch_async_str(TrgClient * tc, gchar * body, gboolean async_http_request(TrgClient *tc, gchar *url, const gchar *cookie, GSourceFunc callback, gpointer data) { trg_request *trg_req = g_new0(trg_request, 1); trg_req->url = g_strdup(url); - trg_req->cookie = g_strdup(cookie); + + if (cookie) + trg_req->cookie = g_strdup(cookie); return dispatch_async_common(tc, trg_req, callback, data); } diff --git a/src/trg-rss-model.c b/src/trg-rss-model.c index 387852d..6e95238 100644 --- a/src/trg-rss-model.c +++ b/src/trg-rss-model.c @@ -56,6 +56,7 @@ typedef struct { TrgRssModel *model; gchar *feed_id; gchar *feed_url; + gchar *feed_cookie; GError *error; trg_response *response; } feed_update; @@ -66,6 +67,7 @@ static void feed_update_free(feed_update *update) { g_free(update->feed_id); g_free(update->feed_url); + g_free(update->feed_cookie); g_free(update); } @@ -96,7 +98,7 @@ static gboolean on_rss_receive(gpointer data) { gtk_list_store_set(GTK_LIST_STORE(model), &iter, RSSCOL_ID, guid, RSSCOL_TITLE, rss_item_get_title(item), RSSCOL_LINK, rss_item_get_link(item), RSSCOL_FEED, - update->feed_id, RSSCOL_PUBDATE, + update->feed_id, RSSCOL_COOKIE, update->feed_cookie, RSSCOL_PUBDATE, rss_item_get_pub_date(item), -1); g_hash_table_insert(priv->table, g_strdup(guid), (void*) 1); } @@ -135,29 +137,43 @@ void trg_rss_model_update(TrgRssModel * model) { TrgRssModelPrivate *priv = TRG_RSS_MODEL_GET_PRIVATE(model); TrgPrefs *prefs = trg_client_get_prefs(priv->client); JsonArray *feeds = trg_prefs_get_rss(prefs); + GRegex *cookie_regex; GList *li; if (!feeds) return; + cookie_regex = g_regex_new("(.*):COOKIE:(.*)", 0, 0, NULL); + for (li = json_array_get_elements(feeds); li != NULL; li = g_list_next(li)) { JsonObject *feed = json_node_get_object((JsonNode *) li->data); - const gchar *url = json_object_get_string_member(feed, "url"); + const gchar *feed_url = json_object_get_string_member(feed, "url"); const gchar *id = json_object_get_string_member(feed, "id"); + feed_update *update; + GMatchInfo *match; - if (!url || !id) + if (!feed_url || !id) continue; - feed_update *update = g_new0(feed_update, 1); - update->feed_url = g_strdup(url); + update = g_new0(feed_update, 1); update->feed_id = g_strdup(id); update->model = model; - async_http_request(priv->client, update->feed_url, NULL, on_rss_receive, + if (g_regex_match (cookie_regex, feed_url, 0, &match)) { + update->feed_url = g_match_info_fetch(match, 1); + update->feed_cookie = g_match_info_fetch(match, 2); + g_match_info_free(match); + } else { + update->feed_url = g_strdup(feed_url); + } + + async_http_request(priv->client, update->feed_url, update->feed_cookie, on_rss_receive, update); } + g_regex_unref(cookie_regex); + /*trg_model_remove_removed(GTK_LIST_STORE(model), RSSCOL_UPDATESERIAL, updateSerial);*/ } @@ -244,6 +260,7 @@ static void trg_rss_model_init(TrgRssModel * self) { column_types[RSSCOL_ID] = G_TYPE_STRING; column_types[RSSCOL_TITLE] = G_TYPE_STRING; column_types[RSSCOL_LINK] = G_TYPE_STRING; + column_types[RSSCOL_COOKIE] = G_TYPE_STRING; column_types[RSSCOL_FEED] = G_TYPE_STRING; column_types[RSSCOL_PUBDATE] = G_TYPE_STRING; column_types[RSSCOL_UPLOADED] = G_TYPE_BOOLEAN; diff --git a/src/trg-rss-model.h b/src/trg-rss-model.h index 206ee41..ddecc95 100644 --- a/src/trg-rss-model.h +++ b/src/trg-rss-model.h @@ -76,6 +76,7 @@ enum { RSSCOL_TITLE, RSSCOL_LINK, RSSCOL_FEED, + RSSCOL_COOKIE, RSSCOL_PUBDATE, RSSCOL_UPLOADED, RSSCOL_COLUMNS diff --git a/src/trg-rss-window.c b/src/trg-rss-window.c index 63af9b1..15a4c1a 100644 --- a/src/trg-rss-window.c +++ b/src/trg-rss-window.c @@ -166,7 +166,7 @@ rss_item_activated(GtkTreeView * treeview, GtkTreeModel *model = gtk_tree_view_get_model(treeview); trg_upload *upload = g_new0(trg_upload, 1); GtkTreeIter iter; - gchar *link, *uid; + gchar *link, *uid, *cookie; //upload->upload_response = response; upload->main_window = priv->parent; @@ -178,12 +178,13 @@ rss_item_activated(GtkTreeView * treeview, gtk_tree_model_get_iter(model, &iter, path); - gtk_tree_model_get(model, &iter, RSSCOL_LINK, &link, RSSCOL_ID, &uid, -1); + gtk_tree_model_get(model, &iter, RSSCOL_LINK, &link, RSSCOL_ID, &uid, RSSCOL_COOKIE, &cookie, -1); upload->uid = uid; - async_http_request(priv->client, link, NULL, on_torrent_receive, upload); + async_http_request(priv->client, link, cookie, on_torrent_receive, upload); + g_free(cookie); g_free(link); } |