Home | History | Annotate | Download | only in ftp
      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
      3 // LICENSE file.
      4 
      5 #ifndef NET_FTP_FTP_DIRECTORY_LISTING_PARSER_H_
      6 #define NET_FTP_FTP_DIRECTORY_LISTING_PARSER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/string16.h"
     10 #include "base/time.h"
     11 #include "net/ftp/ftp_server_type_histograms.h"
     12 
     13 namespace net {
     14 
     15 struct FtpDirectoryListingEntry {
     16   enum Type {
     17     FILE,
     18     DIRECTORY,
     19     SYMLINK,
     20   };
     21 
     22   Type type;
     23   string16 name;
     24   int64 size;  // File size, in bytes. -1 if not applicable.
     25 
     26   // Last modified time, in local time zone.
     27   base::Time last_modified;
     28 };
     29 
     30 class FtpDirectoryListingParser {
     31  public:
     32   virtual ~FtpDirectoryListingParser();
     33 
     34   virtual FtpServerType GetServerType() const = 0;
     35 
     36   // Adds |line| to the internal parsing buffer. Returns true on success.
     37   virtual bool ConsumeLine(const string16& line) = 0;
     38 
     39   // Called after all input has been consumed. Returns true if the parser
     40   // recognizes all received data as a valid listing.
     41   virtual bool OnEndOfInput() = 0;
     42 
     43   // Returns true if there is at least one FtpDirectoryListingEntry available.
     44   virtual bool EntryAvailable() const = 0;
     45 
     46   // Returns the next entry. It is an error to call this function unless
     47   // EntryAvailable returns true.
     48   virtual FtpDirectoryListingEntry PopEntry() = 0;
     49 };
     50 
     51 }  // namespace net
     52 
     53 #endif  // NET_FTP_FTP_DIRECTORY_LISTING_PARSER_H_
     54