silc_idcache_update now saves ID pointer if it wasn't present in
[silc.git] / lib / silcapputil / silcidcache.c
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;