diff --git a/src/castget.c b/src/castget.c index 2498bc2..9793528 100644 --- a/src/castget.c +++ b/src/castget.c @@ -394,7 +394,8 @@ static int _process_channel(const gchar *channel_directory, GKeyFile *kf, c = channel_new(channel_configuration->url, channel_file, channel_configuration->spool_directory, - channel_configuration->filename_pattern, resume); + channel_configuration->filename_pattern, resume, + channel_configuration->user_agent); g_free(channel_file); if (!c) { diff --git a/src/channel.c b/src/channel.c index 09b9335..e8726a5 100644 --- a/src/channel.c +++ b/src/channel.c @@ -58,7 +58,7 @@ static void _enclosure_iterator(const void *user_data, int i, channel *channel_new(const char *url, const char *channel_file, const char *spool_directory, const char *filename_pattern, - int resume) + int resume, const char *user_agent) { channel *c; xmlDocPtr doc; @@ -70,6 +70,7 @@ channel *channel_new(const char *url, const char *channel_file, c->channel_filename = g_strdup(channel_file); c->spool_directory = g_strdup(spool_directory); c->filename_pattern = g_strdup(filename_pattern); + c->user_agent = g_strdup(user_agent); // c->resume = resume; c->rss_last_fetched = NULL; c->downloaded_enclosures = @@ -126,7 +127,7 @@ static void _cast_channel_save_downloaded_enclosure(gpointer key, g_free(escaped_key); } -static int _cast_channel_save_channel(FILE *f, gpointer user_data, int debug) +static int _cast_channel_save_channel(FILE *f, gpointer user_data, int debug, channel *cc) { channel *c = (channel *)user_data; @@ -149,7 +150,7 @@ static int _cast_channel_save_channel(FILE *f, gpointer user_data, int debug) static void _cast_channel_save(channel *c, int debug) { write_by_temporary_file(c->channel_filename, _cast_channel_save_channel, c, - NULL, debug); + NULL, debug, c); } void channel_free(channel *c) @@ -180,7 +181,7 @@ static rss_file *_get_rss(channel *c, void *user_data, channel_callback cb, if (!strncmp("http://", c->url, strlen("http://")) || !strncmp("https://", c->url, strlen("https://"))) - f = rss_open_url(c->url, debug); + f = rss_open_url(c->url, debug, c); else f = rss_open_file(c->url); @@ -256,7 +257,7 @@ static int _do_download(channel *c, channel_info *channel_info, rss_item *item, pb = NULL; if (urlget_buffer(item->enclosure->url, enclosure_file, _enclosure_urlget_cb, - resume_from, debug, pb)) { + resume_from, debug, pb, c)) { g_fprintf(stderr, "Error downloading enclosure from %s.\n", item->enclosure->url); diff --git a/src/channel.h b/src/channel.h index 786577a..ef70b41 100644 --- a/src/channel.h +++ b/src/channel.h @@ -36,6 +36,7 @@ typedef struct _channel { gchar *filename_pattern; GHashTable *downloaded_enclosures; gchar *rss_last_fetched; + gchar *user_agent; } channel; typedef struct _channel_info { @@ -62,7 +63,7 @@ typedef void (*channel_callback)(void *user_data, channel_action action, channel *channel_new(const char *url, const char *channel_file, const char *spool_directory, const char *filename_pattern, - int resume); + int resume, const char *user_agent); void channel_free(channel *c); int channel_update(channel *c, void *user_data, channel_callback cb, int no_download, int no_mark_read, int first_only, diff --git a/src/configuration.c b/src/configuration.c index 5eb00e7..afe1906 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -108,6 +108,7 @@ struct channel_configuration *channel_configuration_new( c->comment_tag = _read_channel_configuration_key(kf, identifier, "comment_tag"); c->regex_filter = _read_channel_configuration_key(kf, identifier, "filter"); + c->user_agent = _read_channel_configuration_key(kf, identifier, "user_agent"); /* Populate with defaults if necessary. */ if (defaults) { @@ -143,6 +144,9 @@ struct channel_configuration *channel_configuration_new( if (!c->regex_filter && defaults->regex_filter) c->regex_filter = g_strdup(defaults->regex_filter); + + if (!c->user_agent && defaults->user_agent) + c->user_agent = g_strdup(defaults->user_agent); } return c; @@ -198,7 +202,8 @@ int channel_configuration_verify_keys(GKeyFile *kf, const char *identifier) !strcmp(key_list[i], "genre_tag") || !strcmp(key_list[i], "year_tag") || !strcmp(key_list[i], "comment_tag") || - !strcmp(key_list[i], "filter"))) { + !strcmp(key_list[i], "filter") || + !strcmp(key_list[i], "user_agent"))) { fprintf(stderr, "Invalid key %s in configuration of channel %s.\n", key_list[i], identifier); return -1; diff --git a/src/configuration.h b/src/configuration.h index 7c2ca40..05e24a0 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -35,6 +35,7 @@ struct channel_configuration { gchar *year_tag; gchar *comment_tag; gchar *regex_filter; + gchar *user_agent; }; struct channel_configuration *channel_configuration_new( diff --git a/src/rss.c b/src/rss.c index 5eae5aa..669c0c2 100644 --- a/src/rss.c +++ b/src/rss.c @@ -21,6 +21,7 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ +#include "channel.h" #include "htmlent.h" #include "libxmlutil.h" #include "rss.h" @@ -252,20 +253,20 @@ rss_file *rss_open_file(const char *filename) return f; } -static int _rss_open_url_cb(FILE *f, gpointer user_data, int debug) +static int _rss_open_url_cb(FILE *f, gpointer user_data, int debug, channel *c) { gchar *url = (gchar *)user_data; - return urlget_file(url, f, debug); + return urlget_file(url, f, debug, c); } -rss_file *rss_open_url(const char *url, int debug) +rss_file *rss_open_url(const char *url, int debug, channel *c) { rss_file *f; gchar *rss_filename; if (write_by_temporary_file(NULL, _rss_open_url_cb, (gpointer)url, - &rss_filename, debug)) + &rss_filename, debug, c)) return NULL; f = rss_open_file(rss_filename); diff --git a/src/rss.h b/src/rss.h index 571e386..dbff74e 100644 --- a/src/rss.h +++ b/src/rss.h @@ -46,7 +46,7 @@ typedef struct _rss_file { } rss_file; rss_file *rss_open_file(const char *filename); -rss_file *rss_open_url(const char *url, int debug); +rss_file *rss_open_url(const char *url, int debug, channel *c); void rss_close(rss_file *f); #endif /* RSS_H */ diff --git a/src/urlget.c b/src/urlget.c index 3a6a45f..9663cba 100644 --- a/src/urlget.c +++ b/src/urlget.c @@ -29,15 +29,16 @@ #include #include -int urlget_file(const char *url, FILE *f, int debug) +int urlget_file(const char *url, FILE *f, int debug, channel *c) { - return urlget_buffer(url, (void *)f, NULL, 0, debug, NULL); + return urlget_buffer(url, (void *)f, NULL, 0, debug, NULL, c); } int urlget_buffer(const char *url, void *user_data, size_t (*write_buffer)(void *buffer, size_t size, size_t nmemb, void *user_data), - long resume_from, int debug, progress_bar *pb) + long resume_from, int debug, progress_bar *pb, + channel *c) { CURL *easyhandle; CURLcode success; @@ -46,8 +47,11 @@ int urlget_buffer(const char *url, void *user_data, gchar *user_agent; /* Construct user agent string. */ - user_agent = g_strdup_printf("%s (%s rss enclosure downloader)", - PACKAGE_STRING, PACKAGE); + if (c->user_agent) + user_agent = g_strdup(c->user_agent); + else + user_agent = g_strdup_printf("%s (%s rss enclosure downloader)", + PACKAGE_STRING, PACKAGE); /* Initialise curl. */ easyhandle = curl_easy_init(); diff --git a/src/urlget.h b/src/urlget.h index 512d2af..045869c 100644 --- a/src/urlget.h +++ b/src/urlget.h @@ -21,11 +21,13 @@ #define URLGET_H #include "progress.h" +#include "channel.h" -int urlget_file(const char *url, FILE *f, int debug); +int urlget_file(const char *url, FILE *f, int debug, channel *c); int urlget_buffer(const char *url, void *user_data, size_t (*write_buffer)(void *buffer, size_t size, size_t nmemb, void *user_data), - long resume_from, int debug, progress_bar *pb); + long resume_from, int debug, progress_bar *pb, + channel *c); #endif /* URLGET_H */ diff --git a/src/utils.c b/src/utils.c index 778472d..94a346d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -32,9 +32,9 @@ int write_by_temporary_file(const gchar *filename, int (*writer)(FILE *f, gpointer user_data, - int debug), + int debug, channel *c), gpointer user_data, gchar **used_filename, - int debug) + int debug, channel *c) { int retval; FILE *f; @@ -72,7 +72,7 @@ int write_by_temporary_file(const gchar *filename, return -1; } - retval = writer(f, user_data, debug); + retval = writer(f, user_data, debug, c); fclose(f); diff --git a/src/utils.h b/src/utils.h index 7c3f176..2bd1470 100644 --- a/src/utils.h +++ b/src/utils.h @@ -20,14 +20,16 @@ #ifndef UTILS_H #define UTILS_H +#include "channel.h" + #include #include int write_by_temporary_file(const gchar *filename, int (*writer)(FILE *f, gpointer user_data, - int debug), + int debug, channel *c), gpointer user_data, gchar **used_filename, - int debug); + int debug, channel *c); gchar *get_rfc822_time(void); #endif /* UTILS_H */