michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef ParseRTPList_h___ michael@0: #define ParseRTPList_h___ michael@0: michael@0: #include michael@0: #include michael@0: #include "prtime.h" michael@0: michael@0: /* ParseFTPList() parses lines from an FTP LIST command. michael@0: ** michael@0: ** Written July 2002 by Cyrus Patel michael@0: ** with acknowledgements to squid, lynx, wget and ftpmirror. michael@0: ** michael@0: ** Arguments: michael@0: ** 'line': line of FTP data connection output. The line is assumed michael@0: ** to end at the first '\0' or '\n' or '\r\n'. michael@0: ** 'state': a structure used internally to track state between michael@0: ** lines. Needs to be bzero()'d at LIST begin. michael@0: ** 'result': where ParseFTPList will store the results of the parse michael@0: ** if 'line' is not a comment and is not junk. michael@0: ** michael@0: ** Returns one of the following: michael@0: ** 'd' - LIST line is a directory entry ('result' is valid) michael@0: ** 'f' - LIST line is a file's entry ('result' is valid) michael@0: ** 'l' - LIST line is a symlink's entry ('result' is valid) michael@0: ** '?' - LIST line is junk. (cwd, non-file/dir/link, etc) michael@0: ** '"' - its not a LIST line (its a "comment") michael@0: ** michael@0: ** It may be advisable to let the end-user see "comments" (particularly when michael@0: ** the listing results in ONLY such lines) because such a listing may be: michael@0: ** - an unknown LIST format (NLST or "custom" format for example) michael@0: ** - an error msg (EPERM,ENOENT,ENFILE,EMFILE,ENOTDIR,ENOTBLK,EEXDEV etc). michael@0: ** - an empty directory and the 'comment' is a "total 0" line or similar. michael@0: ** (warning: a "total 0" can also mean the total size is unknown). michael@0: ** michael@0: ** ParseFTPList() supports all known FTP LISTing formats: michael@0: ** - '/bin/ls -l' and all variants (including Hellsoft FTP for NetWare); michael@0: ** - EPLF (Easily Parsable List Format); michael@0: ** - Windows NT's default "DOS-dirstyle"; michael@0: ** - OS/2 basic server format LIST format; michael@0: ** - VMS (MultiNet, UCX, and CMU) LIST format (including multi-line format); michael@0: ** - IBM VM/CMS, VM/ESA LIST format (two known variants); michael@0: ** - SuperTCP FTP Server for Win16 LIST format; michael@0: ** - NetManage Chameleon (NEWT) for Win16 LIST format; michael@0: ** - '/bin/dls' (two known variants, plus multi-line) LIST format; michael@0: ** If there are others, then I'd like to hear about them (send me a sample). michael@0: ** michael@0: ** NLSTings are not supported explicitely because they cannot be machine michael@0: ** parsed consistently: NLSTings do not have unique characteristics - even michael@0: ** the assumption that there won't be whitespace on the line does not hold michael@0: ** because some nlistings have more than one filename per line and/or michael@0: ** may have filenames that have spaces in them. Moreover, distinguishing michael@0: ** between an error message and an NLST line would require ParseList() to michael@0: ** recognize all the possible strerror() messages in the world. michael@0: */ michael@0: michael@0: michael@0: /* #undef anything you don't want to support */ michael@0: #define SUPPORT_LSL /* /bin/ls -l and dozens of variations therof */ michael@0: #define SUPPORT_DLS /* /bin/dls format (very, Very, VERY rare) */ michael@0: #define SUPPORT_EPLF /* Extraordinarily Pathetic List Format */ michael@0: #define SUPPORT_DOS /* WinNT server in 'site dirstyle' dos */ michael@0: #define SUPPORT_VMS /* VMS (all: MultiNet, UCX, CMU-IP) */ michael@0: #define SUPPORT_CMS /* IBM VM/CMS,VM/ESA (z/VM and LISTING forms) */ michael@0: #define SUPPORT_OS2 /* IBM TCP/IP for OS/2 - FTP Server */ michael@0: #define SUPPORT_W16 /* win16 hosts: SuperTCP or NetManage Chameleon */ michael@0: michael@0: struct list_state michael@0: { michael@0: list_state() { michael@0: memset(this, 0, sizeof(*this)); michael@0: } michael@0: michael@0: PRTime now_time; /* needed for year determination */ michael@0: PRExplodedTime now_tm; /* needed for year determination */ michael@0: int32_t lstyle; /* LISTing style */ michael@0: int32_t parsed_one; /* returned anything yet? */ michael@0: char carry_buf[84]; /* for VMS multiline */ michael@0: uint32_t carry_buf_len; /* length of name in carry_buf */ michael@0: uint32_t numlines; /* number of lines seen */ michael@0: }; michael@0: michael@0: struct list_result michael@0: { michael@0: int32_t fe_type; /* 'd'(dir) or 'l'(link) or 'f'(file) */ michael@0: const char * fe_fname; /* pointer to filename */ michael@0: uint32_t fe_fnlen; /* length of filename */ michael@0: const char * fe_lname; /* pointer to symlink name */ michael@0: uint32_t fe_lnlen; /* length of symlink name */ michael@0: char fe_size[40]; /* size of file in bytes (<= (2^128 - 1)) */ michael@0: PRExplodedTime fe_time; /* last-modified time */ michael@0: int32_t fe_cinfs; /* file system is definitely case insensitive */ michael@0: /* (converting all-upcase names may be desirable) */ michael@0: }; michael@0: michael@0: int ParseFTPList(const char *line, michael@0: struct list_state *state, michael@0: struct list_result *result ); michael@0: michael@0: #endif /* !ParseRTPList_h___ */