Browse Source

Expand mime types and expose mg_get_builtin_mime_type to scripts

mingodad 8 years ago
parent
commit
ac3564d794
2 changed files with 112 additions and 48 deletions
  1. 97 48
      SquiLu-ext/mongoose.c
  2. 15 0
      SquiLu-ext/sq_mongoose.cpp

+ 97 - 48
SquiLu-ext/mongoose.c

@@ -2107,54 +2107,103 @@ static const struct {
   size_t ext_len;
   const char *mime_type;
 } builtin_mime_types[] = {
-  {".html", 5, "text/html"},
-  {".htm", 4, "text/html"},
-  {".shtm", 5, "text/html"},
-  {".shtml", 6, "text/html"},
-  {".css", 4, "text/css"},
-  {".js",  3, "application/x-javascript"},
-  {".ico", 4, "image/x-icon"},
-  {".gif", 4, "image/gif"},
-  {".jpg", 4, "image/jpeg"},
-  {".jpeg", 5, "image/jpeg"},
-  {".png", 4, "image/png"},
-  {".svg", 4, "image/svg+xml"},
-  {".txt", 4, "text/plain"},
-  {".torrent", 8, "application/x-bittorrent"},
-  {".wav", 4, "audio/x-wav"},
-  {".mp3", 4, "audio/x-mp3"},
-  {".mid", 4, "audio/mid"},
-  {".m3u", 4, "audio/x-mpegurl"},
-  {".ogg", 4, "audio/ogg"},
-  {".ram", 4, "audio/x-pn-realaudio"},
-  {".xml", 4, "text/xml"},
-  {".json",  5, "text/json"},
-  {".xslt", 5, "application/xml"},
-  {".xsl", 4, "application/xml"},
-  {".ra",  3, "audio/x-pn-realaudio"},
-  {".doc", 4, "application/msword"},
-  {".exe", 4, "application/octet-stream"},
-  {".zip", 4, "application/x-zip-compressed"},
-  {".xls", 4, "application/excel"},
-  {".tgz", 4, "application/x-tar-gz"},
-  {".tar", 4, "application/x-tar"},
-  {".gz",  3, "application/x-gunzip"},
-  {".arj", 4, "application/x-arj-compressed"},
-  {".rar", 4, "application/x-arj-compressed"},
-  {".rtf", 4, "application/rtf"},
-  {".pdf", 4, "application/pdf"},
-  {".swf", 4, "application/x-shockwave-flash"},
-  {".mpg", 4, "video/mpeg"},
-  {".webm", 5, "video/webm"},
-  {".mpeg", 5, "video/mpeg"},
-  {".mp4", 4, "video/mp4"},
-  {".m4v", 4, "video/x-m4v"},
-  {".asf", 4, "video/x-ms-asf"},
-  {".avi", 4, "video/x-msvideo"},
-  {".bmp", 4, "image/bmp"},
-  {".apk", 4, "application/vnd.android.package-archive"},
-  {".manifest", 9, "text/cache-manifest"},
-  {NULL,  0, NULL}
+    /* IANA registered MIME types
+     * (http://www.iana.org/assignments/media-types)
+     * application types */
+    {".doc", 4, "application/msword"},
+    {".eps", 4, "application/postscript"},
+    {".exe", 4, "application/octet-stream"},
+    {".js", 3, "application/javascript"},
+    {".json", 5, "application/json"},
+    {".pdf", 4, "application/pdf"},
+    {".ps", 3, "application/postscript"},
+    {".rtf", 4, "application/rtf"},
+    {".xhtml", 6, "application/xhtml+xml"},
+    {".xsl", 4, "application/xml"},
+    {".xslt", 5, "application/xml"},
+
+    /* fonts */
+    {".ttf", 4, "application/font-sfnt"},
+    {".cff", 4, "application/font-sfnt"},
+    {".otf", 4, "application/font-sfnt"},
+    {".aat", 4, "application/font-sfnt"},
+    {".sil", 4, "application/font-sfnt"},
+    {".pfr", 4, "application/font-tdpfr"},
+    {".woff", 5, "application/font-woff"},
+
+    /* audio */
+    {".mp3", 4, "audio/mpeg"},
+    {".oga", 4, "audio/ogg"},
+    {".ogg", 4, "audio/ogg"},
+
+    /* image */
+    {".gif", 4, "image/gif"},
+    {".ief", 4, "image/ief"},
+    {".jpeg", 5, "image/jpeg"},
+    {".jpg", 4, "image/jpeg"},
+    {".jpm", 4, "image/jpm"},
+    {".jpx", 4, "image/jpx"},
+    {".png", 4, "image/png"},
+    {".svg", 4, "image/svg+xml"},
+    {".tif", 4, "image/tiff"},
+    {".tiff", 5, "image/tiff"},
+
+    /* model */
+    {".wrl", 4, "model/vrml"},
+
+    /* text */
+    {".css", 4, "text/css"},
+    {".csv", 4, "text/csv"},
+    {".htm", 4, "text/html"},
+    {".html", 5, "text/html"},
+    {".sgm", 4, "text/sgml"},
+    {".shtm", 5, "text/html"},
+    {".shtml", 6, "text/html"},
+    {".txt", 4, "text/plain"},
+    {".xml", 4, "text/xml"},
+
+    /* video */
+    {".mov", 4, "video/quicktime"},
+    {".mp4", 4, "video/mp4"},
+    {".mpeg", 5, "video/mpeg"},
+    {".mpg", 4, "video/mpeg"},
+    {".ogv", 4, "video/ogg"},
+    {".qt", 3, "video/quicktime"},
+
+    /* not registered types
+     * (http://reference.sitepoint.com/html/mime-types-full,
+     * http://www.hansenb.pdx.edu/DMKB/dict/tutorials/mime_typ.php, ..) */
+    {".arj", 4, "application/x-arj-compressed"},
+    {".gz", 3, "application/x-gunzip"},
+    {".rar", 4, "application/x-arj-compressed"},
+    {".swf", 4, "application/x-shockwave-flash"},
+    {".tar", 4, "application/x-tar"},
+    {".tgz", 4, "application/x-tar-gz"},
+    {".torrent", 8, "application/x-bittorrent"},
+    {".ppt", 4, "application/x-mspowerpoint"},
+    {".xls", 4, "application/x-msexcel"},
+    {".zip", 4, "application/x-zip-compressed"},
+    {".aac",
+     4,
+     "audio/aac"}, /* http://en.wikipedia.org/wiki/Advanced_Audio_Coding */
+    {".aif", 4, "audio/x-aif"},
+    {".m3u", 4, "audio/x-mpegurl"},
+    {".mid", 4, "audio/x-midi"},
+    {".ra", 3, "audio/x-pn-realaudio"},
+    {".ram", 4, "audio/x-pn-realaudio"},
+    {".wav", 4, "audio/x-wav"},
+    {".bmp", 4, "image/bmp"},
+    {".ico", 4, "image/x-icon"},
+    {".pct", 4, "image/x-pct"},
+    {".pict", 5, "image/pict"},
+    {".rgb", 4, "image/x-rgb"},
+    {".webm", 5, "video/webm"}, /* http://en.wikipedia.org/wiki/WebM */
+    {".asf", 4, "video/x-ms-asf"},
+    {".avi", 4, "video/x-msvideo"},
+    {".m4v", 4, "video/x-m4v"},
+    {".apk", 4, "application/vnd.android.package-archive"},
+    {".manifest", 9, "text/cache-manifest"},
+    {NULL,  0, NULL}
 };
 
 const char *mg_get_builtin_mime_type(const char *path) {

+ 15 - 0
SquiLu-ext/sq_mongoose.cpp

@@ -870,6 +870,18 @@ sq_mg_url_encode(HSQUIRRELVM v)
     return 1;
 }
 
