Diffstat (limited to 'noncore/net/opietooth/lib/parser.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/lib/parser.cc | 90 |
1 files changed, 75 insertions, 15 deletions
diff --git a/noncore/net/opietooth/lib/parser.cc b/noncore/net/opietooth/lib/parser.cc index 452917b..18d534e 100644 --- a/noncore/net/opietooth/lib/parser.cc +++ b/noncore/net/opietooth/lib/parser.cc | |||
@@ -7,2 +7,30 @@ using namespace OpieTooth; | |||
7 | 7 | ||
8 | namespace { | ||
9 | |||
10 | |||
11 | // "Test Foo Bar" (0x3456) | ||
12 | // @param ret Test Foo Bar | ||
13 | // @eturn 13398 | ||
14 | // tactic find " ( | ||
15 | int convert( const QString& line, QString& ret ) { | ||
16 | ret = QString::null; | ||
17 | int i = 0; | ||
18 | int pos = line.findRev("\" ("); | ||
19 | if ( pos > 0 ) { // it shouldn't be at pos 0 | ||
20 | ret = line.left(pos-1 ).stripWhiteSpace(); | ||
21 | qWarning("ret: %s", ret.latin1() ); | ||
22 | ret = ret.replace(QRegExp("[\"]"), ""); | ||
23 | qWarning("ret: %s", ret.latin1() ); | ||
24 | QString dummy = line.mid(pos + 4 ); | ||
25 | qWarning("dummy: %s", dummy.latin1() ); | ||
26 | dummy = dummy.remove( dummy.length() -1, 1 ); // remove the ( | ||
27 | bool ok; | ||
28 | i = dummy.toInt(&ok, 16 ); | ||
29 | } | ||
30 | return i; | ||
31 | } | ||
32 | |||
33 | }; | ||
34 | |||
35 | |||
8 | Parser::Parser(const QString& output ) { | 36 | Parser::Parser(const QString& output ) { |
@@ -30,2 +58,3 @@ void Parser::parse( const QString& string) { | |||
30 | m_item = serv; | 58 | m_item = serv; |
59 | m_complete = true; | ||
31 | continue; | 60 | continue; |
@@ -39,2 +68,6 @@ void Parser::parse( const QString& string) { | |||
39 | } | 68 | } |
69 | // missed the last one | ||
70 | if (m_complete) { | ||
71 | m_list.append(m_item ); | ||
72 | } | ||
40 | } | 73 | } |
@@ -69,15 +102,14 @@ bool Parser::parseClassId( const QString& str) { | |||
69 | m_classOver = false; | 102 | m_classOver = false; |
70 | QStringList list = QStringList::split('\n', str.stripWhiteSpace() ); | 103 | |
71 | 104 | // "Obex Object Push" (0x1105) | |
72 | if ( list.count() == 2 ) { | 105 | // find backwards the " and the from 0 to pos and the mid pos+1 |
73 | m_item.setClassIdList( list[0] ); | 106 | // then stripWhiteSpace add name replace '"' with "" |
74 | // now let's parse the number (0x1105) | 107 | // and then convert 0x1105 toInt() |
75 | QString classId= list[1]; | 108 | QString classes; |
76 | int classIdInt; | 109 | int ids; |
77 | qWarning("%s", list[1].latin1() ); | 110 | ids = convert( str, classes ); |
78 | classId = classId.remove(0, 3 ); | 111 | qWarning("ids %d", ids ); |
79 | classId = classId.remove( classId.length()-1, 1 ); | 112 | m_item.setClassIdList( classes ); |
80 | qWarning("%s", classId.latin1() ); | 113 | m_item.setClassIdList( ids ); |
81 | m_item.setClassIdList( classId.toInt(&m_ok, 16 ) ); | 114 | |
82 | } | ||
83 | return true; | 115 | return true; |
@@ -93,4 +125,5 @@ bool Parser::parseProtocol( const QString& str) { | |||
93 | 125 | ||
94 | }else if (m_protocolOver && str.startsWith(" ") ) { | 126 | }else if (m_protocolOver && str.startsWith(" ") ) { // "L2CAP" (0x0100) |
95 | qWarning("double protocol filter"); | 127 | qWarning("double protocol filter"); |
128 | |||
96 | if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now | 129 | if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now |
@@ -100,2 +133,5 @@ bool Parser::parseProtocol( const QString& str) { | |||
100 | m_protocolAdded = false; | 133 | m_protocolAdded = false; |
134 | { // the find function | ||
135 | m_protId = convert(str, m_protName ); | ||
136 | } | ||
101 | return true; | 137 | return true; |
@@ -104,2 +140,9 @@ bool Parser::parseProtocol( const QString& str) { | |||
104 | m_protocolAdded = true; | 140 | m_protocolAdded = true; |
141 | QString dummy = str.stripWhiteSpace(); | ||
142 | int pos = dummy.findRev(':'); | ||
143 | if ( pos > -1 ) { | ||
144 | int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt(); | ||
145 | Services::ProtocolDescriptor desc( m_protName, m_protId, port ); | ||
146 | m_item.insertProtocolDescriptor( desc ); | ||
147 | } | ||
105 | return true; | 148 | return true; |
@@ -110,3 +153,20 @@ bool Parser::parseProtocol( const QString& str) { | |||
110 | } | 153 | } |
111 | bool Parser::parseProfile( const QString& ) { | 154 | bool Parser::parseProfile( const QString& str) { |
155 | if (str.startsWith("Profile Descriptor List:") ) { | ||
156 | m_profOver = true; | ||
157 | }else if ( m_profOver && str.startsWith(" ") ) { | ||
158 | m_profId = convert( str, m_profName ); | ||
159 | }else if ( m_profOver && str.startsWith(" ") ) { | ||
160 | // now find | ||
161 | int pos = str.findRev(':'); | ||
162 | if ( pos > 0 ) { | ||
163 | int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt(); | ||
164 | qWarning("dummyInt:%d", dummy ); | ||
165 | Services::ProfileDescriptor desc( m_profName, m_profId, dummy ); | ||
166 | m_item.insertProfileDescriptor(desc); | ||
167 | } | ||
168 | }else | ||
169 | m_profOver = false; | ||
170 | |||
171 | |||
112 | return false; | 172 | return false; |