summaryrefslogtreecommitdiff
path: root/src/trg-file-parser.c
diff options
context:
space:
mode:
authorGravatar Alan F <ajf@eth0.org.uk>2014-03-10 09:10:24 +0000
committerGravatar Alan F <ajf@eth0.org.uk>2014-03-10 09:10:24 +0000
commit1a5447c0138fd25e3f6d78f78593f5b70be5614a (patch)
tree9468304a4688a63788363bcf2457b1767aa513a9 /src/trg-file-parser.c
parentdd0c7d8317dd199b6dd9d612ebb863c4da6cf242 (diff)
parent118b702bec50d9872699357a379413f69e9b176e (diff)
Merge branch 'rss-viewer'. This is the biggest feature I've attempted to add for quite a long time. Quite a lot of refactoring of the HTTP client and threadpool has been done (to make it not send session tokens etc), uploads (was too much code duplication), and the add dialog was done to implement this. Don't expect this to be some fully automatable RSS client, use something like flexget for that, this is just a simple view on RSS feeds. It uses the rss-glib library, which you will probably need to install yourself to optionally use this feature. There are probably bugs still, so report them.
Diffstat (limited to 'src/trg-file-parser.c')
-rw-r--r--src/trg-file-parser.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/src/trg-file-parser.c b/src/trg-file-parser.c
index fbfb6aa..ff4ac62 100644
--- a/src/trg-file-parser.c
+++ b/src/trg-file-parser.c
@@ -134,32 +134,11 @@ static trg_files_tree_node *trg_parse_torrent_file_nodes(be_node *
return top_node;
}
-trg_torrent_file *trg_parse_torrent_file(const gchar * filename)
-{
- GError *error = NULL;
- GMappedFile *mf;
- be_node *top_node, *info_node, *name_node;
- trg_torrent_file *ret = NULL;
-
- if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
- g_message("%s does not exist", filename);
- return NULL;
- }
-
- mf = g_mapped_file_new(filename, FALSE, &error);
+trg_torrent_file *trg_parse_torrent_data(const gchar *data, gsize length) {
+ trg_torrent_file *ret = NULL;
+ be_node *top_node, *info_node, *name_node;
- if (error) {
- g_error("%s", error->message);
- g_error_free(error);
- g_mapped_file_unref(mf);
- return NULL;
- } else {
- top_node =
- be_decoden(g_mapped_file_get_contents(mf),
- g_mapped_file_get_length(mf));
- }
-
- g_mapped_file_unref(mf);
+ top_node = be_decoden(data, length);
if (!top_node) {
return NULL;
@@ -199,3 +178,30 @@ trg_torrent_file *trg_parse_torrent_file(const gchar * filename)
be_free(top_node);
return ret;
}
+
+trg_torrent_file *trg_parse_torrent_file(const gchar * filename)
+{
+ GError *error = NULL;
+ trg_torrent_file *ret = NULL;
+ GMappedFile *mf;
+
+ if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
+ g_message("%s does not exist", filename);
+ return NULL;
+ }
+
+ mf = g_mapped_file_new(filename, FALSE, &error);
+
+ if (error) {
+ g_error("%s", error->message);
+ g_error_free(error);
+ g_mapped_file_unref(mf);
+ return NULL;
+ } else {
+ ret = trg_parse_torrent_data(g_mapped_file_get_contents(mf), g_mapped_file_get_length(mf));
+ }
+
+ g_mapped_file_unref(mf);
+
+ return ret;
+}