ver
[libexssl.git] / include / libexssl / sslnet.h
blob509d48463baaac2f34153274af3e7b845e15bab9
1 #ifndef __SSLWNET_H__
2 #define __SSLWNET_H__
4 #include <errno.h>
5 #include <unistd.h>
6 #include <malloc.h>
7 #include <string.h>
8 #include <arpa/inet.h>
9 #include <sys/socket.h>
10 #include <sys/types.h>
11 #include <netinet/in.h>
12 #include <resolv.h>
13 #include <openssl/ssl.h>
14 #include <openssl/err.h>
15 #include <libex/str.h>
16 #include <libex/net.h>
17 #include <libex/wsnet.h>
19 #define FL_WSLOADEDHDR 0x00000002
20 #define FL_WSLOADEDLEN 0x00000004
21 #define FL_WSLOADEDMASK 0x00000008
22 #define FL_WSLOADED 0x00000010
24 #define SSL_CLIENT 0
25 #define SSL_SERVER 1
27 extern __thread int ssl_errno;
28 cstr_t *ssl_error ();
30 SSL_CTX *ssl_create (int kind);
31 int ssl_config (SSL_CTX *ctx, const char *cert_file, const char *key_file);
33 int ssl_accept (SSL_CTX *ctx, int fd, SSL **ssl);
34 int ssl_connect (SSL_CTX *ctx, int fd, SSL **ssl);
35 ssize_t ssl_recv (SSL *ssl, strbuf_t *buf);
36 ssize_t ssl_send (SSL *ssl, const void *buf, size_t size);
38 int sslws_handshake (SSL *ssl, strbuf_t *buf, strptr_t *url);
39 int sslws_recv (SSL *ssl, netbuf_t *nbuf, ws_t *result);
41 #define NF_SSLACCEPTED 0x80000000
42 typedef struct ssl_ev ssl_ev_t;
43 typedef struct ssl_srv ssl_srv_t;
45 struct ssl_ev {
46 DECLARE_EV;
47 SSL *ssl;
48 } __attribute__ ((aligned(64)));
49 int ssl_free_ev (int fd, net_srv_t *srv);
51 struct ssl_srv {
52 DECLARE_NET_SRV
53 SSL_CTX *ctx_cli;
54 SSL_CTX *ctx_srv;
56 #define SSLSRV_SIZE sizeof(ssl_srv_t)
57 #define SSLEV_SIZE sizeof(ssl_ev_t)
58 net_srv_t *sslws_srv_init_ex (const char *svc, size_t srv_size, size_t ev_size, const char *cert_file, const char *key_file);
59 static inline net_srv_t *sslws_srv_init (const char *svc, const char *cert_file, const char *key_file) {
60 return sslws_srv_init_ex(svc, sizeof(ssl_srv_t), sizeof(ssl_ev_t), cert_file, key_file);
62 void sslws_srv_done (net_srv_t *srv);
64 net_srv_t *sslws_jsonrpc_srv_init_ex (const char *svc, size_t srv_size, size_t ev_size, const char *cert_file, const char *key_file);
65 static inline net_srv_t *sslws_jsonrpc_srv_init (const char *svc, const char *cert_file, const char *key_file) {
66 return sslws_jsonrpc_srv_init_ex(svc, sizeof(ssl_srv_t), sizeof(ssl_ev_t), cert_file, key_file);
69 #endif