Remove BIO_set_callback and friends. This is never used. Change-Id: I20498cab5b59ec141944d4a5e907a1164d0ae559 Reviewed-on: https://boringssl-review.googlesource.com/19184 Commit-Queue: Adam Langley <agl@google.com> Reviewed-by: Adam Langley <agl@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/crypto/bio/bio.c b/crypto/bio/bio.c index 4393a39..cffd05b 100644 --- a/crypto/bio/bio.c +++ b/crypto/bio/bio.c
@@ -96,13 +96,6 @@ return 0; } - if (bio->callback != NULL) { - int i = (int)bio->callback(bio, BIO_CB_FREE, NULL, 0, 0, 1); - if (i <= 0) { - return i; - } - } - next_bio = BIO_pop(bio); if (bio->method != NULL && bio->method->destroy != NULL) { @@ -127,56 +120,23 @@ BIO_free(bio); } -static int bio_io(BIO *bio, void *buf, int len, int callback_flags, - size_t *num) { - int i; - if (bio->callback != NULL) { - i = (int) bio->callback(bio, callback_flags, buf, len, 0L, 1L); - if (i <= 0) { - return i; - } - } - - if (!bio->init) { - OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED); - return -2; - } - - i = 0; - if (buf != NULL && len > 0) { - switch (callback_flags) { - case BIO_CB_READ: - i = bio->method->bread(bio, buf, len); - break; - case BIO_CB_GETS: - i = bio->method->bgets(bio, buf, len); - break; - case BIO_CB_WRITE: - i = bio->method->bwrite(bio, buf, len); - break; - default: - assert(0); - } - } - - if (i > 0) { - *num += i; - } - - if (bio->callback != NULL) { - i = (int)(bio->callback(bio, callback_flags | BIO_CB_RETURN, buf, len, 0L, - (long)i)); - } - - return i; -} - int BIO_read(BIO *bio, void *buf, int len) { if (bio == NULL || bio->method == NULL || bio->method->bread == NULL) { OPENSSL_PUT_ERROR(BIO, BIO_R_UNSUPPORTED_METHOD); return -2; } - return bio_io(bio, buf, len, BIO_CB_READ, &bio->num_read); + if (!bio->init) { + OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED); + return -2; + } + if (len <= 0) { + return 0; + } + int ret = bio->method->bread(bio, buf, len); + if (ret > 0) { + bio->num_read += ret; + } + return ret; } int BIO_gets(BIO *bio, char *buf, int len) { @@ -184,7 +144,18 @@ OPENSSL_PUT_ERROR(BIO, BIO_R_UNSUPPORTED_METHOD); return -2; } - return bio_io(bio, buf, len, BIO_CB_GETS, &bio->num_read); + if (!bio->init) { + OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED); + return -2; + } + if (len <= 0) { + return 0; + } + int ret = bio->method->bgets(bio, buf, len); + if (ret > 0) { + bio->num_read += ret; + } + return ret; } int BIO_write(BIO *bio, const void *in, int inl) { @@ -192,7 +163,18 @@ OPENSSL_PUT_ERROR(BIO, BIO_R_UNSUPPORTED_METHOD); return -2; } - return bio_io(bio, (char *)in, inl, BIO_CB_WRITE, &bio->num_write); + if (!bio->init) { + OPENSSL_PUT_ERROR(BIO, BIO_R_UNINITIALIZED); + return -2; + } + if (inl <= 0) { + return 0; + } + int ret = bio->method->bwrite(bio, in, inl); + if (ret > 0) { + bio->num_write += ret; + } + return ret; } int BIO_puts(BIO *bio, const char *in) { @@ -204,8 +186,6 @@ } long BIO_ctrl(BIO *bio, int cmd, long larg, void *parg) { - long ret; - if (bio == NULL) { return 0; } @@ -215,20 +195,7 @@ return -2; } - if (bio->callback != NULL) { - ret = bio->callback(bio, BIO_CB_CTRL, parg, cmd, larg, 1); - if (ret <= 0) { - return ret; - } - } - - ret = bio->method->ctrl(bio, cmd, larg, parg); - - if (bio->callback != NULL) { - ret = bio->callback(bio, BIO_CB_CTRL | BIO_CB_RETURN, parg, cmd, larg, ret); - } - - return ret; + return bio->method->ctrl(bio, cmd, larg, parg); } char *BIO_ptr_ctrl(BIO *b, int cmd, long larg) { @@ -313,9 +280,6 @@ } long BIO_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp) { - long ret; - bio_info_cb cb; - if (bio == NULL) { return 0; } @@ -325,22 +289,7 @@ return 0; } - cb = bio->callback; - - if (cb != NULL) { - ret = cb(bio, BIO_CB_CTRL, (void *)&fp, cmd, 0, 1L); - if (ret <= 0) { - return ret; - } - } - - ret = bio->method->callback_ctrl(bio, cmd, fp); - - if (cb != NULL) { - ret = cb(bio, BIO_CB_CTRL | BIO_CB_RETURN, (void *)&fp, cmd, 0, ret); - } - - return ret; + return bio->method->callback_ctrl(bio, cmd, fp); } size_t BIO_pending(const BIO *bio) { @@ -371,18 +320,6 @@ return BIO_ctrl(bio, BIO_CTRL_SET_CLOSE, close_flag, NULL); } -void BIO_set_callback(BIO *bio, bio_info_cb callback_func) { - bio->callback = callback_func; -} - -void BIO_set_callback_arg(BIO *bio, char *arg) { - bio->cb_arg = arg; -} - -char *BIO_get_callback_arg(const BIO *bio) { - return bio->cb_arg; -} - OPENSSL_EXPORT size_t BIO_number_read(const BIO *bio) { return bio->num_read; }
diff --git a/include/openssl/bio.h b/include/openssl/bio.h index 9a80cd5..aee58a2 100644 --- a/include/openssl/bio.h +++ b/include/openssl/bio.h
@@ -84,10 +84,9 @@ OPENSSL_EXPORT BIO *BIO_new(const BIO_METHOD *method); /* BIO_free decrements the reference count of |bio|. If the reference count - * drops to zero, it (optionally) calls the BIO's callback with |BIO_CB_FREE|, - * frees the ex_data and then, if the BIO has a destroy callback for the - * method, calls it. Finally it frees |bio| itself. It then repeats that for - * the next BIO in the chain, if any. + * drops to zero, it calls the destroy callback, if present, on the method and + * frees |bio| itself. It then repeats that for the next BIO in the chain, if + * any. * * It returns one on success or zero otherwise. */ OPENSSL_EXPORT int BIO_free(BIO *bio); @@ -248,18 +247,6 @@ * otherwise. */ OPENSSL_EXPORT int BIO_set_close(BIO *bio, int close_flag); -/* BIO_set_callback sets a callback function that will be called before and - * after most operations. See the comment above |bio_info_cb|. */ -OPENSSL_EXPORT void BIO_set_callback(BIO *bio, bio_info_cb callback_func); - -/* BIO_set_callback_arg sets the opaque pointer value that can be read within a - * callback with |BIO_get_callback_arg|. */ -OPENSSL_EXPORT void BIO_set_callback_arg(BIO *bio, char *arg); - -/* BIO_get_callback_arg returns the last value of the opaque callback pointer - * set by |BIO_set_callback_arg|. */ -OPENSSL_EXPORT char *BIO_get_callback_arg(const BIO *bio); - /* BIO_number_read returns the number of bytes that have been read from * |bio|. */ OPENSSL_EXPORT size_t BIO_number_read(const BIO *bio); @@ -714,9 +701,6 @@ struct bio_st { const BIO_METHOD *method; - /* bio, mode, argp, argi, argl, ret */ - long (*callback)(BIO *, int, const char *, int, long, long); - char *cb_arg; /* first argument for the callback */ /* init is non-zero if this |BIO| has been initialised. */ int init;