From c82bcaf01cbb471efdbc118e9aa45a43fb93d4b5 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, 18 Sep 2019 17:11:54 +0800 Subject: Prepare ticket_new function Copied and adjusted from user_new for now. --- rtclient/ticket.h | 14 +++++++++ ticket.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/rtclient/ticket.h b/rtclient/ticket.h index cd782a3..74db994 100644 --- a/rtclient/ticket.h +++ b/rtclient/ticket.h @@ -10,6 +10,20 @@ struct rtclient_ticketlist { extern "C" { #endif + void rtclient_ticket_new(const char *queue + , const char *requestor + , const char *subject + , const char *cc + , const char *admincc + , const char *owner + , const char *status + , const char *priority + , const char *initialpriority + , const char *finalpriority + , const char *timeestimated + , const char *starts + , const char *due + , const char *text); void rtclient_ticket_search(struct rtclient_ticketlist **listptr , const char *query); void rtclient_ticket_freelist(struct rtclient_ticketlist *list); diff --git a/ticket.c b/ticket.c index 6290dcb..d5927b4 100644 --- a/ticket.c +++ b/ticket.c @@ -4,6 +4,93 @@ typedef struct rtclient_ticketlist rtclient_ticketlist; +void rtclient_ticket_new(const char *queue + , const char *requestor + , const char *subject + , const char *cc + , const char *admincc + , const char *owner + , const char *status + , const char *priority + , const char *initialpriority + , const char *finalpriority + , const char *timeestimated + , const char *starts + , const char *due + , const char *text) +{ + size_t length = 0; + if (queue && strcmp(queue, "")) + length += strlen("Queue: \n") + strlen(queue); + if (requestor && strcmp(requestor, "")) + length += strlen("Requestor: \n") + strlen(requestor); + if (subject && strcmp(subject, "")) + length += strlen("Subject: \n") + strlen(subject); + if (cc && strcmp(cc, "")) + length += strlen("Cc: \n") + strlen(cc); + if (admincc && strcmp(admincc, "")) + length += strlen("AdminCc: \n") + strlen(admincc); + if (owner && strcmp(owner, "")) + length += strlen("Owner: \n") + strlen(owner); + if (status && strcmp(status, "")) + length += strlen("Status: \n") + strlen(status); + if (priority && strcmp(priority, "")) + length += strlen("Priority: \n") + strlen(priority); + if (initialpriority && strcmp(initialpriority, "")) + length += strlen("InitialPriority: \n") + strlen(initialpriority); + if (finalpriority && strcmp(finalpriority, "")) + length += strlen("FinalPriority: \n") + strlen(finalpriority); + if (timeestimated && strcmp(timeestimated, "")) + length += strlen("TimeEstimated: \n") + strlen(timeestimated); + if (starts && strcmp(starts, "")) + length += strlen("Starts: \n") + strlen(starts); + if (due && strcmp(due, "")) + length += strlen("Due: \n") + strlen(due); + if (text && strcmp(text, "")) + length += strlen("Text: \n") + strlen(text); + + char content[length + 1]; + memset(content, 0, strlen(content)); + if (queue && strcmp(queue, "")) + sprintf(content, "%sQueue: %s\n", content, queue); + if (requestor && strcmp(requestor, "")) + sprintf(content, "%sRequestor: %s\n", content, requestor); + if (subject && strcmp(subject, "")) + sprintf(content, "%sSubject: %s\n", content, subject); + if (cc && strcmp(cc, "")) + sprintf(content, "%sCc: %s\n", content, cc); + if (admincc && strcmp(admincc, "")) + sprintf(content, "%sAdminCc: %s\n", content, admincc); + if (owner && strcmp(owner, "")) + sprintf(content, "%sOwner: %s\n", content, owner); + if (status && strcmp(status, "")) + sprintf(content, "%sStatus: %s\n", content, status); + if (priority && strcmp(priority, "")) + sprintf(content, "%sPriority: %s\n", content, priority); + if (initialpriority && strcmp(initialpriority, "")) + sprintf(content, "%sInitialPriority: %s\n", content, initialpriority); + if (finalpriority && strcmp(finalpriority, "")) + sprintf(content, "%sFinalPriority: %s\n", content, finalpriority); + if (timeestimated && strcmp(timeestimated, "")) + sprintf(content, "%sTimeEstimated: %s\n", content, timeestimated); + if (starts && strcmp(starts, "")) + sprintf(content, "%sStarts: %s\n", content, starts); + if (due && strcmp(due, "")) + sprintf(content, "%sDue: %s\n", content, due); + if (text && strcmp(text, "")) + sprintf(content, "%sText: %s\n", content, text); + + struct curl_httppost *post, *last = NULL; + curl_formadd(&post, &last + , CURLFORM_COPYNAME, "content" + , CURLFORM_PTRCONTENTS, content + , CURLFORM_END); + last = NULL; + request("/REST/1.0/user/new", "", NULL, NULL, post); + curl_formfree(post); + post = NULL; +} + static size_t search_callback(void *contents, size_t size, size_t nmemb , void *writedata) { -- cgit v1.2.3