comparison libmpdemux/freesdp/common.c @ 18823:ef667dd373e2

new imported library in libmpdemux: freesdp (will be used by native rtsp demuxer)
author ben
date Mon, 26 Jun 2006 17:37:55 +0000
parents
children
comparison
equal deleted inserted replaced
18822:a48dead7424a 18823:ef667dd373e2
1 /*
2 This file is part of FreeSDP
3 Copyright (C) 2001,2002,2003 Federico Montesino Pouzols <fedemp@suidzer0.org>
4
5 FreeSDP is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 /**
21 * @file common.c
22 *
23 * @short Implementation of routines common to parse and formatting
24 * modules .
25 *
26 * This file implements the routines that operate over data structures
27 * that are used in both the parse and formatting modules.
28 **/
29
30 #include "priv.h"
31 #include "common.h"
32
33 static void
34 safe_free (void *ptr)
35 {
36 if (ptr)
37 free (ptr);
38 }
39
40 fsdp_description_t *
41 fsdp_description_new (void)
42 {
43 fsdp_description_t *result = malloc (sizeof (fsdp_description_t));
44
45 result->version = 0;
46 result->o_username = result->o_session_id =
47 result->o_announcement_version = NULL;
48 result->o_network_type = FSDP_NETWORK_TYPE_UNDEFINED;
49 result->o_address_type = FSDP_ADDRESS_TYPE_UNDEFINED;
50 result->o_address = NULL;
51 result->s_name = NULL;
52 result->i_information = NULL;
53 result->u_uri = NULL;
54 result->emails = NULL;
55 result->emails_count = 0;
56 result->phones = NULL;
57 result->phones_count = 0;
58 /* At first, there is no session-level definition for these
59 parameters */
60 result->c_network_type = FSDP_NETWORK_TYPE_UNDEFINED;
61 result->c_address_type = FSDP_ADDRESS_TYPE_UNDEFINED;
62 result->c_address.address = NULL;
63 /* there is no session-level definition for these parameters */
64 result->bw_modifiers = NULL;
65 result->bw_modifiers_count = 0;
66 result->time_periods = NULL;
67 result->time_periods_count = 0;
68 result->timezone_adj = NULL;
69 result->k_encryption_method = FSDP_ENCRYPTION_METHOD_UNDEFINED;
70 result->k_encryption_content = NULL;
71 /* Default/undefined values for attributes */
72 result->a_category = result->a_keywords = result->a_tool = NULL;
73 result->a_type = FSDP_SESSION_TYPE_UNDEFINED;
74 result->a_sendrecv_mode = FSDP_SENDRECV_UNDEFINED;
75 result->a_charset = NULL;
76 result->a_sdplangs = result->a_langs = NULL;
77 result->a_controls = NULL;
78 result->a_range = NULL;
79 result->a_rtpmaps = NULL;
80 result->a_rtpmaps_count = 0;
81 result->a_sdplangs_count = 0;
82 result->a_langs_count = 0;
83 result->a_controls_count = 0;
84 result->unidentified_attributes = NULL;
85 result->unidentified_attributes_count = 0;
86 result->media_announcements = NULL;
87 result->media_announcements_count = 0;
88
89 return result;
90 }
91
92 void
93 fsdp_description_delete (fsdp_description_t * dsc)
94 {
95 fsdp_description_recycle (dsc);
96 safe_free (dsc);
97 }
98
99 void
100 fsdp_description_recycle (fsdp_description_t * dsc)
101 {
102 /* Recursively free all strings and arrays */
103 unsigned int i, j;
104
105 if (!dsc)
106 return;
107
108 safe_free (dsc->o_username);
109 safe_free (dsc->o_session_id);
110 safe_free (dsc->o_announcement_version);
111 safe_free (dsc->o_address);
112 safe_free (dsc->s_name);
113 safe_free (dsc->i_information);
114 safe_free (dsc->u_uri);
115
116 for (i = 0; i < dsc->emails_count; i++)
117 safe_free ((char *) dsc->emails[i]);
118 safe_free (dsc->emails);
119
120 for (i = 0; i < dsc->phones_count; i++)
121 safe_free ((char *) dsc->phones[i]);
122 safe_free (dsc->phones);
123
124 safe_free (dsc->c_address.address);
125
126 for (i = 0; i < dsc->bw_modifiers_count; i++)
127 safe_free (dsc->bw_modifiers[i].b_unknown_bw_modt);
128 safe_free (dsc->bw_modifiers);
129
130 for (i = 0; i < dsc->time_periods_count; i++)
131 {
132 for (j = 0; j < dsc->time_periods[i]->repeats_count; j++)
133 {
134 safe_free (dsc->time_periods[i]->repeats[j]->offsets);
135 safe_free (dsc->time_periods[i]->repeats[j]);
136 }
137 safe_free (dsc->time_periods[i]->repeats);
138 safe_free (dsc->time_periods[i]);
139 }
140 safe_free (dsc->time_periods);
141
142 safe_free (dsc->timezone_adj);
143 safe_free (dsc->a_category);
144 safe_free (dsc->a_keywords);
145 safe_free (dsc->a_tool);
146
147 for (i = 0; i < dsc->a_rtpmaps_count; i++)
148 safe_free (dsc->a_rtpmaps[i]);
149 safe_free (dsc->a_rtpmaps);
150
151 safe_free (dsc->a_charset);
152
153 for (i = 0; i < dsc->a_sdplangs_count; i++)
154 safe_free (dsc->a_sdplangs[i]);
155 safe_free (dsc->a_sdplangs);
156
157 for (i = 0; i < dsc->a_langs_count; i++)
158 safe_free (dsc->a_langs[i]);
159 safe_free (dsc->a_langs);
160
161 for (i = 0; i < dsc->a_controls_count; i++)
162 safe_free (dsc->a_controls[i]);
163 safe_free (dsc->a_controls);
164
165 safe_free (dsc->a_range);
166
167 for (i = 0; i < dsc->media_announcements_count; i++)
168 {
169 for (j = 0; j < dsc->media_announcements[i]->formats_count; j++)
170 safe_free (dsc->media_announcements[i]->formats[j]);
171 safe_free (dsc->media_announcements[i]->formats);
172 safe_free (dsc->media_announcements[i]->i_title);
173
174 for (j = 0; j < dsc->media_announcements[i]->bw_modifiers_count; j++)
175 {
176 if (FSDP_BW_MOD_TYPE_UNKNOWN ==
177 dsc->media_announcements[i]->bw_modifiers[j].b_mod_type)
178 safe_free (dsc->media_announcements[i]->bw_modifiers[j].
179 b_unknown_bw_modt);
180 }
181 safe_free (dsc->media_announcements[i]->bw_modifiers);
182
183 safe_free (dsc->media_announcements[i]->k_encryption_content);
184
185 for (j = 0; j < dsc->media_announcements[i]->a_rtpmaps_count; j++)
186 {
187 safe_free (dsc->media_announcements[i]->a_rtpmaps[j]->pt);
188 safe_free (dsc->media_announcements[i]->a_rtpmaps[j]->
189 encoding_name);
190 safe_free (dsc->media_announcements[i]->a_rtpmaps[j]->parameters);
191 safe_free (dsc->media_announcements[i]->a_rtpmaps[j]);
192 }
193 safe_free (dsc->media_announcements[i]->a_rtpmaps);
194
195 for (j = 0; j < dsc->media_announcements[i]->a_sdplangs_count; j++)
196 safe_free (dsc->media_announcements[i]->a_sdplangs[j]);
197 safe_free (dsc->media_announcements[i]->a_sdplangs);
198
199 for (j = 0; j < dsc->media_announcements[i]->a_langs_count; j++)
200 safe_free (dsc->media_announcements[i]->a_langs[j]);
201 safe_free (dsc->media_announcements[i]->a_langs);
202
203 for (j = 0; j < dsc->media_announcements[i]->a_controls_count; j++)
204 safe_free (dsc->media_announcements[i]->a_controls[j]);
205 safe_free (dsc->media_announcements[i]->a_controls);
206
207 for (j = 0; j < dsc->media_announcements[i]->a_fmtps_count; j++)
208 safe_free (dsc->media_announcements[i]->a_fmtps[j]);
209 safe_free (dsc->media_announcements[i]->a_fmtps);
210
211 for (j = 0;
212 j < dsc->media_announcements[i]->unidentified_attributes_count; j++)
213 safe_free (dsc->media_announcements[i]->unidentified_attributes[j]);
214 safe_free (dsc->media_announcements[i]->unidentified_attributes);
215 safe_free (dsc->media_announcements[i]);
216 }
217 safe_free (dsc->media_announcements);
218
219 /* This prevents the user to make the library crash when incorrectly
220 using recycled but not rebuilt descriptions */
221 dsc->emails_count = 0;
222 dsc->phones_count = 0;
223 dsc->bw_modifiers_count = 0;
224 dsc->time_periods_count = 0;
225 dsc->media_announcements_count = 0;
226 }