示例#1
0
static int proxy_connect_socks5(const char *host, unsigned short port, struct PHB *phb)
{
	phb->host = g_strdup(host);
	phb->port = port;
	phb->proxy_func = s5_canwrite;
	phb->proxy_data = phb;
	
	return( proxy_connect_none( proxyhost, proxyport, phb ) );
}
示例#2
0
static gboolean gaim_io_connected(gpointer data, gint source, b_input_condition cond)
{
	struct PHB *phb = data;
	socklen_t len;
	int error = ETIMEDOUT;
	len = sizeof(error);
	
	if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) {
		if ((phb->gai_cur = phb->gai_cur->ai_next)) {
			int new_fd;
			b_event_remove(phb->inpa);
			if ((new_fd = proxy_connect_none(NULL, 0, phb))) {
				b_event_remove(phb->inpa);
				closesocket(source);
				dup2(new_fd, source);
				closesocket(new_fd);
				phb->inpa = b_input_add(source, B_EV_IO_WRITE, gaim_io_connected, phb);
				return FALSE;
			}
		}
		freeaddrinfo(phb->gai);
		closesocket(source);
		b_event_remove(phb->inpa);
		phb->inpa = 0;
		if( phb->proxy_func )
			phb->proxy_func(phb->proxy_data, -1, B_EV_IO_READ);
		else {
			phb->func(phb->data, -1, B_EV_IO_READ);
			g_free(phb);
		}
		return FALSE;
	}
	freeaddrinfo(phb->gai);
	sock_make_blocking(source);
	b_event_remove(phb->inpa);
	phb->inpa = 0;
	if( phb->proxy_func )
		phb->proxy_func(phb->proxy_data, source, B_EV_IO_READ);
	else {
		phb->func(phb->data, source, B_EV_IO_READ);
		g_free(phb);
	}
	
	return FALSE;
}
示例#3
0
int proxy_connect(const char *host, int port, b_event_handler func, gpointer data)
{
	struct PHB *phb;
	
	if (!host || port <= 0 || !func || strlen(host) > 128) {
		return -1;
	}
	
	phb = g_new0(struct PHB, 1);
	phb->func = func;
	phb->data = data;
	
	if (proxytype == PROXY_NONE || !proxyhost[0] || proxyport <= 0)
		return proxy_connect_none(host, port, phb);
	else if (proxytype == PROXY_HTTP)
		return proxy_connect_http(host, port, phb);
	else if (proxytype == PROXY_SOCKS4)
		return proxy_connect_socks4(host, port, phb);
	else if (proxytype == PROXY_SOCKS5)
		return proxy_connect_socks5(host, port, phb);
	
	g_free(phb);
	return -1;
}