Line data Source code
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/. */
4 :
5 : #include "sdp_os_defs.h"
6 : #include "sdp.h"
7 : #include "sdp_private.h"
8 :
9 : #include "CSFLog.h"
10 :
11 : static const char* logTag = "sdp_config";
12 :
13 : /* Function: void *sdp_init_config()
14 : * Description: Initialize SDP configuration structure with the
15 : * following defaults:
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.
22 : * Parameters: None.
23 : * Returns: A handle for the configuration as a void ptr.
24 : */
25 0 : sdp_conf_options_t *sdp_init_config ()
26 : {
27 : int i;
28 : sdp_conf_options_t *conf_p;
29 :
30 0 : conf_p = SDP_MALLOC(sizeof(sdp_conf_options_t));
31 :
32 0 : if (!conf_p) {
33 0 : CSFLogError(logTag, "SDP: could not allocate configuration object.");
34 0 : return NULL;
35 : }
36 :
37 : /* Set default debug flags. */
38 0 : conf_p->debug_flag[SDP_DEBUG_TRACE] = FALSE;
39 0 : conf_p->debug_flag[SDP_DEBUG_WARNINGS] = FALSE;
40 0 : conf_p->debug_flag[SDP_DEBUG_ERRORS] = FALSE;
41 :
42 : /* Set required lines flags. Note: Only need to set those that */
43 : /* are questionable. Most lines aren't required by default. */
44 0 : conf_p->version_reqd = TRUE;
45 0 : conf_p->owner_reqd = TRUE;
46 0 : conf_p->session_name_reqd = TRUE;
47 0 : conf_p->timespec_reqd = TRUE;
48 :
49 : /* No media types supported by default. */
50 0 : for (i=0; i < SDP_MAX_MEDIA_TYPES; i++) {
51 0 : conf_p->media_supported[i] = FALSE;
52 : }
53 :
54 : /* No network types supported by default. */
55 0 : for (i=0; i < SDP_MAX_NETWORK_TYPES; i++) {
56 0 : conf_p->nettype_supported[i] = FALSE;
57 : }
58 :
59 : /* No address types supported by default. */
60 0 : for (i=0; i < SDP_MAX_ADDR_TYPES; i++) {
61 0 : conf_p->addrtype_supported[i] = FALSE;
62 : }
63 :
64 : /* No transport types supported by default. */
65 0 : for (i=0; i < SDP_MAX_TRANSPORT_TYPES; i++) {
66 0 : conf_p->transport_supported[i] = FALSE;
67 : }
68 :
69 : /* No choose parameters allowed by default. */
70 0 : for (i=0; i < SDP_MAX_CHOOSE_PARAMS; i++) {
71 0 : conf_p->allow_choose[i] = FALSE;
72 : }
73 :
74 : /* Initialize statistics counts */
75 0 : conf_p->num_parses = 0;
76 0 : conf_p->num_builds = 0;
77 0 : conf_p->num_not_sdp_desc = 0;
78 0 : conf_p->num_invalid_token_order = 0;
79 0 : conf_p->num_invalid_param = 0;
80 0 : conf_p->num_no_resource = 0;
81 :
82 : /* Parse error handler stuff */
83 0 : conf_p->error_handler = NULL;
84 0 : conf_p->error_handler_context = NULL;
85 :
86 0 : CSFLogInfo(logTag, "SDP: Initialized config pointer: %p", conf_p);
87 :
88 0 : return (conf_p);
89 : }
90 :
91 0 : void sdp_free_config(sdp_conf_options_t* conf_p) {
92 0 : if (conf_p) {
93 0 : SDP_FREE(conf_p);
94 : }
95 0 : }
96 :
97 : /* Function: void sdp_appl_debug(sdp_conf_options_t *conf_p, sdp_debug_e debug_type,
98 : * tinybool my_bool);
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.
106 : * Returns: Nothing.
107 : */
108 0 : void sdp_appl_debug (sdp_conf_options_t *conf_p, sdp_debug_e debug_type,
109 : tinybool debug_flag)
110 : {
111 0 : if (debug_type < SDP_MAX_DEBUG_TYPES) {
112 0 : conf_p->debug_flag[debug_type] = debug_flag;
113 : }
114 0 : }
115 :
116 :
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
125 : * be required.
126 : * Returns: Nothing.
127 : */
128 0 : void sdp_require_version (sdp_conf_options_t *conf_p, tinybool version_required)
129 : {
130 0 : conf_p->version_reqd = version_required;
131 0 : }
132 :
133 0 : void sdp_require_owner (sdp_conf_options_t *conf_p, tinybool owner_required)
134 : {
135 0 : conf_p->owner_reqd = owner_required;
136 0 : }
137 :
138 0 : void sdp_require_session_name (sdp_conf_options_t *conf_p, tinybool sess_name_required)
139 : {
140 0 : conf_p->session_name_reqd = sess_name_required;
141 0 : }
142 :
143 0 : void sdp_require_timespec (sdp_conf_options_t *conf_p, tinybool timespec_required)
144 : {
145 0 : conf_p->timespec_reqd = timespec_required;
146 0 : }
147 :
148 :
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.
156 : * Returns: Nothing.
157 : */
158 0 : void sdp_media_supported (sdp_conf_options_t *conf_p, sdp_media_e media_type,
159 : tinybool media_supported)
160 : {
161 0 : conf_p->media_supported[media_type] = media_supported;
162 0 : }
163 :
164 :
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
169 : * default.
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
173 : * provided.
174 : * Returns: Nothing.
175 : */
176 0 : void sdp_nettype_supported (sdp_conf_options_t *conf_p, sdp_nettype_e nettype,
177 : tinybool nettype_supported)
178 : {
179 0 : conf_p->nettype_supported[nettype] = nettype_supported;
180 0 : }
181 :
182 :
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
187 : * default.
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
191 : * provided.
192 : * Returns: Nothing.
193 : */
194 0 : void sdp_addrtype_supported (sdp_conf_options_t *conf_p, sdp_addrtype_e addrtype,
195 : tinybool addrtype_supported)
196 : {
197 0 : conf_p->addrtype_supported[addrtype] = addrtype_supported;
198 0 : }
199 :
200 :
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
205 : * by default.
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
209 : * provided.
210 : * Returns: Nothing.
211 : */
212 0 : void sdp_transport_supported (sdp_conf_options_t *conf_p, sdp_transport_e transport,
213 : tinybool transport_supported)
214 : {
215 0 : conf_p->transport_supported[transport] = transport_supported;
216 0 : }
217 :
218 :
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
225 : * should be allowed.
226 : * Returns: Nothing.
227 : */
228 0 : void sdp_allow_choose (sdp_conf_options_t *conf_p, sdp_choose_param_e param, tinybool choose_allowed)
229 : {
230 0 : if (param < SDP_MAX_CHOOSE_PARAMS) {
231 0 : conf_p->allow_choose[param] = choose_allowed;
232 : }
233 0 : }
234 :
235 0 : void sdp_config_set_error_handler(sdp_conf_options_t *conf_p,
236 : sdp_parse_error_handler handler,
237 : void *context)
238 : {
239 0 : conf_p->error_handler = handler;
240 0 : conf_p->error_handler_context = context;
241 0 : }
|