]> git.sesse.net Git - vlc/blob - include/vlc_tls.h
Cleanup server name parameter handling
[vlc] / include / vlc_tls.h
1 /*****************************************************************************
2  * tls.c: Transport Layer Security API
3  *****************************************************************************
4  * Copyright (C) 2004-2007 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 #if !defined( __LIBVLC__ )
25   #error You are not libvlc or one of its plugins. You cannot include this file
26 #endif
27
28 #ifndef _VLC_TLS_H
29 # define _VLC_TLS_H
30
31 # include <vlc_network.h>
32
33 typedef struct tls_server_sys_t tls_server_sys_t;
34
35 struct tls_server_t
36 {
37     VLC_COMMON_MEMBERS
38
39     module_t  *p_module;
40     tls_server_sys_t *p_sys;
41
42     int (*pf_add_CA) ( tls_server_t *, const char * );
43     int (*pf_add_CRL) ( tls_server_t *, const char * );
44
45     tls_session_t * (*pf_session_prepare) ( tls_server_t * );
46 };
47
48 typedef struct tls_session_sys_t tls_session_sys_t;
49
50 struct tls_session_t
51 {
52     VLC_COMMON_MEMBERS
53
54     module_t  *p_module;
55     tls_session_sys_t *p_sys;
56
57     struct virtual_socket_t sock;
58     int (*pf_handshake) ( tls_session_t *, int );
59     int (*pf_handshake2) ( tls_session_t * );
60     void (*pf_close) ( tls_session_t * );
61 };
62
63
64 /*****************************************************************************
65  * tls_ServerCreate:
66  *****************************************************************************
67  * Allocates a whole server's TLS credentials.
68  * Returns NULL on error.
69  *****************************************************************************/
70 VLC_EXPORT( tls_server_t *, tls_ServerCreate, ( vlc_object_t *, const char *, const char * ) );
71
72 /*****************************************************************************
73  * tls_ServerAddCA:
74  *****************************************************************************
75  * Adds one or more certificate authorities.
76  * Returns -1 on error, 0 on success.
77  *****************************************************************************/
78 # define tls_ServerAddCA( a, b ) (((tls_server_t *)a)->pf_add_CA (a, b))
79
80
81 /*****************************************************************************
82  * tls_ServerAddCRL:
83  *****************************************************************************
84  * Adds a certificates revocation list to be sent to TLS clients.
85  * Returns -1 on error, 0 on success.
86  *****************************************************************************/
87 # define tls_ServerAddCRL( a, b ) (((tls_server_t *)a)->pf_add_CRL (a, b))
88
89
90 VLC_EXPORT( void, tls_ServerDelete, ( tls_server_t * ) );
91
92
93 # define tls_ServerSessionPrepare( a ) (((tls_server_t *)a)->pf_session_prepare (a))
94 # define tls_ServerSessionHandshake( a, b ) (((tls_session_t *)a)->pf_handshake (a, b))
95 # define tls_ServerSessionClose( a ) (((tls_session_t *)a)->pf_close (a))
96
97 VLC_EXPORT( tls_session_t *, tls_ClientCreate, ( vlc_object_t *, int, const char * ) );
98 VLC_EXPORT( void, tls_ClientDelete, ( tls_session_t * ) );
99
100 # define tls_ClientSessionHandshake( a, b ) (((tls_session_t *)a)->pf_handshake (a, b))
101
102 # define tls_SessionContinueHandshake( a ) (((tls_session_t *)a)->pf_handshake2 (a))
103
104
105 /* NOTE: It is assumed that a->sock.p_sys = a */
106 # define tls_Send( a, b, c ) (((tls_session_t *)a)->sock.pf_send (a, b, c ))
107
108 # define tls_Recv( a, b, c ) (((tls_session_t *)a)->sock.pf_recv (a, b, c ))
109
110 #endif