From 837c8953fe87bdd5d5bccc444e72739100578ef8 Mon Sep 17 00:00:00 2001 From: Jakub Adam Date: Fri, 11 Sep 2015 11:29:39 +0100 Subject: socket: add nice_socket_is_base_of() This will be used in the next commit. Maniphest Tasks: T114 Reviewed-by: Philip Withnall Differential Revision: https://phabricator.freedesktop.org/D240 --- socket/http.c | 10 ++++++++++ socket/pseudossl.c | 10 ++++++++++ socket/socket.c | 8 ++++++++ socket/socket.h | 16 ++++++++++++++++ socket/socks5.c | 10 ++++++++++ socket/udp-turn-over-tcp.c | 10 ++++++++++ socket/udp-turn.c | 10 ++++++++++ 7 files changed, 74 insertions(+) diff --git a/socket/http.c b/socket/http.c index 404d378..3df3be4 100644 --- a/socket/http.c +++ b/socket/http.c @@ -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); +} diff --git a/socket/pseudossl.c b/socket/pseudossl.c index 5ad4f97..6e65c4a 100644 --- a/socket/pseudossl.c +++ b/socket/pseudossl.c @@ -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); +} diff --git a/socket/socket.c b/socket/socket.c index 9c0d978..f726971 100644 --- a/socket/socket.c +++ b/socket/socket.c @@ -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) { diff --git a/socket/socket.h b/socket/socket.h index 41ea07b..f324f0c 100644 --- a/socket/socket.h +++ b/socket/socket.h @@ -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); diff --git a/socket/socks5.c b/socket/socks5.c index 46d17fb..0603cad 100644 --- a/socket/socks5.c +++ b/socket/socks5.c @@ -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); +} diff --git a/socket/udp-turn-over-tcp.c b/socket/udp-turn-over-tcp.c index d97fa04..c0a1be5 100644 --- a/socket/udp-turn-over-tcp.c +++ b/socket/udp-turn-over-tcp.c @@ -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); +} diff --git a/socket/udp-turn.c b/socket/udp-turn.c index 12f90a0..2e6618e 100644 --- a/socket/udp-turn.c +++ b/socket/udp-turn.c @@ -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) { -- cgit v1.2.1