duplicate.c revision c224fff79d18480a65e9b4504b891b8ea176f5b1
/* Copyright (c) 2005-2016 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "home-expand.h"
#include "file-dotlock.h"
#include "hash.h"
#include "mail-user.h"
#include "mail-storage-settings.h"
#include "duplicate.h"
#include <fcntl.h>
#include <unistd.h>
#define DUPLICATE_FNAME ".dovecot.lda-dupes"
#define COMPRESS_PERCENTAGE 10
#define DUPLICATE_BUFSIZE 4096
#define DUPLICATE_VERSION 2
struct duplicate {
const void *id;
unsigned int id_size;
const char *user;
};
struct duplicate_file_header {
};
struct duplicate_record_header {
};
struct duplicate_file {
const char *path;
int new_fd;
unsigned int changed:1;
};
struct duplicate_context {
char *path;
struct dotlock_settings dotlock_set;
struct duplicate_file *file;
};
static const struct dotlock_settings default_duplicate_dotlock_set = {
.timeout = 20,
.stale_timeout = 10,
};
{
}
static unsigned int duplicate_hash(const struct duplicate *d)
{
/* a char* hash function from ASU -- from glib */
unsigned int g, h = 0;
while (s != end) {
h = (h << 4) + *s;
if ((g = h & 0xf0000000UL)) {
h = h ^ (g >> 24);
h = h ^ g;
}
s++;
}
return h ^ strcase_hash(d->user);
}
static int
unsigned int record_size)
{
const unsigned char *data;
struct duplicate_record_header hdr;
unsigned int change_count;
change_count = 0;
if (record_size == sizeof(hdr))
else {
/* FIXME: backwards compatibility with v1.0 */
}
return -1;
}
return -1;
}
/* still valid, save it */
struct duplicate *d;
void *new_id;
} else {
change_count++;
}
}
return 0;
}
{
struct duplicate_file_header hdr;
const unsigned char *data;
int fd;
unsigned int record_size = 0;
if (fd == -1) {
return 0;
return -1;
}
/* <timestamp> <id_size> <user_size> <id> <user> */
/* FIXME: backwards compatibility with v1.0 */
record_size = sizeof(struct duplicate_record_header);
}
}
if (record_size == 0 ||
return 0;
}
{
struct duplicate_file *file;
;
else {
i_error("Creating lock file for %s timed out in %u secs",
}
(void)duplicate_read(file);
return file;
}
{
}
{
struct duplicate d;
/* duplicate database disabled */
return FALSE;
}
}
}
{
struct duplicate *d;
void *new_id;
/* duplicate database disabled */
return;
}
}
}
{
struct duplicate_file_header hdr;
struct duplicate_record_header rec;
struct hash_iterate_context *iter;
struct duplicate *d;
return;
/* unlock the duplicate database */
return;
}
}
if (o_stream_nfinish(output) < 0) {
return;
}
}
{
struct duplicate_context *ctx;
const struct mail_storage_settings *mail_set;
i_error("User %s doesn't have home dir set, "
}
return ctx;
}
{
}
}