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