bool VHTTPResponse::IsCookieSet (const VHTTPCookie& inCookie) const
{
	XBOX::VectorOfVString	cookieValues;
	
	if (GetHeaders().GetHeaderValues (HEADER_SET_COOKIE, cookieValues))
	{
		XBOX::VString cookieName (inCookie.GetName());
		cookieName.AppendUniChar (CHAR_EQUALS_SIGN);
		
		for (XBOX::VectorOfVString::const_iterator it = cookieValues.begin(); it != cookieValues.end(); ++it)
		{
			XBOX::VectorOfVString multipleCookieValues;

			(*it).GetSubStrings (CHAR_SEMICOLON, multipleCookieValues, false, true);

			XBOX::VectorOfVString::const_iterator found = std::find_if (multipleCookieValues.begin(), multipleCookieValues.end(), FindVStringFunctor (cookieName));
			if (found != multipleCookieValues.end())
			{
				VHTTPCookie cookie (*found);
				if (cookie == inCookie)
					return true;
			}
		}
	}

	return false;
}
void VRemoteDebugPilot::RemoveContext(std::map< OpaqueDebuggerContext, VContextDescriptor* >::iterator& inCtxIt)
{
	XBOX::VError			err;
	XBOX::VString			resp;

	if (fState != STOPPED_STATE)
	{
		// ctx could already have been removed by ABORT
		if (inCtxIt != fContextArray.end())
		{
			if ((*inCtxIt).second->fPage)
			{
				ReleaseRefCountable(&(*inCtxIt).second->fPage);
			}

			if (fState == CONNECTED_STATE)
			{
				resp = CVSTR("{\"method\":\"removeContext\",\"contextId\":\"");
				resp.AppendLong8((sLONG8)((*inCtxIt).first));
				resp += CVSTR("\",\"id\":\"");
				resp += fClientId;
				resp += CVSTR("\"}");
				err = SendToBrowser( resp );
				if (err)
				{
					fWS->Close();
					fState = DISCONNECTING_STATE;
				}
			}
			inCtxIt->second->Release();
			fContextArray.erase(inCtxIt);
		}
	}
}
void GetIPv4FromString (const XBOX::VString& inIPv4String, IP4& outIPv4)
{
	sLONG	hostNameSize = inIPv4String.GetLength() + 1;
	char *	hostName = new char[hostNameSize];

	outIPv4 = INADDR_NONE;
	if (NULL != hostName)
	{
		struct hostent *	remoteHost = NULL;
		struct in_addr		addr = {0};

		inIPv4String.ToCString (hostName, hostNameSize);

		if (isalpha (hostName[0]))	// host address is a name
		{
			remoteHost = gethostbyname (hostName);
		}
		else
		{
			addr.s_addr = inet_addr (hostName);
			if (addr.s_addr != INADDR_NONE)
				remoteHost = gethostbyaddr ((char *) &addr, 4, AF_INET);
		}

		if (NULL != remoteHost)
			outIPv4 = *((sLONG *)remoteHost->h_addr_list[0]);

		delete [] hostName;
	}
}
XBOX::VError VRemoteDebugPilot::SendContextToBrowser(
												std::map< OpaqueDebuggerContext,VContextDescriptor* >::iterator& inCtxIt)
{
	XBOX::VString				resp;
	XBOX::VString				brkptsStr;

	VChromeDebugHandler::GetJSONBreakpoints(brkptsStr);

	resp = CVSTR("{\"method\":\"updateContext\",\"contextId\":\"");
	resp.AppendLong8((sLONG8)(*inCtxIt).first);
	resp += CVSTR("\",\"debugLineNb\":");
	resp.AppendLong((*inCtxIt).second->fDebugInfos.fLineNb);
	resp += CVSTR(",\"debugFileName\":\"");
	resp += (*inCtxIt).second->fDebugInfos.fFileName;
	resp += CVSTR("\",\"debugReason\":\"");
	resp += (*inCtxIt).second->fDebugInfos.fReason;
	resp += CVSTR("\",\"debugComment\":\"");
	resp += (*inCtxIt).second->fDebugInfos.fComment;
	resp += CVSTR("\",\"sourceLine\":\"");
	resp += (*inCtxIt).second->fDebugInfos.fSourceLine;
	resp += CVSTR("\",\"id\":\"");
	resp += fClientId;
	resp += "\",\"breakpoints\":";
	resp += brkptsStr;
	resp += CVSTR("}");
	return SendToBrowser( resp );
}
IHTTPRequestHandler *VHTTPServerProject::RetainMatchingHTTPRequestHandler (const XBOX::VString& inURL)
{
	IHTTPRequestHandler *resultHandler = NULL;
	XBOX::VTaskLock		lock (&fRegexCacheLock);
	XBOX::VString		urlString (inURL);
/*
	// URL Start with project pattern ?
	if (!fSettings->GetProjectPattern().IsEmpty())
	{
		sLONG pos = HTTPServerTools::FindASCIIVString (urlString, fSettings->GetProjectPattern());
		if (pos == 2) // Takes the starting CHAR_SOLIDUS into account
			inURL.GetSubString (pos + fSettings->GetProjectPattern().GetLength(), inURL.GetLength() - fSettings->GetProjectPattern().GetLength() - 1, urlString);
	}
*/

	resultHandler = RetainProcessingHandler<IHTTPRequestHandler> (fRegexCache, urlString, false);

	/* YT 18-Jan-2012 - ACI0075015, ACI0074936 & ACI0074300
		When no requestHandler match and the URL ends by SOLIDUS '/', try to find a requestHandler matching the URL + 
		the index page name (typically for 4D: /index.shtml have to be handled by a specific requestHandler)
	*/
	if ((NULL == resultHandler) && (urlString.GetUniChar (urlString.GetLength()) == CHAR_SOLIDUS))
	{
		urlString.AppendString (fSettings->GetIndexPageName());

		resultHandler = RetainProcessingHandler<IHTTPRequestHandler> (fRegexCache, urlString, false);
	}

	return resultHandler;
}
XBOX::VJSObject VJSGlobalObject::Require (XBOX::VJSContext inContext, const XBOX::VString &inClassName)
{
	XBOX::VJSObject							object(inContext, NULL);
	VJSGlobalObject::SObjectMap::iterator	it;

	if ((it = fRequireMap.find(inClassName)) != fRequireMap.end()) {

		xbox_assert(it->second != NULL);
		object.SetObjectRef(it->second);

	} else {

		if (inClassName.EqualToString("net", true)) {

			VJSNetClass::Class();
			object = VJSNetClass::CreateInstance(inContext, NULL);

		} else if (inClassName.EqualToString("tls", true)) {

			VJSTLSClass::Class();
			object = VJSTLSClass::CreateInstance(inContext, NULL);

		}
 
		if (object.GetObjectRef() != NULL)

			fRequireMap[inClassName] = object.GetObjectRef();

	}

	return object;
}
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);
			}
		}
	}
}
sLONG GetLongFromString (const XBOX::VString& inString)		
{
	bool	isneg = false;		

	XBOX::VIndex sepPos = HTTPServerTools::FindASCIIVString (inString, XBOX::VIntlMgr::GetDefaultMgr()->GetDecimalSeparator());
	if (sepPos <= 0)
		sepPos = inString.GetLength();

	const UniChar* bb = inString.GetCPointer();
	sLONG result = 0;
	for (XBOX::VIndex i = 0; i < sepPos; ++i)
	{
		if ((0 == result) && (bb[i] == CHAR_HYPHEN_MINUS))
			isneg = true;
		if ((bb[i] < CHAR_DIGIT_ZERO) || (bb[i] > CHAR_DIGIT_NINE))
			continue;
		result *= 10;
		result += bb[i] - CHAR_DIGIT_ZERO;
	}

	if (isneg)
		result = -result;
	
	return result;
}
Ejemplo n.º 9
0
	bool HttpRequest::SetUserInfos(const XBOX::VString& inUser, const XBOX::VString& inPasswd, bool inAllowBasic)
	{
		if(!fHandle)
            return false;
		
		XBOX::VString userInfos;
		userInfos.AppendString(inUser).AppendCString(":").AppendString(inPasswd);
	
		int maxlen=2*userInfos.GetLength()+1;  //We convert utf16 to utf8, it should be large enough.
        char* buf=new char[maxlen];
		
        if(!buf)
            return false;
		
		int len=userInfos.ToBlock(buf, maxlen, XBOX::VTC_UTF_8, true, false);
		
		curl_easy_setopt(fHandle, CURLOPT_USERPWD, buf);
		
		delete buf;
		
		if(inAllowBasic)
			curl_easy_setopt(fHandle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST);
		else	
			curl_easy_setopt(fHandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
		
		return true;
	}
bool EndsWithASCIICString (const XBOX::VString& inText, const char *inPattern, bool isCaseSensitive)
{
	sLONG textSize = inText.GetLength();
	sLONG patternSize = (sLONG)strlen (inPattern);

	return (_FindASCIICString (inText.GetCPointer() + (textSize - patternSize), textSize, inPattern, patternSize, isCaseSensitive) == 1);
}
Ejemplo n.º 11
0
bool VJSStorageClass::_SetProperty (XBOX::VJSParms_setProperty &ioParms, VJSStorageObject *inStorageObject)
{
	xbox_assert(inStorageObject != NULL);
 
	XBOX::VString	name;

	if (!ioParms.GetPropertyName(name))

		return true;

	if (name.EqualToUSASCIICString("length")) 

		return true;

	sLONG	i;

	for (i = 0; i < kNumberMethods; i++)
	{
		if (name.EqualToUSASCIICString(kMethodNames[i]))

			return true;
	}
	inStorageObject->SetKeyValue(name, ioParms.GetPropertyValue());
	return true;
}
Ejemplo n.º 12
0
void VJSStorageClass::_HasProperty (XBOX::VJSParms_hasProperty &ioParms, VJSStorageObject *inStorageObject)
{
	xbox_assert(inStorageObject != NULL);

	XBOX::VString	name;

	if (!ioParms.GetPropertyName(name))

		ioParms.ReturnFalse();

	else {

		if (inStorageObject->HasKey(name)
		|| name.EqualToUSASCIICString("length"))

			ioParms.ReturnTrue();

		else {

			sLONG	i;
		
			for (i = 0; i < kNumberMethods; i++) 

				if (name.EqualToUSASCIICString(kMethodNames[i])) 

					ioParms.ReturnTrue();

			ioParms.ReturnFalse();

		}

	}
}
Ejemplo n.º 13
0
void VCacheLog::_FormatCurrentVTaskInfos(bool inForTags)
{
	XBOX::VString	taskName;
	char			nameCStr[256] = {0};

	VTask *currentTask = VTask::GetCurrent();
	currentTask->GetName(taskName);
	taskName.ToCString(nameCStr, 256);

	sLONG	pNum = 0;
	if(currentTask->GetKind() == '4dut')
		pNum = (sLONG) currentTask->GetKindData();

	/********* WARNING **********
	fVTaskInfos is char[512]. If you add more infos, think about increasing its size
	*/
	fVTaskInfos[0] = 0;
	if(inForTags)
	{
		sprintf(fVTaskInfos, "tname=\"%s\" pnum=\"%d\"", nameCStr, pNum);
	}
	else
	{
		sprintf(fVTaskInfos, "%s\t%d", nameCStr, pNum);
	}
}
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();
}
Ejemplo n.º 15
0
BOOL CALLBACK XWinFontMgr::EnumFamScreenCallBackEx(ENUMLOGFONTEX* pelf, NEWTEXTMETRICEX* /*lpntm*/, int FontType,LPVOID pThis)
{
    XBOX::VString fontName;
    fontName.FromCString((const char*)(pelf->elfFullName));
    ((XWinFontMgr *)pThis)->AddFont(fontName);

    return 1;
}
XBOX::VError VHTTPServerLog::_WriteFileHeader (XBOX::VString& ioBuffer)
{
	/*
		see: http://www.w3.org/TR/WD-logfile.html
	*/
	XBOX::VString	serverName;
	XBOX::VString	dateString;
	XBOX::VString	formatName;
	XBOX::VString	tokenNames;

	fNeedHeader = false;
	/*
		#Version: 1.0
		#Date: 12-Jan-1996 00:00:00
	*/
	HTTPProtocol::MakeServerString (serverName);
	_GetCurrentFormatedDate (dateString);
	HTTPServerTools::GetLogFormatName (fSettings.GetLogFormat(), formatName);
	HTTPServerTools::GetLogTokenNamesList (fSettings.GetLogTokens(), tokenNames);

	ioBuffer.AppendCString ("#Version: 1.0\n#Software: ");
	ioBuffer.AppendString (serverName);
	ioBuffer.AppendCString ("\n#Date: ");
	ioBuffer.AppendString (dateString);

	ioBuffer.AppendCString ("\n#Remark: format ");
	ioBuffer.AppendString (formatName);

	ioBuffer.AppendCString ("\n#Fields: ");
	ioBuffer.AppendString (tokenNames);

	ioBuffer.AppendUniChar (HTTP_LF);

	return XBOX::VE_OK;
}
void GetLogFormatName (const EHTTPServerLogFormat inLogFormat, XBOX::VString& outLogFormatName)
{
	switch (inLogFormat)
	{
		case LOG_FORMAT_WLF:		outLogFormatName.FromCString ("WLF");			break;
		case LOG_FORMAT_CLF:		outLogFormatName.FromCString ("CLF");			break;
		case LOG_FORMAT_ELF:		outLogFormatName.FromCString ("ELF");			break;
		case LOG_FORMAT_DLF:		outLogFormatName.FromCString ("DLF");			break;
		default:					outLogFormatName.FromCString ("Unknown");		break;
	}
}
Ejemplo n.º 18
0
    XBOX::VString VStringFromAsciiStdString(const std::string inStr)
    {
        const char* ptr=inStr.c_str();
        int len=inStr.length();

        XBOX::VString outStr;

        outStr.FromBlock(ptr, len, XBOX::VTC_US_ASCII);

        return outStr;
    }
