dovecot-2.0: login proxy: And added new files missing from previ...

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 13 01:25:39 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/e27785694615
changeset: 9776:e27785694615
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 12 18:25:31 2009 -0400
description:
login proxy: And added new files missing from previous commit.

diffstat:

2 files changed, 81 insertions(+)
src/login-common/login-proxy-state.c |   64 ++++++++++++++++++++++++++++++++++
src/login-common/login-proxy-state.h |   17 +++++++++

diffs (89 lines):

diff -r a260d5ac01bf -r e27785694615 src/login-common/login-proxy-state.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/login-common/login-proxy-state.c	Wed Aug 12 18:25:31 2009 -0400
@@ -0,0 +1,64 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "network.h"
+#include "hash.h"
+#include "login-proxy-state.h"
+
+struct login_proxy_state {
+	struct hash_table *hash;
+	pool_t pool;
+};
+
+static unsigned int ip_addr_hash(const void *p)
+{
+	const struct ip_addr *ip = p;
+
+	return net_ip_hash(ip);
+}
+
+static int ip_addr_cmp(const void *p1, const void *p2)
+{
+	const struct ip_addr *ip1 = p1, *ip2 = p2;
+
+	return net_ip_compare(ip1, ip2) ? 0 : 1;
+}
+
+struct login_proxy_state *login_proxy_state_init(void)
+{
+	struct login_proxy_state *state;
+
+	state = i_new(struct login_proxy_state, 1);
+	state->pool = pool_alloconly_create("login proxy state", 1024);
+	state->hash = hash_table_create(default_pool, state->pool, 0,
+					ip_addr_hash, ip_addr_cmp);
+	return state;
+}
+
+void login_proxy_state_deinit(struct login_proxy_state **_state)
+{
+	struct login_proxy_state *state = *_state;
+
+	*_state = NULL;
+	hash_table_destroy(&state->hash);
+	pool_unref(&state->pool);
+	i_free(state);
+}
+
+struct login_proxy_record *
+login_proxy_state_get(struct login_proxy_state *state,
+		      const struct ip_addr *ip)
+{
+	struct login_proxy_record *rec;
+	struct ip_addr *new_ip;
+
+	rec = hash_table_lookup(state->hash, ip);
+	if (rec == NULL) {
+		new_ip = p_new(state->pool, struct ip_addr, 1);
+		*new_ip = *ip;
+
+		rec = p_new(state->pool, struct login_proxy_record, 1);
+		hash_table_insert(state->hash, new_ip, rec);
+	}
+	return rec;
+}
diff -r a260d5ac01bf -r e27785694615 src/login-common/login-proxy-state.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/login-common/login-proxy-state.h	Wed Aug 12 18:25:31 2009 -0400
@@ -0,0 +1,17 @@
+#ifndef LOGIN_PROXY_STATE_H
+#define LOGIN_PROXY_STATE_H
+
+struct login_proxy_record {
+	struct timeval last_failure;
+	struct timeval last_success;
+	unsigned int num_waiting_connections;
+};
+
+struct login_proxy_state *login_proxy_state_init(void);
+void login_proxy_state_deinit(struct login_proxy_state **state);
+
+struct login_proxy_record *
+login_proxy_state_get(struct login_proxy_state *state,
+		      const struct ip_addr *ip);
+
+#endif


More information about the dovecot-cvs mailing list