Ejemplo n.º 1
0
// Handles only folder URIs.
// File URIs are not tmp://-based, but are baseFS-based
// The URI is: tmp:///folder/name#baseFSRoot
clPtr<FS> FSTmp::ParzeURI(const unicode_t* uri, FSPath& path, const std::vector<clPtr<FS>>& checkFS)
{
	std::string	uriUtf8(unicode_to_utf8_string(uri));
	
	LUrlParser::clParseURL clparseURL = LUrlParser::clParseURL::ParseURL(uriUtf8);
	
	if (clparseURL.IsValid() && clparseURL.m_Scheme == "tmp")
	{
		FSString pathFSstring(clparseURL.m_Path);
		path = FSPath(pathFSstring);

		for (clPtr<FS> clPtrFs : checkFS)
		{
			if (clPtrFs->Type() == FS::TMP)
			{
				FSTmp* fsTmp = (FSTmp*) clPtrFs.ptr();
				if (clparseURL.m_Fragment == fsTmp->baseFS->Uri(rootPathName).GetUtf8())
					return clPtrFs;
			}
		}
		// no tmpFS ptr found among checkFS, create baseFS, and FSTmp on top of it.
		FSPath tFSPath;
		FSString fragmentFSString(clparseURL.m_Fragment);
		clPtr<FS> baseFS = ::ParzeURI(fragmentFSString.GetUnicode(), tFSPath, checkFS);
		return new FSTmp(baseFS);
	}
	return new FSSys();
}
Ejemplo n.º 2
0
s32 cellHttpUtilParseUri(vm::ptr<CellHttpUri> uri, vm::cptr<char> str, vm::ptr<void> pool, u32 size, vm::ptr<u32> required)
{
	cellHttpUtil.trace("cellHttpUtilParseUri(uri=*0x%x, str=%s, pool=*0x%x, size=%d, required=*0x%x)", uri, str, pool, size, required);
	LUrlParser::clParseURL URL = LUrlParser::clParseURL::ParseURL(str.get_ptr());
	if ( URL.IsValid() )
	{
		std::string scheme = URL.m_Scheme;
		std::string host = URL.m_Host;
		std::string path = URL.m_Path;
		std::string username = URL.m_UserName;
		std::string password = URL.m_Password;

		u32 schemeOffset = 0;
		u32 hostOffset = scheme.length() + 1;
		u32 pathOffset = hostOffset + host.length() + 1;
		u32 usernameOffset = pathOffset + path.length() + 1;
		u32 passwordOffset = usernameOffset + username.length() + 1;
		u32 totalSize = passwordOffset + password.length() + 1;

		//called twice, first to setup pool, then to populate.
		if (!uri)
		{
			*required = totalSize;
			return CELL_OK;
		}
		else
		{
			std::strncpy((char*)vm::base(pool.addr() + schemeOffset), (char*)scheme.c_str(), scheme.length() + 1);
			std::strncpy((char*)vm::base(pool.addr() + hostOffset), (char*)host.c_str(), host.length() + 1);
			std::strncpy((char*)vm::base(pool.addr() + pathOffset), (char*)path.c_str(), path.length() + 1);
			std::strncpy((char*)vm::base(pool.addr() + usernameOffset), (char*)username.c_str(), username.length() + 1);
			std::strncpy((char*)vm::base(pool.addr() + passwordOffset), (char*)password.c_str(), password.length() + 1);

			uri->scheme.set(pool.addr() + schemeOffset);
			uri->hostname.set(pool.addr() + hostOffset);
			uri->path.set(pool.addr() + pathOffset);
			uri->username.set(pool.addr() + usernameOffset);
			uri->password.set(pool.addr() + passwordOffset);

			if (URL.m_Port != "")
			{
				int port = stoi(URL.m_Port);
				uri->port = port;
			}
			else
			{
				uri->port = (u32)80;
			}
			return CELL_OK;
		}
	}
	else
	{
		std::string parseError;
		switch(URL.m_ErrorCode)
		{
			case LUrlParser::LUrlParserError_Ok:
				parseError = "No error, URL was parsed fine";
				break;
			case LUrlParser::LUrlParserError_Uninitialized:
				parseError = "Error, LUrlParser is uninitialized";
				break;
			case LUrlParser::LUrlParserError_NoUrlCharacter:
				parseError = "Error, the URL has invalid characters";
				break;
			case LUrlParser::LUrlParserError_InvalidSchemeName:
				parseError = "Error, the URL has an invalid scheme";
				break;
			case LUrlParser::LUrlParserError_NoDoubleSlash:
				parseError = "Error, the URL did not contain a double slash";
				break;
			case LUrlParser::LUrlParserError_NoAtSign:
				parseError = "Error, the URL did not contain an @ sign";
				break;
			case LUrlParser::LUrlParserError_UnexpectedEndOfLine:
				parseError = "Error, unexpectedly got the end of the line";
				break;
			case LUrlParser::LUrlParserError_NoSlash:
				parseError = "Error, URI didn't contain a slash";
				break;
			default:
				parseError = "Error, unkown error #" + std::to_string(static_cast<int>(URL.m_ErrorCode));
				break;
		}
		cellHttpUtil.error("%s, while parsing URI, %s.", parseError, str.get_ptr());
		return -1;
	}
}