xref: /titanic_41/usr/src/lib/libsip/common/sip_xaction.h (revision bbfe764ef179c2f606b093b6ec6bb149cde0e31b)
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 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <pthread.h>
37 #include <sip.h>
38 #include <sys/types.h>
39 
40 #include "sip_msg.h"
41 #include "sip_miscdefs.h"
42 
43 /* Various transaction timers */
44 typedef enum sip_timer_type_s {
45 	SIP_XACTION_TIMER_A = 0,
46 	SIP_XACTION_TIMER_B,
47 	SIP_XACTION_TIMER_D,
48 	SIP_XACTION_TIMER_E,
49 	SIP_XACTION_TIMER_F,
50 	SIP_XACTION_TIMER_G,
51 	SIP_XACTION_TIMER_H,
52 	SIP_XACTION_TIMER_I,
53 	SIP_XACTION_TIMER_J,
54 	SIP_XACTION_TIMER_K
55 } sip_xaction_timer_type_t;
56 
57 
58 /* Increment transaction reference count */
59 #define	SIP_XACTION_REFCNT_INCR(trans)	\
60 	(trans)->sip_xaction_ref_cnt++;
61 
62 /* Decrement transaction reference count */
63 #define	SIP_XACTION_REFCNT_DECR(trans)	{				\
64 	(void) pthread_mutex_lock(&((trans)->sip_xaction_mutex));	\
65 	assert((trans)->sip_xaction_ref_cnt > 0);			\
66 	(trans)->sip_xaction_ref_cnt--;					\
67 	if ((trans)->sip_xaction_ref_cnt == 0 && 			\
68 	    SIP_IS_XACTION_TERMINATED((trans)->sip_xaction_state)) {	\
69 		(void) pthread_mutex_unlock(&((trans)->sip_xaction_mutex));\
70 		sip_xaction_delete(trans);				\
71 	} else {							\
72 		(void) pthread_mutex_unlock(&((trans)->sip_xaction_mutex));\
73 	}								\
74 }
75 
76 /* True if transaction is in the terminated state */
77 #define	SIP_IS_XACTION_TERMINATED(trans_state)				\
78 	((trans_state) == SIP_CLNT_INV_TERMINATED ||			\
79 	(trans_state) == SIP_CLNT_NONINV_TERMINATED	||		\
80 	(trans_state) == SIP_SRV_INV_TERMINATED ||			\
81 	(trans_state) == SIP_SRV_NONINV_TERMINATED)
82 
83 /* Transaction structure */
84 typedef struct sip_xaction {
85 	char			*sip_xaction_branch_id;	/* Transaction id */
86 	uint16_t		sip_xaction_hash_digest[8];
87 	_sip_msg_t		*sip_xaction_orig_msg;	/* orig request msg. */
88 	_sip_msg_t		*sip_xaction_last_msg;	/* last msg sent */
89 	sip_conn_object_t	sip_xaction_conn_obj;
90 	int			sip_xaction_state;  /* Transaction State */
91 	sip_method_t		sip_xaction_method;
92 	uint32_t		sip_xaction_ref_cnt;
93 	pthread_mutex_t		sip_xaction_mutex;
94 	sip_timer_t		sip_xaction_TA;
95 	sip_timer_t		sip_xaction_TB;
96 	sip_timer_t		sip_xaction_TD;
97 	sip_timer_t		sip_xaction_TE;
98 	sip_timer_t		sip_xaction_TF;
99 	sip_timer_t		sip_xaction_TG;
100 	sip_timer_t		sip_xaction_TH;
101 	sip_timer_t		sip_xaction_TI;
102 	sip_timer_t		sip_xaction_TJ;
103 	sip_timer_t		sip_xaction_TK;
104 	void			*sip_xaction_ctxt;	/* currently unused */
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