updates.
[silc.git] / lib / silcclient / client_keyagr.c
index b23f6550698659d32e7dac01fdd08d8cda3a849d..37f980034999bb43e7600f318da11237260bc0f1 100644 (file)
@@ -295,7 +295,8 @@ SILC_TASK_CALLBACK(silc_client_key_agreement_timeout)
 void silc_client_send_key_agreement(SilcClient client,
                                    SilcClientConnection conn,
                                    SilcClientEntry client_entry,
-                                   char *hostname,
+                                   const char *hostname,
+                                   const char *bindhost,
                                    int port,
                                    uint32 timeout_secs,
                                    SilcKeyAgreementCallback completion,
@@ -310,18 +311,26 @@ void silc_client_send_key_agreement(SilcClient client,
   if (client_entry->ke)
     return;
 
-  /* Create the listener if hostname and port was provided */
+  /* Create the listener if hostname and port was provided.
+   * also, use bindhost if it was specified.
+   */
+   
   if (hostname) {
     ke = silc_calloc(1, sizeof(*ke));
-    ke->fd = silc_net_create_server(port, hostname);
+    
+    if (bindhost)
+      ke->fd = silc_net_create_server(port, bindhost);
+    else
+      ke->fd = silc_net_create_server(port, hostname);
 
     if (ke->fd < 0) {
       client->ops->say(client, conn, SILC_CLIENT_MESSAGE_ERROR, 
                       "Cannot create listener on %s on port %d: %s", 
-                      hostname, port, strerror(errno));
+                      (bindhost) ? bindhost:hostname, port, strerror(errno));
       completion(client, conn, client_entry, SILC_KEY_AGREEMENT_FAILURE,
                 NULL, context);
       silc_free(ke);
+
       return;
     }
 
@@ -357,7 +366,8 @@ void silc_client_send_key_agreement(SilcClient client,
   silc_client_packet_send(client, sock, SILC_PACKET_KEY_AGREEMENT,
                          client_entry->id, SILC_ID_CLIENT, NULL, NULL,
                          buffer->data, buffer->len, FALSE);
-  silc_free(buffer);
+  silc_buffer_free(buffer);
+
 }
 
 static int 
@@ -606,16 +616,21 @@ void silc_client_abort_key_agreement(SilcClient client,
   assert(client_entry);
 
   if (client_entry->ke) {
+    SilcClientKeyAgreement ke;
+
     if (client_entry->ke->sock) {
       silc_client_del_socket(client_entry->ke->client, client_entry->ke->sock);
       silc_socket_free(client_entry->ke->sock);
     }
-    client_entry->ke = NULL;
     silc_schedule_task_del_by_fd(client->schedule, client_entry->ke->fd);
     if (client_entry->ke->timeout)
       silc_schedule_task_del(client->schedule, 
-                          client_entry->ke->timeout);
-    silc_free(client_entry->ke);
+                            client_entry->ke->timeout);
+    ke = client_entry->ke;
+    client_entry->ke = NULL;
+    ke->completion(client, conn, client_entry, 
+                  SILC_KEY_AGREEMENT_ABORTED, NULL, ke->context);
+    silc_free(ke);
   }
 }
 
@@ -640,7 +655,8 @@ silc_client_key_agreement_resolve_cb(SilcClient client,
     goto out;
 
   /* Parse the key agreement payload */
-  payload = silc_key_agreement_payload_parse(packet->buffer);
+  payload = silc_key_agreement_payload_parse(packet->buffer->data,
+                                            packet->buffer->len);
   if (!payload)
     goto out;