]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Fri, 14 Jan 2022 02:15:43 +0000 (18:15 -0800)
committeralex <[email protected]>
Fri, 14 Jan 2022 02:15:43 +0000 (18:15 -0800)
Makefile.am
inc/opt.h
inc/torrent.h
src/default.c
src/init.c
src/opt/feed.c [new file with mode: 0644]
src/opt/set.c
src/opt/watch.c
src/torrent/free.c
src/torrent/init.c

index b790ce60fdb618555e7f7da3c337f4755166a7a8..6a28b3c3fbd798d9d243f26f130ecd0477a858c5 100644 (file)
@@ -34,6 +34,7 @@ seederd_SOURCES = \
        src/meta.c \
        src/opt/config.c \
        src/opt/env.c \
+       src/opt/feed.c \
        src/opt/filter.c \
        src/opt/loglevel.c \
        src/opt/out.c \
index 96cc4eaa15fd8342bd1ca1cc05e02fd4d83918a3..8c609002d33973b7219df51a3d7a79b1a6005fbd 100644 (file)
--- a/inc/opt.h
+++ b/inc/opt.h
@@ -16,10 +16,11 @@ enum file_filters {
 };
 
 struct options {
-       unsigned int worker_threads;
+       char *feed_url;
+       enum file_filters file_filter;
        unsigned long long piece_length;
        int verbose_flag;
-       enum file_filters file_filter;
+       unsigned int worker_threads;
 };
 
 extern struct options global_options;
@@ -44,6 +45,7 @@ int opt_add_watch(const char*);
 int opt_load_config_file(char*);
 int opt_load_from_env();
 int opt_set(const char*,const char*);
+int opt_set_feed_url(const char*);
 int opt_set_file_filter(const char*);
 void opt_set_log_level(enum log_level);
 int opt_set_out_stream(const char*);
index eb9d89af393eed57678bf6d267baf64a2673c072..69c3511d87a44a4e35124a7ce47103fccfcf94f1 100644 (file)
@@ -39,7 +39,7 @@ ssize_t torrent_file_info(struct torrent*,uint8_t**);
 char *torrent_file_path(unsigned char*,size_t);
 int torrent_file_piece_layers(FILE*,struct torrent*);
 void torrent_free(struct torrent*);
-int torrent_init(struct torrent**,const char*,const char*,unsigned long long);
+int torrent_init(struct torrent**,unsigned long long);
 char *torrent_magnet(struct torrent*);
 
 #endif
