diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-10-14 09:32:03 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-10-14 09:43:31 -0400 |
commit | 5a9688e9e78a25a42bddfc4388fb4ce3311ded74 (patch) | |
tree | bcc1b54c3f8a7f1eab0d6b3e129f098721a41537 /src/download.c | |
parent | b98088f7b7cfe4b08eb39fa1b6b86210cb6c08b8 (diff) | |
download | stasis-5a9688e9e78a25a42bddfc4388fb4ce3311ded74.tar.gz |
Refactor directory structure
* Move core library sources into src/lib/core
* Move command-line programs into src/cli
Diffstat (limited to 'src/download.c')
-rw-r--r-- | src/download.c | 61 |
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 |