コード例 #1
0
ファイル: test_hit.cpp プロジェクト: nshgraph/GAI--
TEST( HitTest, multiple_parameters_add_to_encoded_url )
{
	std::string key;
	std::string value;
	
	std::map<std::string, std::string> parameters;
	parameters[ "key1" ] = "home page";
	parameters[ "key2" ] = "salt&pepper";
	parameters[ "key3" ] = "*****@*****.**";
	
	std::map<std::string, std::string> encoded_parameters;
	encoded_parameters[ "key1" ] = "home%20page";
	encoded_parameters[ "key2" ] = "salt%26pepper";
	encoded_parameters[ "key3" ] = "val%40val.com";
	
    GAITest::TestHit hit;
	hit.setParameters( parameters );
	std::string url = hit.getDispatchURL();
	
	// version is not passed in with setParameters so test it here
	const int version_pos = url.find("v=");
	std::string version = url.substr( version_pos );
	
	const int equals_pos = version.find( "=" );
	key = version.substr( 0, equals_pos );
	value = version.substr( equals_pos + 1 );
	
	// check version parameter
	EXPECT_TRUE( key == "v" );
	EXPECT_TRUE( value == kGAIVersion );
	
	// remove version from url
	url = url.substr( 0, version_pos - 1 );
	
	// tokenize and test parameters
	std::stringstream url_stream( url );
	std::string parameter;
	
	while( std::getline( url_stream, parameter, '&' ) )
	{
		const int location = parameter.find( "=" );
		key = parameter.substr( 0, location );
		value = parameter.substr( location + 1 );
		
		// check parameter is encoded
		EXPECT_TRUE( encoded_parameters[ key ] == value );
    }
}
コード例 #2
0
ファイル: HTTP.cpp プロジェクト: CodeAsm/open-sauce
		/*!
		 * \brief
		 * Builds a complete URL string, combining the values contained in the URL interface instance.
		 * 
		 * \returns
		 * Returns a string containing the URL.
		 * 
		 * Builds a complete URL string, combining the values contained in the URL interface instance.
		 */
		std::string c_url_interface::GetURL()
		{
			std::ostringstream url_stream("");

			// add the scheme
			if(m_scheme.length() == 0)
				url_stream << "http://";
			else
				url_stream << m_scheme << "://";

			// add the username and password
			url_stream << Escape(m_username);
			if(m_password.length())
				url_stream << ":" << Escape(m_password);

			// add the address and port (don't need to escape the address as it cannot have invalid characters)
			url_stream << m_address;
			if(m_port != 80)
				url_stream << ":" << m_port;

			// add the path
			if(m_path.size())
			{
				for(std::vector<std::string>::iterator iter = m_path.begin(); iter != m_path.end(); iter++)
					url_stream << "/" << Escape(*iter);
			}
			else
				url_stream << "/";

			// add the queries
			if(m_query_count)
			{
				url_stream << "?";
				for(uint32 i = 0; i < m_query_count; i++)
				{
					if(i > 0) url_stream << "&";

					url_stream << Escape(m_queries[i].m_field) << "=" << Escape(m_queries[i].m_value);
				}
			}

			// add the fragment
			if(m_fragment.length())
				url_stream << "#" << Escape(m_fragment);

			return url_stream.str();
		}
コード例 #3
0
ファイル: ValueBase.cpp プロジェクト: OspreyHub/ATCD
CORBA::Boolean
CORBA::ValueBase::_tao_read_codebase_url (TAO_InputCDR& strm,
                                          ACE_CString& codebase_url)
{
  CORBA::ULong length = 0;

  size_t buffer_size = strm.length();

  if (!strm.read_ulong (length))
    {
      return 0;
    }

  VERIFY_MAP (TAO_InputCDR, codebase_url_map, Codebase_URL_Map);
  char * pos = strm.rd_ptr();

  // 'length' may not be the codebase url length - it could be the
  // FFFFFFF indirection marker instead. If it is an indirection marker, we
  // get the offset following the indirection marker, otherwise we can follow
  // the same logic using the offset to simply rewind to the start of length
  // and re-read the length as part of the string
  if (TAO_OBV_GIOP_Flags::is_indirection_tag (length))
    {
      return _tao_unmarshal_codebase_url_indirection (strm, codebase_url);
    }

  pos -= sizeof (CORBA::ULong);

  // Cribbed from tc_demarshal_indirection in Typecode_CDR_Extraction.cpp
  TAO_InputCDR url_stream (pos,
                          buffer_size,
                          strm.byte_order ());

  if (!url_stream.good_bit ())
    {
      return 0;
    }

  if (! url_stream.read_string (codebase_url))
    return 0;

  // It's possible the codebase url is read again from an indirection stream,
  // so make sure the codebase url is the same.
  ACE_CString mapped_url;
  if (strm.get_codebase_url_map ()->get()->find (pos, mapped_url) == 0)
  {
    if (TAO_debug_level)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
        ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_read_codebase_url, found %x=%C\n"),
        pos, mapped_url.c_str ()));
    }
    if (ACE_OS::strcmp (mapped_url.c_str (), codebase_url.c_str ()) != 0)
      throw CORBA::INTERNAL ();
  }
  else if (strm.get_codebase_url_map ()->get()->bind (pos, codebase_url) != 0)
  {
    throw CORBA::INTERNAL ();
  }
  else
  {
    if (TAO_debug_level)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
        ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_read_codebase_url, bound %x=%C\n"),
        pos, codebase_url.c_str ()));
    }
  }

  // Since the codebase url is always read from the indirection cdr we have to skip
  // the main CDR forward if we were in fact reading from the current
  // location and not rewinding back some offset.

  strm.skip_bytes (length);

  return 1;
}