summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-12 13:06:26 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-12 13:06:26 +0800
commit5fe434e35b65a42bc365404a7a6c3436a2a99a8b (patch)
tree8e4775d124d42023aa3e2d43070b932114192a99
parentafcfe1bf43eab83357f88fc71ddeb9b0356fd3d0 (diff)
The user nullness can be tested now
-rw-r--r--rtclient.c10
-rw-r--r--rtclient.h2
-rw-r--r--test.c8
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();