not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / solid / bluez / bluez-bluetoothsecurityadaptor.cpp
blob8dbeb3ae7be760156c1edd8c39a1dab5007be758
1 /* This file is part of the KDE project
2 Copyright (C) 2006 Will Stephenson <wstephenson@kde.org>
3 Copyright (C) 2007 Daniel Gollub <dgollub@suse.de>
4 Copyright (C) 2007 Juan González Aguilera <jaguilera@opsiland.info>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "bluez-bluetoothsecurityadaptor.h"
22 #include <kdebug.h>
23 #include <ctime>
24 //BluezBluetoothSecurityPasskeyAgentAdaptor
25 BluezBluetoothSecurityPasskeyAgentAdaptor::BluezBluetoothSecurityPasskeyAgentAdaptor(BluezBluetoothSecurity * security)
26 :QDBusAbstractAdaptor(security),security(security),conn(QDBusConnection::systemBus())
28 serviceName = QString("/org/kde/solid/BluezBluetoothSecurityPasskeyAgentAdaptor%1").arg(time(NULL));
29 bool done = conn.registerObject(serviceName,security,QDBusConnection::ExportAdaptors);
30 if (!done) {
31 kDebug() << "Failed to register the object: " << conn.lastError().name() << " : " << conn.lastError().message();
32 serviceName = "";
33 } else {
34 kDebug() << "DBus service registered at "<< serviceName <<endl;
35 //TODO Add support for an specific local device
36 QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
37 iface.call("RegisterDefaultPasskeyAgent",serviceName);
38 if (iface.lastError().isValid()) {
39 kDebug() << "RegisterDefaultPasskeyAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
40 serviceName = "";
41 } else {
42 kDebug() << "RegisterDefaultPasskeyAgent succesfull!";
48 BluezBluetoothSecurityPasskeyAgentAdaptor::~ BluezBluetoothSecurityPasskeyAgentAdaptor()
50 kDebug() << k_funcinfo;
51 if (!serviceName.isEmpty())
53 QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
54 iface.call("UnregisterDefaultPasskeyAgent",serviceName);
55 if (iface.lastError().isValid()) {
56 kDebug() << "UnregisterDefaultPasskeyAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
57 serviceName = "";
58 } else {
59 kDebug() << "UnregisterDefaultPasskeyAgent Successful!:" << iface.lastError().name() << " : " << iface.lastError().message();
64 QString BluezBluetoothSecurityPasskeyAgentAdaptor::Request(const QString & path, const QString & address, bool numeric,const QDBusMessage &msg)
66 kDebug() << k_funcinfo;
67 Q_UNUSED(path)
68 if (security) {
69 QString answer = security->request(address,numeric);
70 if (!answer.isEmpty()) {
71 return answer;
72 } else {
73 QDBusMessage error = msg.createErrorReply("org.bluez.Error.Rejected","Pairing request rejected");
74 QDBusConnection::systemBus().send(error);
77 return "";//To satisfy the compiler, but the answer is already sent
80 void BluezBluetoothSecurityPasskeyAgentAdaptor::Confirm(const QString & path, const QString & address, const QString & value,const QDBusMessage &msg)
82 kDebug() << k_funcinfo;
83 Q_UNUSED(path)
84 if (security) {
85 if(security->confirm(address,value)) {
86 kDebug() << "Confirmed pin for " << address;
87 } else {
88 QDBusMessage error = msg.createErrorReply("org.bluez.Error.Rejected","Pairing request rejected");
89 QDBusConnection::systemBus().send(error);
94 void BluezBluetoothSecurityPasskeyAgentAdaptor::Display(const QString & path, const QString & address, const QString & value)
96 kDebug() << k_funcinfo;
97 Q_UNUSED(path)
98 if (security) {
99 security->display(address,value);
103 void BluezBluetoothSecurityPasskeyAgentAdaptor::Keypress(const QString & path, const QString & address)
105 kDebug() << k_funcinfo;
106 Q_UNUSED(path)
107 if (security) {
108 security->keypress(address);
112 void BluezBluetoothSecurityPasskeyAgentAdaptor::Complete(const QString & path, const QString & address)
114 kDebug() << k_funcinfo;
115 Q_UNUSED(path)
116 if (security) {
117 security->complete(address);
121 void BluezBluetoothSecurityPasskeyAgentAdaptor::Cancel(const QString & path, const QString & address)
123 kDebug() << k_funcinfo;
124 Q_UNUSED(path)
125 if (security) {
126 security->cancel(address);
130 void BluezBluetoothSecurityPasskeyAgentAdaptor::Release()
132 kDebug() << k_funcinfo;
135 //BluezBluetoothSecurityAuthorizationAgentAdaptor
136 BluezBluetoothSecurityAuthorizationAgentAdaptor::BluezBluetoothSecurityAuthorizationAgentAdaptor(BluezBluetoothSecurity * security)
137 :QDBusAbstractAdaptor(security),security(security),conn(QDBusConnection::systemBus())
139 serviceName = QString("/org/kde/solid/BluezBluetoothSecurityAuthorizationAgentAdaptor%1").arg(time(NULL));
140 bool done = conn.registerObject(
141 serviceName,security,QDBusConnection::ExportAdaptors);
142 if (!done) {
143 kDebug() << "Failed to register the object: " << conn.lastError().name() << " : " << conn.lastError().message();
144 serviceName = "";
145 } else {
146 kDebug() << "DBus service registered at "<< serviceName <<endl;
147 //TODO Add support for an specific local device
148 QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
149 iface.call("RegisterDefaultAuthorizationAgent",serviceName);
150 if (iface.lastError().isValid()) {
151 kDebug() << "RegisterDefaultAuthorizationAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
152 serviceName = "";
153 } else {
154 kDebug() << "RegisterDefaultAuthorizationAgent succesfull!";
159 BluezBluetoothSecurityAuthorizationAgentAdaptor::~ BluezBluetoothSecurityAuthorizationAgentAdaptor()
161 kDebug() << k_funcinfo;
162 if (!serviceName.isEmpty())
164 QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
165 iface.call("UnregisterDefaultAuthorizationAgent",serviceName);
166 if (iface.lastError().isValid()) {
167 kDebug() << "UnregisterDefaultAuthorizationAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
168 serviceName = "";
169 } else {
170 kDebug() << "UnregisterDefaultAuthorizationAgent Successful!:" << iface.lastError().name() << " : " << iface.lastError().message();
175 void BluezBluetoothSecurityAuthorizationAgentAdaptor::Authorize(const QString & adapter_path, const QString & address, const QString & service_path, const QString & uuid,const QDBusMessage &msg)
177 kDebug() << k_funcinfo;
178 Q_UNUSED(service_path)
179 if (security) {
180 if(security->authorize(adapter_path,address,uuid)) {
181 kDebug() << "Service with uuid "<< uuid <<" for " << address << " authorized";
182 } else {
183 QDBusMessage error = msg.createErrorReply("org.bluez.Error.Rejected","Authorization request rejected");
184 QDBusConnection::systemBus().send(error);
189 void BluezBluetoothSecurityAuthorizationAgentAdaptor::Cancel(const QString & adapter_path, const QString & address, const QString & service_path, const QString & uuid)
191 Q_UNUSED(service_path)
192 if (security) {
193 security->cancel(adapter_path,address,uuid);
197 void BluezBluetoothSecurityAuthorizationAgentAdaptor::Release()
199 kDebug() << k_funcinfo;
202 #include "bluez-bluetoothsecurityadaptor.moc"