Diffstat (limited to 'libetpan/src/data-types/mail_cache_db.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libetpan/src/data-types/mail_cache_db.h | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/libetpan/src/data-types/mail_cache_db.h b/libetpan/src/data-types/mail_cache_db.h new file mode 100644 index 0000000..9ce915c --- a/dev/null +++ b/libetpan/src/data-types/mail_cache_db.h | |||
@@ -0,0 +1,148 @@ | |||
1 | /* | ||
2 | * libEtPan! -- a mail stuff library | ||
3 | * | ||
4 | * Copyright (C) 2001, 2005 - DINH Viet Hoa | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. Neither the name of the libEtPan! project nor the names of its | ||
16 | * contributors may be used to endorse or promote products derived | ||
17 | * from this software without specific prior written permission. | ||
18 | * | ||
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND | ||
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE | ||
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
29 | * SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | * $Id$ | ||
34 | */ | ||
35 | |||
36 | #ifndef MAIL_CACHE_DB_H | ||
37 | |||
38 | #define MAIL_CACHE_DB_H | ||
39 | |||
40 | #include <sys/types.h> | ||
41 | #include "mail_cache_db_types.h" | ||
42 | #include "chash.h" | ||
43 | |||
44 | #ifdef __cplusplus | ||
45 | extern "C" { | ||
46 | #endif | ||
47 | |||
48 | /* | ||
49 | this module will handle a database "f(key) -> value" in a file | ||
50 | |||
51 | berkeley DB or other can be used for implementation of low-level file. | ||
52 | */ | ||
53 | |||
54 | /* | ||
55 | mail_cache_db_open() | ||
56 | |||
57 | This function opens the file "filename". | ||
58 | The pointer return in pcache_db should be used for further references | ||
59 | to the database. | ||
60 | */ | ||
61 | |||
62 | int mail_cache_db_open(const char * filename, | ||
63 | struct mail_cache_db ** pcache_db); | ||
64 | |||
65 | /* | ||
66 | mail_cache_db_close() | ||
67 | |||
68 | This function closes the opened database. | ||
69 | The pointer cannot be used later. | ||
70 | */ | ||
71 | |||
72 | void mail_cache_db_close(struct mail_cache_db * cache_db); | ||
73 | |||
74 | /* | ||
75 | mail_cache_db_open_lock() | ||
76 | |||
77 | This function opens and locks the file "filename". | ||
78 | The pointer return in pcache_db should be used for further references | ||
79 | to the database. | ||
80 | */ | ||
81 | |||
82 | int mail_cache_db_open_lock(const char * filename, | ||
83 | struct mail_cache_db ** pcache_db); | ||
84 | |||
85 | /* | ||
86 | mail_cache_db_open_unlock() | ||
87 | |||
88 | This function closes and unlocks the opened database. | ||
89 | The pointer cannot be used later. | ||
90 | */ | ||
91 | |||
92 | void mail_cache_db_close_unlock(const char * filename, | ||
93 | struct mail_cache_db * cache_db); | ||
94 | |||
95 | /* | ||
96 | mail_cache_db_put() | ||
97 | |||
98 | This function will store a given key and value in the database. | ||
99 | */ | ||
100 | |||
101 | int mail_cache_db_put(struct mail_cache_db * cache_db, | ||
102 | const void * key, size_t key_len, const void * value, size_t value_len); | ||
103 | |||
104 | /* | ||
105 | mail_cache_db_get() | ||
106 | |||
107 | This function will retrieve the value corresponding to a given key | ||
108 | from the database. | ||
109 | */ | ||
110 | |||
111 | int mail_cache_db_get(struct mail_cache_db * cache_db, | ||
112 | const void * key, size_t key_len, void ** pvalue, size_t * pvalue_len); | ||
113 | |||
114 | /* | ||
115 | mail_cache_db_get_size() | ||
116 | |||
117 | This function will retrieve the size of the value corresponding | ||
118 | to a given key from the database. | ||
119 | */ | ||
120 | |||
121 | int mail_cache_db_get_size(struct mail_cache_db * cache_db, | ||
122 | const void * key, size_t key_len, size_t * pvalue_len); | ||
123 | |||
124 | /* | ||
125 | mail_cache_db_del() | ||
126 | |||
127 | This function will delete the given key and the corresponding value | ||
128 | from the database. | ||
129 | */ | ||
130 | |||
131 | int mail_cache_db_del(struct mail_cache_db * cache_db, | ||
132 | const void * key, size_t key_len); | ||
133 | |||
134 | /* | ||
135 | mail_cache_clean_up() | ||
136 | |||
137 | This function will delete the key all the key/value pairs of the | ||
138 | database file which key does not exist in the given hash. | ||
139 | */ | ||
140 | |||
141 | int mail_cache_db_clean_up(struct mail_cache_db * cache_db, | ||
142 | chash * exist); | ||
143 | |||
144 | #ifdef __cplusplus | ||
145 | } | ||
146 | #endif | ||
147 | |||
148 | #endif | ||