BIO_set_callback.pod 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. =pod
  2. =head1 NAME
  3. BIO_set_callback_ex, BIO_get_callback_ex, BIO_set_callback, BIO_get_callback,
  4. BIO_set_callback_arg, BIO_get_callback_arg, BIO_debug_callback,
  5. BIO_debug_callback_ex, BIO_callback_fn_ex, BIO_callback_fn
  6. - BIO callback functions
  7. =head1 SYNOPSIS
  8. #include <openssl/bio.h>
  9. typedef long (*BIO_callback_fn_ex)(BIO *b, int oper, const char *argp,
  10. size_t len, int argi,
  11. long argl, int ret, size_t *processed);
  12. void BIO_set_callback_ex(BIO *b, BIO_callback_fn_ex callback);
  13. BIO_callback_fn_ex BIO_get_callback_ex(const BIO *b);
  14. void BIO_set_callback_arg(BIO *b, char *arg);
  15. char *BIO_get_callback_arg(const BIO *b);
  16. long BIO_debug_callback_ex(BIO *bio, int oper, const char *argp, size_t len,
  17. int argi, long argl, int ret, size_t *processed);
  18. The following functions have been deprecated since OpenSSL 3.0, and can be
  19. hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
  20. see L<openssl_user_macros(7)>:
  21. typedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi,
  22. long argl, long ret);
  23. void BIO_set_callback(BIO *b, BIO_callback_fn cb);
  24. BIO_callback_fn BIO_get_callback(const BIO *b);
  25. long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi,
  26. long argl, long ret);
  27. typedef struct bio_mmsg_cb_args_st {
  28. BIO_MSG *msg;
  29. size_t stride, num_msg;
  30. uint64_t flags;
  31. size_t *msgs_processed;
  32. } BIO_MMSG_CB_ARGS;
  33. =head1 DESCRIPTION
  34. BIO_set_callback_ex() and BIO_get_callback_ex() set and retrieve the BIO
  35. callback. The callback is called during most high-level BIO operations. It can
  36. be used for debugging purposes to trace operations on a BIO or to modify its
  37. operation.
  38. BIO_set_callback() and BIO_get_callback() set and retrieve the old format BIO
  39. callback. New code should not use these functions, but they are retained for
  40. backwards compatibility. Any callback set via BIO_set_callback_ex() will get
  41. called in preference to any set by BIO_set_callback().
  42. BIO_set_callback_arg() and BIO_get_callback_arg() are macros which can be
  43. used to set and retrieve an argument for use in the callback.
  44. BIO_debug_callback_ex() is a standard debugging callback which prints
  45. out information relating to each BIO operation. If the callback
  46. argument is set it is interpreted as a BIO to send the information
  47. to, otherwise stderr is used. The BIO_debug_callback() function is the
  48. deprecated version of the same callback for use with the old callback
  49. format BIO_set_callback() function.
  50. BIO_callback_fn_ex is the type of the callback function and BIO_callback_fn
  51. is the type of the old format callback function. The meaning of each argument
  52. is described below:
  53. =over 4
  54. =item B<b>
  55. The BIO the callback is attached to is passed in B<b>.
  56. =item B<oper>
  57. B<oper> is set to the operation being performed. For some operations
  58. the callback is called twice, once before and once after the actual
  59. operation, the latter case has B<oper> or'ed with BIO_CB_RETURN.
  60. =item B<len>
  61. The length of the data requested to be read or written. This is only useful if
  62. B<oper> is BIO_CB_READ, BIO_CB_WRITE or BIO_CB_GETS.
  63. =item B<argp> B<argi> B<argl>
  64. The meaning of the arguments B<argp>, B<argi> and B<argl> depends on
  65. the value of B<oper>, that is the operation being performed.
  66. =item B<processed>
  67. B<processed> is a pointer to a location which will be updated with the amount of
  68. data that was actually read or written. Only used for BIO_CB_READ, BIO_CB_WRITE,
  69. BIO_CB_GETS and BIO_CB_PUTS.
  70. =item B<ret>
  71. B<ret> is the return value that would be returned to the
  72. application if no callback were present. The actual value returned
  73. is the return value of the callback itself. In the case of callbacks
  74. called before the actual BIO operation 1 is placed in B<ret>, if
  75. the return value is not positive it will be immediately returned to
  76. the application and the BIO operation will not be performed.
  77. =back
  78. The callback should normally simply return B<ret> when it has
  79. finished processing, unless it specifically wishes to modify the
  80. value returned to the application.
  81. =head1 CALLBACK OPERATIONS
  82. In the notes below, B<callback> defers to the actual callback
  83. function that is called.
  84. =over 4
  85. =item B<BIO_free(b)>
  86. callback_ex(b, BIO_CB_FREE, NULL, 0, 0, 0L, 1L, NULL)
  87. or
  88. callback(b, BIO_CB_FREE, NULL, 0L, 0L, 1L)
  89. is called before the free operation.
  90. =item B<BIO_read_ex(b, data, dlen, readbytes)>
  91. callback_ex(b, BIO_CB_READ, data, dlen, 0, 0L, 1L, NULL)
  92. or
  93. callback(b, BIO_CB_READ, data, dlen, 0L, 1L)
  94. is called before the read and
  95. callback_ex(b, BIO_CB_READ | BIO_CB_RETURN, data, dlen, 0, 0L, retvalue,
  96. &readbytes)
  97. or
  98. callback(b, BIO_CB_READ|BIO_CB_RETURN, data, dlen, 0L, retvalue)
  99. after.
  100. =item B<BIO_write(b, data, dlen, written)>
  101. callback_ex(b, BIO_CB_WRITE, data, dlen, 0, 0L, 1L, NULL)
  102. or
  103. callback(b, BIO_CB_WRITE, datat, dlen, 0L, 1L)
  104. is called before the write and
  105. callback_ex(b, BIO_CB_WRITE | BIO_CB_RETURN, data, dlen, 0, 0L, retvalue,
  106. &written)
  107. or
  108. callback(b, BIO_CB_WRITE|BIO_CB_RETURN, data, dlen, 0L, retvalue)
  109. after.
  110. =item B<BIO_gets(b, buf, size)>
  111. callback_ex(b, BIO_CB_GETS, buf, size, 0, 0L, 1, NULL, NULL)
  112. or
  113. callback(b, BIO_CB_GETS, buf, size, 0L, 1L)
  114. is called before the operation and
  115. callback_ex(b, BIO_CB_GETS | BIO_CB_RETURN, buf, size, 0, 0L, retvalue,
  116. &readbytes)
  117. or
  118. callback(b, BIO_CB_GETS|BIO_CB_RETURN, buf, size, 0L, retvalue)
  119. after.
  120. =item B<BIO_puts(b, buf)>
  121. callback_ex(b, BIO_CB_PUTS, buf, 0, 0, 0L, 1L, NULL);
  122. or
  123. callback(b, BIO_CB_PUTS, buf, 0, 0L, 1L)
  124. is called before the operation and
  125. callback_ex(b, BIO_CB_PUTS | BIO_CB_RETURN, buf, 0, 0, 0L, retvalue, &written)
  126. or
  127. callback(b, BIO_CB_PUTS|BIO_CB_RETURN, buf, 0, 0L, retvalue)
  128. after.
  129. =item B<BIO_ctrl(BIO *b, int cmd, long larg, void *parg)>
  130. callback_ex(b, BIO_CB_CTRL, parg, 0, cmd, larg, 1L, NULL)
  131. or
  132. callback(b, BIO_CB_CTRL, parg, cmd, larg, 1L)
  133. is called before the call and
  134. callback_ex(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, 0, cmd, larg, ret, NULL)
  135. or
  136. callback(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret)
  137. after.
  138. Note: B<cmd> == B<BIO_CTRL_SET_CALLBACK> is special, because B<parg> is not the
  139. argument of type B<BIO_info_cb> itself. In this case B<parg> is a pointer to
  140. the actual call parameter, see B<BIO_callback_ctrl>.
  141. =item B<BIO_sendmmsg(BIO *b, BIO_MSG *msg, size_t stride, size_t num_msg, uint64_t flags, size_t *msgs_processed)>
  142. callback_ex(b, BIO_CB_SENDMMSG, args, 0, 0, 0, 1, NULL)
  143. or
  144. callback(b, BIO_CB_SENDMMSG, args, 0, 0, 1)
  145. is called before the call and
  146. callback_ex(b, BIO_CB_SENDMMSG | BIO_CB_RETURN, args, ret, 0, 0, ret, NULL)
  147. or
  148. callback(b, BIO_CB_SENDMMSG | BIO_CB_RETURN, args, ret, 0, 0, ret)
  149. after.
  150. B<args> is a pointer to a B<BIO_MMSG_CB_ARGS> structure containing the arguments
  151. passed to BIO_sendmmsg(). B<ret> is the return value of the BIO_sendmmsg() call.
  152. The return value of BIO_sendmmsg() is altered to the value returned by the
  153. B<BIO_CB_SENDMMSG | BIO_CB_RETURN> call.
  154. =item B<BIO_recvmmsg(BIO *b, BIO_MSG *msg, size_t stride, size_t num_msg, uint64_t flags, size_t *msgs_processed)>
  155. See the documentation for BIO_sendmmsg(). BIO_recvmmsg() works identically
  156. except that B<BIO_CB_RECVMMSG> is used instead of B<BIO_CB_SENDMMSG>.
  157. =back
  158. =head1 RETURN VALUES
  159. BIO_get_callback_ex() and BIO_get_callback() return the callback function
  160. previously set by a call to BIO_set_callback_ex() and BIO_set_callback()
  161. respectively.
  162. BIO_get_callback_arg() returns a B<char> pointer to the value previously set
  163. via a call to BIO_set_callback_arg().
  164. BIO_debug_callback() returns 1 or B<ret> if it's called after specific BIO
  165. operations.
  166. =head1 EXAMPLES
  167. The BIO_debug_callback_ex() function is an example, its source is
  168. in crypto/bio/bio_cb.c
  169. =head1 HISTORY
  170. The BIO_debug_callback_ex() function was added in OpenSSL 3.0.
  171. BIO_set_callback(), BIO_get_callback(), and BIO_debug_callback() were
  172. deprecated in OpenSSL 3.0. Use the non-deprecated _ex functions instead.
  173. =head1 COPYRIGHT
  174. Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
  175. Licensed under the Apache License 2.0 (the "License"). You may not use
  176. this file except in compliance with the License. You can obtain a copy
  177. in the file LICENSE in the source distribution or at
  178. L<https://www.openssl.org/source/license.html>.
  179. =cut