summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib/parser.cc
Unidiff
Diffstat (limited to 'noncore/net/opietooth/lib/parser.cc') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/parser.cc90
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
@@ -5,6 +5,34 @@
5 5
6using namespace OpieTooth; 6using namespace OpieTooth;
7 7
8namespace {
9
10
11 // "Test Foo Bar" (0x3456)
12 // @param ret Test Foo Bar
13 // @eturn 13398
14 // tactic find " (
15int 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
8Parser::Parser(const QString& output ) { 36Parser::Parser(const QString& output ) {
9 parse( output ); 37 parse( output );
10} 38}
@@ -28,6 +56,7 @@ void Parser::parse( const QString& string) {
28 m_list.append( m_item ); 56 m_list.append( m_item );
29 Services serv; 57 Services serv;
30 m_item = serv; 58 m_item = serv;
59 m_complete = true;
31 continue; 60 continue;
32 } 61 }
33 } 62 }
@@ -37,6 +66,10 @@ void Parser::parse( const QString& string) {
37 if (parseProtocol( (*it) ) ) ;//continue; 66 if (parseProtocol( (*it) ) ) ;//continue;
38 if (parseProfile( (*it) ) ) ;//continue; 67 if (parseProfile( (*it) ) ) ;//continue;
39 } 68 }
69 // missed the last one
70 if (m_complete) {
71 m_list.append(m_item );
72 }
40} 73}
41bool Parser::parseName( const QString& str) { 74bool Parser::parseName( const QString& str) {
42 if (str.startsWith("Service Name:") ) { 75 if (str.startsWith("Service Name:") ) {
@@ -67,19 +100,18 @@ bool Parser::parseClassId( const QString& str) {
67 }else if ( m_classOver ) { // ok now are the informations in place 100 }else if ( m_classOver ) { // ok now are the informations in place
68 101
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;
84 }else 116 }else
85 m_classOver = true; 117 m_classOver = true;
@@ -91,23 +123,51 @@ bool Parser::parseProtocol( const QString& str) {
91 m_protocolAdded = false; 123 m_protocolAdded = false;
92 return true; 124 return true;
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
97 Services::ProtocolDescriptor desc( m_protName, m_protId ); 130 Services::ProtocolDescriptor desc( m_protName, m_protId );
98 m_item.insertProtocolDescriptor( desc ); 131 m_item.insertProtocolDescriptor( desc );
99 } 132 }
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;
102 }else if (m_protocolOver && str.startsWith(" ") ) { 138 }else if (m_protocolOver && str.startsWith(" ") ) {
103 qWarning("tripple protocol filter"); 139 qWarning("tripple protocol filter");
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;
106 }else if (m_protocolOver ) { 149 }else if (m_protocolOver ) {
107 m_protocolOver = false; 150 m_protocolOver = false;
108 } 151 }
109 return false; 152 return false;
110} 153}
111bool Parser::parseProfile( const QString& ) { 154bool 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;
113} 173}