# HG changeset patch # User William Pitcock # Date 1191170660 18000 # Node ID 31e9908cf91e66b59d4c7fce46c7fa44ce6af89e # Parent b37cea7ef4a9b0f330673eae777b85d877084a35 experimental patch to use libmagic for mimetype support diff -r b37cea7ef4a9 -r 31e9908cf91e src/stdio/Makefile --- a/src/stdio/Makefile Thu Sep 27 13:06:17 2007 -0500 +++ b/src/stdio/Makefile Sun Sep 30 11:44:20 2007 -0500 @@ -8,4 +8,4 @@ CPPFLAGS += ${PLUGIN_CPPFLAGS} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${PANGO_CFLAGS} ${ARCH_DEFINES} ${XML_CPPFLAGS} -I../../intl -I../.. CFLAGS += ${PLUGIN_CFLAGS} -LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${XML_LIBS} +LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${XML_LIBS} -lmagic diff -r b37cea7ef4a9 -r 31e9908cf91e src/stdio/stdio.c --- a/src/stdio/stdio.c Thu Sep 27 13:06:17 2007 -0500 +++ b/src/stdio/stdio.c Sun Sep 30 11:44:20 2007 -0500 @@ -27,6 +27,8 @@ #include +#include + static gchar * vfs_stdio_urldecode_path(const gchar * encoded_path) { @@ -249,6 +251,28 @@ return s.st_size; } +static magic_t mdb_handle = NULL; + +gchar * +stdio_vfs_metadata_impl(VFSFile *file, const gchar *field) +{ + if (!g_ascii_strcasecmp(field, "content-type")) + { + gchar *decpath; + const gchar *out; + + if (mdb_handle == NULL) + mdb_handle = magic_open(MAGIC_MIME); + + decpath = vfs_stdio_urldecode_path(file->uri); + out = magic_file(mdb_handle, decpath); + + return g_strdup(out); + } + + return NULL; +} + VFSConstructor file_const = { "file://", stdio_vfs_fopen_impl, @@ -262,7 +286,8 @@ stdio_vfs_ftell_impl, stdio_vfs_feof_impl, stdio_vfs_truncate_impl, - stdio_vfs_fsize_impl + stdio_vfs_fsize_impl, + stdio_vfs_metadata_impl }; static void init(void)