author | zecke <zecke> | 2002-06-19 20:18:26 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-19 20:18:26 (UTC) |
commit | c5492c760713b3ece235a6d53008e2cb042c5cfc (patch) (unidiff) | |
tree | e0ad3d7e25ba4640caf03000d83b53bef4687c5a | |
parent | 5c56a4cb4bd0aaf3fb2145feb018f8d074a58da2 (diff) | |
download | opie-c5492c760713b3ece235a6d53008e2cb042c5cfc.zip opie-c5492c760713b3ece235a6d53008e2cb042c5cfc.tar.gz opie-c5492c760713b3ece235a6d53008e2cb042c5cfc.tar.bz2 |
Sorry sandman for the .cc this will change
Here the actual parser
-rw-r--r-- | noncore/net/opietooth/lib/parser.cc | 113 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/parser.h | 34 |
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 @@ | |||
1 | |||
2 | #include <qstringlist.h> | ||
3 | |||
4 | #include "parser.h" | ||
5 | |||
6 | using namespace OpieTooth; | ||
7 | |||
8 | Parser::Parser(const QString& output ) { | ||
9 | parse( output ); | ||
10 | } | ||
11 | void Parser::setText(const QString& output) { | ||
12 | parse( output ); | ||
13 | } | ||
14 | Services::ValueList Parser::services() const { | ||
15 | return m_list; | ||
16 | } | ||
17 | void 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 | } | ||
41 | bool 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 | } | ||
49 | bool 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 | } | ||
63 | bool 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 | } | ||
88 | bool 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 | } | ||
111 | bool Parser::parseProfile( const QString& ) { | ||
112 | return false; | ||
113 | } | ||
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 @@ | |||
1 | |||
2 | #ifndef OpieToothParser_H | ||
3 | #define OpieToothParser_H | ||
4 | |||
5 | #include <services.h> | ||
6 | |||
7 | namespace OpieTooth { | ||
8 | class Parser{ | ||
9 | public: | ||
10 | Parser(const QString& output ); | ||
11 | ~Parser() {}; | ||
12 | void setText(const QString& output ); | ||
13 | Services::ValueList services()const; | ||
14 | private: | ||
15 | Services::ValueList m_list; | ||
16 | Services m_item; | ||
17 | void parse( const QString& ); | ||
18 | bool parseName(const QString& ); | ||
19 | bool parseRecHandle( const QString& ); | ||
20 | bool parseClassId( const QString& ); | ||
21 | bool parseProtocol( const QString& id ); | ||
22 | bool parseProfile( const QString& ) ; | ||
23 | bool m_complete:1; | ||
24 | bool m_ok; | ||
25 | bool m_classOver:1; | ||
26 | bool m_protocolOver:1; | ||
27 | bool m_protocolAdded:1; | ||
28 | QString m_protName; | ||
29 | int m_protId; | ||
30 | }; | ||
31 | }; | ||
32 | |||
33 | |||
34 | #endif | ||