void TrimUniChar (XBOX::VString& ioString, const UniChar inCharToTrim)
{
	if (ioString.GetLength() > 0)
	{
		sLONG			length = ioString.GetLength();
		UniChar *		data = (UniChar *)ioString.GetCPointer();
		XBOX::VIndex	leadingChars = 0;
		XBOX::VIndex	endingChars = 0;

		for (UniChar *p = data, *end = (data + length); (p != end) && (*p == inCharToTrim); p++, leadingChars++);
		for (UniChar *p = (data + length - 1), *start = (data - 1); (p != start) && (*p == inCharToTrim); p--, endingChars++);

		if ((0 != leadingChars) || (0 != endingChars))
		{
			if ((leadingChars + endingChars) >= length)
			{
				ioString.Clear();
			}
			else
			{
				ioString.SubString (leadingChars + 1, length - leadingChars - endingChars);
			}
		}
	}
}
void GetSubString (const XBOX::VString& inString, sLONG inFirst, sLONG inLast, XBOX::VString& outString)
{
	if (testAssert ((inFirst >= 0) && (inLast < inString.GetLength())))
		outString.FromBlock (inString.GetCPointer() + inFirst, (inLast - inFirst + 1) * sizeof(UniChar), XBOX::VTC_UTF_16);
	else
		outString.Clear();
}
static
void GetFormatedDateTimeString (const XBOX::VTime& inTime, XBOX::VString &outDateTimeString)
{
	sLONG8 ms = inTime.GetMilliseconds() - (inTime.GetJulianDay() * 24 * 60 * 60 * 1000);

	outDateTimeString.Clear();
	outDateTimeString.Printf ("D%04d%02d%02dT%08d",
		inTime.GetLocalYear(),
		inTime.GetLocalMonth(),
		inTime.GetLocalDay(),
		ms);
}
void MakeHostString (const XBOX::VString& inHost, PortNumber inPort, XBOX::VString& outHostString)
{
	outHostString.Clear();

	if (!inHost.IsEmpty())
		outHostString.AppendString (inHost);

	if (inPort != DEFAULT_LISTENING_PORT)
	{
		outHostString.AppendUniChar (CHAR_COLON);
		outHostString.AppendLong (inPort);
	}
}
void MakeIPv4AddressString (IP4 inIPv4, XBOX::VString& outIPv4String)
{
	struct in_addr	addr = {0};
	char *			buffer = NULL;

	addr.s_addr = htonl (inIPv4);
	buffer = inet_ntoa (addr);

	if (NULL != buffer)
		outIPv4String.AppendCString (buffer);
	else
		outIPv4String.Clear();
}
void VHTTPServerLog::_GetCurrentFormatedTime (XBOX::VString& outTimeString, bool inLocalTime)
{
	sWORD		year, month, day, hour, minute, seconds, milliseconds;
	XBOX::VTime	time;
	
	time.FromSystemTime();	// GMT time
	if (inLocalTime)
		time.GetLocalTime (year, month, day, hour, minute, seconds, milliseconds);
	else
		time.GetUTCTime (year, month, day, hour, minute, seconds, milliseconds);
	
	outTimeString.Clear();
	outTimeString.Printf ("%02d:%02d:%02d", hour, minute, seconds);
}
void VHTTPServerLog::_GetCurrentFormatedDate (XBOX::VString& outDateString, bool inLocalTime, const char inDateSeparator)
{
	sWORD		year, month, day, hour, minute, seconds, milliseconds;
	XBOX::VTime	time;
	
	time.FromSystemTime();	// GMT time
	if (inLocalTime)
		time.GetLocalTime (year, month, day, hour, minute, seconds, milliseconds);
	else
		time.GetUTCTime (year, month, day, hour, minute, seconds, milliseconds);
	
	outDateString.Clear();
	outDateString.Printf ("%04d%c%02d%c%02d %02d:%02d:%02d",	year, inDateSeparator,
																month, inDateSeparator, day,
																hour, minute, seconds);
}
void GetLogTokenNamesList (const VectorOfLogToken& inLogTokens, XBOX::VString& outTokenNames, const UniChar inSeparator)
{
	XBOX::VString						string;
	VectorOfLogToken::const_iterator	nextToken = inLogTokens.begin();

	outTokenNames.Clear();

	for (VectorOfLogToken::const_iterator it = inLogTokens.begin(); it != inLogTokens.end(); ++it)
	{
		GetLogTokenName (*it, string);
		outTokenNames.AppendString (string);
		nextToken = it; 
		if (++nextToken != inLogTokens.end())
			outTokenNames.AppendUniChar (CHAR_SPACE);
	}
}
void VProjectItemFile::GetDescription( XBOX::VString& outDescription) const
{
	outDescription.Clear();

	if (fOwner != NULL)
	{
		VString extension;
		fOwner->GetExtension( extension);

		VFileKind *itemKind = VFileKindManager::Get()->RetainFirstFileKindMatchingWithExtension( extension);
		if (itemKind != NULL)
		{
			outDescription = itemKind->GetDescription();
			ReleaseRefCountable( &itemKind);
		}
	}
}
Пример #10
0
BEGIN_TOOLBOX_NAMESPACE
USING_TOOLBOX_NAMESPACE


