void http_connect_handler(http_connection& c)
{
	++connect_handler_called;
	TEST_CHECK(c.socket().is_open());
	std::cerr << "connected to: " << c.socket().remote_endpoint() << std::endl;
	TEST_CHECK(c.socket().remote_endpoint().address() == address::from_string("127.0.0.1"));
}
void http_connect_handler(http_connection& c)
{
	++connect_handler_called;
	TEST_CHECK(c.socket().is_open());
	error_code ec;
	std::cerr << time_now_string() << " connected to: " << print_endpoint(c.socket().remote_endpoint(ec))
		<< std::endl;
// this is not necessarily true when using a proxy and proxying hostnames
//	TEST_CHECK(c.socket().remote_endpoint(ec).address() == address::from_string("127.0.0.1", ec));
}
示例#3
0
	netfile(const char* url) :
		m_position(0),
		m_eof(false),
		m_buf(NULL),
		m_bufsize(0),
		m_size(0)
	{
		m_nc = new http_connection();
		m_nc->connect(url, HTTP_SERVER_PORT);
		if (m_nc->is_open() == false)
		{
			delete m_nc;
			m_nc = NULL;
		}
	}
示例#4
0
	int read(void* dst, int bytes) 
	{
		assert(dst);

		if (m_nc == NULL)
		{
			return 0;
		}

		// ensure buf
		while (m_bufsize < m_position + bytes)
		{
			m_bufsize += 4096;
			m_buf = (Uint8*) realloc(m_buf, m_bufsize);
		}

		// not enough data in the buffer
		if (m_position + bytes > m_size)
		{
			int n = m_nc->read(m_buf + m_size, m_position + bytes - m_size);
			m_size += n;
		}

		int n = imin(bytes, m_size - m_position);
		memcpy(dst, m_buf + m_position, n);
		m_position += n;
		m_eof = n < bytes ? true : false;

		return n;
	}
void http_tracker_connection::on_connect(http_connection& c)
{
    error_code ec;
    tcp::endpoint ep = c.socket().remote_endpoint(ec);
    m_tracker_ip = ep.address();
    boost::shared_ptr<request_callback> cb = requester();
}
示例#6
0
void upnp::create_port_mapping(http_connection& c, rootdevice& d, int i)
{
	mutex_t::scoped_lock l(m_mutex);

	TORRENT_ASSERT(d.magic == 1337);

	if (!d.upnp_connection)
	{
		TORRENT_ASSERT(d.disabled);
		char msg[200];
		snprintf(msg, sizeof(msg), "mapping %u aborted", i);
		log(msg);
		return;
	}
	
	char const* soap_action = "AddPortMapping";

	char soap[2048];
	error_code ec;
	snprintf(soap, sizeof(soap), "<?xml version=\"1.0\"?>\n"
		"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
		"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
		"<s:Body><u:%s xmlns:u=\"%s\">"
		"<NewRemoteHost></NewRemoteHost>"
		"<NewExternalPort>%u</NewExternalPort>"
		"<NewProtocol>%s</NewProtocol>"
		"<NewInternalPort>%u</NewInternalPort>"
		"<NewInternalClient>%s</NewInternalClient>"
		"<NewEnabled>1</NewEnabled>"
		"<NewPortMappingDescription>%s</NewPortMappingDescription>"
		"<NewLeaseDuration>%u</NewLeaseDuration>"
		"</u:%s></s:Body></s:Envelope>"
		, soap_action, d.service_namespace, d.mapping[i].external_port
		, (d.mapping[i].protocol == udp ? "UDP" : "TCP")
		, d.mapping[i].local_port
		, print_address(c.socket().local_endpoint(ec).address()).c_str()
		, m_user_agent.c_str(), d.lease_duration, soap_action);

	post(d, soap, soap_action);
}