Also initialize the number of timer retransmissions
[sipe-libnice.git] / agent / stream.c
blob1276ae27bad1d9362ff75697d9b0ff4be33751bd
1 /*
2 * This file is part of the Nice GLib ICE library.
4 * (C) 2006-2009 Collabora Ltd.
5 * Contact: Youness Alaoui
6 * (C) 2006-2009 Nokia Corporation. All rights reserved.
7 * Contact: Kai Vehmanen
9 * The contents of this file are subject to the Mozilla Public License Version
10 * 1.1 (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 * http://www.mozilla.org/MPL/
14 * Software distributed under the License is distributed on an "AS IS" basis,
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 * for the specific language governing rights and limitations under the
17 * License.
19 * The Original Code is the Nice GLib ICE library.
21 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
22 * Corporation. All Rights Reserved.
24 * Contributors:
25 * Dafydd Harries, Collabora Ltd.
26 * Youness Alaoui, Collabora Ltd.
28 * Alternatively, the contents of this file may be used under the terms of the
29 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
30 * case the provisions of LGPL are applicable instead of those above. If you
31 * wish to allow use of your version of this file only under the terms of the
32 * LGPL and not to allow others to use your version of this file under the
33 * MPL, indicate your decision by deleting the provisions above and replace
34 * them with the notice and other provisions required by the LGPL. If you do
35 * not delete the provisions above, a recipient may use your version of this
36 * file under either the MPL or the LGPL.
38 #ifdef HAVE_CONFIG_H
39 # include <config.h>
40 #endif
42 #include <string.h>
44 #include "stream.h"
47 * @file stream.c
48 * @brief ICE stream functionality
50 Stream *
51 stream_new (guint n_components)
53 Stream *stream;
54 guint n;
55 Component *component;
57 stream = g_slice_new0 (Stream);
58 for (n = 0; n < n_components; n++) {
59 component = component_new (n + 1);
60 stream->components = g_slist_append (stream->components, component);
63 stream->n_components = n_components;
64 stream->initial_binding_request_received = FALSE;
66 return stream;
69 void
70 stream_free (Stream *stream)
72 GSList *i;
74 for (i = stream->components; i; i = i->next) {
75 Component *component = i->data;
76 component_free (component);
77 i->data = NULL;
79 g_slist_free (stream->components);
80 g_slice_free (Stream, stream);
83 Component *
84 stream_find_component_by_id (const Stream *stream, guint id)
86 GSList *i;
88 for (i = stream->components; i; i = i->next) {
89 Component *component = i->data;
90 if (component && component->id == id)
91 return component;
94 return NULL;
98 * Returns true if all components of the stream are either
99 * 'CONNECTED' or 'READY' (connected plus nominated).
101 gboolean
102 stream_all_components_ready (const Stream *stream)
104 GSList *i;
106 for (i = stream->components; i; i = i->next) {
107 Component *component = i->data;
108 if (component &&
109 !(component->state == NICE_COMPONENT_STATE_CONNECTED ||
110 component->state == NICE_COMPONENT_STATE_READY))
111 return FALSE;
114 return TRUE;
119 * Initialized the local crendentials for the stream.
121 void stream_initialize_credentials (Stream *stream, NiceRNG *rng)
123 /* note: generate ufrag/pwd for the stream (see ICE 15.4.
124 * '"ice-ufrag" and "ice-pwd" Attributes', ID-19) */
125 nice_rng_generate_bytes_print (rng, NICE_STREAM_DEF_UFRAG - 1, stream->local_ufrag);
126 nice_rng_generate_bytes_print (rng, NICE_STREAM_DEF_PWD - 1, stream->local_password);
130 * Resets the stream state to that of a ICE restarted
131 * session.
133 gboolean
134 stream_restart (Stream *stream, NiceRNG *rng)
136 GSList *i;
137 gboolean res = TRUE;
139 stream->initial_binding_request_received = FALSE;
141 stream_initialize_credentials (stream, rng);
143 for (i = stream->components; i && res; i = i->next) {
144 Component *component = i->data;
146 res = component_restart (component);
149 return res;