WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch 2
webcore_parsedcontenttype_2.patch (text/plain), 39.19 KB, created by
Alexander Shalamov
on 2012-11-02 04:40:54 PDT
(
hide
)
Description:
Patch 2
Filename:
MIME Type:
Creator:
Alexander Shalamov
Created:
2012-11-02 04:40:54 PDT
Size:
39.19 KB
patch
obsolete
>diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt >index 91b9edd..614d707 100644 >--- a/Source/WebCore/CMakeLists.txt >+++ b/Source/WebCore/CMakeLists.txt >@@ -1987,7 +1987,6 @@ SET(WebCore_SOURCES > platform/network/BlobResourceHandle.cpp > platform/network/Credential.cpp > platform/network/CredentialStorage.cpp >- platform/network/ContentTypeParser.cpp > platform/network/DataURL.cpp > platform/network/DNSResolveQueue.cpp > platform/network/FormDataBuilder.cpp >@@ -1998,6 +1997,7 @@ SET(WebCore_SOURCES > platform/network/HTTPValidation.cpp > platform/network/MIMEHeader.cpp > platform/network/NetworkStateNotifier.cpp >+ platform/network/ParsedContentType.cpp > platform/network/ProtectionSpace.cpp > platform/network/ProxyServer.cpp > platform/network/ResourceErrorBase.cpp >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 9b37544..bc37374 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,44 @@ >+2012-11-02 Alexander Shalamov <alexander.shalamov@intel.com> >+ >+ Improve ContentTypeParser, so that it could be used to validate mime type according to RFC >+ https://bugs.webkit.org/show_bug.cgi?id=100927 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch adds ParsedContentType class that represents contents of parsed >+ content type string. isValidContentType function could be used to check if >+ format of the content type string is acorrding to RFC 2616 section 4.2. >+ >+ * CMakeLists.txt: >+ * GNUmakefile.list.am: >+ * Target.pri: >+ * WebCore.gypi: >+ * WebCore.xcodeproj/project.pbxproj: >+ * platform/network/MIMEHeader.cpp: >+ (WebCore::MIMEHeader::parseHeader): >+ * platform/network/ParsedContentType.cpp: Renamed from Source/WebCore/platform/network/ContentTypeParser.cpp. >+ (WebCore): >+ (EmptyParsedContentType): >+ (WebCore::EmptyParsedContentType::setContentType): >+ (WebCore::EmptyParsedContentType::setContentTypeParameter): >+ (WebCore::skipSpaces): >+ (WebCore::isTokenCharacter): >+ (WebCore::parseToken): >+ (WebCore::parseQuotedString): >+ (WebCore::substringForRange): >+ (WebCore::parseContentType): >+ (WebCore::isValidContentType): >+ (WebCore::ParsedContentType::ParsedContentType): >+ (WebCore::ParsedContentType::charset): >+ (WebCore::ParsedContentType::parameterValueForName): >+ (WebCore::ParsedContentType::parameterCount): >+ (WebCore::ParsedContentType::setContentType): >+ (WebCore::ParsedContentType::setContentTypeParameter): >+ * platform/network/ParsedContentType.h: Renamed from Source/WebCore/platform/network/ContentTypeParser.h. >+ (WebCore): >+ (ParsedContentType): >+ (WebCore::ParsedContentType::mimeType): >+ > 2012-10-29 Eric Seidel <eric@webkit.org> > > Make rendering tables with <colgroups> twice as fast by avoiding walking the DOM for colgroups 4 times for each cell >diff --git a/Source/WebCore/GNUmakefile.list.am b/Source/WebCore/GNUmakefile.list.am >index 1a05a09..7b1f5ca 100644 >--- a/Source/WebCore/GNUmakefile.list.am >+++ b/Source/WebCore/GNUmakefile.list.am >@@ -4683,8 +4683,6 @@ webcore_sources += \ > Source/WebCore/platform/network/BlobResourceHandle.cpp \ > Source/WebCore/platform/network/BlobResourceHandle.h \ > Source/WebCore/platform/network/BlobStorageData.h \ >- Source/WebCore/platform/network/ContentTypeParser.cpp \ >- Source/WebCore/platform/network/ContentTypeParser.h \ > Source/WebCore/platform/network/CookieStorage.h \ > Source/WebCore/platform/network/Credential.cpp \ > Source/WebCore/platform/network/Credential.h \ >@@ -4708,6 +4706,8 @@ webcore_sources += \ > Source/WebCore/platform/network/MIMEHeader.cpp \ > Source/WebCore/platform/network/MIMEHeader.h \ > Source/WebCore/platform/network/NetworkingContext.h \ >+ Source/WebCore/platform/network/ParsedContentType.cpp \ >+ Source/WebCore/platform/network/ParsedContentType.h \ > Source/WebCore/platform/network/ProxyServer.cpp \ > Source/WebCore/platform/network/ProxyServer.h \ > Source/WebCore/platform/network/NetworkStateNotifier.cpp \ >diff --git a/Source/WebCore/Target.pri b/Source/WebCore/Target.pri >index 2ae5022..c77eb15 100644 >--- a/Source/WebCore/Target.pri >+++ b/Source/WebCore/Target.pri >@@ -1041,7 +1041,6 @@ SOURCES += \ > platform/network/BlobResourceHandle.cpp \ > platform/network/Credential.cpp \ > platform/network/CredentialStorage.cpp \ >- platform/network/ContentTypeParser.cpp \ > platform/network/FormData.cpp \ > platform/network/FormDataBuilder.cpp \ > platform/network/HTTPHeaderMap.cpp \ >@@ -1050,6 +1049,7 @@ SOURCES += \ > platform/network/HTTPValidation.cpp \ > platform/network/MIMEHeader.cpp \ > platform/network/NetworkStateNotifier.cpp \ >+ platform/network/ParsedContentType.cpp \ > platform/network/ProtectionSpace.cpp \ > platform/network/ProxyServer.cpp \ > platform/network/ResourceErrorBase.cpp \ >@@ -2218,7 +2218,6 @@ HEADERS += \ > platform/network/CookieStorage.h \ > platform/network/Credential.h \ > platform/network/CredentialStorage.h \ >- platform/network/ContentTypeParser.h \ > platform/network/DNSResolveQueue.h \ > platform/network/FormDataBuilder.h \ > platform/network/FormData.h \ >@@ -2230,6 +2229,7 @@ HEADERS += \ > platform/network/MIMESniffing.h \ > platform/network/NetworkingContext.h \ > platform/network/NetworkStateNotifier.h \ >+ platform/network/ParsedContentType.h \ > platform/network/ProtectionSpace.h \ > platform/network/ProxyServer.h \ > platform/network/qt/QtMIMETypeSniffer.h \ >diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi >index 19390b6..3902d41 100644 >--- a/Source/WebCore/WebCore.gypi >+++ b/Source/WebCore/WebCore.gypi >@@ -5531,8 +5531,6 @@ > 'platform/network/BlobResourceHandle.cpp', > 'platform/network/BlobResourceHandle.h', > 'platform/network/BlobStorageData.h', >- 'platform/network/ContentTypeParser.cpp', >- 'platform/network/ContentTypeParser.h', > 'platform/network/Credential.cpp', > 'platform/network/CredentialStorage.cpp', > 'platform/network/DNS.h', >@@ -5551,6 +5549,8 @@ > 'platform/network/MIMEHeader.cpp', > 'platform/network/NetworkStateNotifier.cpp', > 'platform/network/NetworkStateNotifier.h', >+ 'platform/network/ParsedContentType.cpp', >+ 'platform/network/ParsedContentType.h', > 'platform/network/ProtectionSpace.cpp', > 'platform/network/ProxyServer.cpp', > 'platform/network/ResourceErrorBase.cpp', >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 538d3f8..7aec4e9 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -966,8 +966,6 @@ > 33C0CCD4112C5E6200CE057D /* SecureTextInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33C0CCD2112C5E6200CE057D /* SecureTextInput.cpp */; }; > 33C0CCD5112C5E6200CE057D /* SecureTextInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C0CCD3112C5E6200CE057D /* SecureTextInput.h */; }; > 33D0212D131DB37B004091A8 /* CookieStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = E13F01EA1270E10D00DFBA71 /* CookieStorage.h */; settings = {ATTRIBUTES = (Private, ); }; }; >- 370D6EDA138454550044103E /* ContentTypeParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 370D6ED8138454550044103E /* ContentTypeParser.cpp */; }; >- 370D6EDB138454550044103E /* ContentTypeParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 370D6ED9138454550044103E /* ContentTypeParser.h */; }; > 371941961566B37200A276D8 /* WebCoreNSCellExtras.m in Sources */ = {isa = PBXBuildFile; fileRef = 371941941566B37200A276D8 /* WebCoreNSCellExtras.m */; }; > 371941971566B37200A276D8 /* WebCoreNSCellExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 371941951566B37200A276D8 /* WebCoreNSCellExtras.h */; }; > 371A67CB11C6C7DB00047B8B /* HyphenationCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 371A67CA11C6C7DB00047B8B /* HyphenationCF.cpp */; }; >@@ -1200,6 +1198,8 @@ > 44311CD812E4E24B000A8D19 /* DOMDocumentPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 44311CD512E4E22D000A8D19 /* DOMDocumentPrivate.h */; }; > 44311CD912E4E257000A8D19 /* DOMDocumentFragmentPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 44311CD412E4E22D000A8D19 /* DOMDocumentFragmentPrivate.h */; }; > 44311F8212E4E66C000A8D19 /* DOMDocumentFragmentInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 85E711450AC5D5340053270F /* DOMDocumentFragmentInternal.h */; }; >+ 447958041643B49A001E0A7F /* ParsedContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 447958031643B47B001E0A7F /* ParsedContentType.h */; settings = {ATTRIBUTES = (Private, ); }; }; >+ 447958051643B4B2001E0A7F /* ParsedContentType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 447958021643B47B001E0A7F /* ParsedContentType.cpp */; }; > 448A29BF0A46D9CB0030759F /* JSHTMLOptionsCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 448A29BD0A46D9CB0030759F /* JSHTMLOptionsCollection.h */; }; > 448A29C00A46D9CB0030759F /* JSHTMLOptionsCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 448A29BE0A46D9CB0030759F /* JSHTMLOptionsCollection.cpp */; }; > 448AD27C0A48137A0023D179 /* JSHTMLOptionsCollectionCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 448AD27A0A4813790023D179 /* JSHTMLOptionsCollectionCustom.cpp */; }; >@@ -8110,8 +8110,6 @@ > 339B5B62131DAA3200F48D02 /* CookiesStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CookiesStrategy.h; sourceTree = "<group>"; }; > 33C0CCD2112C5E6200CE057D /* SecureTextInput.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecureTextInput.cpp; sourceTree = "<group>"; }; > 33C0CCD3112C5E6200CE057D /* SecureTextInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecureTextInput.h; sourceTree = "<group>"; }; >- 370D6ED8138454550044103E /* ContentTypeParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentTypeParser.cpp; sourceTree = "<group>"; }; >- 370D6ED9138454550044103E /* ContentTypeParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentTypeParser.h; sourceTree = "<group>"; }; > 371941941566B37200A276D8 /* WebCoreNSCellExtras.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebCoreNSCellExtras.m; sourceTree = "<group>"; }; > 371941951566B37200A276D8 /* WebCoreNSCellExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreNSCellExtras.h; sourceTree = "<group>"; }; > 371A67CA11C6C7DB00047B8B /* HyphenationCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HyphenationCF.cpp; sourceTree = "<group>"; }; >@@ -8376,6 +8374,8 @@ > 4429AB070CB84F81007647C5 /* DOMTextEventInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMTextEventInternal.h; sourceTree = "<group>"; }; > 44311CD412E4E22D000A8D19 /* DOMDocumentFragmentPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDocumentFragmentPrivate.h; sourceTree = "<group>"; }; > 44311CD512E4E22D000A8D19 /* DOMDocumentPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDocumentPrivate.h; sourceTree = "<group>"; }; >+ 447958021643B47B001E0A7F /* ParsedContentType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentType.cpp; sourceTree = "<group>"; }; >+ 447958031643B47B001E0A7F /* ParsedContentType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParsedContentType.h; sourceTree = "<group>"; }; > 448A29BD0A46D9CB0030759F /* JSHTMLOptionsCollection.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLOptionsCollection.h; sourceTree = "<group>"; }; > 448A29BE0A46D9CB0030759F /* JSHTMLOptionsCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLOptionsCollection.cpp; sourceTree = "<group>"; }; > 448AD27A0A4813790023D179 /* JSHTMLOptionsCollectionCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLOptionsCollectionCustom.cpp; sourceTree = "<group>"; }; >@@ -15629,8 +15629,6 @@ > 2EB4BCD0121F03E300EC4885 /* BlobResourceHandle.cpp */, > 2EB4BCD1121F03E300EC4885 /* BlobResourceHandle.h */, > 2EDEF1F2121B0EFC00726DB2 /* BlobStorageData.h */, >- 370D6ED8138454550044103E /* ContentTypeParser.cpp */, >- 370D6ED9138454550044103E /* ContentTypeParser.h */, > E13F01EA1270E10D00DFBA71 /* CookieStorage.h */, > 514C76580CE923A1007EF3CD /* Credential.cpp */, > 514C76590CE923A1007EF3CD /* Credential.h */, >@@ -15656,6 +15654,8 @@ > 628D214B12131ED10055DCFC /* NetworkingContext.h */, > 1A7FA61A0DDA3BBE0028F8A5 /* NetworkStateNotifier.cpp */, > 1A7FA6180DDA3B3A0028F8A5 /* NetworkStateNotifier.h */, >+ 447958021643B47B001E0A7F /* ParsedContentType.cpp */, >+ 447958031643B47B001E0A7F /* ParsedContentType.h */, > 514C765F0CE923A1007EF3CD /* ProtectionSpace.cpp */, > 514C76600CE923A1007EF3CD /* ProtectionSpace.h */, > 51A052551058874000CC9E95 /* ProtectionSpaceHash.h */, >@@ -22598,7 +22598,6 @@ > 97C471DC12F925BD0086354B /* ContentSecurityPolicy.h in Headers */, > 57B791A614C6A62900F202D1 /* ContentSelectorQuery.h in Headers */, > 41D015CA0F4B5C71004A662F /* ContentType.h in Headers */, >- 370D6EDB138454550044103E /* ContentTypeParser.h in Headers */, > 97627B8E14FB3CEE002CDCA1 /* ContextDestructionObserver.h in Headers */, > A7D3CA11157DF8E900860A97 /* ContextFeatures.h in Headers */, > 93B6A0E60B0BCA5C00F5027A /* ContextMenu.h in Headers */, >@@ -25671,6 +25670,7 @@ > E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */, > 977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */, > FD537353137B651800008DCE /* ZeroPole.h in Headers */, >+ 447958041643B49A001E0A7F /* ParsedContentType.h in Headers */, > ); > runOnlyForDeploymentPostprocessing = 0; > }; >@@ -26213,7 +26213,6 @@ > 97C471DB12F925BD0086354B /* ContentSecurityPolicy.cpp in Sources */, > 57B791A514C6A62900F202D1 /* ContentSelectorQuery.cpp in Sources */, > 41D015CB0F4B5C71004A662F /* ContentType.cpp in Sources */, >- 370D6EDA138454550044103E /* ContentTypeParser.cpp in Sources */, > 97627B8D14FB3CEE002CDCA1 /* ContextDestructionObserver.cpp in Sources */, > A7D3CA10157DF8E900860A97 /* ContextFeatures.cpp in Sources */, > 065AD4F60B0C2EDA005A2B1D /* ContextMenuController.cpp in Sources */, >@@ -28784,6 +28783,7 @@ > 977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */, > FD537352137B651800008DCE /* ZeroPole.cpp in Sources */, > 51ABF64D16392E2800132A7A /* LoaderStrategy.cpp in Sources */, >+ 447958051643B4B2001E0A7F /* ParsedContentType.cpp in Sources */, > ); > runOnlyForDeploymentPostprocessing = 0; > }; >diff --git a/Source/WebCore/platform/network/ContentTypeParser.cpp b/Source/WebCore/platform/network/ContentTypeParser.cpp >deleted file mode 100644 >index dda4588..0000000 >--- a/Source/WebCore/platform/network/ContentTypeParser.cpp >+++ /dev/null >@@ -1,221 +0,0 @@ >- /* >- * Copyright (C) 2011 Google Inc. All rights reserved. >- * >- * Redistribution and use in source and binary forms, with or without >- * modification, are permitted provided that the following conditions are >- * met: >- * >- * * Redistributions of source code must retain the above copyright >- * notice, this list of conditions and the following disclaimer. >- * * Redistributions in binary form must reproduce the above >- * copyright notice, this list of conditions and the following disclaimer >- * in the documentation and/or other materials provided with the >- * distribution. >- * * Neither the name of Google Inc. nor the names of its >- * contributors may be used to endorse or promote products derived from >- * this software without specific prior written permission. >- * >- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT >- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >- */ >- >-#include "config.h" >-#include "ContentTypeParser.h" >- >-#include <wtf/text/CString.h> >-#include <wtf/text/StringBuilder.h> >- >-namespace WebCore { >- >-static void skipSpaces(const String& input, size_t& startIndex) >-{ >- while (startIndex < input.length() && input[startIndex] == ' ') >- ++startIndex; >-} >- >-static bool isTokenCharacter(char c) >-{ >- return isASCII(c) && c > ' ' && c != '"' && c != '(' && c != ')' && c != ',' && c != '/' && (c < ':' || c > '@') && (c < '[' || c > ']'); >-} >- >-static String parseToken(const String& input, size_t& startIndex) >-{ >- if (startIndex >= input.length()) >- return String(); >- >- StringBuilder stringBuilder; >- while (startIndex < input.length()) { >- char currentCharacter = input[startIndex]; >- if (!isTokenCharacter(currentCharacter)) >- return stringBuilder.toString(); >- stringBuilder.append(currentCharacter); >- ++startIndex; >- } >- return stringBuilder.toString(); >-} >- >-static String parseQuotedString(const String& input, size_t& startIndex) >-{ >- if (startIndex >= input.length()) >- return String(); >- >- if (input[startIndex++] != '"' || startIndex >= input.length()) >- return String(); >- >- StringBuilder stringBuilder; >- bool lastCharacterWasBackslash = false; >- char currentCharacter; >- while ((currentCharacter = input[startIndex++]) != '"' || lastCharacterWasBackslash) { >- if (startIndex >= input.length()) >- return String(); >- if (currentCharacter == '\\' && !lastCharacterWasBackslash) { >- lastCharacterWasBackslash = true; >- continue; >- } >- if (lastCharacterWasBackslash) >- lastCharacterWasBackslash = false; >- stringBuilder.append(currentCharacter); >- } >- return stringBuilder.toString(); >-} >- >-ContentTypeParser::ContentTypeParser(const String& contentType) >- : m_contentType(contentType.stripWhiteSpace()) >-{ >- parse(); >-} >- >-String ContentTypeParser::charset() const >-{ >- return parameterValueForName("charset"); >-} >- >-String ContentTypeParser::parameterValueForName(const String& name) const >-{ >- return m_parameters.get(name); >-} >- >-size_t ContentTypeParser::parameterCount() const >-{ >- return m_parameters.size(); >-} >- >-// From http://tools.ietf.org/html/rfc2045#section-5.1: >-// >-// content := "Content-Type" ":" type "/" subtype >-// *(";" parameter) >-// ; Matching of media type and subtype >-// ; is ALWAYS case-insensitive. >-// >-// type := discrete-type / composite-type >-// >-// discrete-type := "text" / "image" / "audio" / "video" / >-// "application" / extension-token >-// >-// composite-type := "message" / "multipart" / extension-token >-// >-// extension-token := ietf-token / x-token >-// >-// ietf-token := <An extension token defined by a >-// standards-track RFC and registered >-// with IANA.> >-// >-// x-token := <The two characters "X-" or "x-" followed, with >-// no intervening white space, by any token> >-// >-// subtype := extension-token / iana-token >-// >-// iana-token := <A publicly-defined extension token. Tokens >-// of this form must be registered with IANA >-// as specified in RFC 2048.> >-// >-// parameter := attribute "=" value >-// >-// attribute := token >-// ; Matching of attributes >-// ; is ALWAYS case-insensitive. >-// >-// value := token / quoted-string >-// >-// token := 1*<any (US-ASCII) CHAR except SPACE, CTLs, >-// or tspecials> >-// >-// tspecials := "(" / ")" / "<" / ">" / "@" / >-// "," / ";" / ":" / "\" / <"> >-// "/" / "[" / "]" / "?" / "=" >-// ; Must be in quoted-string, >-// ; to use within parameter values >- >-void ContentTypeParser::parse() >-{ >- DEFINE_STATIC_LOCAL(const String, contentTypeParameterName, (ASCIILiteral("Content-Type"))); >- >- if (!m_contentType.startsWith(contentTypeParameterName)) { >- LOG_ERROR("Invalid Content-Type string '%s'", m_contentType.ascii().data()); >- return; >- } >- size_t contentTypeLength = m_contentType.length(); >- size_t index = contentTypeParameterName.length(); >- skipSpaces(m_contentType, index); >- if (index >= contentTypeLength || m_contentType[index] != ':' || ++index >= contentTypeLength) { >- LOG_ERROR("Invalid Content-Type string '%s'", m_contentType.ascii().data()); >- return; >- } >- >- // There should not be any quoted strings until we reach the parameters. >- size_t semiColonIndex = m_contentType.find(';', index); >- if (semiColonIndex == notFound) { >- m_mimeType = m_contentType.substring(index).stripWhiteSpace(); >- return; >- } >- >- m_mimeType = m_contentType.substring(index, semiColonIndex - index).stripWhiteSpace(); >- index = semiColonIndex + 1; >- while (true) { >- skipSpaces(m_contentType, index); >- String key = parseToken(m_contentType, index); >- if (key.isEmpty() || index >= contentTypeLength) { >- LOG_ERROR("Invalid Content-Type parameter name."); >- return; >- } >- // Should we tolerate spaces here? >- if (m_contentType[index++] != '=' || index >= contentTypeLength) { >- LOG_ERROR("Invalid Content-Type malformed parameter."); >- return; >- } >- >- // Should we tolerate spaces here? >- String value; >- if (m_contentType[index] == '"') >- value = parseQuotedString(m_contentType, index); >- else >- value = parseToken(m_contentType, index); >- >- if (value.isNull()) { >- LOG_ERROR("Invalid Content-Type, invalid parameter value."); >- return; >- } >- >- // Should we tolerate spaces here? >- if (index < contentTypeLength && m_contentType[index++] != ';') { >- LOG_ERROR("Invalid Content-Type, invalid character at the end of key/value parameter."); >- return; >- } >- >- m_parameters.set(key, value); >- >- if (index >= contentTypeLength) >- return; >- } >-} >- >-} >diff --git a/Source/WebCore/platform/network/ContentTypeParser.h b/Source/WebCore/platform/network/ContentTypeParser.h >deleted file mode 100644 >index 0657b01..0000000 >--- a/Source/WebCore/platform/network/ContentTypeParser.h >+++ /dev/null >@@ -1,66 +0,0 @@ >-/* >- * Copyright (C) 2011 Google Inc. All rights reserved. >- * >- * Redistribution and use in source and binary forms, with or without >- * modification, are permitted provided that the following conditions are >- * met: >- * >- * * Redistributions of source code must retain the above copyright >- * notice, this list of conditions and the following disclaimer. >- * * Redistributions in binary form must reproduce the above >- * copyright notice, this list of conditions and the following disclaimer >- * in the documentation and/or other materials provided with the >- * distribution. >- * * Neither the name of Google Inc. nor the names of its >- * contributors may be used to endorse or promote products derived from >- * this software without specific prior written permission. >- * >- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT >- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >- */ >- >-#ifndef ContentTypeParser_h >-#define ContentTypeParser_h >- >-#include <wtf/HashMap.h> >-#include <wtf/text/StringHash.h> >-#include <wtf/text/WTFString.h> >- >-namespace WebCore { >- >-// FIXME: add support for comments. >-class ContentTypeParser { >-public: >- explicit ContentTypeParser(const String&); >- >- String mimeType() const { return m_mimeType; } >- String charset() const; >- >- // Note that in the case of multiple values for the same name, the last value is returned. >- String parameterValueForName(const String&) const; >- size_t parameterCount() const; >- >-private: >- void parse(); >- >- String m_contentType; >- >- typedef HashMap<String, String> KeyValuePairs; >- KeyValuePairs m_parameters; >- String m_mimeType; >-}; >- >-} >- >-#endif >- >- >diff --git a/Source/WebCore/platform/network/MIMEHeader.cpp b/Source/WebCore/platform/network/MIMEHeader.cpp >index f4e3ebf..048abf8 100644 >--- a/Source/WebCore/platform/network/MIMEHeader.cpp >+++ b/Source/WebCore/platform/network/MIMEHeader.cpp >@@ -31,7 +31,7 @@ > #include "config.h" > #include "MIMEHeader.h" > >-#include "ContentTypeParser.h" >+#include "ParsedContentType.h" > #include "SharedBufferChunkReader.h" > #include <wtf/HashMap.h> > #include <wtf/text/CString.h> >@@ -85,14 +85,13 @@ PassRefPtr<MIMEHeader> MIMEHeader::parseHeader(SharedBufferChunkReader* buffer) > KeyValueMap keyValuePairs = retrieveKeyValuePairs(buffer); > KeyValueMap::iterator mimeParametersIterator = keyValuePairs.find("content-type"); > if (mimeParametersIterator != keyValuePairs.end()) { >- // FIXME: make ContentTypeParser more flexible so we don't have to synthesize the "Content-Type:". >- ContentTypeParser contentTypeParser(makeString("Content-Type:", mimeParametersIterator->value)); >- mimeHeader->m_contentType = contentTypeParser.mimeType(); >+ ParsedContentType parsedContentType(mimeParametersIterator->value); >+ mimeHeader->m_contentType = parsedContentType.mimeType(); > if (!mimeHeader->isMultipart()) >- mimeHeader->m_charset = contentTypeParser.charset().stripWhiteSpace(); >+ mimeHeader->m_charset = parsedContentType.charset().stripWhiteSpace(); > else { >- mimeHeader->m_multipartType = contentTypeParser.parameterValueForName("type"); >- mimeHeader->m_endOfPartBoundary = contentTypeParser.parameterValueForName("boundary"); >+ mimeHeader->m_multipartType = parsedContentType.parameterValueForName("type"); >+ mimeHeader->m_endOfPartBoundary = parsedContentType.parameterValueForName("boundary"); > if (mimeHeader->m_endOfPartBoundary.isNull()) { > LOG_ERROR("No boundary found in multipart MIME header."); > return 0; >diff --git a/Source/WebCore/platform/network/ParsedContentType.cpp b/Source/WebCore/platform/network/ParsedContentType.cpp >new file mode 100644 >index 0000000..815efd7 >--- /dev/null >+++ b/Source/WebCore/platform/network/ParsedContentType.cpp >@@ -0,0 +1,254 @@ >+ /* >+ * Copyright (C) 2011 Google Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions are >+ * met: >+ * >+ * * Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * * Redistributions in binary form must reproduce the above >+ * copyright notice, this list of conditions and the following disclaimer >+ * in the documentation and/or other materials provided with the >+ * distribution. >+ * * Neither the name of Google Inc. nor the names of its >+ * contributors may be used to endorse or promote products derived from >+ * this software without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT >+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "ParsedContentType.h" >+ >+#include <wtf/text/CString.h> >+#include <wtf/text/StringBuilder.h> >+ >+namespace WebCore { >+ >+class EmptyParsedContentType { >+public: >+ void setContentType(const SubstringRange&) const { } >+ void setContentTypeParameter(const SubstringRange&, const SubstringRange&) const { } >+}; >+ >+static void skipSpaces(const String& input, unsigned& startIndex) >+{ >+ while (startIndex < input.length() && input[startIndex] == ' ') >+ ++startIndex; >+} >+ >+static bool isTokenCharacter(char c) >+{ >+ return isASCII(c) && c > ' ' && c != '"' && c != '(' && c != ')' && c != ',' && c != '/' && (c < ':' || c > '@') && (c < '[' || c > ']'); >+} >+ >+static SubstringRange parseToken(const String& input, unsigned& startIndex) >+{ >+ const unsigned inputLenght = input.length(); >+ const unsigned index = startIndex; >+ unsigned& tokenLength = startIndex; >+ >+ if (tokenLength >= inputLenght) >+ return SubstringRange(); >+ >+ while (tokenLength < inputLenght) { >+ if (!isTokenCharacter(input[tokenLength])) >+ return SubstringRange(index, tokenLength); >+ ++tokenLength; >+ } >+ >+ return SubstringRange(index, tokenLength); >+} >+ >+static SubstringRange parseQuotedString(const String& input, unsigned& startIndex) >+{ >+ const unsigned inputLenght = input.length(); >+ const unsigned index = startIndex; >+ unsigned& stringLength = startIndex; >+ >+ if (stringLength >= inputLenght) >+ return SubstringRange(); >+ >+ if (input[stringLength++] != '"' || stringLength >= inputLenght) >+ return SubstringRange(); >+ >+ bool lastCharacterWasBackslash = false; >+ char currentCharacter; >+ while ((currentCharacter = input[stringLength++]) != '"' || lastCharacterWasBackslash) { >+ if (stringLength >= inputLenght) >+ return SubstringRange(); >+ if (currentCharacter == '\\' && !lastCharacterWasBackslash) { >+ lastCharacterWasBackslash = true; >+ continue; >+ } >+ if (lastCharacterWasBackslash) >+ lastCharacterWasBackslash = false; >+ } >+ return SubstringRange(index, stringLength); >+} >+ >+static String substringForRange(const String& string, const SubstringRange& range) >+{ >+ return string.substring(range.first, range.second); >+} >+ >+// From http://tools.ietf.org/html/rfc2045#section-5.1: >+// >+// content := "Content-Type" ":" type "/" subtype >+// *(";" parameter) >+// ; Matching of media type and subtype >+// ; is ALWAYS case-insensitive. >+// >+// type := discrete-type / composite-type >+// >+// discrete-type := "text" / "image" / "audio" / "video" / >+// "application" / extension-token >+// >+// composite-type := "message" / "multipart" / extension-token >+// >+// extension-token := ietf-token / x-token >+// >+// ietf-token := <An extension token defined by a >+// standards-track RFC and registered >+// with IANA.> >+// >+// x-token := <The two characters "X-" or "x-" followed, with >+// no intervening white space, by any token> >+// >+// subtype := extension-token / iana-token >+// >+// iana-token := <A publicly-defined extension token. Tokens >+// of this form must be registered with IANA >+// as specified in RFC 2048.> >+// >+// parameter := attribute "=" value >+// >+// attribute := token >+// ; Matching of attributes >+// ; is ALWAYS case-insensitive. >+// >+// value := token / quoted-string >+// >+// token := 1*<any (US-ASCII) CHAR except SPACE, CTLs, >+// or tspecials> >+// >+// tspecials := "(" / ")" / "<" / ">" / "@" / >+// "," / ";" / ":" / "\" / <"> >+// "/" / "[" / "]" / "?" / "=" >+// ; Must be in quoted-string, >+// ; to use within parameter values >+ >+template <class T> >+bool parseContentType(const String& contentType, T& parserType) >+{ >+ if (contentType.contains('\r') || contentType.contains('\n')) >+ return false; >+ >+ unsigned index = 0; >+ unsigned contentTypeLength = contentType.length(); >+ skipSpaces(contentType, index); >+ if (index >= contentTypeLength) { >+ LOG_ERROR("Invalid Content-Type string '%s'", contentType.ascii().data()); >+ return false; >+ } >+ >+ // There should not be any quoted strings until we reach the parameters. >+ size_t semiColonIndex = contentType.find(';', index); >+ if (semiColonIndex == notFound) { >+ parserType.setContentType(SubstringRange(index, contentTypeLength)); >+ return true; >+ } >+ >+ parserType.setContentType(SubstringRange(index, semiColonIndex - index)); >+ index = semiColonIndex + 1; >+ while (true) { >+ skipSpaces(contentType, index); >+ SubstringRange keyRange = parseToken(contentType, index); >+ if (!keyRange.second || index >= contentTypeLength) { >+ LOG_ERROR("Invalid Content-Type parameter name."); >+ return false; >+ } >+ >+ // Should we tolerate spaces here? >+ if (contentType[index++] != '=' || index >= contentTypeLength) { >+ LOG_ERROR("Invalid Content-Type malformed parameter."); >+ return false; >+ } >+ >+ // Should we tolerate spaces here? >+ String value; >+ SubstringRange valueRange; >+ if (contentType[index] == '"') >+ valueRange = parseQuotedString(contentType, index); >+ else >+ valueRange = parseToken(contentType, index); >+ >+ if (!valueRange.second) { >+ LOG_ERROR("Invalid Content-Type, invalid parameter value."); >+ return false; >+ } >+ >+ // Should we tolerate spaces here? >+ if (index < contentTypeLength && contentType[index++] != ';') { >+ LOG_ERROR("Invalid Content-Type, invalid character at the end of key/value parameter."); >+ return false; >+ } >+ >+ parserType.setContentTypeParameter(keyRange, valueRange); >+ >+ if (index >= contentTypeLength) >+ return true; >+ } >+ >+ return true; >+} >+ >+bool isValidContentType(const String& contentType) >+{ >+ EmptyParsedContentType parsedContentType = EmptyParsedContentType(); >+ return parseContentType<EmptyParsedContentType>(contentType, parsedContentType); >+} >+ >+ParsedContentType::ParsedContentType(const String& contentType) >+ : m_contentType(contentType.stripWhiteSpace()) >+{ >+ parseContentType<ParsedContentType>(m_contentType, *this); >+} >+ >+String ParsedContentType::charset() const >+{ >+ return parameterValueForName("charset"); >+} >+ >+String ParsedContentType::parameterValueForName(const String& name) const >+{ >+ return m_parameters.get(name); >+} >+ >+size_t ParsedContentType::parameterCount() const >+{ >+ return m_parameters.size(); >+} >+ >+void ParsedContentType::setContentType(const SubstringRange& contentRange) >+{ >+ m_mimeType = substringForRange(m_contentType, contentRange).stripWhiteSpace(); >+} >+ >+void ParsedContentType::setContentTypeParameter(const SubstringRange& key, const SubstringRange& value) >+{ >+ m_parameters.set(substringForRange(m_contentType, key), substringForRange(m_contentType, value)); >+} >+ >+} >diff --git a/Source/WebCore/platform/network/ParsedContentType.h b/Source/WebCore/platform/network/ParsedContentType.h >new file mode 100644 >index 0000000..6119035 >--- /dev/null >+++ b/Source/WebCore/platform/network/ParsedContentType.h >@@ -0,0 +1,70 @@ >+/* >+ * Copyright (C) 2011 Google Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions are >+ * met: >+ * >+ * * Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * * Redistributions in binary form must reproduce the above >+ * copyright notice, this list of conditions and the following disclaimer >+ * in the documentation and/or other materials provided with the >+ * distribution. >+ * * Neither the name of Google Inc. nor the names of its >+ * contributors may be used to endorse or promote products derived from >+ * this software without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT >+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#ifndef ParsedContentType_h >+#define ParsedContentType_h >+ >+#include <wtf/HashMap.h> >+#include <wtf/text/StringHash.h> >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+// <index, length> >+typedef std::pair<unsigned, unsigned> SubstringRange; >+bool isValidContentType(const String&); >+ >+// FIXME: add support for comments. >+class ParsedContentType { >+public: >+ explicit ParsedContentType(const String&); >+ >+ String mimeType() const { return m_mimeType; } >+ String charset() const; >+ >+ // Note that in the case of multiple values for the same name, the last value is returned. >+ String parameterValueForName(const String&) const; >+ size_t parameterCount() const; >+ >+private: >+ template<class T> >+ friend bool parseContentType(const String&, T&); >+ void setContentType(const SubstringRange&); >+ void setContentTypeParameter(const SubstringRange&, const SubstringRange&); >+ >+ typedef HashMap<String, String> KeyValuePairs; >+ String m_contentType; >+ KeyValuePairs m_parameters; >+ String m_mimeType; >+}; >+ >+} >+ >+#endif
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 100927
:
171796
|
172034
|
172037
|
172289
|
172318
|
172365
|
174924
|
174950