Ver código fonte

Correcting MLST parsing (from fa0ed3c5)

Is probably noop, but previous version was badly designed at least

Source commit: 53be8eb82644b8cde93f022cfeb7484c68a04a90
Martin Prikryl 4 anos atrás
pai
commit
a8bd2dad09

+ 5 - 4
source/filezilla/FtpControlSocket.cpp

@@ -1733,7 +1733,7 @@ void CFtpControlSocket::List(BOOL bFinish, int nError /*=FALSE*/, CServerPath pa
     pData->pDirectoryListing = new t_directory;
     pData->pDirectoryListing = new t_directory;
     if (GetOptionVal(OPTION_DEBUGSHOWLISTING))
     if (GetOptionVal(OPTION_DEBUGSHOWLISTING))
       m_pTransferSocket->m_pListResult->SendToMessageLog();
       m_pTransferSocket->m_pListResult->SendToMessageLog();
-    pData->pDirectoryListing->direntry = m_pTransferSocket->m_pListResult->getList(num, false);
+    pData->pDirectoryListing->direntry = m_pTransferSocket->m_pListResult->getList(num);
     pData->pDirectoryListing->num = num;
     pData->pDirectoryListing->num = num;
     if (m_pTransferSocket->m_pListResult->m_server.nServerType & FZ_SERVERTYPE_SUB_FTP_VMS && m_CurrentServer.nServerType & FZ_SERVERTYPE_FTP)
     if (m_pTransferSocket->m_pListResult->m_server.nServerType & FZ_SERVERTYPE_SUB_FTP_VMS && m_CurrentServer.nServerType & FZ_SERVERTYPE_FTP)
       m_CurrentServer.nServerType |= FZ_SERVERTYPE_SUB_FTP_VMS;
       m_CurrentServer.nServerType |= FZ_SERVERTYPE_SUB_FTP_VMS;
@@ -2414,12 +2414,13 @@ void CFtpControlSocket::ListFile(CString filename, const CServerPath &path)
       int size = m_ListFile.GetLength();
       int size = m_ListFile.GetLength();
       char *buffer = new char[size + 1];
       char *buffer = new char[size + 1];
       memmove(buffer, (LPCSTR)m_ListFile, m_ListFile.GetLength());
       memmove(buffer, (LPCSTR)m_ListFile, m_ListFile.GetLength());
-      CFtpListResult * pListResult = new CFtpListResult(m_CurrentServer, &m_bUTF8);
+      const bool mlst = true;
+      CFtpListResult * pListResult = new CFtpListResult(m_CurrentServer, mlst, &m_bUTF8);
       pListResult->InitIntern(GetIntern());
       pListResult->InitIntern(GetIntern());
       pListResult->AddData(buffer, size);
       pListResult->AddData(buffer, size);
       if (GetOptionVal(OPTION_DEBUGSHOWLISTING))
       if (GetOptionVal(OPTION_DEBUGSHOWLISTING))
         pListResult->SendToMessageLog();
         pListResult->SendToMessageLog();
-      pData->direntry = pListResult->getList(num, true);
+      pData->direntry = pListResult->getList(num);
       if (pListResult->m_server.nServerType & FZ_SERVERTYPE_SUB_FTP_VMS && m_CurrentServer.nServerType & FZ_SERVERTYPE_FTP)
       if (pListResult->m_server.nServerType & FZ_SERVERTYPE_SUB_FTP_VMS && m_CurrentServer.nServerType & FZ_SERVERTYPE_FTP)
         m_CurrentServer.nServerType |= FZ_SERVERTYPE_SUB_FTP_VMS;
         m_CurrentServer.nServerType |= FZ_SERVERTYPE_SUB_FTP_VMS;
       delete pListResult;
       delete pListResult;
@@ -2785,7 +2786,7 @@ void CFtpControlSocket::FileTransfer(t_transferfile *transferfile/*=0*/,BOOL bFi
       pData->pDirectoryListing=new t_directory;
       pData->pDirectoryListing=new t_directory;
       if (GetOptionVal(OPTION_DEBUGSHOWLISTING))
       if (GetOptionVal(OPTION_DEBUGSHOWLISTING))
         m_pTransferSocket->m_pListResult->SendToMessageLog();
         m_pTransferSocket->m_pListResult->SendToMessageLog();
-      pData->pDirectoryListing->direntry=m_pTransferSocket->m_pListResult->getList(num, false);
+      pData->pDirectoryListing->direntry=m_pTransferSocket->m_pListResult->getList(num);
       pData->pDirectoryListing->num=num;
       pData->pDirectoryListing->num=num;
       if (m_pTransferSocket->m_pListResult->m_server.nServerType&FZ_SERVERTYPE_SUB_FTP_VMS && m_CurrentServer.nServerType&FZ_SERVERTYPE_FTP)
       if (m_pTransferSocket->m_pListResult->m_server.nServerType&FZ_SERVERTYPE_SUB_FTP_VMS && m_CurrentServer.nServerType&FZ_SERVERTYPE_FTP)
         m_CurrentServer.nServerType |= FZ_SERVERTYPE_SUB_FTP_VMS;
         m_CurrentServer.nServerType |= FZ_SERVERTYPE_SUB_FTP_VMS;

+ 10 - 10
source/filezilla/FtpListResult.cpp

@@ -140,10 +140,11 @@
 
 
 #endif
 #endif
 
 
-CFtpListResult::CFtpListResult(t_server server, bool *bUTF8)
+CFtpListResult::CFtpListResult(t_server server, bool mlst, bool *bUTF8)
 {
 {
   listhead=curpos=0;
   listhead=curpos=0;
 
 
+  m_mlst = mlst;
   m_server = server;
   m_server = server;
   m_bUTF8 = bUTF8;
   m_bUTF8 = bUTF8;
 
 
@@ -397,7 +398,7 @@ CFtpListResult::~CFtpListResult()
     delete [] m_curline;
     delete [] m_curline;
 }
 }
 
 
-t_directory::t_direntry *CFtpListResult::getList(int &num, bool mlst)
+t_directory::t_direntry *CFtpListResult::getList(int &num)
 {
 {
   #ifdef _DEBUG
   #ifdef _DEBUG
   USES_CONVERSION;
   USES_CONVERSION;
@@ -410,7 +411,7 @@ t_directory::t_direntry *CFtpListResult::getList(int &num, bool mlst)
     char *tmpline = new char[strlen(line) + 1];
     char *tmpline = new char[strlen(line) + 1];
     strcpy(tmpline, line);
     strcpy(tmpline, line);
     t_directory::t_direntry direntry;
     t_directory::t_direntry direntry;
-    if (parseLine(tmpline, strlen(tmpline), direntry, tmp, mlst))
+    if (parseLine(tmpline, strlen(tmpline), direntry, tmp))
     {
     {
       delete [] tmpline;
       delete [] tmpline;
       if (tmp)
       if (tmp)
@@ -481,7 +482,7 @@ t_directory::t_direntry *CFtpListResult::getList(int &num, bool mlst)
   return res;
   return res;
 }
 }
 
 
-BOOL CFtpListResult::parseLine(const char *lineToParse, const int linelen, t_directory::t_direntry &direntry, int &nFTPServerType, bool mlst)
+BOOL CFtpListResult::parseLine(const char *lineToParse, const int linelen, t_directory::t_direntry &direntry, int &nFTPServerType)
 {
 {
   USES_CONVERSION;
   USES_CONVERSION;
 
 
@@ -490,7 +491,7 @@ BOOL CFtpListResult::parseLine(const char *lineToParse, const int linelen, t_dir
   direntry.owner = L"";
   direntry.owner = L"";
   direntry.group = L"";
   direntry.group = L"";
 
 
-  if (parseAsMlsd(lineToParse, linelen, direntry, mlst))
+  if (parseAsMlsd(lineToParse, linelen, direntry))
     return TRUE;
     return TRUE;
 
 
   if (parseAsUnix(lineToParse, linelen, direntry))
   if (parseAsUnix(lineToParse, linelen, direntry))
@@ -539,7 +540,6 @@ BOOL CFtpListResult::parseLine(const char *lineToParse, const int linelen, t_dir
   return FALSE;
   return FALSE;
 }
 }
 
 
-// Used only with LISTDEBUG
 void CFtpListResult::AddData(char *data, int size)
 void CFtpListResult::AddData(char *data, int size)
 {
 {
   #ifdef _DEBUG
   #ifdef _DEBUG
@@ -589,7 +589,7 @@ void CFtpListResult::AddData(char *data, int size)
     int tmp;
     int tmp;
     char *tmpline = new char[strlen(line) + 1];
     char *tmpline = new char[strlen(line) + 1];
     strcpy(tmpline, line);
     strcpy(tmpline, line);
-    if (parseLine(tmpline, strlen(tmpline), direntry, tmp, false))
+    if (parseLine(tmpline, strlen(tmpline), direntry, tmp))
     {
     {
       delete [] tmpline;
       delete [] tmpline;
       if (tmp)
       if (tmp)
@@ -1262,7 +1262,7 @@ BOOL CFtpListResult::parseAsEPLF(const char *line, const int linelen, t_director
   return FALSE;
   return FALSE;
 }
 }
 
 
-BOOL CFtpListResult::parseAsMlsd(const char *line, const int linelen, t_directory::t_direntry &direntry, bool mlst)
+BOOL CFtpListResult::parseAsMlsd(const char *line, const int linelen, t_directory::t_direntry &direntry)
 {
 {
   #ifdef _DEBUG
   #ifdef _DEBUG
   USES_CONVERSION;
   USES_CONVERSION;
@@ -1355,7 +1355,7 @@ BOOL CFtpListResult::parseAsMlsd(const char *line, const int linelen, t_director
       {
       {
         // ProFTPD up to 1.3.6rc1 and 1.3.5a incorrectly uses "cdir" for the current working directory.
         // ProFTPD up to 1.3.6rc1 and 1.3.5a incorrectly uses "cdir" for the current working directory.
         // So at least in MLST, where this would be the only entry, we treat it like "dir".
         // So at least in MLST, where this would be the only entry, we treat it like "dir".
-        if (mlst)
+        if (m_mlst)
         {
         {
           direntry.dir = TRUE;
           direntry.dir = TRUE;
         }
         }
@@ -1451,7 +1451,7 @@ BOOL CFtpListResult::parseAsMlsd(const char *line, const int linelen, t_director
   pos++;
   pos++;
   CString fileName;
   CString fileName;
   copyStr(fileName, 0, line + pos, linelen - pos, true);
   copyStr(fileName, 0, line + pos, linelen - pos, true);
-  if (mlst)
+  if (m_mlst)
   {
   {
     // do not try to detect path type, assume a standard *nix syntax + do not trim
     // do not try to detect path type, assume a standard *nix syntax + do not trim
     CServerPath path(fileName, FZ_SERVERTYPE_FTP, false);
     CServerPath path(fileName, FZ_SERVERTYPE_FTP, false);

+ 5 - 4
source/filezilla/FtpListResult.h

@@ -33,19 +33,19 @@ public:
   t_server m_server;
   t_server m_server;
   void SendToMessageLog();
   void SendToMessageLog();
   void AddData(char * data,int size);
   void AddData(char * data,int size);
-  CFtpListResult(t_server server, bool * bUTF8 = 0);
+  CFtpListResult(t_server server, bool mlst, bool * bUTF8 = 0);
   virtual ~CFtpListResult();
   virtual ~CFtpListResult();
-  t_directory::t_direntry * getList(int & num, bool mlst);
+  t_directory::t_direntry * getList(int & num);
 
 
 private:
 private:
   typedef std::list<t_directory::t_direntry> tEntryList;
   typedef std::list<t_directory::t_direntry> tEntryList;
   tEntryList m_EntryList;
   tEntryList m_EntryList;
 
 
-  BOOL parseLine(const char * lineToParse, const int linelen, t_directory::t_direntry & direntry, int & nFTPServerType, bool mlst);
+  BOOL parseLine(const char * lineToParse, const int linelen, t_directory::t_direntry & direntry, int & nFTPServerType);
 
 
   BOOL parseAsVMS(const char * line, const int linelen, t_directory::t_direntry & direntry);
   BOOL parseAsVMS(const char * line, const int linelen, t_directory::t_direntry & direntry);
   BOOL parseAsEPLF(const char * line, const int linelen, t_directory::t_direntry & direntry);
   BOOL parseAsEPLF(const char * line, const int linelen, t_directory::t_direntry & direntry);
-  BOOL parseAsMlsd(const char * line, const int linelen, t_directory::t_direntry & direntry, bool mlst);
+  BOOL parseAsMlsd(const char * line, const int linelen, t_directory::t_direntry & direntry);
   BOOL parseAsUnix(const char * line, const int linelen, t_directory::t_direntry & direntry);
   BOOL parseAsUnix(const char * line, const int linelen, t_directory::t_direntry & direntry);
   BOOL parseAsDos(const char * line, const int linelen, t_directory::t_direntry & direntry);
   BOOL parseAsDos(const char * line, const int linelen, t_directory::t_direntry & direntry);
   BOOL parseAsOther(const char * line, const int linelen, t_directory::t_direntry & direntry);
   BOOL parseAsOther(const char * line, const int linelen, t_directory::t_direntry & direntry);
@@ -78,6 +78,7 @@ private:
   std::map<CString, int> m_MonthNamesMap;
   std::map<CString, int> m_MonthNamesMap;
 
 
 protected:
 protected:
+  bool m_mlst;
   bool * m_bUTF8;
   bool * m_bUTF8;
   void copyStr(CString & target, int pos, const char * source, int len, bool mayInvalidateUTF8 = false);
   void copyStr(CString & target, int pos, const char * source, int len, bool mayInvalidateUTF8 = false);
   const char * strnchr(const char * str, int len, char c) const;
   const char * strnchr(const char * str, int len, char c) const;

+ 2 - 1
source/filezilla/TransferSocket.cpp

@@ -49,7 +49,8 @@ CTransferSocket::CTransferSocket(CFtpControlSocket *pOwner, int nMode)
 
 
   if (m_nMode & CSMODE_LIST)
   if (m_nMode & CSMODE_LIST)
   {
   {
-    m_pListResult = new CFtpListResult(pOwner->m_CurrentServer, &pOwner->m_bUTF8);
+    const bool mlst = false;
+    m_pListResult = new CFtpListResult(pOwner->m_CurrentServer, mlst, &pOwner->m_bUTF8);
     m_pListResult->InitIntern(GetIntern());
     m_pListResult->InitIntern(GetIntern());
   }
   }
   else
   else