From 81843655facabb59bcd299a827b2c862dba673e0 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: Tue, 1 Oct 2019 17:29:01 +0800 Subject: Handle ticket history created time into struct tm --- ticket.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/ticket.c b/ticket.c index 63e037c..fc8feb1 100644 --- a/ticket.c +++ b/ticket.c @@ -181,19 +181,35 @@ static size_t history_handler(void *contents, size_t size, size_t nmemb = malloc(strlen(token)); strcpy(ticket_history->creator, ++token); } else if (!strcmp(token, "Created")) { - token = strtok_r(NULL, ":", &tokensaveptr); -#ifdef DEBUG - printf("Created: %s\n", token); -#endif - /* ticket_history->created = malloc(sizeof(struct tm)); - */ + ticket_history->created->tm_isdst = -1; + token = strtok_r(NULL, ":", &tokensaveptr); + char *tmsaveptr = NULL; + char *tm = strtok_r(token, " " + , &tmsaveptr); + char *datesaveptr = NULL; + char *date = strtok_r(tm, "-" + , &datesaveptr); + ticket_history->created->tm_year + = atoi(date) - 1900; + date = strtok_r(NULL, "-", &datesaveptr); + ticket_history->created->tm_mon + = atoi(date) - 1; + date = strtok_r(NULL, "-", &datesaveptr); + ticket_history->created->tm_mday + = atoi(date); + tm = strtok_r(NULL, " ", &tmsaveptr); + ticket_history->created->tm_hour + = atoi(tm); + token = strtok_r(NULL, ":", &tokensaveptr); + ticket_history->created->tm_min + = atoi(token); + token = strtok_r(NULL, ":", &tokensaveptr); + ticket_history->created->tm_sec + = atoi(token); } else if (!strcmp(token, "Attachments")) { token = strtok_r(NULL, ":", &tokensaveptr); -#ifdef DEBUG - printf("Attachments: %s\n", token); -#endif break; } } while ((line = strtok_r(NULL, "\n", &linesaveptr))); -- cgit v1.2.3