updates.
[silc.git] / lib / silcclient / client_channel.c
index 8d3431ca0c4adbc490307146bddd011705413868..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 */
@@ -241,9 +251,7 @@ void silc_client_channel_message(SilcClient client,
        we will use the old key in decryption. If that fails too then we
        cannot do more and will drop the packet. */
     if (!payload) {
-      SILC_LOG_ERROR(("decr failed"));
       if (!channel->old_channel_key) {
-      SILC_LOG_ERROR(("no old key"));
        goto out;
       }
 
@@ -251,7 +259,6 @@ void silc_client_channel_message(SilcClient client,
                                                   channel->old_channel_key,
                                                   channel->old_hmac);
       if (!payload) {
-      SILC_LOG_ERROR(("old decr failed"));
        goto out;
       }
     }
@@ -389,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(
@@ -513,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*/