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