penalty.c revision 4633993e0e102636ba923e327138069a04a5304d
/* Copyright (c) 2009-2012 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "hash.h"
#include "str.h"
#include "strescape.h"
#include "llist.h"
#include "ostream.h"
#include "penalty.h"
#include <time.h>
#define PENALTY_CHECKSUM_SAVE_COUNT
#define CHECKSUM_VALUE_COUNT 2
#define CHECKSUM_VALUE_PTR_COUNT 10
#define LAST_UPDATE_BITS 15
struct penalty_rec {
/* ordered by last_update */
char *ident;
unsigned int last_penalty;
unsigned int penalty:16;
unsigned int checksum_is_pointer:1;
/* we use value up to two different checksums.
after that switch to pointer. */
union {
unsigned int value[CHECKSUM_VALUE_COUNT];
unsigned int *value_ptr;
} checksum;
};
struct penalty {
/* ident => penalty_rec */
struct hash_table *hash;
unsigned int expire_secs;
};
struct penalty *penalty_init(void)
{
return penalty;
}
{
if (rec->checksum_is_pointer)
}
{
}
{
}
static bool
{
unsigned int *checksums;
unsigned int i, count;
if (!rec->checksum_is_pointer) {
} else {
}
for (i = 0; i < count; i++) {
if (i > 0) {
sizeof(checksums[0]) * i);
}
return TRUE;
}
}
return FALSE;
}
{
unsigned int *checksums;
if (!rec->checksum_is_pointer) {
(CHECKSUM_VALUE_COUNT-1));
return;
}
/* switch to using a pointer */
sizeof(checksums[0]) * CHECKSUM_VALUE_COUNT);
}
(CHECKSUM_VALUE_PTR_COUNT-1));
}
{
struct penalty_rec *rec;
*last_penalty_r = 0;
return 0;
}
}
{
struct penalty_rec *rec;
unsigned int diff;
if (rec_last_update > expire_time) {
break;
}
}
}
{
struct penalty_rec *rec;
} else {
}
if (checksum == 0) {
} else {
else {
}
}
} else {
}
}
}
unsigned int checksum)
{
struct penalty_rec *rec;
const unsigned int *checksums;
unsigned int i, count;
return FALSE;
if (!rec->checksum_is_pointer) {
} else {
}
for (i = 0; i < count; i++) {
return TRUE;
}
return FALSE;
}
{
const struct penalty_rec *rec;
str_truncate(str, 0);
break;
}
}