| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 int FtpDirectoryListingBuffer::ProcessRemainingData() { | 65 int FtpDirectoryListingBuffer::ProcessRemainingData() { |
| 66 int rv = ExtractFullLinesFromBuffer(); | 66 int rv = ExtractFullLinesFromBuffer(); |
| 67 if (rv != OK) | 67 if (rv != OK) |
| 68 return rv; | 68 return rv; |
| 69 | 69 |
| 70 if (!buffer_.empty()) | 70 if (!buffer_.empty()) |
| 71 return ERR_INVALID_RESPONSE; | 71 return ERR_INVALID_RESPONSE; |
| 72 | 72 |
| 73 return ParseLines(); | 73 rv = ParseLines(); |
| 74 if (rv != OK) |
| 75 return rv; |
| 76 |
| 77 rv = OnEndOfInput(); |
| 78 if (rv != OK) |
| 79 return rv; |
| 80 |
| 81 DCHECK(current_parser_); |
| 82 return OK; |
| 74 } | 83 } |
| 75 | 84 |
| 76 bool FtpDirectoryListingBuffer::EntryAvailable() const { | 85 bool FtpDirectoryListingBuffer::EntryAvailable() const { |
| 77 return (current_parser_ ? current_parser_->EntryAvailable() : false); | 86 return (current_parser_ ? current_parser_->EntryAvailable() : false); |
| 78 } | 87 } |
| 79 | 88 |
| 80 FtpDirectoryListingEntry FtpDirectoryListingBuffer::PopEntry() { | 89 FtpDirectoryListingEntry FtpDirectoryListingBuffer::PopEntry() { |
| 81 DCHECK(EntryAvailable()); | 90 DCHECK(EntryAvailable()); |
| 82 return current_parser_->PopEntry(); | 91 return current_parser_->PopEntry(); |
| 83 } | 92 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 if (parsers_.empty()) | 148 if (parsers_.empty()) |
| 140 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT; | 149 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT; |
| 141 if (parsers_.size() == 1) | 150 if (parsers_.size() == 1) |
| 142 current_parser_ = *parsers_.begin(); | 151 current_parser_ = *parsers_.begin(); |
| 143 } | 152 } |
| 144 } | 153 } |
| 145 | 154 |
| 146 return OK; | 155 return OK; |
| 147 } | 156 } |
| 148 | 157 |
| 158 int FtpDirectoryListingBuffer::OnEndOfInput() { |
| 159 ParserSet::iterator i = parsers_.begin(); |
| 160 while (i != parsers_.end()) { |
| 161 if ((*i)->OnEndOfInput()) { |
| 162 i++; |
| 163 } else { |
| 164 delete *i; |
| 165 parsers_.erase(i++); |
| 166 } |
| 167 } |
| 168 |
| 169 if (parsers_.size() != 1) { |
| 170 current_parser_ = NULL; |
| 171 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT; |
| 172 } |
| 173 |
| 174 current_parser_ = *parsers_.begin(); |
| 175 return OK; |
| 176 } |
| 177 |
| 149 } // namespace net | 178 } // namespace net |
| OLD | NEW |