+static SQRESULT
+sq_mg_get_builtin_mime_type(HSQUIRRELVM v)
+{
+    SQ_FUNC_VARS_NO_TOP(v);
+    SQ_GET_STRING(v, 2, src);
+
+    const char *dst = mg_get_builtin_mime_type(src);
+
+    sq_pushstring(v, dst, -1);
+    return 1;
+}
+
 static SQRESULT
 sq_mg_md5(HSQUIRRELVM v)
 {
@@ -934,6 +946,7 @@ static SQRegFunction sq_mg_methods[] =
 	_DECL_FUNC(url_decode,  2, _SC(".s")),
 	_DECL_FUNC(uri_decode,  2, _SC(".s")),
 	_DECL_FUNC(url_encode,  2, _SC(".s")),
+	_DECL_FUNC(get_builtin_mime_type,  2, _SC(".s")),
 	_DECL_FUNC(md5,  -2, _SC(".s")),
 #ifdef JNI_ENABLE_LOG
 	_DECL_FUNC(jniLog,  -2, _SC(".s")),
@@ -1072,6 +1085,7 @@ SQRESULT sqext_register_decimal(HSQUIRRELVM v);
 SQRESULT sqext_register_sq_zlib(HSQUIRRELVM v);
 SQRESULT sqext_register_sq_blosc(HSQUIRRELVM v);
 SQRESULT sqext_register_pcre2(HSQUIRRELVM v);
+SQRESULT sqext_register_markdown(HSQUIRRELVM v);
 
 #ifdef __cplusplus
 } /*extern "C"*/
@@ -1087,6 +1101,7 @@ static sq_modules_preload_st modules_preload[] = {
     {"fpdf", sqext_register_Sq_Fpdf},
     {"sqlite3", sqext_register_SQLite3},
     {"zlib", sqext_register_sq_zlib},
+    {"markdown", sqext_register_markdown},
 #if defined(SQ_USE_PCRE2) || defined(SQ_USE_PCRE2_STATIC)
     {"pcre2", sqext_register_pcre2},
 #endif