library/src/network/BP-Network.cc
// adds a proxy to the chain stack
adds a proxy to the chain stack
adds a proxy to the chain stack
BP_ERROR_T BP_NetProxyAddChainElement
(
	P_BP_NETWORK_HANDLE   net_handle,
	char *                description,
	char *                proxy_ip_addr,
	unsigned short        proxy_port,
	char *                destination_host,
	unsigned short        destination_port,
	int                   destination_proto,
	BP_NETWORK_PROXY_TYPE type,
	char *                username,
	char *                passwd
)
{
	if(!net_handle)
		return ERR_FAILURE;
	if(!type)
		return ERR_FAILURE;
	if(!proxy_ip_addr)
		return ERR_FAILURE;
	if(!net_handle->tq)
		return ERR_FAILURE;
	if(!net_handle->proxy_info)
	{
		net_handle->proxy_info = (P_BP_NETWORK_PROXIES) tq_calloc(net_handle->tq, sizeof(BP_NETWORK_PROXIES), 1, BPLN);
		if(!net_handle->proxy_info)
			return ERR_FAILURE;
	}
	net_handle->proxy_info->proxy_chain_n++;
	net_handle->proxy_info->proxy_chain = (P_BP_NETWORK_PROXY) tq_realloc
										  (
												net_handle->tq,
												net_handle->proxy_info->proxy_chain,
												sizeof(BP_NETWORK_PROXY) * net_handle->proxy_info->proxy_chain_n,
												BPLN
											);
	if(!net_handle->proxy_info->proxy_chain)
		return ERR_FAILURE;
	memset
	(
			&net_handle->proxy_info->proxy_chain[net_handle->proxy_info->proxy_chain_n-1],
			0x00,
			sizeof(BP_NETWORK_PROXY)
	);
	P_BP_NETWORK_PROXY current_proxy = &net_handle->proxy_info->proxy_chain[net_handle->proxy_info->proxy_chain_n-1];
	char * new_uuid = BP_GenRandomUUID();
	if(description)
		current_proxy->description = tq_strdup(net_handle->tq, strdup(description), BPLN);
	tq_link_str(net_handle->tq, new_uuid, BPLN);
	current_proxy->uuid = new_uuid;
	current_proxy->type = type;
	if(proxy_ip_addr)
	current_proxy->proxy_ip_addr = (char *) tq_strdup(net_handle->tq, proxy_ip_addr,  BPLN);
	if(proxy_port)
	current_proxy->proxy_port    = proxy_port;
	if(proxy_ip_addr)
	current_proxy->proxy_ip_addr = (char *) tq_strdup(net_handle->tq, proxy_ip_addr,  BPLN);
	if(proxy_port)
	current_proxy->proxy_port    = proxy_port;
	if(destination_host)
	current_proxy->destination_host = (char *) tq_strdup(net_handle->tq, destination_host,  BPLN);
	if(destination_port)
	current_proxy->destination_port    = destination_port;
	if(username)
	current_proxy->user    = (char *) tq_strdup(net_handle->tq, username, BPLN);
	if(passwd)
	current_proxy->pass    = (char *) tq_strdup(net_handle->tq, passwd,   BPLN);
	current_proxy->connected = BP_FALSE;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_NetProxyAddChainElement ( P_BP_NETWORK_HANDLE net_handle , char * description , char * proxy_ip_addr , unsigned short proxy_port , char * destination_host , unsigned short destination_port , int destination_proto , BP_NETWORK_PROXY_TYPE type , char * username , char * passwd ) { if ( ! net_handle ) return ERR_FAILURE ; if ( ! type ) return ERR_FAILURE ; if ( ! proxy_ip_addr ) return ERR_FAILURE ; if ( ! net_handle -> tq ) return ERR_FAILURE ; if ( ! net_handle -> proxy_info ) { net_handle -> proxy_info = ( P_BP_NETWORK_PROXIES ) tq_calloc ( net_handle -> tq , sizeof ( BP_NETWORK_PROXIES ) , 1 , BPLN ) ; if ( ! net_handle -> proxy_info ) return ERR_FAILURE ; } net_handle -> proxy_info -> proxy_chain_n ++ ; net_handle -> proxy_info -> proxy_chain = ( P_BP_NETWORK_PROXY ) tq_realloc ( net_handle -> tq , net_handle -> proxy_info -> proxy_chain , sizeof ( BP_NETWORK_PROXY ) * net_handle -> proxy_info -> proxy_chain_n , BPLN ) ; if ( ! net_handle -> proxy_info -> proxy_chain ) return ERR_FAILURE ; memset ( & net_handle -> proxy_info -> proxy_chain [ net_handle -> proxy_info -> proxy_chain_n - 1 ] , 0x00 , sizeof ( BP_NETWORK_PROXY ) ) ; P_BP_NETWORK_PROXY current_proxy = & net_handle -> proxy_info -> proxy_chain [ net_handle -> proxy_info -> proxy_chain_n - 1 ] ; char * new_uuid = BP_GenRandomUUID ( ) ; if ( description ) current_proxy -> description = tq_strdup ( net_handle -> tq , strdup ( description ) , BPLN ) ; tq_link_str ( net_handle -> tq , new_uuid , BPLN ) ; current_proxy -> uuid = new_uuid ; current_proxy -> type = type ; if ( proxy_ip_addr ) current_proxy -> proxy_ip_addr = ( char * ) tq_strdup ( net_handle -> tq , proxy_ip_addr , BPLN ) ; if ( proxy_port ) current_proxy -> proxy_port = proxy_port ; if ( proxy_ip_addr ) current_proxy -> proxy_ip_addr = ( char * ) tq_strdup ( net_handle -> tq , proxy_ip_addr , BPLN ) ; if ( proxy_port ) current_proxy -> proxy_port = proxy_port ; if ( destination_host ) current_proxy -> destination_host = ( char * ) tq_strdup ( net_handle -> tq , destination_host , BPLN ) ; if ( destination_port ) current_proxy -> destination_port = destination_port ; if ( username ) current_proxy -> user = ( char * ) tq_strdup ( net_handle -> tq , username , BPLN ) ; if ( passwd ) current_proxy -> pass = ( char * ) tq_strdup ( net_handle -> tq , passwd , BPLN ) ; current_proxy -> connected = BP_FALSE ; return ERR_SUCCESS ; }
adds a proxy to the chain stack
adds a proxy to the chain stack
// ensure we have a network handle // check to make sure we have a valid type (zero value // is a bad type) // check we have an ip address to connect to // ensure the network handle has a valid tail queue allocator // if proxy info structure hasn't been created yet, create it // allocate space for proxy info // if we couldn't create the structure, return failure // increase the proxy chain count // (re)allocate space for the proxy chain element // ensure that the proxy chain was allocated ok // zero out the newly allocated memory // set local reference // create a new random uuid // set the description if one was passed in // link the new uuid in our tail queue allocator (memory managment) // set the current proxy uuid as the newly created one // set connection type // set ip address // set port // set ip address // set port // set ip address // set destination port // set username // set password // set connected flag to false (should already be set by calloc, but // assign here just in case BP_FALSE changes for whatever insane reason) // return indicating success