From 7b649aee5d672b791b33a93a6dc9730c22e88068 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 21:44:51 +0800 Subject: Preparing the user function to return info --- rtclient.c | 22 +++++++++++++++++----- rtclient.h | 4 +++- rtuser.h | 24 ++++++++++++------------ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/rtclient.c b/rtclient.c index a66cd56..44088ec 100644 --- a/rtclient.c +++ b/rtclient.c @@ -11,6 +11,7 @@ #include #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) diff --git a/rtclient.h b/rtclient.h index dd3cb61..bdf6965 100644 --- a/rtclient.h +++ b/rtclient.h @@ -1,13 +1,15 @@ #ifndef RTCLIENT_H #define RTCLIENT_H +#include "rtuser.h" + #ifdef __cplusplus extern "C" { #endif bool rtclient_init(const char *server_url); void rtclient_login(const char *name, const char *password); - void rtclient_user(const char *name); + struct rt_user *rtclient_user(const char *name); void rtclient_search(const char *query); void rtclient_cleanup(); diff --git a/rtuser.h b/rtuser.h index dff3de0..9038a4a 100644 --- a/rtuser.h +++ b/rtuser.h @@ -1,28 +1,28 @@ #ifndef RTUSER_H #define RTUSER_H -typedef struct rt_user { - unsigned int id; - char *name; +struct rt_user { + char *id; char *password; - char *authtoken; + char *name; char *emailaddress; - char *organization; char *realname; char *nickname; - char *lang; char *gecos; - char *homephone; - char *workphone; - char *mobilephone; - char *pagerphone; + char *organization; char *address1; char *address2; char *city; char *state; char *zip; char *country; - char *timezone; -} rt_user; + char *homephone; + char *workphone; + char *mobilephone; + char *pagerphone; + char lang[2]; + bool privileged; + bool disabled; +}; #endif // RTUSER_H -- cgit v1.2.3