- if (!silc_hash_table_find(cache->name_table, name, NULL, (void *)ret))
- return FALSE;
-
- return TRUE;
-}
-
-/* Allocates ID cache list. */
-
-static SilcIDCacheList silc_idcache_list_alloc()
-{
- SilcIDCacheList list;
-
- list = silc_calloc(1, sizeof(*list));
- if (!list)
- return FALSE;
-
- return list;
-}
-
-/* Adds cache entry to the ID cache list. If needed reallocates memory
- for the list. */
-
-static void silc_idcache_list_add(SilcIDCacheList list, SilcIDCacheEntry cache)
-{
- int i;
-
- /* Try to add to static cache */
- if (!list->cache_dyn_count)
- for (i = 0; i < (sizeof(list->cache) / sizeof(list->cache[0])); i++) {
- if (!list->cache[i]) {
- list->cache[i] = cache;
- list->cache_count++;
- return;
- }
- }
-
- /* Static cache is full, allocate dynamic cache */
- for (i = 0; i < list->cache_dyn_count; i++) {
- if (!list->cache_dyn[i]) {
- list->cache_dyn[i] = cache;
- list->cache_count++;
- break;
- }
- }
-
- if (i >= list->cache_dyn_count) {
- int k;
-
- i = list->cache_dyn_count;
- list->cache_dyn = silc_realloc(list->cache_dyn,
- sizeof(*list->cache_dyn) * (i + 5));
- if (!list->cache_dyn)
- return;
-
- /* NULL the reallocated area */
- for (k = i; k < (i + 5); k++)
- list->cache_dyn[k] = NULL;
-
- list->cache_dyn[i] = cache;
- list->cache_count++;
- list->cache_dyn_count += 5;
- }
-}
-
-/* Returns number of cache entries in the ID cache list. */
-
-int silc_idcache_list_count(SilcIDCacheList list)
-{
- return list->cache_count;
-}
-
-/* Returns first entry from the ID cache list. */
-
-bool silc_idcache_list_first(SilcIDCacheList list, SilcIDCacheEntry *ret)
-{
- list->pos = 0;
-
- if (!list->cache[list->pos])
- return FALSE;
-
- if (ret)
- *ret = list->cache[list->pos];
-
- return TRUE;
-}
-
-/* Returns next entry from the ID cache list. */
-
-bool silc_idcache_list_next(SilcIDCacheList list, SilcIDCacheEntry *ret)
-{
- list->pos++;
-
- if (!list->dyn &&
- list->pos >= (sizeof(list->cache) / sizeof(list->cache[0]))) {
- list->pos = 0;
- list->dyn = TRUE;
- }
-
- if (list->dyn && list->pos >= list->cache_dyn_count)
- return FALSE;
-
- if (!list->dyn && !list->cache[list->pos])
- return FALSE;
-
- if (list->dyn && !list->cache_dyn[list->pos])
- return FALSE;
-
- if (ret) {
- if (!list->dyn)
- *ret = list->cache[list->pos];
- else
- *ret = list->cache_dyn[list->pos];
- }
-
- return TRUE;
-}
-
-/* Frees ID cache list. User must free the list object returned by
- any of the searching functions. */
-
-void silc_idcache_list_free(SilcIDCacheList list)
-{
- if (list) {
- if (list->cache_dyn)
- silc_free(list->cache_dyn);
- silc_free(list);
- }