void mail_cache_register_fields(struct mail_cache *cache, struct mail_cache_field *fields, unsigned int fields_count) { char *name; void *value; unsigned int new_idx; unsigned int i, j, registered_count; new_idx = cache->fields_count; for (i = 0; i < fields_count; i++) { if (hash_table_lookup_full(cache->field_name_hash, fields[i].name, &name, &value)) { fields[i].idx = POINTER_CAST_TO(value, unsigned int); mail_cache_field_update(cache, &fields[i]); continue; } /* check if the same header is being registered in the same field array */ for (j = 0; j < i; j++) { if (strcasecmp(fields[i].name, fields[j].name) == 0) { fields[i].idx = fields[j].idx; break; } } if (j == i) fields[i].idx = new_idx++; }
bool mail_index_keyword_lookup(struct mail_index *index, const char *keyword, unsigned int *idx_r) { char *key; void *value; /* 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_table_lookup_full(index->keywords_hash, keyword, &key, &value)) { *idx_r = POINTER_CAST_TO(value, unsigned int); return TRUE; }
const char *str_table_ref(struct str_table *table, const char *str) { char *key; void *value; unsigned int ref; if (!hash_table_lookup_full(table->hash, str, &key, &value)) { key = i_strdup(str); ref = 1; } else { ref = POINTER_CAST_TO(value, unsigned int); i_assert(ref > 0); ref++; } hash_table_update(table->hash, key, POINTER_CAST(ref)); return key; }
void str_table_unref(struct str_table *table, const char **str) { char *key; void *value; unsigned int ref; if (!hash_table_lookup_full(table->hash, *str, &key, &value)) i_unreached(); ref = POINTER_CAST_TO(value, unsigned int); i_assert(ref > 0); if (--ref > 0) hash_table_update(table->hash, key, POINTER_CAST(ref)); else { hash_table_remove(table->hash, key); i_free(key); } *str = NULL; }