Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef ParseRTPList_h___
7 #define ParseRTPList_h___
9 #include <stdint.h>
10 #include <string.h>
11 #include "prtime.h"
13 /* ParseFTPList() parses lines from an FTP LIST command.
14 **
15 ** Written July 2002 by Cyrus Patel <cyp@fb14.uni-mainz.de>
16 ** with acknowledgements to squid, lynx, wget and ftpmirror.
17 **
18 ** Arguments:
19 ** 'line': line of FTP data connection output. The line is assumed
20 ** to end at the first '\0' or '\n' or '\r\n'.
21 ** 'state': a structure used internally to track state between
22 ** lines. Needs to be bzero()'d at LIST begin.
23 ** 'result': where ParseFTPList will store the results of the parse
24 ** if 'line' is not a comment and is not junk.
25 **
26 ** Returns one of the following:
27 ** 'd' - LIST line is a directory entry ('result' is valid)
28 ** 'f' - LIST line is a file's entry ('result' is valid)
29 ** 'l' - LIST line is a symlink's entry ('result' is valid)
30 ** '?' - LIST line is junk. (cwd, non-file/dir/link, etc)
31 ** '"' - its not a LIST line (its a "comment")
32 **
33 ** It may be advisable to let the end-user see "comments" (particularly when
34 ** the listing results in ONLY such lines) because such a listing may be:
35 ** - an unknown LIST format (NLST or "custom" format for example)
36 ** - an error msg (EPERM,ENOENT,ENFILE,EMFILE,ENOTDIR,ENOTBLK,EEXDEV etc).
37 ** - an empty directory and the 'comment' is a "total 0" line or similar.
38 ** (warning: a "total 0" can also mean the total size is unknown).
39 **
40 ** ParseFTPList() supports all known FTP LISTing formats:
41 ** - '/bin/ls -l' and all variants (including Hellsoft FTP for NetWare);
42 ** - EPLF (Easily Parsable List Format);
43 ** - Windows NT's default "DOS-dirstyle";
44 ** - OS/2 basic server format LIST format;
45 ** - VMS (MultiNet, UCX, and CMU) LIST format (including multi-line format);
46 ** - IBM VM/CMS, VM/ESA LIST format (two known variants);
47 ** - SuperTCP FTP Server for Win16 LIST format;
48 ** - NetManage Chameleon (NEWT) for Win16 LIST format;
49 ** - '/bin/dls' (two known variants, plus multi-line) LIST format;
50 ** If there are others, then I'd like to hear about them (send me a sample).
51 **
52 ** NLSTings are not supported explicitely because they cannot be machine
53 ** parsed consistently: NLSTings do not have unique characteristics - even
54 ** the assumption that there won't be whitespace on the line does not hold
55 ** because some nlistings have more than one filename per line and/or
56 ** may have filenames that have spaces in them. Moreover, distinguishing
57 ** between an error message and an NLST line would require ParseList() to
58 ** recognize all the possible strerror() messages in the world.
59 */
62 /* #undef anything you don't want to support */
63 #define SUPPORT_LSL /* /bin/ls -l and dozens of variations therof */
64 #define SUPPORT_DLS /* /bin/dls format (very, Very, VERY rare) */
65 #define SUPPORT_EPLF /* Extraordinarily Pathetic List Format */
66 #define SUPPORT_DOS /* WinNT server in 'site dirstyle' dos */
67 #define SUPPORT_VMS /* VMS (all: MultiNet, UCX, CMU-IP) */
68 #define SUPPORT_CMS /* IBM VM/CMS,VM/ESA (z/VM and LISTING forms) */
69 #define SUPPORT_OS2 /* IBM TCP/IP for OS/2 - FTP Server */
70 #define SUPPORT_W16 /* win16 hosts: SuperTCP or NetManage Chameleon */
72 struct list_state
73 {
74 list_state() {
75 memset(this, 0, sizeof(*this));
76 }
78 PRTime now_time; /* needed for year determination */
79 PRExplodedTime now_tm; /* needed for year determination */
80 int32_t lstyle; /* LISTing style */
81 int32_t parsed_one; /* returned anything yet? */
82 char carry_buf[84]; /* for VMS multiline */
83 uint32_t carry_buf_len; /* length of name in carry_buf */
84 uint32_t numlines; /* number of lines seen */
85 };
87 struct list_result
88 {
89 int32_t fe_type; /* 'd'(dir) or 'l'(link) or 'f'(file) */
90 const char * fe_fname; /* pointer to filename */
91 uint32_t fe_fnlen; /* length of filename */
92 const char * fe_lname; /* pointer to symlink name */
93 uint32_t fe_lnlen; /* length of symlink name */
94 char fe_size[40]; /* size of file in bytes (<= (2^128 - 1)) */
95 PRExplodedTime fe_time; /* last-modified time */
96 int32_t fe_cinfs; /* file system is definitely case insensitive */
97 /* (converting all-upcase names may be desirable) */
98 };
100 int ParseFTPList(const char *line,
101 struct list_state *state,
102 struct list_result *result );
104 #endif /* !ParseRTPList_h___ */