From nelson@crynwr.com Wed Oct 04 02:08:10 2000 X-VM-v5-Data: ([nil nil nil t nil nil nil nil nil] ["4944" "" "4" "October" "2000" "02:08:09" "-0000" "Russell Nelson" "nelson@crynwr.com" nil "152" "ftpparse incorporated into ftp-ls.c" "^From:" nil nil "10" nil nil nil nil nil] nil) Return-Path: Delivered-To: nelson@desk.crynwr.com Received: (qmail 23971 invoked by alias); 4 Oct 2000 02:08:10 -0000 Delivered-To: alias-nelson-nelson@crynwr.com Received: (qmail 23968 invoked by uid 501); 4 Oct 2000 02:08:09 -0000 Message-ID: <20001004020809.23967.qmail@desk.crynwr.com> X-Face: $K'YURj"g6ImvqTS_=]8)gqh!5;ElY<[.Rao%j8r+]iUfE{%|v%F<=mcq<6l{K=~mf&#:?" nslS]U~|x{2V=Eex_I#"9K~9)>?m7Lm={(j_&)SX~fzg&ST~P%QUhc{1p]c3@Zn1u*PZlkHM**X^vV l>GkB5y^Kz%w5p~^uDue]hL&ke,N;+Q To: hniksic@srce.hr CC: wget@sunsite.auc.dk, bug-wget@prep.ai.mit.edu, djb@koobera.math.uic.edu Subject: ftpparse incorporated into ftp-ls.c Date: 4 Oct 2000 02:08:09 -0000 Hi. I've incorporated Dan Bernstein's ftpparse code into wget-1.5.2. Dan's code is available from ftp://koobera.math.uic.edu/pub/software/ftpparse.[ch] The advantage of using his ftpparse code is that it interprets more FTP listing types, including his ``EPLF'', Easily Parsed Listing Format. It was quite easy to incorporate. Since I've removed much of the original ftp-ls.c, I'm including it as if the original was empty, to make the patch smaller. --- ftp-ls.c.orig Thu Jul 23 00:16:57 1998 +++ ftp-ls.c Thu Jul 23 00:09:35 1998 @@ -0,0 +1,124 @@ +/* Parsing FTP `ls' output. + Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + +This file is part of Wget. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include + +#include +#include +#ifdef HAVE_STRING_H +# include +#else +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif +#include +#include +#include + +#include "wget.h" +#include "utils.h" +#include "ftp.h" +#include "ftpparse.h" + +/* Convert the Un*x-ish style directory listing stored in FILE to a + linked list of fileinfo (system-independent) entries. The contents + of FILE are considered to be produced by the standard Unix `ls -la' + output (whatever that might be). BSD (no group) and SYSV (with + group) listings are handled. + + The time stamps are stored in a separate variable, time_t + compatible (I hope). The timezones are ignored. */ +static struct fileinfo * +ftp_parse_unix_ls (const char *file) +{ + FILE *fp; + int len; + + char *line; /* tokenizer */ + struct fileinfo *dir, *l, cur; /* list creation */ + + fp = fopen (file, "rb"); + if (!fp) + { + logprintf (LOG_NOTQUIET, "%s: %s\n", file, strerror (errno)); + return NULL; + } + dir = l = NULL; + + /* Line loop to end of file: */ + while ((line = read_whole_line (fp))) + { + struct ftpparse fp; + + DEBUGP (("%s\n", line)); + len = strlen (line); + /* Destroy if there is one. */ + if (len && line[len - 1] == '\r') + line[--len] = '\0'; + + if (ftpparse(&fp, line, len)) { + cur.size = fp.size; + cur.name = (char *)xmalloc (fp.namelen + 1); + memcpy (cur.name, fp.name, fp.namelen); + cur.name[fp.namelen] = '\0'; + DEBUGP (("%s\n", cur.name)); + cur.linkto = NULL; + if (fp.flagtrycwd) { + cur.type = FT_DIRECTORY; + cur.perms = 0644; + } else { + cur.type = FT_PLAINFILE; + cur.perms = 0755; + } + if (!dir) { + l = dir = (struct fileinfo *)xmalloc (sizeof (struct fileinfo)); + memcpy (l, &cur, sizeof (cur)); + l->prev = l->next = NULL; + } else { + cur.prev = l; + l->next = (struct fileinfo *)xmalloc (sizeof (struct fileinfo)); + l = l->next; + memcpy (l, &cur, sizeof (cur)); + l->next = NULL; + } + l->tstamp = fp.mtime; + } + + free (line); + } + + fclose (fp); + return dir; +} + +/* This function is just a stub. It should actually accept some kind + of information what system it is running on -- e.g. FPL_UNIX, + FPL_DOS, FPL_NT, FPL_VMS, etc. and a "guess-me" value, like + FPL_GUESS. Then it would call the appropriate parsers to fill up + fileinfos. + + Since we currently support only the Unix FTP servers, this function + simply returns the result of ftp_parse_unix_ls(). */ +struct fileinfo * +ftp_parse_ls (const char *file) +{ + return ftp_parse_unix_ls (file); +} --- Makefile.in.orig Tue Jun 23 17:29:18 1998 +++ Makefile.in Thu Jul 23 00:14:25 1998 @@ -59,7 +59,7 @@ OBJ = $(ALLOCA) cmpt$o connect$o fnmatch$o ftp$o ftp-basic$o \ ftp-ls$o $(OPIE_OBJ) getopt$o headers$o host$o html$o \ http$o init$o log$o main$o $(MD5_OBJ) netrc$o rbuf$o \ - recur$o retr$o url$o utils$o version$o + recur$o retr$o url$o utils$o version$o ftpparse$o .SUFFIXES: .SUFFIXES: .c .o ._c ._o @@ -156,3 +156,4 @@ retr$o: config.h wget.h sysdep.h options.h utils.h retr.h rbuf.h url.h recur.h ftp.h host.h connect.h url$o: config.h wget.h sysdep.h options.h utils.h url.h host.h html.h utils$o: config.h wget.h sysdep.h options.h utils.h fnmatch.h +ftpparse$o: ftp.h ftpparse.h