Header cache multiplexor. More...
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "lib.h"
#include "compress/lib.h"
#include "store/lib.h"
#include "hcache/hcversion.h"
#include "muttlib.h"
#include "serialize.h"
Go to the source code of this file.
Data Structures | |
struct | RealKey |
Hcache key name (including compression method) More... | |
Functions | |
static size_t | header_size (void) |
Compute the size of the header with uuid validity and crc. More... | |
static void * | dump (struct HeaderCache *hc, const struct Email *e, int *off, uint32_t uidvalidity) |
Serialise an Email object. More... | |
static struct Email * | restore (const unsigned char *d) |
Restore an Email from data retrieved from the cache. More... | |
static struct RealKey * | realkey (const char *key, size_t keylen) |
Compute the real key used in the backend, taking into account the compression method. More... | |
static bool | create_hcache_dir (const char *path) |
Create parent dirs for the hcache database. More... | |
static void | hcache_per_folder (struct Buffer *hcpath, const char *path, const char *folder, hcache_namer_t namer) |
Generate the hcache pathname. More... | |
static char * | get_foldername (const char *folder) |
Where should the cache be stored? More... | |
static void * | fetch_raw (struct HeaderCache *hc, const char *key, size_t keylen, size_t *dlen) |
Fetch a message's header from the cache. More... | |
static void | free_raw (struct HeaderCache *hc, void **data) |
Multiplexor for StoreOps::free. More... | |
struct HeaderCache * | mutt_hcache_open (const char *path, const char *folder, hcache_namer_t namer) |
Multiplexor for StoreOps::open. More... | |
void | mutt_hcache_close (struct HeaderCache *hc) |
Multiplexor for StoreOps::close. More... | |
struct HCacheEntry | mutt_hcache_fetch (struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity) |
Multiplexor for StoreOps::fetch. More... | |
bool | mutt_hcache_fetch_obj_ (struct HeaderCache *hc, const char *key, size_t keylen, void *dst, size_t dstlen) |
Fetch a message's header from the cache into a destination object. More... | |
char * | mutt_hcache_fetch_str (struct HeaderCache *hc, const char *key, size_t keylen) |
Fetch a string from the cache. More... | |
int | mutt_hcache_store (struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity) |
Multiplexor for StoreOps::store. More... | |
int | mutt_hcache_store_raw (struct HeaderCache *hc, const char *key, size_t keylen, void *data, size_t dlen) |
Store a key / data pair. More... | |
int | mutt_hcache_delete_record (struct HeaderCache *hc, const char *key, size_t keylen) |
Multiplexor for StoreOps::delete_record. More... | |
Variables | |
static unsigned int | HcacheVer = 0x0 |
Header Cache version. More... | |
Header cache multiplexor.
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/.
Definition in file hcache.c.
|
static |
|
static |
Serialise an Email object.
hc | Header cache handle |
e | Email to serialise |
off | Size of the binary blob |
uidvalidity | IMAP server identifier |
ptr | Binary blob representing the Email |
This function transforms an Email into a binary string so that it can be saved to a database.
Definition at line 86 of file hcache.c.
|
static |
Restore an Email from data retrieved from the cache.
d | Data retrieved using mutt_hcache_dump |
ptr | Success, the restored header (can't be NULL) |
Definition at line 144 of file hcache.c.
|
static |
Compute the real key used in the backend, taking into account the compression method.
key | Original key |
keylen | Length of original key |
ptr | Static location holding data and length of the real key |
Definition at line 193 of file hcache.c.
|
static |
Create parent dirs for the hcache database.
path | Database filename |
true | Success |
false | Failure (errno set) |
Definition at line 219 of file hcache.c.
|
static |
Generate the hcache pathname.
hcpath | Buffer for the result |
path | Base directory, from $header_cache |
folder | Mailbox name (including protocol) |
namer | Callback to generate database filename - Implements hcache_namer_t |
Generate the pathname for the hcache database, it will be of the form: BASE/FOLDER/NAME
This function will create any parent directories needed, so the caller just needs to create the database file.
If path exists and is a directory, it is used. If path has a trailing '/' it is assumed to be a directory. Otherwise path is assumed to be a file.
Definition at line 263 of file hcache.c.
|
static |
Where should the cache be stored?
folder | Path to be canonicalised |
ptr | New string with canonical path |
Definition at line 321 of file hcache.c.
|
static |
Fetch a message's header from the cache.
[in] | hc | Pointer to the struct HeaderCache structure got by mutt_hcache_open() |
[in] | key | Message identification string |
[in] | keylen | Length of the string pointed to by key |
[out] | dlen | Length of the fetched data |
ptr | Success, the data if found |
NULL | Otherwise |
Definition at line 344 of file hcache.c.
|
static |
Multiplexor for StoreOps::free.
Definition at line 365 of file hcache.c.
struct HeaderCache * mutt_hcache_open | ( | const char * | path, |
const char * | folder, | ||
hcache_namer_t | namer | ||
) |
Multiplexor for StoreOps::open.
Open the connection to the header cache.
< MD5 digest as a string
< MD5 digest as an integer
Definition at line 379 of file hcache.c.
void mutt_hcache_close | ( | struct HeaderCache * | hc | ) |
Multiplexor for StoreOps::close.
Close the connection to the header cache.
Definition at line 489 of file hcache.c.
struct HCacheEntry mutt_hcache_fetch | ( | struct HeaderCache * | hc, |
const char * | key, | ||
size_t | keylen, | ||
uint32_t | uidvalidity | ||
) |
Multiplexor for StoreOps::fetch.
Fetch and validate a message's header from the cache.
Definition at line 513 of file hcache.c.
bool mutt_hcache_fetch_obj_ | ( | struct HeaderCache * | hc, |
const char * | key, | ||
size_t | keylen, | ||
void * | dst, | ||
size_t | dstlen | ||
) |
Fetch a message's header from the cache into a destination object.
[in] | hc | Pointer to the struct HeaderCache structure got by mutt_hcache_open() |
[in] | key | Message identification string |
[in] | keylen | Length of the string pointed to by key |
[out] | dst | Pointer to the destination object |
[in] | dstlen | Size of the destination object |
true | Success, the data was found and the length matches |
false | Otherwise |
Definition at line 574 of file hcache.c.
char * mutt_hcache_fetch_str | ( | struct HeaderCache * | hc, |
const char * | key, | ||
size_t | keylen | ||
) |
Fetch a string from the cache.
[in] | hc | Pointer to the struct HeaderCache structure got by mutt_hcache_open() |
[in] | key | Message identification string |
[in] | keylen | Length of the string pointed to by key |
ptr | Success, the data if found |
NULL | Otherwise |
Definition at line 600 of file hcache.c.
int mutt_hcache_store | ( | struct HeaderCache * | hc, |
const char * | key, | ||
size_t | keylen, | ||
struct Email * | e, | ||
uint32_t | uidvalidity | ||
) |
Multiplexor for StoreOps::store.
Store a Header along with a validity datum.
Definition at line 616 of file hcache.c.
int mutt_hcache_store_raw | ( | struct HeaderCache * | hc, |
const char * | key, | ||
size_t | keylen, | ||
void * | data, | ||
size_t | dlen | ||
) |
Store a key / data pair.
hc | Pointer to the struct HeaderCache structure got by mutt_hcache_open() |
key | Message identification string |
keylen | Length of the string pointed to by key |
data | Payload to associate with key |
dlen | Length of the buffer pointed to by the data parameter |
0 | Success |
num | Generic or backend-specific error code otherwise |
Definition at line 674 of file hcache.c.
int mutt_hcache_delete_record | ( | struct HeaderCache * | hc, |
const char * | key, | ||
size_t | keylen | ||
) |
Multiplexor for StoreOps::delete_record.
Delete a key / data pair.
Definition at line 695 of file hcache.c.