コード例 #1
0
ファイル: FtpAPI.cpp プロジェクト: elfmz/far2l
BOOL ParseDirLine(Connection *Connect,BOOL AllFiles,FTPFileInfo* p)
{
	PROC(("ParseDirLine", "%p,%d", Connect, AllFiles))
	String        Line, Line1;
	FTPDirList    dl;
	FTPServerInfo si;

	while(true)
	{
		Connect->GetOutput(Line);

		if(!Line.Length())
			break;

		if(strstr(Line.c_str(),": Permission denied"))
		{
			WINPORT(SetLastError)(ERROR_ACCESS_DENIED);
			return FALSE;
		}

		if(Line.Length() < 20)
			continue;

		//Check contains skipped text
		static LPCSTR FTPMsg[] =
		{
			"data connection",
			"transfer complete",
			"bytes received",
			"DEVICE:[",
			"Total of "
		};
		BOOL Found = FALSE;

		for(size_t n = 0; n < ARRAYSIZE(FTPMsg); n++)
			if(strstr(Line.c_str(),FTPMsg[n]))
			{
				Found = TRUE;
				break;
			}

		if(Found) continue;

		//Check special skip strings
		if(StrCmp(Line.c_str(), "Directory ", 10) == 0 &&
		        strchr(Line.c_str()+10,'[') != NULL)
			continue;

		//Set start detect info
		memset(p, 0, sizeof(*p));
		si.ServerType = Connect->Host.ServerType;
		StrCpy(si.ServerInfo, Connect->SystemInfo, ARRAYSIZE(si.ServerInfo));
		//Use temp buffer
		Line1 = Line;
		//Detect
		WORD     idx;
		FTPType* tp = dl.GetType(Connect->Host.ServerType);

		if(Connect->Host.ServerType == FTP_TYPE_DETECT ||
		        Connect->Host.ServerType == FTP_TYPE_INVALID ||
		        tp == NULL)
		{
			idx = dl.DetectStringType(&si, Line.c_str(), Line.Length());

			if(idx == FTP_TYPE_INVALID || (tp=dl.GetType(idx)) == NULL)
			{
				LogCmd(Message("ParserDETECT: %s->%s [%s]", Parser2Str(Connect->Host.ServerType,&dl), Parser2Str(idx,&dl), Line1.c_str()), ldInt);

				if(Connect->Host.ServerType != FTP_TYPE_DETECT &&
				        Connect->Host.ServerType != FTP_TYPE_INVALID)
				{
					LogCmd(Message("ParserIGNORE: [%s]", Line1.c_str()), ldInt);
					Connect->AddCmdLine(Message("ParserIGNORE: [%s]", Line1.c_str()));
					continue;
				}

				BadFormat(Connect,Line1.c_str(),FALSE);
				break;
			}
			else
			{
				Log(("ParserDETECTED: %s->%s [%s]",Parser2Str(Connect->Host.ServerType,&dl),Parser2Str(idx,&dl),Line1.c_str()));
				Connect->Host.ServerType = idx;
			}
		}
		else
			idx = Connect->Host.ServerType;

		//Use temp buffer
		Line = Line1;
		Log(("toParse: %d,[%s], %d",Line.Length(),Line.c_str()));

		//Parse
		if(!tp->Parser(&si,p,Line.c_str(),Line.Length()))
		{
			LogCmd(Message("ParserFAIL: %s->%s [%s]",
			               Parser2Str(Connect->Host.ServerType,&dl),
			               Parser2Str(idx,&dl),
			               Line1.c_str()),
			       ldInt);
			Connect->AddCmdLine(Message("ParserFAIL: (%s) [%s]", Parser2Str(idx,&dl), Line1.c_str()));
			continue;
		}

		//Skip entryes
		char *CurName = FTP_FILENAME(p);

		if(p->FileType == NET_SKIP ||
		        !CurName[0] ||
		        StrCmp(CurName,".") == 0 ||
		        (!AllFiles && StrCmp(CurName,"..") == 0))
			continue;

		//Correct attrs
		if(p->FileType == NET_DIRECTORY ||
		        p->FileType == NET_SYM_LINK_TO_DIR)
			SET_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY);

		if(p->FileType == NET_SYM_LINK_TO_DIR ||
		        p->FileType == NET_SYM_LINK)
			SET_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_REPARSE_POINT);

		//Convert name text
//		Connect->ToOEM(CurName);
		//OK
		return TRUE;
	}

	WINPORT(SetLastError)(ERROR_NO_MORE_FILES);
	return FALSE;
}