FtpListResult.h 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 SendToMessageLog();
  34. void AddData(char * data,int size);
  35. CFtpListResult(t_server server, bool mlst, bool * bUTF8 = 0);
  36. virtual ~CFtpListResult();
  37. t_directory::t_direntry * getList(int & num);
  38. private:
  39. typedef std::list<t_directory::t_direntry> tEntryList;
  40. tEntryList m_EntryList;
  41. BOOL parseLine(const char * lineToParse, const int linelen, t_directory::t_direntry & direntry, int & nFTPServerType);
  42. void DoParseLine(char *& Line, t_directory::t_direntry & DirEntry);
  43. BOOL parseAsVMS(const char * line, const int linelen, t_directory::t_direntry & direntry);
  44. BOOL parseAsEPLF(const char * line, const int linelen, t_directory::t_direntry & direntry);
  45. BOOL parseAsMlsd(const char * line, const int linelen, t_directory::t_direntry & direntry);
  46. BOOL parseAsUnix(const char * line, const int linelen, t_directory::t_direntry & direntry);
  47. BOOL parseAsDos(const char * line, const int linelen, t_directory::t_direntry & direntry);
  48. BOOL parseAsOther(const char * line, const int linelen, t_directory::t_direntry & direntry);
  49. BOOL parseAsIBM(const char * line, const int linelen, t_directory::t_direntry & direntry);
  50. BOOL parseAsIBMMVS(const char * line, const int linelen, t_directory::t_direntry & direntry);
  51. BOOL parseAsIBMMVSPDS(const char * line, const int linelen, t_directory::t_direntry & direntry);
  52. BOOL parseAsIBMMVSPDS2(const char * line, const int linelen, t_directory::t_direntry & direntry);
  53. BOOL parseAsWfFtp(const char * line, const int linelen, t_directory::t_direntry & direntry);
  54. const char * GetNextToken(const char * line, const int linelen, int & len, int & pos, int type) const;
  55. bool ParseShortDate(const char * str, int len, t_directory::t_direntry::t_date & date) const;
  56. bool parseTime(const char * str, int len, t_directory::t_direntry::t_date & date) const;
  57. bool ParseSize(const char * str, int len, __int64 & size) const;
  58. bool parseMlsdDateTime(const CString value, t_directory::t_direntry::t_date & date) const;
  59. int pos;
  60. struct t_list
  61. {
  62. char * buffer;
  63. int len;
  64. t_list * next;
  65. } * listhead, * curpos, * m_curlistaddpos;
  66. typedef std::list<int> tTempData;
  67. tTempData m_TempData;
  68. // Month names map
  69. std::map<CString, int> m_MonthNamesMap;
  70. protected:
  71. bool m_mlst;
  72. bool * m_bUTF8;
  73. void copyStr(CString & target, int pos, const char * source, int len, bool mayInvalidateUTF8 = false);
  74. const char * strnchr(const char * str, int len, char c) const;
  75. const char * strnstr(const char * str, int len, const char * c) const;
  76. _int64 strntoi64(const char * str, int len) const;
  77. void AddLine(t_directory::t_direntry & direntry);
  78. char * GetLine();
  79. bool IsNumeric(const char * str, int len) const;
  80. char * m_prevline;
  81. char * m_curline;
  82. };
  83. //---------------------------------------------------------------------------
  84. #endif // FtpListResultH