diff --git a/Makefile b/Makefile index 757c835..d7aac7e 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ CFLAGS += -g -O2 -Wall -Wextra -Wshadow \ LDFLAGS += `pkg-config --libs-only-L gumbo libcurl fuse uuid expat` LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -lexpat COBJS = main.o network.o fuse_local.o link.o cache.o util.o sonic.o log.o\ - config.o + config.o ramcache.o OS := $(shell uname) ifeq ($(OS),Darwin) diff --git a/src/link.c b/src/link.c index 27dc58d..e7e98fe 100644 --- a/src/link.c +++ b/src/link.c @@ -1,6 +1,7 @@ #include "link.h" #include "log.h" +#include "ramcache.h" #include "util.h" #include diff --git a/src/network.c b/src/network.c index 64c0792..395591d 100644 --- a/src/network.c +++ b/src/network.c @@ -1,6 +1,7 @@ #include "network.h" #include "log.h" +#include "ramcache.h" #include "util.h" #include @@ -315,26 +316,6 @@ void transfer_nonblocking(CURL *curl) } } -size_t write_memory_callback(void *recv_data, size_t size, size_t nmemb, - void *userp) -{ - size_t recv_size = size * nmemb; - TransferStruct *ts = (TransferStruct *) userp; - - ts->data = realloc(ts->data, ts->curr_size + recv_size + 1); - if (!ts->data) { - /* - * out of memory! - */ - lprintf(fatal, "realloc failure!\n"); - } - - memmove(&ts->data[ts->curr_size], recv_data, recv_size); - ts->curr_size += recv_size; - ts->data[ts->curr_size] = '\0'; - return recv_size; -} - int HTTP_temp_failure(HTTPResponseCode http_resp) { switch (http_resp) { diff --git a/src/network.h b/src/network.h index c97dcc4..eead3c9 100644 --- a/src/network.h +++ b/src/network.h @@ -12,34 +12,6 @@ typedef struct TransferStruct TransferStruct; #include -/** - * \brief specify the type of data transfer - */ -typedef enum { - FILESTAT = 's', - DATA = 'd' -} TransferType; - -/** - * \brief For storing transfer data and metadata - */ -struct TransferStruct { - /** \brief The array to store the data */ - char *data; - /** \brief The current size of the array */ - size_t curr_size; - /** \brief The type of transfer being done */ - TransferType type; - /** \brief Whether transfer is in progress */ - volatile int transferring; - /** \brief The link associated with the transfer */ - Link *link; - /** \brief The minium requested size */ - size_t min_req_size; - /** \brief Whether we have sent off the minimally requested data*/ - int min_data_sent; -}; - /** \brief HTTP response codes */ typedef enum { HTTP_OK = 200, @@ -65,11 +37,6 @@ void transfer_blocking(CURL *curl); /** \brief non blocking file transfer */ void transfer_nonblocking(CURL *curl); -/** \brief callback function for file transfer */ -size_t -write_memory_callback(void *contents, size_t size, size_t nmemb, - void *userp); - /** * \brief check if a HTTP response code corresponds to a temporary failure */ diff --git a/src/ramcache.c b/src/ramcache.c new file mode 100644 index 0000000..1750ce2 --- /dev/null +++ b/src/ramcache.c @@ -0,0 +1,26 @@ +#include "ramcache.h" + +#include "log.h" + +#include +#include + +size_t write_memory_callback(void *recv_data, size_t size, size_t nmemb, + void *userp) +{ + size_t recv_size = size * nmemb; + TransferStruct *ts = (TransferStruct *) userp; + + ts->data = realloc(ts->data, ts->curr_size + recv_size + 1); + if (!ts->data) { + /* + * out of memory! + */ + lprintf(fatal, "realloc failure!\n"); + } + + memmove(&ts->data[ts->curr_size], recv_data, recv_size); + ts->curr_size += recv_size; + ts->data[ts->curr_size] = '\0'; + return recv_size; +} \ No newline at end of file diff --git a/src/ramcache.h b/src/ramcache.h new file mode 100644 index 0000000..33cada1 --- /dev/null +++ b/src/ramcache.h @@ -0,0 +1,37 @@ +#ifndef RAMCACHE_H +#define RAMCACHE_H +#include "link.h" + +/** + * \brief specify the type of data transfer + */ +typedef enum { + FILESTAT = 's', + DATA = 'd' +} TransferType; + +/** + * \brief For storing transfer data and metadata + */ +struct TransferStruct { + /** \brief The array to store the data */ + char *data; + /** \brief The current size of the array */ + size_t curr_size; + /** \brief The type of transfer being done */ + TransferType type; + /** \brief Whether transfer is in progress */ + volatile int transferring; + /** \brief The link associated with the transfer */ + Link *link; + /** \brief The minium requested size */ + size_t min_req_size; + /** \brief Whether we have sent off the minimally requested data*/ + int min_data_sent; +}; + +/** \brief callback function for file transfer */ +size_t write_memory_callback(void *contents, size_t size, size_t nmemb, + void *userp); + +#endif \ No newline at end of file diff --git a/src/sonic.c b/src/sonic.c index 144cf75..8366d96 100644 --- a/src/sonic.c +++ b/src/sonic.c @@ -3,7 +3,7 @@ #include "config.h" #include "log.h" #include "link.h" - +#include "ramcache.h" #include "util.h" #include