dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libsip / common / sip_miscdefs.h
blob10e28b1861c12cd53e8548a39f7852a1f90ae994
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _SIP_MISCDEFS_H
28 #define _SIP_MISCDEFS_H
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
34 #include <pthread.h>
35 #include <sys/types.h>
36 #include <sys/time.h>
37 #include <stdio.h>
39 #define SIP_NUL '\0'
40 #define SIP_CR '\r'
41 #define SIP_SP ' '
42 #define SIP_HCOLON ':'
43 #define SIP_SEMI ';'
44 #define SIP_COMMA ','
45 #define SIP_LAQUOT '<'
46 #define SIP_RAQUOT '>'
47 #define SIP_QUOTE '"'
48 #define SIP_EQUAL '='
49 #define SIP_SLASH '/'
50 #define SIP_PERIOD '.'
51 #define SIP_LPAR '('
52 #define SIP_RPAR ')'
54 #define SIP_BRANCHID_LEN 28 /* incl. the magic cookie */
55 #define SIP_TAG_LEN 20
56 #define SIP_URI_LEN 25
57 #define SIP_DISPLAY_LEN 25
58 #define SIP_DOMAIN_LEN 25
59 #define SIP_MAX_FWDLEN 5
60 #define SIP_TRANSPORT_LEN 5
61 #define SIP_SIZE_OF_STATUS_CODE 3
62 #define SIP_SPACE_LEN sizeof (char)
64 #define SIP_TRANSACTION_LOG 0x0001
65 #define SIP_DIALOG_LOG 0x0002
66 #define SIP_ASSERT_ERROR 0x0004
68 #define SIP_MS 1L
69 #define SIP_SECONDS (1000 * SIP_MS)
70 #define SIP_MINUTES (60 * SIP_SECONDS)
71 #define SIP_HOURS (60 * SIP_MINUTES)
73 /* timer granularity is in msecs */
74 #define SIP_TIMER_T1 (1 * SIP_SECONDS)
75 #define SIP_TIMER_T2 (4 * SIP_SECONDS)
76 #define SIP_TIMER_T4 (5 * SIP_SECONDS)
78 #ifdef __linux__
79 #define SEC 1
80 #define MILLISEC 1000
81 #define MICROSEC 1000000
82 #define NANOSEC 1000000000
84 typedef struct timespec timestruc_t;
85 typedef long long hrtime_t;
86 #endif
88 extern int sip_timer_T1;
89 extern int sip_timer_T2;
90 extern int sip_timer_T4;
91 extern int sip_timer_TD;
93 /* Structure for SIP timers */
94 typedef struct sip_timer_s {
95 uint_t sip_timerid;
96 struct timeval sip_timeout_val;
97 }sip_timer_t;
99 /* time is in msec */
100 #define SIP_SET_TIMEOUT(timer, time) { \
101 int mtime = (time); \
103 (timer).sip_timeout_val.tv_sec = mtime / MILLISEC; \
104 mtime -= (timer).sip_timeout_val.tv_sec * MILLISEC; \
105 (timer).sip_timeout_val.tv_usec = mtime * MILLISEC; \
108 /* time is in msec */
109 #define SIP_INIT_TIMER(timer, time) { \
110 SIP_SET_TIMEOUT(timer, time); \
111 (timer).sip_timerid = 0; \
114 #define SIP_SCHED_TIMER(timer, obj, func) { \
115 (timer).sip_timerid = sip_stack_timeout((void *)(obj), \
116 (func), &((timer).sip_timeout_val)); \
119 #define SIP_CANCEL_TIMER(timer) { \
120 if ((timer).sip_timerid != 0) { \
121 sip_stack_untimeout((timer).sip_timerid); \
122 (timer).sip_timerid = 0; \
126 /* returned time is in msec */
127 #define SIP_GET_TIMEOUT(timer) \
128 ((timer).sip_timeout_val.tv_sec * MILLISEC + \
129 (timer).sip_timeout_val.tv_usec / MILLISEC)
131 #define SIP_IS_TIMER_RUNNING(timer) ((timer).sip_timerid != 0)
133 #define SIP_UPDATE_COUNTERS(is_request, method, resp_code, outbound, size) { \
134 (void) pthread_mutex_lock(&sip_counters.sip_counter_mutex); \
135 if (sip_counters.enabled) { \
136 (void) sip_measure_traffic((is_request), (method), (resp_code),\
137 (outbound), (size)); \
139 (void) pthread_mutex_unlock(&sip_counters.sip_counter_mutex); \
142 /* This is the transaction list */
143 typedef struct sip_conn_cache_s {
144 void *obj;
145 struct sip_conn_cache_s *next;
146 struct sip_conn_cache_s *prev;
147 } sip_conn_cache_t;
149 /* TCP fragment entry */
150 typedef struct sip_reass_entry_s {
151 char *sip_reass_msg;
152 int sip_reass_msglen;
153 }sip_reass_entry_t;
155 /* Library data in stored in connection object */
156 typedef struct sip_conn_obj_pvt_s {
157 sip_reass_entry_t *sip_conn_obj_reass;
158 pthread_mutex_t sip_conn_obj_reass_lock;
159 sip_conn_cache_t *sip_conn_obj_cache;
160 pthread_mutex_t sip_conn_obj_cache_lock;
161 } sip_conn_obj_pvt_t;
163 /* SIP traffic counters structure */
165 typedef struct sip_traffic_counters_s {
166 boolean_t enabled;
167 time_t starttime;
168 time_t stoptime;
169 uint64_t sip_total_bytes_rcvd;
170 uint64_t sip_total_bytes_sent;
171 uint64_t sip_total_req_rcvd;
172 uint64_t sip_total_req_sent;
173 uint64_t sip_total_resp_rcvd;
174 uint64_t sip_total_resp_sent;
175 uint64_t sip_ack_req_rcvd;
176 uint64_t sip_ack_req_sent;
177 uint64_t sip_bye_req_rcvd;
178 uint64_t sip_bye_req_sent;
179 uint64_t sip_cancel_req_rcvd;
180 uint64_t sip_cancel_req_sent;
181 uint64_t sip_info_req_rcvd;
182 uint64_t sip_info_req_sent;
183 uint64_t sip_invite_req_rcvd;
184 uint64_t sip_invite_req_sent;
185 uint64_t sip_notify_req_rcvd;
186 uint64_t sip_notify_req_sent;
187 uint64_t sip_options_req_rcvd;
188 uint64_t sip_options_req_sent;
189 uint64_t sip_prack_req_rcvd;
190 uint64_t sip_prack_req_sent;
191 uint64_t sip_refer_req_rcvd;
192 uint64_t sip_refer_req_sent;
193 uint64_t sip_register_req_rcvd;
194 uint64_t sip_register_req_sent;
195 uint64_t sip_subscribe_req_rcvd;
196 uint64_t sip_subscribe_req_sent;
197 uint64_t sip_update_req_rcvd;
198 uint64_t sip_update_req_sent;
199 uint64_t sip_1xx_resp_rcvd;
200 uint64_t sip_1xx_resp_sent;
201 uint64_t sip_2xx_resp_rcvd;
202 uint64_t sip_2xx_resp_sent;
203 uint64_t sip_3xx_resp_rcvd;
204 uint64_t sip_3xx_resp_sent;
205 uint64_t sip_4xx_resp_rcvd;
206 uint64_t sip_4xx_resp_sent;
207 uint64_t sip_5xx_resp_rcvd;
208 uint64_t sip_5xx_resp_sent;
209 uint64_t sip_6xx_resp_rcvd;
210 uint64_t sip_6xx_resp_sent;
211 pthread_mutex_t sip_counter_mutex; /* Mutex should be always at end */
212 } sip_traffic_counters_t;
214 /* SIP logfile structure */
215 typedef struct sip_logfile_s {
216 boolean_t sip_logging_enabled;
217 FILE *sip_logfile;
218 pthread_mutex_t sip_logfile_mutex;
219 } sip_logfile_t;
221 typedef struct sip_msg_chain_s {
222 char *sip_msg;
223 int msg_seq;
224 time_t msg_timestamp;
225 struct sip_msg_chain_s *next;
226 }sip_msg_chain_t;
228 typedef struct sip_log_s {
229 sip_msg_chain_t *sip_msgs;
230 int sip_msgcnt;
231 }sip_log_t;
233 extern sip_traffic_counters_t sip_counters;
235 extern sip_logfile_t trans_log;
236 extern sip_logfile_t dialog_log;
238 extern boolean_t sip_manage_dialog;
240 /* To salt the hash function */
241 extern uint64_t sip_hash_salt;
243 extern void sip_timeout_init();
244 extern uint_t sip_timeout(void *, void (*)(void *), struct timeval *);
245 extern boolean_t sip_untimeout(uint_t);
246 extern void sip_md5_hash(char *, int, char *, int, char *, int,
247 char *, int, char *, int, char *, int, uchar_t *);
248 extern void sip_measure_traffic(boolean_t, sip_method_t, int,
249 boolean_t, int);
250 extern void sip_add_log(sip_log_t *, sip_msg_t, int, int);
251 extern void sip_write_to_log(void *, int, char *, int);
253 #ifdef __cplusplus
255 #endif
257 #endif /* _SIP_MISCDEFS_H */