struct director_request *request;
unsigned int username_hash;
- if (!user_directory_get_username_hash(dir->users, username,
- &username_hash)) {
+ if (!director_get_username_hash(dir, username,
+ &username_hash)) {
callback(NULL, NULL, "Failed to expand director_username_hash", context);
return;
}
#include "istream.h"
#include "ostream.h"
#include "iostream-temp.h"
+#include "mail-user-hash.h"
#include "user-directory.h"
#include "mail-host.h"
#include "director-host.h"
i_array_init(&dir->pending_requests, 16);
i_array_init(&dir->connections, 8);
dir->users = user_directory_init(set->director_user_expire,
- set->director_username_hash,
director_user_freed);
dir->mail_hosts = mail_hosts_init(set->director_consistent_hashing);
i_free(iter);
}
+bool
+director_get_username_hash(struct director *dir, const char *username,
+ unsigned int *hash_r)
+{
+ const char *error;
+
+ if (mail_user_hash(username, dir->set->director_username_hash, hash_r,
+ &error))
+ return TRUE;
+ i_error("Failed to expand director_user_expire=%s: %s",
+ dir->set->director_username_hash, error);
+ return FALSE;
+}
+
void directors_init(void)
{
user_move_throttle =
int director_connect_host(struct director *dir, struct director_host *host);
+bool
+director_get_username_hash(struct director *dir, const char *username,
+ unsigned int *hash_r);
+
void directors_init(void);
void directors_deinit(void);
tag = args[1] != NULL ? args[1] : "";
}
if (str_to_uint(username, &username_hash) < 0) {
- if (!user_directory_get_username_hash(users,
- username, &username_hash)) {
+ if (!director_get_username_hash(conn->dir,
+ username, &username_hash)) {
o_stream_nsend_str(conn->output, "TRYAGAIN\n");
return 1;
}
}
if (str_to_uint(args[0], &username_hash) < 0) {
- if (!user_directory_get_username_hash(users,
- args[0], &username_hash)) {
+ if (!director_get_username_hash(conn->dir,
+ args[0], &username_hash)) {
o_stream_nsend_str(conn->output, "TRYAGAIN\n");
return 1;
}
unsigned int hash;
while ((line = i_stream_read_next_line(conn->input)) != NULL) {
- if (!user_directory_get_username_hash(conn->dir->users, line, &hash))
+ if (!director_get_username_hash(conn->dir, line, &hash))
continue;
notify_update_user(conn->dir, line, hash);
}
unsigned int i;
test_begin("user directory ascending");
- dir = user_directory_init(USER_DIR_TIMEOUT, "%u", NULL);
+ dir = user_directory_init(USER_DIR_TIMEOUT, NULL);
(void)user_directory_add(dir, 1, host, ioloop_time + count+1);
for (i = 0; i < count; i++)
unsigned int i;
test_begin("user directory descending");
- dir = user_directory_init(USER_DIR_TIMEOUT, "%u", NULL);
+ dir = user_directory_init(USER_DIR_TIMEOUT, NULL);
for (i = 0; i < count; i++)
(void)user_directory_add(dir, i+1, host, ioloop_time - i);
unsigned int i, count = 10000 + rand()%10000;
test_begin("user directory random");
- dir = user_directory_init(USER_DIR_TIMEOUT, "%u", NULL);
+ dir = user_directory_init(USER_DIR_TIMEOUT, NULL);
for (i = 0; i < count; i++) {
if (rand() % 10 == 0)
timestamp = ioloop_time;
#include "array.h"
#include "hash.h"
#include "llist.h"
-#include "mail-user-hash.h"
#include "mail-host.h"
#include "user-directory.h"
ARRAY(struct user_directory_iter *) iters;
void (*user_free_hook)(struct user *);
- char *username_hash_fmt;
unsigned int timeout_secs;
/* If user's expire time is less than this many seconds away,
don't assume that other directors haven't yet expired it */
array_free(&users);
}
-bool user_directory_get_username_hash(struct user_directory *dir,
- const char *username,
- unsigned int *hash_r)
-{
- const char *error;
-
- if (mail_user_hash(username, dir->username_hash_fmt, hash_r, &error))
- return TRUE;
- i_error("Failed to expand director_user_expire=%s: %s",
- dir->username_hash_fmt, error);
- return FALSE;
-}
-
bool user_directory_user_is_recently_updated(struct user_directory *dir,
struct user *user)
{
}
struct user_directory *
-user_directory_init(unsigned int timeout_secs, const char *username_hash_fmt,
+user_directory_init(unsigned int timeout_secs,
void (*user_free_hook)(struct user *))
{
struct user_directory *dir;
I_MAX(dir->user_near_expiring_secs, USER_NEAR_EXPIRING_MIN);
i_assert(dir->timeout_secs/2 > dir->user_near_expiring_secs);
- dir->username_hash_fmt = i_strdup(username_hash_fmt);
dir->user_free_hook = user_free_hook;
hash_table_create_direct(&dir->hash, default_pool, 0);
i_array_init(&dir->iters, 8);
user_free(dir, dir->head);
hash_table_destroy(&dir->hash);
array_free(&dir->iters);
- i_free(dir->username_hash_fmt);
i_free(dir);
}
/* Create a new directory. Users are dropped if their time gets older
than timeout_secs. */
struct user_directory *
-user_directory_init(unsigned int timeout_secs, const char *username_hash_fmt,
+user_directory_init(unsigned int timeout_secs,
void (*user_free_hook)(struct user *));
void user_directory_deinit(struct user_directory **dir);
timestamps based on remote director's user list after handshake. */
void user_directory_sort(struct user_directory *dir);
-bool user_directory_get_username_hash(struct user_directory *dir,
- const char *username,
- unsigned int *hash_r);
-
bool user_directory_user_is_recently_updated(struct user_directory *dir,
struct user *user);
bool user_directory_user_is_near_expiring(struct user_directory *dir,