1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "sdp_os_defs.h"
7 #include "sdp_private.h"
11 static const char* logTag
= "sdp_config";
13 /* Function: void *sdp_init_config()
14 * Description: Initialize SDP configuration structure with the
16 * All debug levels turned OFF.
17 * All token lines required per RFC2327.
18 * No media types supported.
19 * No network types supported.
20 * No address types supported.
21 * No transport types supported.
23 * Returns: A handle for the configuration as a void ptr.
25 sdp_conf_options_t
*sdp_init_config ()
28 sdp_conf_options_t
*conf_p
;
30 conf_p
= SDP_MALLOC(sizeof(sdp_conf_options_t
));
33 SDPLogError(logTag
, "SDP: could not allocate configuration object.");
37 /* Set default debug flags. */
38 conf_p
->debug_flag
[SDP_DEBUG_TRACE
] = FALSE
;
39 conf_p
->debug_flag
[SDP_DEBUG_WARNINGS
] = FALSE
;
40 conf_p
->debug_flag
[SDP_DEBUG_ERRORS
] = FALSE
;
42 /* Set required lines flags. Note: Only need to set those that */
43 /* are questionable. Most lines aren't required by default. */
44 conf_p
->version_reqd
= TRUE
;
45 conf_p
->owner_reqd
= TRUE
;
46 conf_p
->session_name_reqd
= TRUE
;
47 conf_p
->timespec_reqd
= TRUE
;
49 /* No media types supported by default. */
50 for (i
=0; i
< SDP_MAX_MEDIA_TYPES
; i
++) {
51 conf_p
->media_supported
[i
] = FALSE
;
54 /* No network types supported by default. */
55 for (i
=0; i
< SDP_MAX_NETWORK_TYPES
; i
++) {
56 conf_p
->nettype_supported
[i
] = FALSE
;
59 /* No address types supported by default. */
60 for (i
=0; i
< SDP_MAX_ADDR_TYPES
; i
++) {
61 conf_p
->addrtype_supported
[i
] = FALSE
;
64 /* No transport types supported by default. */
65 for (i
=0; i
< SDP_MAX_TRANSPORT_TYPES
; i
++) {
66 conf_p
->transport_supported
[i
] = FALSE
;
69 /* No choose parameters allowed by default. */
70 for (i
=0; i
< SDP_MAX_CHOOSE_PARAMS
; i
++) {
71 conf_p
->allow_choose
[i
] = FALSE
;
74 /* Initialize statistics counts */
75 conf_p
->num_parses
= 0;
76 conf_p
->num_builds
= 0;
77 conf_p
->num_not_sdp_desc
= 0;
78 conf_p
->num_invalid_token_order
= 0;
79 conf_p
->num_invalid_param
= 0;
80 conf_p
->num_no_resource
= 0;
82 /* Parse error handler stuff */
83 conf_p
->error_handler
= NULL
;
84 conf_p
->error_handler_context
= NULL
;
86 SDPLogInfo(logTag
, "SDP: Initialized config pointer: %p", conf_p
);
91 void sdp_free_config(sdp_conf_options_t
* conf_p
) {
97 /* Function: void sdp_appl_debug(sdp_conf_options_t *conf_p, sdp_debug_e debug_type,
99 * Description: Define the default type of debug for the application.
100 * Valid debug types are ERRORS, WARNINGS, and TRACE. Each
101 * debug type can be turned on/off individually. The
102 * default debug level can be redefined at any time.
103 * Parameters: conf_p The config handle returned by sdp_init_config.
104 * debug_type Specifies the debug type being enabled/disabled.
105 * debug_flag Defines whether the debug should be enabled or not.
108 void sdp_appl_debug (sdp_conf_options_t
*conf_p
, sdp_debug_e debug_type
,
111 if (debug_type
< SDP_MAX_DEBUG_TYPES
) {
112 conf_p
->debug_flag
[debug_type
] = debug_flag
;
117 /* Functions: void sdp_require_version
118 * void sdp_require_owner
119 * void sdp_require_session_name
120 * void sdp_require_timespec
121 * Description: These functions allow the application to not require several
122 * of the tokens that are specifically required by RFC 2327.
123 * Parameters: conf_p The config handle returned by sdp_init_config.
124 * version_required TRUE or FALSE whether the token should
128 void sdp_require_version (sdp_conf_options_t
*conf_p
, tinybool version_required
)
130 conf_p
->version_reqd
= version_required
;
133 void sdp_require_owner (sdp_conf_options_t
*conf_p
, tinybool owner_required
)
135 conf_p
->owner_reqd
= owner_required
;
138 void sdp_require_session_name (sdp_conf_options_t
*conf_p
, tinybool sess_name_required
)
140 conf_p
->session_name_reqd
= sess_name_required
;
143 void sdp_require_timespec (sdp_conf_options_t
*conf_p
, tinybool timespec_required
)
145 conf_p
->timespec_reqd
= timespec_required
;
149 /* Function: sdp_media_supported
150 * Description: These functions allow the application to specify which
151 * media types it supports. The application must set any/all
152 * as required. No media types are supported by default.
153 * Parameters: conf_p The config handle returned by sdp_init_config.
154 * nettype The network type for which support is being set.
155 * media_supported TRUE or FALSE whether the support is provided.
158 void sdp_media_supported (sdp_conf_options_t
*conf_p
, sdp_media_e media_type
,
159 tinybool media_supported
)
161 conf_p
->media_supported
[media_type
] = media_supported
;
165 /* Function: sdp_nettype_supported
166 * Description: This function allows the application to specify which
167 * network types it supports. The application must set
168 * any/all as required. No network types are supported by
170 * Parameters: conf_p The config handle returned by sdp_init_config.
171 * nettype The network type for which support is being set.
172 * nettype_supported TRUE or FALSE whether the support is
176 void sdp_nettype_supported (sdp_conf_options_t
*conf_p
, sdp_nettype_e nettype
,
177 tinybool nettype_supported
)
179 conf_p
->nettype_supported
[nettype
] = nettype_supported
;
183 /* Function: sdp_addrtype_supported
184 * Description: This function allows the application to specify which
185 * address types it supports. The application must set
186 * any/all as required. No address types are supported by
188 * Parameters: conf_p The config handle returned by sdp_init_config.
189 * addrtype The address type for which support is being set.
190 * addrtype_supported TRUE or FALSE whether the support is
194 void sdp_addrtype_supported (sdp_conf_options_t
*conf_p
, sdp_addrtype_e addrtype
,
195 tinybool addrtype_supported
)
197 conf_p
->addrtype_supported
[addrtype
] = addrtype_supported
;
201 /* Function: sdp_transport_supported
202 * Description: This function allows the application to specify which
203 * transport types it supports. The application must set
204 * any/all as required. No transport types are supported
206 * Parameters: conf_p The config handle returned by sdp_init_config.
207 * transport The transport type for which support is being set.
208 * transport_supported TRUE or FALSE whether the support is
212 void sdp_transport_supported (sdp_conf_options_t
*conf_p
, sdp_transport_e transport
,
213 tinybool transport_supported
)
215 conf_p
->transport_supported
[transport
] = transport_supported
;
219 /* Function: sdp_allow_choose
220 * Description: These functions allow the CHOOSE parameter `$' to be
221 * specified in place of certain parameters.
222 * Parameters: conf_p The config handle returned by sdp_init_config.
223 * param The param that may or may not be CHOOSE.
224 * choose_allowed TRUE or FALSE whether the CHOOSE parameter
228 void sdp_allow_choose (sdp_conf_options_t
*conf_p
, sdp_choose_param_e param
, tinybool choose_allowed
)
230 if (param
< SDP_MAX_CHOOSE_PARAMS
) {
231 conf_p
->allow_choose
[param
] = choose_allowed
;
235 void sdp_config_set_error_handler(sdp_conf_options_t
*conf_p
,
236 sdp_parse_error_handler handler
,
239 conf_p
->error_handler
= handler
;
240 conf_p
->error_handler_context
= context
;