2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <stdlib.h>
2N/A#include <assert.h>
2N/A#include <errno.h>
2N/A#include <pthread.h>
2N/A#include <strings.h>
2N/A
2N/A#include "sip_parse_uri.h"
2N/A#include "sip_msg.h"
2N/A#include "sip_miscdefs.h"
2N/A#include "sip_xaction.h"
2N/A#include "sip_hash.h"
2N/A
2N/A#define RFC_3261_BRANCH "z9hG4bK"
2N/A
2N/A/*
2N/A * The transaction hash table
2N/A */
2N/Asip_hash_t sip_xaction_hash[SIP_HASH_SZ];
2N/A
2N/Aint (*sip_xaction_ulp_trans_err)(sip_transaction_t, int, void *) = NULL;
2N/Avoid (*sip_xaction_ulp_state_cb)(sip_transaction_t, sip_msg_t, int, int) = NULL;
2N/A
2N/Aint sip_xaction_add(sip_xaction_t *, char *, _sip_msg_t *, sip_method_t);
2N/Astatic boolean_t sip_is_conn_obj_cache(sip_conn_object_t, void *);
2N/A
2N/A/*
2N/A * Get the md5 hash of the required fields
2N/A */
2N/Aint
2N/Asip_find_md5_digest(char *bid, _sip_msg_t *msg, uint16_t *hindex,
2N/A sip_method_t method)
2N/A{
2N/A boolean_t is_2543;
2N/A
2N/A is_2543 = (bid == NULL ||
2N/A strncmp(bid, RFC_3261_BRANCH, strlen(RFC_3261_BRANCH)) != 0);
2N/A
2N/A if (is_2543 && msg == NULL)
2N/A return (EINVAL);
2N/A if (is_2543) {
2N/A _sip_header_t *from = NULL;
2N/A _sip_header_t *cid = NULL;
2N/A _sip_header_t *via = NULL;
2N/A const sip_str_t *to_uri = NULL;
2N/A int cseq;
2N/A int error = 0;
2N/A
2N/A /*
2N/A * Since the response might contain parameters not in the
2N/A * request, just use the to URI.
2N/A */
2N/A to_uri = sip_get_to_uri_str((sip_msg_t)msg, &error);
2N/A if (to_uri == NULL || error != 0)
2N/A return (EINVAL);
2N/A cseq = sip_get_callseq_num((sip_msg_t)msg, &error);
2N/A if (cseq < 0 || error != 0)
2N/A return (EINVAL);
2N/A (void) pthread_mutex_lock(&msg->sip_msg_mutex);
2N/A via = sip_search_for_header(msg, SIP_VIA, NULL);
2N/A from = sip_search_for_header(msg, SIP_FROM, NULL);
2N/A cid = sip_search_for_header(msg, SIP_CALL_ID, NULL);
2N/A (void) pthread_mutex_unlock(&msg->sip_msg_mutex);
2N/A if (via == NULL || from == NULL || cid == NULL)
2N/A return (EINVAL);
2N/A sip_md5_hash(via->sip_hdr_start,
2N/A via->sip_hdr_end - via->sip_hdr_start,
2N/A cid->sip_hdr_start,
2N/A cid->sip_hdr_end - cid->sip_hdr_start,
2N/A from->sip_hdr_start,
2N/A from->sip_hdr_end - from->sip_hdr_start,
2N/A (char *)&cseq, sizeof (int),
2N/A (char *)&method, sizeof (sip_method_t),
2N/A to_uri->sip_str_ptr, to_uri->sip_str_len,
2N/A (uchar_t *)hindex);
2N/A } else {
2N/A sip_md5_hash(bid, strlen(bid), (char *)&method,
2N/A sizeof (sip_method_t), NULL, 0, NULL, 0, NULL, 0, NULL, 0,
2N/A (uchar_t *)hindex);
2N/A }
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Add object to the connection cache object. Not checking for duplicates!!
2N/A */
2N/Aint
2N/Asip_add_conn_obj_cache(sip_conn_object_t obj, void *cobj)
2N/A{
2N/A void **obj_val;
2N/A sip_conn_obj_pvt_t *pvt_data;
2N/A sip_conn_cache_t *xaction_list;
2N/A sip_xaction_t *sip_trans = (sip_xaction_t *)cobj;
2N/A
2N/A /*
2N/A * Is already cached
2N/A */
2N/A if (sip_trans->sip_xaction_conn_obj != NULL) {
2N/A if (sip_is_conn_obj_cache(sip_trans->sip_xaction_conn_obj,
2N/A (void *)sip_trans)) {
2N/A return (0);
2N/A }
2N/A /*
2N/A * Transaction has cached a different conn_obj, release it
2N/A */
2N/A sip_del_conn_obj_cache(sip_trans->sip_xaction_conn_obj,
2N/A (void *)sip_trans);
2N/A }
2N/A
2N/A xaction_list = malloc(sizeof (sip_conn_cache_t));
2N/A if (xaction_list == NULL)
2N/A return (ENOMEM);
2N/A xaction_list->obj = cobj;
2N/A xaction_list->next = xaction_list->prev = NULL;
2N/A
2N/A obj_val = (void *)obj;
2N/A pvt_data = (sip_conn_obj_pvt_t *)*obj_val;
2N/A if (pvt_data == NULL) {
2N/A free(xaction_list);
2N/A return (EINVAL);
2N/A }
2N/A (void) pthread_mutex_lock(&pvt_data->sip_conn_obj_cache_lock);
2N/A
2N/A if (pvt_data->sip_conn_obj_cache == NULL) {
2N/A pvt_data->sip_conn_obj_cache = xaction_list;
2N/A } else {
2N/A xaction_list->next = pvt_data->sip_conn_obj_cache;
2N/A pvt_data->sip_conn_obj_cache->prev = xaction_list;
2N/A pvt_data->sip_conn_obj_cache = xaction_list;
2N/A }
2N/A sip_refhold_conn(obj);
2N/A sip_trans->sip_xaction_conn_obj = obj;
2N/A (void) pthread_mutex_unlock(&pvt_data->sip_conn_obj_cache_lock);
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Walk thru the list of transactions that have cached this obj and
2N/A * and return true if 'cobj' is one of them.
2N/A */
2N/Astatic boolean_t
2N/Asip_is_conn_obj_cache(sip_conn_object_t obj, void *cobj)
2N/A{
2N/A void **obj_val;
2N/A sip_conn_obj_pvt_t *pvt_data;
2N/A sip_conn_cache_t *xaction_list;
2N/A sip_xaction_t *trans;
2N/A sip_xaction_t *ctrans = (sip_xaction_t *)cobj;
2N/A
2N/A obj_val = (void *)obj;
2N/A pvt_data = (sip_conn_obj_pvt_t *)*obj_val;
2N/A if (pvt_data == NULL)
2N/A return (B_FALSE);
2N/A (void) pthread_mutex_lock(&pvt_data->sip_conn_obj_cache_lock);
2N/A xaction_list = pvt_data->sip_conn_obj_cache;
2N/A while (xaction_list != NULL) {
2N/A trans = (sip_xaction_t *)xaction_list->obj;
2N/A if (ctrans != trans) {
2N/A xaction_list = xaction_list->next;
2N/A continue;
2N/A }
2N/A (void) pthread_mutex_unlock(&pvt_data->sip_conn_obj_cache_lock);
2N/A return (B_TRUE);
2N/A }
2N/A (void) pthread_mutex_unlock(&pvt_data->sip_conn_obj_cache_lock);
2N/A return (B_FALSE);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Walk thru the list of transactions that have cached this obj and
2N/A * refrele the objs.
2N/A */
2N/Avoid
2N/Asip_del_conn_obj_cache(sip_conn_object_t obj, void *cobj)
2N/A{
2N/A void **obj_val;
2N/A sip_conn_obj_pvt_t *pvt_data;
2N/A sip_conn_cache_t *xaction_list;
2N/A sip_conn_cache_t *tmp_list;
2N/A sip_xaction_t *trans;
2N/A sip_xaction_t *ctrans = NULL;
2N/A
2N/A if (cobj != NULL)
2N/A ctrans = (sip_xaction_t *)cobj;
2N/A
2N/A obj_val = (void *)obj;
2N/A pvt_data = (sip_conn_obj_pvt_t *)*obj_val;
2N/A if (pvt_data == NULL) { /* ASSERT FALSE if ctrans != NULL?? */
2N/A if (ctrans != NULL) {
2N/A sip_refrele_conn(obj);
2N/A ctrans->sip_xaction_conn_obj = NULL;
2N/A }
2N/A return;
2N/A }
2N/A (void) pthread_mutex_lock(&pvt_data->sip_conn_obj_cache_lock);
2N/A xaction_list = pvt_data->sip_conn_obj_cache;
2N/A while (xaction_list != NULL) {
2N/A tmp_list = xaction_list;
2N/A trans = (sip_xaction_t *)xaction_list->obj;
2N/A assert(trans != NULL);
2N/A if (ctrans != NULL && ctrans != trans) {
2N/A xaction_list = xaction_list->next;
2N/A continue;
2N/A }
2N/A if (ctrans == NULL)
2N/A (void) pthread_mutex_lock(&trans->sip_xaction_mutex);
2N/A assert(trans->sip_xaction_conn_obj == obj);
2N/A sip_refrele_conn(obj);
2N/A trans->sip_xaction_conn_obj = NULL;
2N/A if (ctrans == NULL)
2N/A (void) pthread_mutex_unlock(&trans->sip_xaction_mutex);
2N/A xaction_list = xaction_list->next;
2N/A
2N/A /*
2N/A * Take the obj out of the list
2N/A */
2N/A if (tmp_list == pvt_data->sip_conn_obj_cache) {
2N/A if (xaction_list == NULL) {
2N/A pvt_data->sip_conn_obj_cache = NULL;
2N/A } else {
2N/A xaction_list->prev = NULL;
2N/A pvt_data->sip_conn_obj_cache = xaction_list;
2N/A }
2N/A } else if (xaction_list == NULL) {
2N/A assert(tmp_list->prev != NULL);
2N/A tmp_list->prev->next = NULL;
2N/A } else {
2N/A assert(tmp_list->prev != NULL);
2N/A tmp_list->prev->next = xaction_list;
2N/A xaction_list->prev = tmp_list->prev;
2N/A }
2N/A tmp_list->prev = NULL;
2N/A tmp_list->next = NULL;
2N/A tmp_list->obj = NULL;
2N/A
2N/A free(tmp_list);
2N/A }
2N/A (void) pthread_mutex_unlock(&pvt_data->sip_conn_obj_cache_lock);
2N/A}
2N/A
2N/A/*
2N/A * Check for a transaction match. Passed to sip_hash_find().
2N/A */
2N/Aboolean_t
2N/Asip_xaction_match(void *obj, void *hindex)
2N/A{
2N/A sip_xaction_t *tmp = (sip_xaction_t *)obj;
2N/A
2N/A tmp = (sip_xaction_t *)obj;
2N/A
2N/A if (SIP_IS_XACTION_TERMINATED(tmp->sip_xaction_state))
2N/A return (B_FALSE);
2N/A if (bcmp(tmp->sip_xaction_hash_digest, hindex,
2N/A sizeof (tmp->sip_xaction_hash_digest)) == 0) {
2N/A SIP_XACTION_REFCNT_INCR(tmp);
2N/A return (B_TRUE);
2N/A }
2N/A return (B_FALSE);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Find a transaction
2N/A */
2N/Astatic sip_xaction_t *
2N/Asip_xaction_find(char *branchid, _sip_msg_t *msg, int which)
2N/A{
2N/A sip_xaction_t *tmp;
2N/A uint16_t hash_index[8];
2N/A int hindex;
2N/A sip_method_t method;
2N/A int error;
2N/A sip_message_type_t *sip_msg_info;
2N/A
2N/A sip_msg_info = msg->sip_msg_req_res;
2N/A method = sip_get_callseq_method((sip_msg_t)msg, &error);
2N/A if (error != 0)
2N/A return (NULL);
2N/A
2N/A /*
2N/A * If we are getting a ACK/CANCEL we need to match with the
2N/A * corresponding INVITE, if any.
2N/A */
2N/A if (sip_msg_info->is_request && which == SIP_SERVER_TRANSACTION &&
2N/A (method == ACK || method == CANCEL)) {
2N/A method = INVITE;
2N/A }
2N/A if (sip_find_md5_digest(branchid, msg, hash_index, method) != 0)
2N/A return (NULL);
2N/A hindex = SIP_DIGEST_TO_HASH(hash_index);
2N/A tmp = (sip_xaction_t *)sip_hash_find(sip_xaction_hash,
2N/A (void *)hash_index, hindex, sip_xaction_match);
2N/A return (tmp);
2N/A}
2N/A
2N/A/*
2N/A * create a transaction.
2N/A */
2N/Astatic sip_xaction_t *
2N/Asip_xaction_create(sip_conn_object_t obj, _sip_msg_t *msg, char *branchid,
2N/A int *error)
2N/A{
2N/A sip_xaction_t *trans;
2N/A sip_message_type_t *sip_msg_info;
2N/A int state = 0;
2N/A int prev_state = 0;
2N/A sip_method_t method;
2N/A int ret;
2N/A int timer1 = sip_timer_T1;
2N/A int timer4 = sip_timer_T4;
2N/A int timerd = sip_timer_TD;
2N/A
2N/A if (error != NULL)
2N/A *error = 0;
2N/A /*
2N/A * Make sure we are not creating a transaction for
2N/A * an ACK request.
2N/A */
2N/A trans = (sip_xaction_t *)malloc(sizeof (sip_xaction_t));
2N/A if (trans == NULL) {
2N/A if (error != NULL)
2N/A *error = ENOMEM;
2N/A return (NULL);
2N/A }
2N/A bzero(trans, sizeof (sip_xaction_t));
2N/A if (branchid == NULL) {
2N/A trans->sip_xaction_branch_id = (char *)sip_branchid(NULL);
2N/A if (trans->sip_xaction_branch_id == NULL) {
2N/A free(trans);
2N/A if (error != NULL)
2N/A *error = ENOMEM;
2N/A return (NULL);
2N/A }
2N/A } else {
2N/A trans->sip_xaction_branch_id = (char *)malloc(strlen(branchid)
2N/A + 1);
2N/A if (trans->sip_xaction_branch_id == NULL) {
2N/A free(trans);
2N/A if (error != NULL)
2N/A *error = ENOMEM;
2N/A return (NULL);
2N/A }
2N/A (void) strncpy(trans->sip_xaction_branch_id, branchid,
2N/A strlen(branchid));
2N/A trans->sip_xaction_branch_id[strlen(branchid)] = '\0';
2N/A }
2N/A (void) pthread_mutex_init(&trans->sip_xaction_mutex, NULL);
2N/A SIP_MSG_REFCNT_INCR(msg);
2N/A trans->sip_xaction_orig_msg = msg;
2N/A assert(msg->sip_msg_req_res != NULL);
2N/A sip_msg_info = msg->sip_msg_req_res;
2N/A if (sip_msg_info->is_request) {
2N/A method = sip_msg_info->sip_req_method;
2N/A } else {
2N/A method = sip_get_callseq_method((sip_msg_t)msg, &ret);
2N/A if (ret != 0) {
2N/A free(trans->sip_xaction_branch_id);
2N/A free(trans);
2N/A if (error != NULL)
2N/A *error = ret;
2N/A return (NULL);
2N/A }
2N/A if (method == INVITE)
2N/A state = SIP_SRV_INV_PROCEEDING;
2N/A else
2N/A state = SIP_SRV_TRYING;
2N/A }
2N/A trans->sip_xaction_method = method;
2N/A trans->sip_xaction_state = state;
2N/A
2N/A /*
2N/A * Get connection object specific timeouts, if present
2N/A */
2N/A if (sip_conn_timer1 != NULL)
2N/A timer1 = sip_conn_timer1(obj);
2N/A if (sip_conn_timer4 != NULL)
2N/A timer4 = sip_conn_timer4(obj);
2N/A if (sip_conn_timerd != NULL)
2N/A timerd = sip_conn_timerd(obj);
2N/A
2N/A SIP_INIT_TIMER(trans->sip_xaction_TA, 2 * timer1);
2N/A SIP_INIT_TIMER(trans->sip_xaction_TB, 64 * timer1)
2N/A SIP_INIT_TIMER(trans->sip_xaction_TD, timerd);
2N/A SIP_INIT_TIMER(trans->sip_xaction_TE, timer1);
2N/A SIP_INIT_TIMER(trans->sip_xaction_TF, 64 * timer1);
2N/A SIP_INIT_TIMER(trans->sip_xaction_TG, 2 * timer1);
2N/A SIP_INIT_TIMER(trans->sip_xaction_TH, 64 * timer1);
2N/A SIP_INIT_TIMER(trans->sip_xaction_TI, timer4);
2N/A SIP_INIT_TIMER(trans->sip_xaction_TJ, 64 * timer1);
2N/A SIP_INIT_TIMER(trans->sip_xaction_TK, timer4);
2N/A
2N/A if ((ret = sip_xaction_add(trans, branchid, msg, method)) != 0) {
2N/A (void) pthread_mutex_destroy(&trans->sip_xaction_mutex);
2N/A free(trans->sip_xaction_branch_id);
2N/A free(trans);
2N/A if (error != NULL)
2N/A *error = ret;
2N/A return (NULL);
2N/A }
2N/A if (sip_xaction_ulp_state_cb != NULL &&
2N/A prev_state != trans->sip_xaction_state) {
2N/A sip_xaction_ulp_state_cb((sip_transaction_t)trans,
2N/A (sip_msg_t)msg, prev_state, trans->sip_xaction_state);
2N/A }
2N/A return (trans);
2N/A}
2N/A
2N/A/*
2N/A * Find a transaction, create if asked for
2N/A */
2N/Asip_xaction_t *
2N/Asip_xaction_get(sip_conn_object_t obj, sip_msg_t msg, boolean_t create,
2N/A int which, int *error)
2N/A{
2N/A char *branchid;
2N/A sip_xaction_t *sip_trans;
2N/A _sip_msg_t *_msg;
2N/A sip_message_type_t *sip_msg_info;
2N/A
2N/A if (error != NULL)
2N/A *error = 0;
2N/A
2N/A _msg = (_sip_msg_t *)msg;
2N/A sip_msg_info = ((_sip_msg_t *)msg)->sip_msg_req_res;
2N/A
2N/A branchid = sip_get_branchid(msg, NULL);
2N/A sip_trans = sip_xaction_find(branchid, _msg, which);
2N/A if (sip_trans == NULL && create) {
2N/A /*
2N/A * If we are sending a request, must be conformant to RFC 3261.
2N/A */
2N/A if (sip_msg_info->is_request &&
2N/A (branchid == NULL || strncmp(branchid,
2N/A RFC_3261_BRANCH, strlen(RFC_3261_BRANCH) != 0))) {
2N/A if (error != NULL)
2N/A *error = EINVAL;
2N/A if (branchid != NULL)
2N/A free(branchid);
2N/A return (NULL);
2N/A }
2N/A sip_trans = sip_xaction_create(obj, _msg, branchid, error);
2N/A if (sip_trans != NULL)
2N/A SIP_XACTION_REFCNT_INCR(sip_trans);
2N/A }
2N/A if (branchid != NULL)
2N/A free(branchid);
2N/A return (sip_trans);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Delete a transaction if the reference count is 0. Passed to
2N/A * sip_hash_delete().
2N/A */
2N/Aboolean_t
2N/Asip_xaction_remove(void *obj, void *hindex, int *found)
2N/A{
2N/A sip_xaction_t *tmp = (sip_xaction_t *)obj;
2N/A int count = 0;
2N/A sip_msg_chain_t *msg_chain;
2N/A sip_msg_chain_t *nmsg_chain;
2N/A
2N/A *found = 0;
2N/A tmp = (sip_xaction_t *)obj;
2N/A (void) pthread_mutex_lock(&tmp->sip_xaction_mutex);
2N/A if (bcmp(tmp->sip_xaction_hash_digest, hindex,
2N/A sizeof (tmp->sip_xaction_hash_digest)) == 0) {
2N/A *found = 1;
2N/A if (tmp->sip_xaction_ref_cnt != 0) {
2N/A (void) pthread_mutex_unlock(&tmp->sip_xaction_mutex);
2N/A return (B_FALSE);
2N/A }
2N/A (void) pthread_mutex_destroy(&tmp->sip_xaction_mutex);
2N/A SIP_CANCEL_TIMER(tmp->sip_xaction_TA);
2N/A SIP_CANCEL_TIMER(tmp->sip_xaction_TB);
2N/A SIP_CANCEL_TIMER(tmp->sip_xaction_TD);
2N/A SIP_CANCEL_TIMER(tmp->sip_xaction_TE);
2N/A SIP_CANCEL_TIMER(tmp->sip_xaction_TF);
2N/A SIP_CANCEL_TIMER(tmp->sip_xaction_TG);
2N/A SIP_CANCEL_TIMER(tmp->sip_xaction_TH);
2N/A SIP_CANCEL_TIMER(tmp->sip_xaction_TI);
2N/A SIP_CANCEL_TIMER(tmp->sip_xaction_TJ);
2N/A SIP_CANCEL_TIMER(tmp->sip_xaction_TK);
2N/A sip_write_to_log((void *)tmp, SIP_TRANSACTION_LOG, NULL, 0);
2N/A free(tmp->sip_xaction_branch_id);
2N/A if (tmp->sip_xaction_last_msg != NULL) {
2N/A SIP_MSG_REFCNT_DECR(tmp->sip_xaction_last_msg);
2N/A tmp->sip_xaction_last_msg = NULL;
2N/A }
2N/A if (tmp->sip_xaction_orig_msg != NULL) {
2N/A SIP_MSG_REFCNT_DECR(tmp->sip_xaction_orig_msg);
2N/A tmp->sip_xaction_orig_msg = NULL;
2N/A }
2N/A if (tmp->sip_xaction_conn_obj != NULL) {
2N/A sip_del_conn_obj_cache(tmp->sip_xaction_conn_obj,
2N/A (void *)tmp);
2N/A }
2N/A /*
2N/A * If the transaction logging is disabled before we could
2N/A * write the captured messages into the transaction log, then
2N/A * we need to free those captured messsages
2N/A */
2N/A for (count = 0; count <= SIP_SRV_NONINV_TERMINATED; count++) {
2N/A msg_chain = tmp->sip_xaction_log[count].sip_msgs;
2N/A while (msg_chain != NULL) {
2N/A nmsg_chain = msg_chain->next;
2N/A if (msg_chain->sip_msg != NULL)
2N/A free(msg_chain->sip_msg);
2N/A free(msg_chain);
2N/A msg_chain = nmsg_chain;
2N/A }
2N/A }
2N/A free(tmp);
2N/A return (B_TRUE);
2N/A }
2N/A (void) pthread_mutex_unlock(&tmp->sip_xaction_mutex);
2N/A return (B_FALSE);
2N/A}
2N/A
2N/A/*
2N/A * Delete a SIP transaction
2N/A */
2N/Avoid
2N/Asip_xaction_delete(sip_xaction_t *trans)
2N/A{
2N/A int hindex;
2N/A
2N/A (void) pthread_mutex_lock(&trans->sip_xaction_mutex);
2N/A hindex = SIP_DIGEST_TO_HASH(trans->sip_xaction_hash_digest);
2N/A if (trans->sip_xaction_ref_cnt != 0) {
2N/A (void) pthread_mutex_unlock(&trans->sip_xaction_mutex);
2N/A return;
2N/A }
2N/A (void) pthread_mutex_unlock(&trans->sip_xaction_mutex);
2N/A sip_hash_delete(sip_xaction_hash, trans->sip_xaction_hash_digest,
2N/A hindex, sip_xaction_remove);
2N/A}
2N/A
2N/A/*
2N/A * Add a SIP transaction into the hash list.
2N/A */
2N/Aint
2N/Asip_xaction_add(sip_xaction_t *trans, char *branchid, _sip_msg_t *msg,
2N/A sip_method_t method)
2N/A{
2N/A uint16_t hash_index[8];
2N/A
2N/A if (sip_find_md5_digest(branchid, msg, hash_index, method) != 0)
2N/A return (EINVAL);
2N/A
2N/A /*
2N/A * trans is not in the list as yet, so no need to hold the lock
2N/A */
2N/A bcopy(hash_index, trans->sip_xaction_hash_digest, sizeof (hash_index));
2N/A
2N/A if (sip_hash_add(sip_xaction_hash, (void *)trans,
2N/A SIP_DIGEST_TO_HASH(hash_index)) != 0) {
2N/A return (ENOMEM);
2N/A }
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Given a state, return the string - This is mostly for debug purposes
2N/A */
2N/Achar *
2N/Asip_get_xaction_state(int state)
2N/A{
2N/A switch (state) {
2N/A case SIP_NEW_TRANSACTION:
2N/A return ("SIP_NEW_TRANSACTION");
2N/A case SIP_CLNT_CALLING:
2N/A return ("SIP_CLNT_CALLING");
2N/A case SIP_CLNT_INV_PROCEEDING:
2N/A return ("SIP_CLNT_INV_PROCEEDING");
2N/A case SIP_CLNT_INV_TERMINATED:
2N/A return ("SIP_CLNT_INV_TERMINATED");
2N/A case SIP_CLNT_INV_COMPLETED:
2N/A return ("SIP_CLNT_INV_COMPLETED");
2N/A case SIP_CLNT_TRYING:
2N/A return ("SIP_CLNT_TRYING");
2N/A case SIP_CLNT_NONINV_PROCEEDING:
2N/A return ("SIP_CLNT_NONINV_PROCEEDING");
2N/A case SIP_CLNT_NONINV_TERMINATED:
2N/A return ("SIP_CLNT_NONINV_TERMINATED");
2N/A case SIP_CLNT_NONINV_COMPLETED:
2N/A return ("SIP_CLNT_NONINV_COMPLETED");
2N/A case SIP_SRV_INV_PROCEEDING:
2N/A return ("SIP_SRV_INV_PROCEEDING");
2N/A case SIP_SRV_INV_COMPLETED:
2N/A return ("SIP_SRV_INV_COMPLETED");
2N/A case SIP_SRV_CONFIRMED:
2N/A return ("SIP_SRV_CONFIRMED");
2N/A case SIP_SRV_INV_TERMINATED:
2N/A return ("SIP_SRV_INV_TERMINATED");
2N/A case SIP_SRV_TRYING:
2N/A return ("SIP_SRV_TRYING");
2N/A case SIP_SRV_NONINV_PROCEEDING:
2N/A return ("SIP_SRV_NONINV_PROCEEDING");
2N/A case SIP_SRV_NONINV_COMPLETED:
2N/A return ("SIP_SRV_NONINV_COMPLETED");
2N/A case SIP_SRV_NONINV_TERMINATED:
2N/A return ("SIP_SRV_NONINV_TERMINATED");
2N/A default :
2N/A return ("UNKNOWN");
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * Initialize the hash table etc.
2N/A */
2N/Avoid
2N/Asip_xaction_init(int (*ulp_trans_err)(sip_transaction_t, int, void *),
2N/A void (*ulp_state_cb)(sip_transaction_t, sip_msg_t, int, int))
2N/A{
2N/A int cnt;
2N/A
2N/A for (cnt = 0; cnt < SIP_HASH_SZ; cnt++) {
2N/A sip_xaction_hash[cnt].hash_count = 0;
2N/A sip_xaction_hash[cnt].hash_head = NULL;
2N/A sip_xaction_hash[cnt].hash_tail = NULL;
2N/A (void) pthread_mutex_init(
2N/A &sip_xaction_hash[cnt].sip_hash_mutex, NULL);
2N/A }
2N/A if (ulp_trans_err != NULL)
2N/A sip_xaction_ulp_trans_err = ulp_trans_err;
2N/A if (ulp_state_cb != NULL)
2N/A sip_xaction_ulp_state_cb = ulp_state_cb;
2N/A}