1 /*!
2  * \file        sccp_globals.h
3  * \brief       SCCP Globals Header
4  * \author      Diederik de Groot < ddegroot@users.sourceforge.net >
5  * \note        This program is free software and may be modified and distributed under the terms of the GNU Public License.
6  *              See the LICENSE file at the top of the source tree.
7  * \since       2016-02-02
8  */
9 #pragma once
10 #include "config.h"
11 #include "define.h"
12 #include "sccp_codec.h"
13 #include "sccp_netsock.h"
14 
15 __BEGIN_C_EXTERN__
16 SCCP_API char SCCP_VERSIONSTR[300];
17 SCCP_API char SCCP_REVISIONSTR[30];
18 
19 typedef struct sccp_servercontext sccp_servercontext_t;
20 /*!
21  * \brief SCCP device-line subscriptionId
22  * \note for addressing individual devices on shared line
23  * \todo current size if 176 bits, could/should be reduced by using charptr instead
24  * \todo at the moment subscriptionId is being copied from lines to channel and linedevices
25  */
26 struct subscriptionId {
27 	char number[SCCP_MAX_EXTENSION];									/*!< will be added to cid */
28 	char name[SCCP_MAX_EXTENSION];										/*!< will be added to cidName */
29 	char label[SCCP_MAX_LABEL];										/*!< will be added to cidName */
30 	char aux[SCCP_MAX_AUX];											/*!< auxiliary parameter. Allows for phone-specific behaviour on a line. */
31 	boolean_t replaceCid;											/*!< Should cidnumber be replaced instead of appended to, controled by the '=' subscription flag */
32 };
33 
34 /*!
35  * \brief SCCP Global Variable Structure
36  */
37 struct sccp_global_vars {
38 	int keepalive;												/*!< KeepAlive */
39 	int32_t debug;												/*!< Debug */
40 	int module_running;
41 	pbx_rwlock_t lock;											/*!< Asterisk: Lock Me Up and Tie me Down */
42 
43 #if ASTERISK_VERSION_GROUP < 110
44 	pthread_t monitor_thread;										/*!< Monitor Thread */
45 	sccp_mutex_t monitor_lock;										/*!< Monitor Asterisk Lock */
46 #endif
47 	sccp_threadpool_t *general_threadpool;									/*!< General Work Threadpool */
48 
49 	SCCP_RWLIST_HEAD (, sccp_session_t) sessions;								/*!< SCCP Sessions */
50 	SCCP_RWLIST_HEAD (, sccp_device_t) devices;								/*!< SCCP Devices */
51 	SCCP_RWLIST_HEAD (, sccp_line_t) lines;									/*!< SCCP Lines */
52 
53 	sccp_mutex_t socket_lock;										/*!< Socket Lock */
54 #ifndef SCCP_ATOMIC
55 	sccp_mutex_t usecnt_lock;										/*!< Use Counter Asterisk Lock */
56 #endif
57 	int usecnt;												/*!< Keep track of when we're in use. */
58 	long int amaflags;											/*!< AmaFlags */
59 	pthread_t mwiMonitorThread;										/*!< MWI Monitor Thread */
60 
61 	char dateformat[SCCP_MAX_DATE_FORMAT];									/*!< Date Format */
62 
63 	sccp_servercontext_t * srvcontexts[2];
64 
65 	struct sccp_ha *ha;											/*!< Permit or deny connections to the main socket */
66 	struct sockaddr_storage bindaddr;									/*!< Bind IP Address */
67 	struct sockaddr_storage secbindaddr;                                                                    /*!< Bind IP Address */
68 	char * cert_file;
69 	struct sccp_ha *localaddr;										/*!< Localnet for Network Address Translation */
70 
71 	struct sockaddr_storage externip;									/*!< External IP Address (\todo should change to an array of external ip's, because externhost could resolv to multiple ip-addresses (h_addr_list)) */
72 	time_t externexpire;											/*!< External Expire */
73 	uint16_t externrefresh;											/*!< External Refresh */
74 
75 	boolean_t recorddigittimeoutchar;									/*!< Record Digit Time Out Char. Whether to include the digittimeoutchar in the call logs */
76 	uint8_t firstdigittimeout;										/*!< First Digit Timeout. Wait up to 16 seconds for first digit */
77 
78 	uint8_t digittimeout;											/*!< Digit Timeout. How long to wait for following digits */
79 	char digittimeoutchar;											/*!< Digit End Character. What char will force the dial (Normally '#') */
80 	boolean_t simulate_enbloc;										/*!< Simulated Enbloc Dialing for older device to speed up dialing */
81 	uint8_t autoanswer_ring_time;										/*!< Auto Answer Ring Time */
82 	skinny_tone_t autoanswer_tone;										/*!< Auto Answer Tone */
83 	skinny_tone_t remotehangup_tone;									/*!< Remote Hangup Tone */
84 	skinny_tone_t transfer_tone;										/*!< Transfer Tone */
85 	skinny_tone_t dnd_tone;											/*!< DND Tone */
86 	skinny_tone_t callwaiting_tone;										/*!< Call Waiting Tone */
87 
88 	uint8_t callwaiting_interval;										/*!< Call Waiting Ring Interval */
89 	uint8_t sccp_tos;											/*!< SCCP Socket Type of Service (TOS) (QOS) (Signaling) */
90 	uint8_t audio_tos;											/*!< Audio Socket Type of Service (TOS) (QOS) (RTP) */
91 	uint8_t video_tos;											/*!< Video Socket Type of Service (TOS) (QOS) (VRTP) */
92 	uint8_t sccp_cos;											/*!< SCCP Socket Class of Service (COS) (QOS) (Signaling) */
93 	uint8_t audio_cos;											/*!< Audio Socket Class of Service (COS) (QOS) (RTP) */
94 	uint8_t video_cos;											/*!< Video Socket Class of Service (COS) (QOS) (VRTP) */
95 	boolean_t dndFeature;											/*!< Do Not Disturb (DND) Mode: \see SCCP_DNDMODE_* */
96 
97 	boolean_t transfer_on_hangup;										/*!< Complete transfer on hangup */
98 #ifdef CS_MANAGER_EVENTS
99 	boolean_t callevents;											/*!< Call Events */
100 #endif
101 	boolean_t echocancel;											/*!< Echo Canel Support (Boolean, default=on) */
102 	boolean_t silencesuppression;										/*!< Silence Suppression Support (Boolean, default=on)  */
103 	boolean_t trustphoneip;											/*!< Trust Phone IP Support (Boolean, default=on) */
104 	boolean_t privacy;											/*!< Privacy Support (Length=2) */
105 	boolean_t mwioncall;											/*!< MWI On Call Support (Boolean, default=on) */
106 	boolean_t directrtp;											/*!< Direct RTP */
107 	boolean_t useoverlap;											/*!< Overlap Dial Support */
108 	boolean_t transfer;											/*!< Transfer Feature Enabled */
109 	boolean_t cfwdall;                                                                                      /*!< Call Forward All Support (Boolean, default=on) */
110 	boolean_t cfwdbusy;                                                                                     /*!< Call Forward on Busy Support (Boolean, default=on) */
111 	boolean_t cfwdnoanswer;                                                                                 /*!< Call Forward on No-Answer Support (Boolean, default=on) */
112 	uint16_t cfwdnoanswer_timeout;                                                                          /*!< Call Forward on No-Answer timeout */
113 	char *meetmeopts;											/*!< Meetme Options to be Used */
114 #if HAVE_ICONV
115 	char *iconvcodepage;											/*!< Iconv Codepage to use during conversion from UTF-8, for old phone models */
116 #endif
117 	sccp_group_t callgroup;											/*!< Call Group */
118 #ifdef CS_SCCP_PICKUP
119 	sccp_group_t pickupgroup;										/*!< PickUp Group */
120 	boolean_t directed_pickup;										/*!< Directed Pickup Extension Support (Boolean, default=on) */
121 	char directed_pickup_context[SCCP_MAX_CONTEXT];								/*!< Directed Pickup Context to Use in DialPlan */
122 	boolean_t pickup_modeanswer;										/*!< Directed PickUp Mode Answer (boolean, default" on) */
123 #ifdef CS_AST_HAS_NAMEDGROUP
124 	char *namedcallgroup;											/*!< Named Call Group */
125 	char *namedpickupgroup;											/*!< Named Pickup Group */
126 #endif
127 #else
128 	uint8_t _padding1[1];
129 #endif
130 	skinny_callHistoryDisposition_t callhistory_answered_elsewhere;						/*!< What to do with the call history for calls that were answered remotely */
131 	skinny_ringtype_t ringtype;										/*!< RingType for incoming calls */
132 	boolean_t meetme;											/*!< Meetme on/off */
133 	boolean_t allowAnonymous;										/*!< Allow Anonymous/Guest Devices */
134 	boolean_t earlyrtp;                                                                                     /*!< Channel State where to open the rtp media stream */
135 
136 	skinny_lampmode_t mwilamp;										/*!< MWI/Lamp (Length:3) */
137 	sccp_blindtransferindication_t blindtransferindication;							/*!< Blind Transfer Indication Support (Boolean, default=on = SCCP_BLINDTRANSFER_MOH) */
138 	sccp_nat_t nat;												/*!< Network Address Translation */
139 	sccp_call_answer_order_t callanswerorder;								/*!< Call Answer Order */
140 
141 #if ASTERISK_VERSION_NUMBER >= 10400
142 	struct ast_jb_conf *global_jbconf;									/*!< Global Jitter Buffer Configuration */
143 #endif
144 	char *servername;											/*!< ServerName */
145 	char *context;												/*!< Global / General Context */
146 	skinny_capabilities_t global_preferences;
147 	char *externhost;											/*!< External HostName */
148 	char *musicclass;											/*!< Music Class */
149 	char *language;												/*!< Language */
150 	char *accountcode;											/*!< Account Code */
151 	char *regcontext;											/*!< Context for auto-extension (DUNDI) */
152 #ifdef CS_SCCP_REALTIME
153 	char *realtimedevicetable;										/*!< Database Table Name for SCCP Devices */
154 	char *realtimelinetable;											/*!< Database Table Name for SCCP Lines */
155 #endif
156 	char used_context[SCCP_MAX_EXTENSION];									/*!< placeholder to check if context are already used in regcontext (DUNDI) */
157 
158 	char *config_file_name;											/*!< SCCP Config File Name in Use */
159 	struct ast_config *cfg;
160 	sccp_hotline_t *hotline;										/*!< HotLine */
161 
162 	char *token_fallback;											/*!< Fall back immediatly on TokenReq (true/false/odd/even) */
163 	int token_backoff_time;											/*!< Backoff time on TokenReject */
164 	int server_priority;											/*!< Server Priority to fallback to */
165 
166 	boolean_t reload_in_progress;										/*!< Reload in Progress */
167 	boolean_t pendingUpdate;
168 };														/*!< SCCP Global Varable Structure */
169 
170 /*!
171  * \brief Scheduler Tasks
172  * \note (NEW) Scheduler Implementation (NEW)
173  */
174 #define SCCP_SCHED_DEL(id) 												\
175 ({															\
176 	int _count = 0; 												\
177 	int _sched_res = -1; 												\
178 	while ((id) > -1 && (_sched_res = iPbx.sched_del((id))) && ++_count < 10) 					\
179 		usleep(1); 												\
180 	if (_count == 10) { 												\
181 		sccp_log((DEBUGCAT_CORE))(VERBOSE_PREFIX_3 "SCCP: Unable to cancel schedule ID %d.\n", (id)); 		\
182 	} 														\
183 	(id) = -1; 			/* this might be seen as a side effect */					\
184 	(_sched_res); 	 												\
185 })
186 
187 /* Global Allocations */
188 SCCP_API struct sccp_global_vars *sccp_globals;
189 
190 __END_C_EXTERN__
191 // kate: indent-width 8; replace-tabs off; indent-mode cstyle; auto-insert-doxygen on; line-numbers on; tab-indents on; keep-extra-spaces off; auto-brackets off;
192