]> git.sesse.net Git - vlc/blob - src/misc/mime.c
build: create a macro to check for, and replace, possibly-inline functions.
[vlc] / src / misc / mime.c
1 /*****************************************************************************
2  * mime.c
3  *****************************************************************************
4  * Copyright © 2004-2012 VLC authors and VideoLAN
5  * Copyright © 2004-2007 Rémi Denis-Courmont
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Rémi Denis-Courmont <rem # videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_common.h>
30 #include <vlc_mime.h>
31
32 #include <string.h>
33
34 static const struct
35 {
36     const char psz_ext[8];
37     const char *psz_mime;
38 } ext_mime[] =
39 {
40     { ".htm",   "text/html" },
41     { ".html",  "text/html" },
42     { ".txt",   "text/plain" },
43     { ".xml",   "text/xml" },
44     { ".dtd",   "text/dtd" },
45
46     { ".css",   "text/css" },
47
48     /* image mime */
49     { ".gif",   "image/gif" },
50     { ".jpe",   "image/jpeg" },
51     { ".jpg",   "image/jpeg" },
52     { ".jpeg",  "image/jpeg" },
53     { ".png",   "image/png" },
54     { ".pct",   "image/x-pict" },
55     /* same as modules/mux/mpjpeg.c here: */
56     { ".mpjpeg","multipart/x-mixed-replace; boundary=7b3cc56e5f51db803f790dad720ed50a" },
57
58     /* media mime */
59     { ".avi",   "video/avi" },
60     { ".asf",   "video/x-ms-asf" },
61     { ".m1a",   "audio/mpeg" },
62     { ".m2a",   "audio/mpeg" },
63     { ".m1v",   "video/mpeg" },
64     { ".m2v",   "video/mpeg" },
65     { ".mp2",   "audio/mpeg" },
66     { ".mp3",   "audio/mpeg" },
67     { ".mpa",   "audio/mpeg" },
68     { ".mpg",   "video/mpeg" },
69     { ".mpeg",  "video/mpeg" },
70     { ".mpe",   "video/mpeg" },
71     { ".mov",   "video/quicktime" },
72     { ".moov",  "video/quicktime" },
73     { ".oga",   "audio/ogg" },
74     { ".ogg",   "application/ogg" },
75     { ".ogm",   "application/ogg" },
76     { ".ogv",   "video/ogg" },
77     { ".ogx",   "application/ogg" },
78     { ".opus",  "audio/ogg; codecs=opus" },
79     { ".spx",   "audio/ogg" },
80     { ".wav",   "audio/wav" },
81     { ".wma",   "audio/x-ms-wma" },
82     { ".wmv",   "video/x-ms-wmv" },
83     { ".webm",  "video/webm" },
84
85     /* end */
86     { "",       "" }
87 };
88
89 const char *vlc_mime_Ext2Mime( const char *psz_url )
90 {
91
92     char *psz_ext;
93
94     psz_ext = strrchr( psz_url, '.' );
95     if( psz_ext )
96     {
97         int i;
98
99         for( i = 0; ext_mime[i].psz_ext[0] ; i++ )
100         {
101             if( !strcasecmp( ext_mime[i].psz_ext, psz_ext ) )
102             {
103                 return ext_mime[i].psz_mime;
104             }
105         }
106     }
107     return "application/octet-stream";
108 }
109