silc-client: handle prompt abort better
[silc.git] / apps / irssi / src / silc / core / client_ops.c
index 41ace322591b7268ead442d55c4fb7cd2ca241c9..b3b6cdbc59b2112d4eab5898dae76dd594cd28d0 100644 (file)
@@ -2476,7 +2476,7 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
   SilcPublicKey local_pubkey;
   SilcSILCPublicKey silc_pubkey;
   SilcUInt16 port;
-  SILC_SERVER_REC *server;
+  SILC_SERVER_REC *server = NULL;
   const char *hostname, *ip;
   unsigned char *pk;
   SilcUInt32 pk_len;
@@ -2487,8 +2487,8 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
                  "server" : "client");
   int i;
 
+  server = (SILC_SERVER_REC*)conn->context;
   if (conn_type != SILC_CONN_CLIENT) {
-    server = (SILC_SERVER_REC*)conn->context;
     SILC_VERIFY(server);
     if (!server) {
       if (completion)
@@ -2497,6 +2497,12 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
     }
   }
 
+  /* If we have pending public key prompt already up */
+  if (server && server->prompt_op) {
+    silc_async_abort(server->prompt_op, NULL, NULL);
+    server->prompt_op = NULL;
+  }
+
   if (silc_pkcs_get_type(public_key) != SILC_PKCS_SILC) {
     printformat_module("fe-common/silc", NULL, NULL,
                       MSGLEVEL_CRAP, SILCTXT_PUBKEY_UNSUPPORTED,
@@ -2599,6 +2605,14 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
                         silc_pubkey->identifier.realname,
                         silc_pubkey->identifier.email ?
                         silc_pubkey->identifier.email : "");
+    else if (conn_type == SILC_CONN_CLIENT &&
+            (silc_pubkey->identifier.realname ||
+             silc_pubkey->identifier.email))
+      printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
+                        SILCTXT_PUBKEY_RECEIVED_CLIENT, "",
+                        silc_pubkey->identifier.realname,
+                        silc_pubkey->identifier.email ?
+                        silc_pubkey->identifier.email : "");
     printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
                       SILCTXT_PUBKEY_FINGERPRINT, entity, fingerprint);
     printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
@@ -2606,7 +2620,8 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
     format = format_get_text("fe-common/silc", NULL, NULL, NULL,
                             SILCTXT_PUBKEY_ACCEPT);
     silc_keyboard_entry_redirect(verify_public_key_completion,
-                           format, 0, verify, &server->prompt_op);
+                                format, 0, verify,
+                                server ? &server->prompt_op : NULL);
     g_free(format);
     silc_free(fingerprint);
     silc_free(babbleprint);
@@ -2630,6 +2645,14 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
                           silc_pubkey->identifier.realname,
                           silc_pubkey->identifier.email ?
                           silc_pubkey->identifier.email : "");
+      else if (conn_type == SILC_CONN_CLIENT &&
+              (silc_pubkey->identifier.realname ||
+               silc_pubkey->identifier.email))
+       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
+                          SILCTXT_PUBKEY_RECEIVED_CLIENT, "",
+                          silc_pubkey->identifier.realname,
+                          silc_pubkey->identifier.email ?
+                          silc_pubkey->identifier.email : "");
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
                         SILCTXT_PUBKEY_FINGERPRINT, entity, fingerprint);
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
@@ -2639,7 +2662,9 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
       format = format_get_text("fe-common/silc", NULL, NULL, NULL,
                               SILCTXT_PUBKEY_ACCEPT_ANYWAY);
       silc_keyboard_entry_redirect(verify_public_key_completion,
-                             format, 0, verify, &server->prompt_op);
+                                  format, 0, verify,
+                                  server ? &server->prompt_op : NULL);
+
       g_free(format);
       silc_free(fingerprint);
       silc_free(babbleprint);
@@ -2660,6 +2685,14 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
                           silc_pubkey->identifier.realname,
                           silc_pubkey->identifier.email ?
                           silc_pubkey->identifier.email : "");
+      else if (conn_type == SILC_CONN_CLIENT &&
+              (silc_pubkey->identifier.realname ||
+               silc_pubkey->identifier.email))
+       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
+                          SILCTXT_PUBKEY_RECEIVED_CLIENT, "",
+                          silc_pubkey->identifier.realname,
+                          silc_pubkey->identifier.email ?
+                          silc_pubkey->identifier.email : "");
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
                         SILCTXT_PUBKEY_FINGERPRINT, entity, fingerprint);
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
@@ -2669,7 +2702,8 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
       format = format_get_text("fe-common/silc", NULL, NULL, NULL,
                               SILCTXT_PUBKEY_ACCEPT_ANYWAY);
       silc_keyboard_entry_redirect(verify_public_key_completion,
-                             format, 0, verify, &server->prompt_op);
+                                  format, 0, verify,
+                                  server ? &server->prompt_op : NULL);
       g_free(format);
       silc_free(fingerprint);
       silc_free(babbleprint);
@@ -2690,6 +2724,14 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
                           silc_pubkey->identifier.realname,
                           silc_pubkey->identifier.email ?
                           silc_pubkey->identifier.email : "");
+      else if (conn_type == SILC_CONN_CLIENT &&
+              (silc_pubkey->identifier.realname ||
+               silc_pubkey->identifier.email))
+       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
+                          SILCTXT_PUBKEY_RECEIVED_CLIENT, "",
+                          silc_pubkey->identifier.realname,
+                          silc_pubkey->identifier.email ?
+                          silc_pubkey->identifier.email : "");
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
                         SILCTXT_PUBKEY_FINGERPRINT, entity, fingerprint);
       printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP,
@@ -2705,7 +2747,8 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
       format = format_get_text("fe-common/silc", NULL, NULL, NULL,
                               SILCTXT_PUBKEY_ACCEPT_ANYWAY);
       silc_keyboard_entry_redirect(verify_public_key_completion,
-                             format, 0, verify, &server->prompt_op);
+                                  format, 0, verify,
+                                  server ? &server->prompt_op : NULL);
       g_free(format);
       silc_free(fingerprint);
       silc_free(babbleprint);