1
0

BIO_set_callback.pod 7.2 KB

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