summaryrefslogtreecommitdiff
path: root/socket
diff options
context:
space:
mode:
authorJakub Adam <jakub.adam@ktknet.cz>2016-04-04 21:52:29 +0100
committerPhilip Withnall <philip@tecnocode.co.uk>2016-04-04 21:54:02 +0100
commite0ed4fb3a236710846d9129438e0077782569633 (patch)
tree269ec37b2454e95139091403facac1133541effb /socket
parent38268e53fde8cd97055d88d2066c0016fe04b31b (diff)
downloadlibnice-e0ed4fb3a236710846d9129438e0077782569633.tar.gz
socket: refactor nice_socket_is_base_of()
• rename to nice_socket_is_based_on() and swap the order of arguments accordingly; the implementation doesn't have to use the confusing 'return other->is_base_of()' pattern anymore • fix potential NULL dereferences The argument order in agent_recv_message_unlocked() was already wrongly swapped in 1732c7d6 and thus this commit isn't changing it back because that order has become the correct one. Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk> Differential Revision: https://phabricator.freedesktop.org/D866
Diffstat (limited to 'socket')
-rw-r--r--socket/http.c11
-rw-r--r--socket/pseudossl.c11
-rw-r--r--socket/socket.c6
-rw-r--r--socket/socket.h14
-rw-r--r--socket/socks5.c11
-rw-r--r--socket/udp-turn-over-tcp.c11
-rw-r--r--socket/udp-turn.c11
7 files changed, 41 insertions, 34 deletions
diff --git a/socket/http.c b/socket/http.c
index 3df3be4..e706dbe 100644
--- a/socket/http.c
+++ b/socket/http.c
@@ -95,7 +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);
+static gboolean socket_is_based_on (NiceSocket *sock, NiceSocket *other);
NiceSocket *
nice_http_socket_new (NiceSocket *base_socket,
@@ -127,7 +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->is_based_on = socket_is_based_on;
sock->close = socket_close;
/* Send HTTP CONNECT */
@@ -646,9 +646,10 @@ socket_set_writable_callback (NiceSocket *sock,
}
static gboolean
-socket_is_base_of (NiceSocket *sock, NiceSocket *other)
+socket_is_based_on (NiceSocket *sock, NiceSocket *other)
{
- HttpPriv *priv = other->priv;
+ HttpPriv *priv = sock->priv;
- return (sock == other) || nice_socket_is_base_of (sock, priv->base_socket);
+ return (sock == other) ||
+ (priv && nice_socket_is_based_on (priv->base_socket, other));
}
diff --git a/socket/pseudossl.c b/socket/pseudossl.c
index 6e65c4a..8ebd0c3 100644
--- a/socket/pseudossl.c
+++ b/socket/pseudossl.c
@@ -116,7 +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);
+static gboolean socket_is_based_on (NiceSocket *sock, NiceSocket *other);
NiceSocket *
nice_pseudossl_socket_new (NiceSocket *base_socket,
@@ -153,7 +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->is_based_on = socket_is_based_on;
sock->close = socket_close;
/* We send 'to' NULL because it will always be to an already connected
@@ -323,9 +323,10 @@ socket_set_writable_callback (NiceSocket *sock,
}
static gboolean
-socket_is_base_of (NiceSocket *sock, NiceSocket *other)
+socket_is_based_on (NiceSocket *sock, NiceSocket *other)
{
- PseudoSSLPriv *priv = other->priv;
+ PseudoSSLPriv *priv = sock->priv;
- return (sock == other) || nice_socket_is_base_of (sock, priv->base_socket);
+ return (sock == other) ||
+ (priv && nice_socket_is_based_on (priv->base_socket, other));
}
diff --git a/socket/socket.c b/socket/socket.c
index c514ecf..08ae31a 100644
--- a/socket/socket.c
+++ b/socket/socket.c
@@ -266,10 +266,10 @@ nice_socket_set_writable_callback (NiceSocket *sock,
}
gboolean
-nice_socket_is_base_of (NiceSocket *sock, NiceSocket *other)
+nice_socket_is_based_on (NiceSocket *sock, NiceSocket *other)
{
- if (other->is_base_of)
- return other->is_base_of (sock, other);
+ if (sock->is_based_on)
+ return sock->is_based_on (sock, other);
return (sock == other);
}
diff --git a/socket/socket.h b/socket/socket.h
index f324f0c..fadcbc1 100644
--- a/socket/socket.h
+++ b/socket/socket.h
@@ -88,7 +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);
+ gboolean (*is_based_on) (NiceSocket *sock, NiceSocket *other);
void (*close) (NiceSocket *sock);
void *priv;
};
@@ -126,19 +126,21 @@ nice_socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
/**
- * nice_socket_is_base_of:
+ * nice_socket_is_based_on:
* @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.
+ * Checks whether @sock wraps @other as a source and destination of its read and
+ * write operations. The function traverses the whole chain of @sock's base
+ * sockets until @other is found or the end is reached.
*
- * Returns: %TRUE if @sock is a base socket of @other, %FALSE otherwise
+ * Returns: %TRUE if @sock is based on @other or if @sock and @other are
+ * the same socket, %FALSE otherwise.
*
* Since: UNRELEASED
*/
gboolean
-nice_socket_is_base_of (NiceSocket *sock, NiceSocket *other);
+nice_socket_is_based_on (NiceSocket *sock, NiceSocket *other);
void
nice_socket_free (NiceSocket *sock);
diff --git a/socket/socks5.c b/socket/socks5.c
index 0603cad..cdf295a 100644
--- a/socket/socks5.c
+++ b/socket/socks5.c
@@ -81,7 +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);
+static gboolean socket_is_based_on (NiceSocket *sock, NiceSocket *other);
NiceSocket *
@@ -109,7 +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->is_based_on = socket_is_based_on;
sock->close = socket_close;
/* Send SOCKS5 handshake */
@@ -492,9 +492,10 @@ socket_set_writable_callback (NiceSocket *sock,
}
static gboolean
-socket_is_base_of (NiceSocket *sock, NiceSocket *other)
+socket_is_based_on (NiceSocket *sock, NiceSocket *other)
{
- Socks5Priv *priv = other->priv;
+ Socks5Priv *priv = sock->priv;
- return (sock == other) || nice_socket_is_base_of (sock, priv->base_socket);
+ return (sock == other) ||
+ (priv && nice_socket_is_based_on (priv->base_socket, other));
}
diff --git a/socket/udp-turn-over-tcp.c b/socket/udp-turn-over-tcp.c
index c0a1be5..fb788b3 100644
--- a/socket/udp-turn-over-tcp.c
+++ b/socket/udp-turn-over-tcp.c
@@ -86,7 +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);
+static gboolean socket_is_based_on (NiceSocket *sock, NiceSocket *other);
NiceSocket *
nice_udp_turn_over_tcp_socket_new (NiceSocket *base_socket,
@@ -108,7 +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->is_based_on = socket_is_based_on;
sock->close = socket_close;
return sock;
@@ -462,9 +462,10 @@ socket_set_writable_callback (NiceSocket *sock,
}
static gboolean
-socket_is_base_of (NiceSocket *sock, NiceSocket *other)
+socket_is_based_on (NiceSocket *sock, NiceSocket *other)
{
- TurnTcpPriv *priv = other->priv;
+ TurnTcpPriv *priv = sock->priv;
- return (sock == other) || nice_socket_is_base_of (sock, priv->base_socket);
+ return (sock == other) ||
+ (priv && nice_socket_is_based_on (priv->base_socket, other));
}
diff --git a/socket/udp-turn.c b/socket/udp-turn.c
index e6e7f89..7786c55 100644
--- a/socket/udp-turn.c
+++ b/socket/udp-turn.c
@@ -125,7 +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 gboolean socket_is_based_on (NiceSocket *sock, NiceSocket *other);
static void priv_process_pending_bindings (UdpTurnPriv *priv);
static gboolean priv_retransmissions_tick_unlocked (UdpTurnPriv *priv);
@@ -244,7 +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->is_based_on = socket_is_based_on;
sock->close = socket_close;
sock->priv = (void *) priv;
@@ -954,11 +954,12 @@ socket_set_writable_callback (NiceSocket *sock,
}
static gboolean
-socket_is_base_of (NiceSocket *sock, NiceSocket *other)
+socket_is_based_on (NiceSocket *sock, NiceSocket *other)
{
- UdpTurnPriv *priv = other->priv;
+ UdpTurnPriv *priv = sock->priv;
- return (sock == other) || nice_socket_is_base_of (sock, priv->base_socket);
+ return (sock == other) ||
+ (priv && nice_socket_is_based_on (priv->base_socket, other));
}
static gboolean