summaryrefslogtreecommitdiff
authorzecke <zecke>2002-06-23 19:25:49 (UTC)
committer zecke <zecke>2002-06-23 19:25:49 (UTC)
commit7c4524d0ff6d329c1f5f76fa2e7a727e553d51c8 (patch) (unidiff)
tree08c4b8268c71e568096ad154b0fecb20df76e25b
parent616f8cef3111756cac0240be10aea38d4f38ad8e (diff)
downloadopie-7c4524d0ff6d329c1f5f76fa2e7a727e553d51c8.zip
opie-7c4524d0ff6d329c1f5f76fa2e7a727e553d51c8.tar.gz
opie-7c4524d0ff6d329c1f5f76fa2e7a727e553d51c8.tar.bz2
Fix Service/Profile parser
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/manager.cc13
-rw-r--r--noncore/net/opietooth/lib/parser.cc49
2 files changed, 46 insertions, 16 deletions
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc
index 177c94e..23506b3 100644
--- a/noncore/net/opietooth/lib/manager.cc
+++ b/noncore/net/opietooth/lib/manager.cc
@@ -106,11 +106,13 @@ void Manager::searchServices( const QString& remDevice ){
106 OProcess *m_sdp =new OProcess(); 106 OProcess *m_sdp =new OProcess();
107 *m_sdp << "sdptool" << "browse" << remDevice; 107 *m_sdp << "sdptool" << "browse" << remDevice;
108 m_sdp->setName( remDevice.latin1() ); 108 m_sdp->setName( remDevice.latin1() );
109 qWarning("search Services for %s", remDevice.latin1() );
109 connect(m_sdp, SIGNAL(processExited(OProcess*) ), 110 connect(m_sdp, SIGNAL(processExited(OProcess*) ),
110 this, SLOT(slotSDPExited(OProcess* ) ) ); 111 this, SLOT(slotSDPExited(OProcess* ) ) );
111 connect(m_sdp, SIGNAL(receivedStdout(OProcess*, char*, int ) ), 112 connect(m_sdp, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
112 this, SLOT(slotSDPOut(OProcess*, char*, int) ) ); 113 this, SLOT(slotSDPOut(OProcess*, char*, int) ) );
113 if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 114 if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
115 qWarning("could not start sdptool" );
114 delete m_sdp; 116 delete m_sdp;
115 Services::ValueList list; 117 Services::ValueList list;
116 emit foundServices( remDevice, list ); 118 emit foundServices( remDevice, list );
@@ -137,21 +139,25 @@ void Manager::slotProcessExited(OProcess* proc ) {
137void Manager::slotSDPOut(OProcess* proc, char* ch, int len) 139void Manager::slotSDPOut(OProcess* proc, char* ch, int len)
138{ 140{
139 QCString str(ch, len+1 ); 141 QCString str(ch, len+1 );
142 qWarning("SDP:%s", str.data() );
140 QMap<QString, QString>::Iterator it; 143 QMap<QString, QString>::Iterator it;
141 it = m_out.find(proc->name() ); 144 it = m_out.find(proc->name() );
145 QString string;
142 if ( it != m_out.end() ) { 146 if ( it != m_out.end() ) {
143 QString string = it.data(); 147 string = it.data();
144 string.append( str );
145 m_out.replace( proc->name(), string );
146 } 148 }
149 string.append( str );
150 m_out.replace( proc->name(), string );
147 151
148} 152}
149void Manager::slotSDPExited( OProcess* proc) 153void Manager::slotSDPExited( OProcess* proc)
150{ 154{
155 qWarning("proc name %s", proc->name() );
151 Services::ValueList list; 156 Services::ValueList list;
152 if (proc->normalExit() ) { 157 if (proc->normalExit() ) {
153 QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); 158 QMap<QString, QString>::Iterator it = m_out.find( proc->name() );
154 if ( it != m_out.end() ) { 159 if ( it != m_out.end() ) {
160 qWarning("found process" );
155 list = parseSDPOutput( it.data() ); 161 list = parseSDPOutput( it.data() );
156 m_out.remove( it ); 162 m_out.remove( it );
157 } 163 }
@@ -161,6 +167,7 @@ void Manager::slotSDPExited( OProcess* proc)
161} 167}
162Services::ValueList Manager::parseSDPOutput( const QString& out ) { 168Services::ValueList Manager::parseSDPOutput( const QString& out ) {
163 Services::ValueList list; 169 Services::ValueList list;
170 qWarning("parsing output" );
164 Parser parser( out ); 171 Parser parser( out );
165 list = parser.services(); 172 list = parser.services();
166 return list; 173 return list;
diff --git a/noncore/net/opietooth/lib/parser.cc b/noncore/net/opietooth/lib/parser.cc
index 18d534e..00ec84a 100644
--- a/noncore/net/opietooth/lib/parser.cc
+++ b/noncore/net/opietooth/lib/parser.cc
@@ -13,20 +13,29 @@ namespace {
13 // @eturn 13398 13 // @eturn 13398
14 // tactic find " ( 14 // tactic find " (
15int convert( const QString& line, QString& ret ) { 15int convert( const QString& line, QString& ret ) {
16// qWarning("called");
16 ret = QString::null; 17 ret = QString::null;
17 int i = 0; 18 int i = 0;
18 int pos = line.findRev("\" ("); 19 int pos = line.findRev("\" (");
19 if ( pos > 0 ) { // it shouldn't be at pos 0 20 if ( pos > 0 ) { // it shouldn't be at pos 0
20 ret = line.left(pos-1 ).stripWhiteSpace(); 21 ret = line.left(pos ).stripWhiteSpace();
21 qWarning("ret: %s", ret.latin1() ); 22 // qWarning("ret: %s", ret.latin1() );
22 ret = ret.replace(QRegExp("[\"]"), ""); 23 ret = ret.replace(QRegExp("[\"]"), "");
23 qWarning("ret: %s", ret.latin1() ); 24 //qWarning("ret: %s", ret.latin1() );
24 QString dummy = line.mid(pos + 4 ); 25 QString dummy = line.mid(pos + 5 );
25 qWarning("dummy: %s", dummy.latin1() ); 26 //qWarning("dummy: %s", dummy.latin1() );
26 dummy = dummy.remove( dummy.length() -1, 1 ); // remove the ( 27 dummy = dummy.replace(QRegExp("[)]"), "");
28 //qWarning("dummy: %s", dummy.latin1() );
29// dummy = dummy.remove( dummy.length() -2, 1 ); // remove the )
27 bool ok; 30 bool ok;
28 i = dummy.toInt(&ok, 16 ); 31 i = dummy.toInt(&ok, 16 );
32 //if (ok ) {
33 // qWarning("converted %d", i);
34 //}else qWarning("failed" );
35 //qWarning("exiting");
36 return i;
29 } 37 }
38 //qWarning("output %d", i );
30 return i; 39 return i;
31} 40}
32 41
@@ -45,15 +54,18 @@ Services::ValueList Parser::services() const {
45void Parser::parse( const QString& string) { 54void Parser::parse( const QString& string) {
46 m_list.clear(); 55 m_list.clear();
47 m_complete = true; 56 m_complete = true;
48 QStringList list = QStringList::split('\n', string ); 57 QStringList list = QStringList::split('\n', string,TRUE );
49 QStringList::Iterator it; 58 QStringList::Iterator it;
50 for (it = list.begin(); it != list.end(); ++it ) { 59 for (it = list.begin(); it != list.end(); ++it ) {
60 qWarning("line:%s:line", (*it).latin1() );
51 if ( (*it).startsWith("Browsing") ) continue; 61 if ( (*it).startsWith("Browsing") ) continue;
52 62
53 if ( (*it).isEmpty() ) { // line is empty because a new Service begins 63 if ( (*it).stripWhiteSpace().isEmpty() ) { // line is empty because a new Service begins
54 // now see if complete and add 64 qWarning("could add");
65 // now see if complete and add
55 if (m_complete ) { 66 if (m_complete ) {
56 m_list.append( m_item ); 67 if (!m_item.serviceName().isEmpty() )
68 m_list.append( m_item );
57 Services serv; 69 Services serv;
58 m_item = serv; 70 m_item = serv;
59 m_complete = true; 71 m_complete = true;
@@ -68,7 +80,16 @@ void Parser::parse( const QString& string) {
68 } 80 }
69 // missed the last one 81 // missed the last one
70 if (m_complete) { 82 if (m_complete) {
71 m_list.append(m_item ); 83 qWarning("adding");
84 if (!m_item.serviceName().isEmpty() )
85 m_list.append(m_item );
86 }
87 QValueList<Services>::Iterator it2;
88
89 if (m_list.isEmpty() )
90 qWarning("m_list is empty");
91 for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) {
92 qWarning("name %s", (*it2).serviceName().latin1() );
72 } 93 }
73} 94}
74bool Parser::parseName( const QString& str) { 95bool Parser::parseName( const QString& str) {
@@ -83,13 +104,15 @@ bool Parser::parseRecHandle( const QString& str) {
83 if (str.startsWith("Service RecHandle:" ) ) { 104 if (str.startsWith("Service RecHandle:" ) ) {
84 QString out = str.mid(18 ).stripWhiteSpace(); 105 QString out = str.mid(18 ).stripWhiteSpace();
85 qWarning("out %s", out.latin1() ); 106 qWarning("out %s", out.latin1() );
86 int value = out.toInt(&m_ok, 16 ); 107 int value = out.mid(2).toInt(&m_ok, 16 );
87 if (m_ok && (value != -1) ) 108 if (m_ok && (value != -1) )
88 m_complete = true; 109 m_complete = true;
89 else 110 else
90 m_complete = false; 111 m_complete = false;
91 return true; 112 qWarning("rec handle %d", value);
92 m_item.setRecHandle( value ); 113 m_item.setRecHandle( value );
114 return true;
115
93 } 116 }
94 return false; 117 return false;
95} 118}