-rw-r--r-- | libopie2/opienet/omanufacturerdb.cpp | 25 | ||||
-rwxr-xr-x | libopie2/tools/stripmanuf.py | 27 |
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 | |||
@@ -1,131 +1,112 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "omanufacturerdb.h" | 31 | #include "omanufacturerdb.h" |
32 | 32 | ||
33 | /* OPIE CORE */ | 33 | /* OPIE CORE */ |
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | 35 | ||
36 | /* QT */ | 36 | /* QT */ |
37 | #include <qstring.h> | 37 | #include <qstring.h> |
38 | #include <qfile.h> | 38 | #include <qfile.h> |
39 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
40 | 40 | ||
41 | OManufacturerDB* OManufacturerDB::_instance = 0; | 41 | OManufacturerDB* OManufacturerDB::_instance = 0; |
42 | 42 | ||
43 | OManufacturerDB* OManufacturerDB::instance() | 43 | OManufacturerDB* OManufacturerDB::instance() |
44 | { | 44 | { |
45 | if ( !OManufacturerDB::_instance ) | 45 | if ( !OManufacturerDB::_instance ) |
46 | { | 46 | { |
47 | odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; | 47 | odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; |
48 | _instance = new OManufacturerDB(); | 48 | _instance = new OManufacturerDB(); |
49 | } | 49 | } |
50 | return _instance; | 50 | return _instance; |
51 | } | 51 | } |
52 | 52 | ||
53 | 53 | ||
54 | OManufacturerDB::OManufacturerDB() | 54 | OManufacturerDB::OManufacturerDB() |
55 | { | 55 | { |
56 | QString filename( "/etc/manufacturers" ); | 56 | QString filename( "/etc/manufacturers" ); |
57 | odebug << "OManufacturerDB: trying to read " << filename << oendl; | 57 | odebug << "OManufacturerDB: trying to read " << filename << oendl; |
58 | if ( !QFile::exists( filename ) ) | 58 | if ( !QFile::exists( filename ) ) |
59 | { | 59 | { |
60 | filename = "/opt/QtPalmtop/etc/manufacturers"; | 60 | filename = "/opt/QtPalmtop/etc/manufacturers"; |
61 | odebug << "OManufacturerDB: trying to read " << filename << oendl; | 61 | odebug << "OManufacturerDB: trying to read " << filename << oendl; |
62 | if ( !QFile::exists( filename ) ) | 62 | if ( !QFile::exists( filename ) ) |
63 | { | 63 | { |
64 | filename = "/usr/share/wellenreiter/manufacturers"; | 64 | filename = "/usr/share/wellenreiter/manufacturers"; |
65 | odebug << "OManufacturerDB: trying to read " << filename << oendl; | 65 | odebug << "OManufacturerDB: trying to read " << filename << oendl; |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | QFile file( filename ); | 69 | QFile file( filename ); |
70 | bool hasFile = file.open( IO_ReadOnly ); | 70 | bool hasFile = file.open( IO_ReadOnly ); |
71 | if (!hasFile) | 71 | if (!hasFile) |
72 | { | 72 | { |
73 | owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; | 73 | owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; |
74 | } | 74 | } |
75 | else | 75 | else |
76 | { | 76 | { |
77 | odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; | 77 | odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; |
78 | QTextStream s( &file ); | 78 | QTextStream s( &file ); |
79 | QString addr; | 79 | QString addr; |
80 | QString manu; | 80 | QString manu; |
81 | QString extManu; | 81 | QString extManu; |
82 | while (!s.atEnd()) | 82 | while (!s.atEnd()) |
83 | { | 83 | { |
84 | s >> addr; | 84 | s >> addr; |
85 | if ( !addr ) // read nothing!? | ||
86 | { | ||
87 | continue; | ||
88 | } | ||
89 | else | ||
90 | if ( addr[0] == '#' ) | ||
91 | { | ||
92 | continue; | ||
93 | } | ||
94 | s.skipWhiteSpace(); | ||
95 | s >> manu; | 85 | s >> manu; |
96 | s.skipWhiteSpace(); | ||
97 | s >> extManu; | 86 | s >> extManu; |
98 | if ( extManu[0] == '#' ) // we have an extended manufacturer | 87 | |
99 | { | ||
100 | s.skipWhiteSpace(); | ||
101 | extManu = s.readLine(); | ||
102 | odebug << "OManufacturerDB: read " << extManu << " as extended manufacturer string" << oendl; | ||
103 | manufacturersExt.insert( addr, extManu ); | ||
104 | } | ||
105 | else | ||
106 | s.readLine(); | ||
107 | odebug << "OManufacturerDB: read tuple " << addr << ", " << manu << oendl; | ||
108 | manufacturers.insert( addr, manu ); | 88 | manufacturers.insert( addr, manu ); |
89 | manufacturersExt.insert( addr, extManu ); | ||
90 | odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; | ||
109 | } | 91 | } |
110 | } | 92 | } |
111 | |||
112 | } | 93 | } |
113 | 94 | ||
114 | 95 | ||
115 | OManufacturerDB::~OManufacturerDB() | 96 | OManufacturerDB::~OManufacturerDB() |
116 | { | 97 | { |
117 | } | 98 | } |
118 | 99 | ||
119 | 100 | ||
120 | const QString& OManufacturerDB::lookup( const QString& macaddr ) const | 101 | const QString& OManufacturerDB::lookup( const QString& macaddr ) const |
121 | { | 102 | { |
122 | return manufacturers[macaddr.upper().left(8)]; | 103 | return manufacturers[macaddr.upper().left(8)]; |
123 | } | 104 | } |
124 | 105 | ||
125 | 106 | ||
126 | const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const | 107 | const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const |
127 | { | 108 | { |
128 | QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); | 109 | QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); |
129 | return it == manufacturersExt.end() ? lookup( macaddr ) : *it; | 110 | return it == manufacturersExt.end() ? lookup( macaddr ) : *it; |
130 | } | 111 | } |
131 | 112 | ||
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 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | # | ||
4 | # converts a manufacturer file in ethereal format (taken from their CVS) | ||
5 | # into something smaller and faster parseable | ||
6 | # | ||
7 | |||
8 | import sys | ||
9 | import os | ||
10 | |||
11 | i = file( sys.argv[1], "r" ) | ||
12 | o = file( sys.argv[2], "w" ) | ||
13 | |||
14 | for line in i: | ||
15 | #print line.strip() | ||
16 | entries = line.strip().split() | ||
17 | #print "number of entries =", len( entries ) | ||
18 | #print entries | ||
19 | if len( entries ) < 2: | ||
20 | continue | ||
21 | elif len( entries ) == 2: | ||
22 | print "2-line detected." | ||
23 | print >>o, entries[0], entries[1], entries[1] | ||
24 | elif len( entries ) > 2: | ||
25 | print >>o, entries[0], entries[1], "_".join( entries[3:] ) | ||
26 | else: | ||
27 | assert( false ) \ No newline at end of file | ||