• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

SolidModules

bluez-bluetoothsecurityadaptor.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2006 Will Stephenson <wstephenson@kde.org>
00003     Copyright (C) 2007 Daniel Gollub <dgollub@suse.de>
00004     Copyright (C) 2007 Juan González Aguilera <jaguilera@opsiland.info>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License version 2 as published by the Free Software Foundation.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 
00020 */
00021 #include "bluez-bluetoothsecurityadaptor.h"
00022 #include <kdebug.h>
00023 #include <ctime>
00024 //BluezBluetoothSecurityPasskeyAgentAdaptor
00025 BluezBluetoothSecurityPasskeyAgentAdaptor::BluezBluetoothSecurityPasskeyAgentAdaptor(BluezBluetoothSecurity * security)
00026     :QDBusAbstractAdaptor(security),security(security),conn(QDBusConnection::systemBus())
00027 {
00028     serviceName = QString("/org/kde/solid/BluezBluetoothSecurityPasskeyAgentAdaptor%1").arg(time(NULL));
00029     bool done = conn.registerObject(serviceName,security,QDBusConnection::ExportAdaptors);
00030     if (!done) {
00031         kDebug() << "Failed to register the object: " << conn.lastError().name() << " : " << conn.lastError().message();
00032         serviceName = "";
00033     } else {
00034         kDebug() << "DBus service registered at "<< serviceName <<endl;
00035                 //TODO Add support for an specific local device
00036         QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
00037         iface.call("RegisterDefaultPasskeyAgent",serviceName);
00038         if (iface.lastError().isValid()) {
00039             kDebug() << "RegisterDefaultPasskeyAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
00040             serviceName = "";
00041         } else {
00042             kDebug() << "RegisterDefaultPasskeyAgent succesfull!";
00043         }
00044     }
00045 
00046 }
00047 
00048 BluezBluetoothSecurityPasskeyAgentAdaptor::~ BluezBluetoothSecurityPasskeyAgentAdaptor()
00049 {
00050     kDebug() << k_funcinfo;
00051     if (!serviceName.isEmpty())
00052     {
00053         QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
00054         iface.call("UnregisterDefaultPasskeyAgent",serviceName);
00055         if (iface.lastError().isValid()) {
00056             kDebug() << "UnregisterDefaultPasskeyAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
00057             serviceName = "";
00058         } else {
00059             kDebug() << "UnregisterDefaultPasskeyAgent Successful!:" << iface.lastError().name() << " : " << iface.lastError().message();
00060         }
00061     }
00062 }
00063 
00064 QString BluezBluetoothSecurityPasskeyAgentAdaptor::Request(const QString & path, const QString & address, bool numeric,const QDBusMessage &msg)
00065 {
00066     kDebug() << k_funcinfo;
00067     Q_UNUSED(path)
00068     if (security) {
00069         QString answer = security->request(address,numeric);
00070         if (!answer.isEmpty()) {
00071             return answer;
00072         } else {
00073             QDBusMessage error = msg.createErrorReply("org.bluez.Error.Rejected","Pairing request rejected");
00074             QDBusConnection::systemBus().send(error);
00075         }
00076     }
00077     return "";//To satisfy the compiler, but the answer is already sent
00078 }
00079 
00080 void BluezBluetoothSecurityPasskeyAgentAdaptor::Confirm(const QString & path, const QString & address, const QString & value,const QDBusMessage &msg)
00081 {
00082     kDebug() << k_funcinfo;
00083     Q_UNUSED(path)
00084     if (security) {
00085         if(security->confirm(address,value)) {
00086             kDebug() << "Confirmed pin for " << address;
00087         } else {
00088             QDBusMessage error = msg.createErrorReply("org.bluez.Error.Rejected","Pairing request rejected");
00089             QDBusConnection::systemBus().send(error);
00090         }
00091     }
00092 }
00093 
00094 void BluezBluetoothSecurityPasskeyAgentAdaptor::Display(const QString & path, const QString & address, const QString & value)
00095 {
00096     kDebug() << k_funcinfo;
00097     Q_UNUSED(path)
00098     if (security) {
00099         security->display(address,value);
00100     }
00101 }
00102 
00103 void BluezBluetoothSecurityPasskeyAgentAdaptor::Keypress(const QString & path, const QString & address)
00104 {
00105     kDebug() << k_funcinfo;
00106     Q_UNUSED(path)
00107     if (security) {
00108         security->keypress(address);
00109     }
00110 }
00111 
00112 void BluezBluetoothSecurityPasskeyAgentAdaptor::Complete(const QString & path, const QString & address)
00113 {
00114     kDebug() << k_funcinfo;
00115     Q_UNUSED(path)
00116     if (security) {
00117         security->complete(address);
00118     }
00119 }
00120 
00121 void BluezBluetoothSecurityPasskeyAgentAdaptor::Cancel(const QString & path, const QString & address)
00122 {
00123     kDebug() << k_funcinfo;
00124     Q_UNUSED(path)
00125     if (security) {
00126         security->cancel(address);
00127     }
00128 }
00129 
00130 void BluezBluetoothSecurityPasskeyAgentAdaptor::Release()
00131 {
00132     kDebug() << k_funcinfo;
00133 }
00134 
00135 //BluezBluetoothSecurityAuthorizationAgentAdaptor
00136 BluezBluetoothSecurityAuthorizationAgentAdaptor::BluezBluetoothSecurityAuthorizationAgentAdaptor(BluezBluetoothSecurity * security)
00137     :QDBusAbstractAdaptor(security),security(security),conn(QDBusConnection::systemBus())
00138 {
00139     serviceName = QString("/org/kde/solid/BluezBluetoothSecurityAuthorizationAgentAdaptor%1").arg(time(NULL));
00140     bool done = conn.registerObject(
00141                                     serviceName,security,QDBusConnection::ExportAdaptors);
00142     if (!done) {
00143         kDebug() << "Failed to register the object: " << conn.lastError().name() << " : " << conn.lastError().message();
00144         serviceName = "";
00145     } else {
00146         kDebug() << "DBus service registered at "<< serviceName <<endl;
00147                 //TODO Add support for an specific local device
00148         QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
00149         iface.call("RegisterDefaultAuthorizationAgent",serviceName);
00150         if (iface.lastError().isValid()) {
00151             kDebug() << "RegisterDefaultAuthorizationAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
00152             serviceName = "";
00153         } else {
00154             kDebug() << "RegisterDefaultAuthorizationAgent succesfull!";
00155         }
00156     }
00157 
00158 }
00159 BluezBluetoothSecurityAuthorizationAgentAdaptor::~ BluezBluetoothSecurityAuthorizationAgentAdaptor()
00160 {
00161     kDebug() << k_funcinfo;
00162     if (!serviceName.isEmpty())
00163     {
00164         QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
00165         iface.call("UnregisterDefaultAuthorizationAgent",serviceName);
00166         if (iface.lastError().isValid()) {
00167             kDebug() << "UnregisterDefaultAuthorizationAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
00168             serviceName = "";
00169         } else {
00170             kDebug() << "UnregisterDefaultAuthorizationAgent Successful!:" << iface.lastError().name() << " : " << iface.lastError().message();
00171         }
00172     }
00173 }
00174 
00175 void BluezBluetoothSecurityAuthorizationAgentAdaptor::Authorize(const QString & adapter_path, const QString & address, const QString & service_path, const QString & uuid,const QDBusMessage &msg)
00176 {
00177     kDebug() << k_funcinfo;
00178     Q_UNUSED(service_path)
00179     if (security) {
00180         if(security->authorize(adapter_path,address,uuid)) {
00181             kDebug() << "Service with uuid "<< uuid <<" for " << address << " authorized";
00182         } else {
00183             QDBusMessage error = msg.createErrorReply("org.bluez.Error.Rejected","Authorization request rejected");
00184             QDBusConnection::systemBus().send(error);
00185         }
00186     }
00187 }
00188 
00189 void BluezBluetoothSecurityAuthorizationAgentAdaptor::Cancel(const QString & adapter_path, const QString & address, const QString & service_path, const QString & uuid)
00190 {
00191     Q_UNUSED(service_path)
00192     if (security) {
00193         security->cancel(adapter_path,address,uuid);
00194     }
00195 }
00196 
00197 void BluezBluetoothSecurityAuthorizationAgentAdaptor::Release()
00198 {
00199     kDebug() << k_funcinfo;
00200 }
00201 
00202 #include "bluez-bluetoothsecurityadaptor.moc"

SolidModules

Skip menu "SolidModules"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal