Skip to content

Commit

Permalink
Fixed #389 - QRZ auth over POST with form data
Browse files Browse the repository at this point in the history
  • Loading branch information
foldynl committed Jun 9, 2024
1 parent 9dc6db6 commit ec4c038
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions core/QRZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,34 @@ void QRZ::queryCallsign(const QString &callsign)
return;
}

QUrlQuery query;
query.addQueryItem("s", sessionId);
QUrlQuery params;
params.addQueryItem("s", sessionId);

const Callsign qCall(callsign);

if (qCall.isValid())
{
// currently QRZ.com does not handle correctly prefixes and suffixes.
// That's why it's better to give it away if possible
query.addQueryItem("callsign", qCall.getBase());
params.addQueryItem("callsign", qCall.getBase());
}
else
{
query.addQueryItem("callsign", callsign);
params.addQueryItem("callsign", callsign);
}

QUrl url(API_URL);
url.setQuery(query);

if ( currentReply )
{
qCWarning(runtime) << "processing a new request but the previous one hasn't been completed yet !!!";
}

currentReply = nam->get(QNetworkRequest(url));
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

qCDebug(runtime) << url;

currentReply = nam->post(request, params.query(QUrl::FullyEncoded).toUtf8());

currentReply->setProperty("queryCallsign", QVariant(callsign));
currentReply->setProperty("messageType", QVariant("callsignInfoQuery"));

Expand All @@ -103,7 +106,6 @@ void QRZ::abortQuery()
}
}


void QRZ::uploadContact(const QSqlRecord &record)
{
FCT_IDENTIFICATION;
Expand Down Expand Up @@ -137,15 +139,12 @@ void QRZ::actionInsert(QByteArray& data, const QString &insertPolicy)
QUrl url(API_LOGBOOK_URL);

QNetworkRequest request(url);

request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

qCDebug(runtime) << url;

if ( currentReply )
{
qCWarning(runtime) << "processing a new request but the previous one hasn't been completed yet !!!";
}

currentReply = nam->post(request, params.query(QUrl::FullyEncoded).toUtf8());

Expand Down Expand Up @@ -266,20 +265,20 @@ void QRZ::authenticate()

if ( !username.isEmpty() && !password.isEmpty() )
{
QUrlQuery query;
query.addQueryItem("username", username.toUtf8().toPercentEncoding());
query.addQueryItem("password", password.toUtf8().toPercentEncoding());
query.addQueryItem("agent", "QLog");
QUrlQuery params;
params.addQueryItem("username", username.toUtf8().toPercentEncoding());
params.addQueryItem("password", password.toUtf8().toPercentEncoding());
params.addQueryItem("agent", "QLog");

QUrl url(API_URL);
url.setQuery(query);

if ( currentReply )
{
qCWarning(runtime) << "processing a new request but the previous one hasn't been completed yet !!!";
}

currentReply = nam->get(QNetworkRequest(url));
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

currentReply = nam->post(request, params.query(QUrl::FullyEncoded).toUtf8());
currentReply->setProperty("messageType", QVariant("authenticate"));
lastSeenPassword = password;
}
Expand Down

0 comments on commit ec4c038

Please sign in to comment.