]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Sun, 5 Sep 2021 23:14:16 +0000 (16:14 -0700)
committeralex <[email protected]>
Sun, 5 Sep 2021 23:14:16 +0000 (16:14 -0700)
16 files changed:
Makefile.am
inc/add.h [new file with mode: 0644]
inc/default.h
inc/opt.h
inc/setup.h
inc/torrent.h [new file with mode: 0644]
inc/util.h [new file with mode: 0644]
src/add.c [new file with mode: 0644]
src/default.c
src/opt/env.c
src/opt/piecel.c
src/opt/watch.c
src/setup.c
src/torrent.c [new file with mode: 0644]
src/util/dir.c [new file with mode: 0644]
src/util/file.c [new file with mode: 0644]

index 37671894a9a24fad782a0211611cb81938357b01..2fb2ad54f0dd0c2f02be64229c4d0220f4a80e7d 100644 (file)
@@ -11,21 +11,29 @@ endif
 bin_PROGRAMS = seederd
 
 seederd_SOURCES = \
+       src/add.c \
        src/default.c \
        src/log.c \
        src/main.c \
        src/opt/config.c \
        src/opt/env.c \
        src/opt/loglevel.c \
+       src/opt/piecel.c \
        src/opt/set.c \
        src/opt/watch.c \
        src/setup.c \
-       src/usage.c
+       src/torrent.c \
+       src/usage.c \
+       src/util/dir.c \
+       src/util/file.c
 
 seederd_SOURCES += \
+       inc/add.h \
        inc/default.h \
        inc/log.h \
        inc/main.h \
        inc/opt.h \
        inc/setup.h \
-       inc/usage.h
+       inc/torrent.h \
+       inc/usage.h \
+       inc/util.h
diff --git a/inc/add.h b/inc/add.h
new file mode 100644 (file)
index 0000000..3d8e699
--- /dev/null
+++ b/inc/add.h
@@ -0,0 +1,8 @@
+#ifndef __ADD_H_
+#define __ADD_H_
+
+#include<log.h>
+
+void *add(void*);
+
+#endif
index 5d2669745082ec14a649fa0e7ef3f0a0767da670..4b43a4c1658110662bce8e99a0972d6c3ca907e4 100644 (file)
@@ -4,6 +4,8 @@
 #include<log.h>
 #include<opt.h>
 
+#define DEFAULT_MESSAGE_SETTING_DEFAULTS "setting default values\n"
+
 int defaults();
 
 #endif
index 1188d2f0c06e6bf064299d86d3cab48c2c906b9c..b3506d2a8de45255ee421ed407321e6d8df0b985 100644 (file)
--- a/inc/opt.h
+++ b/inc/opt.h
@@ -2,12 +2,16 @@
 #define __OPT_H_
 
 #include<string.h>
-#include<sys/stat.h>
 
 #include<log.h>
+#include<torrent.h>
+#include<util.h>
 
 #define OPT_MESSAGE_CONFIG_FILE_FORMAT_ERROR "invalid format in config file %s:%d\n"
+#define OPT_MESSAGE_ENV_LOADING "loading settings from environment\n"
 #define OPT_MESSAGE_LOADING_CONFIG_FILE "loading config file %s\n"
+#define OPT_MESSAGE_PIECE_LENGTH_INVALID "invalid piece length of %llu\npiece length must be >16384 and a power of 2\n"
+#define OPT_MESSAGE_PIECE_LENGTH_SET "piece length set to %llu\n"
 #define OPT_MESSAGE_UNABLE_OPEN_FILE "unable to open file %s\n"
 #define OPT_MESSAGE_UNKNOWN_OPTION "unknown option %s\n"
 #define OPT_MESSAGE_WATCH_ADD_SUCCESS "watching %s\n"
index bcf246ae0cba7e49214892ed6e2f592f9cbf04ad..8d5d5260223405cae4dc7f3347d428fc1149cbdd 100644 (file)
@@ -1,9 +1,11 @@
 #ifndef __SETUP_H_
 #define __SETUP_H_
 
+#include<add.h>
 #include<log.h>
 
 int setup();
+int setup_adding();
 int setup_logging();
 
 #endif
