diff options
| author | Alexandr Akulich <akulichalexander@gmail.com> | 2014-06-19 18:57:32 +0600 |
|---|---|---|
| committer | David Edmundson <kde@davidedmundson.co.uk> | 2014-07-28 15:25:45 +0200 |
| commit | eb9ae568d189e354d52565b24657c3df9325af1a (patch) | |
| tree | f62135d2e6ca59e37094527f4f34398e28520a74 | |
| parent | 9ecdd378fdfc7c2d15c390f7cf7102be69ffc218 (diff) | |
Added BaseChannelSASLAuthenticationInterface.
| -rw-r--r-- | TelepathyQt/base-channel-internal.h | 49 | ||||
| -rw-r--r-- | TelepathyQt/base-channel.cpp | 372 | ||||
| -rw-r--r-- | TelepathyQt/base-channel.h | 103 | ||||
| -rw-r--r-- | TelepathyQt/service-types.h | 2 |
4 files changed, 526 insertions, 0 deletions
diff --git a/TelepathyQt/base-channel-internal.h b/TelepathyQt/base-channel-internal.h index e0238d03..51873751 100644 --- a/TelepathyQt/base-channel-internal.h +++ b/TelepathyQt/base-channel-internal.h @@ -191,6 +191,55 @@ public: BaseChannelCaptchaAuthenticationInterface *mInterface; }; +class TP_QT_NO_EXPORT BaseChannelSASLAuthenticationInterface::Adaptee : public QObject +{ + Q_OBJECT + Q_PROPERTY(QStringList availableMechanisms READ availableMechanisms) + Q_PROPERTY(bool hasInitialData READ hasInitialData) + Q_PROPERTY(bool canTryAgain READ canTryAgain) + Q_PROPERTY(uint saslStatus READ saslStatus) + Q_PROPERTY(QString saslError READ saslError) + Q_PROPERTY(QVariantMap saslErrorDetails READ saslErrorDetails) + Q_PROPERTY(QString authorizationIdentity READ authorizationIdentity) + Q_PROPERTY(QString defaultUsername READ defaultUsername) + Q_PROPERTY(QString defaultRealm READ defaultRealm) + Q_PROPERTY(bool maySaveResponse READ maySaveResponse) + +public: + Adaptee(BaseChannelSASLAuthenticationInterface *interface); + ~Adaptee(); + + QStringList availableMechanisms() const; + bool hasInitialData() const; + bool canTryAgain() const; + uint saslStatus() const; + QString saslError() const; + QVariantMap saslErrorDetails() const; + QString authorizationIdentity() const; + QString defaultUsername() const; + QString defaultRealm() const; + bool maySaveResponse() const; + +private Q_SLOTS: + void startMechanism(const QString &mechanism, + const Tp::Service::ChannelInterfaceSASLAuthenticationAdaptor::StartMechanismContextPtr &context); + void startMechanismWithData(const QString &mechanism, const QByteArray &initialData, + const Tp::Service::ChannelInterfaceSASLAuthenticationAdaptor::StartMechanismWithDataContextPtr &context); + void respond(const QByteArray &responseData, + const Tp::Service::ChannelInterfaceSASLAuthenticationAdaptor::RespondContextPtr &context); + void acceptSasl( + const Tp::Service::ChannelInterfaceSASLAuthenticationAdaptor::AcceptSASLContextPtr &context); + void abortSasl(uint reason, const QString &debugMessage, + const Tp::Service::ChannelInterfaceSASLAuthenticationAdaptor::AbortSASLContextPtr &context); + +signals: + void saslStatusChanged(uint status, const QString &reason, const QVariantMap &details); + void newChallenge(const QByteArray &challengeData); + +private: + BaseChannelSASLAuthenticationInterface *mInterface; +}; + class TP_QT_NO_EXPORT BaseChannelGroupInterface::Adaptee : public QObject { Q_OBJECT diff --git a/TelepathyQt/base-channel.cpp b/TelepathyQt/base-channel.cpp index d9d60106..83a64621 100644 --- a/TelepathyQt/base-channel.cpp +++ b/TelepathyQt/base-channel.cpp @@ -985,6 +985,378 @@ void BaseChannelCaptchaAuthenticationInterface::setCaptchaErrorDetails(const QVa mPriv->captchaErrorDetails = error; } +//Chan.I.SASLAuthentication +struct TP_QT_NO_EXPORT BaseChannelSASLAuthenticationInterface::Private { + Private(BaseChannelSASLAuthenticationInterface *parent, + const QStringList &availableMechanisms, + bool hasInitialData, + bool canTryAgain, + const QString &authorizationIdentity, + const QString &defaultUsername, + const QString &defaultRealm, + bool maySaveResponse) + : availableMechanisms(availableMechanisms), + hasInitialData(hasInitialData), + canTryAgain(canTryAgain), + saslStatus(0), + authorizationIdentity(authorizationIdentity), + defaultUsername(defaultUsername), + defaultRealm(defaultRealm), + maySaveResponse(maySaveResponse), + adaptee(new BaseChannelSASLAuthenticationInterface::Adaptee(parent)) + { + } + + QStringList availableMechanisms; + bool hasInitialData; + bool canTryAgain; + uint saslStatus; + QString saslError; + QVariantMap saslErrorDetails; + QString authorizationIdentity; + QString defaultUsername; + QString defaultRealm; + bool maySaveResponse; + StartMechanismCallback startMechanismCB; + StartMechanismWithDataCallback startMechanismWithDataCB; + RespondCallback respondCB; + AcceptSASLCallback acceptSaslCB; + AbortSASLCallback abortSaslCB; + BaseChannelSASLAuthenticationInterface::Adaptee *adaptee; +}; + +BaseChannelSASLAuthenticationInterface::Adaptee::Adaptee(BaseChannelSASLAuthenticationInterface *interface) + : QObject(interface), + mInterface(interface) +{ +} + +BaseChannelSASLAuthenticationInterface::Adaptee::~Adaptee() +{ +} + +QStringList BaseChannelSASLAuthenticationInterface::Adaptee::availableMechanisms() const +{ + return mInterface->availableMechanisms(); +} + +bool BaseChannelSASLAuthenticationInterface::Adaptee::hasInitialData() const +{ + return mInterface->hasInitialData(); +} + +bool BaseChannelSASLAuthenticationInterface::Adaptee::canTryAgain() const +{ + return mInterface->canTryAgain(); +} + +uint BaseChannelSASLAuthenticationInterface::Adaptee::saslStatus() const +{ + return mInterface->saslStatus(); +} + +QString BaseChannelSASLAuthenticationInterface::Adaptee::saslError() const +{ + return mInterface->saslError(); +} + +QVariantMap BaseChannelSASLAuthenticationInterface::Adaptee::saslErrorDetails() const +{ + return mInterface->saslErrorDetails(); +} + +QString BaseChannelSASLAuthenticationInterface::Adaptee::authorizationIdentity() const +{ + return mInterface->authorizationIdentity(); +} + +QString BaseChannelSASLAuthenticationInterface::Adaptee::defaultUsername() const +{ + return mInterface->defaultUsername(); +} + +QString BaseChannelSASLAuthenticationInterface::Adaptee::defaultRealm() const +{ + return mInterface->defaultRealm(); +} + +bool BaseChannelSASLAuthenticationInterface::Adaptee::maySaveResponse() const +{ + return mInterface->maySaveResponse(); +} + +void BaseChannelSASLAuthenticationInterface::Adaptee::startMechanism(const QString &mechanism, + const Tp::Service::ChannelInterfaceSASLAuthenticationAdaptor::StartMechanismContextPtr &context) +{ + qDebug() << "BaseChannelSASLAuthenticationInterface::Adaptee::startMechanism"; + DBusError error; + mInterface->startMechanism(mechanism, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseChannelSASLAuthenticationInterface::Adaptee::startMechanismWithData(const QString &mechanism, const QByteArray &initialData, + const Tp::Service::ChannelInterfaceSASLAuthenticationAdaptor::StartMechanismWithDataContextPtr &context) +{ + qDebug() << "BaseChannelSASLAuthenticationInterface::Adaptee::startMechanismWithData"; + DBusError error; + mInterface->startMechanismWithData(mechanism, initialData, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseChannelSASLAuthenticationInterface::Adaptee::respond(const QByteArray &responseData, + const Tp::Service::ChannelInterfaceSASLAuthenticationAdaptor::RespondContextPtr &context) +{ + qDebug() << "BaseChannelSASLAuthenticationInterface::Adaptee::respond"; + DBusError error; + mInterface->respond(responseData, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseChannelSASLAuthenticationInterface::Adaptee::acceptSasl( + const Tp::Service::ChannelInterfaceSASLAuthenticationAdaptor::AcceptSASLContextPtr &context) +{ + qDebug() << "BaseChannelSASLAuthenticationInterface::Adaptee::acceptSasl"; + DBusError error; + mInterface->acceptSasl(&error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +void BaseChannelSASLAuthenticationInterface::Adaptee::abortSasl(uint reason, const QString &debugMessage, + const Tp::Service::ChannelInterfaceSASLAuthenticationAdaptor::AbortSASLContextPtr &context) +{ + qDebug() << "BaseChannelSASLAuthenticationInterface::Adaptee::abortSasl"; + DBusError error; + mInterface->abortSasl(reason, debugMessage, &error); + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(); +} + +/** + * \class BaseChannelSASLAuthenticationInterface + * \ingroup servicecm + * \headerfile TelepathyQt/base-channel.h <TelepathyQt/BaseChannel> + * + * \brief Base class for implementations of Channel.Interface.SASLAuthentication + * + */ + +/** + * Class constructor. + */ +BaseChannelSASLAuthenticationInterface::BaseChannelSASLAuthenticationInterface(const QStringList &availableMechanisms, + bool hasInitialData, + bool canTryAgain, + const QString &authorizationIdentity, + const QString &defaultUsername, + const QString &defaultRealm, + bool maySaveResponse) + : AbstractChannelInterface(TP_QT_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION), + mPriv(new Private(this, availableMechanisms, hasInitialData, canTryAgain, authorizationIdentity, defaultUsername, defaultRealm, maySaveResponse)) +{ +} + +/** + * Class destructor. + */ +BaseChannelSASLAuthenticationInterface::~BaseChannelSASLAuthenticationInterface() +{ + delete mPriv; +} + +/** + * Return the immutable properties of this interface. + * + * Immutable properties cannot change after the interface has been registered + * on a service on the bus with registerInterface(). + * + * \return The immutable properties of this interface. + */ +QVariantMap BaseChannelSASLAuthenticationInterface::immutableProperties() const +{ + QVariantMap map; + map.insert(TP_QT_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION + QLatin1String(".AvailableMechanisms"), + QVariant::fromValue(mPriv->adaptee->availableMechanisms())); + map.insert(TP_QT_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION + QLatin1String(".HasInitialData"), + QVariant::fromValue(mPriv->adaptee->hasInitialData())); + map.insert(TP_QT_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION + QLatin1String(".CanTryAgain"), + QVariant::fromValue(mPriv->adaptee->canTryAgain())); + map.insert(TP_QT_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION + QLatin1String(".AuthorizationIdentity"), + QVariant::fromValue(mPriv->adaptee->authorizationIdentity())); + map.insert(TP_QT_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION + QLatin1String(".DefaultUsername"), + QVariant::fromValue(mPriv->adaptee->defaultUsername())); + map.insert(TP_QT_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION + QLatin1String(".DefaultRealm"), + QVariant::fromValue(mPriv->adaptee->defaultRealm())); + map.insert(TP_QT_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION + QLatin1String(".MaySaveResponse"), + QVariant::fromValue(mPriv->adaptee->maySaveResponse())); + return map; +} + +QStringList BaseChannelSASLAuthenticationInterface::availableMechanisms() const +{ + return mPriv->availableMechanisms; +} + +bool BaseChannelSASLAuthenticationInterface::hasInitialData() const +{ + return mPriv->hasInitialData; +} + +bool BaseChannelSASLAuthenticationInterface::canTryAgain() const +{ + return mPriv->canTryAgain; +} + +uint BaseChannelSASLAuthenticationInterface::saslStatus() const +{ + return mPriv->saslStatus; +} + +void BaseChannelSASLAuthenticationInterface::setSaslStatus(uint status, const QString &reason, const QVariantMap &details) +{ + mPriv->saslStatus = status; + QMetaObject::invokeMethod(mPriv->adaptee, "saslStatusChanged", Q_ARG(uint, status), Q_ARG(QString, reason), Q_ARG(QVariantMap, details)); //Can simply use emit in Qt5 +} + +QString BaseChannelSASLAuthenticationInterface::saslError() const +{ + return mPriv->saslError; +} + +void BaseChannelSASLAuthenticationInterface::setSaslError(const QString &saslError) +{ + mPriv->saslError = saslError; +} + +QVariantMap BaseChannelSASLAuthenticationInterface::saslErrorDetails() const +{ + return mPriv->saslErrorDetails; +} + +void BaseChannelSASLAuthenticationInterface::setSaslErrorDetails(const QVariantMap &saslErrorDetails) +{ + mPriv->saslErrorDetails = saslErrorDetails; +} + +QString BaseChannelSASLAuthenticationInterface::authorizationIdentity() const +{ + return mPriv->authorizationIdentity; +} + +QString BaseChannelSASLAuthenticationInterface::defaultUsername() const +{ + return mPriv->defaultUsername; +} + +QString BaseChannelSASLAuthenticationInterface::defaultRealm() const +{ + return mPriv->defaultRealm; +} + +bool BaseChannelSASLAuthenticationInterface::maySaveResponse() const +{ + return mPriv->maySaveResponse; +} + +void BaseChannelSASLAuthenticationInterface::createAdaptor() +{ + (void) new Service::ChannelInterfaceSASLAuthenticationAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); +} + +void BaseChannelSASLAuthenticationInterface::setStartMechanismCallback(const BaseChannelSASLAuthenticationInterface::StartMechanismCallback &cb) +{ + mPriv->startMechanismCB = cb; +} + +void BaseChannelSASLAuthenticationInterface::startMechanism(const QString &mechanism, DBusError *error) +{ + if (!mPriv->startMechanismCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->startMechanismCB(mechanism, error); +} + +void BaseChannelSASLAuthenticationInterface::setStartMechanismWithDataCallback(const BaseChannelSASLAuthenticationInterface::StartMechanismWithDataCallback &cb) +{ + mPriv->startMechanismWithDataCB = cb; +} + +void BaseChannelSASLAuthenticationInterface::startMechanismWithData(const QString &mechanism, const QByteArray &initialData, DBusError *error) +{ + if (!mPriv->startMechanismWithDataCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->startMechanismWithDataCB(mechanism, initialData, error); +} + +void BaseChannelSASLAuthenticationInterface::setRespondCallback(const BaseChannelSASLAuthenticationInterface::RespondCallback &cb) +{ + mPriv->respondCB = cb; +} + +void BaseChannelSASLAuthenticationInterface::respond(const QByteArray &responseData, DBusError *error) +{ + if (!mPriv->respondCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->respondCB(responseData, error); +} + +void BaseChannelSASLAuthenticationInterface::setAcceptSaslCallback(const BaseChannelSASLAuthenticationInterface::AcceptSASLCallback &cb) +{ + mPriv->acceptSaslCB = cb; +} + +void BaseChannelSASLAuthenticationInterface::acceptSasl(DBusError *error) +{ + if (!mPriv->acceptSaslCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->acceptSaslCB(error); +} + +void BaseChannelSASLAuthenticationInterface::setAbortSaslCallback(const BaseChannelSASLAuthenticationInterface::AbortSASLCallback &cb) +{ + mPriv->abortSaslCB = cb; +} + +void BaseChannelSASLAuthenticationInterface::abortSasl(uint reason, const QString &debugMessage, DBusError *error) +{ + if (!mPriv->abortSaslCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return; + } + return mPriv->abortSaslCB(reason, debugMessage, error); +} + +void BaseChannelSASLAuthenticationInterface::newChallenge(const QByteArray &challengeData) +{ + QMetaObject::invokeMethod(mPriv->adaptee, "newChallenge", Q_ARG(QByteArray, challengeData)); //Can simply use emit in Qt5 +} + //Chan.I.Group BaseChannelGroupInterface::Adaptee::Adaptee(BaseChannelGroupInterface *interface) : QObject(interface), diff --git a/TelepathyQt/base-channel.h b/TelepathyQt/base-channel.h index a877b6ff..1d00cae1 100644 --- a/TelepathyQt/base-channel.h +++ b/TelepathyQt/base-channel.h @@ -287,6 +287,109 @@ private: Private *mPriv; }; +class TP_QT_EXPORT BaseChannelSASLAuthenticationInterface : public AbstractChannelInterface +{ + Q_OBJECT + Q_DISABLE_COPY(BaseChannelSASLAuthenticationInterface) + +public: + static BaseChannelSASLAuthenticationInterfacePtr create(const QStringList &availableMechanisms, + bool hasInitialData, + bool canTryAgain, + const QString &authorizationIdentity, + const QString &defaultUsername, + const QString &defaultRealm, + bool maySaveResponse) + { + return BaseChannelSASLAuthenticationInterfacePtr(new BaseChannelSASLAuthenticationInterface(availableMechanisms, + hasInitialData, + canTryAgain, + authorizationIdentity, + defaultUsername, + defaultRealm, + maySaveResponse)); + } + template<typename BaseChannelSASLAuthenticationInterfaceSubclass> + static SharedPtr<BaseChannelSASLAuthenticationInterfaceSubclass> create(const QStringList &availableMechanisms, + bool hasInitialData, + bool canTryAgain, + const QString &authorizationIdentity, + const QString &defaultUsername, + const QString &defaultRealm, + bool maySaveResponse) + { + return SharedPtr<BaseChannelSASLAuthenticationInterfaceSubclass>( + new BaseChannelSASLAuthenticationInterfaceSubclass(availableMechanisms, + hasInitialData, + canTryAgain, + authorizationIdentity, + defaultUsername, + defaultRealm, + maySaveResponse)); + } + + virtual ~BaseChannelSASLAuthenticationInterface(); + + QVariantMap immutableProperties() const; + + QStringList availableMechanisms() const; + bool hasInitialData() const; + bool canTryAgain() const; + QString authorizationIdentity() const; + QString defaultUsername() const; + QString defaultRealm() const; + bool maySaveResponse() const; + + uint saslStatus() const; + void setSaslStatus(uint status, const QString &reason, const QVariantMap &details); + + QString saslError() const; + void setSaslError(const QString &saslError); + + QVariantMap saslErrorDetails() const; + void setSaslErrorDetails(const QVariantMap &saslErrorDetails); + + typedef Callback2<void, const QString &, DBusError*> StartMechanismCallback; + void setStartMechanismCallback(const StartMechanismCallback &cb); + void startMechanism(const QString &mechanism, DBusError *error); + + typedef Callback3<void, const QString &, const QByteArray &, DBusError*> StartMechanismWithDataCallback; + void setStartMechanismWithDataCallback(const StartMechanismWithDataCallback &cb); + void startMechanismWithData(const QString &mechanism, const QByteArray &initialData, DBusError *error); + + typedef Callback2<void, const QByteArray &, DBusError*> RespondCallback; + void setRespondCallback(const RespondCallback &cb); + void respond(const QByteArray &responseData, DBusError *error); + + typedef Callback1<void, DBusError*> AcceptSASLCallback; + void setAcceptSaslCallback(const AcceptSASLCallback &cb); + void acceptSasl(DBusError *error); + + typedef Callback3<void, uint, const QString &, DBusError*> AbortSASLCallback; + void setAbortSaslCallback(const AbortSASLCallback &cb); + void abortSasl(uint reason, const QString &debugMessage, DBusError *error); + + void newChallenge(const QByteArray &challengeData); + +protected: + BaseChannelSASLAuthenticationInterface(const QStringList &availableMechanisms, + bool hasInitialData, + bool canTryAgain, + const QString &authorizationIdentity, + const QString &defaultUsername, + const QString &defaultRealm, + bool maySaveResponse); + +private: + void createAdaptor(); + + class Adaptee; + friend class Adaptee; + struct Private; + friend struct Private; + Private *mPriv; +}; + class TP_QT_EXPORT BaseChannelGroupInterface : public AbstractChannelInterface { Q_OBJECT diff --git a/TelepathyQt/service-types.h b/TelepathyQt/service-types.h index 33adbf69..ba17c2bb 100644 --- a/TelepathyQt/service-types.h +++ b/TelepathyQt/service-types.h @@ -50,6 +50,7 @@ class BaseChannel; class BaseChannelTextType; class BaseChannelMessagesInterface; class BaseChannelServerAuthenticationType; +class BaseChannelSASLAuthenticationInterface; class BaseChannelCaptchaAuthenticationInterface; class BaseChannelGroupInterface; class DBusService; @@ -74,6 +75,7 @@ typedef SharedPtr<BaseChannel> BaseChannelPtr; typedef SharedPtr<BaseChannelTextType> BaseChannelTextTypePtr; typedef SharedPtr<BaseChannelMessagesInterface> BaseChannelMessagesInterfacePtr; typedef SharedPtr<BaseChannelServerAuthenticationType> BaseChannelServerAuthenticationTypePtr; +typedef SharedPtr<BaseChannelSASLAuthenticationInterface> BaseChannelSASLAuthenticationInterfacePtr; typedef SharedPtr<BaseChannelCaptchaAuthenticationInterface> BaseChannelCaptchaAuthenticationInterfacePtr; typedef SharedPtr<BaseChannelGroupInterface> BaseChannelGroupInterfacePtr; typedef SharedPtr<DBusService> DBusServicePtr; |
