1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
7 \brief Small utility to manage MIME types
16 #include <yaz/xmalloc.h>
20 struct yaz_mime_entry {
23 struct yaz_mime_entry *next;
26 struct yaz_mime_info {
27 struct yaz_mime_entry *table;
30 yaz_mime_types yaz_mime_types_create()
32 yaz_mime_types p = (yaz_mime_types) xmalloc(sizeof(*p));
37 void yaz_mime_types_add(yaz_mime_types t, const char *suffix,
38 const char *mime_type)
40 struct yaz_mime_entry *e = (struct yaz_mime_entry *) xmalloc(sizeof(*e));
41 e->mime_type = xstrdup(mime_type);
42 e->suffix = xstrdup(suffix);
47 const char *yaz_mime_lookup_suffix(yaz_mime_types t, const char *suffix)
49 struct yaz_mime_entry *e = t->table;
50 for (; e; e = e->next)
52 if (!strcmp(e->suffix, suffix))
58 const char *yaz_mime_lookup_fname(yaz_mime_types t, const char *fname)
60 const char *cp = strrchr(fname, '.');
61 if (!cp) /* if no . return now */
63 return yaz_mime_lookup_suffix(t, cp+1); /* skip . */
66 void yaz_mime_types_destroy(yaz_mime_types t)
68 struct yaz_mime_entry *e = t->table;
71 struct yaz_mime_entry *e_next = e->next;
83 * c-file-style: "Stroustrup"
84 * indent-tabs-mode: nil
86 * vim: shiftwidth=4 tabstop=8 expandtab