#include <libubox/ustream.h>
#include "ustream-ssl.h"
+#include "openssl_bio_compat.h"
#include "ustream-internal.h"
static int
s_ustream_new(BIO *b)
{
- b->init = 1;
- b->num = 0;
- b->ptr = NULL;
- b->flags = 0;
+ BIO_set_init(b, 1);
+ BIO_set_data(b, NULL);
+ BIO_clear_flags(b, ~0);
return 1;
}
if (!b)
return 0;
- b->ptr = NULL;
- b->init = 0;
- b->flags = 0;
+ BIO_set_data(b, NULL);
+ BIO_set_init(b, 0);
+ BIO_clear_flags(b, ~0);
return 1;
}
static int
s_ustream_read(BIO *b, char *buf, int len)
{
- struct ustream *s;
+ struct bio_ctx *ctx;
char *sbuf;
int slen;
if (!buf || len <= 0)
return 0;
- s = (struct ustream *)b->ptr;
- if (!s)
+ ctx = (struct bio_ctx *)BIO_get_data(b);
+ if (!ctx || !ctx->stream)
return 0;
- sbuf = ustream_get_read_buf(s, &slen);
+ sbuf = ustream_get_read_buf(ctx->stream, &slen);
BIO_clear_retry_flags(b);
if (!slen) {
slen = len;
memcpy(buf, sbuf, slen);
- ustream_consume(s, slen);
+ ustream_consume(ctx->stream, slen);
return slen;
}
static int
s_ustream_write(BIO *b, const char *buf, int len)
{
- struct ustream *s;
+ struct bio_ctx *ctx;
if (!buf || len <= 0)
return 0;
- s = (struct ustream *)b->ptr;
- if (!s)
+ ctx = (struct bio_ctx *)BIO_get_data(b);
+ if (!ctx || !ctx->stream)
return 0;
- if (s->write_error)
+ if (ctx->stream->write_error)
return len;
- return ustream_write(s, buf, len, false);
+ return ustream_write(ctx->stream, buf, len, false);
}
static int
};
}
-static BIO_METHOD methods_ustream = {
- 100 | BIO_TYPE_SOURCE_SINK,
- "ustream",
- s_ustream_write,
- s_ustream_read,
- s_ustream_puts,
- s_ustream_gets,
- s_ustream_ctrl,
- s_ustream_new,
- s_ustream_free,
- NULL,
-};
-
static BIO *ustream_bio_new(struct ustream *s)
{
BIO *bio;
+ struct bio_ctx *ctx = calloc(1, sizeof(struct bio_ctx));
+
+ ctx->stream = s;
+ ctx->meth = BIO_meth_new(100 | BIO_TYPE_SOURCE_SINK, "ustream");
+
+ BIO_meth_set_write(ctx->meth, s_ustream_write);
+ BIO_meth_set_read(ctx->meth, s_ustream_read);
+ BIO_meth_set_puts(ctx->meth, s_ustream_puts);
+ BIO_meth_set_gets(ctx->meth, s_ustream_gets);
+ BIO_meth_set_ctrl(ctx->meth, s_ustream_ctrl);
+ BIO_meth_set_create(ctx->meth, s_ustream_new);
+ BIO_meth_set_destroy(ctx->meth, s_ustream_free);
+ bio = BIO_new(ctx->meth);
+ BIO_set_data(bio, ctx);
- bio = BIO_new(&methods_ustream);
- bio->ptr = s;
return bio;
}