3
* XML Service Record parser of BlueZ D-Bus API
5
* Copyright (C) 2006 Daniel Gollub <dgollub@suse.de>
8
* This file is part of libkbluetooth.
10
* libkbluetooth is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* libkbluetooth is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with libkbluetooth; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
#include "servicerecord.h"
32
ServiceRecord::ServiceRecord(const QString &xml) : mXml(xml)
36
doc.setContent( xml );
38
QDomElement docElement = doc.documentElement();
40
for(QDomNode n = docElement.firstChild(); !n.isNull(); n = n.nextSibling() ) {
41
QDomElement e = n.toElement();
43
kdDebug() << e.text() << endl;
45
if ( e.attribute("id") == "0x0001" ) {
46
mUuid = parseAttributeUuid(e);
47
} else if ( e.attribute("id") == "0x0009" ) {
48
mServId = parseAttributeUuid(e);
49
} else if ( e.attribute("id") == "0x0004" ) {
50
mRfcommChannel = parseAttributeRfcomm(e);
51
} else if ( e.attribute("id") == "0x0100" ) {
52
mName = parseAttributeName(e);
53
} else if ( e.attribute("id") == "0x0101" ) {
55
mTyp = parseAttributeName(e);
61
ServiceRecord::~ServiceRecord()
65
QString ServiceRecord::parseAttributeName(const QDomElement &e)
67
kdDebug() << k_funcinfo << mXml << endl;
68
QDomNodeList list = e.elementsByTagName("text");
69
QString serviceName = list.item(0).toElement().attribute("value");
70
if (list.item(0).toElement().attribute("encoding") == "hex") {
71
QString localValue = list.item(0).toElement().attribute("value");
72
QString a = localValue.mid(0, 2);
75
serviceName.insert(0, (char) a.toInt(&ok, 16));
76
for (uint i=2; i < localValue.length(); i = i + 2) {
77
a = localValue.mid(i, 2);
78
serviceName.insert(i/2, (char) a.toInt(&ok, 16));
80
serviceName.setLength(localValue.length()/2 - 1);
83
kdDebug() << "serviceName: " << serviceName << endl;
87
QStringList ServiceRecord::parseAttributeUuid(const QDomElement &e)
91
QDomNodeList list = e.elementsByTagName("sequence").item(0).toElement().elementsByTagName("uuid");
92
for (uint i=0;i <list.count(); ++i) {
93
QString id = list.item(i).toElement().attribute("value");
100
int ServiceRecord::parseAttributeRfcomm(const QDomElement &e)
102
int rfcommChannelValue = -1;
104
QDomNodeList list = e.elementsByTagName("sequence");
105
for (uint i=0;i <list.count(); ++i) {
107
for( m = list.item(i).firstChild(); !m.isNull(); m = m.nextSibling() ) {
108
QDomNodeList list = e.elementsByTagName("uuid");
109
bool isRfcomm = false;
110
for (uint i=0;i <list.count(); ++i) {
111
if (list.item(i).toElement().tagName() == "uuid"
112
&& list.item(i).toElement().attribute("value") == "0x0003")
119
// get RFCOMM Channel
120
list = e.elementsByTagName("uint8");
121
for (uint i=0;i <list.count(); ++i) {
122
rfcommChannelValue = list.item(i).toElement().attribute("value").toInt(0, 16);
127
return rfcommChannelValue;