summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-03-13 16:08:55 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-03-13 16:08:55 +0800
commit000716f554aad82d774f7ef1c7b09e82e3342546 (patch)
tree9f10156e909118f411bda34c5d799d38e05db84c
parent6e5428f317c15ac78af3d440e377e7e77d2a0e0e (diff)
Default empty next/fail page means null C version
-rw-r--r--interchange/member.hxx8
-rw-r--r--member.cxx32
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);