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