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

Side by Side Diff: net/third_party/parseftp/ParseFTPList.h

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

Powered by Google App Engine
This is Rietveld 408576698