#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)});
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; }
}
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);
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(
&(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; }
}
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(