BIO_set_callback.pod 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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, readbytes)
  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, readbytes)
  83. or
  84. callback(b, BIO_CB_READ|BIO_CB_RETURN, data, dlen, 0L, retvalue)
  85. after.
  86. =item B<BIO_write(b, data, dlen, written)>
  87. callback_ex(b, BIO_CB_WRITE, data, dlen, 0, 0L, 1L, written)
  88. or
  89. callback(b, BIO_CB_WRITE, datat, dlen, 0L, 1L)
  90. is called before the write and
  91. callback_ex(b, BIO_CB_WRITE | BIO_CB_RETURN, data, dlen, 0, 0L, retvalue, written)
  92. or
  93. callback(b, BIO_CB_WRITE|BIO_CB_RETURN, data, dlen, 0L, retvalue)
  94. after.
  95. =item B<BIO_gets(b, buf, size)>
  96. callback_ex(b, BIO_CB_GETS, buf, size, 0, 0L, 1, NULL, NULL)
  97. or
  98. callback(b, BIO_CB_GETS, buf, size, 0L, 1L)
  99. is called before the operation and
  100. callback_ex(b, BIO_CB_GETS | BIO_CB_RETURN, buf, size, 0, 0L, retvalue, readbytes)
  101. or
  102. callback(b, BIO_CB_GETS|BIO_CB_RETURN, buf, size, 0L, retvalue)
  103. after.
  104. =item B<BIO_puts(b, buf)>
  105. callback_ex(b, BIO_CB_PUTS, buf, 0, 0, 0L, 1L, NULL);
  106. or
  107. callback(b, BIO_CB_PUTS, buf, 0, 0L, 1L)
  108. is called before the operation and
  109. callback_ex(b, BIO_CB_PUTS | BIO_CB_RETURN, buf, 0, 0, 0L, retvalue, written)
  110. or
  111. callback(b, BIO_CB_WRITE|BIO_CB_RETURN, buf, 0, 0L, retvalue)
  112. after.
  113. =item B<BIO_ctrl(BIO *b, int cmd, long larg, void *parg)>
  114. callback_ex(b, BIO_CB_CTRL, parg, 0, cmd, larg, 1L, NULL)
  115. or
  116. callback(b, BIO_CB_CTRL, parg, cmd, larg, 1L)
  117. is called before the call and
  118. callback_ex(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, 0, cmd, larg, ret, NULL)
  119. or
  120. callback(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret)
  121. after.
  122. =back
  123. =head1 EXAMPLE
  124. The BIO_debug_callback() function is a good example, its source is
  125. in crypto/bio/bio_cb.c
  126. =head1 COPYRIGHT
  127. Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
  128. Licensed under the OpenSSL license (the "License"). You may not use
  129. this file except in compliance with the License. You can obtain a copy
  130. in the file LICENSE in the source distribution or at
  131. L<https://www.openssl.org/source/license.html>.
  132. =cut