Fix crash on expired keyboard prompts
[silc.git] / apps / irssi / src / silc / core / clientutil.h
1 /*
2
3   client.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20
21 #ifndef CLIENTUTIL_H
22 #define CLIENTUTIL_H
23
24 #include "signals.h"
25
26 /* Prototypes */
27 void silc_client_list_ciphers();
28 void silc_client_list_hash_funcs();
29 void silc_client_list_hmacs();
30 void silc_client_list_pkcs();
31 int silc_client_check_silc_dir();
32 int silc_client_load_keys(SilcClient client);
33
34 typedef enum
35 {
36         KeyboardCompletionSuccess, /* Success; keyboard data returned to callback. */
37         KeyboardCompletionAborted, /* Operation was aborted after starting successfully. */
38         KeyboardCompletionFailed /* Operation was not started successfully. */
39 } SilcKeyboardPromptStatus;
40
41 typedef void (*SILC_KEYBOARD_PROMPT_PROC)(
42         const char *line,
43         void *context,
44         SilcKeyboardPromptStatus reason);
45
46 /*
47  * Prompt for keyboard input.
48  *
49  * If the function returns FALSE, then the prompt operation could not be
50  * initiated and the user supplied callback is called to indicate that the
51  * operation was not started (reason KeyboardCompletionFailed).  This can be
52  * used to centralize all cleanup work in the callback function.
53  *
54  * If the function returns TRUE, then the operation was initiated successfully
55  * and the prompt callback is guaranteed to be called sometime in the future.
56  * Note that it is posssible for the completion callback to have been already
57  * called by the time the function returns TRUE.  In this instance, the
58  * callback will eventually be called with KeyboardCompletionSuccess, unless
59  * the operation is aborted before then.
60  *
61  * If the function returns TRUE, then a SilcAsyncOperation context may be
62  * returned.  If an async operation context is returned, then the operation has
63  * not been completed immediately, and may be canceled with a call to
64  * silc_async_abort(*async).
65  *
66  * Note that the SilcAsyncOperation object's lifetime is managed internally.  A
67  * user may call silc_async_abort exactly once, after which it can never touch
68  * the async context again.  Additionally, the async context may not be
69  * referenced after the user callback returns.  The recommended way to handle
70  * the async operation context is to remove the reference to it when the user
71  * callback is called, either for an abort or regular completion.  If the
72  * callback is called with a KeyboardCompletionFailed reason, then no async
73  * context object was allocated.
74  *
75  * If an abort is requested, then the user callback is called with reason code
76  * KeyboardCompletionAborted.  In this case, the user should clean up all
77  * associated callback data and perform the handling expected in the abort case,
78  * such as the associated server connection going away while the operation was
79  * in progress.
80  *
81  * There can only be one keyboard redirect operation in progress.  If a
82  * keyboard redirect operation is aborted while we are still waiting for data,
83  * then we abort all callbacks until that callback returns.
84  */
85 bool silc_keyboard_entry_redirect(
86         SILC_KEYBOARD_PROMPT_PROC prompt_func,
87         const char *entry,
88         int flags,
89         void *data,
90         SilcAsyncOperation *async);
91
92 #ifdef SILC_PLUGIN
93 typedef struct {
94   char *old, *passphrase, *file, *pkcs;
95   int bits;
96 } CREATE_KEY_REC;
97
98 void create_key_passphrase(const char *answer, CREATE_KEY_REC *rec);
99 void change_private_key_passphrase(const char *answer, CREATE_KEY_REC *rec);
100 #endif
101
102 #endif