Merged silc_1_1_branch to trunk.
[silc.git] / apps / silcd / command_reply.c
index d9ebf2933c8630c9f2e7dbf3c0943efeb4f20047..97aedf0e8e37455267c4818136418a9c24510b9f 100644 (file)
@@ -150,11 +150,6 @@ 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_idlist_del_data(client);
@@ -179,7 +174,8 @@ silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd)
   SilcUInt32 mode = 0, len, len2, id_len, flen;
   const char *hostname, *ip;
 
-  silc_socket_stream_get_info(cmd->sock, NULL, &hostname, &ip, NULL);
+  silc_socket_stream_get_info(silc_packet_stream_get_stream(cmd->sock),
+                             NULL, &hostname, &ip, NULL);
 
   id_data = silc_argument_get_arg_type(cmd->args, 2, &id_len);
   nickname = silc_argument_get_arg_type(cmd->args, 3, &len);
@@ -265,9 +261,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);
@@ -281,11 +278,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 */
@@ -359,12 +351,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);
@@ -458,7 +450,8 @@ silc_server_command_reply_whowas_save(SilcServerCommandReplyContext cmd)
   int global = FALSE;
   const char *hostname, *ip;
 
-  silc_socket_stream_get_info(cmd->sock, NULL, &hostname, &ip, NULL);
+  silc_socket_stream_get_info(silc_packet_stream_get_stream(cmd->sock),
+                             NULL, &hostname, &ip, NULL);
 
   id_data = silc_argument_get_arg_type(cmd->args, 2, &id_len);
   nickname = silc_argument_get_arg_type(cmd->args, 3, &len);
@@ -549,6 +542,15 @@ silc_server_command_reply_whowas_save(SilcServerCommandReplyContext cmd)
                     client);
   }
 
+  /* If client is global and is not on any channel then add that we'll
+     expire the entry after a while. */
+  if (global) {
+    silc_idlist_find_client_by_id(server->global_list, client->id,
+                                 FALSE, &cache);
+    if (!silc_hash_table_count(client->channels))
+      silc_dlist_add(server->expired_clients, client);
+  }
+
   return TRUE;
 }
 
@@ -1197,7 +1199,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)
@@ -1381,10 +1384,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;
     }