503
|
1 /* Audacious
|
|
2 * Copyright (c) 2007 William Pitcock
|
|
3 *
|
|
4 * This program is free software; you can redistribute it and/or modify
|
|
5 * it under the terms of the GNU General Public License as published by
|
|
6 * the Free Software Foundation; either version 2 of the License, or
|
|
7 * (at your option) any later version.
|
|
8 *
|
|
9 * This program is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 * GNU General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU General Public License
|
|
15 * along with this program; if not, write to the Free Software
|
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17 */
|
|
18
|
|
19 #include <glib.h>
|
|
20
|
|
21 #include <audacious/vfs.h>
|
|
22 #include <audacious/plugin.h>
|
|
23 #include <stdio.h>
|
|
24
|
|
25 #include <unistd.h>
|
|
26 #include <sys/stat.h>
|
|
27 #include <sys/types.h>
|
|
28
|
|
29 #include <string.h>
|
|
30 #include <errno.h>
|
|
31
|
|
32 #include <libmms/mms.h>
|
|
33
|
|
34 /*
|
|
35 * TODO:
|
|
36 * - mmsh:// support
|
|
37 */
|
|
38
|
|
39 typedef struct {
|
|
40 mms_t *mms;
|
|
41 GSList *charstack;
|
|
42 } MMSHandle;
|
|
43
|
|
44 VFSFile *
|
|
45 mms_vfs_fopen_impl(const gchar * path,
|
|
46 const gchar * mode)
|
|
47 {
|
|
48 VFSFile *file;
|
|
49 MMSHandle *handle;
|
|
50
|
|
51 if (!path || !mode)
|
|
52 return NULL;
|
|
53
|
|
54 file = g_new(VFSFile, 1);
|
|
55 handle = g_new0(MMSHandle, 1);
|
|
56
|
|
57 file->handle = handle;
|
|
58
|
|
59 if (file->handle == NULL) {
|
|
60 g_free(file);
|
|
61 file = NULL;
|
|
62 }
|
|
63
|
|
64 handle->mms = mms_connect(NULL, NULL, path, 128 * 1024);
|
|
65
|
|
66 if (handle->mms == NULL) {
|
|
67 g_free(handle);
|
|
68 g_free(file);
|
|
69 file = NULL;
|
|
70 }
|
|
71
|
|
72 return file;
|
|
73 }
|
|
74
|
|
75 gint
|
|
76 mms_vfs_fclose_impl(VFSFile * file)
|
|
77 {
|
|
78 gint ret = 0;
|
|
79
|
|
80 if (file == NULL)
|
|
81 return -1;
|
|
82
|
|
83 if (file->handle)
|
|
84 {
|
|
85 MMSHandle *handle = (MMSHandle *) file->handle;
|
|
86
|
|
87 mms_close(handle->mms);
|
|
88 g_free(handle);
|
|
89 }
|
|
90
|
|
91 return ret;
|
|
92 }
|
|
93
|
|
94 size_t
|
|
95 mms_vfs_fread_impl(gpointer ptr,
|
|
96 size_t size,
|
|
97 size_t nmemb,
|
|
98 VFSFile * file)
|
|
99 {
|
|
100 MMSHandle *handle;
|
|
101 gint ret;
|
|
102
|
|
103 if (file == NULL)
|
|
104 return 0;
|
|
105
|
|
106 handle = (MMSHandle *) file->handle;
|
|
107
|
|
108 ret = mms_read(NULL, handle->mms, ptr, size * nmemb);
|
|
109
|
|
110 if (ret < 0)
|
|
111 {
|
|
112 g_message("** mms **: errno(%d): %s", errno, strerror(errno));
|
|
113 ret = EOF;
|
|
114 }
|
|
115
|
|
116 return ret;
|
|
117 }
|
|
118
|
|
119 size_t
|
|
120 mms_vfs_fwrite_impl(gconstpointer ptr,
|
|
121 size_t size,
|
|
122 size_t nmemb,
|
|
123 VFSFile * file)
|
|
124 {
|
|
125 return -1;
|
|
126 }
|
|
127
|
|
128 gint
|
|
129 mms_vfs_getc_impl(VFSFile *stream)
|
|
130 {
|
|
131 MMSHandle *handle = (MMSHandle *) stream->handle;
|
|
132 guchar c;
|
|
133
|
|
134 if (handle->charstack != NULL)
|
|
135 {
|
|
136 c = GPOINTER_TO_UINT(handle->charstack->data);
|
|
137 handle->charstack = g_slist_remove_link(handle->charstack, handle->charstack);
|
|
138 return c;
|
|
139 }
|
|
140 else
|
|
141 {
|
|
142 mms_read(NULL, handle->mms, &c, 1);
|
|
143 return c;
|
|
144 }
|
|
145
|
|
146 return EOF;
|
|
147 }
|
|
148
|
|
149 gint
|
|
150 mms_vfs_ungetc_impl(gint c, VFSFile *stream)
|
|
151 {
|
|
152 MMSHandle *handle = (MMSHandle *) stream->handle;
|
|
153
|
|
154 handle->charstack = g_slist_append(handle->charstack, GUINT_TO_POINTER(c));
|
|
155
|
|
156 if (handle->charstack != NULL)
|
|
157 return c;
|
|
158
|
|
159 return EOF;
|
|
160 }
|
|
161
|
|
162 gint
|
|
163 mms_vfs_fseek_impl(VFSFile * file,
|
|
164 glong offset,
|
|
165 gint whence)
|
|
166 {
|
|
167 return -1;
|
|
168 }
|
|
169
|
|
170 void
|
|
171 mms_vfs_rewind_impl(VFSFile * file)
|
|
172 {
|
|
173 return;
|
|
174 }
|
|
175
|
|
176 glong
|
|
177 mms_vfs_ftell_impl(VFSFile * file)
|
|
178 {
|
|
179 MMSHandle *handle = (MMSHandle *) file->handle;
|
|
180
|
|
181 return mms_get_current_pos(handle->mms);
|
|
182 }
|
|
183
|
|
184 gboolean
|
|
185 mms_vfs_feof_impl(VFSFile * file)
|
|
186 {
|
|
187 MMSHandle *handle = (MMSHandle *) file->handle;
|
|
188
|
|
189 return (gboolean) (mms_get_current_pos(handle->mms) ==
|
|
190 mms_get_length(handle->mms));
|
|
191 }
|
|
192
|
|
193 gint
|
|
194 mms_vfs_truncate_impl(VFSFile * file, glong size)
|
|
195 {
|
|
196 return -1;
|
|
197 }
|
|
198
|
965
|
199 off_t
|
|
200 mms_vfs_fsize_impl(VFSFile * file)
|
|
201 {
|
|
202 return -1;
|
|
203 }
|
|
204
|
503
|
205 VFSConstructor mms_const = {
|
|
206 "mms://",
|
|
207 mms_vfs_fopen_impl,
|
|
208 mms_vfs_fclose_impl,
|
|
209 mms_vfs_fread_impl,
|
|
210 mms_vfs_fwrite_impl,
|
|
211 mms_vfs_getc_impl,
|
|
212 mms_vfs_ungetc_impl,
|
|
213 mms_vfs_fseek_impl,
|
|
214 mms_vfs_rewind_impl,
|
|
215 mms_vfs_ftell_impl,
|
|
216 mms_vfs_feof_impl,
|
965
|
217 mms_vfs_truncate_impl,
|
|
218 mms_vfs_fsize_impl
|
503
|
219 };
|
|
220
|
|
221 static void init(void)
|
|
222 {
|
|
223 vfs_register_transport(&mms_const);
|
|
224 }
|
|
225
|
|
226 static void cleanup(void)
|
|
227 {
|
|
228 #if 0
|
|
229 vfs_unregister_transport(&mms_const);
|
|
230 #endif
|
|
231 }
|
|
232
|
|
233 LowlevelPlugin llp_mms = {
|
|
234 NULL,
|
|
235 NULL,
|
|
236 "mms:// URI Transport",
|
|
237 init,
|
|
238 cleanup,
|
|
239 };
|
|
240
|
|
241 LowlevelPlugin *get_lplugin_info(void)
|
|
242 {
|
|
243 return &llp_mms;
|
|
244 }
|
|
245
|