xref: /titanic_51/usr/src/lib/libsip/common/sip_xaction.h (revision 9e26e16f703d2dfcc0689de957c21efcb72473e6)
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 2006 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 <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 
40 /* Various transaction timers */
41 typedef enum sip_timer_type_s {
42 	SIP_XACTION_TIMER_A = 0,
43 	SIP_XACTION_TIMER_B,
44 	SIP_XACTION_TIMER_D,
45 	SIP_XACTION_TIMER_E,
46 	SIP_XACTION_TIMER_F,
47 	SIP_XACTION_TIMER_G,
48 	SIP_XACTION_TIMER_H,
49 	SIP_XACTION_TIMER_I,
50 	SIP_XACTION_TIMER_J,
51 	SIP_XACTION_TIMER_K
52 } sip_xaction_timer_type_t;
53 
54 
55 /* Increment transaction reference count */
56 #define	SIP_XACTION_REFCNT_INCR(trans)	\
57 	(trans)->sip_xaction_ref_cnt++;
58 
59 /* Decrement transaction reference count */
60 #define	SIP_XACTION_REFCNT_DECR(trans)	{				\
61 	(void) pthread_mutex_lock(&((trans)->sip_xaction_mutex));	\
62 	assert((trans)->sip_xaction_ref_cnt > 0);			\
63 	(trans)->sip_xaction_ref_cnt--;					\
64 	if ((trans)->sip_xaction_ref_cnt == 0 && 			\
65 	    SIP_IS_XACTION_TERMINATED((trans)->sip_xaction_state)) {	\
66 		(void) pthread_mutex_unlock(&((trans)->sip_xaction_mutex));\
67 		sip_xaction_delete(trans);				\
68 	} else {							\
69 		(void) pthread_mutex_unlock(&((trans)->sip_xaction_mutex));\
70 	}								\
71 }
72 
73 /* True if transaction is in the terminated state */
74 #define	SIP_IS_XACTION_TERMINATED(trans_state)				\
75 	((trans_state) == SIP_CLNT_INV_TERMINATED ||			\
76 	(trans_state) == SIP_CLNT_NONINV_TERMINATED	||		\
77 	(trans_state) == SIP_SRV_INV_TERMINATED ||			\
78 	(trans_state) == SIP_SRV_NONINV_TERMINATED)
79 
80 /* Transaction structure */
81 typedef struct sip_xaction {
82 	char			*sip_xaction_branch_id;	/* Transaction id */
83 	uint16_t		sip_xaction_hash_digest[8];
84 	_sip_msg_t		*sip_xaction_orig_msg;	/* orig request msg. */
85 	_sip_msg_t		*sip_xaction_last_msg;	/* last msg sent */
86 	sip_conn_object_t	sip_xaction_conn_obj;
87 	int			sip_xaction_state;  /* Transaction State */
88 	sip_method_t		sip_xaction_method;
89 	uint32_t		sip_xaction_ref_cnt;
90 	pthread_mutex_t		sip_xaction_mutex;
91 	sip_timer_t		sip_xaction_TA;
92 	sip_timer_t		sip_xaction_TB;
93 	sip_timer_t		sip_xaction_TD;
94 	sip_timer_t		sip_xaction_TE;
95 	sip_timer_t		sip_xaction_TF;
96 	sip_timer_t		sip_xaction_TG;
97 	sip_timer_t		sip_xaction_TH;
98 	sip_timer_t		sip_xaction_TI;
99 	sip_timer_t		sip_xaction_TJ;
100 	sip_timer_t		sip_xaction_TK;
101 	void			*sip_xaction_ctxt;	/* currently unused */
102 } sip_xaction_t;
103 
104 extern void		sip_xaction_init(int (*ulp_trans_err)(sip_transaction_t,
105 			    int, void *), void (*ulp_state_cb)
106 			    (sip_transaction_t, sip_msg_t, int, int));
107 extern int		sip_xaction_output(sip_conn_object_t, sip_xaction_t *,
108 			    _sip_msg_t *);
109 extern int		sip_xaction_input(sip_conn_object_t, sip_xaction_t *,
110 			    _sip_msg_t **);
111 extern sip_xaction_t	*sip_xaction_get(sip_conn_object_t, sip_msg_t,
112 			    boolean_t, int, int *);
113 extern void		sip_xaction_delete(sip_xaction_t *);
114 extern char		*sip_get_xaction_state(int);
115 extern int 		(*sip_xaction_ulp_trans_err)(sip_transaction_t, int,
116 			    void *);
117 extern void 		(*sip_xaction_ulp_state_cb)(sip_transaction_t,
118 			    sip_msg_t, int, int);
119 extern void		sip_del_conn_obj_cache(sip_conn_object_t, void *);
120 extern int		sip_add_conn_obj_cache(sip_conn_object_t, void *);
121 extern void		sip_xaction_terminate(sip_xaction_t *, _sip_msg_t *,
122 			    int);
123 #ifdef	__cplusplus
124 }
125 #endif
126 
127 #endif	/* _SIP_XACTION_H */
128