From cea020634e1155f5998c8c8eb541f826ca3d3fd3 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Sun, 19 Aug 2007 03:45:07 +0000 Subject: [PATCH] mime consistency fixes from Reuben Thomas --- ChangeLog | 17 +++++++++++++++++ configure.in | 9 ++++++--- magic/magic.mime | 30 +++++++++++++++--------------- src/ascmagic.c | 4 ++-- src/compress.c | 8 +++++--- src/is_tar.c | 7 +++---- src/magic.c | 5 +++-- 7 files changed, 51 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2c8418e..80385988 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-08-19 6:30 Christos Zoulas + + * Make mime format consistent so that it can + be easily parsed: + mimetype [charset=character-set] [encoding=encoding-mime-type] + + Remove spurious extra text from some MIME type printouts + (mostly in is_tar). + + Fix one case where -i produced nothing at all (for a 1-byte file, + which is now classed as application/octet-stream). + + Remove 7/8bit classifications, since they were arbitrary + and not based on the file data. + + This work was done by Reuben Thomas + 2007-05-24 10:00 Christos Zoulas * Fix another integer overflow (Colin Percival) diff --git a/configure.in b/configure.in index 189edbd7..a0819c7e 100644 --- a/configure.in +++ b/configure.in @@ -106,12 +106,15 @@ AC_CHECK_TYPE_STDC(uint32_t, unsigned int) AC_CHECK_TYPE_STDC(int32_t, int) AC_C_LONG_LONG if test $ac_cv_c_long_long = yes; then - long64='unsigned long long'; + ulong64='unsigned long long'; + long64='long long'; else - long64='unsigned long'; + ulong64='unsigned long'; + long64='long'; fi dnl This needs a patch to autoconf 2.13 acgeneral.m4 -AC_CHECK_TYPE2_STDC(uint64_t, $long64) +AC_CHECK_TYPE2_STDC(uint64_t, $ulong64) +AC_CHECK_TYPE2_STDC(int64_t, $long64) AC_CHECK_SIZEOF_STDC_HEADERS(uint8_t, 0) AC_CHECK_SIZEOF_STDC_HEADERS(uint16_t, 0) diff --git a/magic/magic.mime b/magic/magic.mime index 787a6c86..462f5eb1 100644 --- a/magic/magic.mime +++ b/magic/magic.mime @@ -210,7 +210,7 @@ # XPM icons (Greg Roelofs, newt@uchicago.edu) # ideally should go into "images", but entries below would tag XPM as C source -0 string /*\ XPM image/x-xpmi 7bit +0 string /*\ XPM image/x-xpmi # 3DS (3d Studio files) Conflicts with diff output 0x3d '=' #16 beshort 0x3d3d image/x-3ds @@ -429,11 +429,11 @@ # PBMPLUS # PBM file -0 string P1 image/x-portable-bitmap 7bit +0 string P1 image/x-portable-bitmap # PGM file -0 string P2 image/x-portable-greymap 7bit +0 string P2 image/x-portable-greymap # PPM file -0 string P3 image/x-portable-pixmap 7bit +0 string P3 image/x-portable-pixmap # PBM "rawbits" file 0 string P4 image/x-portable-bitmap # PGM "rawbits" file @@ -501,7 +501,7 @@ # lisp: file(1) magic for lisp programs # # various lisp types, from Daniel Quinlan (quinlan@yggdrasil.com) -0 string ;; text/plain 8bit +0 string ;; text/plain # Emacs 18 - this is always correct, but not very magical. 0 string \012( application/x-elc # Emacs 19 @@ -511,17 +511,17 @@ # mail.news: file(1) magic for mail and news # # There are tests to ascmagic.c to cope with mail and news. -0 string Relay-Version: message/rfc822 7bit -0 string #!\ rnews message/rfc822 7bit -0 string N#!\ rnews message/rfc822 7bit -0 string Forward\ to message/rfc822 7bit -0 string Pipe\ to message/rfc822 7bit -0 string Return-Path: message/rfc822 7bit +0 string Relay-Version: message/rfc822 +0 string #!\ rnews message/rfc822 +0 string N#!\ rnews message/rfc822 +0 string Forward\ to message/rfc822 +0 string Pipe\ to message/rfc822 +0 string Return-Path: message/rfc822 0 string Received: message/rfc822 -0 string Path: message/news 8bit -0 string Xref: message/news 8bit -0 string From: message/rfc822 7bit -0 string Article message/news 8bit +0 string Path: message/news +0 string Xref: message/news +0 string From: message/rfc822 +0 string Article message/news #------------------------------------------------------------------------------ # msword: file(1) magic for MS Word files # diff --git a/src/ascmagic.c b/src/ascmagic.c index 564556dd..add8bf4c 100644 --- a/src/ascmagic.c +++ b/src/ascmagic.c @@ -49,7 +49,7 @@ #include "names.h" #ifndef lint -FILE_RCSID("@(#)$File: ascmagic.c,v 1.50 2007/03/15 14:51:00 christos Exp $") +FILE_RCSID("@(#)$File: ascmagic.c,v 1.51 2007/08/19 03:45:07 christos Exp $") #endif /* lint */ typedef unsigned long unichar; @@ -281,7 +281,7 @@ subtype_identified: } if (code_mime) { - if (file_printf(ms, "; charset=") == -1) + if (file_printf(ms, " charset=") == -1) goto done; if (file_printf(ms, code_mime) == -1) goto done; diff --git a/src/compress.c b/src/compress.c index 2ccbef6e..5f8a7bbc 100644 --- a/src/compress.c +++ b/src/compress.c @@ -55,7 +55,7 @@ #ifndef lint -FILE_RCSID("@(#)$File: compress.c,v 1.51 2007/03/05 02:41:29 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.52 2007/08/19 03:45:08 christos Exp $") #endif private struct { @@ -112,11 +112,13 @@ file_zmagic(struct magic_set *ms, int fd, const char *name, rv = -1; if (file_buffer(ms, -1, name, newbuf, nsz) == -1) goto error; - if (file_printf(ms, " (") == -1) + if (file_printf(ms, (ms->flags & MAGIC_MIME) ? + " compressed-encoding=" : " (") == -1) goto error; if (file_buffer(ms, -1, NULL, buf, nbytes) == -1) goto error; - if (file_printf(ms, ")") == -1) + if (!(ms->flags & MAGIC_MIME) && + file_printf(ms, ")") == -1) goto error; rv = 1; break; diff --git a/src/is_tar.c b/src/is_tar.c index c7d4d4d9..02ef975d 100644 --- a/src/is_tar.c +++ b/src/is_tar.c @@ -45,7 +45,7 @@ #include "tar.h" #ifndef lint -FILE_RCSID("@(#)$File: is_tar.c,v 1.27 2007/01/12 17:38:28 christos Exp $") +FILE_RCSID("@(#)$File: is_tar.c,v 1.28 2007/08/19 03:45:08 christos Exp $") #endif #define isodigit(c) ( ((c) >= '0') && ((c) <= '7') ) @@ -68,13 +68,12 @@ file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes) return 1; case 2: if (file_printf(ms, (ms->flags & MAGIC_MIME) ? - "application/x-tar, POSIX" : "POSIX tar archive") == -1) + "application/x-tar" : "POSIX tar archive") == -1) return -1; return 1; case 3: if (file_printf(ms, (ms->flags & MAGIC_MIME) ? - "application/x-tar, POSIX (GNU)" : - "POSIX tar archive (GNU)") == -1) + "application/x-tar" : "POSIX tar archive (GNU)") == -1) return -1; return 1; default: diff --git a/src/magic.c b/src/magic.c index 54db48b1..14feca7d 100644 --- a/src/magic.c +++ b/src/magic.c @@ -63,7 +63,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$File: magic.c,v 1.41 2007/03/26 17:59:50 christos Exp $") +FILE_RCSID("@(#)$File: magic.c,v 1.42 2007/08/19 03:45:08 christos Exp $") #endif /* lint */ #ifdef __EMX__ @@ -331,7 +331,8 @@ magic_file(struct magic_set *ms, const char *inname) "application/x-empty" : "empty") == -1) goto done; } else if (nbytes == 1) { - if (file_printf(ms, "very short file (no magic)") == -1) + if (file_printf(ms, (ms->flags & MAGIC_MIME) ? + "application/octet-stream" : "very short file (no magic)") == -1) goto done; } else { (void)memset(buf + nbytes, 0, SLOP); /* NUL terminate */ -- 2.50.1