2 * ustream-ssl - library for SSL over ustream
4 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <libubox/ustream.h>
23 #include "ustream-ssl.h"
24 #include "ustream-internal.h"
26 static int s_ustream_read(char *buf, int len, void *ctx)
28 struct ustream *s = ctx;
35 sbuf = ustream_get_read_buf(s, &slen);
42 memcpy(buf, sbuf, slen);
43 ustream_consume(s, slen);
48 static int s_ustream_write(char *buf, int len, void *ctx)
50 struct ustream *s = ctx;
55 return ustream_write(s, buf, len, false);
58 static int io_recv_cb(SSL* ssl, char *buf, int sz, void *ctx)
60 return s_ustream_read(buf, sz, ctx);
63 static int io_send_cb(SSL* ssl, char *buf, int sz, void *ctx)
65 return s_ustream_write(buf, sz, ctx);
68 __hidden void ustream_set_io(struct ustream_ssl_ctx *ctx, void *ssl, struct ustream *conn)
70 #ifndef NO_WOLFSSL_SSLSETIO_SEND_RECV
71 wolfSSL_SSLSetIORecv(ssl, io_recv_cb);
72 wolfSSL_SSLSetIOSend(ssl, io_send_cb);
74 wolfSSL_SetIORecv((void *) ctx, io_recv_cb);
75 wolfSSL_SetIOSend((void *) ctx, io_send_cb);
79 wolfSSL_SetIOReadCtx(ssl, conn);
80 wolfSSL_SetIOWriteCtx(ssl, conn);