From 1e7e62f8cdda90328531b3a7c31fb68240b6245f Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Tue, 5 Jun 2001 19:05:52 +0000 Subject: [PATCH] A good use of the UI interface is as a password callback replacement (for new functions...). One might still want to be able to pass down a user-data pointer to be used by the UI. However, ex_data doesn't quite cut it, since that means the appropriate index to it might need to be shared between parts that aren't really related in that sense, and would require the currently hidden (static) index holders to be uncovered. Not a good thing. Therefore, add the possibility to add a user-data pointer to a UI. --- crypto/ui/ui.h | 13 +++++++++++++ crypto/ui/ui_lib.c | 12 ++++++++++++ crypto/ui/ui_locl.h | 1 + 3 files changed, 26 insertions(+) diff --git a/crypto/ui/ui.h b/crypto/ui/ui.h index 9a03e8a9ec..452d9dcbfc 100644 --- a/crypto/ui/ui.h +++ b/crypto/ui/ui.h @@ -129,6 +129,19 @@ int UI_dup_info_string(UI *ui, const char *text); int UI_add_error_string(UI *ui, const char *text); int UI_dup_error_string(UI *ui, const char *text); +/* The following function is used to store a pointer to user-specific data. + Any previous such pointer will be returned and replaced. + + For callback purposes, this function makes a lot more sense than using + ex_data, since the latter requires that different parts of OpenSSL or + applications share the same ex_data index. + + Note that the UI_OpenSSL() method completely ignores the user data. + Other methods may not, however. */ +void *UI_add_user_data(UI *ui, void *user_data); +/* We need a user data retrieving function as well. */ +void *UI_get0_user_data(UI *ui); + /* Return the result associated with a prompt given with the index i. */ const char *UI_get0_result(UI *ui, int i); diff --git a/crypto/ui/ui_lib.c b/crypto/ui/ui_lib.c index c5d17042f9..f8881dee05 100644 --- a/crypto/ui/ui_lib.c +++ b/crypto/ui/ui_lib.c @@ -256,6 +256,18 @@ int UI_dup_error_string(UI *ui, const char *text) NULL); } +void *UI_add_user_data(UI *ui, void *user_data) + { + void *old_data = ui->user_data; + ui->user_data = user_data; + return old_data; + } + +void *UI_get0_user_data(UI *ui) + { + return ui->user_data; + } + const char *UI_get0_result(UI *ui, int i) { if (i < 0) diff --git a/crypto/ui/ui_locl.h b/crypto/ui/ui_locl.h index d5470a6c05..4adf0d821b 100644 --- a/crypto/ui/ui_locl.h +++ b/crypto/ui/ui_locl.h @@ -104,6 +104,7 @@ struct ui_st STACK_OF(UI_STRING) *strings; /* We might want to prompt for more than one thing at a time, and with different echoing status. */ + void *user_data; CRYPTO_EX_DATA ex_data; }; -- 2.25.1