Merged from silc_1_0_branch.
[silc.git] / lib / silcclient / client_notify.c
index 50d5c562e6d1a35da4860ad7d6ce07fba7cfdcc3..f42ebaa6482bc21f6cd9d16e86df364b0d426847 100644 (file)
@@ -597,82 +597,51 @@ void silc_client_notify_by_server(SilcClient client,
     if (!client_id)
       goto out;
 
-    /* From protocol version 1.1 we get the new nickname in notify as well,
-       so we don't have to resolve it.  Do it the hard way if server doesn't
-       send it to us. */
+    /* Take the nickname */
     tmp = silc_argument_get_arg_type(args, 3, NULL);
-    if (tmp) {
-      /* Protocol version 1.1 */
-      char *tmp_nick = NULL;
-
-      /* Check whether nickname changed at all.  It is possible that nick
-        change notify is received but nickname didn't changed, only the
-        ID changes. */
-      if (client->internal->params->nickname_parse)
-       client->internal->params->nickname_parse(client_entry->nickname,
-                                                &tmp_nick);
-      else
-       tmp_nick = strdup(tmp);
-
-      if (tmp_nick && !strcmp(tmp, tmp_nick)) {
-       /* Nickname didn't change. Update only the ID */
-       silc_idcache_del_by_context(conn->internal->client_cache,
-                                   client_entry);
-       silc_free(client_entry->id);
-       client_entry->id = silc_id_dup(client_id, SILC_ID_CLIENT);
-       silc_idcache_add(conn->internal->client_cache, strdup(tmp),
-                        client_entry->id, client_entry, 0, NULL);
-
-       /* Notify application */
-       client->internal->ops->notify(client, conn, type, 
-                                     client_entry, client_entry);
-       break;
-      }
-      silc_free(tmp_nick);
-
-      /* Create new client entry, and save all old information with the
-        new nickname and client ID */
-      client_entry2 = silc_client_add_client(client, conn, NULL, NULL, 
-                                            client_entry->realname,
-                                            silc_id_dup(client_id, 
-                                                        SILC_ID_CLIENT), 0);
-      if (!client_entry2)
-       goto out;
-
-      if (client_entry->server)
-       client_entry2->server = strdup(client_entry->server);
-      if (client_entry->username)
-       client_entry2->username = strdup(client_entry->username);
-      if (client_entry->hostname)
-       client_entry2->hostname = strdup(client_entry->hostname);
-      silc_client_update_client(client, conn, client_entry2, tmp, NULL, NULL,
-                               client_entry->mode);
-    } else {
-      /* Protocol version 1.0 */
+    if (!tmp)
+      goto out;
 
-      /* Find client entry and if not found resolve it */
-      client_entry2 = silc_client_get_client_by_id(client, conn, client_id);
-      if (!client_entry2) {
-       /* Resolve the entry information */
-       silc_client_notify_by_server_resolve(client, conn, packet, 
-                                            SILC_ID_CLIENT, client_id);
+    /* Check whether nickname changed at all.  It is possible that nick
+       change notify is received but nickname didn't changed, only the
+       ID changes.  Check whether the hashes in the Client ID match, if
+       they do nickname didn't change. */
+    if (SILC_ID_COMPARE_HASH(client_entry->id, client_id)) {
+      /* Nickname didn't change. Update only the ID */
+      silc_idcache_del_by_context(conn->internal->client_cache,
+                                 client_entry);
+      silc_free(client_entry->id);
+      client_entry->id = silc_id_dup(client_id, SILC_ID_CLIENT);
+      silc_idcache_add(conn->internal->client_cache, strdup(tmp),
+                      client_entry->id, client_entry, 0, NULL);
+
+      /* Notify application */
+      client->internal->ops->notify(client, conn, type, 
+                                   client_entry, client_entry);
+      break;
+    }
 
-       /* Add the new entry even though we resolved it. This is because we
-          want to replace the old entry with the new entry here right now. */
-       client_entry2 = 
-         silc_client_add_client(client, conn, NULL, NULL, NULL, 
-                                silc_id_dup(client_id, SILC_ID_CLIENT), 
-                                client_entry->mode);
-
-       /* Replace old ID entry with new one on all channels. */
-       silc_client_replace_from_channels(client, conn, client_entry,
-                                         client_entry2);
-       break;
-      }
+    /* Create new client entry, and save all old information with the
+       new nickname and client ID */
+    client_entry2 = silc_client_add_client(client, conn, NULL, NULL, 
+                                          client_entry->realname,
+                                          silc_id_dup(client_id, 
+                                                      SILC_ID_CLIENT), 0);
+    if (!client_entry2)
+      goto out;
 
-      if (client_entry2 != conn->local_entry)
-       silc_client_nickname_format(client, conn, client_entry2);
-    }
+    if (client_entry->server)
+      client_entry2->server = strdup(client_entry->server);
+    if (client_entry->username)
+      client_entry2->username = strdup(client_entry->username);
+    if (client_entry->hostname)
+      client_entry2->hostname = strdup(client_entry->hostname);
+    client_entry2->fingerprint = client_entry->fingerprint;
+    client_entry2->fingerprint_len = client_entry->fingerprint_len;
+    client_entry->fingerprint = NULL;
+    client_entry->fingerprint_len = NULL;
+    silc_client_update_client(client, conn, client_entry2, tmp, NULL, NULL,
+                             client_entry->mode);
 
     /* Remove the old from cache */
     silc_idcache_del_by_context(conn->internal->client_cache, client_entry);