summaryrefslogtreecommitdiff
path: root/libopie2/opienet/omanufacturerdb.cpp
Unidiff
Diffstat (limited to 'libopie2/opienet/omanufacturerdb.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/omanufacturerdb.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp
new file mode 100644
index 0000000..ea15125
--- a/dev/null
+++ b/libopie2/opienet/omanufacturerdb.cpp
@@ -0,0 +1,96 @@
1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3**
4** This file is part of Opie Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14**********************************************************************/
15
16#include "omanufacturerdb.h"
17
18// Qt
19#include <qstring.h>
20#include <qfile.h>
21#include <qtextstream.h>
22
23OManufacturerDB* OManufacturerDB::_instance = 0;
24
25OManufacturerDB* OManufacturerDB::instance()
26{
27 if ( !OManufacturerDB::_instance )
28 {
29 qDebug( "OManufacturerDB::instance(): creating OManufacturerDB..." );
30 _instance = new OManufacturerDB();
31 }
32 return _instance;
33}
34
35
36OManufacturerDB::OManufacturerDB()
37{
38 QString filename( "/etc/manufacturers" );
39 qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename );
40 if ( !QFile::exists( filename ) )
41 {
42 filename = "/opt/QtPalmtop/etc/manufacturers";
43 qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename );
44 if ( !QFile::exists( filename ) )
45 {
46 filename = "/usr/share/wellenreiter/manufacturers";
47 qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename );
48 }
49 }
50
51 QFile file( filename );
52 bool hasFile = file.open( IO_ReadOnly );
53 if (!hasFile)
54 {
55 qWarning( "OManufacturerDB: no valid manufacturer list found.", (const char*) filename );
56 }
57 else
58 {
59 qDebug( "OManufacturerDB: found manufacturer list in '%s'...", (const char*) filename );
60 QTextStream s( &file );
61 QString addr;
62 QString manu;
63 while (!s.atEnd())
64 {
65 s >> addr;
66 if ( !addr ) // read nothing!?
67 {
68 continue;
69 }
70 else
71 if ( addr[0] == '#' )
72 {
73 s.readLine();
74 continue;
75 }
76 s.skipWhiteSpace();
77 s >> manu;
78 s.readLine();
79 //qDebug( "ManufacturerDB: read pair %s, %s", (const char*) addr, (const char*) manu );
80 manufacturers.insert( addr, manu );
81
82 }
83 }
84
85}
86
87
88OManufacturerDB::~OManufacturerDB()
89{
90}
91
92
93const QString& OManufacturerDB::lookup( const QString& macaddr ) const
94{
95 return manufacturers[macaddr.upper().left(8)];
96}