forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcache.h
149 lines (132 loc) · 5.61 KB
/
hcache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Copyright (C) 2004 Thomas Glanzmann <[email protected]>
* Copyright (C) 2004 Tobias Werth <[email protected]>
* Copyright (C) 2004 Brian Fundakowski Feldman <[email protected]>
* Copyright (C) 2016 Pietro Cerutti <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MUTT_HCACHE_H
#define _MUTT_HCACHE_H 1
#include "mutt.h"
struct header_cache;
typedef struct header_cache header_cache_t;
typedef int (*hcache_namer_t)(const char *path, char *dest, size_t dlen);
/**
* mutt_hcache_open - open the connection to the header cache.
*
* @param path Location of the header cache (often as specified by the user).
* @param folder Name of the folder containing the messages.
* @param namer Optional (might be NULL) client-specific function to form the
* final name of the hcache database file.
* @return Pointer to a header_cache_t struct on success, NULL otherwise.
*/
header_cache_t *mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer);
/**
* mutt_hcache_close - close the connection to the header cache.
*
* @param h Pointer to the header_cache_t structure got by mutt_hcache_open.
*/
void mutt_hcache_close(header_cache_t *h);
/**
* mutt_hcache_fetch - fetch and validate a message's header from the cache.
*
* @param h Pointer to the header_cache_t structure got by mutt_hcache_open.
* @param key Message identification string.
* @param keylen Length of the string pointed to by key.
* @return Pointer to the data if found and valid, NULL otherwise.
* @note This function performs a check on the validity of the data found by
* comparing it with the crc value of the header_cache_t structure.
* @note The returned pointer must be freed by calling mutt_hcache_free. This
* must be done before closing the header cache with mutt_hcache_close.
*/
void *mutt_hcache_fetch(header_cache_t *h, const char *key, size_t keylen);
/**
* mutt_hcache_fetch_raw - fetch a message's header from the cache.
*
* @param h Pointer to the header_cache_t structure got by mutt_hcache_open.
* @param key Message identification string.
* @param keylen Length of the string pointed to by key.
* @return Pointer to the data if found, NULL otherwise.
* @note This function does not perform any check on the validity of the data
* found.
* @note The returned pointer must be freed by calling mutt_hcache_free. This
* must be done before closing the header cache with mutt_hcache_close.
*/
void *mutt_hcache_fetch_raw(header_cache_t *h, const char *key, size_t keylen);
/**
* mutt_hcache_free - free previously fetched data.
*
* @param h Pointer to the header_cache_t structure got by mutt_hcache_open.
* @param data Pointer to the data got using hcache_fetch or hcache_fetch_raw.
*/
void mutt_hcache_free(header_cache_t *h, void **data);
/**
* mutt_hcache_restore - restore a HEADER from data retrieved from the cache.
*
* @param d Data retrieved using mutt_hcache_fetch or mutt_hcache_fetch_raw.
* @return Pointer to the restored header (cannot be NULL).
* @note The returned HEADER must be free'd by caller code with
* mutt_free_header.
*/
HEADER *mutt_hcache_restore(const unsigned char *d);
/**
* mutt_hcache_store - store a HEADER along with a validity datum.
*
* @param h Pointer to the header_cache_t structure got by mutt_hcache_open.
* @param key Message identification string.
* @param keylen Length of the string pointed to by key.
* @param header Message header to store.
* @param uidvalidity IMAP-specific UIDVALIDITY value, or 0 to use the current
* time.
* @return 0 on success, -1 otherwise.
*/
int mutt_hcache_store(header_cache_t *h, const char *key, size_t keylen,
HEADER *header, unsigned int uidvalidity);
/**
* mutt_hcache_store_raw - store a key / data pair.
*
* @param h Pointer to the header_cache_t structure got by mutt_hcache_open.
* @param key Message identification string.
* @param keylen Length of the string pointed to by key.
* @param data Payload to associate with key.
* @param dlen Length of the buffer pointed to by the @data parameter.
* @return 0 on success, -1 otherwise.
*/
int mutt_hcache_store_raw(header_cache_t *h, const char *key, size_t keylen,
void *data, size_t dlen);
/**
* mutt_hcache_delete - delete a key / data pair.
*
* @param h Pointer to the header_cache_t structure got by mutt_hcache_open.
* @param key Message identification string.
* @param keylen Length of the string pointed to by key.
* @return 0 on success, -1 otherwise.
*/
int mutt_hcache_delete(header_cache_t *h, const char *key, size_t keylen);
/**
* mutt_hcache_backend_list - get a list of backend identification strings.
*
* @return Comma separated string describing the compiled-in backends.
* @note The returned string must be free'd by the caller.
*/
const char *mutt_hcache_backend_list(void);
/**
* mutt_hcache_is_valid_backend
*
* @param s String identifying a backend.
* @return 1 if s is recognized as a valid backend, 0 otherwise.
*/
int mutt_hcache_is_valid_backend(const char *s);
#endif /* _MUTT_HCACHE_H */