rtsp: make local_ip and remote_ip variables

Separate local_ip and remote_ip into separate variables for clarity.
This commit is contained in:
Wim Taymans 2013-04-04 12:32:24 +02:00
parent 4826ec4e4d
commit a4e44df6b9

View file

@ -105,7 +105,7 @@ typedef enum
struct _GstRTSPConnection struct _GstRTSPConnection
{ {
/*< private > */ /*< private > */
/* URL for the connection */ /* URL for the remote connection */
GstRTSPUrl *url; GstRTSPUrl *url;
/* connection state */ /* connection state */
@ -119,7 +119,9 @@ struct _GstRTSPConnection
gboolean tunneled; gboolean tunneled;
GstRTSPTunnelState tstate; GstRTSPTunnelState tstate;
gchar *ip; /* the remote and local ip */
gchar *remote_ip;
gchar *local_ip;
gint read_ahead; gint read_ahead;
@ -248,7 +250,7 @@ gst_rtsp_connection_create_from_socket (GSocket * socket, const gchar * ip,
GstRTSPResult res; GstRTSPResult res;
GSocketAddress *addr; GSocketAddress *addr;
GError *err = NULL; GError *err = NULL;
gchar *localip; gchar *local_ip;
g_return_val_if_fail (G_IS_SOCKET (socket), GST_RTSP_EINVAL); g_return_val_if_fail (G_IS_SOCKET (socket), GST_RTSP_EINVAL);
g_return_val_if_fail (ip != NULL, GST_RTSP_EINVAL); g_return_val_if_fail (ip != NULL, GST_RTSP_EINVAL);
@ -262,7 +264,7 @@ gst_rtsp_connection_create_from_socket (GSocket * socket, const gchar * ip,
if (!addr) if (!addr)
goto getnameinfo_failed; goto getnameinfo_failed;
localip = g_inet_address_to_string (g_inet_socket_address_get_address local_ip = g_inet_address_to_string (g_inet_socket_address_get_address
(G_INET_SOCKET_ADDRESS (addr))); (G_INET_SOCKET_ADDRESS (addr)));
g_object_unref (addr); g_object_unref (addr);
@ -279,7 +281,8 @@ gst_rtsp_connection_create_from_socket (GSocket * socket, const gchar * ip,
newconn->socket0 = G_SOCKET (g_object_ref (socket)); newconn->socket0 = G_SOCKET (g_object_ref (socket));
newconn->socket1 = G_SOCKET (g_object_ref (socket)); newconn->socket1 = G_SOCKET (g_object_ref (socket));
newconn->write_socket = newconn->read_socket = newconn->socket0; newconn->write_socket = newconn->read_socket = newconn->socket0;
newconn->ip = localip; newconn->remote_ip = g_strdup (ip);
newconn->local_ip = local_ip;
newconn->initial_buffer = g_strdup (initial_buffer); newconn->initial_buffer = g_strdup (initial_buffer);
*conn = newconn; *conn = newconn;
@ -296,7 +299,7 @@ getnameinfo_failed:
newconn_failed: newconn_failed:
{ {
GST_ERROR ("failed to make connection"); GST_ERROR ("failed to make connection");
g_free (localip); g_free (local_ip);
gst_rtsp_url_free (url); gst_rtsp_url_free (url);
return res; return res;
} }
@ -335,6 +338,7 @@ gst_rtsp_connection_accept (GSocket * socket, GstRTSPConnection ** conn,
if (!addr) if (!addr)
goto getnameinfo_failed; goto getnameinfo_failed;
/* get the remote ip address and port */
ip = g_inet_address_to_string (g_inet_socket_address_get_address ip = g_inet_address_to_string (g_inet_socket_address_get_address
(G_INET_SOCKET_ADDRESS (addr))); (G_INET_SOCKET_ADDRESS (addr)));
port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr)); port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr));
@ -536,7 +540,7 @@ setup_tunneling (GstRTSPConnection * conn, GTimeVal * timeout)
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->ip; ip = conn->remote_ip;
port = url_port; port = url_port;
} }
@ -590,8 +594,8 @@ setup_tunneling (GstRTSPConnection * conn, GTimeVal * timeout)
/* and resolve the new ip address */ /* and resolve the new ip address */
if (!(ip = do_resolve (value, conn->cancellable))) if (!(ip = do_resolve (value, conn->cancellable)))
goto not_resolved; goto not_resolved;
g_free (conn->ip); g_free (conn->remote_ip);
conn->ip = ip; conn->remote_ip = ip;
} }
} }
@ -662,7 +666,7 @@ wrong_result:
} }
not_resolved: not_resolved:
{ {
GST_ERROR ("could not resolve %s", conn->ip); GST_ERROR ("could not resolve %s", conn->remote_ip);
res = GST_RTSP_ENET; res = GST_RTSP_ENET;
goto exit; goto exit;
} }
@ -717,8 +721,8 @@ gst_rtsp_connection_connect (GstRTSPConnection * conn, GTimeVal * timeout)
/* 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);
g_free (conn->ip); g_free (conn->remote_ip);
conn->ip = ip; conn->remote_ip = ip;
} }
/* connect to the host/port */ /* connect to the host/port */
@ -2018,9 +2022,11 @@ gen_tunnel_reply (GstRTSPConnection * conn, GstRTSPStatusCode code,
gst_rtsp_message_add_header (msg, GST_RTSP_HDR_PRAGMA, "no-cache"); gst_rtsp_message_add_header (msg, GST_RTSP_HDR_PRAGMA, "no-cache");
if (code == GST_RTSP_STS_OK) { if (code == GST_RTSP_STS_OK) {
if (conn->ip) /* add the local ip address to the tunnel reply, this is where the client
* should send the POST request to */
if (conn->local_ip)
gst_rtsp_message_add_header (msg, GST_RTSP_HDR_X_SERVER_IP_ADDRESS, gst_rtsp_message_add_header (msg, GST_RTSP_HDR_X_SERVER_IP_ADDRESS,
conn->ip); conn->local_ip);
gst_rtsp_message_add_header (msg, GST_RTSP_HDR_CONTENT_TYPE, gst_rtsp_message_add_header (msg, GST_RTSP_HDR_CONTENT_TYPE,
"application/x-rtsp-tunnelled"); "application/x-rtsp-tunnelled");
} }
@ -2186,8 +2192,10 @@ gst_rtsp_connection_close (GstRTSPConnection * conn)
conn->socket1 = NULL; conn->socket1 = NULL;
} }
g_free (conn->ip); g_free (conn->remote_ip);
conn->ip = NULL; conn->remote_ip = NULL;
g_free (conn->local_ip);
conn->local_ip = NULL;
conn->read_ahead = 0; conn->read_ahead = 0;
@ -2680,7 +2688,7 @@ gst_rtsp_connection_get_ip (const GstRTSPConnection * conn)
{ {
g_return_val_if_fail (conn != NULL, NULL); g_return_val_if_fail (conn != NULL, NULL);
return conn->ip; return conn->remote_ip;
} }
/** /**
@ -2695,8 +2703,8 @@ gst_rtsp_connection_set_ip (GstRTSPConnection * conn, const gchar * ip)
{ {
g_return_if_fail (conn != NULL); g_return_if_fail (conn != NULL);
g_free (conn->ip); g_free (conn->remote_ip);
conn->ip = g_strdup (ip); conn->remote_ip = g_strdup (ip);
} }
/** /**