Commit ab1c576e authored by Sebastian Dröge's avatar Sebastian Dröge

xdgmime: Add new typefinder based on xdgmime

This typefinder is mostly useful to filter out any false positives
by the other typefinders like the usual Word document misdetected as
MP3 file.
parent 27f19cf9
......@@ -124,6 +124,9 @@ dnl check for libm, for sin() etc.
AC_CHECK_LIBM
AC_SUBST(LIBM)
dnl needed for gst/xdgmime
AC_FUNC_MMAP
dnl *** checks for header files ***
AC_CHECK_HEADERS([unistd.h], HAVE_UNISTD_H=yes)
......@@ -282,6 +285,7 @@ AG_GST_CHECK_PLUGIN(tta)
AG_GST_CHECK_PLUGIN(valve)
AG_GST_CHECK_PLUGIN(videosignal)
AG_GST_CHECK_PLUGIN(vmnc)
AG_GST_CHECK_PLUGIN(xdgmime)
AG_GST_CHECK_PLUGIN(y4m)
dnl *** plug-ins to exclude ***
......@@ -1468,6 +1472,7 @@ gst/valve/Makefile
gst/videosignal/Makefile
gst/vmnc/Makefile
gst/real/Makefile
gst/xdgmime/Makefile
gst/y4m/Makefile
gst-libs/Makefile
gst-libs/gst/Makefile
......
plugin_LTLIBRARIES = libgstxdgmime.la
libgstxdgmime_la_SOURCES = gstxdgmime.c \
xdgmime/xdgmimealias.c \
xdgmime/xdgmime.c \
xdgmime/xdgmimecache.c \
xdgmime/xdgmimeglob.c \
xdgmime/xdgmimeicon.c \
xdgmime/xdgmimeint.c \
xdgmime/xdgmimemagic.c \
xdgmime/xdgmimeparent.c
libgstxdgmime_la_CFLAGS = $(GST_CFLAGS) -DXDG_PREFIX=gst_xdg_mime
libgstxdgmime_la_LIBADD = $(GST_LIBS)
libgstxdgmime_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstxdgmime_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = xdgmime/xdgmimealias.h \
xdgmime/xdgmimecache.h \
xdgmime/xdgmimeglob.h \
xdgmime/xdgmime.h \
xdgmime/xdgmimeicon.h \
xdgmime/xdgmimeint.h \
xdgmime/xdgmimemagic.h \
xdgmime/xdgmimeparent.h
EXTRA_DIST =
/* GStreamer
* Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gst/gst.h>
#include "xdgmime/xdgmime.h"
GST_DEBUG_CATEGORY (xdgmime_debug);
#define GST_CAT_DEFAULT xdgmime_debug
static void
xdgmime_typefind (GstTypeFind * find, gpointer user_data)
{
const gchar *mimetype;
gsize length = 16384;
guint64 tf_length;
gint prio;
guint8 *data;
GstCaps *caps;
if ((tf_length = gst_type_find_get_length (find)) > 0)
length = MIN (length, tf_length);
if ((data = gst_type_find_peek (find, 0, length)) == NULL)
return;
mimetype = xdg_mime_get_mime_type_for_data (data, length, &prio);
if (mimetype == NULL || g_str_equal (mimetype, XDG_MIME_TYPE_UNKNOWN))
return;
GST_DEBUG ("Got mimetype '%s' with prio %d", mimetype, prio);
caps = gst_caps_new_simple (mimetype, NULL);
gst_type_find_suggest (find, GST_TYPE_FIND_LIKELY, caps);
}
static gboolean
plugin_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (xdgmime_debug, "xdgmime", 0, "XDG-MIME");
return gst_type_find_register (plugin,
"xdgmime", GST_RANK_MARGINAL, xdgmime_typefind, NULL, NULL, NULL, NULL);
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"xdgmime",
"XDG-MIME",
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
This diff is collapsed.
/* -*- mode: C; c-file-style: "gnu" -*- */
/* xdgmime.h: XDG Mime Spec mime resolver. Based on version 0.11 of the spec.
*
* More info can be found at http://www.freedesktop.org/standards/
*
* Copyright (C) 2003 Red Hat, Inc.
* Copyright (C) 2003 Jonathan Blandford <jrb@alum.mit.edu>
*
* Licensed under the Academic Free License version 2.0
* Or under the following terms:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __XDG_MIME_H__
#define __XDG_MIME_H__
#include <stdlib.h>
#include <sys/stat.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef XDG_PREFIX
#define XDG_ENTRY(func) _XDG_ENTRY2(XDG_PREFIX,func)
#define _XDG_ENTRY2(prefix,func) _XDG_ENTRY3(prefix,func)
#define _XDG_ENTRY3(prefix,func) prefix##_##func
#define XDG_RESERVED_ENTRY(func) _XDG_RESERVED_ENTRY2(XDG_PREFIX,func)
#define _XDG_RESERVED_ENTRY2(prefix,func) _XDG_RESERVED_ENTRY3(prefix,func)
#define _XDG_RESERVED_ENTRY3(prefix,func) _##prefix##_##func
#endif
typedef void (*XdgMimeCallback) (void *user_data);
typedef void (*XdgMimeDestroy) (void *user_data);
#ifdef XDG_PREFIX
#define xdg_mime_get_mime_type_for_data XDG_ENTRY(get_mime_type_for_data)
#define xdg_mime_get_mime_type_for_file XDG_ENTRY(get_mime_type_for_file)
#define xdg_mime_get_mime_type_from_file_name XDG_ENTRY(get_mime_type_from_file_name)
#define xdg_mime_get_mime_types_from_file_name XDG_ENTRY(get_mime_types_from_file_name)
#define xdg_mime_is_valid_mime_type XDG_ENTRY(is_valid_mime_type)
#define xdg_mime_mime_type_equal XDG_ENTRY(mime_type_equal)
#define xdg_mime_media_type_equal XDG_ENTRY(media_type_equal)
#define xdg_mime_mime_type_subclass XDG_ENTRY(mime_type_subclass)
#define xdg_mime_get_mime_parents XDG_ENTRY(get_mime_parents)
#define xdg_mime_list_mime_parents XDG_ENTRY(list_mime_parents)
#define xdg_mime_unalias_mime_type XDG_ENTRY(unalias_mime_type)
#define xdg_mime_get_max_buffer_extents XDG_ENTRY(get_max_buffer_extents)
#define xdg_mime_shutdown XDG_ENTRY(shutdown)
#define xdg_mime_dump XDG_ENTRY(dump)
#define xdg_mime_register_reload_callback XDG_ENTRY(register_reload_callback)
#define xdg_mime_remove_callback XDG_ENTRY(remove_callback)
#define xdg_mime_type_unknown XDG_ENTRY(type_unknown)
#define xdg_mime_get_icon XDG_ENTRY(get_icon)
#define xdg_mime_get_generic_icon XDG_ENTRY(get_generic_icon)
#define _xdg_mime_mime_type_equal XDG_RESERVED_ENTRY(mime_type_equal)
#define _xdg_mime_mime_type_subclass XDG_RESERVED_ENTRY(mime_type_subclass)
#define _xdg_mime_unalias_mime_type XDG_RESERVED_ENTRY(unalias_mime_type)
#endif
extern const char xdg_mime_type_unknown[];
#define XDG_MIME_TYPE_UNKNOWN xdg_mime_type_unknown
const char *xdg_mime_get_mime_type_for_data (const void *data,
size_t len,
int *result_prio);
const char *xdg_mime_get_mime_type_for_file (const char *file_name,
struct stat *statbuf);
const char *xdg_mime_get_mime_type_from_file_name (const char *file_name);
int xdg_mime_get_mime_types_from_file_name(const char *file_name,
const char *mime_types[],
int n_mime_types);
int xdg_mime_is_valid_mime_type (const char *mime_type);
int xdg_mime_mime_type_equal (const char *mime_a,
const char *mime_b);
int xdg_mime_media_type_equal (const char *mime_a,
const char *mime_b);
int xdg_mime_mime_type_subclass (const char *mime_a,
const char *mime_b);
/* xdg_mime_get_mime_parents() is deprecated since it does
* not work correctly with caches. Use xdg_mime_list_parents()
* instead, but notice that that function expects you to free
* the array it returns.
*/
const char **xdg_mime_get_mime_parents (const char *mime);
char ** xdg_mime_list_mime_parents (const char *mime);
const char *xdg_mime_unalias_mime_type (const char *mime);
const char *xdg_mime_get_icon (const char *mime);
const char *xdg_mime_get_generic_icon (const char *mime);
int xdg_mime_get_max_buffer_extents (void);
void xdg_mime_shutdown (void);
void xdg_mime_dump (void);
int xdg_mime_register_reload_callback (XdgMimeCallback callback,
void *data,
XdgMimeDestroy destroy);
void xdg_mime_remove_callback (int callback_id);
/* Private versions of functions that don't call xdg_mime_init () */
int _xdg_mime_mime_type_equal (const char *mime_a,
const char *mime_b);
int _xdg_mime_mime_type_subclass (const char *mime,
const char *base);
const char *_xdg_mime_unalias_mime_type (const char *mime);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __XDG_MIME_H__ */
/* -*- mode: C; c-file-style: "gnu" -*- */
/* xdgmimealias.c: Private file. Datastructure for storing the aliases.
*
* More info can be found at http://www.freedesktop.org/standards/
*
* Copyright (C) 2004 Red Hat, Inc.
* Copyright (C) 2004 Matthias Clasen <mclasen@redhat.com>
*
* Licensed under the Academic Free License version 2.0
* Or under the following terms:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "xdgmimealias.h"
#include "xdgmimeint.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <fnmatch.h>
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
typedef struct XdgAlias XdgAlias;
struct XdgAlias
{
char *alias;
char *mime_type;
};
struct XdgAliasList
{
struct XdgAlias *aliases;
int n_aliases;
};
XdgAliasList *
_xdg_mime_alias_list_new (void)
{
XdgAliasList *list;
list = malloc (sizeof (XdgAliasList));
list->aliases = NULL;
list->n_aliases = 0;
return list;
}
void
_xdg_mime_alias_list_free (XdgAliasList * list)
{
int i;
if (list->aliases) {
for (i = 0; i < list->n_aliases; i++) {
free (list->aliases[i].alias);
free (list->aliases[i].mime_type);
}
free (list->aliases);
}
free (list);
}
static int
alias_entry_cmp (const void *v1, const void *v2)
{
return strcmp (((XdgAlias *) v1)->alias, ((XdgAlias *) v2)->alias);
}
const char *
_xdg_mime_alias_list_lookup (XdgAliasList * list, const char *alias)
{
XdgAlias *entry;
XdgAlias key;
if (list->n_aliases > 0) {
key.alias = (char *) alias;
key.mime_type = NULL;
entry = bsearch (&key, list->aliases, list->n_aliases,
sizeof (XdgAlias), alias_entry_cmp);
if (entry)
return entry->mime_type;
}
return NULL;
}
void
_xdg_mime_alias_read_from_file (XdgAliasList * list, const char *file_name)
{
FILE *file;
char line[255];
int alloc;
file = fopen (file_name, "r");
if (file == NULL)
return;
/* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars.
* Blah */
alloc = list->n_aliases + 16;
list->aliases = realloc (list->aliases, alloc * sizeof (XdgAlias));
while (fgets (line, 255, file) != NULL) {
char *sep;
if (line[0] == '#')
continue;
sep = strchr (line, ' ');
if (sep == NULL)
continue;
*(sep++) = '\000';
sep[strlen (sep) - 1] = '\000';
if (list->n_aliases == alloc) {
alloc <<= 1;
list->aliases = realloc (list->aliases, alloc * sizeof (XdgAlias));
}
list->aliases[list->n_aliases].alias = strdup (line);
list->aliases[list->n_aliases].mime_type = strdup (sep);
list->n_aliases++;
}
list->aliases = realloc (list->aliases, list->n_aliases * sizeof (XdgAlias));
fclose (file);
if (list->n_aliases > 1)
qsort (list->aliases, list->n_aliases, sizeof (XdgAlias), alias_entry_cmp);
}
void
_xdg_mime_alias_list_dump (XdgAliasList * list)
{
int i;
if (list->aliases) {
for (i = 0; i < list->n_aliases; i++) {
printf ("%s %s\n", list->aliases[i].alias, list->aliases[i].mime_type);
}
}
}
/* -*- mode: C; c-file-style: "gnu" -*- */
/* xdgmimealias.h: Private file. Datastructure for storing the aliases.
*
* More info can be found at http://www.freedesktop.org/standards/
*
* Copyright (C) 2004 Red Hat, Inc.
* Copyright (C) 200 Matthias Clasen <mclasen@redhat.com>
*
* Licensed under the Academic Free License version 2.0
* Or under the following terms:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __XDG_MIME_ALIAS_H__
#define __XDG_MIME_ALIAS_H__
#include "xdgmime.h"
typedef struct XdgAliasList XdgAliasList;
#ifdef XDG_PREFIX
#define _xdg_mime_alias_read_from_file XDG_RESERVED_ENTRY(alias_read_from_file)
#define _xdg_mime_alias_list_new XDG_RESERVED_ENTRY(alias_list_new)
#define _xdg_mime_alias_list_free XDG_RESERVED_ENTRY(alias_list_free)
#define _xdg_mime_alias_list_lookup XDG_RESERVED_ENTRY(alias_list_lookup)
#define _xdg_mime_alias_list_dump XDG_RESERVED_ENTRY(alias_list_dump)
#endif
void _xdg_mime_alias_read_from_file (XdgAliasList *list,
const char *file_name);
XdgAliasList *_xdg_mime_alias_list_new (void);
void _xdg_mime_alias_list_free (XdgAliasList *list);
const char *_xdg_mime_alias_list_lookup (XdgAliasList *list,
const char *alias);
void _xdg_mime_alias_list_dump (XdgAliasList *list);
#endif /* __XDG_MIME_ALIAS_H__ */
This diff is collapsed.
/* -*- mode: C; c-file-style: "gnu" -*- */
/* xdgmimecache.h: Private file. Datastructure for mmapped caches.
*
* More info can be found at http://www.freedesktop.org/standards/
*
* Copyright (C) 2005 Matthias Clasen <mclasen@redhat.com>
*
* Licensed under the Academic Free License version 2.0
* Or under the following terms:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __XDG_MIME_CACHE_H__
#define __XDG_MIME_CACHE_H__
#include "xdgmime.h"
typedef struct _XdgMimeCache XdgMimeCache;
#ifdef XDG_PREFIX
#define _xdg_mime_cache_new_from_file XDG_RESERVED_ENTRY(cache_new_from_file)
#define _xdg_mime_cache_ref XDG_RESERVED_ENTRY(cache_ref)
#define _xdg_mime_cache_unref XDG_RESERVED_ENTRY(cache_unref)
#define _xdg_mime_cache_get_max_buffer_extents XDG_RESERVED_ENTRY(cache_get_max_buffer_extents)
#define _xdg_mime_cache_get_mime_type_for_data XDG_RESERVED_ENTRY(cache_get_mime_type_for_data)
#define _xdg_mime_cache_get_mime_type_for_file XDG_RESERVED_ENTRY(cache_get_mime_type_for_file)
#define _xdg_mime_cache_get_mime_type_from_file_name XDG_RESERVED_ENTRY(cache_get_mime_type_from_file_name)
#define _xdg_mime_cache_get_mime_types_from_file_name XDG_RESERVED_ENTRY(cache_get_mime_types_from_file_name)
#define _xdg_mime_cache_list_mime_parents XDG_RESERVED_ENTRY(cache_list_mime_parents)
#define _xdg_mime_cache_mime_type_subclass XDG_RESERVED_ENTRY(cache_mime_type_subclass)
#define _xdg_mime_cache_unalias_mime_type XDG_RESERVED_ENTRY(cache_unalias_mime_type)
#define _xdg_mime_cache_get_icon XDG_RESERVED_ENTRY(cache_get_icon)
#define _xdg_mime_cache_get_generic_icon XDG_RESERVED_ENTRY(cache_get_generic_icon)
#define _xdg_mime_cache_glob_dump XDG_RESERVED_ENTRY(cache_glob_dump)
#endif
extern XdgMimeCache **_caches;
XdgMimeCache *_xdg_mime_cache_new_from_file (const char *file_name);
XdgMimeCache *_xdg_mime_cache_ref (XdgMimeCache *cache);
void _xdg_mime_cache_unref (XdgMimeCache *cache);
const char *_xdg_mime_cache_get_mime_type_for_data (const void *data,
size_t len,
int *result_prio);
const char *_xdg_mime_cache_get_mime_type_for_file (const char *file_name,
struct stat *statbuf);
int _xdg_mime_cache_get_mime_types_from_file_name (const char *file_name,
const char *mime_types[],
int n_mime_types);
const char *_xdg_mime_cache_get_mime_type_from_file_name (const char *file_name);
int _xdg_mime_cache_is_valid_mime_type (const char *mime_type);
int _xdg_mime_cache_mime_type_equal (const char *mime_a,
const char *mime_b);
int _xdg_mime_cache_media_type_equal (const char *mime_a,
const char *mime_b);
int _xdg_mime_cache_mime_type_subclass (const char *mime_a,
const char *mime_b);
char **_xdg_mime_cache_list_mime_parents (const char *mime);
const char *_xdg_mime_cache_unalias_mime_type (const char *mime);
int _xdg_mime_cache_get_max_buffer_extents (void);
const char *_xdg_mime_cache_get_icon (const char *mime);
const char *_xdg_mime_cache_get_generic_icon (const char *mime);
void _xdg_mime_cache_glob_dump (void);
#endif /* __XDG_MIME_CACHE_H__ */
This diff is collapsed.
/* -*- mode: C; c-file-style: "gnu" -*- */
/* xdgmimeglob.h: Private file. Datastructure for storing the globs.
*
* More info can be found at http://www.freedesktop.org/standards/
*
* Copyright (C) 2003 Red Hat, Inc.
* Copyright (C) 2003 Jonathan Blandford <jrb@alum.mit.edu>
*
* Licensed under the Academic Free License version 2.0
* Or under the following terms:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __XDG_MIME_GLOB_H__
#define __XDG_MIME_GLOB_H__
#include "xdgmime.h"
typedef struct XdgGlobHash XdgGlobHash;
typedef enum
{
XDG_GLOB_LITERAL, /* Makefile */
XDG_GLOB_SIMPLE, /* *.gif */
XDG_GLOB_FULL /* x*.[ch] */
} XdgGlobType;
#ifdef XDG_PREFIX
#define _xdg_mime_glob_read_from_file XDG_RESERVED_ENTRY(glob_read_from_file)
#define _xdg_glob_hash_new XDG_RESERVED_ENTRY(hash_new)
#define _xdg_glob_hash_free XDG_RESERVED_ENTRY(hash_free)
#define _xdg_glob_hash_lookup_file_name XDG_RESERVED_ENTRY(hash_lookup_file_name)
#define _xdg_glob_hash_append_glob XDG_RESERVED_ENTRY(hash_append_glob)
#define _xdg_glob_determine_type XDG_RESERVED_ENTRY(determine_type)
#define _xdg_glob_hash_dump XDG_RESERVED_ENTRY(hash_dump)
#endif
void _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash,
const char *file_name);
XdgGlobHash *_xdg_glob_hash_new (void);
void _xdg_glob_hash_free (XdgGlobHash *glob_hash);
int _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash,
const char *text,
const char *mime_types[],
int n_mime_types);
void _xdg_glob_hash_append_glob (XdgGlobHash *glob_hash,
const char *glob,
const char *mime_type,
int weight);
XdgGlobType _xdg_glob_determine_type (const char *glob);
void _xdg_glob_hash_dump (XdgGlobHash *glob_hash);
#endif /* __XDG_MIME_GLOB_H__ */
/* -*- mode: C; c-file-style: "gnu" -*- */
/* xdgmimeicon.c: Private file. Datastructure for storing the aliases.
*
* More info can be found at http://www.freedesktop.org/standards/
*
* Copyright (C) 2008 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.0
* Or under the following terms:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "xdgmimeicon.h"
#include "xdgmimeint.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <fnmatch.h>
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
typedef struct XdgIcon XdgIcon;
struct XdgIcon
{
char *mime_type;
char *icon_name;
};
struct XdgIconList
{
struct XdgIcon *icons;
int n_icons;
};
XdgIconList *
_xdg_mime_icon_list_new (void)
{
XdgIconList *list;
list = malloc (sizeof (XdgIconList));
list->icons = NULL;
list->n_icons = 0;
return list;
}
void
_xdg_mime_icon_list_free (XdgIconList * list)
{
int i;
if (list->icons) {
for (i = 0; i < list->n_icons; i++) {
free (list->icons[i].mime_type);
free (list->icons[i].icon_name);
}
free (list->icons);
}
free (list);
}
static int
icon_entry_cmp (const void *v1, const void *v2)
{
return strcmp (((XdgIcon *) v1)->mime_type, ((XdgIcon *) v2)->mime_type);
}
const char *
_xdg_mime_icon_list_lookup (XdgIconList * list, const char *mime_type)
{
XdgIcon *entry;
XdgIcon key;
if (list->n_icons > 0) {
key.mime_type = (char *) mime_type;
key.icon_name = NULL;
entry = bsearch (&key, list->icons, list->n_icons,
sizeof (XdgIcon), icon_entry_cmp);
if (entry)
return entry->icon_name;
}
return NULL;
}