609140ecc86e1eeb45b58f2140186d7607bea0d6
[umurmur.git] / src / ssl.h
1 /* Copyright (C) 2009-2011, Martin Johansson <martin@fatbob.nu>
2    Copyright (C) 2005-2011, Thorvald Natvig <thorvald@natvig.com>
3
4    All rights reserved.
5
6    Redistribution and use in source and binary forms, with or without
7    modification, are permitted provided that the following conditions
8    are met:
9
10    - Redistributions of source code must retain the above copyright notice,
11      this list of conditions and the following disclaimer.
12    - Redistributions in binary form must reproduce the above copyright notice,
13      this list of conditions and the following disclaimer in the documentation
14      and/or other materials provided with the distribution.
15    - Neither the name of the Developers nor the names of its contributors may
16      be used to endorse or promote products derived from this software without
17      specific prior written permission.
18
19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
23    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef SSL_H_987698
33 #define SSL_H_987698
34
35 #ifdef USE_POLARSSL
36 #include <polarssl/ssl.h>
37 #else
38 #include <openssl/x509v3.h>
39 #include <openssl/ssl.h>
40 #endif
41
42 #include "types.h"
43 #include <inttypes.h>
44
45 #ifdef USE_POLARSSL
46 #define SSLI_ERROR_WANT_READ -0x0F300 /* PolarSSL uses -0x0f00 -> --0x0f90 */
47 #define SSLI_ERROR_WANT_WRITE -0x0F310
48 #define SSLI_ERROR_ZERO_RETURN POLARSSL_ERR_NET_CONN_RESET
49 #define SSLI_ERROR_CONNRESET POLARSSL_ERR_NET_CONN_RESET
50 #define SSLI_ERROR_SYSCALL POLARSSL_ERR_NET_RECV_FAILED
51
52 typedef ssl_context SSL_handle_t;
53
54 #else
55
56 #define SSLI_ERROR_WANT_READ SSL_ERROR_WANT_READ
57 #define SSLI_ERROR_WANT_WRITE SSL_ERROR_WANT_WRITE
58 #define SSLI_ERROR_ZERO_RETURN SSL_ERROR_ZERO_RETURN
59 #define SSLI_ERROR_CONNRESET SSL_ERROR_ZERO_RETURN
60 #define SSLI_ERROR_SYSCALL SSL_ERROR_SYSCALL
61
62 typedef SSL SSL_handle_t;
63
64 #endif
65
66 void SSLi_init(void);
67 void SSLi_deinit(void);
68 SSL_handle_t *SSLi_newconnection(int *fd, bool_t *SSLready);
69 void SSLi_closeconnection(SSL_handle_t *ssl);
70 int SSLi_nonblockaccept(SSL_handle_t *ssl, bool_t *SSLready);
71 int SSLi_read(SSL_handle_t *ssl, uint8_t *buf, int len);
72 int SSLi_write(SSL_handle_t *ssl, uint8_t *buf, int len);
73 int SSLi_get_error(SSL_handle_t *ssl, int code);
74 bool_t SSLi_data_pending(SSL_handle_t *ssl);
75 void SSLi_shutdown(SSL_handle_t *ssl);
76 void SSLi_free(SSL_handle_t *ssl);
77
78 #endif