summaryrefslogtreecommitdiff
authorkorovkin <korovkin>2006-03-19 14:42:34 (UTC)
committer korovkin <korovkin>2006-03-19 14:42:34 (UTC)
commitadbd8bde1b0b24e5ea7047dea7228451964ac23a (patch) (unidiff)
tree761e7695e2c88ae2ac40d9b4e4adeff7d931cddc
parent3b671ecea335b81c65ec03ad70fa3f25e9bb0a3e (diff)
downloadopie-adbd8bde1b0b24e5ea7047dea7228451964ac23a.zip
opie-adbd8bde1b0b24e5ea7047dea7228451964ac23a.tar.gz
opie-adbd8bde1b0b24e5ea7047dea7228451964ac23a.tar.bz2
We scan ports prior to scanning names.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/parser.cc22
1 files changed, 10 insertions, 12 deletions
diff --git a/noncore/net/opietooth/lib/parser.cc b/noncore/net/opietooth/lib/parser.cc
index 7e95907..d20b9f3 100644
--- a/noncore/net/opietooth/lib/parser.cc
+++ b/noncore/net/opietooth/lib/parser.cc
@@ -30,176 +30,174 @@ int convert( const QString& line, QString& ret ) {
30 //owarn << "ret: " << ret.latin1() << oendl; 30 //owarn << "ret: " << ret.latin1() << oendl;
31 QString dummy = line.mid(pos + 5 ); 31 QString dummy = line.mid(pos + 5 );
32 //owarn << "dummy: " << dummy.latin1() << oendl; 32 //owarn << "dummy: " << dummy.latin1() << oendl;
33 dummy = dummy.replace(QRegExp("[)]"), ""); 33 dummy = dummy.replace(QRegExp("[)]"), "");
34 //owarn << "dummy: " << dummy.latin1() << oendl; 34 //owarn << "dummy: " << dummy.latin1() << oendl;
35// dummy = dummy.remove( dummy.length() -2, 1 ); // remove the ) 35// dummy = dummy.remove( dummy.length() -2, 1 ); // remove the )
36 bool ok; 36 bool ok;
37 i = dummy.toInt(&ok, 16 ); 37 i = dummy.toInt(&ok, 16 );
38 //if (ok ) { 38 //if (ok ) {
39 // owarn << "converted " << i << oendl; 39 // owarn << "converted " << i << oendl;
40 //}else owarn << "failed" << oendl; 40 //}else owarn << "failed" << oendl;
41 //owarn << "exiting" << oendl; 41 //owarn << "exiting" << oendl;
42 return i; 42 return i;
43 } 43 }
44 //owarn << "output " << i << oendl; 44 //owarn << "output " << i << oendl;
45 return i; 45 return i;
46} 46}
47 47
48}; 48};
49 49
50 50
51Parser::Parser(const QString& output ) { 51Parser::Parser(const QString& output ) {
52 parse( output ); 52 parse( output );
53} 53}
54void Parser::setText(const QString& output) { 54void Parser::setText(const QString& output) {
55 parse( output ); 55 parse( output );
56} 56}
57Services::ValueList Parser::services() const { 57Services::ValueList Parser::services() const {
58 return m_list; 58 return m_list;
59} 59}
60void Parser::parse( const QString& string) { 60void Parser::parse( const QString& string) {
61 m_list.clear(); 61 m_list.clear();
62 m_complete = true; 62 m_complete = true;
63 QStringList list = QStringList::split('\n', string,TRUE ); 63 QStringList list = QStringList::split('\n', string,TRUE );
64 QStringList::Iterator it; 64 QStringList::Iterator it;
65 for (it = list.begin(); it != list.end(); ++it ) { 65 for (it = list.begin(); it != list.end(); ++it ) {
66 //owarn << "line:" << (*it).latin1() << oendl; 66 //owarn << "line:" << (*it).latin1() << oendl;
67 if ( (*it).startsWith("Browsing") ) continue; 67 if ( (*it).startsWith("Browsing") ) continue;
68 68
69 if ( (*it).stripWhiteSpace().isEmpty() ) { // line is empty because a new Service begins 69 if ( (*it).stripWhiteSpace().isEmpty() ) { // line is empty because a new Service begins
70 owarn << "could add" << oendl; 70 owarn << "could add" << oendl;
71 // now see if complete and add 71 // now see if complete and add
72 if (m_complete ) { 72 if (m_complete ) {
73 if (!m_item.serviceName().isEmpty() ) 73 if (!m_item.serviceName().isEmpty() )
74 m_list.append( m_item ); 74 m_list.append( m_item );
75 Services serv; 75 Services serv;
76 m_item = serv; 76 m_item = serv;
77 m_complete = true; 77 m_complete = true;
78 continue; 78 continue;
79 } 79 }
80 } 80 }
81 if (parseName( (*it) ) ) ;//continue; 81 if (parseName( (*it) ) ) ;//continue;
82 if (parseRecHandle( (*it) ) ) ;//continue; 82 if (parseRecHandle( (*it) ) ) ;//continue;
83 if (parseClassId( (*it) ) ) ;//continue; 83 if (parseClassId( (*it) ) ) ;//continue;
84 if (parseProtocol( (*it) ) ) ;//continue; 84 if (parseProtocol( (*it) ) ) ;//continue;
85 if (parseProfile( (*it) ) ) ;//continue; 85 if (parseProfile( (*it) ) ) ;//continue;
86 } 86 }
87 // missed the last one 87 // missed the last one
88 if (m_complete) { 88 if (m_complete) {
89// owarn << "adding" << oendl; 89// owarn << "adding" << oendl;
90 if (!m_item.serviceName().isEmpty() ) 90 if (!m_item.serviceName().isEmpty() )
91 m_list.append(m_item ); 91 m_list.append(m_item );
92 } 92 }
93 QValueList<Services>::Iterator it2; 93 QValueList<Services>::Iterator it2;
94 94
95 if (m_list.isEmpty() ) 95 if (m_list.isEmpty() )
96 owarn << "m_list is empty" << oendl; 96 owarn << "m_list is empty" << oendl;
97 for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) { 97 for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) {
98 owarn << "name " << (*it2).serviceName().latin1() << oendl; 98 owarn << "name " << (*it2).serviceName().latin1() << oendl;
99 } 99 }
100} 100}
101bool Parser::parseName( const QString& str) { 101bool Parser::parseName( const QString& str) {
102 if (str.startsWith("Service Name:") ) { 102 if (str.startsWith("Service Name:") ) {
103 m_item.setServiceName( str.mid(13).stripWhiteSpace() ); 103 m_item.setServiceName( str.mid(13).stripWhiteSpace() );
104 owarn << m_item.serviceName() << oendl; 104 owarn << m_item.serviceName() << oendl;
105 return true; 105 return true;
106 } 106 }
107 return false; 107 return false;
108} 108}
109bool Parser::parseRecHandle( const QString& str) { 109bool Parser::parseRecHandle( const QString& str) {
110 if (str.startsWith("Service RecHandle:" ) ) { 110 if (str.startsWith("Service RecHandle:" ) ) {
111 QString out = str.mid(18 ).stripWhiteSpace(); 111 QString out = str.mid(18 ).stripWhiteSpace();
112 owarn << "out " << out.latin1() << oendl; 112 owarn << "out " << out.latin1() << oendl;
113 int value = out.mid(2).toInt(&m_ok, 16 ); 113 int value = out.mid(2).toInt(&m_ok, 16 );
114 if (m_ok && (value != -1) ) 114 if (m_ok && (value != -1) )
115 m_complete = true; 115 m_complete = true;
116 else 116 else
117 m_complete = false; 117 m_complete = false;
118 owarn << "rec handle " << value << oendl; 118 owarn << "rec handle " << value << oendl;
119 m_item.setRecHandle( value ); 119 m_item.setRecHandle( value );
120 return true; 120 return true;
121 121
122 } 122 }
123 return false; 123 return false;
124} 124}
125bool Parser::parseClassId( const QString& str) { 125bool Parser::parseClassId( const QString& str) {
126 if (str.startsWith("Service Class ID List:") ) { 126 if (str.startsWith("Service Class ID List:") ) {
127 owarn << "found class id" << oendl; 127 owarn << "found class id" << oendl;
128 owarn << "line: " << str.latin1() << oendl; 128 owarn << "line: " << str.latin1() << oendl;
129 m_classOver = true; 129 m_classOver = true;
130 return true; 130 return true;
131 }else if ( m_classOver && str.startsWith(" " ) ){ // ok now are the informations in place 131 }else if ( m_classOver && str.startsWith(" " ) ){ // ok now are the informations in place
132 owarn << "line with class id" << oendl; 132 owarn << "line with class id" << oendl;
133 owarn << str.latin1() << oendl; 133 owarn << str.latin1() << oendl;
134 134
135 // "Obex Object Push" (0x1105) 135 // "Obex Object Push" (0x1105)
136 // find backwards the " and the from 0 to pos and the mid pos+1 136 // find backwards the " and the from 0 to pos and the mid pos+1
137 // then stripWhiteSpace add name replace '"' with "" 137 // then stripWhiteSpace add name replace '"' with ""
138 // and then convert 0x1105 toInt() 138 // and then convert 0x1105 toInt()
139 QString classes; 139 QString classes;
140 int ids; 140 int ids;
141 ids = convert( str, classes ); 141 ids = convert( str, classes );
142 owarn << "ids " << ids << oendl; 142 owarn << "ids " << ids << oendl;
143 m_item.insertClassId( ids, classes ); 143 m_item.insertClassId( ids, classes );
144 144
145 return true; 145 return true;
146 }else{ 146 }else{
147 owarn << "Else " << m_classOver << oendl; 147 owarn << "Else " << m_classOver << oendl;
148 m_classOver = false; 148 m_classOver = false;
149 } 149 }
150 return false; 150 return false;
151} 151}
152bool Parser::parseProtocol( const QString& str) { 152bool Parser::parseProtocol( const QString& str) {
153 if (str.startsWith("Protocol Descriptor List:") ) { 153 if (str.startsWith("Protocol Descriptor List:") ) {
154 m_protocolOver = true; 154 m_protocolOver = true;
155 m_protocolAdded = false; 155 m_protocolAdded = false;
156 return true; 156 return true;
157 157
158 }else if (m_protocolOver && str.startsWith(" ") ) {
159 m_protocolAdded = true;
160 QString dummy = str.stripWhiteSpace();
161 int pos = dummy.findRev(':');
162 if ( pos > -1 ) {
163 int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt();
164 Services::ProtocolDescriptor desc( m_protName, m_protId, port );
165 m_item.insertProtocolDescriptor( desc );
166 }
167 return true;
158 }else if (m_protocolOver && str.startsWith(" ") ) { // "L2CAP" (0x0100) 168 }else if (m_protocolOver && str.startsWith(" ") ) { // "L2CAP" (0x0100)
159 owarn << "double protocol filter" << oendl;
160 169
161 if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now 170 if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now
162 Services::ProtocolDescriptor desc( m_protName, m_protId ); 171 Services::ProtocolDescriptor desc( m_protName, m_protId );
163 m_item.insertProtocolDescriptor( desc ); 172 m_item.insertProtocolDescriptor( desc );
164 } 173 }
165 m_protocolAdded = false; 174 m_protocolAdded = false;
166 { // the find function 175 { // the find function
167 m_protId = convert(str, m_protName ); 176 m_protId = convert(str, m_protName );
168 } 177 }
169 return true; 178 return true;
170 }else if (m_protocolOver && str.startsWith(" ") ) {
171 owarn << "tripple protocol filter" << oendl;
172 m_protocolAdded = true;
173 QString dummy = str.stripWhiteSpace();
174 int pos = dummy.findRev(':');
175 if ( pos > -1 ) {
176 int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt();
177 Services::ProtocolDescriptor desc( m_protName, m_protId, port );
178 m_item.insertProtocolDescriptor( desc );
179 }
180 return true;
181 }else if (m_protocolOver ) { 179 }else if (m_protocolOver ) {
182 m_protocolOver = false; 180 m_protocolOver = false;
183 } 181 }
184 return false; 182 return false;
185} 183}
186bool Parser::parseProfile( const QString& str) { 184bool Parser::parseProfile( const QString& str) {
187 if (str.startsWith("Profile Descriptor List:") ) { 185 if (str.startsWith("Profile Descriptor List:") ) {
188 m_profOver = true; 186 m_profOver = true;
189 }else if ( m_profOver && str.startsWith(" ") ) { 187 }else if ( m_profOver && str.startsWith(" ") ) {
190 m_profId = convert( str, m_profName ); 188 m_profId = convert( str, m_profName );
191 }else if ( m_profOver && str.startsWith(" ") ) { 189 }else if ( m_profOver && str.startsWith(" ") ) {
192 // now find 190 // now find
193 int pos = str.findRev(':'); 191 int pos = str.findRev(':');
194 if ( pos > 0 ) { 192 if ( pos > 0 ) {
195 int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt(); 193 int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt();
196 owarn << "dummyInt: " << dummy << oendl; 194 owarn << "dummyInt: " << dummy << oendl;
197 Services::ProfileDescriptor desc( m_profName, m_profId, dummy ); 195 Services::ProfileDescriptor desc( m_profName, m_profId, dummy );
198 m_item.insertProfileDescriptor(desc); 196 m_item.insertProfileDescriptor(desc);
199 } 197 }
200 }else 198 }else
201 m_profOver = false; 199 m_profOver = false;
202 200
203 201
204 return false; 202 return false;
205} 203}