summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);