updates.
[silc.git] / lib / silcclient / client_notify.c
index 24e8854eb3173e3381cc466faeb796dc735628f7..50aebb3ca84f19db80c87459f2450b7237abd492 100644 (file)
@@ -456,7 +456,7 @@ void silc_client_notify_by_server(SilcClient client,
       goto out;
 
     /* Ignore my ID */
-    if (SILC_ID_CLIENT_COMPARE(client_id, conn->local_id))
+    if (conn->local_id && SILC_ID_CLIENT_COMPARE(client_id, conn->local_id))
       break;
 
     /* Find old Client entry */
@@ -482,6 +482,31 @@ void silc_client_notify_by_server(SilcClient client,
     tmp = silc_argument_get_arg_type(args, 3, NULL);
     if (tmp) {
       /* Protocol version 1.1 */
+      char *tmp_nick;
+
+      /* 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 (!strcmp(tmp, tmp_nick)) {
+       /* Nickname didn't change. Update only the ID */
+       silc_idcache_del_by_context(conn->client_cache, client_entry);
+       silc_free(client_entry->id);
+       client_entry->id = silc_id_dup(client_id, SILC_ID_CLIENT);
+       silc_idcache_add(conn->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 */
@@ -898,25 +923,53 @@ void silc_client_notify_by_server(SilcClient client,
       tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
       if (tmp) {
        silc_free(client_id);
-       client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
-       if (!client_id)
+       id = silc_id_payload_parse_id(tmp, tmp_len, &id_type);
+       if (!id)
          goto out;
 
-       /* Find killer's client entry and if not found resolve it */
-       client_entry2 = silc_client_get_client_by_id(client, conn, client_id);
-       if (!client_entry2) {
-         silc_client_notify_by_server_resolve(client, conn, packet, 
-                                              SILC_ID_CLIENT, client_id);
-         goto out;
+       /* Find Client entry */
+       if (id_type == SILC_ID_CLIENT) {
+         /* Find Client entry */
+         client_id = id;
+         client_entry2 = silc_client_get_client_by_id(client, conn, 
+                                                      client_id);
+         if (!client_entry) {
+           silc_client_notify_by_server_resolve(client, conn, packet, 
+                                                SILC_ID_CLIENT, client_id);
+           goto out;
+         }
+       } else if (id_type == SILC_ID_SERVER) {
+         /* Find Server entry */
+         server_id = id;
+         server = silc_client_get_server_by_id(client, conn, server_id);
+         if (!server) {
+           silc_client_notify_by_server_resolve(client, conn, packet, 
+                                                SILC_ID_SERVER, server_id);
+           goto out;
+         }
+      
+         /* Save the pointer to the client_entry pointer */
+         client_entry2 = (SilcClientEntry)server;
        } else {
-         if (client_entry2 != conn->local_entry)
-           silc_client_nickname_format(client, conn, client_entry2);
+         /* Find Channel entry */
+         channel_id = id;
+         channel = silc_client_get_channel_by_id(client, conn, channel_id);
+         if (!channel) {
+           silc_client_notify_by_server_resolve(client, conn, packet, 
+                                                SILC_ID_CHANNEL, channel_id);
+           goto out;
+         }
+         
+         /* Save the pointer to the client_entry pointer */
+         client_entry2 = (SilcClientEntry)channel;
+         silc_free(channel_id);
+         channel_id = NULL;
        }
       }
 
       /* Notify application. */
       client->internal->ops->notify(client, conn, type, client_entry, 
-                                   comment, client_entry2);
+                                   comment, id_type, client_entry2);
 
       if (client_entry != conn->local_entry)
        /* Remove the client from all channels and free it */