]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/file.c
mothra: never snarf the "Go:" box
[plan9front.git] / sys / src / cmd / file.c
index 9a1c904e7f95f2bd60ec4a4517027c71239a4145..7da5abdaaf6540421d8d2c185eac40e181fb79b0 100644 (file)
@@ -150,11 +150,13 @@ int       ishtml(void);
 int    isrfc822(void);
 int    ismbox(void);
 int    islimbo(void);
+int    ismp3(void);
 int    ismung(void);
 int    isp9bit(void);
 int    isp9font(void);
 int    isrtf(void);
 int    ismsdos(void);
+int    isicocur(void);
 int    iself(void);
 int    istring(void);
 int    isoffstr(void);
@@ -192,7 +194,9 @@ int (*call[])(void) =
        isp9bit,        /* plan 9 image (as from /dev/window) */
        isrtf,          /* rich text format */
        ismsdos,        /* msdos exe (virus file attachement) */
+       isicocur,               /* windows icon or cursor file */
        isface,         /* ascii face file */
+       ismp3,
 
        /* last resorts */
        ismung,         /* entropy compressed/encrypted */
@@ -586,7 +590,7 @@ Filemagic long0tab[] = {
        /* "pXc2 */
        0x32630070,     0xFFFF00FF,     "pac4 audio file\n",    OCTET,
        0xBA010000,     0xFFFFFFFF,     "mpeg system stream\n", OCTET,
-       0x43614c66,     0xFFFFFFFF,     "FLAC audio file\n",    OCTET,
+       0x43614c66,     0xFFFFFFFF,     "FLAC audio file\n",    "audio/flac",
        0x30800CC0,     0xFFFFFFFF,     "inferno .dis executable\n", OCTET,
        0x04034B50,     0xFFFFFFFF,     "zip archive\n", "application/zip",
        070707,         0xFFFF,         "cpio archive\n", "application/x-cpio",
@@ -800,12 +804,14 @@ struct    FILE_STRING
        "\377\330\377\340",     "jpeg",                         4,      "image/jpeg",
        "\377\330\377\341",     "jpeg",                         4,      "image/jpeg",
        "\377\330\377\333",     "jpeg",                         4,      "image/jpeg",
+       "\xff\xd8",             "jpeg",                         2,      "image/jpeg",
        "BM",                   "bmp",                          2,      "image/bmp", 
        "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1",     "microsoft office document",    8,      "application/doc",
        "<MakerFile ",          "FrameMaker file",              11,     "application/framemaker",
        "\033E\033",    "HP PCL printer data",          3,      OCTET,
        "\033%-12345X", "HPJCL file",           9,      "application/hpjcl",
        "ID3",                  "mp3 audio with id3",   3,      "audio/mpeg",
+       "OggS",                 "ogg audio",            4,      "audio/ogg",
        "\211PNG",              "PNG image",            4,      "image/png",
        "P3\n",                 "ppm",                          3,      "image/ppm",
        "P6\n",                 "ppm",                          3,      "image/ppm",
@@ -831,6 +837,9 @@ struct      FILE_STRING
                                "pem x.509 certificate", -1,    "text/plain",
        "subject=/C=",          "pem certificate with header", -1, "text/plain",
        "process snapshot ",    "process snapshot",     -1,     "application/snapfs",
+       "d8:announce",          "torrent file",         11,     "application/x-bittorrent",
+       "[playlist]",           "playlist",             10,     "application/x-scpls",
+       "#EXTM3U",              "playlist",             7,      "audio/x-mpegurl",
        0,0,0,0
 };
 
@@ -870,7 +879,7 @@ struct offstr
        ulong   off;
        struct FILE_STRING;
 } offstrs[] = {
-       32*1024, "\001CD001\001",       "ISO9660 CD image",     7,      OCTET,
+       32*1024, "\001CD001\001",       "ISO9660 CD image",     7,      "application/x-iso9660-image",
        0, 0, 0, 0, 0
 };
 
