BIO_set_callback.pod 6.5 KB

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