]> git.sesse.net Git - vlc/blob - src/input/access.c
Fix comment
[vlc] / src / input / access.c
1 /*****************************************************************************
2  * access.c
3  *****************************************************************************
4  * Copyright (C) 1999-2008 the VideoLAN team
5  * $Id$
6  *
7  * Author: Laurent Aimar <fenrir _AT_ videolan _DOT_ 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 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "access.h"
29 #include <libvlc.h>
30 #include <vlc_url.h>
31
32 /* Decode URL (which has had its scheme stripped earlier) to a file path. */
33 static char *get_path(const char *location)
34 {
35     char *url, *path;
36
37     /* Prepending "file://" is a bit hackish. But then again, we do not want
38      * to hard-code the list of schemes that use file paths in make_path().
39      */
40     if (asprintf(&url, "file://%s", location) == -1)
41         return NULL;
42
43     path = make_path (url);
44     free (url);
45     return path;
46 }
47
48 /*****************************************************************************
49  * access_New:
50  *****************************************************************************/
51 access_t *__access_New( vlc_object_t *p_obj, input_thread_t *p_parent_input,
52                         const char *psz_access, const char *psz_demux,
53                         const char *psz_location )
54 {
55     access_t *p_access = vlc_custom_create( p_obj, sizeof (*p_access),
56                                             VLC_OBJECT_GENERIC, "access" );
57
58     if( p_access == NULL )
59         return NULL;
60
61     /* */
62
63     p_access->p_input = p_parent_input;
64
65     p_access->psz_access = strdup( psz_access );
66     p_access->psz_location = strdup( psz_location );
67     p_access->psz_filepath = get_path( psz_location );
68     p_access->psz_demux  = strdup( psz_demux );
69
70     msg_Dbg( p_obj, "creating access '%s' location='%s', path='%s'",
71              psz_access, psz_location, p_access->psz_filepath );
72
73     p_access->pf_read    = NULL;
74     p_access->pf_block   = NULL;
75     p_access->pf_seek    = NULL;
76     p_access->pf_control = NULL;
77     p_access->p_sys      = NULL;
78
79     access_InitFields( p_access );
80
81     /* Before module_need (for var_Create...) */
82     vlc_object_attach( p_access, p_obj );
83
84     p_access->p_module = module_need( p_access, "access", psz_access, true );
85
86     if( p_access->p_module == NULL )
87     {
88         free( p_access->psz_access );
89         free( p_access->psz_location );
90         free( p_access->psz_filepath );
91         free( p_access->psz_demux );
92         vlc_object_release( p_access );
93         return NULL;
94     }
95
96     return p_access;
97 }
98
99 /*****************************************************************************
100  * access_Delete:
101  *****************************************************************************/
102 void access_Delete( access_t *p_access )
103 {
104     module_unneed( p_access, p_access->p_module );
105
106     free( p_access->psz_access );
107     free( p_access->psz_location );
108     free( p_access->psz_filepath );
109     free( p_access->psz_demux );
110
111     vlc_object_release( p_access );
112 }
113
114
115 /*****************************************************************************
116  * access_GetParentInput:
117  *****************************************************************************/
118 input_thread_t * access_GetParentInput( access_t *p_access )
119 {
120     return p_access->p_input ? vlc_object_hold((vlc_object_t *)p_access->p_input) : NULL;
121 }
122