]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Thu, 13 Jan 2022 04:51:09 +0000 (20:51 -0800)
committeralex <[email protected]>
Thu, 13 Jan 2022 04:51:09 +0000 (20:51 -0800)
inc/tree.h
src/feed/entries.c
src/meta.c
src/tree.c

index f315945a4a82a9cbd685cd7f3d5cccd9461472ad..bfdbad6b78424ce7cee3f02b1c2b7a5ae8a9a927 100644 (file)
@@ -27,5 +27,6 @@ void tree_entry_free(struct tree_entry*);
 int tree_entry_init(struct tree_entry**, struct file*);
 void tree_free(struct tree*);
 int tree_init(struct tree**);
+size_t tree_length(const struct tree*);
 
 #endif
index 62cf75126d4d5381ec3a92bb34f88de8298fc733..e5f090c65c7388eb14cf213f8643f26639b35a4a 100644 (file)
@@ -1,10 +1,10 @@
 #include<feed.h>
 
-static int entry_default(struct rss_entry*,const char*,struct file*);
+static int entry_default(struct rss_entry*,const char*,struct tree_entry*);
 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);
+static int entry_default(struct rss_entry *entry, const char *feed_url, struct tree_entry *p) {
+       entry->title = strdup(p->name);
        if(NULL==entry->title) { return -1; }
 
        entry->pub_date = *localtime(&(time_t){time(NULL)});
@@ -15,6 +15,7 @@ static int entry_default(struct rss_entry *entry, const char *feed_url, struct f
 int feed_entries(FILE *fp, struct torrent *torrent) {
        struct tree_entry *p;
        struct rss_entry **entries, *entry;
+       char *path;
        size_t count, index;
 
        if(NULL==fp) { return -1; }
@@ -30,27 +31,27 @@ int feed_entries(FILE *fp, struct torrent *torrent) {
        }
 
        index = 0;
-       for(size_t i=0;i<torrent->files.roots->size;i++) {
-               p = torrent->files.roots->map[i];
-               if(p!=NULL) {
-                       if(rss_entry_init(&entry)<0) { 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++;
+       p = torrent->tree->entries;
+       entry = NULL;
+       while(p!=NULL) {
+               if(rss_entry_init(&entry)<0) { goto clean; }
+               
+               if(entry_default(entry,torrent->feed_url,p)<0) { goto clean; }
+
+               path = concat(torrent->root,p->name);
+               if(NULL==path) { goto clean; }
+
+               if(meta_entry(path,entry)<0) {
+                       free(path);
+                       goto clean;
                }
+               free(path);
+
+               entries[index] = entry;
+               entry = NULL;
+               index++;
+
+               p = p->next;
        }
        
        qsort(entries,count,sizeof(struct rss_entry*),&entries_sort);
index 6ae4cdf929355b11c4d144b57f7a99536262430d..77b346888bd8fd464cc50592d932adb64e4b2b85 100644 (file)
@@ -20,8 +20,10 @@ int meta_entry(const char *path, struct rss_entry *entry) {
 
        while((i = next_line(fp,&key,&value,buf,META_MAX_LINE_SIZE))>0) {
                if(strcmp(key,RSS_TAG_TITLE)==0) {
+                       if(entry->title!=NULL) { free(entry->title); }
                        entry->title = strndup(value,i);
                } else if(strcmp(key,RSS_TAG_LINK)==0) {
+                       if(entry->link!=NULL) { free(entry->link); }
                        entry->link = strndup(value,i);
                } else if(strcmp(key,RSS_TAG_PUBDATE)==0) {
                        if(NULL==strptime(
@@ -30,8 +32,10 @@ int meta_entry(const char *path, struct rss_entry *entry) {
                                &(entry->pub_date) /* struct tm *tm */
                        )) { return -1; }
                } else if(strcmp(key,RSS_TAG_DESCRIPTION)==0) {
+                       if(entry->description!=NULL) { free(entry->description); }
                        entry->description = strndup(value,i);
                } else if(strcmp(key,RSS_TAG_GUID)==0) {
+                       if(entry->guid!=NULL) { free(entry->guid); }
                        entry->guid = strndup(value,i);
                } else { goto panic; }
        }
@@ -112,12 +116,16 @@ int meta_info(const char *path, struct rss_channel_info *info) {
 
        while((i = next_line(fp,&key,&value,buf,META_MAX_LINE_SIZE))>0) {
                if(strcmp(key,RSS_TAG_TITLE)==0) {
+                       if(info->title!=NULL) { free(info->title); }
                        info->title = strndup(value,i);
                } else if(strcmp(key,RSS_TAG_LINK)==0) {
+                       if(info->link!=NULL) { free(info->link); }
                        info->link = strndup(value,i);
                } else if(strcmp(key,RSS_TAG_DESCRIPTION)==0) {
+                       if(info->description!=NULL) { free(info->description); }
                        info->description = strndup(value,i);
                } else if(strcmp(key,RSS_TAG_LANGUAGE)==0) {
+                       if(info->language!=NULL) { free(info->language); }
                        info->language = strndup(value,i);
                } else if(strcmp(key,RSS_TAG_LASTBUILDDATE)==0) {
                        if(NULL==strptime(
index 0da7b550abb0c95262546916f5446a6978bb1562..be39db5dc5e6712411d73cf46dfb28b3b781df85 100644 (file)
@@ -271,3 +271,16 @@ int tree_init(struct tree **p) {
 
        return 1;
 }
+
+size_t tree_length(const struct tree *root) {
+       struct tree_entry *p;
+       
+       size_t i = 0;
+       p = root->entries;
+       while(p!=NULL) {
+               i++;
+               p = p->next;
+       }
+
+       return i;
+}