OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 2 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
3 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
4 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 4 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
5 * Copyright (C) 2009 Google Inc. All rights reserved. | 5 * Copyright (C) 2009 Google Inc. All rights reserved. |
6 * Copyright (C) 2011 Apple Inc. All Rights Reserved. | 6 * Copyright (C) 2011 Apple Inc. All Rights Reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 154 |
155 // suborigin-name = LOWERALPHA *( LOWERALPHA / DIGIT ) | 155 // suborigin-name = LOWERALPHA *( LOWERALPHA / DIGIT ) |
156 // | 156 // |
157 // Does not trim whitespace before or after the suborigin-name. | 157 // Does not trim whitespace before or after the suborigin-name. |
158 const UChar* parseSuboriginName(const UChar* begin, | 158 const UChar* parseSuboriginName(const UChar* begin, |
159 const UChar* end, | 159 const UChar* end, |
160 String& name, | 160 String& name, |
161 WTF::Vector<String>& messages) { | 161 WTF::Vector<String>& messages) { |
162 // Parse the name of the suborigin (no spaces, single string) | 162 // Parse the name of the suborigin (no spaces, single string) |
163 if (begin == end) { | 163 if (begin == end) { |
164 messages.append(String("No Suborigin name specified.")); | 164 messages.push_back(String("No Suborigin name specified.")); |
165 return nullptr; | 165 return nullptr; |
166 } | 166 } |
167 | 167 |
168 const UChar* position = begin; | 168 const UChar* position = begin; |
169 | 169 |
170 if (!skipExactly<UChar, isASCIILower>(position, end)) { | 170 if (!skipExactly<UChar, isASCIILower>(position, end)) { |
171 messages.append("Invalid character \'" + String(position, 1) + | 171 messages.push_back("Invalid character \'" + String(position, 1) + |
172 "\' in suborigin. First character must be a lower case " | 172 "\' in suborigin. First character must be a lower case " |
173 "alphabetic character."); | 173 "alphabetic character."); |
174 return nullptr; | 174 return nullptr; |
175 } | 175 } |
176 | 176 |
177 skipWhile<UChar, isASCIILowerAlphaOrDigit>(position, end); | 177 skipWhile<UChar, isASCIILowerAlphaOrDigit>(position, end); |
178 if (position != end && !isASCIISpace(*position)) { | 178 if (position != end && !isASCIISpace(*position)) { |
179 messages.append("Invalid character \'" + String(position, 1) + | 179 messages.push_back("Invalid character \'" + String(position, 1) + |
180 "\' in suborigin."); | 180 "\' in suborigin."); |
181 return nullptr; | 181 return nullptr; |
182 } | 182 } |
183 | 183 |
184 size_t length = position - begin; | 184 size_t length = position - begin; |
185 name = String(begin, length).lower(); | 185 name = String(begin, length).lower(); |
186 return position; | 186 return position; |
187 } | 187 } |
188 | 188 |
189 const UChar* parseSuboriginPolicyOption(const UChar* begin, | 189 const UChar* parseSuboriginPolicyOption(const UChar* begin, |
190 const UChar* end, | 190 const UChar* end, |
191 String& option, | 191 String& option, |
192 WTF::Vector<String>& messages) { | 192 WTF::Vector<String>& messages) { |
193 const UChar* position = begin; | 193 const UChar* position = begin; |
194 | 194 |
195 if (*position != '\'') { | 195 if (*position != '\'') { |
196 messages.append("Invalid character \'" + String(position, 1) + | 196 messages.push_back("Invalid character \'" + String(position, 1) + |
197 "\' in suborigin policy. Suborigin policy options must " | 197 "\' in suborigin policy. Suborigin policy options must " |
198 "start and end with a single quote."); | 198 "start and end with a single quote."); |
199 return nullptr; | 199 return nullptr; |
200 } | 200 } |
201 position = position + 1; | 201 position = position + 1; |
202 | 202 |
203 skipWhile<UChar, isASCIILowerAlphaOrDigitOrHyphen>(position, end); | 203 skipWhile<UChar, isASCIILowerAlphaOrDigitOrHyphen>(position, end); |
204 if (position == end || isASCIISpace(*position)) { | 204 if (position == end || isASCIISpace(*position)) { |
205 messages.append(String("Expected \' to end policy option.")); | 205 messages.push_back(String("Expected \' to end policy option.")); |
206 return nullptr; | 206 return nullptr; |
207 } | 207 } |
208 | 208 |
209 if (*position != '\'') { | 209 if (*position != '\'') { |
210 messages.append("Invalid character \'" + String(position, 1) + | 210 messages.push_back("Invalid character \'" + String(position, 1) + |
211 "\' in suborigin policy."); | 211 "\' in suborigin policy."); |
212 return nullptr; | 212 return nullptr; |
213 } | 213 } |
214 | 214 |
215 ASSERT(position > begin); | 215 ASSERT(position > begin); |
216 size_t length = (position + 1) - begin; | 216 size_t length = (position + 1) - begin; |
217 | 217 |
218 option = String(begin, length); | 218 option = String(begin, length); |
219 return position + 1; | 219 return position + 1; |
220 } | 220 } |
221 | 221 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 safeHeader.substring(pos, nextEqualSignPosition - pos) | 631 safeHeader.substring(pos, nextEqualSignPosition - pos) |
632 .stripWhiteSpace()); | 632 .stripWhiteSpace()); |
633 pos += nextEqualSignPosition - pos + 1; | 633 pos += nextEqualSignPosition - pos + 1; |
634 | 634 |
635 String value = safeHeader.substring(pos, max - pos).stripWhiteSpace(); | 635 String value = safeHeader.substring(pos, max - pos).stripWhiteSpace(); |
636 if (value[0] == '"') { | 636 if (value[0] == '"') { |
637 // The value is a quoted string | 637 // The value is a quoted string |
638 size_t nextDoubleQuotePosition = value.find('"', 1); | 638 size_t nextDoubleQuotePosition = value.find('"', 1); |
639 if (nextDoubleQuotePosition != kNotFound) { | 639 if (nextDoubleQuotePosition != kNotFound) { |
640 // Store the value as a quoted string without quotes | 640 // Store the value as a quoted string without quotes |
641 result.append(std::pair<String, String>( | 641 result.push_back(std::pair<String, String>( |
642 directive, value.substring(1, nextDoubleQuotePosition - 1) | 642 directive, value.substring(1, nextDoubleQuotePosition - 1) |
643 .stripWhiteSpace())); | 643 .stripWhiteSpace())); |
644 pos += | 644 pos += |
645 (safeHeader.find('"', pos) - pos) + nextDoubleQuotePosition + 1; | 645 (safeHeader.find('"', pos) - pos) + nextDoubleQuotePosition + 1; |
646 // Move past next comma, if there is one | 646 // Move past next comma, if there is one |
647 size_t nextCommaPosition2 = safeHeader.find(',', pos); | 647 size_t nextCommaPosition2 = safeHeader.find(',', pos); |
648 if (nextCommaPosition2 != kNotFound) | 648 if (nextCommaPosition2 != kNotFound) |
649 pos += nextCommaPosition2 - pos + 1; | 649 pos += nextCommaPosition2 - pos + 1; |
650 else | 650 else |
651 return; // Parse error if there is anything left with no comma | 651 return; // Parse error if there is anything left with no comma |
652 } else { | 652 } else { |
653 // Parse error; just use the rest as the value | 653 // Parse error; just use the rest as the value |
654 result.append(std::pair<String, String>( | 654 result.push_back(std::pair<String, String>( |
655 directive, | 655 directive, |
656 trimToNextSeparator( | 656 trimToNextSeparator( |
657 value.substring(1, value.length() - 1).stripWhiteSpace()))); | 657 value.substring(1, value.length() - 1).stripWhiteSpace()))); |
658 return; | 658 return; |
659 } | 659 } |
660 } else { | 660 } else { |
661 // The value is a token until the next comma | 661 // The value is a token until the next comma |
662 size_t nextCommaPosition2 = value.find(','); | 662 size_t nextCommaPosition2 = value.find(','); |
663 if (nextCommaPosition2 != kNotFound) { | 663 if (nextCommaPosition2 != kNotFound) { |
664 // The value is delimited by the next comma | 664 // The value is delimited by the next comma |
665 result.append(std::pair<String, String>( | 665 result.push_back(std::pair<String, String>( |
666 directive, | 666 directive, |
667 trimToNextSeparator( | 667 trimToNextSeparator( |
668 value.substring(0, nextCommaPosition2).stripWhiteSpace()))); | 668 value.substring(0, nextCommaPosition2).stripWhiteSpace()))); |
669 pos += (safeHeader.find(',', pos) - pos) + 1; | 669 pos += (safeHeader.find(',', pos) - pos) + 1; |
670 } else { | 670 } else { |
671 // The rest is the value; no change to value needed | 671 // The rest is the value; no change to value needed |
672 result.append( | 672 result.push_back( |
673 std::pair<String, String>(directive, trimToNextSeparator(value))); | 673 std::pair<String, String>(directive, trimToNextSeparator(value))); |
674 return; | 674 return; |
675 } | 675 } |
676 } | 676 } |
677 } else if (nextCommaPosition != kNotFound && | 677 } else if (nextCommaPosition != kNotFound && |
678 (nextCommaPosition < nextEqualSignPosition || | 678 (nextCommaPosition < nextEqualSignPosition || |
679 nextEqualSignPosition == kNotFound)) { | 679 nextEqualSignPosition == kNotFound)) { |
680 // Add directive to map with empty string as value | 680 // Add directive to map with empty string as value |
681 result.append(std::pair<String, String>( | 681 result.push_back(std::pair<String, String>( |
682 trimToNextSeparator(safeHeader.substring(pos, nextCommaPosition - pos) | 682 trimToNextSeparator(safeHeader.substring(pos, nextCommaPosition - pos) |
683 .stripWhiteSpace()), | 683 .stripWhiteSpace()), |
684 "")); | 684 "")); |
685 pos += nextCommaPosition - pos + 1; | 685 pos += nextCommaPosition - pos + 1; |
686 } else { | 686 } else { |
687 // Add last directive to map with empty string as value | 687 // Add last directive to map with empty string as value |
688 result.append(std::pair<String, String>( | 688 result.push_back(std::pair<String, String>( |
689 trimToNextSeparator( | 689 trimToNextSeparator( |
690 safeHeader.substring(pos, max - pos).stripWhiteSpace()), | 690 safeHeader.substring(pos, max - pos).stripWhiteSpace()), |
691 "")); | 691 "")); |
692 return; | 692 return; |
693 } | 693 } |
694 } | 694 } |
695 } | 695 } |
696 | 696 |
697 CacheControlHeader parseCacheControlDirectives( | 697 CacheControlHeader parseCacheControlDirectives( |
698 const AtomicString& cacheControlValue, | 698 const AtomicString& cacheControlValue, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 headerSet.add(value.stripWhiteSpace(isWhitespace)); | 769 headerSet.add(value.stripWhiteSpace(isWhitespace)); |
770 } | 770 } |
771 | 771 |
772 bool parseSuboriginHeader(const String& header, | 772 bool parseSuboriginHeader(const String& header, |
773 Suborigin* suborigin, | 773 Suborigin* suborigin, |
774 WTF::Vector<String>& messages) { | 774 WTF::Vector<String>& messages) { |
775 Vector<String> headers; | 775 Vector<String> headers; |
776 header.split(',', true, headers); | 776 header.split(',', true, headers); |
777 | 777 |
778 if (headers.size() > 1) | 778 if (headers.size() > 1) |
779 messages.append( | 779 messages.push_back( |
780 "Multiple Suborigin headers found. Ignoring all but the first."); | 780 "Multiple Suborigin headers found. Ignoring all but the first."); |
781 | 781 |
782 Vector<UChar> characters; | 782 Vector<UChar> characters; |
783 headers[0].appendTo(characters); | 783 headers[0].appendTo(characters); |
784 | 784 |
785 const UChar* position = characters.data(); | 785 const UChar* position = characters.data(); |
786 const UChar* end = position + characters.size(); | 786 const UChar* end = position + characters.size(); |
787 | 787 |
788 skipWhile<UChar, isASCIISpace>(position, end); | 788 skipWhile<UChar, isASCIISpace>(position, end); |
789 | 789 |
(...skipping 16 matching lines...) Expand all Loading... |
806 position = parseSuboriginPolicyOption(position, end, optionName, messages); | 806 position = parseSuboriginPolicyOption(position, end, optionName, messages); |
807 | 807 |
808 if (!position) { | 808 if (!position) { |
809 suborigin->clear(); | 809 suborigin->clear(); |
810 return false; | 810 return false; |
811 } | 811 } |
812 | 812 |
813 Suborigin::SuboriginPolicyOptions option = | 813 Suborigin::SuboriginPolicyOptions option = |
814 getSuboriginPolicyOptionFromString(optionName); | 814 getSuboriginPolicyOptionFromString(optionName); |
815 if (option == Suborigin::SuboriginPolicyOptions::None) | 815 if (option == Suborigin::SuboriginPolicyOptions::None) |
816 messages.append("Ignoring unknown suborigin policy option " + optionName + | 816 messages.push_back("Ignoring unknown suborigin policy option " + |
817 "."); | 817 optionName + "."); |
818 else | 818 else |
819 suborigin->addPolicyOption(option); | 819 suborigin->addPolicyOption(option); |
820 } | 820 } |
821 | 821 |
822 return true; | 822 return true; |
823 } | 823 } |
824 | 824 |
825 bool parseMultipartHeadersFromBody(const char* bytes, | 825 bool parseMultipartHeadersFromBody(const char* bytes, |
826 size_t size, | 826 size_t size, |
827 ResourceResponse* response, | 827 ResourceResponse* response, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 StringBuilder sb; | 872 StringBuilder sb; |
873 sb.append("["); | 873 sb.append("["); |
874 sb.append(header); | 874 sb.append(header); |
875 sb.append("]"); | 875 sb.append("]"); |
876 std::unique_ptr<JSONValue> headerValue = | 876 std::unique_ptr<JSONValue> headerValue = |
877 parseJSON(sb.toString(), maxParseDepth); | 877 parseJSON(sb.toString(), maxParseDepth); |
878 return JSONArray::from(std::move(headerValue)); | 878 return JSONArray::from(std::move(headerValue)); |
879 } | 879 } |
880 | 880 |
881 } // namespace blink | 881 } // namespace blink |
OLD | NEW |