Added some asserts and error checks.
[silc.git] / lib / silcclient / client_channel.c
index 8d781039ae74b1ffe35d9691d3aa9e05eed60ffa..d4aac686b25dbfe4f0309d034e053fc5787fbd9d 100644 (file)
@@ -43,7 +43,7 @@ void silc_client_send_channel_message(SilcClient client,
                                      int force_send)
 {
   int i;
-  SilcSocketConnection sock = conn->sock;
+  SilcSocketConnection sock;
   SilcBuffer payload;
   SilcPacketContext packetdata;
   const SilcBufferStruct packet;
@@ -54,6 +54,8 @@ void silc_client_send_channel_message(SilcClient client,
   int block_len;
   SilcChannelUser chu;
 
+  assert(client && conn && channel);
+  sock = conn->sock;
   SILC_LOG_DEBUG(("Sending packet to channel"));
 
   chu = silc_client_on_channel(channel, conn->local_entry);
@@ -69,6 +71,8 @@ void silc_client_send_channel_message(SilcClient client,
       chu->mode & SILC_CHANNEL_UMODE_CHANOP &&
       !(chu->mode & SILC_CHANNEL_UMODE_CHANFO))
     return;
+  if (chu->mode & SILC_CHANNEL_UMODE_QUIET)
+    return;
 
   /* Take the key to be used */
   if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY) {
@@ -112,8 +116,7 @@ void silc_client_send_channel_message(SilcClient client,
     for (i = 0; i < iv_len; i++) channel->iv[i] = 
                                   silc_rng_get_byte(client->rng);
   else
-    silc_hash_make(client->internal->md5hash, channel->iv, iv_len, 
-                  channel->iv);
+    silc_hash_make(client->md5hash, channel->iv, iv_len, channel->iv);
 
   /* Encode the channel payload. This also encrypts the message payload. */
   payload = silc_channel_message_payload_encode(flags, data_len, data, iv_len, 
@@ -121,8 +124,8 @@ void silc_client_send_channel_message(SilcClient client,
                                                client->rng);
 
   /* Get data used in packet header encryption, keys and stuff. */
-  cipher = conn->send_key;
-  hmac = conn->hmac_send;
+  cipher = conn->internal->send_key;
+  hmac = conn->internal->hmac_send;
   id_string = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
 
   /* Set the packet context pointers. The destination ID is always
@@ -156,7 +159,7 @@ void silc_client_send_channel_message(SilcClient client,
 
   /* Encrypt the header and padding of the packet. This is encrypted 
      with normal session key shared with our server. */
-  silc_packet_encrypt(cipher, hmac, conn->psn_send++,
+  silc_packet_encrypt(cipher, hmac, conn->internal->psn_send++,
                      (SilcBuffer)&packet, SILC_PACKET_HEADER_LEN + 
                      packetdata.src_id_len + packetdata.dst_id_len +
                      packetdata.padlen);
@@ -300,12 +303,13 @@ void silc_client_channel_message(SilcClient client,
 
   /* Find client entry */
   client_entry = silc_client_get_client_by_id(client, conn, client_id);
-  if (!client_entry || !client_entry->nickname) {
+  if (!client_entry || !client_entry->nickname ||
+      !silc_client_on_channel(channel, client_entry)) {
     /* Resolve the client info */
     SilcChannelClientResolve res = silc_calloc(1, sizeof(*res));
     res->payload = payload;
     res->channel_id = id;
-    silc_client_get_client_by_id_resolve(client, conn, client_id,
+    silc_client_get_client_by_id_resolve(client, conn, client_id, NULL,
                                         silc_client_channel_message_cb,
                                         res);
     payload = NULL;
@@ -313,11 +317,6 @@ void silc_client_channel_message(SilcClient client,
     goto out;
   }
 
-  if (!silc_client_on_channel(channel, client_entry)) {
-    SILC_LOG_WARNING(("Received channel message from client not on channel"));
-    goto out;
-  }
-
   message = silc_channel_message_get_data(payload, &message_len);
 
   /* Pass the message to application */
@@ -498,6 +497,8 @@ int silc_client_add_channel_private_key(SilcClient client,
   unsigned char hash[32];
   SilcSKEKeyMaterial *keymat;
 
+  assert(client && channel);
+
   if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY))
     return FALSE;
 
@@ -515,7 +516,7 @@ int silc_client_add_channel_private_key(SilcClient client,
   /* Produce the key material */
   keymat = silc_calloc(1, sizeof(*keymat));
   if (silc_ske_process_key_material_data(key, key_len, 16, 256, 16, 
-                                        client->internal->md5hash, keymat) 
+                                        client->md5hash, keymat) 
       != SILC_SKE_STATUS_OK)
     return FALSE;
 
@@ -576,6 +577,8 @@ int silc_client_del_channel_private_keys(SilcClient client,
 {
   SilcChannelPrivateKey entry;
 
+  assert(client && channel);
+
   if (!channel->private_keys)
     return FALSE;
 
@@ -611,6 +614,8 @@ int silc_client_del_channel_private_key(SilcClient client,
 {
   SilcChannelPrivateKey entry;
 
+  assert(client && channel);
+
   if (!channel->private_keys)
     return FALSE;
 
@@ -655,6 +660,8 @@ silc_client_list_channel_private_keys(SilcClient client,
   SilcChannelPrivateKey *keys = NULL, entry;
   SilcUInt32 count = 0;
 
+  assert(client && channel);
+
   if (!channel->private_keys)
     return NULL;
 
@@ -688,6 +695,7 @@ void silc_client_current_channel_private_key(SilcClient client,
                                             SilcChannelEntry channel,
                                             SilcChannelPrivateKey key)
 {
+  assert(client && channel);
   channel->curr_key = key;
 }