From: Pekka Riikonen Date: Wed, 26 Jul 2000 07:03:20 +0000 (+0000) Subject: Use ID check as well in silc_idcache_add. X-Git-Tag: SILC.0.1~419 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=a9e43b9844ef7ff026174e917f9553ca3692081c;p=silc.git Use ID check as well in silc_idcache_add. --- diff --git a/lib/silccore/idcache.c b/lib/silccore/idcache.c index a7013e4b..8955fff9 100644 --- a/lib/silccore/idcache.c +++ b/lib/silccore/idcache.c @@ -20,6 +20,9 @@ /* * $Id$ * $Log$ + * Revision 1.6 2000/07/26 07:03:20 priikone + * Use ID check as well in silc_idcache_add. + * * Revision 1.5 2000/07/18 06:51:48 priikone * Use length of data found from cache instead of length of searched * data in comparison. @@ -307,8 +310,8 @@ int silc_idcache_find_by_data_loose(SilcIDCache cache, char *data, return TRUE; } -/* Find ID Cache entry by ID. Returns list of cache entries. */ -/* XXX this may be useless, need for list really? */ +/* Find ID Cache entry by ID. Returns list of cache entries. If `id' is + SILC_ID_CACHE_ANY this returns all ID's of type `type'. */ int silc_idcache_find_by_id(SilcIDCache cache, void *id, SilcIdType type, SilcIDCacheList *ret) @@ -323,9 +326,15 @@ int silc_idcache_find_by_id(SilcIDCache cache, void *id, SilcIdType type, list = silc_idcache_list_alloc(); - for (i = 0; i < cache->cache_count; i++) - if (cache->cache[i].id && !memcmp(cache->cache[i].id, id, id_len)) - silc_idcache_list_add(list, &(cache->cache[i])); + if (id != SILC_ID_CACHE_ANY) { + for (i = 0; i < cache->cache_count; i++) + if (cache->cache[i].id && !memcmp(cache->cache[i].id, id, id_len)) + silc_idcache_list_add(list, &(cache->cache[i])); + } else { + for (i = 0; i < cache->cache_count; i++) + if (cache->cache[i].id && cache->cache[i].type == type) + silc_idcache_list_add(list, &(cache->cache[i])); + } if (!silc_idcache_list_count(list)) return FALSE; @@ -412,7 +421,7 @@ int silc_idcache_add(SilcIDCache cache, char *data, SilcIdType id_type, return FALSE; for (i = 0; i < count; i++) { - if (c[i].data == NULL) { + if (c[i].data == NULL && c[i].id == NULL) { c[i].data = data; c[i].type = id_type; c[i].id = id; diff --git a/lib/silccore/idcache.h b/lib/silccore/idcache.h index 87030db0..582019ce 100644 --- a/lib/silccore/idcache.h +++ b/lib/silccore/idcache.h @@ -68,6 +68,8 @@ typedef struct SilcIDCacheStruct *SilcIDCache; /* Forward declaration for ID Cache List */ typedef struct SilcIDCacheListStruct *SilcIDCacheList; +#define SILC_ID_CACHE_ANY ((void *)1) + #define SILC_ID_CACHE_EXPIRE 3600 /* Prototypes */