| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 6 // |
| 7 // The contents of this file are subject to the Mozilla Public License Version |
| 8 // 1.1 (the "License"); you may not use this file except in compliance with |
| 9 // the License. You may obtain a copy of the License at |
| 10 // http://www.mozilla.org/MPL/ |
| 11 // |
| 12 // Software distributed under the License is distributed on an "AS IS" basis, |
| 13 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 14 // for the specific language governing rights and limitations under the |
| 15 // License. |
| 16 // |
| 17 // The Original Code is mozilla.org Code. |
| 18 // |
| 19 // The Initial Developer of the Original Code is |
| 20 // Cyrus Patel <cyp@fb14.uni-mainz.de>. |
| 21 // Portions created by the Initial Developer are Copyright (C) 2002 |
| 22 // the Initial Developer. All Rights Reserved. |
| 23 // |
| 24 // Contributor(s): |
| 25 // Doug Turner <dougt@netscape.com> |
| 26 // |
| 27 // Alternatively, the contents of this file may be used under the terms of |
| 28 // either the GNU General Public License Version 2 or later (the "GPL"), or |
| 29 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 30 // in which case the provisions of the GPL or the LGPL are applicable instead |
| 31 // of those above. If you wish to allow use of your version of this file only |
| 32 // under the terms of either the GPL or the LGPL, and not to allow others to |
| 33 // use your version of this file under the terms of the MPL, indicate your |
| 34 // decision by deleting the provisions above and replace them with the notice |
| 35 // and other provisions required by the GPL or the LGPL. If you do not delete |
| 36 // the provisions above, a recipient may use your version of this file under |
| 37 // the terms of any one of the MPL, the GPL or the LGPL. |
| 38 |
| 39 // Derived from: |
| 40 // mozilla/netwerk/streamconv/converters/ParseFTPList.cpp revision 1.10 |
| 41 |
| 42 #include "net/ftp/ftp_directory_parser.h" |
| 43 |
| 44 #include <stdlib.h> |
| 45 #include <string.h> |
| 46 #include <ctype.h> |
| 47 |
| 48 #include "build/build_config.h" |
| 49 #include "base/basictypes.h" |
| 50 #include "base/string_util.h" |
| 51 |
| 52 // #undef anything you don't want to support |
| 53 #define SUPPORT_LSL // /bin/ls -l and dozens of variations therof |
| 54 #define SUPPORT_DLS // /bin/dls format (very, Very, VERY rare) |
| 55 #define SUPPORT_EPLF // Extraordinarily Pathetic List Format |
| 56 #define SUPPORT_DOS // WinNT server in 'site dirstyle' dos |
| 57 #define SUPPORT_VMS // VMS (all: MultiNet, UCX, CMU-IP) |
| 58 #define SUPPORT_CMS // IBM VM/CMS,VM/ESA (z/VM and LISTING forms) |
| 59 #define SUPPORT_OS2 // IBM TCP/IP for OS/2 - FTP Server |
| 60 #define SUPPORT_W16 // win16 hosts: SuperTCP or NetManage Chameleon |
| 61 |
| 62 // Implement the Unix gmtime_r() function for Windows. |
| 63 #if defined(OS_WIN) |
| 64 static struct tm *gmtime_r(const time_t *timer, struct tm *result) { |
| 65 errno_t error = gmtime_s(result, timer); |
| 66 if (error) { |
| 67 errno = error; |
| 68 return NULL; |
| 69 } |
| 70 return result; |
| 71 } |
| 72 #endif |
| 73 |
| 74 namespace net { |
| 75 |
| 76 LineType ParseFTPLine(const char *line, |
| 77 struct ListState *state, |
| 78 struct ListResult *result) { |
| 79 unsigned int carry_buf_len; |
| 80 unsigned int linelen, pos; |
| 81 const char *p; |
| 82 |
| 83 if (!line || !state || !result) |
| 84 return FTP_TYPE_JUNK; |
| 85 |
| 86 memset(result, 0, sizeof(*result)); |
| 87 |
| 88 state->numlines++; |
| 89 |
| 90 // Carry buffer is only valid from one line to the next. |
| 91 carry_buf_len = state->carry_buf_len; |
| 92 state->carry_buf_len = 0; |
| 93 |
| 94 linelen = 0; |
| 95 |
| 96 // Strip leading whitespace. |
| 97 while (*line == ' ' || *line == '\t') |
| 98 line++; |
| 99 |
| 100 // Line is terminated at first '\0' or '\n'. |
| 101 p = line; |
| 102 while (*p && *p != '\n') |
| 103 p++; |
| 104 linelen = p - line; |
| 105 |
| 106 if (linelen > 0 && *p == '\n' && *(p-1) == '\r') |
| 107 linelen--; |
| 108 |
| 109 // DON'T strip trailing whitespace. |
| 110 if (linelen > 0) { |
| 111 static const char *month_names = "JanFebMarAprMayJunJulAugSepOctNovDec"; |
| 112 const char *tokens[16]; |
| 113 unsigned int toklen[(sizeof(tokens)/sizeof(tokens[0]))]; |
| 114 unsigned int linelen_sans_wsp; |
| 115 unsigned int numtoks = 0; |
| 116 unsigned int tokmarker = 0; |
| 117 unsigned int month_num = 0; |
| 118 char tbuf[4]; |
| 119 int lstyle = 0; |
| 120 |
| 121 // VMS long filename carryover buffer. |
| 122 if (carry_buf_len) { |
| 123 tokens[0] = state->carry_buf; |
| 124 toklen[0] = carry_buf_len; |
| 125 numtoks++; |
| 126 } |
| 127 |
| 128 pos = 0; |
| 129 while (pos < linelen && numtoks < (sizeof(tokens)/sizeof(tokens[0]))) { |
| 130 while (pos < linelen && |
| 131 (line[pos] == ' ' || line[pos] == '\t' || line[pos] == '\r')) |
| 132 pos++; |
| 133 if (pos < linelen) { |
| 134 tokens[numtoks] = &line[pos]; |
| 135 while (pos < linelen && |
| 136 (line[pos] != ' ' && line[pos] != '\t' && line[pos] != '\r')) |
| 137 pos++; |
| 138 if (tokens[numtoks] != &line[pos]) { |
| 139 toklen[numtoks] = (&line[pos] - tokens[numtoks]); |
| 140 numtoks++; |
| 141 } |
| 142 } |
| 143 } |
| 144 linelen_sans_wsp = &(tokens[numtoks-1][toklen[numtoks-1]]) - tokens[0]; |
| 145 if (numtoks == (sizeof(tokens)/sizeof(tokens[0]))) { |
| 146 pos = linelen; |
| 147 while (pos > 0 && (line[pos-1] == ' ' || line[pos-1] == '\t')) |
| 148 pos--; |
| 149 linelen_sans_wsp = pos; |
| 150 } |
| 151 |
| 152 #if defined(SUPPORT_EPLF) |
| 153 // EPLF handling must come somewhere before /bin/dls handling. |
| 154 if (!lstyle && (!state->lstyle || state->lstyle == 'E')) { |
| 155 if (*line == '+' && linelen > 4 && numtoks >= 2) { |
| 156 pos = 1; |
| 157 while (pos < (linelen-1)) { |
| 158 p = &line[pos++]; |
| 159 if (*p == '/') |
| 160 result->fe_type = FTP_TYPE_DIRECTORY; // Its a dir. |
| 161 else if (*p == 'r') |
| 162 result->fe_type = FTP_TYPE_FILE; |
| 163 else if (*p == 'm') { |
| 164 if (isdigit(line[pos])) { |
| 165 while (pos < linelen && isdigit(line[pos])) |
| 166 pos++; |
| 167 if (pos < linelen && line[pos] == ',') { |
| 168 uint64 seconds = 0; |
| 169 seconds = StringToInt64(p + 1); |
| 170 time_t tim = static_cast<time_t>(seconds); |
| 171 gmtime_r(&tim, &result->fe_time); |
| 172 } |
| 173 } |
| 174 } else if (*p == 's') { |
| 175 if (isdigit(line[pos])) { |
| 176 while (pos < linelen && isdigit(line[pos])) |
| 177 pos++; |
| 178 if (pos < linelen && line[pos] == ',' && |
| 179 ((&line[pos]) - (p+1)) < |
| 180 static_cast<int>(sizeof(result->fe_size) - 1)) { |
| 181 memcpy(result->fe_size, p + 1, |
| 182 (unsigned)(&line[pos] - (p + 1))); |
| 183 result->fe_size[(&line[pos] - (p+1))] = '\0'; |
| 184 } |
| 185 } |
| 186 } else if (isalpha(*p)) { |
| 187 while (pos < linelen && *++p != ',') |
| 188 pos++; |
| 189 } else if (*p != '\t' || (p + 1) != tokens[1]) { |
| 190 break; // Its not EPLF after all. |
| 191 } else { |
| 192 state->parsed_one = 1; |
| 193 state->lstyle = lstyle = 'E'; |
| 194 |
| 195 p = &(line[linelen_sans_wsp]); |
| 196 result->fe_fname = tokens[1]; |
| 197 result->fe_fnlen = p - tokens[1]; |
| 198 |
| 199 // Access denied. |
| 200 if (!result->fe_type) { |
| 201 // is assuming 'f'ile correct? |
| 202 result->fe_type = FTP_TYPE_FILE; |
| 203 return FTP_TYPE_JUNK; // NO! junk it. |
| 204 } |
| 205 return result->fe_type; |
| 206 } |
| 207 if (pos >= (linelen-1) || line[pos] != ',') |
| 208 break; |
| 209 pos++; |
| 210 } // while (pos < linelen) |
| 211 memset(result, 0, sizeof(*result)); |
| 212 } // if (*line == '+' && linelen > 4 && numtoks >= 2). |
| 213 } // if (!lstyle && (!state->lstyle || state->lstyle == 'E')). |
| 214 #endif // SUPPORT_EPLF |
| 215 |
| 216 #if defined(SUPPORT_VMS) |
| 217 // try VMS Multinet/UCX/CMS server |
| 218 if (!lstyle && (!state->lstyle || state->lstyle == 'V')) { |
| 219 // Legal characters in a VMS file/dir spec are [A-Z0-9$.-_~]. |
| 220 // '$' cannot begin a filename and `-' cannot be used as the first |
| 221 // or last character. '.' is only valid as a directory separator |
| 222 // and <file>.<type> separator. A canonical filename spec might look |
| 223 // like this: DISK$VOL:[DIR1.DIR2.DIR3]FILE.TYPE;123 |
| 224 // All VMS FTP servers LIST in uppercase. |
| 225 // We need to be picky about this in order to support |
| 226 // multi-line listings correctly. |
| 227 if ((!state->parsed_one && |
| 228 numtoks == 1) || (numtoks == 2 && toklen[0] == 9 && |
| 229 memcmp(tokens[0], "Directory", 9) == 0)) { |
| 230 // If no dirstyle has been detected yet, and this line is a |
| 231 // VMS list's dirname, then turn on VMS dirstyle. |
| 232 // eg "ACA:[ANONYMOUS]", "DISK$FTP:[ANONYMOUS]", "SYS$ANONFTP:" |
| 233 p = tokens[0]; |
| 234 pos = toklen[0]; |
| 235 if (numtoks == 2) { |
| 236 p = tokens[1]; |
| 237 pos = toklen[1]; |
| 238 } |
| 239 pos--; |
| 240 if (pos >= 3) { |
| 241 while (pos > 0 && p[pos] != '[') { |
| 242 pos--; |
| 243 if (p[pos] == '-' || p[pos] == '$') { |
| 244 if (pos == 0 || p[pos-1] == '[' || p[pos-1] == '.' || |
| 245 (p[pos] == '-' && (p[pos+1] == ']' || p[pos+1] == '.'))) |
| 246 break; |
| 247 } else if (p[pos] != '.' && p[pos] != '~' && |
| 248 !isdigit(p[pos]) && !isalpha(p[pos])) { |
| 249 break; |
| 250 } else if (isalpha(p[pos]) && p[pos] != toupper(p[pos])) { |
| 251 break; |
| 252 } |
| 253 } |
| 254 if (pos > 0) { |
| 255 pos--; |
| 256 if (p[pos] != ':' || p[pos+1] != '[') |
| 257 pos = 0; |
| 258 } |
| 259 } |
| 260 if (pos > 0 && p[pos] == ':') { |
| 261 while (pos > 0) { |
| 262 pos--; |
| 263 if (p[pos] != '$' && p[pos] != '_' && p[pos] != '-' && |
| 264 p[pos] != '~' && !isdigit(p[pos]) && !isalpha(p[pos])) |
| 265 break; |
| 266 else if (isalpha(p[pos]) && p[pos] != toupper(p[pos])) |
| 267 break; |
| 268 } |
| 269 if (pos == 0) { |
| 270 state->lstyle = 'V'; |
| 271 return FTP_TYPE_JUNK; // Its junk. |
| 272 } |
| 273 } |
| 274 // fallthrough |
| 275 } else if ((tokens[0][toklen[0]-1]) != ';') { |
| 276 if (numtoks == 1 && (state->lstyle == 'V' && !carry_buf_len)) |
| 277 lstyle = 'V'; |
| 278 else if (numtoks < 4); |
| 279 else if (toklen[1] >= 10 && memcmp(tokens[1], "%RMS-E-PRV", 10) == 0) |
| 280 lstyle = 'V'; |
| 281 else if ((&line[linelen] - tokens[1]) >= 22 && |
| 282 memcmp(tokens[1], "insufficient privilege", 22) == 0) |
| 283 lstyle = 'V'; |
| 284 else if (numtoks != 4 && numtoks != 6) { |
| 285 } else if (numtoks == 6 && ( |
| 286 toklen[5] < 4 || *tokens[5] != '(' || |
| 287 (tokens[5][toklen[5]-1]) != ')')) { |
| 288 } else if ((toklen[2] == 10 || toklen[2] == 11) && |
| 289 (tokens[2][toklen[2]-5]) == '-' && |
| 290 (tokens[2][toklen[2]-9]) == '-' && |
| 291 (((toklen[3] == 4 || toklen[3] == 5 || toklen[3] == 7 || |
| 292 toklen[3] == 8) && |
| 293 (tokens[3][toklen[3]-3]) == ':') || |
| 294 ((toklen[3] == 10 || toklen[3] == 11) && |
| 295 (tokens[3][toklen[3]-3]) == '.')) && |
| 296 // Time in [H]H:MM[:SS[.CC]] format. |
| 297 isdigit(*tokens[1]) && // size |
| 298 isdigit(*tokens[2]) && // date |
| 299 isdigit(*tokens[3]) // time |
| 300 ) { |
| 301 lstyle = 'V'; |
| 302 } |
| 303 if (lstyle == 'V') { |
| 304 // MultiNet FTP: |
| 305 // LOGIN.COM;2 1 4-NOV-1994 04:09 [ANONYMOUS] (RWE,RWE,,) |
| 306 // PUB.DIR;1 1 27-JAN-1994 14:46 [ANONYMOUS] (RWE,RWE,RE,RWE) |
| 307 // README.FTP;1 %RMS-E-PRV, insufficient privilege or file |
| 308 // protection violation |
| 309 // ROUSSOS.DIR;1 1 27-JAN-1994 14:48 [CS,ROUSSOS] (RWE,RWE,RE,R) |
| 310 // S67-50903.JPG;1 328 22-SEP-1998 16:19 [ANONYMOUS] (RWED,RWED,,) |
| 311 // UCX FTP: |
| 312 // CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12[ANONYMOU,ANONYMOUS] |
| 313 // (RWED,RWED,,) |
| 314 // CMU/VMS-IP FTP |
| 315 // [VMSSERV.FILES]ALARM.DIR;1 1/3 5-MAR-1993 18:09 |
| 316 // TCPware FTP |
| 317 // FOO.BAR;1 4 5-MAR-1993 18:09:01.12 |
| 318 // Long filename example: |
| 319 // THIS-IS-A-LONG-VMS-FILENAME.AND-THIS-IS-A-LONG-VMS-FILETYPE\r\n |
| 320 // 213[/nnn] 29-JAN-1996 03:33[:nn] [ANONYMOU,ANONYMOUS] (RWED,RWED,
,) |
| 321 tokmarker = 0; |
| 322 p = tokens[0]; |
| 323 pos = 0; |
| 324 if (*p == '[' && toklen[0] >= 4) { |
| 325 if (p[1] != ']') { |
| 326 p++; |
| 327 pos++; |
| 328 } |
| 329 while (lstyle && pos < toklen[0] && *p != ']') { |
| 330 if (*p != '$' && *p != '.' && *p != '_' && *p != '-' && |
| 331 *p != '~' && !isdigit(*p) && !isalpha(*p)) |
| 332 lstyle = 0; |
| 333 pos++; |
| 334 p++; |
| 335 } |
| 336 if (lstyle && pos < (toklen[0]-1) && *p == ']') { |
| 337 pos++; |
| 338 p++; |
| 339 tokmarker = pos; // length of leading "[DIR1.DIR2.etc]" |
| 340 } |
| 341 } |
| 342 while (lstyle && pos < toklen[0] && *p != ';') { |
| 343 if (*p != '$' && *p != '.' && *p != '_' && *p != '-' && |
| 344 *p != '~' && !isdigit(*p) && !isalpha(*p)) |
| 345 lstyle = 0; |
| 346 else if (isalpha(*p) && *p != toupper(*p)) |
| 347 lstyle = 0; |
| 348 p++; |
| 349 pos++; |
| 350 } |
| 351 if (lstyle && *p == ';') { |
| 352 if (pos == 0 || pos == (toklen[0]-1)) |
| 353 lstyle = 0; |
| 354 for (pos++;lstyle && pos < toklen[0];pos++) { |
| 355 if (!isdigit(tokens[0][pos])) |
| 356 lstyle = 0; |
| 357 } |
| 358 } |
| 359 pos = (p - tokens[0]); // => fnlength sans ";####" |
| 360 pos -= tokmarker; // => fnlength sans "[DIR1.DIR2.etc]" |
| 361 p = &(tokens[0][tokmarker]); // offset of basename. |
| 362 |
| 363 if (!lstyle || pos > 80) { |
| 364 // VMS filenames can't be longer than that. |
| 365 lstyle = 0; |
| 366 } else if (numtoks == 1) { |
| 367 // If VMS has been detected and there is only one token and |
| 368 // that token was a VMS filename then this is a multiline |
| 369 // VMS LIST entry. |
| 370 if (pos >= (sizeof(state->carry_buf) - 1)) |
| 371 pos = (sizeof(state->carry_buf) - 1); // Shouldn't happen. |
| 372 memcpy(state->carry_buf, p, pos); |
| 373 state->carry_buf_len = pos; |
| 374 return FTP_TYPE_JUNK; // Tell caller to treat as junk. |
| 375 } else if (isdigit(*tokens[1])) { // not no-privs message. |
| 376 for (pos = 0; lstyle && pos < (toklen[1]); pos++) { |
| 377 if (!isdigit((tokens[1][pos])) && (tokens[1][pos]) != '/') |
| 378 lstyle = 0; |
| 379 } |
| 380 if (lstyle && numtoks > 4) { // Multinet or UCX but not CMU. |
| 381 for (pos = 1; lstyle && pos < (toklen[5]-1); pos++) { |
| 382 p = &(tokens[5][pos]); |
| 383 if (*p != 'R' && *p != 'W' && *p != 'E' && |
| 384 *p != 'D' && *p != ',') |
| 385 lstyle = 0; |
| 386 } |
| 387 } |
| 388 } |
| 389 } // passed initial tests |
| 390 } // else if ((tokens[0][toklen[0]-1]) != ';') |
| 391 |
| 392 if (lstyle == 'V') { |
| 393 state->parsed_one = 1; |
| 394 state->lstyle = lstyle; |
| 395 if (isdigit(*tokens[1])) { // not permission denied etc |
| 396 // strip leading directory name |
| 397 if (*tokens[0] == '[') { // CMU server |
| 398 pos = toklen[0] - 1; |
| 399 p = tokens[0] + 1; |
| 400 while (*p != ']') { |
| 401 p++; |
| 402 pos--; |
| 403 } |
| 404 toklen[0] = --pos; |
| 405 tokens[0] = ++p; |
| 406 } |
| 407 pos = 0; |
| 408 while (pos < toklen[0] && (tokens[0][pos]) != ';') |
| 409 pos++; |
| 410 |
| 411 result->fe_cinfs = 1; |
| 412 result->fe_type = FTP_TYPE_FILE; |
| 413 result->fe_fname = tokens[0]; |
| 414 result->fe_fnlen = pos; |
| 415 |
| 416 if (pos > 4) { |
| 417 p = &(tokens[0][pos-4]); |
| 418 if (p[0] == '.' && p[1] == 'D' && p[2] == 'I' && p[3] == 'R') { |
| 419 result->fe_fnlen -= 4; |
| 420 result->fe_type = FTP_TYPE_DIRECTORY; |
| 421 } |
| 422 } |
| 423 |
| 424 if (result->fe_type != FTP_TYPE_DIRECTORY) { |
| 425 // #### or used/allocated form. If used/allocated form, then |
| 426 // 'used' is the size in bytes if and only if 'used'<=allocated. |
| 427 // If 'used' is size in bytes then it can be > 2^32 |
| 428 // If 'used' is not size in bytes then it is size in blocks. |
| 429 pos = 0; |
| 430 while (pos < toklen[1] && (tokens[1][pos]) != '/') |
| 431 pos++; |
| 432 // size requires multiplication by blocksize. |
| 433 // |
| 434 // We could assume blocksize is 512 (like Lynx does) and |
| 435 // shift by 9, but that might not be right. Even if it |
| 436 // were, doing that wouldn't reflect what the file's |
| 437 // real size was. The sanest thing to do is not use the |
| 438 // LISTing's filesize, so we won't (like ftpmirror). |
| 439 // |
| 440 // ulltoa(((uint64)fsz)<<9, result->fe_size, 10); |
| 441 // |
| 442 // A block is always 512 bytes on OpenVMS, compute size. |
| 443 // So its rounded up to the next block, so what, its better |
| 444 // than not showing the size at all. |
| 445 // A block is always 512 bytes on OpenVMS, compute size. |
| 446 // So its rounded up to the next block, so what, its better |
| 447 // than not showing the size at all. |
| 448 uint64 size = strtoul(tokens[1], NULL, 10) * 512; |
| 449 base::snprintf(result->fe_size, sizeof(result->fe_size), |
| 450 "%lld", size); |
| 451 } // if (result->fe_type != FTP_TYPE_DIRECTORY) |
| 452 |
| 453 p = tokens[2] + 2; |
| 454 if (*p == '-') |
| 455 p++; |
| 456 tbuf[0] = p[0]; |
| 457 tbuf[1] = tolower(p[1]); |
| 458 tbuf[2] = tolower(p[2]); |
| 459 month_num = 0; |
| 460 for (pos = 0; pos < (12*3); pos += 3) { |
| 461 if (tbuf[0] == month_names[pos+0] && |
| 462 tbuf[1] == month_names[pos + 1] && |
| 463 tbuf[2] == month_names[pos + 2]) |
| 464 break; |
| 465 month_num++; |
| 466 } |
| 467 if (month_num >= 12) |
| 468 month_num = 0; |
| 469 result->fe_time.tm_mon = month_num; |
| 470 result->fe_time.tm_mday = StringToInt(tokens[2]); |
| 471 result->fe_time.tm_year = StringToInt(p + 4); |
| 472 // NSPR wants year as XXXX |
| 473 |
| 474 p = tokens[3] + 2; |
| 475 if (*p == ':') |
| 476 p++; |
| 477 if (p[2] == ':') |
| 478 result->fe_time.tm_sec = StringToInt(p + 3); |
| 479 result->fe_time.tm_hour = StringToInt(tokens[3]); |
| 480 result->fe_time.tm_min = StringToInt(p); |
| 481 return result->fe_type; |
| 482 } // if (isdigit(*tokens[1])) |
| 483 return FTP_TYPE_JUNK; // junk |
| 484 } // if (lstyle == 'V') |
| 485 } // if (!lstyle && (!state->lstyle || state->lstyle == 'V')) |
| 486 #endif // SUPPORT_VMS |
| 487 |
| 488 #if defined(SUPPORT_CMS) |
| 489 // Virtual Machine/Conversational Monitor System (IBM Mainframe) |
| 490 if (!lstyle && (!state->lstyle || state->lstyle == 'C')) { // VM/CMS |
| 491 // LISTing according to mirror.pl |
| 492 // Filename FileType Fm Format Lrecl Records Blocks Date Time |
| 493 // LASTING GLOBALV A1 V 41 21 1 9/16/91 15:10:32 |
| 494 // J43401 NETLOG A0 V 77 1 1 9/12/91 12:36:04 |
| 495 // PROFILE EXEC A1 V 17 3 1 9/12/91 12:39:07 |
| 496 // DIRUNIX SCRIPT A1 V 77 1216 17 1/04/93 20:30:47 |
| 497 // MAIL PROFILE A2 F 80 1 1 10/14/92 16:12:27 |
| 498 // BADY2K TEXT A0 V 1 1 1 1/03/102 10:11:12 |
| 499 // AUTHORS A1 DIR - - - 9/20/99 10:31:11 |
| 500 // |
| 501 // LISTing from vm.marist.edu and vm.sc.edu |
| 502 // 220-FTPSERVE IBM VM Level 420 at VM.MARIST.EDU, 04:58:12 EDT WEDNESDAY
2002-07-10 |
| 503 // AUTHORS DIR - - - 1999-09-20 10:31:11 - |
| 504 // HARRINGTON DIR - - - 1997-02-12 15:33:28 - |
| 505 // PICS DIR - - - 2000-10-12 15:43:23 - |
| 506 // SYSFILE DIR - - - 2000-07-20 17:48:01 - |
| 507 // WELCNVT EXEC V 72 9 1 1999-09-20 17:16:18 - |
| 508 // WELCOME EREADME F 80 21 1 1999-12-27 16:19:00 - |
| 509 // WELCOME README V 82 21 1 1999-12-27 16:19:04 - |
| 510 // README ANONYMOU V 71 26 1 1997-04-02 12:33:20 TCP291 |
| 511 // README ANONYOLD V 71 15 1 1995-08-25 16:04:27 TCP291 |
| 512 if (numtoks >= 7 && (toklen[0]+toklen[1]) <= 16) { |
| 513 for (pos = 1; !lstyle && (pos+5) < numtoks; pos++) { |
| 514 p = tokens[pos]; |
| 515 if ((toklen[pos] == 1 && (*p == 'F' || *p == 'V')) || |
| 516 (toklen[pos] == 3 && *p == 'D' && p[1] == 'I' && p[2] == 'R')) { |
| 517 if (toklen[pos+5] == 8 && (tokens[pos+5][2]) == ':' && |
| 518 (tokens[pos+5][5]) == ':') { |
| 519 p = tokens[pos+4]; |
| 520 if ((toklen[pos+4] == 10 && p[4] == '-' && p[7] == '-') || |
| 521 (toklen[pos+4] >= 7 && toklen[pos+4] <= 9 && |
| 522 p[((p[1] != '/')?(2):(1))] == '/' && |
| 523 p[((p[1] != '/')?(5):(4))] == '/')) { |
| 524 // Y2K bugs possible ("7/06/102" or "13/02/101") |
| 525 if ((*tokens[pos+1] == '-' && |
| 526 *tokens[pos+2] == '-' && |
| 527 *tokens[pos+3] == '-') || |
| 528 (isdigit(*tokens[pos+1]) && |
| 529 isdigit(*tokens[pos+2]) && |
| 530 isdigit(*tokens[pos+3]))) { |
| 531 lstyle = 'C'; |
| 532 tokmarker = pos; |
| 533 } // if ((*tokens[pos+1] == '-' && |
| 534 } // if ((toklen[pos+4] == 10 |
| 535 } // toklen[pos+5] == 8 |
| 536 } // if ((toklen[pos] == 1 && (*p == 'F' |
| 537 } // for (pos = 1; !lstyle && (pos+5) < numtoks; pos++) |
| 538 } // if (numtoks >= 7) |
| 539 // extra checking if first pass |
| 540 if (lstyle && !state->lstyle) { |
| 541 for (pos = 0, p = tokens[0]; lstyle && pos < toklen[0]; pos++, p++) { |
| 542 if (isalpha(*p) && toupper(*p) != *p) |
| 543 lstyle = 0; |
| 544 } |
| 545 for (pos = tokmarker+1; pos <= tokmarker+3; pos++) { |
| 546 if (!(toklen[pos] == 1 && *tokens[pos] == '-')) { |
| 547 for (p = tokens[pos]; lstyle && p < (tokens[pos] + toklen[pos]); |
| 548 p++) { |
| 549 if (!isdigit(*p)) |
| 550 lstyle = 0; |
| 551 } // for (p = tokens[pos]; lstyle |
| 552 } // if (!(toklen[pos] == 1 |
| 553 } // for (pos = tokmarker+1; |
| 554 for (pos = 0, p = tokens[tokmarker+4]; |
| 555 lstyle && pos < toklen[tokmarker+4]; pos++, p++) { |
| 556 if (*p == '/') { |
| 557 // There may be Y2K bugs in the date. Don't simplify to |
| 558 // pos != (len-3) && pos != (len-6) like time is done. |
| 559 if ((tokens[tokmarker + 4][1]) == '/') { |
| 560 if (pos != 1 && pos != 4) |
| 561 lstyle = 0; |
| 562 } else if (pos != 2 && pos != 5) { |
| 563 lstyle = 0; |
| 564 } |
| 565 } else if (*p != '-' && !isdigit(*p)) { |
| 566 lstyle = 0; |
| 567 } else if (*p == '-' && pos != 4 && pos != 7) { |
| 568 lstyle = 0; |
| 569 } |
| 570 } |
| 571 for (pos = 0, p = tokens[tokmarker+5]; |
| 572 lstyle && pos < toklen[tokmarker+5]; pos++, p++) { |
| 573 if (*p != ':' && !isdigit(*p)) |
| 574 lstyle = 0; |
| 575 else if (*p == ':' && pos != (toklen[tokmarker+5]-3) |
| 576 && pos != (toklen[tokmarker+5]-6)) |
| 577 lstyle = 0; |
| 578 } |
| 579 } // if (lstyle && !state->lstyle) |
| 580 |
| 581 if (lstyle == 'C') { |
| 582 state->parsed_one = 1; |
| 583 state->lstyle = lstyle; |
| 584 |
| 585 p = tokens[tokmarker+4]; |
| 586 if (toklen[tokmarker+4] == 10) { // newstyle: YYYY-MM-DD format |
| 587 result->fe_time.tm_year = StringToInt(p + 0) - 1900; |
| 588 result->fe_time.tm_mon = StringToInt(p + 5) - 1; |
| 589 result->fe_time.tm_mday = StringToInt(p + 8); |
| 590 } else { // oldstyle: [M]M/DD/YY format |
| 591 pos = toklen[tokmarker + 4]; |
| 592 result->fe_time.tm_mon = StringToInt(p) - 1; |
| 593 result->fe_time.tm_mday = StringToInt((p + pos)-5); |
| 594 result->fe_time.tm_year = StringToInt((p + pos)-2); |
| 595 if (result->fe_time.tm_year < 70) |
| 596 result->fe_time.tm_year += 100; |
| 597 } |
| 598 p = tokens[tokmarker + 5]; |
| 599 pos = toklen[tokmarker + 5]; |
| 600 result->fe_time.tm_hour = StringToInt(p); |
| 601 result->fe_time.tm_min = StringToInt((p + pos) - 5); |
| 602 result->fe_time.tm_sec = StringToInt((p + pos) - 2); |
| 603 |
| 604 result->fe_cinfs = 1; |
| 605 result->fe_fname = tokens[0]; |
| 606 result->fe_fnlen = toklen[0]; |
| 607 result->fe_type = FTP_TYPE_FILE; |
| 608 |
| 609 p = tokens[tokmarker]; |
| 610 if (toklen[tokmarker] == 3 && *p == 'D' && p[1] == 'I' && p[2] == 'R') |
| 611 result->fe_type = FTP_TYPE_DIRECTORY; |
| 612 |
| 613 if ((toklen[tokmarker+4] == 10 && tokmarker > 1) || |
| 614 (toklen[tokmarker+4] != 10 && tokmarker > 2)) { |
| 615 // have a filetype column |
| 616 char *dot; |
| 617 p = &(tokens[0][toklen[0]]); |
| 618 memcpy(&dot, &p, sizeof(dot)); // NASTY |
| 619 *dot++ = '.'; |
| 620 p = tokens[1]; |
| 621 for (pos = 0; pos < toklen[1]; pos++) |
| 622 *dot++ = *p++; |
| 623 result->fe_fnlen += 1 + toklen[1]; |
| 624 } |
| 625 // oldstyle LISTING: |
| 626 // files/dirs not on the 'A' minidisk are not RETRievable/CHDIRable |
| 627 // if (toklen[tokmarker+4] != 10 && *tokens[tokmarker-1] != 'A') |
| 628 // return FTP_TYPE_JUNK; |
| 629 |
| 630 // VM/CMS LISTings have no usable filesize field. |
| 631 // Have to use the 'SIZE' command for that. |
| 632 return result->fe_type; |
| 633 } // if (lstyle == 'C' && (!state->lstyle || state->lstyle == lstyle)) |
| 634 } // VM/CMS |
| 635 #endif // SUPPORT_CMS |
| 636 |
| 637 #if defined(SUPPORT_DOS) // WinNT DOS dirstyle |
| 638 if (!lstyle && (!state->lstyle || state->lstyle == 'W')) { |
| 639 // "10-23-00 01:27PM <DIR> veronist" |
| 640 // "06-15-00 07:37AM <DIR> zoe" |
| 641 // "07-14-00 01:35PM 2094926 canprankdesk.tif" |
| 642 // "07-21-00 01:19PM 95077 Jon Kauffman Enjoys the Good Life.jpg" |
| 643 // "07-21-00 01:19PM 52275 Name Plate.jpg" |
| 644 // "07-14-00 01:38PM 2250540 Valentineoffprank-HiRes.jpg" |
| 645 if ((numtoks >= 4) && toklen[0] == 8 && toklen[1] == 7 && |
| 646 (*tokens[2] == '<' || isdigit(*tokens[2]))) { |
| 647 p = tokens[0]; |
| 648 if (isdigit(p[0]) && isdigit(p[1]) && p[2] == '-' && |
| 649 isdigit(p[3]) && isdigit(p[4]) && p[5] == '-' && |
| 650 isdigit(p[6]) && isdigit(p[7])) { |
| 651 p = tokens[1]; |
| 652 if (isdigit(p[0]) && isdigit(p[1]) && p[2] == ':' && |
| 653 isdigit(p[3]) && isdigit(p[4]) && |
| 654 (p[5] == 'A' || p[5] == 'P') && p[6] == 'M') { |
| 655 lstyle = 'W'; |
| 656 if (!state->lstyle) { |
| 657 p = tokens[2]; |
| 658 // <DIR> or <JUNCTION> |
| 659 if (*p != '<' || p[toklen[2] - 1] != '>') { |
| 660 for (pos = 1; (lstyle && pos < toklen[2]); pos++) { |
| 661 if (!isdigit(*++p)) |
| 662 lstyle = 0; |
| 663 } |
| 664 } |
| 665 } |
| 666 } |
| 667 } |
| 668 } |
| 669 if (lstyle == 'W') { |
| 670 state->parsed_one = 1; |
| 671 state->lstyle = lstyle; |
| 672 |
| 673 p = &(line[linelen_sans_wsp]); // line end sans wsp |
| 674 result->fe_cinfs = 1; |
| 675 result->fe_fname = tokens[3]; |
| 676 result->fe_fnlen = p - tokens[3]; |
| 677 result->fe_type = FTP_TYPE_DIRECTORY; |
| 678 |
| 679 if (*tokens[2] != '<') { // not <DIR> or <JUNCTION> |
| 680 result->fe_type = FTP_TYPE_FILE; |
| 681 pos = toklen[2]; |
| 682 while (pos > (sizeof(result->fe_size) - 1)) |
| 683 pos = (sizeof(result->fe_size) - 1); |
| 684 memcpy(result->fe_size, tokens[2], pos); |
| 685 result->fe_size[pos] = '\0'; |
| 686 } else if ((tokens[2][1]) != 'D') { // not <DIR> |
| 687 result->fe_type = FTP_TYPE_JUNK; // unknown until junc for sure |
| 688 if (result->fe_fnlen > 4) { |
| 689 p = result->fe_fname; |
| 690 for (pos = result->fe_fnlen - 4; pos > 0; pos--) { |
| 691 if (p[0] == ' ' && p[3] == ' ' && p[2] == '>' && |
| 692 (p[1] == '=' || p[1] == '-')) { |
| 693 result->fe_type = FTP_TYPE_SYMLINK; |
| 694 result->fe_fnlen = p - result->fe_fname; |
| 695 result->fe_lname = p + 4; |
| 696 result->fe_lnlen = &(line[linelen_sans_wsp]) |
| 697 - result->fe_lname; |
| 698 break; |
| 699 } |
| 700 p++; |
| 701 } |
| 702 } |
| 703 } |
| 704 |
| 705 result->fe_time.tm_mon = StringToInt(tokens[0]+0); |
| 706 if (result->fe_time.tm_mon != 0) { |
| 707 result->fe_time.tm_mon--; |
| 708 result->fe_time.tm_mday = StringToInt(tokens[0]+3); |
| 709 result->fe_time.tm_year = StringToInt(tokens[0]+6); |
| 710 if (result->fe_time.tm_year < 80) |
| 711 result->fe_time.tm_year += 100; |
| 712 } |
| 713 |
| 714 result->fe_time.tm_hour = StringToInt(tokens[1]+0); |
| 715 result->fe_time.tm_min = StringToInt(tokens[1]+3); |
| 716 if ((tokens[1][5]) == 'P' && result->fe_time.tm_hour < 12) |
| 717 result->fe_time.tm_hour += 12; |
| 718 |
| 719 // the caller should do this (if dropping "." and ".." is desired) |
| 720 // if (result->fe_type == FTP_TYPE_DIRECTORY && result->fe_fname[0] |
| 721 // == '.' && |
| 722 // (result->fe_fnlen == 1 || (result->fe_fnlen == 2 && |
| 723 // result->fe_fname[1] == '.'))) |
| 724 // return FTP_TYPE_JUNK; |
| 725 |
| 726 return result->fe_type; |
| 727 } // if (lstyle == 'W' && (!state->lstyle || state->lstyle == lstyle)) |
| 728 } // if (!lstyle && (!state->lstyle || state->lstyle == 'W')) |
| 729 #endif |
| 730 |
| 731 #if defined(SUPPORT_OS2) |
| 732 if (!lstyle && (!state->lstyle || state->lstyle == 'O')) { // OS/2 test |
| 733 // 220 server IBM TCP/IP for OS/2 - FTP Server ver 23:04:36 on |
| 734 // Jan 15 1997 ready. |
| 735 // fixed position, space padded columns. I have only a vague idea |
| 736 // of what the contents between col 18 and 34 might be: All I can infer |
| 737 // is that there may be attribute flags in there and there may be |
| 738 // a " DIR" in there. |
| 739 // |
| 740 // 1 2 3 4 5 6 |
| 741 // 0123456789012345678901234567890123456789012345678901234567890123456789 |
| 742 // ----- size -------|??????????????? MM-DD-YY| HH:MM| nnnnnnnnn.... |
| 743 // 0 DIR 04-11-95 16:26 . |
| 744 // 0 DIR 04-11-95 16:26 .. |
| 745 // 0 DIR 04-11-95 16:26 ADDRESS |
| 746 // 612 RHSA 07-28-95 16:45 air_tra1.bag |
| 747 // 195 A 08-09-95 10:23 Alfa1.bag |
| 748 // 0 RHS DIR 04-11-95 16:26 ATTACH |
| 749 // 372 A 08-09-95 10:26 Aussie_1.bag |
| 750 // 310992 06-28-94 09:56 INSTALL.EXE |
| 751 // 1 2 3 4 |
| 752 // 01234567890123456789012345678901234567890123456789 |
| 753 // dirlist from the mirror.pl project, col positions from Mozilla. |
| 754 |
| 755 p = &(line[toklen[0]]); |
| 756 // \s(\d\d-\d\d-\d\d)\s+(\d\d:\d\d)\s |
| 757 if (numtoks >= 4 && toklen[0] <= 18 && isdigit(*tokens[0]) && |
| 758 (linelen - toklen[0]) >= (53-18) && |
| 759 p[18-18] == ' ' && p[34-18] == ' ' && |
| 760 p[37-18] == '-' && p[40-18] == '-' && p[43-18] == ' ' && |
| 761 p[45-18] == ' ' && p[48-18] == ':' && p[51-18] == ' ' && |
| 762 isdigit(p[35-18]) && isdigit(p[36-18]) && |
| 763 isdigit(p[38-18]) && isdigit(p[39-18]) && |
| 764 isdigit(p[41-18]) && isdigit(p[42-18]) && |
| 765 isdigit(p[46-18]) && isdigit(p[47-18]) && |
| 766 isdigit(p[49-18]) && isdigit(p[50-18])) { |
| 767 lstyle = 'O'; // OS/2 |
| 768 if (!state->lstyle) { |
| 769 for (pos = 1; lstyle && pos < toklen[0]; pos++) { |
| 770 if (!isdigit(tokens[0][pos])) |
| 771 lstyle = 0; |
| 772 } |
| 773 } |
| 774 } |
| 775 |
| 776 if (lstyle == 'O') { |
| 777 state->parsed_one = 1; |
| 778 state->lstyle = lstyle; |
| 779 |
| 780 p = &(line[toklen[0]]); |
| 781 |
| 782 result->fe_cinfs = 1; |
| 783 result->fe_fname = &p[53-18]; |
| 784 result->fe_fnlen = (&(line[linelen_sans_wsp])) |
| 785 - (result->fe_fname); |
| 786 result->fe_type = FTP_TYPE_FILE; |
| 787 |
| 788 // I don't have a real listing to determine exact pos, so scan. |
| 789 for (pos = (18-18); pos < ((35-18)-4); pos++) { |
| 790 if (p[pos+0] == ' ' && p[pos+1] == 'D' && |
| 791 p[pos+2] == 'I' && p[pos+3] == 'R') { |
| 792 result->fe_type = FTP_TYPE_DIRECTORY; |
| 793 break; |
| 794 } |
| 795 } |
| 796 |
| 797 if (result->fe_type != FTP_TYPE_DIRECTORY) { |
| 798 pos = toklen[0]; |
| 799 if (pos > (sizeof(result->fe_size)-1)) |
| 800 pos = (sizeof(result->fe_size)-1); |
| 801 memcpy(result->fe_size, tokens[0], pos); |
| 802 result->fe_size[pos] = '\0'; |
| 803 } |
| 804 |
| 805 result->fe_time.tm_mon = StringToInt(&p[35-18]) - 1; |
| 806 result->fe_time.tm_mday = StringToInt(&p[38-18]); |
| 807 result->fe_time.tm_year = StringToInt(&p[41-18]); |
| 808 if (result->fe_time.tm_year < 80) |
| 809 result->fe_time.tm_year += 100; |
| 810 result->fe_time.tm_hour = StringToInt(&p[46-18]); |
| 811 result->fe_time.tm_min = StringToInt(&p[49-18]); |
| 812 |
| 813 // The caller should do this (if dropping "." and ".." is desired) |
| 814 // if (result->fe_type == FTP_TYPE_DIRECTORY && |
| 815 // result->fe_fname[0] == '.' && (result->fe_fnlen == 1 || |
| 816 // (result->fe_fnlen == 2 && result->fe_fname[1] == '.'))) |
| 817 // return FTP_TYPE_JUNK; |
| 818 |
| 819 return result->fe_type; |
| 820 } // if (lstyle == 'O') |
| 821 } // if (!lstyle && (!state->lstyle || state->lstyle == 'O')) |
| 822 #endif // SUPPORT_OS2 |
| 823 |
| 824 #if defined(SUPPORT_LSL) |
| 825 if (!lstyle && (!state->lstyle || state->lstyle == 'U')) { // /bin/ls & co. |
| 826 // UNIX-style listing, without inum and without blocks |
| 827 // "-rw-r--r-- 1 root other 531 Jan 29 03:26 README" |
| 828 // "dr-xr-xr-x 2 root other 512 Apr 8 1994 etc" |
| 829 // "dr-xr-xr-x 2 root 512 Apr 8 1994 etc" |
| 830 // "lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin" |
| 831 // Also produced by Microsoft's FTP servers for Windows: |
| 832 // "---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z" |
| 833 // "d--------- 1 owner group 0 May 9 19:45 Softlib" |
| 834 // Also WFTPD for MSDOS: |
| 835 // "-rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp" |
| 836 // Hellsoft for NetWare: |
| 837 // "d[RWCEMFA] supervisor 512 Jan 16 18:53 login" |
| 838 // "-[RWCEMFA] rhesus 214059 Oct 20 15:27 cx.exe" |
| 839 // Newer Hellsoft for NetWare: (netlab2.usu.edu) |
| 840 // - [RWCEAFMS] NFAUUser 192 Apr 27 15:21 HEADER.html |
| 841 // d [RWCEAFMS] jrd 512 Jul 11 03:01 allupdates |
| 842 // Also NetPresenz for the Mac: |
| 843 // "-------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit" |
| 844 // "drwxrwxr-x folder 2 May 10 1996 network" |
| 845 // Protected directory: |
| 846 // "drwx-wx-wt 2 root wheel 512 Jul 1 02:15 incoming" |
| 847 // uid/gid instead of username/groupname: |
| 848 // "drwxr-xr-x 2 0 0 512 May 28 22:17 etc" |
| 849 |
| 850 if (numtoks >= 6) { |
| 851 // there are two perm formats (Hellsoft/NetWare and *IX strmode(3)). |
| 852 // Scan for size column only if the perm format is one or the other. |
| 853 if (toklen[0] == 1 || (tokens[0][1]) == '[') { |
| 854 if (*tokens[0] == FTP_TYPE_DIRECTORY || *tokens[0] == '-') { |
| 855 pos = toklen[0]-1; |
| 856 p = tokens[0] + 1; |
| 857 if (pos == 0) { |
| 858 p = tokens[1]; |
| 859 pos = toklen[1]; |
| 860 } |
| 861 if ((pos == 9 || pos == 10) && |
| 862 (*p == '[' && p[pos-1] == ']') && |
| 863 (p[1] == 'R' || p[1] == '-') && |
| 864 (p[2] == 'W' || p[2] == '-') && |
| 865 (p[3] == 'C' || p[3] == '-') && |
| 866 (p[4] == 'E' || p[4] == '-')) { |
| 867 // rest is FMA[S] or AFM[S] |
| 868 lstyle = 'U'; // very likely one of the NetWare servers |
| 869 } |
| 870 } |
| 871 } else if ((toklen[0] == 10 || toklen[0] == 11) && |
| 872 strchr("-bcdlpsw?DFam", *tokens[0])) { |
| 873 p = &(tokens[0][1]); |
| 874 if ((p[0] == 'r' || p[0] == '-') && |
| 875 (p[1] == 'w' || p[1] == '-') && |
| 876 (p[3] == 'r' || p[3] == '-') && |
| 877 (p[4] == 'w' || p[4] == '-') && |
| 878 (p[6] == 'r' || p[6] == '-') && |
| 879 (p[7] == 'w' || p[7] == '-')) { |
| 880 // 'x'/p[9] can be S|s|x|-|T|t or implementation specific |
| 881 lstyle = 'U'; // very likely /bin/ls |
| 882 } |
| 883 } |
| 884 } |
| 885 if (lstyle == 'U') { // first token checks out |
| 886 lstyle = 0; |
| 887 for (pos = (numtoks-5); !lstyle && pos > 1; pos--) { |
| 888 // scan for: (\d+)\s+([A-Z][a-z][a-z])\s+ |
| 889 // (\d\d\d\d|\d\:\d\d|\d\d\:\d\d|\d\:\d\d\:\d\d|\d\d\:\d\d\:\d\d) |
| 890 // \s+(.+)$ |
| 891 if (isdigit(*tokens[pos]) // size |
| 892 // (\w\w\w) |
| 893 && toklen[pos+1] == 3 && isalpha(*tokens[pos+1]) && |
| 894 isalpha(tokens[pos+1][1]) && isalpha(tokens[pos+1][2]) |
| 895 // (\d|\d\d) |
| 896 && isdigit(*tokens[pos+2]) && |
| 897 (toklen[pos+2] == 1 || |
| 898 (toklen[pos+2] == 2 && isdigit(tokens[pos+2][1]))) |
| 899 && toklen[pos+3] >= 4 && isdigit(*tokens[pos+3]) |
| 900 // (\d\:\d\d\:\d\d|\d\d\:\d\d\:\d\d) |
| 901 && (toklen[pos+3] <= 5 || ( |
| 902 (toklen[pos+3] == 7 || toklen[pos+3] == 8) && |
| 903 (tokens[pos+3][toklen[pos+3]-3]) == ':')) |
| 904 && isdigit(tokens[pos+3][toklen[pos+3]-2]) |
| 905 && isdigit(tokens[pos+3][toklen[pos+3]-1]) |
| 906 && ( |
| 907 // (\d\d\d\d) |
| 908 ((toklen[pos+3] == 4 || toklen[pos+3] == 5) && |
| 909 isdigit(tokens[pos+3][1]) && |
| 910 isdigit(tokens[pos+3][2]) ) |
| 911 // (\d\:\d\d|\d\:\d\d\:\d\d) |
| 912 || ((toklen[pos+3] == 4 || toklen[pos+3] == 7) && |
| 913 (tokens[pos+3][1]) == ':' && |
| 914 isdigit(tokens[pos+3][2]) && isdigit(tokens[pos+3][3])) |
| 915 // (\d\d\:\d\d|\d\d\:\d\d\:\d\d) |
| 916 || ((toklen[pos+3] == 5 || toklen[pos+3] == 8) && |
| 917 isdigit(tokens[pos+3][1]) && (tokens[pos+3][2]) == ':' && |
| 918 isdigit(tokens[pos+3][3]) && isdigit(tokens[pos+3][4])))) { |
| 919 lstyle = 'U'; // assume /bin/ls or variant format |
| 920 tokmarker = pos; |
| 921 // check that size is numeric |
| 922 p = tokens[tokmarker]; |
| 923 unsigned int i; |
| 924 for (i = 0; i < toklen[tokmarker]; i++) { |
| 925 if (!isdigit(*p++)) { |
| 926 lstyle = 0; |
| 927 break; |
| 928 } |
| 929 } |
| 930 if (lstyle) { |
| 931 month_num = 0; |
| 932 p = tokens[tokmarker+1]; |
| 933 for (i = 0; i < (12*3); i+=3) { |
| 934 if (p[0] == month_names[i+0] && |
| 935 p[1] == month_names[i+1] && |
| 936 p[2] == month_names[i+2]) |
| 937 break; |
| 938 month_num++; |
| 939 } |
| 940 if (month_num >= 12) |
| 941 lstyle = 0; |
| 942 } |
| 943 } // relative position test |
| 944 } // for (pos = (numtoks-5); !lstyle && pos > 1; pos--) |
| 945 } // if (lstyle == 'U') |
| 946 |
| 947 if (lstyle == 'U') { |
| 948 state->parsed_one = 1; |
| 949 state->lstyle = lstyle; |
| 950 |
| 951 result->fe_cinfs = 0; |
| 952 result->fe_type = FTP_TYPE_JUNK; |
| 953 if (*tokens[0] == 'd' || *tokens[0] == 'D') |
| 954 result->fe_type = FTP_TYPE_DIRECTORY; |
| 955 else if (*tokens[0] == 'l') |
| 956 result->fe_type = FTP_TYPE_SYMLINK; |
| 957 else if (*tokens[0] == '-' || *tokens[0] == 'F') |
| 958 result->fe_type = FTP_TYPE_FILE; // (hopefully a regular file) |
| 959 |
| 960 if (result->fe_type != FTP_TYPE_DIRECTORY) { |
| 961 pos = toklen[tokmarker]; |
| 962 if (pos > (sizeof(result->fe_size)-1)) |
| 963 pos = (sizeof(result->fe_size)-1); |
| 964 memcpy(result->fe_size, tokens[tokmarker], pos); |
| 965 result->fe_size[pos] = '\0'; |
| 966 } |
| 967 |
| 968 result->fe_time.tm_mon = month_num; |
| 969 result->fe_time.tm_mday = StringToInt(tokens[tokmarker+2]); |
| 970 if (result->fe_time.tm_mday == 0) |
| 971 result->fe_time.tm_mday++; |
| 972 |
| 973 p = tokens[tokmarker+3]; |
| 974 pos = (unsigned int)StringToInt(p); |
| 975 if (p[1] == ':') // one digit hour |
| 976 p--; |
| 977 if (p[2] != ':') { // year |
| 978 result->fe_time.tm_year = pos; |
| 979 } else { |
| 980 result->fe_time.tm_hour = pos; |
| 981 result->fe_time.tm_min = StringToInt(p+3); |
| 982 if (p[5] == ':') |
| 983 result->fe_time.tm_sec = StringToInt(p+6); |
| 984 |
| 985 if (!state->now_time) { |
| 986 time_t now = time(NULL); |
| 987 state->now_time = now * 1000000; |
| 988 gmtime_r(&now, &state->now_tm); |
| 989 } |
| 990 |
| 991 result->fe_time.tm_year = state->now_tm.tm_year; |
| 992 if ( (( state->now_tm.tm_mon << 5) + state->now_tm.tm_mday) < |
| 993 ((result->fe_time.tm_mon << 5) + result->fe_time.tm_mday) ) |
| 994 result->fe_time.tm_year--; |
| 995 } // time/year |
| 996 |
| 997 result->fe_fname = tokens[tokmarker+4]; |
| 998 result->fe_fnlen = (&(line[linelen_sans_wsp])) |
| 999 - (result->fe_fname); |
| 1000 |
| 1001 if (result->fe_type == FTP_TYPE_SYMLINK && result->fe_fnlen > 4) { |
| 1002 p = result->fe_fname + 1; |
| 1003 for (pos = 1; pos < (result->fe_fnlen - 4); pos++) { |
| 1004 if (*p == ' ' && p[1] == '-' && p[2] == '>' && p[3] == ' ') { |
| 1005 result->fe_lname = p + 4; |
| 1006 result->fe_lnlen = (&(line[linelen_sans_wsp])) |
| 1007 - (result->fe_lname); |
| 1008 result->fe_fnlen = pos; |
| 1009 break; |
| 1010 } |
| 1011 p++; |
| 1012 } |
| 1013 } |
| 1014 |
| 1015 #if defined(SUPPORT_LSLF) // some (very rare) servers return ls -lF |
| 1016 if (result->fe_fnlen > 1) { |
| 1017 p = result->fe_fname[result->fe_fnlen-1]; |
| 1018 pos = result->fe_type; |
| 1019 if (pos == FTP_TYPE_DIRECTORY) { |
| 1020 if (*p == '/') result->fe_fnlen--; // directory |
| 1021 } else if (pos == FTP_TYPE_SYMLINK) { |
| 1022 if (*p == '@') result->fe_fnlen--; // symlink |
| 1023 } else if (pos == FTP_TYPE_FILE) { |
| 1024 if (*p == '*') result->fe_fnlen--; // executable |
| 1025 } else if (*p == '=' || *p == '%' || *p == '|') { |
| 1026 result->fe_fnlen--; // socket, whiteout, fifo |
| 1027 } |
| 1028 } |
| 1029 #endif // SUPPORT_LSLF |
| 1030 // the caller should do this (if dropping "." and ".." is desired) |
| 1031 // if (result->fe_type == FTP_TYPE_DIRECTORY && |
| 1032 // result->fe_fname[0] == '.' && (result->fe_fnlen == 1 || |
| 1033 // (result->fe_fnlen == 2 && result->fe_fname[1] == '.'))) |
| 1034 // return FTP_TYPE_JUNK; |
| 1035 return result->fe_type; |
| 1036 } // if (lstyle == 'U') |
| 1037 } // if (!lstyle && (!state->lstyle || state->lstyle == 'U')) |
| 1038 #endif // SUPPORT_LSL |
| 1039 |
| 1040 #if defined(SUPPORT_W16) // 16bit Windows |
| 1041 // old SuperTCP suite FTP server for Win3.1 |
| 1042 if (!lstyle && (!state->lstyle || state->lstyle == 'w')) { |
| 1043 // old NetManage Chameleon TCP/IP suite FTP server for Win3.1 |
| 1044 // SuperTCP dirlist from the mirror.pl project |
| 1045 // mon/day/year separator may be '/' or '-'. |
| 1046 // . <DIR> 11-16-94 17:16 |
| 1047 // .. <DIR> 11-16-94 17:16 |
| 1048 // INSTALL <DIR> 11-16-94 17:17 |
| 1049 // CMT <DIR> 11-21-94 10:17 |
| 1050 // DESIGN1.DOC 11264 05-11-95 14:20 |
| 1051 // README.TXT 1045 05-10-95 11:01 |
| 1052 // WPKIT1.EXE 960338 06-21-95 17:01 |
| 1053 // CMT.CSV 0 07-06-95 14:56 |
| 1054 // |
| 1055 // Chameleon dirlist guessed from lynx |
| 1056 // . <DIR> Nov 16 1994 17:16 |
| 1057 // .. <DIR> Nov 16 1994 17:16 |
| 1058 // INSTALL <DIR> Nov 16 1994 17:17 |
| 1059 // CMT <DIR> Nov 21 1994 10:17 |
| 1060 // DESIGN1.DOC 11264 May 11 1995 14:20 A |
| 1061 // README.TXT 1045 May 10 1995 11:01 |
| 1062 // WPKIT1.EXE 960338 Jun 21 1995 17:01 R |
| 1063 // CMT.CSV 0 Jul 06 1995 14:56 RHA |
| 1064 if (numtoks >= 4 && toklen[0] < 13 && |
| 1065 ((toklen[1] == 5 && *tokens[1] == '<') || isdigit(*tokens[1]))) { |
| 1066 if (numtoks == 4 |
| 1067 && (toklen[2] == 8 || toklen[2] == 9) |
| 1068 && (((tokens[2][2]) == '/' && (tokens[2][5]) == '/') || |
| 1069 ((tokens[2][2]) == '-' && (tokens[2][5]) == '-')) |
| 1070 && (toklen[3] == 4 || toklen[3] == 5) |
| 1071 && (tokens[3][toklen[3]-3]) == ':' |
| 1072 && isdigit(tokens[2][0]) && isdigit(tokens[2][1]) |
| 1073 && isdigit(tokens[2][3]) && isdigit(tokens[2][4]) |
| 1074 && isdigit(tokens[2][6]) && isdigit(tokens[2][7]) |
| 1075 && (toklen[2] < 9 || isdigit(tokens[2][8])) |
| 1076 && isdigit(tokens[3][toklen[3]-1]) |
| 1077 && isdigit(tokens[3][toklen[3]-2]) |
| 1078 && isdigit(tokens[3][toklen[3]-4]) && isdigit(*tokens[3])) { |
| 1079 lstyle = 'w'; |
| 1080 } else if ((numtoks == 6 || numtoks == 7) |
| 1081 && toklen[2] == 3 && toklen[3] == 2 |
| 1082 && toklen[4] == 4 && toklen[5] == 5 |
| 1083 && (tokens[5][2]) == ':' |
| 1084 && isalpha(tokens[2][0]) && isalpha(tokens[2][1]) |
| 1085 && isalpha(tokens[2][2]) |
| 1086 && isdigit(tokens[3][0]) && isdigit(tokens[3][1]) |
| 1087 && isdigit(tokens[4][0]) && isdigit(tokens[4][1]) |
| 1088 && isdigit(tokens[4][2]) && isdigit(tokens[4][3]) |
| 1089 && isdigit(tokens[5][0]) && isdigit(tokens[5][1]) |
| 1090 && isdigit(tokens[5][3]) && isdigit(tokens[5][4])) { |
| 1091 // could also check that (&(tokens[5][5]) - tokens[2]) == 17 |
| 1092 lstyle = 'w'; |
| 1093 } |
| 1094 if (lstyle && state->lstyle != lstyle) { // first time |
| 1095 p = tokens[1]; |
| 1096 if (toklen[1] != 5 || p[0] != '<' || p[1] != 'D' || |
| 1097 p[2] != 'I' || p[3] != 'R' || p[4] != '>') { |
| 1098 for (pos = 0; lstyle && pos < toklen[1]; pos++) { |
| 1099 if (!isdigit(*p++)) |
| 1100 lstyle = 0; |
| 1101 } |
| 1102 } // not <DIR> |
| 1103 } // if (first time) |
| 1104 } // if (numtoks == ...) |
| 1105 |
| 1106 if (lstyle == 'w') { |
| 1107 state->parsed_one = 1; |
| 1108 state->lstyle = lstyle; |
| 1109 |
| 1110 result->fe_cinfs = 1; |
| 1111 result->fe_fname = tokens[0]; |
| 1112 result->fe_fnlen = toklen[0]; |
| 1113 result->fe_type = FTP_TYPE_DIRECTORY; |
| 1114 |
| 1115 p = tokens[1]; |
| 1116 if (isdigit(*p)) { |
| 1117 result->fe_type = FTP_TYPE_FILE; |
| 1118 pos = toklen[1]; |
| 1119 if (pos > (sizeof(result->fe_size) - 1)) |
| 1120 pos = sizeof(result->fe_size) - 1; |
| 1121 memcpy(result->fe_size, p, pos); |
| 1122 result->fe_size[pos] = '\0'; |
| 1123 } |
| 1124 |
| 1125 p = tokens[2]; |
| 1126 if (toklen[2] == 3) { // Chameleon |
| 1127 tbuf[0] = toupper(p[0]); |
| 1128 tbuf[1] = tolower(p[1]); |
| 1129 tbuf[2] = tolower(p[2]); |
| 1130 for (pos = 0; pos < (12*3); pos+=3) { |
| 1131 if (tbuf[0] == month_names[pos+0] && |
| 1132 tbuf[1] == month_names[pos+1] && |
| 1133 tbuf[2] == month_names[pos+2]) { |
| 1134 result->fe_time.tm_mon = pos/3; |
| 1135 result->fe_time.tm_mday = StringToInt(tokens[3]); |
| 1136 result->fe_time.tm_year = StringToInt(tokens[4]) - 1900; |
| 1137 break; |
| 1138 } |
| 1139 } |
| 1140 pos = 5; // Chameleon toknum of date field |
| 1141 } else { |
| 1142 result->fe_time.tm_mon = StringToInt(p+0)-1; |
| 1143 result->fe_time.tm_mday = StringToInt(p+3); |
| 1144 result->fe_time.tm_year = StringToInt(p+6); |
| 1145 if (result->fe_time.tm_year < 80) // SuperTCP |
| 1146 result->fe_time.tm_year += 100; |
| 1147 |
| 1148 pos = 3; // SuperTCP toknum of date field |
| 1149 } |
| 1150 |
| 1151 result->fe_time.tm_hour = StringToInt(tokens[pos]); |
| 1152 result->fe_time.tm_min = StringToInt(&(tokens[pos][toklen[pos]-2])); |
| 1153 |
| 1154 // the caller should do this (if dropping "." and ".." is desired) |
| 1155 // if (result->fe_type == FTP_TYPE_DIRECTORY && |
| 1156 // result->fe_fname[0] == '.' && (result->fe_fnlen == 1 || |
| 1157 // (result->fe_fnlen == 2 && result->fe_fname[1] == '.'))) |
| 1158 // return FTP_TYPE_JUNK; |
| 1159 |
| 1160 return result->fe_type; |
| 1161 } // (lstyle == 'w') |
| 1162 } // if (!lstyle && (!state->lstyle || state->lstyle == 'w')) |
| 1163 #endif // SUPPORT_W16 |
| 1164 |
| 1165 #if defined(SUPPORT_DLS) // dls -dtR |
| 1166 if (!lstyle && |
| 1167 (state->lstyle == 'D' || (!state->lstyle && state->numlines == 1))) { |
| 1168 // /bin/dls lines have to be immediately recognizable (first line) |
| 1169 // I haven't seen an FTP server that delivers a /bin/dls listing, |
| 1170 // but can infer the format from the lynx and mirror.pl projects. |
| 1171 // Both formats are supported. |
| 1172 // |
| 1173 // Lynx says: |
| 1174 // README 763 Information about this server\0 |
| 1175 // bin/ - \0 |
| 1176 // etc/ = \0 |
| 1177 // ls-lR 0 \0 |
| 1178 // ls-lR.Z 3 \0 |
| 1179 // pub/ = Public area\0 |
| 1180 // usr/ - \0 |
| 1181 // morgan 14 -> ../real/morgan\0 |
| 1182 // TIMIT.mostlikely.Z\0 |
| 1183 // 79215 \0 |
| 1184 // |
| 1185 // mirror.pl says: |
| 1186 // filename: ^(\S*)\s+ |
| 1187 // size: (\-|\=|\d+)\s+ |
| 1188 // month/day: ((\w\w\w\s+\d+|\d+\s+\w\w\w)\s+ |
| 1189 // time/year: (\d+:\d+|\d\d\d\d))\s+ |
| 1190 // rest: (.+) |
| 1191 // |
| 1192 // README 763 Jul 11 21:05 Information about this server |
| 1193 // bin/ - Apr 28 1994 |
| 1194 // etc/ = 11 Jul 21:04 |
| 1195 // ls-lR 0 6 Aug 17:14 |
| 1196 // ls-lR.Z 3 05 Sep 1994 |
| 1197 // pub/ = Jul 11 21:04 Public area |
| 1198 // usr/ - Sep 7 09:39 |
| 1199 // morgan 14 Apr 18 09:39 -> ../real/morgan |
| 1200 // TIMIT.mostlikely.Z |
| 1201 // 79215 Jul 11 21:04 |
| 1202 if (!state->lstyle && line[linelen-1] == ':' && |
| 1203 linelen >= 2 && toklen[numtoks-1] != 1) { |
| 1204 // code in mirror.pl suggests that a listing may be preceded |
| 1205 // by a PWD line in the form "/some/dir/names/here:" |
| 1206 // but does not necessarily begin with '/'. *sigh* |
| 1207 pos = 0; |
| 1208 p = line; |
| 1209 while (pos < (linelen-1)) { |
| 1210 // illegal (or extremely unusual) chars in a dirspec |
| 1211 if (*p == '<' || *p == '|' || *p == '>' || |
| 1212 *p == '?' || *p == '*' || *p == '\\') |
| 1213 break; |
| 1214 if (*p == '/' && pos < (linelen-2) && p[1] == '/') |
| 1215 break; |
| 1216 pos++; |
| 1217 p++; |
| 1218 } |
| 1219 if (pos == (linelen-1)) { |
| 1220 state->lstyle = 'D'; |
| 1221 return FTP_TYPE_JUNK; |
| 1222 } |
| 1223 } |
| 1224 |
| 1225 if (!lstyle && numtoks >= 2) { |
| 1226 pos = 22; // pos of (\d+|-|=) if this is not part of a multiline |
| 1227 if (state->lstyle && carry_buf_len) // first is from previous line |
| 1228 pos = toklen[1]-1; // and is 'as-is' (may contain whitespace) |
| 1229 if (linelen > pos) { |
| 1230 p = &line[pos]; |
| 1231 if ((*p == '-' || *p == '=' || isdigit(*p)) && |
| 1232 ((linelen == (pos+1)) || |
| 1233 (linelen >= (pos+3) && p[1] == ' ' && p[2] == ' '))) { |
| 1234 tokmarker = 1; |
| 1235 if (!carry_buf_len) { |
| 1236 pos = 1; |
| 1237 while (pos < numtoks && (tokens[pos]+toklen[pos]) < (&line[23])) |
| 1238 pos++; |
| 1239 tokmarker = 0; |
| 1240 if ((tokens[pos]+toklen[pos]) == (&line[23])) |
| 1241 tokmarker = pos; |
| 1242 } |
| 1243 if (tokmarker) { |
| 1244 lstyle = 'D'; |
| 1245 if (*tokens[tokmarker] == '-' || *tokens[tokmarker] == '=') { |
| 1246 if (toklen[tokmarker] != 1 || |
| 1247 (tokens[tokmarker - 1][toklen[tokmarker - 1] - 1]) != '/') |
| 1248 lstyle = 0; |
| 1249 } else { |
| 1250 for (pos = 0; lstyle && pos < toklen[tokmarker]; pos++) { |
| 1251 if (!isdigit(tokens[tokmarker][pos])) |
| 1252 lstyle = 0; |
| 1253 } |
| 1254 } |
| 1255 if (lstyle && !state->lstyle) { // first time |
| 1256 // scan for illegal (or incredibly unusual) chars in fname |
| 1257 for (p = tokens[0]; lstyle && |
| 1258 p < &(tokens[tokmarker - 1][toklen[tokmarker - 1]]); p++) { |
| 1259 if (*p == '<' || *p == '|' || *p == '>' || |
| 1260 *p == '?' || *p == '*' || *p == '/' || *p == '\\') |
| 1261 lstyle = 0; |
| 1262 } |
| 1263 } |
| 1264 } // size token found |
| 1265 } // expected chars behind expected size token |
| 1266 } // if (linelen > pos) |
| 1267 } // if (!lstyle && numtoks >= 2) |
| 1268 |
| 1269 if (!lstyle && state->lstyle == 'D' && !carry_buf_len) { |
| 1270 // the filename of a multi-line entry can be identified |
| 1271 // correctly only if dls format had been previously established. |
| 1272 // This should always be true because there should be entries |
| 1273 // for '.' and/or '..' and/or CWD that precede the rest of the |
| 1274 // listing. |
| 1275 pos = linelen; |
| 1276 if (pos > (sizeof(state->carry_buf) - 1)) |
| 1277 pos = sizeof(state->carry_buf) - 1; |
| 1278 memcpy(state->carry_buf, line, pos); |
| 1279 state->carry_buf_len = pos; |
| 1280 return FTP_TYPE_JUNK; |
| 1281 } |
| 1282 |
| 1283 if (lstyle == 'D') { |
| 1284 state->parsed_one = 1; |
| 1285 state->lstyle = lstyle; |
| 1286 |
| 1287 p = &(tokens[tokmarker-1][toklen[tokmarker - 1]]); |
| 1288 result->fe_fname = tokens[0]; |
| 1289 result->fe_fnlen = p - tokens[0]; |
| 1290 result->fe_type = FTP_TYPE_FILE; |
| 1291 |
| 1292 if (result->fe_fname[result->fe_fnlen - 1] == '/') { |
| 1293 if (result->fe_lnlen == 1) { |
| 1294 result->fe_type = FTP_TYPE_JUNK; |
| 1295 } else { |
| 1296 result->fe_fnlen--; |
| 1297 result->fe_type = FTP_TYPE_DIRECTORY; |
| 1298 } |
| 1299 } else if (isdigit(*tokens[tokmarker])) { |
| 1300 pos = toklen[tokmarker]; |
| 1301 if (pos > (sizeof(result->fe_size) - 1)) |
| 1302 pos = sizeof(result->fe_size) - 1; |
| 1303 memcpy(result->fe_size, tokens[tokmarker], pos); |
| 1304 result->fe_size[pos] = '\0'; |
| 1305 } |
| 1306 |
| 1307 if ((tokmarker+3) < numtoks && |
| 1308 (&(tokens[numtoks - 1][toklen[numtoks-1]]) - |
| 1309 tokens[tokmarker + 1]) >= (1 + 1 + 3 + 1 + 4)) { |
| 1310 pos = (tokmarker + 3); |
| 1311 p = tokens[pos]; |
| 1312 pos = toklen[pos]; |
| 1313 |
| 1314 if ((pos == 4 || pos == 5) && isdigit(*p) && |
| 1315 isdigit(p[pos-1]) && isdigit(p[pos - 2]) |
| 1316 && ((pos == 5 && p[2] == ':') || |
| 1317 (pos == 4 && (isdigit(p[1]) || p[1] == ':')))) { |
| 1318 month_num = tokmarker + 1; // assumed position of month field |
| 1319 pos = tokmarker + 2; // assumed position of mday field |
| 1320 if (isdigit(*tokens[month_num])) { // positions are reversed |
| 1321 month_num++; |
| 1322 pos--; |
| 1323 } |
| 1324 p = tokens[month_num]; |
| 1325 if (isdigit(*tokens[pos]) |
| 1326 && (toklen[pos] == 1 || |
| 1327 (toklen[pos] == 2 && isdigit(tokens[pos][1]))) |
| 1328 && toklen[month_num] == 3 |
| 1329 && isalpha(*p) && isalpha(p[1]) && isalpha(p[2])) { |
| 1330 pos = StringToInt(tokens[pos]); |
| 1331 if (pos > 0 && pos <= 31) { |
| 1332 result->fe_time.tm_mday = pos; |
| 1333 month_num = 1; |
| 1334 for (pos = 0; pos < (12*3); pos += 3) { |
| 1335 if (p[0] == month_names[pos + 0] && |
| 1336 p[1] == month_names[pos + 1] && |
| 1337 p[2] == month_names[pos + 2]) |
| 1338 break; |
| 1339 month_num++; |
| 1340 } |
| 1341 if (month_num > 12) |
| 1342 result->fe_time.tm_mday = 0; |
| 1343 else |
| 1344 result->fe_time.tm_mon = month_num - 1; |
| 1345 } |
| 1346 } |
| 1347 if (result->fe_time.tm_mday) { |
| 1348 tokmarker += 3; // skip mday/mon/yrtime (to find " -> ") |
| 1349 p = tokens[tokmarker]; |
| 1350 |
| 1351 pos = StringToInt(p); |
| 1352 if (pos > 24) { |
| 1353 result->fe_time.tm_year = pos - 1900; |
| 1354 } else { |
| 1355 if (p[1] == ':') |
| 1356 p--; |
| 1357 result->fe_time.tm_hour = pos; |
| 1358 result->fe_time.tm_min = StringToInt(p + 3); |
| 1359 if (!state->now_time) { |
| 1360 time_t now = time(NULL); |
| 1361 state->now_time = now * 1000000; |
| 1362 gmtime_r(&now, &state->now_tm); |
| 1363 } |
| 1364 result->fe_time.tm_year = state->now_tm.tm_year; |
| 1365 if ((( state->now_tm.tm_mon << 4) + |
| 1366 state->now_tm.tm_mday) < |
| 1367 ((result->fe_time.tm_mon << 4) + |
| 1368 result->fe_time.tm_mday)) |
| 1369 result->fe_time.tm_year--; |
| 1370 } // got year or time |
| 1371 } // got month/mday |
| 1372 } // may have year or time |
| 1373 } // enough remaining to possibly have date/time |
| 1374 |
| 1375 if (numtoks > (tokmarker+2)) { |
| 1376 pos = tokmarker+1; |
| 1377 p = tokens[pos]; |
| 1378 if (toklen[pos] == 2 && *p == '-' && p[1] == '>') { |
| 1379 p = &(tokens[numtoks - 1][toklen[numtoks - 1]]); |
| 1380 result->fe_type = FTP_TYPE_SYMLINK; |
| 1381 result->fe_lname = tokens[pos + 1]; |
| 1382 result->fe_lnlen = p - result->fe_lname; |
| 1383 if (result->fe_lnlen > 1 && |
| 1384 result->fe_lname[result->fe_lnlen -1] == '/') |
| 1385 result->fe_lnlen--; |
| 1386 } |
| 1387 } // if (numtoks > (tokmarker+2)) |
| 1388 |
| 1389 // The caller should do this (if dropping "." and ".." is desired) |
| 1390 // if (result->fe_type == FTP_TYPE_DIRECTORY && |
| 1391 // result->fe_fname[0] == '.' && (result->fe_fnlen == 1 || |
| 1392 // (result->fe_fnlen == 2 && result->fe_fname[1] == '.'))) |
| 1393 // return FTP_TYPE_JUNK; |
| 1394 return result->fe_type; |
| 1395 } // if (lstyle == 'D') |
| 1396 } // if (!lstyle && (!state->lstyle || state->lstyle == 'D')) |
| 1397 #endif |
| 1398 } // if (linelen > 0) |
| 1399 |
| 1400 if (state->parsed_one || state->lstyle) // junk if we fail to parse |
| 1401 return FTP_TYPE_JUNK; // this time but had previously parsed successfully |
| 1402 return FTP_TYPE_COMMENT; // its part of a comment or error message |
| 1403 } |
| 1404 |
| 1405 } // namespace net |
| OLD | NEW |