Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: net/http/http_chunked_decoder.cc

Issue 193072: Move StringPiece into the base namespace. It is colliding (Closed)
Patch Set: take 2 Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/registry_controlled_domain.cc ('k') | net/http/http_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* ***** BEGIN LICENSE BLOCK ***** 1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 * 3 *
4 * The contents of this file are subject to the Mozilla Public License Version 4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with 5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at 6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/ 7 * http://www.mozilla.org/MPL/
8 * 8 *
9 * Software distributed under the License is distributed on an "AS IS" basis, 9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 return result; 87 return result;
88 } 88 }
89 89
90 int HttpChunkedDecoder::ScanForChunkRemaining(const char* buf, int buf_len) { 90 int HttpChunkedDecoder::ScanForChunkRemaining(const char* buf, int buf_len) {
91 DCHECK(chunk_remaining_ == 0); 91 DCHECK(chunk_remaining_ == 0);
92 DCHECK(buf_len > 0); 92 DCHECK(buf_len > 0);
93 93
94 int bytes_consumed = 0; 94 int bytes_consumed = 0;
95 95
96 size_t index_of_lf = StringPiece(buf, buf_len).find('\n'); 96 size_t index_of_lf = base::StringPiece(buf, buf_len).find('\n');
97 if (index_of_lf != StringPiece::npos) { 97 if (index_of_lf != base::StringPiece::npos) {
98 buf_len = static_cast<int>(index_of_lf); 98 buf_len = static_cast<int>(index_of_lf);
99 if (buf_len && buf[buf_len - 1] == '\r') // Eliminate a preceding CR. 99 if (buf_len && buf[buf_len - 1] == '\r') // Eliminate a preceding CR.
100 buf_len--; 100 buf_len--;
101 bytes_consumed = static_cast<int>(index_of_lf) + 1; 101 bytes_consumed = static_cast<int>(index_of_lf) + 1;
102 102
103 // Make buf point to the full line buffer to parse. 103 // Make buf point to the full line buffer to parse.
104 if (!line_buf_.empty()) { 104 if (!line_buf_.empty()) {
105 line_buf_.append(buf, buf_len); 105 line_buf_.append(buf, buf_len);
106 buf = line_buf_.data(); 106 buf = line_buf_.data();
107 buf_len = static_cast<int>(line_buf_.size()); 107 buf_len = static_cast<int>(line_buf_.size());
108 } 108 }
109 109
110 if (reached_last_chunk_) { 110 if (reached_last_chunk_) {
111 if (buf_len) { 111 if (buf_len) {
112 DLOG(INFO) << "ignoring http trailer"; 112 DLOG(INFO) << "ignoring http trailer";
113 } else { 113 } else {
114 reached_eof_ = true; 114 reached_eof_ = true;
115 } 115 }
116 } else if (chunk_terminator_remaining_) { 116 } else if (chunk_terminator_remaining_) {
117 if (buf_len) { 117 if (buf_len) {
118 DLOG(ERROR) << "chunk data not terminated properly"; 118 DLOG(ERROR) << "chunk data not terminated properly";
119 return ERR_INVALID_CHUNKED_ENCODING; 119 return ERR_INVALID_CHUNKED_ENCODING;
120 } 120 }
121 chunk_terminator_remaining_ = false; 121 chunk_terminator_remaining_ = false;
122 } else if (buf_len) { 122 } else if (buf_len) {
123 // Ignore any chunk-extensions. 123 // Ignore any chunk-extensions.
124 size_t index_of_semicolon = StringPiece(buf, buf_len).find(';'); 124 size_t index_of_semicolon = base::StringPiece(buf, buf_len).find(';');
125 if (index_of_semicolon != StringPiece::npos) 125 if (index_of_semicolon != base::StringPiece::npos)
126 buf_len = static_cast<int>(index_of_semicolon); 126 buf_len = static_cast<int>(index_of_semicolon);
127 127
128 if (!ParseChunkSize(buf, buf_len, &chunk_remaining_)) { 128 if (!ParseChunkSize(buf, buf_len, &chunk_remaining_)) {
129 DLOG(ERROR) << "Failed parsing HEX from: " << 129 DLOG(ERROR) << "Failed parsing HEX from: " <<
130 std::string(buf, buf_len); 130 std::string(buf, buf_len);
131 return ERR_INVALID_CHUNKED_ENCODING; 131 return ERR_INVALID_CHUNKED_ENCODING;
132 } 132 }
133 133
134 if (chunk_remaining_ == 0) 134 if (chunk_remaining_ == 0)
135 reached_last_chunk_ = true; 135 reached_last_chunk_ = true;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // Us: ^\X+[ ]*$ 174 // Us: ^\X+[ ]*$
175 bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) { 175 bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) {
176 DCHECK(len >= 0); 176 DCHECK(len >= 0);
177 177
178 // Strip trailing spaces 178 // Strip trailing spaces
179 while (len && start[len - 1] == ' ') 179 while (len && start[len - 1] == ' ')
180 len--; 180 len--;
181 181
182 // Be more restrictive than HexStringToInt; 182 // Be more restrictive than HexStringToInt;
183 // don't allow inputs with leading "-", "+", "0x", "0X" 183 // don't allow inputs with leading "-", "+", "0x", "0X"
184 if (StringPiece(start, len).find_first_not_of("0123456789abcdefABCDEF")!= 184 if (base::StringPiece(start, len).find_first_not_of("0123456789abcdefABCDEF")
185 StringPiece::npos) 185 != base::StringPiece::npos)
186 return false; 186 return false;
187 187
188 int parsed_number; 188 int parsed_number;
189 bool ok = HexStringToInt(std::string(start, len), &parsed_number); 189 bool ok = HexStringToInt(std::string(start, len), &parsed_number);
190 if (ok && parsed_number >= 0) { 190 if (ok && parsed_number >= 0) {
191 *out = parsed_number; 191 *out = parsed_number;
192 return true; 192 return true;
193 } 193 }
194 return false; 194 return false;
195 } 195 }
196 196
197 } // namespace net 197 } // namespace net
OLDNEW
« no previous file with comments | « net/base/registry_controlled_domain.cc ('k') | net/http/http_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698