summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib/parser.cc
authorzecke <zecke>2002-06-20 22:23:44 (UTC)
committer zecke <zecke>2002-06-20 22:23:44 (UTC)
commit7b4a1dfd56b64e588d3fe6c75a51490df13e9797 (patch) (side-by-side diff)
tree43db3e094004ad478c43d93ddeafed044534035e /noncore/net/opietooth/lib/parser.cc
parentc2eb66bc5c5ac4225edff8b369026bd208f8c148 (diff)
downloadopie-7b4a1dfd56b64e588d3fe6c75a51490df13e9797.zip
opie-7b4a1dfd56b64e588d3fe6c75a51490df13e9797.tar.gz
opie-7b4a1dfd56b64e588d3fe6c75a51490df13e9797.tar.bz2
German politicians suck
Diffstat (limited to 'noncore/net/opietooth/lib/parser.cc') (more/less context) (ignore 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 @@
using namespace OpieTooth;
+namespace {
+
+
+ // "Test Foo Bar" (0x3456)
+ // @param ret Test Foo Bar
+ // @eturn 13398
+ // tactic find " (
+int convert( const QString& line, QString& ret ) {
+ ret = QString::null;
+ int i = 0;
+ int pos = line.findRev("\" (");
+ if ( pos > 0 ) { // it shouldn't be at pos 0
+ ret = line.left(pos-1 ).stripWhiteSpace();
+ qWarning("ret: %s", ret.latin1() );
+ ret = ret.replace(QRegExp("[\"]"), "");
+ qWarning("ret: %s", ret.latin1() );
+ QString dummy = line.mid(pos + 4 );
+ qWarning("dummy: %s", dummy.latin1() );
+ dummy = dummy.remove( dummy.length() -1, 1 ); // remove the (
+ bool ok;
+ i = dummy.toInt(&ok, 16 );
+ }
+ return i;
+}
+
+};
+
+
Parser::Parser(const QString& output ) {
parse( output );
}
@@ -28,6 +56,7 @@ void Parser::parse( const QString& string) {
m_list.append( m_item );
Services serv;
m_item = serv;
+ m_complete = true;
continue;
}
}
@@ -37,6 +66,10 @@ void Parser::parse( const QString& string) {
if (parseProtocol( (*it) ) ) ;//continue;
if (parseProfile( (*it) ) ) ;//continue;
}
+ // missed the last one
+ if (m_complete) {
+ m_list.append(m_item );
+ }
}
bool Parser::parseName( const QString& str) {
if (str.startsWith("Service Name:") ) {
@@ -67,19 +100,18 @@ bool Parser::parseClassId( const QString& str) {
}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 ) );
- }
+
+ // "Obex Object Push" (0x1105)
+ // find backwards the " and the from 0 to pos and the mid pos+1
+ // then stripWhiteSpace add name replace '"' with ""
+ // and then convert 0x1105 toInt()
+ QString classes;
+ int ids;
+ ids = convert( str, classes );
+ qWarning("ids %d", ids );
+ m_item.setClassIdList( classes );
+ m_item.setClassIdList( ids );
+
return true;
}else
m_classOver = true;
@@ -91,23 +123,51 @@ bool Parser::parseProtocol( const QString& str) {
m_protocolAdded = false;
return true;
- }else if (m_protocolOver && str.startsWith(" ") ) {
+ }else if (m_protocolOver && str.startsWith(" ") ) { // "L2CAP" (0x0100)
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;
+ { // the find function
+ m_protId = convert(str, m_protName );
+ }
return true;
}else if (m_protocolOver && str.startsWith(" ") ) {
qWarning("tripple protocol filter");
m_protocolAdded = true;
+ QString dummy = str.stripWhiteSpace();
+ int pos = dummy.findRev(':');
+ if ( pos > -1 ) {
+ int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt();
+ Services::ProtocolDescriptor desc( m_protName, m_protId, port );
+ m_item.insertProtocolDescriptor( desc );
+ }
return true;
}else if (m_protocolOver ) {
m_protocolOver = false;
}
return false;
}
-bool Parser::parseProfile( const QString& ) {
+bool Parser::parseProfile( const QString& str) {
+ if (str.startsWith("Profile Descriptor List:") ) {
+ m_profOver = true;
+ }else if ( m_profOver && str.startsWith(" ") ) {
+ m_profId = convert( str, m_profName );
+ }else if ( m_profOver && str.startsWith(" ") ) {
+ // now find
+ int pos = str.findRev(':');
+ if ( pos > 0 ) {
+ int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt();
+ qWarning("dummyInt:%d", dummy );
+ Services::ProfileDescriptor desc( m_profName, m_profId, dummy );
+ m_item.insertProfileDescriptor(desc);
+ }
+ }else
+ m_profOver = false;
+
+
return false;
}