From 316a8686aac06ca326c65e624559a8f7ae8b73f1 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: Sun, 8 Sep 2019 23:04:41 +0800 Subject: Functions to get user info and to free it --- rtclient.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'rtclient.c') diff --git a/rtclient.c b/rtclient.c index 90a0863..2d12314 100644 --- a/rtclient.c +++ b/rtclient.c @@ -5,9 +5,8 @@ #include #endif // ANDROID #endif // DEBUG -#include -#include #include +#include #include #include "rtclient.h" @@ -83,8 +82,8 @@ user_callback(void *contents, size_t size, size_t nmemb, void *writedata) lines[i++] = line; line = strtok(NULL, "\n"); } - rt_user *user = (rt_user *)writedata; - user = malloc(sizeof(rt_user)); + rt_user **userp = (rt_user **)writedata; + rt_user *user = *userp; for (unsigned short i = 0; i < nproperties; i++) { char *token = strtok(lines[i], ":"); if (!strcmp(token, "id")) { @@ -182,7 +181,6 @@ user_callback(void *contents, size_t size, size_t nmemb, void *writedata) user->disabled = (bool)atoi(++token); } } - free(user); } return realsize; @@ -197,13 +195,13 @@ static inline void request(const char *path, const char *suffix) curl_easy_perform(curl); } -rt_user *rtclient_user(const char *name) +bool rtclient_get_user(rt_user **user, const char *name) { - rt_user *user = NULL; - curl_easy_setopt(curl, CURLOPT_WRITEDATA, user); + *user = malloc(sizeof(rt_user)); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)user); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, user_callback); request("/REST/1.0/user/", name); - return user; + return (bool)(*user); } void rtclient_search(const char *query) @@ -211,6 +209,32 @@ void rtclient_search(const char *query) request("/REST/1.0/search/ticket?query=", query); } +void rtclient_user_free(rt_user *user) +{ + free(user->id); + free(user->password); + free(user->name); + free(user->emailaddress); + free(user->realname); + free(user->nickname); + free(user->gecos); + free(user->organization); + free(user->address1); + free(user->address2); + free(user->city); + free(user->state); + free(user->zip); + free(user->country); + free(user->homephone); + free(user->workphone); + free(user->mobilephone); + free(user->pagerphone); + free(user->contactinfo); + free(user->comments); + free(user->signature); + free(user); +} + void rtclient_cleanup() { if (curl) { -- cgit v1.2.3