e7acb31fbd9b44398a930a4c4a12fa069c1780f0
[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 void cdb_cull_logs(void);
37
38
39 /*
40  * Database records beginning with this magic number are assumed to
41  * be compressed.  In the event that a database record actually begins with
42  * this magic number, we *must* compress it whether we want to or not,
43  * because the fetch function will try to uncompress it anyway.
44  * 
45  * (No need to #ifdef this stuff; it compiles ok even if zlib is not present
46  * and doesn't declare anything so it won't bloat the code)
47  */
48 #define COMPRESS_MAGIC  0xc0ffeeee
49
50 struct CtdlCompressHeader {
51         int magic;
52         size_t uncompressed_len;
53         size_t compressed_len;
54 };
55
56 typedef enum __eCheckType {
57         eCheckExist,   /* look up the item, return the timestamp if its there, 0 if not. */
58         eCheckUpdate,  /* if it exists, refresh in db timestamp. return the timstamp if its there, 0 if not. */
59         eUpdate,       /* insert/update the new value, return the old if its there, 0 if not. */
60         eWrite         /* write this to DB, unconditional. */
61 }eCheckType;
62
63 time_t CheckIfAlreadySeen(const char *Facility,
64                           StrBuf *guid,
65                           time_t now,
66                           time_t antiexpire,
67                           eCheckType cType,
68                           long ccid,
69                           long ioid);
70
71
72 #endif /* DATABASE_H */
73