michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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: #include "ParseFTPList.h" michael@0: #include michael@0: #include michael@0: #include michael@0: #include "plstr.h" michael@0: #include "nsDebug.h" michael@0: #include "prprf.h" michael@0: michael@0: /* ==================================================================== */ michael@0: michael@0: static inline int ParsingFailed(struct list_state *state) michael@0: { michael@0: if (state->parsed_one || state->lstyle) /* junk if we fail to parse */ michael@0: return '?'; /* this time but had previously parsed successfully */ michael@0: return '"'; /* its part of a comment or error message */ michael@0: } michael@0: michael@0: int ParseFTPList(const char *line, struct list_state *state, michael@0: struct list_result *result ) michael@0: { michael@0: unsigned int carry_buf_len; /* copy of state->carry_buf_len */ michael@0: unsigned int linelen, pos; michael@0: const char *p; michael@0: michael@0: if (!line || !state || !result) michael@0: return 0; michael@0: michael@0: memset( result, 0, sizeof(*result) ); michael@0: state->numlines++; michael@0: michael@0: /* carry buffer is only valid from one line to the next */ michael@0: carry_buf_len = state->carry_buf_len; michael@0: state->carry_buf_len = 0; michael@0: michael@0: linelen = 0; michael@0: michael@0: /* strip leading whitespace */ michael@0: while (*line == ' ' || *line == '\t') michael@0: line++; michael@0: michael@0: /* line is terminated at first '\0' or '\n' */ michael@0: p = line; michael@0: while (*p && *p != '\n') michael@0: p++; michael@0: linelen = p - line; michael@0: michael@0: if (linelen > 0 && *p == '\n' && *(p-1) == '\r') michael@0: linelen--; michael@0: michael@0: /* DON'T strip trailing whitespace. */ michael@0: michael@0: if (linelen > 0) michael@0: { michael@0: static const char *month_names = "JanFebMarAprMayJunJulAugSepOctNovDec"; michael@0: const char *tokens[16]; /* 16 is more than enough */ michael@0: unsigned int toklen[(sizeof(tokens)/sizeof(tokens[0]))]; michael@0: unsigned int linelen_sans_wsp; // line length sans whitespace michael@0: unsigned int numtoks = 0; michael@0: unsigned int tokmarker = 0; /* extra info for lstyle handler */ michael@0: unsigned int month_num = 0; michael@0: char tbuf[4]; michael@0: int lstyle = 0; michael@0: michael@0: if (carry_buf_len) /* VMS long filename carryover buffer */ michael@0: { michael@0: tokens[0] = state->carry_buf; michael@0: toklen[0] = carry_buf_len; michael@0: numtoks++; michael@0: } michael@0: michael@0: pos = 0; michael@0: while (pos < linelen && numtoks < (sizeof(tokens)/sizeof(tokens[0])) ) michael@0: { michael@0: while (pos < linelen && michael@0: (line[pos] == ' ' || line[pos] == '\t' || line[pos] == '\r')) michael@0: pos++; michael@0: if (pos < linelen) michael@0: { michael@0: tokens[numtoks] = &line[pos]; michael@0: while (pos < linelen && michael@0: (line[pos] != ' ' && line[pos] != '\t' && line[pos] != '\r')) michael@0: pos++; michael@0: if (tokens[numtoks] != &line[pos]) michael@0: { michael@0: toklen[numtoks] = (&line[pos] - tokens[numtoks]); michael@0: numtoks++; michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (!numtoks) michael@0: return ParsingFailed(state); michael@0: michael@0: linelen_sans_wsp = &(tokens[numtoks-1][toklen[numtoks-1]]) - tokens[0]; michael@0: if (numtoks == (sizeof(tokens)/sizeof(tokens[0])) ) michael@0: { michael@0: pos = linelen; michael@0: while (pos > 0 && (line[pos-1] == ' ' || line[pos-1] == '\t')) michael@0: pos--; michael@0: linelen_sans_wsp = pos; michael@0: } michael@0: michael@0: /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ michael@0: michael@0: #if defined(SUPPORT_EPLF) michael@0: /* EPLF handling must come somewhere before /bin/dls handling. */ michael@0: if (!lstyle && (!state->lstyle || state->lstyle == 'E')) michael@0: { michael@0: if (*line == '+' && linelen > 4 && numtoks >= 2) michael@0: { michael@0: pos = 1; michael@0: while (pos < (linelen-1)) michael@0: { michael@0: p = &line[pos++]; michael@0: if (*p == '/') michael@0: result->fe_type = 'd'; /* its a dir */ michael@0: else if (*p == 'r') michael@0: result->fe_type = 'f'; /* its a file */ michael@0: else if (*p == 'm') michael@0: { michael@0: if (isdigit(line[pos])) michael@0: { michael@0: while (pos < linelen && isdigit(line[pos])) michael@0: pos++; michael@0: if (pos < linelen && line[pos] == ',') michael@0: { michael@0: PRTime t; michael@0: PRTime seconds; michael@0: PR_sscanf(p+1, "%llu", &seconds); michael@0: t = seconds * PR_USEC_PER_SEC; michael@0: PR_ExplodeTime(t, PR_LocalTimeParameters, &(result->fe_time) ); michael@0: } michael@0: } michael@0: } michael@0: else if (*p == 's') michael@0: { michael@0: if (isdigit(line[pos])) michael@0: { michael@0: while (pos < linelen && isdigit(line[pos])) michael@0: pos++; michael@0: if (pos < linelen && line[pos] == ',' && michael@0: ((&line[pos]) - (p+1)) < int(sizeof(result->fe_size)-1) ) michael@0: { michael@0: memcpy( result->fe_size, p+1, (unsigned)(&line[pos] - (p+1)) ); michael@0: result->fe_size[(&line[pos] - (p+1))] = '\0'; michael@0: } michael@0: } michael@0: } michael@0: else if (isalpha(*p)) /* 'i'/'up' or unknown "fact" (property) */ michael@0: { michael@0: while (pos < linelen && *++p != ',') michael@0: pos++; michael@0: } michael@0: else if (*p != '\t' || (p+1) != tokens[1]) michael@0: { michael@0: break; /* its not EPLF after all */ michael@0: } michael@0: else michael@0: { michael@0: state->parsed_one = 1; michael@0: state->lstyle = lstyle = 'E'; michael@0: michael@0: p = &(line[linelen_sans_wsp]); michael@0: result->fe_fname = tokens[1]; michael@0: result->fe_fnlen = p - tokens[1]; michael@0: michael@0: if (!result->fe_type) /* access denied */ michael@0: { michael@0: result->fe_type = 'f'; /* is assuming 'f'ile correct? */ michael@0: return '?'; /* NO! junk it. */ michael@0: } michael@0: return result->fe_type; michael@0: } michael@0: if (pos >= (linelen-1) || line[pos] != ',') michael@0: break; michael@0: pos++; michael@0: } /* while (pos < linelen) */ michael@0: memset( result, 0, sizeof(*result) ); michael@0: } /* if (*line == '+' && linelen > 4 && numtoks >= 2) */ michael@0: } /* if (!lstyle && (!state->lstyle || state->lstyle == 'E')) */ michael@0: #endif /* SUPPORT_EPLF */ michael@0: michael@0: /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ michael@0: michael@0: #if defined(SUPPORT_VMS) michael@0: if (!lstyle && (!state->lstyle || state->lstyle == 'V')) michael@0: { /* try VMS Multinet/UCX/CMS server */ michael@0: /* michael@0: * Legal characters in a VMS file/dir spec are [A-Z0-9$.-_~]. michael@0: * '$' cannot begin a filename and `-' cannot be used as the first michael@0: * or last character. '.' is only valid as a directory separator michael@0: * and . separator. A canonical filename spec might look michael@0: * like this: DISK$VOL:[DIR1.DIR2.DIR3]FILE.TYPE;123 michael@0: * All VMS FTP servers LIST in uppercase. michael@0: * michael@0: * We need to be picky about this in order to support michael@0: * multi-line listings correctly. michael@0: */ michael@0: if (!state->parsed_one && michael@0: (numtoks == 1 || (numtoks == 2 && toklen[0] == 9 && michael@0: memcmp(tokens[0], "Directory", 9)==0 ))) michael@0: { michael@0: /* If no dirstyle has been detected yet, and this line is a michael@0: * VMS list's dirname, then turn on VMS dirstyle. michael@0: * eg "ACA:[ANONYMOUS]", "DISK$FTP:[ANONYMOUS]", "SYS$ANONFTP:" michael@0: */ michael@0: p = tokens[0]; michael@0: pos = toklen[0]; michael@0: if (numtoks == 2) michael@0: { michael@0: p = tokens[1]; michael@0: pos = toklen[1]; michael@0: } michael@0: pos--; michael@0: if (pos >= 3) michael@0: { michael@0: while (pos > 0 && p[pos] != '[') michael@0: { michael@0: pos--; michael@0: if (p[pos] == '-' || p[pos] == '$') michael@0: { michael@0: if (pos == 0 || p[pos-1] == '[' || p[pos-1] == '.' || michael@0: (p[pos] == '-' && (p[pos+1] == ']' || p[pos+1] == '.'))) michael@0: break; michael@0: } michael@0: else if (p[pos] != '.' && p[pos] != '~' && michael@0: !isdigit(p[pos]) && !isalpha(p[pos])) michael@0: break; michael@0: else if (isalpha(p[pos]) && p[pos] != toupper(p[pos])) michael@0: break; michael@0: } michael@0: if (pos > 0) michael@0: { michael@0: pos--; michael@0: if (p[pos] != ':' || p[pos+1] != '[') michael@0: pos = 0; michael@0: } michael@0: } michael@0: if (pos > 0 && p[pos] == ':') michael@0: { michael@0: while (pos > 0) michael@0: { michael@0: pos--; michael@0: if (p[pos] != '$' && p[pos] != '_' && p[pos] != '-' && michael@0: p[pos] != '~' && !isdigit(p[pos]) && !isalpha(p[pos])) michael@0: break; michael@0: else if (isalpha(p[pos]) && p[pos] != toupper(p[pos])) michael@0: break; michael@0: } michael@0: if (pos == 0) michael@0: { michael@0: state->lstyle = 'V'; michael@0: return '?'; /* its junk */ michael@0: } michael@0: } michael@0: /* fallthrough */ michael@0: } michael@0: else if ((tokens[0][toklen[0]-1]) != ';') michael@0: { michael@0: if (numtoks == 1 && (state->lstyle == 'V' && !carry_buf_len)) michael@0: lstyle = 'V'; michael@0: else if (numtoks < 4) michael@0: ; michael@0: else if (toklen[1] >= 10 && memcmp(tokens[1], "%RMS-E-PRV", 10) == 0) michael@0: lstyle = 'V'; michael@0: else if ((&line[linelen] - tokens[1]) >= 22 && michael@0: memcmp(tokens[1], "insufficient privilege", 22) == 0) michael@0: lstyle = 'V'; michael@0: else if (numtoks != 4 && numtoks != 6) michael@0: ; michael@0: else if (numtoks == 6 && ( michael@0: toklen[5] < 4 || *tokens[5] != '(' || /* perms */ michael@0: (tokens[5][toklen[5]-1]) != ')' )) michael@0: ; michael@0: else if ( (toklen[2] == 10 || toklen[2] == 11) && michael@0: (tokens[2][toklen[2]-5]) == '-' && michael@0: (tokens[2][toklen[2]-9]) == '-' && michael@0: (((toklen[3]==4 || toklen[3]==5 || toklen[3]==7 || toklen[3]==8) && michael@0: (tokens[3][toklen[3]-3]) == ':' ) || michael@0: ((toklen[3]==10 || toklen[3]==11 ) && michael@0: (tokens[3][toklen[3]-3]) == '.' ) michael@0: ) && /* time in [H]H:MM[:SS[.CC]] format */ michael@0: isdigit(*tokens[1]) && /* size */ michael@0: isdigit(*tokens[2]) && /* date */ michael@0: isdigit(*tokens[3]) /* time */ michael@0: ) michael@0: { michael@0: lstyle = 'V'; michael@0: } michael@0: if (lstyle == 'V') michael@0: { michael@0: /* michael@0: * MultiNet FTP: michael@0: * LOGIN.COM;2 1 4-NOV-1994 04:09 [ANONYMOUS] (RWE,RWE,,) michael@0: * PUB.DIR;1 1 27-JAN-1994 14:46 [ANONYMOUS] (RWE,RWE,RE,RWE) michael@0: * README.FTP;1 %RMS-E-PRV, insufficient privilege or file protection violation michael@0: * ROUSSOS.DIR;1 1 27-JAN-1994 14:48 [CS,ROUSSOS] (RWE,RWE,RE,R) michael@0: * S67-50903.JPG;1 328 22-SEP-1998 16:19 [ANONYMOUS] (RWED,RWED,,) michael@0: * UCX FTP: michael@0: * CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12 [ANONYMOU,ANONYMOUS] (RWED,RWED,,) michael@0: * CMU/VMS-IP FTP michael@0: * [VMSSERV.FILES]ALARM.DIR;1 1/3 5-MAR-1993 18:09 michael@0: * TCPware FTP michael@0: * FOO.BAR;1 4 5-MAR-1993 18:09:01.12 michael@0: * Long filename example: michael@0: * THIS-IS-A-LONG-VMS-FILENAME.AND-THIS-IS-A-LONG-VMS-FILETYPE\r\n michael@0: * 213[/nnn] 29-JAN-1996 03:33[:nn] [ANONYMOU,ANONYMOUS] (RWED,RWED,,) michael@0: */ michael@0: tokmarker = 0; michael@0: p = tokens[0]; michael@0: pos = 0; michael@0: if (*p == '[' && toklen[0] >= 4) /* CMU style */ michael@0: { michael@0: if (p[1] != ']') michael@0: { michael@0: p++; michael@0: pos++; michael@0: } michael@0: while (lstyle && pos < toklen[0] && *p != ']') michael@0: { michael@0: if (*p != '$' && *p != '.' && *p != '_' && *p != '-' && michael@0: *p != '~' && !isdigit(*p) && !isalpha(*p)) michael@0: lstyle = 0; michael@0: pos++; michael@0: p++; michael@0: } michael@0: if (lstyle && pos < (toklen[0]-1)) michael@0: { michael@0: /* ']' was found and there is at least one character after it */ michael@0: NS_ASSERTION(*p == ']', "unexpected state"); michael@0: pos++; michael@0: p++; michael@0: tokmarker = pos; /* length of leading "[DIR1.DIR2.etc]" */ michael@0: } else { michael@0: /* not a CMU style listing */ michael@0: lstyle = 0; michael@0: } michael@0: } michael@0: while (lstyle && pos < toklen[0] && *p != ';') michael@0: { michael@0: if (*p != '$' && *p != '.' && *p != '_' && *p != '-' && michael@0: *p != '~' && !isdigit(*p) && !isalpha(*p)) michael@0: lstyle = 0; michael@0: else if (isalpha(*p) && *p != toupper(*p)) michael@0: lstyle = 0; michael@0: p++; michael@0: pos++; michael@0: } michael@0: if (lstyle && *p == ';') michael@0: { michael@0: if (pos == 0 || pos == (toklen[0]-1)) michael@0: lstyle = 0; michael@0: for (pos++;lstyle && pos < toklen[0];pos++) michael@0: { michael@0: if (!isdigit(tokens[0][pos])) michael@0: lstyle = 0; michael@0: } michael@0: } michael@0: pos = (p - tokens[0]); /* => fnlength sans ";####" */ michael@0: pos -= tokmarker; /* => fnlength sans "[DIR1.DIR2.etc]" */ michael@0: p = &(tokens[0][tokmarker]); /* offset of basename */ michael@0: michael@0: if (!lstyle || pos == 0 || pos > 80) /* VMS filenames can't be longer than that */ michael@0: { michael@0: lstyle = 0; michael@0: } michael@0: else if (numtoks == 1) michael@0: { michael@0: /* if VMS has been detected and there is only one token and that michael@0: * token was a VMS filename then this is a multiline VMS LIST entry. michael@0: */ michael@0: if (pos >= (sizeof(state->carry_buf)-1)) michael@0: pos = (sizeof(state->carry_buf)-1); /* shouldn't happen */ michael@0: memcpy( state->carry_buf, p, pos ); michael@0: state->carry_buf_len = pos; michael@0: return '?'; /* tell caller to treat as junk */ michael@0: } michael@0: else if (isdigit(*tokens[1])) /* not no-privs message */ michael@0: { michael@0: for (pos = 0; lstyle && pos < (toklen[1]); pos++) michael@0: { michael@0: if (!isdigit((tokens[1][pos])) && (tokens[1][pos]) != '/') michael@0: lstyle = 0; michael@0: } michael@0: if (lstyle && numtoks > 4) /* Multinet or UCX but not CMU */ michael@0: { michael@0: for (pos = 1; lstyle && pos < (toklen[5]-1); pos++) michael@0: { michael@0: p = &(tokens[5][pos]); michael@0: if (*p!='R' && *p!='W' && *p!='E' && *p!='D' && *p!=',') michael@0: lstyle = 0; michael@0: } michael@0: } michael@0: } michael@0: } /* passed initial tests */ michael@0: } /* else if ((tokens[0][toklen[0]-1]) != ';') */ michael@0: michael@0: if (lstyle == 'V') michael@0: { michael@0: state->parsed_one = 1; michael@0: state->lstyle = lstyle; michael@0: michael@0: if (isdigit(*tokens[1])) /* not permission denied etc */ michael@0: { michael@0: /* strip leading directory name */ michael@0: if (*tokens[0] == '[') /* CMU server */ michael@0: { michael@0: pos = toklen[0]-1; michael@0: p = tokens[0]+1; michael@0: while (*p != ']') michael@0: { michael@0: p++; michael@0: pos--; michael@0: } michael@0: toklen[0] = --pos; michael@0: tokens[0] = ++p; michael@0: } michael@0: pos = 0; michael@0: while (pos < toklen[0] && (tokens[0][pos]) != ';') michael@0: pos++; michael@0: michael@0: result->fe_cinfs = 1; michael@0: result->fe_type = 'f'; michael@0: result->fe_fname = tokens[0]; michael@0: result->fe_fnlen = pos; michael@0: michael@0: if (pos > 4) michael@0: { michael@0: p = &(tokens[0][pos-4]); michael@0: if (p[0] == '.' && p[1] == 'D' && p[2] == 'I' && p[3] == 'R') michael@0: { michael@0: result->fe_fnlen -= 4; michael@0: result->fe_type = 'd'; michael@0: } michael@0: } michael@0: michael@0: if (result->fe_type != 'd') michael@0: { michael@0: /* #### or used/allocated form. If used/allocated form, then michael@0: * 'used' is the size in bytes if and only if 'used'<=allocated. michael@0: * If 'used' is size in bytes then it can be > 2^32 michael@0: * If 'used' is not size in bytes then it is size in blocks. michael@0: */ michael@0: pos = 0; michael@0: while (pos < toklen[1] && (tokens[1][pos]) != '/') michael@0: pos++; michael@0: michael@0: /* michael@0: * I've never seen size come back in bytes, its always in blocks, and michael@0: * the following test fails. So, always perform the "size in blocks". michael@0: * I'm leaving the "size in bytes" code if'd out in case we ever need michael@0: * to re-instate it. michael@0: */ michael@0: #if 0 michael@0: if (pos < toklen[1] && ( (pos<<1) > (toklen[1]-1) || michael@0: (strtoul(tokens[1], (char **)0, 10) > michael@0: strtoul(tokens[1]+pos+1, (char **)0, 10)) )) michael@0: { /* size is in bytes */ michael@0: if (pos > (sizeof(result->fe_size)-1)) michael@0: pos = sizeof(result->fe_size)-1; michael@0: memcpy( result->fe_size, tokens[1], pos ); michael@0: result->fe_size[pos] = '\0'; michael@0: } michael@0: else /* size is in blocks */ michael@0: #endif michael@0: { michael@0: /* size requires multiplication by blocksize. michael@0: * michael@0: * We could assume blocksize is 512 (like Lynx does) and michael@0: * shift by 9, but that might not be right. Even if it michael@0: * were, doing that wouldn't reflect what the file's michael@0: * real size was. The sanest thing to do is not use the michael@0: * LISTing's filesize, so we won't (like ftpmirror). michael@0: * michael@0: * ulltoa(((unsigned long long)fsz)<<9, result->fe_size, 10); michael@0: * michael@0: * A block is always 512 bytes on OpenVMS, compute size. michael@0: * So its rounded up to the next block, so what, its better michael@0: * than not showing the size at all. michael@0: * A block is always 512 bytes on OpenVMS, compute size. michael@0: * So its rounded up to the next block, so what, its better michael@0: * than not showing the size at all. michael@0: */ michael@0: uint64_t fsz = uint64_t(strtoul(tokens[1], (char **)0, 10) * 512); michael@0: PR_snprintf(result->fe_size, sizeof(result->fe_size), michael@0: "%lld", fsz); michael@0: } michael@0: michael@0: } /* if (result->fe_type != 'd') */ michael@0: michael@0: p = tokens[2] + 2; michael@0: if (*p == '-') michael@0: p++; michael@0: tbuf[0] = p[0]; michael@0: tbuf[1] = tolower(p[1]); michael@0: tbuf[2] = tolower(p[2]); michael@0: month_num = 0; michael@0: for (pos = 0; pos < (12*3); pos+=3) michael@0: { michael@0: if (tbuf[0] == month_names[pos+0] && michael@0: tbuf[1] == month_names[pos+1] && michael@0: tbuf[2] == month_names[pos+2]) michael@0: break; michael@0: month_num++; michael@0: } michael@0: if (month_num >= 12) michael@0: month_num = 0; michael@0: result->fe_time.tm_month = month_num; michael@0: result->fe_time.tm_mday = atoi(tokens[2]); michael@0: result->fe_time.tm_year = atoi(p+4); // NSPR wants year as XXXX michael@0: michael@0: p = tokens[3] + 2; michael@0: if (*p == ':') michael@0: p++; michael@0: if (p[2] == ':') michael@0: result->fe_time.tm_sec = atoi(p+3); michael@0: result->fe_time.tm_hour = atoi(tokens[3]); michael@0: result->fe_time.tm_min = atoi(p); michael@0: michael@0: return result->fe_type; michael@0: michael@0: } /* if (isdigit(*tokens[1])) */ michael@0: michael@0: return '?'; /* junk */ michael@0: michael@0: } /* if (lstyle == 'V') */ michael@0: } /* if (!lstyle && (!state->lstyle || state->lstyle == 'V')) */ michael@0: #endif michael@0: michael@0: /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ michael@0: michael@0: #if defined(SUPPORT_CMS) michael@0: /* Virtual Machine/Conversational Monitor System (IBM Mainframe) */ michael@0: if (!lstyle && (!state->lstyle || state->lstyle == 'C')) /* VM/CMS */ michael@0: { michael@0: /* LISTing according to mirror.pl michael@0: * Filename FileType Fm Format Lrecl Records Blocks Date Time michael@0: * LASTING GLOBALV A1 V 41 21 1 9/16/91 15:10:32 michael@0: * J43401 NETLOG A0 V 77 1 1 9/12/91 12:36:04 michael@0: * PROFILE EXEC A1 V 17 3 1 9/12/91 12:39:07 michael@0: * DIRUNIX SCRIPT A1 V 77 1216 17 1/04/93 20:30:47 michael@0: * MAIL PROFILE A2 F 80 1 1 10/14/92 16:12:27 michael@0: * BADY2K TEXT A0 V 1 1 1 1/03/102 10:11:12 michael@0: * AUTHORS A1 DIR - - - 9/20/99 10:31:11 michael@0: * michael@0: * LISTing from vm.marist.edu and vm.sc.edu michael@0: * 220-FTPSERVE IBM VM Level 420 at VM.MARIST.EDU, 04:58:12 EDT WEDNESDAY 2002-07-10 michael@0: * AUTHORS DIR - - - 1999-09-20 10:31:11 - michael@0: * HARRINGTON DIR - - - 1997-02-12 15:33:28 - michael@0: * PICS DIR - - - 2000-10-12 15:43:23 - michael@0: * SYSFILE DIR - - - 2000-07-20 17:48:01 - michael@0: * WELCNVT EXEC V 72 9 1 1999-09-20 17:16:18 - michael@0: * WELCOME EREADME F 80 21 1 1999-12-27 16:19:00 - michael@0: * WELCOME README V 82 21 1 1999-12-27 16:19:04 - michael@0: * README ANONYMOU V 71 26 1 1997-04-02 12:33:20 TCP291 michael@0: * README ANONYOLD V 71 15 1 1995-08-25 16:04:27 TCP291 michael@0: */ michael@0: if (numtoks >= 7 && (toklen[0]+toklen[1]) <= 16) michael@0: { michael@0: for (pos = 1; !lstyle && (pos+5) < numtoks; pos++) michael@0: { michael@0: p = tokens[pos]; michael@0: if ((toklen[pos] == 1 && (*p == 'F' || *p == 'V')) || michael@0: (toklen[pos] == 3 && *p == 'D' && p[1] == 'I' && p[2] == 'R')) michael@0: { michael@0: if (toklen[pos+5] == 8 && (tokens[pos+5][2]) == ':' && michael@0: (tokens[pos+5][5]) == ':' ) michael@0: { michael@0: p = tokens[pos+4]; michael@0: if ((toklen[pos+4] == 10 && p[4] == '-' && p[7] == '-') || michael@0: (toklen[pos+4] >= 7 && toklen[pos+4] <= 9 && michael@0: p[((p[1]!='/')?(2):(1))] == '/' && michael@0: p[((p[1]!='/')?(5):(4))] == '/')) michael@0: /* Y2K bugs possible ("7/06/102" or "13/02/101") */ michael@0: { michael@0: if ( (*tokens[pos+1] == '-' && michael@0: *tokens[pos+2] == '-' && michael@0: *tokens[pos+3] == '-') || michael@0: (isdigit(*tokens[pos+1]) && michael@0: isdigit(*tokens[pos+2]) && michael@0: isdigit(*tokens[pos+3])) ) michael@0: { michael@0: lstyle = 'C'; michael@0: tokmarker = pos; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } /* for (pos = 1; !lstyle && (pos+5) < numtoks; pos++) */ michael@0: } /* if (numtoks >= 7) */ michael@0: michael@0: /* extra checking if first pass */ michael@0: if (lstyle && !state->lstyle) michael@0: { michael@0: for (pos = 0, p = tokens[0]; lstyle && pos < toklen[0]; pos++, p++) michael@0: { michael@0: if (isalpha(*p) && toupper(*p) != *p) michael@0: lstyle = 0; michael@0: } michael@0: for (pos = tokmarker+1; pos <= tokmarker+3; pos++) michael@0: { michael@0: if (!(toklen[pos] == 1 && *tokens[pos] == '-')) michael@0: { michael@0: for (p = tokens[pos]; lstyle && p<(tokens[pos]+toklen[pos]); p++) michael@0: { michael@0: if (!isdigit(*p)) michael@0: lstyle = 0; michael@0: } michael@0: } michael@0: } michael@0: for (pos = 0, p = tokens[tokmarker+4]; michael@0: lstyle && pos < toklen[tokmarker+4]; pos++, p++) michael@0: { michael@0: if (*p == '/') michael@0: { michael@0: /* There may be Y2K bugs in the date. Don't simplify to michael@0: * pos != (len-3) && pos != (len-6) like time is done. michael@0: */ michael@0: if ((tokens[tokmarker+4][1]) == '/') michael@0: { michael@0: if (pos != 1 && pos != 4) michael@0: lstyle = 0; michael@0: } michael@0: else if (pos != 2 && pos != 5) michael@0: lstyle = 0; michael@0: } michael@0: else if (*p != '-' && !isdigit(*p)) michael@0: lstyle = 0; michael@0: else if (*p == '-' && pos != 4 && pos != 7) michael@0: lstyle = 0; michael@0: } michael@0: for (pos = 0, p = tokens[tokmarker+5]; michael@0: lstyle && pos < toklen[tokmarker+5]; pos++, p++) michael@0: { michael@0: if (*p != ':' && !isdigit(*p)) michael@0: lstyle = 0; michael@0: else if (*p == ':' && pos != (toklen[tokmarker+5]-3) michael@0: && pos != (toklen[tokmarker+5]-6)) michael@0: lstyle = 0; michael@0: } michael@0: } /* initial if() */ michael@0: michael@0: if (lstyle == 'C') michael@0: { michael@0: state->parsed_one = 1; michael@0: state->lstyle = lstyle; michael@0: michael@0: p = tokens[tokmarker+4]; michael@0: if (toklen[tokmarker+4] == 10) /* newstyle: YYYY-MM-DD format */ michael@0: { michael@0: result->fe_time.tm_year = atoi(p+0) - 1900; michael@0: result->fe_time.tm_month = atoi(p+5) - 1; michael@0: result->fe_time.tm_mday = atoi(p+8); michael@0: } michael@0: else /* oldstyle: [M]M/DD/YY format */ michael@0: { michael@0: pos = toklen[tokmarker+4]; michael@0: result->fe_time.tm_month = atoi(p) - 1; michael@0: result->fe_time.tm_mday = atoi((p+pos)-5); michael@0: result->fe_time.tm_year = atoi((p+pos)-2); michael@0: if (result->fe_time.tm_year < 70) michael@0: result->fe_time.tm_year += 100; michael@0: } michael@0: michael@0: p = tokens[tokmarker+5]; michael@0: pos = toklen[tokmarker+5]; michael@0: result->fe_time.tm_hour = atoi(p); michael@0: result->fe_time.tm_min = atoi((p+pos)-5); michael@0: result->fe_time.tm_sec = atoi((p+pos)-2); michael@0: michael@0: result->fe_cinfs = 1; michael@0: result->fe_fname = tokens[0]; michael@0: result->fe_fnlen = toklen[0]; michael@0: result->fe_type = 'f'; michael@0: michael@0: p = tokens[tokmarker]; michael@0: if (toklen[tokmarker] == 3 && *p=='D' && p[1]=='I' && p[2]=='R') michael@0: result->fe_type = 'd'; michael@0: michael@0: if ((/*newstyle*/ toklen[tokmarker+4] == 10 && tokmarker > 1) || michael@0: (/*oldstyle*/ toklen[tokmarker+4] != 10 && tokmarker > 2)) michael@0: { /* have a filetype column */ michael@0: char *dot; michael@0: p = &(tokens[0][toklen[0]]); michael@0: memcpy( &dot, &p, sizeof(dot) ); /* NASTY! */ michael@0: *dot++ = '.'; michael@0: p = tokens[1]; michael@0: for (pos = 0; pos < toklen[1]; pos++) michael@0: *dot++ = *p++; michael@0: result->fe_fnlen += 1 + toklen[1]; michael@0: } michael@0: michael@0: /* oldstyle LISTING: michael@0: * files/dirs not on the 'A' minidisk are not RETRievable/CHDIRable michael@0: if (toklen[tokmarker+4] != 10 && *tokens[tokmarker-1] != 'A') michael@0: return '?'; michael@0: */ michael@0: michael@0: /* VM/CMS LISTings have no usable filesize field. michael@0: * Have to use the 'SIZE' command for that. michael@0: */ michael@0: return result->fe_type; michael@0: michael@0: } /* if (lstyle == 'C' && (!state->lstyle || state->lstyle == lstyle)) */ michael@0: } /* VM/CMS */ michael@0: #endif michael@0: michael@0: /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ michael@0: michael@0: #if defined(SUPPORT_DOS) /* WinNT DOS dirstyle */ michael@0: if (!lstyle && (!state->lstyle || state->lstyle == 'W')) michael@0: { michael@0: /* michael@0: * "10-23-00 01:27PM veronist" michael@0: * "06-15-00 07:37AM zoe" michael@0: * "07-14-00 01:35PM 2094926 canprankdesk.tif" michael@0: * "07-21-00 01:19PM 95077 Jon Kauffman Enjoys the Good Life.jpg" michael@0: * "07-21-00 01:19PM 52275 Name Plate.jpg" michael@0: * "07-14-00 01:38PM 2250540 Valentineoffprank-HiRes.jpg" michael@0: */ michael@0: if ((numtoks >= 4) && toklen[0] == 8 && toklen[1] == 7 && michael@0: (*tokens[2] == '<' || isdigit(*tokens[2])) ) michael@0: { michael@0: p = tokens[0]; michael@0: if ( isdigit(p[0]) && isdigit(p[1]) && p[2]=='-' && michael@0: isdigit(p[3]) && isdigit(p[4]) && p[5]=='-' && michael@0: isdigit(p[6]) && isdigit(p[7]) ) michael@0: { michael@0: p = tokens[1]; michael@0: if ( isdigit(p[0]) && isdigit(p[1]) && p[2]==':' && michael@0: isdigit(p[3]) && isdigit(p[4]) && michael@0: (p[5]=='A' || p[5]=='P') && p[6]=='M') michael@0: { michael@0: lstyle = 'W'; michael@0: if (!state->lstyle) michael@0: { michael@0: p = tokens[2]; michael@0: /* or */ michael@0: if (*p != '<' || p[toklen[2]-1] != '>') michael@0: { michael@0: for (pos = 1; (lstyle && pos < toklen[2]); pos++) michael@0: { michael@0: if (!isdigit(*++p)) michael@0: lstyle = 0; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (lstyle == 'W') michael@0: { michael@0: state->parsed_one = 1; michael@0: state->lstyle = lstyle; michael@0: michael@0: p = &(line[linelen]); /* line end */ michael@0: result->fe_cinfs = 1; michael@0: result->fe_fname = tokens[3]; michael@0: result->fe_fnlen = p - tokens[3]; michael@0: result->fe_type = 'd'; michael@0: michael@0: if (*tokens[2] != '<') /* not or */ michael@0: { michael@0: // try to handle correctly spaces at the beginning of the filename michael@0: // filesize (token[2]) must end at offset 38 michael@0: if (tokens[2] + toklen[2] - line == 38) { michael@0: result->fe_fname = &(line[39]); michael@0: result->fe_fnlen = p - result->fe_fname; michael@0: } michael@0: result->fe_type = 'f'; michael@0: pos = toklen[2]; michael@0: while (pos > (sizeof(result->fe_size)-1)) michael@0: pos = (sizeof(result->fe_size)-1); michael@0: memcpy( result->fe_size, tokens[2], pos ); michael@0: result->fe_size[pos] = '\0'; michael@0: } michael@0: else { michael@0: // try to handle correctly spaces at the beginning of the filename michael@0: // token[2] must begin at offset 24, the length is 5 or 10 michael@0: // token[3] must begin at offset 39 or higher michael@0: if (tokens[2] - line == 24 && (toklen[2] == 5 || toklen[2] == 10) && michael@0: tokens[3] - line >= 39) { michael@0: result->fe_fname = &(line[39]); michael@0: result->fe_fnlen = p - result->fe_fname; michael@0: } michael@0: michael@0: if ((tokens[2][1]) != 'D') /* not */ michael@0: { michael@0: result->fe_type = '?'; /* unknown until junc for sure */ michael@0: if (result->fe_fnlen > 4) michael@0: { michael@0: p = result->fe_fname; michael@0: for (pos = result->fe_fnlen - 4; pos > 0; pos--) michael@0: { michael@0: if (p[0] == ' ' && p[3] == ' ' && p[2] == '>' && michael@0: (p[1] == '=' || p[1] == '-')) michael@0: { michael@0: result->fe_type = 'l'; michael@0: result->fe_fnlen = p - result->fe_fname; michael@0: result->fe_lname = p + 4; michael@0: result->fe_lnlen = &(line[linelen]) michael@0: - result->fe_lname; michael@0: break; michael@0: } michael@0: p++; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: result->fe_time.tm_month = atoi(tokens[0]+0); michael@0: if (result->fe_time.tm_month != 0) michael@0: { michael@0: result->fe_time.tm_month--; michael@0: result->fe_time.tm_mday = atoi(tokens[0]+3); michael@0: result->fe_time.tm_year = atoi(tokens[0]+6); michael@0: /* if year has only two digits then assume that michael@0: 00-79 is 2000-2079 michael@0: 80-99 is 1980-1999 */ michael@0: if (result->fe_time.tm_year < 80) michael@0: result->fe_time.tm_year += 2000; michael@0: else if (result->fe_time.tm_year < 100) michael@0: result->fe_time.tm_year += 1900; michael@0: } michael@0: michael@0: result->fe_time.tm_hour = atoi(tokens[1]+0); michael@0: result->fe_time.tm_min = atoi(tokens[1]+3); michael@0: if ((tokens[1][5]) == 'P' && result->fe_time.tm_hour < 12) michael@0: result->fe_time.tm_hour += 12; michael@0: michael@0: /* the caller should do this (if dropping "." and ".." is desired) michael@0: if (result->fe_type == 'd' && result->fe_fname[0] == '.' && michael@0: (result->fe_fnlen == 1 || (result->fe_fnlen == 2 && michael@0: result->fe_fname[1] == '.'))) michael@0: return '?'; michael@0: */ michael@0: michael@0: return result->fe_type; michael@0: } /* if (lstyle == 'W' && (!state->lstyle || state->lstyle == lstyle)) */ michael@0: } /* if (!lstyle && (!state->lstyle || state->lstyle == 'W')) */ michael@0: #endif michael@0: michael@0: /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ michael@0: michael@0: #if defined(SUPPORT_OS2) michael@0: if (!lstyle && (!state->lstyle || state->lstyle == 'O')) /* OS/2 test */ michael@0: { michael@0: /* 220 server IBM TCP/IP for OS/2 - FTP Server ver 23:04:36 on Jan 15 1997 ready. michael@0: * fixed position, space padded columns. I have only a vague idea michael@0: * of what the contents between col 18 and 34 might be: All I can infer michael@0: * is that there may be attribute flags in there and there may be michael@0: * a " DIR" in there. michael@0: * michael@0: * 1 2 3 4 5 6 michael@0: *0123456789012345678901234567890123456789012345678901234567890123456789 michael@0: *----- size -------|??????????????? MM-DD-YY| HH:MM| nnnnnnnnn.... michael@0: * 0 DIR 04-11-95 16:26 . michael@0: * 0 DIR 04-11-95 16:26 .. michael@0: * 0 DIR 04-11-95 16:26 ADDRESS michael@0: * 612 RHSA 07-28-95 16:45 air_tra1.bag michael@0: * 195 A 08-09-95 10:23 Alfa1.bag michael@0: * 0 RHS DIR 04-11-95 16:26 ATTACH michael@0: * 372 A 08-09-95 10:26 Aussie_1.bag michael@0: * 310992 06-28-94 09:56 INSTALL.EXE michael@0: * 1 2 3 4 michael@0: * 01234567890123456789012345678901234567890123456789 michael@0: * dirlist from the mirror.pl project, col positions from Mozilla. michael@0: */ michael@0: p = &(line[toklen[0]]); michael@0: /* \s(\d\d-\d\d-\d\d)\s+(\d\d:\d\d)\s */ michael@0: if (numtoks >= 4 && toklen[0] <= 18 && isdigit(*tokens[0]) && michael@0: (linelen - toklen[0]) >= (53-18) && michael@0: p[18-18] == ' ' && p[34-18] == ' ' && michael@0: p[37-18] == '-' && p[40-18] == '-' && p[43-18] == ' ' && michael@0: p[45-18] == ' ' && p[48-18] == ':' && p[51-18] == ' ' && michael@0: isdigit(p[35-18]) && isdigit(p[36-18]) && michael@0: isdigit(p[38-18]) && isdigit(p[39-18]) && michael@0: isdigit(p[41-18]) && isdigit(p[42-18]) && michael@0: isdigit(p[46-18]) && isdigit(p[47-18]) && michael@0: isdigit(p[49-18]) && isdigit(p[50-18]) michael@0: ) michael@0: { michael@0: lstyle = 'O'; /* OS/2 */ michael@0: if (!state->lstyle) michael@0: { michael@0: for (pos = 1; lstyle && pos < toklen[0]; pos++) michael@0: { michael@0: if (!isdigit(tokens[0][pos])) michael@0: lstyle = 0; michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (lstyle == 'O') michael@0: { michael@0: state->parsed_one = 1; michael@0: state->lstyle = lstyle; michael@0: michael@0: p = &(line[toklen[0]]); michael@0: michael@0: result->fe_cinfs = 1; michael@0: result->fe_fname = &p[53-18]; michael@0: result->fe_fnlen = (&(line[linelen_sans_wsp])) michael@0: - (result->fe_fname); michael@0: result->fe_type = 'f'; michael@0: michael@0: /* I don't have a real listing to determine exact pos, so scan. */ michael@0: for (pos = (18-18); pos < ((35-18)-4); pos++) michael@0: { michael@0: if (p[pos+0] == ' ' && p[pos+1] == 'D' && michael@0: p[pos+2] == 'I' && p[pos+3] == 'R') michael@0: { michael@0: result->fe_type = 'd'; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: if (result->fe_type != 'd') michael@0: { michael@0: pos = toklen[0]; michael@0: if (pos > (sizeof(result->fe_size)-1)) michael@0: pos = (sizeof(result->fe_size)-1); michael@0: memcpy( result->fe_size, tokens[0], pos ); michael@0: result->fe_size[pos] = '\0'; michael@0: } michael@0: michael@0: result->fe_time.tm_month = atoi(&p[35-18]) - 1; michael@0: result->fe_time.tm_mday = atoi(&p[38-18]); michael@0: result->fe_time.tm_year = atoi(&p[41-18]); michael@0: if (result->fe_time.tm_year < 80) michael@0: result->fe_time.tm_year += 100; michael@0: result->fe_time.tm_hour = atoi(&p[46-18]); michael@0: result->fe_time.tm_min = atoi(&p[49-18]); michael@0: michael@0: /* the caller should do this (if dropping "." and ".." is desired) michael@0: if (result->fe_type == 'd' && result->fe_fname[0] == '.' && michael@0: (result->fe_fnlen == 1 || (result->fe_fnlen == 2 && michael@0: result->fe_fname[1] == '.'))) michael@0: return '?'; michael@0: */ michael@0: michael@0: return result->fe_type; michael@0: } /* if (lstyle == 'O') */ michael@0: michael@0: } /* if (!lstyle && (!state->lstyle || state->lstyle == 'O')) */ michael@0: #endif michael@0: michael@0: /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ michael@0: michael@0: #if defined(SUPPORT_LSL) michael@0: if (!lstyle && (!state->lstyle || state->lstyle == 'U')) /* /bin/ls & co. */ michael@0: { michael@0: /* UNIX-style listing, without inum and without blocks michael@0: * "-rw-r--r-- 1 root other 531 Jan 29 03:26 README" michael@0: * "dr-xr-xr-x 2 root other 512 Apr 8 1994 etc" michael@0: * "dr-xr-xr-x 2 root 512 Apr 8 1994 etc" michael@0: * "lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin" michael@0: * Also produced by Microsoft's FTP servers for Windows: michael@0: * "---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z" michael@0: * "d--------- 1 owner group 0 May 9 19:45 Softlib" michael@0: * Also WFTPD for MSDOS: michael@0: * "-rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp" michael@0: * Hellsoft for NetWare: michael@0: * "d[RWCEMFA] supervisor 512 Jan 16 18:53 login" michael@0: * "-[RWCEMFA] rhesus 214059 Oct 20 15:27 cx.exe" michael@0: * Newer Hellsoft for NetWare: (netlab2.usu.edu) michael@0: * - [RWCEAFMS] NFAUUser 192 Apr 27 15:21 HEADER.html michael@0: * d [RWCEAFMS] jrd 512 Jul 11 03:01 allupdates michael@0: * Also NetPresenz for the Mac: michael@0: * "-------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit" michael@0: * "drwxrwxr-x folder 2 May 10 1996 network" michael@0: * Protected directory: michael@0: * "drwx-wx-wt 2 root wheel 512 Jul 1 02:15 incoming" michael@0: * uid/gid instead of username/groupname: michael@0: * "drwxr-xr-x 2 0 0 512 May 28 22:17 etc" michael@0: */ michael@0: michael@0: bool is_old_Hellsoft = false; michael@0: michael@0: if (numtoks >= 6) michael@0: { michael@0: /* there are two perm formats (Hellsoft/NetWare and *IX strmode(3)). michael@0: * Scan for size column only if the perm format is one or the other. michael@0: */ michael@0: if (toklen[0] == 1 || (tokens[0][1]) == '[') michael@0: { michael@0: if (*tokens[0] == 'd' || *tokens[0] == '-') michael@0: { michael@0: pos = toklen[0]-1; michael@0: p = tokens[0] + 1; michael@0: if (pos == 0) michael@0: { michael@0: p = tokens[1]; michael@0: pos = toklen[1]; michael@0: } michael@0: if ((pos == 9 || pos == 10) && michael@0: (*p == '[' && p[pos-1] == ']') && michael@0: (p[1] == 'R' || p[1] == '-') && michael@0: (p[2] == 'W' || p[2] == '-') && michael@0: (p[3] == 'C' || p[3] == '-') && michael@0: (p[4] == 'E' || p[4] == '-')) michael@0: { michael@0: /* rest is FMA[S] or AFM[S] */ michael@0: lstyle = 'U'; /* very likely one of the NetWare servers */ michael@0: if (toklen[0] == 10) michael@0: is_old_Hellsoft = true; michael@0: } michael@0: } michael@0: } michael@0: else if ((toklen[0] == 10 || toklen[0] == 11) michael@0: && strchr("-bcdlpsw?DFam", *tokens[0])) michael@0: { michael@0: p = &(tokens[0][1]); michael@0: if ((p[0] == 'r' || p[0] == '-') && michael@0: (p[1] == 'w' || p[1] == '-') && michael@0: (p[3] == 'r' || p[3] == '-') && michael@0: (p[4] == 'w' || p[4] == '-') && michael@0: (p[6] == 'r' || p[6] == '-') && michael@0: (p[7] == 'w' || p[7] == '-')) michael@0: /* 'x'/p[9] can be S|s|x|-|T|t or implementation specific */ michael@0: { michael@0: lstyle = 'U'; /* very likely /bin/ls */ michael@0: } michael@0: } michael@0: } michael@0: if (lstyle == 'U') /* first token checks out */ michael@0: { michael@0: lstyle = 0; michael@0: for (pos = (numtoks-5); !lstyle && pos > 1; pos--) michael@0: { michael@0: /* scan for: (\d+)\s+([A-Z][a-z][a-z])\s+ michael@0: * (\d\d\d\d|\d\:\d\d|\d\d\:\d\d|\d\:\d\d\:\d\d|\d\d\:\d\d\:\d\d) michael@0: * \s+(.+)$ michael@0: */ michael@0: if (isdigit(*tokens[pos]) /* size */ michael@0: /* (\w\w\w) */ michael@0: && toklen[pos+1] == 3 && isalpha(*tokens[pos+1]) && michael@0: isalpha(tokens[pos+1][1]) && isalpha(tokens[pos+1][2]) michael@0: /* (\d|\d\d) */ michael@0: && isdigit(*tokens[pos+2]) && michael@0: (toklen[pos+2] == 1 || michael@0: (toklen[pos+2] == 2 && isdigit(tokens[pos+2][1]))) michael@0: && toklen[pos+3] >= 4 && isdigit(*tokens[pos+3]) michael@0: /* (\d\:\d\d\:\d\d|\d\d\:\d\d\:\d\d) */ michael@0: && (toklen[pos+3] <= 5 || ( michael@0: (toklen[pos+3] == 7 || toklen[pos+3] == 8) && michael@0: (tokens[pos+3][toklen[pos+3]-3]) == ':')) michael@0: && isdigit(tokens[pos+3][toklen[pos+3]-2]) michael@0: && isdigit(tokens[pos+3][toklen[pos+3]-1]) michael@0: && ( michael@0: /* (\d\d\d\d) */ michael@0: ((toklen[pos+3] == 4 || toklen[pos+3] == 5) && michael@0: isdigit(tokens[pos+3][1]) && michael@0: isdigit(tokens[pos+3][2]) ) michael@0: /* (\d\:\d\d|\d\:\d\d\:\d\d) */ michael@0: || ((toklen[pos+3] == 4 || toklen[pos+3] == 7) && michael@0: (tokens[pos+3][1]) == ':' && michael@0: isdigit(tokens[pos+3][2]) && isdigit(tokens[pos+3][3])) michael@0: /* (\d\d\:\d\d|\d\d\:\d\d\:\d\d) */ michael@0: || ((toklen[pos+3] == 5 || toklen[pos+3] == 8) && michael@0: isdigit(tokens[pos+3][1]) && (tokens[pos+3][2]) == ':' && michael@0: isdigit(tokens[pos+3][3]) && isdigit(tokens[pos+3][4])) michael@0: ) michael@0: ) michael@0: { michael@0: lstyle = 'U'; /* assume /bin/ls or variant format */ michael@0: tokmarker = pos; michael@0: michael@0: /* check that size is numeric */ michael@0: p = tokens[tokmarker]; michael@0: unsigned int i; michael@0: for (i = 0; i < toklen[tokmarker]; i++) michael@0: { michael@0: if (!isdigit(*p++)) michael@0: { michael@0: lstyle = 0; michael@0: break; michael@0: } michael@0: } michael@0: if (lstyle) michael@0: { michael@0: month_num = 0; michael@0: p = tokens[tokmarker+1]; michael@0: for (i = 0; i < (12*3); i+=3) michael@0: { michael@0: if (p[0] == month_names[i+0] && michael@0: p[1] == month_names[i+1] && michael@0: p[2] == month_names[i+2]) michael@0: break; michael@0: month_num++; michael@0: } michael@0: if (month_num >= 12) michael@0: lstyle = 0; michael@0: } michael@0: } /* relative position test */ michael@0: } /* for (pos = (numtoks-5); !lstyle && pos > 1; pos--) */ michael@0: } /* if (lstyle == 'U') */ michael@0: michael@0: if (lstyle == 'U') michael@0: { michael@0: state->parsed_one = 1; michael@0: state->lstyle = lstyle; michael@0: michael@0: result->fe_cinfs = 0; michael@0: result->fe_type = '?'; michael@0: if (*tokens[0] == 'd' || *tokens[0] == 'l') michael@0: result->fe_type = *tokens[0]; michael@0: else if (*tokens[0] == 'D') michael@0: result->fe_type = 'd'; michael@0: else if (*tokens[0] == '-' || *tokens[0] == 'F') michael@0: result->fe_type = 'f'; /* (hopefully a regular file) */ michael@0: michael@0: if (result->fe_type != 'd') michael@0: { michael@0: pos = toklen[tokmarker]; michael@0: if (pos > (sizeof(result->fe_size)-1)) michael@0: pos = (sizeof(result->fe_size)-1); michael@0: memcpy( result->fe_size, tokens[tokmarker], pos ); michael@0: result->fe_size[pos] = '\0'; michael@0: } michael@0: michael@0: result->fe_time.tm_month = month_num; michael@0: result->fe_time.tm_mday = atoi(tokens[tokmarker+2]); michael@0: if (result->fe_time.tm_mday == 0) michael@0: result->fe_time.tm_mday++; michael@0: michael@0: p = tokens[tokmarker+3]; michael@0: pos = (unsigned int)atoi(p); michael@0: if (p[1] == ':') /* one digit hour */ michael@0: p--; michael@0: if (p[2] != ':') /* year */ michael@0: { michael@0: result->fe_time.tm_year = pos; michael@0: } michael@0: else michael@0: { michael@0: result->fe_time.tm_hour = pos; michael@0: result->fe_time.tm_min = atoi(p+3); michael@0: if (p[5] == ':') michael@0: result->fe_time.tm_sec = atoi(p+6); michael@0: michael@0: if (!state->now_time) michael@0: { michael@0: state->now_time = PR_Now(); michael@0: PR_ExplodeTime((state->now_time), PR_LocalTimeParameters, &(state->now_tm) ); michael@0: } michael@0: michael@0: result->fe_time.tm_year = state->now_tm.tm_year; michael@0: if ( (( state->now_tm.tm_month << 5) + state->now_tm.tm_mday) < michael@0: ((result->fe_time.tm_month << 5) + result->fe_time.tm_mday) ) michael@0: result->fe_time.tm_year--; michael@0: michael@0: } /* time/year */ michael@0: michael@0: // The length of the whole date string should be 12. On AIX the length michael@0: // is only 11 when the year is present in the date string and there is michael@0: // 1 padding space at the end of the string. In both cases the filename michael@0: // starts at offset 13 from the start of the date string. michael@0: // Don't care about leading spaces when the date string has different michael@0: // format or when old Hellsoft output was detected. michael@0: { michael@0: const char *date_start = tokens[tokmarker+1]; michael@0: const char *date_end = tokens[tokmarker+3] + toklen[tokmarker+3]; michael@0: if (!is_old_Hellsoft && ((date_end - date_start) == 12 || michael@0: ((date_end - date_start) == 11 && date_end[1] == ' '))) michael@0: result->fe_fname = date_start + 13; michael@0: else michael@0: result->fe_fname = tokens[tokmarker+4]; michael@0: } michael@0: michael@0: result->fe_fnlen = (&(line[linelen])) michael@0: - (result->fe_fname); michael@0: michael@0: if (result->fe_type == 'l' && result->fe_fnlen > 4) michael@0: { michael@0: /* First try to use result->fe_size to find " -> " sequence. michael@0: This can give proper result for cases like "aaa -> bbb -> ccc". */ michael@0: uint32_t fe_size = atoi(result->fe_size); michael@0: michael@0: if (result->fe_fnlen > (fe_size + 4) && michael@0: PL_strncmp(result->fe_fname + result->fe_fnlen - fe_size - 4 , " -> ", 4) == 0) michael@0: { michael@0: result->fe_lname = result->fe_fname + (result->fe_fnlen - fe_size); michael@0: result->fe_lnlen = (&(line[linelen])) - (result->fe_lname); michael@0: result->fe_fnlen -= fe_size + 4; michael@0: } michael@0: else michael@0: { michael@0: /* Search for sequence " -> " from the end for case when there are michael@0: more occurrences. F.e. if ftpd returns "a -> b -> c" assume michael@0: "a -> b" as a name. Powerusers can remove unnecessary parts michael@0: manually but there is no way to follow the link when some michael@0: essential part is missing. */ michael@0: p = result->fe_fname + (result->fe_fnlen - 5); michael@0: for (pos = (result->fe_fnlen - 5); pos > 0; pos--) michael@0: { michael@0: if (PL_strncmp(p, " -> ", 4) == 0) michael@0: { michael@0: result->fe_lname = p + 4; michael@0: result->fe_lnlen = (&(line[linelen])) michael@0: - (result->fe_lname); michael@0: result->fe_fnlen = pos; michael@0: break; michael@0: } michael@0: p--; michael@0: } michael@0: } michael@0: } michael@0: michael@0: #if defined(SUPPORT_LSLF) /* some (very rare) servers return ls -lF */ michael@0: if (result->fe_fnlen > 1) michael@0: { michael@0: p = result->fe_fname[result->fe_fnlen-1]; michael@0: pos = result->fe_type; michael@0: if (pos == 'd') { michael@0: if (*p == '/') result->fe_fnlen--; /* directory */ michael@0: } else if (pos == 'l') { michael@0: if (*p == '@') result->fe_fnlen--; /* symlink */ michael@0: } else if (pos == 'f') { michael@0: if (*p == '*') result->fe_fnlen--; /* executable */ michael@0: } else if (*p == '=' || *p == '%' || *p == '|') { michael@0: result->fe_fnlen--; /* socket, whiteout, fifo */ michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: /* the caller should do this (if dropping "." and ".." is desired) michael@0: if (result->fe_type == 'd' && result->fe_fname[0] == '.' && michael@0: (result->fe_fnlen == 1 || (result->fe_fnlen == 2 && michael@0: result->fe_fname[1] == '.'))) michael@0: return '?'; michael@0: */ michael@0: michael@0: return result->fe_type; michael@0: michael@0: } /* if (lstyle == 'U') */ michael@0: michael@0: } /* if (!lstyle && (!state->lstyle || state->lstyle == 'U')) */ michael@0: #endif michael@0: michael@0: /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ michael@0: michael@0: #if defined(SUPPORT_W16) /* 16bit Windows */ michael@0: if (!lstyle && (!state->lstyle || state->lstyle == 'w')) michael@0: { /* old SuperTCP suite FTP server for Win3.1 */ michael@0: /* old NetManage Chameleon TCP/IP suite FTP server for Win3.1 */ michael@0: /* michael@0: * SuperTCP dirlist from the mirror.pl project michael@0: * mon/day/year separator may be '/' or '-'. michael@0: * . 11-16-94 17:16 michael@0: * .. 11-16-94 17:16 michael@0: * INSTALL 11-16-94 17:17 michael@0: * CMT 11-21-94 10:17 michael@0: * DESIGN1.DOC 11264 05-11-95 14:20 michael@0: * README.TXT 1045 05-10-95 11:01 michael@0: * WPKIT1.EXE 960338 06-21-95 17:01 michael@0: * CMT.CSV 0 07-06-95 14:56 michael@0: * michael@0: * Chameleon dirlist guessed from lynx michael@0: * . Nov 16 1994 17:16 michael@0: * .. Nov 16 1994 17:16 michael@0: * INSTALL Nov 16 1994 17:17 michael@0: * CMT Nov 21 1994 10:17 michael@0: * DESIGN1.DOC 11264 May 11 1995 14:20 A michael@0: * README.TXT 1045 May 10 1995 11:01 michael@0: * WPKIT1.EXE 960338 Jun 21 1995 17:01 R michael@0: * CMT.CSV 0 Jul 06 1995 14:56 RHA michael@0: */ michael@0: if (numtoks >= 4 && toklen[0] < 13 && michael@0: ((toklen[1] == 5 && *tokens[1] == '<') || isdigit(*tokens[1])) ) michael@0: { michael@0: if (numtoks == 4 michael@0: && (toklen[2] == 8 || toklen[2] == 9) michael@0: && (((tokens[2][2]) == '/' && (tokens[2][5]) == '/') || michael@0: ((tokens[2][2]) == '-' && (tokens[2][5]) == '-')) michael@0: && (toklen[3] == 4 || toklen[3] == 5) michael@0: && (tokens[3][toklen[3]-3]) == ':' michael@0: && isdigit(tokens[2][0]) && isdigit(tokens[2][1]) michael@0: && isdigit(tokens[2][3]) && isdigit(tokens[2][4]) michael@0: && isdigit(tokens[2][6]) && isdigit(tokens[2][7]) michael@0: && (toklen[2] < 9 || isdigit(tokens[2][8])) michael@0: && isdigit(tokens[3][toklen[3]-1]) && isdigit(tokens[3][toklen[3]-2]) michael@0: && isdigit(tokens[3][toklen[3]-4]) && isdigit(*tokens[3]) michael@0: ) michael@0: { michael@0: lstyle = 'w'; michael@0: } michael@0: else if ((numtoks == 6 || numtoks == 7) michael@0: && toklen[2] == 3 && toklen[3] == 2 michael@0: && toklen[4] == 4 && toklen[5] == 5 michael@0: && (tokens[5][2]) == ':' michael@0: && isalpha(tokens[2][0]) && isalpha(tokens[2][1]) michael@0: && isalpha(tokens[2][2]) michael@0: && isdigit(tokens[3][0]) && isdigit(tokens[3][1]) michael@0: && isdigit(tokens[4][0]) && isdigit(tokens[4][1]) michael@0: && isdigit(tokens[4][2]) && isdigit(tokens[4][3]) michael@0: && isdigit(tokens[5][0]) && isdigit(tokens[5][1]) michael@0: && isdigit(tokens[5][3]) && isdigit(tokens[5][4]) michael@0: /* could also check that (&(tokens[5][5]) - tokens[2]) == 17 */ michael@0: ) michael@0: { michael@0: lstyle = 'w'; michael@0: } michael@0: if (lstyle && state->lstyle != lstyle) /* first time */ michael@0: { michael@0: p = tokens[1]; michael@0: if (toklen[1] != 5 || p[0] != '<' || p[1] != 'D' || michael@0: p[2] != 'I' || p[3] != 'R' || p[4] != '>') michael@0: { michael@0: for (pos = 0; lstyle && pos < toklen[1]; pos++) michael@0: { michael@0: if (!isdigit(*p++)) michael@0: lstyle = 0; michael@0: } michael@0: } /* not */ michael@0: } /* if (first time) */ michael@0: } /* if (numtoks == ...) */ michael@0: michael@0: if (lstyle == 'w') michael@0: { michael@0: state->parsed_one = 1; michael@0: state->lstyle = lstyle; michael@0: michael@0: result->fe_cinfs = 1; michael@0: result->fe_fname = tokens[0]; michael@0: result->fe_fnlen = toklen[0]; michael@0: result->fe_type = 'd'; michael@0: michael@0: p = tokens[1]; michael@0: if (isdigit(*p)) michael@0: { michael@0: result->fe_type = 'f'; michael@0: pos = toklen[1]; michael@0: if (pos > (sizeof(result->fe_size)-1)) michael@0: pos = sizeof(result->fe_size)-1; michael@0: memcpy( result->fe_size, p, pos ); michael@0: result->fe_size[pos] = '\0'; michael@0: } michael@0: michael@0: p = tokens[2]; michael@0: if (toklen[2] == 3) /* Chameleon */ michael@0: { michael@0: tbuf[0] = toupper(p[0]); michael@0: tbuf[1] = tolower(p[1]); michael@0: tbuf[2] = tolower(p[2]); michael@0: for (pos = 0; pos < (12*3); pos+=3) michael@0: { michael@0: if (tbuf[0] == month_names[pos+0] && michael@0: tbuf[1] == month_names[pos+1] && michael@0: tbuf[2] == month_names[pos+2]) michael@0: { michael@0: result->fe_time.tm_month = pos/3; michael@0: result->fe_time.tm_mday = atoi(tokens[3]); michael@0: result->fe_time.tm_year = atoi(tokens[4]) - 1900; michael@0: break; michael@0: } michael@0: } michael@0: pos = 5; /* Chameleon toknum of date field */ michael@0: } michael@0: else michael@0: { michael@0: result->fe_time.tm_month = atoi(p+0)-1; michael@0: result->fe_time.tm_mday = atoi(p+3); michael@0: result->fe_time.tm_year = atoi(p+6); michael@0: if (result->fe_time.tm_year < 80) /* SuperTCP */ michael@0: result->fe_time.tm_year += 100; michael@0: michael@0: pos = 3; /* SuperTCP toknum of date field */ michael@0: } michael@0: michael@0: result->fe_time.tm_hour = atoi(tokens[pos]); michael@0: result->fe_time.tm_min = atoi(&(tokens[pos][toklen[pos]-2])); michael@0: michael@0: /* the caller should do this (if dropping "." and ".." is desired) michael@0: if (result->fe_type == 'd' && result->fe_fname[0] == '.' && michael@0: (result->fe_fnlen == 1 || (result->fe_fnlen == 2 && michael@0: result->fe_fname[1] == '.'))) michael@0: return '?'; michael@0: */ michael@0: michael@0: return result->fe_type; michael@0: } /* (lstyle == 'w') */ michael@0: michael@0: } /* if (!lstyle && (!state->lstyle || state->lstyle == 'w')) */ michael@0: #endif michael@0: michael@0: /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ michael@0: michael@0: #if defined(SUPPORT_DLS) /* dls -dtR */ michael@0: if (!lstyle && michael@0: (state->lstyle == 'D' || (!state->lstyle && state->numlines == 1))) michael@0: /* /bin/dls lines have to be immediately recognizable (first line) */ michael@0: { michael@0: /* I haven't seen an FTP server that delivers a /bin/dls listing, michael@0: * but can infer the format from the lynx and mirror.pl projects. michael@0: * Both formats are supported. michael@0: * michael@0: * Lynx says: michael@0: * README 763 Information about this server\0 michael@0: * bin/ - \0 michael@0: * etc/ = \0 michael@0: * ls-lR 0 \0 michael@0: * ls-lR.Z 3 \0 michael@0: * pub/ = Public area\0 michael@0: * usr/ - \0 michael@0: * morgan 14 -> ../real/morgan\0 michael@0: * TIMIT.mostlikely.Z\0 michael@0: * 79215 \0 michael@0: * michael@0: * mirror.pl says: michael@0: * filename: ^(\S*)\s+ michael@0: * size: (\-|\=|\d+)\s+ michael@0: * month/day: ((\w\w\w\s+\d+|\d+\s+\w\w\w)\s+ michael@0: * time/year: (\d+:\d+|\d\d\d\d))\s+ michael@0: * rest: (.+) michael@0: * michael@0: * README 763 Jul 11 21:05 Information about this server michael@0: * bin/ - Apr 28 1994 michael@0: * etc/ = 11 Jul 21:04 michael@0: * ls-lR 0 6 Aug 17:14 michael@0: * ls-lR.Z 3 05 Sep 1994 michael@0: * pub/ = Jul 11 21:04 Public area michael@0: * usr/ - Sep 7 09:39 michael@0: * morgan 14 Apr 18 09:39 -> ../real/morgan michael@0: * TIMIT.mostlikely.Z michael@0: * 79215 Jul 11 21:04 michael@0: */ michael@0: if (!state->lstyle && line[linelen-1] == ':' && michael@0: linelen >= 2 && toklen[numtoks-1] != 1) michael@0: { michael@0: /* code in mirror.pl suggests that a listing may be preceded michael@0: * by a PWD line in the form "/some/dir/names/here:" michael@0: * but does not necessarily begin with '/'. *sigh* michael@0: */ michael@0: pos = 0; michael@0: p = line; michael@0: while (pos < (linelen-1)) michael@0: { michael@0: /* illegal (or extremely unusual) chars in a dirspec */ michael@0: if (*p == '<' || *p == '|' || *p == '>' || michael@0: *p == '?' || *p == '*' || *p == '\\') michael@0: break; michael@0: if (*p == '/' && pos < (linelen-2) && p[1] == '/') michael@0: break; michael@0: pos++; michael@0: p++; michael@0: } michael@0: if (pos == (linelen-1)) michael@0: { michael@0: state->lstyle = 'D'; michael@0: return '?'; michael@0: } michael@0: } michael@0: michael@0: if (!lstyle && numtoks >= 2) michael@0: { michael@0: pos = 22; /* pos of (\d+|-|=) if this is not part of a multiline */ michael@0: if (state->lstyle && carry_buf_len) /* first is from previous line */ michael@0: pos = toklen[1]-1; /* and is 'as-is' (may contain whitespace) */ michael@0: michael@0: if (linelen > pos) michael@0: { michael@0: p = &line[pos]; michael@0: if ((*p == '-' || *p == '=' || isdigit(*p)) && michael@0: ((linelen == (pos+1)) || michael@0: (linelen >= (pos+3) && p[1] == ' ' && p[2] == ' ')) ) michael@0: { michael@0: tokmarker = 1; michael@0: if (!carry_buf_len) michael@0: { michael@0: pos = 1; michael@0: while (pos < numtoks && (tokens[pos]+toklen[pos]) < (&line[23])) michael@0: pos++; michael@0: tokmarker = 0; michael@0: if ((tokens[pos]+toklen[pos]) == (&line[23])) michael@0: tokmarker = pos; michael@0: } michael@0: if (tokmarker) michael@0: { michael@0: lstyle = 'D'; michael@0: if (*tokens[tokmarker] == '-' || *tokens[tokmarker] == '=') michael@0: { michael@0: if (toklen[tokmarker] != 1 || michael@0: (tokens[tokmarker-1][toklen[tokmarker-1]-1]) != '/') michael@0: lstyle = 0; michael@0: } michael@0: else michael@0: { michael@0: for (pos = 0; lstyle && pos < toklen[tokmarker]; pos++) michael@0: { michael@0: if (!isdigit(tokens[tokmarker][pos])) michael@0: lstyle = 0; michael@0: } michael@0: } michael@0: if (lstyle && !state->lstyle) /* first time */ michael@0: { michael@0: /* scan for illegal (or incredibly unusual) chars in fname */ michael@0: for (p = tokens[0]; lstyle && michael@0: p < &(tokens[tokmarker-1][toklen[tokmarker-1]]); p++) michael@0: { michael@0: if (*p == '<' || *p == '|' || *p == '>' || michael@0: *p == '?' || *p == '*' || *p == '/' || *p == '\\') michael@0: lstyle = 0; michael@0: } michael@0: } michael@0: michael@0: } /* size token found */ michael@0: } /* expected chars behind expected size token */ michael@0: } /* if (linelen > pos) */ michael@0: } /* if (!lstyle && numtoks >= 2) */ michael@0: michael@0: if (!lstyle && state->lstyle == 'D' && !carry_buf_len) michael@0: { michael@0: /* the filename of a multi-line entry can be identified michael@0: * correctly only if dls format had been previously established. michael@0: * This should always be true because there should be entries michael@0: * for '.' and/or '..' and/or CWD that precede the rest of the michael@0: * listing. michael@0: */ michael@0: pos = linelen; michael@0: if (pos > (sizeof(state->carry_buf)-1)) michael@0: pos = sizeof(state->carry_buf)-1; michael@0: memcpy( state->carry_buf, line, pos ); michael@0: state->carry_buf_len = pos; michael@0: return '?'; michael@0: } michael@0: michael@0: if (lstyle == 'D') michael@0: { michael@0: state->parsed_one = 1; michael@0: state->lstyle = lstyle; michael@0: michael@0: p = &(tokens[tokmarker-1][toklen[tokmarker-1]]); michael@0: result->fe_fname = tokens[0]; michael@0: result->fe_fnlen = p - tokens[0]; michael@0: result->fe_type = 'f'; michael@0: michael@0: if (result->fe_fname[result->fe_fnlen-1] == '/') michael@0: { michael@0: if (result->fe_lnlen == 1) michael@0: result->fe_type = '?'; michael@0: else michael@0: { michael@0: result->fe_fnlen--; michael@0: result->fe_type = 'd'; michael@0: } michael@0: } michael@0: else if (isdigit(*tokens[tokmarker])) michael@0: { michael@0: pos = toklen[tokmarker]; michael@0: if (pos > (sizeof(result->fe_size)-1)) michael@0: pos = sizeof(result->fe_size)-1; michael@0: memcpy( result->fe_size, tokens[tokmarker], pos ); michael@0: result->fe_size[pos] = '\0'; michael@0: } michael@0: michael@0: if ((tokmarker+3) < numtoks && michael@0: (&(tokens[numtoks-1][toklen[numtoks-1]]) - michael@0: tokens[tokmarker+1]) >= (1+1+3+1+4) ) michael@0: { michael@0: pos = (tokmarker+3); michael@0: p = tokens[pos]; michael@0: pos = toklen[pos]; michael@0: michael@0: if ((pos == 4 || pos == 5) michael@0: && isdigit(*p) && isdigit(p[pos-1]) && isdigit(p[pos-2]) michael@0: && ((pos == 5 && p[2] == ':') || michael@0: (pos == 4 && (isdigit(p[1]) || p[1] == ':'))) michael@0: ) michael@0: { michael@0: month_num = tokmarker+1; /* assumed position of month field */ michael@0: pos = tokmarker+2; /* assumed position of mday field */ michael@0: if (isdigit(*tokens[month_num])) /* positions are reversed */ michael@0: { michael@0: month_num++; michael@0: pos--; michael@0: } michael@0: p = tokens[month_num]; michael@0: if (isdigit(*tokens[pos]) michael@0: && (toklen[pos] == 1 || michael@0: (toklen[pos] == 2 && isdigit(tokens[pos][1]))) michael@0: && toklen[month_num] == 3 michael@0: && isalpha(*p) && isalpha(p[1]) && isalpha(p[2]) ) michael@0: { michael@0: pos = atoi(tokens[pos]); michael@0: if (pos > 0 && pos <= 31) michael@0: { michael@0: result->fe_time.tm_mday = pos; michael@0: month_num = 1; michael@0: for (pos = 0; pos < (12*3); pos+=3) michael@0: { michael@0: if (p[0] == month_names[pos+0] && michael@0: p[1] == month_names[pos+1] && michael@0: p[2] == month_names[pos+2]) michael@0: break; michael@0: month_num++; michael@0: } michael@0: if (month_num > 12) michael@0: result->fe_time.tm_mday = 0; michael@0: else michael@0: result->fe_time.tm_month = month_num - 1; michael@0: } michael@0: } michael@0: if (result->fe_time.tm_mday) michael@0: { michael@0: tokmarker += 3; /* skip mday/mon/yrtime (to find " -> ") */ michael@0: p = tokens[tokmarker]; michael@0: michael@0: pos = atoi(p); michael@0: if (pos > 24) michael@0: result->fe_time.tm_year = pos-1900; michael@0: else michael@0: { michael@0: if (p[1] == ':') michael@0: p--; michael@0: result->fe_time.tm_hour = pos; michael@0: result->fe_time.tm_min = atoi(p+3); michael@0: if (!state->now_time) michael@0: { michael@0: state->now_time = PR_Now(); michael@0: PR_ExplodeTime((state->now_time), PR_LocalTimeParameters, &(state->now_tm) ); michael@0: } michael@0: result->fe_time.tm_year = state->now_tm.tm_year; michael@0: if ( (( state->now_tm.tm_month << 4) + state->now_tm.tm_mday) < michael@0: ((result->fe_time.tm_month << 4) + result->fe_time.tm_mday) ) michael@0: result->fe_time.tm_year--; michael@0: } /* got year or time */ michael@0: } /* got month/mday */ michael@0: } /* may have year or time */ michael@0: } /* enough remaining to possibly have date/time */ michael@0: michael@0: if (numtoks > (tokmarker+2)) michael@0: { michael@0: pos = tokmarker+1; michael@0: p = tokens[pos]; michael@0: if (toklen[pos] == 2 && *p == '-' && p[1] == '>') michael@0: { michael@0: p = &(tokens[numtoks-1][toklen[numtoks-1]]); michael@0: result->fe_type = 'l'; michael@0: result->fe_lname = tokens[pos+1]; michael@0: result->fe_lnlen = p - result->fe_lname; michael@0: if (result->fe_lnlen > 1 && michael@0: result->fe_lname[result->fe_lnlen-1] == '/') michael@0: result->fe_lnlen--; michael@0: } michael@0: } /* if (numtoks > (tokmarker+2)) */ michael@0: michael@0: /* the caller should do this (if dropping "." and ".." is desired) michael@0: if (result->fe_type == 'd' && result->fe_fname[0] == '.' && michael@0: (result->fe_fnlen == 1 || (result->fe_fnlen == 2 && michael@0: result->fe_fname[1] == '.'))) michael@0: return '?'; michael@0: */ michael@0: michael@0: return result->fe_type; michael@0: michael@0: } /* if (lstyle == 'D') */ michael@0: } /* if (!lstyle && (!state->lstyle || state->lstyle == 'D')) */ michael@0: #endif michael@0: michael@0: /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ michael@0: michael@0: } /* if (linelen > 0) */ michael@0: michael@0: return ParsingFailed(state); michael@0: } michael@0: michael@0: /* ==================================================================== */ michael@0: /* standalone testing */ michael@0: /* ==================================================================== */ michael@0: #if 0 michael@0: michael@0: #include michael@0: michael@0: static int do_it(FILE *outfile, michael@0: char *line, size_t linelen, struct list_state *state, michael@0: char **cmnt_buf, unsigned int *cmnt_buf_sz, michael@0: char **list_buf, unsigned int *list_buf_sz ) michael@0: { michael@0: struct list_result result; michael@0: char *p; michael@0: int rc; michael@0: michael@0: rc = ParseFTPList( line, state, &result ); michael@0: michael@0: if (!outfile) michael@0: { michael@0: outfile = stdout; michael@0: if (rc == '?') michael@0: fprintf(outfile, "junk: %.*s\n", (int)linelen, line ); michael@0: else if (rc == '"') michael@0: fprintf(outfile, "cmnt: %.*s\n", (int)linelen, line ); michael@0: else michael@0: fprintf(outfile, michael@0: "list: %02u-%02u-%02u %02u:%02u%cM %20s %.*s%s%.*s\n", michael@0: (result.fe_time.tm_mday ? (result.fe_time.tm_month + 1) : 0), michael@0: result.fe_time.tm_mday, michael@0: (result.fe_time.tm_mday ? (result.fe_time.tm_year % 100) : 0), michael@0: result.fe_time.tm_hour - michael@0: ((result.fe_time.tm_hour > 12)?(12):(0)), michael@0: result.fe_time.tm_min, michael@0: ((result.fe_time.tm_hour >= 12) ? 'P' : 'A'), michael@0: (rc == 'd' ? " " : michael@0: (rc == 'l' ? " " : result.fe_size)), michael@0: (int)result.fe_fnlen, result.fe_fname, michael@0: ((rc == 'l' && result.fe_lnlen) ? " -> " : ""), michael@0: (int)((rc == 'l' && result.fe_lnlen) ? result.fe_lnlen : 0), michael@0: ((rc == 'l' && result.fe_lnlen) ? result.fe_lname : "") ); michael@0: } michael@0: else if (rc != '?') /* NOT junk */ michael@0: { michael@0: char **bufp = list_buf; michael@0: unsigned int *bufz = list_buf_sz; michael@0: michael@0: if (rc == '"') /* comment - make it a 'result' */ michael@0: { michael@0: memset( &result, 0, sizeof(result)); michael@0: result.fe_fname = line; michael@0: result.fe_fnlen = linelen; michael@0: result.fe_type = 'f'; michael@0: if (line[linelen-1] == '/') michael@0: { michael@0: result.fe_type = 'd'; michael@0: result.fe_fnlen--; michael@0: } michael@0: bufp = cmnt_buf; michael@0: bufz = cmnt_buf_sz; michael@0: rc = result.fe_type; michael@0: } michael@0: michael@0: linelen = 80 + result.fe_fnlen + result.fe_lnlen; michael@0: p = (char *)realloc( *bufp, *bufz + linelen ); michael@0: if (!p) michael@0: return -1; michael@0: sprintf( &p[*bufz], michael@0: "%02u-%02u-%04u %02u:%02u:%02u %20s %.*s%s%.*s\n", michael@0: (result.fe_time.tm_mday ? (result.fe_time.tm_month + 1) : 0), michael@0: result.fe_time.tm_mday, michael@0: (result.fe_time.tm_mday ? (result.fe_time.tm_year + 1900) : 0), michael@0: result.fe_time.tm_hour, michael@0: result.fe_time.tm_min, michael@0: result.fe_time.tm_sec, michael@0: (rc == 'd' ? " " : michael@0: (rc == 'l' ? " " : result.fe_size)), michael@0: (int)result.fe_fnlen, result.fe_fname, michael@0: ((rc == 'l' && result.fe_lnlen) ? " -> " : ""), michael@0: (int)((rc == 'l' && result.fe_lnlen) ? result.fe_lnlen : 0), michael@0: ((rc == 'l' && result.fe_lnlen) ? result.fe_lname : "") ); michael@0: linelen = strlen(&p[*bufz]); michael@0: *bufp = p; michael@0: *bufz = *bufz + linelen; michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: int main(int argc, char *argv[]) michael@0: { michael@0: FILE *infile = (FILE *)0; michael@0: FILE *outfile = (FILE *)0; michael@0: int need_close_in = 0; michael@0: int need_close_out = 0; michael@0: michael@0: if (argc > 1) michael@0: { michael@0: infile = stdin; michael@0: if (strcmp(argv[1], "-") == 0) michael@0: need_close_in = 0; michael@0: else if ((infile = fopen(argv[1], "r")) != ((FILE *)0)) michael@0: need_close_in = 1; michael@0: else michael@0: fprintf(stderr, "Unable to open input file '%s'\n", argv[1]); michael@0: } michael@0: if (infile && argc > 2) michael@0: { michael@0: outfile = stdout; michael@0: if (strcmp(argv[2], "-") == 0) michael@0: need_close_out = 0; michael@0: else if ((outfile = fopen(argv[2], "w")) != ((FILE *)0)) michael@0: need_close_out = 1; michael@0: else michael@0: { michael@0: fprintf(stderr, "Unable to open output file '%s'\n", argv[2]); michael@0: fclose(infile); michael@0: infile = (FILE *)0; michael@0: } michael@0: } michael@0: michael@0: if (!infile) michael@0: { michael@0: char *appname = &(argv[0][strlen(argv[0])]); michael@0: while (appname > argv[0]) michael@0: { michael@0: appname--; michael@0: if (*appname == '/' || *appname == '\\' || *appname == ':') michael@0: { michael@0: appname++; michael@0: break; michael@0: } michael@0: } michael@0: fprintf(stderr, michael@0: "Usage: %s []\n" michael@0: "\nIf an outout file is specified the results will be" michael@0: "\nbe post-processed, and only the file entries will appear" michael@0: "\n(or all comments if there are no file entries)." michael@0: "\nNot specifying an output file causes %s to run in \"debug\"" michael@0: "\nmode, ie results are printed as lines are parsed." michael@0: "\nIf a filename is a single dash ('-'), stdin/stdout is used." michael@0: "\n", appname, appname ); michael@0: } michael@0: else michael@0: { michael@0: char *cmnt_buf = (char *)0; michael@0: unsigned int cmnt_buf_sz = 0; michael@0: char *list_buf = (char *)0; michael@0: unsigned int list_buf_sz = 0; michael@0: michael@0: struct list_state state; michael@0: char line[512]; michael@0: michael@0: memset( &state, 0, sizeof(state) ); michael@0: while (fgets(line, sizeof(line), infile)) michael@0: { michael@0: size_t linelen = strlen(line); michael@0: if (linelen < (sizeof(line)-1)) michael@0: { michael@0: if (linelen > 0 && line[linelen-1] == '\n') michael@0: linelen--; michael@0: if (do_it( outfile, line, linelen, &state, michael@0: &cmnt_buf, &cmnt_buf_sz, &list_buf, &list_buf_sz) != 0) michael@0: { michael@0: fprintf(stderr, "Insufficient memory. Listing may be incomplete.\n"); michael@0: break; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: /* no '\n' found. drop this and everything up to the next '\n' */ michael@0: fprintf(stderr, "drop: %.*s", (int)linelen, line ); michael@0: while (linelen == sizeof(line)) michael@0: { michael@0: if (!fgets(line, sizeof(line), infile)) michael@0: break; michael@0: linelen = 0; michael@0: while (linelen < sizeof(line) && line[linelen] != '\n') michael@0: linelen++; michael@0: fprintf(stderr, "%.*s", (int)linelen, line ); michael@0: } michael@0: fprintf(stderr, "\n"); michael@0: } michael@0: } michael@0: if (outfile) michael@0: { michael@0: if (list_buf) michael@0: fwrite( list_buf, 1, list_buf_sz, outfile ); michael@0: else if (cmnt_buf) michael@0: fwrite( cmnt_buf, 1, cmnt_buf_sz, outfile ); michael@0: } michael@0: if (list_buf) michael@0: free(list_buf); michael@0: if (cmnt_buf) michael@0: free(cmnt_buf); michael@0: michael@0: if (need_close_in) michael@0: fclose(infile); michael@0: if (outfile && need_close_out) michael@0: fclose(outfile); michael@0: } michael@0: michael@0: return 0; michael@0: } michael@0: #endif