summaryrefslogtreecommitdiff
authorzecke <zecke>2002-06-23 19:25:49 (UTC)
committer zecke <zecke>2002-06-23 19:25:49 (UTC)
commit7c4524d0ff6d329c1f5f76fa2e7a727e553d51c8 (patch) (side-by-side diff)
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
@@ -1,219 +1,226 @@
#include <opie/oprocess.h>
#include "parser.h"
#include "manager.h"
using namespace OpieTooth;
Manager::Manager( const QString& dev )
: QObject()
{
qWarning("created");
m_device = dev;
m_hcitool = 0;
m_sdp = 0;
}
Manager::Manager( Device* /*dev*/ )
: QObject()
{
m_hcitool = 0;
m_sdp = 0;
}
Manager::Manager()
: QObject()
{
m_hcitool = 0;
m_sdp = 0;
}
Manager::~Manager(){
delete m_hcitool;
delete m_sdp;
}
void Manager::setDevice( const QString& dev ){
m_device = dev;
}
void Manager::setDevice( Device* /*dev*/ ){
}
void Manager::isAvailable( const QString& device ){
OProcess* l2ping = new OProcess();
l2ping->setName( device.latin1() );
*l2ping << "l2ping" << "-c1" << device;
connect(l2ping, SIGNAL(processExited(OProcess* ) ),
this, SLOT(slotProcessExited(OProcess*) ) );
if (!l2ping->start() ) {
emit available( device, false );
delete l2ping;
}
}
void Manager::isAvailable( Device* /*dev*/ ){
}
void Manager::searchDevices( const QString& device ){
qWarning("search devices");
OProcess* hcitool = new OProcess();
hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() );
*hcitool << "hcitool" << "scan";
connect( hcitool, SIGNAL(processExited(OProcess*) ) ,
this, SLOT(slotHCIExited(OProcess* ) ) );
connect( hcitool, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
this, SLOT(slotHCIOut(OProcess*, char*, int ) ) );
if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
qWarning("could not start");
RemoteDevice::ValueList list;
emit foundDevices( device, list );
delete hcitool;
}
}
void Manager::searchDevices(Device* /*d*/ ){
}
void Manager::addService(const QString& name ){
OProcess proc;
proc << "sdptool" << "add" << name;
bool bo = true;
if (!proc.start(OProcess::DontCare ) )
bo = false;
emit addedService( name, bo );
}
void Manager::addServices(const QStringList& list){
QStringList::ConstIterator it;
for (it = list.begin(); it != list.end(); ++it )
addService( (*it) );
}
void Manager::removeService( const QString& name ){
OProcess prc;
prc << "sdptool" << "del" << name;
bool bo = true;
if (!prc.start(OProcess::DontCare ) )
bo = false;
emit removedService( name, bo );
}
void Manager::removeServices( const QStringList& list){
QStringList::ConstIterator it;
for (it = list.begin(); it != list.end(); ++it )
removeService( (*it) );
}
void Manager::searchServices( const QString& remDevice ){
OProcess *m_sdp =new OProcess();
*m_sdp << "sdptool" << "browse" << remDevice;
m_sdp->setName( remDevice.latin1() );
+ qWarning("search Services for %s", remDevice.latin1() );
connect(m_sdp, SIGNAL(processExited(OProcess*) ),
this, SLOT(slotSDPExited(OProcess* ) ) );
connect(m_sdp, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
this, SLOT(slotSDPOut(OProcess*, char*, int) ) );
if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
+ qWarning("could not start sdptool" );
delete m_sdp;
Services::ValueList list;
emit foundServices( remDevice, list );
}
}
void Manager::searchServices( const RemoteDevice& dev){
searchServices( dev.mac() );
}
QString Manager::toDevice( const QString& /*mac*/ ){
return QString::null;
}
QString Manager::toMac( const QString &/*device*/ ){
return QString::null;
}
void Manager::slotProcessExited(OProcess* proc ) {
bool conn= false;
if (proc->normalExit() && proc->exitStatus() == 0 )
conn = true;
QString name = QString::fromLatin1(proc->name() );
emit available( name, conn );
delete proc;
}
void Manager::slotSDPOut(OProcess* proc, char* ch, int len)
{
QCString str(ch, len+1 );
+ qWarning("SDP:%s", str.data() );
QMap<QString, QString>::Iterator it;
it = m_out.find(proc->name() );
+ QString string;
if ( it != m_out.end() ) {
- QString string = it.data();
- string.append( str );
- m_out.replace( proc->name(), string );
+ string = it.data();
}
+ string.append( str );
+ m_out.replace( proc->name(), string );
}
void Manager::slotSDPExited( OProcess* proc)
{
+ qWarning("proc name %s", proc->name() );
Services::ValueList list;
if (proc->normalExit() ) {
QMap<QString, QString>::Iterator it = m_out.find( proc->name() );
if ( it != m_out.end() ) {
+ qWarning("found process" );
list = parseSDPOutput( it.data() );
m_out.remove( it );
}
}
emit foundServices( proc->name(), list );
delete proc;
}
Services::ValueList Manager::parseSDPOutput( const QString& out ) {
Services::ValueList list;
+ qWarning("parsing output" );
Parser parser( out );
list = parser.services();
return list;
}
void Manager::slotHCIExited(OProcess* proc ) {
qWarning("process exited");
RemoteDevice::ValueList list;
if (proc->normalExit() ) {
qWarning("normalExit %s", proc->name() );
QMap<QString, QString>::Iterator it = m_devices.find(proc->name() );
if (it != m_devices.end() ) {
qWarning("!= end ;)");
list = parseHCIOutput( it.data() );
m_devices.remove( it );
}
}
emit foundDevices( proc->name(), list );
delete proc;
}
void Manager::slotHCIOut(OProcess* proc, char* ch, int len) {
QCString str( ch, len+1 );
qWarning("hci: %s", str.data() );
QMap<QString, QString>::Iterator it;
it = m_devices.find( proc->name() );
qWarning("proc->name %s", proc->name() );
QString string;
if (it != m_devices.end() ) {
qWarning("slotHCIOut ");
string = it.data();
}
string.append( str );
m_devices.replace( proc->name(), string );
}
RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) {
qWarning("parseHCI %s", output.latin1() );
RemoteDevice::ValueList list;
QStringList strList = QStringList::split('\n', output );
QStringList::Iterator it;
QString str;
for ( it = strList.begin(); it != strList.end(); ++it ) {
str = (*it).stripWhiteSpace();
qWarning("OpieTooth %s", str.latin1() );
int pos = str.findRev(':' );
if ( pos > 0 ) {
QString mac = str.left(17 );
str.remove( 0, 17 );
qWarning("mac %s", mac.latin1() );
qWarning("rest:%s", str.latin1() );
RemoteDevice rem( mac , str.stripWhiteSpace() );
list.append( rem );
}
}
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
@@ -1,173 +1,196 @@
#include <qstringlist.h>
#include "parser.h"
using namespace OpieTooth;
namespace {
// "Test Foo Bar" (0x3456)
// @param ret Test Foo Bar
// @eturn 13398
// tactic find " (
int convert( const QString& line, QString& ret ) {
+// qWarning("called");
ret = QString::null;
int i = 0;
int pos = line.findRev("\" (");
if ( pos > 0 ) { // it shouldn't be at pos 0
- ret = line.left(pos-1 ).stripWhiteSpace();
- qWarning("ret: %s", ret.latin1() );
+ ret = line.left(pos ).stripWhiteSpace();
+ // qWarning("ret: %s", ret.latin1() );
ret = ret.replace(QRegExp("[\"]"), "");
- qWarning("ret: %s", ret.latin1() );
- QString dummy = line.mid(pos + 4 );
- qWarning("dummy: %s", dummy.latin1() );
- dummy = dummy.remove( dummy.length() -1, 1 ); // remove the (
+ //qWarning("ret: %s", ret.latin1() );
+ QString dummy = line.mid(pos + 5 );
+ //qWarning("dummy: %s", dummy.latin1() );
+ dummy = dummy.replace(QRegExp("[)]"), "");
+ //qWarning("dummy: %s", dummy.latin1() );
+// dummy = dummy.remove( dummy.length() -2, 1 ); // remove the )
bool ok;
i = dummy.toInt(&ok, 16 );
+ //if (ok ) {
+ // qWarning("converted %d", i);
+ //}else qWarning("failed" );
+ //qWarning("exiting");
+ return i;
}
+ //qWarning("output %d", i );
return i;
}
};
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 list = QStringList::split('\n', string,TRUE );
QStringList::Iterator it;
for (it = list.begin(); it != list.end(); ++it ) {
+ qWarning("line:%s:line", (*it).latin1() );
if ( (*it).startsWith("Browsing") ) continue;
- if ( (*it).isEmpty() ) { // line is empty because a new Service begins
- // now see if complete and add
+ if ( (*it).stripWhiteSpace().isEmpty() ) { // line is empty because a new Service begins
+ qWarning("could add");
+ // now see if complete and add
if (m_complete ) {
- m_list.append( m_item );
+ if (!m_item.serviceName().isEmpty() )
+ m_list.append( m_item );
Services serv;
m_item = serv;
m_complete = true;
continue;
}
}
if (parseName( (*it) ) ) ;//continue;
if (parseRecHandle( (*it) ) ) ;//continue;
if (parseClassId( (*it) ) ) ;//continue;
if (parseProtocol( (*it) ) ) ;//continue;
if (parseProfile( (*it) ) ) ;//continue;
}
// missed the last one
if (m_complete) {
- m_list.append(m_item );
+ qWarning("adding");
+ if (!m_item.serviceName().isEmpty() )
+ m_list.append(m_item );
+ }
+ QValueList<Services>::Iterator it2;
+
+ if (m_list.isEmpty() )
+ qWarning("m_list is empty");
+ for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) {
+ qWarning("name %s", (*it2).serviceName().latin1() );
}
}
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 );
+ int value = out.mid(2).toInt(&m_ok, 16 );
if (m_ok && (value != -1) )
m_complete = true;
else
m_complete = false;
- return true;
+ qWarning("rec handle %d", value);
m_item.setRecHandle( value );
+ return true;
+
}
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;
// "Obex Object Push" (0x1105)
// find backwards the " and the from 0 to pos and the mid pos+1
// then stripWhiteSpace add name replace '"' with ""
// and then convert 0x1105 toInt()
QString classes;
int ids;
ids = convert( str, classes );
qWarning("ids %d", ids );
m_item.setClassIdList( classes );
m_item.setClassIdList( ids );
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(" ") ) { // "L2CAP" (0x0100)
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;
{ // the find function
m_protId = convert(str, m_protName );
}
return true;
}else if (m_protocolOver && str.startsWith(" ") ) {
qWarning("tripple protocol filter");
m_protocolAdded = true;
QString dummy = str.stripWhiteSpace();
int pos = dummy.findRev(':');
if ( pos > -1 ) {
int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt();
Services::ProtocolDescriptor desc( m_protName, m_protId, port );
m_item.insertProtocolDescriptor( desc );
}
return true;
}else if (m_protocolOver ) {
m_protocolOver = false;
}
return false;
}
bool Parser::parseProfile( const QString& str) {
if (str.startsWith("Profile Descriptor List:") ) {
m_profOver = true;
}else if ( m_profOver && str.startsWith(" ") ) {
m_profId = convert( str, m_profName );
}else if ( m_profOver && str.startsWith(" ") ) {
// now find
int pos = str.findRev(':');
if ( pos > 0 ) {
int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt();
qWarning("dummyInt:%d", dummy );
Services::ProfileDescriptor desc( m_profName, m_profId, dummy );
m_item.insertProfileDescriptor(desc);
}
}else
m_profOver = false;
return false;
}