12882Svi117747 /*
22882Svi117747  * CDDL HEADER START
32882Svi117747  *
42882Svi117747  * The contents of this file are subject to the terms of the
52882Svi117747  * Common Development and Distribution License (the "License").
62882Svi117747  * You may not use this file except in compliance with the License.
72882Svi117747  *
82882Svi117747  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92882Svi117747  * or http://www.opensolaris.org/os/licensing.
102882Svi117747  * See the License for the specific language governing permissions
112882Svi117747  * and limitations under the License.
122882Svi117747  *
132882Svi117747  * When distributing Covered Code, include this CDDL HEADER in each
142882Svi117747  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152882Svi117747  * If applicable, add the following below this CDDL HEADER, with the
162882Svi117747  * fields enclosed by brackets "[]" replaced with your own identifying
172882Svi117747  * information: Portions Copyright [yyyy] [name of copyright owner]
182882Svi117747  *
192882Svi117747  * CDDL HEADER END
202882Svi117747  */
212882Svi117747 
222882Svi117747 /*
233439Svi117747  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
242882Svi117747  * Use is subject to license terms.
252882Svi117747  */
262882Svi117747 
272882Svi117747 #pragma ident	"%Z%%M%	%I%	%E% SMI"
282882Svi117747 
293439Svi117747 #include <stdlib.h>
303439Svi117747 #include <assert.h>
313439Svi117747 #include <errno.h>
323439Svi117747 #include <pthread.h>
333439Svi117747 #include <sip.h>
343439Svi117747 
352882Svi117747 #include "sip_msg.h"
362882Svi117747 #include "sip_miscdefs.h"
373439Svi117747 #include "sip_parse_uri.h"
382882Svi117747 #include "sip_dialog.h"
392882Svi117747 
402882Svi117747 /*
412882Svi117747  * Create a request using the state maintained in the dialog.
422882Svi117747  */
432882Svi117747 sip_msg_t
442882Svi117747 sip_create_dialog_req(sip_method_t method, sip_dialog_t dialog,
452882Svi117747     char *transport, char *sent_by, int sent_by_port, char *via_param,
462882Svi117747     uint32_t maxforward, int cseq)
472882Svi117747 {
482882Svi117747 	_sip_dialog_t	*_dialog;
492882Svi117747 	sip_msg_t	sip_msg;
502882Svi117747 	char		*uri;
512882Svi117747 	int		oldseq = 0;
522882Svi117747 
532882Svi117747 	if (!sip_manage_dialog || dialog == NULL || transport == NULL ||
542882Svi117747 	    sent_by == NULL) {
552882Svi117747 		return (NULL);
562882Svi117747 	}
572882Svi117747 	if ((sip_msg = sip_new_msg()) == NULL)
582882Svi117747 		return (NULL);
592882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
602882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
612882Svi117747 	/*
622882Svi117747 	 * Depending on the route set, if any, the request URI could either
632882Svi117747 	 * be the contact URI or the 1st URI from the route set.
642882Svi117747 	 */
652882Svi117747 	uri = (char *)sip_dialog_req_uri(_dialog);
662882Svi117747 	if (uri == NULL)
672882Svi117747 		goto err_ret;
682882Svi117747 	if (sip_add_request_line(sip_msg, method, uri) != 0) {
692882Svi117747 		free(uri);
702882Svi117747 		goto err_ret;
712882Svi117747 	}
722882Svi117747 	free(uri);
732882Svi117747 	if (sip_copy_header(sip_msg, _dialog->sip_dlg_local_uri_tag, NULL) != 0)
742882Svi117747 		goto err_ret;
752882Svi117747 	if (sip_copy_header(sip_msg, _dialog->sip_dlg_remote_uri_tag, NULL) !=
762882Svi117747 	    0) {
772882Svi117747 		goto err_ret;
782882Svi117747 	}
79*4702Sgm209912 	if (sip_copy_header(sip_msg, _dialog->sip_dlg_local_contact, NULL) != 0)
80*4702Sgm209912 		goto err_ret;
812882Svi117747 	if (sip_add_via(sip_msg, transport, sent_by, sent_by_port, via_param) !=
822882Svi117747 	    0) {
832882Svi117747 		goto err_ret;
842882Svi117747 	}
852882Svi117747 	if (sip_add_maxforward(sip_msg, maxforward) != 0)
862882Svi117747 		goto err_ret;
872882Svi117747 	if (sip_copy_header(sip_msg, _dialog->sip_dlg_call_id, NULL) != 0)
882882Svi117747 		goto err_ret;
892882Svi117747 	if (cseq < 0) {
902882Svi117747 		if (_dialog->sip_dlg_local_cseq == 0)
912882Svi117747 			_dialog->sip_dlg_local_cseq = 1;
922882Svi117747 		oldseq = _dialog->sip_dlg_local_cseq;
932882Svi117747 		cseq = ++_dialog->sip_dlg_local_cseq;
942882Svi117747 	}
952882Svi117747 	if (sip_add_cseq(sip_msg, method, cseq) != 0) {
962882Svi117747 		_dialog->sip_dlg_local_cseq = oldseq;
972882Svi117747 		goto err_ret;
982882Svi117747 	}
992882Svi117747 	/*
1002882Svi117747 	 * The route set, even if empty, overrides any pre-existing route set.
1012882Svi117747 	 * If the route set is empty, the UAC MUST NOT add a Route header
1022882Svi117747 	 * field to the request.
1032882Svi117747 	 */
1042882Svi117747 	(void) sip_delete_header_by_name(sip_msg, SIP_ROUTE);
1052882Svi117747 
1062882Svi117747 	if (_dialog->sip_dlg_route_set != NULL) {
1072882Svi117747 		if (sip_copy_header(sip_msg, _dialog->sip_dlg_route_set,
1082882Svi117747 		    NULL) != 0) {
1092882Svi117747 			_dialog->sip_dlg_local_cseq = oldseq;
1102882Svi117747 			goto err_ret;
1112882Svi117747 		}
1122882Svi117747 	}
1132882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
1142882Svi117747 	return (sip_msg);
1152882Svi117747 err_ret:
1162882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
1172882Svi117747 	sip_free_msg(sip_msg);
1182882Svi117747 	return (NULL);
1192882Svi117747 }
1202882Svi117747 
1212882Svi117747 /*
1222882Svi117747  * Get the Dialog method
1232882Svi117747  */
1242882Svi117747 int
1252882Svi117747 sip_get_dialog_method(sip_dialog_t dialog, int *error)
1262882Svi117747 {
1272882Svi117747 	_sip_dialog_t	*_dialog;
1282882Svi117747 
1292882Svi117747 	if (error != NULL)
1302882Svi117747 		*error = 0;
1312882Svi117747 	if (!sip_manage_dialog) {
1322882Svi117747 		if (error != NULL)
1332882Svi117747 			*error = EINVAL;
1342882Svi117747 		return (0);
1352882Svi117747 	}
1362882Svi117747 	if (dialog == NULL) {
1372882Svi117747 		if (error != NULL)
1382882Svi117747 			*error = EINVAL;
1392882Svi117747 		return (0);
1402882Svi117747 	}
1412882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
1422882Svi117747 	return (_dialog->sip_dlg_method);
1432882Svi117747 }
1442882Svi117747 
1452882Svi117747 /*
1462882Svi117747  * Get the Dialog state
1472882Svi117747  */
1482882Svi117747 int
1492882Svi117747 sip_get_dialog_state(sip_dialog_t dialog, int *error)
1502882Svi117747 {
1512882Svi117747 	_sip_dialog_t	*_dialog;
1522882Svi117747 
1532882Svi117747 	if (error != NULL)
1542882Svi117747 		*error = 0;
1552882Svi117747 	if (!sip_manage_dialog) {
1562882Svi117747 		if (error != NULL)
1572882Svi117747 			*error = EINVAL;
1582882Svi117747 		return (0);
1592882Svi117747 	}
1602882Svi117747 	if (dialog == NULL) {
1612882Svi117747 		if (error != NULL)
1622882Svi117747 			*error = EINVAL;
1632882Svi117747 		return (0);
1642882Svi117747 	}
1652882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
1662882Svi117747 	return (_dialog->sip_dlg_state);
1672882Svi117747 }
1682882Svi117747 
1692882Svi117747 /*
1702882Svi117747  * Return the dialog callid
1712882Svi117747  */
1722882Svi117747 const sip_str_t *
1732882Svi117747 sip_get_dialog_callid(sip_dialog_t dialog, int *error)
1742882Svi117747 {
1752882Svi117747 	_sip_dialog_t		*_dialog;
1762882Svi117747 	const struct sip_value	*val;
1772882Svi117747 	const sip_str_t		*callid = NULL;
1782882Svi117747 
1792882Svi117747 	if (error != NULL)
1802882Svi117747 		*error = 0;
1812882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
1822882Svi117747 		if (error != NULL)
1832882Svi117747 			*error = EINVAL;
1842882Svi117747 		return (NULL);
1852882Svi117747 	}
1862882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
1872882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
1882882Svi117747 	if (dialog->sip_dlg_call_id != NULL) {
1892882Svi117747 		val = sip_get_header_value(_dialog->sip_dlg_call_id, error);
1902882Svi117747 		if (val == NULL) {
1912882Svi117747 			(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
1922882Svi117747 			return (NULL);
1932882Svi117747 		}
1942882Svi117747 		callid = &((sip_hdr_value_t *)val)->str_val;
1952882Svi117747 	}
1962882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
1972882Svi117747 	return (callid);
1982882Svi117747 }
1992882Svi117747 
2002882Svi117747 /*
2012882Svi117747  * Return the dialog localtag.
2022882Svi117747  */
2032882Svi117747 const sip_str_t *
2042882Svi117747 sip_get_dialog_local_tag(sip_dialog_t dialog, int *error)
2052882Svi117747 {
2062882Svi117747 	_sip_dialog_t		*_dialog;
2072882Svi117747 	const sip_str_t		*ltag = NULL;
2082882Svi117747 	const struct sip_value	*val;
2092882Svi117747 
2102882Svi117747 	if (error != NULL)
2112882Svi117747 		*error = 0;
2122882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
2132882Svi117747 		if (error != NULL)
2142882Svi117747 			*error = EINVAL;
2152882Svi117747 		return (NULL);
2162882Svi117747 	}
2172882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
2182882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
2192882Svi117747 	if (dialog->sip_dlg_local_uri_tag != NULL) {
2202882Svi117747 		val = sip_get_header_value(_dialog->sip_dlg_local_uri_tag,
2212882Svi117747 		    error);
2222882Svi117747 		if (val == NULL) {
2232882Svi117747 			(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2242882Svi117747 			return (NULL);
2252882Svi117747 		}
2262882Svi117747 		ltag = sip_get_param_value((sip_header_value_t)val, "tag",
2272882Svi117747 		    error);
2282882Svi117747 	}
2292882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2302882Svi117747 	return (ltag);
2312882Svi117747 }
2322882Svi117747 
2332882Svi117747 /*
2342882Svi117747  * Return the dialog remotetag
2352882Svi117747  */
2362882Svi117747 const sip_str_t *
2372882Svi117747 sip_get_dialog_remote_tag(sip_dialog_t dialog, int *error)
2382882Svi117747 {
2392882Svi117747 	_sip_dialog_t		*_dialog;
2402882Svi117747 	const sip_str_t		*ttag = NULL;
2412882Svi117747 	const struct sip_value	*val;
2422882Svi117747 
2432882Svi117747 	if (error != NULL)
2442882Svi117747 		*error = 0;
2452882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
2462882Svi117747 		if (error != NULL)
2472882Svi117747 			*error = EINVAL;
2482882Svi117747 		return (NULL);
2492882Svi117747 	}
2502882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
2512882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
2522882Svi117747 	if (dialog->sip_dlg_remote_uri_tag != NULL) {
2532882Svi117747 		val = sip_get_header_value(_dialog->sip_dlg_remote_uri_tag,
2542882Svi117747 		    error);
2552882Svi117747 		if (val == NULL) {
2562882Svi117747 			(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2572882Svi117747 			return (NULL);
2582882Svi117747 		}
2592882Svi117747 		ttag = sip_get_param_value((sip_header_value_t)val, "tag",
2602882Svi117747 		    error);
2612882Svi117747 	}
2622882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2632882Svi117747 
2642882Svi117747 	return (ttag);
2652882Svi117747 }
2662882Svi117747 
2672882Svi117747 /*
2682882Svi117747  * Return the dialog localuri.
2692882Svi117747  */
2702882Svi117747 const struct sip_uri *
2712882Svi117747 sip_get_dialog_local_uri(sip_dialog_t dialog, int *error)
2722882Svi117747 {
2732882Svi117747 	_sip_dialog_t		*_dialog;
2742882Svi117747 	const _sip_uri_t	*luri = NULL;
2752882Svi117747 	const struct sip_value	*val;
2762882Svi117747 
2772882Svi117747 	if (error != NULL)
2782882Svi117747 		*error = 0;
2792882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
2802882Svi117747 		if (error != NULL)
2812882Svi117747 			*error = EINVAL;
2822882Svi117747 		return (NULL);
2832882Svi117747 	}
2842882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
2852882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
2862882Svi117747 	if (dialog->sip_dlg_local_uri_tag != NULL) {
2872882Svi117747 		val = sip_get_header_value(_dialog->sip_dlg_local_uri_tag,
2882882Svi117747 		    error);
2892882Svi117747 		if (val == NULL) {
2902882Svi117747 			(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2912882Svi117747 			return (NULL);
2922882Svi117747 		}
2932882Svi117747 		luri = val->sip_value_parse_uri;
2942882Svi117747 	}
2952882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2962882Svi117747 
2972882Svi117747 	return ((sip_uri_t)luri);
2982882Svi117747 }
2992882Svi117747 
3002882Svi117747 /*
3012882Svi117747  * Return the dialog remoteuri.
3022882Svi117747  */
3032882Svi117747 const struct sip_uri *
3042882Svi117747 sip_get_dialog_remote_uri(sip_dialog_t dialog, int *error)
3052882Svi117747 {
3062882Svi117747 	_sip_dialog_t		*_dialog;
3072882Svi117747 	const _sip_uri_t	*ruri = NULL;
3082882Svi117747 	const struct sip_value	*val;
3092882Svi117747 
3102882Svi117747 	if (error != NULL)
3112882Svi117747 		*error = 0;
3122882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
3132882Svi117747 		if (error != NULL)
3142882Svi117747 			*error = EINVAL;
3152882Svi117747 		return (NULL);
3162882Svi117747 	}
3172882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
3182882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
3192882Svi117747 	if (dialog->sip_dlg_remote_uri_tag != NULL) {
3202882Svi117747 		val = sip_get_header_value(dialog->sip_dlg_remote_uri_tag,
3212882Svi117747 		    error);
3222882Svi117747 		if (val == NULL) {
3232882Svi117747 			(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
3242882Svi117747 			return (NULL);
3252882Svi117747 		}
3262882Svi117747 		ruri = val->sip_value_parse_uri;
3272882Svi117747 	}
3282882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
3292882Svi117747 	return ((sip_uri_t)ruri);
3302882Svi117747 }
3312882Svi117747 
3322882Svi117747 /*
3332882Svi117747  * Return the dialog remotetarg.
3342882Svi117747  */
3352882Svi117747 const struct sip_uri *
3362882Svi117747 sip_get_dialog_remote_target_uri(sip_dialog_t dialog, int *error)
3372882Svi117747 {
3382882Svi117747 	_sip_dialog_t		*_dialog;
3392882Svi117747 	const struct sip_uri	*rtarg = NULL;
3402882Svi117747 	const struct sip_value	*val;
3412882Svi117747 
3422882Svi117747 	if (error != NULL)
3432882Svi117747 		*error = 0;
3442882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
3452882Svi117747 		if (error != NULL)
3462882Svi117747 			*error = EINVAL;
3472882Svi117747 		return (NULL);
3482882Svi117747 	}
3492882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
3502882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
3512882Svi117747 	if (dialog->sip_dlg_remote_target != NULL) {
3522882Svi117747 		val = sip_get_header_value(_dialog->sip_dlg_remote_target,
3532882Svi117747 		    error);
3542882Svi117747 		if (val == NULL) {
3552882Svi117747 			(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
3562882Svi117747 			return (NULL);
3572882Svi117747 		}
3582882Svi117747 		rtarg = val->sip_value_parse_uri;
3592882Svi117747 	}
3602882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
3612882Svi117747 
3622882Svi117747 	return ((sip_uri_t)rtarg);
3632882Svi117747 }
3642882Svi117747 
3652882Svi117747 /*
3662882Svi117747  * Return the dialog route set
3672882Svi117747  */
3682882Svi117747 const sip_str_t *
3692882Svi117747 sip_get_dialog_route_set(sip_dialog_t dialog, int *error)
3702882Svi117747 {
3712882Svi117747 	_sip_dialog_t		*_dialog;
3722882Svi117747 
3732882Svi117747 	if (error != NULL)
3742882Svi117747 		*error = 0;
3752882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
3762882Svi117747 		if (error != NULL)
3772882Svi117747 			*error = EINVAL;
3782882Svi117747 		return (NULL);
3792882Svi117747 	}
3802882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
3812882Svi117747 	if (_dialog->sip_dlg_rset.sip_str_len > 0)
3822882Svi117747 		return (&_dialog->sip_dlg_rset);
3832882Svi117747 	return (NULL);
3842882Svi117747 }
3852882Svi117747 
3862882Svi117747 /*
3872882Svi117747  * Return the dialog secure
3882882Svi117747  */
3892882Svi117747 boolean_t
3902882Svi117747 sip_is_dialog_secure(sip_dialog_t dialog, int *error)
3912882Svi117747 {
3922882Svi117747 	_sip_dialog_t	*_dialog;
3932882Svi117747 	boolean_t	issecure;
3942882Svi117747 
3952882Svi117747 	if (error != NULL)
3962882Svi117747 		*error = 0;
3972882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
3982882Svi117747 		if (error != NULL)
3992882Svi117747 			*error = EINVAL;
4002882Svi117747 		return (B_FALSE);
4012882Svi117747 	}
4022882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
4032882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
4042882Svi117747 	issecure = _dialog->sip_dlg_secure;
4052882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
4062882Svi117747 	return (issecure);
4072882Svi117747 }
4082882Svi117747 
4092882Svi117747 /*
4102882Svi117747  * Return the dialog local cseq
4112882Svi117747  */
4122882Svi117747 uint32_t
4132882Svi117747 sip_get_dialog_local_cseq(sip_dialog_t dialog, int *error)
4142882Svi117747 {
4152882Svi117747 	_sip_dialog_t	*_dialog;
4162882Svi117747 	uint32_t	cseq;
4172882Svi117747 
4182882Svi117747 	if (error != NULL)
4192882Svi117747 		*error = 0;
4202882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
4212882Svi117747 		if (error != NULL)
4222882Svi117747 			*error = EINVAL;
4232882Svi117747 		return (0);
4242882Svi117747 	}
4252882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
4262882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
4272882Svi117747 	cseq = _dialog->sip_dlg_local_cseq;
4282882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
4292882Svi117747 	return (cseq);
4302882Svi117747 }
4312882Svi117747 
4322882Svi117747 /*
4332882Svi117747  * Return the dialog remote cseq
4342882Svi117747  */
4352882Svi117747 uint32_t
4362882Svi117747 sip_get_dialog_remote_cseq(sip_dialog_t dialog, int *error)
4372882Svi117747 {
4382882Svi117747 	_sip_dialog_t	*_dialog;
4392882Svi117747 	uint32_t	cseq;
4402882Svi117747 
4412882Svi117747 	if (error != NULL)
4422882Svi117747 		*error = 0;
4432882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
4442882Svi117747 		if (error != NULL)
4452882Svi117747 			*error = EINVAL;
4462882Svi117747 		return (0);
4472882Svi117747 	}
4482882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
4492882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
4502882Svi117747 	cseq = _dialog->sip_dlg_remote_cseq;
4512882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
4522882Svi117747 	return (cseq);
4532882Svi117747 }
4542882Svi117747 
4552882Svi117747 /*
4562882Svi117747  * Return the dialog type
4572882Svi117747  */
4582882Svi117747 int
4592882Svi117747 sip_get_dialog_type(sip_dialog_t dialog, int *error)
4602882Svi117747 {
4612882Svi117747 	_sip_dialog_t	*_dialog;
4622882Svi117747 	int		type;
4632882Svi117747 
4642882Svi117747 	if (error != NULL)
4652882Svi117747 		*error = 0;
4662882Svi117747 	if (!sip_manage_dialog || dialog == NULL) {
4672882Svi117747 		if (error != NULL)
4682882Svi117747 			*error = EINVAL;
4692882Svi117747 		return (-1);
4702882Svi117747 	}
4712882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
4722882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
4732882Svi117747 	type = _dialog->sip_dlg_type;
4742882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
4752882Svi117747 	return (type);
4762882Svi117747 }
4772882Svi117747 
4782882Svi117747 
4792882Svi117747 /*
4802882Svi117747  * Partial dialog ?
4812882Svi117747  */
4822882Svi117747 boolean_t
4832882Svi117747 sip_incomplete_dialog(sip_dialog_t dialog)
4842882Svi117747 {
4852882Svi117747 	_sip_dialog_t	*_dialog;
4862882Svi117747 	boolean_t	isnew;
4872882Svi117747 
4882882Svi117747 	if (!sip_manage_dialog || dialog == NULL)
4892882Svi117747 		return (B_FALSE);
4902882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
4912882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
4922882Svi117747 	isnew = _dialog->sip_dlg_state == SIP_DLG_NEW;
4932882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
4942882Svi117747 	return (isnew);
4952882Svi117747 }
4962882Svi117747 
4972882Svi117747 /*
4982882Svi117747  * Hold dialog
4992882Svi117747  */
5002882Svi117747 void
5012882Svi117747 sip_hold_dialog(sip_dialog_t dialog)
5022882Svi117747 {
5032882Svi117747 	_sip_dialog_t	*_dialog;
5042882Svi117747 
5052882Svi117747 	if (!sip_manage_dialog || dialog == NULL)
5062882Svi117747 		return;
5072882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
5082882Svi117747 	(void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
5092882Svi117747 	SIP_DLG_REFCNT_INCR(_dialog);
5102882Svi117747 	(void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
5112882Svi117747 }
5122882Svi117747 
5132882Svi117747 /*
5142882Svi117747  * Release dialog
5152882Svi117747  */
5162882Svi117747 void
5172882Svi117747 sip_release_dialog(sip_dialog_t dialog)
5182882Svi117747 {
5192882Svi117747 	_sip_dialog_t	*_dialog;
5202882Svi117747 
5212882Svi117747 	if (!sip_manage_dialog || dialog == NULL)
5222882Svi117747 		return;
5232882Svi117747 	_dialog = (_sip_dialog_t *)dialog;
5242882Svi117747 	SIP_DLG_REFCNT_DECR(_dialog);
5252882Svi117747 }
5262882Svi117747 
5272882Svi117747 /*
5282882Svi117747  * Delete a dialog
5292882Svi117747  */
5302882Svi117747 void
5312882Svi117747 sip_delete_dialog(sip_dialog_t dialog)
5322882Svi117747 {
5332882Svi117747 	if (!sip_manage_dialog || dialog == NULL)
5342882Svi117747 		return;
5352882Svi117747 	sip_dialog_terminate(dialog, NULL);
5362882Svi117747 }
537