Fixed silc_client_get_clients_local to parse nick@server string
[silc.git] / lib / silcclient / client_entry.c
index c59a48fd3e4992008c26ed4a53cea0323688f2b5..705e1cd1a74d088581be2f03b6d0ecfe8672eaff 100644 (file)
@@ -72,19 +72,22 @@ SilcDList silc_client_get_clients_local_ext(SilcClient client,
   SilcList list;
   SilcDList clients;
   SilcClientEntry entry;
-  char *nicknamec, *parsed = NULL, *format = NULL;
+  char nick[128 + 1], *nicknamec, *parsed = NULL, *format = NULL;
 
   if (!client || !conn || !nickname)
     return NULL;
 
+  /* Get nickname from nickname@server string */
+  silc_parse_userfqdn(nickname, nick, sizeof(nick), NULL, 0);
+
   /* Parse nickname in case it is formatted */
-  if (!silc_client_nickname_parse(client, conn, (char *)nickname, &parsed))
+  if (!silc_client_nickname_parse(client, conn, (char *)nick, &parsed))
     return NULL;
 
   if (!get_all && parsed)
-    format = (char *)nickname;
+    format = (char *)nick;
   if (!parsed) {
-    parsed = silc_memdup(nickname, strlen(nickname));
+    parsed = silc_memdup(nick, strlen(nick));
     if (!parsed)
       return NULL;
   }
@@ -340,7 +343,7 @@ static SilcUInt16 silc_client_get_clients_i(SilcClient client,
 
   /* Parse server name from the nickname if set */
   if (silc_parse_userfqdn(nickname, nick, sizeof(nick),
-                         serv, sizeof(serv) == 2))
+                         serv, sizeof(serv)) == 2)
     server = (const char *)serv;
   nickname = (const char *)nick;
 
@@ -1125,7 +1128,8 @@ SilcClientEntry silc_client_nickname_format(SilcClient client,
   }
 
   /* Is the requested client formatted already */
-  if (!silc_utf8_strcasecmp(client_entry->nickname, 
+  if (client_entry->nickname_normalized &&
+      !silc_utf8_strcasecmp(client_entry->nickname,
                            client_entry->nickname_normalized))
     formatted = TRUE;
 
@@ -1142,7 +1146,7 @@ SilcClientEntry silc_client_nickname_format(SilcClient client,
       unformatted = entry;
       break;
     }
-  }  
+  }
 
   /* If there are no other unformatted clients and the requested client is
      unformatted, just return it. */
@@ -1151,7 +1155,7 @@ SilcClientEntry silc_client_nickname_format(SilcClient client,
     return client_entry;
   }
 
-  /* If priority formatting then the requested client will get the 
+  /* If priority formatting then the requested client will get the
      unformatted nickname, and the unformatted client will get a new
      formatted nickname. */
   if (priority) {
@@ -1161,7 +1165,7 @@ SilcClientEntry silc_client_nickname_format(SilcClient client,
                                      &cp))
         return NULL;
 
-      silc_snprintf(client_entry->nickname, sizeof(client_entry->nickname), 
+      silc_snprintf(client_entry->nickname, sizeof(client_entry->nickname),
                    cp);
       silc_free(cp);
     }
@@ -1622,9 +1626,10 @@ SilcBool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
                                 SilcChannelEntry channel)
 {
   SilcIDCacheEntry id_cache;
-  SilcBool ret;
+  SilcBool ret = TRUE;
   SilcCipher key;
   SilcHmac hmac;
+  char *namec;
 
   if (!channel)
     return FALSE;
@@ -1636,10 +1641,12 @@ SilcBool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
 
   silc_mutex_lock(conn->internal->lock);
   if (silc_idcache_find_by_context(conn->internal->channel_cache, channel,
-                                  &id_cache))
-    silc_free(id_cache->name);
-  ret = silc_idcache_del_by_context(conn->internal->channel_cache,
-                                   channel, NULL);
+                                  &id_cache)) {
+    namec = id_cache->name;
+    ret = silc_idcache_del_by_context(conn->internal->channel_cache,
+                                     channel, NULL);
+    silc_free(namec);
+  }
   silc_mutex_unlock(conn->internal->lock);
 
   if (!ret)
@@ -2029,7 +2036,8 @@ SilcBool silc_client_del_server(SilcClient client, SilcClientConnection conn,
                                SilcServerEntry server)
 {
   SilcIDCacheEntry id_cache;
-  SilcBool ret;
+  SilcBool ret = TRUE;
+  char *namec;
 
   if (!server)
     return FALSE;
@@ -2041,10 +2049,12 @@ SilcBool silc_client_del_server(SilcClient client, SilcClientConnection conn,
 
   silc_mutex_lock(conn->internal->lock);
   if (silc_idcache_find_by_context(conn->internal->server_cache, server,
-                                  &id_cache))
-    silc_free(id_cache->name);
-  ret = silc_idcache_del_by_context(conn->internal->server_cache,
-                                   server, NULL);
+                                  &id_cache)) {
+    namec = id_cache->name;
+    ret = silc_idcache_del_by_context(conn->internal->server_cache,
+                                     server, NULL);
+    silc_free(namec);
+  }
   silc_mutex_unlock(conn->internal->lock);
 
   silc_free(server->server_name);