コード例 #1
0
ファイル: VValueBag.cpp プロジェクト: StephaneH/core-XToolbox
CharSet VValueBag::DebugDump(char* inTextBuffer, sLONG& inBufferSize) const
{
	if (VProcess::Get() != NULL)
	{
		VString dump;
		VString temp;
		VIndex i;
		VIndex count = GetAttributesCount();
		for (i = 1 ; i <= count ; ++i)
		{
			const VValueSingle* theValue = GetNthAttribute( i, &temp);
			dump.AppendPrintf("%S = %A\n", &temp, theValue);
		}
		
		count = GetElementNamesCount();
		for (i = 1 ; i <= count ; ++i)
		{
			const VBagArray *theBagArray = GetNthElementName( i, &temp);

			dump.AppendPrintf("=======\n%d %S :\n", theBagArray->GetCount(), &temp);
			
			for (sLONG j = 1 ; j <= theBagArray->GetCount() ; ++j) {
				dump.AppendPrintf("--\n%V", theBagArray->RetainNth(j));
			}
		}

		dump.Truncate(inBufferSize/2);
		inBufferSize = (sLONG) dump.ToBlock(inTextBuffer, inBufferSize, VTC_UTF_16, false, false);
	} else
		inBufferSize = 0;
	return VTC_UTF_16;
}
コード例 #2
0
/*
	static
*/
VError VFolder::ResolveAliasFolder( VFolder **ioFolder, bool inDeleteInvalidAlias)
{
	VError err = VE_OK;
	if ( (*ioFolder != NULL) && (*ioFolder)->fPath.IsFolder() && !(*ioFolder)->fFolder.Exists( false /* doesn't check alias */) )
	{
		// the folder doesn't exists
		// maybe is it an alias file?
		VString path = (*ioFolder)->fPath.GetPath();
		if (testAssert( path[path.GetLength()-1] == FOLDER_SEPARATOR))
		{
			path.Truncate( path.GetLength()-1);
			#if VERSIONWIN
			path += ".lnk";
			#endif
			VFile file( path);
			if (file.IsAliasFile() && file.Exists())
			{
				VFilePath resolvedPath;
				err = file.GetImpl()->ResolveAlias( resolvedPath);	// nothrow
				if (err == VE_OK)
				{
					if (resolvedPath.IsFolder())
					{
						(*ioFolder)->Release();
						*ioFolder = new VFolder( resolvedPath);
					}
					else if (inDeleteInvalidAlias)
					{
						err = file.Delete();
					}
					else
					{
						StThrowFileError errThrow( *ioFolder, VE_FILE_CANNOT_RESOLVE_ALIAS_TO_FOLDER);
						err = errThrow.GetError();
					}
				}
				else if (inDeleteInvalidAlias)
				{
					err = file.Delete();
				}
				else
				{
					if (IS_NATIVE_VERROR( err))
					{
						StThrowFileError errThrow( &file, VE_FILE_CANNOT_RESOLVE_ALIAS, err);
						err = errThrow.GetError();
					}
				}
			}
		}
	}
	return err;
}
コード例 #3
0
void VHTMLSyntax::SwapComment( ICodeEditorDocument* inDocument, VString& ioString, bool inComment )
{
	if ( inComment )
	{
		ioString.Insert( CVSTR( "<!--" ), 1 );
		ioString += CVSTR( "-->" );
	}
	else
	{
		if ( ioString.BeginsWith( CVSTR( "<!--" ) ) )
			ioString.Remove( 1, 4 );

		if ( ioString.EndsWith( CVSTR( "-->" ) ) )
			ioString.Truncate( ioString.GetLength() - 3 );
	}
}
コード例 #4
0
void VSpanHandler::SetFontSize(const VString& inValue, float inDPI)
{
	Real size = 0;
	VTextStyle* TheStyle = fStyles->GetData();
	if(!TheStyle)
		return;
	if(inValue.EndsWith("pt", true))
	{
		VString textsize = inValue;
		textsize.Truncate( inValue.GetLength()-2);
		size = textsize.GetReal();
		//we need convert from format dpi to 72 dpi
#if VERSIONWIN
		TheStyle->SetFontSize(floor(size*(inDPI ? inDPI : VSpanTextParser::Get()->GetDPI())/72.0f+0.5f));
#else
		TheStyle->SetFontSize(size);
#endif
	}
}
コード例 #5
0
VError VServiceDiscoveryServer::_HandlePacket (VUDPEndPoint *inEndPoint, uBYTE *inPacket, uLONG inPacketSize, uLONG inBufferSize)
{
	xbox_assert(inEndPoint != NULL);
	xbox_assert(inPacket != NULL);
		
	uLONG									numberQuestions, size, i, offset;
	VError									error;
	const uBYTE								*p;
	VString									vString;
	std::list<VServiceRecord>::iterator		j;
	std::map<VString, bool>					queriedServices, queriedAddresses;
	std::map<VString, bool>::iterator		k;		
		
	if (inPacketSize < 12) 
		
		return VE_SRVR_BONJOUR_MALFORMED_PACKET;
	
	if ((inPacket[2] & 0x80)
	|| (inPacket[3] & 0x0f)
	|| !(numberQuestions = Bonjour::Read2Bytes(&inPacket[4])))
		
		return VE_OK;
	
	p = &inPacket[12];
	for (i = 0; i < numberQuestions; i++) {
		
		uWORD	questionType, questionClass;
		
		size = inPacketSize;
		if ((error = Bonjour::ParseDNSName(inPacket, &size, p - inPacket, &vString)) != VE_OK) 

			return error;

		p += size;	
		questionType = Bonjour::Read2Bytes(p);
		questionClass = Bonjour::Read2Bytes(p + 2);		
		p += 4;
		
		if (questionClass != 1)
			
			continue;
		
		if (questionType == Bonjour::kTypePTR) {

			if (vString.EndsWith(".local", true)) {
			
				vString.Truncate(vString.GetLength() - 6);
				
				for (j = fServiceRecords.begin(); j != fServiceRecords.end(); j++)

					if (j->fServiceName.EqualToString(vString, true)) {

						queriedServices[vString] = true;
						break;

					} else if (vString.EqualToString("_services._dns-sd._udp", true)) {
						
						queriedServices[vString] = true;
						break;
				
					}
				
			}
			
		} else if (questionType == Bonjour::kTypeA) 
			
			queriedAddresses[vString] = true;

		// Ignore all other types of queries.

	}	
	
	error = VE_OK;
	offset = p - inPacket;
	for (k = queriedServices.begin(); k != queriedServices.end(); k++) 

		if (k->first.EqualToString("_services._dns-sd._udp", true))

			error = _SendServiceList(inEndPoint, inPacket, inBufferSize, offset);

		else
		
			error = _AnswerQuery(inEndPoint, inPacket, inBufferSize, offset, k->first);

	// Note that a hostname can have several network address(es).

	for (k = queriedAddresses.begin(); k != queriedAddresses.end(); k++) 
		
		for (j = fServiceRecords.begin(); j != fServiceRecords.end(); j++)
		
			if (j->fHostName.EqualToString(k->first, false)) 
				
				error = _SendAddressAnswer(inEndPoint, inPacket, inBufferSize, offset, *j);

	return error;
}
コード例 #6
0
VError VServiceDiscoveryClient::_ParsePacket (const uBYTE *inPacket, uLONG inPacketSize, 
													std::vector<VServiceRecord> *outServiceRecord, 
													const std::vector<VString> &inServiceNames,
													sLONG inIdentifier)
{
	xbox_assert(inPacket != NULL && outServiceRecord != NULL);
	
	VError			error;
	uLONG			numberQuestions, numberResourceRecords, size;
	const uBYTE		*p, *q;
	VString			vString;
	
	if (inPacketSize < 12)
	
		return VE_SRVR_BONJOUR_MALFORMED_PACKET;
			
	if (inPacket[3] & 0x0f)
		
		return VE_OK;		// Ignore.
	
	// If identifier isn't used, allow service detection from any "captured" packets.
	
	if ((inIdentifier >= 0 && (Bonjour::Read2Bytes(inPacket) != inIdentifier)) || !(inPacket[2] & 0x80)) 
		
		return VE_OK;		// Ignore.

	numberQuestions = Bonjour::Read2Bytes(&inPacket[4]);
	numberResourceRecords = Bonjour::Read2Bytes(&inPacket[6]);
	numberResourceRecords += Bonjour::Read2Bytes(&inPacket[8]);
	numberResourceRecords += Bonjour::Read2Bytes(&inPacket[10]); 

	// Skip questions.
	
	p = &inPacket[12];
	q = inPacket + inPacketSize;
	for (uLONG i = 0; i < numberQuestions; i++) {

		size = inPacketSize;
		if ((error = Bonjour::ParseDNSName(inPacket, &size, p - inPacket, &vString)) != VE_OK)
			
			return error;
				
		if ((p += size + 4) > q) 
		
			return VE_SRVR_BONJOUR_MALFORMED_PACKET;
		
	}
	
	std::vector<PendingRecord>	pendingRecords;
	uLONG						i, j;
	
	// Parse all resource records.
	
	error = VE_OK;
	for (i = 0; i < numberResourceRecords && error == VE_OK; i++) {
		
		VString	name;
		uWORD			type;
		uLONG			dataSize, timeToLive;
		const uBYTE		*data;
		
		size = inPacketSize;
		if ((error = Bonjour::ParseResourceRecord(inPacket, &size, p - inPacket, 
												  &name, &type, &dataSize, &data, &timeToLive)) != VE_OK)
			
			break;
		
		p += size;	
		
		switch (type) {

			case Bonjour::kTypeA: {

				if (dataSize != 4) {
				
					error = VE_SRVR_BONJOUR_MALFORMED_PACKET;
					break;
					
				}
			
				for (j = 0; j < pendingRecords.size(); j++)
				
					if (pendingRecords[j].fHasSRV
					&& pendingRecords[j].fTarget.EqualToString(name, true)) {

						VNetAddress	address(*((IP4 *) data));
					
						pendingRecords[j].fServiceRecord.fIPv4Address = address.GetIP(NULL);
						pendingRecords[j].fHasA = true;
						
					}
				
				break;
				
			}

			case Bonjour::kTypeAAAA: {

				if (dataSize != 16) {
				
					error = VE_SRVR_BONJOUR_MALFORMED_PACKET;
					break;
					
				}

				for (j = 0; j < pendingRecords.size(); j++)
				
					if (pendingRecords[j].fHasSRV
					&& pendingRecords[j].fTarget.EqualToString(name, true)) {
						
						VNetAddress	address(*((IP6 *) data));
					
						pendingRecords[j].fServiceRecord.fIPv6Address = address.GetIP(NULL);
						pendingRecords[j].fHasAAAA = true;
						
					}
				
				break;

			}
				
			case Bonjour::kTypePTR: {

				VString	notSuffixedName;

				notSuffixedName = name;
				if (notSuffixedName.EndsWith(".local", true))

					notSuffixedName.Truncate(notSuffixedName .GetLength() - 6);

				for (j = 0; j < inServiceNames.size(); j++)
					
					if (inServiceNames[j].EqualToString(notSuffixedName, true)) 
						
						break;
				
				if (j == inServiceNames.size())
					
					break;

				size = inPacketSize;
				if ((error = Bonjour::ParseDNSName(inPacket, &size , data - inPacket, &vString)) != VE_OK)
					
					break;
					
				if (size != dataSize) { 
				
					error = VE_SRVR_BONJOUR_MALFORMED_PACKET;
					break;
					
				}
						
				for (j = 0; j < pendingRecords.size(); j++)
					
					if (pendingRecords[j].fServiceRecord.fServiceName.EqualToString(name, true) 
					&& pendingRecords[j].fServiceRecord.fProviderName.EqualToString(vString, true))
						
						break;
						
				if (j == pendingRecords.size()) {

					PendingRecord	record;
						
					record.fServiceRecord.fServiceName = name;
					record.fServiceRecord.fProviderName = vString;
					record.fHasSRV = record.fHasA = record.fHasAAAA = false;
					record.fTarget.Clear();
					
					pendingRecords.push_back(record);
						
				}
				
				break;
				
			}
				
			case Bonjour::kTypeTXT: {
			
				for (j = 0; j < pendingRecords.size(); j++)
					
					if (pendingRecords[j].fServiceRecord.fProviderName.EqualToString(name, true)) {
						
						size = dataSize;
						if ((error = Bonjour::TXTToValueBag(data, &size, &pendingRecords[j].fServiceRecord.fValueBag)) != VE_OK)
							
							break;
							
						if (size != dataSize) 
								
							error = VE_SRVR_BONJOUR_MALFORMED_PACKET;
						
						break;
						
					}
				
				break;
				
			}

			case Bonjour::kTypeSRV: {
				
				for (j = 0; j < pendingRecords.size(); j++)
					
					if (pendingRecords[j].fServiceRecord.fProviderName.EqualToString(name, true)) {

						size = inPacketSize;
						if ((error = Bonjour::ParseDNSName(inPacket, &size, data - inPacket + 6, &vString)) != VE_OK)
							
							break;
						
						if (size != dataSize - 6) {
							
							error = VE_SRVR_BONJOUR_MALFORMED_PACKET;
							break;
							
						}
						
						pendingRecords[j].fServiceRecord.fPort = Bonjour::Read2Bytes(data + 4);	// Ignore priority and weight.
						pendingRecords[j].fTarget = vString;
						pendingRecords[j].fHasSRV = true;
											
						break;					
						
					}
											
				break;	
		
			}
								
			default:	break;	// Ignore.
				
		}
				
	}	
	
	if (error != VE_OK)
		
		return error;
	
	// Find out detected records.
	
	for (i = 0; i < pendingRecords.size(); i++)
		
		if (pendingRecords[i].fHasSRV && (pendingRecords[i].fHasA || pendingRecords[i].fHasAAAA)) {
			
			if (pendingRecords[i].fServiceRecord.fProviderName.EndsWith(pendingRecords[i].fServiceRecord.fServiceName))

				pendingRecords[i].fServiceRecord.fProviderName.Truncate(
					pendingRecords[i].fServiceRecord.fProviderName.GetLength() 
					- pendingRecords[i].fServiceRecord.fServiceName.GetLength() 
					- 1);															// Remove "." dot.

			if (pendingRecords[i].fServiceRecord.fServiceName.EndsWith(".local"))

				pendingRecords[i].fServiceRecord.fServiceName.Truncate(
					pendingRecords[i].fServiceRecord.fServiceName.GetLength() 
					- 6);

			pendingRecords[i].fServiceRecord.fHostName = pendingRecords[i].fTarget;
			outServiceRecord->push_back(pendingRecords[i].fServiceRecord);

		}

	return VE_OK;
}
コード例 #7
0
void VHTMLSyntax::GetSuggestions( ICodeEditorDocument* inDocument, sLONG inLineNumber, sLONG inPos, ITipInfoArray *outSuggestions, sLONG& outStartOffset, bool inAll )
{
	// Get the text for the line up to the point of insertion, and we'll lex that to see if we can come up 
	// with some rational suggestions for the user.
	VString xstr;
	inDocument->GetLine( inLineNumber, xstr );
	xstr.Truncate( inPos );

	char *lexinput = CreateUTF8String( xstr );
	struct htmlLexeme *list = parseHTML( lexinput );

	// Gin up some line params for tracking state information
	VLineSyntaxParams *currentLineParams = currentLineParams = new VLineSyntaxParams();
	if (inLineNumber > 0) {
		// We're starting where we left off on the previous line
		currentLineParams->CopyState( static_cast< VLineSyntaxParams * >( inDocument->GetLineSyntaxParams( inLineNumber - 1 ) ) );
	}

	// Given the list of HTML tokens, let's walk over the list and try to make some sense
	// of them.  Walk over the list one token at a time, and see if we can make sense of 
	// what we've got.  This is going to be awfully similar to the way we do things in the
	// SetLine method, except that we're not actually updating the line state for the current
	// line.  Instead, we're working on a copy of the existing information.
	struct htmlLexeme *cur = list;
	int lastTokenProcessed = 0;
	while (cur) {
		if (kKeyword == cur->fStyle) {
			lastTokenProcessed = 3;

			// Keywords a bit trickier than you might think because we need to be sure they're actually part of a
			// tag.  If the user types something like: <b>This table rocks</b>, we only want to highlight the b in the
			// begin and end tag, and not the "table" in the user's text.  To deal with this, we have an "in tag" flag
			// that basically turns keyword highlighting on and off.
			if (currentLineParams->IsProcessingTag()) {
				// If we're processing an opening tag, then we want to push the keyword onto the tag stack.  But if we're
				// processing a closing tag, then we want to pop the last keyword off the tag stack and try to match it up
				// to what we just processed.  If they match, we're golden.  If not, we just assume the user's mismatching
				// their tags because they're an idiot.
				VString tagName;
				xstr.GetSubString( cur->fOffset + 1, cur->fLength, tagName );

				if (currentLineParams->IsProcessingStartTag()) {
					currentLineParams->PushTag( tagName );

					// Note that we are no longer processing the start of a tag.  This allows us to handle attributes
					// separately from the tag itself.
					currentLineParams->SetIsProcessingStartTag( false );
				} else {
					VString lastTag;
					currentLineParams->PopTag( lastTag );

					if (!lastTag.EqualTo( tagName, false )) {
						// The tags don't match, so we're just going to ignore the issue
						// TODO: do something more sensible here
					}
				}
			}
		} else if (kTagOpen == cur->fStyle || kEndTagOpen == cur->fStyle) {
			lastTokenProcessed = (kTagOpen == cur->fStyle) ? 1 : 2;

			currentLineParams->SetIsProcessingTag( true );
			currentLineParams->SetIsProcessingStartTag( kTagOpen == cur->fStyle );
		} else if (kTagClose == cur->fStyle || kTagSelfClose == cur->fStyle) {
			lastTokenProcessed = 0;

			currentLineParams->SetIsProcessingTag( false );

			// If we just handled a self-closing tag (like <br />), then we want to pop it from the stack
			// TODO: some tags can't have matching pairs, like <br>, so even if it's not self-closing, we want
			// to pop it off the tag stack.  Handle that here
			if (kTagSelfClose == cur->fStyle) {
				VString toss;
				currentLineParams->PopTag( toss );
			}
		} else {
			lastTokenProcessed = 0;
		}

		cur = cur->fNext;
	}

	if (lastTokenProcessed == 1) {
		// We processed a tag opener, but no keyword for the tag.  So let's make a bunch of suggestions!
	} else if (lastTokenProcessed == 2) {
		// We processed a tag closer, but no keyword for the tag.  Grab the last opened tag from the list
		// and suggest it as the closer
		VString suggestion;
		currentLineParams->LastTag( suggestion );
		outSuggestions->AddTip( new VCodeEditorTipInfo( inDocument, suggestion, htmlcolorShadow[ keyword_col ] ) );
	}

	delete currentLineParams;
	FreeLexemeList( list );
}