📄 ftpdirectoryparser.cpp
字号:
if (lstyle && numtoks > 4) /* Multinet or UCX but not CMU */ { for (pos = 1; lstyle && pos < (toklen[5]-1); pos++) { p = &(tokens[5][pos]); if (*p!='R' && *p!='W' && *p!='E' && *p!='D' && *p!=',') lstyle = 0; } } } } /* passed initial tests */ } /* else if ((tokens[0][toklen[0]-1]) != ';') */ if (lstyle == 'V') { state.parsedOne = true; state.listStyle = lstyle; if (isASCIIDigit(*tokens[1])) /* not permission denied etc */ { /* strip leading directory name */ if (*tokens[0] == '[') /* CMU server */ { pos = toklen[0]-1; p = tokens[0]+1; while (*p != ']') { p++; pos--; } toklen[0] = --pos; tokens[0] = ++p; } pos = 0; while (pos < toklen[0] && (tokens[0][pos]) != ';') pos++; result.caseSensitive = true; result.type = FTPFileEntry; result.filename = tokens[0]; result.filenameLength = pos; if (pos > 4) { p = &(tokens[0][pos-4]); if (p[0] == '.' && p[1] == 'D' && p[2] == 'I' && p[3] == 'R') { result.filenameLength -= 4; result.type = FTPDirectoryEntry; } } if (result.type != FTPDirectoryEntry) { /* #### or used/allocated form. If used/allocated form, then * 'used' is the size in bytes if and only if 'used'<=allocated. * If 'used' is size in bytes then it can be > 2^32 * If 'used' is not size in bytes then it is size in blocks. */ pos = 0; while (pos < toklen[1] && (tokens[1][pos]) != '/') pos++; /* * I've never seen size come back in bytes, its always in blocks, and * the following test fails. So, always perform the "size in blocks". * I'm leaving the "size in bytes" code if'd out in case we ever need * to re-instate it.*/#if 0 if (pos < toklen[1] && ( (pos<<1) > (toklen[1]-1) || (strtoul(tokens[1], (char **)0, 10) > strtoul(tokens[1]+pos+1, (char **)0, 10)) )) { /* size is in bytes */ if (pos > (sizeof(result.fe_size)-1)) pos = sizeof(result.fe_size)-1; memcpy( result.fe_size, tokens[1], pos ); result.fe_size[pos] = '\0'; } else /* size is in blocks */#endif { /* size requires multiplication by blocksize. * * We could assume blocksize is 512 (like Lynx does) and * shift by 9, but that might not be right. Even if it * were, doing that wouldn't reflect what the file's * real size was. The sanest thing to do is not use the * LISTing's filesize, so we won't (like ftpmirror). * * ulltoa(((unsigned long long)fsz)<<9, result.fe_size, 10); * * A block is always 512 bytes on OpenVMS, compute size. * So its rounded up to the next block, so what, its better * than not showing the size at all. * A block is always 512 bytes on OpenVMS, compute size. * So its rounded up to the next block, so what, its better * than not showing the size at all. */ uint64_t size = strtoul(tokens[1], NULL, 10) * 512; result.fileSize = String::number(size); } } /* if (result.type != FTPDirectoryEntry) */ p = tokens[2] + 2; if (*p == '-') p++; tbuf[0] = p[0]; tbuf[1] = toASCIILower(p[1]); tbuf[2] = toASCIILower(p[2]); month_num = 0; for (pos = 0; pos < (12*3); pos+=3) { if (tbuf[0] == month_names[pos+0] && tbuf[1] == month_names[pos+1] && tbuf[2] == month_names[pos+2]) break; month_num++; } if (month_num >= 12) month_num = 0; result.modifiedTime.tm_mon = month_num; result.modifiedTime.tm_mday = atoi(tokens[2]); result.modifiedTime.tm_year = atoi(p+4); // NSPR wants year as XXXX p = tokens[3] + 2; if (*p == ':') p++; if (p[2] == ':') result.modifiedTime.tm_sec = atoi(p+3); result.modifiedTime.tm_hour = atoi(tokens[3]); result.modifiedTime.tm_min = atoi(p); return result.type; } /* if (isASCIIDigit(*tokens[1])) */ return FTPJunkEntry; /* junk */ } /* if (lstyle == 'V') */ } /* if (!lstyle && (!state.listStyle || state.listStyle == 'V')) */#endif /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */#if defined(SUPPORT_CMS) /* Virtual Machine/Conversational Monitor System (IBM Mainframe) */ if (!lstyle && (!state.listStyle || state.listStyle == 'C')) /* VM/CMS */ { /* LISTing according to mirror.pl * Filename FileType Fm Format Lrecl Records Blocks Date Time * LASTING GLOBALV A1 V 41 21 1 9/16/91 15:10:32 * J43401 NETLOG A0 V 77 1 1 9/12/91 12:36:04 * PROFILE EXEC A1 V 17 3 1 9/12/91 12:39:07 * DIRUNIX SCRIPT A1 V 77 1216 17 1/04/93 20:30:47 * MAIL PROFILE A2 F 80 1 1 10/14/92 16:12:27 * BADY2K TEXT A0 V 1 1 1 1/03/102 10:11:12 * AUTHORS A1 DIR - - - 9/20/99 10:31:11 * * LISTing from vm.marist.edu and vm.sc.edu * 220-FTPSERVE IBM VM Level 420 at VM.MARIST.EDU, 04:58:12 EDT WEDNESDAY 2002-07-10 * AUTHORS DIR - - - 1999-09-20 10:31:11 - * HARRINGTON DIR - - - 1997-02-12 15:33:28 - * PICS DIR - - - 2000-10-12 15:43:23 - * SYSFILE DIR - - - 2000-07-20 17:48:01 - * WELCNVT EXEC V 72 9 1 1999-09-20 17:16:18 - * WELCOME EREADME F 80 21 1 1999-12-27 16:19:00 - * WELCOME README V 82 21 1 1999-12-27 16:19:04 - * README ANONYMOU V 71 26 1 1997-04-02 12:33:20 TCP291 * README ANONYOLD V 71 15 1 1995-08-25 16:04:27 TCP291 */ if (numtoks >= 7 && (toklen[0]+toklen[1]) <= 16) { for (pos = 1; !lstyle && (pos+5) < numtoks; pos++) { p = tokens[pos]; if ((toklen[pos] == 1 && (*p == 'F' || *p == 'V')) || (toklen[pos] == 3 && *p == 'D' && p[1] == 'I' && p[2] == 'R')) { if (toklen[pos+5] == 8 && (tokens[pos+5][2]) == ':' && (tokens[pos+5][5]) == ':' ) { p = tokens[pos+4]; if ((toklen[pos+4] == 10 && p[4] == '-' && p[7] == '-') || (toklen[pos+4] >= 7 && toklen[pos+4] <= 9 && p[((p[1]!='/')?(2):(1))] == '/' && p[((p[1]!='/')?(5):(4))] == '/')) /* Y2K bugs possible ("7/06/102" or "13/02/101") */ { if ( (*tokens[pos+1] == '-' && *tokens[pos+2] == '-' && *tokens[pos+3] == '-') || (isASCIIDigit(*tokens[pos+1]) && isASCIIDigit(*tokens[pos+2]) && isASCIIDigit(*tokens[pos+3])) ) { lstyle = 'C'; tokmarker = pos; } } } } } /* for (pos = 1; !lstyle && (pos+5) < numtoks; pos++) */ } /* if (numtoks >= 7) */ /* extra checking if first pass */ if (lstyle && !state.listStyle) { for (pos = 0, p = tokens[0]; lstyle && pos < toklen[0]; pos++, p++) { if (isASCIIAlpha(*p) && toASCIIUpper(*p) != *p) lstyle = 0; } for (pos = tokmarker+1; pos <= tokmarker+3; pos++) { if (!(toklen[pos] == 1 && *tokens[pos] == '-')) { for (p = tokens[pos]; lstyle && p<(tokens[pos]+toklen[pos]); p++) { if (!isASCIIDigit(*p)) lstyle = 0; } } } for (pos = 0, p = tokens[tokmarker+4]; lstyle && pos < toklen[tokmarker+4]; pos++, p++) { if (*p == '/') { /* There may be Y2K bugs in the date. Don't simplify to * pos != (len-3) && pos != (len-6) like time is done. */ if ((tokens[tokmarker+4][1]) == '/') { if (pos != 1 && pos != 4) lstyle = 0; } else if (pos != 2 && pos != 5) lstyle = 0; } else if (*p != '-' && !isASCIIDigit(*p)) lstyle = 0; else if (*p == '-' && pos != 4 && pos != 7) lstyle = 0; } for (pos = 0, p = tokens[tokmarker+5]; lstyle && pos < toklen[tokmarker+5]; pos++, p++) { if (*p != ':' && !isASCIIDigit(*p)) lstyle = 0; else if (*p == ':' && pos != (toklen[tokmarker+5]-3) && pos != (toklen[tokmarker+5]-6)) lstyle = 0; } } /* initial if() */ if (lstyle == 'C') { state.parsedOne = true; state.listStyle = lstyle; p = tokens[tokmarker+4]; if (toklen[tokmarker+4] == 10) /* newstyle: YYYY-MM-DD format */ { result.modifiedTime.tm_year = atoi(p+0) - 1900; result.modifiedTime.tm_mon = atoi(p+5) - 1; result.modifiedTime.tm_mday = atoi(p+8); } else /* oldstyle: [M]M/DD/YY format */ { pos = toklen[tokmarker+4]; result.modifiedTime.tm_mon = atoi(p) - 1; result.modifiedTime.tm_mday = atoi((p+pos)-5); result.modifiedTime.tm_year = atoi((p+pos)-2); if (result.modifiedTime.tm_year < 70) result.modifiedTime.tm_year += 100; } p = tokens[tokmarker+5]; pos = toklen[tokmarker+5]; result.modifiedTime.tm_hour = atoi(p); result.modifiedTime.tm_min = atoi((p+pos)-5); result.modifiedTime.tm_sec = atoi((p+pos)-2); result.caseSensitive = true; result.filename = tokens[0]; result.filenameLength = toklen[0]; result.type = FTPFileEntry; p = tokens[tokmarker]; if (toklen[tokmarker] == 3 && *p=='D' && p[1]=='I' && p[2]=='R') result.type = FTPDirectoryEntry; if ((/*newstyle*/ toklen[tokmarker+4] == 10 && tokmarker > 1) || (/*oldstyle*/ toklen[tokmarker+4] != 10 && tokmarker > 2)) { /* have a filetype column */ char *dot; p = &(tokens[0][toklen[0]]); memcpy( &dot, &p, sizeof(dot) ); /* NASTY! */ *dot++ = '.'; p = tokens[1]; for (pos = 0; pos < toklen[1]; pos++) *dot++ = *p++; result.filenameLength += 1 + toklen[1]; } /* oldstyle LISTING: * files/dirs not on the 'A' minidisk are not RETRievable/CHDIRable if (toklen[tokmarker+4] != 10 && *tokens[tokmarker-1] != 'A') return FTPJunkEntry; */ /* VM/CMS LISTings have no usable filesize field. * Have to use the 'SIZE' command for that. */ return result.type; } /* if (lstyle == 'C' && (!state.listStyle || state.listStyle == lstyle)) */ } /* VM/CMS */#endif /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */#if defined(SUPPORT_DOS) /* WinNT DOS dirstyle */ if (!lstyle && (!state.listStyle || state.listStyle == 'W')) { /* * "10-23-00 01:27PM <DIR> veronist" * "06-15-00 07:37AM <DIR> zoe" * "07-14-00 01:35PM 2094926 canprankdesk.tif" * "07-21-00 01:19PM 95077 Jon Kauffman Enjoys the Good Life.jpg" * "07-21-00 01:19PM 52275 Name Plate.jpg" * "07-14-00 01:38PM 2250540 Valentineoffprank-HiRes.jpg" */ if ((numtoks >= 4) && toklen[0] == 8 && toklen[1] == 7 && (*tokens[2] == '<' || isASCIIDigit(*tokens[2])) ) { p = tokens[0]; if ( isASCIIDigit(p[0]) && isASCIIDigit(p[1]) && p[2]=='-' && isASCIIDigit(p[3]) && isASCIIDigit(p[4]) && p[5]=='-' && isASCIIDigit(p[6]) && isASCIIDigit(p[7]) ) { p = tokens[1]; if ( isASCIIDigit(p[0]) && isASCIIDigit(p[1]) && p[2]==':' && isASCIIDigit(p[3]) && isASCIIDigit(p[4]) && (p[5]=='A' || p[5]=='P') && p[6]=='M') { lstyle = 'W'; if (!state.listStyle) { p = tokens[2]; /* <DIR> or <JUNCTION> */ if (*p != '<' || p[toklen[2]-1] != '>') { for (pos = 1; (lstyle && pos < toklen[2]); pos++) { if (!isASCIIDigit(*++p)) lstyle = 0; } } } } } } if (lstyle == 'W') { state.parsedOne = true; state.listStyle = lstyle; p = &(line[linelen_sans_wsp]); /* line end sans wsp */ result.caseSensitive = true; result.filename = tokens[3]; result.filenameLength = p - tokens[3]; result.type = FTPDirectoryEntry; if (*tokens[2] != '<') /* not <DIR> or <JUNCTION> */ { result.type = FTPFileEntry; pos = toklen[2]; result.fileSize = String(tokens[2], pos); } else if ((tokens[2][1]) != 'D') /* not <DIR> */ { result.type = FTPJunkEntry; /* unknown until junc for sure */ if (result.filenameLength > 4) { p = result.filename; for (pos = result.filenameLength - 4; pos > 0; pos--) { if (p[0] == ' ' && p[3] == ' ' && p[2] == '>' && (p[1] == '=' || p[1] == '-')) { result.type = FTPLinkEntry; result.filenameLength = p - result.filename; result.linkname = p + 4; result.linknameLength = &(line[linelen_sans_wsp]) - result.linkname; break; } p++; } } } result.modifiedTime.tm_mon = atoi(tokens[0]+0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -