updates.
[silc.git] / lib / silcclient / command_reply.c
index ae68cb7981a036af02cb77c03a359749b4e8a284..79acee69291f3865e8a859debadc8201eab32c59 100644 (file)
@@ -257,43 +257,13 @@ silc_client_command_reply_whois_save(SilcClientCommandReplyContext cmd,
                                       silc_hash_client_id_compare, NULL,
                                       &id_cache)) {
     SILC_LOG_DEBUG(("Adding new client entry"));
-
-    client_entry = silc_calloc(1, sizeof(*client_entry));
-    client_entry->id = client_id;
-    silc_parse_nickname(nickname, &client_entry->nickname, 
-                       &client_entry->server, &client_entry->num);
-    client_entry->username = strdup(username);
-    if (realname)
-      client_entry->realname = strdup(realname);
-    client_entry->mode = mode;
-    
-    /* Add client to cache */
-    silc_idcache_add(conn->client_cache, client_entry->nickname,
-                    client_id, (void *)client_entry, FALSE);
+    client_entry = 
+      silc_client_add_client(cmd->client, conn, nickname, username, realname,
+                            client_id, mode);
   } else {
     client_entry = (SilcClientEntry)id_cache->context;
-    if (client_entry->nickname)
-      silc_free(client_entry->nickname);
-    if (client_entry->server)
-      silc_free(client_entry->server);
-    if (client_entry->username)
-      silc_free(client_entry->username);
-    if (client_entry->realname)
-      silc_free(client_entry->realname);
-    client_entry->mode = mode;
-
-    SILC_LOG_DEBUG(("Updating client entry"));
-
-    silc_parse_nickname(nickname, &client_entry->nickname, 
-                       &client_entry->server, &client_entry->num);
-    client_entry->username = strdup(username);
-    if (realname)
-      client_entry->realname = strdup(realname);
-
-    /* Remove the old cache entry and create a new one */
-    silc_idcache_del_by_context(conn->client_cache, client_entry);
-    silc_idcache_add(conn->client_cache, client_entry->nickname, 
-                    client_entry->id, client_entry, FALSE);
+    silc_client_update_client(cmd->client, conn, client_entry, 
+                             nickname, username, realname, mode);
     silc_free(client_id);
   }
 
@@ -477,38 +447,13 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd,
                                         silc_hash_client_id_compare, NULL,
                                         &id_cache)) {
       SILC_LOG_DEBUG(("Adding new client entry"));
-      
-      client_entry = silc_calloc(1, sizeof(*client_entry));
-      client_entry->id = silc_id_dup(client_id, id_type);
-      silc_parse_nickname(name, &client_entry->nickname, 
-                         &client_entry->server, &client_entry->num);
-      if (info)
-       client_entry->username = strdup(info);
-      
-      /* Add client to cache */
-      silc_idcache_add(conn->client_cache, client_entry->nickname,
-                      client_entry->id, (void *)client_entry, FALSE);
+      client_entry = 
+       silc_client_add_client(cmd->client, conn, name, info, NULL,
+                              silc_id_dup(client_id, id_type), 0);
     } else {
       client_entry = (SilcClientEntry)id_cache->context;
-      if (client_entry->nickname)
-       silc_free(client_entry->nickname);
-      if (client_entry->server)
-       silc_free(client_entry->server);
-      if (info && client_entry->username)
-       silc_free(client_entry->username);
-      
-      SILC_LOG_DEBUG(("Updating client entry"));
-      
-      silc_parse_nickname(name, &client_entry->nickname, 
-                         &client_entry->server, &client_entry->num);
-      
-      if (info)
-       client_entry->username = strdup(info);
-      
-      /* Remove the old cache entry and create a new one */
-      silc_idcache_del_by_context(conn->client_cache, client_entry);
-      silc_idcache_add(conn->client_cache, client_entry->nickname, 
-                      client_entry->id, client_entry, FALSE);
+      silc_client_update_client(cmd->client, conn, client_entry, 
+                               name, info, NULL, 0);
     }
 
     /* Notify application */
@@ -527,7 +472,8 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd,
       
       server_entry = silc_calloc(1, sizeof(*server_entry));
       server_entry->server_id = silc_id_dup(server_id, id_type);
-      server_entry->server_name = strdup(name);
+      if (name)
+       server_entry->server_name = strdup(name);
       if (info)
        server_entry->server_info = strdup(info);
       
@@ -550,9 +496,12 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd,
     /* Check if we have this channel cached already. */
     if (!silc_idcache_find_by_id_one(conn->channel_cache, 
                                     (void *)channel_id, &id_cache)) {
+      if (!name)
+       break;
+
       SILC_LOG_DEBUG(("Adding new channel entry"));
       channel_entry = silc_client_new_channel_id(client, conn->sock, 
-                                                name, 0, idp);
+                                                strdup(name), 0, idp);
     } else {
       channel_entry = (SilcChannelEntry)id_cache->context;
     }
@@ -1138,10 +1087,9 @@ SILC_CLIENT_CMD_REPLY_FUNC(join)
                                         silc_hash_client_id_compare, NULL,
                                         &id_cache)) {
       /* No, we don't have it, add entry for it. */
-      client_entry = silc_calloc(1, sizeof(*client_entry));
-      client_entry->id = silc_id_dup(client_id, SILC_ID_CLIENT);
-      silc_idcache_add(conn->client_cache, NULL, client_entry->id, 
-                      (void *)client_entry, FALSE);
+      client_entry = 
+       silc_client_add_client(cmd->client, conn, NULL, NULL, NULL,
+                              silc_id_dup(client_id, SILC_ID_CLIENT), 0);
     } else {
       /* Yes, we have it already */
       client_entry = (SilcClientEntry)id_cache->context;
@@ -1935,21 +1883,19 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey)
 
   /* Get the public key payload */
   tmp = silc_argument_get_arg_type(cmd->args, 3, &len);
-  if (!tmp)
-    goto out;
-
-  /* Decode the public key */
-
-  SILC_GET16_MSB(pk_len, tmp);
-  SILC_GET16_MSB(type, tmp + 2);
-  pk = tmp + 4;
-
-  if (type != SILC_SKE_PK_TYPE_SILC)
-    goto out;
-
-  if (!silc_pkcs_public_key_decode(pk, pk_len, &public_key))
-    goto out;
-
+  if (tmp) {
+    /* Decode the public key */
+    SILC_GET16_MSB(pk_len, tmp);
+    SILC_GET16_MSB(type, tmp + 2);
+    pk = tmp + 4;
+    
+    if (type != SILC_SKE_PK_TYPE_SILC)
+      goto out;
+    
+    if (!silc_pkcs_public_key_decode(pk, pk_len, &public_key))
+      goto out;
+  } 
+   
   id_type = silc_id_payload_get_type(idp);
   if (id_type == SILC_ID_CLIENT) {
     /* Received client's public key */