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