SEEN-Database: refactor database interface for remembering whether we already aggrega...
[citadel.git] / citadel / database.h
1 /*
2  * Copyright (c) 1987-2012 by the citadel.org team
3  *
4  *  This program is open source software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License version 3.
6  *
7  *  This program is distributed in the hope that it will be useful,
8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *  GNU General Public License for more details.
11  */
12
13 #ifndef DATABASE_H
14 #define DATABASE_H
15
16
17 void open_databases (void);
18 void close_databases (void);
19 int cdb_store (int cdb, const void *key, int keylen, void *data, int datalen);
20 int cdb_delete (int cdb, void *key, int keylen);
21 struct cdbdata *cdb_fetch (int cdb, const void *key, int keylen);
22 void cdb_free (struct cdbdata *cdb);
23 void cdb_rewind (int cdb);
24 struct cdbdata *cdb_next_item (int cdb);
25 void cdb_close_cursor(int cdb);
26 void cdb_begin_transaction(void);
27 void cdb_end_transaction(void);
28 void cdb_allocate_tsd(void);
29 void cdb_free_tsd(void);
30 void cdb_check_handles(void);
31 void cdb_trunc(int cdb);
32 void *checkpoint_thread(void *arg);
33 void cdb_chmod_data(void);
34 void cdb_checkpoint(void);
35 void check_handles(void *arg);
36
37 /*
38  * Database records beginning with this magic number are assumed to
39  * be compressed.  In the event that a database record actually begins with
40  * this magic number, we *must* compress it whether we want to or not,
41  * because the fetch function will try to uncompress it anyway.
42  * 
43  * (No need to #ifdef this stuff; it compiles ok even if zlib is not present
44  * and doesn't declare anything so it won't bloat the code)
45  */
46 #define COMPRESS_MAGIC  0xc0ffeeee
47
48 struct CtdlCompressHeader {
49         int magic;
50         size_t uncompressed_len;
51         size_t compressed_len;
52 };
53
54 typedef enum __eCheckType {
55         eCheckExist,
56         eCheckUpdate,
57         eUpdate,
58         eWrite
59 }eCheckType;
60
61 time_t CheckIfAlreadySeen(const char *Facility,
62                           StrBuf *guid,
63                           time_t now,
64                           time_t antiexpire,
65                           eCheckType cType,
66                           long ccid,
67                           long ioid);
68
69
70 #endif /* DATABASE_H */
71