| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/balsa/balsa_frame.h" | 5 #include "net/tools/balsa/balsa_frame.h" |
| 6 | 6 |
| 7 // Visual C++ defines _M_IX86_FP as 2 if the /arch:SSE2 compiler option is | 7 // Visual C++ defines _M_IX86_FP as 2 if the /arch:SSE2 compiler option is |
| 8 // specified. | 8 // specified. |
| 9 #if !defined(__SSE2__) && _M_IX86_FP == 2 | 9 #if !defined(__SSE2__) && _M_IX86_FP == 2 |
| 10 #define __SSE2__ 1 | 10 #define __SSE2__ 1 |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 #if __SSE2__ | 14 #if __SSE2__ |
| 15 #include <emmintrin.h> | 15 #include <emmintrin.h> |
| 16 #endif // __SSE2__ | 16 #endif // __SSE2__ |
| 17 | 17 |
| 18 #include <limits> | 18 #include <limits> |
| 19 #include <string> | 19 #include <string> |
| 20 #include <utility> | 20 #include <utility> |
| 21 #include <vector> | 21 #include <vector> |
| 22 | 22 |
| 23 #include "base/logging.h" | 23 #include "base/logging.h" |
| 24 #include "base/strings/string_piece.h" | 24 #include "base/strings/string_piece.h" |
| 25 #include "base/strings/string_util.h" |
| 25 #include "net/tools/balsa/balsa_enums.h" | 26 #include "net/tools/balsa/balsa_enums.h" |
| 26 #include "net/tools/balsa/balsa_headers.h" | 27 #include "net/tools/balsa/balsa_headers.h" |
| 27 #include "net/tools/balsa/balsa_visitor_interface.h" | 28 #include "net/tools/balsa/balsa_visitor_interface.h" |
| 28 #include "net/tools/balsa/buffer_interface.h" | 29 #include "net/tools/balsa/buffer_interface.h" |
| 29 #include "net/tools/balsa/simple_buffer.h" | 30 #include "net/tools/balsa/simple_buffer.h" |
| 30 #include "net/tools/balsa/split.h" | 31 #include "net/tools/balsa/split.h" |
| 31 #include "net/tools/balsa/string_piece_utils.h" | 32 #include "net/tools/balsa/string_piece_utils.h" |
| 32 | 33 |
| 33 #if defined(COMPILER_MSVC) | 34 #if defined(COMPILER_MSVC) |
| 34 #include <intrin.h> | 35 #include <intrin.h> |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 } else { | 718 } else { |
| 718 const char* start = p; | 719 const char* start = p; |
| 719 while (++p != end && *p != delim) { | 720 while (++p != end && *p != delim) { |
| 720 // Skip to the next occurence of the delimiter. | 721 // Skip to the next occurence of the delimiter. |
| 721 } | 722 } |
| 722 *before = base::StringPiece(start, p - start); | 723 *before = base::StringPiece(start, p - start); |
| 723 if (p != end) | 724 if (p != end) |
| 724 *after = base::StringPiece(p + 1, end - (p + 1)); | 725 *after = base::StringPiece(p + 1, end - (p + 1)); |
| 725 else | 726 else |
| 726 *after = base::StringPiece(""); | 727 *after = base::StringPiece(""); |
| 727 StringPieceUtils::RemoveWhitespaceContext(before); | 728 *before = base::TrimWhitespaceASCII(*before, base::TRIM_ALL); |
| 728 StringPieceUtils::RemoveWhitespaceContext(after); | 729 *after = base::TrimWhitespaceASCII(*after, base::TRIM_ALL); |
| 729 return true; | 730 return true; |
| 730 } | 731 } |
| 731 } | 732 } |
| 732 | 733 |
| 733 *before = original; | 734 *before = original; |
| 734 *after = ""; | 735 *after = ""; |
| 735 return false; | 736 return false; |
| 736 } | 737 } |
| 737 | 738 |
| 738 // TODO(phython): Fix this function to properly deal with quoted values. | 739 // TODO(phython): Fix this function to properly deal with quoted values. |
| 739 // E.g. ";;foo", "\";;\"", or \"aa; | 740 // E.g. ";;foo", "\";;\"", or \"aa; |
| 740 // The last example, the semi-colon is a separator between extensions. | 741 // The last example, the semi-colon is a separator between extensions. |
| 741 void ProcessChunkExtensionsManual(base::StringPiece all_extensions, | 742 void ProcessChunkExtensionsManual(base::StringPiece all_extensions, |
| 742 BalsaHeaders* extensions) { | 743 BalsaHeaders* extensions) { |
| 743 base::StringPiece extension; | 744 base::StringPiece extension; |
| 744 base::StringPiece remaining; | 745 base::StringPiece remaining; |
| 745 StringPieceUtils::RemoveWhitespaceContext(&all_extensions); | 746 all_extensions = base::TrimWhitespaceASCII(all_extensions, base::TRIM_ALL); |
| 746 SplitStringPiece(all_extensions, ';', &extension, &remaining); | 747 SplitStringPiece(all_extensions, ';', &extension, &remaining); |
| 747 while (!extension.empty()) { | 748 while (!extension.empty()) { |
| 748 base::StringPiece key; | 749 base::StringPiece key; |
| 749 base::StringPiece value; | 750 base::StringPiece value; |
| 750 SplitStringPiece(extension, '=', &key, &value); | 751 SplitStringPiece(extension, '=', &key, &value); |
| 751 if (!value.empty()) { | 752 if (!value.empty()) { |
| 752 // Strip quotation marks if they exist. | 753 // Strip quotation marks if they exist. |
| 753 if (!value.empty() && value[0] == '"') | 754 if (!value.empty() && value[0] == '"') |
| 754 value.remove_prefix(1); | 755 value.remove_prefix(1); |
| 755 if (!value.empty() && value[value.length() - 1] == '"') | 756 if (!value.empty() && value[value.length() - 1] == '"') |
| 756 value.remove_suffix(1); | 757 value.remove_suffix(1); |
| 757 } | 758 } |
| 758 | 759 |
| 759 extensions->AppendHeader(key, value); | 760 extensions->AppendHeader(key, value); |
| 760 | 761 |
| 761 StringPieceUtils::RemoveWhitespaceContext(&remaining); | 762 remaining = base::TrimWhitespaceASCII(remaining, base::TRIM_ALL); |
| 762 SplitStringPiece(remaining, ';', &extension, &remaining); | 763 SplitStringPiece(remaining, ';', &extension, &remaining); |
| 763 } | 764 } |
| 764 } | 765 } |
| 765 | 766 |
| 766 } // anonymous namespace | 767 } // anonymous namespace |
| 767 | 768 |
| 768 void BalsaFrame::ProcessChunkExtensions(const char* input, size_t size, | 769 void BalsaFrame::ProcessChunkExtensions(const char* input, size_t size, |
| 769 BalsaHeaders* extensions) { | 770 BalsaHeaders* extensions) { |
| 770 ProcessChunkExtensionsManual(base::StringPiece(input, size), extensions); | 771 ProcessChunkExtensionsManual(base::StringPiece(input, size), extensions); |
| 771 } | 772 } |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 << "$$$$$$$$$$$$$$$" | 1567 << "$$$$$$$$$$$$$$$" |
| 1567 << " consumed: " << (current - input); | 1568 << " consumed: " << (current - input); |
| 1568 if (Error()) { | 1569 if (Error()) { |
| 1569 LOG(INFO) << BalsaFrameEnums::ErrorCodeToString(ErrorCode()); | 1570 LOG(INFO) << BalsaFrameEnums::ErrorCodeToString(ErrorCode()); |
| 1570 } | 1571 } |
| 1571 #endif // DEBUGFRAMER | 1572 #endif // DEBUGFRAMER |
| 1572 return current - input; | 1573 return current - input; |
| 1573 } | 1574 } |
| 1574 | 1575 |
| 1575 } // namespace net | 1576 } // namespace net |
| OLD | NEW |