xref: /titanic_50/usr/src/lib/libsip/common/sip_uri_ui.c (revision 2c2c41837e330b002c4220a39638150db504fe0e)
140cb5e5dSvi117747 /*
240cb5e5dSvi117747  * CDDL HEADER START
340cb5e5dSvi117747  *
440cb5e5dSvi117747  * The contents of this file are subject to the terms of the
540cb5e5dSvi117747  * Common Development and Distribution License (the "License").
640cb5e5dSvi117747  * You may not use this file except in compliance with the License.
740cb5e5dSvi117747  *
840cb5e5dSvi117747  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
940cb5e5dSvi117747  * or http://www.opensolaris.org/os/licensing.
1040cb5e5dSvi117747  * See the License for the specific language governing permissions
1140cb5e5dSvi117747  * and limitations under the License.
1240cb5e5dSvi117747  *
1340cb5e5dSvi117747  * When distributing Covered Code, include this CDDL HEADER in each
1440cb5e5dSvi117747  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1540cb5e5dSvi117747  * If applicable, add the following below this CDDL HEADER, with the
1640cb5e5dSvi117747  * fields enclosed by brackets "[]" replaced with your own identifying
1740cb5e5dSvi117747  * information: Portions Copyright [yyyy] [name of copyright owner]
1840cb5e5dSvi117747  *
1940cb5e5dSvi117747  * CDDL HEADER END
2040cb5e5dSvi117747  */
2140cb5e5dSvi117747 
2240cb5e5dSvi117747 /*
23*2c2c4183Svi117747  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
2440cb5e5dSvi117747  * Use is subject to license terms.
2540cb5e5dSvi117747  */
2640cb5e5dSvi117747 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2740cb5e5dSvi117747 
2840cb5e5dSvi117747 #include <stdlib.h>
2940cb5e5dSvi117747 #include <string.h>
3040cb5e5dSvi117747 #include <ctype.h>
31*2c2c4183Svi117747 #include <errno.h>
3240cb5e5dSvi117747 
3340cb5e5dSvi117747 #include "sip_parse_uri.h"
3440cb5e5dSvi117747 
3540cb5e5dSvi117747 void
sip_free_parsed_uri(sip_uri_t uri)3640cb5e5dSvi117747 sip_free_parsed_uri(sip_uri_t uri)
3740cb5e5dSvi117747 {
3840cb5e5dSvi117747 	_sip_uri_t	*_uri;
3940cb5e5dSvi117747 
4040cb5e5dSvi117747 	if (uri == NULL)
4140cb5e5dSvi117747 		return;
4240cb5e5dSvi117747 
4340cb5e5dSvi117747 	_uri = (_sip_uri_t *)uri;
4440cb5e5dSvi117747 	if (_uri->sip_uri_issip) {
4540cb5e5dSvi117747 		sip_param_t	*param;
4640cb5e5dSvi117747 		sip_param_t	*param_next;
4740cb5e5dSvi117747 
4840cb5e5dSvi117747 		param = _uri->sip_uri_params;
4940cb5e5dSvi117747 		while (param != NULL) {
5040cb5e5dSvi117747 			param_next = param->param_next;
5140cb5e5dSvi117747 			free(param);
5240cb5e5dSvi117747 			param = param_next;
5340cb5e5dSvi117747 		}
5440cb5e5dSvi117747 	}
5540cb5e5dSvi117747 	free(_uri);
5640cb5e5dSvi117747 }
5740cb5e5dSvi117747 
5840cb5e5dSvi117747 /*
5940cb5e5dSvi117747  * Parse the URI in uri_str
6040cb5e5dSvi117747  */
6140cb5e5dSvi117747 struct sip_uri *
sip_parse_uri(sip_str_t * uri_str,int * error)6240cb5e5dSvi117747 sip_parse_uri(sip_str_t *uri_str, int *error)
6340cb5e5dSvi117747 {
6440cb5e5dSvi117747 	struct sip_uri	*parsed_uri;
6540cb5e5dSvi117747 
6640cb5e5dSvi117747 	if (error != NULL)
6740cb5e5dSvi117747 		*error = 0;
6840cb5e5dSvi117747 
6940cb5e5dSvi117747 	if (uri_str == NULL) {
7040cb5e5dSvi117747 		if (error != NULL)
7140cb5e5dSvi117747 			*error = EINVAL;
7240cb5e5dSvi117747 		return (NULL);
7340cb5e5dSvi117747 	}
7440cb5e5dSvi117747 	parsed_uri = calloc(1, sizeof (_sip_uri_t));
7540cb5e5dSvi117747 	if (parsed_uri == NULL) {
7640cb5e5dSvi117747 		if (error != NULL)
7740cb5e5dSvi117747 			*error = ENOMEM;
7840cb5e5dSvi117747 		return (NULL);
7940cb5e5dSvi117747 	}
8040cb5e5dSvi117747 
8140cb5e5dSvi117747 	sip_uri_parse_it(parsed_uri, uri_str);
8240cb5e5dSvi117747 	if (parsed_uri->sip_uri_errflags & SIP_URIERR_MEMORY) {
8340cb5e5dSvi117747 		free(parsed_uri);
8440cb5e5dSvi117747 		if (error != NULL)
8540cb5e5dSvi117747 			*error = ENOMEM;
8640cb5e5dSvi117747 		return (NULL);
8740cb5e5dSvi117747 	}
8840cb5e5dSvi117747 	if (parsed_uri->sip_uri_errflags != 0 && error != NULL)
8940cb5e5dSvi117747 		*error = EPROTO;
9040cb5e5dSvi117747 	return ((sip_uri_t)parsed_uri);
9140cb5e5dSvi117747 }
9240cb5e5dSvi117747 
9340cb5e5dSvi117747 /*
9440cb5e5dSvi117747  * Get parsed URI
9540cb5e5dSvi117747  */
9640cb5e5dSvi117747 const struct sip_uri *
sip_get_uri_parsed(sip_header_value_t value,int * error)9740cb5e5dSvi117747 sip_get_uri_parsed(sip_header_value_t value, int *error)
9840cb5e5dSvi117747 {
9940cb5e5dSvi117747 	const struct sip_uri	*ret = NULL;
10040cb5e5dSvi117747 
10140cb5e5dSvi117747 	if (error != NULL)
10240cb5e5dSvi117747 		*error = 0;
10340cb5e5dSvi117747 	if (value == NULL || value->sip_value_parse_uri == NULL ||
10440cb5e5dSvi117747 	    value->value_state == SIP_VALUE_DELETED) {
10540cb5e5dSvi117747 		if (error != NULL)
10640cb5e5dSvi117747 			*error = EINVAL;
10740cb5e5dSvi117747 		return (NULL);
10840cb5e5dSvi117747 	}
10940cb5e5dSvi117747 	ret = value->sip_value_parse_uri;
11040cb5e5dSvi117747 	if (ret->sip_uri_errflags != 0 && error != NULL)
11140cb5e5dSvi117747 		*error = EINVAL;
11240cb5e5dSvi117747 	return ((sip_uri_t)ret);
11340cb5e5dSvi117747 }
11440cb5e5dSvi117747 
11540cb5e5dSvi117747 /*
11640cb5e5dSvi117747  * Return TRUE if this is a SIP URI
11740cb5e5dSvi117747  */
11840cb5e5dSvi117747 boolean_t
sip_is_sipuri(const struct sip_uri * uri)11940cb5e5dSvi117747 sip_is_sipuri(const struct sip_uri *uri)
12040cb5e5dSvi117747 {
12140cb5e5dSvi117747 	_sip_uri_t	*_uri;
12240cb5e5dSvi117747 
12340cb5e5dSvi117747 	if (uri == NULL)
12440cb5e5dSvi117747 		return (B_FALSE);
12540cb5e5dSvi117747 	_uri = (_sip_uri_t *)uri;
12640cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_SCHEME) == 0 &&
12740cb5e5dSvi117747 	    _uri->sip_uri_scheme.sip_str_len > 0 && _uri->sip_uri_issip) {
12840cb5e5dSvi117747 		return (B_TRUE);
12940cb5e5dSvi117747 	}
13040cb5e5dSvi117747 	return (B_FALSE);
13140cb5e5dSvi117747 }
13240cb5e5dSvi117747 
13340cb5e5dSvi117747 /*
13440cb5e5dSvi117747  * Some common checks
13540cb5e5dSvi117747  */
13640cb5e5dSvi117747 static _sip_uri_t *
sip_check_get_param(const struct sip_uri * uri,int * error)13740cb5e5dSvi117747 sip_check_get_param(const struct sip_uri *uri, int *error)
13840cb5e5dSvi117747 {
13940cb5e5dSvi117747 	if (error != NULL)
14040cb5e5dSvi117747 		*error = 0;
14140cb5e5dSvi117747 
14240cb5e5dSvi117747 	if (uri == NULL) {
14340cb5e5dSvi117747 		if (error != NULL)
14440cb5e5dSvi117747 			*error = EINVAL;
14540cb5e5dSvi117747 		return (NULL);
14640cb5e5dSvi117747 	}
14740cb5e5dSvi117747 	return ((_sip_uri_t *)uri);
14840cb5e5dSvi117747 }
14940cb5e5dSvi117747 
15040cb5e5dSvi117747 
15140cb5e5dSvi117747 /*
15240cb5e5dSvi117747  * Return the URI scheme
15340cb5e5dSvi117747  */
15440cb5e5dSvi117747 const sip_str_t *
sip_get_uri_scheme(const struct sip_uri * uri,int * error)15540cb5e5dSvi117747 sip_get_uri_scheme(const struct sip_uri *uri, int *error)
15640cb5e5dSvi117747 {
15740cb5e5dSvi117747 	_sip_uri_t	*_uri;
15840cb5e5dSvi117747 
15940cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
16040cb5e5dSvi117747 	if (_uri == NULL)
16140cb5e5dSvi117747 		return (NULL);
16240cb5e5dSvi117747 
16340cb5e5dSvi117747 	if (((_uri->sip_uri_errflags & SIP_URIERR_SCHEME) != 0 ||
16440cb5e5dSvi117747 	    _uri->sip_uri_scheme.sip_str_len == 0) && error != NULL) {
16540cb5e5dSvi117747 		*error = EINVAL;
16640cb5e5dSvi117747 	}
16740cb5e5dSvi117747 	if (_uri->sip_uri_scheme.sip_str_len > 0)
16840cb5e5dSvi117747 		return (&_uri->sip_uri_scheme);
16940cb5e5dSvi117747 	return (NULL);
17040cb5e5dSvi117747 }
17140cb5e5dSvi117747 
17240cb5e5dSvi117747 /*
17340cb5e5dSvi117747  *  Return user name from URI
17440cb5e5dSvi117747  */
17540cb5e5dSvi117747 const sip_str_t *
sip_get_uri_user(const struct sip_uri * uri,int * error)17640cb5e5dSvi117747 sip_get_uri_user(const struct sip_uri *uri, int *error)
17740cb5e5dSvi117747 {
17840cb5e5dSvi117747 	_sip_uri_t	*_uri;
17940cb5e5dSvi117747 
18040cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
18140cb5e5dSvi117747 	if (_uri == NULL)
18240cb5e5dSvi117747 		return (NULL);
18340cb5e5dSvi117747 
18440cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_USER) != 0 && error != NULL)
18540cb5e5dSvi117747 		*error = EINVAL;
18640cb5e5dSvi117747 	if (uri->sip_uri_user.sip_str_len > 0)
18740cb5e5dSvi117747 		return (&uri->sip_uri_user);
18840cb5e5dSvi117747 	return (NULL);
18940cb5e5dSvi117747 }
19040cb5e5dSvi117747 
19140cb5e5dSvi117747 /*
19240cb5e5dSvi117747  *  Return password from URI
19340cb5e5dSvi117747  */
19440cb5e5dSvi117747 const sip_str_t *
sip_get_uri_password(const struct sip_uri * uri,int * error)19540cb5e5dSvi117747 sip_get_uri_password(const struct sip_uri *uri, int *error)
19640cb5e5dSvi117747 {
19740cb5e5dSvi117747 	_sip_uri_t	*_uri;
19840cb5e5dSvi117747 
19940cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
20040cb5e5dSvi117747 	if (_uri == NULL)
20140cb5e5dSvi117747 		return (NULL);
20240cb5e5dSvi117747 
20340cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_PASS) != 0 && error != NULL)
20440cb5e5dSvi117747 		*error = EINVAL;
20540cb5e5dSvi117747 	if (_uri->sip_uri_password.sip_str_len > 0)
20640cb5e5dSvi117747 		return (&_uri->sip_uri_password);
20740cb5e5dSvi117747 	return (NULL);
20840cb5e5dSvi117747 }
20940cb5e5dSvi117747 
21040cb5e5dSvi117747 /*
21140cb5e5dSvi117747  * Get host from the URI
21240cb5e5dSvi117747  */
21340cb5e5dSvi117747 const sip_str_t *
sip_get_uri_host(const struct sip_uri * uri,int * error)21440cb5e5dSvi117747 sip_get_uri_host(const struct sip_uri *uri, int *error)
21540cb5e5dSvi117747 {
21640cb5e5dSvi117747 	_sip_uri_t	*_uri;
21740cb5e5dSvi117747 
21840cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
21940cb5e5dSvi117747 	if (_uri == NULL)
22040cb5e5dSvi117747 		return (NULL);
22140cb5e5dSvi117747 
22240cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_HOST) != 0 && error != NULL)
22340cb5e5dSvi117747 		*error = EINVAL;
22440cb5e5dSvi117747 	if (_uri->sip_uri_host.sip_str_len > 0)
22540cb5e5dSvi117747 		return (&_uri->sip_uri_host);
22640cb5e5dSvi117747 	return (NULL);
22740cb5e5dSvi117747 }
22840cb5e5dSvi117747 
22940cb5e5dSvi117747 /*
23040cb5e5dSvi117747  * Get port from the URI
23140cb5e5dSvi117747  */
23240cb5e5dSvi117747 int
sip_get_uri_port(const struct sip_uri * uri,int * error)23340cb5e5dSvi117747 sip_get_uri_port(const struct sip_uri *uri, int *error)
23440cb5e5dSvi117747 {
23540cb5e5dSvi117747 	_sip_uri_t	*_uri;
23640cb5e5dSvi117747 
23740cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
23840cb5e5dSvi117747 	if (_uri == NULL)
23940cb5e5dSvi117747 		return (NULL);
24040cb5e5dSvi117747 
24140cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_PORT) != 0) {
24240cb5e5dSvi117747 		if (error != NULL)
24340cb5e5dSvi117747 			*error = EINVAL;
24440cb5e5dSvi117747 		return (0);
24540cb5e5dSvi117747 	}
24640cb5e5dSvi117747 	return (_uri->sip_uri_port);
24740cb5e5dSvi117747 }
24840cb5e5dSvi117747 
24940cb5e5dSvi117747 const sip_param_t *
sip_get_uri_params(const struct sip_uri * uri,int * error)25040cb5e5dSvi117747 sip_get_uri_params(const struct sip_uri *uri, int *error)
25140cb5e5dSvi117747 {
25240cb5e5dSvi117747 	_sip_uri_t		*_uri;
25340cb5e5dSvi117747 
25440cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
25540cb5e5dSvi117747 	if (_uri == NULL)
25640cb5e5dSvi117747 		return (NULL);
25740cb5e5dSvi117747 
25840cb5e5dSvi117747 	if (!_uri->sip_uri_issip) {
25940cb5e5dSvi117747 		if (error != NULL)
26040cb5e5dSvi117747 			*error = EINVAL;
26140cb5e5dSvi117747 		return (NULL);
26240cb5e5dSvi117747 	}
26340cb5e5dSvi117747 
26440cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_PARAM) != 0 && error != NULL)
26540cb5e5dSvi117747 		*error = EINVAL;
26640cb5e5dSvi117747 	return (_uri->sip_uri_params);
26740cb5e5dSvi117747 }
26840cb5e5dSvi117747 
26940cb5e5dSvi117747 /*
27040cb5e5dSvi117747  * Get headers from the URI
27140cb5e5dSvi117747  */
27240cb5e5dSvi117747 const sip_str_t *
sip_get_uri_headers(const struct sip_uri * uri,int * error)27340cb5e5dSvi117747 sip_get_uri_headers(const struct sip_uri *uri, int *error)
27440cb5e5dSvi117747 {
27540cb5e5dSvi117747 	_sip_uri_t	*_uri;
27640cb5e5dSvi117747 
27740cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
27840cb5e5dSvi117747 	if (_uri == NULL)
27940cb5e5dSvi117747 		return (NULL);
28040cb5e5dSvi117747 
28140cb5e5dSvi117747 	if (!_uri->sip_uri_issip) {
28240cb5e5dSvi117747 		if (error != NULL)
28340cb5e5dSvi117747 			*error = EINVAL;
28440cb5e5dSvi117747 		return (NULL);
28540cb5e5dSvi117747 	}
28640cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_HEADER) != 0 && error != NULL)
28740cb5e5dSvi117747 		*error = EINVAL;
28840cb5e5dSvi117747 	if (_uri->sip_uri_headers.sip_str_len > 0)
28940cb5e5dSvi117747 		return (&_uri->sip_uri_headers);
29040cb5e5dSvi117747 	return (NULL);
29140cb5e5dSvi117747 }
29240cb5e5dSvi117747 
29340cb5e5dSvi117747 /*
29440cb5e5dSvi117747  *  Return opaque value for an ABS URI
29540cb5e5dSvi117747  */
29640cb5e5dSvi117747 const sip_str_t *
sip_get_uri_opaque(const struct sip_uri * uri,int * error)29740cb5e5dSvi117747 sip_get_uri_opaque(const struct sip_uri *uri, int *error)
29840cb5e5dSvi117747 {
29940cb5e5dSvi117747 	_sip_uri_t	*_uri;
30040cb5e5dSvi117747 
30140cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
30240cb5e5dSvi117747 	if (_uri == NULL)
30340cb5e5dSvi117747 		return (NULL);
30440cb5e5dSvi117747 
30540cb5e5dSvi117747 	if (_uri->sip_uri_issip) {
30640cb5e5dSvi117747 		if (error != NULL)
30740cb5e5dSvi117747 			*error = EINVAL;
30840cb5e5dSvi117747 		return (NULL);
30940cb5e5dSvi117747 	}
31040cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_OPAQUE) != 0 && error != NULL)
31140cb5e5dSvi117747 		*error = EINVAL;
31240cb5e5dSvi117747 	if (_uri->sip_uri_opaque.sip_str_len > 0)
31340cb5e5dSvi117747 		return (&_uri->sip_uri_opaque);
31440cb5e5dSvi117747 	return (NULL);
31540cb5e5dSvi117747 }
31640cb5e5dSvi117747 
31740cb5e5dSvi117747 /*
31840cb5e5dSvi117747  * Return query from an absolute URI
31940cb5e5dSvi117747  */
32040cb5e5dSvi117747 const sip_str_t *
sip_get_uri_query(const struct sip_uri * uri,int * error)32140cb5e5dSvi117747 sip_get_uri_query(const struct sip_uri *uri, int *error)
32240cb5e5dSvi117747 {
32340cb5e5dSvi117747 	_sip_uri_t	*_uri;
32440cb5e5dSvi117747 
32540cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
32640cb5e5dSvi117747 	if (_uri == NULL)
32740cb5e5dSvi117747 		return (NULL);
32840cb5e5dSvi117747 
32940cb5e5dSvi117747 	if (_uri->sip_uri_issip) {
33040cb5e5dSvi117747 		if (error != NULL)
33140cb5e5dSvi117747 			*error = EINVAL;
33240cb5e5dSvi117747 		return (NULL);
33340cb5e5dSvi117747 	}
33440cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_QUERY) != 0 && error != NULL)
33540cb5e5dSvi117747 		*error = EINVAL;
33640cb5e5dSvi117747 	if (_uri->sip_uri_query.sip_str_len > 0)
33740cb5e5dSvi117747 		return (&_uri->sip_uri_query);
33840cb5e5dSvi117747 	return (NULL);
33940cb5e5dSvi117747 }
34040cb5e5dSvi117747 
34140cb5e5dSvi117747 /*
34240cb5e5dSvi117747  *  Get path from an assolute URI
34340cb5e5dSvi117747  */
34440cb5e5dSvi117747 const sip_str_t *
sip_get_uri_path(const struct sip_uri * uri,int * error)34540cb5e5dSvi117747 sip_get_uri_path(const struct sip_uri *uri, int *error)
34640cb5e5dSvi117747 {
34740cb5e5dSvi117747 	_sip_uri_t	*_uri;
34840cb5e5dSvi117747 
34940cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
35040cb5e5dSvi117747 	if (_uri == NULL)
35140cb5e5dSvi117747 		return (NULL);
35240cb5e5dSvi117747 
35340cb5e5dSvi117747 	if (_uri->sip_uri_issip) {
35440cb5e5dSvi117747 		if (error != NULL)
35540cb5e5dSvi117747 			*error = EINVAL;
35640cb5e5dSvi117747 		return (NULL);
35740cb5e5dSvi117747 	}
35840cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_PATH) != 0 && error != NULL)
35940cb5e5dSvi117747 		*error = EINVAL;
36040cb5e5dSvi117747 	if (_uri->sip_uri_path.sip_str_len > 0)
36140cb5e5dSvi117747 		return (&_uri->sip_uri_path);
36240cb5e5dSvi117747 	return (NULL);
36340cb5e5dSvi117747 }
36440cb5e5dSvi117747 
36540cb5e5dSvi117747 /*
36640cb5e5dSvi117747  * Get the reg-name from absolute URI
36740cb5e5dSvi117747  */
36840cb5e5dSvi117747 const sip_str_t	*
sip_get_uri_regname(const struct sip_uri * uri,int * error)36940cb5e5dSvi117747 sip_get_uri_regname(const struct sip_uri *uri, int *error)
37040cb5e5dSvi117747 {
37140cb5e5dSvi117747 	_sip_uri_t	*_uri;
37240cb5e5dSvi117747 
37340cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
37440cb5e5dSvi117747 	if (_uri == NULL)
37540cb5e5dSvi117747 		return (NULL);
37640cb5e5dSvi117747 
37740cb5e5dSvi117747 	if (_uri->sip_uri_issip) {
37840cb5e5dSvi117747 		if (error != NULL)
37940cb5e5dSvi117747 			*error = EINVAL;
38040cb5e5dSvi117747 		return (NULL);
38140cb5e5dSvi117747 	}
38240cb5e5dSvi117747 	if ((_uri->sip_uri_errflags & SIP_URIERR_REGNAME) != 0 && error != NULL)
38340cb5e5dSvi117747 		*error = EINVAL;
38440cb5e5dSvi117747 	if (_uri->sip_uri_regname.sip_str_len > 0)
38540cb5e5dSvi117747 		return (&_uri->sip_uri_regname);
38640cb5e5dSvi117747 	return (NULL);
38740cb5e5dSvi117747 }
38840cb5e5dSvi117747 
38940cb5e5dSvi117747 /*
39040cb5e5dSvi117747  * Return TRUE if this is a teluser
39140cb5e5dSvi117747  */
39240cb5e5dSvi117747 boolean_t
sip_is_uri_teluser(const struct sip_uri * uri)39340cb5e5dSvi117747 sip_is_uri_teluser(const struct sip_uri *uri)
39440cb5e5dSvi117747 {
39540cb5e5dSvi117747 	_sip_uri_t	*_uri;
39640cb5e5dSvi117747 
39740cb5e5dSvi117747 	if (uri == NULL)
39840cb5e5dSvi117747 		return (B_FALSE);
39940cb5e5dSvi117747 
40040cb5e5dSvi117747 	_uri = (_sip_uri_t *)uri;
40140cb5e5dSvi117747 	return (_uri->sip_uri_isteluser);
40240cb5e5dSvi117747 }
40340cb5e5dSvi117747 
40440cb5e5dSvi117747 int
sip_get_uri_errflags(const struct sip_uri * uri,int * error)40540cb5e5dSvi117747 sip_get_uri_errflags(const struct sip_uri *uri, int *error)
40640cb5e5dSvi117747 {
40740cb5e5dSvi117747 	_sip_uri_t	*_uri;
40840cb5e5dSvi117747 
40940cb5e5dSvi117747 	_uri = sip_check_get_param(uri, error);
41040cb5e5dSvi117747 	if (_uri == NULL)
41140cb5e5dSvi117747 		return (0);
41240cb5e5dSvi117747 	return (_uri->sip_uri_errflags);
41340cb5e5dSvi117747 }
41440cb5e5dSvi117747 
41540cb5e5dSvi117747 /*
41640cb5e5dSvi117747  * the caller is responsible for freeing the returned string
41740cb5e5dSvi117747  */
41840cb5e5dSvi117747 char *
sip_uri_errflags_to_str(int errflags)41940cb5e5dSvi117747 sip_uri_errflags_to_str(int errflags)
42040cb5e5dSvi117747 {
42140cb5e5dSvi117747 	char	*err_info = NULL;
42240cb5e5dSvi117747 
42340cb5e5dSvi117747 	if (errflags == 0)
42440cb5e5dSvi117747 		return (NULL);
42540cb5e5dSvi117747 
42640cb5e5dSvi117747 	err_info = (char *)malloc(SIP_URI_BUF_SIZE);
42740cb5e5dSvi117747 	if (err_info == NULL)
42840cb5e5dSvi117747 		return (NULL);
42940cb5e5dSvi117747 
43040cb5e5dSvi117747 	if (errflags & SIP_URIERR_NOURI) {
43140cb5e5dSvi117747 		(void) strncpy(err_info, "Error : No URI",
43240cb5e5dSvi117747 		    strlen("Error : No URI"));
43340cb5e5dSvi117747 		err_info[strlen("Error : No URI")] = '\0';
43440cb5e5dSvi117747 		return (err_info);
43540cb5e5dSvi117747 	}
43640cb5e5dSvi117747 
43740cb5e5dSvi117747 	(void) strncpy(err_info, "Error(s) in", strlen("Error(s) in"));
43840cb5e5dSvi117747 	err_info[strlen("Error(s) in")] = '\0';
43940cb5e5dSvi117747 	if (errflags & SIP_URIERR_SCHEME)
44040cb5e5dSvi117747 		(void) strncat(err_info, " SCHEME,", strlen(" SCHEME,"));
44140cb5e5dSvi117747 	if (errflags & SIP_URIERR_USER)
44240cb5e5dSvi117747 		(void) strncat(err_info, " USER,", strlen(" USER,"));
44340cb5e5dSvi117747 	if (errflags & SIP_URIERR_PASS)
44440cb5e5dSvi117747 		(void) strncat(err_info, " PASSWORD,", strlen(" PASSWORD,"));
44540cb5e5dSvi117747 	if (errflags & SIP_URIERR_HOST)
44640cb5e5dSvi117747 		(void) strncat(err_info, " HOST,", strlen(" HOST,"));
44740cb5e5dSvi117747 	if (errflags & SIP_URIERR_PORT)
44840cb5e5dSvi117747 		(void) strncat(err_info, " PORT,", strlen(" PORT,"));
44940cb5e5dSvi117747 	if (errflags & SIP_URIERR_PARAM) {
45040cb5e5dSvi117747 		(void) strncat(err_info, " PARAMETERS,",
45140cb5e5dSvi117747 		    strlen(" PARAMETERS,"));
45240cb5e5dSvi117747 	}
45340cb5e5dSvi117747 	if (errflags & SIP_URIERR_HEADER)
45440cb5e5dSvi117747 		(void) strncat(err_info, " HEADERS,", strlen(" HEADERS,"));
45540cb5e5dSvi117747 	if (errflags & SIP_URIERR_OPAQUE)
45640cb5e5dSvi117747 		(void) strncat(err_info, " OPAQUE,", strlen(" OPAQUE,"));
45740cb5e5dSvi117747 	if (errflags & SIP_URIERR_QUERY)
45840cb5e5dSvi117747 		(void) strncat(err_info, " QUERY,", strlen(" QUERY,"));
45940cb5e5dSvi117747 	if (errflags & SIP_URIERR_PATH)
46040cb5e5dSvi117747 		(void) strncat(err_info, " PATH,", strlen(" PATH,"));
46140cb5e5dSvi117747 	if (errflags & SIP_URIERR_REGNAME)
46240cb5e5dSvi117747 		(void) strncat(err_info, " REG-NAME,", strlen(" REG-NAME,"));
46340cb5e5dSvi117747 	if (strlen(err_info) == strlen("Error(s) in")) {
46440cb5e5dSvi117747 		free(err_info);
46540cb5e5dSvi117747 		err_info = NULL;
46640cb5e5dSvi117747 	} else {
46740cb5e5dSvi117747 		err_info[strlen(err_info) - 1] = '\0';
46840cb5e5dSvi117747 		(void) strncat(err_info, " part(s)", strlen(" part(s)"));
46940cb5e5dSvi117747 	}
47040cb5e5dSvi117747 	return (err_info);
47140cb5e5dSvi117747 }
472