Fix crash on expired keyboard prompts
[silc.git] / apps / irssi / src / silc / core / clientutil.h
index 240100a600ed6d9b3c4dfedc82d66d82e7ba4af6..dc60a0499b299363599bb39636d04f4a2e72e2b9 100644 (file)
@@ -31,6 +31,64 @@ void silc_client_list_pkcs();
 int silc_client_check_silc_dir();
 int silc_client_load_keys(SilcClient client);
 
+typedef enum
+{
+       KeyboardCompletionSuccess, /* Success; keyboard data returned to callback. */
+       KeyboardCompletionAborted, /* Operation was aborted after starting successfully. */
+       KeyboardCompletionFailed /* Operation was not started successfully. */
+} SilcKeyboardPromptStatus;
+
+typedef void (*SILC_KEYBOARD_PROMPT_PROC)(
+       const char *line,
+       void *context,
+       SilcKeyboardPromptStatus reason);
+
+/*
+ * Prompt for keyboard input.
+ *
+ * If the function returns FALSE, then the prompt operation could not be
+ * initiated and the user supplied callback is called to indicate that the
+ * operation was not started (reason KeyboardCompletionFailed).  This can be
+ * used to centralize all cleanup work in the callback function.
+ *
+ * If the function returns TRUE, then the operation was initiated successfully
+ * and the prompt callback is guaranteed to be called sometime in the future.
+ * Note that it is posssible for the completion callback to have been already
+ * called by the time the function returns TRUE.  In this instance, the
+ * callback will eventually be called with KeyboardCompletionSuccess, unless
+ * the operation is aborted before then.
+ *
+ * If the function returns TRUE, then a SilcAsyncOperation context may be
+ * returned.  If an async operation context is returned, then the operation has
+ * not been completed immediately, and may be canceled with a call to
+ * silc_async_abort(*async).
+ *
+ * Note that the SilcAsyncOperation object's lifetime is managed internally.  A
+ * user may call silc_async_abort exactly once, after which it can never touch
+ * the async context again.  Additionally, the async context may not be
+ * referenced after the user callback returns.  The recommended way to handle
+ * the async operation context is to remove the reference to it when the user
+ * callback is called, either for an abort or regular completion.  If the
+ * callback is called with a KeyboardCompletionFailed reason, then no async
+ * context object was allocated.
+ *
+ * If an abort is requested, then the user callback is called with reason code
+ * KeyboardCompletionAborted.  In this case, the user should clean up all
+ * associated callback data and perform the handling expected in the abort case,
+ * such as the associated server connection going away while the operation was
+ * in progress.
+ *
+ * There can only be one keyboard redirect operation in progress.  If a
+ * keyboard redirect operation is aborted while we are still waiting for data,
+ * then we abort all callbacks until that callback returns.
+ */
+bool silc_keyboard_entry_redirect(
+       SILC_KEYBOARD_PROMPT_PROC prompt_func,
+       const char *entry,
+       int flags,
+       void *data,
+       SilcAsyncOperation *async);
+
 #ifdef SILC_PLUGIN
 typedef struct {
   char *old, *passphrase, *file, *pkcs;