Merged transfer status struct and transfer data struct

This commit is contained in:
Fufu Fang 2021-09-01 11:56:18 +01:00
parent a76366c481
commit 464c8e4863
6 changed files with 26 additions and 27 deletions

View File

@ -1,7 +1,7 @@
VERSION = 1.2.3
CFLAGS += -O2 -Wall -Wextra -Wshadow -rdynamic -D_GNU_SOURCE\
-D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\"\
CFLAGS += -O2 -Wall -Wextra -Wshadow -fsanitize=undefined -rdynamic\
-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\"\
`pkg-config --cflags-only-I gumbo libcurl fuse uuid expat`
LDFLAGS += `pkg-config --libs-only-L gumbo libcurl fuse uuid expat`
LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -lexpat

View File

@ -113,7 +113,7 @@ static void Link_req_file_stat(Link * this_link)
*
* It gets freed in curl_multi_perform_once();
*/
TransferStatusStruct *transfer = CALLOC(1, sizeof(TransferStatusStruct));
TransferStruct *transfer = CALLOC(1, sizeof(TransferStruct));
transfer->link = this_link;
transfer->type = FILESTAT;
@ -434,12 +434,12 @@ void LinkTable_print(LinkTable * linktbl)
}
}
TransferDataStruct Link_to_TransferDataStruct(Link * head_link)
TransferStruct Link_to_TransferStruct(Link * head_link)
{
char *url = head_link->f_url;
CURL *curl = Link_to_curl(head_link);
TransferDataStruct buf;
TransferStruct buf;
buf.size = 0;
buf.data = NULL;
@ -493,7 +493,7 @@ LinkTable *LinkTable_new(const char *url)
/*
* start downloading the base URL
*/
TransferDataStruct buf = Link_to_TransferDataStruct(linktbl->links[0]);
TransferStruct buf = Link_to_TransferStruct(linktbl->links[0]);
if (buf.size == 0) {
LinkTable_free(linktbl);
return NULL;
@ -810,7 +810,7 @@ path_download(const char *path, char *output_buf, size_t req_size,
snprintf(range_str, sizeof(range_str), "%lu-%lu", start, end);
lprintf(debug, "%s: %s\n", path, range_str);
TransferDataStruct buf;
TransferStruct buf;
buf.size = 0;
buf.data = NULL;
@ -818,7 +818,7 @@ path_download(const char *path, char *output_buf, size_t req_size,
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &buf);
curl_easy_setopt(curl, CURLOPT_RANGE, range_str);
TransferDataStruct header;
TransferStruct header;
header.size = 0;
header.data = NULL;
curl_easy_setopt(curl, CURLOPT_HEADERDATA, (void *) &header);

View File

@ -23,6 +23,12 @@ typedef enum {
LINK_UNINITIALISED_FILE = 'U'
} LinkType;
/** \brief specify the type of data transfer */
typedef enum {
FILESTAT = 's',
DATA = 'd'
} TransferType;
/** \brief For storing transfer data */
typedef struct {
/** \brief The array to store the data */
@ -31,20 +37,13 @@ typedef struct {
size_t size;
/** \brief The minium requested size */
size_t min_req_size;
} TransferDataStruct;
/** \brief specify the type of data transfer */
typedef enum {
FILESTAT = 's',
DATA = 'd'
} TransferType;
/** \brief For storing transfer status and metadata */
typedef struct {
/** \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;
} TransferStatusStruct;
} TransferStruct;
/**
* \brief link table type
@ -147,9 +146,9 @@ LinkTable *LinkTable_disk_open(const char *dirn);
/**
* \brief Download a link's content to the memory
* \warning You MUST free the memory field in TransferDataStruct after use!
* \warning You MUST free the memory field in TransferStruct after use!
*/
TransferDataStruct Link_to_TransferDataStruct(Link * head_link);
TransferStruct Link_to_TransferStruct(Link * head_link);
/**
* \brief Allocate a LinkTable

View File

@ -144,11 +144,11 @@ void parse_config_file(char ***argv, int *argc)
char *space;
space = strchr(buf, ' ');
if (!space) {
*argv = realloc(*argv, *argc * sizeof(char **));
*argv = realloc(*argv, *argc * sizeof(char *));
(*argv)[*argc - 1] = strndup(buf, buf_len);
} else {
(*argc)++;
*argv = realloc(*argv, *argc * sizeof(char **));
*argv = realloc(*argv, *argc * sizeof(char *));
/*
* Only copy up to the space character
*/

View File

@ -117,7 +117,7 @@ curl_process_msgs(CURLMsg * curl_msg, int n_running_curl, int n_mesgs)
(void) n_mesgs;
static volatile int slept = 0;
if (curl_msg->msg == CURLMSG_DONE) {
TransferStatusStruct *transfer;
TransferStruct *transfer;
CURL *curl = curl_msg->easy_handle;
curl_easy_getinfo(curl_msg->easy_handle, CURLINFO_PRIVATE,
&transfer);
@ -311,7 +311,7 @@ void transfer_blocking(CURL * curl)
* We don't need to malloc here, as the transfer is finished before
* the variable gets popped from the stack
*/
volatile TransferStatusStruct transfer;
volatile TransferStruct transfer;
transfer.type = DATA;
transfer.transferring = 1;
curl_easy_setopt(curl, CURLOPT_PRIVATE, &transfer);
@ -357,7 +357,7 @@ write_memory_callback(void *contents, size_t size, size_t nmemb,
void *userp)
{
size_t realsize = size * nmemb;
TransferDataStruct *mem = (TransferDataStruct *) userp;
TransferStruct *mem = (TransferStruct *) userp;
mem->data = realloc(mem->data, mem->size + realsize + 1);
if (!mem->data) {

View File

@ -332,7 +332,7 @@ static LinkTable *sonic_url_to_LinkTable(const char *url,
/*
* start downloading the base URL
*/
TransferDataStruct xml = Link_to_TransferDataStruct(linktbl->links[0]);
TransferStruct xml = Link_to_TransferStruct(linktbl->links[0]);
if (xml.size == 0) {
LinkTable_free(linktbl);
return NULL;