summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/parser.cc113
-rw-r--r--noncore/net/opietooth/lib/parser.h34
2 files changed, 147 insertions, 0 deletions
diff --git a/noncore/net/opietooth/lib/parser.cc b/noncore/net/opietooth/lib/parser.cc
new file mode 100644
index 0000000..452917b
--- a/dev/null
+++ b/noncore/net/opietooth/lib/parser.cc
@@ -0,0 +1,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;
+}
diff --git a/noncore/net/opietooth/lib/parser.h b/noncore/net/opietooth/lib/parser.h
new file mode 100644
index 0000000..7642ac3
--- a/dev/null
+++ b/noncore/net/opietooth/lib/parser.h
@@ -0,0 +1,34 @@
+
+#ifndef OpieToothParser_H
+#define OpieToothParser_H
+
+#include <services.h>
+
+namespace OpieTooth {
+ class Parser{
+ public:
+ Parser(const QString& output );
+ ~Parser() {};
+ void setText(const QString& output );
+ Services::ValueList services()const;
+ private:
+ Services::ValueList m_list;
+ Services m_item;
+ void parse( const QString& );
+ bool parseName(const QString& );
+ bool parseRecHandle( const QString& );
+ bool parseClassId( const QString& );
+ bool parseProtocol( const QString& id );
+ bool parseProfile( const QString& ) ;
+ bool m_complete:1;
+ bool m_ok;
+ bool m_classOver:1;
+ bool m_protocolOver:1;
+ bool m_protocolAdded:1;
+ QString m_protName;
+ int m_protId;
+ };
+};
+
+
+#endif