FtpListResult.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //---------------------------------------------------------------------------
  2. #ifndef FtpListResultH
  3. #define FtpListResultH
  4. //---------------------------------------------------------------------------
  5. /*This class parses the directory listing returned from the server. These formats are supported:
  6. -rw-r--r-- 1 root other 531 Jan 29 03:26 README\r\n
  7. dr-xr-xr-x 2 root other 512 Apr 8 1994 etc\r\n
  8. dr-xr-xr-x 2 root 512 Apr 8 1994 etc\r\n
  9. lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin\r\n
  10. ---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z\r\n
  11. d--------- 1 owner group 0 May 9 19:45 Softlib\r\n
  12. -rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp\r\n
  13. d [R----F--] supervisor 512 Jan 16 18:53 login\r\n
  14. - [R----F--] rhesus 214059 Oct 20 15:27 cx.exe\r\n
  15. -------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit\r\n
  16. drwxrwxr-x folder 2 May 10 1996 network\r\n
  17. 00README.TXT;1 2 30-DEC-1996 17:44 [SYSTEM] (RWED,RWED,RE,RE)\r\n
  18. CORE.DIR;1 1 8-SEP-1996 16:09 [SYSTEM] (RWE,RWE,RE,RE)\r\n
  19. CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12 [ANONYMOU,ANONYMOUS] (RWED,RWED,,)\r\n
  20. 04-27-00 09:09PM <DIR> licensed\r\n
  21. 07-18-00 10:16AM <DIR> pub\r\n
  22. 04-14-00 03:47PM 589 readme.htm\r\n
  23. Multiple spaces are ignored (except within filenames), a single LF character at the end is also supported as well as multiple
  24. CRLF pairs and other variants.
  25. */
  26. //---------------------------------------------------------------------------
  27. #include "ApiLog.h"
  28. //---------------------------------------------------------------------------
  29. class CFtpListResult : public CApiLog
  30. {
  31. public:
  32. t_server m_server;
  33. void AddData(const char * data,int size);
  34. CFtpListResult(t_server server, bool mlst, bool * bUTF8, bool vmsAllRevisions, bool debugShowListing);
  35. t_directory::t_direntry * getList(int & num);
  36. private:
  37. typedef std::list<t_directory::t_direntry> tEntryList;
  38. tEntryList m_EntryList;
  39. BOOL parseLine(const char * lineToParse, const int linelen, t_directory::t_direntry & direntry);
  40. BOOL parseAsVMS(const char * line, const int linelen, t_directory::t_direntry & direntry);
  41. BOOL parseAsEPLF(const char * line, const int linelen, t_directory::t_direntry & direntry);
  42. BOOL parseAsMlsd(const char * line, const int linelen, t_directory::t_direntry & direntry);
  43. BOOL parseAsUnix(const char * line, const int linelen, t_directory::t_direntry & direntry);
  44. BOOL parseAsDos(const char * line, const int linelen, t_directory::t_direntry & direntry);
  45. BOOL parseAsOther(const char * line, const int linelen, t_directory::t_direntry & direntry);
  46. BOOL parseAsIBM(const char * line, const int linelen, t_directory::t_direntry & direntry);
  47. BOOL parseAsIBMMVS(const char * line, const int linelen, t_directory::t_direntry & direntry);
  48. BOOL parseAsIBMMVSPDS(const char * line, const int linelen, t_directory::t_direntry & direntry);
  49. BOOL parseAsIBMMVSPDS2(const char * line, const int linelen, t_directory::t_direntry & direntry);
  50. BOOL parseAsWfFtp(const char * line, const int linelen, t_directory::t_direntry & direntry);
  51. const char * GetNextToken(const char * line, const int linelen, int & len, int & pos, int type) const;
  52. bool ParseShortDate(const char * str, int len, t_directory::t_direntry::t_date & date) const;
  53. bool parseTime(const char * str, int len, t_directory::t_direntry::t_date & date) const;
  54. bool ParseSize(const char * str, int len, __int64 & size) const;
  55. void TimeTToDate(time_t TimeT, t_directory::t_direntry::t_date & date) const;
  56. static void GuessYearIfUnknown(t_directory::t_direntry::t_date & Date);
  57. bool parseMlsdDateTime(const CString value, t_directory::t_direntry::t_date & date) const;
  58. RawByteString FBuffer;
  59. typedef std::list<int> tTempData;
  60. tTempData m_TempData;
  61. // Month names map
  62. std::map<CString, int> m_MonthNamesMap;
  63. bool m_vmsAllRevisions;
  64. bool m_debugShowListing;
  65. protected:
  66. bool m_mlst;
  67. bool * m_bUTF8;
  68. void copyStr(CString & target, int pos, const char * source, int len, bool mayInvalidateUTF8 = false);
  69. const char * strnchr(const char * str, int len, char c) const;
  70. const char * strnstr(const char * str, int len, const char * c) const;
  71. _int64 strntoi64(const char * str, int len) const;
  72. void AddLine(t_directory::t_direntry & direntry);
  73. bool IsNumeric(const char * str, int len) const;
  74. bool IsNewLineChar(char C) const;
  75. void SendLineToMessageLog(const RawByteString & Line);
  76. };
  77. //---------------------------------------------------------------------------
  78. #endif // FtpListResultH