Mercurial > audlegacy-plugins
comparison src/stdio/stdio.c @ 1921:31e9908cf91e
experimental patch to use libmagic for mimetype support
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sun, 30 Sep 2007 11:44:20 -0500 |
parents | 761e17b23e0c |
children | c276e2b74646 |
comparison
equal
deleted
inserted
replaced
1908:b37cea7ef4a9 | 1921:31e9908cf91e |
---|---|
25 #include <sys/stat.h> | 25 #include <sys/stat.h> |
26 #include <sys/types.h> | 26 #include <sys/types.h> |
27 | 27 |
28 #include <string.h> | 28 #include <string.h> |
29 | 29 |
30 #include <magic.h> | |
31 | |
30 static gchar * | 32 static gchar * |
31 vfs_stdio_urldecode_path(const gchar * encoded_path) | 33 vfs_stdio_urldecode_path(const gchar * encoded_path) |
32 { | 34 { |
33 const gchar *cur, *ext; | 35 const gchar *cur, *ext; |
34 gchar *path, *tmp; | 36 gchar *path, *tmp; |
247 return -1; | 249 return -1; |
248 | 250 |
249 return s.st_size; | 251 return s.st_size; |
250 } | 252 } |
251 | 253 |
254 static magic_t mdb_handle = NULL; | |
255 | |
256 gchar * | |
257 stdio_vfs_metadata_impl(VFSFile *file, const gchar *field) | |
258 { | |
259 if (!g_ascii_strcasecmp(field, "content-type")) | |
260 { | |
261 gchar *decpath; | |
262 const gchar *out; | |
263 | |
264 if (mdb_handle == NULL) | |
265 mdb_handle = magic_open(MAGIC_MIME); | |
266 | |
267 decpath = vfs_stdio_urldecode_path(file->uri); | |
268 out = magic_file(mdb_handle, decpath); | |
269 | |
270 return g_strdup(out); | |
271 } | |
272 | |
273 return NULL; | |
274 } | |
275 | |
252 VFSConstructor file_const = { | 276 VFSConstructor file_const = { |
253 "file://", | 277 "file://", |
254 stdio_vfs_fopen_impl, | 278 stdio_vfs_fopen_impl, |
255 stdio_vfs_fclose_impl, | 279 stdio_vfs_fclose_impl, |
256 stdio_vfs_fread_impl, | 280 stdio_vfs_fread_impl, |
260 stdio_vfs_fseek_impl, | 284 stdio_vfs_fseek_impl, |
261 stdio_vfs_rewind_impl, | 285 stdio_vfs_rewind_impl, |
262 stdio_vfs_ftell_impl, | 286 stdio_vfs_ftell_impl, |
263 stdio_vfs_feof_impl, | 287 stdio_vfs_feof_impl, |
264 stdio_vfs_truncate_impl, | 288 stdio_vfs_truncate_impl, |
265 stdio_vfs_fsize_impl | 289 stdio_vfs_fsize_impl, |
290 stdio_vfs_metadata_impl | |
266 }; | 291 }; |
267 | 292 |
268 static void init(void) | 293 static void init(void) |
269 { | 294 { |
270 vfs_register_transport(&file_const); | 295 vfs_register_transport(&file_const); |