From f9e3eb4c9cf83d724d510f20391ab8f88f68fd71 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: Wed, 2 Oct 2019 12:51:17 +0800 Subject: Ticket history function takes format argument --- rtclient/ticket.h | 9 ++++++++- ticket.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/rtclient/ticket.h b/rtclient/ticket.h index 104f811..9aaf656 100644 --- a/rtclient/ticket.h +++ b/rtclient/ticket.h @@ -6,6 +6,12 @@ struct rtclient_ticket { char *subject; }; +enum rtclient_ticket_result_format { + RTCLIENT_TICKET_RESULT_FORMAT_S = 0 + , RTCLIENT_TICKET_RESULT_FORMAT_I + , RTCLIENT_TICKET_RESULT_FORMAT_L +}; + enum rtclient_ticket_history_type { RTCLIENT_TICKET_HISTORY_TYPE_UNKNOWN = 0 , RTCLIENT_TICKET_HISTORY_TYPE_CREATE @@ -71,7 +77,8 @@ extern "C" { , const char *due , const char *text); void rtclient_ticket_history(struct rtclient_ticket_history_list **listptr - , unsigned int id); + , unsigned int id + , enum rtclient_ticket_result_format result_format); void rtclient_ticket_history_free (struct rtclient_ticket_history *history); void rtclient_ticket_history_list_free diff --git a/ticket.c b/ticket.c index 990fc9c..658df7f 100644 --- a/ticket.c +++ b/ticket.c @@ -40,7 +40,29 @@ void rtclient_ticket_new(const char *queue }, 28); } -static size_t history_handler(void *contents, size_t size, size_t nmemb +static size_t history_i_handler(void *contents, size_t size, size_t nmemb + , void *writedata) +{ + size_t realsize = size * nmemb; + char response[realsize + 1]; + memcpy(response, contents, realsize); + response[realsize] = '\0'; + + return realsize; +} + +static size_t history_s_handler(void *contents, size_t size, size_t nmemb + , void *writedata) +{ + size_t realsize = size * nmemb; + char response[realsize + 1]; + memcpy(response, contents, realsize); + response[realsize] = '\0'; + + return realsize; +} + +static size_t history_l_handler(void *contents, size_t size, size_t nmemb , void *writedata) { size_t realsize = size * nmemb; @@ -272,12 +294,27 @@ static size_t history_handler(void *contents, size_t size, size_t nmemb } void rtclient_ticket_history(rtclient_ticket_history_list **listptr - , unsigned int id) + , unsigned int id + , enum rtclient_ticket_result_format result_format) { *listptr = malloc(sizeof(rtclient_ticket_history_list)); (*listptr)->length = 0; - request(history_handler, (void *)listptr, NULL, "%s%u%s" - , "REST/1.0/ticket/", id, "/history?format=l"); + size_t (*handler)(void *, size_t, size_t, void *) = history_s_handler; + char format = 's'; + switch (result_format) { + case RTCLIENT_TICKET_RESULT_FORMAT_I: + handler = history_i_handler; + format = 'i'; + break; + case RTCLIENT_TICKET_RESULT_FORMAT_L: + handler = history_l_handler; + format = 'l'; + break; + default: + break; + } + request(handler, (void *)listptr, NULL, "%s%u%s%c", "REST/1.0/ticket/", id + , "/history?format=", format); } void rtclient_ticket_history_free(struct rtclient_ticket_history *history) -- cgit v1.2.3