@@ -920,45 +929,20 @@ iff(void)
        return 0;
 }
 
-char*  html_string[] =
-{
-       "?xml",
-       "!--",
-       "![CDATA[",
-       "!DOCTYPE",
-       "html",
-       "head",
-       "title",
-       "link",
-       "meta",
-       "body",
-       "script",
-       "strong",
-       "input",
-       "table",
-       "form",
-       "font",
-       "div",
-       "h1",
-       "h2",
-       "h3",
-       "h4",
-       "h5",
-       "h6",
-       "ol",
-       "ul",
-       "li",
-       "dl",
-       "br",
-       "hr",
-       "em",
-       "th",
-       "tr",
-       "td",
-       "p",
-       "b",
-       "i",
-       "a",
+char*  html_string[] = {
+       "blockquote",
+       "!DOCTYPE", "![CDATA[", "basefont", "frameset", "noframes", "textarea",
+       "caption",
+       "button", "center", "iframe", "object", "option", "script",
+       "select", "strong",
+       "blink", "embed", "frame", "input", "label", "param", "small",
+       "style", "table", "tbody", "tfoot", "thead", "title",
+       "?xml", "body", "code", "font", "form", "head", "html",
+       "link", "menu", "meta", "span",
+       "!--", "big", "dir", "div", "img", "pre", "sub", "sup",
+       "br", "dd", "dl", "dt", "em", "h1", "h2", "h3", "h4", "h5",
+       "h6", "hr", "li", "ol", "td", "th", "tr", "tt", "ul",
+       "a", "b", "i", "p", "q", "u",
        0,
 };
 
@@ -985,11 +969,13 @@ ishtml(void)
                        if(p + n > buf+nbuf)
                                continue;
                        if(cistrncmp(html_string[i], (char*)p, n) == 0) {
-                               if(++count > 2) {
-                                       print(mime ? "text/html\n" : "HTML file\n");
-                                       return 1;
-                               }
                                p += n;
+                               if(p < buf+nbuf && strchr("\t\r\n />", *p)){
+                                       if(++count > 2) {
+                                               print(mime ? "text/html\n" : "HTML file\n");
+                                               return 1;
+                                       }
+                               }
                                break;
                        }
                }
@@ -1151,6 +1137,23 @@ isas(void)
        return 1;
 }
 
+int
+ismp3(void)
+{
+       uchar *p, *e;
+
+       p = buf;
+       e = p + nbuf-1;
+       while((p < e) && (p = memchr(p, 0xFF, e - p))){
+               if((p[1] & 0xFE) == 0xFA){
+                       print(mime ? "audio/mpeg\n" : "mp3 audio\n");
+                       return 1;
+               }
+               p++;
+       }
+       return 0;
+}
+
 /*
  * low entropy means encrypted
  */
@@ -1179,6 +1182,9 @@ ismung(void)
                else
                if(buf[0]=='B' && buf[1]=='Z' && buf[2]=='h')
                        print(mime ? "application/x-bzip2" : "bzip2 compressed\n");
+               else
+               if(buf[0]==0x78 && buf[1]==0x9c)
+                       print(mime ? "application/x-deflate" : "zlib compressed\n");
                else
                        print(mime ? OCTET : "encrypted\n");
                return 1;
@@ -1475,6 +1481,24 @@ ismsdos(void)
        return 0;
 }
 
+int
+isicocur(void)
+{
+       if(buf[0] || buf[1] || buf[3] || buf[9])
+               return 0;
+       if(buf[4] == 0x00 && buf[5] == 0x00)
+               return 0;
+       switch(buf[2]){
+       case 1:
+               print(mime ? "image/x-icon\n" : "Microsoft icon file\n");
+               return 1;
+       case 2:
+               print(mime ? "image/x-icon\n" : "Microsoft cursor file\n");
+               return 1;
+       }
+       return 0;
+}
+
 int
 iself(void)
 {