X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Firssi%2Fsrc%2Fsilc%2Fcore%2Fclient_ops.c;fp=apps%2Firssi%2Fsrc%2Fsilc%2Fcore%2Fclient_ops.c;h=16feddc7583a8b2c18dd200f736473b2a8ba6d92;hb=3192ac4ddd09cd3fabe10a88cd5c885f217650a4;hp=2de86781ee02c2339e3728f42678ac95e0e36e01;hpb=5c43a88e369950a34b1c40d655b598bedd16beda;p=silc.git diff --git a/apps/irssi/src/silc/core/client_ops.c b/apps/irssi/src/silc/core/client_ops.c index 2de86781..16feddc7 100644 --- a/apps/irssi/src/silc/core/client_ops.c +++ b/apps/irssi/src/silc/core/client_ops.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2001 - 2007 Pekka Riikonen + Copyright (C) 2001 - 2008 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1440,17 +1440,18 @@ void silc_getkey_cb(bool success, void *context) } /* - * Drop our references as need be. - */ - switch (getkey->id_type) - { - case SILC_ID_CLIENT: - silc_client_unref_client(getkey->client, getkey->conn, (SilcClientEntry)getkey->entry); - break; - - case SILC_ID_SERVER: - silc_client_unref_server(getkey->client, getkey->conn, (SilcServerEntry)getkey->entry); - break; + * Drop our references as need be. + */ + switch (getkey->id_type) { + case SILC_ID_CLIENT: + silc_client_unref_client(getkey->client, getkey->conn, + (SilcClientEntry)getkey->entry); + break; + + case SILC_ID_SERVER: + silc_client_unref_server(getkey->client, getkey->conn, + (SilcServerEntry)getkey->entry); + break; } silc_free(getkey); @@ -2112,17 +2113,16 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn, ((SilcClientEntry)entry)->nickname : ((SilcServerEntry)entry)->server_name); - switch (id_type) - { - case SILC_ID_CLIENT: - name = ((SilcClientEntry)entry)->nickname; - silc_client_ref_client(client, conn, (SilcClientEntry)entry); - break; - - case SILC_ID_SERVER: - name = ((SilcServerEntry)entry)->server_name; - silc_client_ref_server(client, conn, (SilcServerEntry)entry); - break; + switch (id_type) { + case SILC_ID_CLIENT: + name = ((SilcClientEntry)entry)->nickname; + silc_client_ref_client(client, conn, (SilcClientEntry)entry); + break; + + case SILC_ID_SERVER: + name = ((SilcServerEntry)entry)->server_name; + silc_client_ref_server(client, conn, (SilcServerEntry)entry); + break; } silc_verify_public_key_internal(client, conn, name, @@ -2395,10 +2395,10 @@ typedef struct { } *PublicKeyVerify; static void verify_public_key_completion(const char *line, void *context, - SilcKeyboardPromptStatus reason) + SilcKeyboardPromptStatus reason) { PublicKeyVerify verify = (PublicKeyVerify)context; - bool success = (reason == KeyboardCompletionSuccess); + SilcBool success = (reason == KeyboardCompletionSuccess); if (success && (line[0] == 'Y' || line[0] == 'y')) { /* Call the completion */ @@ -2426,21 +2426,17 @@ static void verify_public_key_completion(const char *line, void *context, * we failed due to an overlapping callback, in which case we shouldn't * overwrite the async context block pointer. */ - - if (reason != KeyboardCompletionFailed) - { + if (reason != KeyboardCompletionFailed) { /* - * Null out the completion context in the server record as this operation - * is done as far as we are concerned. The underlying keyboard library - * routine will take care of freeing the async context memory when the - * actual callback is called by irssi in the abort case. In the success - * case, it will free the async context memory after we return from this - * routine. - */ - - SILC_SERVER_REC *server = (SILC_SERVER_REC*)(verify->conn->context); - - server->prompt_op = NULL; + * Null out the completion context in the server record as this operation + * is done as far as we are concerned. The underlying keyboard library + * routine will take care of freeing the async context memory when the + * actual callback is called by irssi in the abort case. In the success + * case, it will free the async context memory after we return from this + * routine. + */ + SILC_SERVER_REC *server = (SILC_SERVER_REC*)(verify->conn->context); + server->prompt_op = NULL; } silc_free(verify->filename); @@ -2479,48 +2475,11 @@ silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn, int i; server = (SILC_SERVER_REC*)conn->context; - - /* - * If we don't have a context yet, then we'll set it up based on the - * stream context associated with the SilcPacketStream that is attached - * to the SilcClientConnection. This is a bit ugly, but we need to have a - * per-connection context value to perform the public key verify operation, - * and the public API was not designed to let us have this in a particularly - * straightforward fashion. - */ - + SILC_VERIFY(server); if (!server) { - SilcPacketStream packet_stream; - SilcStream stream; - - packet_stream = conn->stream; - - if (!packet_stream) - { - if (completion) - completion(FALSE, context); - return; - } - - stream = silc_packet_stream_get_stream(packet_stream); - - if (!stream) - { - if (completion) - completion(FALSE, context); - return; - } - - server = (SILC_SERVER_REC*)(silc_socket_stream_get_context(stream)); - - if (!server) - { - if (completion) - completion(FALSE, context); - return; - } - - conn->context = (void *)server; + if (completion) + completion(FALSE, context); + return; } if (silc_pkcs_get_type(public_key) != SILC_PKCS_SILC) { @@ -2778,7 +2737,7 @@ typedef struct { } *AskPassphrase; void ask_passphrase_completion(const char *passphrase, void *context, - SilcKeyboardPromptStatus reason) + SilcKeyboardPromptStatus reason) { AskPassphrase p = (AskPassphrase)context; if (passphrase && passphrase[0] == '\0') @@ -2786,11 +2745,9 @@ void ask_passphrase_completion(const char *passphrase, void *context, p->completion((unsigned char *)passphrase, passphrase ? strlen(passphrase) : 0, p->context); - if (reason != KeyboardCompletionFailed) - { + if (reason != KeyboardCompletionFailed) { SILC_SERVER_REC *server = (SILC_SERVER_REC *)(p->conn->context); - - server->prompt_op = NULL; + server->prompt_op = NULL; } silc_free(p); @@ -2800,14 +2757,22 @@ void silc_ask_passphrase(SilcClient client, SilcClientConnection conn, SilcAskPassphrase completion, void *context) { SILC_SERVER_REC *server = (SILC_SERVER_REC*)(conn->context); - AskPassphrase p = silc_calloc(1, sizeof(*p)); - + AskPassphrase p; + + p = silc_calloc(1, sizeof(*p)); + if (!p) { + if (completion) + completion(NULL, 0, context); + return; + } + p->completion = completion; p->conn = conn; p->context = context; silc_keyboard_entry_redirect(ask_passphrase_completion, - "Passphrase: ", ENTRY_REDIRECT_FLAG_HIDDEN, p, &server->prompt_op); + "Passphrase: ", ENTRY_REDIRECT_FLAG_HIDDEN, + p, &server->prompt_op); } typedef struct {