diff --git a/inc/torrent.h b/inc/torrent.h
new file mode 100644 (file)
index 0000000..21ab327
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __TORRENT_H_
+#define __TORRENT_H_
+
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+
+struct torrent {
+       char *root;
+};
+
+void torrent_free(struct torrent*);
+int torrent_init(struct torrent**,char*);
+
+#endif
diff --git a/inc/util.h b/inc/util.h
new file mode 100644 (file)
index 0000000..4d5febb
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __UTIL_H_
+#define __UTIL_H_
+
+#include<stdio.h>
+#include<sys/stat.h>
+
+int is_directory(char*);
+int is_file(char*);
+
+#endif
diff --git a/src/add.c b/src/add.c
new file mode 100644 (file)
index 0000000..84984b1
--- /dev/null
+++ b/src/add.c
@@ -0,0 +1,5 @@
+#include<add.h>
+
+void *add(void *p) {
+       return NULL;
+}
index 21896cb551a10891930066ece29189f93ec20a93..cbc4a2dedc26fb27361823a95df56a472f814c22 100644 (file)
@@ -1,6 +1,7 @@
 #include<default.h>
 
 int defaults() {
+       // logging needs to be setup first
        logging_thread = pthread_self();
 
 #ifndef NDEBUG
@@ -8,6 +9,11 @@ int defaults() {
 #else
        opt_set_log_level(LOG_LEVEL_DEFAULT);
 #endif
+       // end logging section
+
+       log_info(DEFAULT_MESSAGE_SETTING_DEFAULTS);
+
+       opt_set_piece_length("16384");
        
        return 1;
 }
index 0537777fc7ce752017a1cbd2406b4583168b4909..4ec76dbaeb8149db8b48d0967d3876af6db87748 100644 (file)
@@ -12,6 +12,8 @@
 int opt_load_from_env() {
        char *p;
 
+       log_info(OPT_MESSAGE_ENV_LOADING);
+
        CHECK_ENV("CONFIG",opt_load_config_file);
        CHECK_ENV("PIECE_LENGTH",opt_set_piece_length);
 
index 3636b57e283d602e89f171f0d6f8787ed92fbc04..1b5ba7dc7336388bc66583a68a7d47eab2d277d8 100644 (file)
@@ -1,5 +1,16 @@
 #include<opt.h>
 
 int opt_set_piece_length(char *length) {
+       char *end;
+       unsigned long long i;
+
+       i = strtoull(length,&end,10);
+
+       if((i<16384)||(!(i&&!(i&(i-1))))) {
+               log_err(OPT_MESSAGE_PIECE_LENGTH_INVALID,i);
+               return -1;
+       }
+
+       log_info(OPT_MESSAGE_PIECE_LENGTH_SET,i);
        return -1;
 }
index 1734b05a20b84435289db484d9cf5df7a448ce0b..320f9371c0c2b24815c046979f0548a05c2c8449 100644 (file)
@@ -1,21 +1,17 @@
 #include<opt.h>
 
 int opt_add_watch(char *directory) {
-       struct stat st;
-
-       if(stat(directory,&st)!=0) {
-               perror("stat");
+       struct torrent *p;
+       if(!is_directory(directory)) {
                log_err(OPT_MESSAGE_WATCH_INVALID_DIRECTORY,directory);
                return -1;
        }
 
-       if(!S_ISDIR(st.st_mode)) {
-               log_err(OPT_MESSAGE_WATCH_INVALID_DIRECTORY,directory);
-               return -1;
-       }
+       if(torrent_init(&p,directory)<0) { return -1; }
+       torrent_free(p);
 
        log_msg(OPT_MESSAGE_WATCH_ADD_SUCCESS,directory);
 
        log_err("not implemented\n");
-       return 1;
+       return -1;
 }
index 44851a8daf1aaa5df92cfc3f2e70e291a0721885..f7621e126421dd8fec7f4b6e1844b1e8c1d704aa 100644 (file)
@@ -3,6 +3,18 @@
 
 int setup() {
        if(setup_logging()<0) { return -1; }
+       if(setup_adding()<0) { return -1; }
+       return 1;
+}
+
+pthread_t adding_thread;
+
+int setup_adding() {
+       if(pthread_create(&adding_thread,NULL,&add,NULL)!=0) {
+               perror("pthread_create");
+               return -1;
+       }
+
        return 1;
 }
 
diff --git a/src/torrent.c b/src/torrent.c
new file mode 100644 (file)
index 0000000..7f78130
--- /dev/null
@@ -0,0 +1,24 @@
+#include<torrent.h>
+
+void torrent_free(struct torrent *p) {
+       free(p->root);
+       free(p);
+}
+
+int torrent_init(struct torrent **p, char *root) {
+       *p = malloc(sizeof(struct torrent));
+       if(NULL==(*p)) {
+               perror("malloc");
+               return -1;
+       }
+
+       (*p)->root = malloc(strlen(root)+1);
+       if(NULL==(*p)->root) {
+               perror("malloc");
+               free(*p);
+               return -1;
+       }
+       strcpy((*p)->root,root);
+
+       return 1;
+}
diff --git a/src/util/dir.c b/src/util/dir.c
new file mode 100644 (file)
index 0000000..07d324b
--- /dev/null
@@ -0,0 +1,15 @@
+#include<util.h>
+
+int is_directory(char *path) {
+       struct stat st;
+       
+       if(stat(path,&st)!=0) {
+               perror("stat");
+               return -1;
+       }
+
+
+       if(!S_ISDIR(st.st_mode)) { return -1; }
+
+       return 1;
+}
diff --git a/src/util/file.c b/src/util/file.c
new file mode 100644 (file)
index 0000000..4fcbe59
--- /dev/null
@@ -0,0 +1,14 @@
+#include<util.h>
+
+int is_file(char *path) {
+       struct stat st;
+
+       if(stat(path,&st)!=0) {
+               perror("stat");
+               return -1;
+       }
+
+       if(!S_ISREG(st.st_mode)) { return -1; }
+
+       return 1;
+}