component_attach_socket (component, cdisco->nicesock);
}
- cdisco->turn = turn;
+ cdisco->turn = turn_server_ref (turn);
cdisco->server = turn->server;
cdisco->stream = stream;
if (candidate->password)
g_free (candidate->password);
+ if (candidate->turn)
+ turn_server_unref (candidate->turn);
+
g_slice_free (NiceCandidate, candidate);
}
memcpy (copy, candidate, sizeof(NiceCandidate));
+ copy->turn = NULL;
copy->username = g_strdup (copy->username);
copy->password = g_strdup (copy->password);
*/
struct _TurnServer
{
+ gint ref_count;
+
NiceAddress server; /**< TURN server address */
gchar *username; /**< TURN username */
gchar *password; /**< TURN password */
void
component_clean_turn_servers (Component *cmp)
{
- GList *item;
- for (item = cmp->turn_servers; item; item = g_list_next (item)) {
- TurnServer *turn = item->data;
- g_free (turn->username);
- g_free (turn->password);
- g_slice_free (TurnServer, turn);
- }
- g_list_free (cmp->turn_servers);
+ g_list_free_full (cmp->turn_servers, (GDestroyNotify) turn_server_unref);
cmp->turn_servers = NULL;
}
nice_address_init (&turn->server);
+ turn->ref_count = 1;
if (nice_address_set_from_string (&turn->server, server_ip)) {
nice_address_set_port (&turn->server, server_port);
} else {
return turn;
}
+
+TurnServer *
+turn_server_ref (TurnServer *turn)
+{
+ turn->ref_count++;
+
+ return turn;
+}
+
+void
+turn_server_unref (TurnServer *turn)
+{
+ turn->ref_count--;
+
+ if (turn->ref_count == 0) {
+ g_free (turn->username);
+ g_free (turn->password);
+ g_slice_free (TurnServer, turn);
+ }
+}
turn_server_new (const gchar *server_ip, guint server_port,
const gchar *username, const gchar *password, NiceRelayType type);
+TurnServer *
+turn_server_ref (TurnServer *turn);
+
+void
+turn_server_unref (TurnServer *turn);
+
+
G_END_DECLS
#endif /* _NICE_COMPONENT_H */
*/
static void discovery_free_item (CandidateDiscovery *cand)
{
+ if (cand->turn)
+ turn_server_unref (cand->turn);
+
g_slice_free (CandidateDiscovery, cand);
}
candidate->stream_id = stream_id;
candidate->component_id = component_id;
candidate->addr = *address;
- candidate->turn = turn;
+ candidate->turn = turn_server_ref (turn);
/* step: link to the base candidate+socket */
relay_socket = nice_turn_socket_new (agent->main_context, address,