src/block.c \
src/default.c \
src/feed/entries.c \
+ src/feed/feeds.c \
src/feed/gen.c \
src/feed/info.c \
src/feed/path.c \
int feeds();
int feed_entries(FILE*,struct torrent*);
+int feed_generate(struct torrent*);
int feed_info(FILE*,struct torrent*);
char *feed_path(const char*);
void tree_free(struct tree*);
int tree_init(struct tree**);
size_t tree_length(const struct tree*);
+int tree_remove(struct tree*,const char*);
#endif
--- /dev/null
+#include<feed.h>
+
+int feeds() {
+ for(size_t i=0;i<session.torrent_count;i++) {
+ if(feed_generate(session.torrents[i])<0) { return -1; }
+ }
+
+ return 1;
+}
+
#include<feed.h>
-static int feed_generate(struct torrent*);
-
-int feeds() {
- for(size_t i=0;i<session.torrent_count;i++) {
- if(feed_generate(session.torrents[i])<0) { return -1; }
- }
-
- return 1;
-}
-
-static int feed_generate(struct torrent *torrent) {
+int feed_generate(struct torrent *torrent) {
FILE *fp;
char *path;
+ if(NULL==torrent) { return -1; }
+
if(is_directory(FEED_DIRECTORY)<0) {
if(directory_create(FEED_DIRECTORY)<0) { return -1; }
}
int torrent_remove(struct torrent *torrent, const char *path) {
struct file *p;
- if(tree_remove(torrent->tree,path)<0) { return -1; }
p = hashmap_remove(torrent->files.paths,path,strlen(path));
if(p!=NULL) {
p = hashmap_remove(torrent->files.roots,p->root,crypto_hash_sha256_BYTES);
if(NULL==p) { return -1; }
-
- file_free(p);
}
+ if(tree_remove(torrent->tree,path)<0) { return -1; }
+
return 1;
}
static int advance(ssize_t,uint8_t**,size_t*);
static struct tree* tree_add_directory(struct tree*,const char*);
static int tree_add_file(struct tree*,struct file*);
+static struct tree_entry *tree_entry_find(struct tree*,const char*);
static int tree_entry_init_directory(struct tree_entry**,const char*);
+static struct tree_entry *tree_entry_remove(struct tree*,const char*);
static int advance(ssize_t i, uint8_t **buf, size_t *len) {
if(i<0) { return -1; }
return i;
}
+struct tree_entry *tree_entry_find(struct tree *tree, const char *name) {
+ struct tree_entry *p;
+
+ p = tree->entries;
+ while(p!=NULL) {
+ if(strcmp(p->name,name)==0) {
+ return p;
+ }
+
+ p = p->next;
+ }
+
+ return NULL;
+}
+
void tree_entry_free(struct tree_entry *p) {
if(NULL==p) { return; }
return -1;
}
+static struct tree_entry *tree_entry_remove(struct tree *tree, const char *name) {
+ struct tree_entry *prev, *p;
+
+ prev = NULL;
+ p = tree->entries;
+ while(p!=NULL) {
+ if(strcmp(p->name,name)==0) {
+ if(prev!=NULL) {
+ prev->next = p->next;
+ } else {
+ tree->entries = p->next;
+ }
+
+ p->next = NULL;
+ return p;
+ }
+
+ prev = p;
+ p = p->next;
+ }
+
+ return NULL;
+}
+
void tree_free(struct tree *p) {
if(NULL==p) { return; }
return i;
}
+
+int tree_remove(struct tree *tree, const char *to_remove) {
+ struct tree_entry *entry_p;
+ char *path, *p, *prev;
+
+ if(NULL==tree) { return -1; }
+ if(NULL==to_remove) { return -1; }
+
+ path = strdup(to_remove);
+
+ prev = NULL;
+ p = strtok(path,"/");
+ while(p!=NULL) {
+ if(prev!=NULL) { // prev contains next subdirectory
+ entry_p = tree_entry_find(tree,prev);
+ if(NULL==entry_p) { goto clean; }
+
+ if(NULL==entry_p->children) { goto clean; }
+
+ tree = entry_p->children;
+ }
+
+ prev = p;
+ p = strtok(NULL,"/");
+ }
+
+ entry_p = tree_entry_remove(tree,prev);
+ if(NULL==entry_p) { goto clean; }
+
+ tree_entry_free(entry_p);
+ free(path);
+
+ return 1;
+clean:
+ free(path);
+ return 0;
+}
$(top_srcdir)/src/file.c \
$(top_srcdir)/src/hashmap.c \
$(top_srcdir)/src/torrent/add.c \
+ $(top_srcdir)/src/torrent/file.c \
$(top_srcdir)/src/torrent/free.c \
$(top_srcdir)/src/torrent/init.c \
+ $(top_srcdir)/src/torrent/magnet.c \
+ $(top_srcdir)/src/torrent/path.c \
+ $(top_srcdir)/src/torrent/piece.c \
+ $(top_srcdir)/src/torrent/remove.c \
$(top_srcdir)/src/tree.c
bencode_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 \
$(top_srcdir)/src/meta.c \
$(top_srcdir)/src/rss/entry.c \
$(top_srcdir)/src/rss/free.c \
+ $(top_srcdir)/src/rss/footer.c \
+ $(top_srcdir)/src/rss/header.c \
$(top_srcdir)/src/rss/info.c \
$(top_srcdir)/src/rss/init.c
+feed_tests_CPPFLAGS = $(AM_CPPFLAGS) \
+ -DFEED_GEN_SRC_FILE="$(top_srcdir)/src/feed/gen.c" \
+ -DFEED_PATH_SRC_FILE="$(top_srcdir)/src/feed/path.c" \
+ -DTORRENT_INFO_SRC_FILE="$(top_srcdir)/src/torrent/info.c"
+
file_tests_SOURCES = \
$(common_SOURCES) \
file.tests.c \
torrent.tests.c \
$(top_srcdir)/src/fs/concat.c \
$(top_srcdir)/src/fs/dir.c \
- $(top_srcdir)/src/hash.c \
- $(top_srcdir)/src/torrent/file.c \
- $(top_srcdir)/src/torrent/magnet.c \
- $(top_srcdir)/src/torrent/path.c \
- $(top_srcdir)/src/torrent/piece.c
+ $(top_srcdir)/src/hash.c
torrent_tests_CPPFLAGS = $(AM_CPPFLAGS) \
-DTORRENT_INFO_SRC_FILE="$(top_srcdir)/src/torrent/info.c"
#include<feed.h>
+#include INCLUDE(FEED_PATH_SRC_FILE)
+#include INCLUDE(FEED_GEN_SRC_FILE)
+#include INCLUDE(TORRENT_INFO_SRC_FILE)
+
int main();
static void feed_entries_basic_test();
+static void feed_generate_basic_test();
static void feed_info_basic_test();
static void feed_path_basic_test();
static FILE *setup_file_pointer();
feed_info_basic_test();
feed_entries_basic_test();
feed_path_basic_test();
+ feed_generate_basic_test();
clean_env();
FILE *fp;
struct torrent *p;
unsigned char hash[crypto_hash_sha256_BYTES];
- unsigned char expected[crypto_hash_sha256_BYTES] = {185,160,108,238,240,237,217,219,97,190,118,39,179,198,241,61,191,24,149,75,124,56,189,148,163,13,185,110,30,115,222,186};
+ unsigned char expected[crypto_hash_sha256_BYTES] = {247,202,150,77,202,46,21,104,21,158,65,19,138,184,234,91,149,83,166,163,25,206,148,227,250,179,195,162,207,128,251,211};
fp = setup_file_pointer();
assert(-1==feed_entries(NULL,NULL));
assert(-1==feed_entries(fp,NULL));
+ assert(torrent_remove(p,"/test2")==1);
+
assert(1==feed_entries(fp,p));
torrent_free(p);
reset_env();
}
+static void feed_generate_basic_test() {
+ struct torrent *p;
+
+ TORRENT_SETUP_EXAMPLE(&p);
+
+ assert(feed_generate(NULL)==-1);
+
+ assert(feed_generate(p)==1);
+
+ torrent_free(p);
+
+ reset_env();
+}
+
static void feed_info_basic_test() {
FILE *fp;
struct torrent *p;
p = feed_path("test");
assert(p!=NULL);
- assert(strcmp(p,TEST_DIRECTORY "/test" FEED_FILE_EXTENSION)==0);
+ assert(strcmp(p,FEED_DIRECTORY "/test" FEED_FILE_EXTENSION)==0);
free(p);
}
static void tree_bencode_length_basic_test();
static void tree_init_basic_test();
static void tree_length_basic_test();
+static void tree_remove_basic_test();
int main() {
setup_env();
tree_add_alphabetic_test();
tree_bencode_length_basic_test();
tree_length_basic_test();
+ tree_remove_basic_test();
clean_env();
tree_free(p);
}
+
+static void tree_remove_basic_test() {
+ struct tree *p;
+ struct file *file;
+
+ assert(1==tree_init(&p));
+
+ assert(-1==tree_remove(NULL,NULL));
+ assert(-1==tree_remove(p,NULL));
+
+ assert(1==file_init(&file,"/test/hello/what?"));
+
+ assert(1==tree_add(p,"/test/hello/what?",file));
+
+ assert(1==file_init(&file,"/test/hello/temp"));
+ assert(1==tree_add(p,"/test/hello/temp",file));
+
+ assert(1==file_init(&file,"test3"));
+ assert(1==tree_add(p,"/test3",file));
+
+ assert(2==tree_length(p));
+
+ assert(p->entries->children!=NULL);
+ assert(strcmp(p->entries->children->entries->name,"hello")==0);
+
+ assert(2==tree_length(p->entries->children->entries->children));
+
+ assert(1==tree_remove(p,"/test3"));
+ assert(1==tree_length(p));
+
+ assert(2==tree_length(p->entries->children->entries->children));
+
+ assert(1==tree_remove(p,"/test/hello/temp"));
+ assert(1==tree_length(p->entries->children->entries->children));
+
+ assert(1==tree_remove(p,"/test/hello"));
+
+ assert(p->entries->children!=NULL);
+ assert(0==tree_length(p->entries->children));
+
+ assert(p->entries->children->entries==NULL);
+ assert(1==tree_length(p));
+
+ tree_free(p);
+}