summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Adam <jakub.adam@ktknet.cz>2015-09-11 11:29:39 +0100
committerPhilip Withnall <philip.withnall@collabora.co.uk>2015-09-11 11:30:23 +0100
commit837c8953fe87bdd5d5bccc444e72739100578ef8 (patch)
treed5c4af28aee37f5b08245bda48fc89746b06aa9e
parentc6bc33c031493e0db11a1f57055a656f6428c60a (diff)
downloadlibnice-837c8953fe87bdd5d5bccc444e72739100578ef8.tar.gz
socket: add nice_socket_is_base_of()
This will be used in the next commit. Maniphest Tasks: T114 Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk> Differential Revision: https://phabricator.freedesktop.org/D240
-rw-r--r--socket/http.c10
-rw-r--r--socket/pseudossl.c10
-rw-r--r--socket/socket.c8
-rw-r--r--socket/socket.h16
-rw-r--r--socket/socks5.c10
-rw-r--r--socket/udp-turn-over-tcp.c10
-rw-r--r--socket/udp-turn.c10
7 files changed, 74 insertions, 0 deletions
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;
@@ -952,6 +954,14 @@ socket_set_writable_callback (NiceSocket *sock,
}
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)
{
SendRequest *req = pointer;