| 1947 | BOOL CFtpListResult::parseAsVOS(const char *line, const int linelen, t_directory::t_direntry &direntry) |
| 1948 | { |
| 1949 | int pos = 0; |
| 1950 | int tokenlen = 0; |
| 1951 | |
| 1952 | const char *str = GetNextToken(line, linelen, tokenlen, pos, 0); |
| 1953 | if (!str) |
| 1954 | return FALSE; |
| 1955 | |
| 1956 | //Set directory and link flags |
| 1957 | //Always assume links point directories |
| 1958 | //GUI frontend should try to figure out |
| 1959 | //to where the link really points |
| 1960 | if (tokenlen == 1) |
| 1961 | { |
| 1962 | switch(str[0]){ |
| 1963 | case 'n': |
| 1964 | case 'e': |
| 1965 | case 'r': |
| 1966 | case 'w': direntry.dir = false; break; |
| 1967 | case 's': |
| 1968 | case 'm': direntry.dir = true; break; |
| 1969 | default: return FALSE; |
| 1970 | } |
| 1971 | direntry.bLink = false; |
| 1972 | copyStr(direntry.permissionstr, 0, str, tokenlen); |
| 1973 | |
| 1974 | //Size |
| 1975 | str = GetNextToken(line, linelen, tokenlen, pos, 0); |
| 1976 | CString STR = str; |
| 1977 | if (!str) |
| 1978 | return FALSE; |
| 1979 | if (ParseSize(str, tokenlen, direntry.size)) |
| 1980 | direntry.size = direntry.size * 4096; //1 block == 4096 bytes |
| 1981 | else return FALSE; |
| 1982 | |
| 1983 | if (!direntry.dir) |
| 1984 | { |
| 1985 | // if not a dir the next token is the file organization |
| 1986 | // it is unused by now |
| 1987 | str = GetNextToken(line, linelen, tokenlen, pos, 0); |
| 1988 | if (!str) |
| 1989 | return FALSE; |
| 1990 | } |
| 1991 | str = NULL; |
| 1992 | } |
| 1993 | else if(tokenlen == 8) |
| 1994 | { |
| 1995 | direntry.dir = true; |
| 1996 | direntry.bLink = true; |
| 1997 | } |
| 1998 | else return FALSE; |
| 1999 | |
| 2000 | if (str == NULL) |
| 2001 | str = GetNextToken(line, linelen, tokenlen, pos, 0); |
| 2002 | |
| 2003 | //Date |
| 2004 | if (!str) |
| 2005 | return FALSE; |
| 2006 | |
| 2007 | const char *syear = str; |
| 2008 | int len = tokenlen; |
| 2009 | |
| 2010 | const char *smonth = strnchr(syear, len, '-'); |
| 2011 | if (smonth) |
| 2012 | { |
| 2013 | smonth++; |
| 2014 | int len = len - (smonth - syear + 1); |
| 2015 | const char *sday = strnchr(smonth, len, '-'); |
| 2016 | if (sday) |
| 2017 | { |
| 2018 | sday++; |
| 2019 | direntry.date.year = static_cast<int>(strntoi64(syear, smonth - syear +1)); |
| 2020 | if (direntry.date.year >= 80) direntry.date.year += 1900; |
| 2021 | else direntry.date.year += 2000; |
| 2022 | direntry.date.month = static_cast<int>(strntoi64(smonth, sday - smonth + 1)); |
| 2023 | direntry.date.day = static_cast<int>(strntoi64(sday, len - (sday - smonth + 1))); |
| 2024 | direntry.date.hastime = TRUE; |
| 2025 | } |
| 2026 | else |
| 2027 | return FALSE; |
| 2028 | } |
| 2029 | else |
| 2030 | return FALSE; |
| 2031 | |
| 2032 | //Time |
| 2033 | str = GetNextToken(line, linelen, tokenlen, pos, 0); |
| 2034 | if (!str) |
| 2035 | return FALSE; |
| 2036 | |
| 2037 | const char *shour = str; |
| 2038 | len = tokenlen; |
| 2039 | |
| 2040 | const char *sminute = strnchr(shour, len, ':'); |
| 2041 | if (sminute) |
| 2042 | { |
| 2043 | sminute++; |
| 2044 | int len = len - (sminute - shour + 1); |
| 2045 | const char *ssecond = strnchr(sminute, len, ':'); |
| 2046 | if (ssecond) |
| 2047 | { |
| 2048 | ssecond++; |
| 2049 | direntry.date.hour = static_cast<int>(strntoi64(shour, sminute - shour +1)); |
| 2050 | direntry.date.minute = static_cast<int>(strntoi64(sminute, ssecond - sminute + 1)); |
| 2051 | //no second by now |
| 2052 | //direntry.date.second = static_cast<int>(strntoi64(ssecond, len - (ssecond - sminute + 1))); |
| 2053 | direntry.date.hasdate = TRUE; |
| 2054 | } |
| 2055 | else |
| 2056 | return FALSE; |
| 2057 | } |
| 2058 | else |
| 2059 | return FALSE; |
| 2060 | |
| 2061 | //Get filename |
| 2062 | str = GetNextToken(line, linelen, tokenlen, pos, 1); |
| 2063 | if (!str) |
| 2064 | return FALSE; |
| 2065 | |
| 2066 | //Trim link data from filename |
| 2067 | if (direntry.bLink) |
| 2068 | { |
| 2069 | const char *pos = strnstr(str, tokenlen, " -> "); |
| 2070 | if (pos) |
| 2071 | { |
| 2072 | copyStr(direntry.linkTarget, 0, pos + 4, tokenlen - (pos - str) - 4); |
| 2073 | tokenlen = pos - str; |
| 2074 | } |
| 2075 | |
| 2076 | if (!tokenlen) |
| 2077 | return FALSE; |
| 2078 | } |
| 2079 | |
| 2080 | copyStr(direntry.name, 0, str, tokenlen, true); |
| 2081 | |
| 2082 | direntry.bUnsure = FALSE; |
| 2083 | return TRUE; |
| 2084 | } |
| 2085 | |