Merge commit 'origin/silc.1.1.branch'
[silc.git] / apps / silcd / command_reply.c
index d2d8ec3cb8cbba90e877a618d7ca5cf9323c84e6..0b1645ec4fba9332a1c8e0dea17eba370916680d 100644 (file)
@@ -150,13 +150,9 @@ silc_server_command_process_error(SilcServerCommandReplyContext cmd,
       if (!client)
        return;
 
-      if (client->data.public_key)
-       silc_hash_table_del_by_context(server->pk_hash,
-                                      client->data.public_key,
-                                      client);
-
       silc_server_remove_from_channels(server, NULL, client, TRUE,
                                       NULL, TRUE, FALSE);
+      silc_dlist_del(server->expired_clients, client);
       silc_idlist_del_data(client);
       silc_idlist_del_client(server->global_list, client);
     }
@@ -266,9 +262,10 @@ silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd)
       return FALSE;
     }
 
-    /* Remove the old cache entry  */
-    silc_idcache_del_by_context(global ? server->global_list->clients :
-                               server->local_list->clients, client, NULL);
+    /* Update entry */
+    silc_idcache_update_by_context(global ? server->global_list->clients :
+                                  server->local_list->clients, client, NULL,
+                                  nickname, TRUE);
 
     silc_free(client->nickname);
     silc_free(client->username);
@@ -282,11 +279,6 @@ silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd)
     client->mode = mode;
     client->data.status |= SILC_IDLIST_STATUS_RESOLVED;
     client->data.status &= ~SILC_IDLIST_STATUS_RESOLVING;
-
-    /* Create new cache entry */
-    silc_idcache_add(global ? server->global_list->clients :
-                    server->local_list->clients, nickname, client->id,
-                    client);
   }
 
   /* Save channel list if it was sent to us */
@@ -360,12 +352,12 @@ silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd)
 
            SILC_LOG_DEBUG(("Saved client public key from attributes"));
 
-           /* Add to public key hash table */
-           if (!silc_hash_table_find_by_context(server->pk_hash,
-                                                client->data.public_key,
-                                                client, NULL))
-             silc_hash_table_add(server->pk_hash,
-                                 client->data.public_key, client);
+           /* Add client's public key to repository */
+           if (!silc_server_get_public_key_by_client(server, client, NULL))
+             silc_skr_add_public_key_simple(server->repository,
+                                            client->data.public_key,
+                                            SILC_SKR_USAGE_IDENTIFICATION,
+                                            client, NULL);
 
            silc_free(pk.type);
            silc_free(pk.data);
@@ -524,7 +516,7 @@ silc_server_command_reply_whowas_save(SilcServerCommandReplyContext cmd)
     if (!nickname) {
       SILC_LOG_ERROR(("Malformed nickname '%s' received in WHOWAS reply "
                      "from %s",
-                     hostname ? hostname : "", nick));
+                     nick, hostname ? hostname : ""));
       return FALSE;
     }
 
@@ -542,13 +534,24 @@ silc_server_command_reply_whowas_save(SilcServerCommandReplyContext cmd)
     client->servername = servername[0] ? strdup(servername) : NULL;
     client->data.status |= SILC_IDLIST_STATUS_RESOLVED;
     client->data.status &= ~SILC_IDLIST_STATUS_RESOLVING;
+    client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
+
+    /* Update cache entry */
+    silc_idcache_update_by_context(global ? server->global_list->clients :
+                                  server->local_list->clients, client, NULL,
+                                  nickname, TRUE);
+  }
 
-    /* Remove the old cache entry and create a new one */
-    silc_idcache_del_by_context(global ? server->global_list->clients :
-                               server->local_list->clients, client, NULL);
-    silc_idcache_add(global ? server->global_list->clients :
-                    server->local_list->clients, nickname, client->id,
-                    client);
+  /* If client is global and is not on any channel then add that we'll
+     expire the entry after a while. */
+  if (global) {
+    client = silc_idlist_find_client_by_id(server->global_list, client->id,
+                                          FALSE, &cache);
+    if (client && !silc_hash_table_count(client->channels)) {
+      client->data.created = silc_time();
+      silc_dlist_del(server->expired_clients, client);
+      silc_dlist_add(server->expired_clients, client);
+    }
   }
 
   return TRUE;
@@ -675,17 +678,13 @@ silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd)
          return FALSE;
        }
 
-       /* Remove the old cache entry */
-       silc_idcache_del_by_context(global ? server->global_list->clients :
-                                   server->local_list->clients, client, NULL);
-
        silc_free(client->nickname);
        client->nickname = strdup(nick);
 
-       /* Add new cache entry */
-       silc_idcache_add(global ? server->global_list->clients :
-                        server->local_list->clients, name, client->id,
-                        client);
+       /* Update the context */
+       silc_idcache_update_by_context(global ? server->global_list->clients :
+                                      server->local_list->clients, client,
+                                      NULL, name, TRUE);
       }
 
       if (info) {
@@ -1199,7 +1198,8 @@ SILC_SERVER_CMD_REPLY_FUNC(join)
     silc_hmac_free(hmac);
   silc_server_command_reply_free(cmd);
 
-  silc_pkcs_public_key_free(founder_key);
+  if (founder_key)
+    silc_pkcs_public_key_free(founder_key);
   if (client_id_list)
     silc_buffer_free(client_id_list);
   if (client_mode_list)
@@ -1383,10 +1383,12 @@ SILC_SERVER_CMD_REPLY_FUNC(getkey)
     }
 
     if (!client->data.public_key) {
-      if (!silc_hash_table_find_by_context(server->pk_hash, public_key,
-                                          client, NULL))
-       silc_hash_table_add(server->pk_hash, public_key, client);
-
+      /* Add client's public key to repository */
+      if (!silc_server_get_public_key_by_client(server, client, NULL))
+       silc_skr_add_public_key_simple(server->repository,
+                                      public_key,
+                                      SILC_SKR_USAGE_IDENTIFICATION,
+                                      client, NULL);
       client->data.public_key = public_key;
       public_key = NULL;
     }