library/src/network/BP-Network.cc
// This routine attempts to connect all the proxies found within a provided network handle.
This routine attempts to connect all the proxies found within a provided network handle.
This routine attempts to connect all the proxies found within a provided network handle .
BP_ERROR_T BP_NetProxyConnectChain(P_BP_NETWORK_HANDLE net_handle)
{
	if(!net_handle)
		return ERR_FAILURE;
	if(!net_handle->proxy_info)
		return ERR_FAILURE;
	if(!net_handle->proxy_info->proxy_chain_n || !net_handle->proxy_info->proxy_chain)
		return ERR_FAILURE;
	P_BP_NETWORK_PROXY current_proxy = NULL;
	size_t n = 0;
	for(; n < net_handle->proxy_info->proxy_chain_n; n++)
	{
		current_proxy = &net_handle->proxy_info->proxy_chain[n];
		switch(current_proxy->type)
		{
			case BP_NETWORK_PROXY_TYPE_SOCKS4A:
				BP_NetProxyConnectSOCKS4A(net_handle, current_proxy);
				if(current_proxy->connected == BP_FALSE)
					return ERR_FAILURE;
				net_handle->current_proxy_depth++;
				break;
			case BP_NETWORK_PROXY_TYPE_SOCKS5:
				BP_NetProxyConnectSOCKS5(net_handle, current_proxy);
				if(current_proxy->connected == BP_FALSE)
					return ERR_FAILURE;
				net_handle->current_proxy_depth++;
				break;
			case BP_NETWORK_PROXY_TYPE_CONNECT:
				break;
			default:
				return ERR_FAILURE;
				break;
		}
	}
	net_handle->proxy_chain_established_successfully = true;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_NetProxyConnectChain ( P_BP_NETWORK_HANDLE net_handle ) { if ( ! net_handle ) return ERR_FAILURE ; if ( ! net_handle -> proxy_info ) return ERR_FAILURE ; if ( ! net_handle -> proxy_info -> proxy_chain_n || ! net_handle -> proxy_info -> proxy_chain ) return ERR_FAILURE ; P_BP_NETWORK_PROXY current_proxy = NULL ; size_t n = 0 ; for ( ; n < net_handle -> proxy_info -> proxy_chain_n ; n ++ ) { current_proxy = & net_handle -> proxy_info -> proxy_chain [ n ] ; switch ( current_proxy -> type ) { case BP_NETWORK_PROXY_TYPE_SOCKS4A : BP_NetProxyConnectSOCKS4A ( net_handle , current_proxy ) ; if ( current_proxy -> connected == BP_FALSE ) return ERR_FAILURE ; net_handle -> current_proxy_depth ++ ; break ; case BP_NETWORK_PROXY_TYPE_SOCKS5 : BP_NetProxyConnectSOCKS5 ( net_handle , current_proxy ) ; if ( current_proxy -> connected == BP_FALSE ) return ERR_FAILURE ; net_handle -> current_proxy_depth ++ ; break ; case BP_NETWORK_PROXY_TYPE_CONNECT : break ; default : return ERR_FAILURE ; break ; } } net_handle -> proxy_chain_established_successfully = true ; return ERR_SUCCESS ; }
This routine attempts to connect all the proxies found within a provided network handle.
This routine attempts to connect all the proxies found within a provided network handle .
// ensure we have a network handle // ensure we have a proxy info structure // ensure we have proxies within the proxy info // structure. // reference pointer used for convienence within the lower loop // walk the chain and attempt connects // set handle to current proxy // switch on the proxy type to determine which connect routine to // utilize when making the connection. // if the type is socks4a, attempt to connect // attempt to connect through a socks4 proxy // check to see if the proxy has connected OK, if not, exit // if we connected successfully, set the current proxy depth here // continue the loop // connect socks5 // attempt to connect through a socks4 proxy // check to see if the proxy has connected OK, if not, exit // if we connected successfully, set the current proxy depth here // continue the loop // connect via http connect proxy // default condition is a bad or unset proxy value, this causes chain to return // If we've exited here, we've successfully established a proxy // chain through this network handle. // return indicating success