blob: 452917bc187fecdee5fbc38bd3b93d20b1a4ea7c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#include <qstringlist.h>
#include "parser.h"
using namespace OpieTooth;
Parser::Parser(const QString& output ) {
parse( output );
}
void Parser::setText(const QString& output) {
parse( output );
}
Services::ValueList Parser::services() const {
return m_list;
}
void Parser::parse( const QString& string) {
m_list.clear();
m_complete = true;
QStringList list = QStringList::split('\n', string );
QStringList::Iterator it;
for (it = list.begin(); it != list.end(); ++it ) {
if ( (*it).startsWith("Browsing") ) continue;
if ( (*it).isEmpty() ) { // line is empty because a new Service begins
// now see if complete and add
if (m_complete ) {
m_list.append( m_item );
Services serv;
m_item = serv;
continue;
}
}
if (parseName( (*it) ) ) ;//continue;
if (parseRecHandle( (*it) ) ) ;//continue;
if (parseClassId( (*it) ) ) ;//continue;
if (parseProtocol( (*it) ) ) ;//continue;
if (parseProfile( (*it) ) ) ;//continue;
}
}
bool Parser::parseName( const QString& str) {
if (str.startsWith("Service Name:") ) {
m_item.setServiceName( str.mid(13).stripWhiteSpace() );
qWarning(m_item.serviceName() );
return true;
}
return false;
}
bool Parser::parseRecHandle( const QString& str) {
if (str.startsWith("Service RecHandle:" ) ) {
QString out = str.mid(18 ).stripWhiteSpace();
qWarning("out %s", out.latin1() );
int value = out.toInt(&m_ok, 16 );
if (m_ok && (value != -1) )
m_complete = true;
else
m_complete = false;
return true;
m_item.setRecHandle( value );
}
return false;
}
bool Parser::parseClassId( const QString& str) {
if (str.startsWith("Service Class ID List:") ) {
m_classOver = true;
return true;
}else if ( m_classOver ) { // ok now are the informations in place
m_classOver = false;
QStringList list = QStringList::split('\n', str.stripWhiteSpace() );
if ( list.count() == 2 ) {
m_item.setClassIdList( list[0] );
// now let's parse the number (0x1105)
QString classId= list[1];
int classIdInt;
qWarning("%s", list[1].latin1() );
classId = classId.remove(0, 3 );
classId = classId.remove( classId.length()-1, 1 );
qWarning("%s", classId.latin1() );
m_item.setClassIdList( classId.toInt(&m_ok, 16 ) );
}
return true;
}else
m_classOver = true;
return false;
}
bool Parser::parseProtocol( const QString& str) {
if (str.startsWith("Protocol Descriptor List:") ) {
m_protocolOver = true;
m_protocolAdded = false;
return true;
}else if (m_protocolOver && str.startsWith(" ") ) {
qWarning("double protocol filter");
if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now
Services::ProtocolDescriptor desc( m_protName, m_protId );
m_item.insertProtocolDescriptor( desc );
}
m_protocolAdded = false;
return true;
}else if (m_protocolOver && str.startsWith(" ") ) {
qWarning("tripple protocol filter");
m_protocolAdded = true;
return true;
}else if (m_protocolOver ) {
m_protocolOver = false;
}
return false;
}
bool Parser::parseProfile( const QString& ) {
return false;
}
|