xref: /titanic_41/usr/src/lib/libsip/common/sip_dialog.h (revision 35a5a3587fd94b666239c157d3722745250ccbd7)
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_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_local_contact;
72 	_sip_header_t		*sip_dlg_new_local_contact; /* for re-INVITE */
73 	_sip_header_t		*sip_dlg_route_set;
74 	_sip_header_t		*sip_dlg_event;
75 	sip_str_t		sip_dlg_rset;
76 	sip_str_t		sip_dlg_req_uri;
77 	_sip_header_t		*sip_dlg_call_id;
78 	uint32_t		sip_dlg_local_cseq;
79 	uint32_t		sip_dlg_remote_cseq;
80 	uint16_t		sip_dlg_id[8];
81 	boolean_t		sip_dlg_secure;
82 	dialog_state_t		sip_dlg_state;
83 	int			sip_dlg_type;	/* CALLEE or CALLER */
84 	pthread_mutex_t		sip_dlg_mutex;
85 	uint32_t		sip_dlg_ref_cnt;
86 	sip_timer_t		sip_dlg_timer;	/* to delete partial dialogs */
87 	boolean_t		sip_dlg_on_fork;
88 	sip_method_t		sip_dlg_method;
89 	void			*sip_dlg_ctxt;	/* currently unused */
90 	int			sip_dlg_msgcnt;
91 	sip_log_t		sip_dlg_log[SIP_DLG_DESTROYED + 1];
92 } _sip_dialog_t;
93 
94 void			sip_dialog_init(void (*sip_ulp_dlg_del)(sip_dialog_t,
95 			    sip_msg_t, void *),
96 			    void (*ulp_dlg_state)(sip_dialog_t, sip_msg_t,
97 			    int, int));
98 sip_dialog_t		sip_dialog_create(_sip_msg_t *, _sip_msg_t *, int);
99 sip_dialog_t		sip_dialog_find(_sip_msg_t *);
100 int			sip_dialog_process(_sip_msg_t *, sip_dialog_t *);
101 sip_dialog_t		sip_update_dialog(sip_dialog_t, _sip_msg_t *);
102 void			sip_dialog_add_new_contact(sip_dialog_t, _sip_msg_t *);
103 void			sip_dialog_terminate(sip_dialog_t, sip_msg_t);
104 sip_dialog_t		sip_seed_dialog(sip_conn_object_t, _sip_msg_t *,
105 			    boolean_t, int);
106 char			*sip_dialog_req_uri(sip_dialog_t);
107 void			sip_dialog_delete(_sip_dialog_t *);
108 extern char		*sip_get_dialog_state_str(int);
109 extern boolean_t	sip_incomplete_dialog(sip_dialog_t);
110 
111 #ifdef	__cplusplus
112 }
113 #endif
114 
115 #endif	/* _SIP_DIALOG_H */
116