| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http/http_content_disposition.h" | 5 #include "net/http/http_content_disposition.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_tokenizer.h" | 9 #include "base/strings/string_tokenizer.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // decoding a quoted-printable string. Returns true if the input was valid. | 27 // decoding a quoted-printable string. Returns true if the input was valid. |
| 28 bool DecodeQEncoding(const std::string& input, std::string* output) { | 28 bool DecodeQEncoding(const std::string& input, std::string* output) { |
| 29 std::string temp; | 29 std::string temp; |
| 30 temp.reserve(input.size()); | 30 temp.reserve(input.size()); |
| 31 for (std::string::const_iterator it = input.begin(); it != input.end(); | 31 for (std::string::const_iterator it = input.begin(); it != input.end(); |
| 32 ++it) { | 32 ++it) { |
| 33 if (*it == '_') { | 33 if (*it == '_') { |
| 34 temp.push_back(' '); | 34 temp.push_back(' '); |
| 35 } else if (*it == '=') { | 35 } else if (*it == '=') { |
| 36 if ((input.end() - it < 3) || | 36 if ((input.end() - it < 3) || |
| 37 !IsHexDigit(static_cast<unsigned char>(*(it + 1))) || | 37 !base::IsHexDigit(static_cast<unsigned char>(*(it + 1))) || |
| 38 !IsHexDigit(static_cast<unsigned char>(*(it + 2)))) | 38 !base::IsHexDigit(static_cast<unsigned char>(*(it + 2)))) |
| 39 return false; | 39 return false; |
| 40 unsigned char ch = HexDigitToInt(*(it + 1)) * 16 + | 40 unsigned char ch = |
| 41 HexDigitToInt(*(it + 2)); | 41 base::HexDigitToInt(*(it + 1)) * 16 + base::HexDigitToInt(*(it + 2)); |
| 42 temp.push_back(static_cast<char>(ch)); | 42 temp.push_back(static_cast<char>(ch)); |
| 43 ++it; | 43 ++it; |
| 44 ++it; | 44 ++it; |
| 45 } else if (0x20 < *it && *it < 0x7F && *it != '?') { | 45 } else if (0x20 < *it && *it < 0x7F && *it != '?') { |
| 46 // In a Q-encoded word, only printable ASCII characters | 46 // In a Q-encoded word, only printable ASCII characters |
| 47 // represent themselves. Besides, space, '=', '_' and '?' are | 47 // represent themselves. Besides, space, '=', '_' and '?' are |
| 48 // not allowed, but they're already filtered out. | 48 // not allowed, but they're already filtered out. |
| 49 DCHECK_NE('=', *it); | 49 DCHECK_NE('=', *it); |
| 50 DCHECK_NE('?', *it); | 50 DCHECK_NE('?', *it); |
| 51 DCHECK_NE('_', *it); | 51 DCHECK_NE('_', *it); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // If the disposition-type isn't a valid token the then the | 352 // If the disposition-type isn't a valid token the then the |
| 353 // Content-Disposition header is malformed, and we treat the first bytes as | 353 // Content-Disposition header is malformed, and we treat the first bytes as |
| 354 // a parameter rather than a disposition-type. | 354 // a parameter rather than a disposition-type. |
| 355 if (!HttpUtil::IsToken(type_begin, type_end)) | 355 if (!HttpUtil::IsToken(type_begin, type_end)) |
| 356 return begin; | 356 return begin; |
| 357 | 357 |
| 358 parse_result_flags_ |= HAS_DISPOSITION_TYPE; | 358 parse_result_flags_ |= HAS_DISPOSITION_TYPE; |
| 359 | 359 |
| 360 DCHECK(std::find(type_begin, type_end, '=') == type_end); | 360 DCHECK(std::find(type_begin, type_end, '=') == type_end); |
| 361 | 361 |
| 362 if (LowerCaseEqualsASCII(type_begin, type_end, "inline")) { | 362 if (base::LowerCaseEqualsASCII(type_begin, type_end, "inline")) { |
| 363 type_ = INLINE; | 363 type_ = INLINE; |
| 364 } else if (LowerCaseEqualsASCII(type_begin, type_end, "attachment")) { | 364 } else if (base::LowerCaseEqualsASCII(type_begin, type_end, "attachment")) { |
| 365 type_ = ATTACHMENT; | 365 type_ = ATTACHMENT; |
| 366 } else { | 366 } else { |
| 367 parse_result_flags_ |= HAS_UNKNOWN_DISPOSITION_TYPE; | 367 parse_result_flags_ |= HAS_UNKNOWN_DISPOSITION_TYPE; |
| 368 type_ = ATTACHMENT; | 368 type_ = ATTACHMENT; |
| 369 } | 369 } |
| 370 return delimiter; | 370 return delimiter; |
| 371 } | 371 } |
| 372 | 372 |
| 373 // http://tools.ietf.org/html/rfc6266 | 373 // http://tools.ietf.org/html/rfc6266 |
| 374 // | 374 // |
| (...skipping 20 matching lines...) Expand all Loading... |
| 395 | 395 |
| 396 std::string::const_iterator pos = header.begin(); | 396 std::string::const_iterator pos = header.begin(); |
| 397 std::string::const_iterator end = header.end(); | 397 std::string::const_iterator end = header.end(); |
| 398 pos = ConsumeDispositionType(pos, end); | 398 pos = ConsumeDispositionType(pos, end); |
| 399 | 399 |
| 400 std::string filename; | 400 std::string filename; |
| 401 std::string ext_filename; | 401 std::string ext_filename; |
| 402 | 402 |
| 403 HttpUtil::NameValuePairsIterator iter(pos, end, ';'); | 403 HttpUtil::NameValuePairsIterator iter(pos, end, ';'); |
| 404 while (iter.GetNext()) { | 404 while (iter.GetNext()) { |
| 405 if (filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), | 405 if (filename.empty() && |
| 406 iter.name_end(), | 406 base::LowerCaseEqualsASCII(iter.name_begin(), iter.name_end(), |
| 407 "filename")) { | 407 "filename")) { |
| 408 DecodeFilenameValue(iter.value(), referrer_charset, &filename, | 408 DecodeFilenameValue(iter.value(), referrer_charset, &filename, |
| 409 &parse_result_flags_); | 409 &parse_result_flags_); |
| 410 if (!filename.empty()) | 410 if (!filename.empty()) |
| 411 parse_result_flags_ |= HAS_FILENAME; | 411 parse_result_flags_ |= HAS_FILENAME; |
| 412 } else if (ext_filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), | 412 } else if (ext_filename.empty() && |
| 413 iter.name_end(), | 413 base::LowerCaseEqualsASCII(iter.name_begin(), iter.name_end(), |
| 414 "filename*")) { | 414 "filename*")) { |
| 415 DecodeExtValue(iter.raw_value(), &ext_filename); | 415 DecodeExtValue(iter.raw_value(), &ext_filename); |
| 416 if (!ext_filename.empty()) | 416 if (!ext_filename.empty()) |
| 417 parse_result_flags_ |= HAS_EXT_FILENAME; | 417 parse_result_flags_ |= HAS_EXT_FILENAME; |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 | 420 |
| 421 if (!ext_filename.empty()) | 421 if (!ext_filename.empty()) |
| 422 filename_ = ext_filename; | 422 filename_ = ext_filename; |
| 423 else | 423 else |
| 424 filename_ = filename; | 424 filename_ = filename; |
| 425 } | 425 } |
| 426 | 426 |
| 427 } // namespace net | 427 } // namespace net |
| OLD | NEW |