diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-07 21:44:51 +0800 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-07 21:44:51 +0800 |
commit | 7b649aee5d672b791b33a93a6dc9730c22e88068 (patch) | |
tree | ab901b1baf491c3655eb7a7ddd1cc022c80f848b /rtclient.c | |
parent | f7ba1ecac822d0fad68ef768016d96cf30b5e77e (diff) |
Preparing the user function to return info
Diffstat (limited to 'rtclient.c')
-rw-r--r-- | rtclient.c | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -11,6 +11,7 @@ #include <curl/curl.h> #include "rtclient.h" +typedef struct rt_user rt_user; static CURL *curl = NULL; static char *server_url = NULL; @@ -71,10 +72,18 @@ user_callback(void *contents, size_t size, size_t nmemb, void *writedata) char response[realsize + 1]; memcpy(&response[0], contents, realsize); response[realsize] = '\0'; - char *token = strtok(response, "\n"); - if (strstr(token, "200 Ok")) - while (token) - token = strtok(NULL, "\n"); + char *lines[21]; + char *line = strtok(response, "\n"); + if (strstr(line, "200 Ok")) { + rt_user *user = (rt_user *)writedata; + user = malloc(sizeof(rt_user)); + line = strtok(NULL, "\n"); + while (line) { + printf("Line:\n%s\n", line); + line = strtok(NULL, "\n"); + } + free(user); + } return realsize; } @@ -87,10 +96,13 @@ static inline void request(const char *path, const char *suffix) curl_easy_perform(curl); } -void rtclient_user(const char *name) +rt_user *rtclient_user(const char *name) { + rt_user *user = NULL; + curl_easy_setopt(curl, CURLOPT_WRITEDATA, user); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, user_callback); request("/REST/1.0/user/", name); + return user; } void rtclient_search(const char *query) |