xref: /titanic_51/usr/src/lib/libcommputil/common/sdp.h (revision a93a1f58a8763fa69172980b98e3d24720c1136e)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SDP_H
28 #define	_SDP_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 
38 #define	SDP_VERSION_FIELD	'v'
39 #define	SDP_ORIGIN_FIELD	'o'
40 #define	SDP_NAME_FIELD		's'
41 #define	SDP_INFO_FIELD		'i'
42 #define	SDP_URI_FIELD		'u'
43 #define	SDP_EMAIL_FIELD		'e'
44 #define	SDP_PHONE_FIELD		'p'
45 #define	SDP_CONNECTION_FIELD	'c'
46 #define	SDP_BANDWIDTH_FIELD	'b'
47 #define	SDP_TIME_FIELD		't'
48 #define	SDP_REPEAT_FIELD	'r'
49 #define	SDP_ZONE_FIELD		'z'
50 #define	SDP_KEY_FIELD		'k'
51 #define	SDP_ATTRIBUTE_FIELD	'a'
52 #define	SDP_MEDIA_FIELD		'm'
53 
54 /* SDP Parse errors */
55 #define	SDP_VERSION_ERROR	0x00000001
56 #define	SDP_ORIGIN_ERROR	0x00000002
57 #define	SDP_NAME_ERROR		0x00000004
58 #define	SDP_INFO_ERROR		0x00000008
59 #define	SDP_URI_ERROR		0x00000010
60 #define	SDP_EMAIL_ERROR		0x00000020
61 #define	SDP_PHONE_ERROR		0x00000040
62 #define	SDP_CONNECTION_ERROR	0x00000080
63 #define	SDP_BANDWIDTH_ERROR	0x00000100
64 #define	SDP_TIME_ERROR		0x00000200
65 #define	SDP_REPEAT_TIME_ERROR	0x00000400
66 #define	SDP_ZONE_ERROR		0x00000800
67 #define	SDP_KEY_ERROR		0x00001000
68 #define	SDP_ATTRIBUTE_ERROR	0x00002000
69 #define	SDP_MEDIA_ERROR		0x00004000
70 #define	SDP_FIELDS_ORDER_ERROR	0x00008000
71 #define	SDP_MISSING_FIELDS	0x00010000
72 
73 #define	SDP_AUDIO		"audio"
74 #define	SDP_VIDEO		"video"
75 #define	SDP_TEXT		"text"
76 #define	SDP_APPLICATION		"application"
77 #define	SDP_MESSAGE		"message"
78 #define	SDP_RTPMAP		"rtpmap"
79 
80 #define	SDP_SESSION_VERSION_1	1
81 
82 typedef struct sdp_list {
83 	void			*value;
84 	struct sdp_list		*next;
85 } sdp_list_t;
86 
87 /*
88  * SDP origin field.
89  * o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
90  */
91 typedef struct sdp_origin {
92 	char			*o_username;
93 	uint64_t 		o_id;
94 	uint64_t 		o_version;
95 	char			*o_nettype;
96 	char			*o_addrtype;
97 	char			*o_address;
98 } sdp_origin_t;
99 
100 /*
101  * SDP connection field.
102  * c=<nettype> <addrtype> <connection-address>[/ttl]/<number of addresses>
103  */
104 typedef struct sdp_conn {
105 	char			*c_nettype;
106 	char			*c_addrtype;
107 	char			*c_address;
108 	int 			c_addrcount;
109 	struct sdp_conn		*c_next;
110 	uint8_t			c_ttl;
111 } sdp_conn_t;
112 
113 /*
114  * SDP repeat field. Always found in time structure.
115  * r=<repeat interval> <active duration> <offsets from start-time>
116  */
117 typedef struct sdp_repeat {
118 	uint64_t		r_interval;
119 	uint64_t		r_duration;
120 	sdp_list_t 		*r_offset;
121 	struct sdp_repeat	*r_next;
122 } sdp_repeat_t;
123 
124 /*
125  * SDP time field.
126  * t=<start-time> <stop-time>
127  */
128 typedef struct sdp_time {
129 	uint64_t 		t_start;
130 	uint64_t 		t_stop;
131 	sdp_repeat_t 		*t_repeat;
132 	struct sdp_time		*t_next;
133 } sdp_time_t;
134 
135 /*
136  * SDP time zone field.
137  * z=<adjustment time> <offset> <adjustment time> <offset> ....
138  */
139 typedef struct sdp_zone {
140 	uint64_t 		z_time;
141 	char			*z_offset;
142 	struct sdp_zone		*z_next;
143 } sdp_zone_t;
144 
145 /*
146  * SDP attribute field.
147  * a=<attribute> or a=<attribute>:<value>
148  */
149 typedef struct sdp_attr {
150 	char			*a_name;
151 	char			*a_value;
152 	struct sdp_attr		*a_next;
153 } sdp_attr_t;
154 
155 /*
156  * SDP bandwidth field.
157  * b=<bwtype>:<bandwidth>
158  */
159 typedef struct sdp_bandwidth {
160 	char			*b_type;
161 	uint64_t 		b_value;
162 	struct sdp_bandwidth	*b_next;
163 } sdp_bandwidth_t;
164 
165 /*
166  * SDP key field to session or media section of SDP.
167  * k=<method> or k=<method>:<encryption key>
168  */
169 typedef struct sdp_key {
170 	char			*k_method;
171 	char			*k_enckey;
172 } sdp_key_t;
173 
174 typedef struct sdp_session	sdp_session_t;
175 
176 /*
177  * SDP media section, contains media fields and other fields within
178  * media section.
179  * m=<media> <port>[/portcount] <proto> <fmt> ...
180  */
181 typedef struct sdp_media {
182 	char			*m_name;
183 	uint_t			m_port;
184 	int			m_portcount;
185 	char			*m_proto;
186 	sdp_list_t 		*m_format;
187 	char			*m_info;
188 	sdp_conn_t 		*m_conn;
189 	sdp_bandwidth_t 	*m_bw;
190 	sdp_key_t 		*m_key;
191 	sdp_attr_t 		*m_attr;
192 	struct sdp_media 	*m_next;
193 	sdp_session_t		*m_session;
194 } sdp_media_t;
195 
196 struct sdp_session {
197 	int			sdp_session_version;
198 	int 			s_version;
199 	sdp_origin_t 		*s_origin;
200 	char			*s_name;
201 	char			*s_info;
202 	char			*s_uri;
203 	sdp_list_t 		*s_email;
204 	sdp_list_t 		*s_phone;
205 	sdp_conn_t 		*s_conn;
206 	sdp_bandwidth_t 	*s_bw;
207 	sdp_time_t 		*s_time;
208 	sdp_zone_t 		*s_zone;
209 	sdp_key_t 		*s_key;
210 	sdp_attr_t 		*s_attr;
211 	sdp_media_t 		*s_media;
212 };
213 
214 extern int		sdp_parse(const char *, int, int, sdp_session_t **,
215 			    uint_t *);
216 extern sdp_media_t	*sdp_find_media(sdp_media_t *, const char *);
217 extern sdp_attr_t	*sdp_find_attribute(sdp_attr_t *, const char *);
218 extern sdp_attr_t	*sdp_find_media_rtpmap(sdp_media_t *, const char *);
219 extern sdp_session_t	*sdp_clone_session(const sdp_session_t *);
220 extern sdp_session_t	*sdp_new_session();
221 extern int		sdp_add_origin(sdp_session_t *, const char *, uint64_t,
222 			    uint64_t, const char *, const char *, const char *);
223 extern int		sdp_add_name(sdp_session_t *, const char *);
224 extern int		sdp_add_information(char **, const char *);
225 extern int		sdp_add_uri(sdp_session_t *, const char *);
226 extern int		sdp_add_email(sdp_session_t *, const char *);
227 extern int		sdp_add_phone(sdp_session_t *, const char *);
228 extern int		sdp_add_connection(sdp_conn_t **, const char *,
229 			    const char *, const char *, uint8_t, int);
230 extern int		sdp_add_bandwidth(sdp_bandwidth_t **, const char *,
231 			    uint64_t);
232 extern int		sdp_add_repeat(sdp_time_t *, uint64_t, uint64_t,
233 			    const char *);
234 extern int		sdp_add_time(sdp_session_t *, uint64_t, uint64_t,
235 			    sdp_time_t **);
236 extern int		sdp_add_zone(sdp_session_t *, uint64_t, const char *);
237 extern int		sdp_add_key(sdp_key_t **, const char *, const char *);
238 extern int		sdp_add_attribute(sdp_attr_t **, const char *,
239 			    const char *);
240 extern int		sdp_add_media(sdp_session_t *, const char *, uint_t,
241 			    int, const char *, const char *, sdp_media_t **);
242 extern int		sdp_delete_all_field(sdp_session_t *, const char);
243 extern int		sdp_delete_all_media_field(sdp_media_t *, const char);
244 extern int		sdp_delete_media(sdp_media_t **, sdp_media_t *);
245 extern int		sdp_delete_attribute(sdp_attr_t **, sdp_attr_t *);
246 extern void		sdp_free_session(sdp_session_t *);
247 extern char		*sdp_session_to_str(const sdp_session_t *, int *);
248 
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif /* _SDP_H */
255