Remove the file:// URI decode hack
[vlc/asuraparaju-public.git] / modules / access / attachment.c
blobac5f3dae5b25ed2042317fe717e25a76d4106d31
1 /*****************************************************************************
2 * attachment.c: Input reading an attachment.
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
5 * $Id$
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_access.h>
35 #include <vlc_input.h>
37 /*****************************************************************************
38 * Module descriptor
39 *****************************************************************************/
40 static int Open (vlc_object_t *);
41 static void Close(vlc_object_t *);
43 vlc_module_begin()
44 set_shortname(N_("Attachment"))
45 set_description(N_("Attachment input"))
46 set_category(CAT_INPUT)
47 set_subcategory(SUBCAT_INPUT_ACCESS)
49 set_capability("access", 0)
50 add_shortcut("attachment")
51 set_callbacks(Open, Close)
52 vlc_module_end()
54 /*****************************************************************************
55 * Local prototypes
56 *****************************************************************************/
57 struct access_sys_t {
58 input_attachment_t *a;
61 static ssize_t Read(access_t *, uint8_t *, size_t);
62 static int Seek(access_t *, uint64_t);
63 static int Control(access_t *, int, va_list);
65 /* */
66 static int Open(vlc_object_t *object)
68 access_t *access = (access_t *)object;
69 access_sys_t *sys;
71 input_thread_t *input = access_GetParentInput(access);
72 if (!input)
73 return VLC_EGENERIC;
75 input_attachment_t *a;
76 if (input_Control(input, INPUT_GET_ATTACHMENT, &a, access->psz_location))
77 a = NULL;
79 vlc_object_release(input);
81 if (!a) {
82 msg_Err(access, "Failed to find the attachment '%s'",
83 access->psz_location);
84 return VLC_EGENERIC;
87 /* */
88 access->p_sys = sys = malloc(sizeof(*sys));
89 if (!sys) {
90 vlc_input_attachment_Delete(a);
91 return VLC_ENOMEM;
93 sys->a = a;
95 /* */
96 access_InitFields(access);
97 access->pf_read = Read;
98 access->pf_block = NULL;
99 access->pf_control = Control;
100 access->pf_seek = Seek;
102 return VLC_SUCCESS;
105 /* */
106 static void Close(vlc_object_t *object)
108 access_t *access = (access_t *)object;
109 access_sys_t *sys = access->p_sys;
111 vlc_input_attachment_Delete(sys->a);
112 free(sys);
115 /* */
116 static ssize_t Read(access_t *access, uint8_t *buffer, size_t size)
118 access_sys_t *sys = access->p_sys;
120 access->info.b_eof = access->info.i_pos >= sys->a->i_data;
121 if (access->info.b_eof)
122 return 0;
124 const size_t copy = __MIN(size, sys->a->i_data - access->info.i_pos);
125 memcpy(buffer, (uint8_t*)sys->a->p_data + access->info.i_pos, copy);
126 access->info.i_pos += copy;
127 return copy;
130 /* */
131 static int Seek(access_t *access, uint64_t position)
133 access->info.i_pos = position;
134 access->info.b_eof = false;
135 return VLC_SUCCESS;
138 /* */
139 static int Control(access_t *access, int query, va_list args)
141 VLC_UNUSED(access);
142 switch (query)
144 /* */
145 case ACCESS_CAN_SEEK:
146 case ACCESS_CAN_FASTSEEK:
147 case ACCESS_CAN_PAUSE:
148 case ACCESS_CAN_CONTROL_PACE: {
149 bool *b = va_arg(args, bool*);
150 *b = true;
151 return VLC_SUCCESS;
153 case ACCESS_GET_PTS_DELAY: {
154 int64_t *d = va_arg(args, int64_t *);
155 *d = DEFAULT_PTS_DELAY;
156 return VLC_SUCCESS;
158 case ACCESS_SET_PAUSE_STATE:
159 return VLC_SUCCESS;
161 default:
162 return VLC_EGENERIC;