#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; }
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++;
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));
#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() {
feed_info_basic_test();
feed_entries_basic_test();
+ feed_path_basic_test();
clean_env();
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;