diff --git a/Makefile b/Makefile index 3e6e6d5..8ecc903 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CFLAGS+= -O2 -Wall -Wextra -Wshadow -rdynamic\ -D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\" \ `pkg-config --cflags-only-I gumbo libcurl fuse uuid` LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -luuid -COBJS = main.o network.o fuse_local.o link.o cache.o util.o sonic.o +COBJS = network.o fuse_local.o link.o cache.o util.o main.o prefix ?= /usr/local diff --git a/src/link.c b/src/link.c index fbd897a..41aba74 100644 --- a/src/link.c +++ b/src/link.c @@ -26,13 +26,40 @@ int ROOT_LINK_OFFSET = 0; */ static pthread_mutex_t link_lock; -void link_system_init() +LinkTable *LinkSystem_init(const char *url) { if (pthread_mutex_init(&link_lock, NULL) != 0) { fprintf(stderr, "link_system_init(): link_lock initialisation failed!\n"); exit_failure(); } + + /* --------- Set the length of the root link ----------- */ + /* This is where the '/' should be */ + ROOT_LINK_OFFSET = strnlen(url, MAX_PATH_LEN) - 1; + if (url[ROOT_LINK_OFFSET] != '/') { + /* + * If '/' is not there, it is automatically added, so we need to skip 2 + * characters + */ + ROOT_LINK_OFFSET += 2; + } else { + /* If '/' is there, we need to skip it */ + ROOT_LINK_OFFSET += 1; + } + + /* ----------- Enable cache system --------------------*/ + if (NETWORK_CONFIG.cache_enabled) { + if (NETWORK_CONFIG.cache_dir) { + CacheSystem_init(NETWORK_CONFIG.cache_dir, 0); + } else { + CacheSystem_init(url, 1); + } + } + + /* ----------- Create the root link table --------------*/ + ROOT_LINK_TBL = LinkTable_new(url); + return ROOT_LINK_TBL; } static void LinkTable_add(LinkTable *linktbl, Link *link) diff --git a/src/link.h b/src/link.h index 1779fc3..50fbd37 100644 --- a/src/link.h +++ b/src/link.h @@ -93,7 +93,7 @@ extern int ROOT_LINK_OFFSET; /** * \brief initialise link sub-system. */ -void link_system_init(); +LinkTable *LinkSystem_init(const char *url); /** * \brief Add a link to the curl multi bundle for querying stats diff --git a/src/main.c b/src/main.c index 2bf379f..3d399a3 100644 --- a/src/main.c +++ b/src/main.c @@ -35,11 +35,11 @@ int main(int argc, char **argv) /*--- FUSE expects the first initialisation to be the program's name ---*/ add_arg(&fuse_argv, &fuse_argc, argv[0]); - /* initialise link subsystem */ - link_system_init(); - /* initialise network configuration struct */ - network_config_init(); + NetworkConfig_init(); + + /* initialise network subsystem */ + NetworkSystem_init(); /* parse the config file, if it exists, store it in all_argv and all_argc */ parse_config_file(&all_argv, &all_argc); @@ -51,6 +51,10 @@ int main(int argc, char **argv) /* parse the combined argument list */ if (parse_arg_list(all_argc, all_argv, &fuse_argv, &fuse_argc)) { + /* + * The user basically didn't supply enough arguments, if we reach here + * The point is to print some error messages + */ goto fuse_start; } @@ -64,7 +68,7 @@ int main(int argc, char **argv) print_help(argv[0], 0); exit(EXIT_FAILURE); } else { - if(!network_init(base_url)) { + if(!LinkSystem_init(base_url)) { fprintf(stderr, "Error: Network initialisation failed.\n"); exit(EXIT_FAILURE); } diff --git a/src/network.c b/src/network.c index 0f6f8fe..ea59800 100644 --- a/src/network.c +++ b/src/network.c @@ -158,7 +158,7 @@ static void curl_process_msgs(CURLMsg *curl_msg, int n_running_curl, * \details effectively based on * https://curl.haxx.se/libcurl/c/multi-double.html */ -int curl_multi_perform_once() +int curl_multi_perform_once(void) { #ifdef NETWORK_LOCK_DEBUG fprintf(stderr, @@ -231,7 +231,7 @@ int curl_multi_perform_once() return n_running_curl; } -void network_config_init() +void NetworkConfig_init(void) { NETWORK_CONFIG.username = NULL; NETWORK_CONFIG.password = NULL; @@ -244,7 +244,7 @@ void network_config_init() NETWORK_CONFIG.cache_dir = NULL; } -LinkTable *network_init(const char *url) +void NetworkSystem_init(void) { /* ------- Global related ----------*/ if (curl_global_init(CURL_GLOBAL_ALL)) { @@ -297,33 +297,6 @@ LinkTable *network_init(const char *url) /* --------- Print off SSL engine version stream --------- */ curl_version_info_data *data = curl_version_info(CURLVERSION_NOW); fprintf(stderr, "libcurl SSL engine: %s\n", data->ssl_version); - - /* --------- Set the length of the root link ----------- */ - /* This is where the '/' should be */ - ROOT_LINK_OFFSET = strnlen(url, MAX_PATH_LEN) - 1; - if (url[ROOT_LINK_OFFSET] != '/') { - /* - * If '/' is not there, it is automatically added, so we need to skip 2 - * characters - */ - ROOT_LINK_OFFSET += 2; - } else { - /* If '/' is there, we need to skip it */ - ROOT_LINK_OFFSET += 1; - } - - /* ----------- Enable cache system --------------------*/ - if (NETWORK_CONFIG.cache_enabled) { - if (NETWORK_CONFIG.cache_dir) { - CacheSystem_init(NETWORK_CONFIG.cache_dir, 0); - } else { - CacheSystem_init(url, 1); - } - } - - /* ----------- Create the root link table --------------*/ - ROOT_LINK_TBL = LinkTable_new(url); - return ROOT_LINK_TBL; } void transfer_blocking(CURL *curl) diff --git a/src/network.h b/src/network.h index 9eb1894..ac76ad7 100644 --- a/src/network.h +++ b/src/network.h @@ -46,13 +46,13 @@ extern NetworkConfigStruct NETWORK_CONFIG; extern CURLSH *CURL_SHARE; /** \brief perform one transfer cycle */ -int curl_multi_perform_once(); +int curl_multi_perform_once(void); /** \brief initialise network config struct */ -void network_config_init(); +void NetworkConfig_init(void); /** \brief initialise the network module */ -LinkTable *network_init(const char *url); +void NetworkSystem_init(void); /** \brief blocking file transfer */ void transfer_blocking(CURL *curl); diff --git a/src/sonic.c b/src/sonic.c index d011543..4977ea1 100644 --- a/src/sonic.c +++ b/src/sonic.c @@ -88,6 +88,8 @@ LinkTable *sonic_LinkTable_new(const int id) url = sonic_gen_url_first_part("getIndexes"); } + printf("%s\n", url); + LinkTable *linktbl = LinkTable_alloc(url); /* start downloading the base URL */ @@ -110,6 +112,10 @@ LinkTable *sonic_LinkTable_new(const int id) // (void) argv; // // sonic_config_init(argv[1], argv[2], argv[3]); +// +// link_system_init(); +// network_config_init(); +// // sonic_LinkTable_new(0); // sonic_LinkTable_new(3); // }