...
authoralex <[email protected]>
Sun, 16 Jan 2022 01:50:39 +0000 (17:50 -0800)
committeralex <[email protected]>
Sun, 16 Jan 2022 01:50:39 +0000 (17:50 -0800)
src/default.c
src/opt/config.c
src/opt/piecel.c
src/opt/watch.c
src/opt/worker.c
test/unit/Makefile.am
test/unit/meta.tests.c
test/unit/opt.tests.c

index cdcf59d4b7e5ca5541b41e3939fc728f41f467fe..9ac4b16fdc307b7dc389995b8d60d1908eea247a 100644 (file)
@@ -52,19 +52,21 @@ static int default_add_all_directories() {
                if(strcmp(ent->d_name,".")==0) { continue; }
                if(strcmp(ent->d_name,"..")==0) { continue; }
 
-               p = malloc(sizeof(char)*(strlen(PREFIX)+strlen(ent->d_name)+1));
-               if(NULL==p) {
-                       perror("malloc");
-                       return -1;
-               }
+               if(ent->d_type==DT_DIR) {
+                       p = malloc(sizeof(char)*(strlen(PREFIX)+strlen(ent->d_name)+1));
+                       if(NULL==p) {
+                               perror("malloc");
+                               return -1;
+                       }
+
+                       sprintf(p,PREFIX "/%s",ent->d_name);
+                       if(opt_add_watch(p)<0) {
+                               free(p);
+                               return -1;
+                       }
 
-               sprintf(p,PREFIX "/%s",ent->d_name);
-               if(opt_add_watch(p)<0) {
                        free(p);
-                       return -1;
                }
-
-               free(p);
        }
 
        closedir(dir);
index 863ac561019cf9a06011fd53822d517325385d8f..fdab188493e2917bbc484545de8ac4cba378cc5d 100644 (file)
@@ -6,6 +6,8 @@ int opt_load_config_file(char *path) {
        char buf[1024];
        int line, i;
 
+       if(NULL==path) { return -1; }
+
        log_info(OPT_MESSAGE_LOADING_CONFIG_FILE,path);
 
        fp = fopen(path,"r");
index 3c6dac252825bae2ed567efec447238dfdc66f86..1aa8f8a42089bb9596849aef2fb3d04f7c495c8f 100644 (file)
@@ -4,6 +4,8 @@ int opt_set_piece_length(const char *length) {
        char *end;
        unsigned long long i;
 
+       if(NULL==length) { return -1; }
+
        i = strtoull(length,&end,10);
 
        if((i<16384)||(!(i&&!(i&(i-1))))) {
index 2eb864417046e670fea6af604504db93ebb68561..fe2c05609bcba1f8ae583d01b1d8dd6c8f936010 100644 (file)
@@ -4,12 +4,13 @@ int opt_add_watch(const char *directory) {
        struct torrent *p;
        char *name;
 
-       if(!is_directory(directory)) {
+       if(NULL==directory) { return -1; }
+
+       if(is_directory(directory)<0) {
                log_err(OPT_MESSAGE_WATCH_INVALID_DIRECTORY,directory);
                return -1;
        }
 
-
        name = strdup(directory);
        if(NULL==name) { return -1; }
        name = basename(name);
index d830d76ddd72b21a66120fa5468e1ebc7881374e..9f70aab13165a52b79a6ccd188c9aa480dad359a 100644 (file)
@@ -3,6 +3,8 @@
 int opt_set_worker_threads(const char *str) {
        char *end;
 
+       if(NULL==str) { return -1; }
+
        global_options.worker_threads = strtoul(str,&end,10);
        if(0==global_options.worker_threads) {
                log_err(OPT_MESSAGE_WORKER_THREADS_INVALID,str);
index 49cd59e873c8bd49b844127030f7288af24b0b18..dd21f44616b39600aec15c80583ca98477e742b6 100644 (file)
@@ -130,7 +130,8 @@ opt_tests_SOURCES = \
        $(top_srcdir)/src/opt/piecel.c \
        $(top_srcdir)/src/opt/set.c \
        $(top_srcdir)/src/opt/watch.c \
-       $(top_srcdir)/src/opt/worker.c
+       $(top_srcdir)/src/opt/worker.c \
+       $(top_srcdir)/src/session.c
 
 opt_tests_CPPFLAGS = $(AM_CPPFLAGS) \
        -DTORRENT_INFO_SRC_FILE="$(top_srcdir)/src/torrent/info.c"
index 495d06cc4ec923dca0e391f094022b82bd06383f..fe2ce6053bb11cf1249a2343a3296eebc48395cf 100644 (file)
@@ -10,9 +10,11 @@ char *strptime(const char *s, const char *format, struct tm *tm) {
 
 int main();
 static void meta_entry_basic_test();
+static void meta_entry_overwrite_test();
 static void meta_escape_basic_test();
 static void meta_escape_length_test();
 static void meta_info_basic_test();
+static void meta_info_overwrite_test();
 static void meta_search_basic_test();
 
 int main() {
@@ -24,7 +26,9 @@ int main() {
        meta_search_basic_test();
 
        meta_entry_basic_test();
+       meta_entry_overwrite_test();
        meta_info_basic_test();
+       meta_info_overwrite_test();
 
        clean_env();
 
@@ -52,15 +56,27 @@ static void meta_entry_basic_test() {
 
        assert(meta_entry(TEST_FILE_1,entry)==1);
 
+       // pub_date is skipped because of strptime issue
+       // (had to be mocked because of compilation issue during testing)
        assert(strcmp(entry->title,"test title")==0);
        assert(strcmp(entry->link,"https://whatisarealink.com")==0);
-//     assert(strcmp(entry->pub_date,"")==0);
        assert(strcmp(entry->description,"I wonder if \n this'll properly be formatted/escaped \\&gt;&lt;?")==0);
        assert(strcmp(entry->guid,"magnet=asldkfjsldkfjslkdjfldsdjlfkjsdf")==0);
 
        rss_entry_free(entry);
 }
 
+static void meta_entry_overwrite_test() {
+       struct rss_entry *entry;
+       
+       assert(1==rss_entry_init(&entry));
+       
+       assert(meta_entry(TEST_FILE_1,entry)==1);
+       assert(meta_entry(TEST_FILE_1,entry)==1);
+       
+       rss_entry_free(entry);
+}
+
 static void meta_escape_length_test() {
        char buf[10];
 
@@ -138,15 +154,27 @@ static void meta_info_basic_test() {
        
        assert(meta_info(PREFIX,info)==1);
 
+       // last_build_date is skipped because of strptime issue
+       // (had to be mocked because of compilation issue during testing)
        assert(strcmp(info->title,"TITLE")==0);
        assert(strcmp(info->link,"http://test.com")==0);
        assert(strcmp(info->description,"what is a description")==0);
        assert(strcmp(info->language,"en-us")==0);
-//     assert(strcmp(info->last_build_date,"")==0);
 
        rss_channel_info_free(info);
 }
 
+static void meta_info_overwrite_test() {
+       struct rss_channel_info *info;
+
+       assert(rss_channel_info_init(&info)==1);
+       
+       assert(meta_info(PREFIX,info)==1);
+       assert(meta_info(PREFIX,info)==1);
+       
+       rss_channel_info_free(info);
+}
+
 static void meta_search_basic_test() {
        FILE *fp;
        fp = meta_search(NULL);
index 821dd0ff4086994d99892680e5b22702e5e24a2a..70a95b373298336c3c241af1da79037c8dab9967 100644 (file)
@@ -2,8 +2,6 @@
 
 #include<opt.h>
 
-int session_torrent_add(struct torrent *p) { return 1; }
-
 #include INCLUDE(TORRENT_INFO_SRC_FILE)
 
 pthread_t logging_thread;
@@ -77,6 +75,7 @@ static void opt_add_watch_basic_test() {
        assert(-1==opt_add_watch(NULL));
        assert(-1==opt_add_watch("notarealexistingdirectorylksdjflkajsdfklajsklf"));
        
+       opt_set_log_level(LOG_LEVEL_SILENT);
        assert(1==opt_add_watch(TEST_DIRECTORY));
 
        assert(1==defaults());