Ejemplo n.º 1
0
BOOL CObjectEntry::SetValueStringFormat(CStdString strFormattedValue)
{
    CMmcDataConversion conversion;
    unsigned __int64 uInt64Value(0);
    CStdString strValue = _T("");
    int iIndex;
    BOOL oResult(TRUE);

    //Remove leading text
    iIndex = strFormattedValue.FindOneOf("0123456789");
    if(iIndex != -1) strValue = strFormattedValue.Right(strFormattedValue.GetLength()-iIndex); else strValue = strFormattedValue;

    //Check Types
    if(conversion.DecUInt64Str2UInt64(strValue, &uInt64Value, FALSE))
    {
        m_ValueStringFormat = OVF_DEC;
        oResult = TRUE;
    }
    else if(conversion.HexUInt64Str2UInt64(strValue, &uInt64Value, FALSE))
    {
        m_ValueStringFormat = OVF_HEX;
        oResult = TRUE;
    }
    else
    {
        m_ValueStringFormat = OVF_DEC;
        oResult = FALSE;
    }

    return oResult;
}
Ejemplo n.º 2
0
const bool CommandLineParser::GetBoolFromToken(CStdString sToken)
{
	// Token strings which contain either ':' or '=' and end in one of the 'enabled' strings are considered true.
	// All others are considered false.
	if( !sToken.IsEmpty() )
	{	
		int iValuePos = sToken.FindOneOf(_T(":="));

		if( iValuePos >= 0 )
		{
			CStdString sValue = DeQuote(sToken.Mid(iValuePos+1));
			CStdString sLowercaseValue = sValue.ToLower();

			if( (sLowercaseValue == "enabled")	||
				(sLowercaseValue == "enable")	||
				(sLowercaseValue == "true")		||
				(sLowercaseValue == "on")		||
				(sLowercaseValue == "1") )
			{
				return true;
			}
		}
	}
	
	return false;
}
Ejemplo n.º 3
0
const CStdString CommandLineParser::GetValueFromToken(CStdString sToken)
{
	if (sToken.IsEmpty())
		return _T("");


	int iValuePos = sToken.FindOneOf(_T(":="));
	if (iValuePos==-1)
		return _T("");

	return DeQuote(sToken.Mid(iValuePos+1));
}
Ejemplo n.º 4
0
CStdString DocProvHelper::ReplaceInvalidFileNameChars(CStdString sString) const
{
	while (true)
	{
		/* TXTEX_IGNORE */ 		int iPos = sString.FindOneOf(_T(":*?\"&<>|"));
		if (iPos==-1)
			break;

		sString.erase(sString.begin()+iPos);
	}

	return sString;
}
Ejemplo n.º 5
0
const CStdString CommandLineParser::GetSwitchKeyFromToken(CStdString sToken)
{
	if (sToken.IsEmpty())
		return _T("");

	sToken.ToLower();

	switch (sToken[0])
	{
	case _T('/'):
	case _T('-'):
		{
			CStdString sSwitch = sToken.Mid(1);

			int iValuePos = sSwitch.FindOneOf(_T(":="));
			if (iValuePos==-1)
				return sSwitch;

			return sSwitch.Left(iValuePos);
		}
	default:
		return _T("");
	}
}
Ejemplo n.º 6
0
void COptions::SetOption(int nOptionID, LPCTSTR value, bool save /*=true*/)
{
	CStdString str = value;
	Init();

	switch (nOptionID)
	{
	case OPTION_SERVERPORT:
	case OPTION_TLSPORTS:
		{
			std::set<int> portSet;

			str.TrimLeft(_T(" ,"));

			int pos = str.FindOneOf(_T(" ,"));
			while (pos != -1)
			{
				int port = _ttoi(str.Left(pos));
				if (port >= 1 && port <= 65535)
					portSet.insert(port);
				str = str.Mid(pos + 1);
				str.TrimLeft(_T(" ,"));
				pos = str.FindOneOf(_T(" ,"));
			}
			if (str != _T(""))
			{
				int port = _ttoi(str);
				if (port >= 1 && port <= 65535)
					portSet.insert(port);
			}

			str = _T("");
			for (std::set<int>::const_iterator iter = portSet.begin(); iter != portSet.end(); iter++)
			{
				CStdString tmp;
				tmp.Format(_T("%d "), *iter);
				str += tmp;
			}
			str.TrimRight(' ');
		}
		break;
	case OPTION_WELCOMEMESSAGE:
		{
			std::vector<CStdString> msgLines;
			int oldpos = 0;
			str.Replace(_T("\r\n"), _T("\n"));
			int pos = str.Find(_T("\n"));
			CStdString line;
			while (pos != -1)
			{
				if (pos)
				{
					line = str.Mid(oldpos, pos - oldpos);
					line = line.Left(CONST_WELCOMEMESSAGE_LINESIZE);
					line.TrimRight(_T(" "));
					if (msgLines.size() || line != _T(""))
						msgLines.push_back(line);
				}
				oldpos = pos + 1;
				pos = str.Find(_T("\n"), oldpos);
			}
			line = str.Mid(oldpos);
			if (line != _T(""))
			{
				line = line.Left(CONST_WELCOMEMESSAGE_LINESIZE);
				msgLines.push_back(line);
			}
			str = _T("");
			for (unsigned int i = 0; i < msgLines.size(); i++)
				str += msgLines[i] + _T("\r\n");
			str.TrimRight(_T("\r\n"));
			if (str == _T(""))
			{
				str = _T("%v");
				str += _T("\r\nwritten by Tim Kosse ([email protected])");
				str += _T("\r\nPlease visit https://filezilla-project.org/");
			}
		}
		break;
	case OPTION_ADMINIPBINDINGS:
		{
			CStdString sub;
			std::list<CStdString> ipBindList;
			for (unsigned int i = 0; i<_tcslen(value); i++)
			{
				TCHAR cur = value[i];
				if ((cur < '0' || cur > '9') && cur != '.' && cur != ':')
				{
					if (sub == _T("") && cur == '*')
					{
						ipBindList.clear();
						ipBindList.push_back(_T("*"));
						break;
					}

					if (sub != _T(""))
					{
						if (IsIpAddress(sub))
							ipBindList.push_back(sub);
						sub = _T("");
					}
				}
				else
					sub += cur;
			}
			if (sub != _T(""))
			{
				if (IsIpAddress(sub))
					ipBindList.push_back(sub);
			}
			str = _T("");
			for (std::list<CStdString>::iterator iter = ipBindList.begin(); iter!=ipBindList.end(); iter++)
				if (!IsLocalhost(*iter))
					str += *iter + _T(" ");

			str.TrimRight(_T(" "));
		}
		break;
	case OPTION_ADMINPASS:
		if (str != _T("") && str.GetLength() < 6)
			return;
		break;
	case OPTION_MODEZ_DISALLOWED_IPS:
	case OPTION_IPFILTER_ALLOWED:
	case OPTION_IPFILTER_DISALLOWED:
	case OPTION_ADMINIPADDRESSES:
		{
			str.Replace('\r', ' ');
			str.Replace('\n', ' ');
			str.Replace('\r', ' ');
			while (str.Replace(_T("  "), _T(" ")));
			str += _T(" ");

			CStdString ips;

			int pos = str.Find(' ');
			while (pos != -1)
			{
				CStdString sub = str.Left(pos);
				str = str.Mid(pos + 1);
				str.TrimLeft(' ');

				if (sub == _T("*"))
					ips += _T(" ") + sub;
				else
				{
					if (IsValidAddressFilter(sub))
						ips += " " + sub;
					pos = str.Find(' ');
				}
			}
			ips.TrimLeft(' ');

			str = ips;
		}
		break;
	case OPTION_IPBINDINGS:
		{
			std::list<CStdString> ipBindList;

			str += _T(" ");
			while (!str.empty()) {
				int pos  = str.Find(' ');
				if (pos < 0) {
					break;
				}
				CStdString sub = str.Left(pos);
				str = str.Mid(pos + 1);

				if (sub == _T("*")) {
					ipBindList.clear();
					ipBindList.push_back(_T("*"));
					break;
				}
				else if (IsIpAddress(sub, true)) {
					ipBindList.push_back(sub);
				}
			}

			if (ipBindList.empty())
				ipBindList.push_back(_T("*"));

			str.clear();
			for (auto const& ip : ipBindList) {
				str += ip + _T(" ");
			}

			str.TrimRight(_T(" "));
		}
		break;
	case OPTION_CUSTOMPASVIPSERVER:
		if (str.Find(_T("filezilla.sourceforge.net")) != -1)
			str = _T("http://ip.filezilla-project.org/ip.php");
		break;
	}

	{
		simple_lock lock(m_mutex);
		m_sOptionsCache[nOptionID-1].bCached = TRUE;
		m_sOptionsCache[nOptionID-1].nType = 0;
		m_sOptionsCache[nOptionID-1].str = str;
		m_OptionsCache[nOptionID-1]=m_sOptionsCache[nOptionID-1];
	}

	if (!save)
		return;

	USES_CONVERSION;
	CStdString xmlFileName = GetExecutableDirectory() + _T("FileZilla Server.xml");
	char* bufferA = T2A(xmlFileName);
	if (!bufferA)
		return;

	TiXmlDocument document;
	if (!document.LoadFile(bufferA))
		return;

	TiXmlElement* pRoot = document.FirstChildElement("FileZillaServer");
	if (!pRoot)
		return;

	TiXmlElement* pSettings = pRoot->FirstChildElement("Settings");
	if (!pSettings)
		pSettings = pRoot->LinkEndChild(new TiXmlElement("Settings"))->ToElement();

	TiXmlElement* pItem;
	for (pItem = pSettings->FirstChildElement("Item"); pItem; pItem = pItem->NextSiblingElement("Item"))
	{
		const char* pName = pItem->Attribute("name");
		if (!pName)
			continue;
		CStdString name(pName);
		if (name != m_Options[nOptionID-1].name)
			continue;

		break;
	}

	if (!pItem)
		pItem = pSettings->LinkEndChild(new TiXmlElement("Item"))->ToElement();
	pItem->Clear();
	pItem->SetAttribute("name", ConvToNetwork(m_Options[nOptionID - 1].name).c_str());
	pItem->SetAttribute("type", "string");
	pItem->LinkEndChild(new TiXmlText(ConvToNetwork(value).c_str()));

	document.SaveFile(bufferA);
}