]> git.sesse.net Git - vlc/blob - include/vlc_tls.h
A bit of headers cleanup
[vlc] / include / vlc_tls.h
1 /*****************************************************************************
2  * tls.c: TLS wrapper
3  *****************************************************************************
4  * Copyright (C) 2004-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: RĂ©mi Denis-Courmont <rem # videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef _VLC_TLS_H
25 # define _VLC_TLS_H
26
27 # include <vlc_network.h>
28
29 struct tls_t
30 {
31     VLC_COMMON_MEMBERS
32
33     /* Module properties */
34     module_t  *p_module;
35     void *p_sys;
36
37     tls_server_t * (*pf_server_create) ( tls_t *, const char *,
38                                          const char * );
39     tls_session_t * (*pf_client_create) ( tls_t * );
40 };
41
42 struct tls_server_t
43 {
44     VLC_COMMON_MEMBERS
45
46     void *p_sys;
47
48     void (*pf_delete) ( tls_server_t * );
49
50     int (*pf_add_CA) ( tls_server_t *, const char * );
51     int (*pf_add_CRL) ( tls_server_t *, const char * );
52
53     tls_session_t * (*pf_session_prepare) ( tls_server_t * );
54 };
55
56 struct tls_session_t
57 {
58     VLC_COMMON_MEMBERS
59
60     void *p_sys;
61
62     struct virtual_socket_t sock;
63     int (*pf_handshake) ( tls_session_t *, int, const char * );
64     int (*pf_handshake2) ( tls_session_t * );
65     void (*pf_close) ( tls_session_t * );
66 };
67
68
69 /*****************************************************************************
70  * tls_ServerCreate:
71  *****************************************************************************
72  * Allocates a whole server's TLS credentials.
73  * Returns NULL on error.
74  *****************************************************************************/
75 VLC_EXPORT( tls_server_t *, tls_ServerCreate, ( vlc_object_t *, const char *, const char * ) );
76
77 /*****************************************************************************
78  * tls_ServerAddCA:
79  *****************************************************************************
80  * Adds one or more certificate authorities.
81  * Returns -1 on error, 0 on success.
82  *****************************************************************************/
83 # define tls_ServerAddCA( a, b ) (((tls_server_t *)a)->pf_add_CA (a, b))
84
85
86 /*****************************************************************************
87  * tls_ServerAddCRL:
88  *****************************************************************************
89  * Adds a certificates revocation list to be sent to TLS clients.
90  * Returns -1 on error, 0 on success.
91  *****************************************************************************/
92 # define tls_ServerAddCRL( a, b ) (((tls_server_t *)a)->pf_add_CRL (a, b))
93
94
95 VLC_EXPORT( void, tls_ServerDelete, ( tls_server_t * ) );
96
97
98 # define tls_ServerSessionPrepare( a ) (((tls_server_t *)a)->pf_session_prepare (a))
99 # define tls_ServerSessionHandshake( a, b ) (((tls_session_t *)a)->pf_handshake (a, b, NULL))
100 # define tls_ServerSessionClose( a ) (((tls_session_t *)a)->pf_close (a))
101
102 VLC_EXPORT( tls_session_t *, tls_ClientCreate, ( vlc_object_t *, int, const char * ) );
103 VLC_EXPORT( void, tls_ClientDelete, ( tls_session_t * ) );
104
105 # define tls_ClientSessionHandshake( a, b, c ) (((tls_session_t *)a)->pf_handshake (a, b, c))
106
107 # define tls_SessionContinueHandshake( a ) (((tls_session_t *)a)->pf_handshake2 (a))
108
109
110 /* NOTE: It is assumed that a->sock.p_sys = a */
111 # define tls_Send( a, b, c ) (((tls_session_t *)a)->sock.pf_send (a, b, c ))
112
113 # define tls_Recv( a, b, c ) (((tls_session_t *)a)->sock.pf_recv (a, b, c ))
114
115 #endif