From 000716f554aad82d774f7ef1c7b09e82e3342546 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: Mon, 13 Mar 2023 16:08:55 +0800 Subject: Default empty next/fail page means null C version --- interchange/member.hxx | 8 ++++---- member.cxx | 32 ++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/interchange/member.hxx b/interchange/member.hxx index 3f00dba..560cea4 100644 --- a/interchange/member.hxx +++ b/interchange/member.hxx @@ -82,10 +82,10 @@ namespace QInterchange { QString const& password, QString const& confirm, QString const& failPage = nullptr); - void logIn(QString const& username, - QString const& password, - QString const& nextPage = nullptr, - QString const& failPage = nullptr); + void logIn(QString const& userName, + QString const& passWord, + QString const& nextPage = "", + QString const& failPage = ""); void account(); void setAccount(QString const& firstName, QString const& lastName, diff --git a/member.cxx b/member.cxx index 175a355..a346d74 100644 --- a/member.cxx +++ b/member.cxx @@ -126,24 +126,28 @@ namespace QInterchange { void Member::logIn(QString const& username, QString const& password, QString const& nextPage, QString const& failPage) { - auto unData = username.toLatin1().constData(); - unCopy = (char*)malloc(strlen(unData) + 1); - strcpy(unCopy, unData); - auto pwData = password.toLatin1().constData(); - pwCopy = (char*)malloc(strlen(pwData) + 1); - strcpy(pwCopy, pwData); - auto npData = nextPage.toLatin1().constData(); - npCopy = (char*)malloc(strlen(npData) + 1); - strcpy(npCopy, npData); - auto fpData = failPage.toLatin1().constData(); - fpCopy = (char*)malloc(strlen(fpData) + 1); - strcpy(fpCopy, fpData); + unCopy = (char*)malloc(username.size() + 1); + strcpy(unCopy, username.toLatin1().constData()); + pwCopy = (char*)malloc(password.size() + 1); + strcpy(pwCopy, password.toLatin1().constData()); + if (nextPage.isEmpty()) + npCopy = nullptr; + else { + npCopy = (char*)malloc(nextPage.size() + 1); + strcpy(npCopy, nextPage.toLatin1().constData()); + } + if (failPage.isEmpty()) + fpCopy = nullptr; + else { + fpCopy = (char*)malloc(failPage.size() + 1); + strcpy(fpCopy, failPage.toLatin1().constData()); + } interchange_member_login(unCopy, pwCopy, npCopy, fpCopy, [](interchange_response* response) { free(unCopy); free(pwCopy); - free(npCopy); - free(fpCopy); + if (npCopy) free(npCopy); + if (fpCopy) free(fpCopy); member->emitLogin(QString{response->data}); interchange_free_response(response); }, nullptr); -- cgit v1.2.3