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 \
};
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;
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*);
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
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);
// 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; }
{
if(opt_set_worker_threads(buf)<0) { return -1; }
}
- if(opt_set_file_filter("default")<0) { return -1; }
// restore logging output
#ifndef NDEBUG
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'},
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:
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;
--- /dev/null
+#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;
+}
// 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},
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;
}
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);
#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; }
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; }