1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
7 \brief Small utility to manage MIME types
17 #include <yaz/xmalloc.h>
21 struct yaz_mime_entry {
24 struct yaz_mime_entry *next;
27 struct yaz_mime_info {
28 struct yaz_mime_entry *table;
31 yaz_mime_types yaz_mime_types_create()
33 yaz_mime_types p = (yaz_mime_types) xmalloc(sizeof(*p));
38 void yaz_mime_types_add(yaz_mime_types t, const char *suffix,
39 const char *mime_type)
41 struct yaz_mime_entry *e = (struct yaz_mime_entry *) xmalloc(sizeof(*e));
42 e->mime_type = xstrdup(mime_type);
43 e->suffix = xstrdup(suffix);
48 const char *yaz_mime_lookup_suffix(yaz_mime_types t, const char *suffix)
50 struct yaz_mime_entry *e = t->table;
51 for (; e; e = e->next)
53 if (!strcmp(e->suffix, suffix))
59 const char *yaz_mime_lookup_fname(yaz_mime_types t, const char *fname)
61 const char *cp = strrchr(fname, '.');
62 if (!cp) /* if no . return now */
64 return yaz_mime_lookup_suffix(t, cp+1); /* skip . */
67 void yaz_mime_types_destroy(yaz_mime_types t)
69 struct yaz_mime_entry *e = t->table;
72 struct yaz_mime_entry *e_next = e->next;
84 * c-file-style: "Stroustrup"
85 * indent-tabs-mode: nil
87 * vim: shiftwidth=4 tabstop=8 expandtab