summaryrefslogtreecommitdiff
path: root/rtclient.c
diff options
context:
space:
mode:
authorErik Prabowo Kamal <erik@darapsa.co.id>2019-08-31 18:12:36 +0800
committerErik Prabowo Kamal <erik@darapsa.co.id>2019-08-31 18:12:36 +0800
commitf4f2546bad4ad3bffb2ffe8f561445c81dd2fda5 (patch)
tree2da3ddb55f2dcb254009221fbb0f1b25f54df435 /rtclient.c
parent169dd662e082b0102c32e0248097146378fd99a4 (diff)
Initialisation takes the server URL as a parameter
Diffstat (limited to 'rtclient.c')
-rw-r--r--rtclient.c15
1 files changed, 11 insertions, 4 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 <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();
}