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

Side by Side Diff: net/ftp/ftp_directory_listing_buffer.cc

Issue 465059: Implement parser for Netware-style FTP LIST response listing. (Closed)
Patch Set: Created 11 years 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
OLDNEW
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"
11 #include "net/ftp/ftp_directory_listing_parser_ls.h" 11 #include "net/ftp/ftp_directory_listing_parser_ls.h"
12 #include "net/ftp/ftp_directory_listing_parser_netware.h"
12 #include "net/ftp/ftp_directory_listing_parser_vms.h" 13 #include "net/ftp/ftp_directory_listing_parser_vms.h"
13 #include "net/ftp/ftp_directory_listing_parser_windows.h" 14 #include "net/ftp/ftp_directory_listing_parser_windows.h"
14 #include "unicode/ucsdet.h" 15 #include "unicode/ucsdet.h"
15 16
16 namespace { 17 namespace {
17 18
18 // A very simple-minded character encoding detection. 19 // A very simple-minded character encoding detection.
19 // TODO(jungshik): We can apply more heuristics here (e.g. using various hints 20 // TODO(jungshik): We can apply more heuristics here (e.g. using various hints
20 // like TLD, the UI language/default encoding of a client, etc). In that case, 21 // like TLD, the UI language/default encoding of a client, etc). In that case,
21 // this should be pulled out of here and moved somewhere in base because there 22 // this should be pulled out of here and moved somewhere in base because there
(...skipping 15 matching lines...) Expand all
37 return encoding; 38 return encoding;
38 } 39 }
39 40
40 } // namespace 41 } // namespace
41 42
42 namespace net { 43 namespace net {
43 44
44 FtpDirectoryListingBuffer::FtpDirectoryListingBuffer() 45 FtpDirectoryListingBuffer::FtpDirectoryListingBuffer()
45 : current_parser_(NULL) { 46 : current_parser_(NULL) {
46 parsers_.insert(new FtpDirectoryListingParserLs()); 47 parsers_.insert(new FtpDirectoryListingParserLs());
48 parsers_.insert(new FtpDirectoryListingParserNetware());
47 parsers_.insert(new FtpDirectoryListingParserVms()); 49 parsers_.insert(new FtpDirectoryListingParserVms());
48 parsers_.insert(new FtpDirectoryListingParserWindows()); 50 parsers_.insert(new FtpDirectoryListingParserWindows());
49 } 51 }
50 52
51 FtpDirectoryListingBuffer::~FtpDirectoryListingBuffer() { 53 FtpDirectoryListingBuffer::~FtpDirectoryListingBuffer() {
52 STLDeleteElements(&parsers_); 54 STLDeleteElements(&parsers_);
53 } 55 }
54 56
55 int FtpDirectoryListingBuffer::ConsumeData(const char* data, int data_length) { 57 int FtpDirectoryListingBuffer::ConsumeData(const char* data, int data_length) {
56 buffer_.append(data, data_length); 58 buffer_.append(data, data_length);
(...skipping 16 matching lines...) Expand all
73 return ERR_INVALID_RESPONSE; 75 return ERR_INVALID_RESPONSE;
74 76
75 rv = ParseLines(); 77 rv = ParseLines();
76 if (rv != OK) 78 if (rv != OK)
77 return rv; 79 return rv;
78 80
79 rv = OnEndOfInput(); 81 rv = OnEndOfInput();
80 if (rv != OK) 82 if (rv != OK)
81 return rv; 83 return rv;
82 84
83 DCHECK(current_parser_);
84 return OK; 85 return OK;
85 } 86 }
86 87
87 bool FtpDirectoryListingBuffer::EntryAvailable() const { 88 bool FtpDirectoryListingBuffer::EntryAvailable() const {
88 return (current_parser_ ? current_parser_->EntryAvailable() : false); 89 return (current_parser_ ? current_parser_->EntryAvailable() : false);
89 } 90 }
90 91
91 FtpDirectoryListingEntry FtpDirectoryListingBuffer::PopEntry() { 92 FtpDirectoryListingEntry FtpDirectoryListingBuffer::PopEntry() {
92 DCHECK(EntryAvailable()); 93 DCHECK(EntryAvailable());
93 return current_parser_->PopEntry(); 94 return current_parser_->PopEntry();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 while (i != parsers_.end()) { 163 while (i != parsers_.end()) {
163 if ((*i)->OnEndOfInput()) { 164 if ((*i)->OnEndOfInput()) {
164 i++; 165 i++;
165 } else { 166 } else {
166 delete *i; 167 delete *i;
167 parsers_.erase(i++); 168 parsers_.erase(i++);
168 } 169 }
169 } 170 }
170 171
171 if (parsers_.size() != 1) { 172 if (parsers_.size() != 1) {
172 current_parser_ = NULL; 173 DCHECK(!current_parser_);
174
175 // We may hit an ambiguity in case of listings which have no entries. That's
176 // fine, as long as all remaining parsers agree that the listing is empty.
177 bool all_listings_empty = true;
178 for (ParserSet::iterator i = parsers_.begin(); i != parsers_.end(); ++i) {
179 if ((*i)->EntryAvailable())
180 all_listings_empty = false;
181 }
182 if (all_listings_empty)
183 return OK;
184
173 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT; 185 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT;
174 } 186 }
175 187
176 current_parser_ = *parsers_.begin(); 188 current_parser_ = *parsers_.begin();
177 return OK; 189 return OK;
178 } 190 }
179 191
180 } // namespace net 192 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698