]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Wed, 12 Jan 2022 02:53:13 +0000 (18:53 -0800)
committeralex <[email protected]>
Wed, 12 Jan 2022 02:53:13 +0000 (18:53 -0800)
inc/torrent.h
src/feed/entries.c
test/unit/Makefile.am
test/unit/feed.tests.c

index 5eb2f3fc22cb0f63cb5c690b77356e460d5094ba..eb9d89af393eed57678bf6d267baf64a2673c072 100644 (file)
@@ -20,6 +20,7 @@ struct torrent_files {
 struct torrent {
        char *root;
        char *name;
+       char *feed_url;
        
        unsigned long long piece_length;
 
index 71b91bdc801d700ebcda604da4eb570cb2d4d686..62cf75126d4d5381ec3a92bb34f88de8298fc733 100644 (file)
@@ -1,19 +1,26 @@
 #include<feed.h>
 
+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;i<torrent->files.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));
 
index 88e0b6ac382837f181138f44d60692f8b6c45589..edd06a73027efe6994c184d9c59038333f9dd5e2 100644 (file)
@@ -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 \
index 31f5beff976ffdb3f17a608587623566ccd4dfd9..19079f28a3661d3fda316e07fc3e8345cbbe5312 100644 (file)
@@ -3,8 +3,9 @@
 #include<feed.h>
 
 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;