xref: /illumos-gate/usr/src/lib/libsip/common/sip_dialog.h (revision 0fb96ba1f1ce26ff8b286f8f928769a6afcb00a6)
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 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <pthread.h>
35 #include <sip.h>
36 #include <sys/types.h>
37 
38 #include "sip_msg.h"
39 #include "sip_miscdefs.h"
40 
41 /*
42  * Dialogs are linked in their own list.
43  */
44 
45 
46 /* This is always done within sip_dlg_mutex */
47 #define	SIP_DLG_REFCNT_INCR(dialog)					\
48 	(dialog)->sip_dlg_ref_cnt++;
49 
50 #define	SIP_DLG_REFCNT_DECR(dialog)	 {				\
51 	(void) pthread_mutex_lock(&((dialog)->sip_dlg_mutex));		\
52 	assert((dialog)->sip_dlg_ref_cnt > 0);				\
53 	(dialog)->sip_dlg_ref_cnt--;					\
54 	if ((dialog)->sip_dlg_ref_cnt == 0 &&				\
55 	    (dialog)->sip_dlg_state == SIP_DLG_DESTROYED) {		\
56 		(void) pthread_mutex_unlock(&((dialog)->sip_dlg_mutex)); \
57 		sip_dialog_delete(dialog);				\
58 	} else {							\
59 		(void) pthread_mutex_unlock(&((dialog)->sip_dlg_mutex));\
60 	}								\
61 }
62 
63 /* The dialog structure */
64 typedef struct sip_dialog
65 {
66 	_sip_header_t		*sip_dlg_remote_uri_tag;
67 	_sip_header_t		*sip_dlg_local_uri_tag;
68 	_sip_header_t		*sip_dlg_remote_target;
69 	_sip_header_t		*sip_dlg_local_contact;
70 	_sip_header_t		*sip_dlg_new_local_contact; /* for re-INVITE */
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 	int			sip_dlg_msgcnt;
89 	sip_log_t		sip_dlg_log[SIP_DLG_DESTROYED + 1];
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 char		*sip_get_dialog_state_str(int);
107 extern boolean_t	sip_incomplete_dialog(sip_dialog_t);
108 
109 #ifdef	__cplusplus
110 }
111 #endif
112 
113 #endif	/* _SIP_DIALOG_H */
114