xref: /titanic_41/usr/src/lib/libsip/common/sip_dialog.h (revision 5ce5f3670f7934e376808da0d1309924ecf8f9e5)
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_DIALOG_H
28 #define	_SIP_DIALOG_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 /*
44  * Dialogs are linked in their own list.
45  */
46 
47 
48 /* This is always done within sip_dlg_mutex */
49 #define	SIP_DLG_REFCNT_INCR(dialog)					\
50 	(dialog)->sip_dlg_ref_cnt++;
51 
52 #define	SIP_DLG_REFCNT_DECR(dialog)	 {				\
53 	(void) pthread_mutex_lock(&((dialog)->sip_dlg_mutex));		\
54 	assert((dialog)->sip_dlg_ref_cnt > 0);				\
55 	(dialog)->sip_dlg_ref_cnt--;					\
56 	if ((dialog)->sip_dlg_ref_cnt == 0 &&				\
57 	    (dialog)->sip_dlg_state == SIP_DLG_DESTROYED) {		\
58 		(void) pthread_mutex_unlock(&((dialog)->sip_dlg_mutex)); \
59 		sip_dialog_delete(dialog);				\
60 	} else {							\
61 		(void) pthread_mutex_unlock(&((dialog)->sip_dlg_mutex));\
62 	}								\
63 }
64 
65 /* The dialog structure */
66 typedef struct sip_dialog
67 {
68 	_sip_header_t		*sip_dlg_remote_uri_tag;
69 	_sip_header_t		*sip_dlg_local_uri_tag;
70 	_sip_header_t		*sip_dlg_remote_target;
71 	_sip_header_t		*sip_dlg_route_set;
72 	_sip_header_t		*sip_dlg_event;
73 	sip_str_t		sip_dlg_rset;
74 	sip_str_t		sip_dlg_req_uri;
75 	_sip_header_t		*sip_dlg_call_id;
76 	uint32_t		sip_dlg_local_cseq;
77 	uint32_t		sip_dlg_remote_cseq;
78 	uint16_t		sip_dlg_id[8];
79 	boolean_t		sip_dlg_secure;
80 	dialog_state_t		sip_dlg_state;
81 	int			sip_dlg_type;	/* CALLEE or CALLER */
82 	pthread_mutex_t		sip_dlg_mutex;
83 	uint32_t		sip_dlg_ref_cnt;
84 	sip_timer_t		sip_dlg_timer;	/* to delete partial dialogs */
85 	boolean_t		sip_dlg_on_fork;
86 	sip_method_t		sip_dlg_method;
87 	void			*sip_dlg_ctxt;	/* currently unused */
88 } _sip_dialog_t;
89 
90 void			sip_dialog_init(void (*sip_ulp_dlg_del)(sip_dialog_t,
91 			    sip_msg_t, void *),
92 			    void (*ulp_dlg_state)(sip_dialog_t, sip_msg_t,
93 			    int, int));
94 sip_dialog_t		sip_dialog_create(_sip_msg_t *, _sip_msg_t *, int);
95 sip_dialog_t		sip_dialog_find(_sip_msg_t *);
96 int			sip_dialog_process(_sip_msg_t *, sip_dialog_t *);
97 sip_dialog_t		sip_update_dialog(sip_dialog_t, _sip_msg_t *);
98 void			sip_dialog_terminate(sip_dialog_t, sip_msg_t);
99 sip_dialog_t		sip_seed_dialog(sip_conn_object_t, _sip_msg_t *,
100 			    boolean_t, int);
101 char			*sip_dialog_req_uri(sip_dialog_t);
102 void			sip_dialog_delete(_sip_dialog_t *);
103 extern boolean_t	sip_incomplete_dialog(sip_dialog_t);
104 
105 #ifdef	__cplusplus
106 }
107 #endif
108 
109 #endif	/* _SIP_DIALOG_H */
110