index f40cc9d341a6678c824795a3552a4f05efbde48d..cdcf59d4b7e5ca5541b41e3939fc728f41f467fe 100644 (file)
@@ -5,7 +5,9 @@ struct options global_options;
 static int default_add_all_directories();
 
 int defaults() {
-       // logging needs to be setup first
+       // setting logging thread to the current thread so messages
+       // will be printed asap (also logging thread will not
+       // have been created yet).
        logging_thread = pthread_self();
 
        log_info(DEFAULT_MESSAGE_SETTING_DEFAULTS);
@@ -13,6 +15,8 @@ int defaults() {
        // suppress output temporarily
        opt_set_log_level(LOG_LEVEL_SILENT);
 
+       if(opt_set_feed_url("")<0) { return -1; }
+       if(opt_set_file_filter("default")<0) { return -1; }
        if(opt_set_piece_length("16384")<0) { return -1; }
        
        {
@@ -21,7 +25,6 @@ int defaults() {
                if(opt_set_worker_threads(buf)<0) { return -1; }
        }
 
-       if(opt_set_file_filter("default")<0) { return -1; }
 
        // restore logging output       
 #ifndef NDEBUG
index ee405a33be650e79e666a29ca2859f1ee2509d38..4da9b66b431851cd1c11865793da0bb668cb4216 100644 (file)
@@ -6,6 +6,7 @@
 struct option long_options[] = {
        {"config-file", required_argument, 0, 'c'},
        {"daemon", no_argument, 0, 'd'},
+       {"feed-url", required_argument, 0, 'u'},
        {"file-filter", required_argument, 0, 'f'},
        {"help", no_argument, 0, 'h'},
        {"log-file", required_argument, 0, 'l'},
@@ -29,7 +30,7 @@ int init(int argc, char **argv) {
        while(1) {
                int option_index = 0;
 
-               if((c = getopt_long(argc,argv,"c:df:hl:qvw:",long_options,&option_index))==-1) { break; }
+               if((c = getopt_long(argc,argv,"c:df:hl:qu:vw:",long_options,&option_index))==-1) { break; }
 
                switch(c) {
                        case 1:
@@ -54,6 +55,9 @@ int init(int argc, char **argv) {
                        case 'q':
                                opt_set_log_level(LOG_LEVEL_SILENT);
                                break;
+                       case 'u':
+                               if(opt_set_feed_url(optarg)<0) { return -1; }
+                               break;
                        case 'v':
                                opt_set_log_level(LOG_LEVEL_VERBOSE);
                                break;
diff --git a/src/opt/feed.c b/src/opt/feed.c
new file mode 100644 (file)
index 0000000..4d2e913
--- /dev/null
@@ -0,0 +1,12 @@
+#include<opt.h>
+
+int opt_set_feed_url(const char *url) {
+       if(NULL==url) { return -1; }
+
+       if(global_options.feed_url!=NULL) { free(global_options.feed_url); }
+
+       global_options.feed_url = strdup(url);
+       if(NULL==global_options.feed_url) { return -1; }
+
+       return 1;
+}
index 6059b443df2f291bff7a82cecdff18be76c7b466..25d7f02f8caf4e50b625670a612acce8182b3869 100644 (file)
@@ -8,6 +8,7 @@ struct option_lookup_table_entry {
 // NOTE: see src/init.c for list of CLI options
 
 struct option_lookup_table_entry option_lookup_table[] = {
+       {"feed_url",&opt_set_feed_url},
        {"file_filter",&opt_set_file_filter},
        {"piece_length",&opt_set_piece_length},
        {"watch_directory",&opt_add_watch},
index e4842b15b4ddefb984dcf76579dc534c125f4e65..2eb864417046e670fea6af604504db93ebb68561 100644 (file)
@@ -9,13 +9,29 @@ int opt_add_watch(const char *directory) {
                return -1;
        }
 
+
        name = strdup(directory);
+       if(NULL==name) { return -1; }
        name = basename(name);
 
-       if(torrent_init(&p,directory,name,global_options.piece_length)<0) { return -1; }
-       if(session_torrent_add(p)<0) { return -1; }
+       if(torrent_init(&p,global_options.piece_length)<0) { return -1; }
+
+       p->root = strdup(directory);
+       if(NULL==p->root) { goto clean; }
+
+       p->name = strdup(name);
+       if(NULL==p->name) { goto clean; }
+       free(name);
+
+       p->feed_url = strdup(global_options.feed_url);
+       if(NULL==p->feed_url) { goto clean; }
+
+       if(session_torrent_add(p)<0) { goto clean; }
 
        log_msg(OPT_MESSAGE_WATCH_ADD_SUCCESS,p->root,p->name);
 
        return 1;
+clean:
+       torrent_free(p);
+       return -1;
 }
index 3905e669c1c6af6ab6f1b840cd9e167ec29b11c3..abf64936f75149f7437894caafb4d475df574aa5 100644 (file)
@@ -5,6 +5,7 @@ void torrent_free(struct torrent *p) {
 
        if(p->root!=NULL) { free(p->root); }
        if(p->name!=NULL) { free(p->name); }
+       if(p->feed_url!=NULL) { free(p->feed_url); }
        
        // clear first, tree_free will also free files
        hashmap_clear(p->files.paths);
index 6b631f975d75e610f5c2c7edfd60c4a7ee8a1b55..c15a110a95da7678d1e69a4da4fb8b0e555faa62 100644 (file)
@@ -2,10 +2,8 @@
 
 #define TORRENT_FILES_HASHMAP_INITIAL_SIZE 8
 
-int torrent_init(struct torrent **torrent_p, const char *root, const char *name, unsigned long long piece_length) {
+int torrent_init(struct torrent **torrent_p, unsigned long long piece_length) {
        if(NULL==torrent_p) { return -1; }
-       if(NULL==root) { return -1; }
-       if(NULL==name) { return -1; }
 
        if((piece_length<16384)||(!(piece_length&&!(piece_length&(piece_length-1))))) { return -1; }
 
@@ -15,12 +13,9 @@ int torrent_init(struct torrent **torrent_p, const char *root, const char *name,
                return -1;
        }
 
-       (*torrent_p)->root = strdup(root);
-       if(NULL==(*torrent_p)->root) { goto clean; }
-
-       (*torrent_p)->name = strdup(name);
-       if(NULL==(*torrent_p)->name) { goto clean; }
-
+       (*torrent_p)->root = NULL;
+       (*torrent_p)->name = NULL;
+       (*torrent_p)->feed_url = NULL;
        (*torrent_p)->piece_length = piece_length;
 
        if(tree_init(&((*torrent_p)->tree))<0) { goto clean; }