Based on patch by Apple.
--HG--
branch : HEAD
auth_cache_node_unlink(cache, node);
cache->size_left += node->alloc_size;
- hash_remove(cache->hash, node->data);
+ hash_table_remove(cache->hash, node->data);
i_free(node);
}
struct auth_cache *cache;
cache = i_new(struct auth_cache, 1);
- cache->hash = hash_create(default_pool, default_pool, 0, str_hash,
- (hash_cmp_callback_t *)strcmp);
+ cache->hash = hash_table_create(default_pool, default_pool, 0, str_hash,
+ (hash_cmp_callback_t *)strcmp);
cache->size_left = max_size;
cache->ttl_secs = ttl_secs;
cache->neg_ttl_secs = neg_ttl_secs;
lib_signals_unset_handler(SIGUSR2, sig_auth_cache_stats, cache);
auth_cache_clear(cache);
- hash_destroy(&cache->hash);
+ hash_table_destroy(&cache->hash);
i_free(cache);
}
{
while (cache->tail != NULL)
auth_cache_node_destroy(cache, cache->tail);
- hash_clear(cache->hash, FALSE);
+ hash_table_clear(cache->hash, FALSE);
}
const char *
auth_request_get_var_expand_table(request,
auth_request_str_escape));
- node = hash_lookup(cache->hash, str_c(str));
+ node = hash_table_lookup(cache->hash, str_c(str));
if (node == NULL) {
cache->miss_count++;
return NULL;
while (cache->size_left < alloc_size)
auth_cache_node_destroy(cache, cache->tail);
- node = hash_lookup(cache->hash, str_c(str));
+ node = hash_table_lookup(cache->hash, str_c(str));
if (node != NULL) {
/* key is already in cache (probably expired), remove it */
auth_cache_node_destroy(cache, node);
auth_cache_node_link_head(cache, node);
cache->size_left -= alloc_size;
- hash_insert(cache->hash, node->data, node);
+ hash_table_insert(cache->hash, node->data, node);
}
void auth_cache_remove(struct auth_cache *cache,
auth_request_get_var_expand_table(request,
auth_request_str_escape));
- node = hash_lookup(cache->hash, str_c(str));
+ node = hash_table_lookup(cache->hash, str_c(str));
if (node == NULL)
return;
handler = p_new(pool, struct auth_request_handler, 1);
handler->refcount = 1;
handler->pool = pool;
- handler->requests = hash_create(default_pool, pool, 0, NULL, NULL);
+ handler->requests = hash_table_create(default_pool, pool, 0, NULL, NULL);
handler->auth = auth;
handler->callback = callback;
handler->context = context;
if (--handler->refcount > 0)
return;
- iter = hash_iterate_init(handler->requests);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(handler->requests);
+ while (hash_table_iterate(iter, &key, &value)) {
struct auth_request *auth_request = value;
auth_request_unref(&auth_request);
}
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
/* notify parent that we're done with all requests */
handler->callback(NULL, handler->context);
- hash_destroy(&handler->requests);
+ hash_table_destroy(&handler->requests);
pool_unref(&handler->pool);
}
static void auth_request_handler_remove(struct auth_request_handler *handler,
struct auth_request *request)
{
- hash_remove(handler->requests, POINTER_CAST(request->id));
+ hash_table_remove(handler->requests, POINTER_CAST(request->id));
auth_request_unref(&request);
}
struct hash_iterate_context *iter;
void *key, *value;
- iter = hash_iterate_init(handler->requests);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(handler->requests);
+ while (hash_table_iterate(iter, &key, &value)) {
struct auth_request *request = value;
if (request->last_access + AUTH_REQUEST_TIMEOUT < ioloop_time)
auth_request_handler_remove(handler, request);
}
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
}
static void get_client_extra_fields(struct auth_request *request,
return FALSE;
}
- hash_insert(handler->requests, POINTER_CAST(id), request);
+ hash_table_insert(handler->requests, POINTER_CAST(id), request);
if (request->auth->ssl_require_client_cert &&
!request->valid_client_cert) {
id = (unsigned int)strtoul(args, NULL, 10);
- request = hash_lookup(handler->requests, POINTER_CAST(id));
+ request = hash_table_lookup(handler->requests, POINTER_CAST(id));
if (request == NULL) {
struct auth_stream_reply *reply;
reply = auth_stream_reply_init(pool_datastack_create());
- request = hash_lookup(handler->requests, POINTER_CAST(client_id));
+ request = hash_table_lookup(handler->requests, POINTER_CAST(client_id));
if (request == NULL) {
i_error("Master request %u.%u not found",
handler->client_pid, client_id);
if (*name != '\0' &&
(skip_attr == NULL || strcmp(skip_attr, value) != 0)) {
- hash_insert(attr_map, name, value);
+ hash_table_insert(attr_map, name, value);
(*attr_names_r)[j++] = name;
}
}
if (str_len(static_data) > 0) {
- hash_insert(attr_map, "",
- p_strdup(conn->pool, str_c(static_data)));
+ hash_table_insert(attr_map, "",
+ p_strdup(conn->pool, str_c(static_data)));
}
}
ctx->auth_request = auth_request;
ctx->attr_map = attr_map;
- static_data = hash_lookup(attr_map, "");
+ static_data = hash_table_lookup(attr_map, "");
if (static_data != NULL) {
const struct var_expand_table *table;
string_t *str;
static void
db_ldap_result_change_attr(struct db_ldap_result_iterate_context *ctx)
{
- ctx->name = hash_lookup(ctx->attr_map, ctx->attr);
+ ctx->name = hash_table_lookup(ctx->attr_map, ctx->attr);
ctx->template = NULL;
if (ctx->debug != NULL) {
aqueue_deinit(&conn->request_queue);
if (conn->pass_attr_map != NULL)
- hash_destroy(&conn->pass_attr_map);
+ hash_table_destroy(&conn->pass_attr_map);
if (conn->user_attr_map != NULL)
- hash_destroy(&conn->user_attr_map);
+ hash_table_destroy(&conn->user_attr_map);
pool_unref(&conn->pool);
}
char *user;
size_t len;
- if (hash_lookup(pw->users, username) != NULL) {
+ if (hash_table_lookup(pw->users, username) != NULL) {
i_error("passwd-file %s: User %s exists more than once",
pw->path, username);
return;
p_strsplit_spaces(pw->pool, extra_fields, " ");
}
- hash_insert(pw->users, user, pu);
+ hash_table_insert(pw->users, user, pu);
}
static struct passwd_file *
pw->fd = -1;
if (db->files != NULL)
- hash_insert(db->files, pw->path, pw);
+ hash_table_insert(db->files, pw->path, pw);
return pw;
}
pw->size = st.st_size;
pw->pool = pool_alloconly_create(MEMPOOL_GROWING"passwd_file", 10240);
- pw->users = hash_create(default_pool, pw->pool, 100,
- str_hash, (hash_cmp_callback_t *)strcmp);
+ pw->users = hash_table_create(default_pool, pw->pool, 100,
+ str_hash, (hash_cmp_callback_t *)strcmp);
input = i_stream_create_fd(pw->fd, 4096, FALSE);
i_stream_set_return_partial_line(input, TRUE);
if (pw->db->debug) {
i_info("passwd-file %s: Read %u users",
- pw->path, hash_count(pw->users));
+ pw->path, hash_table_count(pw->users));
}
return TRUE;
}
}
if (pw->users != NULL)
- hash_destroy(&pw->users);
+ hash_table_destroy(&pw->users);
if (pw->pool != NULL)
pool_unref(&pw->pool);
}
static void passwd_file_free(struct passwd_file *pw)
{
if (pw->db->files != NULL)
- hash_remove(pw->db->files, pw->path);
+ hash_table_remove(pw->db->files, pw->path);
passwd_file_close(pw);
i_free(pw->path);
db->path = i_strdup(path);
if (db->vars) {
- db->files = hash_create(default_pool, default_pool, 100,
- str_hash,
- (hash_cmp_callback_t *)strcmp);
+ db->files = hash_table_create(default_pool, default_pool, 100,
+ str_hash,
+ (hash_cmp_callback_t *)strcmp);
} else {
db->default_file = passwd_file_new(db, path);
}
if (db->default_file != NULL)
passwd_file_free(db->default_file);
else {
- iter = hash_iterate_init(db->files);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(db->files);
+ while (hash_table_iterate(iter, &key, &value)) {
struct passwd_file *file = value;
passwd_file_free(file);
}
- hash_iterate_deinit(&iter);
- hash_destroy(&db->files);
+ hash_table_iterate_deinit(&iter);
+ hash_table_destroy(&db->files);
}
i_free(db->path);
i_free(db);
dest = t_str_new(256);
var_expand(dest, db->path, table);
- pw = hash_lookup(db->files, str_c(dest));
+ pw = hash_table_lookup(db->files, str_c(dest));
if (pw == NULL) {
/* doesn't exist yet. create lookup for it. */
pw = passwd_file_new(db, str_c(dest));
"lookup: user=%s file=%s",
str_c(username), pw->path);
- pu = hash_lookup(pw->users, str_c(username));
+ pu = hash_table_lookup(pw->users, str_c(username));
if (pu == NULL)
auth_request_log_info(request, "passwd-file", "unknown user");
return pu;
if (otp_lock_table != NULL)
return;
- otp_lock_table = hash_create(system_pool, system_pool,
- 128, strcase_hash,
- (hash_cmp_callback_t *)strcasecmp);
+ otp_lock_table = hash_table_create(system_pool, system_pool,
+ 128, strcase_hash,
+ (hash_cmp_callback_t *)strcasecmp);
}
int otp_try_lock(struct auth_request *auth_request)
{
- if (hash_lookup(otp_lock_table, auth_request->user))
+ if (hash_table_lookup(otp_lock_table, auth_request->user))
return FALSE;
- hash_insert(otp_lock_table, auth_request->user, auth_request);
+ hash_table_insert(otp_lock_table, auth_request->user, auth_request);
return TRUE;
}
if (!request->lock)
return;
- hash_remove(otp_lock_table, auth_request->user);
+ hash_table_remove(otp_lock_table, auth_request->user);
request->lock = FALSE;
}
verify_plain_callback_t *callback =
(verify_plain_callback_t *)request->callback;
- hash_remove(module->clients, POINTER_CAST(request->pid));
+ hash_table_remove(module->clients, POINTER_CAST(request->pid));
if (result == PASSDB_RESULT_OK) {
if (strchr(str_c(request->input_buf), '\n') != NULL) {
struct checkpassword_passdb_module *module)
{
struct chkpw_auth_request *request =
- hash_lookup(module->clients, POINTER_CAST(status->pid));
+ hash_table_lookup(module->clients, POINTER_CAST(status->pid));
switch (checkpassword_sigchld_handler(status, request)) {
case SIGCHLD_RESULT_UNKNOWN_CHILD:
io_add(fd_out[1], IO_WRITE, checkpassword_child_output,
chkpw_auth_request);
- hash_insert(module->clients, POINTER_CAST(pid), chkpw_auth_request);
+ hash_table_insert(module->clients, POINTER_CAST(pid),
+ chkpw_auth_request);
if (checkpassword_passdb_children != NULL)
child_wait_add_pid(checkpassword_passdb_children, pid);
PKG_LIBEXECDIR"/checkpassword-reply";
module->clients =
- hash_create(default_pool, default_pool, 0, NULL, NULL);
+ hash_table_create(default_pool, default_pool, 0, NULL, NULL);
return &module->module;
}
struct hash_iterate_context *iter;
void *key, *value;
- iter = hash_iterate_init(module->clients);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(module->clients);
+ while (hash_table_iterate(iter, &key, &value)) {
checkpassword_request_finish(value,
PASSDB_RESULT_INTERNAL_FAILURE);
}
- hash_iterate_deinit(&iter);
- hash_destroy(&module->clients);
+ hash_table_iterate_deinit(&iter);
+ hash_table_destroy(&module->clients);
if (checkpassword_passdb_children != NULL)
child_wait_free(&checkpassword_passdb_children);
module = p_new(auth_passdb->auth->pool, struct ldap_passdb_module, 1);
module->conn = conn = db_ldap_init(args);
conn->pass_attr_map =
- hash_create(default_pool, conn->pool, 0, str_hash,
- (hash_cmp_callback_t *)strcmp);
+ hash_table_create(default_pool, conn->pool, 0, str_hash,
+ (hash_cmp_callback_t *)strcmp);
db_ldap_set_attrs(conn, conn->set.pass_attrs, &conn->pass_attr_names,
conn->pass_attr_map,
userdb_callback_t *callback =
(userdb_callback_t *)request->callback;
- hash_remove(module->clients, POINTER_CAST(request->pid));
+ hash_table_remove(module->clients, POINTER_CAST(request->pid));
if (result == USERDB_RESULT_OK) {
if (strchr(str_c(request->input_buf), '\n') != NULL) {
struct checkpassword_userdb_module *module)
{
struct chkpw_auth_request *request =
- hash_lookup(module->clients, POINTER_CAST(status->pid));
+ hash_table_lookup(module->clients, POINTER_CAST(status->pid));
switch (checkpassword_sigchld_handler(status, request)) {
case SIGCHLD_RESULT_UNKNOWN_CHILD:
io_add(fd_out[1], IO_WRITE, checkpassword_child_output,
chkpw_auth_request);
- hash_insert(module->clients, POINTER_CAST(pid), chkpw_auth_request);
+ hash_table_insert(module->clients, POINTER_CAST(pid),
+ chkpw_auth_request);
if (checkpassword_userdb_children != NULL)
child_wait_add_pid(checkpassword_userdb_children, pid);
PKG_LIBEXECDIR"/checkpassword-reply";
module->clients =
- hash_create(default_pool, default_pool, 0, NULL, NULL);
+ hash_table_create(default_pool, default_pool, 0, NULL, NULL);
return &module->module;
}
struct hash_iterate_context *iter;
void *key, *value;
- iter = hash_iterate_init(module->clients);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(module->clients);
+ while (hash_table_iterate(iter, &key, &value)) {
checkpassword_request_finish(value,
USERDB_RESULT_INTERNAL_FAILURE);
}
- hash_iterate_deinit(&iter);
- hash_destroy(&module->clients);
+ hash_table_iterate_deinit(&iter);
+ hash_table_destroy(&module->clients);
if (checkpassword_userdb_children != NULL)
child_wait_free(&checkpassword_userdb_children);
module = p_new(auth_userdb->auth->pool, struct ldap_userdb_module, 1);
module->conn = conn = db_ldap_init(args);
conn->user_attr_map =
- hash_create(default_pool, conn->pool, 0, str_hash,
- (hash_cmp_callback_t *)strcmp);
+ hash_table_create(default_pool, conn->pool, 0, str_hash,
+ (hash_cmp_callback_t *)strcmp);
db_ldap_set_attrs(conn, conn->set.user_attrs, &conn->user_attr_names,
conn->user_attr_map, NULL);
d->user = p_strndup(file->pool,
data + hdr.id_size, hdr.user_size);
d->time = hdr.stamp;
- hash_insert(file->hash, d, d);
+ hash_table_insert(file->hash, d, d);
} else {
change_count++;
}
i_stream_skip(input, hdr.id_size + hdr.user_size);
}
- if (hash_count(file->hash) * COMPRESS_PERCENTAGE / 100 > change_count)
+ if (hash_table_count(file->hash) *
+ COMPRESS_PERCENTAGE / 100 > change_count)
file->changed = TRUE;
return 0;
}
&file->dotlock);
if (file->new_fd == -1)
i_error("file_dotlock_create(%s) failed: %m", path);
- file->hash = hash_create(default_pool, pool, 0,
- duplicate_hash, duplicate_cmp);
+ file->hash = hash_table_create(default_pool, pool, 0,
+ duplicate_hash, duplicate_cmp);
(void)duplicate_read(file);
return file;
}
if (file->dotlock != NULL)
file_dotlock_delete(&file->dotlock);
- hash_destroy(&file->hash);
+ hash_table_destroy(&file->hash);
pool_unref(&file->pool);
}
d.id_size = id_size;
d.user = user;
- return hash_lookup(duplicate_file->hash, &d) != NULL;
+ return hash_table_lookup(duplicate_file->hash, &d) != NULL;
}
void duplicate_mark(const void *id, size_t id_size,
d->time = timestamp;
duplicate_file->changed = TRUE;
- hash_insert(duplicate_file->hash, d, d);
+ hash_table_insert(duplicate_file->hash, d, d);
}
void duplicate_flush(void)
o_stream_send(output, &hdr, sizeof(hdr));
memset(&rec, 0, sizeof(rec));
- iter = hash_iterate_init(file->hash);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(file->hash);
+ while (hash_table_iterate(iter, &key, &value)) {
struct duplicate *d = value;
rec.stamp = d->time;
o_stream_send(output, d->id, rec.id_size);
o_stream_send(output, d->user, rec.user_size);
}
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
o_stream_unref(&output);
file->changed = FALSE;
conn->input = i_stream_create_fd(fd, AUTH_CLIENT_MAX_LINE_LENGTH,
FALSE);
conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
- conn->requests = hash_create(default_pool, pool, 100, NULL, NULL);
+ conn->requests = hash_table_create(default_pool, pool, 100, NULL, NULL);
conn->auth_mechs_buf = buffer_create_dynamic(default_pool, 256);
conn->to = timeout_add(AUTH_HANDSHAKE_TIMEOUT,
return;
i_assert(conn->refcount == 0);
- hash_destroy(&conn->requests);
+ hash_table_destroy(&conn->requests);
buffer_free(&conn->auth_mechs_buf);
i_stream_unref(&conn->input);
try it for the next */
request->plaintext_data = i_strdup(data);
- hash_insert(request->next_conn->requests,
- POINTER_CAST(request->id), request);
+ hash_table_insert(request->next_conn->requests,
+ POINTER_CAST(request->id), request);
if (auth_server_send_new_request(request->next_conn,
request, &error) == 0)
request->retrying = TRUE;
id = (unsigned int)strtoul(list[0], NULL, 10);
- request = hash_lookup(conn->requests, POINTER_CAST(id));
+ request = hash_table_lookup(conn->requests, POINTER_CAST(id));
if (request == NULL) {
/* We've already destroyed the request */
return TRUE;
}
- hash_remove(request->conn->requests, POINTER_CAST(id));
- if (request->next_conn != NULL)
- hash_remove(request->next_conn->requests, POINTER_CAST(id));
+ hash_table_remove(request->conn->requests, POINTER_CAST(id));
+ if (request->next_conn != NULL) {
+ hash_table_remove(request->next_conn->requests,
+ POINTER_CAST(id));
+ }
request->conn = conn;
request->next_conn = NULL;
id = (unsigned int)strtoul(args, NULL, 10);
- request = hash_lookup(conn->requests, POINTER_CAST(id));
+ request = hash_table_lookup(conn->requests, POINTER_CAST(id));
if (request == NULL) {
/* We've already destroyed the request */
return TRUE;
id = (unsigned int)strtoul(list[0], NULL, 10);
- request = hash_lookup(conn->requests, POINTER_CAST(id));
+ request = hash_table_lookup(conn->requests, POINTER_CAST(id));
if (request == NULL) {
/* We've already destroyed the request */
return TRUE;
}
- hash_remove(conn->requests, POINTER_CAST(request->id));
+ hash_table_remove(conn->requests, POINTER_CAST(request->id));
if (request->retrying) {
next = request->next_conn == NULL ? NULL :
get_next_plain_server(request->next_conn);
}
request->conn = conn;
} else {
- hash_insert(next->requests, POINTER_CAST(request->id),
- request);
+ hash_table_insert(next->requests,
+ POINTER_CAST(request->id), request);
request->next_conn = next;
T_BEGIN {
struct hash_iterate_context *iter;
void *key, *value;
- iter = hash_iterate_init(conn->requests);
- while (hash_iterate(iter, &key, &value))
+ iter = hash_table_iterate_init(conn->requests);
+ while (hash_table_iterate(iter, &key, &value))
request_hash_remove(conn, value);
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
}
struct auth_request *
T_BEGIN {
if (auth_server_send_new_request(conn, request, error_r) == 0) {
- hash_insert(conn->requests, POINTER_CAST(request->id),
- request);
+ hash_table_insert(conn->requests,
+ POINTER_CAST(request->id), request);
} else {
auth_client_request_free(request);
request = NULL;
{
void *id = POINTER_CAST(request->id);
- hash_remove(request->conn->requests, id);
+ hash_table_remove(request->conn->requests, id);
if (request->next_conn != NULL)
- hash_remove(request->next_conn->requests, id);
+ hash_table_remove(request->next_conn->requests, id);
request->callback(request, -1, NULL, NULL, request->context);
auth_client_request_free(request);
dict->dict = *driver;
dict->path = i_strdup(uri);
dict->hash_pool = pool_alloconly_create("file dict", 1024);
- dict->hash = hash_create(default_pool, dict->hash_pool, 0, str_hash,
- (hash_cmp_callback_t *)strcmp);
+ dict->hash = hash_table_create(default_pool, dict->hash_pool, 0,
+ str_hash, (hash_cmp_callback_t *)strcmp);
dict->fd = -1;
return &dict->dict;
}
{
struct file_dict *dict = (struct file_dict *)_dict;
- hash_destroy(&dict->hash);
+ hash_table_destroy(&dict->hash);
pool_unref(&dict->hash_pool);
i_free(dict->path);
i_free(dict);
return -1;
}
- hash_clear(dict->hash, TRUE);
+ hash_table_clear(dict->hash, TRUE);
p_clear(dict->hash_pool);
input = i_stream_create_fd(dict->fd, (size_t)-1, FALSE);
(value = i_stream_read_next_line(input)) != NULL) {
key = p_strdup(dict->hash_pool, key);
value = p_strdup(dict->hash_pool, value);
- hash_insert(dict->hash, key, value);
+ hash_table_insert(dict->hash, key, value);
}
i_stream_destroy(&input);
return 0;
if (file_dict_refresh(dict) < 0)
return -1;
- *value_r = p_strdup(pool, hash_lookup(dict->hash, key));
+ *value_r = p_strdup(pool, hash_table_lookup(dict->hash, key));
return *value_r == NULL ? 0 : 1;
}
ctx->path = i_strdup(path);
ctx->path_len = strlen(path);
ctx->flags = flags;
- ctx->iter = hash_iterate_init(dict->hash);
+ ctx->iter = hash_table_iterate_init(dict->hash);
if (file_dict_refresh(dict) < 0)
ctx->failed = TRUE;
(struct file_dict_iterate_context *)_ctx;
void *key, *value;
- while (hash_iterate(ctx->iter, &key, &value)) {
+ while (hash_table_iterate(ctx->iter, &key, &value)) {
if (strncmp(ctx->path, key, ctx->path_len) != 0)
continue;
struct file_dict_iterate_context *ctx =
(struct file_dict_iterate_context *)_ctx;
- hash_iterate_deinit(&ctx->iter);
+ hash_table_iterate_deinit(&ctx->iter);
i_free(ctx->path);
i_free(ctx);
}
changes = array_get(&ctx->changes, &count);
for (i = 0; i < count; i++) {
- if (hash_lookup_full(dict->hash, changes[i].key,
- &orig_key, &orig_value)) {
+ if (hash_table_lookup_full(dict->hash, changes[i].key,
+ &orig_key, &orig_value)) {
key = orig_key;
old_value = orig_value;
} else {
value = p_strdup(dict->hash_pool,
changes[i].value.str);
}
- hash_update(dict->hash, key, value);
+ hash_table_update(dict->hash, key, value);
break;
case FILE_DICT_CHANGE_TYPE_UNSET:
if (old_value != NULL)
- hash_remove(dict->hash, key);
+ hash_table_remove(dict->hash, key);
break;
}
}
output = o_stream_create_fd(fd, 0, FALSE);
o_stream_cork(output);
- iter = hash_iterate_init(dict->hash);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(dict->hash);
+ while (hash_table_iterate(iter, &key, &value)) {
o_stream_send_str(output, key);
o_stream_send(output, "\n", 1);
o_stream_send_str(output, value);
o_stream_send(output, "\n", 1);
}
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
o_stream_destroy(&output);
if (file_dotlock_replace(&dotlock,
new_idx = cache->fields_count;
for (i = 0; i < fields_count; i++) {
- if (hash_lookup_full(cache->field_name_hash, fields[i].name,
- &orig_key, &orig_value)) {
+ if (hash_table_lookup_full(cache->field_name_hash,
+ fields[i].name,
+ &orig_key, &orig_value)) {
i_assert(fields[i].type < MAIL_CACHE_FIELD_COUNT);
fields[i].idx =
if (!field_has_fixed_size(cache->fields[idx].field.type))
cache->fields[idx].field.field_size = (unsigned int)-1;
- hash_insert(cache->field_name_hash, name, POINTER_CAST(idx));
+ hash_table_insert(cache->field_name_hash,
+ name, POINTER_CAST(idx));
}
cache->fields_count = new_idx;
}
{
void *orig_key, *orig_value;
- if (hash_lookup_full(cache->field_name_hash, name,
- &orig_key, &orig_value))
+ if (hash_table_lookup_full(cache->field_name_hash, name,
+ &orig_key, &orig_value))
return POINTER_CAST_TO(orig_value, unsigned int);
else
return (unsigned int)-1;
return -1;
}
- if (hash_lookup_full(cache->field_name_hash, names,
- &orig_key, &orig_value)) {
+ if (hash_table_lookup_full(cache->field_name_hash, names,
+ &orig_key, &orig_value)) {
/* already exists, see if decision can be updated */
fidx = POINTER_CAST_TO(orig_value, unsigned int);
if (!cache->fields[fidx].decision_dirty) {
i_strconcat(index->filepath, MAIL_CACHE_FILE_SUFFIX, NULL);
cache->field_pool = pool_alloconly_create("Cache fields", 1024);
cache->field_name_hash =
- hash_create(default_pool, cache->field_pool, 0,
- strcase_hash, (hash_cmp_callback_t *)strcasecmp);
+ hash_table_create(default_pool, cache->field_pool, 0,
+ strcase_hash, (hash_cmp_callback_t *)strcasecmp);
cache->dotlock_settings.use_excl_lock = index->use_excl_dotlocks;
cache->dotlock_settings.nfs_flush = index->nfs_flush;
mail_cache_file_close(cache);
- hash_destroy(&cache->field_name_hash);
+ hash_table_destroy(&cache->field_name_hash);
pool_unref(&cache->field_pool);
i_free(cache->field_file_map);
i_free(cache->file_field_map);
index->keywords_pool = pool_alloconly_create("keywords", 512);
i_array_init(&index->keywords, 16);
index->keywords_hash =
- hash_create(default_pool, index->keywords_pool, 0,
- strcase_hash, (hash_cmp_callback_t *)strcasecmp);
+ hash_table_create(default_pool, index->keywords_pool, 0,
+ strcase_hash, (hash_cmp_callback_t *)strcasecmp);
index->log = mail_transaction_log_alloc(index);
mail_index_modseq_init(index);
return index;
mail_index_close(index);
mail_transaction_log_free(&index->log);
- hash_destroy(&index->keywords_hash);
+ hash_table_destroy(&index->keywords_hash);
pool_unref(&index->extension_pool);
pool_unref(&index->keywords_pool);
/* keywords_hash keeps a name => index mapping of keywords.
Keywords are never removed from it, so the index values are valid
for the lifetime of the mail_index. */
- if (hash_lookup_full(index->keywords_hash, keyword, NULL, &value)) {
+ if (hash_table_lookup_full(index->keywords_hash, keyword,
+ NULL, &value)) {
*idx_r = POINTER_CAST_TO(value, unsigned int);
return TRUE;
}
keyword = keyword_dup = p_strdup(index->keywords_pool, keyword);
*idx_r = array_count(&index->keywords);
- hash_insert(index->keywords_hash, keyword_dup, POINTER_CAST(*idx_r));
+ hash_table_insert(index->keywords_hash,
+ keyword_dup, POINTER_CAST(*idx_r));
array_append(&index->keywords, &keyword, 1);
}
char *key;
key = i_strdup_printf("%s\t%s", db_driver, connect_string);
- db = hash_lookup(pool->dbs, key);
+ db = hash_table_lookup(pool->dbs, key);
if (db != NULL) {
ctx = SQL_POOL_CONTEXT(db);
if (ctx->refcount == 0) {
db->v.deinit = sql_pool_db_deinit;
MODULE_CONTEXT_SET(db, sql_pool_module, ctx);
- hash_insert(pool->dbs, ctx->key, db);
+ hash_table_insert(pool->dbs, ctx->key, db);
}
ctx->refcount++;
struct sql_pool *pool;
pool = i_new(struct sql_pool, 1);
- pool->dbs = hash_create(default_pool, default_pool, 0, str_hash,
- (hash_cmp_callback_t *)strcmp);
+ pool->dbs = hash_table_create(default_pool, default_pool, 0, str_hash,
+ (hash_cmp_callback_t *)strcmp);
pool->max_unused_connections = max_unused_connections;
return pool;
}
struct sql_pool *pool = *_pool;
*_pool = NULL;
- hash_destroy(&pool->dbs);
+ hash_table_destroy(&pool->dbs);
i_free(pool);
}
&file_id, &offset))
return -1;
- entry = hash_lookup(ctx->syncs, POINTER_CAST(file_id));
+ entry = hash_table_lookup(ctx->syncs, POINTER_CAST(file_id));
if (entry == NULL) {
if (sync_rec->type == MAIL_INDEX_SYNC_TYPE_EXPUNGE ||
ctx->flush_dirty_flags) {
entry = p_new(ctx->pool, struct dbox_sync_file_entry, 1);
entry->file_id = file_id;
- hash_insert(ctx->syncs, POINTER_CAST(file_id), entry);
+ hash_table_insert(ctx->syncs, POINTER_CAST(file_id), entry);
}
uid_file = (file_id & DBOX_FILE_ID_FLAG_UID) != 0;
/* read all changes and sort them to file_id order */
ctx->pool = pool_alloconly_create("dbox sync pool", 1024*32);
- ctx->syncs = hash_create(default_pool, ctx->pool, 0, NULL, NULL);
+ ctx->syncs = hash_table_create(default_pool, ctx->pool, 0, NULL, NULL);
i_array_init(&ctx->expunge_files, 32);
i_array_init(&ctx->locked_files, 32);
if (ret > 0) {
/* now sync each file separately */
- iter = hash_iterate_init(ctx->syncs);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(ctx->syncs);
+ while (hash_table_iterate(iter, &key, &value)) {
const struct dbox_sync_file_entry *entry = value;
if ((ret = dbox_sync_file(ctx, entry)) <= 0)
break;
}
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
}
if (ret > 0)
dbox_sync_unlock_files(ctx);
array_free(&ctx->locked_files);
- hash_destroy(&ctx->syncs);
+ hash_table_destroy(&ctx->syncs);
pool_unref(&ctx->pool);
return ret;
}
/* (iii) Look up the message associated with the thread
subject in the subject table. */
- if (!hash_lookup_full(ctx->subject_hash, subject, &key, &value)) {
+ if (!hash_table_lookup_full(ctx->subject_hash, subject, &key, &value)) {
/* (iv) If there is no message in the subject table with the
thread subject, add the current message and the thread
subject to the subject table. */
hash_subject = p_strdup(ctx->subject_pool, subject);
- hash_insert(ctx->subject_hash, hash_subject, node);
+ hash_table_insert(ctx->subject_hash, hash_subject, node);
} else {
hash_subject = key;
hash_node = value;
(node->dummy ||
(hash_node->reply_or_forward && !is_reply_or_forward))) {
hash_node->parent_root_idx1 = node->root_idx1;
- hash_update(ctx->subject_hash, hash_subject, node);
+ hash_table_update(ctx->subject_hash, hash_subject, node);
} else {
node->parent_root_idx1 = hash_node->root_idx1;
}
pool_alloconly_create(MEMPOOL_GROWING"base subjects",
nearest_power(count * 20));
gather_ctx.subject_hash =
- hash_create(default_pool, gather_ctx.subject_pool, count * 2,
- str_hash, (hash_cmp_callback_t *)strcmp);
+ hash_table_create(default_pool, gather_ctx.subject_pool,
+ count * 2, str_hash,
+ (hash_cmp_callback_t *)strcmp);
i_array_init(&sorted_children, 64);
for (i = 0; i < count; i++) {
}
i_assert(roots[count-1].parent_root_idx1 <= count);
array_free(&sorted_children);
- hash_destroy(&gather_ctx.subject_hash);
+ hash_table_destroy(&gather_ctx.subject_hash);
pool_unref(&gather_ctx.subject_pool);
}
mk->path = i_strconcat(dir, "/" MAILDIR_KEYWORDS_NAME, NULL);
mk->pool = pool_alloconly_create("maildir keywords", 512);
i_array_init(&mk->list, MAILDIR_MAX_KEYWORDS);
- mk->hash = hash_create(default_pool, mk->pool, 0,
- strcase_hash, (hash_cmp_callback_t *)strcasecmp);
+ mk->hash = hash_table_create(default_pool, mk->pool, 0,
+ strcase_hash, (hash_cmp_callback_t *)strcasecmp);
mk->dotlock_settings.use_excl_lock =
(box->storage->flags & MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0;
struct maildir_keywords *mk = *_mk;
*_mk = NULL;
- hash_destroy(&mk->hash);
+ hash_table_destroy(&mk->hash);
array_free(&mk->list);
pool_unref(&mk->pool);
i_free(mk->path);
static void maildir_keywords_clear(struct maildir_keywords *mk)
{
array_clear(&mk->list);
- hash_clear(mk->hash, FALSE);
+ hash_table_clear(mk->hash, FALSE);
p_clear(mk->pool);
}
/* save it */
new_name = p_strdup(mk->pool, p);
- hash_insert(mk->hash, new_name, POINTER_CAST(idx + 1));
+ hash_table_insert(mk->hash, new_name, POINTER_CAST(idx + 1));
strp = array_idx_modifiable(&mk->list, idx);
*strp = new_name;
{
void *p;
- p = hash_lookup(mk->hash, name);
+ p = hash_table_lookup(mk->hash, name);
if (p == NULL) {
if (mk->synced)
return -1;
if (maildir_keywords_sync(mk) < 0)
return -1;
- p = hash_lookup(mk->hash, name);
+ p = hash_table_lookup(mk->hash, name);
if (p == NULL)
return -1;
}
i_assert(chridx < MAILDIR_MAX_KEYWORDS);
new_name = p_strdup(mk->pool, name);
- hash_insert(mk->hash, new_name, POINTER_CAST(chridx + 1));
+ hash_table_insert(mk->hash, new_name, POINTER_CAST(chridx + 1));
strp = array_idx_modifiable(&mk->list, chridx);
*strp = new_name;
uidlist->ibox = ibox;
uidlist->path = i_strconcat(control_dir, "/"MAILDIR_UIDLIST_NAME, NULL);
i_array_init(&uidlist->records, 128);
- uidlist->files = hash_create(default_pool, default_pool, 4096,
- maildir_filename_base_hash,
- maildir_filename_base_cmp);
+ uidlist->files = hash_table_create(default_pool, default_pool, 4096,
+ maildir_filename_base_hash,
+ maildir_filename_base_cmp);
uidlist->next_uid = 1;
uidlist->hdr_extensions = str_new(default_pool, 128);
maildir_uidlist_update(uidlist);
maildir_uidlist_close(uidlist);
- hash_destroy(&uidlist->files);
+ hash_table_destroy(&uidlist->files);
if (uidlist->record_pool != NULL)
pool_unref(&uidlist->record_pool);
return FALSE;
}
- old_rec = hash_lookup(uidlist->files, line);
+ old_rec = hash_table_lookup(uidlist->files, line);
if (old_rec != NULL) {
/* This can happen if expunged file is moved back and the file
was appended to uidlist. */
}
rec->filename = p_strdup(uidlist->record_pool, line);
- hash_insert(uidlist->files, rec->filename, rec);
+ hash_table_insert(uidlist->files, rec->filename, rec);
array_append(&uidlist->records, &rec, 1);
return TRUE;
}
ctx->record_pool = pool_alloconly_create(MEMPOOL_GROWING
"maildir_uidlist_sync", 16384);
- ctx->files = hash_create(default_pool, ctx->record_pool, 4096,
- maildir_filename_base_hash,
- maildir_filename_base_cmp);
+ ctx->files = hash_table_create(default_pool, ctx->record_pool, 4096,
+ maildir_filename_base_hash,
+ maildir_filename_base_cmp);
i_array_init(&ctx->records, array_count(&uidlist->records));
return 1;
struct maildir_uidlist_rec *rec;
/* we'll update uidlist directly */
- rec = hash_lookup(uidlist->files, filename);
+ rec = hash_table_lookup(uidlist->files, filename);
if (rec == NULL) {
/* doesn't exist in uidlist */
if (!ctx->locked) {
rec->flags = (rec->flags | flags) & ~MAILDIR_UIDLIST_REC_FLAG_NONSYNCED;
rec->filename = p_strdup(uidlist->record_pool, filename);
- hash_insert(uidlist->files, rec->filename, rec);
+ hash_table_insert(uidlist->files, rec->filename, rec);
ctx->finished = FALSE;
}
return 1;
}
- rec = hash_lookup(ctx->files, filename);
+ rec = hash_table_lookup(ctx->files, filename);
if (rec != NULL) {
if ((rec->flags & (MAILDIR_UIDLIST_REC_FLAG_NEW_DIR |
MAILDIR_UIDLIST_REC_FLAG_MOVED)) == 0) {
rec->flags &= ~(MAILDIR_UIDLIST_REC_FLAG_NEW_DIR |
MAILDIR_UIDLIST_REC_FLAG_MOVED);
} else {
- old_rec = hash_lookup(uidlist->files, filename);
+ old_rec = hash_table_lookup(uidlist->files, filename);
i_assert(old_rec != NULL || UIDLIST_IS_LOCKED(uidlist));
rec = p_new(ctx->record_pool, struct maildir_uidlist_rec, 1);
rec->flags = (rec->flags | flags) & ~MAILDIR_UIDLIST_REC_FLAG_NONSYNCED;
rec->filename = p_strdup(ctx->record_pool, filename);
- hash_insert(ctx->files, rec->filename, rec);
+ hash_table_insert(ctx->files, rec->filename, rec);
return 1;
}
i_assert(ctx->partial);
- rec = hash_lookup(ctx->uidlist->files, filename);
+ rec = hash_table_lookup(ctx->uidlist->files, filename);
i_assert(rec != NULL);
i_assert(rec->uid != (uint32_t)-1);
- hash_remove(ctx->uidlist->files, filename);
+ hash_table_remove(ctx->uidlist->files, filename);
idx = maildir_uidlist_records_array_delete(ctx->uidlist, rec);
if (ctx->first_unwritten_pos != (unsigned int)-1) {
{
struct maildir_uidlist_rec *rec;
- rec = hash_lookup(ctx->files, filename);
+ rec = hash_table_lookup(ctx->files, filename);
return rec == NULL ? NULL : rec->filename;
}
{
struct maildir_uidlist_rec *rec;
- rec = hash_lookup(uidlist->files, filename);
+ rec = hash_table_lookup(uidlist->files, filename);
if (rec == NULL)
return FALSE;
{
struct maildir_uidlist_rec *rec;
- rec = hash_lookup(uidlist->files, filename);
+ rec = hash_table_lookup(uidlist->files, filename);
return rec == NULL ? NULL : rec->filename;
}
uidlist->records = ctx->records;
ctx->records.arr.buffer = NULL;
- hash_destroy(&uidlist->files);
+ hash_table_destroy(&uidlist->files);
uidlist->files = ctx->files;
ctx->files = NULL;
maildir_uidlist_unlock(ctx->uidlist);
if (ctx->files != NULL)
- hash_destroy(&ctx->files);
+ hash_table_destroy(&ctx->files);
if (ctx->record_pool != NULL)
pool_unref(&ctx->record_pool);
if (array_is_created(&ctx->records))
{
struct maildir_uidlist_rec *rec;
- rec = hash_lookup(uidlist->files, filename);
+ rec = hash_table_lookup(uidlist->files, filename);
i_assert(rec != NULL);
rec->flags |= flags;
if (wait->pid_count > 0) {
/* this should be rare, so iterating hash is fast enough */
- iter = hash_iterate_init(child_pids);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(child_pids);
+ while (hash_table_iterate(iter, &key, &value)) {
if (value == wait) {
- hash_remove(child_pids, key);
+ hash_table_remove(child_pids, key);
if (--wait->pid_count == 0)
break;
}
}
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
}
i_free(wait);
void child_wait_add_pid(struct child_wait *wait, pid_t pid)
{
wait->pid_count++;
- hash_insert(child_pids, POINTER_CAST(pid), wait);
+ hash_table_insert(child_pids, POINTER_CAST(pid), wait);
}
void child_wait_remove_pid(struct child_wait *wait, pid_t pid)
{
wait->pid_count--;
- hash_remove(child_pids, POINTER_CAST(pid));
+ hash_table_remove(child_pids, POINTER_CAST(pid));
}
static void
struct child_wait_status status;
while ((status.pid = waitpid(-1, &status.status, WNOHANG)) > 0) {
- status.wait = hash_lookup(child_pids, POINTER_CAST(status.pid));
+ status.wait = hash_table_lookup(child_pids,
+ POINTER_CAST(status.pid));
if (status.wait != NULL) {
child_wait_remove_pid(status.wait, status.pid);
status.wait->callback(&status, status.wait->context);
void child_wait_init(void)
{
- child_pids = hash_create(default_pool, default_pool, 0, NULL, NULL);
+ child_pids = hash_table_create(default_pool, default_pool, 0,
+ NULL, NULL);
lib_signals_set_handler(SIGCHLD, TRUE, sigchld_handler, NULL);
}
lib_signals_unset_handler(SIGCHLD, sigchld_handler, NULL);
- iter = hash_iterate_init(child_pids);
- while (hash_iterate(iter, &key, &value))
+ iter = hash_table_iterate_init(child_pids);
+ while (hash_table_iterate(iter, &key, &value))
i_free(value);
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
- hash_destroy(&child_pids);
+ hash_table_destroy(&child_pids);
}
unsigned int pos;
};
-static bool hash_resize(struct hash_table *table, bool grow);
+static bool hash_table_resize(struct hash_table *table, bool grow);
static int direct_cmp(const void *p1, const void *p2)
{
}
struct hash_table *
-hash_create(pool_t table_pool, pool_t node_pool, unsigned int initial_size,
- hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb)
+hash_table_create(pool_t table_pool, pool_t node_pool, unsigned int initial_size,
+ hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb)
{
struct hash_table *table;
}
}
-static void hash_destroy_nodes(struct hash_table *table)
+static void hash_table_destroy_nodes(struct hash_table *table)
{
unsigned int i;
}
}
-void hash_destroy(struct hash_table **_table)
+void hash_table_destroy(struct hash_table **_table)
{
struct hash_table *table = *_table;
*_table = NULL;
if (!table->node_pool->alloconly_pool) {
- hash_destroy_nodes(table);
+ hash_table_destroy_nodes(table);
destroy_node_list(table, table->free_nodes);
}
p_free(table->table_pool, table);
}
-void hash_clear(struct hash_table *table, bool free_nodes)
+void hash_table_clear(struct hash_table *table, bool free_nodes)
{
if (!table->node_pool->alloconly_pool)
- hash_destroy_nodes(table);
+ hash_table_destroy_nodes(table);
if (free_nodes) {
if (!table->node_pool->alloconly_pool)
}
static struct hash_node *
-hash_lookup_node(const struct hash_table *table,
- const void *key, unsigned int hash)
+hash_table_lookup_node(const struct hash_table *table,
+ const void *key, unsigned int hash)
{
struct hash_node *node;
return NULL;
}
-void *hash_lookup(const struct hash_table *table, const void *key)
+void *hash_table_lookup(const struct hash_table *table, const void *key)
{
struct hash_node *node;
- node = hash_lookup_node(table, key, table->hash_cb(key));
+ node = hash_table_lookup_node(table, key, table->hash_cb(key));
return node != NULL ? node->value : NULL;
}
-bool hash_lookup_full(const struct hash_table *table, const void *lookup_key,
- void **orig_key, void **value)
+bool hash_table_lookup_full(const struct hash_table *table,
+ const void *lookup_key,
+ void **orig_key, void **value)
{
struct hash_node *node;
- node = hash_lookup_node(table, lookup_key,
- table->hash_cb(lookup_key));
+ node = hash_table_lookup_node(table, lookup_key,
+ table->hash_cb(lookup_key));
if (node == NULL)
return FALSE;
}
static struct hash_node *
-hash_insert_node(struct hash_table *table, void *key, void *value,
- bool check_existing)
+hash_table_insert_node(struct hash_table *table, void *key, void *value,
+ bool check_existing)
{
struct hash_node *node, *prev;
unsigned int hash;
if (check_existing && table->removed_count > 0) {
/* there may be holes, have to check everything */
- node = hash_lookup_node(table, key, hash);
+ node = hash_table_lookup_node(table, key, hash);
if (node != NULL) {
node->value = value;
return node;
}
if (node == NULL) {
- if (table->frozen == 0 && hash_resize(table, TRUE)) {
+ if (table->frozen == 0 && hash_table_resize(table, TRUE)) {
/* resized table, try again */
- return hash_insert_node(table, key, value, FALSE);
+ return hash_table_insert_node(table, key, value, FALSE);
}
if (table->free_nodes == NULL)
return node;
}
-void hash_insert(struct hash_table *table, void *key, void *value)
+void hash_table_insert(struct hash_table *table, void *key, void *value)
{
struct hash_node *node;
- node = hash_insert_node(table, key, value, TRUE);
+ node = hash_table_insert_node(table, key, value, TRUE);
node->key = key;
}
-void hash_update(struct hash_table *table, void *key, void *value)
+void hash_table_update(struct hash_table *table, void *key, void *value)
{
- (void)hash_insert_node(table, key, value, TRUE);
+ (void)hash_table_insert_node(table, key, value, TRUE);
}
-static void hash_compress(struct hash_table *table, struct hash_node *root)
+static void
+hash_table_compress(struct hash_table *table, struct hash_node *root)
{
struct hash_node *node, *next;
}
}
-static void hash_compress_removed(struct hash_table *table)
+static void hash_table_compress_removed(struct hash_table *table)
{
unsigned int i;
for (i = 0; i < table->size; i++)
- hash_compress(table, &table->nodes[i]);
+ hash_table_compress(table, &table->nodes[i]);
table->removed_count = 0;
}
-void hash_remove(struct hash_table *table, const void *key)
+void hash_table_remove(struct hash_table *table, const void *key)
{
struct hash_node *node;
unsigned int hash;
hash = table->hash_cb(key);
- node = hash_lookup_node(table, key, hash);
+ node = hash_table_lookup_node(table, key, hash);
if (unlikely(node == NULL))
i_panic("key not found from hash");
if (table->frozen != 0)
table->removed_count++;
- else if (!hash_resize(table, FALSE))
- hash_compress(table, &table->nodes[hash % table->size]);
+ else if (!hash_table_resize(table, FALSE))
+ hash_table_compress(table, &table->nodes[hash % table->size]);
}
-unsigned int hash_count(const struct hash_table *table)
+unsigned int hash_table_count(const struct hash_table *table)
{
return table->nodes_count;
}
-struct hash_iterate_context *hash_iterate_init(struct hash_table *table)
+struct hash_iterate_context *hash_table_iterate_init(struct hash_table *table)
{
struct hash_iterate_context *ctx;
- hash_freeze(table);
+ hash_table_freeze(table);
ctx = i_new(struct hash_iterate_context, 1);
ctx->table = table;
return ctx;
}
-static struct hash_node *hash_iterate_next(struct hash_iterate_context *ctx,
- struct hash_node *node)
+static struct hash_node *
+hash_table_iterate_next(struct hash_iterate_context *ctx,
+ struct hash_node *node)
{
do {
node = node->next;
return node;
}
-bool hash_iterate(struct hash_iterate_context *ctx,
- void **key_r, void **value_r)
+bool hash_table_iterate(struct hash_iterate_context *ctx,
+ void **key_r, void **value_r)
{
struct hash_node *node;
node = ctx->next;
if (node != NULL && node->key == NULL)
- node = hash_iterate_next(ctx, node);
+ node = hash_table_iterate_next(ctx, node);
if (node == NULL) {
*key_r = *value_r = NULL;
return FALSE;
*key_r = node->key;
*value_r = node->value;
- ctx->next = hash_iterate_next(ctx, node);
+ ctx->next = hash_table_iterate_next(ctx, node);
return TRUE;
}
-void hash_iterate_deinit(struct hash_iterate_context **_ctx)
+void hash_table_iterate_deinit(struct hash_iterate_context **_ctx)
{
struct hash_iterate_context *ctx = *_ctx;
*_ctx = NULL;
- hash_thaw(ctx->table);
+ hash_table_thaw(ctx->table);
i_free(ctx);
}
-void hash_freeze(struct hash_table *table)
+void hash_table_freeze(struct hash_table *table)
{
table->frozen++;
}
-void hash_thaw(struct hash_table *table)
+void hash_table_thaw(struct hash_table *table)
{
i_assert(table->frozen > 0);
return;
if (table->removed_count > 0) {
- if (!hash_resize(table, FALSE))
- hash_compress_removed(table);
+ if (!hash_table_resize(table, FALSE))
+ hash_table_compress_removed(table);
}
}
-static bool hash_resize(struct hash_table *table, bool grow)
+static bool hash_table_resize(struct hash_table *table, bool grow)
{
struct hash_node *old_nodes, *node, *next;
unsigned int next_size, old_size, i;
/* move the data */
for (i = 0; i < old_size; i++) {
node = &old_nodes[i];
- if (node->key != NULL)
- hash_insert_node(table, node->key, node->value, FALSE);
+ if (node->key != NULL) {
+ hash_table_insert_node(table, node->key,
+ node->value, FALSE);
+ }
for (node = node->next; node != NULL; node = next) {
next = node->next;
if (node->key != NULL) {
- hash_insert_node(table, node->key,
- node->value, FALSE);
+ hash_table_insert_node(table, node->key,
+ node->value, FALSE);
}
free_node(table, node);
}
return TRUE;
}
-void hash_copy(struct hash_table *dest, struct hash_table *src)
+void hash_table_copy(struct hash_table *dest, struct hash_table *src)
{
struct hash_iterate_context *iter;
void *key, *value;
- hash_freeze(dest);
+ hash_table_freeze(dest);
- iter = hash_iterate_init(src);
- while (hash_iterate(iter, &key, &value))
- hash_insert(dest, key, value);
- hash_iterate_deinit(&iter);
+ iter = hash_table_iterate_init(src);
+ while (hash_table_iterate(iter, &key, &value))
+ hash_table_insert(dest, key, value);
+ hash_table_iterate_deinit(&iter);
- hash_thaw(dest);
+ hash_table_thaw(dest);
}
/* a char* hash function from ASU -- from glib */
table_pool is used to allocate/free large hash tables, node_pool is used
for smaller allocations and can also be alloconly pool. The pools must not
- be free'd before hash_destroy() is called. */
+ be free'd before hash_table_destroy() is called. */
+/* APPLE - renamed from hash_create/hash_destroy to avoid libc conflict */
struct hash_table *
-hash_create(pool_t table_pool, pool_t node_pool, unsigned int initial_size,
- hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb);
-void hash_destroy(struct hash_table **table);
+hash_table_create(pool_t table_pool, pool_t node_pool, unsigned int initial_size,
+ hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb);
+void hash_table_destroy(struct hash_table **table);
/* Remove all nodes from hash table. If free_collisions is TRUE, the
memory allocated from node_pool is freed, or discarded with
alloconly pools. */
-void hash_clear(struct hash_table *table, bool free_collisions);
+void hash_table_clear(struct hash_table *table, bool free_collisions);
-void *hash_lookup(const struct hash_table *table, const void *key) ATTR_PURE;
-bool hash_lookup_full(const struct hash_table *table, const void *lookup_key,
- void **orig_key, void **value);
+void *hash_table_lookup(const struct hash_table *table, const void *key) ATTR_PURE;
+bool hash_table_lookup_full(const struct hash_table *table,
+ const void *lookup_key,
+ void **orig_key, void **value);
-/* Insert/update node in hash table. The difference is that hash_insert()
- replaces the key in table to given one, while hash_update() doesnt. */
-void hash_insert(struct hash_table *table, void *key, void *value);
-void hash_update(struct hash_table *table, void *key, void *value);
+/* Insert/update node in hash table. The difference is that hash_table_insert()
+ replaces the key in table to given one, while hash_table_update() doesnt. */
+void hash_table_insert(struct hash_table *table, void *key, void *value);
+void hash_table_update(struct hash_table *table, void *key, void *value);
-void hash_remove(struct hash_table *table, const void *key);
-unsigned int hash_count(const struct hash_table *table) ATTR_PURE;
+void hash_table_remove(struct hash_table *table, const void *key);
+unsigned int hash_table_count(const struct hash_table *table) ATTR_PURE;
-/* Iterates through all nodes in hash table. You may safely call hash_*()
+/* Iterates through all nodes in hash table. You may safely call hash_table_*()
functions while iterating, but if you add any new nodes, they may or may
not be called for in this iteration. */
-struct hash_iterate_context *hash_iterate_init(struct hash_table *table);
-bool hash_iterate(struct hash_iterate_context *ctx,
- void **key_r, void **value_r);
-void hash_iterate_deinit(struct hash_iterate_context **ctx);
+struct hash_iterate_context *hash_table_iterate_init(struct hash_table *table);
+bool hash_table_iterate(struct hash_iterate_context *ctx,
+ void **key_r, void **value_r);
+void hash_table_iterate_deinit(struct hash_iterate_context **ctx);
/* Hash table isn't resized, and removed nodes aren't removed from
the list while hash table is freezed. Supports nesting. */
-void hash_freeze(struct hash_table *table);
-void hash_thaw(struct hash_table *table);
+void hash_table_freeze(struct hash_table *table);
+void hash_table_thaw(struct hash_table *table);
/* Copy all nodes from one hash table to another */
-void hash_copy(struct hash_table *dest, struct hash_table *src);
+void hash_table_copy(struct hash_table *dest, struct hash_table *src);
/* hash function for strings */
unsigned int str_hash(const void *p) ATTR_PURE;
return;
}
- client = hash_lookup(master_requests, POINTER_CAST(reply->tag));
+ client = hash_table_lookup(master_requests, POINTER_CAST(reply->tag));
if (client == NULL)
i_fatal("Master sent reply with unknown tag %u", reply->tag);
- hash_remove(master_requests, POINTER_CAST(reply->tag));
+ hash_table_remove(master_requests, POINTER_CAST(reply->tag));
if (client != &destroyed_client) {
client_call_master_callback(client, reply);
/* NOTE: client may be destroyed now */
client->master_tag = req->tag;
client->master_callback = callback;
- hash_insert(master_requests, POINTER_CAST(req->tag), client);
+ hash_table_insert(master_requests, POINTER_CAST(req->tag), client);
}
void master_request_abort(struct client *client)
/* we're still going to get the reply from the master, so just
remember that we want to ignore it */
- hash_update(master_requests, POINTER_CAST(client->master_tag),
- &destroyed_client);
+ hash_table_update(master_requests, POINTER_CAST(client->master_tag),
+ &destroyed_client);
memset(&reply, 0, sizeof(reply));
reply.status = MASTER_LOGIN_STATUS_INTERNAL_ERROR;
main_ref();
master_fd = fd;
- master_requests = hash_create(system_pool, system_pool,
- 0, NULL, NULL);
+ master_requests = hash_table_create(system_pool, system_pool,
+ 0, NULL, NULL);
master_pos = 0;
io_master = io_add(master_fd, IO_READ, master_input, NULL);
void master_deinit(void)
{
- hash_destroy(&master_requests);
+ hash_table_destroy(&master_requests);
if (io_master != NULL)
io_remove(&io_master);
if (--proxy->refcount > 0)
return TRUE;
- hash_remove(ssl_proxies, proxy);
+ hash_table_remove(ssl_proxies, proxy);
gnutls_deinit(proxy->session);
proxy->fd_plain = sfd[0];
proxy->ip = *ip;
- hash_insert(ssl_proxies, proxy, proxy);
+ hash_table_insert(ssl_proxies, proxy, proxy);
proxy->refcount++;
ssl_handshake(proxy);
gnutls_certificate_set_dh_params(x509_cred, dh_params);
gnutls_certificate_set_rsa_export_params(x509_cred, rsa_params);
- ssl_proxies = hash_create(system_pool, system_pool, 0, NULL, NULL);
+ ssl_proxies = hash_table_create(system_pool, system_pool, 0,
+ NULL, NULL);
ssl_initialized = TRUE;
}
if (!ssl_initialized)
return;
- iter = hash_iterate_init(ssl_proxies);
- while (hash_iterate(iter, &key, &value))
+ iter = hash_table_iterate_init(ssl_proxies);
+ while (hash_table_iterate(iter, &key, &value))
ssl_proxy_destroy(value);
- hash_iterate_deinit(iter);
- hash_destroy(ssl_proxies);
+ hash_table_iterate_deinit(iter);
+ hash_table_destroy(ssl_proxies);
gnutls_certificate_free_credentials(x509_cred);
gnutls_global_deinit();
}
auth_process_destroy(process);
} else {
- hash_insert(process->requests, POINTER_CAST(auth_tag), request);
+ hash_table_insert(process->requests,
+ POINTER_CAST(auth_tag), request);
}
}
}
id = (unsigned int)strtoul(list[0], NULL, 10);
- request = hash_lookup(process->requests, POINTER_CAST(id));
+ request = hash_table_lookup(process->requests, POINTER_CAST(id));
if (request == NULL) {
i_error("BUG: Auth process %s sent unrequested reply with ID "
"%u", dec2str(process->pid), id);
}
auth_master_callback(list[1], list + 2, request);
- hash_remove(process->requests, POINTER_CAST(id));
+ hash_table_remove(process->requests, POINTER_CAST(id));
return TRUE;
}
id = (unsigned int)strtoul(args, NULL, 10);
- request = hash_lookup(process->requests, POINTER_CAST(id));
+ request = hash_table_lookup(process->requests, POINTER_CAST(id));
if (request == NULL) {
i_error("BUG: Auth process %s sent unrequested reply with ID "
"%u", dec2str(process->pid), id);
}
auth_master_callback(NULL, NULL, request);
- hash_remove(process->requests, POINTER_CAST(id));
+ hash_table_remove(process->requests, POINTER_CAST(id));
return TRUE;
}
id = (unsigned int)strtoul(args, NULL, 10);
- request = hash_lookup(process->requests, POINTER_CAST(id));
+ request = hash_table_lookup(process->requests, POINTER_CAST(id));
if (request == NULL) {
i_error("BUG: Auth process %s sent unrequested reply with ID "
"%u", dec2str(process->pid), id);
}
auth_master_callback(NULL, NULL, request);
- hash_remove(process->requests, POINTER_CAST(id));
+ hash_table_remove(process->requests, POINTER_CAST(id));
return TRUE;
}
p->io = io_add(fd, IO_READ, auth_process_input, p);
p->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE);
p->output = o_stream_create_fd(fd, MAX_OUTBUF_SIZE, FALSE);
- p->requests = hash_create(default_pool, default_pool, 0, NULL, NULL);
+ p->requests = hash_table_create(default_pool, default_pool, 0,
+ NULL, NULL);
group->process_count++;
if (close(p->worker_listen_fd) < 0)
i_error("close(worker_listen) failed: %m");
- iter = hash_iterate_init(p->requests);
- while (hash_iterate(iter, &key, &value))
+ iter = hash_table_iterate_init(p->requests);
+ while (hash_table_iterate(iter, &key, &value))
auth_master_callback(NULL, NULL, value);
- hash_iterate_deinit(&iter);
- hash_destroy(&p->requests);
+ hash_table_iterate_deinit(&iter);
+ hash_table_destroy(&p->requests);
i_stream_destroy(&p->input);
o_stream_destroy(&p->output);
struct child_process *child_process_lookup(pid_t pid)
{
- return hash_lookup(processes, POINTER_CAST(pid));
+ return hash_table_lookup(processes, POINTER_CAST(pid));
}
void child_process_add(pid_t pid, struct child_process *process)
{
- hash_insert(processes, POINTER_CAST(pid), process);
+ hash_table_insert(processes, POINTER_CAST(pid), process);
}
void child_process_remove(pid_t pid)
{
- hash_remove(processes, POINTER_CAST(pid));
+ hash_table_remove(processes, POINTER_CAST(pid));
}
void child_process_init_env(void)
void child_processes_init(void)
{
- processes = hash_create(default_pool, default_pool, 128, NULL, NULL);
+ processes = hash_table_create(default_pool, default_pool, 128, NULL, NULL);
lib_signals_set_handler(SIGCHLD, TRUE, sigchld_handler, NULL);
}
/* make sure we log if child processes died unexpectedly */
sigchld_handler(SIGCHLD, NULL);
lib_signals_unset_handler(SIGCHLD, sigchld_handler, NULL);
- hash_destroy(&processes);
+ hash_table_destroy(&processes);
}
struct hash_iterate_context *iter;
void *key, *value;
- iter = hash_iterate_init(processes);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(processes);
+ while (hash_table_iterate(iter, &key, &value)) {
struct login_process *p = value;
if (p->process.type == PROCESS_TYPE_LOGIN)
login_process_destroy(p);
}
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
while (login_groups != NULL) {
struct login_group *group = login_groups;
memset(&reply, 0, sizeof(reply));
- iter = hash_iterate_init(processes);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(processes);
+ while (hash_table_iterate(iter, &key, &value)) {
struct login_process *p = value;
if (p->process.type == PROCESS_TYPE_LOGIN && p->group == group)
(void)o_stream_send(p->output, &reply, sizeof(reply));
}
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
}
static int login_group_start_missings(struct login_group *group)
lookup_group.user = t_strdup_noconst(user);
lookup_group.remote_ip = *ip;
- return hash_lookup(mail_process_groups, &lookup_group);
+ return hash_table_lookup(mail_process_groups, &lookup_group);
}
static struct mail_process_group *
group->remote_ip = *ip;
i_array_init(&group->processes, 10);
- hash_insert(mail_process_groups, group, group);
+ hash_table_insert(mail_process_groups, group, group);
return group;
}
if (count == 1) {
/* last process in this group */
i_assert(pids[0] == pid);
- hash_remove(mail_process_groups, group);
+ hash_table_remove(mail_process_groups, group);
mail_process_group_free(group);
} else {
for (i = 0; i < count; i++) {
void mail_processes_init(void)
{
- mail_process_groups = hash_create(default_pool, default_pool, 0,
- mail_process_group_hash,
- mail_process_group_cmp);
+ mail_process_groups = hash_table_create(default_pool, default_pool, 0,
+ mail_process_group_hash,
+ mail_process_group_cmp);
child_process_set_destroy_callback(PROCESS_TYPE_IMAP,
mail_process_destroyed);
struct hash_iterate_context *iter;
void *key, *value;
- iter = hash_iterate_init(mail_process_groups);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(mail_process_groups);
+ while (hash_table_iterate(iter, &key, &value)) {
struct mail_process_group *group = value;
mail_process_group_free(group);
}
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
- hash_destroy(&mail_process_groups);
+ hash_table_destroy(&mail_process_groups);
}
cache->validity_rec_size = validity_rec_size;
cache->right_names_pool =
pool_alloconly_create("ACL right names", 1024);
- cache->objects = hash_create(default_pool, default_pool, 0,
- str_hash, (hash_cmp_callback_t *)strcmp);
+ cache->objects = hash_table_create(default_pool, default_pool, 0,
+ str_hash, (hash_cmp_callback_t *)strcmp);
cache->right_name_idx_map =
- hash_create(default_pool, cache->right_names_pool, 0,
- str_hash, (hash_cmp_callback_t *)strcmp);
+ hash_table_create(default_pool, cache->right_names_pool, 0,
+ str_hash, (hash_cmp_callback_t *)strcmp);
i_array_init(&cache->right_idx_name_map, DEFAULT_ACL_RIGHTS_COUNT);
return cache;
}
acl_cache_flush_all(cache);
array_free(&cache->right_idx_name_map);
- hash_destroy(&cache->right_name_idx_map);
- hash_destroy(&cache->objects);
+ hash_table_destroy(&cache->right_name_idx_map);
+ hash_table_destroy(&cache->objects);
pool_unref(&cache->right_names_pool);
i_free(cache);
}
/* use +1 for right_name_idx_map values because we can't add NULL
values. */
- idx_p = hash_lookup(cache->right_name_idx_map, right);
+ idx_p = hash_table_lookup(cache->right_name_idx_map, right);
if (idx_p == NULL) {
/* new right name, add it */
const_name = name = p_strdup(cache->right_names_pool, right);
idx = array_count(&cache->right_idx_name_map);
array_append(&cache->right_idx_name_map, &const_name, 1);
- hash_insert(cache->right_name_idx_map, name,
- POINTER_CAST(idx + 1));
+ hash_table_insert(cache->right_name_idx_map, name,
+ POINTER_CAST(idx + 1));
} else {
idx = POINTER_CAST_TO(idx_p, unsigned int)-1;
}
{
struct acl_object_cache *obj_cache;
- obj_cache = hash_lookup(cache->objects, objname);
+ obj_cache = hash_table_lookup(cache->objects, objname);
if (obj_cache != NULL) {
- hash_remove(cache->objects, objname);
+ hash_table_remove(cache->objects, objname);
acl_cache_free_object_cache(obj_cache);
}
}
struct hash_iterate_context *iter;
void *key, *value;
- iter = hash_iterate_init(cache->objects);
- while (hash_iterate(iter, &key, &value)) {
+ iter = hash_table_iterate_init(cache->objects);
+ while (hash_table_iterate(iter, &key, &value)) {
struct acl_object_cache *obj_cache = value;
acl_cache_free_object_cache(obj_cache);
}
- hash_iterate_deinit(&iter);
+ hash_table_iterate_deinit(&iter);
- hash_clear(cache->objects, FALSE);
+ hash_table_clear(cache->objects, FALSE);
}
static void
{
struct acl_object_cache *obj_cache;
- obj_cache = hash_lookup(cache->objects, objname);
+ obj_cache = hash_table_lookup(cache->objects, objname);
if (obj_cache == NULL) {
obj_cache = i_malloc(sizeof(struct acl_object_cache) +
cache->validity_rec_size);
obj_cache->name = i_strdup(objname);
- hash_insert(cache->objects, obj_cache->name, obj_cache);
+ hash_table_insert(cache->objects, obj_cache->name, obj_cache);
*created_r = TRUE;
} else {
*created_r = FALSE;
{
struct acl_object_cache *obj_cache;
- obj_cache = hash_lookup(cache->objects, objname);
+ obj_cache = hash_table_lookup(cache->objects, objname);
return obj_cache == NULL ? NULL : (obj_cache + 1);
}
{
struct acl_object_cache *obj_cache;
- obj_cache = hash_lookup(cache->objects, objname);
+ obj_cache = hash_table_lookup(cache->objects, objname);
if (obj_cache == NULL ||
obj_cache->my_current_rights == &negative_cache_entry)
return NULL;