diff options
author | Erik Prabowo Kamal <erik@darapsa.co.id> | 2019-08-30 18:52:32 +0800 |
---|---|---|
committer | Erik Prabowo Kamal <erik@darapsa.co.id> | 2019-08-30 18:52:32 +0800 |
commit | 16b8e66c64ee8acd6ea2ce34372e52406a990d2a (patch) | |
tree | b3dfd8b7eb9e30bbe43fb0a3c0bd6ba1cec5908f | |
parent | 89cd9ab12cb2aa09f92e312cd0418a036dc0ed8d (diff) |
Managed to post login credentials to the RT server
For now, it's just to get a response
-rw-r--r-- | rtclient.c | 44 | ||||
-rw-r--r-- | rtclient.h | 1 |
2 files changed, 45 insertions, 0 deletions
@@ -25,6 +25,50 @@ bool rtclient_init() return (bool)handle; } +static size_t handle_login(const char *response, size_t size, size_t nmemb, void *writedata) +{ +#ifdef DEBUG +#ifdef ANDROID + __android_log_print(ANDROID_LOG_DEBUG, "libkelakon.so", "Login response:\n%s", response); +#else + fprintf(stderr, "Login response:\n%s\n", response); +#endif // ANDROID +#endif // DEBUG + return size * nmemb; +} + +void rtclient_login(const char *name, const char *password) +{ + struct curl_httppost *post, *last = NULL; + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "user", + CURLFORM_PTRCONTENTS, name, + CURLFORM_END); + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "pass", + CURLFORM_PTRCONTENTS, password, + CURLFORM_END); + last = NULL; + + curl_easy_setopt(handle, CURLOPT_URL, "https://darapsa.co.id/rt"); + curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, handle_login); + curl_easy_setopt(handle, CURLOPT_HTTPPOST, post); +#ifdef DEBUG + CURLcode res = +#endif // DEBUG + curl_easy_perform(handle); +#ifdef DEBUG + if (res != CURLE_OK) { + const char *error = curl_easy_strerror(res); +#ifdef ANDROID + __android_log_print(ANDROID_LOG_ERROR, "libkelakon.so", "cURL perform error: %s", error); +#else + fprintf(stderr, "cURL perform error: %s\n", error); +#endif // ANDROID + } +#endif // DEBUG +} + void rtclient_cleanup() { if (handle) @@ -6,6 +6,7 @@ extern "C" { #endif bool rtclient_init(); + void rtclient_login(const char *name, const char *password); void rtclient_cleanup(); #ifdef __cplusplus |