From 3cc0e54e13432387622d4f9815c150865ed87ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Sat, 7 Sep 2019 18:14:42 +0800 Subject: Started parsing user properties retrieval into tokens --- rtclient.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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); } -- cgit v1.2.3