|
1 // Copyright (C) 2000 Bruce Guenter <bruceg@em.ca> |
|
2 // |
|
3 // This program is free software; you can redistribute it and/or modify |
|
4 // it under the terms of the GNU General Public License as published by |
|
5 // the Free Software Foundation; either version 2 of the License, or |
|
6 // (at your option) any later version. |
|
7 // |
|
8 // This program is distributed in the hope that it will be useful, |
|
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 // GNU General Public License for more details. |
|
12 // |
|
13 // You should have received a copy of the GNU General Public License |
|
14 // along with this program; if not, write to the Free Software |
|
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 #include <config.h> |
|
18 #include "vpwtable.h" |
|
19 #include <stdlib.h> |
|
20 #include "misc/autodelete.h" |
|
21 #include "cdb++/cdb++.h" |
|
22 |
|
23 class cdb_vpwtable_reader : public vpwtable_reader |
|
24 { |
|
25 private: |
|
26 cdb_reader cdb; |
|
27 public: |
|
28 cdb_vpwtable_reader(const mystring& filename); |
|
29 ~cdb_vpwtable_reader(); |
|
30 bool operator!() const; |
|
31 bool get(vpwentry& out); |
|
32 bool rewind(); |
|
33 bool end(); |
|
34 }; |
|
35 |
|
36 vpwtable_reader* vpwtable::start_read() const |
|
37 { |
|
38 return new cdb_vpwtable_reader(filename); |
|
39 } |
|
40 |
|
41 cdb_vpwtable_reader::cdb_vpwtable_reader(const mystring& filename) |
|
42 : cdb(filename) |
|
43 { |
|
44 } |
|
45 |
|
46 cdb_vpwtable_reader::~cdb_vpwtable_reader() |
|
47 { |
|
48 end(); |
|
49 } |
|
50 |
|
51 bool cdb_vpwtable_reader::operator !() const |
|
52 { |
|
53 return !cdb; |
|
54 } |
|
55 |
|
56 bool cdb_vpwtable_reader::end() |
|
57 { |
|
58 return true; |
|
59 } |
|
60 |
|
61 bool cdb_vpwtable_reader::rewind() |
|
62 { |
|
63 return !!cdb && cdb.firstrec(); |
|
64 } |
|
65 |
|
66 bool cdb_vpwtable_reader::get(vpwentry& out) |
|
67 { |
|
68 autodelete<datum> rec = cdb.nextrec(); |
|
69 if(!rec) |
|
70 return false; |
|
71 if(!out.from_record(rec->key, rec->data)) |
|
72 return false; |
|
73 return true; |
|
74 } |