2 This file is part of FreeSDP
3 Copyright (C) 2001,2002,2003 Federico Montesino Pouzols <fedemp@suidzer0.org>
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.
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.
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
23 * @short Implementation of routines common to parse and formatting
26 * This file implements the routines that operate over data structures
27 * that are used in both the parse and formatting modules.
41 fsdp_description_new (void)
43 fsdp_description_t
*result
= malloc (sizeof (fsdp_description_t
));
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
;
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
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;
93 fsdp_description_delete (fsdp_description_t
* dsc
)
95 fsdp_description_recycle (dsc
);
100 fsdp_description_recycle (fsdp_description_t
* dsc
)
102 /* Recursively free all strings and arrays */
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
);
116 for (i
= 0; i
< dsc
->emails_count
; i
++)
117 safe_free ((char *) dsc
->emails
[i
]);
118 safe_free (dsc
->emails
);
120 for (i
= 0; i
< dsc
->phones_count
; i
++)
121 safe_free ((char *) dsc
->phones
[i
]);
122 safe_free (dsc
->phones
);
124 safe_free (dsc
->c_address
.address
);
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
);
130 for (i
= 0; i
< dsc
->time_periods_count
; i
++)
132 for (j
= 0; j
< dsc
->time_periods
[i
]->repeats_count
; j
++)
134 safe_free (dsc
->time_periods
[i
]->repeats
[j
]->offsets
);
135 safe_free (dsc
->time_periods
[i
]->repeats
[j
]);
137 safe_free (dsc
->time_periods
[i
]->repeats
);
138 safe_free (dsc
->time_periods
[i
]);
140 safe_free (dsc
->time_periods
);
142 safe_free (dsc
->timezone_adj
);
143 safe_free (dsc
->a_category
);
144 safe_free (dsc
->a_keywords
);
145 safe_free (dsc
->a_tool
);
147 for (i
= 0; i
< dsc
->a_rtpmaps_count
; i
++)
148 safe_free (dsc
->a_rtpmaps
[i
]);
149 safe_free (dsc
->a_rtpmaps
);
151 safe_free (dsc
->a_charset
);
153 for (i
= 0; i
< dsc
->a_sdplangs_count
; i
++)
154 safe_free (dsc
->a_sdplangs
[i
]);
155 safe_free (dsc
->a_sdplangs
);
157 for (i
= 0; i
< dsc
->a_langs_count
; i
++)
158 safe_free (dsc
->a_langs
[i
]);
159 safe_free (dsc
->a_langs
);
161 for (i
= 0; i
< dsc
->a_controls_count
; i
++)
162 safe_free (dsc
->a_controls
[i
]);
163 safe_free (dsc
->a_controls
);
165 safe_free (dsc
->a_range
);
167 for (i
= 0; i
< dsc
->media_announcements_count
; i
++)
169 if (!dsc
->media_announcements
[i
]) continue;
170 for (j
= 0; j
< dsc
->media_announcements
[i
]->formats_count
; j
++)
171 safe_free (dsc
->media_announcements
[i
]->formats
[j
]);
172 safe_free (dsc
->media_announcements
[i
]->formats
);
173 safe_free (dsc
->media_announcements
[i
]->i_title
);
175 for (j
= 0; j
< dsc
->media_announcements
[i
]->bw_modifiers_count
; j
++)
177 if (FSDP_BW_MOD_TYPE_UNKNOWN
==
178 dsc
->media_announcements
[i
]->bw_modifiers
[j
].b_mod_type
)
179 safe_free (dsc
->media_announcements
[i
]->bw_modifiers
[j
].
182 safe_free (dsc
->media_announcements
[i
]->bw_modifiers
);
184 safe_free (dsc
->media_announcements
[i
]->k_encryption_content
);
186 for (j
= 0; j
< dsc
->media_announcements
[i
]->a_rtpmaps_count
; j
++)
188 safe_free (dsc
->media_announcements
[i
]->a_rtpmaps
[j
]->pt
);
189 safe_free (dsc
->media_announcements
[i
]->a_rtpmaps
[j
]->
191 safe_free (dsc
->media_announcements
[i
]->a_rtpmaps
[j
]->parameters
);
192 safe_free (dsc
->media_announcements
[i
]->a_rtpmaps
[j
]);
194 safe_free (dsc
->media_announcements
[i
]->a_rtpmaps
);
196 for (j
= 0; j
< dsc
->media_announcements
[i
]->a_sdplangs_count
; j
++)
197 safe_free (dsc
->media_announcements
[i
]->a_sdplangs
[j
]);
198 safe_free (dsc
->media_announcements
[i
]->a_sdplangs
);
200 for (j
= 0; j
< dsc
->media_announcements
[i
]->a_langs_count
; j
++)
201 safe_free (dsc
->media_announcements
[i
]->a_langs
[j
]);
202 safe_free (dsc
->media_announcements
[i
]->a_langs
);
204 for (j
= 0; j
< dsc
->media_announcements
[i
]->a_controls_count
; j
++)
205 safe_free (dsc
->media_announcements
[i
]->a_controls
[j
]);
206 safe_free (dsc
->media_announcements
[i
]->a_controls
);
208 for (j
= 0; j
< dsc
->media_announcements
[i
]->a_fmtps_count
; j
++)
209 safe_free (dsc
->media_announcements
[i
]->a_fmtps
[j
]);
210 safe_free (dsc
->media_announcements
[i
]->a_fmtps
);
213 j
< dsc
->media_announcements
[i
]->unidentified_attributes_count
; j
++)
214 safe_free (dsc
->media_announcements
[i
]->unidentified_attributes
[j
]);
215 safe_free (dsc
->media_announcements
[i
]->unidentified_attributes
);
216 safe_free (dsc
->media_announcements
[i
]);
218 safe_free (dsc
->media_announcements
);
220 /* This prevents the user to make the library crash when incorrectly
221 using recycled but not rebuilt descriptions */
222 dsc
->emails_count
= 0;
223 dsc
->phones_count
= 0;
224 dsc
->bw_modifiers_count
= 0;
225 dsc
->time_periods_count
= 0;
226 dsc
->media_announcements_count
= 0;