Header cache multiplexor. More...
#include "config.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 struct RealKey * | realkey (struct HeaderCache *hc, const char *key, size_t keylen, bool compress) |
Compute the real key used in the backend, taking into account the compression method. | |
static void | hcache_free (struct HeaderCache **ptr) |
Free a header cache. | |
static struct HeaderCache * | hcache_new (void) |
Create a new header cache. | |
static size_t | header_size (void) |
Compute the size of the header with uuid validity and crc. | |
static uint32_t | email_pack_flags (const struct Email *e) |
Pack the Email flags into a uint32_t. | |
static void | email_unpack_flags (struct Email *e, uint32_t packed) |
Unpack the Email flags from a uint32_t. | |
static uint32_t | email_pack_timezone (const struct Email *e) |
Pack the Email timezone into a uint32_t. | |
static void | email_unpack_timezone (struct Email *e, uint32_t packed) |
Unpack the Email timezone from a uint32_t. | |
static void * | dump_email (struct HeaderCache *hc, const struct Email *e, int *off, uint32_t uidvalidity) |
Serialise an Email object. | |
static struct Email * | restore_email (const unsigned char *d) |
Restore an Email from data retrieved from the cache. | |
static bool | create_hcache_dir (const char *path) |
Create parent dirs for the hcache database. | |
static void | hcache_per_folder (struct HeaderCache *hc, struct Buffer *hcpath, const char *path, hcache_namer_t namer) |
Generate the hcache pathname. | |
static char * | get_foldername (const char *folder) |
Where should the cache be stored? | |
static void | free_raw (struct HeaderCache *hc, void **data) |
Multiplexor for StoreOps::free. | |
static unsigned int | generate_hcachever (void) |
Calculate hcache version from dynamic configuration. | |
struct HeaderCache * | hcache_open (const char *path, const char *folder, hcache_namer_t namer, bool create) |
Multiplexor for StoreOps::open. | |
void | hcache_close (struct HeaderCache **ptr) |
Multiplexor for StoreOps::close. | |
struct HCacheEntry | hcache_fetch_email (struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity) |
Multiplexor for StoreOps::fetch. | |
bool | hcache_fetch_raw_obj_full (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. | |
char * | hcache_fetch_raw_str (struct HeaderCache *hc, const char *key, size_t keylen) |
Fetch a string from the cache. | |
int | hcache_store_email (struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity) |
Multiplexor for StoreOps::store. | |
int | hcache_store_raw (struct HeaderCache *hc, const char *key, size_t keylen, void *data, size_t dlen) |
Store a key / data pair. | |
int | hcache_delete_email (struct HeaderCache *hc, const char *key, size_t keylen) |
Multiplexor for StoreOps::delete_record. | |
int | hcache_delete_raw (struct HeaderCache *hc, const char *key, size_t keylen) |
Multiplexor for StoreOps::delete_record. | |
Variables | |
static unsigned int | HcacheVer = 0x0 |
Header Cache version. | |
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 |
Compute the real key used in the backend, taking into account the compression method.
hc | Header cache handle |
key | Original key |
keylen | Length of original key |
compress | Will the data be compressed? |
ptr | Static location holding data and length of the real key |
Definition at line 80 of file hcache.c.
|
static |
|
static |
Create a new header cache.
ptr | Newly created header cache |
Definition at line 118 of file hcache.c.
|
static |
|
inlinestatic |
Pack the Email flags into a uint32_t.
e | Email to pack |
num | uint32_t of packed flags |
Definition at line 139 of file hcache.c.
|
inlinestatic |
Unpack the Email flags from a uint32_t.
e | Email to unpack into |
packed | Packed flags |
Definition at line 164 of file hcache.c.
|
inlinestatic |
Pack the Email timezone into a uint32_t.
e | Email to pack |
num | uint32_t of packed timezone |
Definition at line 189 of file hcache.c.
|
inlinestatic |
Unpack the Email timezone from a uint32_t.
e | Email to unpack into |
packed | Packed timezone |
Definition at line 204 of file hcache.c.
|
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 227 of file hcache.c.
|
static |
Restore an Email from data retrieved from the cache.
d | Data retrieved using hcache_fetch_email() |
ptr | Success, the restored header (can't be NULL) |
Definition at line 267 of file hcache.c.
|
static |
Create parent dirs for the hcache database.
path | Database filename |
true | Success |
false | Failure (errno set) |
Definition at line 312 of file hcache.c.
|
static |
Generate the hcache pathname.
hc | Header cache handle |
hcpath | Buffer for the result |
path | Base directory, from $header_cache |
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 356 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 409 of file hcache.c.
|
static |
Multiplexor for StoreOps::free.
Definition at line 423 of file hcache.c.
|
static |
Calculate hcache version from dynamic configuration.
num | Header cache version |
< MD5 digest as a string
< MD5 digest as an integer
Definition at line 432 of file hcache.c.
struct HeaderCache * hcache_open | ( | const char * | path, |
const char * | folder, | ||
hcache_namer_t | namer, | ||
bool | create | ||
) |
Multiplexor for StoreOps::open.
Open the connection to the header cache.
Definition at line 471 of file hcache.c.
void hcache_close | ( | struct HeaderCache ** | ptr | ) |
Multiplexor for StoreOps::close.
Close the connection to the header cache.
Definition at line 542 of file hcache.c.
struct HCacheEntry hcache_fetch_email | ( | 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 562 of file hcache.c.
bool hcache_fetch_raw_obj_full | ( | 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 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 623 of file hcache.c.
char * hcache_fetch_raw_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 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 652 of file hcache.c.
int hcache_store_email | ( | 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 670 of file hcache.c.
int 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 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 724 of file hcache.c.
int hcache_delete_email | ( | struct HeaderCache * | hc, |
const char * | key, | ||
size_t | keylen | ||
) |
Multiplexor for StoreOps::delete_record.
Delete a key / data pair.
Definition at line 739 of file hcache.c.
int hcache_delete_raw | ( | struct HeaderCache * | hc, |
const char * | key, | ||
size_t | keylen | ||
) |
Multiplexor for StoreOps::delete_record.
Delete a key / data pair.
Definition at line 752 of file hcache.c.