stupid WLM 2009 CRC32 typo workaround (ugly, I know...)
[sipe-libnice.git] / agent / stream.c
blobe6dd82c5f16c0cf31cc6b15e0052ef1aec2f6313
1 /*
2 * This file is part of the Nice GLib ICE library.
4 * (C) 2006, 2007 Collabora Ltd.
5 * Contact: Dafydd Harries
6 * (C) 2006, 2007 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.
27 * Alternatively, the contents of this file may be used under the terms of the
28 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
29 * case the provisions of LGPL are applicable instead of those above. If you
30 * wish to allow use of your version of this file only under the terms of the
31 * LGPL and not to allow others to use your version of this file under the
32 * MPL, indicate your decision by deleting the provisions above and replace
33 * them with the notice and other provisions required by the LGPL. If you do
34 * not delete the provisions above, a recipient may use your version of this
35 * file under either the MPL or the LGPL.
37 #ifdef HAVE_CONFIG_H
38 # include <config.h>
39 #endif
41 #include <string.h>
43 #include "stream.h"
45 /**
46 * @file stream.c
47 * @brief ICE stream functionality
49 Stream *
50 stream_new (guint n_components)
52 Stream *stream;
53 guint n;
54 gboolean errors = FALSE;
55 GSList *modified_list;
56 Component *component;
58 stream = g_slice_new0 (Stream);
59 for (n = 0; n < n_components; n++) {
60 component = component_new (n + 1);
61 if (component) {
62 modified_list = g_slist_append (stream->components, component);
63 if (modified_list)
64 stream->components = modified_list;
65 else
66 errors = TRUE;
68 else
69 errors = TRUE;
72 if (errors) {
73 stream_free (stream);
74 return NULL;
77 stream->n_components = n_components;
78 stream->initial_binding_request_received = FALSE;
80 return stream;
83 void
84 stream_free (Stream *stream)
86 GSList *i;
88 for (i = stream->components; i; i = i->next) {
89 Component *component = i->data;
90 component_free (component);
91 i->data = NULL;
93 g_slist_free (stream->components);
94 g_slice_free (Stream, stream);
97 Component *
98 stream_find_component_by_id (const Stream *stream, guint id)
100 GSList *i;
102 for (i = stream->components; i; i = i->next) {
103 Component *component = i->data;
104 if (component && component->id == id)
105 return component;
108 return NULL;
112 * Returns true if all components of the stream are either
113 * 'CONNECTED' or 'READY' (connected plus nominated).
115 gboolean
116 stream_all_components_ready (const Stream *stream)
118 GSList *i;
120 for (i = stream->components; i; i = i->next) {
121 Component *component = i->data;
122 if (component &&
123 !(component->state == NICE_COMPONENT_STATE_CONNECTED ||
124 component->state == NICE_COMPONENT_STATE_READY))
125 return FALSE;
128 return TRUE;
133 * Initialized the local crendentials for the stream.
135 void stream_initialize_credentials (Stream *stream, NiceRNG *rng)
137 /* note: generate ufrag/pwd for the stream (see ICE 15.4.
138 * '"ice-ufrag" and "ice-pwd" Attributes', ID-19) */
139 nice_rng_generate_bytes_print (rng, NICE_STREAM_DEF_UFRAG - 1, stream->local_ufrag);
140 nice_rng_generate_bytes_print (rng, NICE_STREAM_DEF_PWD - 1, stream->local_password);
144 * Resets the stream state to that of a ICE restarted
145 * session.
147 gboolean
148 stream_restart (Stream *stream, NiceRNG *rng)
150 GSList *i;
151 gboolean res = TRUE;
153 stream->initial_binding_request_received = FALSE;
155 stream_initialize_credentials (stream, rng);
157 for (i = stream->components; i && res; i = i->next) {
158 Component *component = i->data;
160 res = component_restart (component);
163 return res;