void VVirtualFolderSetting::LoadFromBag (const XBOX::VValueBag& inValueBag, const XBOX::VFilePath& inProjectFolderPath)
{
	inValueBag.GetString (RIASettingsKeys::VirtualFolders::name, fName);
	inValueBag.GetString (RIASettingsKeys::VirtualFolders::location, fLocation);
	inValueBag.GetString (RIASettingsKeys::VirtualFolders::index, fIndex);

	if (HTTPServerTools::BeginsWithASCIICString (fLocation, "http://") ||
		HTTPServerTools::BeginsWithASCIICString (fLocation, "https://"))
	{
		fUseRedirect = true;
	}
	else
	{
		XBOX::VFilePath path;
		BuildFolderPath (inProjectFolderPath, fLocation, path);
		if (path.IsFolder())
		{
			path.GetPath (fLocation);
		}
		else
		{
			XBOX::VFilePath	folder;
			XBOX::VString	string;

			path.GetFolder (folder);
			path.GetFileName (string);
			folder.ToSubFolder (string);
			folder.GetPath (fLocation);
		}
	}
}
示例#2
0
const OTString & OTPaths::AppDataFolder()
{
	if (m_strAppDataFolder.Exists()) return m_strAppDataFolder;  // already got it, just return it.

	OTString strHomeDataFolder(""), strAppDataFolder("");  // eg. /home/user/  (the folder that the OT appdata folder will be in.)

	if(!GetHomeFromSystem(strHomeDataFolder)) { OT_ASSERT(false); return m_strAppDataFolder; }

	// now lets change all the '\' into '/'
	// then check that the path /home/user indeed exists, and is a folder.

	FixPath(strHomeDataFolder,strHomeDataFolder,true);
	if(!PathExists(strHomeDataFolder)) OT_ASSERT(false);

	// ok, we have the HomeData Folder, lets append our OT folder to it.

	if(!AppendFolder(strAppDataFolder,strHomeDataFolder,OT_APPDATA_DIR)) OT_ASSERT(false);

	bool bFolderCreated;
	if(!BuildFolderPath(strAppDataFolder,bFolderCreated)) OT_ASSERT(false);

	m_strAppDataFolder = strAppDataFolder;  // all good lets set it.

	return m_strAppDataFolder;
}
void VHTTPServerProjectSettings::SetWebFolderPath (const XBOX::VString& inValue)
{
	BuildFolderPath (fProjectFolderPath, inValue, fWebFolderPath);

	Tell_SettingsChanged();
}
void VHTTPServerProjectSettings::SetWebFolderPath (const XBOX::VFilePath& inValue)
{
	BuildFolderPath (fProjectFolderPath, inValue.GetPath(), fWebFolderPath);

	Tell_SettingsChanged();
}
XBOX::VError VHTTPServerProjectSettings::LoadFromBag (const XBOX::VValueBag *inBag)
{
	if (NULL == inBag)
		return XBOX::VE_INVALID_PARAMETER;

#if 0 /*VERSIONDEBUG*/
	XBOX::VString xmlString ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
	inBag->DumpXML (xmlString, CVSTR ("settings"), true);
#endif

	/* Project settings */
	const XBOX::VValueBag *projectSettings = RetainSettings (inBag, RIASettingsKeys::Project::kXmlElement);
	if (projectSettings)
	{
		XBOX::VString ipString = RIASettingsKeys::Project::listen.Get (projectSettings);
#if WITH_DEPRECATED_IPV4_API
		fListeningAddress = ServerNetTools::GetIPAddress (ipString);
#else
		fListeningAddress.FromString (ipString);
#endif		
		fHostName = RIASettingsKeys::Project::hostName.Get (projectSettings);
#if HTTP_SERVER_USE_PROJECT_PATTERNS
		fProjectPattern = RIASettingsKeys::Project::pattern.Get (projectSettings);
#endif

#if WITH_DEPRECATED_IPV4_API
		if ((fListeningAddress != 0) && (fListeningAddress != LOCALHOST_ADDRESS))
#else
		if ((fListeningAddress != XBOX::VNetAddress::GetAnyIP()) && (fListeningAddress != XBOX::VNetAddress::GetLoopbackIP()))
#endif		
		{
#if WITH_DEPRECATED_IPV4_API
			std::vector<IP4> ipv4Addresses;
			if (ServerNetTools::GetLocalIPv4Addresses (ipv4Addresses) > 0)
			{
				if (!FindValueInVector (ipv4Addresses, fListeningAddress))
					fListeningAddress = 0; // Listening on all IP addresses
			}
#else
			XBOX::VectorOfVString	localIPAddresses;

			if (HTTPServerTools::GetLocalIPAddresses (localIPAddresses) > 0)
			{
				if (!FindValueInVector (localIPAddresses, fListeningAddress))
					fListeningAddress.FromString (XBOX::VNetAddress::GetAnyIP()); // Listening on all IP addresses
			}
#endif			
		}

		XBOX::VString authType;
		RIASettingsKeys::Project::realm.Get (projectSettings, fRealm);
		RIASettingsKeys::Project::authType.Get (projectSettings, authType);
		fAuthType = HTTPServerTools::GetAuthenticationMethodFromName (authType);

		XBOX::QuickReleaseRefCountable (projectSettings);
	}


	/*  HTTP Settings */
	const XBOX::VValueBag *httpSettings = RetainSettings (inBag, RIASettingsKeys::HTTP::kXmlElement);
	if (httpSettings)
	{
		fPort = RIASettingsKeys::HTTP::port.Get (httpSettings);
		fAllowSSL = RIASettingsKeys::HTTP::allowSSL.Get (httpSettings);
		fSSLMandatory = RIASettingsKeys::HTTP::SSLMandatory.Get (httpSettings);
		fSSLPort = RIASettingsKeys::HTTP::SSLPort.Get (httpSettings);

		if (fSSLMandatory && !fAllowSSL)
			fAllowSSL = true;

		if (fAllowSSL)
		{
			XBOX::VString certificatePath = RIASettingsKeys::HTTP::SSLCertificatePath.Get (httpSettings);
			BuildFolderPath (fProjectFolderPath, certificatePath, fSSLCertificatesFolderPath);
		}

		XBOX::VString charSetString = RIASettingsKeys::HTTP::standardSet.Get (httpSettings);
		XBOX::CharSet charSet = VTextConverters::Get()->GetCharSetFromName (charSetString);
		fDefaultCharSet = (charSet != XBOX::VTC_UNKNOWN) ? charSet : XBOX::VTC_UTF_8;

		/* cache settings */
		fEnableCache = RIASettingsKeys::HTTP::useCache.Get (httpSettings);
		fCacheMaxSize = RIASettingsKeys::HTTP::pageCacheSize.Get (httpSettings) * 1024;			// expressed in Kilo-Bytes in settings file
		fCachedObjectMaxSize = RIASettingsKeys::HTTP::cachedObjectMaxSize.Get (httpSettings);	// expressed in Bytes in settings file

		/* compression settings */
		fEnableCompression = RIASettingsKeys::HTTP::allowCompression.Get (httpSettings);
		fCompressionMinThreshold = RIASettingsKeys::HTTP::compressionMinThreshold.Get (httpSettings);
		fCompressionMaxThreshold = RIASettingsKeys::HTTP::compressionMaxThreshold.Get (httpSettings);

		/* Keep-Alive settings */
		fEnableKeepAlive = RIASettingsKeys::HTTP::acceptKeepAliveConnections.Get (httpSettings);
/* Temporary disable theses settings loading... because of a bug with long timeout values (sic...)
		fKeepAliveTimeout = RIASettingsKeys::HTTP::maximumTimeout.Get (httpSettings);
		fKeepAliveMaxConnections = RIASettingsKeys::HTTP::maximumRequestsByConnection.Get (httpSettings);
*/

		/* Log settings */
		fLogFormat = HTTPServerTools::GetLogFormatFromName (RIASettingsKeys::HTTP::logFormat.Get (httpSettings));
		SetLogRotationMode (LRC_ROTATE_ON_FILE_SIZE);
		SetLogMaxSize (RIASettingsKeys::HTTP::logMaxSize.Get (httpSettings));
		XBOX::VString logFolderPathString = RIASettingsKeys::HTTP::logPath.Get (httpSettings);
		BuildFolderPath (fProjectFolderPath, logFolderPathString, fLogFolderPath);
		fLogFileName = RIASettingsKeys::HTTP::logFileName.Get (httpSettings);

		const XBOX::VBagArray *logTokens = RetainMultipleSettings (httpSettings, RIASettingsKeys::HTTP::Log::kXmlElement);
		if (NULL != logTokens)
		{
			XBOX::VIndex count = logTokens->GetCount();

			if (count > 0)
			{
				XBOX::VString tokenName;
				XBOX::VTaskLock lock (&fLogTokensVectorLock);

				fLogTokensVector.clear();
				for (XBOX::VIndex i = 1; i <= count; ++i)
				{
					const XBOX::VValueBag *bag = logTokens->GetNth (i);
					if (NULL != bag)
					{
						bag->GetString (RIASettingsKeys::HTTP::Log::field, tokenName);
						if (!tokenName.IsEmpty())
						{
							EHTTPServerLogToken token = HTTPServerTools::GetLogTokenFromName (tokenName);
							if (token != LOG_TOKEN_NONE)
								AppendUniqueValueToVector (fLogTokensVector, token);
						}
					}
				}
			}

			XBOX::QuickReleaseRefCountable (logTokens);
		}

		XBOX::QuickReleaseRefCountable (httpSettings);
	}

	/* Web App settings */
	const XBOX::VValueBag *webAppSettings = RetainSettings (inBag, RIASettingsKeys::WebApp::kXmlElement);
	if (webAppSettings)
	{
		XBOX::VString webFolderPath;
		webFolderPath = RIASettingsKeys::WebApp::documentRoot.Get (webAppSettings);
		BuildFolderPath (fProjectFolderPath, webFolderPath, fWebFolderPath);
		fIndexPageName = RIASettingsKeys::WebApp::directoryIndex.Get (webAppSettings);

		XBOX::QuickReleaseRefCountable (webAppSettings);
	}

	/* Resources settings */
	LoadResourcesSettingsFromBag( *inBag);

	/* Virtual Folders settings */
	LoadVirtualFoldersSettingsFromBag( *inBag);

	Tell_SettingsChanged();

	return XBOX::VE_OK;
}