[2368] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * argdb.cpp --
|
---|
| 4 | * Copyright (C) 2001 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 6 | * A component of the Greenstone digital library software
|
---|
| 7 | * from the New Zealand Digital Library Project at the
|
---|
| 8 | * University of Waikato, New Zealand.
|
---|
| 9 | *
|
---|
| 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *
|
---|
| 24 | *********************************************************************/
|
---|
| 25 |
|
---|
[7424] | 26 | #include "gsdl_modules_cfg.h"
|
---|
| 27 | #ifdef GSDL_USE_COLLECTOR_ACTION
|
---|
| 28 |
|
---|
[22067] | 29 | #include "fileutil.h"
|
---|
| 30 |
|
---|
[15683] | 31 | // argdb is used by the collector for storing cgi arguments on disk (in a database)
|
---|
[2368] | 32 |
|
---|
| 33 | #include "argdb.h"
|
---|
[22067] | 34 |
|
---|
| 35 | #if defined(USE_GDBM)
|
---|
[15432] | 36 | #include "gdbmclass.h"
|
---|
[22067] | 37 | #define DBCLASS gdbmclass
|
---|
| 38 | #define DBFNAME "argdb.gdb"
|
---|
[2368] | 39 |
|
---|
[22067] | 40 | #elif defined(USE_JDBM)
|
---|
| 41 | #include "jdbmnaiveclass.h"
|
---|
| 42 | #define DBCLASS jdbmnaiveclass
|
---|
| 43 | #define DBFNAME "argdb.jdb"
|
---|
| 44 |
|
---|
| 45 | #elif defined(USE_SQLITE)
|
---|
| 46 | #include "sqlitedbclass.h"
|
---|
| 47 | #define DBCLASS sqlitedbclass
|
---|
| 48 | #define DBFNAME "argdb.litedb"
|
---|
| 49 |
|
---|
| 50 | #elif defined(USE_MSSQL)
|
---|
| 51 | #include "mssqldbclass.h"
|
---|
| 52 | #define DBCLASS mssqldbclass
|
---|
| 53 | #define DBFNAME "argdb.msdb"
|
---|
| 54 |
|
---|
| 55 | #else
|
---|
| 56 | #error "Unable to compile Greenstone. Need at least one database backend enabled."
|
---|
| 57 | #endif
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | argdb::argdb (const text_t& gsdlhome, const text_t &args_tmp) {
|
---|
| 61 |
|
---|
| 62 | gsdlhome_ = gsdlhome;
|
---|
| 63 | dbfile_ = filename_cat(gsdlhome, "tmp", args_tmp, DBFNAME);
|
---|
| 64 |
|
---|
[2368] | 65 | }
|
---|
| 66 |
|
---|
| 67 | bool argdb::update_args (text_tmap &argmap) {
|
---|
[22067] | 68 |
|
---|
| 69 | DBCLASS argdb(gsdlhome_);
|
---|
| 70 | if (!argdb.opendatabase(dbfile_, DB_WRITER_CREATE, 1000, true)) return false;
|
---|
[2368] | 71 | infodbclass info;
|
---|
| 72 |
|
---|
| 73 | argdb.getinfo("savedargs", info);
|
---|
| 74 |
|
---|
| 75 | text_tmap::iterator here = argmap.begin();
|
---|
| 76 | text_tmap::iterator end = argmap.end();
|
---|
| 77 | while (here != end) {
|
---|
| 78 | if (!(*here).second.empty()) {
|
---|
| 79 | info.setinfo((*here).first, (*here).second);
|
---|
| 80 | }
|
---|
[9620] | 81 | ++here;
|
---|
[2368] | 82 | }
|
---|
| 83 |
|
---|
| 84 | bool rv = argdb.setinfo ("savedargs", info);
|
---|
| 85 | argdb.closedatabase();
|
---|
| 86 | return rv;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | bool argdb::get_args (text_tmap &argmap) {
|
---|
| 90 | argmap.erase(argmap.begin(), argmap.end());
|
---|
[22067] | 91 | DBCLASS argdb(gsdlhome_);
|
---|
| 92 | if (!argdb.opendatabase(dbfile_, DB_READER, 1000, true)) return false;
|
---|
[2368] | 93 | infodbclass info;
|
---|
| 94 |
|
---|
| 95 | if (!argdb.getinfo("savedargs", info)) return false;
|
---|
| 96 |
|
---|
| 97 | infodbclass::const_iterator here = info.begin();
|
---|
| 98 | infodbclass::const_iterator end = info.end();
|
---|
| 99 | while (here != end) {
|
---|
| 100 | argmap[(*here).first] = info[(*here).first];
|
---|
[9620] | 101 | ++here;
|
---|
[2368] | 102 | }
|
---|
| 103 | argdb.closedatabase();
|
---|
| 104 | return true;
|
---|
| 105 | }
|
---|
[7424] | 106 |
|
---|
| 107 | #endif //GSDL_USE_COLLECTOR_ACTION
|
---|