File indexing completed on 2023-09-24 05:08:00
0001 /* 0002 * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/> 0003 * @author Andre Moreira Magalhaes <andre.magalhaes@collabora.co.uk> 0004 * Copyright (C) 2011 David Edmundson <kde@davidedmundson.co.uk> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 0019 */ 0020 0021 #include "sasl-handler.h" 0022 0023 #include "sasl-auth-op.h" 0024 0025 #include <KTp/telepathy-handler-application.h> 0026 0027 #include <QDBusConnection> 0028 0029 #include <TelepathyQt/Channel> 0030 #include <TelepathyQt/ChannelClassSpecList> 0031 #include <TelepathyQt/ChannelDispatchOperation> 0032 #include <TelepathyQt/MethodInvocationContext> 0033 0034 #include <QDebug> 0035 0036 static inline Tp::ChannelClassSpecList channelFilter() { 0037 Tp::ChannelClassSpecList filter; 0038 QVariantMap saslOtherProperties; 0039 saslOtherProperties.insert( 0040 TP_QT_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION + QLatin1String(".AuthenticationMethod"), 0041 TP_QT_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION); 0042 filter.append(Tp::ChannelClassSpec(TP_QT_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION, 0043 Tp::HandleTypeNone, false, saslOtherProperties)); 0044 return filter; 0045 } 0046 0047 0048 SaslHandler::SaslHandler() 0049 : Tp::AbstractClientHandler(channelFilter()) 0050 { 0051 } 0052 0053 SaslHandler::~SaslHandler() 0054 { 0055 } 0056 0057 bool SaslHandler::bypassApproval() const 0058 { 0059 return true; 0060 } 0061 0062 void SaslHandler::handleChannels(const Tp::MethodInvocationContextPtr<> &context, 0063 const Tp::AccountPtr &account, 0064 const Tp::ConnectionPtr &connection, 0065 const QList<Tp::ChannelPtr> &channels, 0066 const QList<Tp::ChannelRequestPtr> &requestsSatisfied, 0067 const QDateTime &userActionTime, 0068 const Tp::AbstractClientHandler::HandlerInfo &handlerInfo) 0069 { 0070 Q_UNUSED(connection); 0071 Q_UNUSED(requestsSatisfied); 0072 Q_UNUSED(userActionTime); 0073 Q_UNUSED(handlerInfo); 0074 0075 Q_ASSERT(channels.size() == 1); 0076 0077 KTp::TelepathyHandlerApplication::newJob(); 0078 SaslAuthOp *auth = new SaslAuthOp( 0079 account, channels.first()); 0080 connect(auth, 0081 SIGNAL(ready(Tp::PendingOperation*)), 0082 SLOT(onAuthReady(Tp::PendingOperation*))); 0083 connect(auth, 0084 SIGNAL(finished(Tp::PendingOperation*)), 0085 SLOT(onAuthFinished(Tp::PendingOperation*))); 0086 mAuthContexts.insert(auth, context); 0087 } 0088 0089 void SaslHandler::onAuthReady(Tp::PendingOperation *op) 0090 { 0091 SaslAuthOp *auth = qobject_cast<SaslAuthOp*>(op); 0092 Q_ASSERT(mAuthContexts.contains(auth)); 0093 0094 Tp::MethodInvocationContextPtr<> context = mAuthContexts.value(auth); 0095 context->setFinished(); 0096 } 0097 0098 void SaslHandler::onAuthFinished(Tp::PendingOperation *op) 0099 { 0100 SaslAuthOp *auth = qobject_cast<SaslAuthOp*>(op); 0101 Q_ASSERT(mAuthContexts.contains(auth)); 0102 0103 if (op->isError()) { 0104 qWarning() << "Error in SASL auth:" << op->errorName() << "-" << op->errorMessage(); 0105 } 0106 0107 mAuthContexts.remove(auth); 0108 KTp::TelepathyHandlerApplication::jobFinished(); 0109 }