updates.
[silc.git] / lib / silcclient / command_reply.c
index 01fe350cfd1a0a386b1ff6d12f676a96ed1171c2..a9d3ba704ceb4eabd1fb7e8d9dda66259fdcc487 100644 (file)
@@ -162,7 +162,7 @@ void silc_client_command_reply_process(SilcClient client,
   uint16 ident;
 
   /* Get command reply payload from packet */
-  payload = silc_command_payload_parse(buffer);
+  payload = silc_command_payload_parse(buffer->data, buffer->len);
   if (!payload) {
     /* Silently ignore bad reply packet */
     SILC_LOG_DEBUG(("Bad command reply packet"));
@@ -239,6 +239,8 @@ silc_client_command_reply_whois_save(SilcClientCommandReplyContext cmd,
   char *realname = NULL;
   uint32 idle = 0, mode = 0;
   SilcBuffer channels = NULL;
+  unsigned char *fingerprint;
+  uint32 fingerprint_len;
   
   argc = silc_argument_get_arg_num(cmd->args);
 
@@ -277,6 +279,8 @@ silc_client_command_reply_whois_save(SilcClientCommandReplyContext cmd,
   if (tmp)
     SILC_GET32_MSB(idle, tmp);
 
+  fingerprint = silc_argument_get_arg_type(cmd->args, 9, &fingerprint_len);
+
   /* Check if we have this client cached already. */
   if (!silc_idcache_find_by_id_one_ext(conn->client_cache, (void *)client_id, 
                                       NULL, NULL, 
@@ -293,13 +297,21 @@ silc_client_command_reply_whois_save(SilcClientCommandReplyContext cmd,
     silc_free(client_id);
   }
 
+  if (fingerprint && !client_entry->fingerprint) {
+    client_entry->fingerprint = 
+      silc_calloc(fingerprint_len, 
+                 sizeof(*client_entry->fingerprint));
+    memcpy(client_entry->fingerprint, fingerprint, fingerprint_len);
+    client_entry->fingerprint_len = fingerprint_len;
+  }
+
   if (client_entry->status & SILC_CLIENT_STATUS_RESOLVING)
     client_entry->status &= ~SILC_CLIENT_STATUS_RESOLVING;
 
   /* Notify application */
   if (!cmd->callback)
     COMMAND_REPLY((ARGS, client_entry, nickname, username, realname, 
-                  channels, mode, idle));
+                  channels, mode, idle, fingerprint));
 
   if (channels)
     silc_buffer_free(channels);
@@ -389,8 +401,8 @@ SILC_CLIENT_CMD_REPLY_FUNC(whowas)
   }
 
  out:
-  SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_WHOIS);
-  SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_WHOIS);
+  SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_WHOWAS);
+  SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_WHOWAS);
   silc_client_command_reply_free(cmd);
 }
 
@@ -421,7 +433,7 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd,
     COMMAND_REPLY_ERROR;
     return;
   }
-  idp = silc_id_payload_parse_data(id_data, len);
+  idp = silc_id_payload_parse(id_data, len);
   if (!idp) {
     COMMAND_REPLY_ERROR;
     return;
@@ -480,7 +492,8 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd,
       
       /* Add server to cache */
       silc_idcache_add(conn->server_cache, server_entry->server_name,
-                      server_entry->server_id, (void *)server_entry, FALSE);
+                      server_entry->server_id, (void *)server_entry, 
+                      0, NULL);
     } else {
       server_entry = (SilcServerEntry)id_cache->context;
     }
@@ -578,7 +591,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick)
 
   /* Take received Client ID */
   tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
-  idp = silc_id_payload_parse_data(tmp, len);
+  idp = silc_id_payload_parse(tmp, len);
   if (!idp) {
     COMMAND_REPLY_ERROR;
     goto out;
@@ -586,7 +599,11 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick)
   silc_client_receive_new_id(cmd->client, cmd->sock, idp);
     
   /* Notify application */
+  SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_NICK);
   COMMAND_REPLY((ARGS, conn->local_entry));
+  SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_NICK);
+  silc_client_command_reply_free(cmd);
+  return;
 
  out:
   SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_NICK);
@@ -821,7 +838,10 @@ SILC_CLIENT_CMD_REPLY_FUNC(info)
 
     /* Add it to the cache */
     silc_idcache_add(conn->server_cache, server->server_name,
-                    server->server_id, (void *)server, FALSE);
+                    server->server_id, (void *)server, 0, NULL);
+
+    if (SILC_ID_SERVER_COMPARE(server_id, conn->remote_id))
+      goto out;
   } else {
     server = (SilcServerEntry)id_cache->context;
   }
@@ -858,12 +878,14 @@ SILC_CLIENT_CMD_REPLY_FUNC(ping)
   curtime = time(NULL);
   id = silc_id_str2id(cmd->packet->src_id, cmd->packet->src_id_len,
                      cmd->packet->src_id_type);
-  if (!id) {
+  if (!id || !conn->ping) {
     COMMAND_REPLY_ERROR;
     goto out;
   }
 
   for (i = 0; i < conn->ping_count; i++) {
+    if (!conn->ping[i].dest_id)
+      continue;
     if (SILC_ID_SERVER_COMPARE(conn->ping[i].dest_id, id)) {
       diff = curtime - conn->ping[i].start_time;
       cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, 
@@ -911,8 +933,9 @@ SILC_CLIENT_CMD_REPLY_FUNC(join)
 
   SILC_GET16_MSB(status, silc_argument_get_arg_type(cmd->args, 1, NULL));
   if (status != SILC_STATUS_OK) {
-    cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
-            "%s", silc_client_command_status_message(status));
+    if (status != SILC_STATUS_ERR_USER_ON_CHANNEL)
+      cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+                           "%s", silc_client_command_status_message(status));
     COMMAND_REPLY_ERROR;
     goto out;
   }
@@ -944,7 +967,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join)
     silc_free(channel_name);
     goto out;
   }
-  idp = silc_id_payload_parse_data(tmp, len);
+  idp = silc_id_payload_parse(tmp, len);
   if (!idp) {
     COMMAND_REPLY_ERROR;
     silc_free(channel_name);
@@ -1823,7 +1846,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey)
     COMMAND_REPLY_ERROR;
     goto out;
   }
-  idp = silc_id_payload_parse_data(tmp, len);
+  idp = silc_id_payload_parse(tmp, len);
   if (!idp) {
     COMMAND_REPLY_ERROR;
     goto out;