A LOT updates. Cannot separate. :)
[silc.git] / lib / silccore / idcache.c
index a7013e4b6c045ae6f3d6acabe73807ab6911988e..9dc176f3c84401806870adab7decc839a0427924 100644 (file)
   GNU General Public License for more details.
 
 */
-/*
- * $Id$
- * $Log$
- * 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.
- *
- * Revision 1.4  2000/07/17 11:46:36  priikone
- *     Added debug logging
- *
- * Revision 1.3  2000/07/12 05:54:01  priikone
- *     Major rewrite of whole ID Cache system.
- *
- * Revision 1.2  2000/07/05 06:06:35  priikone
- *     Global cosmetic change.
- *
- * Revision 1.1.1.1  2000/06/27 11:36:55  priikone
- *     Imported from internal CVS/Added Log headers.
- *
- *
- */
+/* $Id$ */
 
 #include "silcincludes.h"
 #include "idcache.h"
@@ -307,8 +287,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 +303,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 +398,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;