]> git.sesse.net Git - vlc/blob - include/vlc_tls.h
Fix TLS session cleanup
[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_open)  ( tls_server_t * );
46     void            (*pf_close) ( tls_server_t *, tls_session_t * );
47 };
48
49 typedef struct tls_session_sys_t tls_session_sys_t;
50
51 struct tls_session_t
52 {
53     VLC_COMMON_MEMBERS
54
55     module_t  *p_module;
56     tls_session_sys_t *p_sys;
57
58     struct virtual_socket_t sock;
59     void (*pf_set_fd) ( tls_session_t *, int );
60     int  (*pf_handshake) ( tls_session_t * );
61 };
62
63
64 tls_server_t *tls_ServerCreate (vlc_object_t *, const char *, const char *);
65 void tls_ServerDelete (tls_server_t *);
66 int tls_ServerAddCA (tls_server_t *srv, const char *path);
67 int tls_ServerAddCRL (tls_server_t *srv, const char *path);
68
69 tls_session_t *tls_ServerSessionPrepare (tls_server_t *);
70 int tls_ServerSessionHandshake (tls_session_t *, int fd);
71 int tls_SessionContinueHandshake (tls_session_t *);
72 void tls_ServerSessionClose (tls_session_t *);
73
74 VLC_EXPORT( tls_session_t *, tls_ClientCreate, ( vlc_object_t *, int, const char * ) );
75 VLC_EXPORT( void, tls_ClientDelete, ( tls_session_t * ) );
76
77 /* NOTE: It is assumed that a->sock.p_sys = a */
78 # define tls_Send( a, b, c ) (((tls_session_t *)a)->sock.pf_send (a, b, c ))
79
80 # define tls_Recv( a, b, c ) (((tls_session_t *)a)->sock.pf_recv (a, b, c ))
81
82 #endif