📄 u_mimetypes.pas
字号:
(*
* One Way Network Sniffer (OWNS)
* Copyright (C) 2001-2002 OWNS
*
* http://owns.sourceforge.net/
* http://www.owns.st
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)
(*
* $Id: u_MimeTypes.pas,v 1.5 2001/08/18 18:01:43 owns Exp $
* represents a mime type
* the function guessContentFromType guess the content from data given
*)
unit u_MimeTypes;
interface
uses SysUtils;
type
TMimeType = class
private
FMediaType : String;
FSubType : String;
FExt : String;
FContentType : String;
function getText : String;
procedure setContentType(p_ContentType : String);
function getExt : String;
public
constructor create; overload;
constructor create(p_ContentType : String); overload;
property ContentType : String read FContentType write setContentType; // ex : image/jpeg ; des param鑤res
property MediaType : String read FMediaType; // ex : image
property SubType : String read FSubType; // ex : jpeg
property Text : String read getText; // ex : image/jpeg
property Ext : String read getExt; // ex : jpg
end;
function guessContentTypeFromContent(p_Content : PChar) : string;
implementation
// try to determine the mime type from the content
// returns '' if it has not been determined
// p_COntent must be 8 bytes at least
// (see URLConnection.guessContentTypeFromStream in Java)
function guessContentTypeFromContent(p_Content : PChar) : string;
var
c1, c2, c3, c4, c5, c6, c7, c8 : Char;
begin
c1 := p_Content[0];
c2 := p_Content[1];
c3 := p_Content[2];
c4 := p_Content[3];
c5 := p_Content[4];
c6 := p_Content[5];
c7 := p_Content[6];
c8 := p_Content[7];
result := '';
if (c1 = 'G') and (c2 = 'I') and (c3 = 'F')and (c4 = '8') then
result := 'image/gif'
else
if (c1 = '#') and (c2 = 'd') and (c3 = 'e')and (c4 = 'f') then
result := 'image/x-bitmap'
else
if (c1 = '!') and (c2 = ' ') and (c3 = 'X')and (c4 = 'P')
and (c5 = 'M') and (c6 = '2') then
result := 'image/x-pixmap'
else
if (c1 = #137) and (c2 = #80) and (c3 = #78) and (c4 = #71) and (c5 = #13) and
(c6 = #10) and (c7 = #26) and (c8 = #10) then
result := 'image/png'
else
if (c1 = #$2E) and (c2 = #$73) and (c3 = #$6E) and (c4 = #$64) then
result := 'audio/basic' // .au format, big endian
else
if (c1 = #$64) and (c2 = #$6E) and (c3 = #$73) and (c4 = #$2E) then
result := 'audio/basic' // .au format, little endian
else
if (c1 = '<') then
begin
if ((c2 = '!')) or
((c2 = 'h') and (c3 = 't') and (c4 = 'm') and (c5 = 'l')) or
((c2 = 'h') and (c3 = 'e') and (c4 = 'a') and (c5 = 'd')) or
((c2 = 'b') and (c3 = 'o') and (c4 = 'd') and (c5 = 'y')) or
((c2 = 'H') and (c3 = 'T') and (c4 = 'M') and (c5 = 'L')) or
((c2 = 'H') and (c3 = 'E') and (c4 = 'A') and (c5 = 'D')) or
((c2 = 'B') and (c3 = 'O') and (c4 = 'D') and (c5 = 'Y')) then
result := 'text/html'
else
if (c2 = '?') and (c3 = 'x') and (c4 = 'm') and (c5 = 'l') and (c6 = ' ') then
result := 'application/xml';
end
else
if (c1 = #$FF) and (c2 = #$D8) and (c3 = #$FF) and (c4 = #$E0) then
result := 'image/jpeg'
else
if (c1 = #$FF) and (c2 = #$D8) and (c3 = #$FF) and (c4 = #$EE) then
result := 'image/jpg'
else
if (c1 = 'R') and (c2 = 'a') and (c3 = 'r') and (c4 = '!') then
result := 'application/x-rar'
else
if (c1 = 'F') and (c2 = 'W') and (c3 = 'S')then
result := 'application/x-shockwave-flash'
else
if (c1 = 'M') and (c2 = 'S') and (c3 = 'C') and (c4 = 'F') then
result := 'application/cab'
else
if (c1 = 'M') and (c2 = 'Z') then
result := 'application/x-msdos-program'
else
if (c1 = 'P') and (c2 = 'K') and (c3 = #$03) and (c4 = #$04) then
result := 'application/zip'
else
if (c1 = 'B') and (c2 = 'M') then
result := 'image/bmp';
end;
constructor TMimeType.create;
begin
end;
constructor TMimeType.create(p_ContentType : String);
begin
setContentType(p_ContentType);
end;
function TMimeType.getText : String;
begin
result := FMediaType+'/'+FSubType;
end;
const
kSubTypesImages : array[0..6,0..1] of string =
(('gif','gif'),
('jpeg','jpg'),
('pjpeg','jpg'),
('png','png'),
('bmp','bmp'),
('tiff','tiff'),
('x-xbitmap','xbm'));
kSubTypesText : array[0..4,0..1] of string =
(('html','html'),
('plain','txt'),
('xml','xml'),
('css','css'),
('javascript','js'));
kSubTypesAudio : array[0..8,0..1] of string =
(('mpeg','mp3'),
('x-midi','mid'),
('midi','mid'),
('mid','mid'),
('x-pn-realaudio','ra'),
('x-mpeg','mp3'),
('x-wav','wav'),
('x-pn-realaudio-plugin','rm'),
('basic','snd'));
kSubTypesApplication : array[0..21,0..1] of string =
(('zip','zip'),
('x-zip-compressed','zip'),
('x-javascript','js'),
('pdf','pdf'),
('x-shockwave-flash','swf'),
('octet-stream','stream'),
('x-unknown-content-type','unk'),
('x-rar','rar'),
('x-rar-compressed','rar'),
('x-avc','avc'), // fichiers avp
('x-arj-compressed','arj'),
('x-compressed','gz'),
('x-pointplus','css'),
('x-tar','tar'),
('x-rpm','rpm'),
('msword','doc'),
('java-vm','class'),
('x-java-archive','jar'),
('x-gzip','gz'),
('x-msdownload','exe'),
('x-msdos-program','exe'),
('cab','cab'));
kSubTypesVideo : array[0..4,0..1] of string =
(('mpeg','mpeg'),
('x-msvideo','avi'),
('quicktime','qt'),
('msvideo','avi'),
('x-ms-asf','asf'));
kSubTypesMessage : array[0..0,0..1] of string =
(
('rfc822','eml')); // celui-l
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -