summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp329
1 files changed, 329 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp
new file mode 100644
index 0000000..9069c09
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp
@@ -0,0 +1,329 @@
1//-*-c++-*-
2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12#include <assert.h>
13#include <qregexp.h>
14#include <opie2/odebug.h>
15
16#include <OTUUID.h>
17#include <OTSDPAttribute.h>
18
19using namespace Opietooth2;
20
21OTSDPAttribute::OTSDPAttribute() {
22 type = INVALID;
23 memset( &Value, 0, sizeof( Value ) );
24}
25
26OTSDPAttribute::~OTSDPAttribute() {
27 if( type == INT ) {
28 delete Value.intVal;
29 } else if( type == UUID ) {
30 delete Value.uuidVal;
31 } else if( type == UINT ) {
32 delete Value.uintVal;
33 } else if( type == STRING ||
34 type == URL
35 ) {
36 delete Value.stringVal;
37 } else if( type == ALTERNATIVE ||
38 type == SEQUENCE
39 ) {
40 delete Value.sequenceVal;
41 }
42}
43
44OTSDPAttribute::OTSDPAttribute( sdp_data_t * attrib ) {
45 setNil();
46 switch( attrib->dtd ) {
47 case SDP_DATA_NIL: // Nil type
48 { setNil();
49 break;
50 }
51 case SDP_UINT8: // Unsigned integer
52 setUInt(attrib->val.uint8);
53 break;
54 case SDP_UINT16: // Unsigned integer
55 setUInt(attrib->val.uint16);
56 break;
57 case SDP_UINT32: // Unsigned integer
58 setUInt(attrib->val.uint32);
59 break;
60 case SDP_UINT64: // Unsigned integer
61 setUInt(attrib->val.uint64);
62 break;
63 case SDP_UINT128: // Unsigned integer
64 // setUInt(attrib->val.uint16);
65 assert(false); // BUG/TODO: uint128 integers not supported
66 break;
67 case SDP_INT8: // Unsigned integer
68 setInt(attrib->val.int8);
69 break;
70 case SDP_INT16: // Unsigned integer
71 setInt(attrib->val.int16);
72 break;
73 case SDP_INT32: // Unsigned integer
74 setInt(attrib->val.int32);
75 break;
76 case SDP_INT64: // Unsigned integer
77 setInt(attrib->val.int64);
78 break;
79 case SDP_INT128: // Unsigned integer
80 // newAttr.setInt(attrib->val.uint16);
81 assert(false); // BUG/TODO: uint128 integers not supported
82 break;
83 case SDP_UUID16:
84 { OTUUID id;
85 ::uuid_t uuidVal = attrib->val.uuid;
86 id.setUUID32(uuidVal.value.uuid16);
87 setUUID(id );
88 }
89 break;
90 case SDP_UUID32:
91 { OTUUID id;
92 ::uuid_t uuidVal = attrib->val.uuid;
93 id.setUUID32(uuidVal.value.uuid32);
94 setUUID(id );
95 }
96 break;
97 case SDP_UUID128:
98 { OTUUID id;
99 ::uuid_t uuidVal = attrib->val.uuid;
100 uint64_t* v128;
101 v128 = reinterpret_cast<uint64_t*>(&(uuidVal.value.uuid128));
102 id.setUUID128(v128[0], v128[1]);
103 setUUID(id );
104 }
105 break;
106 case SDP_TEXT_STR_UNSPEC :
107 case SDP_TEXT_STR8 :
108 case SDP_TEXT_STR16 :
109 case SDP_TEXT_STR32 :
110 setString( QString(attrib->val.str) );
111 break;
112 case SDP_URL_STR_UNSPEC :
113 case SDP_URL_STR8 :
114 case SDP_URL_STR16 :
115 case SDP_URL_STR32 :
116 setURL( QString(attrib->val.str) );
117 break;
118 case SDP_BOOL:
119 setBool( attrib->val.int8 != 0);
120 break;
121 case SDP_SEQ_UNSPEC :
122 case SDP_SEQ8 :
123 case SDP_SEQ16 :
124 case SDP_SEQ32 :
125 case SDP_ALT_UNSPEC :
126 case SDP_ALT8 :
127 case SDP_ALT16 :
128 case SDP_ALT32 :
129 { AttributeVector subAttribs;
130 OTSDPAttribute * Attr;
131 sdp_data_t* subAttrib = attrib->val.dataseq;
132
133 for (; subAttrib; subAttrib = subAttrib->next) {
134
135 Attr = new OTSDPAttribute(subAttrib);
136 subAttribs.resize( subAttribs.size() + 1 );
137 subAttribs.insert( subAttribs.size() - 1, Attr );
138 }
139
140 if( attrib->dtd == SDP_ALT_UNSPEC ||
141 attrib->dtd == SDP_ALT8 ||
142 attrib->dtd == SDP_ALT16 ||
143 attrib->dtd == SDP_ALT32 ) {
144 setAlternative(subAttribs);
145 } else {
146 setSequence(subAttribs);
147 }
148 break;
149 }
150 } // end case
151}
152
153QString OTSDPAttribute::toString( void ) {
154 QString S;
155 switch( type ) {
156 case INVALID :
157 S = "invalid";
158 break;
159 case NIL :
160 S = "NIL";
161 break;
162 case UINT :
163 S = Value.uintVal->toString();
164 break;
165 case INT :
166 S = Value.intVal->toString();
167 break;
168 case UUID :
169 S = Value.uuidVal->toString();
170 break;
171 case BOOLEAN :
172 S = (Value.boolVal) ? "true" : "false";
173 break;
174 case STRING :
175 S = *(Value.stringVal);
176 break;
177 case URL :
178 S = *(Value.stringVal);
179 break;
180 case SEQUENCE :
181 S.sprintf( "Sequence(%d)", Value.sequenceVal->count() );
182 break;
183 case ALTERNATIVE :
184 S.sprintf( "Alternative(%d)", Value.sequenceVal->count() );
185 break;
186 case UNKNOWN :
187 S = "unknown";
188 break;
189 }
190 return S;
191}
192
193void OTSDPAttribute::setNil() {
194 type = NIL;
195}
196
197void OTSDPAttribute::setInt(const OTSDPAttribute::int128_t & val) {
198 type = INT;
199 Value.intVal = new int128_t( val );
200}
201
202void OTSDPAttribute::setUInt(const uint128_t & val) {
203 type = UINT;
204 Value.uintVal = new uint128_t(val);
205}
206
207void OTSDPAttribute::setUUID(const OTUUID & val) {
208 type = UUID;
209 Value.uuidVal = new OTUUID( val );
210}
211
212void OTSDPAttribute::setBool(bool val) {
213 type = BOOLEAN;
214 Value.boolVal = val;
215}
216
217void OTSDPAttribute::setString( const QString & val) {
218 type = STRING;
219 Value.stringVal = new QString( val );
220}
221
222void OTSDPAttribute::setURL( const QString & val) {
223 type = URL;
224 Value.stringVal = new QString(val);
225}
226
227void OTSDPAttribute::setSequence(const AttributeVector& val) {
228 type = SEQUENCE;
229 Value.sequenceVal = new AttributeVector();
230 Value.sequenceVal->setAutoDelete( TRUE );
231 *Value.sequenceVal = val;
232}
233
234void OTSDPAttribute::setAlternative(const AttributeVector& val) {
235 type = ALTERNATIVE;
236 Value.sequenceVal = new AttributeVector();
237 Value.sequenceVal->setAutoDelete( TRUE );
238 *Value.sequenceVal = val;
239}
240
241QString OTSDPAttribute::getString() {
242 assert(type == STRING);
243 return *Value.stringVal;
244}
245
246QString OTSDPAttribute::getURL() {
247 assert(type == URL);
248 return *Value.stringVal;
249}
250
251const OTSDPAttribute::int128_t & OTSDPAttribute::getInt() {
252 assert(type == INT);
253 return *Value.intVal;
254}
255
256
257const OTSDPAttribute::uint128_t & OTSDPAttribute::getUInt() {
258 assert(type == UINT);
259 return *Value.uintVal;
260}
261
262const OTUUID & OTSDPAttribute::getUUID() {
263 assert(type == UUID);
264 return *Value.uuidVal;
265}
266
267bool OTSDPAttribute::getBool() {
268 assert(type == BOOLEAN);
269 return Value.boolVal;
270}
271
272AttributeVector * OTSDPAttribute::getSequence() {
273 assert(type == SEQUENCE);
274 return Value.sequenceVal;
275}
276
277AttributeVector * OTSDPAttribute::getAlternative() {
278 assert(type == ALTERNATIVE);
279 return Value.sequenceVal;
280}
281
282UUIDVector OTSDPAttribute::getAllUUIDs() {
283
284 UUIDVector uuids;
285
286 if (getType() == UUID) {
287 uuids.resize( uuids.size()+1 );
288 uuids[uuids.size()-1] = getUUID();
289 } else {
290 AttributeVector * subAttributes = 0 ;
291
292 if (getType() == SEQUENCE) {
293 subAttributes = getSequence();
294 } else if (getType() == ALTERNATIVE) {
295 subAttributes = getAlternative();
296 }
297
298 int os;
299 for( unsigned int i = 0; i < subAttributes->count(); i++ ) {
300 UUIDVector subUUIDs = (*subAttributes)[i]->getAllUUIDs();
301
302 os = uuids.size();
303 uuids.resize( uuids.size()+subUUIDs.count() );
304
305 for( unsigned int k = 0; k < subUUIDs.count(); k++ ) {
306 uuids[os + k] = subUUIDs[k];
307 }
308 }
309 }
310 return uuids;
311}
312
313static char * Attr2String[] = {
314 "Invalid",
315 "Nil",
316 "UInt",
317 "int",
318 "UUID",
319 "Boolean",
320 "String",
321 "Sequence",
322 "Alternative",
323 "URL",
324 "Unknown"
325};
326
327const char * OTSDPAttribute::getTypeString() {
328 return Attr2String[type];
329}