summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-07 18:14:42 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-07 18:14:42 +0800
commit3cc0e54e13432387622d4f9815c150865ed87ae6 (patch)
treebcb7c5e27eab3f3b4a78a1f94da5e93d6d1b0828
parent3143fc2733736a52ed94e07827993fe32be90ff3 (diff)
Started parsing user properties retrieval into tokens
-rw-r--r--rtclient.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/rtclient.c b/rtclient.c
index f109e8e..b2199a0 100644
--- a/rtclient.c
+++ b/rtclient.c
@@ -47,6 +47,7 @@ void rtclient_login(const char *name, const char *password)
curl_easy_setopt(curl, CURLOPT_URL, server_url);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
#ifdef DEBUG
CURLcode res =
#endif // DEBUG
@@ -63,6 +64,27 @@ void rtclient_login(const char *name, const char *password)
#endif // DEBUG
}
+static size_t
+user_callback(void *contents, size_t size, size_t nmemb, void *writedata)
+{
+ size_t realsize = size * nmemb;
+ char response[realsize + 1];
+ memcpy(&response[0], contents, realsize);
+ response[realsize] = '\0';
+ char *token = strtok(response, "\n");
+ while (token) {
+#ifdef DEBUG
+#ifdef ANDROID
+ __android_log_print(ANDROID_LOG_ERROR, "librtclient.so", "Token:\n %s", token);
+#else
+ fprintf(stderr, "Token:\n%s\n", token);
+#endif // ANDROID
+#endif // DEBUG
+ token = strtok(NULL, "\n");
+ }
+ return realsize;
+}
+
static inline void request(const char *path, const char *suffix)
{
char url[strlen(server_url) + strlen(path) + strlen(suffix) + 1];
@@ -74,6 +96,7 @@ static inline void request(const char *path, const char *suffix)
void rtclient_user(const char *name)
{
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, user_callback);
request("/REST/1.0/user/", name);
}