예제 #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;
}
예제 #2
0
파일: FtpAPI.cpp 프로젝트: elfmz/far2l
BOOL FtpSystemInfo(Connection *Connect,char *Buffer,int MaxSize)
{
	char *ChPtr;
	Assert(Connect && "FtpSystemInfo");

	if(Buffer && MaxSize < 1)
		return FALSE;

	if(!Connect->SystemInfoFilled)
	{
		FP_Screen _scr;
		Connect->SystemInfoFilled = TRUE;

		if(Connect->ProcessCommand("syst"))
		{
			char tmp[ 200 ];  //Do not need to use String. Limit system info by 200 chars.
			Connect->GetReply((BYTE*)tmp,sizeof(tmp));

			if((ChPtr=strchr(tmp,'\r')) != NULL)
				*ChPtr=0;

			if((ChPtr=strchr(tmp,'\n')) != NULL)
				*ChPtr=0;

			if(isdigit(tmp[0]) && isdigit(tmp[1]) && isdigit(tmp[2]))
				StrCpy(Connect->SystemInfo,tmp+4,ARRAYSIZE(Connect->SystemInfo));
			else
				StrCpy(Connect->SystemInfo,tmp,ARRAYSIZE(Connect->SystemInfo));
		}
		else
		{
			*Connect->SystemInfo = 0;
		}

		FTPDirList    dl;
		FTPServerInfo si;
		String        Line;
		si.ServerType = Connect->Host.ServerType;
		StrCpy(si.ServerInfo, Connect->SystemInfo, ARRAYSIZE(si.ServerInfo));
		WORD idx = dl.DetectStringType(&si, Line.c_str(), Line.Length());

		if(idx==FTP_TYPE_MVS)
		{
			Log(("site directorymode"));

			if(Connect->ProcessCommand("site directorymode"))
			{
				char tmp[ 200 ];  //Do not need to use String. Limit system info by 200 chars.
				Connect->GetReply((BYTE*)tmp,sizeof(tmp));
			}
		}
	}

	if(Buffer)
	{
		StrCpy(Buffer,Connect->SystemInfo,MaxSize);
		return *Buffer != 0;
	}
	else
		return TRUE;
}