- {
- ui->meth=meth;
- return ui->meth;
- }
-
-
-UI_METHOD *UI_create_method(void)
- {
- return (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD));
- }
-
-int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui))
- {
- if (method)
- {
- method->ui_open_session = opener;
- return 0;
- }
- else
- return -1;
- }
-
-int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis))
- {
- if (method)
- {
- method->ui_write_string = writer;
- return 0;
- }
- else
- return -1;
- }
-
-int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis))
- {
- if (method)
- {
- method->ui_read_string = reader;
- return 0;
- }
- else
- return -1;
- }
-
-int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui))
- {
- if (method)
- {
- method->ui_close_session = closer;
- return 0;
- }
- else
- return -1;
- }
-
-int (*UI_method_get_opener(UI_METHOD *method))(UI*)
- {
- if (method)
- return method->ui_open_session;
- else
- return NULL;
- }
-
-int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*)
- {
- if (method)
- return method->ui_write_string;
- else
- return NULL;
- }
-
-int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*)
- {
- if (method)
- return method->ui_read_string;
- else
- return NULL;
- }
-
-int (*UI_method_get_closer(UI_METHOD *method))(UI*)
- {
- if (method)
- return method->ui_close_session;
- else
- return NULL;
- }
+{
+ ui->meth = meth;
+ return ui->meth;
+}
+
+UI_METHOD *UI_create_method(const char *name)
+{
+ UI_METHOD *ui_method = NULL;
+
+ if ((ui_method = OPENSSL_zalloc(sizeof(*ui_method))) == NULL
+ || (ui_method->name = OPENSSL_strdup(name)) == NULL
+ || !CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI_METHOD, ui_method,
+ &ui_method->ex_data)) {
+
+ if (ui_method != NULL) {
+ if (ui_method->name != NULL)
+ /*
+ * These conditions indicate that the CRYPTO_new_ex_data()
+ * call failed.
+ */
+ ERR_raise(ERR_LIB_UI, ERR_R_CRYPTO_LIB);
+ OPENSSL_free(ui_method->name);
+ }
+ OPENSSL_free(ui_method);
+ return NULL;
+ }
+ return ui_method;
+}
+
+/*
+ * BIG FSCKING WARNING!!!! If you use this on a statically allocated method
+ * (that is, it hasn't been allocated using UI_create_method(), you deserve
+ * anything Murphy can throw at you and more! You have been warned.
+ */
+void UI_destroy_method(UI_METHOD *ui_method)
+{
+ if (ui_method == NULL)
+ return;
+ CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI_METHOD, ui_method,
+ &ui_method->ex_data);
+ OPENSSL_free(ui_method->name);
+ ui_method->name = NULL;
+ OPENSSL_free(ui_method);
+}
+
+int UI_method_set_opener(UI_METHOD *method, int (*opener) (UI *ui))
+{
+ if (method != NULL) {
+ method->ui_open_session = opener;
+ return 0;
+ }
+ return -1;
+}
+
+int UI_method_set_writer(UI_METHOD *method,
+ int (*writer) (UI *ui, UI_STRING *uis))
+{
+ if (method != NULL) {
+ method->ui_write_string = writer;
+ return 0;
+ }
+ return -1;
+}
+
+int UI_method_set_flusher(UI_METHOD *method, int (*flusher) (UI *ui))
+{
+ if (method != NULL) {
+ method->ui_flush = flusher;
+ return 0;
+ }
+ return -1;
+}
+
+int UI_method_set_reader(UI_METHOD *method,
+ int (*reader) (UI *ui, UI_STRING *uis))
+{
+ if (method != NULL) {
+ method->ui_read_string = reader;
+ return 0;
+ }
+ return -1;
+}
+
+int UI_method_set_closer(UI_METHOD *method, int (*closer) (UI *ui))
+{
+ if (method != NULL) {
+ method->ui_close_session = closer;
+ return 0;
+ }
+ return -1;
+}
+
+int UI_method_set_data_duplicator(UI_METHOD *method,
+ void *(*duplicator) (UI *ui, void *ui_data),
+ void (*destructor)(UI *ui, void *ui_data))
+{
+ if (method != NULL) {
+ method->ui_duplicate_data = duplicator;
+ method->ui_destroy_data = destructor;
+ return 0;
+ }
+ return -1;
+}
+
+int UI_method_set_prompt_constructor(UI_METHOD *method,
+ char *(*prompt_constructor) (UI *ui,
+ const char *,
+ const char *))
+{
+ if (method != NULL) {
+ method->ui_construct_prompt = prompt_constructor;
+ return 0;
+ }
+ return -1;
+}
+
+int UI_method_set_ex_data(UI_METHOD *method, int idx, void *data)
+{
+ return CRYPTO_set_ex_data(&method->ex_data, idx, data);
+}
+
+int (*UI_method_get_opener(const UI_METHOD *method)) (UI *)
+{
+ if (method != NULL)
+ return method->ui_open_session;
+ return NULL;
+}
+
+int (*UI_method_get_writer(const UI_METHOD *method)) (UI *, UI_STRING *)
+{
+ if (method != NULL)
+ return method->ui_write_string;
+ return NULL;
+}
+
+int (*UI_method_get_flusher(const UI_METHOD *method)) (UI *)
+{
+ if (method != NULL)
+ return method->ui_flush;
+ return NULL;
+}
+
+int (*UI_method_get_reader(const UI_METHOD *method)) (UI *, UI_STRING *)
+{
+ if (method != NULL)
+ return method->ui_read_string;
+ return NULL;
+}
+
+int (*UI_method_get_closer(const UI_METHOD *method)) (UI *)
+{
+ if (method != NULL)
+ return method->ui_close_session;
+ return NULL;
+}
+
+char *(*UI_method_get_prompt_constructor(const UI_METHOD *method))
+ (UI *, const char *, const char *)
+{
+ if (method != NULL)
+ return method->ui_construct_prompt;
+ return NULL;
+}
+
+void *(*UI_method_get_data_duplicator(const UI_METHOD *method)) (UI *, void *)
+{
+ if (method != NULL)
+ return method->ui_duplicate_data;
+ return NULL;
+}
+
+void (*UI_method_get_data_destructor(const UI_METHOD *method)) (UI *, void *)
+{
+ if (method != NULL)
+ return method->ui_destroy_data;
+ return NULL;
+}
+
+const void *UI_method_get_ex_data(const UI_METHOD *method, int idx)
+{
+ return CRYPTO_get_ex_data(&method->ex_data, idx);
+}