From 5fe434e35b65a42bc365404a7a6c3436a2a99a8b 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: Thu, 12 Sep 2019 13:06:26 +0800 Subject: The user nullness can be tested now --- rtclient.c | 10 +++------- rtclient.h | 2 +- test.c | 8 +++++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/rtclient.c b/rtclient.c index a2d4554..1871377 100644 --- a/rtclient.c +++ b/rtclient.c @@ -149,11 +149,8 @@ user_callback(void *contents, size_t size, size_t nmemb, void *writedata) } } } else { -#ifdef DEBUG - fprintf(stderr, "Status: %s\n", line); -#endif - free(user); - user = NULL; + free(*userptr); + *userptr = NULL; } return realsize; @@ -210,11 +207,10 @@ void rtclient_login(const char *name, const char *password) post = NULL; } -bool rtclient_userget(rt_user **userptr, const char *name) +void rtclient_userget(rt_user **userptr, const char *name) { *userptr = malloc(sizeof(rt_user)); request("/REST/1.0/user/", name, user_callback, (void *)userptr, NULL); - return (bool)*userptr; } void rtclient_search(const char *query) diff --git a/rtclient.h b/rtclient.h index ec92d64..cf5062a 100644 --- a/rtclient.h +++ b/rtclient.h @@ -9,7 +9,7 @@ extern "C" { bool rtclient_init(const char *server_url); void rtclient_login(const char *name, const char *password); - bool rtclient_userget(struct rt_user **userptr, const char *name); + void rtclient_userget(struct rt_user **userptr, const char *name); void rtclient_search(const char *query); void rtclient_userfree(struct rt_user *user); void rtclient_cleanup(); diff --git a/test.c b/test.c index 43c034c..f0348ee 100644 --- a/test.c +++ b/test.c @@ -29,7 +29,10 @@ int main(void) free(pass); struct rt_user *user = NULL; - if (rtclient_userget(&user, name)) + rtclient_userget(&user, name); + free(name); + + if (user) { printf("id: %s\npassword: %s\nname: %s\nemailaddress: %s\nrealname: %s\nnickname: %s\ngecos: %s\norganization: %s\naddress1: %s\naddress2: %s\ncity: %s\nstate: %s\nzip: %s\ncountry: %s\nhomephone: %s\nworkphone: %s\nmobilephone: %s\npagerphone: %s\ncontactinfo: %s\ncomments: %s\nsignature: %s\nlang: %s\nprivileged: %d\ndisabled: %d\n" , user->id, user->password, user->name, user->emailaddress , user->realname, user->nickname, user->gecos @@ -39,9 +42,8 @@ int main(void) , user->pagerphone, user->contactinfo, user->comments , user->signature, user->lang, user->privileged , user->disabled); - free(name); - if (user) rtclient_userfree(user); + } rtclient_cleanup(); -- cgit v1.2.3