| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 5 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 6 // | 6 // |
| 7 // The contents of this file are subject to the Mozilla Public License Version | 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 | 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 | 9 // the License. You may obtain a copy of the License at |
| 10 // http://www.mozilla.org/MPL/ | 10 // http://www.mozilla.org/MPL/ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // decision by deleting the provisions above and replace them with the notice | 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 | 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 | 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. | 37 // the terms of any one of the MPL, the GPL or the LGPL. |
| 38 | 38 |
| 39 // Derived from: | 39 // Derived from: |
| 40 // mozilla/netwerk/streamconv/converters/ParseFTPList.cpp revision 1.10 | 40 // mozilla/netwerk/streamconv/converters/ParseFTPList.cpp revision 1.10 |
| 41 | 41 |
| 42 #include "net/ftp/ftp_directory_parser.h" | 42 #include "net/ftp/ftp_directory_parser.h" |
| 43 | 43 |
| 44 #include <stdlib.h> | 44 |
| 45 #include <string.h> | 45 #include <time.h> |
| 46 #include <ctype.h> | |
| 47 | 46 |
| 48 #include "build/build_config.h" | 47 #include "build/build_config.h" |
| 49 #include "base/basictypes.h" | 48 #include "base/basictypes.h" |
| 50 #include "base/string_util.h" | 49 #include "base/string_util.h" |
| 51 | 50 |
| 51 using base::Time; |
| 52 |
| 52 // #undef anything you don't want to support | 53 // #undef anything you don't want to support |
| 53 #define SUPPORT_LSL // /bin/ls -l and dozens of variations therof | 54 #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_DLS // /bin/dls format (very, Very, VERY rare) |
| 55 #define SUPPORT_EPLF // Extraordinarily Pathetic List Format | 56 #define SUPPORT_EPLF // Extraordinarily Pathetic List Format |
| 56 #define SUPPORT_DOS // WinNT server in 'site dirstyle' dos | 57 #define SUPPORT_DOS // WinNT server in 'site dirstyle' dos |
| 57 #define SUPPORT_VMS // VMS (all: MultiNet, UCX, CMU-IP) | 58 #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_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_OS2 // IBM TCP/IP for OS/2 - FTP Server |
| 60 #define SUPPORT_W16 // win16 hosts: SuperTCP or NetManage Chameleon | 61 #define SUPPORT_W16 // win16 hosts: SuperTCP or NetManage Chameleon |
| 61 | 62 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 result->fe_type = FTP_TYPE_DIRECTORY; // Its a dir. | 164 result->fe_type = FTP_TYPE_DIRECTORY; // Its a dir. |
| 164 else if (*p == 'r') | 165 else if (*p == 'r') |
| 165 result->fe_type = FTP_TYPE_FILE; | 166 result->fe_type = FTP_TYPE_FILE; |
| 166 else if (*p == 'm') { | 167 else if (*p == 'm') { |
| 167 if (isdigit(line[pos])) { | 168 if (isdigit(line[pos])) { |
| 168 while (pos < linelen && isdigit(line[pos])) | 169 while (pos < linelen && isdigit(line[pos])) |
| 169 pos++; | 170 pos++; |
| 170 if (pos < linelen && line[pos] == ',') { | 171 if (pos < linelen && line[pos] == ',') { |
| 171 uint64 seconds = 0; | 172 uint64 seconds = 0; |
| 172 seconds = StringToInt64(p + 1); | 173 seconds = StringToInt64(p + 1); |
| 173 time_t tim = static_cast<time_t>(seconds); | 174 Time t = Time::FromTimeT(seconds); |
| 174 gmtime_r(&tim, &result->fe_time); | 175 t.LocalExplode(&(result->fe_time)); |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 } else if (*p == 's') { | 178 } else if (*p == 's') { |
| 178 if (isdigit(line[pos])) { | 179 if (isdigit(line[pos])) { |
| 179 while (pos < linelen && isdigit(line[pos])) | 180 while (pos < linelen && isdigit(line[pos])) |
| 180 pos++; | 181 pos++; |
| 181 if (pos < linelen && line[pos] == ',' && | 182 if (pos < linelen && line[pos] == ',' && |
| 182 ((&line[pos]) - (p+1)) < | 183 ((&line[pos]) - (p+1)) < |
| 183 static_cast<int>(sizeof(result->fe_size) - 1)) { | 184 static_cast<int>(sizeof(result->fe_size) - 1)) { |
| 184 memcpy(result->fe_size, p + 1, | 185 memcpy(result->fe_size, p + 1, |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 month_num = 0; | 463 month_num = 0; |
| 463 for (pos = 0; pos < (12*3); pos += 3) { | 464 for (pos = 0; pos < (12*3); pos += 3) { |
| 464 if (tbuf[0] == month_names[pos+0] && | 465 if (tbuf[0] == month_names[pos+0] && |
| 465 tbuf[1] == month_names[pos + 1] && | 466 tbuf[1] == month_names[pos + 1] && |
| 466 tbuf[2] == month_names[pos + 2]) | 467 tbuf[2] == month_names[pos + 2]) |
| 467 break; | 468 break; |
| 468 month_num++; | 469 month_num++; |
| 469 } | 470 } |
| 470 if (month_num >= 12) | 471 if (month_num >= 12) |
| 471 month_num = 0; | 472 month_num = 0; |
| 472 result->fe_time.tm_mon = month_num; | 473 result->fe_time.month = month_num + 1; |
| 473 result->fe_time.tm_mday = StringToInt(tokens[2]); | 474 result->fe_time.day_of_month = StringToInt(tokens[2]); |
| 474 result->fe_time.tm_year = StringToInt(p + 4); | 475 result->fe_time.year = StringToInt(p + 4); |
| 475 // NSPR wants year as XXXX | |
| 476 | 476 |
| 477 p = tokens[3] + 2; | 477 p = tokens[3] + 2; |
| 478 if (*p == ':') | 478 if (*p == ':') |
| 479 p++; | 479 p++; |
| 480 if (p[2] == ':') | 480 if (p[2] == ':') |
| 481 result->fe_time.tm_sec = StringToInt(p + 3); | 481 result->fe_time.second = StringToInt(p + 3); |
| 482 result->fe_time.tm_hour = StringToInt(tokens[3]); | 482 result->fe_time.hour = StringToInt(tokens[3]); |
| 483 result->fe_time.tm_min = StringToInt(p); | 483 result->fe_time.minute = StringToInt(p); |
| 484 return result->fe_type; | 484 return result->fe_type; |
| 485 } // if (isdigit(*tokens[1])) | 485 } // if (isdigit(*tokens[1])) |
| 486 return FTP_TYPE_JUNK; // junk | 486 return FTP_TYPE_JUNK; // junk |
| 487 } // if (lstyle == 'V') | 487 } // if (lstyle == 'V') |
| 488 } // if (!lstyle && (!state->lstyle || state->lstyle == 'V')) | 488 } // if (!lstyle && (!state->lstyle || state->lstyle == 'V')) |
| 489 #endif // SUPPORT_VMS | 489 #endif // SUPPORT_VMS |
| 490 | 490 |
| 491 #if defined(SUPPORT_CMS) | 491 #if defined(SUPPORT_CMS) |
| 492 // Virtual Machine/Conversational Monitor System (IBM Mainframe) | 492 // Virtual Machine/Conversational Monitor System (IBM Mainframe) |
| 493 if (!lstyle && (!state->lstyle || state->lstyle == 'C')) { // VM/CMS | 493 if (!lstyle && (!state->lstyle || state->lstyle == 'C')) { // VM/CMS |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 lstyle = 0; | 580 lstyle = 0; |
| 581 } | 581 } |
| 582 } // if (lstyle && !state->lstyle) | 582 } // if (lstyle && !state->lstyle) |
| 583 | 583 |
| 584 if (lstyle == 'C') { | 584 if (lstyle == 'C') { |
| 585 state->parsed_one = 1; | 585 state->parsed_one = 1; |
| 586 state->lstyle = lstyle; | 586 state->lstyle = lstyle; |
| 587 | 587 |
| 588 p = tokens[tokmarker+4]; | 588 p = tokens[tokmarker+4]; |
| 589 if (toklen[tokmarker+4] == 10) { // newstyle: YYYY-MM-DD format | 589 if (toklen[tokmarker+4] == 10) { // newstyle: YYYY-MM-DD format |
| 590 result->fe_time.tm_year = StringToInt(p + 0) - 1900; | 590 result->fe_time.year = StringToInt(p + 0); |
| 591 result->fe_time.tm_mon = StringToInt(p + 5) - 1; | 591 result->fe_time.month = StringToInt(p + 5); |
| 592 result->fe_time.tm_mday = StringToInt(p + 8); | 592 result->fe_time.day_of_month = StringToInt(p + 8); |
| 593 } else { // oldstyle: [M]M/DD/YY format | 593 } else { // oldstyle: [M]M/DD/YY format |
| 594 pos = toklen[tokmarker + 4]; | 594 pos = toklen[tokmarker + 4]; |
| 595 result->fe_time.tm_mon = StringToInt(p) - 1; | 595 result->fe_time.month = StringToInt(p); |
| 596 result->fe_time.tm_mday = StringToInt((p + pos)-5); | 596 result->fe_time.day_of_month = StringToInt((p + pos)-5); |
| 597 result->fe_time.tm_year = StringToInt((p + pos)-2); | 597 result->fe_time.year = StringToInt((p + pos)-2); |
| 598 if (result->fe_time.tm_year < 70) | 598 if (result->fe_time.year < 70) |
| 599 result->fe_time.tm_year += 100; | 599 result->fe_time.year += 100; |
| 600 result->fe_time.year += 1900; |
| 600 } | 601 } |
| 601 p = tokens[tokmarker + 5]; | 602 p = tokens[tokmarker + 5]; |
| 602 pos = toklen[tokmarker + 5]; | 603 pos = toklen[tokmarker + 5]; |
| 603 result->fe_time.tm_hour = StringToInt(p); | 604 result->fe_time.hour = StringToInt(p); |
| 604 result->fe_time.tm_min = StringToInt((p + pos) - 5); | 605 result->fe_time.minute = StringToInt((p + pos) - 5); |
| 605 result->fe_time.tm_sec = StringToInt((p + pos) - 2); | 606 result->fe_time.second = StringToInt((p + pos) - 2); |
| 606 | 607 |
| 607 result->fe_cinfs = 1; | 608 result->fe_cinfs = 1; |
| 608 result->fe_fname = tokens[0]; | 609 result->fe_fname = tokens[0]; |
| 609 result->fe_fnlen = toklen[0]; | 610 result->fe_fnlen = toklen[0]; |
| 610 result->fe_type = FTP_TYPE_FILE; | 611 result->fe_type = FTP_TYPE_FILE; |
| 611 | 612 |
| 612 p = tokens[tokmarker]; | 613 p = tokens[tokmarker]; |
| 613 if (toklen[tokmarker] == 3 && *p == 'D' && p[1] == 'I' && p[2] == 'R') | 614 if (toklen[tokmarker] == 3 && *p == 'D' && p[1] == 'I' && p[2] == 'R') |
| 614 result->fe_type = FTP_TYPE_DIRECTORY; | 615 result->fe_type = FTP_TYPE_DIRECTORY; |
| 615 | 616 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 result->fe_lname = p + 4; | 699 result->fe_lname = p + 4; |
| 699 result->fe_lnlen = &(line[linelen_sans_wsp]) | 700 result->fe_lnlen = &(line[linelen_sans_wsp]) |
| 700 - result->fe_lname; | 701 - result->fe_lname; |
| 701 break; | 702 break; |
| 702 } | 703 } |
| 703 p++; | 704 p++; |
| 704 } | 705 } |
| 705 } | 706 } |
| 706 } | 707 } |
| 707 | 708 |
| 708 result->fe_time.tm_mon = StringToInt(tokens[0]+0); | 709 result->fe_time.month = StringToInt(tokens[0] + 0); |
| 709 if (result->fe_time.tm_mon != 0) { | 710 if (result->fe_time.month != 1) { |
| 710 result->fe_time.tm_mon--; | 711 result->fe_time.month--; |
| 711 result->fe_time.tm_mday = StringToInt(tokens[0]+3); | 712 result->fe_time.day_of_month = StringToInt(tokens[0] + 3); |
| 712 result->fe_time.tm_year = StringToInt(tokens[0]+6); | 713 result->fe_time.year = StringToInt(tokens[0] + 6); |
| 713 if (result->fe_time.tm_year < 80) | 714 if (result->fe_time.year < 80) |
| 714 result->fe_time.tm_year += 100; | 715 result->fe_time.year += 100; |
| 716 result->fe_time.year += 1900; |
| 715 } | 717 } |
| 716 | 718 |
| 717 result->fe_time.tm_hour = StringToInt(tokens[1]+0); | 719 result->fe_time.hour = StringToInt(tokens[1]+0); |
| 718 result->fe_time.tm_min = StringToInt(tokens[1]+3); | 720 result->fe_time.minute = StringToInt(tokens[1]+3); |
| 719 if ((tokens[1][5]) == 'P' && result->fe_time.tm_hour < 12) | 721 if ((tokens[1][5]) == 'P' && result->fe_time.hour < 12) |
| 720 result->fe_time.tm_hour += 12; | 722 result->fe_time.hour += 12; |
| 721 | 723 |
| 722 // the caller should do this (if dropping "." and ".." is desired) | 724 // the caller should do this (if dropping "." and ".." is desired) |
| 723 // if (result->fe_type == FTP_TYPE_DIRECTORY && result->fe_fname[0] | 725 // if (result->fe_type == FTP_TYPE_DIRECTORY && result->fe_fname[0] |
| 724 // == '.' && | 726 // == '.' && |
| 725 // (result->fe_fnlen == 1 || (result->fe_fnlen == 2 && | 727 // (result->fe_fnlen == 1 || (result->fe_fnlen == 2 && |
| 726 // result->fe_fname[1] == '.'))) | 728 // result->fe_fname[1] == '.'))) |
| 727 // return FTP_TYPE_JUNK; | 729 // return FTP_TYPE_JUNK; |
| 728 | 730 |
| 729 return result->fe_type; | 731 return result->fe_type; |
| 730 } // if (lstyle == 'W' && (!state->lstyle || state->lstyle == lstyle)) | 732 } // if (lstyle == 'W' && (!state->lstyle || state->lstyle == lstyle)) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 } | 800 } |
| 799 | 801 |
| 800 if (result->fe_type != FTP_TYPE_DIRECTORY) { | 802 if (result->fe_type != FTP_TYPE_DIRECTORY) { |
| 801 pos = toklen[0]; | 803 pos = toklen[0]; |
| 802 if (pos > (sizeof(result->fe_size)-1)) | 804 if (pos > (sizeof(result->fe_size)-1)) |
| 803 pos = (sizeof(result->fe_size)-1); | 805 pos = (sizeof(result->fe_size)-1); |
| 804 memcpy(result->fe_size, tokens[0], pos); | 806 memcpy(result->fe_size, tokens[0], pos); |
| 805 result->fe_size[pos] = '\0'; | 807 result->fe_size[pos] = '\0'; |
| 806 } | 808 } |
| 807 | 809 |
| 808 result->fe_time.tm_mon = StringToInt(&p[35-18]) - 1; | 810 result->fe_time.month = StringToInt(&p[35-18]); |
| 809 result->fe_time.tm_mday = StringToInt(&p[38-18]); | 811 result->fe_time.day_of_month = StringToInt(&p[38 - 18]); |
| 810 result->fe_time.tm_year = StringToInt(&p[41-18]); | 812 result->fe_time.year = StringToInt(&p[41 - 18]); |
| 811 if (result->fe_time.tm_year < 80) | 813 if (result->fe_time.year < 80) |
| 812 result->fe_time.tm_year += 100; | 814 result->fe_time.year += 100; |
| 813 result->fe_time.tm_hour = StringToInt(&p[46-18]); | 815 result->fe_time.year += 1900; |
| 814 result->fe_time.tm_min = StringToInt(&p[49-18]); | 816 result->fe_time.hour = StringToInt(&p[46 - 18]); |
| 817 result->fe_time.minute = StringToInt(&p[49 - 18]); |
| 815 | 818 |
| 816 // The caller should do this (if dropping "." and ".." is desired) | 819 // The caller should do this (if dropping "." and ".." is desired) |
| 817 // if (result->fe_type == FTP_TYPE_DIRECTORY && | 820 // if (result->fe_type == FTP_TYPE_DIRECTORY && |
| 818 // result->fe_fname[0] == '.' && (result->fe_fnlen == 1 || | 821 // result->fe_fname[0] == '.' && (result->fe_fnlen == 1 || |
| 819 // (result->fe_fnlen == 2 && result->fe_fname[1] == '.'))) | 822 // (result->fe_fnlen == 2 && result->fe_fname[1] == '.'))) |
| 820 // return FTP_TYPE_JUNK; | 823 // return FTP_TYPE_JUNK; |
| 821 | 824 |
| 822 return result->fe_type; | 825 return result->fe_type; |
| 823 } // if (lstyle == 'O') | 826 } // if (lstyle == 'O') |
| 824 } // if (!lstyle && (!state->lstyle || state->lstyle == 'O')) | 827 } // if (!lstyle && (!state->lstyle || state->lstyle == 'O')) |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 result->fe_type = FTP_TYPE_FILE; // (hopefully a regular file) | 964 result->fe_type = FTP_TYPE_FILE; // (hopefully a regular file) |
| 962 | 965 |
| 963 if (result->fe_type != FTP_TYPE_DIRECTORY) { | 966 if (result->fe_type != FTP_TYPE_DIRECTORY) { |
| 964 pos = toklen[tokmarker]; | 967 pos = toklen[tokmarker]; |
| 965 if (pos > (sizeof(result->fe_size)-1)) | 968 if (pos > (sizeof(result->fe_size)-1)) |
| 966 pos = (sizeof(result->fe_size)-1); | 969 pos = (sizeof(result->fe_size)-1); |
| 967 memcpy(result->fe_size, tokens[tokmarker], pos); | 970 memcpy(result->fe_size, tokens[tokmarker], pos); |
| 968 result->fe_size[pos] = '\0'; | 971 result->fe_size[pos] = '\0'; |
| 969 } | 972 } |
| 970 | 973 |
| 971 result->fe_time.tm_mon = month_num; | 974 result->fe_time.month = month_num + 1; |
| 972 result->fe_time.tm_mday = StringToInt(tokens[tokmarker+2]); | 975 result->fe_time.day_of_month = StringToInt(tokens[tokmarker+2]); |
| 973 if (result->fe_time.tm_mday == 0) | 976 if (result->fe_time.day_of_month == 0) |
| 974 result->fe_time.tm_mday++; | 977 result->fe_time.day_of_month++; |
| 975 | 978 |
| 976 p = tokens[tokmarker+3]; | 979 p = tokens[tokmarker+3]; |
| 977 pos = (unsigned int)StringToInt(p); | 980 pos = (unsigned int)StringToInt(p); |
| 978 if (p[1] == ':') // one digit hour | 981 if (p[1] == ':') // one digit hour |
| 979 p--; | 982 p--; |
| 980 if (p[2] != ':') { // year | 983 if (p[2] != ':') { // year |
| 981 result->fe_time.tm_year = pos; | 984 result->fe_time.year = pos; |
| 982 } else { | 985 } else { |
| 983 result->fe_time.tm_hour = pos; | 986 result->fe_time.hour = pos; |
| 984 result->fe_time.tm_min = StringToInt(p+3); | 987 result->fe_time.minute = StringToInt(p+3); |
| 985 if (p[5] == ':') | 988 if (p[5] == ':') |
| 986 result->fe_time.tm_sec = StringToInt(p+6); | 989 result->fe_time.second = StringToInt(p+6); |
| 987 | 990 if (!state->now_tm_valid) { |
| 988 if (!state->now_time) { | 991 Time t = Time::Now(); |
| 989 time_t now = time(NULL); | 992 t.LocalExplode(&state->now_tm); |
| 990 state->now_time = now * 1000000; | 993 state->now_tm_valid = true; |
| 991 gmtime_r(&now, &state->now_tm); | |
| 992 } | 994 } |
| 993 | 995 result->fe_time.year = state->now_tm.year; |
| 994 result->fe_time.tm_year = state->now_tm.tm_year; | 996 if ( (( state->now_tm.month << 5) + state->now_tm.day_of_month) < |
| 995 if ( (( state->now_tm.tm_mon << 5) + state->now_tm.tm_mday) < | 997 ((result->fe_time.month << 5) + result->fe_time.day_of_month) ) |
| 996 ((result->fe_time.tm_mon << 5) + result->fe_time.tm_mday) ) | 998 result->fe_time.year--; |
| 997 result->fe_time.tm_year--; | |
| 998 } // time/year | 999 } // time/year |
| 999 | 1000 |
| 1000 result->fe_fname = tokens[tokmarker+4]; | 1001 result->fe_fname = tokens[tokmarker+4]; |
| 1001 result->fe_fnlen = (&(line[linelen_sans_wsp])) | 1002 result->fe_fnlen = (&(line[linelen_sans_wsp])) |
| 1002 - (result->fe_fname); | 1003 - (result->fe_fname); |
| 1003 | 1004 |
| 1004 if (result->fe_type == FTP_TYPE_SYMLINK && result->fe_fnlen > 4) { | 1005 if (result->fe_type == FTP_TYPE_SYMLINK && result->fe_fnlen > 4) { |
| 1005 p = result->fe_fname + 1; | 1006 p = result->fe_fname + 1; |
| 1006 for (pos = 1; pos < (result->fe_fnlen - 4); pos++) { | 1007 for (pos = 1; pos < (result->fe_fnlen - 4); pos++) { |
| 1007 if (*p == ' ' && p[1] == '-' && p[2] == '>' && p[3] == ' ') { | 1008 if (*p == ' ' && p[1] == '-' && p[2] == '>' && p[3] == ' ') { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 pos = sizeof(result->fe_size) - 1; | 1124 pos = sizeof(result->fe_size) - 1; |
| 1124 memcpy(result->fe_size, p, pos); | 1125 memcpy(result->fe_size, p, pos); |
| 1125 result->fe_size[pos] = '\0'; | 1126 result->fe_size[pos] = '\0'; |
| 1126 } | 1127 } |
| 1127 | 1128 |
| 1128 p = tokens[2]; | 1129 p = tokens[2]; |
| 1129 if (toklen[2] == 3) { // Chameleon | 1130 if (toklen[2] == 3) { // Chameleon |
| 1130 tbuf[0] = toupper(p[0]); | 1131 tbuf[0] = toupper(p[0]); |
| 1131 tbuf[1] = tolower(p[1]); | 1132 tbuf[1] = tolower(p[1]); |
| 1132 tbuf[2] = tolower(p[2]); | 1133 tbuf[2] = tolower(p[2]); |
| 1133 for (pos = 0; pos < (12*3); pos+=3) { | 1134 for (pos = 0; pos < (12 * 3); pos += 3) { |
| 1134 if (tbuf[0] == month_names[pos+0] && | 1135 if (tbuf[0] == month_names[pos + 0] && |
| 1135 tbuf[1] == month_names[pos+1] && | 1136 tbuf[1] == month_names[pos + 1] && |
| 1136 tbuf[2] == month_names[pos+2]) { | 1137 tbuf[2] == month_names[pos + 2]) { |
| 1137 result->fe_time.tm_mon = pos/3; | 1138 result->fe_time.month = pos / 3 + 1; |
| 1138 result->fe_time.tm_mday = StringToInt(tokens[3]); | 1139 result->fe_time.day_of_month = StringToInt(tokens[3]); |
| 1139 result->fe_time.tm_year = StringToInt(tokens[4]) - 1900; | 1140 result->fe_time.year = StringToInt(tokens[4]); |
| 1140 break; | 1141 break; |
| 1141 } | 1142 } |
| 1142 } | 1143 } |
| 1143 pos = 5; // Chameleon toknum of date field | 1144 pos = 5; // Chameleon toknum of date field |
| 1144 } else { | 1145 } else { |
| 1145 result->fe_time.tm_mon = StringToInt(p+0)-1; | 1146 result->fe_time.month = StringToInt(p + 0); |
| 1146 result->fe_time.tm_mday = StringToInt(p+3); | 1147 result->fe_time.day_of_month = StringToInt(p + 3); |
| 1147 result->fe_time.tm_year = StringToInt(p+6); | 1148 result->fe_time.year = StringToInt(p+6); |
| 1148 if (result->fe_time.tm_year < 80) // SuperTCP | 1149 if (result->fe_time.year < 80) // SuperTCP |
| 1149 result->fe_time.tm_year += 100; | 1150 result->fe_time.year += 100; |
| 1150 | 1151 result->fe_time.year += 1900; |
| 1151 pos = 3; // SuperTCP toknum of date field | 1152 pos = 3; // SuperTCP toknum of date field |
| 1152 } | 1153 } |
| 1153 | 1154 |
| 1154 result->fe_time.tm_hour = StringToInt(tokens[pos]); | 1155 result->fe_time.hour = StringToInt(tokens[pos]); |
| 1155 result->fe_time.tm_min = StringToInt(&(tokens[pos][toklen[pos]-2])); | 1156 result->fe_time.minute = StringToInt(&(tokens[pos][toklen[pos]-2])); |
| 1156 | 1157 |
| 1157 // the caller should do this (if dropping "." and ".." is desired) | 1158 // the caller should do this (if dropping "." and ".." is desired) |
| 1158 // if (result->fe_type == FTP_TYPE_DIRECTORY && | 1159 // if (result->fe_type == FTP_TYPE_DIRECTORY && |
| 1159 // result->fe_fname[0] == '.' && (result->fe_fnlen == 1 || | 1160 // result->fe_fname[0] == '.' && (result->fe_fnlen == 1 || |
| 1160 // (result->fe_fnlen == 2 && result->fe_fname[1] == '.'))) | 1161 // (result->fe_fnlen == 2 && result->fe_fname[1] == '.'))) |
| 1161 // return FTP_TYPE_JUNK; | 1162 // return FTP_TYPE_JUNK; |
| 1162 | 1163 |
| 1163 return result->fe_type; | 1164 return result->fe_type; |
| 1164 } // (lstyle == 'w') | 1165 } // (lstyle == 'w') |
| 1165 } // if (!lstyle && (!state->lstyle || state->lstyle == 'w')) | 1166 } // if (!lstyle && (!state->lstyle || state->lstyle == 'w')) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 pos--; | 1326 pos--; |
| 1326 } | 1327 } |
| 1327 p = tokens[month_num]; | 1328 p = tokens[month_num]; |
| 1328 if (isdigit(*tokens[pos]) | 1329 if (isdigit(*tokens[pos]) |
| 1329 && (toklen[pos] == 1 || | 1330 && (toklen[pos] == 1 || |
| 1330 (toklen[pos] == 2 && isdigit(tokens[pos][1]))) | 1331 (toklen[pos] == 2 && isdigit(tokens[pos][1]))) |
| 1331 && toklen[month_num] == 3 | 1332 && toklen[month_num] == 3 |
| 1332 && isalpha(*p) && isalpha(p[1]) && isalpha(p[2])) { | 1333 && isalpha(*p) && isalpha(p[1]) && isalpha(p[2])) { |
| 1333 pos = StringToInt(tokens[pos]); | 1334 pos = StringToInt(tokens[pos]); |
| 1334 if (pos > 0 && pos <= 31) { | 1335 if (pos > 0 && pos <= 31) { |
| 1335 result->fe_time.tm_mday = pos; | 1336 result->fe_time.day_of_month = pos; |
| 1336 month_num = 1; | 1337 month_num = 1; |
| 1337 for (pos = 0; pos < (12*3); pos += 3) { | 1338 for (pos = 0; pos < (12*3); pos += 3) { |
| 1338 if (p[0] == month_names[pos + 0] && | 1339 if (p[0] == month_names[pos + 0] && |
| 1339 p[1] == month_names[pos + 1] && | 1340 p[1] == month_names[pos + 1] && |
| 1340 p[2] == month_names[pos + 2]) | 1341 p[2] == month_names[pos + 2]) |
| 1341 break; | 1342 break; |
| 1342 month_num++; | 1343 month_num++; |
| 1343 } | 1344 } |
| 1344 if (month_num > 12) | 1345 if (month_num > 12) |
| 1345 result->fe_time.tm_mday = 0; | 1346 result->fe_time.day_of_month = 0; |
| 1346 else | 1347 else |
| 1347 result->fe_time.tm_mon = month_num - 1; | 1348 result->fe_time.month = month_num + 1; |
| 1348 } | 1349 } |
| 1349 } | 1350 } |
| 1350 if (result->fe_time.tm_mday) { | 1351 if (result->fe_time.day_of_month) { |
| 1351 tokmarker += 3; // skip mday/mon/yrtime (to find " -> ") | 1352 tokmarker += 3; // skip mday/mon/yrtime (to find " -> ") |
| 1352 p = tokens[tokmarker]; | 1353 p = tokens[tokmarker]; |
| 1353 | 1354 |
| 1354 pos = StringToInt(p); | 1355 pos = StringToInt(p); |
| 1355 if (pos > 24) { | 1356 if (pos > 24) { |
| 1356 result->fe_time.tm_year = pos - 1900; | 1357 result->fe_time.year = pos; |
| 1357 } else { | 1358 } else { |
| 1358 if (p[1] == ':') | 1359 if (p[1] == ':') |
| 1359 p--; | 1360 p--; |
| 1360 result->fe_time.tm_hour = pos; | 1361 result->fe_time.hour = pos; |
| 1361 result->fe_time.tm_min = StringToInt(p + 3); | 1362 result->fe_time.minute = StringToInt(p + 3); |
| 1362 if (!state->now_time) { | 1363 if (!state->now_tm_valid) { |
| 1363 time_t now = time(NULL); | 1364 Time t = Time::Now(); |
| 1364 state->now_time = now * 1000000; | 1365 t.LocalExplode(&state->now_tm); |
| 1365 gmtime_r(&now, &state->now_tm); | 1366 state->now_tm_valid = true; |
| 1366 } | 1367 } |
| 1367 result->fe_time.tm_year = state->now_tm.tm_year; | 1368 result->fe_time.year = state->now_tm.year; |
| 1368 if ((( state->now_tm.tm_mon << 4) + | 1369 if ((( state->now_tm.month << 4) + |
| 1369 state->now_tm.tm_mday) < | 1370 state->now_tm.day_of_month) < |
| 1370 ((result->fe_time.tm_mon << 4) + | 1371 ((result->fe_time.month << 4) + |
| 1371 result->fe_time.tm_mday)) | 1372 result->fe_time.day_of_month)) |
| 1372 result->fe_time.tm_year--; | 1373 result->fe_time.year--; |
| 1373 } // got year or time | 1374 } // got year or time |
| 1374 } // got month/mday | 1375 } // got month/mday |
| 1375 } // may have year or time | 1376 } // may have year or time |
| 1376 } // enough remaining to possibly have date/time | 1377 } // enough remaining to possibly have date/time |
| 1377 | 1378 |
| 1378 if (numtoks > (tokmarker+2)) { | 1379 if (numtoks > (tokmarker+2)) { |
| 1379 pos = tokmarker+1; | 1380 pos = tokmarker+1; |
| 1380 p = tokens[pos]; | 1381 p = tokens[pos]; |
| 1381 if (toklen[pos] == 2 && *p == '-' && p[1] == '>') { | 1382 if (toklen[pos] == 2 && *p == '-' && p[1] == '>') { |
| 1382 p = &(tokens[numtoks - 1][toklen[numtoks - 1]]); | 1383 p = &(tokens[numtoks - 1][toklen[numtoks - 1]]); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1399 } // if (!lstyle && (!state->lstyle || state->lstyle == 'D')) | 1400 } // if (!lstyle && (!state->lstyle || state->lstyle == 'D')) |
| 1400 #endif | 1401 #endif |
| 1401 } // if (linelen > 0) | 1402 } // if (linelen > 0) |
| 1402 | 1403 |
| 1403 if (state->parsed_one || state->lstyle) // junk if we fail to parse | 1404 if (state->parsed_one || state->lstyle) // junk if we fail to parse |
| 1404 return FTP_TYPE_JUNK; // this time but had previously parsed successfully | 1405 return FTP_TYPE_JUNK; // this time but had previously parsed successfully |
| 1405 return FTP_TYPE_COMMENT; // its part of a comment or error message | 1406 return FTP_TYPE_COMMENT; // its part of a comment or error message |
| 1406 } | 1407 } |
| 1407 | 1408 |
| 1408 } // namespace net | 1409 } // namespace net |
| OLD | NEW |