updates.
[silc.git] / lib / silcclient / client_channel.c
index 0ac903df235e6727a05140d795d23ac881e36cf0..1a4a6d5968a7dc86acd239d228369e0ce975f571 100644 (file)
@@ -177,6 +177,16 @@ static void silc_client_channel_message_cb(SilcClient client,
     if (!channel)
       goto out;
 
+    /* If this client is not on channel, add it there since it clearly
+       is there. */
+    if (!silc_client_on_channel(channel, clients[0])) {
+      SilcChannelUser chu = silc_calloc(1, sizeof(*chu));
+      chu->client = clients[0];
+      chu->channel = channel;
+      silc_hash_table_add(channel->user_list, clients[0], chu);
+      silc_hash_table_add(clients[0]->channels, channel, chu);
+    }
+
     message = silc_channel_message_get_data(res->payload, NULL);
     
     /* Pass the message to application */
@@ -386,8 +396,7 @@ void silc_client_save_channel_key(SilcClient client,
   key = silc_channel_key_get_key(payload, &tmp_len);
   cipher = silc_channel_key_get_cipher(payload, NULL);
   channel->key_len = tmp_len * 8;
-  channel->key = silc_calloc(tmp_len, sizeof(*channel->key));
-  memcpy(channel->key, key, tmp_len);
+  channel->key = silc_memdup(key, tmp_len);
 
   if (!silc_cipher_alloc(cipher, &channel->channel_key)) {
     client->internal->ops->say(
@@ -510,8 +519,7 @@ int silc_client_add_channel_private_key(SilcClient client,
 
   /* Save the key */
   entry = silc_calloc(1, sizeof(*entry));
-  entry->key = silc_calloc(keymat->enc_key_len / 8, sizeof(*entry->key));
-  memcpy(entry->key, keymat->send_enc_key, keymat->enc_key_len / 8);
+  entry->key = silc_memdup(keymat->send_enc_key, keymat->enc_key_len / 8);
   entry->key_len = keymat->enc_key_len / 8;
 
   /* Allocate the cipher and set the key*/