summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2012-03-29 13:06:24 +0100
committerWill Thompson <will.thompson@collabora.co.uk>2012-12-06 14:46:58 +0000
commit191c3fbfa4f5309227e664273cd8b300871b04b9 (patch)
tree038296e62118b9402b5a13d18cbe0a8dc62d3ae6 /src
parenta188bd209fc34195a0ccd2d12485c1da68265299 (diff)
Split gabble_bytestream_socks5_initiate() in two
This more clearly separates the code which sets up the listener (which can fail) and the subsequent code to transmit IP addresses to the peer (which cannot fail), I think.
Diffstat (limited to 'src')
-rw-r--r--src/bytestream-socks5.c90
1 files changed, 51 insertions, 39 deletions
diff --git a/src/bytestream-socks5.c b/src/bytestream-socks5.c
index 282835bd6..0d34a8d65 100644
--- a/src/bytestream-socks5.c
+++ b/src/bytestream-socks5.c
@@ -1873,47 +1873,18 @@ new_connection_cb (GibberListener *listener,
}
/*
- * gabble_bytestream_socks5_initiate
- *
- * Implements gabble_bytestream_iface_initiate on GabbleBytestreamIface
+ * Consumes @ips.
*/
-static gboolean
-gabble_bytestream_socks5_initiate (GabbleBytestreamIface *iface)
+static void
+send_streamhosts (
+ GabbleBytestreamSocks5 *self,
+ GSList *ips)
{
- GabbleBytestreamSocks5 *self = GABBLE_BYTESTREAM_SOCKS5 (iface);
- GabbleBytestreamSocks5Private *priv =
- GABBLE_BYTESTREAM_SOCKS5_GET_PRIVATE (self);
+ GabbleBytestreamSocks5Private *priv = self->priv;
gchar *port;
gint port_num;
WockyStanza *msg;
WockyNode *query_node;
- GSList *ips, *ip;
-
- if (priv->bytestream_state != GABBLE_BYTESTREAM_STATE_INITIATING)
- {
- DEBUG ("bytestream is not is the initiating state (state %d)",
- priv->bytestream_state);
- return FALSE;
- }
-
- ips = get_local_interfaces_ips ();
- if (ips == NULL)
- {
- DEBUG ("Can't get IP addresses");
- return FALSE;
- }
-
- g_assert (priv->listener == NULL);
- priv->listener = gibber_listener_new ();
-
- g_signal_connect (priv->listener, "new-connection",
- G_CALLBACK (new_connection_cb), self);
-
- if (!gibber_listener_listen_tcp (priv->listener, 0, NULL))
- {
- DEBUG ("can't listen for incoming connection");
- return FALSE;
- }
port_num = gibber_listener_get_port (priv->listener);
port = g_strdup_printf ("%d", port_num);
@@ -1927,17 +1898,17 @@ gabble_bytestream_socks5_initiate (GabbleBytestreamIface *iface)
'*', &query_node,
')', NULL);
- for (ip = ips; ip != NULL; ip = g_slist_next (ip))
+ for (; ips != NULL; ips = g_slist_delete_link (ips, ips))
{
WockyNode *node = wocky_node_add_child (query_node, "streamhost");
wocky_node_set_attributes (node,
"jid", priv->self_full_jid,
- "host", ip->data,
+ "host", ips->data,
"port", port,
NULL);
- g_free (ip->data);
+ g_free (ips->data);
}
g_slist_free (ips);
@@ -1965,7 +1936,7 @@ gabble_bytestream_socks5_initiate (GabbleBytestreamIface *iface)
NULL);
g_free (portstr);
}
- g_slist_free (proxies);
+ g_slist_free (proxies);
}
else
{
@@ -1978,7 +1949,48 @@ gabble_bytestream_socks5_initiate (GabbleBytestreamIface *iface)
conn_util_send_iq_async (priv->conn, msg, NULL,
socks5_init_reply_cb, tp_weak_ref_new (self, NULL, NULL));
g_object_unref (msg);
+}
+
+/*
+ * gabble_bytestream_socks5_initiate
+ *
+ * Implements gabble_bytestream_iface_initiate on GabbleBytestreamIface
+ */
+static gboolean
+gabble_bytestream_socks5_initiate (GabbleBytestreamIface *iface)
+{
+ GabbleBytestreamSocks5 *self = GABBLE_BYTESTREAM_SOCKS5 (iface);
+ GabbleBytestreamSocks5Private *priv =
+ GABBLE_BYTESTREAM_SOCKS5_GET_PRIVATE (self);
+ GSList *ips;
+
+ if (priv->bytestream_state != GABBLE_BYTESTREAM_STATE_INITIATING)
+ {
+ DEBUG ("bytestream is not is the initiating state (state %d)",
+ priv->bytestream_state);
+ return FALSE;
+ }
+
+ ips = get_local_interfaces_ips ();
+ if (ips == NULL)
+ {
+ DEBUG ("Can't get IP addresses");
+ return FALSE;
+ }
+
+ g_assert (priv->listener == NULL);
+ priv->listener = gibber_listener_new ();
+
+ g_signal_connect (priv->listener, "new-connection",
+ G_CALLBACK (new_connection_cb), self);
+
+ if (!gibber_listener_listen_tcp (priv->listener, 0, NULL))
+ {
+ DEBUG ("can't listen for incoming connection");
+ return FALSE;
+ }
+ send_streamhosts (self, ips);
return TRUE;
}