예제 #1
0
static bool correct_vms_name(String& name)
{
	bool ret = false;
	FTPDirList dl;
	FTPType *tp = dl.GetType(FTP_TYPE_VMS);
	if (tp && tp->PWDParse)
	{
		char tmp[1024];
		if (tp->PWDParse(nullptr, name.c_str(), tmp, sizeof(tmp)))
		{
			name = tmp;
			ret = true;
		}
	}
	return ret;
}
예제 #2
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;
}
예제 #3
0
파일: FtpAPI.cpp 프로젝트: elfmz/far2l
BOOL FtpGetFtpDirectory(Connection *Connect)
{
	String         s, s1;
	FTPDirList     dl;
	char          *m;
	FTPServerInfo  si;
	WORD           idx;
	//Exec
	{
		FP_Screen  _scr;

		if(!Connect->ProcessCommand("pwd"))
			return FALSE;
	}
	Connect->GetReply(s);

	do
	{
		//Detect if unknown
		si.ServerType = Connect->Host.ServerType;
		StrCpy(si.ServerInfo, Connect->SystemInfo, ARRAYSIZE(si.ServerInfo));
		idx = Connect->Host.ServerType;

		if(idx == FTP_TYPE_DETECT || idx == FTP_TYPE_INVALID)
			idx = dl.DetectDirStringType(&si, s.c_str());

		//Parse
		FTPType*   tp;
		char       tmp[ 1024 ];  //There is not way to use String.

		if((tp=dl.GetType(idx)) != NULL &&
		        tp->PWDParse &&
		        tp->PWDParse(&si, s.c_str(), tmp, sizeof(tmp)))
		{
			Connect->CurDir = tmp;
			break;
		}

		//Del digits
		m = s.c_str();

		while(*m && (isdigit(*m) || strchr("\t\b ",*m) != NULL)) m++;

		if(!m[0])
			return FALSE;

		s.Del(0, (int)(m-s.c_str()));

		//Decode FF
		if(Connect->Host.UndupFF)
		{
			for(m = s.c_str(); *m; m++)
			{
				if(m[0] == (char)0xFF && m[1] == (char)0xFF)
				{
					s1.Add((char)0xFF);
					m++;
				}
				else
					s1.Add(*m);
			}

			s = s1;
		}

		//Set classic path
		/* Unix:
		     - name enclosed with '"'
		     - if '"' is in name it doubles
		*/
		int b;

		if((b=s.Chr('\"')) != -1)
		{
			s1.Null();

			for(int n = b+1; n < s.Length(); n++)
				if(s[n] == '\"')
				{
					if(s[n+1] == '\"')
					{
						s1.Add(s[n]);
						n++;
					}
					else
						break;
				}
				else
					s1.Add(s[n]);

			Connect->CurDir = s1;
		}
		else
			//Raw
			Connect->CurDir = s;
	}
	while(0);

	//Remove NL\CR
	int num;

	while((num=Connect->CurDir.Chr("\r\n")) != -1)
		Connect->CurDir.SetLength(num);

	return TRUE;
}