1 /* $Id: dbdb.h,v 1.7 2002/10/14 22:17:19 tommy Exp $ */
2 
3 /*
4  * Copyright (c) 2002 Tom Marshall <tommy@tig-grr.com>
5  *
6  * This program is free software.  It may be distributed under the terms
7  * in the file LICENSE, found in the top level of the distribution.
8  */
9 
10 #ifndef _DBDB_H
11 #define _DBDB_H
12 
13 #ifdef HAVE_LIBDB
14 
15 #include <db.h>
16 
17 typedef struct _dbtdb dbtdb_t;
18 struct _dbtdb
19 {
20     bool_t      (*close)(dbtdb_t*);
21     bool_t      (*mergeclose)(dbtdb_t*,vec_t*);
22     bool_t      (*unmergeclose)(dbtdb_t*,vec_t*);
23     bool_t      (*import)(dbtdb_t*,cpchar);
24     bool_t      (*export)(dbtdb_t*,cpchar);
25     uint        (*getmsgcount)(dbtdb_t*);
26     uint        (*getcount)(dbtdb_t*,str_t*);
27 
28     DB*             dbp;        /* db handle */
29 #if defined(DB_VERSION_MAJOR) && DB_VERSION_MAJOR >= 3
30     DB_ENV*         envp;       /* we don't own this */
31 #endif /* DB_VERSION_MAJOR */
32     uint            nmsgs;      /* number of messages in table (cached) */
33 };
34 
35 typedef struct _dbhdb dbhdb_t;
36 struct _dbhdb
37 {
38     bool_t      (*close)(dbhdb_t*);
39     dbt_t*      (*opentable)(dbhdb_t*,cpchar,bool_t);
40 
41     char*       dir;        /* directory for db files */
42 #if defined(DB_VERSION_MAJOR) && DB_VERSION_MAJOR >= 3
43     DB_ENV*     envp;       /* db environment */
44 #endif /* DB_VERSION_MAJOR */
45 };
46 
47 dbh_t*  dbdb_db_open( cpchar dbhost, cpchar dbname, cpchar dbuser, cpchar dbpass );
48 bool_t  dbdb_db_close( dbhdb_t* pthis );
49 dbt_t*  dbdb_db_opentable( dbhdb_t* pthis, cpchar table, bool_t rdonly );
50 
51 bool_t  dbdb_table_close( dbtdb_t* pthis );
52 bool_t  dbdb_table_mergeclose( dbtdb_t* pthis, vec_t* pmsg );
53 bool_t  dbdb_table_unmergeclose( dbtdb_t* pthis, vec_t* pmsg );
54 bool_t  dbdb_table_import( dbtdb_t* pthis, cpchar filename );
55 bool_t  dbdb_table_export( dbtdb_t* pthis, cpchar filename );
56 uint    dbdb_table_getmsgcount( dbtdb_t* pthis );
57 uint    dbdb_table_getcount( dbtdb_t* pthis, str_t* pword );
58 
59 #endif /* def HAVE_LIBDB */
60 
61 #endif /* ndef _DBDB_H */
62