mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
Revert "rtspconnection: Use a GSocketAddressNumerator to resolve the addresses"
This reverts commit 15a0bb0a10
.
We should be using GSocketClient
This commit is contained in:
parent
00bbca2f9f
commit
15f3c995aa
1 changed files with 98 additions and 117 deletions
|
@ -370,14 +370,71 @@ getnameinfo_failed:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gchar *
|
||||||
|
do_resolve (const gchar * host, GCancellable * cancellable)
|
||||||
|
{
|
||||||
|
GResolver *resolver;
|
||||||
|
GInetAddress *addr;
|
||||||
|
GError *err = NULL;
|
||||||
|
gchar *ip;
|
||||||
|
|
||||||
|
addr = g_inet_address_new_from_string (host);
|
||||||
|
if (!addr) {
|
||||||
|
GList *results, *l;
|
||||||
|
|
||||||
|
resolver = g_resolver_get_default ();
|
||||||
|
|
||||||
|
results = g_resolver_lookup_by_name (resolver, host, cancellable, &err);
|
||||||
|
if (!results)
|
||||||
|
goto name_resolve;
|
||||||
|
|
||||||
|
for (l = results; l; l = l->next) {
|
||||||
|
GInetAddress *tmp = l->data;
|
||||||
|
|
||||||
|
if (g_inet_address_get_family (tmp) == G_SOCKET_FAMILY_IPV4 ||
|
||||||
|
g_inet_address_get_family (tmp) == G_SOCKET_FAMILY_IPV6) {
|
||||||
|
addr = G_INET_ADDRESS (g_object_ref (tmp));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_resolver_free_addresses (results);
|
||||||
|
g_object_unref (resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!addr)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ip = g_inet_address_to_string (addr);
|
||||||
|
g_object_unref (addr);
|
||||||
|
|
||||||
|
return ip;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
name_resolve:
|
||||||
|
{
|
||||||
|
GST_ERROR ("failed to resolve %s: %s", host, err->message);
|
||||||
|
g_clear_error (&err);
|
||||||
|
g_object_unref (resolver);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static GstRTSPResult
|
static GstRTSPResult
|
||||||
do_connect (GSocketAddress * saddr, GSocket ** socket_out,
|
do_connect (const gchar * ip, guint16 port, GSocket ** socket_out,
|
||||||
GTimeVal * timeout, GCancellable * cancellable)
|
GTimeVal * timeout, GCancellable * cancellable)
|
||||||
{
|
{
|
||||||
GSocket *socket;
|
GSocket *socket;
|
||||||
GstClockTime to;
|
GstClockTime to;
|
||||||
|
GInetAddress *addr;
|
||||||
|
GSocketAddress *saddr;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
|
|
||||||
|
addr = g_inet_address_new_from_string (ip);
|
||||||
|
g_assert (addr);
|
||||||
|
saddr = g_inet_socket_address_new (addr, port);
|
||||||
|
g_object_unref (addr);
|
||||||
|
|
||||||
socket =
|
socket =
|
||||||
g_socket_new (g_socket_address_get_family (saddr), G_SOCKET_TYPE_STREAM,
|
g_socket_new (g_socket_address_get_family (saddr), G_SOCKET_TYPE_STREAM,
|
||||||
G_SOCKET_PROTOCOL_TCP, &err);
|
G_SOCKET_PROTOCOL_TCP, &err);
|
||||||
|
@ -414,6 +471,7 @@ do_connect (GSocketAddress * saddr, GSocket ** socket_out,
|
||||||
goto sys_error;
|
goto sys_error;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
g_object_unref (saddr);
|
||||||
|
|
||||||
*socket_out = socket;
|
*socket_out = socket;
|
||||||
|
|
||||||
|
@ -424,12 +482,14 @@ no_socket:
|
||||||
{
|
{
|
||||||
GST_ERROR ("no socket: %s", err->message);
|
GST_ERROR ("no socket: %s", err->message);
|
||||||
g_clear_error (&err);
|
g_clear_error (&err);
|
||||||
|
g_object_unref (saddr);
|
||||||
return GST_RTSP_ESYS;
|
return GST_RTSP_ESYS;
|
||||||
}
|
}
|
||||||
sys_error:
|
sys_error:
|
||||||
{
|
{
|
||||||
GST_ERROR ("system error: %s", err->message);
|
GST_ERROR ("system error: %s", err->message);
|
||||||
g_clear_error (&err);
|
g_clear_error (&err);
|
||||||
|
g_object_unref (saddr);
|
||||||
g_object_unref (socket);
|
g_object_unref (socket);
|
||||||
return GST_RTSP_ESYS;
|
return GST_RTSP_ESYS;
|
||||||
}
|
}
|
||||||
|
@ -437,20 +497,21 @@ timeout:
|
||||||
{
|
{
|
||||||
GST_ERROR ("timeout");
|
GST_ERROR ("timeout");
|
||||||
g_clear_error (&err);
|
g_clear_error (&err);
|
||||||
|
g_object_unref (saddr);
|
||||||
g_object_unref (socket);
|
g_object_unref (socket);
|
||||||
return GST_RTSP_ETIMEOUT;
|
return GST_RTSP_ETIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstRTSPResult
|
static GstRTSPResult
|
||||||
setup_tunneling (GstRTSPConnection * conn, GSocketAddress * sockaddr,
|
setup_tunneling (GstRTSPConnection * conn, GTimeVal * timeout)
|
||||||
GTimeVal * timeout)
|
|
||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
GstRTSPResult res;
|
GstRTSPResult res;
|
||||||
|
gchar *ip;
|
||||||
gchar *uri;
|
gchar *uri;
|
||||||
gchar *value;
|
gchar *value;
|
||||||
guint16 url_port;
|
guint16 port, url_port;
|
||||||
GstRTSPUrl *url;
|
GstRTSPUrl *url;
|
||||||
gchar *hostparam;
|
gchar *hostparam;
|
||||||
GstRTSPMessage *msg;
|
GstRTSPMessage *msg;
|
||||||
|
@ -473,10 +534,14 @@ setup_tunneling (GstRTSPConnection * conn, GSocketAddress * sockaddr,
|
||||||
uri = g_strdup_printf ("http://%s:%d%s%s%s", url->host, url_port,
|
uri = g_strdup_printf ("http://%s:%d%s%s%s", url->host, url_port,
|
||||||
url->abspath, url->query ? "?" : "", url->query ? url->query : "");
|
url->abspath, url->query ? "?" : "", url->query ? url->query : "");
|
||||||
hostparam = g_strdup_printf ("%s:%d", url->host, url_port);
|
hostparam = g_strdup_printf ("%s:%d", url->host, url_port);
|
||||||
|
ip = conn->proxy_host;
|
||||||
|
port = conn->proxy_port;
|
||||||
} else {
|
} else {
|
||||||
uri = g_strdup_printf ("%s%s%s", url->abspath, url->query ? "?" : "",
|
uri = g_strdup_printf ("%s%s%s", url->abspath, url->query ? "?" : "",
|
||||||
url->query ? url->query : "");
|
url->query ? url->query : "");
|
||||||
hostparam = NULL;
|
hostparam = NULL;
|
||||||
|
ip = conn->remote_ip;
|
||||||
|
port = url_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create the GET request for the read connection */
|
/* create the GET request for the read connection */
|
||||||
|
@ -525,67 +590,20 @@ setup_tunneling (GstRTSPConnection * conn, GSocketAddress * sockaddr,
|
||||||
url->host = g_strdup (value);
|
url->host = g_strdup (value);
|
||||||
g_free (hostparam);
|
g_free (hostparam);
|
||||||
hostparam = g_strdup_printf ("%s:%d", url->host, url_port);
|
hostparam = g_strdup_printf ("%s:%d", url->host, url_port);
|
||||||
|
|
||||||
/* connect to the host/port */
|
|
||||||
res = do_connect (sockaddr, &conn->socket1, timeout, conn->cancellable);
|
|
||||||
if (res != GST_RTSP_OK)
|
|
||||||
goto connect_failed;
|
|
||||||
} else {
|
} else {
|
||||||
GSocketConnectable *connectable;
|
|
||||||
GSocketAddressEnumerator *enumerator;
|
|
||||||
GError *error = NULL;
|
|
||||||
gboolean first = TRUE;
|
|
||||||
|
|
||||||
sockaddr = NULL;
|
|
||||||
|
|
||||||
/* and resolve the new ip address */
|
/* and resolve the new ip address */
|
||||||
connectable = g_network_address_new (value, url_port);
|
if (!(ip = do_resolve (value, conn->cancellable)))
|
||||||
enumerator = g_socket_connectable_enumerate (connectable);
|
goto not_resolved;
|
||||||
g_object_unref (connectable);
|
g_free (conn->remote_ip);
|
||||||
|
conn->remote_ip = ip;
|
||||||
while (TRUE) {
|
|
||||||
sockaddr =
|
|
||||||
g_socket_address_enumerator_next (enumerator, conn->cancellable,
|
|
||||||
&error);
|
|
||||||
if (!sockaddr) {
|
|
||||||
if (!error)
|
|
||||||
GST_DEBUG ("no more addresses");
|
|
||||||
else
|
|
||||||
GST_DEBUG ("failed to retrieve next address %s", error->message);
|
|
||||||
|
|
||||||
g_object_unref (enumerator);
|
|
||||||
|
|
||||||
res = GST_RTSP_ESYS;
|
|
||||||
if (first)
|
|
||||||
goto not_resolved;
|
|
||||||
else
|
|
||||||
goto connect_failed;
|
|
||||||
}
|
|
||||||
first = FALSE;
|
|
||||||
|
|
||||||
/* connect to the host/port */
|
|
||||||
res = do_connect (sockaddr, &conn->socket0, timeout, conn->cancellable);
|
|
||||||
|
|
||||||
if (res == GST_RTSP_OK) {
|
|
||||||
g_free (conn->remote_ip);
|
|
||||||
conn->remote_ip =
|
|
||||||
g_inet_address_to_string (g_inet_socket_address_get_address
|
|
||||||
(G_INET_SOCKET_ADDRESS (sockaddr)));
|
|
||||||
g_object_unref (sockaddr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
g_object_unref (sockaddr);
|
|
||||||
sockaddr = NULL;
|
|
||||||
}
|
|
||||||
g_object_unref (enumerator);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
/* connect to the host/port */
|
|
||||||
res = do_connect (sockaddr, &conn->socket1, timeout, conn->cancellable);
|
|
||||||
if (res != GST_RTSP_OK)
|
|
||||||
goto connect_failed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* connect to the host/port */
|
||||||
|
res = do_connect (ip, port, &conn->socket1, timeout, conn->cancellable);
|
||||||
|
if (res != GST_RTSP_OK)
|
||||||
|
goto connect_failed;
|
||||||
|
|
||||||
/* this is now our writing socket */
|
/* this is now our writing socket */
|
||||||
conn->write_socket = conn->socket1;
|
conn->write_socket = conn->socket1;
|
||||||
|
|
||||||
|
@ -678,11 +696,8 @@ gst_rtsp_connection_connect (GstRTSPConnection * conn, GTimeVal * timeout)
|
||||||
{
|
{
|
||||||
GstRTSPResult res;
|
GstRTSPResult res;
|
||||||
gchar *ip;
|
gchar *ip;
|
||||||
|
guint16 port;
|
||||||
GstRTSPUrl *url;
|
GstRTSPUrl *url;
|
||||||
gboolean proxy = FALSE, first = TRUE;
|
|
||||||
GSocketConnectable *connectable;
|
|
||||||
GSocketAddressEnumerator *enumerator;
|
|
||||||
GSocketAddress *sockaddr = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (conn != NULL, GST_RTSP_EINVAL);
|
g_return_val_if_fail (conn != NULL, GST_RTSP_EINVAL);
|
||||||
g_return_val_if_fail (conn->url != NULL, GST_RTSP_EINVAL);
|
g_return_val_if_fail (conn->url != NULL, GST_RTSP_EINVAL);
|
||||||
|
@ -690,73 +705,39 @@ gst_rtsp_connection_connect (GstRTSPConnection * conn, GTimeVal * timeout)
|
||||||
|
|
||||||
url = conn->url;
|
url = conn->url;
|
||||||
|
|
||||||
|
|
||||||
if (conn->proxy_host && conn->tunneled) {
|
if (conn->proxy_host && conn->tunneled) {
|
||||||
connectable = g_network_address_new (conn->proxy_host, conn->proxy_port);
|
if (!(ip = do_resolve (conn->proxy_host, conn->cancellable))) {
|
||||||
proxy = TRUE;
|
GST_ERROR ("could not resolve %s", conn->proxy_host);
|
||||||
|
goto not_resolved;
|
||||||
|
}
|
||||||
|
port = conn->proxy_port;
|
||||||
|
g_free (conn->proxy_host);
|
||||||
|
conn->proxy_host = ip;
|
||||||
} else {
|
} else {
|
||||||
guint16 port;
|
if (!(ip = do_resolve (url->host, conn->cancellable))) {
|
||||||
|
GST_ERROR ("could not resolve %s", url->host);
|
||||||
|
goto not_resolved;
|
||||||
|
}
|
||||||
/* get the port from the url */
|
/* get the port from the url */
|
||||||
gst_rtsp_url_get_port (url, &port);
|
gst_rtsp_url_get_port (url, &port);
|
||||||
connectable = g_network_address_new (url->host, port);
|
|
||||||
|
g_free (conn->remote_ip);
|
||||||
|
conn->remote_ip = ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
enumerator = g_socket_connectable_enumerate (connectable);
|
/* connect to the host/port */
|
||||||
g_object_unref (connectable);
|
res = do_connect (ip, port, &conn->socket0, timeout, conn->cancellable);
|
||||||
|
if (res != GST_RTSP_OK)
|
||||||
while (TRUE) {
|
goto connect_failed;
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
sockaddr =
|
|
||||||
g_socket_address_enumerator_next (enumerator, conn->cancellable,
|
|
||||||
&error);
|
|
||||||
if (!sockaddr) {
|
|
||||||
if (!error)
|
|
||||||
GST_DEBUG ("no more addresses");
|
|
||||||
else
|
|
||||||
GST_DEBUG ("failed to retrieve next address %s", error->message);
|
|
||||||
g_clear_error (&error);
|
|
||||||
|
|
||||||
g_object_unref (enumerator);
|
|
||||||
res = GST_RTSP_ESYS;
|
|
||||||
if (first)
|
|
||||||
goto not_resolved;
|
|
||||||
else
|
|
||||||
goto connect_failed;
|
|
||||||
}
|
|
||||||
first = FALSE;
|
|
||||||
|
|
||||||
/* connect to the host/port */
|
|
||||||
res = do_connect (sockaddr, &conn->socket0, timeout, conn->cancellable);
|
|
||||||
|
|
||||||
if (res == GST_RTSP_OK) {
|
|
||||||
ip = g_inet_address_to_string (g_inet_socket_address_get_address
|
|
||||||
(G_INET_SOCKET_ADDRESS (sockaddr)));
|
|
||||||
if (proxy) {
|
|
||||||
conn->proxy_host = ip;
|
|
||||||
} else {
|
|
||||||
g_free (conn->remote_ip);
|
|
||||||
conn->remote_ip = ip;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
g_object_unref (sockaddr);
|
|
||||||
sockaddr = NULL;
|
|
||||||
}
|
|
||||||
g_object_unref (enumerator);
|
|
||||||
g_assert (sockaddr);
|
|
||||||
|
|
||||||
/* this is our read URL */
|
/* this is our read URL */
|
||||||
conn->read_socket = conn->socket0;
|
conn->read_socket = conn->socket0;
|
||||||
|
|
||||||
if (conn->tunneled) {
|
if (conn->tunneled) {
|
||||||
res = setup_tunneling (conn, sockaddr, timeout);
|
res = setup_tunneling (conn, timeout);
|
||||||
g_object_unref (sockaddr);
|
|
||||||
if (res != GST_RTSP_OK)
|
if (res != GST_RTSP_OK)
|
||||||
goto tunneling_failed;
|
goto tunneling_failed;
|
||||||
} else {
|
} else {
|
||||||
g_object_unref (sockaddr);
|
|
||||||
conn->write_socket = conn->socket0;
|
conn->write_socket = conn->socket0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue