Beispiel #1
0
static OWSLSocket *
transport_socket_add
(
	OWSLSocket socket,
	TransportType type
)
{
	OWSLSocketMode mode ;
	OWSLSocket * allocated_socket = NULL ;
	OWSLCallback callback ;
	OWList * list ;

	if (socket > 0)
	{
		allocated_socket = malloc (sizeof (OWSLSocket)) ;
		if (allocated_socket != NULL)
		{
			if (owsl_blocking_mode_set (socket, OWSL_NON_BLOCKING))
			{
				owsl_close (socket) ;
				free (allocated_socket) ;
				return NULL ;
			}

			mode = owsl_mode_get (socket) ;
			list = transport_socket_list_get (type, mode) ;
			callback = transport_callback_get (type, mode) ;

			if (owsl_callback_set (socket, callback, NULL))
			{
				owsl_close (socket) ;
				free (allocated_socket) ;
				return NULL ;
			}

			* allocated_socket = socket ;

			if (owlist_add (list, allocated_socket, transport_socket_compare))
			{
				owsl_close (socket) ;
				free (allocated_socket) ;
				return NULL ;
			}
		}
	}

	return allocated_socket ;
}
Beispiel #2
0
static int
transport_socket_free
(
	OWSLSocket * socket
)
{
	int return_code = 0 ;
	return_code |= owsl_close (* socket) ;
	free (socket) ;
	return return_code ;
}
Beispiel #3
0
int
owsl_socket_terminate
(void)
{
	OWSLSocket socket ;
	int return_code = 0 ;

	for (socket = 1 ; socket <= OWSL_SOCKET_MAX ; socket ++)
	{
		if (owsl_socket_info_get (socket) != NULL)
		{
			return_code |= owsl_close (socket) ;
		}
	}

	return return_code ;
}
Beispiel #4
0
HttpRet is_tunnel_conn_allowed(const char *http_gate_addr, int http_gate_port,
								const char *sip_addr, int sip_port,
								const char *proxy_addr, int proxy_port,
								const char *proxy_login, const char *proxy_passwd,
								NETLIB_BOOLEAN ssl, int timeout, const char *sip_realm,
								NETLIB_BOOLEAN ping, int ping_timeout)
{
	int return_code = 0 ;
	OWSLSocket http_tunnel_socket ;
	int proxy_enabled = (proxy_addr != NULL && *proxy_addr ? 1 : 0) ;
	struct sockaddr * remote_address ;

	/* TODO: IPv6 support in netlib */
	http_tunnel_socket = owsl_socket_by_type
	(
		ssl == NETLIB_TRUE ? OWSL_TYPE_IPV4_UOHS : OWSL_TYPE_IPV4_UOH
	) ;
	if (http_tunnel_socket <= 0)
	{
		return HTTP_NOK ;
	}

	return_code |= owsl_parameter_set (http_tunnel_socket, "proxy.local.enable", & proxy_enabled) ;
	return_code |= owsl_parameter_set (http_tunnel_socket, "proxy.local.addr", proxy_addr) ;
	return_code |= owsl_parameter_set (http_tunnel_socket, "proxy.local.port", & proxy_port) ;
	return_code |= owsl_parameter_set (http_tunnel_socket, "proxy.local.login", proxy_login) ;
	return_code |= owsl_parameter_set (http_tunnel_socket, "proxy.local.passwd", proxy_passwd) ;
	return_code |= owsl_parameter_set (http_tunnel_socket, "gateway.http.addr", http_gate_addr) ;
	return_code |= owsl_parameter_set (http_tunnel_socket, "gateway.http.port", & http_gate_port) ;
	return_code |= owsl_parameter_set (http_tunnel_socket, "connection.timeout", & timeout) ;
	if (return_code != 0)
	{
		owsl_close (http_tunnel_socket) ;
		return HTTP_NOK ;
	}

	/* TODO: IPv6 support */
	remote_address = owsl_address_port_new (OWSL_AF_IPV4, sip_addr, sip_port) ;
	if (remote_address == NULL)
	{
		owsl_close (http_tunnel_socket) ;
		return HTTP_NOK ;
	}

	return_code = owsl_connect
	(
		http_tunnel_socket,
		remote_address,
		OWSL_ADDRESS_SIZE
	) ;
	free (remote_address) ;
	if (return_code != 0)
	{
		owsl_close (http_tunnel_socket) ;
		return HTTP_NOK ;
		/* TODO: manage HTTP_AUTH ? */
	}

	if (ping)
	{
		return_code = sip_ping (http_tunnel_socket, ping_timeout, "nobody", sip_realm) ;
		if (return_code == NETLIB_FALSE)
		{
			owsl_close (http_tunnel_socket) ;
			return HTTP_NOK ;
		}
	}

	owsl_close (http_tunnel_socket) ;

	return HTTP_OK ;
}
Beispiel #5
0
NETLIB_BOOLEAN
udp_sip_ping
(
	const char * sip_server,
	unsigned short sip_port,
	unsigned short local_port,
	int ping_timeout,
	const char * sip_address,
	const char * sip_realm
)
{
	int return_code ;
	OWSLSocket udp_socket ;
	struct sockaddr * local_address ;
	struct sockaddr * remote_address ;
	char * ip = OWSL_LOCAL_ADDRESS ;
	char public_ip [OWSL_IP_MAX_SIZE] ;
	if (owsl_address_public_ip_get (OWSL_AF_IPV4, public_ip, sizeof (public_ip)) == 0)
	{
		ip = public_ip ;
	}

	/* TODO: IPv6 support in netlib */
	udp_socket = owsl_socket_by_type (OWSL_TYPE_IPV4_UDP) ;
	if (udp_socket <= 0)
	{
		return NETLIB_FALSE ;
	}

	return_code = owsl_reuse_set (udp_socket) ;
	if (return_code != 0)
	{
		owsl_close (udp_socket) ;
		return NETLIB_FALSE ;
	}

	/* TODO: IPv6 support in netlib */
	local_address = owsl_address_ip_port_new (OWSL_AF_IPV4, ip, local_port) ;
	if (local_address == NULL)
	{
		owsl_close (udp_socket) ;
		return NETLIB_FALSE ;
	}

	return_code = owsl_bind (udp_socket, local_address, /*OWSL_ADDRESS_SIZE*/sizeof(struct sockaddr)) ;
	free (local_address) ;
	if (return_code != 0)
	{
		owsl_close (udp_socket) ;
		return NETLIB_FALSE ;
	}

	/* TODO: IPv6 support in netlib */
	remote_address = owsl_address_port_new (OWSL_AF_IPV4, sip_server, sip_port) ;
	if (remote_address == NULL)
	{
		owsl_close (udp_socket) ;
		return NETLIB_FALSE ;
	}

	return_code = owsl_connect (udp_socket, remote_address, /*OWSL_ADDRESS_SIZE*/sizeof(struct sockaddr)) ;
	free (remote_address) ;
	if (return_code != 0)
	{
		NETLIB_LOG_ERROR (make_error_string ("udp_sip_ping : connect")) ;
		owsl_close (udp_socket) ;
		return NETLIB_FALSE ;
	}

	return_code = sip_ping (udp_socket, ping_timeout, sip_address, sip_realm) ;

	owsl_close (udp_socket) ;

	return return_code == 0 ? NETLIB_TRUE : NETLIB_FALSE ;
}