Commit 837c8953 authored by Jakub Adam's avatar Jakub Adam Committed by Philip Withnall

socket: add nice_socket_is_base_of()

This will be used in the next commit.

Maniphest Tasks: T114
Reviewed-by: default avatarPhilip Withnall <philip.withnall@collabora.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D240
parent c6bc33c0
......@@ -95,6 +95,7 @@ static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
static gboolean socket_is_base_of (NiceSocket *sock, NiceSocket *other);
NiceSocket *
nice_http_socket_new (NiceSocket *base_socket,
......@@ -126,6 +127,7 @@ nice_http_socket_new (NiceSocket *base_socket,
sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->is_base_of = socket_is_base_of;
sock->close = socket_close;
/* Send HTTP CONNECT */
......@@ -642,3 +644,11 @@ socket_set_writable_callback (NiceSocket *sock,
nice_socket_set_writable_callback (priv->base_socket, callback, user_data);
}
static gboolean
socket_is_base_of (NiceSocket *sock, NiceSocket *other)
{
HttpPriv *priv = other->priv;
return (sock == other) || nice_socket_is_base_of (sock, priv->base_socket);
}
......@@ -116,6 +116,7 @@ static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
static gboolean socket_is_base_of (NiceSocket *sock, NiceSocket *other);
NiceSocket *
nice_pseudossl_socket_new (NiceSocket *base_socket,
......@@ -152,6 +153,7 @@ nice_pseudossl_socket_new (NiceSocket *base_socket,
sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->is_base_of = socket_is_base_of;
sock->close = socket_close;
/* We send 'to' NULL because it will always be to an already connected
......@@ -319,3 +321,11 @@ socket_set_writable_callback (NiceSocket *sock,
nice_socket_set_writable_callback (priv->base_socket, callback, user_data);
}
static gboolean
socket_is_base_of (NiceSocket *sock, NiceSocket *other)
{
PseudoSSLPriv *priv = other->priv;
return (sock == other) || nice_socket_is_base_of (sock, priv->base_socket);
}
......@@ -265,6 +265,14 @@ nice_socket_set_writable_callback (NiceSocket *sock,
sock->set_writable_callback (sock, callback, user_data);
}
gboolean
nice_socket_is_base_of (NiceSocket *sock, NiceSocket *other)
{
if (sock->is_base_of)
return sock->is_base_of (sock, other);
return (sock == other);
}
void
nice_socket_free (NiceSocket *sock)
{
......
......@@ -88,6 +88,7 @@ struct _NiceSocket
gboolean (*can_send) (NiceSocket *sock, NiceAddress *addr);
void (*set_writable_callback) (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
gboolean (*is_base_of) (NiceSocket *sock, NiceSocket *other);
void (*close) (NiceSocket *sock);
void *priv;
};
......@@ -124,6 +125,21 @@ void
nice_socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
/**
* nice_socket_is_base_of:
* @sock: a #NiceSocket
* @other: another #NiceSocket
*
* Check whether @sock is equal to, or a base socket of, @other or one of
* @other's base sockets.
*
* Returns: %TRUE if @sock is a base socket of @other, %FALSE otherwise
*
* Since: UNRELEASED
*/
gboolean
nice_socket_is_base_of (NiceSocket *sock, NiceSocket *other);
void
nice_socket_free (NiceSocket *sock);
......
......@@ -81,6 +81,7 @@ static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
static gboolean socket_is_base_of (NiceSocket *sock, NiceSocket *other);
NiceSocket *
......@@ -108,6 +109,7 @@ nice_socks5_socket_new (NiceSocket *base_socket,
sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->is_base_of = socket_is_base_of;
sock->close = socket_close;
/* Send SOCKS5 handshake */
......@@ -488,3 +490,11 @@ socket_set_writable_callback (NiceSocket *sock,
nice_socket_set_writable_callback (priv->base_socket, callback, user_data);
}
static gboolean
socket_is_base_of (NiceSocket *sock, NiceSocket *other)
{
Socks5Priv *priv = other->priv;
return (sock == other) || nice_socket_is_base_of (sock, priv->base_socket);
}
......@@ -86,6 +86,7 @@ static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
static gboolean socket_is_base_of (NiceSocket *sock, NiceSocket *other);
NiceSocket *
nice_udp_turn_over_tcp_socket_new (NiceSocket *base_socket,
......@@ -107,6 +108,7 @@ nice_udp_turn_over_tcp_socket_new (NiceSocket *base_socket,
sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->is_base_of = socket_is_base_of;
sock->close = socket_close;
return sock;
......@@ -458,3 +460,11 @@ socket_set_writable_callback (NiceSocket *sock,
nice_socket_set_writable_callback (priv->base_socket, callback, user_data);
}
static gboolean
socket_is_base_of (NiceSocket *sock, NiceSocket *other)
{
TurnTcpPriv *priv = other->priv;
return (sock == other) || nice_socket_is_base_of (sock, priv->base_socket);
}
......@@ -125,6 +125,7 @@ static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
static gboolean socket_is_base_of (NiceSocket *sock, NiceSocket *other);
static void priv_process_pending_bindings (UdpTurnPriv *priv);
static gboolean priv_retransmissions_tick_unlocked (UdpTurnPriv *priv);
......@@ -243,6 +244,7 @@ nice_udp_turn_socket_new (GMainContext *ctx, NiceAddress *addr,
sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->is_base_of = socket_is_base_of;
sock->close = socket_close;
sock->priv = (void *) priv;
......@@ -951,6 +953,14 @@ socket_set_writable_callback (NiceSocket *sock,
nice_socket_set_writable_callback (priv->base_socket, callback, user_data);
}
static gboolean
socket_is_base_of (NiceSocket *sock, NiceSocket *other)
{
UdpTurnPriv *priv = other->priv;
return (sock == other) || nice_socket_is_base_of (sock, priv->base_socket);
}
static gboolean
priv_forget_send_request (gpointer pointer)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment