From 8107effd171ffb5285e4e6d79ff9a2b7e4669c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Wed, 2 Feb 2022 11:51:44 +0800 Subject: Conform to updated librtclient commit 12cde42c929b63a1ef1b2ad7f3482336419980b2 --- client.cxx | 127 ++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 40 deletions(-) (limited to 'client.cxx') diff --git a/client.cxx b/client.cxx index 5bf4801..c931191 100644 --- a/client.cxx +++ b/client.cxx @@ -1,21 +1,36 @@ #include #include +#include #include #include #include "qrtclient.hxx" namespace RTClient { - Client::Client(char const* url, char const* certificate) - { - rtclient_init(url, certificate); - } +static Client* client; +static char *nCopy, *pwCopy; - void Client::logIn(QString const& name, QString const& password) - { - rtclient_login(name.toLatin1().constData(), password.toLatin1().constData()); - emit loggedIn(name); - } +Client::Client(char const* url, char const* cookies, char const* certificate) +{ + client = this; + rtclient_init(url, cookies, certificate); +} + +void Client::logIn(QString const& name, QString const& password) +{ + auto nData = name.toLatin1().constData(); + nCopy = (char*)malloc(strlen(nData) + 1); + strcpy(nCopy, nData); + auto pwData = password.toLatin1().constData(); + pwCopy = (char*)malloc(strlen(pwData) + 1); + strcpy(pwCopy, pwData); + rtclient_login(nCopy, pwCopy, [](rtclient_response* response) { + rtclient_free_response(response); + client->emitLoggedIn(QString{nCopy}); + free(nCopy); + free(pwCopy); + }); +} void Client::userNew(QString const& name, QString const& password, @@ -68,19 +83,22 @@ void Client::userNew(QString const& name, privileged); } - void Client::userShow(unsigned int id) - { - rtclient_user* user = nullptr; - rtclient_user_showid(&user, id); - emit userShown(user); - } +void Client::userShow(unsigned int id) +{ + rtclient_user_showid(id, [](struct rtclient_user* user) { + client->emitUserShown(User{user}); + rtclient_user_free(user); + }); +} - void Client::userShow(QString const& name) - { - rtclient_user* user = nullptr; - rtclient_user_showname(&user, name.toLatin1().constData()); - emit userShown(user); - } +void Client::userShow(QString const& name) +{ + rtclient_user_showname(name.toLatin1().constData(), + [](struct rtclient_user* user) { + client->emitUserShown(User{user}); + rtclient_user_free(user); + }); +} void Client::ticketNew(QString const& queue, QString const& requestor, @@ -113,24 +131,53 @@ void Client::ticketNew(QString const& queue, text.toLatin1().constData()); } - void Client::searchTicket(QString const& owner) - { - QString query{"Owner='" % owner % "'"}; - rtclient_search_ticket_list* list = nullptr; - rtclient_search_ticket(&list, query.toLatin1().constData()); - emit searchedTicket(list); - } - - void Client::ticketHistory(int id, bool longFormat) - { - rtclient_ticket_history_list* historyList = nullptr; - rtclient_ticket_history(&historyList, id, longFormat); - emit gotTicketHistory(historyList); - } - - Client::~Client() - { - rtclient_cleanup(); - } +void Client::searchTicket(QString const& owner) +{ + QString query{"Owner='" % owner % "'"}; + rtclient_search_ticket(query.toLatin1().constData(), + [](struct rtclient_ticket** list) { + client->emitSearchedTicket(TicketList{list}); + size_t i = 0; + while (list[i]) { + free(list[i]->subject); + free(list[i++]); + } + }); +} + +void Client::ticketHistoryList(int id, bool longFormat) +{ + rtclient_ticket_history_list(id, longFormat, + [](struct rtclient_ticket_history** list) { + client->emitGotTicketHistoryList(TicketHistoryList{list}); + size_t i = 0; +// while (list[i]) rtclient_ticket_history_free(list[i++]); + }); +} + +void Client::emitLoggedIn(QString const& name) +{ + emit loggedIn(name); +} + +void Client::emitUserShown(User const& user) +{ + emit userShown(user); +} + +void Client::emitSearchedTicket(TicketList const& list) +{ + emit searchedTicket(list); +} + +void Client::emitGotTicketHistoryList(TicketHistoryList const& list) +{ + emit gotTicketHistoryList(list); +} + +Client::~Client() +{ + rtclient_cleanup(); +} } -- cgit v1.2.3