connect-limit.c revision 02c335c23bf5fa225a467c19f2c063fb0dc7b8c3
/* Copyright (c) 2009-2016 Dovecot authors, see the included COPYING file */
#include "common.h"
#include "hash.h"
#include "str.h"
#include "strescape.h"
#include "ostream.h"
#include "connect-limit.h"
struct ident_pid {
/* ident string points to ident_hash keys */
const char *ident;
unsigned int refcount;
};
struct connect_limit {
/* ident => unsigned int refcount */
HASH_TABLE(char *, void *) ident_hash;
/* struct ident_pid => struct ident_pid */
};
static unsigned int ident_pid_hash(const struct ident_pid *i)
{
}
{
return -1;
return 1;
else
}
struct connect_limit *connect_limit_init(void)
{
struct connect_limit *limit;
return limit;
}
{
}
const char *ident)
{
void *value;
return POINTER_CAST_TO(value, unsigned int);
}
const char *ident)
{
char *key;
void *value;
} else {
}
lookup_i.ident = ident;
if (i == NULL) {
i->ident = key;
i->refcount = 1;
} else {
i->refcount++;
}
}
static void
{
char *key;
void *value;
unsigned int new_refcount;
i_panic("connect limit hash tables are inconsistent");
if (new_refcount > 0) {
} else {
}
}
const char *ident)
{
lookup_i.ident = ident;
if (i == NULL) {
i_error("connect limit: disconnection for unknown "
return;
}
if (--i->refcount == 0) {
i_free(i);
}
connect_limit_ident_hash_unref(limit, ident);
}
{
struct hash_iterate_context *iter;
/* this should happen rarely (or never), so this slow implementation
should be fine. */
connect_limit_ident_hash_unref(limit, i->ident);
i_free(i);
}
}
}
{
struct hash_iterate_context *iter;
str_truncate(str, 0);
str_append_tabescaped(str, i->ident);
break;
}
}