void GetAuthenticationMethodName (const HTTPAuthenticationMethod inAuthenticationMethod, XBOX::VString& outAuthenticationMethodName)
{
	switch (inAuthenticationMethod)
	{
		case AUTH_BASIC:				outAuthenticationMethodName.FromCString ("Basic");			break;
		case AUTH_DIGEST:				outAuthenticationMethodName.FromCString ("Digest");			break;
		case AUTH_KERBEROS:				outAuthenticationMethodName.FromCString ("Kerberos");		break;
		case AUTH_NTLM:					outAuthenticationMethodName.FromCString ("NTLM");			break;
		default:						outAuthenticationMethodName.FromCString ("None");			break;
	}
}
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 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 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);
	}
}
/* private */
void VVirtualFolder::_NormalizeFolder()
{
	assert (NULL != fFolder);

	if (!fFolder->Exists())
		fFolder->CreateRecursive();

	if (fFolder->Exists())
	{
		XBOX::VFilePath folderPath (fFolder->GetPath());
		XBOX::VFilePath indexPath;

		indexPath = folderPath.ToSubFile (fIndexFileName);

		if (indexPath.IsFile())
		{
			XBOX::VFile indexFile (indexPath);

			if (!indexFile.Exists())
			{
				XBOX::VFolder *componentFolder = VHTTPServer::RetainComponentFolder (kBF_RESOURCES_FOLDER);

				if (NULL != componentFolder)
				{
					XBOX::VFilePath		defaultIndexPath = componentFolder->GetPath();
					XBOX::DialectCode	dialectCode = XBOX::VIntlMgr::GetDefaultMgr()->GetCurrentDialectCode();
					XBOX::VString		languageCode;
					XBOX::VString		fileName;

					XBOX::VIntlMgr::GetDefaultMgr()->GetISO6391LanguageCode (dialectCode, languageCode);

					fileName.AppendCString ("index_");
					fileName.AppendString (languageCode);
					fileName.AppendCString (".html");

					defaultIndexPath.ToSubFolder (CVSTR ("Default Page")).ToSubFile (fileName);

					if (defaultIndexPath.IsFile())
					{
						XBOX::VFile defaultIndexFile (defaultIndexPath);

						if (defaultIndexFile.Exists())
							indexFile.CopyFrom (defaultIndexFile);
					}

					XBOX::QuickReleaseRefCountable (componentFolder);
				}
			}
		}
	}
}
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);
}
Ejemplo n.º 25
0
    std::string StdStringFromAsciiVString(const XBOX::VString inStr)
    {
        int len=inStr.GetLength();
        char* buf=new char[len];

        if(!buf)
            return std::string();

        inStr.ToBlock(buf, len, XBOX::VTC_US_ASCII, false, false);

        std::string outStr(buf, len);
        delete[] buf;

        return outStr;
    }
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);
}
XBOX::VError Base64Decode (XBOX::VString& ioString)
{
	if (!ioString.DecodeBase64())
		return VE_HTTP_BASE64_DECODING_FAILED;

	return XBOX::VE_OK;
}
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 VRemoteDebugPilot::TreatNewContextMsg(RemoteDebugPilotMsg_t& ioMsg)
{
	XBOX::VError			err;
	XBOX::VString			resp;

	if (fState != STOPPED_STATE)
	{
		if ( testAssert(fContextArray.size() < K_NB_MAX_CTXS) )
		{

			VContextDescriptor*		newCtx = new VContextDescriptor();
			*(ioMsg.outctx) = (OpaqueDebuggerContext)sRemoteDebugPilotContextId;
			sRemoteDebugPilotContextId++;
			std::pair< OpaqueDebuggerContext, VContextDescriptor* >	l_pair( *(ioMsg.outctx), newCtx);
			std::pair< std::map< OpaqueDebuggerContext, VContextDescriptor* >::iterator, bool >	newElt =
					fContextArray.insert( l_pair );

			if (testAssert(newElt.second))
			{
				if (fState == CONNECTED_STATE)
				{
					resp = CVSTR("{\"method\":\"newContext\",\"contextId\":\"");
					resp.AppendLong8((sLONG8)(*(ioMsg.outctx)));
					resp += CVSTR("\",\"id\":\"");
					resp += fClientId;
					resp += CVSTR("\"}");

					err = SendToBrowser( resp );
					if (err)
					{
						fWS->Close();
						fState = DISCONNECTING_STATE;
					}
				}
				else
				{
					err = VE_OK;
				}
				if (!err)
				{
					fPipeStatus = VE_OK;
				}
			}
		}
	}
	fPipeOutSem.Unlock();
}
void VHTTPServerLog::_WriteUsername (const XBOX::VString& inUserName, XBOX::VString& ioStream)
{
	if (!inUserName.IsEmpty())
	{
		bool			wasCtrl = false;
		XBOX::VString	userName;

		for (XBOX::VIndex pos = 0; pos < inUserName.GetLength(); ++pos)
		{
			// When user name contains CHAR_SPACE, replace it by CHAR_LOW_LINE '_'
			if ((inUserName[pos] <= CHAR_SPACE) && (inUserName[pos] > 0))
			{
				if (!wasCtrl)
					userName.AppendUniChar (CHAR_LOW_LINE);
				wasCtrl = (inUserName[pos] != CHAR_SPACE);
			}
			else
			{
				userName.AppendUniChar (inUserName[pos]);
				wasCtrl = false;
			}
		}

		ioStream.AppendString (userName);
	}
	else
	{
		ioStream.AppendUniChar (CHAR_HYPHEN_MINUS);
	}
}