src/torrent/magnet.c \
src/torrent/path.c \
src/torrent/piece.c \
+ src/torrent/remove.c \
src/tree.c \
src/usage.c \
src/watch.c
void torrent_free(struct torrent*);
int torrent_init(struct torrent**,unsigned long long);
char *torrent_magnet(struct torrent*);
+int torrent_remove(struct torrent*,const char*);
#endif
entry->title = strdup(p->name);
if(NULL==entry->title) { return -1; }
+ entry->link = concat(feed_url,p->name);
+ if(NULL==entry->link) { return -1; }
+
entry->pub_date = *localtime(&(time_t){time(NULL)});
return 1;
--- /dev/null
+#include<torrent.h>
+
+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);
+ }
+
+ return 1;
+}
assert(feed_info(NULL,NULL)==-1);
assert(feed_info(fp,NULL)==-1);
- assert(1==torrent_init(&p,TEST_DIRECTORY,TEST_DIRECTORY,16384));
+ TORRENT_SETUP_EXAMPLE(&p);
assert(1==feed_info(fp,p));
TORRENT_SETUP_EXAMPLE_FILE(&file1,TEST_FILE_1,1); \
TORRENT_SETUP_EXAMPLE_FILE(&file2,TEST_FILE_2,2); \
\
- assert(torrent_init(p,TEST_DIRECTORY,TEST_DIRECTORY,16384)==1); \
+ assert(torrent_init(p,16384)==1); \
+\
+ (*p)->root = strdup(TEST_DIRECTORY); \
+ assert((*p)->root!=NULL); \
+ (*p)->name = strdup(TEST_DIRECTORY); \
+ assert((*p)->name!=NULL); \
+ (*p)->feed_url = strdup("https://test.com"); \
+ assert((*p)->feed_url!=NULL); \
\
assert(torrent_add(*p,file1)==1); \
assert(torrent_add(*p,file2)==1); \
assert(file_init(&file4,TEST_FILE_4)==1);
memset(file4->root,4,crypto_hash_sha256_BYTES);
- assert(torrent_init(&torrent,TEST_DIRECTORY,TEST_DIRECTORY,16384)==1);
+ assert(torrent_init(&torrent,16384)==1);
+
+ torrent->root = strdup(TEST_DIRECTORY);
+ assert(torrent->root!=NULL);
+ torrent->name = strdup(TEST_DIRECTORY);
+ assert(torrent->name!=NULL);
assert(torrent_add(torrent,file1)==1);
assert(torrent_add(torrent,file2)==1);
const char infohash_expected[] = "267a5a34b592074f74287fc221a6cf64a3caad36377e57c5c5f64caea0527646";
const char torrent_file_hash_expected[] = "b39f0f4c88e8de4576d02969dfbefac0bbd6de2c9ab49109632e417f4ceb23ad";
- assert(torrent_init(&torrent_p,TEST_DIRECTORY,TEST_DIRECTORY,16384)==1);
+ assert(torrent_init(&torrent_p,16384)==1);
+
+ torrent_p->root = strdup(TEST_DIRECTORY);
+ assert(torrent_p->root!=NULL);
+ torrent_p->name = strdup(TEST_DIRECTORY);
+ assert(torrent_p->name!=NULL);
assert(1==file_init(&file_p,TEST_FILE_1));
assert(file_hash(file_p,16384)==1);
static void torrent_init_basic_test() {
struct torrent *torrent;
- assert(torrent_init(&torrent,NULL,NULL,0)<0);
- assert(torrent_init(&torrent,"src",NULL,0)<0);
- assert(torrent_init(&torrent,"src","src",1000)<0);
+ assert(torrent_init(&torrent,0)<0);
+ assert(torrent_init(&torrent,1000)<0);
- assert(torrent_init(&torrent,"src","src",16384)==1);
+ assert(torrent_init(&torrent,16384)==1);
torrent_free(torrent);
}
static void tree_bencode_basic_test();
static void tree_bencode_length_basic_test();
static void tree_init_basic_test();
+static void tree_length_basic_test();
int main() {
setup_env();
tree_add_extended_test();
tree_add_alphabetic_test();
tree_bencode_length_basic_test();
+ tree_length_basic_test();
clean_env();
tree_free(p);
}
+
+static void tree_length_basic_test() {
+ struct tree *p;
+ struct file *file;
+
+ assert(1==tree_init(&p));
+
+ assert(0==tree_length(p));
+
+ assert(1==file_init(&file,"test"));
+
+ assert(1==tree_add(p,file->path,file));
+ assert(1==tree_length(p));
+
+ assert(1==file_init(&file,"test2"));
+
+ assert(1==tree_add(p,file->path,file));
+ assert(2==tree_length(p));
+
+ tree_free(p);
+}