34 return ((
ch <= 0x20) &&
ch);
59bool FTPDirectoryParser::parseDOS (
63 bool bDirectory =
false;
66 sal_uInt16 nMonth = 0;
69 sal_uInt16 nMinute = 0;
75 STATE_1_DAY, STATE_1_YEAR, STATE_1_YEAR_LWS, STATE_1_HOUR,
76 STATE_1_MINUTE, STATE_1_MINUTE_LWS, STATE_1_AP,
77 STATE_1_APM, STATE_1_LESS, STATE_1_D, STATE_1_DI,
78 STATE_1_DIR, STATE_1_SIZE,
79 STATE_2_SIZE, STATE_2_SIZE_LWS, STATE_2_ATTRIB,
80 STATE_2_D, STATE_2_DI, STATE_2_DIR_LWS,
81 STATE_2_MONTH, STATE_2_DAY, STATE_2_YEAR, STATE_2_YEAR_LWS,
82 STATE_2_HOUR, STATE_2_MINUTE,
88 enum StateType eState = STATE_INIT_LWS;
89 for (
const char *
p = pBuffer;
90 eState != STATE_ERROR && *
p;
96 if (*
p >=
'0' && *
p <=
'9')
100 eState = STATE_MONTH_OR_SIZE;
103 eState = STATE_ERROR;
106 case STATE_MONTH_OR_SIZE:
107 if (*
p >=
'0' && *
p <=
'9')
109 nMonth = 10 * nMonth + (*
p -
'0');
116 eState = STATE_2_SIZE;
123 eState = STATE_2_SIZE_LWS;
125 else if ((*
p ==
'.' || *
p ==
'-') && nMonth && nMonth <= 12)
128 eState = STATE_1_DAY;
131 eState = STATE_ERROR;
135 if (*
p >=
'0' && *
p <=
'9')
138 nDay = 10 * nDay + (*
p -
'0');
142 eState = STATE_ERROR;
143 else if ((*
p ==
'.' || *
p ==
'-') && nDay && nDay <= 31)
146 eState = STATE_1_YEAR;
149 eState = STATE_ERROR;
153 if (*
p >=
'0' && *
p <=
'9')
157 nYear = 10 * nYear + (*
p -
'0');
161 eState = STATE_ERROR;
166 eState = STATE_1_YEAR_LWS;
168 eState = STATE_ERROR;
172 case STATE_1_YEAR_LWS:
173 if (*
p >=
'0' && *
p <=
'9')
177 eState = STATE_1_HOUR;
180 eState = STATE_ERROR;
184 if (*
p >=
'0' && *
p <=
'9')
187 nHour = 10 * nHour + (*
p -
'0');
191 eState = STATE_ERROR;
192 else if (*
p ==
':' && nHour < 24)
195 eState = STATE_1_MINUTE;
198 eState = STATE_ERROR;
202 if (*
p >=
'0' && *
p <=
'9')
205 nMinute = 10 * nMinute + (*
p -
'0');
209 eState = STATE_ERROR;
210 else if ((*
p ==
'a' || *
p ==
'A') && nMinute < 60)
211 if (nHour >= 1 && nHour <= 11)
213 else if (nHour == 12)
219 eState = STATE_ERROR;
220 else if ((*
p ==
'p' || *
p ==
'P') && nMinute < 60)
221 if (nHour >= 1 && nHour <= 11)
226 else if (nHour == 12)
229 eState = STATE_ERROR;
231 eState = STATE_1_MINUTE_LWS;
233 eState = STATE_ERROR;
236 case STATE_1_MINUTE_LWS:
237 if (*
p ==
'a' || *
p ==
'A')
238 if (nHour >= 1 && nHour <= 11)
240 else if (nHour == 12)
246 eState = STATE_ERROR;
247 else if (*
p ==
'p' || *
p ==
'P')
248 if (nHour >= 1 && nHour <= 11)
253 else if (nHour == 12)
256 eState = STATE_ERROR;
258 eState = STATE_1_LESS;
259 else if (*
p >=
'0' && *
p <=
'9')
262 eState = STATE_1_SIZE;
265 eState = STATE_ERROR;
269 eState = *
p ==
'm' || *
p ==
'M' ? STATE_1_APM : STATE_ERROR;
274 eState = STATE_1_LESS;
275 else if (*
p >=
'0' && *
p <=
'9')
278 eState = STATE_1_SIZE;
281 eState = STATE_ERROR;
285 eState = *
p ==
'd' || *
p ==
'D' ? STATE_1_D : STATE_ERROR;
289 eState = *
p ==
'i' || *
p ==
'I' ? STATE_1_DI : STATE_ERROR;
293 eState = *
p ==
'r' || *
p ==
'R' ? STATE_1_DIR : STATE_ERROR;
300 eState = STATE_LWS_NAME;
303 eState = STATE_ERROR;
307 if (*
p >=
'0' && *
p <=
'9')
308 nSize = 10 * nSize + (*
p -
'0');
310 eState = STATE_LWS_NAME;
312 eState = STATE_ERROR;
316 if (*
p >=
'0' && *
p <=
'9')
317 nSize = 10 * nSize + (*
p -
'0');
319 eState = STATE_2_SIZE_LWS;
321 eState = STATE_ERROR;
324 case STATE_2_SIZE_LWS:
325 if (*
p ==
'd' || *
p ==
'D')
327 else if ((*
p >=
'a' && *
p <=
'z') || (*
p >=
'A' && *
p <=
'Z'))
328 eState = STATE_2_ATTRIB;
329 else if (*
p >=
'0' && *
p <=
'9')
333 eState = STATE_2_MONTH;
336 eState = STATE_ERROR;
341 eState = STATE_2_SIZE_LWS;
342 else if ((*p < 'a' || *p >
'z') && (*p < 'A' || *p >
'Z'))
343 eState = STATE_ERROR;
347 if (*
p ==
'i' || *
p ==
'I')
349 else if ((*
p >=
'a' && *
p <=
'z') || (*
p >=
'A' && *
p <=
'Z'))
350 eState = STATE_2_ATTRIB;
352 eState = STATE_2_SIZE_LWS;
354 eState = STATE_ERROR;
358 if (*
p ==
'r' || *
p ==
'R')
361 eState = STATE_2_DIR_LWS;
365 if ((*
p >=
'a' && *
p <=
'z') || (*
p >=
'A' && *
p <=
'Z'))
366 eState = STATE_2_ATTRIB;
368 eState = STATE_2_SIZE_LWS;
370 eState = STATE_ERROR;
374 case STATE_2_DIR_LWS:
375 if (*
p >=
'0' && *
p <=
'9')
379 eState = STATE_2_MONTH;
382 eState = STATE_ERROR;
386 if (*
p >=
'0' && *
p <=
'9')
389 nMonth = 10 * nMonth + (*
p -
'0');
393 eState = STATE_ERROR;
394 else if (*
p ==
'-' && nMonth && nMonth <= 12)
397 eState = STATE_2_DAY;
400 eState = STATE_ERROR;
404 if (*
p >=
'0' && *
p <=
'9')
407 nDay = 10 * nDay + (*
p -
'0');
411 eState = STATE_ERROR;
412 else if (*
p ==
'-' && nDay && nDay <= 31)
415 eState = STATE_2_YEAR;
418 eState = STATE_ERROR;
422 if (*
p >=
'0' && *
p <=
'9')
426 nYear = 10 * nYear + (*
p -
'0');
430 eState = STATE_ERROR;
435 eState = STATE_2_YEAR_LWS;
437 eState = STATE_ERROR;
441 case STATE_2_YEAR_LWS:
442 if (*
p >=
'0' && *
p <=
'9')
446 eState = STATE_2_HOUR;
449 eState = STATE_ERROR;
453 if (*
p >=
'0' && *
p <=
'9')
456 nHour = 10 * nHour + (*
p -
'0');
460 eState = STATE_ERROR;
461 else if (*
p ==
':' && nHour < 24)
464 eState = STATE_2_MINUTE;
467 eState = STATE_ERROR;
471 if (*
p >=
'0' && *
p <=
'9')
475 nMinute = 10 * nMinute + (*
p -
'0');
479 eState = STATE_ERROR;
484 eState = STATE_LWS_NAME;
486 eState = STATE_ERROR;
560 static OUString aFirstLineName;
561 static bool bFirstLineDir =
false;
563 for (
bool bFirstLine =
true;; bFirstLine =
false)
565 const char *
p = pBuffer;
569 while (*
p ==
'\t' || *
p ==
' ')
573 const char *pFileName =
p;
574 while ((*
p >=
'A' && *
p <=
'Z') ||
575 (*
p >=
'a' && *
p <=
'z') ||
576 (*
p >=
'0' && *
p <=
'9') ||
577 *
p ==
'-' || *
p ==
'_' || *
p ==
'$')
580 if (*
p !=
'.' ||
p == pFileName ||
p - pFileName > 39)
582 if (!aFirstLineName.isEmpty())
589 const char *pFileType = ++
p;
590 while ((*
p >=
'A' && *
p <=
'Z') ||
591 (*
p >=
'a' && *
p <=
'z') ||
592 (*
p >=
'0' && *
p <=
'9') ||
593 *
p ==
'-' || *
p ==
'_' || *
p ==
'$')
596 if (*
p !=
';' ||
p == pFileName ||
p - pFileName > 39)
598 if (!aFirstLineName.isEmpty())
606 if ((
p - pFileType == 4) &&
607 (pFileType[0] ==
'D' || pFileType[0] ==
'd') &&
608 (pFileType[1] ==
'I' || pFileType[1] ==
'i') &&
609 (pFileType[2] ==
'R' || pFileType[2] ==
'r') )
621 if (*p < '1' || *p >
'9')
623 if (!aFirstLineName.isEmpty())
629 while (*
p >=
'0' && *
p <=
'9')
634 while (*
p ==
'\t' || *
p ==
' ')
643 if (!aFirstLineName.isEmpty())
655 aFirstLineName = rEntry.
m_aName;
667 rEntry.
m_aName = aFirstLineName;
671 if (*
p !=
'\t' && *
p !=
' ')
674 while (*
p ==
'\t' || *
p ==
' ')
679 if (*p < '0' || *p >
'9')
681 sal_uInt32 nSize = *
p -
'0';
683 while (*
p >=
'0' && *
p <=
'9')
684 nSize = 10 * rEntry.
m_nSize + (*
p++ -
'0');
688 if (*
p !=
'\t' && *
p !=
' ')
691 while (*
p ==
'\t' || *
p ==
' ')
699 if (*p < '1' || *p >
'9')
703 else if (*
p ==
'1' || *
p ==
'2')
706 if (*
p >=
'0' && *
p <=
'9')
707 nDay = 10 * nDay + (*
p++ -
'0');
712 nDay = (*
p ==
'0' || *
p ==
'1') ? 30 + (*
p++ -
'0') : 3;
714 else if (*
p >=
'4' && *
p <=
'9')
724 char const * pMonth =
p;
725 sal_Int32
const monthLen = 3;
726 for (
int i = 0;
i < monthLen; ++
i)
728 if (!((*
p >=
'A' && *
p <=
'Z') || (*
p >=
'a' && *
p <=
'z')))
732 if (rtl_str_compareIgnoreAsciiCase_WithLength(
733 pMonth, monthLen,
"JAN", monthLen) == 0)
735 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
736 pMonth, monthLen,
"FEB", monthLen) == 0)
738 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
739 pMonth, monthLen,
"MAR", monthLen) == 0)
741 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
742 pMonth, monthLen,
"APR", monthLen) == 0)
744 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
745 pMonth, monthLen,
"MAY", monthLen) == 0)
747 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
748 pMonth, monthLen,
"JUN", monthLen) == 0)
750 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
751 pMonth, monthLen,
"JUL", monthLen) == 0)
753 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
754 pMonth, monthLen,
"AUG", monthLen) == 0)
756 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
757 pMonth, monthLen,
"SEP", monthLen) == 0)
759 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
760 pMonth, monthLen,
"OCT", monthLen) == 0)
762 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
763 pMonth, monthLen,
"NOV", monthLen) == 0)
765 else if (rtl_str_compareIgnoreAsciiCase_WithLength(
766 pMonth, monthLen,
"DEC", monthLen) == 0)
774 sal_uInt16 nYear = 0;
775 for (
int i = 0;
i < 2; ++
i)
777 if (*p < '0' || *p >
'9')
779 nYear = 10 * nYear + (*
p++ -
'0');
781 if (*
p >=
'0' && *
p <=
'9')
783 nYear = 10 * nYear + (*
p++ -
'0');
784 if (*p < '0' || *p >
'9')
786 nYear = 10 * nYear + (*
p++ -
'0');
791 if (*
p !=
'\t' && *
p !=
' ')
794 while (*
p ==
'\t' || *
p ==
' ')
799 if (*
p ==
'0' || *
p ==
'1')
802 if (*
p >=
'0' && *
p <=
'9')
803 nHour = 10 * nHour + (*
p++ -
'0');
808 nHour = (*
p >=
'0' && *
p <=
'3') ? 20 + (*
p++ -
'0') : 2;
810 else if (*
p >=
'3' && *
p <=
'9')
823 if (*p < '0' || *p >
'5')
826 sal_uInt16 nMinute = *
p++ -
'0';
827 if (*p < '0' || *p >
'9')
830 nMinute = 10 * nMinute + (*
p++ -
'0');
836 return !*
p || *
p ==
'\t' || *
p ==
' ';
850 if (!((*p1 ==
'-') || (*p1 ==
'd') || (*p1 ==
'l')))
876 FOUND_NONE, FOUND_SIZE, FOUND_MONTH, FOUND_DAY, FOUND_YEAR_TIME
879 const char *pDayStart =
nullptr;
880 const char *pDayEnd =
nullptr;
882 for (
eMode = FOUND_NONE; *p1 &&
eMode != FOUND_YEAR_TIME; p1 = p2 + 1)
919 eMode = FOUND_YEAR_TIME;
922 pDayStart, pDayEnd, rEntry.
m_nSize) &&
932 case FOUND_YEAR_TIME:
937 if (
eMode == FOUND_YEAR_TIME)
957 if (!*pStart || !*pEnd || pStart == pEnd)
961 if (*pStart >=
'0' && *pStart <=
'9')
963 for (; pStart < pEnd; ++pStart)
964 if ((*pStart >=
'0') && (*pStart <=
'9'))
965 rSize = 10 * rSize + (*pStart -
'0');
979 for (; pStart < pEnd; ++pStart)
980 if ((*pStart >=
'1') && (*pStart <=
'9'))
983 rSize = 10 * rSize + (*pStart -
'0');
985 else if ((*pStart ==
'0') && nDigits)
990 else if ((*pStart >
' ') && (sal::static_int_cast<sal_uInt8>(*pStart) <=
'\x7F'))
992 nNonDigits += nDigits + 1;
998 return ((nNonDigits >= 9) && (nDigits >= 7));
1010 if (!*pStart || !*pEnd || pStart + 3 != pEnd)
1013 if ((pStart[0] ==
'j' || pStart[0] ==
'J') &&
1014 (pStart[1] ==
'a' || pStart[1] ==
'A') &&
1015 (pStart[2] ==
'n' || pStart[2] ==
'N') )
1020 if ((pStart[0] ==
'f' || pStart[0] ==
'F') &&
1021 (pStart[1] ==
'e' || pStart[1] ==
'E') &&
1022 (pStart[2] ==
'b' || pStart[2] ==
'B') )
1027 if ((pStart[0] ==
'm' || pStart[0] ==
'M') &&
1028 (pStart[1] ==
'a' || pStart[1] ==
'A') &&
1029 (pStart[2] ==
'r' || pStart[2] ==
'R') )
1034 if ((pStart[0] ==
'a' || pStart[0] ==
'A') &&
1035 (pStart[1] ==
'p' || pStart[1] ==
'P') &&
1036 (pStart[2] ==
'r' || pStart[2] ==
'R') )
1041 if ((pStart[0] ==
'm' || pStart[0] ==
'M') &&
1042 (pStart[1] ==
'a' || pStart[1] ==
'A') &&
1043 (pStart[2] ==
'y' || pStart[2] ==
'Y') )
1048 if ((pStart[0] ==
'j' || pStart[0] ==
'J') &&
1049 (pStart[1] ==
'u' || pStart[1] ==
'U') &&
1050 (pStart[2] ==
'n' || pStart[2] ==
'N') )
1055 if ((pStart[0] ==
'j' || pStart[0] ==
'J') &&
1056 (pStart[1] ==
'u' || pStart[1] ==
'U') &&
1057 (pStart[2] ==
'l' || pStart[2] ==
'L') )
1062 if ((pStart[0] ==
'a' || pStart[0] ==
'A') &&
1063 (pStart[1] ==
'u' || pStart[1] ==
'U') &&
1064 (pStart[2] ==
'g' || pStart[2] ==
'G') )
1069 if ((pStart[0] ==
's' || pStart[0] ==
'S') &&
1070 (pStart[1] ==
'e' || pStart[1] ==
'E') &&
1071 (pStart[2] ==
'p' || pStart[2] ==
'P') )
1076 if ((pStart[0] ==
'o' || pStart[0] ==
'O') &&
1077 (pStart[1] ==
'c' || pStart[1] ==
'C') &&
1078 (pStart[2] ==
't' || pStart[2] ==
'T') )
1083 if ((pStart[0] ==
'n' || pStart[0] ==
'N') &&
1084 (pStart[1] ==
'o' || pStart[1] ==
'O') &&
1085 (pStart[2] ==
'v' || pStart[2] ==
'V') )
1090 if ((pStart[0] ==
'd' || pStart[0] ==
'D') &&
1091 (pStart[1] ==
'e' || pStart[1] ==
'E') &&
1092 (pStart[2] ==
'c' || pStart[2] ==
'C') )
1108 if (!*pStart || !*pEnd || pStart == pEnd)
1110 if (*pStart < '0' || *pStart >
'9')
1113 sal_uInt16 nDay = *pStart -
'0';
1114 if (pStart + 1 < pEnd)
1116 if (pStart + 2 != pEnd || pStart[1] <
'0' || pStart[1] >
'9')
1118 nDay = 10 * nDay + (pStart[1] -
'0');
1120 if (!nDay || nDay > 31)
1135 if (!*pStart || !*pEnd || pStart == pEnd ||
1136 *pStart < '0' || *pStart >
'9')
1139 sal_uInt16 nNumber = *pStart -
'0';
1146 if (*pStart < '0' || *pStart >
'9')
1149 nNumber = 10 * nNumber + (*pStart -
'0');
1156 if (*pStart < '0' || *pStart >
'9')
1159 nNumber = 10 * nNumber + (*pStart -
'0');
1162 if (pStart == pEnd || *pStart < '0' || *pStart >
'9')
1165 nNumber = 10 * nNumber + (*pStart -
'0');
1166 if (pStart + 1 != pEnd || nNumber < 1970)
1183 if ((nHour > 23 ) || (pStart + 3 != pEnd) ||
1184 (pStart[1] <
'0') || (pStart[1] >
'5') ||
1185 (pStart[2] <
'0') || (pStart[2] >
'9') )
1188 sal_uInt16 nMin = 10 * (pStart[1] -
'0') + (pStart[2] -
'0');
1203 osl_getSystemTime(&aTimeVal);
1204 oslDateTime aCurrDateTime;
1205 osl_getDateTimeFromTimeValue(&aTimeVal,&aCurrDateTime);
1207 if (rDateTime.
GetMonth() > aCurrDateTime.Month)
1208 rDateTime.
SetYear(aCurrDateTime.Year - 1);
1210 rDateTime.
SetYear(aCurrDateTime.Year);
1223 DateTime &rDateTime, sal_uInt16 nYear)
1228 osl_getSystemTime(&aTimeVal);
1229 oslDateTime aCurrDateTime;
1230 osl_getDateTimeFromTimeValue(&aTimeVal,&aCurrDateTime);
1231 sal_uInt16 nCurrentYear = aCurrDateTime.Year;
1233 sal_uInt16 nCurrentCentury = nCurrentYear / 100;
1234 nCurrentYear %= 100;
1235 if (nCurrentYear < 50)
1236 if (nYear <= nCurrentYear)
1237 nYear += nCurrentCentury * 100;
1238 else if (nYear < nCurrentYear + 50)
1239 nYear += nCurrentCentury * 100;
1241 nYear += (nCurrentCentury - 1) * 100;
1243 if (nYear >= nCurrentYear)
1244 nYear += nCurrentCentury * 100;
1245 else if (nYear >= nCurrentYear - 50)
1246 nYear += nCurrentCentury * 100;
1248 nYear += (nCurrentCentury + 1) * 100;
1258 OUString &rPath,
const char *value, sal_Int32 length)
1264 rPath = OUString (
value,
length, RTL_TEXTENCODING_UTF8);
static bool parseUNIX_isTime(const char *pStart, const char *pEnd, sal_uInt16 nHour, DateTime &rDateTime)
static bool parseUNIX_isYearTimeField(const char *pStart, const char *pEnd, DateTime &rDateTime)
static void setYear(DateTime &rDateTime, sal_uInt16 nYear)
static bool parseUNIX_isMonthField(const char *pStart, const char *pEnd, DateTime &rDateTime)
static bool parseUNIX(FTPDirentry &rEntry, const char *pBuffer)
static bool parseUNIX_isSizeField(const char *pStart, const char *pEnd, sal_uInt32 &rSize)
static bool parseUNIX_isDayField(const char *pStart, const char *pEnd, DateTime &rDateTime)
static bool parseVMS(FTPDirentry &rEntry, const char *pBuffer)
static bool setPath(OUString &rPath, const char *value, sal_Int32 length=-1)
static bool ascii_isWhitespace(sal_Unicode ch)
Definition of ftpcontentprovider.
@ INETCOREFTP_FILEMODE_ISDIR
@ INETCOREFTP_FILEMODE_WRITE
@ INETCOREFTP_FILEMODE_ISLINK
@ INETCOREFTP_FILEMODE_READ
sal_uInt16 GetMonth() const
void SetYear(sal_uInt16 year)
void SetMin(sal_uInt16 minutes)
void SetMonth(sal_uInt16 month)
void SetNanoSec(sal_uInt32 nanoSec)
void SetDay(sal_uInt16 day)
void SetHour(sal_uInt16 hours)
void SetSec(sal_uInt16 seconds)