diff options
Diffstat (limited to 'crypto/comp')
-rw-r--r-- | crypto/comp/c_zlib.c | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/crypto/comp/c_zlib.c b/crypto/comp/c_zlib.c index 07c45d0dfc..68b9da78be 100644 --- a/crypto/comp/c_zlib.c +++ b/crypto/comp/c_zlib.c @@ -58,7 +58,8 @@ #include <openssl/objects.h> #include <openssl/comp.h> #include <openssl/err.h> -#include <internal/cryptlib_int.h> +#include "internal/cryptlib_int.h" +#include "internal/bio.h" #include "comp_lcl.h" COMP_METHOD *COMP_zlib(void); @@ -371,9 +372,9 @@ static int bio_zlib_new(BIO *bi) ctx->zout.zalloc = Z_NULL; ctx->zout.zfree = Z_NULL; ctx->comp_level = Z_DEFAULT_COMPRESSION; - bi->init = 1; - bi->ptr = (char *)ctx; - bi->flags = 0; + BIO_set_init(bi, 1); + BIO_set_data(bi, ctx); + return 1; } @@ -382,7 +383,7 @@ static int bio_zlib_free(BIO *bi) BIO_ZLIB_CTX *ctx; if (!bi) return 0; - ctx = (BIO_ZLIB_CTX *) bi->ptr; + ctx = BIO_get_data(bi); if (ctx->ibuf) { /* Destroy decompress context */ inflateEnd(&ctx->zin); @@ -394,9 +395,9 @@ static int bio_zlib_free(BIO *bi) OPENSSL_free(ctx->obuf); } OPENSSL_free(ctx); - bi->ptr = NULL; - bi->init = 0; - bi->flags = 0; + BIO_set_data(bi, NULL); + BIO_set_init(bi, 0); + return 1; } @@ -405,9 +406,11 @@ static int bio_zlib_read(BIO *b, char *out, int outl) BIO_ZLIB_CTX *ctx; int ret; z_stream *zin; + BIO *next = BIO_next(b); + if (!out || !outl) return 0; - ctx = (BIO_ZLIB_CTX *) b->ptr; + ctx = BIO_get_data(b); zin = &ctx->zin; BIO_clear_retry_flags(b); if (!ctx->ibuf) { @@ -442,7 +445,7 @@ static int bio_zlib_read(BIO *b, char *out, int outl) * No data in input buffer try to read some in, if an error then * return the total data read. */ - ret = BIO_read(b->next_bio, ctx->ibuf, ctx->ibufsize); + ret = BIO_read(next, ctx->ibuf, ctx->ibufsize); if (ret <= 0) { /* Total data read */ int tot = outl - zin->avail_out; @@ -461,9 +464,11 @@ static int bio_zlib_write(BIO *b, const char *in, int inl) BIO_ZLIB_CTX *ctx; int ret; z_stream *zout; + BIO *next = BIO_next(b); + if (!in || !inl) return 0; - ctx = (BIO_ZLIB_CTX *) b->ptr; + ctx = BIO_get_data(b); if (ctx->odone) return 0; zout = &ctx->zout; @@ -487,7 +492,7 @@ static int bio_zlib_write(BIO *b, const char *in, int inl) for (;;) { /* If data in output buffer write it first */ while (ctx->ocount) { - ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount); + ret = BIO_write(next, ctx->optr, ctx->ocount); if (ret <= 0) { /* Total data written */ int tot = inl - zout->avail_in; @@ -526,7 +531,9 @@ static int bio_zlib_flush(BIO *b) BIO_ZLIB_CTX *ctx; int ret; z_stream *zout; - ctx = (BIO_ZLIB_CTX *) b->ptr; + BIO *next = BIO_next(b); + + ctx = BIO_get_data(b); /* If no data written or already flush show success */ if (!ctx->obuf || (ctx->odone && !ctx->ocount)) return 1; @@ -538,7 +545,7 @@ static int bio_zlib_flush(BIO *b) for (;;) { /* If data in output buffer write it first */ while (ctx->ocount) { - ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount); + ret = BIO_write(next, ctx->optr, ctx->ocount); if (ret <= 0) { BIO_copy_next_retry(b); return ret; @@ -573,9 +580,11 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr) BIO_ZLIB_CTX *ctx; int ret, *ip; int ibs, obs; - if (!b->next_bio) + BIO *next = BIO_next(b); + + if (next == NULL) return 0; - ctx = (BIO_ZLIB_CTX *) b->ptr; + ctx = BIO_get_data(b); switch (cmd) { case BIO_CTRL_RESET: @@ -587,7 +596,7 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr) case BIO_CTRL_FLUSH: ret = bio_zlib_flush(b); if (ret > 0) - ret = BIO_flush(b->next_bio); + ret = BIO_flush(next); break; case BIO_C_SET_BUFF_SIZE: @@ -620,12 +629,12 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr) case BIO_C_DO_STATE_MACHINE: BIO_clear_retry_flags(b); - ret = BIO_ctrl(b->next_bio, cmd, num, ptr); + ret = BIO_ctrl(next, cmd, num, ptr); BIO_copy_next_retry(b); break; default: - ret = BIO_ctrl(b->next_bio, cmd, num, ptr); + ret = BIO_ctrl(next, cmd, num, ptr); break; } @@ -635,9 +644,10 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr) static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) { - if (!b->next_bio) + BIO *next = BIO_next(b); + if (next == NULL) return 0; - return BIO_callback_ctrl(b->next_bio, cmd, fp); + return BIO_callback_ctrl(next, cmd, fp); } #endif |