mirror of https://code.videolan.org/videolan/vlc
Move mime type guessing by extension to separate file and export it
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
This commit is contained in:
parent
1cbac3d871
commit
0df51d03d9
|
@ -118,6 +118,7 @@ set( SOURCES_libvlccore_common
|
|||
misc/events.c
|
||||
misc/image.c
|
||||
misc/messages.c
|
||||
misc/mime.c
|
||||
misc/objects.c
|
||||
misc/variables.h
|
||||
misc/variables.c
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*****************************************************************************
|
||||
* vlc_mime.h: Mime type recognition
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2012 VLC authors and VideoLAN
|
||||
*
|
||||
* This program 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.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef VLC_MIME_H
|
||||
#define VLC_MIME_H 1
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Mime type recognition helpers.
|
||||
*/
|
||||
|
||||
VLC_API const char * vlc_mime_Ext2Mime( const char *psz_url );
|
||||
|
||||
#endif /* _VLC_MIME_H */
|
|
@ -64,6 +64,7 @@ pluginsinclude_HEADERS = \
|
|||
../include/vlc_messages.h \
|
||||
../include/vlc_meta.h \
|
||||
../include/vlc_media_library.h \
|
||||
../include/vlc_mime.h \
|
||||
../include/vlc_modules.h \
|
||||
../include/vlc_mouse.h \
|
||||
../include/vlc_mtime.h \
|
||||
|
@ -438,6 +439,7 @@ SOURCES_libvlc_common = \
|
|||
misc/events.c \
|
||||
misc/image.c \
|
||||
misc/messages.c \
|
||||
misc/mime.c \
|
||||
misc/objects.c \
|
||||
misc/variables.h \
|
||||
misc/variables.c \
|
||||
|
|
|
@ -535,6 +535,7 @@ vlc_meta_New
|
|||
vlc_meta_Set
|
||||
vlc_meta_SetStatus
|
||||
vlc_meta_TypeToLocalizedString
|
||||
vlc_mime_Ext2Mime
|
||||
vlc_mutex_destroy
|
||||
vlc_mutex_init
|
||||
vlc_mutex_init_recursive
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
/*****************************************************************************
|
||||
* mime.c
|
||||
*****************************************************************************
|
||||
* Copyright © 2004-2012 VLC authors and VideoLAN
|
||||
* Copyright © 2004-2007 Rémi Denis-Courmont
|
||||
*
|
||||
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
|
||||
* Rémi Denis-Courmont <rem # videolan.org>
|
||||
*
|
||||
* This program 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.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <vlc_common.h>
|
||||
#include <vlc_mime.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static const struct
|
||||
{
|
||||
const char psz_ext[8];
|
||||
const char *psz_mime;
|
||||
} ext_mime[] =
|
||||
{
|
||||
{ ".htm", "text/html" },
|
||||
{ ".html", "text/html" },
|
||||
{ ".txt", "text/plain" },
|
||||
{ ".xml", "text/xml" },
|
||||
{ ".dtd", "text/dtd" },
|
||||
|
||||
{ ".css", "text/css" },
|
||||
|
||||
/* image mime */
|
||||
{ ".gif", "image/gif" },
|
||||
{ ".jpe", "image/jpeg" },
|
||||
{ ".jpg", "image/jpeg" },
|
||||
{ ".jpeg", "image/jpeg" },
|
||||
{ ".png", "image/png" },
|
||||
/* same as modules/mux/mpjpeg.c here: */
|
||||
{ ".mpjpeg","multipart/x-mixed-replace; boundary=7b3cc56e5f51db803f790dad720ed50a" },
|
||||
|
||||
/* media mime */
|
||||
{ ".avi", "video/avi" },
|
||||
{ ".asf", "video/x-ms-asf" },
|
||||
{ ".m1a", "audio/mpeg" },
|
||||
{ ".m2a", "audio/mpeg" },
|
||||
{ ".m1v", "video/mpeg" },
|
||||
{ ".m2v", "video/mpeg" },
|
||||
{ ".mp2", "audio/mpeg" },
|
||||
{ ".mp3", "audio/mpeg" },
|
||||
{ ".mpa", "audio/mpeg" },
|
||||
{ ".mpg", "video/mpeg" },
|
||||
{ ".mpeg", "video/mpeg" },
|
||||
{ ".mpe", "video/mpeg" },
|
||||
{ ".mov", "video/quicktime" },
|
||||
{ ".moov", "video/quicktime" },
|
||||
{ ".oga", "audio/ogg" },
|
||||
{ ".ogg", "application/ogg" },
|
||||
{ ".ogm", "application/ogg" },
|
||||
{ ".ogv", "video/ogg" },
|
||||
{ ".ogx", "application/ogg" },
|
||||
{ ".spx", "audio/ogg" },
|
||||
{ ".wav", "audio/wav" },
|
||||
{ ".wma", "audio/x-ms-wma" },
|
||||
{ ".wmv", "video/x-ms-wmv" },
|
||||
{ ".webm", "video/webm" },
|
||||
|
||||
/* end */
|
||||
{ "", "" }
|
||||
};
|
||||
|
||||
const char *vlc_mime_Ext2Mime( const char *psz_url )
|
||||
{
|
||||
|
||||
char *psz_ext;
|
||||
|
||||
psz_ext = strrchr( psz_url, '.' );
|
||||
if( psz_ext )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; ext_mime[i].psz_ext[0] ; i++ )
|
||||
{
|
||||
if( !strcasecmp( ext_mime[i].psz_ext, psz_ext ) )
|
||||
{
|
||||
return ext_mime[i].psz_mime;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "application/octet-stream";
|
||||
}
|
||||
|
|
@ -38,6 +38,7 @@
|
|||
#include <vlc_rand.h>
|
||||
#include <vlc_charset.h>
|
||||
#include <vlc_url.h>
|
||||
#include <vlc_mime.h>
|
||||
#include "../libvlc.h"
|
||||
|
||||
#include <string.h>
|
||||
|
@ -172,81 +173,6 @@ struct httpd_client_t
|
|||
/*****************************************************************************
|
||||
* Various functions
|
||||
*****************************************************************************/
|
||||
static const struct
|
||||
{
|
||||
const char psz_ext[8];
|
||||
const char *psz_mime;
|
||||
} http_mime[] =
|
||||
{
|
||||
{ ".htm", "text/html" },
|
||||
{ ".html", "text/html" },
|
||||
{ ".txt", "text/plain" },
|
||||
{ ".xml", "text/xml" },
|
||||
{ ".dtd", "text/dtd" },
|
||||
|
||||
{ ".css", "text/css" },
|
||||
|
||||
/* image mime */
|
||||
{ ".gif", "image/gif" },
|
||||
{ ".jpe", "image/jpeg" },
|
||||
{ ".jpg", "image/jpeg" },
|
||||
{ ".jpeg", "image/jpeg" },
|
||||
{ ".png", "image/png" },
|
||||
/* same as modules/mux/mpjpeg.c here: */
|
||||
{ ".mpjpeg","multipart/x-mixed-replace; boundary=7b3cc56e5f51db803f790dad720ed50a" },
|
||||
|
||||
/* media mime */
|
||||
{ ".avi", "video/avi" },
|
||||
{ ".asf", "video/x-ms-asf" },
|
||||
{ ".m1a", "audio/mpeg" },
|
||||
{ ".m2a", "audio/mpeg" },
|
||||
{ ".m1v", "video/mpeg" },
|
||||
{ ".m2v", "video/mpeg" },
|
||||
{ ".mp2", "audio/mpeg" },
|
||||
{ ".mp3", "audio/mpeg" },
|
||||
{ ".mpa", "audio/mpeg" },
|
||||
{ ".mpg", "video/mpeg" },
|
||||
{ ".mpeg", "video/mpeg" },
|
||||
{ ".mpe", "video/mpeg" },
|
||||
{ ".mov", "video/quicktime" },
|
||||
{ ".moov", "video/quicktime" },
|
||||
{ ".oga", "audio/ogg" },
|
||||
{ ".ogg", "application/ogg" },
|
||||
{ ".ogm", "application/ogg" },
|
||||
{ ".ogv", "video/ogg" },
|
||||
{ ".ogx", "application/ogg" },
|
||||
{ ".spx", "audio/ogg" },
|
||||
{ ".wav", "audio/wav" },
|
||||
{ ".wma", "audio/x-ms-wma" },
|
||||
{ ".wmv", "video/x-ms-wmv" },
|
||||
{ ".webm", "video/webm" },
|
||||
|
||||
/* end */
|
||||
{ "", "" }
|
||||
};
|
||||
|
||||
static const char *httpd_MimeFromUrl( const char *psz_url )
|
||||
{
|
||||
|
||||
char *psz_ext;
|
||||
|
||||
psz_ext = strrchr( psz_url, '.' );
|
||||
if( psz_ext )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; http_mime[i].psz_ext[0] ; i++ )
|
||||
{
|
||||
if( !strcasecmp( http_mime[i].psz_ext, psz_ext ) )
|
||||
{
|
||||
return http_mime[i].psz_mime;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "application/octet-stream";
|
||||
}
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned i_code;
|
||||
|
@ -459,7 +385,7 @@ httpd_file_t *httpd_FileNew( httpd_host_t *host,
|
|||
}
|
||||
else
|
||||
{
|
||||
file->psz_mime = strdup( httpd_MimeFromUrl( psz_url ) );
|
||||
file->psz_mime = strdup( vlc_mime_Ext2Mime( psz_url ) );
|
||||
}
|
||||
|
||||
file->pf_fill = pf_fill;
|
||||
|
@ -857,7 +783,7 @@ httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
|
|||
}
|
||||
else
|
||||
{
|
||||
stream->psz_mime = strdup( httpd_MimeFromUrl( psz_url ) );
|
||||
stream->psz_mime = strdup( vlc_mime_Ext2Mime( psz_url ) );
|
||||
}
|
||||
stream->i_header = 0;
|
||||
stream->p_header = NULL;
|
||||
|
|
Loading…
Reference in New Issue