diff options
author | Erik Prabowo Kamal <erik@darapsa.co.id> | 2019-08-31 18:12:36 +0800 |
---|---|---|
committer | Erik Prabowo Kamal <erik@darapsa.co.id> | 2019-08-31 18:12:36 +0800 |
commit | f4f2546bad4ad3bffb2ffe8f561445c81dd2fda5 (patch) | |
tree | 2da3ddb55f2dcb254009221fbb0f1b25f54df435 | |
parent | 169dd662e082b0102c32e0248097146378fd99a4 (diff) |
Initialisation takes the server URL as a parameter
-rw-r--r-- | rtclient.c | 15 | ||||
-rw-r--r-- | rtclient.h | 2 |
2 files changed, 12 insertions, 5 deletions
@@ -6,12 +6,15 @@ #endif // ANDROID #endif // DEBUG #include <stdbool.h> +#include <string.h> +#include <stdlib.h> #include <curl/curl.h> #include "rtclient.h" static CURL *handle = NULL; +static char *server_url = NULL; -bool rtclient_init() +bool rtclient_init(const char *url) { curl_global_init(CURL_GLOBAL_SSL); handle = curl_easy_init(); @@ -19,7 +22,9 @@ bool rtclient_init() curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L); #ifdef DEBUG curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L); -#endif +#endif // DEBUG + server_url = malloc(strlen(url) + 1); + strcpy(server_url, url); } return (bool)handle; @@ -50,7 +55,7 @@ void rtclient_login(const char *name, const char *password) CURLFORM_END); last = NULL; - curl_easy_setopt(handle, CURLOPT_URL, "https://darapsa.co.id/rt"); + curl_easy_setopt(handle, CURLOPT_URL, server_url); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, handle_login); curl_easy_setopt(handle, CURLOPT_HTTPPOST, post); #ifdef DEBUG @@ -71,7 +76,9 @@ void rtclient_login(const char *name, const char *password) void rtclient_cleanup() { - if (handle) + if (handle) { + free(server_url); curl_easy_cleanup(handle); + } curl_global_cleanup(); } @@ -5,7 +5,7 @@ extern "C" { #endif - bool rtclient_init(); + bool rtclient_init(const char *server_url); void rtclient_login(const char *name, const char *password); void rtclient_cleanup(); |