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 /*
23*5842Sgm209912 * Copyright 2008 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
sip_create_dialog_req(sip_method_t method,sip_dialog_t dialog,char * transport,char * sent_by,int sent_by_port,char * via_param,uint32_t maxforward,int cseq)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 }
794702Sgm209912 if (sip_copy_header(sip_msg, _dialog->sip_dlg_local_contact, NULL) != 0)
804702Sgm209912 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 /*
1225092Sgm209912 * Create a request using the state maintained in the dialog. The request will
1235092Sgm209912 * not have Contact header.
1245092Sgm209912 */
1255092Sgm209912 sip_msg_t
sip_create_dialog_req_nocontact(sip_method_t method,sip_dialog_t dialog,char * transport,char * sent_by,int sent_by_port,char * via_param,uint32_t maxforward,int cseq)1265092Sgm209912 sip_create_dialog_req_nocontact(sip_method_t method, sip_dialog_t dialog,
1275092Sgm209912 char *transport, char *sent_by, int sent_by_port, char *via_param,
1285092Sgm209912 uint32_t maxforward, int cseq)
1295092Sgm209912 {
1305092Sgm209912 sip_msg_t sip_msg;
1315092Sgm209912
1325092Sgm209912 sip_msg = sip_create_dialog_req(method, dialog, transport, sent_by,
1335092Sgm209912 sent_by_port, via_param, maxforward, cseq);
1345092Sgm209912 if (sip_msg != NULL) {
1355092Sgm209912 if (sip_delete_header_by_name(sip_msg, SIP_CONTACT) != 0) {
1365092Sgm209912 sip_free_msg(sip_msg);
1375092Sgm209912 return (NULL);
1385092Sgm209912 }
1395092Sgm209912 }
1405092Sgm209912
1415092Sgm209912 return (sip_msg);
1425092Sgm209912 }
1435092Sgm209912
1445092Sgm209912 /*
1452882Svi117747 * Get the Dialog method
1462882Svi117747 */
1472882Svi117747 int
sip_get_dialog_method(sip_dialog_t dialog,int * error)1482882Svi117747 sip_get_dialog_method(sip_dialog_t dialog, int *error)
1492882Svi117747 {
1502882Svi117747 _sip_dialog_t *_dialog;
1512882Svi117747
1522882Svi117747 if (error != NULL)
1532882Svi117747 *error = 0;
1542882Svi117747 if (!sip_manage_dialog) {
1552882Svi117747 if (error != NULL)
1562882Svi117747 *error = EINVAL;
1572882Svi117747 return (0);
1582882Svi117747 }
1592882Svi117747 if (dialog == NULL) {
1602882Svi117747 if (error != NULL)
1612882Svi117747 *error = EINVAL;
1622882Svi117747 return (0);
1632882Svi117747 }
1642882Svi117747 _dialog = (_sip_dialog_t *)dialog;
1652882Svi117747 return (_dialog->sip_dlg_method);
1662882Svi117747 }
1672882Svi117747
1682882Svi117747 /*
1692882Svi117747 * Get the Dialog state
1702882Svi117747 */
1712882Svi117747 int
sip_get_dialog_state(sip_dialog_t dialog,int * error)1722882Svi117747 sip_get_dialog_state(sip_dialog_t dialog, int *error)
1732882Svi117747 {
1742882Svi117747 _sip_dialog_t *_dialog;
1752882Svi117747
1762882Svi117747 if (error != NULL)
1772882Svi117747 *error = 0;
1782882Svi117747 if (!sip_manage_dialog) {
1792882Svi117747 if (error != NULL)
1802882Svi117747 *error = EINVAL;
1812882Svi117747 return (0);
1822882Svi117747 }
1832882Svi117747 if (dialog == NULL) {
1842882Svi117747 if (error != NULL)
1852882Svi117747 *error = EINVAL;
1862882Svi117747 return (0);
1872882Svi117747 }
1882882Svi117747 _dialog = (_sip_dialog_t *)dialog;
1892882Svi117747 return (_dialog->sip_dlg_state);
1902882Svi117747 }
1912882Svi117747
1922882Svi117747 /*
1932882Svi117747 * Return the dialog callid
1942882Svi117747 */
1952882Svi117747 const sip_str_t *
sip_get_dialog_callid(sip_dialog_t dialog,int * error)1962882Svi117747 sip_get_dialog_callid(sip_dialog_t dialog, int *error)
1972882Svi117747 {
1982882Svi117747 _sip_dialog_t *_dialog;
1992882Svi117747 const struct sip_value *val;
2002882Svi117747 const sip_str_t *callid = NULL;
2012882Svi117747
2022882Svi117747 if (error != NULL)
2032882Svi117747 *error = 0;
2042882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
2052882Svi117747 if (error != NULL)
2062882Svi117747 *error = EINVAL;
2072882Svi117747 return (NULL);
2082882Svi117747 }
2092882Svi117747 _dialog = (_sip_dialog_t *)dialog;
2102882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
2112882Svi117747 if (dialog->sip_dlg_call_id != NULL) {
2122882Svi117747 val = sip_get_header_value(_dialog->sip_dlg_call_id, error);
2132882Svi117747 if (val == NULL) {
2142882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2152882Svi117747 return (NULL);
2162882Svi117747 }
2172882Svi117747 callid = &((sip_hdr_value_t *)val)->str_val;
2182882Svi117747 }
2192882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2202882Svi117747 return (callid);
2212882Svi117747 }
2222882Svi117747
2232882Svi117747 /*
2242882Svi117747 * Return the dialog localtag.
2252882Svi117747 */
2262882Svi117747 const sip_str_t *
sip_get_dialog_local_tag(sip_dialog_t dialog,int * error)2272882Svi117747 sip_get_dialog_local_tag(sip_dialog_t dialog, int *error)
2282882Svi117747 {
2292882Svi117747 _sip_dialog_t *_dialog;
2302882Svi117747 const sip_str_t *ltag = NULL;
2312882Svi117747 const struct sip_value *val;
2322882Svi117747
2332882Svi117747 if (error != NULL)
2342882Svi117747 *error = 0;
2352882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
2362882Svi117747 if (error != NULL)
2372882Svi117747 *error = EINVAL;
2382882Svi117747 return (NULL);
2392882Svi117747 }
2402882Svi117747 _dialog = (_sip_dialog_t *)dialog;
2412882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
2422882Svi117747 if (dialog->sip_dlg_local_uri_tag != NULL) {
2432882Svi117747 val = sip_get_header_value(_dialog->sip_dlg_local_uri_tag,
2442882Svi117747 error);
2452882Svi117747 if (val == NULL) {
2462882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2472882Svi117747 return (NULL);
2482882Svi117747 }
2492882Svi117747 ltag = sip_get_param_value((sip_header_value_t)val, "tag",
2502882Svi117747 error);
2512882Svi117747 }
2522882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2532882Svi117747 return (ltag);
2542882Svi117747 }
2552882Svi117747
2562882Svi117747 /*
2572882Svi117747 * Return the dialog remotetag
2582882Svi117747 */
2592882Svi117747 const sip_str_t *
sip_get_dialog_remote_tag(sip_dialog_t dialog,int * error)2602882Svi117747 sip_get_dialog_remote_tag(sip_dialog_t dialog, int *error)
2612882Svi117747 {
2622882Svi117747 _sip_dialog_t *_dialog;
2632882Svi117747 const sip_str_t *ttag = NULL;
2642882Svi117747 const struct sip_value *val;
2652882Svi117747
2662882Svi117747 if (error != NULL)
2672882Svi117747 *error = 0;
2682882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
2692882Svi117747 if (error != NULL)
2702882Svi117747 *error = EINVAL;
2712882Svi117747 return (NULL);
2722882Svi117747 }
2732882Svi117747 _dialog = (_sip_dialog_t *)dialog;
2742882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
2752882Svi117747 if (dialog->sip_dlg_remote_uri_tag != NULL) {
2762882Svi117747 val = sip_get_header_value(_dialog->sip_dlg_remote_uri_tag,
2772882Svi117747 error);
2782882Svi117747 if (val == NULL) {
2792882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2802882Svi117747 return (NULL);
2812882Svi117747 }
2822882Svi117747 ttag = sip_get_param_value((sip_header_value_t)val, "tag",
2832882Svi117747 error);
2842882Svi117747 }
2852882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
2862882Svi117747
2872882Svi117747 return (ttag);
2882882Svi117747 }
2892882Svi117747
2902882Svi117747 /*
2912882Svi117747 * Return the dialog localuri.
2922882Svi117747 */
2932882Svi117747 const struct sip_uri *
sip_get_dialog_local_uri(sip_dialog_t dialog,int * error)2942882Svi117747 sip_get_dialog_local_uri(sip_dialog_t dialog, int *error)
2952882Svi117747 {
2962882Svi117747 _sip_dialog_t *_dialog;
2972882Svi117747 const _sip_uri_t *luri = NULL;
2982882Svi117747 const struct sip_value *val;
2992882Svi117747
3002882Svi117747 if (error != NULL)
3012882Svi117747 *error = 0;
3022882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
3032882Svi117747 if (error != NULL)
3042882Svi117747 *error = EINVAL;
3052882Svi117747 return (NULL);
3062882Svi117747 }
3072882Svi117747 _dialog = (_sip_dialog_t *)dialog;
3082882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
3092882Svi117747 if (dialog->sip_dlg_local_uri_tag != NULL) {
3102882Svi117747 val = sip_get_header_value(_dialog->sip_dlg_local_uri_tag,
3112882Svi117747 error);
3122882Svi117747 if (val == NULL) {
3132882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
3142882Svi117747 return (NULL);
3152882Svi117747 }
3162882Svi117747 luri = val->sip_value_parse_uri;
3172882Svi117747 }
3182882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
3192882Svi117747
3202882Svi117747 return ((sip_uri_t)luri);
3212882Svi117747 }
3222882Svi117747
3232882Svi117747 /*
3242882Svi117747 * Return the dialog remoteuri.
3252882Svi117747 */
3262882Svi117747 const struct sip_uri *
sip_get_dialog_remote_uri(sip_dialog_t dialog,int * error)3272882Svi117747 sip_get_dialog_remote_uri(sip_dialog_t dialog, int *error)
3282882Svi117747 {
3292882Svi117747 _sip_dialog_t *_dialog;
3302882Svi117747 const _sip_uri_t *ruri = NULL;
3312882Svi117747 const struct sip_value *val;
3322882Svi117747
3332882Svi117747 if (error != NULL)
3342882Svi117747 *error = 0;
3352882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
3362882Svi117747 if (error != NULL)
3372882Svi117747 *error = EINVAL;
3382882Svi117747 return (NULL);
3392882Svi117747 }
3402882Svi117747 _dialog = (_sip_dialog_t *)dialog;
3412882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
3422882Svi117747 if (dialog->sip_dlg_remote_uri_tag != NULL) {
3432882Svi117747 val = sip_get_header_value(dialog->sip_dlg_remote_uri_tag,
3442882Svi117747 error);
3452882Svi117747 if (val == NULL) {
3462882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
3472882Svi117747 return (NULL);
3482882Svi117747 }
3492882Svi117747 ruri = val->sip_value_parse_uri;
3502882Svi117747 }
3512882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
3522882Svi117747 return ((sip_uri_t)ruri);
3532882Svi117747 }
3542882Svi117747
3552882Svi117747 /*
3562882Svi117747 * Return the dialog remotetarg.
3572882Svi117747 */
3582882Svi117747 const struct sip_uri *
sip_get_dialog_remote_target_uri(sip_dialog_t dialog,int * error)3592882Svi117747 sip_get_dialog_remote_target_uri(sip_dialog_t dialog, int *error)
3602882Svi117747 {
3612882Svi117747 _sip_dialog_t *_dialog;
3622882Svi117747 const struct sip_uri *rtarg = NULL;
3632882Svi117747 const struct sip_value *val;
3642882Svi117747
3652882Svi117747 if (error != NULL)
3662882Svi117747 *error = 0;
3672882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
3682882Svi117747 if (error != NULL)
3692882Svi117747 *error = EINVAL;
3702882Svi117747 return (NULL);
3712882Svi117747 }
3722882Svi117747 _dialog = (_sip_dialog_t *)dialog;
3732882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
3742882Svi117747 if (dialog->sip_dlg_remote_target != NULL) {
3752882Svi117747 val = sip_get_header_value(_dialog->sip_dlg_remote_target,
3762882Svi117747 error);
3772882Svi117747 if (val == NULL) {
3782882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
3792882Svi117747 return (NULL);
3802882Svi117747 }
3812882Svi117747 rtarg = val->sip_value_parse_uri;
3822882Svi117747 }
3832882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
3842882Svi117747
3852882Svi117747 return ((sip_uri_t)rtarg);
3862882Svi117747 }
3872882Svi117747
3882882Svi117747 /*
3895092Sgm209912 * Return the dialog local contact uri.
3905092Sgm209912 */
3915092Sgm209912 const struct sip_uri *
sip_get_dialog_local_contact_uri(sip_dialog_t dialog,int * error)3925092Sgm209912 sip_get_dialog_local_contact_uri(sip_dialog_t dialog, int *error)
3935092Sgm209912 {
3945092Sgm209912 _sip_dialog_t *_dialog;
3955092Sgm209912 const struct sip_uri *lcuri = NULL;
3965092Sgm209912 const struct sip_value *val;
3975092Sgm209912
3985092Sgm209912 if (error != NULL)
3995092Sgm209912 *error = 0;
4005092Sgm209912 if (!sip_manage_dialog || dialog == NULL) {
4015092Sgm209912 if (error != NULL)
4025092Sgm209912 *error = EINVAL;
4035092Sgm209912 return (NULL);
4045092Sgm209912 }
4055092Sgm209912 _dialog = (_sip_dialog_t *)dialog;
4065092Sgm209912 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
4075092Sgm209912 if (dialog->sip_dlg_local_contact != NULL) {
4085092Sgm209912 val = sip_get_header_value(_dialog->sip_dlg_local_contact,
4095092Sgm209912 error);
4105092Sgm209912 if (val == NULL) {
4115092Sgm209912 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
4125092Sgm209912 return (NULL);
4135092Sgm209912 }
4145092Sgm209912 lcuri = val->sip_value_parse_uri;
4155092Sgm209912 }
4165092Sgm209912 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
4175092Sgm209912
4185092Sgm209912 return ((sip_uri_t)lcuri);
4195092Sgm209912 }
4205092Sgm209912
4215092Sgm209912 /*
4222882Svi117747 * Return the dialog route set
4232882Svi117747 */
4242882Svi117747 const sip_str_t *
sip_get_dialog_route_set(sip_dialog_t dialog,int * error)4252882Svi117747 sip_get_dialog_route_set(sip_dialog_t dialog, int *error)
4262882Svi117747 {
4272882Svi117747 _sip_dialog_t *_dialog;
4282882Svi117747
4292882Svi117747 if (error != NULL)
4302882Svi117747 *error = 0;
4312882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
4322882Svi117747 if (error != NULL)
4332882Svi117747 *error = EINVAL;
4342882Svi117747 return (NULL);
4352882Svi117747 }
4362882Svi117747 _dialog = (_sip_dialog_t *)dialog;
4372882Svi117747 if (_dialog->sip_dlg_rset.sip_str_len > 0)
4382882Svi117747 return (&_dialog->sip_dlg_rset);
4392882Svi117747 return (NULL);
4402882Svi117747 }
4412882Svi117747
4422882Svi117747 /*
4432882Svi117747 * Return the dialog secure
4442882Svi117747 */
4452882Svi117747 boolean_t
sip_is_dialog_secure(sip_dialog_t dialog,int * error)4462882Svi117747 sip_is_dialog_secure(sip_dialog_t dialog, int *error)
4472882Svi117747 {
4482882Svi117747 _sip_dialog_t *_dialog;
4492882Svi117747 boolean_t issecure;
4502882Svi117747
4512882Svi117747 if (error != NULL)
4522882Svi117747 *error = 0;
4532882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
4542882Svi117747 if (error != NULL)
4552882Svi117747 *error = EINVAL;
4562882Svi117747 return (B_FALSE);
4572882Svi117747 }
4582882Svi117747 _dialog = (_sip_dialog_t *)dialog;
4592882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
4602882Svi117747 issecure = _dialog->sip_dlg_secure;
4612882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
4622882Svi117747 return (issecure);
4632882Svi117747 }
4642882Svi117747
4652882Svi117747 /*
4662882Svi117747 * Return the dialog local cseq
4672882Svi117747 */
4682882Svi117747 uint32_t
sip_get_dialog_local_cseq(sip_dialog_t dialog,int * error)4692882Svi117747 sip_get_dialog_local_cseq(sip_dialog_t dialog, int *error)
4702882Svi117747 {
4712882Svi117747 _sip_dialog_t *_dialog;
4722882Svi117747 uint32_t cseq;
4732882Svi117747
4742882Svi117747 if (error != NULL)
4752882Svi117747 *error = 0;
4762882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
4772882Svi117747 if (error != NULL)
4782882Svi117747 *error = EINVAL;
4792882Svi117747 return (0);
4802882Svi117747 }
4812882Svi117747 _dialog = (_sip_dialog_t *)dialog;
4822882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
4832882Svi117747 cseq = _dialog->sip_dlg_local_cseq;
4842882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
4852882Svi117747 return (cseq);
4862882Svi117747 }
4872882Svi117747
4882882Svi117747 /*
4892882Svi117747 * Return the dialog remote cseq
4902882Svi117747 */
4912882Svi117747 uint32_t
sip_get_dialog_remote_cseq(sip_dialog_t dialog,int * error)4922882Svi117747 sip_get_dialog_remote_cseq(sip_dialog_t dialog, int *error)
4932882Svi117747 {
4942882Svi117747 _sip_dialog_t *_dialog;
4952882Svi117747 uint32_t cseq;
4962882Svi117747
4972882Svi117747 if (error != NULL)
4982882Svi117747 *error = 0;
4992882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
5002882Svi117747 if (error != NULL)
5012882Svi117747 *error = EINVAL;
5022882Svi117747 return (0);
5032882Svi117747 }
5042882Svi117747 _dialog = (_sip_dialog_t *)dialog;
5052882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
5062882Svi117747 cseq = _dialog->sip_dlg_remote_cseq;
5072882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
5082882Svi117747 return (cseq);
5092882Svi117747 }
5102882Svi117747
5112882Svi117747 /*
5122882Svi117747 * Return the dialog type
5132882Svi117747 */
5142882Svi117747 int
sip_get_dialog_type(sip_dialog_t dialog,int * error)5152882Svi117747 sip_get_dialog_type(sip_dialog_t dialog, int *error)
5162882Svi117747 {
5172882Svi117747 _sip_dialog_t *_dialog;
5182882Svi117747 int type;
5192882Svi117747
5202882Svi117747 if (error != NULL)
5212882Svi117747 *error = 0;
5222882Svi117747 if (!sip_manage_dialog || dialog == NULL) {
5232882Svi117747 if (error != NULL)
5242882Svi117747 *error = EINVAL;
5252882Svi117747 return (-1);
5262882Svi117747 }
5272882Svi117747 _dialog = (_sip_dialog_t *)dialog;
5282882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
5292882Svi117747 type = _dialog->sip_dlg_type;
5302882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
5312882Svi117747 return (type);
5322882Svi117747 }
5332882Svi117747
534*5842Sgm209912 /*
535*5842Sgm209912 * Return the number of messages exchanged within a dialog.
536*5842Sgm209912 */
537*5842Sgm209912 int
sip_get_dialog_msgcnt(sip_dialog_t dialog,int * error)538*5842Sgm209912 sip_get_dialog_msgcnt(sip_dialog_t dialog, int *error)
539*5842Sgm209912 {
540*5842Sgm209912 _sip_dialog_t *_dialog;
541*5842Sgm209912 int nmsgs;
542*5842Sgm209912
543*5842Sgm209912 if (error != NULL)
544*5842Sgm209912 *error = 0;
545*5842Sgm209912 if (!sip_manage_dialog || dialog == NULL) {
546*5842Sgm209912 if (error != NULL)
547*5842Sgm209912 *error = EINVAL;
548*5842Sgm209912 return (-1);
549*5842Sgm209912 }
550*5842Sgm209912 _dialog = (_sip_dialog_t *)dialog;
551*5842Sgm209912 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
552*5842Sgm209912 nmsgs = _dialog->sip_dlg_msgcnt;
553*5842Sgm209912 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
554*5842Sgm209912 return (nmsgs);
555*5842Sgm209912 }
5562882Svi117747
5572882Svi117747 /*
5582882Svi117747 * Partial dialog ?
5592882Svi117747 */
5602882Svi117747 boolean_t
sip_incomplete_dialog(sip_dialog_t dialog)5612882Svi117747 sip_incomplete_dialog(sip_dialog_t dialog)
5622882Svi117747 {
5632882Svi117747 _sip_dialog_t *_dialog;
5642882Svi117747 boolean_t isnew;
5652882Svi117747
5662882Svi117747 if (!sip_manage_dialog || dialog == NULL)
5672882Svi117747 return (B_FALSE);
5682882Svi117747 _dialog = (_sip_dialog_t *)dialog;
5692882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
5702882Svi117747 isnew = _dialog->sip_dlg_state == SIP_DLG_NEW;
5712882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
5722882Svi117747 return (isnew);
5732882Svi117747 }
5742882Svi117747
5752882Svi117747 /*
5762882Svi117747 * Hold dialog
5772882Svi117747 */
5782882Svi117747 void
sip_hold_dialog(sip_dialog_t dialog)5792882Svi117747 sip_hold_dialog(sip_dialog_t dialog)
5802882Svi117747 {
5812882Svi117747 _sip_dialog_t *_dialog;
5822882Svi117747
5832882Svi117747 if (!sip_manage_dialog || dialog == NULL)
5842882Svi117747 return;
5852882Svi117747 _dialog = (_sip_dialog_t *)dialog;
5862882Svi117747 (void) pthread_mutex_lock(&_dialog->sip_dlg_mutex);
5872882Svi117747 SIP_DLG_REFCNT_INCR(_dialog);
5882882Svi117747 (void) pthread_mutex_unlock(&_dialog->sip_dlg_mutex);
5892882Svi117747 }
5902882Svi117747
5912882Svi117747 /*
5922882Svi117747 * Release dialog
5932882Svi117747 */
5942882Svi117747 void
sip_release_dialog(sip_dialog_t dialog)5952882Svi117747 sip_release_dialog(sip_dialog_t dialog)
5962882Svi117747 {
5972882Svi117747 _sip_dialog_t *_dialog;
5982882Svi117747
5992882Svi117747 if (!sip_manage_dialog || dialog == NULL)
6002882Svi117747 return;
6012882Svi117747 _dialog = (_sip_dialog_t *)dialog;
6022882Svi117747 SIP_DLG_REFCNT_DECR(_dialog);
6032882Svi117747 }
6042882Svi117747
6052882Svi117747 /*
6062882Svi117747 * Delete a dialog
6072882Svi117747 */
6082882Svi117747 void
sip_delete_dialog(sip_dialog_t dialog)6092882Svi117747 sip_delete_dialog(sip_dialog_t dialog)
6102882Svi117747 {
6112882Svi117747 if (!sip_manage_dialog || dialog == NULL)
6122882Svi117747 return;
6132882Svi117747 sip_dialog_terminate(dialog, NULL);
6142882Svi117747 }
615