The indexes returned by ***_get_ex_new_index() functions are used when
[openssl.git] / crypto / ui / ui_lib.c
index 2559ea54b69e48d3d1c337875234dfddb85eb07f..c526426f8b2b73eac5aa88a7990d8d141a4ebd3c 100644 (file)
@@ -1,9 +1,9 @@
 /* crypto/ui/ui_lib.c -*- mode:C; c-file-style: "eay" -*- */
-/* Written by Richard Levitte (levitte@stacken.kth.se) for the OpenSSL
- * project 2000.
+/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
+ * project 2001.
  */
 /* ====================================================================
- * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 2001 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -176,6 +176,8 @@ static int general_allocate_string(UI *ui, const char *prompt,
                        s->_.string_data.result_maxsize=maxsize;
                        s->_.string_data.test_buf=test_buf;
                        ret=sk_UI_STRING_push(ui->strings, s);
+                       /* sk_push() returns 0 on error.  Let's addapt that */
+                       if (ret <= 0) ret--;
                        }
                else
                        free_string(s);
@@ -223,6 +225,9 @@ static int general_allocate_boolean(UI *ui,
                                s->_.boolean_data.ok_chars = ok_chars;
                                s->_.boolean_data.cancel_chars = cancel_chars;
                                ret=sk_UI_STRING_push(ui->strings, s);
+                               /* sk_push() returns 0 on error.
+                                  Let's addapt that */
+                               if (ret <= 0) ret--;
                                }
                        else
                                free_string(s);
@@ -569,9 +574,10 @@ int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)())
 int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
             CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
         {
-       ui_meth_num++;
-       return(CRYPTO_get_ex_new_index(ui_meth_num-1,
-               &ui_meth,argl,argp,new_func,dup_func,free_func));
+       if(CRYPTO_get_ex_new_index(ui_meth_num, &ui_meth, argl, argp,
+                               new_func, dup_func, free_func) < 0)
+               return -1;
+       return (ui_meth_num++);
         }
 
 int UI_set_ex_data(UI *r, int idx, void *arg)
@@ -701,6 +707,14 @@ int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*)
                return NULL;
        }
 
+int (*UI_method_get_flusher(UI_METHOD *method))(UI*)
+       {
+       if (method)
+               return method->ui_flush;
+       else
+               return NULL;
+       }
+
 int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*)
        {
        if (method)