UI_create_method.pod 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. =pod
  2. =head1 NAME
  3. UI_METHOD,
  4. UI_create_method, UI_destroy_method, UI_method_set_opener,
  5. UI_method_set_writer, UI_method_set_flusher, UI_method_set_reader,
  6. UI_method_set_closer, UI_method_set_prompt_constructor,
  7. UI_method_set_ex_data, UI_method_get_opener, UI_method_get_writer,
  8. UI_method_get_flusher, UI_method_get_reader, UI_method_get_closer,
  9. UI_method_get_prompt_constructor, UI_method_get_ex_data - user
  10. interface method creation and destruction
  11. =head1 SYNOPSIS
  12. #include <openssl/ui.h>
  13. typedef struct ui_method_st UI_METHOD;
  14. UI_METHOD *UI_create_method(const char *name);
  15. void UI_destroy_method(UI_METHOD *ui_method);
  16. int UI_method_set_opener(UI_METHOD *method, int (*opener) (UI *ui));
  17. int UI_method_set_writer(UI_METHOD *method,
  18. int (*writer) (UI *ui, UI_STRING *uis));
  19. int UI_method_set_flusher(UI_METHOD *method, int (*flusher) (UI *ui));
  20. int UI_method_set_reader(UI_METHOD *method,
  21. int (*reader) (UI *ui, UI_STRING *uis));
  22. int UI_method_set_closer(UI_METHOD *method, int (*closer) (UI *ui));
  23. int UI_method_set_prompt_constructor(UI_METHOD *method,
  24. char *(*prompt_constructor) (UI *ui,
  25. const char
  26. *object_desc,
  27. const char
  28. *object_name));
  29. int UI_method_set_ex_data(UI_METHOD *method, int idx, void *data);
  30. int (*UI_method_get_opener(const UI_METHOD *method)) (UI *);
  31. int (*UI_method_get_writer(const UI_METHOD *method)) (UI *, UI_STRING *);
  32. int (*UI_method_get_flusher(const UI_METHOD *method)) (UI *);
  33. int (*UI_method_get_reader(const UI_METHOD *method)) (UI *, UI_STRING *);
  34. int (*UI_method_get_closer(const UI_METHOD *method)) (UI *);
  35. char *(*UI_method_get_prompt_constructor(const UI_METHOD *method))
  36. (UI *, const char *, const char *);
  37. const void *UI_method_get_ex_data(const UI_METHOD *method, int idx);
  38. =head1 DESCRIPTION
  39. A method contains a few functions that implement the low level of the
  40. User Interface.
  41. These functions are:
  42. =over 4
  43. =item an opener
  44. This function takes a reference to a UI and starts a session, for
  45. example by opening a channel to a tty, or by creating a dialog box.
  46. =item a writer
  47. This function takes a reference to a UI and a UI String, and writes
  48. the string where appropriate, maybe to the tty, maybe added as a field
  49. label in a dialog box.
  50. Note that this gets fed all strings associated with a UI, one after
  51. the other, so care must be taken which ones it actually uses.
  52. =item a flusher
  53. This function takes a reference to a UI, and flushes everything that
  54. has been output so far.
  55. For example, if the method builds up a dialog box, this can be used to
  56. actually display it and accepting input ended with a pressed button.
  57. =item a reader
  58. This function takes a reference to a UI and a UI string and reads off
  59. the given prompt, maybe from the tty, maybe from a field in a dialog
  60. box.
  61. Note that this gets fed all strings associated with a UI, one after
  62. the other, so care must be taken which ones it actually uses.
  63. =item a closer
  64. This function takes a reference to a UI, and closes the session, maybe
  65. by closing the channel to the tty, maybe by destroying a dialog box.
  66. =back
  67. All of these functions are expected to return 0 on error, 1 on
  68. success, or -1 on out-off-band events, for example if some prompting
  69. has been cancelled (by pressing Ctrl-C, for example).
  70. Only the flusher or the reader are expected to return -1.
  71. If returned by another of the functions, it's treated as if 0 was
  72. returned.
  73. Regarding the writer and the reader, don't assume the former should
  74. only write and don't assume the latter should only read.
  75. This depends on the needs of the method.
  76. For example, a typical tty reader wouldn't write the prompts in the
  77. write, but would rather do so in the reader, because of the sequential
  78. nature of prompting on a tty.
  79. This is how the UI_OpenSSL() method does it.
  80. In contrast, a method that builds up a dialog box would add all prompt
  81. text in the writer, have all input read in the flusher and store the
  82. results in some temporary buffer, and finally have the reader just
  83. fetch those results.
  84. The central function that uses these method functions is UI_process(),
  85. and it does it in five steps:
  86. =over 4
  87. =item 1.
  88. Open the session using the opener function if that one's defined.
  89. If an error occurs, jump to 5.
  90. =item 2.
  91. For every UI String associated with the UI, call the writer function
  92. if that one's defined.
  93. If an error occurs, jump to 5.
  94. =item 3.
  95. Flush everything using the flusher function if that one's defined.
  96. If an error occurs, jump to 5.
  97. =item 4.
  98. For every UI String associated with the UI, call the reader function
  99. if that one's defined.
  100. If an error occurs, jump to 5.
  101. =item 5.
  102. Close the session using the closer function if that one's defined.
  103. =back
  104. UI_create_method() creates a new UI method with a given B<name>.
  105. UI_destroy_method() destroys the given UI method B<ui_method>.
  106. UI_method_set_opener(), UI_method_set_writer(),
  107. UI_method_set_flusher(), UI_method_set_reader() and
  108. UI_method_set_closer() set the five main method function to the given
  109. function pointer.
  110. UI_method_set_prompt_constructor() sets the prompt constructor.
  111. See L<UI_construct_prompt(3)>.
  112. UI_method_set_ex_data() sets application specific data with a given
  113. EX_DATA index.
  114. See L<CRYPTO_get_ex_new_index(3)> for general information on how to
  115. get that index.
  116. UI_method_get_opener(), UI_method_get_writer(),
  117. UI_method_get_flusher(), UI_method_get_reader(),
  118. UI_method_get_closer() and UI_method_get_prompt_constructor() return
  119. the different method functions.
  120. UI_method_get_ex_data() returns the application data previously stored
  121. with UI_method_set_ex_data().
  122. =head1 RETURN VALUES
  123. UI_create_method() returns a UI_METHOD pointer on success, NULL on
  124. error.
  125. UI_method_set_opener(), UI_method_set_writer(),
  126. UI_method_set_flusher(), UI_method_set_reader(),
  127. UI_method_set_closer() and UI_method_set_prompt_constructor() return
  128. 0 on success, -1 if the given B<method> is NULL.
  129. UI_method_set_ex_data() returns 1 on success and 0 on error (because
  130. CRYPTO_set_ex_data() does so).
  131. UI_method_get_opener(), UI_method_get_writer(),
  132. UI_method_get_flusher(), UI_method_get_reader(),
  133. UI_method_get_closer() and UI_method_get_prompt_constructor() return
  134. the requested function pointer if it's set in the method, otherwise
  135. NULL.
  136. UI_method_get_ex_data() returns a pointer to the application specific
  137. data associated with the method.
  138. =head1 SEE ALSO
  139. L<UI(3)>, L<CRYPTO_get_ex_data(3)>, L<UI_STRING(3)>
  140. =head1 COPYRIGHT
  141. Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
  142. Licensed under the OpenSSL license (the "License"). You may not use
  143. this file except in compliance with the License. You can obtain a copy
  144. in the file LICENSE in the source distribution or at
  145. L<https://www.openssl.org/source/license.html>.
  146. =cut