4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Helper functions to skip white spaces, find tokens, find separators and free
40 #include "sdp_parse.h"
41 #include "commp_util.h"
44 sdp_free_origin(sdp_origin_t
*origin
)
47 free(origin
->o_username
);
48 free(origin
->o_nettype
);
49 free(origin
->o_addrtype
);
50 free(origin
->o_address
);
56 sdp_free_key(sdp_key_t
*key
)
66 sdp_free_zone(sdp_zone_t
*zone
)
68 sdp_zone_t
*next_zone
;
70 while (zone
!= NULL
) {
71 next_zone
= zone
->z_next
;
79 sdp_free_list(sdp_list_t
*list
)
81 sdp_list_t
*next_list
;
83 while (list
!= NULL
) {
84 next_list
= list
->next
;
92 sdp_free_media(sdp_media_t
*media
)
94 sdp_media_t
*next_media
;
96 while (media
!= NULL
) {
97 next_media
= media
->m_next
;
100 if (media
->m_format
!= NULL
)
101 sdp_free_list(media
->m_format
);
103 if (media
->m_conn
!= NULL
)
104 sdp_free_connection(media
->m_conn
);
105 if (media
->m_bw
!= NULL
)
106 sdp_free_bandwidth(media
->m_bw
);
107 if (media
->m_key
!= NULL
)
108 sdp_free_key(media
->m_key
);
109 if (media
->m_attr
!= NULL
)
110 sdp_free_attribute(media
->m_attr
);
117 sdp_free_attribute(sdp_attr_t
*attr
)
119 sdp_attr_t
*next_attr
;
121 while (attr
!= NULL
) {
122 next_attr
= attr
->a_next
;
131 sdp_free_connection(sdp_conn_t
*conn
)
133 sdp_conn_t
*next_conn
;
135 while (conn
!= NULL
) {
136 next_conn
= conn
->c_next
;
137 free(conn
->c_nettype
);
138 free(conn
->c_addrtype
);
139 free(conn
->c_address
);
146 sdp_free_bandwidth(sdp_bandwidth_t
*bw
)
148 sdp_bandwidth_t
*next_bw
;
151 next_bw
= bw
->b_next
;
159 sdp_free_repeat(sdp_repeat_t
*repeat
)
161 sdp_repeat_t
*next_repeat
;
163 while (repeat
!= NULL
) {
164 next_repeat
= repeat
->r_next
;
165 sdp_free_list(repeat
->r_offset
);
167 repeat
= next_repeat
;
172 sdp_free_time(sdp_time_t
*time
)
174 sdp_time_t
*next_time
;
176 while (time
!= NULL
) {
177 next_time
= time
->t_next
;
178 sdp_free_repeat(time
->t_repeat
);
185 sdp_free_session(sdp_session_t
*session
)
189 if (session
->s_origin
!= NULL
)
190 sdp_free_origin(session
->s_origin
);
191 free(session
->s_name
);
192 free(session
->s_info
);
193 free(session
->s_uri
);
194 if (session
->s_email
!= NULL
)
195 sdp_free_list(session
->s_email
);
196 if (session
->s_phone
!= NULL
)
197 sdp_free_list(session
->s_phone
);
198 if (session
->s_conn
!= NULL
)
199 sdp_free_connection(session
->s_conn
);
200 if (session
->s_bw
!= NULL
)
201 sdp_free_bandwidth(session
->s_bw
);
202 if (session
->s_time
!= NULL
)
203 sdp_free_time(session
->s_time
);
204 if (session
->s_zone
!= NULL
)
205 sdp_free_zone(session
->s_zone
);
206 if (session
->s_key
!= NULL
)
207 sdp_free_key(session
->s_key
);
208 if (session
->s_attr
!= NULL
)
209 sdp_free_attribute(session
->s_attr
);
210 if (session
->s_media
!= NULL
)
211 sdp_free_media(session
->s_media
);
216 * Adds text of a given length to a linked list. If the list is NULL to
217 * start with it builds the new list
220 add_value_to_list(sdp_list_t
**list
, const char *value
, int len
, boolean_t text
)
222 sdp_list_t
*new = NULL
;
223 sdp_list_t
*tmp
= NULL
;
225 new = malloc(sizeof (sdp_list_t
));
230 new->value
= (char *)calloc(1, len
+ 1);
232 new->value
= (uint64_t *)calloc(1, sizeof (uint64_t));
233 if (new->value
== NULL
) {
238 (void) strncpy(new->value
, value
, len
);
240 if (commp_time_to_secs((char *)value
, (char *)(value
+
241 len
), new->value
) != 0) {
250 while (tmp
->next
!= NULL
)
258 * Given a linked list converts it to space separated string.
261 sdp_list_to_str(sdp_list_t
*list
, char **buf
, boolean_t text
)
274 while (list
!= NULL
) {
276 size
+= strlen((char *)list
->value
);
278 size
+= snprintf(c
, 1, "%lld",
279 *(uint64_t *)list
->value
);
285 *buf
= calloc(1, size
+ 1);
289 while (list
!= NULL
) {
291 wrote
= snprintf(ret
, size
, "%s ",
292 (char *)list
->value
);
294 wrote
= snprintf(ret
, size
, "%lld ",
295 *(uint64_t *)list
->value
);
308 * Given a space separated string, converts it into linked list. SDP field
309 * repeat and media can have undefined number of offsets or formats
310 * respectively. We need to capture it in a linked list.
313 sdp_str_to_list(sdp_list_t
**list
, const char *buf
, int len
, boolean_t text
)
324 /* takes care of strings with just spaces */
325 if (commp_skip_white_space(¤t
, end
) != 0)
327 while (current
< end
) {
328 (void) commp_skip_white_space(¤t
, end
);
330 while (current
< end
) {
331 if (isspace(*current
))
335 if (current
!= begin
) {
336 if ((ret
= add_value_to_list(list
, begin
,
337 current
- begin
, text
)) != 0) {
338 sdp_free_list(*list
);