factored out network / root link table initialisation code
This commit is contained in:
parent
dec32b0bb4
commit
ed8452a4a3
2
Makefile
2
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
|
||||
|
||||
|
|
29
src/link.c
29
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)
|
||||
|
|
|
@ -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
|
||||
|
|
14
src/main.c
14
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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
// }
|
||||
|
|
Loading…
Reference in New Issue