diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2023-01-25 21:16:56 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2023-01-25 21:16:56 +0800 |
commit | 0e8e63c8199417d9c920e1a6b9a2a90ef4e595de (patch) | |
tree | c66419605cbfaa0a54ef71dea7049b4f755202c9 | |
parent | 39390f76cb75cfd5830495301cb08221e7934d5b (diff) |
Writes/reads to/from a cookie file
-rw-r--r-- | interchange.c | 13 | ||||
-rw-r--r-- | interchange.h | 4 | ||||
-rw-r--r-- | request.c | 4 |
3 files changed, 17 insertions, 4 deletions
diff --git a/interchange.c b/interchange.c index a8ba970..5219474 100644 --- a/interchange.c +++ b/interchange.c @@ -8,6 +8,7 @@ char *image_dir; emscripten_fetch_attr_t attr; #else char *sampleurl; +char *cookiefile = NULL; char *cainfo = NULL; #endif @@ -15,7 +16,8 @@ char *cainfo = NULL; extern void handle_results(interchange_response *); #endif -void interchange_init(const char *url, const char *dir, const char *certificate) +void interchange_init(const char *url, const char *dir, const char *cookie, + const char *certificate) { image_dir = malloc(strlen(dir) + 1); strcpy(image_dir, dir); @@ -30,6 +32,10 @@ void interchange_init(const char *url, const char *dir, const char *certificate) if (append) strcat(sampleurl, "/"); curl_global_init(CURL_GLOBAL_SSL); + if (cookie) { + cookiefile = malloc(strlen(cookie) + 1); + strcpy(cookiefile, cookie); + } if (certificate) { cainfo = malloc(strlen(certificate) + 1); strcpy(cainfo, certificate); @@ -106,7 +112,10 @@ void interchange_cleanup() { free(image_dir); #ifndef __EMSCRIPTEN__ - free(cainfo); + if (cainfo) + free(cainfo); + if (cookiefile) + free(cookiefile); free(sampleurl); curl_global_cleanup(); #endif diff --git a/interchange.h b/interchange.h index 91a2222..7503edf 100644 --- a/interchange.h +++ b/interchange.h @@ -40,9 +40,11 @@ extern "C" { * \brief A function that needs to be run first. * \param sampleurl The value of the SAMPLEURL setting in products/variable.txt. * \param image_dir The value of the IMAGE_DIR setting in products/variable.txt. + * \param certificate Path to the cookie file. * \param certificate Path to the CA certificate file. */ -void interchange_init(const char *sampleurl, const char *image_dir, const char *certificate); +void interchange_init(const char *sampleurl, const char *image_dir, + const char *cookie, const char *certificate); /*! * \brief For fetching data about products that belong a specific group. @@ -18,6 +18,7 @@ extern emscripten_fetch_attr_t attr; extern char *sampleurl; extern char *cainfo; +extern char *cookiefile; struct container { struct curl_httppost *post; @@ -148,7 +149,8 @@ void request(void (*handler)(interchange_response *), void (*callback)(void *), #else CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); + curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookiefile); + curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookiefile); if (cainfo) curl_easy_setopt(curl, CURLOPT_CAINFO, cainfo); #ifdef DEBUG |