summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2003-12-08 18:12:34 (UTC)
committer mickeyl <mickeyl>2003-12-08 18:12:34 (UTC)
commitbbc55b1790e93973c0fdf7ad5f758f6ff4da2269 (patch) (side-by-side diff)
tree1ed235702c8c5b62ca31e11795e3a83194f97987 /libopie2
parentac49d8a09fe739ed451c632e154a409f142cefcd (diff)
downloadopie-bbc55b1790e93973c0fdf7ad5f758f6ff4da2269.zip
opie-bbc55b1790e93973c0fdf7ad5f758f6ff4da2269.tar.gz
opie-bbc55b1790e93973c0fdf7ad5f758f6ff4da2269.tar.bz2
use a slightly smaller manufacturerdb format, that saves ~100KB and
improves parsing speed. Even better would be .gz compressed QDataStream though...
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/omanufacturerdb.cpp25
-rwxr-xr-xlibopie2/tools/stripmanuf.py27
2 files changed, 30 insertions, 22 deletions
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp
index bcce11f..006ae72 100644
--- a/libopie2/opienet/omanufacturerdb.cpp
+++ b/libopie2/opienet/omanufacturerdb.cpp
@@ -37,95 +37,76 @@
#include <qstring.h>
#include <qfile.h>
#include <qtextstream.h>
OManufacturerDB* OManufacturerDB::_instance = 0;
OManufacturerDB* OManufacturerDB::instance()
{
if ( !OManufacturerDB::_instance )
{
odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl;
_instance = new OManufacturerDB();
}
return _instance;
}
OManufacturerDB::OManufacturerDB()
{
QString filename( "/etc/manufacturers" );
odebug << "OManufacturerDB: trying to read " << filename << oendl;
if ( !QFile::exists( filename ) )
{
filename = "/opt/QtPalmtop/etc/manufacturers";
odebug << "OManufacturerDB: trying to read " << filename << oendl;
if ( !QFile::exists( filename ) )
{
filename = "/usr/share/wellenreiter/manufacturers";
odebug << "OManufacturerDB: trying to read " << filename << oendl;
}
}
QFile file( filename );
bool hasFile = file.open( IO_ReadOnly );
if (!hasFile)
{
owarn << "OManufacturerDB: no valid manufacturer list found." << oendl;
}
else
{
odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl;
QTextStream s( &file );
QString addr;
QString manu;
QString extManu;
while (!s.atEnd())
{
s >> addr;
- if ( !addr ) // read nothing!?
- {
- continue;
- }
- else
- if ( addr[0] == '#' )
- {
- continue;
- }
- s.skipWhiteSpace();
s >> manu;
- s.skipWhiteSpace();
s >> extManu;
- if ( extManu[0] == '#' ) // we have an extended manufacturer
- {
- s.skipWhiteSpace();
- extManu = s.readLine();
- odebug << "OManufacturerDB: read " << extManu << " as extended manufacturer string" << oendl;
- manufacturersExt.insert( addr, extManu );
- }
- else
- s.readLine();
- odebug << "OManufacturerDB: read tuple " << addr << ", " << manu << oendl;
+
manufacturers.insert( addr, manu );
+ manufacturersExt.insert( addr, extManu );
+ odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl;
}
}
-
}
OManufacturerDB::~OManufacturerDB()
{
}
const QString& OManufacturerDB::lookup( const QString& macaddr ) const
{
return manufacturers[macaddr.upper().left(8)];
}
const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const
{
QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) );
return it == manufacturersExt.end() ? lookup( macaddr ) : *it;
}
diff --git a/libopie2/tools/stripmanuf.py b/libopie2/tools/stripmanuf.py
new file mode 100755
index 0000000..28de0f9
--- a/dev/null
+++ b/libopie2/tools/stripmanuf.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+#
+# converts a manufacturer file in ethereal format (taken from their CVS)
+# into something smaller and faster parseable
+#
+
+import sys
+import os
+
+i = file( sys.argv[1], "r" )
+o = file( sys.argv[2], "w" )
+
+for line in i:
+ #print line.strip()
+ entries = line.strip().split()
+ #print "number of entries =", len( entries )
+ #print entries
+ if len( entries ) < 2:
+ continue
+ elif len( entries ) == 2:
+ print "2-line detected."
+ print >>o, entries[0], entries[1], entries[1]
+ elif len( entries ) > 2:
+ print >>o, entries[0], entries[1], "_".join( entries[3:] )
+ else:
+ assert( false ) \ No newline at end of file