aboutsummaryrefslogtreecommitdiff
path: root/src/download.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2024-10-14 12:47:03 -0400
committerGitHub <noreply@github.com>2024-10-14 12:47:03 -0400
commitca762e2fd21266e6ed7b800d135e386c2ec48861 (patch)
tree48978ff793f2a969df196cfa7700100e5c82a2f5 /src/download.c
parent20a4c8c1707055c6d53265213f2a2d6b834aa037 (diff)
parent26000fb8e6cc08c227d4463de60e28881179e5cb (diff)
downloadstasis-ca762e2fd21266e6ed7b800d135e386c2ec48861.tar.gz
Merge pull request #61 from jhunkeler/restructure-the-world
Restructure the world
Diffstat (limited to 'src/download.c')
-rw-r--r--src/download.c61
1 files changed, 0 insertions, 61 deletions
diff --git a/src/download.c b/src/download.c
deleted file mode 100644
index f83adda..0000000
--- a/src/download.c
+++ /dev/null
@@ -1,61 +0,0 @@
-//
-// Created by jhunk on 10/5/23.
-//
-
-#include <string.h>
-#include <stdlib.h>
-#include "download.h"
-
-size_t download_writer(void *fp, size_t size, size_t nmemb, void *stream) {
- size_t bytes = fwrite(fp, size, nmemb, (FILE *) stream);
- return bytes;
-}
-
-long download(char *url, const char *filename, char **errmsg) {
- extern char *VERSION;
- CURL *c;
- CURLcode curl_code;
- long http_code = -1;
- FILE *fp;
- char user_agent[20];
- sprintf(user_agent, "stasis/%s", VERSION);
- long timeout = 30L;
- char *timeout_str = getenv("STASIS_DOWNLOAD_TIMEOUT");
-
- curl_global_init(CURL_GLOBAL_ALL);
- c = curl_easy_init();
- curl_easy_setopt(c, CURLOPT_URL, url);
- curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, download_writer);
- fp = fopen(filename, "wb");
- if (!fp) {
- return -1;
- }
-
- curl_easy_setopt(c, CURLOPT_VERBOSE, 0L);
- curl_easy_setopt(c, CURLOPT_FOLLOWLOCATION, 1L);
- curl_easy_setopt(c, CURLOPT_USERAGENT, user_agent);
- curl_easy_setopt(c, CURLOPT_NOPROGRESS, 0L);
- curl_easy_setopt(c, CURLOPT_WRITEDATA, fp);
-
- if (timeout_str) {
- timeout = strtol(timeout_str, NULL, 10);
- }
- curl_easy_setopt(c, CURLOPT_CONNECTTIMEOUT, timeout);
-
- curl_code = curl_easy_perform(c);
- if (curl_code != CURLE_OK) {
- if (errmsg) {
- strcpy(*errmsg, curl_easy_strerror(curl_code));
- } else {
- fprintf(stderr, "\nCURL ERROR: %s\n", curl_easy_strerror(curl_code));
- }
- goto failed;
- }
- curl_easy_getinfo(c, CURLINFO_RESPONSE_CODE, &http_code);
-
- failed:
- fclose(fp);
- curl_easy_cleanup(c);
- curl_global_cleanup();
- return http_code;
-} \ No newline at end of file