Added Requested Attributes sending and receiving support to
[silc.git] / lib / silcclient / client_prvmsg.c
index 2ef43aec9245307d993752a0ae37fff1a546ec80..dca5d000d1e93eb7843686fa18b5681a173806ef 100644 (file)
@@ -71,7 +71,7 @@ void silc_client_send_private_message(SilcClient client,
   /* We have private message specific key */
 
   /* Get data used in the encryption */
-  cipher = client_entry->send_key;
+  cipher = conn->send_key;
   hmac = conn->hmac_send;
   block_len = silc_cipher_get_block_len(cipher);
 
@@ -103,7 +103,6 @@ void silc_client_send_private_message(SilcClient client,
   }
 
   /* Encrypt the header and padding of the packet. */
-  cipher = conn->send_key;
   silc_packet_encrypt(cipher, hmac, conn->psn_send++,
                      (SilcBuffer)&packet, SILC_PACKET_HEADER_LEN + 
                      packetdata.src_id_len + packetdata.dst_id_len +
@@ -149,6 +148,9 @@ void silc_client_private_message(SilcClient client,
   SilcClientID *remote_id = NULL;
   SilcClientEntry remote_client;
   SilcMessageFlags flags;
+  unsigned char *message;
+  SilcUInt32 message_len;
+  SilcCipher cipher = NULL;
 
   if (packet->src_id_type != SILC_ID_CLIENT)
     goto out;
@@ -167,19 +169,25 @@ void silc_client_private_message(SilcClient client,
        goto out;
       }
       remote_client->status |= SILC_CLIENT_STATUS_RESOLVING;
+      remote_client->resolve_cmd_ident = conn->cmd_ident + 1;
     }
 
     /* Resolve the client info */
-    silc_client_get_client_by_id_resolve(client, conn, remote_id,
+    silc_client_get_client_by_id_resolve(client, conn, remote_id, NULL,
                                         silc_client_private_message_cb,
                                         silc_packet_context_dup(packet));
     return;
   }
 
+  cipher = remote_client->receive_key;
+  if (packet->flags & SILC_PACKET_FLAG_PRIVMSG_KEY && !cipher) {
+    silc_free(remote_id);
+    return;
+  }
+
   /* Parse the payload and decrypt it also if private message key is set */
   payload = silc_private_message_payload_parse(packet->buffer->data,
-                                              packet->buffer->len,
-                                              remote_client->receive_key);
+                                              packet->buffer->len, cipher);
   if (!payload) {
     silc_free(remote_id);
     return;
@@ -188,10 +196,9 @@ void silc_client_private_message(SilcClient client,
   flags = silc_private_message_get_flags(payload);
 
   /* Pass the private message to application */
-  client->internal->ops->private_message(
-                                client, conn, remote_client, flags,
-                                silc_private_message_get_message(payload, 
-                                                                 NULL));
+  message = silc_private_message_get_message(payload, &message_len);
+  client->internal->ops->private_message(client, conn, remote_client, flags,
+                                        message, message_len);
 
   /* See if we are away (gone). If we are away we will reply to the
      sender with the set away message. */
@@ -280,6 +287,7 @@ void silc_client_private_message_key(SilcClient client,
     return;
 
   silc_client_get_client_by_id_resolve(client, sock->user_data, remote_id,
+                                      NULL,
                                       silc_client_private_message_key_cb,
                                       silc_packet_context_dup(packet));
   silc_free(remote_id);