From 6df5e1206e09e96cb0f28476f747215ca56731e2 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 11 Jan 2022 18:53:13 -0800 Subject: [PATCH] ... --- inc/torrent.h | 1 + src/feed/entries.c | 37 +++++++++++++++++++++++++++---------- test/unit/Makefile.am | 1 + test/unit/feed.tests.c | 17 ++++++++++++++++- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/inc/torrent.h b/inc/torrent.h index 5eb2f3f..eb9d89a 100644 --- a/inc/torrent.h +++ b/inc/torrent.h @@ -20,6 +20,7 @@ struct torrent_files { struct torrent { char *root; char *name; + char *feed_url; unsigned long long piece_length; diff --git a/src/feed/entries.c b/src/feed/entries.c index 71b91bd..62cf751 100644 --- a/src/feed/entries.c +++ b/src/feed/entries.c @@ -1,19 +1,26 @@ #include +static int entry_default(struct rss_entry*,const char*,struct file*); static int entries_sort(const void*,const void*); +static int entry_default(struct rss_entry *entry, const char *feed_url, struct file *file_p) { + entry->title = strdup(file_p->name); + if(NULL==entry->title) { return -1; } + + entry->pub_date = *localtime(&(time_t){time(NULL)}); + + return 1; +} + int feed_entries(FILE *fp, struct torrent *torrent) { - struct file *p; + struct tree_entry *p; struct rss_entry **entries, *entry; size_t count, index; if(NULL==fp) { return -1; } if(NULL==torrent) { return -1; } - count = 0; - for(size_t i=0;ifiles.roots->size;i++) { - if(torrent->files.roots->map[i]!=NULL) { count++; } - } + count = tree_length(torrent->tree); entries = malloc(sizeof(struct rss_entry*)*count); if(NULL==entries) { return -1; } @@ -27,9 +34,19 @@ int feed_entries(FILE *fp, struct torrent *torrent) { p = torrent->files.roots->map[i]; if(p!=NULL) { if(rss_entry_init(&entry)<0) { goto clean; } - if(meta_entry(p->path,entry)<0) { - rss_entry_free(entry); - goto clean; + { + int ret; + if((ret = meta_entry(p->path,entry))<0) { + rss_entry_free(entry); + goto clean; + } + + if(ret==0) { + if(entry_default(entry,torrent_p,p)<0) { + rss_entry_free(entry); + goto clean; + } + } } entries[index] = entry; index++; @@ -65,8 +82,8 @@ static int entries_sort(const void *p1,const void *p2) { if(NULL==p1) { return 1; } if(NULL==p2) { return -1; } - entry1 = (struct rss_entry*)p1; - entry2 = (struct rss_entry*)p2; + entry1 = *(struct rss_entry**)p1; + entry2 = *(struct rss_entry**)p2; a = mktime(&(entry1->pub_date)); b = mktime(&(entry2->pub_date)); diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 88e0b6a..edd06a7 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -52,6 +52,7 @@ feed_tests_SOURCES = \ feed.tests.c \ $(top_srcdir)/src/feed/entries.c \ $(top_srcdir)/src/feed/info.c \ + $(top_srcdir)/src/feed/path.c \ $(top_srcdir)/src/fs/concat.c \ $(top_srcdir)/src/fs/dir.c \ $(top_srcdir)/src/hash.c \ diff --git a/test/unit/feed.tests.c b/test/unit/feed.tests.c index 31f5bef..19079f2 100644 --- a/test/unit/feed.tests.c +++ b/test/unit/feed.tests.c @@ -3,8 +3,9 @@ #include int main(); -static void feed_info_basic_test(); static void feed_entries_basic_test(); +static void feed_info_basic_test(); +static void feed_path_basic_test(); static FILE *setup_file_pointer(); int main() { @@ -12,6 +13,7 @@ int main() { feed_info_basic_test(); feed_entries_basic_test(); + feed_path_basic_test(); clean_env(); @@ -68,6 +70,19 @@ static void feed_info_basic_test() { reset_env(); } +static void feed_path_basic_test() { + char *p; + + assert(NULL==feed_path(NULL)); + + p = feed_path("test"); + assert(p!=NULL); + + assert(strcmp(p,TEST_DIRECTORY "/test" FEED_FILE_EXTENSION)==0); + + free(p); +} + static FILE *setup_file_pointer() { FILE *fp; -- 2.30.2