aboutsummaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c54
1 files changed, 18 insertions, 36 deletions
diff --git a/src/net.c b/src/net.c
index bacfc8b..b435f4d 100644
--- a/src/net.c
+++ b/src/net.c
@@ -8,25 +8,25 @@
#include "net.h"
#include "common.h"
-
+
size_t memoryCallback(void* contents, size_t size, size_t nmemb, void* userp)
{
- size_t realsize = size * nmemb;
- struct MemoryStruct* mem = (struct MemoryStruct*)userp;
-
- uint8_t* ptr = realloc(mem->memory, mem->size + realsize + 1);
- if(ptr == NULL) {
- /* out of memory! */
- puts("out of memory");
- return 0;
- }
-
- mem->memory = ptr;
- memcpy(&(mem->memory[mem->size]), contents, realsize);
- mem->size += realsize;
- mem->memory[mem->size] = 0;
-
- return realsize;
+ size_t realsize = size * nmemb;
+ struct MemoryStruct* mem = (struct MemoryStruct*)userp;
+
+ uint8_t* ptr = realloc(mem->memory, mem->size + realsize + 1);
+ if(ptr == NULL)
+ {
+ puts("out of memory");
+ return 0;
+ }
+
+ mem->memory = ptr;
+ memcpy(&(mem->memory[mem->size]), contents, realsize);
+ mem->size += realsize;
+ mem->memory[mem->size] = 0;
+
+ return realsize;
}
struct MemoryStruct* downloadToRam(const char* URL)
@@ -75,24 +75,6 @@ struct MemoryStruct* downloadToRam(const char* URL)
return chunk;
}
-void downloadFile(const char* URL, const char* path)
-{
- struct MemoryStruct* chunk = downloadToRam(URL);
-
- if (chunk)
- {
- FILE* file = fopen(path, "wb");
- if (file)
- {
- fwrite(chunk->memory, chunk->size, 1, file);
- fclose(file);
- }
-
- free(chunk->memory);
- free(chunk);
- }
-}
-
struct json_object* fetchJSON(const char* URL)
{
struct MemoryStruct* chunk = downloadToRam(URL);
@@ -109,4 +91,4 @@ struct json_object* fetchJSON(const char* URL)
}
return json;
-} \ No newline at end of file
+}