Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Intel Corporation. All rights reserved. | 3 * Copyright (C) 2012 Intel Corporation. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #ifndef ParsedContentType_h | 32 #ifndef ParsedParameterizedContentHeaderField_h |
| 33 #define ParsedContentType_h | 33 #define ParsedParameterizedContentHeaderField_h |
| 34 | 34 |
| 35 #include "platform/PlatformExport.h" | 35 #include "platform/PlatformExport.h" |
| 36 #include "platform/wtf/Allocator.h" | 36 #include "platform/wtf/Allocator.h" |
| 37 #include "platform/wtf/HashMap.h" | 37 #include "platform/wtf/HashMap.h" |
| 38 #include "platform/wtf/text/StringHash.h" | 38 #include "platform/wtf/text/StringHash.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 // ParsedContentType parses the constructor argument as specified in RFC2045 | 42 // ParsedParameterizedContentHeaderField parses the constructor argument as |
| 43 // and stores the result. | 43 // specified in RFC2045 and stores the result. |
| 44 // FIXME: add support for comments. | 44 // FIXME: add support for comments. |
| 45 class PLATFORM_EXPORT ParsedContentType final { | 45 class PLATFORM_EXPORT ParsedParameterizedContentHeaderField { |
|
yhirano
2017/05/15 11:14:51
Please write tests.
e_hakkinen
2017/05/18 09:35:48
Done.
| |
| 46 STACK_ALLOCATED(); | 46 STACK_ALLOCATED(); |
| 47 | 47 |
| 48 public: | 48 public: |
| 49 // When |Relaxed| is specified, the parser parses parameter values in a sloppy | 49 // When |Relaxed| is specified, the parser parses parameter values in a sloppy |
| 50 // manner, i.e., only ';' and '"' are treated as special characters. | 50 // manner, i.e., only ';' and '"' are treated as special characters. |
| 51 // See https://chromiumcodereview.appspot.com/23043002. | 51 // See https://chromiumcodereview.appspot.com/23043002. |
| 52 // When |Strict| is specified, the parser does not allow multiple values | 52 // When |Strict| is specified, the parser does not allow multiple values |
| 53 // for the same parameter. Some RFCs based on RFC2045 (e.g. RFC6838) note that | 53 // for the same parameter. Some RFCs based on RFC2045 (e.g. RFC6838) note that |
| 54 // "It is an error for a specific parameter to be specified more than once." | 54 // "It is an error for a specific parameter to be specified more than once." |
| 55 enum class Mode { | 55 enum class Mode { |
| 56 kNormal, | 56 kNormal, |
| 57 kRelaxed, | 57 kRelaxed, |
| 58 kStrict, | 58 kStrict, |
| 59 }; | 59 }; |
| 60 explicit ParsedContentType(const String&, Mode = Mode::kNormal); | |
| 61 | 60 |
| 62 String MimeType() const { return mime_type_; } | 61 explicit ParsedParameterizedContentHeaderField(const String&, |
| 63 String Charset() const; | 62 Mode = Mode::kNormal); |
| 63 | |
| 64 String Type() const { return type_; } | |
| 64 | 65 |
| 65 // Note that in the case of multiple values for the same name, the last value | 66 // Note that in the case of multiple values for the same name, the last value |
| 66 // is returned. | 67 // is returned. |
| 67 String ParameterValueForName(const String&) const; | 68 String ParameterValueForName(const String&) const; |
| 68 size_t ParameterCount() const; | 69 size_t ParameterCount() const; |
| 69 | 70 |
| 70 bool IsValid() const { return is_valid_; } | 71 bool IsValid() const { return is_valid_; } |
| 71 | 72 |
| 73 protected: | |
| 74 class Input final { | |
| 75 public: | |
| 76 explicit Input(const String& header_field); | |
| 77 | |
| 78 bool Consume(char); | |
| 79 bool ConsumeToken(Mode, StringView& output); | |
| 80 bool ConsumeTokenOrQuotedString(Mode, String& output); | |
| 81 unsigned Index() const { return index_; } | |
| 82 bool IsConsumed() const { return index_ >= input_.length(); } | |
| 83 void SkipSpaces(); | |
| 84 | |
| 85 private: | |
| 86 bool ConsumeQuotedString(String& output); | |
| 87 | |
| 88 unsigned index_; | |
| 89 String input_; | |
|
horo
2017/05/15 05:57:54
nit: const String input_;
e_hakkinen
2017/05/18 09:35:48
Done.
| |
| 90 }; | |
| 91 | |
| 92 ParsedParameterizedContentHeaderField(); | |
| 93 | |
| 94 bool ParseParameters(Input&, Mode); | |
| 95 void SetType(const String& type) { type_ = type; } | |
| 96 | |
| 72 private: | 97 private: |
| 73 bool Parse(const String&); | 98 bool Parse(const String&, Mode); |
| 74 | 99 |
| 75 const Mode mode_; | |
| 76 bool is_valid_; | 100 bool is_valid_; |
| 77 | 101 |
| 78 typedef HashMap<String, String> KeyValuePairs; | 102 typedef HashMap<String, String> KeyValuePairs; |
| 79 KeyValuePairs parameters_; | 103 KeyValuePairs parameters_; |
| 80 String mime_type_; | 104 String type_; |
| 81 }; | 105 }; |
| 82 | 106 |
| 83 } // namespace blink | 107 } // namespace blink |
| 84 | 108 |
| 85 #endif | 109 #endif |
| OLD | NEW |