Fixed compiling issues when enabling GSM MS side support.
[lcr.git] / apppbx.h
1 /*****************************************************************************\
2 **                                                                           **
3 ** Linux Call Router                                                         **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** EndpointAppPBX header file                                                **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12
13 enum { /* release actions: see epoint.release */
14         RELEASE_NONE,
15         RELEASE_JOIN,           /* join, hold */
16         RELEASE_PORT_JOINONLY,  /* join, port */
17         RELEASE_ALL,            /* join, hold, port */
18 };
19
20 enum { /* states as viewed from io port (state of calls are always connected) */
21         EPOINT_STATE_IDLE,              /* no call */
22         EPOINT_STATE_IN_SETUP,          /* setup sent */
23         EPOINT_STATE_OUT_SETUP,         /* setup sent */
24         EPOINT_STATE_IN_OVERLAP,        /* more information */
25         EPOINT_STATE_OUT_OVERLAP,       /* more information */
26         EPOINT_STATE_IN_PROCEEDING,     /* proceeding */
27         EPOINT_STATE_OUT_PROCEEDING,    /* proceeding */
28         EPOINT_STATE_IN_ALERTING,       /* ringing */
29         EPOINT_STATE_OUT_ALERTING,      /* ringing */
30         EPOINT_STATE_CONNECT,           /* connected */
31         EPOINT_STATE_IN_DISCONNECT,     /* disconnected receiving tones */
32         EPOINT_STATE_OUT_DISCONNECT,    /* disconnected sending tones */
33 };
34
35 #define EPOINT_STATE_NAMES \
36 static const char *state_name[] = { \
37         "EPOINT_STATE_IDLE", \
38         "EPOINT_STATE_IN_SETUP", \
39         "EPOINT_STATE_OUT_SETUP", \
40         "EPOINT_STATE_IN_OVERLAP", \
41         "EPOINT_STATE_OUT_OVERLAP", \
42         "EPOINT_STATE_IN_PROCEEDING", \
43         "EPOINT_STATE_OUT_PROCEEDING", \
44         "EPOINT_STATE_IN_ALERTING", \
45         "EPOINT_STATE_OUT_ALERTING", \
46         "EPOINT_STATE_CONNECT", \
47         "EPOINT_STATE_IN_DISCONNECT", \
48         "EPOINT_STATE_OUT_DISCONNECT", \
49 }; \
50 int state_name_num = sizeof(state_name) / sizeof(char *);
51
52 int vbox_refresh(struct lcr_timer *timer, void *instance, int index);
53
54 extern class EndpointAppPBX *apppbx_first;
55
56 /* structure of an EndpointAppPBX */
57 class EndpointAppPBX : public EndpointApp
58 {
59         public:
60         EndpointAppPBX(class Endpoint *epoint, int origin);
61         ~EndpointAppPBX();
62
63         class EndpointAppPBX    *next;
64
65         int                     e_hold;                 /* is this endpoint on hold ? */
66         char                    e_tone[256];            /* save tone for resuming ports */
67
68         unsigned int            e_adminid;
69
70         /* states */
71         int                     e_state;                /* state of endpoint */
72         char                    e_extension_interface[32];/* current internal isdn interface (usefull for callback to internal phone) */
73         struct caller_info      e_callerinfo;           /* information about the caller */
74         struct dialing_info     e_dialinginfo;          /* information about dialing */
75         struct connect_info     e_connectinfo;          /* information about connected line */
76         struct redir_info       e_redirinfo;            /* info about redirection (to the calling user) */
77         struct capa_info        e_capainfo;             /* info about l3,l2 capacity */
78         struct rtp_info         e_rtpinfo;              /* info about rtp port forwarding and payload type */
79         time_t                  e_start, e_stop;        /* time */
80         int                     e_origin;               /* origin of call 0=incoming 1=outgoing */
81         struct route_ruleset    *e_ruleset;             /* current ruleset pointer (NULL=no ruleset) */
82         struct route_rule       *e_rule;                /* current rule pointer (NULL=no rule) */
83         struct route_action     *e_action;              /* current action pointer (NULL=no action) */
84         int                     e_rule_nesting;         /* 'goto'/'menu' recrusion counter to prevent infinie loops */
85         struct route_action     *e_match_to_action;     /* what todo when timeout */
86         char                    *e_match_to_extdialing; /* dialing after matching timeout rule */
87         int                     e_select;               /* current selection for various selector options */
88         char                    *e_extdialing;          /* dialing after matching rule */
89         int             e_overlap;              /* is set if additional information is/are received after setup */
90         struct extension e_ext;                 /* extension information */
91
92 //      int e_knocking;                         /* true, if knocking */
93 //      double e_knocktime;                     /* next time to knock */
94
95 //      char e_join_tone[64], e_hold_tone[64];  /* current tone */
96         int e_join_pattern/*, e_hold_pattern*/; /* pattern available */
97
98         /* action */
99         char e_dialing_queue[32];               /* holds dialing during setup state */
100         double e_powerdelay;                    /* delay when to redial */
101         int e_powercount;                       /* power count */
102         int e_powerlimit;                       /* power limit */
103         struct lcr_timer        e_action_timeout;
104         struct lcr_timer        e_match_timeout;
105
106         /* port relation */
107         int e_multipoint_cause;                 /* cause value of disconnected multiport calls (highest priority) */
108         int e_multipoint_location;              /* location of cause with highest priority */
109
110         /* join relation */
111         int e_join_cause;
112         int e_join_location;    
113
114         /* callback */
115         char e_cbdialing[256];                  /* dialing information after callback */
116         char e_cbcaller[256];                   /* extension for the epoint which calls back */
117         char e_cbto[32];                        /* override callerid to call back to */
118         struct caller_info e_callbackinfo;      /* information about the callback caller */
119         struct lcr_timer        e_redial_timeout;
120         int e_powerdial_on;
121         struct lcr_timer        e_powerdial_timeout;
122         struct lcr_timer        e_cfnr_timeout;
123         struct lcr_timer        e_cfnr_call_timeout;
124         struct lcr_timer        e_callback_timeout;
125         struct lcr_timer        e_password_timeout;
126
127         /* dtmf stuff */
128         int e_connectedmode;                    /* if the port should stay connected if the enpoint disconnects or releases (usefull for callback) */
129         int e_dtmf;                             /* allow dtmf */
130         /* read doc/keypad.txt for more information */
131         int e_dtmf_time;                        /* time when the last key was received. */
132         int e_dtmf_last;                        /* last dtmf key */
133         int e_enablekeypad;                     /* remote app requests dtmf */
134
135         /* transmit and receive state */
136         int e_tx_state;                         /* current endpoint's state */
137         int e_rx_state;                         /* current endpoint's state */
138
139         /* vbox playback variables */
140         char e_vbox[32];                        /* current vbox extension (during playback) */
141         int e_vbox_state;                       /* state of vbox during playback */
142         int e_vbox_menu;                        /* currently selected menu using '*' and '#' */
143         char e_vbox_display[128];               /* current display message */
144         struct lcr_timer e_vbox_refresh;        /* display must be refreshed du to change */
145         int e_vbox_counter;                     /* current playback counter in seconds */
146         int e_vbox_counter_max;                 /* size of file in seconds */
147         int e_vbox_counter_last;                /* temp variable to recognise a change in seconds */
148         int e_vbox_play;                        /* current file that is played */
149         int e_vbox_speed;                       /* current speed to play */
150         int e_vbox_index_num;                   /* number of files */
151         char e_vbox_index_file[128];            /* current file name */
152         int e_vbox_index_hour;                  /* current time the file recorded... */
153         int e_vbox_index_min;
154         int e_vbox_index_mon;
155         int e_vbox_index_mday;
156         int e_vbox_index_year;
157         char e_vbox_index_callerid[128];        /* current caller id */
158         int e_vbox_index_callerid_index;        /* next digit to speak */
159
160         /* efi */
161         int e_efi_state;                        /* current spoken sample */
162         int e_efi_digit;                        /* current spoken digit */
163
164 #ifdef WITH_CRYPT
165         /* crypt states and vars */
166         int e_crypt;                            /* current user level crypt state */
167         int e_crypt_state;                      /* current crypt manager state */
168         char e_crypt_info[33];                  /* last information text */
169         int e_crypt_timeout_sec;                /* timer */
170         int e_crypt_timeout_usec;               /* timer */
171         unsigned int e_crypt_random;            /* current random number for ident */
172         unsigned int e_crypt_bogomips;          /* bogomips for ident */
173         unsigned char e_crypt_key[256];         /* the session key */
174         int e_crypt_key_len;
175         unsigned char e_crypt_ckey[256];        /* the encrypted session key */
176         int e_crypt_ckey_len;
177         unsigned char e_crypt_rsa_n[512];       /* rsa key */
178         unsigned char e_crypt_rsa_e[16];
179         unsigned char e_crypt_rsa_d[512];
180         unsigned char e_crypt_rsa_p[512];
181         unsigned char e_crypt_rsa_q[512];
182         unsigned char e_crypt_rsa_dmp1[512];
183         unsigned char e_crypt_rsa_dmq1[512];
184         unsigned char e_crypt_rsa_iqmp[512];
185         int e_crypt_rsa_n_len;
186         int e_crypt_rsa_e_len;
187         int e_crypt_rsa_d_len;
188         int e_crypt_rsa_p_len;
189         int e_crypt_rsa_q_len;
190         int e_crypt_rsa_dmp1_len;
191         int e_crypt_rsa_dmq1_len;
192         int e_crypt_rsa_iqmp_len;
193         int e_crypt_keyengine_busy;             /* current job and busy state */
194         int e_crypt_keyengine_return;           /* return */
195         struct lcr_timer e_crypt_handler; /* poll timer for crypt events */
196 #endif
197
198         /* messages */
199         void hookflash(void);
200         void ea_message_port(unsigned int port_id, int message, union parameter *param);
201         void port_setup(struct port_list *portlist, int message_type, union parameter *param);
202         void port_information(struct port_list *portlist, int message_type, union parameter *param);
203         void port_dtmf(struct port_list *portlist, int message_type, union parameter *param);
204         void port_crypt(struct port_list *portlist, int message_type, union parameter *param);
205         void port_overlap(struct port_list *portlist, int message_type, union parameter *param);
206         void port_proceeding(struct port_list *portlist, int message_type, union parameter *param);
207         void port_alerting(struct port_list *portlist, int message_type, union parameter *param);
208         void port_connect(struct port_list *portlist, int message_type, union parameter *param);
209         void port_disconnect_release(struct port_list *portlist, int message_type, union parameter *param);
210         void port_timeout(struct port_list *portlist, int message_type, union parameter *param);
211         void port_notify(struct port_list *portlist, int message_type, union parameter *param);
212         void port_progress(struct port_list *portlist, int message_type, union parameter *param);
213         void port_facility(struct port_list *portlist, int message_type, union parameter *param);
214         void port_suspend(struct port_list *portlist, int message_type, union parameter *param);
215         void port_resume(struct port_list *portlist, int message_type, union parameter *param);
216         void port_enablekeypad(struct port_list *portlist, int message_type, union parameter *param);
217         void ea_message_join(unsigned int join_id, int message, union parameter *param);
218         void join_crypt(struct port_list *portlist, int message_type, union parameter *param);
219         void join_mISDNsignal(struct port_list *portlist, int message_type, union parameter *param);
220         void join_bridge(struct port_list *portlist, int message_type, union parameter *param);
221         void join_setup(struct port_list *portlist, int message_type, union parameter *param);
222         void join_information(struct port_list *portlist, int message_type, union parameter *param);
223         void join_overlap(struct port_list *portlist, int message_type, union parameter *param);
224         void join_proceeding(struct port_list *portlist, int message_type, union parameter *param);
225         void join_alerting(struct port_list *portlist, int message_type, union parameter *param);
226         void join_connect(struct port_list *portlist, int message_type, union parameter *param);
227         void join_disconnect_release(int message_type, union parameter *param);
228         void join_notify(struct port_list *portlist, int message_type, union parameter *param);
229         void join_facility(struct port_list *portlist, int message_type, union parameter *param);
230         void join_dtmf(struct port_list *portlist, int message_type, union parameter *param);
231
232         /* epoint */
233         void new_state(int state);
234         void release(int release, int joinlocation, int joincause, int portlocation, int portcause, int force);
235         void notify_active(void);
236         void keypad_function(char digit);
237         void set_tone(struct port_list *portlist, const char *tone);
238         void out_setup(int cfnr);
239         char *apply_callerid_display(const char *id, int itype, int ntype, int present, int screen, const char *extension, const char *name);
240         void auth(int job, int bit_num);
241
242         /* vbox playback stuff */
243         void vbox_init(void);
244         void vbox_index_read(int num);
245         void vbox_index_remove(int num);
246         void efi_message_eof(void);
247         void vbox_message_eof(void);
248         void set_tone_vbox(const char *tone);
249         void set_play_vbox(const char *file, int offset);
250         void set_play_speed(int speed);
251
252         /* efi */
253         void set_tone_efi(const char *tone);
254         
255         /* routing */
256         struct route_ruleset *rulesetbyname(char *name);
257         struct route_action *route(struct route_ruleset *ruleset);
258         struct route_param *routeparam(struct route_action *action, unsigned long long id);
259
260         /* init / dialing / hangup */
261         int _action_init_call(char *remote);
262         void action_init_call(void);
263         void action_init_remote(void);
264         void action_dialing_internal(void);
265         void action_dialing_external(void);
266         void action_dialing_h323(void);
267         void action_dialing_remote(void);
268         void action_dialing_vbox_record(void);
269         void action_init_partyline(void);
270         void action_hangup_call(void);
271         void action_dialing_login(void);
272         void action_init_change_callerid(void);
273         void _action_callerid_calleridnext(int next);
274         void action_dialing_callerid(void);
275         void action_dialing_calleridnext(void);
276         void action_init_change_forward(void);
277         void action_dialing_forward(void);
278         void action_init_redial_reply(void);
279         void _action_redial_reply(int in);
280         void action_dialing_redial(void);
281         void action_dialing_reply(void);
282         void action_dialing_powerdial(void);
283         void action_dialing_callback(void);
284         void action_hangup_callback(void);
285         void action_dialing_abbrev(void);
286         void action_dialing_test(void);
287         void action_init_play(void);
288         void action_init_vbox_play(void);
289         void action_init_efi(void);
290         void action_dialing_vbox_play(void);
291         void action_dialing_calculator(void);
292         void action_dialing_timer(void);
293         void _action_goto_menu(int mode);
294         void action_dialing_goto(void);
295         void action_dialing_menu(void);
296         void action_dialing_disconnect(void);
297         void action_dialing_release(void);
298         void action_dialing_help(void);
299         void action_dialing_deflect(void);
300         void action_dialing_setforward(void);
301         void action_init_execute(void);
302         void action_hangup_execute(void);
303         void action_execute(void);
304         void action_hangup_file(void);
305         void action_init_pick(void);
306         void action_dialing_password(void);
307         void action_dialing_password_wr(void);
308         void process_dialing(int timeout);
309         void process_hangup(int cause, int location);
310
311         /* facility function */
312         void pick_join(char *extension);
313         void join_join(void);
314         void encrypt_shared(void);
315         void encrypt_keyex(void);
316         void encrypt_off(void);
317         void encrypt_result(int message, char *text);
318         int check_external(const char **errstr, class Port **port);
319
320         /* crypt */
321         void cryptman_keyengine(int job);
322         void cr_ident(int message, unsigned char *param, int len);
323         void cr_activate(int message, unsigned char *param, int len);
324         void cr_deactivate(int message, unsigned char *param, int len);
325         void cr_master(int message, unsigned char *param, int len);
326         void cr_slave(int message, unsigned char *param, int len);
327         void cr_looped(int message, unsigned char *param, int len);
328         void cr_abort(int message, unsigned char *param, int len);
329         void cr_abort_engine(int message, unsigned char *param, int len);
330         void cr_abort_wait(int message, unsigned char *param, int len);
331         void cr_genrsa(int message, unsigned char *param, int len);
332         void cr_keyerror(int message, unsigned char *param, int len);
333         void cr_pubkey(int message, unsigned char *param, int len);
334         void cr_cptrsa(int message, unsigned char *param, int len);
335         void cr_cskey(int message, unsigned char *param, int len);
336         void cr_decrsa(int message, unsigned char *param, int len);
337         void cr_waitdelay(int message, unsigned char *param, int len);
338         void cr_bfactive(int message, unsigned char *param, int len);
339         void cr_crypterror(int message, unsigned char *param, int len);
340         void cr_release(int message, unsigned char *param, int len);
341         void cr_sactivate(int message, unsigned char *param, int len);
342         void cr_sdeactivate(int message, unsigned char *param, int len);
343         void cr_sbfactive(int message, unsigned char *param, int len);
344         void cr_scrypterror(int message, unsigned char *param, int len);
345         void cr_sabort(int message, unsigned char *param, int len);
346         void cr_info(int message, unsigned char *param, int len);
347         void cryptman_message(int message, unsigned char *param, int len);
348         void cryptman_msg2man(unsigned char *param, int len);
349         void cryptman_addinf(unsigned char *buf, int buf_size, int element, int len, void *data);
350         int cryptman_sizeofinf(unsigned char *buf, int element);
351         unsigned char *cryptman_getinf(unsigned char *buf, int element, unsigned char *to);
352         void cryptman_msg2peer(unsigned char *buf);
353         void cryptman_msg2user(int msg, const char *text);
354         void cryptman_msg2crengine(int msg, unsigned char *buf, int len);
355         void cryptman_state(int state);
356         void cryptman_timeout(int secs);
357         void message_disconnect_port(struct port_list *portlist, int cause, int location, const char *display);
358         void logmessage(int message_type, union parameter *param, unsigned int port_id, int dir);
359         void trace_header(const char *name, int direction);
360 };
361
362
363 void apply_callerid_restriction(struct extension *ext, char *id, int *ntype, int *present, int *screen, char *extension, char *name);
364 void send_mail(char *filename, char *callerid, char *callerintern, char *callername, char *vbox_email, int vbox_year, int vbox_mon, int vbox_mday, int vbox_hour, int vbox_min, char *terminal);
365
366