示例#1
0
/// Convert the path separator characters in the given object path to valid directory delimiters for the current
/// platform.
///
/// Note that objects with instance indices are not supported for file paths.  Instance index delimiters will not be
/// converted, and may be invalid file name characters on certain platforms.
///
/// @param[out] rFilePath     Converted file path.
/// @param[in]  rPackagePath  Asset path string to convert (can be the same as the output file path).
void AssetPath::ConvertStringToFilePath( String& rFilePath, const String& rPackagePath )
{
#if HELIUM_PACKAGE_PATH_CHAR != HELIUM_PATH_SEPARATOR_CHAR && HELIUM_PACKAGE_PATH_CHAR != HELIUM_ALT_PATH_SEPARATOR_CHAR
	size_t pathLength = rPackagePath.GetSize();
	if( &rFilePath == &rPackagePath )
	{
		for( size_t characterIndex = 0; characterIndex < pathLength; ++characterIndex )
		{
			char& rCharacter = rFilePath[ characterIndex ];
			if( rCharacter == HELIUM_PACKAGE_PATH_CHAR || rCharacter == HELIUM_OBJECT_PATH_CHAR )
			{
				rCharacter = Helium::s_InternalPathSeparator;
			}
		}
	}
	else
	{
		rFilePath.Remove( 0, rFilePath.GetSize() );
		rFilePath.Reserve( rPackagePath.GetSize() );

		for( size_t characterIndex = 0; characterIndex < pathLength; ++characterIndex )
		{
			char character = rPackagePath[ characterIndex ];
			if( character == HELIUM_PACKAGE_PATH_CHAR || character == HELIUM_OBJECT_PATH_CHAR )
			{
				character = Helium::s_InternalPathSeparator;
			}

			rFilePath.Add( character );
		}
	}
#else
	rFilePath = rPackagePath;
#endif
}
示例#2
0
文件: Mix.cpp 项目: CyberShadow/FAR
void WINAPI QuoteStr(String& str)
{
	String  buff;

	if(str.Chr(quotes) == -1)
		return;

	buff.Add('\"');

	for(int n = 0; n < str.Length(); n++)
		if(str[n] == '\"')
		{
			buff.Add('\"');
			buff.Add('\"');
		}
		else
			buff.Add(str[n]);

	buff.Add('\"');
	str = buff;
}
示例#3
0
void FTPHost::MkUrl(String& str,LPCSTR Path,LPCSTR nm,BOOL sPwd)
{
	bool defPara = StrCmp(User,"anonymous") == 0 &&
	               StrCmp(Password,Opt.DefaultPassword) == 0;

	if(!defPara && User[0])
	{
		if(Password[0])
			str.printf("ftp://%s:%s@%s",
			           User,
			           (sPwd || IS_FLAG(Opt.PwdSecurity,SEC_PLAINPWD)) ? Password : "",
			           Host);
		else
			str.printf("ftp://%s@%s",User,Host);
	}
	else
		str.printf("ftp://%s",Host);

	if(Path && *Path)
	{
		if(*Path != '/')
			str.Add('/');

		str.cat(Path);
	}

	if(nm && *nm)
	{
		int len = str.Length()-1;

		if(len >= 0 && str[len] != '/' && str[len] != '\\')
			str.Add('/');

		str.Add(nm);
	}

	FixFTPSlash(str);
}
示例#4
0
/// Builds a packet using set stats and returns it as a string.
String SIPPacket::BuildPacket(){
	// Check other stuff.
	String fullPacket;
	// Initial CRLF
	fullPacket.Add("\r\n");
	for (int i = 0; i < header.Size(); ++i){
		fullPacket.Add(header[i]);
		fullPacket.Add("\r\n");
	}
	// Add separating CRLF
	fullPacket.Add("\r\n");
	for (int i = 0; i < body.Size(); ++i){
		fullPacket.Add(body[i]);
		fullPacket.Add("\r\n");
	}
	fullPacket.Add("\r\n\r\n");
	return fullPacket;
}
示例#5
0
/// Fetches target section in string using given start and end-tokens. Returns the first occurance, if any, or an empty string if none such exist.
String GetSection(String inString, char withStartToken, char andEndToken){
	int startIndex = -1, endIndex = -1;
	for (int i = 0; i < inString.Length(); ++i){
		char c = inString.CharAt(i);
		if (c == withStartToken)
			startIndex = i+1;
		if (c == andEndToken)
			endIndex = i;
		if (startIndex >= 0 && endIndex >= 0)
			break;
	}
	if (startIndex < 0 && endIndex < 0)
		return String();
	String newString;
	for (int i = startIndex; i < endIndex; ++i){
		newString.Add(inString.CharAt(i));
	}
	std::cout<<"newString: "<<newString<<" length: "<<newString.Length();
	return newString;
}
示例#6
0
// Ref: http://tools.ietf.org/html/rfc3261#section-24
// Builds the header using the previously set parameters. Call this again if you change any of them!
void SIPPacket::BuildHeader(){
	// Make sure body is set before calculating header-parameters!
	if (!bodySet){
		std::cout<< "ERROR: Body not set before calling SIPPacket::BuildHeader! Fix this, yo.";
		assert(bodySet);	
	}
	// Set default sender (us) if no sender already specified.
	if (!sender)
		sender = defaultSender;
	if (!senderSet){
		SetSender(sender);
	}
	if (!recipientSet){
		SetRecipient(recipient);
	}
	header.Clear();
	String typeName = PacketTypeName();
	switch(type){
		case SIP_REGISTER:
		case SIP_INFO:
		case SIP_INVITE:
		case SIP_BYE:
		case SIP_ACK:
		case SIP_CANCEL:
		case SIP_OPTIONS:
		case SIP_SUBSCRIBE:
		case SIP_NOTIFY:
			header.Add(typeName+" sip:"+recipientAddress+" SIP/"+SIPVersion);
			break;
		case SIP_OK:
		case SIP_BAD_REQUEST:
			header.Add("SIP/"+String(SIPVersion)+" "+typeName);
			break;
		default:
			std::cout<<"Unrecognized packet type: "<<type<<" typeName: "<<typeName;
			assert(false && "Unrecognized packet-type when setting first row in SIP message header. Add a new case for it?");
			break;
	}
	String toString = "To: "+recipientData;
	/// Only do this if the recipient is known.
	SIPSessionData * recipientSessionData = NULL;
	if (recipient){
		recipientSessionData = (SIPSessionData*)recipient->GetSessionData(SessionType::SIP);
		if (recipientSessionData->theirTag.Length()){
			toString.Add(";tag="+recipientSessionData->theirTag);
		}
	}
	header.Add(toString);
	String senderString = "From: "+senderData;
	if (recipientSessionData){
		if (recipientSessionData->ourTag.Length()){
			senderString.Add(";tag="+recipientSessionData->ourTag);
		}
	}
	header.Add(senderString);
	// TODO: Add Call-ID ?
	// Add CSeq
	if (cSeq.Length())
		header.Add("CSeq: "+cSeq);
	// Script-type, for Subscribe messages
	if (event.Length()){
		header.Add("Script: "+event);
	}
	// TODO: Add Contact
	if (expirationTime >= 0)
		header.Add("Expires: "+String::ToString(expirationTime));
	int bodyLength = BodyLength();
	if (bodyLength > 0){
		if (!contentType.Length())
			contentType = "application/customP2PMediaProtocol";
		header.Add("Content-Type: "+contentType);
	}
	header.Add("Content-Length: "+String::ToString(bodyLength));
	headerSet = true;
}