1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/streamconv/converters/ParseFTPList.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef ParseRTPList_h___ 1.10 +#define ParseRTPList_h___ 1.11 + 1.12 +#include <stdint.h> 1.13 +#include <string.h> 1.14 +#include "prtime.h" 1.15 + 1.16 +/* ParseFTPList() parses lines from an FTP LIST command. 1.17 +** 1.18 +** Written July 2002 by Cyrus Patel <cyp@fb14.uni-mainz.de> 1.19 +** with acknowledgements to squid, lynx, wget and ftpmirror. 1.20 +** 1.21 +** Arguments: 1.22 +** 'line': line of FTP data connection output. The line is assumed 1.23 +** to end at the first '\0' or '\n' or '\r\n'. 1.24 +** 'state': a structure used internally to track state between 1.25 +** lines. Needs to be bzero()'d at LIST begin. 1.26 +** 'result': where ParseFTPList will store the results of the parse 1.27 +** if 'line' is not a comment and is not junk. 1.28 +** 1.29 +** Returns one of the following: 1.30 +** 'd' - LIST line is a directory entry ('result' is valid) 1.31 +** 'f' - LIST line is a file's entry ('result' is valid) 1.32 +** 'l' - LIST line is a symlink's entry ('result' is valid) 1.33 +** '?' - LIST line is junk. (cwd, non-file/dir/link, etc) 1.34 +** '"' - its not a LIST line (its a "comment") 1.35 +** 1.36 +** It may be advisable to let the end-user see "comments" (particularly when 1.37 +** the listing results in ONLY such lines) because such a listing may be: 1.38 +** - an unknown LIST format (NLST or "custom" format for example) 1.39 +** - an error msg (EPERM,ENOENT,ENFILE,EMFILE,ENOTDIR,ENOTBLK,EEXDEV etc). 1.40 +** - an empty directory and the 'comment' is a "total 0" line or similar. 1.41 +** (warning: a "total 0" can also mean the total size is unknown). 1.42 +** 1.43 +** ParseFTPList() supports all known FTP LISTing formats: 1.44 +** - '/bin/ls -l' and all variants (including Hellsoft FTP for NetWare); 1.45 +** - EPLF (Easily Parsable List Format); 1.46 +** - Windows NT's default "DOS-dirstyle"; 1.47 +** - OS/2 basic server format LIST format; 1.48 +** - VMS (MultiNet, UCX, and CMU) LIST format (including multi-line format); 1.49 +** - IBM VM/CMS, VM/ESA LIST format (two known variants); 1.50 +** - SuperTCP FTP Server for Win16 LIST format; 1.51 +** - NetManage Chameleon (NEWT) for Win16 LIST format; 1.52 +** - '/bin/dls' (two known variants, plus multi-line) LIST format; 1.53 +** If there are others, then I'd like to hear about them (send me a sample). 1.54 +** 1.55 +** NLSTings are not supported explicitely because they cannot be machine 1.56 +** parsed consistently: NLSTings do not have unique characteristics - even 1.57 +** the assumption that there won't be whitespace on the line does not hold 1.58 +** because some nlistings have more than one filename per line and/or 1.59 +** may have filenames that have spaces in them. Moreover, distinguishing 1.60 +** between an error message and an NLST line would require ParseList() to 1.61 +** recognize all the possible strerror() messages in the world. 1.62 +*/ 1.63 + 1.64 + 1.65 +/* #undef anything you don't want to support */ 1.66 +#define SUPPORT_LSL /* /bin/ls -l and dozens of variations therof */ 1.67 +#define SUPPORT_DLS /* /bin/dls format (very, Very, VERY rare) */ 1.68 +#define SUPPORT_EPLF /* Extraordinarily Pathetic List Format */ 1.69 +#define SUPPORT_DOS /* WinNT server in 'site dirstyle' dos */ 1.70 +#define SUPPORT_VMS /* VMS (all: MultiNet, UCX, CMU-IP) */ 1.71 +#define SUPPORT_CMS /* IBM VM/CMS,VM/ESA (z/VM and LISTING forms) */ 1.72 +#define SUPPORT_OS2 /* IBM TCP/IP for OS/2 - FTP Server */ 1.73 +#define SUPPORT_W16 /* win16 hosts: SuperTCP or NetManage Chameleon */ 1.74 + 1.75 +struct list_state 1.76 +{ 1.77 + list_state() { 1.78 + memset(this, 0, sizeof(*this)); 1.79 + } 1.80 + 1.81 + PRTime now_time; /* needed for year determination */ 1.82 + PRExplodedTime now_tm; /* needed for year determination */ 1.83 + int32_t lstyle; /* LISTing style */ 1.84 + int32_t parsed_one; /* returned anything yet? */ 1.85 + char carry_buf[84]; /* for VMS multiline */ 1.86 + uint32_t carry_buf_len; /* length of name in carry_buf */ 1.87 + uint32_t numlines; /* number of lines seen */ 1.88 +}; 1.89 + 1.90 +struct list_result 1.91 +{ 1.92 + int32_t fe_type; /* 'd'(dir) or 'l'(link) or 'f'(file) */ 1.93 + const char * fe_fname; /* pointer to filename */ 1.94 + uint32_t fe_fnlen; /* length of filename */ 1.95 + const char * fe_lname; /* pointer to symlink name */ 1.96 + uint32_t fe_lnlen; /* length of symlink name */ 1.97 + char fe_size[40]; /* size of file in bytes (<= (2^128 - 1)) */ 1.98 + PRExplodedTime fe_time; /* last-modified time */ 1.99 + int32_t fe_cinfs; /* file system is definitely case insensitive */ 1.100 + /* (converting all-upcase names may be desirable) */ 1.101 +}; 1.102 + 1.103 +int ParseFTPList(const char *line, 1.104 + struct list_state *state, 1.105 + struct list_result *result ); 1.106 + 1.107 +#endif /* !ParseRTPList_h___ */