Integer type name change.
[silc.git] / lib / silcclient / client_channel.c
index 814dea43b6c03b942ea56fab22ddac58bbaf09fd..c98a8823909d602fe8b666995b99e7e0f5e4e5ed 100644 (file)
@@ -22,7 +22,8 @@
    channel key receiving and setting, and channel private key handling 
    routines. */
 
-#include "clientlibincludes.h"
+#include "silcincludes.h"
+#include "silcclient.h"
 #include "client_internal.h"
 
 /* Sends packet to the `channel'. Packet to channel is always encrypted
@@ -38,7 +39,7 @@ void silc_client_send_channel_message(SilcClient client,
                                      SilcChannelPrivateKey key,
                                      SilcMessageFlags flags,
                                      unsigned char *data, 
-                                     uint32 data_len, 
+                                     SilcUInt32 data_len, 
                                      int force_send)
 {
   int i;
@@ -48,7 +49,7 @@ void silc_client_send_channel_message(SilcClient client,
   SilcCipher cipher;
   SilcHmac hmac;
   unsigned char *id_string;
-  uint32 iv_len;
+  SilcUInt32 iv_len;
   int block_len;
 
   SILC_LOG_DEBUG(("Sending packet to channel"));
@@ -164,7 +165,7 @@ typedef struct {
 static void silc_client_channel_message_cb(SilcClient client,
                                           SilcClientConnection conn,
                                           SilcClientEntry *clients,
-                                          uint32 clients_count,
+                                          SilcUInt32 clients_count,
                                           void *context)
 {
   SilcChannelClientResolve res = (SilcChannelClientResolve)context;
@@ -177,6 +178,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,14 +252,16 @@ 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) {
-      if (!channel->old_channel_key)
+      if (!channel->old_channel_key) {
        goto out;
+      }
 
       payload = silc_channel_message_payload_parse(buffer->data, buffer->len, 
                                                   channel->old_channel_key,
                                                   channel->old_hmac);
-      if (!payload)
+      if (!payload) {
        goto out;
+      }
     }
   } else if (channel->private_keys) {
     SilcChannelPrivateKey entry;
@@ -330,7 +343,7 @@ void silc_client_save_channel_key(SilcClient client,
                                  SilcChannelEntry channel)
 {
   unsigned char *id_string, *key, *cipher, *hmac, hash[32];
-  uint32 tmp_len;
+  SilcUInt32 tmp_len;
   SilcChannelID *id;
   SilcChannelKeyPayload payload;
 
@@ -384,8 +397,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(
@@ -462,7 +474,7 @@ int silc_client_add_channel_private_key(SilcClient client,
                                        char *cipher,
                                        char *hmac,
                                        unsigned char *key,
-                                       uint32 key_len)
+                                       SilcUInt32 key_len)
 {
   SilcChannelPrivateKey entry;
   unsigned char hash[32];
@@ -508,8 +520,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*/
@@ -618,10 +629,10 @@ SilcChannelPrivateKey *
 silc_client_list_channel_private_keys(SilcClient client,
                                      SilcClientConnection conn,
                                      SilcChannelEntry channel,
-                                     uint32 *key_count)
+                                     SilcUInt32 *key_count)
 {
   SilcChannelPrivateKey *keys = NULL, entry;
-  uint32 count = 0;
+  SilcUInt32 count = 0;
 
   if (!channel->private_keys)
     return NULL;
@@ -642,7 +653,7 @@ silc_client_list_channel_private_keys(SilcClient client,
 /* Frees the SilcChannelPrivateKey array. */
 
 void silc_client_free_channel_private_keys(SilcChannelPrivateKey *keys,
-                                          uint32 key_count)
+                                          SilcUInt32 key_count)
 {
   silc_free(keys);
 }