summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-14 07:22:00 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-14 07:22:00 +0800
commit4ccd288909c6a9f1fe47ae72744ffba6f0ef410e (patch)
treee050c2649fb54354884660ec3b4f0333375072d6
parente9561a9bd14469edab70886d98e050bfe054a3eb (diff)
A function to free ticket list and its tickets
-rw-r--r--rtclient.c10
-rw-r--r--rtclient.h3
-rw-r--r--test.c7
3 files changed, 13 insertions, 7 deletions
diff --git a/rtclient.c b/rtclient.c
index dfdd1c1..ea8811a 100644
--- a/rtclient.c
+++ b/rtclient.c
@@ -252,7 +252,7 @@ void rtclient_userget(rt_user **userptr, const char *name)
request("/REST/1.0/user/", name, user_callback, (void *)userptr, NULL);
}
-void rtclient_search(rt_ticketlist **listptr, const char *query)
+void rtclient_ticketssearch(rt_ticketlist **listptr, const char *query)
{
*listptr = malloc(sizeof(rt_ticketlist));
request("/REST/1.0/search/ticket?query=", query, search_callback
@@ -286,6 +286,14 @@ void rtclient_userfree(rt_user *user)
user = NULL;
}
+void rtclient_ticketsfree(rt_ticketlist *list)
+{
+ for (unsigned short i = 0; i < list->length; i++)
+ free(list->tickets[i]);
+ free(list);
+ list = NULL;
+}
+
void rtclient_cleanup()
{
if (curl) {
diff --git a/rtclient.h b/rtclient.h
index df96f3e..e53591b 100644
--- a/rtclient.h
+++ b/rtclient.h
@@ -11,8 +11,9 @@ extern "C" {
bool rtclient_init(const char *server_url);
void rtclient_login(const char *name, const char *password);
void rtclient_userget(struct rt_user **userptr, const char *name);
- void rtclient_search(struct rt_ticketlist **listptr, const char *query);
+ void rtclient_ticketssearch(struct rt_ticketlist **listptr, const char *query);
void rtclient_userfree(struct rt_user *user);
+ void rtclient_ticketsfree(struct rt_ticketlist *list);
void rtclient_cleanup();
#ifdef __cplusplus
diff --git a/test.c b/test.c
index f7fca73..9be48dc 100644
--- a/test.c
+++ b/test.c
@@ -47,16 +47,13 @@ int main(void)
static const char *prefix = "Owner='";
char query[strlen(prefix) + strlen(name) + 2];
sprintf(query, "%s%s'", prefix, name);
- rtclient_search(&list, query);
+ rtclient_ticketssearch(&list, query);
if (list) {
- printf("List length = %d\n", list->length);
for (unsigned short i = 0; i < list->length; i++) {
char *ticket = list->tickets[i];
printf("Ticket %d: %s\n", i, ticket);
- if (ticket)
- free(ticket);
}
- free(list);
+ rtclient_ticketsfree(list);
}
}
free(name);