summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/opietooth2/OTSDPService.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTSDPService.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTSDPService.cpp189
1 files changed, 189 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPService.cpp b/noncore/settings/networksettings2/opietooth2/OTSDPService.cpp
new file mode 100644
index 0000000..07b505c
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTSDPService.cpp
@@ -0,0 +1,189 @@
1/***************************************************************************
2 * Copyright (C) 2003 by Fred Schaettgen *
3 * kdebluetooth@schaettgen.de *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
10
11#include <opie2/odebug.h>
12
13#include <OTSDPAttribute.h>
14#include <OTSDPService.h>
15
16using namespace Opietooth2;
17
18OTSDPService::OTSDPService() : attributeList() {
19}
20
21OTSDPService::~OTSDPService() {
22 for (unsigned int n=0; n < attributeList.count(); ++n) {
23 delete attributeList[n].attr;
24 }
25}
26
27void OTSDPService::addAttribute(int id, OTSDPAttribute * attr) {
28 attributeList.resize( attributeList.size() + 1 );
29
30 attributeList[attributeList.size() - 1].id = id;
31 attributeList[attributeList.size() - 1].attr = attr;
32}
33
34const OTSDPAttribute & OTSDPService::attribute(int index) {
35 return *(attributeList[index].attr);
36}
37
38int OTSDPService::attributeID(int index) {
39 return attributeList[index].id;
40
41}
42
43OTSDPAttribute * OTSDPService::attributeByID(int id) {
44
45 for (unsigned int n=0; n < attributeList.count(); ++n) {
46 if (attributeList[n].id == id) {
47 return attributeList[n].attr;
48 }
49 }
50 return 0;
51}
52
53bool OTSDPService::recordHandle(uint32_t *handle) {
54 OTSDPAttribute * attrib;
55 attrib = attributeByID(0x00);
56 if( attrib && attrib->getType() == OTSDPAttribute::UINT) {
57 *handle = (uint32_t)attrib->getUInt().lo;
58 return true;
59 }
60 return false;
61}
62
63QString OTSDPService::name(void) {
64 QString S;
65 OTSDPAttribute * attrib;
66 attrib = attributeByID(0x100);
67 if( attrib && attrib->getType() == OTSDPAttribute::STRING) {
68 S = attrib->getString();
69 }
70 return S;
71}
72
73QString OTSDPService::description() {
74 QString S;
75 OTSDPAttribute * attrib;
76 attrib = attributeByID(0x101);
77 if ( attrib && attrib->getType() == OTSDPAttribute::STRING) {
78 S = attrib->getString();
79 }
80 return S;
81}
82
83UUIDVector OTSDPService::allUUIDs() {
84 UUIDVector uuidList;
85
86 for ( unsigned int i = 0;
87 i < attributeList.count();
88 i ++ ) {
89 int os;
90 UUIDVector subList = attributeList[i].attr->getAllUUIDs();
91 os = uuidList.size();
92 uuidList.resize( uuidList.size()+subList.count() );
93
94 for( unsigned int k = 0; k < subList.count(); k++ ) {
95 uuidList[os + k] = subList[k];
96 }
97 }
98 return uuidList;
99}
100
101bool OTSDPService::rfcommChannel(unsigned int &n) {
102 // Get the rfcomm channel
103 OTSDPAttribute * protoDescAttr;
104 // Get the the protocol descriptor list attribute (0x04)
105 protoDescAttr = attributeByID(0x04);
106 if( ! protoDescAttr ) {
107 return false;
108 }
109
110 AttributeVector & protoDescList = *(protoDescAttr->getSequence());
111
112 for( unsigned int i = 0;
113 i < protoDescList.count();
114 i ++ ) {
115 AttributeVector & attrList = *(protoDescList[i]->getSequence());
116
117 //The List must have at least 2 Attributes
118 //Example:
119 // UUID16 : 0x0003 - RFCOMM
120 // Channel/Port (Integer) : 0x6
121 if(attrList.size() >= 2) {
122 // The first Attribute of the list must be an UUID
123 if( attrList[0]->getType() != OTSDPAttribute::UUID)
124 continue;
125 // The UUID must have the value of "0x0003" that's the RFCOMM UUID
126 OTUUID rfcommUUID( "0x0003" );
127 if( attrList[0]->getUUID() != rfcommUUID) //RFCOMM UUID
128 continue;
129 //If the UUID is ok we get the rfcomm channel number
130 if( attrList[1]->getType() != OTSDPAttribute::UINT)
131 continue;
132
133 n = attrList[1]->getUInt().lo;
134
135 return true;
136 }
137 }
138 // If we're here, we haven't found a correct Rfcomm channel, so we return false
139 return false;
140}
141
142bool OTSDPService::hasClassID(const OTUUID & uuid) {
143 OTSDPAttribute * ClassIDAttr;
144
145 // Get the the ClassID descriptor list attribute (0x01)
146 ClassIDAttr = attributeByID( 0x01);
147 if( ! ClassIDAttr ) {
148 return false;
149 }
150
151 AttributeVector & ClassIDList = *(ClassIDAttr->getSequence());
152 for( unsigned int i = 0 ;
153 i < ClassIDList.count() ;
154 i ++ ) {
155 if( ClassIDList[i]->getType() != OTSDPAttribute::UUID)
156 continue;
157 if( ClassIDList[i]->getUUID() == uuid)
158 return true;
159 }
160 return false;
161}
162
163/** Get a vector of UUID of the services class Id List */
164UUIDVector OTSDPService::classIDList( void ) {
165
166 UUIDVector uuidList;
167 OTSDPAttribute * ClassIDAttr;
168
169 // Get the the ClassID descriptor list attribute (0x01)
170 ClassIDAttr = attributeByID( 0x01);
171 if( ! ClassIDAttr ) {
172 return uuidList;
173 }
174
175 AttributeVector & ClassIDList = *(ClassIDAttr->getSequence());
176
177 for( unsigned int i = 0 ;
178 i < ClassIDList.count() ;
179 i ++ ) {
180 if( ClassIDList[i]->getType() != OTSDPAttribute::UUID)
181 continue;
182
183 uuidList.resize( uuidList.size() + 1 );
184 uuidList[ uuidList.size() - 1 ] = ClassIDList[i]->getUUID();
185 }
186
187 return uuidList;
188}
189