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.
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.
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]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
32 #include "sip_parse_uri.h"
35 sip_free_parsed_uri(sip_uri_t uri
)
42 _uri
= (_sip_uri_t
*)uri
;
43 if (_uri
->sip_uri_issip
) {
45 sip_param_t
*param_next
;
47 param
= _uri
->sip_uri_params
;
48 while (param
!= NULL
) {
49 param_next
= param
->param_next
;
58 * Parse the URI in uri_str
61 sip_parse_uri(sip_str_t
*uri_str
, int *error
)
63 struct sip_uri
*parsed_uri
;
68 if (uri_str
== NULL
) {
73 parsed_uri
= calloc(1, sizeof (_sip_uri_t
));
74 if (parsed_uri
== NULL
) {
80 sip_uri_parse_it(parsed_uri
, uri_str
);
81 if (parsed_uri
->sip_uri_errflags
& SIP_URIERR_MEMORY
) {
87 if (parsed_uri
->sip_uri_errflags
!= 0 && error
!= NULL
)
89 return ((sip_uri_t
)parsed_uri
);
95 const struct sip_uri
*
96 sip_get_uri_parsed(sip_header_value_t value
, int *error
)
98 const struct sip_uri
*ret
= NULL
;
102 if (value
== NULL
|| value
->sip_value_parse_uri
== NULL
||
103 value
->value_state
== SIP_VALUE_DELETED
) {
108 ret
= value
->sip_value_parse_uri
;
109 if (ret
->sip_uri_errflags
!= 0 && error
!= NULL
)
111 return ((sip_uri_t
)ret
);
115 * Return TRUE if this is a SIP URI
118 sip_is_sipuri(const struct sip_uri
*uri
)
124 _uri
= (_sip_uri_t
*)uri
;
125 if ((_uri
->sip_uri_errflags
& SIP_URIERR_SCHEME
) == 0 &&
126 _uri
->sip_uri_scheme
.sip_str_len
> 0 && _uri
->sip_uri_issip
) {
136 sip_check_get_param(const struct sip_uri
*uri
, int *error
)
146 return ((_sip_uri_t
*)uri
);
151 * Return the URI scheme
154 sip_get_uri_scheme(const struct sip_uri
*uri
, int *error
)
158 _uri
= sip_check_get_param(uri
, error
);
162 if (((_uri
->sip_uri_errflags
& SIP_URIERR_SCHEME
) != 0 ||
163 _uri
->sip_uri_scheme
.sip_str_len
== 0) && error
!= NULL
) {
166 if (_uri
->sip_uri_scheme
.sip_str_len
> 0)
167 return (&_uri
->sip_uri_scheme
);
172 * Return user name from URI
175 sip_get_uri_user(const struct sip_uri
*uri
, int *error
)
179 _uri
= sip_check_get_param(uri
, error
);
183 if ((_uri
->sip_uri_errflags
& SIP_URIERR_USER
) != 0 && error
!= NULL
)
185 if (uri
->sip_uri_user
.sip_str_len
> 0)
186 return (&uri
->sip_uri_user
);
191 * Return password from URI
194 sip_get_uri_password(const struct sip_uri
*uri
, int *error
)
198 _uri
= sip_check_get_param(uri
, error
);
202 if ((_uri
->sip_uri_errflags
& SIP_URIERR_PASS
) != 0 && error
!= NULL
)
204 if (_uri
->sip_uri_password
.sip_str_len
> 0)
205 return (&_uri
->sip_uri_password
);
210 * Get host from the URI
213 sip_get_uri_host(const struct sip_uri
*uri
, int *error
)
217 _uri
= sip_check_get_param(uri
, error
);
221 if ((_uri
->sip_uri_errflags
& SIP_URIERR_HOST
) != 0 && error
!= NULL
)
223 if (_uri
->sip_uri_host
.sip_str_len
> 0)
224 return (&_uri
->sip_uri_host
);
229 * Get port from the URI
232 sip_get_uri_port(const struct sip_uri
*uri
, int *error
)
236 _uri
= sip_check_get_param(uri
, error
);
240 if ((_uri
->sip_uri_errflags
& SIP_URIERR_PORT
) != 0) {
245 return (_uri
->sip_uri_port
);
249 sip_get_uri_params(const struct sip_uri
*uri
, int *error
)
253 _uri
= sip_check_get_param(uri
, error
);
257 if (!_uri
->sip_uri_issip
) {
263 if ((_uri
->sip_uri_errflags
& SIP_URIERR_PARAM
) != 0 && error
!= NULL
)
265 return (_uri
->sip_uri_params
);
269 * Get headers from the URI
272 sip_get_uri_headers(const struct sip_uri
*uri
, int *error
)
276 _uri
= sip_check_get_param(uri
, error
);
280 if (!_uri
->sip_uri_issip
) {
285 if ((_uri
->sip_uri_errflags
& SIP_URIERR_HEADER
) != 0 && error
!= NULL
)
287 if (_uri
->sip_uri_headers
.sip_str_len
> 0)
288 return (&_uri
->sip_uri_headers
);
293 * Return opaque value for an ABS URI
296 sip_get_uri_opaque(const struct sip_uri
*uri
, int *error
)
300 _uri
= sip_check_get_param(uri
, error
);
304 if (_uri
->sip_uri_issip
) {
309 if ((_uri
->sip_uri_errflags
& SIP_URIERR_OPAQUE
) != 0 && error
!= NULL
)
311 if (_uri
->sip_uri_opaque
.sip_str_len
> 0)
312 return (&_uri
->sip_uri_opaque
);
317 * Return query from an absolute URI
320 sip_get_uri_query(const struct sip_uri
*uri
, int *error
)
324 _uri
= sip_check_get_param(uri
, error
);
328 if (_uri
->sip_uri_issip
) {
333 if ((_uri
->sip_uri_errflags
& SIP_URIERR_QUERY
) != 0 && error
!= NULL
)
335 if (_uri
->sip_uri_query
.sip_str_len
> 0)
336 return (&_uri
->sip_uri_query
);
341 * Get path from an assolute URI
344 sip_get_uri_path(const struct sip_uri
*uri
, int *error
)
348 _uri
= sip_check_get_param(uri
, error
);
352 if (_uri
->sip_uri_issip
) {
357 if ((_uri
->sip_uri_errflags
& SIP_URIERR_PATH
) != 0 && error
!= NULL
)
359 if (_uri
->sip_uri_path
.sip_str_len
> 0)
360 return (&_uri
->sip_uri_path
);
365 * Get the reg-name from absolute URI
368 sip_get_uri_regname(const struct sip_uri
*uri
, int *error
)
372 _uri
= sip_check_get_param(uri
, error
);
376 if (_uri
->sip_uri_issip
) {
381 if ((_uri
->sip_uri_errflags
& SIP_URIERR_REGNAME
) != 0 && error
!= NULL
)
383 if (_uri
->sip_uri_regname
.sip_str_len
> 0)
384 return (&_uri
->sip_uri_regname
);
389 * Return TRUE if this is a teluser
392 sip_is_uri_teluser(const struct sip_uri
*uri
)
399 _uri
= (_sip_uri_t
*)uri
;
400 return (_uri
->sip_uri_isteluser
);
404 sip_get_uri_errflags(const struct sip_uri
*uri
, int *error
)
408 _uri
= sip_check_get_param(uri
, error
);
411 return (_uri
->sip_uri_errflags
);
415 * the caller is responsible for freeing the returned string
418 sip_uri_errflags_to_str(int errflags
)
420 char *err_info
= NULL
;
425 err_info
= (char *)malloc(SIP_URI_BUF_SIZE
);
426 if (err_info
== NULL
)
429 if (errflags
& SIP_URIERR_NOURI
) {
430 (void) strncpy(err_info
, "Error : No URI",
431 strlen("Error : No URI"));
432 err_info
[strlen("Error : No URI")] = '\0';
436 (void) strncpy(err_info
, "Error(s) in", strlen("Error(s) in"));
437 err_info
[strlen("Error(s) in")] = '\0';
438 if (errflags
& SIP_URIERR_SCHEME
)
439 (void) strncat(err_info
, " SCHEME,", strlen(" SCHEME,"));
440 if (errflags
& SIP_URIERR_USER
)
441 (void) strncat(err_info
, " USER,", strlen(" USER,"));
442 if (errflags
& SIP_URIERR_PASS
)
443 (void) strncat(err_info
, " PASSWORD,", strlen(" PASSWORD,"));
444 if (errflags
& SIP_URIERR_HOST
)
445 (void) strncat(err_info
, " HOST,", strlen(" HOST,"));
446 if (errflags
& SIP_URIERR_PORT
)
447 (void) strncat(err_info
, " PORT,", strlen(" PORT,"));
448 if (errflags
& SIP_URIERR_PARAM
) {
449 (void) strncat(err_info
, " PARAMETERS,",
450 strlen(" PARAMETERS,"));
452 if (errflags
& SIP_URIERR_HEADER
)
453 (void) strncat(err_info
, " HEADERS,", strlen(" HEADERS,"));
454 if (errflags
& SIP_URIERR_OPAQUE
)
455 (void) strncat(err_info
, " OPAQUE,", strlen(" OPAQUE,"));
456 if (errflags
& SIP_URIERR_QUERY
)
457 (void) strncat(err_info
, " QUERY,", strlen(" QUERY,"));
458 if (errflags
& SIP_URIERR_PATH
)
459 (void) strncat(err_info
, " PATH,", strlen(" PATH,"));
460 if (errflags
& SIP_URIERR_REGNAME
)
461 (void) strncat(err_info
, " REG-NAME,", strlen(" REG-NAME,"));
462 if (strlen(err_info
) == strlen("Error(s) in")) {
466 err_info
[strlen(err_info
) - 1] = '\0';
467 (void) strncat(err_info
, " part(s)", strlen(" part(s)"));