Exemplo n.º 1
0
/**
 * @brief Converts a url into a local filename.
 *
 * @retval fn   a character buffer to hold the local filename.
 * @param nfn   the number of elements in the buffer @p fn points to.
 */
bool doc::filename(char * fn, int nfn)
{
  fn[0] = '\0';

  char *e = 0, *s = const_cast<char *>(stripProtocol(url_));

  if ((e = strrchr(s,'#')) != 0)
    *e = '\0';

  const char *protocol = url_protocol();

  // Get a local copy of http files
  if (strcmp(protocol, "http") == 0)
    {
      if (tmpfile_)		// Already fetched it
	s = tmpfile_;
      else if ((s = const_cast<char *>(the_system->http_fetch(url_))))
	{
	  tmpfile_ = new char[strlen(s)+1];
	  strcpy(tmpfile_, s);
	  free(s);		// assumes tempnam or equiv...
	  s = tmpfile_;
	}
    }

  // Unrecognized protocol (need ftp here...)
  else if (strcmp(protocol, "file") != 0)
    s = 0;

#ifdef _WIN32
  // Does not like "//C:" skip "// "
   if(s)
   {
	   if(strlen(s)>2 && s[0] == '/' && s[1] == '/'&& s[2] == '/')
		   s=s+3;
	   else
	   if(strlen(s)>2 && s[0] == '/' && s[1] == '/')
		   s=s+2;
   }
#endif

  if (s)
    {
      strncpy( fn, s, nfn-1 );
      fn[nfn-1] = '\0';
    }

  if (e) *e = '#';

  return s && *s;
}
/* static */
void LLURLDispatcherImpl::regionHandleCallback(U64 region_handle, const std::string& url, const LLUUID& snapshot_id, bool teleport)
{
	std::string sim_string = stripProtocol(url);
	std::string region_name;
	S32 x = 128;
	S32 y = 128;
	S32 z = 0;
	LLURLSimString::parse(sim_string, &region_name, &x, &y, &z);

	// remap x and y to local coordinates
	S32 local_x = x % REGION_WIDTH_UNITS;
	S32 local_y = y % REGION_WIDTH_UNITS;
	if (local_x < 0)
		local_x += REGION_WIDTH_UNITS;
	if (local_y < 0)
		local_y += REGION_WIDTH_UNITS;
	
	LLVector3 local_pos;
	local_pos.mV[VX] = (F32)local_x;
	local_pos.mV[VY] = (F32)local_y;
	local_pos.mV[VZ] = (F32)z;


	
	if (teleport)
	{
		LLVector3d global_pos = from_region_handle(region_handle);
		global_pos += LLVector3d(local_pos);
		gAgent.teleportViaLocation(global_pos);
		if(gFloaterWorldMap)
		{
			gFloaterWorldMap->trackLocation(global_pos);
		}
	}
	else
	{
		// display informational floater, allow user to click teleport btn
		LLFloaterURLDisplay* url_displayp = LLFloaterURLDisplay::getInstance(LLSD());


		url_displayp->displayParcelInfo(region_handle, local_pos);
		if(snapshot_id.notNull())
		{
			url_displayp->setSnapshotDisplay(snapshot_id);
		}
		std::string locationString = llformat("%s %d, %d, %d", region_name.c_str(), x, y, z);
		url_displayp->setLocationString(locationString);
	}
}
Exemplo n.º 3
0
string stringUtils::urlPath(string url)
{
    url = stripProtocol(url);
    size_t found;
    found = url.find("/");
    if(found != string::npos)
    {
        url.erase(0, found);
        return url;
    }
    else
    {
        return "/";
    }
}
Exemplo n.º 4
0
string stringUtils::urlHostname(string url)
{
    url = stripProtocol(url);
    size_t found;
    found = url.find("/");
    if(found != string::npos)
    {
        url.erase(found);
    }
    found = url.find(":");
    if(found != string::npos)
    {
        url.erase(found);
    }
    return url;
}
Exemplo n.º 5
0
string stringUtils::urlPort(string url)
{
    url = stripProtocol(url);
    size_t found;
    found = url.find("/");
    if(found != string::npos)
    {
        url.erase(found);
    }
    found = url.find(":");
    if(found != string::npos)
    {
        return url.erase(0, found+1);
    }
    else
    {
        return "80"; //default to returning the http port
    }
}
// static
bool LLURLDispatcherImpl::dispatchRegion(const std::string& url, bool right_mouse)
{
	if (!isSLURL(url))
	{
		return false;
	}

	// Before we're logged in, need to update the startup screen
	// to tell the user where they are going.
	if (LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP)
	{
		// Parse it and stash in globals, it will be dispatched in
		// STATE_CLEANUP.
		LLURLSimString::setString(url);
		// We're at the login screen, so make sure user can see
		// the login location box to know where they are going.
		
		LLPanelLogin::refreshLocation( true );
		return true;
	}

	std::string sim_string = stripProtocol(url);
	std::string region_name;
	S32 x = 128;
	S32 y = 128;
	S32 z = 0;
	LLURLSimString::parse(sim_string, &region_name, &x, &y, &z);

	LLFloaterURLDisplay* url_displayp = LLFloaterURLDisplay::getInstance(LLSD());
	url_displayp->setName(region_name);

	// Request a region handle by name
	LLWorldMap::getInstance()->sendNamedRegionRequest(region_name,
									  LLURLDispatcherImpl::regionNameCallback,
									  url,
									  false);	// don't teleport
	return true;
}
/*static*/
void LLURLDispatcherImpl::regionNameCallback(U64 region_handle, const std::string& url, const LLUUID& snapshot_id, bool teleport)
{
	std::string sim_string = stripProtocol(url);
	std::string region_name;
	S32 x = 128;
	S32 y = 128;
	S32 z = 0;
	LLURLSimString::parse(sim_string, &region_name, &x, &y, &z);

	LLVector3 local_pos;
	local_pos.mV[VX] = (F32)x;
	local_pos.mV[VY] = (F32)y;
	local_pos.mV[VZ] = (F32)z;

	
	// determine whether the point is in this region
	if ((x >= 0) && (x < REGION_WIDTH_UNITS) &&
		(y >= 0) && (y < REGION_WIDTH_UNITS))
	{
		// if so, we're done
		regionHandleCallback(region_handle, url, snapshot_id, teleport);
	}

	else
	{
		// otherwise find the new region from the location
		
		// add the position to get the new region
		LLVector3d global_pos = from_region_handle(region_handle) + LLVector3d(local_pos);

		U64 new_region_handle = to_region_handle(global_pos);
		LLWorldMap::getInstance()->sendHandleRegionRequest(new_region_handle,
										   LLURLDispatcherImpl::regionHandleCallback,
										   url, teleport);
	}
}
Exemplo n.º 8
0
/**
 * @brief Get an output stream for writing to the resource.
 *
 * @return an output stream.
 */
std::ostream & doc::output_stream()
{
    this->out_ = new std::ofstream(stripProtocol(url_), std::ios::out);
    return *this->out_;
}