]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Sat, 15 Jan 2022 01:56:12 +0000 (17:56 -0800)
committeralex <[email protected]>
Sat, 15 Jan 2022 01:56:12 +0000 (17:56 -0800)
Makefile.am
inc/torrent.h
src/feed/entries.c
src/torrent/remove.c [new file with mode: 0644]
test/unit/feed.tests.c
test/unit/test_macros.h
test/unit/torrent.tests.c
test/unit/tree.tests.c

index 6a28b3c3fbd798d9d243f26f130ecd0477a858c5..2a45b3aaa52610e036e19452b787574068af91cd 100644 (file)
@@ -60,6 +60,7 @@ seederd_SOURCES = \
        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
index 69c3511d87a44a4e35124a7ce47103fccfcf94f1..76fd5e85189ab235e16c49af9321c9d9453ad58b 100644 (file)
@@ -41,5 +41,6 @@ int torrent_file_piece_layers(FILE*,struct torrent*);
 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
index e5f090c65c7388eb14cf213f8643f26639b35a4a..ec1fd01fe11096c3c5ab934761f8dea697d36b3f 100644 (file)
@@ -7,6 +7,9 @@ static int entry_default(struct rss_entry *entry, const char *feed_url, struct t
        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;
diff --git a/src/torrent/remove.c b/src/torrent/remove.c
new file mode 100644 (file)
index 0000000..70fbac3
--- /dev/null
@@ -0,0 +1,16 @@
+#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;
+}
index 19079f28a3661d3fda316e07fc3e8345cbbe5312..95f5c4d47efcd41a89eae796bdc406c768a4efeb 100644 (file)
@@ -56,7 +56,7 @@ static void feed_info_basic_test() {
        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));
 
index 9c9233faff6c807294a3a6ff6ee48b5eaf20bf51..3b52da65f91306e604632e5f453c2b026aa40756 100644 (file)
        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); \
index 4ae8528cb4668f78c170213e7a2c62b91a47c0b5..70792e487c5cb6b1c4e157e4d2ba6f7c715e975f 100644 (file)
@@ -43,7 +43,12 @@ static void torrent_add_basic_test() {
                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);
@@ -120,7 +125,12 @@ static void torrent_file_info_conformance_test() {
        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);
@@ -208,11 +218,10 @@ static void torrent_file_piece_layers_basic_test() {
 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);
 }
 
index c86529df91796cf92751490ec2ab23e0cf2f3072..cb169b348dd2b03fb93e0c7acc3235ff196af94b 100644 (file)
@@ -10,6 +10,7 @@ static void tree_add_extended_test();
 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();
@@ -20,6 +21,7 @@ int main() {
        tree_add_extended_test();
        tree_add_alphabetic_test();
        tree_bencode_length_basic_test();
+       tree_length_basic_test();
 
        clean_env();
 
@@ -267,3 +269,24 @@ static void tree_init_basic_test() {
 
        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);
+}