xref: /onnv-gate/usr/src/lib/libsip/common/sip_xaction.h (revision 5842:e93f793783f6)
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 #ifndef	_SIP_XACTION_H
282882Svi117747 #define	_SIP_XACTION_H
292882Svi117747 
302882Svi117747 #pragma ident	"%Z%%M%	%I%	%E% SMI"
312882Svi117747 
322882Svi117747 #ifdef	__cplusplus
332882Svi117747 extern "C" {
342882Svi117747 #endif
352882Svi117747 
363439Svi117747 #include <pthread.h>
373439Svi117747 #include <sip.h>
383439Svi117747 #include <sys/types.h>
393439Svi117747 
403439Svi117747 #include "sip_msg.h"
413439Svi117747 #include "sip_miscdefs.h"
422882Svi117747 
432882Svi117747 /* Various transaction timers */
442882Svi117747 typedef enum sip_timer_type_s {
452882Svi117747 	SIP_XACTION_TIMER_A = 0,
462882Svi117747 	SIP_XACTION_TIMER_B,
472882Svi117747 	SIP_XACTION_TIMER_D,
482882Svi117747 	SIP_XACTION_TIMER_E,
492882Svi117747 	SIP_XACTION_TIMER_F,
502882Svi117747 	SIP_XACTION_TIMER_G,
512882Svi117747 	SIP_XACTION_TIMER_H,
522882Svi117747 	SIP_XACTION_TIMER_I,
532882Svi117747 	SIP_XACTION_TIMER_J,
542882Svi117747 	SIP_XACTION_TIMER_K
552882Svi117747 } sip_xaction_timer_type_t;
562882Svi117747 
572882Svi117747 
582882Svi117747 /* Increment transaction reference count */
592882Svi117747 #define	SIP_XACTION_REFCNT_INCR(trans)	\
602882Svi117747 	(trans)->sip_xaction_ref_cnt++;
612882Svi117747 
622882Svi117747 /* Decrement transaction reference count */
632882Svi117747 #define	SIP_XACTION_REFCNT_DECR(trans)	{				\
642882Svi117747 	(void) pthread_mutex_lock(&((trans)->sip_xaction_mutex));	\
652882Svi117747 	assert((trans)->sip_xaction_ref_cnt > 0);			\
662882Svi117747 	(trans)->sip_xaction_ref_cnt--;					\
672882Svi117747 	if ((trans)->sip_xaction_ref_cnt == 0 && 			\
682882Svi117747 	    SIP_IS_XACTION_TERMINATED((trans)->sip_xaction_state)) {	\
692882Svi117747 		(void) pthread_mutex_unlock(&((trans)->sip_xaction_mutex));\
702882Svi117747 		sip_xaction_delete(trans);				\
712882Svi117747 	} else {							\
722882Svi117747 		(void) pthread_mutex_unlock(&((trans)->sip_xaction_mutex));\
732882Svi117747 	}								\
742882Svi117747 }
752882Svi117747 
762882Svi117747 /* True if transaction is in the terminated state */
772882Svi117747 #define	SIP_IS_XACTION_TERMINATED(trans_state)				\
782882Svi117747 	((trans_state) == SIP_CLNT_INV_TERMINATED ||			\
792882Svi117747 	(trans_state) == SIP_CLNT_NONINV_TERMINATED	||		\
802882Svi117747 	(trans_state) == SIP_SRV_INV_TERMINATED ||			\
812882Svi117747 	(trans_state) == SIP_SRV_NONINV_TERMINATED)
822882Svi117747 
832882Svi117747 /* Transaction structure */
842882Svi117747 typedef struct sip_xaction {
852882Svi117747 	char			*sip_xaction_branch_id;	/* Transaction id */
862882Svi117747 	uint16_t		sip_xaction_hash_digest[8];
872882Svi117747 	_sip_msg_t		*sip_xaction_orig_msg;	/* orig request msg. */
882882Svi117747 	_sip_msg_t		*sip_xaction_last_msg;	/* last msg sent */
892882Svi117747 	sip_conn_object_t	sip_xaction_conn_obj;
902882Svi117747 	int			sip_xaction_state;  /* Transaction State */
912882Svi117747 	sip_method_t		sip_xaction_method;
922882Svi117747 	uint32_t		sip_xaction_ref_cnt;
932882Svi117747 	pthread_mutex_t		sip_xaction_mutex;
942882Svi117747 	sip_timer_t		sip_xaction_TA;
952882Svi117747 	sip_timer_t		sip_xaction_TB;
962882Svi117747 	sip_timer_t		sip_xaction_TD;
972882Svi117747 	sip_timer_t		sip_xaction_TE;
982882Svi117747 	sip_timer_t		sip_xaction_TF;
992882Svi117747 	sip_timer_t		sip_xaction_TG;
1002882Svi117747 	sip_timer_t		sip_xaction_TH;
1012882Svi117747 	sip_timer_t		sip_xaction_TI;
1022882Svi117747 	sip_timer_t		sip_xaction_TJ;
1032882Svi117747 	sip_timer_t		sip_xaction_TK;
1042882Svi117747 	void			*sip_xaction_ctxt;	/* currently unused */
105*5842Sgm209912 	int			sip_xaction_msgcnt;
106*5842Sgm209912 	sip_log_t		sip_xaction_log[SIP_SRV_NONINV_TERMINATED + 1];
1072882Svi117747 } sip_xaction_t;
1082882Svi117747 
1092882Svi117747 extern void		sip_xaction_init(int (*ulp_trans_err)(sip_transaction_t,
1102882Svi117747 			    int, void *), void (*ulp_state_cb)
1112882Svi117747 			    (sip_transaction_t, sip_msg_t, int, int));
1122882Svi117747 extern int		sip_xaction_output(sip_conn_object_t, sip_xaction_t *,
1132882Svi117747 			    _sip_msg_t *);
1142882Svi117747 extern int		sip_xaction_input(sip_conn_object_t, sip_xaction_t *,
1152882Svi117747 			    _sip_msg_t **);
1162882Svi117747 extern sip_xaction_t	*sip_xaction_get(sip_conn_object_t, sip_msg_t,
1172882Svi117747 			    boolean_t, int, int *);
1182882Svi117747 extern void		sip_xaction_delete(sip_xaction_t *);
1192882Svi117747 extern char		*sip_get_xaction_state(int);
1202882Svi117747 extern int 		(*sip_xaction_ulp_trans_err)(sip_transaction_t, int,
1212882Svi117747 			    void *);
1222882Svi117747 extern void 		(*sip_xaction_ulp_state_cb)(sip_transaction_t,
1232882Svi117747 			    sip_msg_t, int, int);
1242882Svi117747 extern void		sip_del_conn_obj_cache(sip_conn_object_t, void *);
1252882Svi117747 extern int		sip_add_conn_obj_cache(sip_conn_object_t, void *);
1262882Svi117747 extern void		sip_xaction_terminate(sip_xaction_t *, _sip_msg_t *,
1272882Svi117747 			    int);
1282882Svi117747 #ifdef	__cplusplus
1292882Svi117747 }
1302882Svi117747 #endif
1312882Svi117747 
1322882Svi117747 #endif	/* _SIP_XACTION_H */
133