]> git.sesse.net Git - vlc/blob - src/input/access.c
Sanitize input headers (pass 4).
[vlc] / src / input / access.c
1 /*****************************************************************************
2  * access.c
3  *****************************************************************************
4  * Copyright (C) 1999-2004 the VideoLAN team
5  * $Id$
6  *
7  * Author: Laurent Aimar <fenrir@via.ecp.fr>
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 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "access.h"
29 #include <libvlc.h>
30
31 /*****************************************************************************
32  * access_InternalNew:
33  *****************************************************************************/
34 static access_t *access_InternalNew( vlc_object_t *p_obj, const char *psz_access,
35                                       const char *psz_demux, const char *psz_path,
36                                       access_t *p_source )
37 {
38     static const char typename[] = "access";
39     access_t *p_access = vlc_custom_create( p_obj, sizeof (*p_access),
40                                             VLC_OBJECT_GENERIC, typename );
41
42     if( p_access == NULL )
43         return NULL;
44
45     /* Parse URL */
46     p_access->p_source = p_source;
47     if( p_source )
48     {
49         msg_Dbg( p_obj, "creating access filter '%s'", psz_access );
50     }
51     else
52     {
53         msg_Dbg( p_obj, "creating access '%s' path='%s'",
54                  psz_access, psz_path );
55         p_access->psz_path   = strdup( psz_path );
56     }
57     p_access->psz_access = strdup( psz_access );
58     p_access->psz_demux  = strdup( psz_demux );
59
60     p_access->pf_read    = NULL;
61     p_access->pf_block   = NULL;
62     p_access->pf_seek    = NULL;
63     p_access->pf_control = NULL;
64     p_access->p_sys      = NULL;
65     p_access->info.i_update = 0;
66     p_access->info.i_size   = 0;
67     p_access->info.i_pos    = 0;
68     p_access->info.b_eof    = false;
69     p_access->info.b_prebuffered = false;
70     p_access->info.i_title  = 0;
71     p_access->info.i_seekpoint = 0;
72
73
74     /* Before module_need (for var_Create...) */
75     vlc_object_attach( p_access, p_obj );
76
77     p_access->p_module =
78          module_need( p_access, p_source ? "access_filter" : "access",
79                       psz_access, true );
80
81     if( p_access->p_module == NULL )
82     {
83         vlc_object_detach( p_access );
84         free( p_access->psz_access );
85         free( p_access->psz_path );
86         free( p_access->psz_demux );
87         vlc_object_release( p_access );
88         return NULL;
89     }
90
91     return p_access;
92 }
93
94 /*****************************************************************************
95  * access_New:
96  *****************************************************************************/
97 access_t *__access_New( vlc_object_t *p_obj, const char *psz_access,
98                          const char *psz_demux, const char *psz_path )
99 {
100     return access_InternalNew( p_obj, psz_access, psz_demux,
101                                 psz_path, NULL );
102 }
103
104 /*****************************************************************************
105  * access_FilterNew:
106  *****************************************************************************/
107 access_t *access_FilterNew( access_t *p_source, const char *psz_access_filter )
108 {
109     return access_InternalNew( VLC_OBJECT(p_source), psz_access_filter,
110                                 p_source->psz_demux, p_source->psz_path,
111                                 p_source );
112 }
113
114 /*****************************************************************************
115  * access_Delete:
116  *****************************************************************************/
117 void access_Delete( access_t *p_access )
118 {
119     module_unneed( p_access, p_access->p_module );
120     vlc_object_detach( p_access );
121
122     free( p_access->psz_access );
123     free( p_access->psz_path );
124     free( p_access->psz_demux );
125
126     if( p_access->p_source )
127     {
128         access_Delete( p_access->p_source );
129     }
130
131     vlc_object_release( p_access );
132 }
133