silc_idcache_update now saves ID pointer if it wasn't present in
authorPekka Riikonen <priikone@silcnet.org>
Tue, 24 Apr 2007 17:31:23 +0000 (17:31 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 24 Apr 2007 17:31:23 +0000 (17:31 +0000)
the entry.

lib/silcapputil/silcidcache.c
lib/silcapputil/silcidcache.h

index 7340414a3d22c10687255ba41d047d5245118b46..00237fb829564a71f212e5aa3c318a4af595375c 100644 (file)
@@ -244,15 +244,19 @@ SilcBool silc_idcache_update(SilcIDCache cache, SilcIDCacheEntry entry,
     return FALSE;
 
   if (new_id) {
-    if (!silc_hash_table_del_by_context(cache->id_table, entry->id, entry))
-      return FALSE;
+    if (entry->id) {
+      if (!silc_hash_table_del_by_context(cache->id_table, entry->id, entry))
+       return FALSE;
 
-    if (cache->id_type == SILC_ID_CLIENT)
-      *(SilcClientID *)entry->id = *(SilcClientID *)new_id;
-    if (cache->id_type == SILC_ID_SERVER)
-      *(SilcServerID *)entry->id = *(SilcServerID *)new_id;
-    if (cache->id_type == SILC_ID_CHANNEL)
-      *(SilcChannelID *)entry->id = *(SilcChannelID *)new_id;
+      if (cache->id_type == SILC_ID_CLIENT)
+       *(SilcClientID *)entry->id = *(SilcClientID *)new_id;
+      if (cache->id_type == SILC_ID_SERVER)
+       *(SilcServerID *)entry->id = *(SilcServerID *)new_id;
+      if (cache->id_type == SILC_ID_CHANNEL)
+       *(SilcChannelID *)entry->id = *(SilcChannelID *)new_id;
+    } else {
+      entry->id = new_id;
+    }
 
     if (!silc_hash_table_add(cache->id_table, entry->id, entry))
       return FALSE;
index 05a009ded6fd8635cf34f803b265ab8bc0da32ba..8d4278abb28fb9b07279b2f51a390b21a4401ff8 100644 (file)
@@ -208,7 +208,8 @@ SilcBool silc_idcache_del_by_context(SilcIDCache cache, void *context,
  * DESCRIPTION
  *
  *    Updates cache `entry' with new values.  If the `new_id' is non-NULL
- *    then the new value will be copied over the old value in the `entry'.
+ *    then the new value will be copied over the old value in the `entry'
+ *    unless the ID doesn't exist, when the `new_id' will be stored in `entry'.
  *    If the `new_name' is non-NULL then the `entry' will be updated with
  *    `new_name'.  The caller is responsible of freeing the old name if it
  *    was updated with new one.  The old ID value does not need to be freed