WordDBInfo.cc

Go to the documentation of this file.
00001 // WordDBInfo.cc
00002 //
00003 //
00004 // Part of the ht://Dig package   <http://www.htdig.org/>
00005 // Copyright (c) 1999, 2000, 2001 The ht://Dig Group
00006 // For copyright details, see the file COPYING in your distribution
00007 // or the GNU General Public License version 2 or later
00008 // <http://www.gnu.org/copyleft/gpl.html>
00009 //
00010 //
00011 #ifdef HAVE_CONFIG_H
00012 #include "config.h"
00013 #endif /* HAVE_CONFIG_H */
00014 
00015 #include <stdlib.h>
00016 #include <stdio.h>
00017 
00018 #include "db.h"
00019 #include "WordDBInfo.h"
00020 
00021 //
00022 // WordDBInfo implementation
00023 //
00024 
00025 //
00026 // Like standard function but allows easy breakpoint setting.
00027 //
00028 static void message(const char *errpfx, char *msg)
00029 {
00030   fprintf(stderr, "%s: %s\n", errpfx, msg);
00031 }
00032 
00033 WordDBInfo::WordDBInfo(const Configuration& config)
00034 {
00035   dbenv = 0;
00036 
00037   if(config.Boolean("wordlist_env_skip")) return;
00038 
00039   int error;
00040   if((error = CDB_db_env_create(&dbenv, 0)) != 0) {
00041     fprintf(stderr, "WordDBInfo: CDB_db_env_create %s\n", CDB_db_strerror(error));
00042     return;
00043   }
00044   dbenv->set_errpfx(dbenv, "WordDB");
00045   dbenv->set_errcall(dbenv, message);
00046   if(dbenv->set_verbose(dbenv, DB_VERB_CHKPOINT, 1) != 0)
00047     return;
00048   if(dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, 1) != 0)
00049     return;
00050   if(dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, 1) != 0)
00051     return;
00052   if(dbenv->set_verbose(dbenv, DB_VERB_WAITSFOR, 1) != 0)
00053     return;
00054   int cache_size = config.Value("wordlist_cache_size", 10*1024*1024);
00055   if(cache_size > 0) {
00056     if(dbenv->set_cachesize(dbenv, 0, cache_size, 1) != 0)
00057       return;
00058   }
00059 
00060   char* dir = 0;
00061   int flags = DB_CREATE;
00062   if(config.Boolean("wordlist_env_share")) {
00063     const String& env_dir = config["wordlist_env_dir"];
00064     if(env_dir.empty()) {
00065       fprintf(stderr, "WordDB: wordlist_env_dir not specified\n");
00066       return;
00067     }
00068     dir = strdup((const char*)env_dir);
00069 
00070     if(config.Boolean("wordlist_env_cdb"))
00071       flags |= DB_INIT_CDB;
00072     else
00073       flags |= DB_INIT_LOCK | DB_INIT_MPOOL;
00074 
00075   } else {
00076     flags |= DB_PRIVATE | DB_INIT_LOCK | DB_INIT_MPOOL;
00077   }
00078 
00079   if((error = dbenv->open(dbenv, (const char*)dir, flags, 0666)) != 0)
00080     dbenv->err(dbenv, error, "open %s", (dir ? dir : ""));
00081   if(dir) free(dir);
00082 }
00083 
00084 WordDBInfo::~WordDBInfo()
00085 {
00086   if(dbenv) dbenv->close(dbenv, 0);
00087 }

Generated on Sun Jun 8 10:56:40 2008 for GNUmifluz by  doxygen 1.5.5