compiles, but not running properly
This commit is contained in:
parent
31f8509f42
commit
2d42313e8f
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
||||||
VERSION = 1.2.3
|
VERSION = 1.2.3
|
||||||
|
|
||||||
CFLAGS += -O2 -Wall -Wextra -Wshadow -fanalyzer -fsanitize=undefined \
|
CFLAGS += -O2 -g -Wall -Wextra -Wshadow -fanalyzer -fsanitize=undefined \
|
||||||
-Wno-analyzer-file-leak\
|
-Wno-analyzer-file-leak\
|
||||||
-rdynamic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\"\
|
-rdynamic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\"\
|
||||||
`pkg-config --cflags-only-I gumbo libcurl fuse uuid expat`
|
`pkg-config --cflags-only-I gumbo libcurl fuse uuid expat`
|
||||||
|
|
|
@ -89,7 +89,7 @@ static char *CacheSystem_calc_dir(const char *url)
|
||||||
|
|
||||||
void CacheSystem_init(const char *path, int url_supplied)
|
void CacheSystem_init(const char *path, int url_supplied)
|
||||||
{
|
{
|
||||||
if (pthread_mutex_init(&cf_lock, NULL)) {
|
if (pthread_mutex_lock(&cf_lock, NULL)) {
|
||||||
lprintf(fatal, "cf_lock initialisation failed!\n");
|
lprintf(fatal, "cf_lock initialisation failed!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -940,7 +940,7 @@ static void *Cache_bgdl(void *arg)
|
||||||
|
|
||||||
uint8_t *recv_buf = CALLOC(cf->blksz, sizeof(uint8_t));
|
uint8_t *recv_buf = CALLOC(cf->blksz, sizeof(uint8_t));
|
||||||
lprintf(debug, "thread %x spawned.\n ", pthread_self());
|
lprintf(debug, "thread %x spawned.\n ", pthread_self());
|
||||||
long recv = path_download(cf->fs_path, (char *) recv_buf, cf->blksz,
|
long recv = Link_download(cf->link, (char *) recv_buf, cf->blksz,
|
||||||
cf->next_dl_offset);
|
cf->next_dl_offset);
|
||||||
if (recv < 0) {
|
if (recv < 0) {
|
||||||
lprintf(error, "thread %x received %ld bytes, \
|
lprintf(error, "thread %x received %ld bytes, \
|
||||||
|
@ -1019,7 +1019,7 @@ Cache_read(Cache * cf, char *const output_buf, const off_t len,
|
||||||
|
|
||||||
uint8_t *recv_buf = CALLOC(cf->blksz, sizeof(uint8_t));
|
uint8_t *recv_buf = CALLOC(cf->blksz, sizeof(uint8_t));
|
||||||
lprintf(debug, "thread %x: spawned.\n ", pthread_self());
|
lprintf(debug, "thread %x: spawned.\n ", pthread_self());
|
||||||
long recv = path_download(cf->fs_path, (char *) recv_buf, cf->blksz,
|
long recv = Link_download(cf->link, (char *) recv_buf, cf->blksz,
|
||||||
dl_offset);
|
dl_offset);
|
||||||
if (recv < 0) {
|
if (recv < 0) {
|
||||||
lprintf(error, "thread %x received %ld bytes, \
|
lprintf(error, "thread %x received %ld bytes, \
|
||||||
|
|
41
src/link.c
41
src/link.c
|
@ -112,7 +112,7 @@ static void Link_req_file_stat(Link * this_link)
|
||||||
* We need to put the variable on the heap, because otherwise the
|
* We need to put the variable on the heap, because otherwise the
|
||||||
* variable gets popped from the stack as the function returns.
|
* variable gets popped from the stack as the function returns.
|
||||||
*
|
*
|
||||||
* It gets freed in curl_multi_perform_once();
|
* It gets freed in curl_process_msgs();
|
||||||
*/
|
*/
|
||||||
TransferStruct *transfer = CALLOC(1, sizeof(TransferStruct));
|
TransferStruct *transfer = CALLOC(1, sizeof(TransferStruct));
|
||||||
|
|
||||||
|
@ -435,10 +435,10 @@ void LinkTable_print(LinkTable * linktbl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TransferStruct Link_to_TransferStruct(Link * head_link)
|
TransferStruct Link_download_full(Link * link)
|
||||||
{
|
{
|
||||||
char *url = head_link->f_url;
|
char *url = link->f_url;
|
||||||
CURL *curl = Link_to_curl(head_link);
|
CURL *curl = Link_to_curl(link);
|
||||||
|
|
||||||
TransferStruct buf;
|
TransferStruct buf;
|
||||||
buf.size = 0;
|
buf.size = 0;
|
||||||
|
@ -468,7 +468,7 @@ TransferStruct Link_to_TransferStruct(Link * head_link)
|
||||||
}
|
}
|
||||||
while (HTTP_temp_failure(http_resp));
|
while (HTTP_temp_failure(http_resp));
|
||||||
|
|
||||||
curl_easy_getinfo(curl, CURLINFO_FILETIME, &(head_link->time));
|
curl_easy_getinfo(curl, CURLINFO_FILETIME, &(link->time));
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -494,7 +494,7 @@ LinkTable *LinkTable_new(const char *url)
|
||||||
/*
|
/*
|
||||||
* start downloading the base URL
|
* start downloading the base URL
|
||||||
*/
|
*/
|
||||||
TransferStruct buf = Link_to_TransferStruct(linktbl->links[0]);
|
TransferStruct buf = Link_download_full(linktbl->links[0]);
|
||||||
if (buf.size == 0) {
|
if (buf.size == 0) {
|
||||||
LinkTable_free(linktbl);
|
LinkTable_free(linktbl);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -793,23 +793,14 @@ Link *path_to_Link(const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
long
|
||||||
path_download(const char *path, char *output_buf, size_t req_size,
|
Link_download(Link *link, char *output_buf, size_t req_size,
|
||||||
off_t offset)
|
off_t offset)
|
||||||
{
|
{
|
||||||
if (!path) {
|
|
||||||
lprintf(fatal, "NULL path supplied\n");
|
|
||||||
}
|
|
||||||
Link *link;
|
|
||||||
link = path_to_Link(path);
|
|
||||||
if (!link) {
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t start = offset;
|
size_t start = offset;
|
||||||
size_t end = start + req_size;
|
size_t end = start + req_size;
|
||||||
char range_str[64];
|
char range_str[64];
|
||||||
snprintf(range_str, sizeof(range_str), "%lu-%lu", start, end);
|
snprintf(range_str, sizeof(range_str), "%lu-%lu", start, end);
|
||||||
lprintf(debug, "%s: %s\n", path, range_str);
|
lprintf(debug, "%s: %s\n", link->linkname, range_str);
|
||||||
|
|
||||||
TransferStruct buf;
|
TransferStruct buf;
|
||||||
buf.size = 0;
|
buf.size = 0;
|
||||||
|
@ -866,3 +857,19 @@ range requests\n");
|
||||||
|
|
||||||
return recv;
|
return recv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
path_download(const char *path, char *output_buf, size_t req_size,
|
||||||
|
off_t offset)
|
||||||
|
{
|
||||||
|
if (!path) {
|
||||||
|
lprintf(fatal, "NULL path supplied\n");
|
||||||
|
}
|
||||||
|
Link *link;
|
||||||
|
link = path_to_Link(path);
|
||||||
|
if (!link) {
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Link_download(link, output_buf, req_size, offset);
|
||||||
|
}
|
||||||
|
|
64
src/link.h
64
src/link.h
|
@ -33,6 +33,33 @@ typedef enum {
|
||||||
DATA = 'd'
|
DATA = 'd'
|
||||||
} TransferType;
|
} TransferType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief For storing transfer data and metadata
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
/** \brief The array to store the data */
|
||||||
|
char *data;
|
||||||
|
/** \brief The size of the array */
|
||||||
|
size_t size;
|
||||||
|
/** \brief The minium requested size */
|
||||||
|
size_t min_req_size;
|
||||||
|
/** \brief The type of transfer being done */
|
||||||
|
TransferType type;
|
||||||
|
/** \brief Whether transfer is in progress */
|
||||||
|
int transferring;
|
||||||
|
/** \brief The link associated with the transfer */
|
||||||
|
Link *link;
|
||||||
|
} TransferStruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief link table type
|
||||||
|
* \details index 0 contains the Link for the base URL
|
||||||
|
*/
|
||||||
|
struct LinkTable {
|
||||||
|
int num;
|
||||||
|
Link **links;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Link type data structure
|
* \brief Link type data structure
|
||||||
*/
|
*/
|
||||||
|
@ -51,35 +78,12 @@ struct Link {
|
||||||
long time;
|
long time;
|
||||||
/** \brief The pointer associated with the cache file */
|
/** \brief The pointer associated with the cache file */
|
||||||
Cache *cache_ptr;
|
Cache *cache_ptr;
|
||||||
|
/** \brief The pointer associated with the transfer struct */
|
||||||
|
TransferStruct *ts_ptr;
|
||||||
/** \brief Stores *sonic related data */
|
/** \brief Stores *sonic related data */
|
||||||
Sonic sonic;
|
Sonic sonic;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief link table type
|
|
||||||
* \details index 0 contains the Link for the base URL
|
|
||||||
*/
|
|
||||||
struct LinkTable {
|
|
||||||
int num;
|
|
||||||
Link **links;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** \brief For storing transfer data */
|
|
||||||
typedef struct {
|
|
||||||
/** \brief The array to store the data */
|
|
||||||
char *data;
|
|
||||||
/** \brief The size of the array */
|
|
||||||
size_t size;
|
|
||||||
/** \brief The minium requested size */
|
|
||||||
size_t min_req_size;
|
|
||||||
/** \brief The type of transfer being done */
|
|
||||||
TransferType type;
|
|
||||||
/** \brief Whether transfer is in progress */
|
|
||||||
int transferring;
|
|
||||||
/** \brief The link associated with the transfer */
|
|
||||||
Link *link;
|
|
||||||
} TransferStruct;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief root link table
|
* \brief root link table
|
||||||
*/
|
*/
|
||||||
|
@ -106,12 +110,18 @@ void Link_set_file_stat(Link * this_link, CURL * curl);
|
||||||
LinkTable *LinkTable_new(const char *url);
|
LinkTable *LinkTable_new(const char *url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief download a link
|
* \brief download a path
|
||||||
* \return the number of bytes downloaded
|
* \return the number of bytes downloaded
|
||||||
*/
|
*/
|
||||||
long path_download(const char *path, char *output_buf, size_t size,
|
long path_download(const char *path, char *output_buf, size_t size,
|
||||||
off_t offset);
|
off_t offset);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Download a Link
|
||||||
|
* \return the number of bytes downloaded
|
||||||
|
*/
|
||||||
|
long Link_download(Link *link, char *output_buf, size_t req_size, off_t offset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief find the link associated with a path
|
* \brief find the link associated with a path
|
||||||
*/
|
*/
|
||||||
|
@ -136,7 +146,7 @@ LinkTable *LinkTable_disk_open(const char *dirn);
|
||||||
* \brief Download a link's content to the memory
|
* \brief Download a link's content to the memory
|
||||||
* \warning You MUST free the memory field in TransferStruct after use!
|
* \warning You MUST free the memory field in TransferStruct after use!
|
||||||
*/
|
*/
|
||||||
TransferStruct Link_to_TransferStruct(Link * head_link);
|
TransferStruct Link_download_full(Link * head_link);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Allocate a LinkTable
|
* \brief Allocate a LinkTable
|
||||||
|
|
|
@ -18,7 +18,7 @@ typedef enum {
|
||||||
/**
|
/**
|
||||||
* \brief The default log level
|
* \brief The default log level
|
||||||
*/
|
*/
|
||||||
#define DEFAULT_LOG_LEVEL fatal | error | warning | info | debug
|
#define DEFAULT_LOG_LEVEL fatal | error | warning | info | debug | cache_lock_debug
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Get the log level from the environment.
|
* \brief Get the log level from the environment.
|
||||||
|
|
|
@ -163,9 +163,9 @@ void parse_config_file(char ***argv, int *argc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fclose(config);
|
||||||
}
|
}
|
||||||
FREE(full_path);
|
FREE(full_path);
|
||||||
fclose(config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -332,7 +332,7 @@ static LinkTable *sonic_url_to_LinkTable(const char *url,
|
||||||
/*
|
/*
|
||||||
* start downloading the base URL
|
* start downloading the base URL
|
||||||
*/
|
*/
|
||||||
TransferStruct xml = Link_to_TransferStruct(linktbl->links[0]);
|
TransferStruct xml = Link_download_full(linktbl->links[0]);
|
||||||
if (xml.size == 0) {
|
if (xml.size == 0) {
|
||||||
LinkTable_free(linktbl);
|
LinkTable_free(linktbl);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue