BRL-CAD
mime.h
Go to the documentation of this file.
1/* M I M E . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2023 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21#ifndef BU_MIME_H
22#define BU_MIME_H
23
24#include "common.h"
25
26#include "bu/defines.h"
27#include "bu/mime_types.h"
28
29
30__BEGIN_DECLS
31
32/** @addtogroup bu_mime
33 *
34 * @brief
35 * Functions generated by the mime.cmake script - see the
36 * generated files mime.c and mime_types.h for the resulting C code
37 * and mime type declarations
38 *
39 * Standard types are maintained in misc/mime.types - that file
40 * is a copy of the Apache file and is not changed locally:
41 * http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
42 *
43 * Customizations for BRL-CAD are maintained in misc/mime_cad.types
44 * and any types not covered by the standard mime set (such as
45 * the majority of geometry formats) are added there instead of
46 * changing mime.types.
47 */
48/** @{ */
49/** @file bu/mime.h */
50
51/**
52 * @brief Use the file extension to attempt to determine the media type
53 * of the file within the specified context.
54 *
55 * returns -1 if no match was found, or an integer if a result
56 * was found. It is the responsibility of the caller to cast
57 * the return int to the correct mime_CONTEXT_t type.
58 */
59BU_EXPORT extern int bu_file_mime(const char *ext, bu_mime_context_t context);
60
61
62/**
63 * @brief Given a mime type and a context, return the file extension(s)
64 * associated with that type.
65 *
66 * returns NULL if no match was found, or a comma separated string
67 * containing the extensions if a result was found.
68 * It is the responsibility of the caller to free the returned string.
69 */
70BU_EXPORT extern const char *bu_file_mime_ext(int t, bu_mime_context_t context);
71
72
73/**
74 * @brief Given a mime type and a context, return a human readable string
75 * spelling out the type (corresponding to the enum string in
76 * source code.)
77 *
78 * returns NULL if no match was found, or a string if a result was found.
79 * It is the responsibility of the caller to free the returned string.
80 */
81BU_EXPORT extern const char *bu_file_mime_str(int t, bu_mime_context_t context);
82
83
84/**
85 * @brief Given a string produced by bu_file_mime_str, convert it back into
86 * integer form.
87 *
88 * returns -1 if no match was found, or an integer if a result
89 * was found. It is the responsibility of the caller to cast
90 * the return int to the correct mime_CONTEXT_t type.
91 */
92BU_EXPORT extern int bu_file_mime_int(const char *str);
93
94
95/** @} */
96
97__END_DECLS
98
99#endif /* BU_MIME_H */
100
101/*
102 * Local Variables:
103 * mode: C
104 * tab-width: 8
105 * indent-tabs-mode: t
106 * c-file-style: "stroustrup"
107 * End:
108 * ex: shiftwidth=4 tabstop=8
109 */
Header file for the BRL-CAD common definitions.
int bu_file_mime(const char *ext, bu_mime_context_t context)
Use the file extension to attempt to determine the media type of the file within the specified contex...
const char * bu_file_mime_ext(int t, bu_mime_context_t context)
Given a mime type and a context, return the file extension(s) associated with that type.
int bu_file_mime_int(const char *str)
Given a string produced by bu_file_mime_str, convert it back into integer form.
const char * bu_file_mime_str(int t, bu_mime_context_t context)
Given a mime type and a context, return a human readable string spelling out the type (corresponding ...