xref: /titanic_50/usr/src/lib/libsip/common/sip_dialog.h (revision de777a601dfef76d8d54837de77dc672dce47498)
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_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 } _sip_dialog_t;
91 
92 void			sip_dialog_init(void (*sip_ulp_dlg_del)(sip_dialog_t,
93 			    sip_msg_t, void *),
94 			    void (*ulp_dlg_state)(sip_dialog_t, sip_msg_t,
95 			    int, int));
96 sip_dialog_t		sip_dialog_create(_sip_msg_t *, _sip_msg_t *, int);
97 sip_dialog_t		sip_dialog_find(_sip_msg_t *);
98 int			sip_dialog_process(_sip_msg_t *, sip_dialog_t *);
99 sip_dialog_t		sip_update_dialog(sip_dialog_t, _sip_msg_t *);
100 void			sip_dialog_add_new_contact(sip_dialog_t, _sip_msg_t *);
101 void			sip_dialog_terminate(sip_dialog_t, sip_msg_t);
102 sip_dialog_t		sip_seed_dialog(sip_conn_object_t, _sip_msg_t *,
103 			    boolean_t, int);
104 char			*sip_dialog_req_uri(sip_dialog_t);
105 void			sip_dialog_delete(_sip_dialog_t *);
106 extern boolean_t	sip_incomplete_dialog(sip_dialog_t);
107 
108 #ifdef	__cplusplus
109 }
110 #endif
111 
112 #endif	/* _SIP_DIALOG_H */
113