From f4f2546bad4ad3bffb2ffe8f561445c81dd2fda5 Mon Sep 17 00:00:00 2001 From: Erik Prabowo Kamal Date: Sat, 31 Aug 2019 18:12:36 +0800 Subject: Initialisation takes the server URL as a parameter --- rtclient.c | 15 +++++++++++---- rtclient.h | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/rtclient.c b/rtclient.c index 0022103..4567430 100644 --- a/rtclient.c +++ b/rtclient.c @@ -6,12 +6,15 @@ #endif // ANDROID #endif // DEBUG #include +#include +#include #include #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(); } diff --git a/rtclient.h b/rtclient.h index dfeea5b..228c141 100644 --- a/rtclient.h +++ b/rtclient.h @@ -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(); -- cgit v1.2.3