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

Side by Side Diff: net/ftp/ftp_directory_parser.h

Issue 28298: Directory listing code for new Portable FTP(Patch SET-2) (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « net/build/net.vcproj ('k') | net/ftp/ftp_directory_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 // The contents of this file are subject to the Mozilla Public License Version
7 // 1.1 (the "License"); you may not use this file except in compliance with
8 // the License. You may obtain a copy of the License at
9 // http://www.mozilla.org/MPL/
10 // Software distributed under the License is distributed on an "AS IS" basis,
11 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 // for the specific language governing rights and limitations under the
13 // License.
14 //
15 // The Original Code is mozilla.org Code.
16 //
17 // The Initial Developer of the Original Code is
18 // Cyrus Patel <cyp@fb14.uni-mainz.de>.
19 // Portions created by the Initial Developer are Copyright (C) 2002
20 // the Initial Developer. All Rights Reserved.
21 //
22 // Contributor(s):
23 // Doug Turner <dougt@netscape.com>
24 //
25 // Alternatively, the contents of this file may be used under the terms of
26 // either the GNU General Public License Version 2 or later (the "GPL"), or
27 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 // in which case the provisions of the GPL or the LGPL are applicable instead
29 // of those above. If you wish to allow use of your version of this file only
30 // under the terms of either the GPL or the LGPL, and not to allow others to
31 // use your version of this file under the terms of the MPL, indicate your
32 // decision by deleting the provisions above and replace them with the notice
33 // and other provisions required by the GPL or the LGPL. If you do not delete
34 // the provisions above, a recipient may use your version of this file under
35 // the terms of any one of the MPL, the GPL or the LGPL.
36
37 // Derived from:
38 // mozilla/netwerk/streamconv/converters/ParseFTPList.h revision 1.3
39
40
41 #ifndef NET_FTP_DIRECTORY_PARSER_H_
42 #define NET_FTP_DIRECTORY_PARSER_H_
43
44 #include <time.h>
45
46 #include "base/basictypes.h"
47
48
49 namespace net {
50
51 struct ListState {
52 int64 now_time; // needed for year determination.
53 struct tm now_tm; // needed for year determination.
54 int lstyle; // LISTing style.
55 int parsed_one; // returned anything yet?
56 char carry_buf[84]; // for VMS multiline.
57 unsigned int carry_buf_len; // length of name in carry_buf.
58 unsigned int numlines; // number of lines seen.
59 };
60
61 enum LineType {
62 FTP_TYPE_DIRECTORY, // LIST line is a directory entry ('result' is valid).
63 FTP_TYPE_FILE, // LIST line is a file's entry ('result' is valid).
64 FTP_TYPE_SYMLINK, // LIST line is a symlink's entry ('result' is valid).
65 FTP_TYPE_JUNK, // LIST line is junk. (cwd, non-file/dir/link, etc).
66 FTP_TYPE_COMMENT // Its not a LIST line (its a "comment").
67 };
68
69 struct ListResult {
70 LineType fe_type;
71 const char* fe_fname; // pointer to filename
72 unsigned int fe_fnlen; // length of filename
73 const char* fe_lname; // pointer to symlink name
74 unsigned int fe_lnlen; // length of symlink name
75 char fe_size[40]; // size of file in bytes (<= (2^128 - 1))
76 int fe_cinfs; // file system is definitely case insensitive
77 struct tm fe_time; // last-modified time
78 };
79
80 // ParseFTPLine() parses line from an FTP LIST command.
81 //
82 // Written July 2002 by Cyrus Patel <cyp@fb14.uni-mainz.de>
83 // with acknowledgements to squid, lynx, wget and ftpmirror.
84 //
85 // Arguments:
86 // 'line': line of FTP data connection output. The line is assumed
87 // to end at the first '\0' or '\n' or '\r\n'.
88 // 'state': a structure used internally to track state between
89 // lines. Needs to be bzero()'d at LIST begin.
90 // 'result': where ParseFTPList will store the results of the parse
91 // if 'line' is not a comment and is not junk.
92 //
93 // Returns one of the following:
94 // 'd' - LIST line is a directory entry ('result' is valid)
95 // 'f' - LIST line is a file's entry ('result' is valid)
96 // 'l' - LIST line is a symlink's entry ('result' is valid)
97 // '?' - LIST line is junk. (cwd, non-file/dir/link, etc)
98 // '"' - its not a LIST line (its a "comment")
99 //
100 // It may be advisable to let the end-user see "comments" (particularly when
101 // the listing results in ONLY such lines) because such a listing may be:
102 // - an unknown LIST format (NLST or "custom" format for example)
103 // - an error msg (EPERM,ENOENT,ENFILE,EMFILE,ENOTDIR,ENOTBLK,EEXDEV etc).
104 // - an empty directory and the 'comment' is a "total 0" line or similar.
105 // (warning: a "total 0" can also mean the total size is unknown).
106 //
107 // ParseFTPList() supports all known FTP LISTing formats:
108 // - '/bin/ls -l' and all variants (including Hellsoft FTP for NetWare);
109 // - EPLF (Easily Parsable List Format);
110 // - Windows NT's default "DOS-dirstyle";
111 // - OS/2 basic server format LIST format;
112 // - VMS (MultiNet, UCX, and CMU) LIST format (including multi-line format);
113 // - IBM VM/CMS, VM/ESA LIST format (two known variants);
114 // - SuperTCP FTP Server for Win16 LIST format;
115 // - NetManage Chameleon (NEWT) for Win16 LIST format;
116 // - '/bin/dls' (two known variants, plus multi-line) LIST format;
117 // If there are others, then I'd like to hear about them (send me a sample).
118 //
119 // NLSTings are not supported explicitely because they cannot be machine
120 // parsed consistently: NLSTings do not have unique characteristics - even
121 // the assumption that there won't be whitespace on the line does not hold
122 // because some nlistings have more than one filename per line and/or
123 // may have filenames that have spaces in them. Moreover, distinguishing
124 // between an error message and an NLST line would require ParseList() to
125 // recognize all the possible strerror() messages in the world.
126
127 LineType ParseFTPLine(const char *line,
128 struct ListState *state,
129 struct ListResult *result);
130
131 } // namespace net
132
133 #endif // NET_FTP_DIRECTORY_PARSER_H_
OLDNEW
« no previous file with comments | « net/build/net.vcproj ('k') | net/ftp/ftp_directory_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698