• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ustream-ssl/ustream-io-wolfssl.c

  1 /*
  2  * ustream-ssl - library for SSL over ustream
  3  *
  4  * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
  5  *
  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.
  9  *
 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.
 17  */
 18 
 19 #include <string.h>
 20 
 21 #include <libubox/ustream.h>
 22 
 23 #include "ustream-ssl.h"
 24 #include "ustream-internal.h"
 25 
 26 static int s_ustream_read(char *buf, int len, void *ctx)
 27 {
 28         struct ustream *s = ctx;
 29         char *sbuf;
 30         int slen;
 31 
 32         if (s->eof)
 33                 return -3;
 34 
 35         sbuf = ustream_get_read_buf(s, &slen);
 36         if (slen > len)
 37                 slen = len;
 38 
 39         if (!slen)
 40                 return -2;
 41 
 42         memcpy(buf, sbuf, slen);
 43         ustream_consume(s, slen);
 44 
 45         return slen;
 46 }
 47 
 48 static int s_ustream_write(char *buf, int len, void *ctx)
 49 {
 50         struct ustream *s = ctx;
 51 
 52         if (s->write_error)
 53                 return len;
 54 
 55         return ustream_write(s, buf, len, false);
 56 }
 57 
 58 static int io_recv_cb(SSL* ssl, char *buf, int sz, void *ctx)
 59 {
 60         return s_ustream_read(buf, sz, ctx);
 61 }
 62 
 63 static int io_send_cb(SSL* ssl, char *buf, int sz, void *ctx)
 64 {
 65         return s_ustream_write(buf, sz, ctx);
 66 }
 67 
 68 __hidden void ustream_set_io(struct ustream_ssl *us)
 69 {
 70         if (!us->conn) {
 71                 wolfSSL_set_fd(us->ssl, us->fd.fd);
 72                 return;
 73         }
 74 
 75         wolfSSL_SSLSetIORecv(us->ssl, io_recv_cb);
 76         wolfSSL_SSLSetIOSend(us->ssl, io_send_cb);
 77         wolfSSL_SetIOReadCtx(us->ssl, us->conn);
 78         wolfSSL_SetIOWriteCtx(us->ssl, us->conn);
 79 }
 80 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt