Added Requested Attributes sending and receiving support to
[silc.git] / lib / silcclient / client_keyagr.c
index 2c5e20880c3ef617bdbb80d858d959d42c9892cb..3e9efd5fd9375df0773e79db6d5f8002d9216abe 100644 (file)
@@ -24,7 +24,8 @@
    and in protocol.c. This file implements the client-to-client key 
    agreement as defined by the SILC protocol. */
 
-#include "clientlibincludes.h"
+#include "silcincludes.h"
+#include "silcclient.h"
 #include "client_internal.h"
 
 SILC_TASK_CALLBACK(silc_client_key_agreement_final);
@@ -298,7 +299,7 @@ void silc_client_send_key_agreement(SilcClient client,
                                    const char *hostname,
                                    const char *bindhost,
                                    int port,
-                                   uint32 timeout_secs,
+                                   SilcUInt32 timeout_secs,
                                    SilcKeyAgreementCallback completion,
                                    void *context)
 {
@@ -306,10 +307,20 @@ void silc_client_send_key_agreement(SilcClient client,
   SilcClientKeyAgreement ke = NULL;
   SilcBuffer buffer;
 
-  assert(client_entry);
+  if (!client_entry)
+    return;
 
-  if (client_entry->ke)
+  if (client_entry->ke) {
+    completion(client, conn, client_entry, SILC_KEY_AGREEMENT_ALREADY_STARTED,
+              NULL, context);
     return;
+  }
+
+  if (client_entry == conn->local_entry) {
+    completion(client, conn, client_entry, SILC_KEY_AGREEMENT_SELF_DENIED,
+              NULL, context);
+    return;
+  }
 
   /* Create the listener if hostname and port was provided.
    * also, use bindhost if it was specified.
@@ -331,7 +342,6 @@ void silc_client_send_key_agreement(SilcClient client,
       completion(client, conn, client_entry, SILC_KEY_AGREEMENT_FAILURE,
                 NULL, context);
       silc_free(ke);
-
       return;
     }
 
@@ -368,7 +378,6 @@ void silc_client_send_key_agreement(SilcClient client,
                          client_entry->id, SILC_ID_CLIENT, NULL, NULL,
                          buffer->data, buffer->len, FALSE);
   silc_buffer_free(buffer);
-
 }
 
 static int 
@@ -518,7 +527,20 @@ void silc_client_perform_key_agreement(SilcClient client,
 
   SILC_LOG_DEBUG(("Start"));
 
-  assert(client_entry && hostname && port);
+  if (!client_entry)
+    return;
+
+  if (!hostname || !port) {
+    completion(client, conn, client_entry, SILC_KEY_AGREEMENT_FAILURE,
+              NULL, context);
+    return;
+  }
+
+  if (client_entry == conn->local_entry) {
+    completion(client, conn, client_entry, SILC_KEY_AGREEMENT_SELF_DENIED,
+              NULL, context);
+    return;
+  }
 
   ke = silc_calloc(1, sizeof(*ke));
   ke->client = client;
@@ -556,7 +578,14 @@ void silc_client_perform_key_agreement_fd(SilcClient client,
 
   SILC_LOG_DEBUG(("Start"));
 
-  assert(client_entry);
+  if (!client_entry)
+    return;
+
+  if (client_entry == conn->local_entry) {
+    completion(client, conn, client_entry, SILC_KEY_AGREEMENT_SELF_DENIED,
+              NULL, context);
+    return;
+  }
 
   ke = silc_calloc(1, sizeof(*ke));
   ke->client = client;
@@ -614,7 +643,8 @@ void silc_client_abort_key_agreement(SilcClient client,
                                     SilcClientConnection conn,
                                     SilcClientEntry client_entry)
 {
-  assert(client_entry);
+  if (!client_entry)
+    return;
 
   if (client_entry->ke) {
     SilcClientKeyAgreement ke;
@@ -643,7 +673,7 @@ static void
 silc_client_key_agreement_resolve_cb(SilcClient client,
                                     SilcClientConnection conn,
                                     SilcClientEntry *clients,
-                                    uint32 clients_count,
+                                    SilcUInt32 clients_count,
                                     void *context)
 {
   SilcPacketContext *packet = (SilcPacketContext *)context;
@@ -703,6 +733,7 @@ void silc_client_key_agreement(SilcClient client,
     return;
 
   silc_client_get_client_by_id_resolve(client, sock->user_data, remote_id,
+                                      NULL,
                                       silc_client_key_agreement_resolve_cb,
                                       silc_packet_context_dup(packet));
   silc_free(remote_id);