1787cd036fe46875e00b70b7e2bf24836554cfb7
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 /* not defined in the header file */
27 typedef int (*CallbackIORecv
)(char *buf
, int sz
, void *ctx
);
28 typedef int (*CallbackIOSend
)(char *buf
, int sz
, void *ctx
);
30 void SetCallbackIORecv_Ctx(SSL_CTX
*, CallbackIORecv
);
31 void SetCallbackIOSend_Ctx(SSL_CTX
*, CallbackIOSend
);
32 void SetCallbackIO_ReadCtx(SSL
* ssl
, void *rctx
);
33 void SetCallbackIO_WriteCtx(SSL
* ssl
, void *wctx
);
35 static int s_ustream_read(char *buf
, int len
, void *ctx
)
37 struct ustream
*s
= ctx
;
44 sbuf
= ustream_get_read_buf(s
, &slen
);
51 memcpy(buf
, sbuf
, slen
);
52 ustream_consume(s
, slen
);
57 static int s_ustream_write(char *buf
, int len
, void *ctx
)
59 struct ustream
*s
= ctx
;
61 return ustream_write(s
, buf
, len
, false);
64 __hidden
void ustream_set_io(void *ctx
, void *ssl
, struct ustream
*conn
)
66 SetCallbackIO_ReadCtx(ssl
, conn
);
67 SetCallbackIO_WriteCtx(ssl
, conn
);
68 SetCallbackIORecv_Ctx(ctx
, s_ustream_read
);
69 SetCallbackIOSend_Ctx(ctx
, s_ustream_write
);