UnregisterService.cpp Example File
pushCollector/10.0/pushCollector/src/service/UnregisterService.cpp
#include "UnregisterService.hpp"
#include <QDebug>
UnregisterService::UnregisterService(QObject *parent)
: QObject(parent)
, m_reply(0)
{
connect(&m_accessManager,SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)),
this, SLOT(onSslErrors(QNetworkReply*, const QList<QSslError>&)));
}
User UnregisterService::getCurrentlyRegisteredUser()
{
return m_userDAO.user();
}
void UnregisterService::removeUser()
{
m_userDAO.remove();
}
void UnregisterService::unsubscribeFromPushInitiator(const User& user)
{
m_currentUser = user;
const Configuration config = m_configurationService.configuration();
QUrl url(config.pushInitiatorUrl() + "/unsubscribe");
url.addQueryItem("appid",config.providerApplicationId());
url.addQueryItem("username",user.userId());
url.addQueryItem("password",user.password());
qDebug() << "URL: " << url;
m_reply = m_accessManager.get(QNetworkRequest(url));
connect(m_reply, SIGNAL(finished()), this, SLOT(httpFinished()));
}
void UnregisterService::httpFinished()
{
qDebug() << "httpFinished called";
int code = -1;
QString description;
if (m_reply->error() == QNetworkReply::NoError) {
const QString returnCode = QString::fromUtf8(m_reply->readAll());
qDebug() << "returnCode: " << returnCode;
if (returnCode == "rc=200"){
const User storedUser = getCurrentlyRegisteredUser();
if ((m_currentUser.userId() == storedUser.userId()) && (m_currentUser.password() == storedUser.password())){
m_userDAO.remove();
}
code = 200;
} else if (returnCode == "rc=10002") {
code = 10002;
description = tr("Error: The application ID specified in the configuration settings could not be found, or it was found to be inactive or expired.");
} else if (returnCode == "rc=10007") {
code = 10007;
description = tr("Error: The subscriber (matching the username and password specified) could not be found.");
} else if (returnCode == "rc=10020") {
code = 10020;
description = tr("Error: The subscriber ID generated by the Push Initiator (based on the username and password specified) was null or empty, "
"longer than 42 characters in length, or matched the 'push_all' keyword.");
} else if (returnCode == "rc=10025") {
code = 10025;
description = tr("Error: The Push Initiator application has the bypass subscription flag set to true (so no unsubscribe is allowed).");
} else if (returnCode == "rc=10026") {
code = 10026;
description = tr("Error: The username or password specified was incorrect.");
} else if (returnCode == "rc=10027") {
code = 10027;
description = tr("Error: A CPSubscriptionFailureException was thrown by the onUnsubscribeSuccess method of the implementation "
"being used of the ContentProviderSubscriptionService interface.");
} else if (returnCode == "rc=-9999") {
code = -9999;
description = tr("Error: General error (i.e. rc=-9999).");
} else {
description = tr("Error: Unknown error code: %0.").arg(returnCode);
}
} else {
qDebug() << "network error";
code = m_reply->error();
description = m_reply->errorString();
}
emit piDeregistrationCompleted(code, description);
m_reply->deleteLater();
}
void UnregisterService::onSslErrors(QNetworkReply * reply, const QList<QSslError> & errors)
{
qDebug() << "onSslErrors called";
reply->ignoreSslErrors(errors);
}