diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-12 13:06:26 +0800 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-12 13:06:26 +0800 |
commit | 5fe434e35b65a42bc365404a7a6c3436a2a99a8b (patch) | |
tree | 8e4775d124d42023aa3e2d43070b932114192a99 | |
parent | afcfe1bf43eab83357f88fc71ddeb9b0356fd3d0 (diff) |
The user nullness can be tested now
-rw-r--r-- | rtclient.c | 10 | ||||
-rw-r--r-- | rtclient.h | 2 | ||||
-rw-r--r-- | test.c | 8 |
3 files changed, 9 insertions, 11 deletions
@@ -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) @@ -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(); @@ -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(); |