| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "net/ftp/ftp_directory_listing_buffer.h" | 5 #include "net/ftp/ftp_directory_listing_buffer.h" |
| 6 | 6 |
| 7 #include "base/i18n/icu_string_conversions.h" | 7 #include "base/i18n/icu_string_conversions.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 | 59 |
| 60 return ParseLines(); | 60 return ParseLines(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 int FtpDirectoryListingBuffer::ProcessRemainingData() { | 63 int FtpDirectoryListingBuffer::ProcessRemainingData() { |
| 64 int rv = ExtractFullLinesFromBuffer(); | 64 int rv = ExtractFullLinesFromBuffer(); |
| 65 if (rv != OK) | 65 if (rv != OK) |
| 66 return rv; | 66 return rv; |
| 67 | 67 |
| 68 if (!buffer_.empty()) |
| 69 return ERR_INVALID_RESPONSE; |
| 70 |
| 68 return ParseLines(); | 71 return ParseLines(); |
| 69 } | 72 } |
| 70 | 73 |
| 71 bool FtpDirectoryListingBuffer::EntryAvailable() const { | 74 bool FtpDirectoryListingBuffer::EntryAvailable() const { |
| 72 return (current_parser_ ? current_parser_->EntryAvailable() : false); | 75 return (current_parser_ ? current_parser_->EntryAvailable() : false); |
| 73 } | 76 } |
| 74 | 77 |
| 75 FtpDirectoryListingEntry FtpDirectoryListingBuffer::PopEntry() { | 78 FtpDirectoryListingEntry FtpDirectoryListingBuffer::PopEntry() { |
| 76 DCHECK(EntryAvailable()); | 79 DCHECK(EntryAvailable()); |
| 77 return current_parser_->PopEntry(); | 80 return current_parser_->PopEntry(); |
| 78 } | 81 } |
| 79 | 82 |
| 83 FtpServerType FtpDirectoryListingBuffer::GetServerType() const { |
| 84 return (current_parser_ ? current_parser_->GetServerType() : SERVER_UNKNOWN); |
| 85 } |
| 86 |
| 80 bool FtpDirectoryListingBuffer::ConvertToDetectedEncoding( | 87 bool FtpDirectoryListingBuffer::ConvertToDetectedEncoding( |
| 81 const std::string& from, string16* to) { | 88 const std::string& from, string16* to) { |
| 82 std::string encoding(encoding_.empty() ? "ascii" : encoding_); | 89 std::string encoding(encoding_.empty() ? "ascii" : encoding_); |
| 83 return base::CodepageToUTF16(from, encoding.c_str(), | 90 return base::CodepageToUTF16(from, encoding.c_str(), |
| 84 base::OnStringConversionError::FAIL, to); | 91 base::OnStringConversionError::FAIL, to); |
| 85 } | 92 } |
| 86 | 93 |
| 87 int FtpDirectoryListingBuffer::ExtractFullLinesFromBuffer() { | 94 int FtpDirectoryListingBuffer::ExtractFullLinesFromBuffer() { |
| 88 if (encoding_.empty()) | 95 if (encoding_.empty()) |
| 89 encoding_ = DetectEncoding(buffer_); | 96 encoding_ = DetectEncoding(buffer_); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT; | 138 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT; |
| 132 if (parsers_.size() == 1) | 139 if (parsers_.size() == 1) |
| 133 current_parser_ = *parsers_.begin(); | 140 current_parser_ = *parsers_.begin(); |
| 134 } | 141 } |
| 135 } | 142 } |
| 136 | 143 |
| 137 return OK; | 144 return OK; |
| 138 } | 145 } |
| 139 | 146 |
| 140 } // namespace net | 147 } // namespace net |
| OLD | NEW |