/*
* Copyright (C) 2004 Thomas Glanzmann <sithglan@stud.uni-erlangen.de>
* Copyright (C) 2004 Tobias Werth <sitowert@stud.uni-erlangen.de>
* Copyright (C) 2004 Brian Fundakowski Feldman <green@FreeBSD.org>
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#if HAVE_QDBM
#include <depot.h>
#include <cabin.h>
#include <villa.h>
#elif HAVE_TC
#include <tcbdb.h>
#elif HAVE_GDBM
#include <gdbm.h>
#elif HAVE_DB4
#include <db.h>
#endif
#include <errno.h>
#include <fcntl.h>
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include "mutt.h"
#include "hcache.h"
#include "hcversion.h"
#include "mx.h"
#include "lib.h"
#include "md5.h"
#include "rfc822.h"
unsigned int hcachever = 0x0;
#if HAVE_QDBM
struct header_cache
{
VILLA *db;
char *folder;
unsigned int crc;
};
#elif HAVE_TC
struct header_cache
{
TCBDB *db;
char *folder;
unsigned int crc;
};
#elif HAVE_GDBM
struct header_cache
{
GDBM_FILE db;
char *folder;
unsigned int crc;
};
#elif HAVE_DB4
struct header_cache
{
DB_ENV *env;
DB *db;
char *folder;
unsigned int crc;
int fd;
char lockfile[_POSIX_PATH_MAX];
};
static void mutt_hcache_dbt_init(DBT * dbt, void *data, size_t len);
static void mutt_hcache_dbt_empty_init(DBT * dbt);
#endif
typedef union
{
struct timeval timeval;
unsigned int uidvalidity;
} validate;
static void *
lazy_malloc(size_t siz)
{
if (0 < siz && siz < 4096)
siz = 4096;
return safe_malloc(siz);
}
static void
lazy_realloc(void *ptr, size_t siz)
{
void **p = (void **) ptr;
if (p != NULL && 0 < siz && siz < 4096)
return;
safe_realloc(ptr, siz);
}
static unsigned char *
dump_int(unsigned int i, unsigned char *d, int *off)
{
lazy_realloc(&d, *off + sizeof (int));
memcpy(d + *off, &i, sizeof (int));
(*off) += sizeof (int);
return d;
}
static void
restore_int(unsigned int *i, cons