//--------------------------------------------------------------------------------------------------


static
void _GetRFC1123DateString (const XBOX::VTime& inDate, XBOX::VString& outString)
{
	sWORD year, month, day, hour, minute, second, millisecond;
	inDate.GetUTCTime (year, month, day, hour, minute, second, millisecond);

	outString.Clear();

	switch (inDate.GetWeekDay())
	{
	case 0:		outString.AppendCString ("Sun");	break;
	case 1:		outString.AppendCString ("Mon");	break;
	case 2:		outString.AppendCString ("Tue");	break;
	case 3:		outString.AppendCString ("Wed");	break;
	case 4:		outString.AppendCString ("Thu");	break;
	case 5:		outString.AppendCString ("Fri");	break;
	case 6:		outString.AppendCString ("Sat");	break;
	}

	outString.AppendPrintf (", %02d-", day);

	switch (month)
	{
	case 1:		outString.AppendCString ("Jan");	break;
	case 2:		outString.AppendCString ("Feb");	break;
	case 3:		outString.AppendCString ("Mar");	break;
	case 4:		outString.AppendCString ("Apr");	break;
	case 5:		outString.AppendCString ("May");	break;
	case 6:		outString.AppendCString ("Jun");	break;
	case 7:		outString.AppendCString ("Jul");	break;
	case 8:		outString.AppendCString ("Aug");	break;
	case 9:		outString.AppendCString ("Sep");	break;
	case 10:	outString.AppendCString ("Oct");	break;
	case 11:	outString.AppendCString ("Nov");	break;
	case 12:	outString.AppendCString ("Dec");	break;
	}

	outString.AppendPrintf ("-%04d %02d:%02d:%02d GMT", year, hour, minute, second);
}
void VHTTPServerLog::_MakeDateString (const XBOX::VTime& inTime, XBOX::VString& outDateString)
{
	/*	See description: http://httpd.apache.org/docs/2.2/logs.html#common

	[day/month/year:hour:minute:second zone]
	day = 2*digit
	month = 3*letter
	year = 4*digit
	hour = 2*digit
	minute = 2*digit
	second = 2*digit
	zone = (`+' | `-') 4*digit
	*/

	sWORD			year = 0, month = 0, day = 0, hour = 0, minute = 0, seconds = 0, milliseconds = 0;
	static sLONG	sGMTOffSet = 0;
	static bool		sGMTOffSetUndefined = true;

	inTime.GetUTCTime (year, month, day, hour, minute, seconds, milliseconds);

	if (sGMTOffSetUndefined)
	{
		sGMTOffSet = (XBOX::VSystem::GetGMTOffset (true) / (3600));
		sGMTOffSetUndefined = false;
	}

	outDateString.Clear();
	outDateString.Printf (	"%02d/%s/%04d:%02d:%02d:%02d %c%02ld00",
		day,
		CONST_ABBREVIATED_ENGLISH_MONTH_NAMES[month],
		year,
		hour,
		minute,
		seconds,
		(sGMTOffSet >= 0) ? '+' : '-',
		sGMTOffSet);
}
XBOX::VError VHTTPServerLog::_WriteWLF_ELF (const IHTTPResponse& inHTTPResponse)
{
	XBOX::VString				string;
	XBOX::VString				ipAddress;
	const VectorOfLogToken		tokens = fSettings.GetLogTokens();
	const EHTTPServerLogFormat	format = fSettings.GetLogFormat();

	for (VectorOfLogToken::const_iterator it = tokens.begin(); it != tokens.end(); ++it)
	{
		switch (*it)
		{
			case LOG_TOKEN_DATE:
				string.Clear();
				if (format == LOG_FORMAT_ELF)
				{
					_GetCurrentFormatedDate (string, false);
				}
				else
				{
					_GetCurrentFormatedDate (string, true, HTTP_SOLIDUS);
				}

				if (!string.IsEmpty())
				{
					fRequestsBuffer.AppendString (string);					
				}
				else
				{
					fRequestsBuffer.AppendUniChar (CHAR_HYPHEN_MINUS);
				}
				break;

			case LOG_TOKEN_TIME:
				string.Clear();
				if (format == LOG_FORMAT_WLF)
					_GetCurrentFormatedTime (string, true);				
				else
					_GetCurrentFormatedTime (string, false);
				fRequestsBuffer.AppendString (string);	
				break;

			case LOG_TOKEN_STATUS:
				string.FromLong ((sLONG)inHTTPResponse.GetResponseStatusCode());
				fRequestsBuffer.AppendString (string);
				break;

			case LOG_TOKEN_ELF_S_IP:
				string.Clear();
				HTTPServerTools::MakeIPv4String (inHTTPResponse.GetIPv4(), string);
				fRequestsBuffer.AppendString (string);
				break;

			case LOG_TOKEN_HOST_NAME:	//	= C_DNS .....
			case LOG_TOKEN_ELF_C_DNS:	//	DNS lookup : tres couteux en perf : remplacé par l'IP du client (les analyseurs de log font le DNS lookup)...
			case LOG_TOKEN_ELF_C_IP:	//	Client IP Address 192.0.1.3
				string.Clear();
				HTTPServerTools::MakeIPv4String (inHTTPResponse.GetIPv4(), string);
				fRequestsBuffer.AppendString (string);
				break;

			case LOG_TOKEN_METHOD:	// The HTTP method : GET HEAD POST. If Unknown, we just copy it
				string.Clear();
				HTTPProtocol::MakeHTTPMethodString (inHTTPResponse.GetRequest().GetRequestMethod(), string);
				fRequestsBuffer.AppendString (string);
				break;

			case LOG_TOKEN_BYTES_SENT:	//WLF : Bytes sent to the client : = HTTP Content Length
				string.Clear();
				if (inHTTPResponse.GetResponseHeader (STRING_HEADER_CONTENT_LENGTH, string) && !string.IsEmpty())
					fRequestsBuffer.AppendString (string);
				else
					fRequestsBuffer.AppendUniChar (CHAR_DIGIT_ZERO);
				break;

			case LOG_TOKEN_AGENT:	// The identity of the browser software or other client. Mozilla/4.04_(Macintosh;_U;_PPC)
				string.Clear();
				if (inHTTPResponse.GetRequest().GetHTTPHeaders().GetHeaderValue (STRING_HEADER_USER_AGENT, string) && !string.IsEmpty())
				{
					string.Exchange (CHAR_SPACE, CHAR_LOW_LINE);
					fRequestsBuffer.AppendString (string);
				}
				else
				{
					fRequestsBuffer.AppendUniChar (CHAR_HYPHEN_MINUS);
				}
				break;

			case LOG_TOKEN_CS_USER_AGENT:	// HTTP request's "User-Agent" header field. "Mozilla/4.04 (Macintosh; U; PPC)"
				string.Clear();
				inHTTPResponse.GetRequest().GetHTTPHeaders().GetHeaderValue (STRING_HEADER_USER_AGENT, string);
				fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
				fRequestsBuffer.AppendString (string);
				fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
				break;

			case LOG_TOKEN_USER:	//The User Name if there was a Web User entry for a realm.
				string.Clear();
				inHTTPResponse.GetRequest().GetAuthenticationInfos()->GetUserName (string);
				_WriteUsername (string, fRequestsBuffer);
				break;

			case LOG_TOKEN_REFERER: //HTTP request's "Referer" header field, sending  the URL that referred to the current page. www.google.com
				string.Clear();
				inHTTPResponse.GetRequest().GetHTTPHeaders().GetHeaderValue (STRING_HEADER_REFERER, string);
				if (!string.IsEmpty())
					fRequestsBuffer.AppendString (string);
				else
					fRequestsBuffer.AppendUniChar (CHAR_HYPHEN_MINUS);
				break;

			case LOG_TOKEN_CS_REFERER:	//HTTP request's "Referer" header field, sending  the URL that referred to the current page.  www.google.com
				string.Clear();
				inHTTPResponse.GetRequest().GetHTTPHeaders().GetHeaderValue (STRING_HEADER_REFERER, string);
				fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
				fRequestsBuffer.AppendString (string);
				fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
				break;

			case LOG_TOKEN_ELF_CS_HOST: // = LOG_TOKEN_HOSTFIELD. The "HOST" field of the HTTP request
				fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
				fRequestsBuffer.AppendString (inHTTPResponse.GetRequest().GetHost());
				fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
				break;

			case LOG_TOKEN_ELF_URI:
				string.FromString (inHTTPResponse.GetRequest().GetURL());
				if (!string.IsEmpty())
					fRequestsBuffer.AppendString (string);
				else
					fRequestsBuffer.AppendUniChar (CHAR_HYPHEN_MINUS);
				break;

			case LOG_TOKEN_URL:
			case LOG_TOKEN_ELF_CS_URI_STEM:	//	Path portion of the HTTP request. "/status/stat.html"
				string.FromString (inHTTPResponse.GetRequest().GetURLPath());
				if (!string.IsEmpty())
					fRequestsBuffer.AppendString (string);
				else
					fRequestsBuffer.AppendUniChar (CHAR_HYPHEN_MINUS);
				break;

			case LOG_TOKEN_SEARCH_ARGS:	//	The search arguments to the URL (text after a question  mark)
				string.FromString (inHTTPResponse.GetRequest().GetURLQuery());
				fRequestsBuffer.AppendString (string);
				break;

			case LOG_TOKEN_ELF_CS_URI_QUERY:	// 	Search argument portion of the HTTP request. "first=last&last=first"
				string.FromString (inHTTPResponse.GetRequest().GetURLQuery());
				if (!string.IsEmpty())
					fRequestsBuffer.AppendString (string);
				else
					fRequestsBuffer.AppendUniChar (CHAR_HYPHEN_MINUS);
				break;

			case LOG_TOKEN_CONNECTION_ID:	// A number that is unique for each connection for this invocation of the server. Typically socket number.
			{
				sLONG rawSocket = inHTTPResponse.GetRawSocket();
				if (rawSocket > 0)
				{
					fRequestsBuffer.AppendLong (rawSocket);
				}
				else
				{
					fRequestsBuffer.AppendUniChar (CHAR_HYPHEN_MINUS);
				}
				break;
			}
			case LOG_TOKEN_ELF_CS_COOKIE:	// The "cookie" information sent in this request "Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 20-Jan-05 23:12:40 GMT"
				string.Clear();
				inHTTPResponse.GetRequest().GetHTTPHeaders().GetHeaderValue (STRING_HEADER_COOKIE, string);
				fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
				fRequestsBuffer.AppendString (string);
				fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
				break;

			case LOG_TOKEN_TRANSFER_TIME:	// Time-Taken in millisecond like IIS
			{
				uLONG timeTaken = (XBOX::VSystem::GetCurrentTime() - inHTTPResponse.GetStartRequestTime());
				fRequestsBuffer.AppendLong (timeTaken);
				break;
			}
			case LOG_TOKEN_WLF_BYTES_RECEIVED:
			{
				sLONG8 bytesReceived = inHTTPResponse.GetRequest().GetRequestBody().GetDataSize();
				if (bytesReceived > 0)
				{
					fRequestsBuffer.AppendLong8 (bytesReceived);
				}
				else
				{
					fRequestsBuffer.AppendUniChar (CHAR_DIGIT_ZERO);
				}
				break;
			}

			case LOG_TOKEN_PATH_ARGS: //The path arguments to the URL for a CGI (the text after a dollar sign)
			{
				sLONG			posChar = 0;
				XBOX::VString	pathArgString;
				
				string.FromString (inHTTPResponse.GetRequest().GetURL());

				if (!string.IsEmpty() && (posChar = string.FindUniChar (CHAR_DOLLAR_SIGN)) > 0)
				{
					// Let's delete all the stuff before '$'
					string.GetSubString (posChar + 1, string.GetLength() - posChar, pathArgString);

					// We delete the query arguments after the ? : we only want the string after the '$'
					if ((posChar = pathArgString.FindUniChar (CHAR_QUESTION_MARK)) > 0)
						pathArgString.SubString (1, posChar - 1);
				}

				if (!pathArgString.IsEmpty())
				{
					fRequestsBuffer.AppendString (pathArgString);
				}
				else
				{
					fRequestsBuffer.AppendUniChar (CHAR_HYPHEN_MINUS);
				}
				break;
			}

			default:	// this should never happen.
				assert (false);
				fRequestsBuffer.AppendCString ("UNKNOWN_FIELD"); 
				break;
		}

		VectorOfLogToken::const_iterator nextToken = it;
		if (++nextToken != tokens.end())
			fRequestsBuffer.AppendUniChar (CHAR_SPACE);
	}

	fRequestsBuffer.AppendUniChar (HTTP_LF);

	return XBOX::VE_OK;
}
XBOX::VError VHTTPServerLog::_WriteCLF_DLF (const IHTTPResponse& inHTTPResponse)
{
	XBOX::VString	string;
	XBOX::VTime		time;

	// GMT time
	time.FromSystemTime();

	// Client IP address
	HTTPServerTools::MakeIPv4String (inHTTPResponse.GetIPv4(), string);
	fRequestsBuffer.AppendString (string);
	fRequestsBuffer.AppendUniChar (CHAR_SPACE);
	
	// RFC931
	fRequestsBuffer.AppendUniChar (CHAR_HYPHEN_MINUS);
	fRequestsBuffer.AppendUniChar (CHAR_SPACE);
	
	// AuthUser
	XBOX::VString userName;
	inHTTPResponse.GetRequest().GetAuthenticationInfos()->GetUserName (userName);
	
	if (userName.IsEmpty())
		fRequestsBuffer.AppendUniChar (CHAR_HYPHEN_MINUS);
	else
		fRequestsBuffer.AppendString (userName);
	fRequestsBuffer.AppendUniChar (CHAR_SPACE);

	// Date & Time
	string.Clear();
	_MakeDateString (time, string);

	fRequestsBuffer.AppendUniChar (CHAR_LEFT_SQUARE_BRACKET);
	fRequestsBuffer.AppendString (string);
	fRequestsBuffer.AppendUniChar (CHAR_RIGHT_SQUARE_BRACKET);
	fRequestsBuffer.AppendUniChar (CHAR_SPACE);

	// HTTP Request
	fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
	fRequestsBuffer.AppendString (inHTTPResponse.GetRequest().GetRequestLine());
	fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
	fRequestsBuffer.AppendUniChar (CHAR_SPACE);
	
	// HTTP Status
	string.Clear();
	string.FromLong ((sLONG)inHTTPResponse.GetResponseStatusCode());
	fRequestsBuffer.AppendString (string);
	fRequestsBuffer.AppendUniChar (CHAR_SPACE);

	// HTTP Content Length
	string.Clear();
	if (!inHTTPResponse.GetResponseHeader (STRING_HEADER_CONTENT_LENGTH, string) || string.IsEmpty())
		string.FromLong(0);
	fRequestsBuffer.AppendString (string);
	
	// We add the last fields for the DLF log format
	if (fSettings.GetLogFormat() == LOG_FORMAT_DLF)
	{	
		// HTTP Referrer
		string.Clear();
		fRequestsBuffer.AppendUniChar (CHAR_SPACE);
		inHTTPResponse.GetRequest().GetHTTPHeaders().GetHeaderValue (STRING_HEADER_REFERER, string);
		fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
		fRequestsBuffer.AppendString (string);
		fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
		fRequestsBuffer.AppendUniChar (CHAR_SPACE);
		
		// HTTP User-Agent
		string.Clear();
		inHTTPResponse.GetRequest().GetHTTPHeaders().GetHeaderValue (STRING_HEADER_USER_AGENT, string);
		fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
		fRequestsBuffer.AppendString (string);
		fRequestsBuffer.AppendUniChar (CHAR_QUOTATION_MARK);
	}

	fRequestsBuffer.AppendUniChar (HTTP_LF);

	return XBOX::VE_OK;
}
Пример #14
0
//ACI0078887 23rd Nov 2012, O.R., always specify folder used for computing relative path of entry in TOC
VError VArchiveStream::_WriteCatalog( const VFile* inFile, const XBOX::VFilePath& inSourceFolder,const VString &inExtraInfo, uLONG8 &ioTotalByteCount )
{
	VString fileInfo;
	VStr8 slash("/");
	VStr8 extra("::");
	VStr8 folderSep(XBOX::FOLDER_SEPARATOR);
	VError result = VE_INVALID_PARAMETER;
	XBOX::VString savedExtraInfo = inExtraInfo;

	//ACI0078887 23rd Nov 2012, O.R., compute relative path using the specified source folder
	//don't assume that extra info carries relative folder info
		//ACI0078887 23rd Nov 2012, O.R., compute relative path using the specified source folder
	//don't assume that extra info carries relative folder info
	if (savedExtraInfo == PRESERVE_PARENT_OPTION)
	{
		//this is a bogus extra info that we use internally so we need to clear it so that it is not saved into
		//the archive.
		//This options means that the file will have to be restored in with its parent directory preserved.
		savedExtraInfo.Clear();

		VFolder *folder = inFile->RetainParentFolder();
		VString fileName;
		folder->GetName(fileInfo);
		// folder name can be a drive letter like Z:
		fileInfo.Exchange( (UniChar) ':', (UniChar) '_');
		inFile->GetName(fileName);
		fileInfo += slash;
		fileInfo += fileName;
		fileInfo.Insert( slash, 1 );
		folder->Release();
		result  = VE_OK;
	}
	else
	{
		if(testAssert(inFile->GetPath().GetRelativePath(inSourceFolder,fileInfo)))
		{
			result  = VE_OK;
			fileInfo.Insert( FOLDER_SEPARATOR, 1);
		}
	}

	if(result == VE_OK)
	{
		fileInfo.Exchange(folderSep ,slash, 1, 255);
		if ( fileInfo.GetUniChar(1) == '/' )
			fileInfo.Insert( '.', 1 );

		fileInfo += extra;
		fileInfo += savedExtraInfo;
		result = fStream->PutLong('file');
		if ( result == VE_OK )
		{
			result = fileInfo.WriteToStream(fStream);
		}
		if ( result == VE_OK )
		{
			sLONG8 fileSize = 0;
			inFile->GetSize(&fileSize);
			fStream->PutLong8(fileSize);
			ioTotalByteCount += fileSize;
	#if VERSIONWIN || VERSION_LINUX
			/* rez file size */
			fStream->PutLong8(0);
			/* no file kind or creator under Windows */
			fStream->PutLong(0); /* kind */
			fStream->PutLong(0); /* creator */
	#elif VERSIONMAC
			inFile->GetResourceForkSize(&fileSize);
			fStream->PutLong8(fileSize);
			ioTotalByteCount += fileSize;

			OsType osType;
			inFile->MAC_GetKind( &osType );
			result = fStream->PutLong( osType );
			inFile->MAC_GetCreator( &osType );
			result = fStream->PutLong( osType );
	#endif
		}
	}
	return result;
}
XBOX::VError VHTTPServerProjectSettings::SaveToBag (XBOX::VValueBag *outBag)
{
	if (NULL == outBag)
		return XBOX::VE_INVALID_PARAMETER;

	XBOX::VValueBag *projectSettings = new XBOX::VValueBag ();
	if (projectSettings)
	{
		XBOX::VString	ipString;
		XBOX::VString	authTypeString;

#if WITH_DEPRECATED_IPV4_API
		ServerNetTools::GetIPAdress (fListeningAddress, ipString);
#else
		ipString.FromString (fListeningAddress);
#endif
		HTTPServerTools::GetAuthenticationMethodName (fAuthType, authTypeString);

		projectSettings->SetLong (RIASettingsKeys::Project::refCount, GetRefCount());
		projectSettings->SetString (RIASettingsKeys::Project::listen, ipString);
		projectSettings->SetString (RIASettingsKeys::Project::hostName, fHostName);
#if HTTP_SERVER_USE_PROJECT_PATTERNS
		projectSettings->SetString (RIASettingsKeys::Project::pattern, fProjectPattern);
#endif
		projectSettings->SetString (RIASettingsKeys::Project::realm, fRealm);
		projectSettings->SetString (RIASettingsKeys::Project::authType, authTypeString);
		outBag->AddElement (RIASettingsKeys::Project::kXmlElement, projectSettings);
		XBOX::ReleaseRefCountable (&projectSettings);
	}

	XBOX::VValueBag *httpSettings = new XBOX::VValueBag ();
	if (httpSettings)
	{
		XBOX::VString posixPath;

		httpSettings->SetLong (RIASettingsKeys::HTTP::port, fPort);
		httpSettings->SetBool (RIASettingsKeys::HTTP::allowSSL, fAllowSSL);
		httpSettings->SetBool (RIASettingsKeys::HTTP::SSLMandatory, fSSLMandatory);
		httpSettings->SetLong (RIASettingsKeys::HTTP::SSLPort, fSSLPort);

		if (fSSLCertificatesFolderPath.IsValid())
		{
			fSSLCertificatesFolderPath.GetPosixPath (posixPath);
			httpSettings->SetString (RIASettingsKeys::HTTP::SSLCertificatePath, posixPath);
		}

		XBOX::VString charSetName;
		VTextConverters::Get()->GetNameFromCharSet (fDefaultCharSet, charSetName);
		httpSettings->SetString (RIASettingsKeys::HTTP::standardSet, charSetName);

		/* cache settings */
		httpSettings->SetBool (RIASettingsKeys::HTTP::useCache, fEnableCache);
		httpSettings->SetLong (RIASettingsKeys::HTTP::pageCacheSize, fCacheMaxSize);
		httpSettings->SetLong (RIASettingsKeys::HTTP::cachedObjectMaxSize, fCachedObjectMaxSize);

		/* compression settings */
		httpSettings->SetBool (RIASettingsKeys::HTTP::allowCompression, fEnableCompression);
		httpSettings->SetLong (RIASettingsKeys::HTTP::compressionMinThreshold, fCompressionMinThreshold);
		httpSettings->SetLong (RIASettingsKeys::HTTP::compressionMaxThreshold, fCompressionMaxThreshold);

		/* Keep-Alive settings */
		httpSettings->SetBool (RIASettingsKeys::HTTP::acceptKeepAliveConnections, fEnableKeepAlive);
		httpSettings->SetLong (RIASettingsKeys::HTTP::maximumTimeout, fKeepAliveTimeout);
		httpSettings->SetLong (RIASettingsKeys::HTTP::maximumRequestsByConnection, fKeepAliveMaxConnections);

		/* Log settings */
		XBOX::VString logFormatName;
		HTTPServerTools::GetLogFormatName ((EHTTPServerLogFormat)fLogFormat, logFormatName);
		posixPath.Clear();
		fLogFolderPath.GetPosixPath (posixPath);
		httpSettings->SetString (RIASettingsKeys::HTTP::logFormat, logFormatName);
		httpSettings->SetString (RIASettingsKeys::HTTP::logPath, posixPath);
		httpSettings->SetString (RIASettingsKeys::HTTP::logFileName, fLogFileName);
		httpSettings->SetLong (RIASettingsKeys::HTTP::logMaxSize, GetLogMaxSize());

		/* Log Tokens settings */
		XBOX::VBagArray *logTokenSettings = new XBOX::VBagArray ();
		if (NULL != logTokenSettings)
		{
			XBOX::VTaskLock lock (&fLogTokensVectorLock);
			XBOX::VString	tokenName;

			for (VectorOfLogToken::const_iterator it = fLogTokensVector.begin(); it != fLogTokensVector.end(); ++it)
			{
				XBOX::VValueBag *bag = new XBOX::VValueBag ();
				if (NULL != bag)
				{
					HTTPServerTools::GetLogTokenName (*it, tokenName);
					bag->SetString (RIASettingsKeys::HTTP::Log::field, tokenName);
					logTokenSettings->AddTail (bag);
					bag->Release();
				}
			}

			if (logTokenSettings->GetCount())
				httpSettings->SetElements (RIASettingsKeys::HTTP::Log::kXmlElement, logTokenSettings);

			XBOX::ReleaseRefCountable (&logTokenSettings);
		}

		outBag->AddElement (RIASettingsKeys::HTTP::kXmlElement, httpSettings);
		XBOX::ReleaseRefCountable (&httpSettings);
	}

	/* Web App settings */
	XBOX::VValueBag *webAppSettings = new XBOX::VValueBag ();
	if (webAppSettings)
	{
		XBOX::VString posixPath;
		fWebFolderPath.GetPosixPath (posixPath);
		webAppSettings->SetString (RIASettingsKeys::WebApp::documentRoot, posixPath);
		webAppSettings->SetString (RIASettingsKeys::WebApp::directoryIndex, fIndexPageName);

		outBag->AddElement (RIASettingsKeys::WebApp::kXmlElement, webAppSettings);
		XBOX::ReleaseRefCountable (&webAppSettings);
	}

	/* Resources settings */
	XBOX::VBagArray *resourcesSettings = new XBOX::VBagArray ();
	if (resourcesSettings)
	{
		XBOX::VTaskLock lock (&fResourcesVectorLock);

		for (VHTTPResourcesVector::const_iterator it = fResourcesVector.begin(); it != fResourcesVector.end(); ++it)
		{
			if (!it->IsNull())
			{
				XBOX::VValueBag *bag = new XBOX::VValueBag ();
				if (bag)
				{
					(*it)->SaveToBag (*bag);
					resourcesSettings->AddTail (bag);
					bag->Release();
				}
			}
		}

		if (resourcesSettings->GetCount())
			outBag->SetElements (RIASettingsKeys::Resources::kXmlElement, resourcesSettings);

		XBOX::ReleaseRefCountable (&resourcesSettings);
	}

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

	return XBOX::VE_OK;
}
Пример #16
0
XBOX::VError VRPCService::GetProxy( XBOX::VString& outProxy, const XBOX::VString& inModulePath, const XBOX::VString& inNamespace, const IHTTPRequest* inRequest, IHTTPResponse* inResponse)
{
	VError err = VE_OK;

	outProxy.Clear();

	if (fApplication != NULL)
	{
		VRIAContext *riaContext = fApplication->RetainNewContext( err);
		if (err == VE_OK)
		{
			VRPCCatalog *catalog = fApplication->RetainRPCCatalog( riaContext, &err, inRequest, inResponse);
			if (err == VE_OK)
			{
				if (catalog != NULL)
				{
					MapOfRPCSchema schemas;

					err = catalog->RetainSchemasByModule( inModulePath, schemas);
					if (err == VE_OK)
					{
						// Build the proxy
						VFile *bodyFile = NULL, *templateFile = NULL;
						VFilePath path;

						VRIAServerApplication::Get()->GetWAFrameworkFolderPath( path);
						path.ToSubFolder( L"Core").ToSubFolder( L"Runtime").ToSubFolder( L"rpcService");
						path.SetFileName( L"proxy-body.js", true);

						bodyFile = new VFile( path);
						if (bodyFile == NULL)
							err = vThrowError( VE_MEMORY_FULL);
						
						if (err == VE_OK)
						{
							path.SetFileName( L"proxy-template.js", true);
							templateFile = new VFile( path);
							if (templateFile == NULL)
								err = vThrowError( VE_MEMORY_FULL);
						}
						
						if (err == VE_OK && bodyFile->Exists() && templateFile->Exists())
						{
							VString templateString;
							VFileStream bodyStream( bodyFile);
							VFileStream templateStream( templateFile);
							
							err = bodyStream.OpenReading();
							if (err == VE_OK)
								templateStream.OpenReading();
							if (err == VE_OK)
								err = bodyStream.GetText( outProxy);
							if (err == VE_OK)
							{
								VValueBag bag;
								bag.SetString( L"rpc-pattern", fPatternForMethods);
								bag.SetString( L"publishInGlobalNamespace", (fPublishInClientGlobalNamespace) ? L"true" : L"false");
								outProxy.Format( &bag);
							}
							if (err == VE_OK)
								err = templateStream.GetText( templateString);
							if (err == VE_OK)
							{
								if (templateString.BeginsWith( L"/*"))
								{
									// sc 28/08/2014, remove the copyright
									VIndex end = templateString.Find( L"*/");
									if (end > 0)
									{
										templateString.Remove( 1, end + 1);
									}
								}

								for (MapOfRPCSchema::const_iterator iter = schemas.begin() ; iter != schemas.end() ; ++iter)
								{
									VValueBag bag;
									bag.SetString( L"function-name", iter->first.GetMethodName());
									bag.SetString( L"namespace", inNamespace);
									bag.SetString( L"modulePath", inModulePath);
									VString proxy( templateString);
									proxy.Format( &bag);
									outProxy.AppendString( proxy);
								}
							}

							bodyStream.CloseReading();
							templateStream.CloseReading();
						}
						else
						{
							err = vThrowError( VE_FILE_NOT_FOUND);
						}

						QuickReleaseRefCountable( bodyFile);
						QuickReleaseRefCountable( templateFile);
					}
				}
				else
				{
					err = vThrowError( VE_RIA_RPC_CATALOG_NOT_FOUND);
				}
			}
		}
		ReleaseRefCountable( &riaContext);
	}

	return err;	
}