]> git.sesse.net Git - vlc/blob - src/input/access.c
* access: init info field.
[vlc] / src / input / access.c
1 /*****************************************************************************
2  * access.c
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VideoLAN
5  * $Id: demux.c 7546 2004-04-29 13:53:29Z gbazin $
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include <stdlib.h>
25 #include <vlc/vlc.h>
26 #include <vlc/input.h>
27
28 #include "ninput.h"
29
30 int access_vaControl( input_thread_t *p_input, int i_query, va_list args )
31 {
32     if( p_input->pf_access_control )
33     {
34         return p_input->pf_access_control( p_input, i_query, args );
35     }
36     return VLC_EGENERIC;
37 }
38
39 int access_Control( input_thread_t *p_input, int i_query, ...  )
40 {
41     va_list args;
42     int     i_result;
43
44     va_start( args, i_query );
45     i_result = access_vaControl( p_input, i_query, args );
46     va_end( args );
47
48     return i_result;
49 }
50
51 int access_vaControlDefault( input_thread_t *p_input, int i_query, va_list args )
52 {
53     return VLC_EGENERIC;
54 }
55
56 /*****************************************************************************
57  * access2_New:
58  *****************************************************************************/
59 access_t *__access2_New( vlc_object_t *p_obj, char *psz_mrl )
60 {
61     access_t *p_access = vlc_object_create( p_obj, VLC_OBJECT_ACCESS );
62
63     char    *psz_dup = strdup( psz_mrl ? psz_mrl : "" );
64     char    *psz = strchr( psz_dup, ':' );
65
66     if( p_access == NULL )
67     {
68         msg_Err( p_obj, "vlc_object_create( p_obj, VLC_OBJECT_ACCESS ) had failed" );
69         free( psz_dup );
70         return NULL;
71     }
72
73     /* Parse URL */
74     p_access->psz_access = NULL;
75     p_access->psz_path   = NULL;
76
77     if( psz )
78     {
79         *psz++ = '\0';
80
81         if( psz[0] == '/' && psz[1] == '/' )
82         {
83             psz += 2;
84         }
85         p_access->psz_path = strdup( psz );
86
87         psz = strchr( psz_dup, '/' );
88         if( psz )
89         {
90             *psz++ = '\0';
91         }
92         p_access->psz_access = strdup( psz_dup );
93     }
94     else
95     {
96         p_access->psz_path = strdup( psz_mrl );
97     }
98     free( psz_dup );
99
100
101     p_access->psz_demux = strdup( "" );
102     if( p_access->psz_access == NULL )
103     {
104         p_access->psz_access = strdup( "" );
105     }
106     if( p_access->psz_path == NULL )
107     {
108         p_access->psz_path = strdup( "" );
109     }
110     msg_Dbg( p_obj, "access2_New: '%s' -> access='%s' path='%s'",
111              psz_mrl,
112              p_access->psz_access, p_access->psz_path );
113
114     p_access->pf_read    = NULL;
115     p_access->pf_block   = NULL;
116     p_access->pf_seek    = NULL;
117     p_access->pf_control = NULL;
118     p_access->p_sys      = NULL;
119     p_access->info.i_update = 0;
120     p_access->info.i_size   = 0;
121     p_access->info.i_pos    = 0;
122     p_access->info.b_eof    = VLC_FALSE;
123     p_access->info.i_title  = 0;
124     p_access->info.i_seekpoint = 0;
125
126
127     /* Before module_Need (for var_Create...) */
128     vlc_object_attach( p_access, p_obj );
129
130     p_access->p_module =
131         module_Need( p_access, "access2", p_access->psz_access, VLC_FALSE );
132
133     if( p_access->p_module == NULL )
134     {
135         vlc_object_detach( p_access );
136         free( p_access->psz_access );
137         free( p_access->psz_path );
138         free( p_access->psz_demux );
139         vlc_object_destroy( p_access );
140         return NULL;
141     }
142
143     return p_access;
144 }
145
146 /*****************************************************************************
147  * demux2_Delete:
148  *****************************************************************************/
149 void access2_Delete( access_t *p_access )
150 {
151     module_Unneed( p_access, p_access->p_module );
152     vlc_object_detach( p_access );
153
154     free( p_access->psz_access );
155     free( p_access->psz_path );
156     free( p_access->psz_demux );
157
158     vlc_object_destroy( p_access );
159 }