1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SIP_XACTION_H 28 #define _SIP_XACTION_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #include <pthread.h> 35 #include <sip.h> 36 #include <sys/types.h> 37 38 #include "sip_msg.h" 39 #include "sip_miscdefs.h" 40 41 /* Various transaction timers */ 42 typedef enum sip_timer_type_s { 43 SIP_XACTION_TIMER_A = 0, 44 SIP_XACTION_TIMER_B, 45 SIP_XACTION_TIMER_D, 46 SIP_XACTION_TIMER_E, 47 SIP_XACTION_TIMER_F, 48 SIP_XACTION_TIMER_G, 49 SIP_XACTION_TIMER_H, 50 SIP_XACTION_TIMER_I, 51 SIP_XACTION_TIMER_J, 52 SIP_XACTION_TIMER_K 53 } sip_xaction_timer_type_t; 54 55 56 /* Increment transaction reference count */ 57 #define SIP_XACTION_REFCNT_INCR(trans) \ 58 (trans)->sip_xaction_ref_cnt++; 59 60 /* Decrement transaction reference count */ 61 #define SIP_XACTION_REFCNT_DECR(trans) { \ 62 (void) pthread_mutex_lock(&((trans)->sip_xaction_mutex)); \ 63 assert((trans)->sip_xaction_ref_cnt > 0); \ 64 (trans)->sip_xaction_ref_cnt--; \ 65 if ((trans)->sip_xaction_ref_cnt == 0 && \ 66 SIP_IS_XACTION_TERMINATED((trans)->sip_xaction_state)) { \ 67 (void) pthread_mutex_unlock(&((trans)->sip_xaction_mutex));\ 68 sip_xaction_delete(trans); \ 69 } else { \ 70 (void) pthread_mutex_unlock(&((trans)->sip_xaction_mutex));\ 71 } \ 72 } 73 74 /* True if transaction is in the terminated state */ 75 #define SIP_IS_XACTION_TERMINATED(trans_state) \ 76 ((trans_state) == SIP_CLNT_INV_TERMINATED || \ 77 (trans_state) == SIP_CLNT_NONINV_TERMINATED || \ 78 (trans_state) == SIP_SRV_INV_TERMINATED || \ 79 (trans_state) == SIP_SRV_NONINV_TERMINATED) 80 81 /* Transaction structure */ 82 typedef struct sip_xaction { 83 char *sip_xaction_branch_id; /* Transaction id */ 84 uint16_t sip_xaction_hash_digest[8]; 85 _sip_msg_t *sip_xaction_orig_msg; /* orig request msg. */ 86 _sip_msg_t *sip_xaction_last_msg; /* last msg sent */ 87 sip_conn_object_t sip_xaction_conn_obj; 88 int sip_xaction_state; /* Transaction State */ 89 sip_method_t sip_xaction_method; 90 uint32_t sip_xaction_ref_cnt; 91 pthread_mutex_t sip_xaction_mutex; 92 sip_timer_t sip_xaction_TA; 93 sip_timer_t sip_xaction_TB; 94 sip_timer_t sip_xaction_TD; 95 sip_timer_t sip_xaction_TE; 96 sip_timer_t sip_xaction_TF; 97 sip_timer_t sip_xaction_TG; 98 sip_timer_t sip_xaction_TH; 99 sip_timer_t sip_xaction_TI; 100 sip_timer_t sip_xaction_TJ; 101 sip_timer_t sip_xaction_TK; 102 void *sip_xaction_ctxt; /* currently unused */ 103 int sip_xaction_msgcnt; 104 sip_log_t sip_xaction_log[SIP_SRV_NONINV_TERMINATED + 1]; 105 } sip_xaction_t; 106 107 extern void sip_xaction_init(int (*ulp_trans_err)(sip_transaction_t, 108 int, void *), void (*ulp_state_cb) 109 (sip_transaction_t, sip_msg_t, int, int)); 110 extern int sip_xaction_output(sip_conn_object_t, sip_xaction_t *, 111 _sip_msg_t *); 112 extern int sip_xaction_input(sip_conn_object_t, sip_xaction_t *, 113 _sip_msg_t **); 114 extern sip_xaction_t *sip_xaction_get(sip_conn_object_t, sip_msg_t, 115 boolean_t, int, int *); 116 extern void sip_xaction_delete(sip_xaction_t *); 117 extern char *sip_get_xaction_state(int); 118 extern int (*sip_xaction_ulp_trans_err)(sip_transaction_t, int, 119 void *); 120 extern void (*sip_xaction_ulp_state_cb)(sip_transaction_t, 121 sip_msg_t, int, int); 122 extern void sip_del_conn_obj_cache(sip_conn_object_t, void *); 123 extern int sip_add_conn_obj_cache(sip_conn_object_t, void *); 124 extern void sip_xaction_terminate(sip_xaction_t *, _sip_msg_t *, 125 int); 126 #ifdef __cplusplus 127 } 128 #endif 129 130 #endif /* _SIP_XACTION_H */ 131