Fix: Correctly forward facility IE content
[lcr.git] / action.cpp
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** all actions (and hangup) are processed here                               **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include "main.h"
13
14 extern char **environ;
15
16
17 /*
18  * process init 'internal' / 'external' / 'vbox-record' / 'partyline'...
19  */
20 void EndpointAppPBX::action_init_call(void)
21 {
22         class Join              *join;
23
24         /* a created call, this should never happen */
25         if (ea_endpoint->ep_join_id) {
26                 if (options.deb & DEBUG_EPOINT)
27                         PERROR("EPOINT(%d): We already have a call instance, this should never happen!\n", ea_endpoint->ep_serial);
28                 return;
29         }
30
31         /* create join */
32         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
33         join = new JoinPBX(ea_endpoint);
34         if (!join)
35                 FATAL("No memoy for Join instance.\n");
36         ea_endpoint->ep_join_id = join->j_serial;
37         return;
38 }
39
40 /*
41  * process dialing 'internal'
42  */
43 void EndpointAppPBX::action_dialing_internal(void)
44 {
45         struct capa_info        capainfo;
46         struct caller_info      callerinfo;
47         struct redir_info       redirinfo;
48         struct rtp_info         rtpinfo;
49         struct dialing_info     dialinginfo;
50         struct port_list        *portlist = ea_endpoint->ep_portlist;
51         struct lcr_msg          *message;
52         struct extension        ext;
53         struct route_param      *rparam;
54
55         /* send proceeding, because number is complete */
56         set_tone(portlist, "proceeding");
57         message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
58         message_put(message);
59         logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
60         new_state(EPOINT_STATE_IN_PROCEEDING);
61
62         /* create bearer/caller/dialinginfo */
63         memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
64         memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
65         memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
66         memcpy(&rtpinfo, &e_rtpinfo, sizeof(rtpinfo));
67         memset(&dialinginfo, 0, sizeof(dialinginfo));
68         dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
69         SCPY(dialinginfo.id, e_dialinginfo.id);
70
71         /* process extension */
72         if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
73                 SCPY(dialinginfo.id, rparam->string_value);
74
75         /* process number type */
76         if ((rparam = routeparam(e_action, PARAM_TYPE)))
77                 dialinginfo.ntype = rparam->integer_value;
78
79         /* process service */
80         if ((rparam = routeparam(e_action, PARAM_CAPA))) {
81                 capainfo.bearer_capa = rparam->integer_value;
82                 if (capainfo.bearer_capa != INFO_BC_SPEECH
83                  && capainfo.bearer_capa != INFO_BC_AUDIO) {
84                         capainfo.bearer_mode = INFO_BMODE_PACKET;
85                 }
86                 capainfo.bearer_info1 = INFO_INFO1_NONE;
87                 capainfo.hlc = INFO_HLC_NONE;
88                 capainfo.exthlc = INFO_HLC_NONE;
89         }
90         if ((rparam = routeparam(e_action, PARAM_BMODE))) {
91                 capainfo.bearer_mode = rparam->integer_value;
92         }
93         if ((rparam = routeparam(e_action, PARAM_INFO1))) {
94                 capainfo.bearer_info1 = rparam->integer_value;
95         }
96         if ((rparam = routeparam(e_action, PARAM_HLC))) {
97                 capainfo.hlc = rparam->integer_value;
98         }
99         if ((rparam = routeparam(e_action, PARAM_EXTHLC))) {
100                 capainfo.exthlc = rparam->integer_value;
101         }
102
103         /* process presentation */
104         if ((rparam = routeparam(e_action, PARAM_PRESENT))) {
105                 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
106         }
107
108         /* check if extension exists AND only if not multiple extensions */
109         if (!strchr(dialinginfo.id,',') && !read_extension(&ext, dialinginfo.id)) {
110                 trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE);
111                 add_trace("extension", NULL, dialinginfo.id);
112                 end_trace();
113                 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
114                 new_state(EPOINT_STATE_OUT_DISCONNECT);
115                 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
116                 set_tone(portlist, "cause_86");
117                 return;
118         }
119         /* check if internal calls are denied */
120         if (e_ext.rights < 1) {
121                 trace_header("ACTION extension (dialing to extension denied)", DIRECTION_NONE);
122                 add_trace("extension", NULL, dialinginfo.id);
123                 end_trace();
124                 new_state(EPOINT_STATE_OUT_DISCONNECT);
125                 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
126                 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
127                 set_tone(portlist, "cause_81");
128                 return;
129         }
130
131         /* add or update internal call */
132         trace_header("ACTION extension (calling)", DIRECTION_NONE);
133         add_trace("extension", NULL, dialinginfo.id);
134         end_trace();
135         message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
136         memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
137         memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
138         memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
139         memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
140         memcpy(&message->param.setup.rtpinfo, &rtpinfo, sizeof(struct rtp_info));
141         message_put(message);
142 }
143
144 /* process dialing external
145  */
146 void EndpointAppPBX::action_dialing_external(void)
147 {
148         struct capa_info capainfo;
149         struct caller_info callerinfo;
150         struct redir_info redirinfo;
151         struct rtp_info rtpinfo;
152         struct dialing_info dialinginfo;
153         char *p;
154         struct port_list *portlist = ea_endpoint->ep_portlist;
155         struct lcr_msg *message;
156         struct route_param *rparam;
157
158         /* special processing of delete characters '*' and '#' */
159         if (e_ext.delete_ext) {
160                 /* dialing a # causes a clearing of complete number */
161                 if (strchr(e_extdialing, '#')) {
162                         e_extdialing[0] = '\0';
163                         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): '#' detected: terminal '%s' selected caller id '%s' and continues dialing: '%s'\n", ea_endpoint->ep_serial, e_ext.number, e_callerinfo.id, e_extdialing);
164                 }
165                 /* eliminate digits before '*', which is a delete digit
166                  */
167                 if (strchr(e_extdialing, '*')) {
168                         /* remove digits */
169                         while((p=strchr(e_extdialing, '*'))) {
170                                 if (p > e_extdialing) { /* only if there is a digit in front */
171                                         UCPY(p-1, p);
172                                         p--;
173                                 }
174                                 UCPY(p, p+1); /* remove '*' */
175                         }
176                         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s deleted digits and got new string: %s\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing);
177                 }
178         }
179
180         /* create bearer/caller/dialinginfo */
181         memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
182         memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
183         memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
184         memcpy(&rtpinfo, &e_rtpinfo, sizeof(rtpinfo));
185         memset(&dialinginfo, 0, sizeof(dialinginfo));
186         dialinginfo.itype = INFO_ITYPE_ISDN;
187 //      dialinginfo.sending_complete = 0;
188         SCPY(dialinginfo.id, e_extdialing);
189
190         /* process prefix */
191         if ((rparam = routeparam(e_action, PARAM_PREFIX)))
192                 SPRINT(dialinginfo.id, "%s%s", rparam->string_value, e_extdialing);
193
194         if ((rparam = routeparam(e_action, PARAM_CONTEXT)))
195                 SCPY(dialinginfo.context, rparam->string_value);
196
197         /* process keypad */
198         if ((rparam = routeparam(e_action, PARAM_KEYPAD))) {
199                 SCPY(dialinginfo.keypad, dialinginfo.id);
200                 dialinginfo.id[0] = '\0';
201         }
202
203         /* process number complete */
204         if ((rparam = routeparam(e_action, PARAM_COMPLETE)))
205                 dialinginfo.sending_complete = 1;
206
207         /* process number type */
208         if ((rparam = routeparam(e_action, PARAM_TYPE)))
209                 dialinginfo.ntype = rparam->integer_value;
210
211         /* process service */
212         if ((rparam = routeparam(e_action, PARAM_CAPA))) {
213                 capainfo.bearer_capa = rparam->integer_value;
214                 if (capainfo.bearer_capa != INFO_BC_SPEECH
215                  && capainfo.bearer_capa != INFO_BC_AUDIO) {
216                         capainfo.bearer_mode = INFO_BMODE_PACKET;
217                 }
218                 capainfo.bearer_info1 = INFO_INFO1_NONE;
219                 capainfo.hlc = INFO_HLC_NONE;
220                 capainfo.exthlc = INFO_HLC_NONE;
221         }
222         if ((rparam = routeparam(e_action, PARAM_BMODE))) {
223                 capainfo.bearer_mode = rparam->integer_value;
224         }
225         if ((rparam = routeparam(e_action, PARAM_INFO1))) {
226                 capainfo.bearer_info1 = rparam->integer_value;
227         }
228         if ((rparam = routeparam(e_action, PARAM_HLC))) {
229                 capainfo.hlc = rparam->integer_value;
230         }
231         if ((rparam = routeparam(e_action, PARAM_EXTHLC))) {
232                 capainfo.exthlc = rparam->integer_value;
233         }
234
235
236         /* process callerid */
237         if ((rparam = routeparam(e_action, PARAM_CALLERID))) {
238                 SCPY(callerinfo.id, rparam->string_value);
239         }
240         if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE))) {
241                 callerinfo.ntype = rparam->integer_value;
242         }
243
244         /* process presentation */
245         if ((rparam = routeparam(e_action, PARAM_PRESENT))) {
246                 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
247         }
248
249         /* process interfaces */
250         if ((rparam = routeparam(e_action, PARAM_INTERFACES)))
251                 SCPY(dialinginfo.interfaces, rparam->string_value);
252
253         /* check if local calls are denied */
254         if (e_ext.rights < 2) {
255                 trace_header("ACTION extern (calling denied)", DIRECTION_NONE);
256                 end_trace();
257                 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
258                 set_tone(portlist, "cause_82");
259                 denied:
260                 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
261                 new_state(EPOINT_STATE_OUT_DISCONNECT);
262                 return;
263         }
264
265         if (!strncmp(dialinginfo.id, options.national, strlen(options.national))
266          || dialinginfo.ntype == INFO_NTYPE_NATIONAL
267          || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL) {
268                 /* check if national calls are denied */
269                 if (e_ext.rights < 3) {
270                         trace_header("ACTION extern (national calls denied)", DIRECTION_NONE);
271                         end_trace();
272                         release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
273                         set_tone(portlist, "cause_83");
274                         goto denied;
275                 }
276         }
277
278         if (!strncmp(dialinginfo.id, options.international, strlen(options.international))
279          || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL) {
280                 /* check if international calls are denied */
281                 if (e_ext.rights < 4) {
282                         trace_header("ACTION extern (international calls denied)", DIRECTION_NONE);
283                         end_trace();
284                         release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
285                         set_tone(portlist, "cause_84");
286                         goto denied;
287                 }
288         }
289
290         /* add or update outgoing call */
291         trace_header("ACTION extern (calling)", DIRECTION_NONE);
292         add_trace("number", NULL, dialinginfo.id);
293         if (dialinginfo.sending_complete)
294         add_trace("number", "complete", "yes");
295         if (dialinginfo.interfaces[0])
296                 add_trace("interfaces", NULL, dialinginfo.interfaces);
297         end_trace();
298         message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
299         memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
300         memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
301         memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
302         memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
303         memcpy(&message->param.setup.rtpinfo, &rtpinfo, sizeof(struct rtp_info));
304         message_put(message);
305 }
306
307
308 /*
309  * process dialing the "am" and record
310  */
311 void EndpointAppPBX::action_dialing_vbox_record(void)
312 {
313         struct dialing_info dialinginfo;
314         struct port_list *portlist = ea_endpoint->ep_portlist;
315         struct lcr_msg *message;
316         struct extension ext;
317         struct route_param *rparam;
318
319         portlist = ea_endpoint->ep_portlist;
320
321         /* check for given extension */
322         if (!(rparam = routeparam(e_action, PARAM_EXTENSION))) {
323                 trace_header("ACTION vbox-record (no extension given by parameter)", DIRECTION_NONE);
324                 end_trace();
325
326                 new_state(EPOINT_STATE_OUT_DISCONNECT);
327                 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
328                 set_tone(portlist, "cause_3f");
329                 return;
330         }
331
332         /* check if extension exists */
333         if (!read_extension(&ext, rparam->string_value)) {
334                 trace_header("ACTION vbox-record (given extension does not exists)", DIRECTION_NONE);
335                 add_trace("extension", NULL, "%s", rparam->string_value);
336                 end_trace();
337                 new_state(EPOINT_STATE_OUT_DISCONNECT);
338                 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
339                 set_tone(portlist, "cause_86");
340                 return;
341         }
342
343         /* check if internal calls are denied */
344         if (e_ext.rights < 1) {
345                 trace_header("ACTION vbox-record (internal calls are denied)", DIRECTION_NONE);
346                 end_trace();
347                 new_state(EPOINT_STATE_OUT_DISCONNECT);
348                 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
349                 set_tone(portlist, "cause_81");
350                 return;
351         }
352
353         set_tone(portlist, "proceeding");
354         message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
355         message_put(message);
356         logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
357         new_state(EPOINT_STATE_IN_PROCEEDING);
358
359         memset(&dialinginfo, 0, sizeof(dialinginfo));
360         dialinginfo.itype = INFO_ITYPE_VBOX;
361         dialinginfo.sending_complete = 1;
362         SCPY(dialinginfo.id, rparam->string_value);
363
364         /* append special announcement (if given) */
365         if ((rparam = routeparam(e_action, PARAM_ANNOUNCEMENT)))
366         if (rparam->string_value[0]) {
367                 SCAT(dialinginfo.id, ",");
368                 SCAT(dialinginfo.id, rparam->string_value);
369         }
370
371         /* add or update internal call */
372         trace_header("ACTION vbox-record (calling)", DIRECTION_NONE);
373         add_trace("extension", NULL, "%s", dialinginfo.id);
374         end_trace();
375         message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
376         memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
377         memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
378         memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
379         memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
380         message_put(message);
381 }
382
383
384 /*
385  * process partyline
386  */
387 void EndpointAppPBX::action_init_partyline(void)
388 {
389         class Join *join;
390         class JoinPBX *joinpbx;
391         struct port_list *portlist = ea_endpoint->ep_portlist;
392         struct lcr_msg *message;
393         struct route_param *rparam;
394         int partyline, jingle = 0;
395         struct join_relation *relation;
396
397         portlist = ea_endpoint->ep_portlist;
398
399         /* check for given extension */
400         if (!(rparam = routeparam(e_action, PARAM_ROOM))) {
401                 trace_header("ACTION partyline (no room parameter)", DIRECTION_NONE);
402                 end_trace();
403                 noroom:
404                 new_state(EPOINT_STATE_OUT_DISCONNECT);
405                 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
406                 set_tone(portlist, "cause_3f");
407                 return;
408         }
409         if (rparam->integer_value <= 0) {
410                 trace_header("ACTION partyline (illegal room parameter)", DIRECTION_NONE);
411                 add_trace("room", NULL, "%d", rparam->integer_value);
412                 end_trace();
413                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): invalid value for 'room'.\n", ea_endpoint->ep_serial);
414                 goto noroom;
415         }
416         partyline = rparam->integer_value;
417         if ((rparam = routeparam(e_action, PARAM_JINGLE)))
418                 jingle = 1;
419
420         /* don't create join if partyline exists */
421         join = join_first;
422         while(join) {
423                 if (join->j_type == JOIN_TYPE_PBX) {
424                         joinpbx = (class JoinPBX *)join;
425                         if (joinpbx->j_partyline == partyline)
426                                 break;
427                 }
428                 join = join->next;
429         }
430         if (!join) {
431                 /* create join */
432                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
433                 if (!(join = new JoinPBX(ea_endpoint)))
434                         FATAL("No memory for join object\n");
435         } else {
436 //NOTE: joinpbx must be set here
437                 /* add relation to existing join */
438                 if (!(relation=joinpbx->add_relation()))
439                         FATAL("No memory for join relation\n");
440                 relation->type = RELATION_TYPE_SETUP;
441                 relation->channel_state = 1;
442                 relation->rx_state = NOTIFY_STATE_ACTIVE;
443                 relation->tx_state = NOTIFY_STATE_ACTIVE;
444                 relation->epoint_id = ea_endpoint->ep_serial;
445
446         }
447         ea_endpoint->ep_join_id = join->j_serial;
448
449         set_tone(portlist, "proceeding");
450         message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
451         message_put(message);
452         logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
453         new_state(EPOINT_STATE_IN_PROCEEDING);
454
455         /* send setup to join */
456         trace_header("ACTION partyline (calling)", DIRECTION_NONE);
457         add_trace("room", NULL, "%d", partyline);
458         add_trace("jingle", NULL, (jingle)?"on":"off");
459         end_trace();
460         message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
461         message->param.setup.partyline = partyline;
462         message->param.setup.partyline_jingle = jingle;
463         memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info));
464         memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
465         memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
466         memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
467         message_put(message);
468 }
469
470
471 /*
472  * process hangup of all calls
473  */
474 void EndpointAppPBX::action_hangup_call(void)
475 {
476         trace_header("ACTION hangup", DIRECTION_NONE);
477         end_trace();
478 }
479
480
481 /*
482  * process dialing 'login'
483  */
484 void EndpointAppPBX::action_dialing_login(void)
485 {
486         struct port_list *portlist = ea_endpoint->ep_portlist;
487         struct lcr_msg *message;
488         char *extension;
489         struct route_param *rparam;
490
491         /* extension parameter */
492         if ((rparam = routeparam(e_action, PARAM_EXTENSION))) {
493                 /* extension is given by parameter */
494                 extension = rparam->string_value;
495                 if (extension[0] == '\0')
496                         return;
497                 if (!read_extension(&e_ext, extension)) {
498                         trace_header("ACTION login (extension doesn't exist)", DIRECTION_NONE);
499                         add_trace("extension", NULL, "%s", extension);
500                         end_trace();
501                         /* extension doesn't exist */
502                         new_state(EPOINT_STATE_OUT_DISCONNECT);
503                         message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
504                         set_tone(portlist, "cause_86");
505                         return;
506                 }
507         } else {
508                 /* extension must be given by dialstring */
509                 extension = e_extdialing;
510                 if (extension[0] == '\0')
511                         return;
512                 if (!read_extension(&e_ext, extension)) {
513                         trace_header("ACTION login (extension incomplete or does not exist)", DIRECTION_NONE);
514                         add_trace("extension", NULL, "%s", extension);
515                         end_trace();
516                         return;
517                 }
518         }
519
520         /* we changed our extension */
521         SCPY(e_ext.number, extension);
522         new_state(EPOINT_STATE_CONNECT);
523         e_dtmf = 1;
524         e_connectedmode = 1;
525
526         /* send connect with extension's caller id (COLP) */
527         message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
528         SCPY(message->param.connectinfo.id, e_ext.callerid);
529         message->param.connectinfo.ntype = e_ext.callerid_type;
530         if (e_ext.callerid_present==INFO_PRESENT_ALLOWED && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
531                 message->param.connectinfo.present = INFO_PRESENT_RESTRICTED;
532         else    message->param.connectinfo.present = e_ext.callerid_present;
533         /* handle restricted caller ids */
534         apply_callerid_restriction(&e_ext, message->param.connectinfo.id, &message->param.connectinfo.ntype, &message->param.connectinfo.present, &message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name);
535         /* display callerid if desired for extension */
536         SCPY(message->param.connectinfo.display, apply_callerid_display(message->param.connectinfo.id, message->param.connectinfo.itype, message->param.connectinfo.ntype, message->param.connectinfo.present, message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name));
537         message->param.connectinfo.ntype = e_ext.callerid_type;
538         message_put(message);
539         logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
540
541         /* set our caller id */
542         SCPY(e_callerinfo.id, e_ext.callerid);
543         e_callerinfo.ntype = e_ext.callerid_type;
544         e_callerinfo.present = e_ext.callerid_present;
545
546         /* enable connectedmode */
547         e_connectedmode = 1;
548         e_dtmf = 1;
549
550         if (!(rparam = routeparam(e_action, PARAM_NOPASSWORD))) {
551                 /* make call state to enter password */
552                 trace_header("ACTION login (ask for password)", DIRECTION_NONE);
553                 add_trace("extension", NULL, "%s", e_ext.number);
554                 end_trace();
555                 new_state(EPOINT_STATE_IN_OVERLAP);
556                 e_ruleset = NULL;
557                 e_rule = NULL;
558                 e_action = &action_password;
559                 unsched_timer(&e_match_timeout);
560                 e_match_to_action = NULL;
561                 e_dialinginfo.id[0] = '\0';
562                 e_extdialing = strchr(e_dialinginfo.id, '\0');
563
564                 /* set timeout */
565                 schedule_timer(&e_password_timeout, 20, 0);
566
567                 /* do dialing */
568                 process_dialing(0);
569         } else {
570                 /* make call state  */
571                 new_state(EPOINT_STATE_IN_OVERLAP);
572                 e_ruleset = ruleset_main;
573                 if (e_ruleset)
574                         e_rule = e_ruleset->rule_first;
575                 e_action = NULL;
576                 e_dialinginfo.id[0] = '\0';
577                 e_extdialing = e_dialinginfo.id;
578                 set_tone(portlist, "dialpbx");
579         }
580 }
581
582
583 /*
584  * process init 'change_callerid'
585  */
586 void EndpointAppPBX::action_init_change_callerid(void)
587 {
588         struct port_list *portlist = ea_endpoint->ep_portlist;
589
590         if (!e_ext.change_callerid) {
591                 /* service not available */
592                 trace_header("ACTION change-callerid (denied for this caller)", DIRECTION_NONE);
593                 end_trace();
594                 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
595                 new_state(EPOINT_STATE_OUT_DISCONNECT);
596                 set_tone(portlist,"cause_87");
597                 return;
598         }
599 }
600
601 /* process dialing callerid
602  */
603 void EndpointAppPBX::_action_callerid_calleridnext(int next)
604 {
605         struct port_list *portlist = ea_endpoint->ep_portlist;
606         struct route_param *rparam;
607         char buffer[64], *callerid;
608         char old_id[64] = "", new_id[64] = "";
609         int old_type=0, new_type=0, old_present=0, new_present=0;
610
611         if ((rparam = routeparam(e_action, PARAM_CALLERID))) {
612                 /* the caller ID is given by parameter */
613                 callerid = rparam->string_value;
614         } else {
615                 /* caller ID is dialed */
616                 if (!strchr(e_extdialing, '#')) {
617                         /* no complete ID yet */
618                         return;
619                 }
620                 *strchr(e_extdialing, '#') = '\0';
621                 callerid = e_extdialing;
622         }
623
624         /* given callerid type */
625         if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
626                 switch(rparam->integer_value) {
627                         case INFO_NTYPE_SUBSCRIBER:
628                         SPRINT(buffer, "s%s", callerid);
629                         callerid = buffer;
630                         break;
631                         case INFO_NTYPE_NATIONAL:
632                         SPRINT(buffer, "n%s", callerid);
633                         callerid = buffer;
634                         break;
635                         case INFO_NTYPE_INTERNATIONAL:
636                         SPRINT(buffer, "i%s", callerid);
637                         callerid = buffer;
638                         break;
639                         default:
640                         SPRINT(buffer, "%s", callerid);
641                         callerid = buffer;
642                         break;
643                 }
644
645         /* caller id complete, dialing with new caller id */
646         /* write new parameters */
647         if (read_extension(&e_ext, e_ext.number)) {
648                 old_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
649                 old_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
650                 SCPY(old_id, (!next)?e_ext.callerid:e_ext.id_next_call);
651                 if (callerid[0] == '\0') {
652                         /* no caller id */
653                         (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
654                 } else {
655                         /* new caller id */
656                         (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_ALLOWED;
657                         if ((rparam = routeparam(e_action, PARAM_PRESENT))) if (rparam->integer_value == 0)
658                                 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
659                         if (e_ext.callerid_type == INFO_NTYPE_UNKNOWN) /* if callerid is unknown, the given id is not nationalized */ {
660                                 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, callerid);
661                                 (!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN;
662                         } else {
663                                 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, nationalize_callerinfo(callerid,&((!next)?e_ext.callerid_type:e_ext.id_next_call_type), options.national, options.international));
664                         }
665                         if (!next) e_ext.id_next_call_type = -1;
666                         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): nationalized callerid: '%s' type=%d\n", ea_endpoint->ep_serial, (!next)?e_ext.callerid:e_ext.id_next_call, (!next)?e_ext.callerid_type:e_ext.id_next_call_type);
667                 }
668                 new_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
669                 new_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
670                 SCPY(new_id, (!next)?e_ext.callerid:e_ext.id_next_call);
671                 write_extension(&e_ext, e_ext.number);
672         }
673
674         /* function activated */
675         if (next)
676                 trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE);
677         else
678                 trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE);
679         add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type, options.national, options.international));
680         add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
681         add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type, options.national, options.international));
682         add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
683         end_trace();
684         message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
685         new_state(EPOINT_STATE_OUT_DISCONNECT);
686         set_tone(portlist,"activated");
687 }
688
689 /* process dialing callerid for all call
690  */
691 void EndpointAppPBX::action_dialing_callerid(void)
692 {
693         _action_callerid_calleridnext(0);
694 }
695
696 /* process dialing callerid for next call
697  */
698 void EndpointAppPBX::action_dialing_calleridnext(void)
699 {
700         _action_callerid_calleridnext(1);
701 }
702
703
704 /*
705  * process init 'change_forward'
706  */
707 void EndpointAppPBX::action_init_change_forward(void)
708 {
709         struct port_list *portlist = ea_endpoint->ep_portlist;
710
711         if (!e_ext.change_forward) {
712                 trace_header("ACTION change-forward (denied for this caller)", DIRECTION_NONE);
713                 end_trace();
714                 /* service not available */             
715                 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
716                 new_state(EPOINT_STATE_OUT_DISCONNECT);
717                 set_tone(portlist,"cause_87");
718                 return;
719         }
720 }
721
722 /* process dialing forwarding
723  */
724 void EndpointAppPBX::action_dialing_forward(void)
725 {
726         struct port_list *portlist = ea_endpoint->ep_portlist;
727         int diversion = INFO_DIVERSION_CFU;
728         char *dest = e_extdialing;
729         struct route_param *rparam;
730
731         /* if diversion type is given */
732         if ((rparam = routeparam(e_action, PARAM_DIVERSION)))
733                 diversion = rparam->integer_value;
734
735         if ((rparam = routeparam(e_action, PARAM_DEST))) {
736                 /* if destination is given */
737                 dest = rparam->string_value;
738         } else {
739                 if (!strchr(e_extdialing, '#'))
740                         return;
741                 *strchr(e_extdialing, '#') = '\0';
742                 dest = e_extdialing;
743         }
744
745         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing forwarding to '%s'.\n", ea_endpoint->ep_serial, e_ext.number, dest);
746         if (read_extension(&e_ext, e_ext.number)) {
747                 switch(diversion) {
748                         case INFO_DIVERSION_CFU:
749                         trace_header("ACTION change-forward (new CFU=unconditional)", DIRECTION_NONE);
750                         add_trace("destin'", NULL, "%s", dest);
751                         end_trace();
752                         SCPY(e_ext.cfu, dest);
753                         break;
754                         case INFO_DIVERSION_CFB:
755                         trace_header("ACTION change-forward (new CFB=busy)", DIRECTION_NONE);
756                         add_trace("destin'", NULL, "%s", dest);
757                         end_trace();
758                         SCPY(e_ext.cfb, dest);
759                         break;
760                         case INFO_DIVERSION_CFNR:
761                         if ((rparam = routeparam(e_action, PARAM_DELAY)))
762                                 e_ext.cfnr_delay = rparam->integer_value;
763                         trace_header("ACTION change-forward (new CFNR=no response)", DIRECTION_NONE);
764                         add_trace("destin'", NULL, "%s", dest);
765                         add_trace("delay", NULL, "%s", e_ext.cfnr_delay);
766                         end_trace();
767                         SCPY(e_ext.cfnr, dest);
768                         break;
769                         case INFO_DIVERSION_CFP:
770                         trace_header("ACTION change-forward (new CFP=parallel)", DIRECTION_NONE);
771                         add_trace("destin'", NULL, "%s", dest);
772                         end_trace();
773                         SCPY(e_ext.cfp, dest);
774                         break;
775                 }
776                 write_extension(&e_ext, e_ext.number);
777         }
778         /* function (de)activated */
779         message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
780         new_state(EPOINT_STATE_OUT_DISCONNECT);
781         if (dest[0])
782                 set_tone(portlist,"activated");
783         else
784                 set_tone(portlist,"deactivated");
785 }
786
787
788 /* process dialing redial
789 */
790 void EndpointAppPBX::action_init_redial_reply(void)
791 {
792         struct port_list *portlist = ea_endpoint->ep_portlist;
793
794         e_select = 0;
795         if (!e_ext.last_out[0]) {
796                 trace_header("ACTION redial/reply (no last number stored)", DIRECTION_NONE);
797                 end_trace();
798                 new_state(EPOINT_STATE_OUT_DISCONNECT);
799                 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
800                 set_tone(portlist, "cause_3f");
801                 return;
802         }
803 }
804
805 /* process dialing redial
806 */
807 void EndpointAppPBX::_action_redial_reply(int in)
808 {
809         struct lcr_msg *message;
810         char *last;
811         struct route_param *rparam;
812
813         last = (in)?e_ext.last_in[0]:e_ext.last_out[0];
814
815         /* if no display is available */
816         if (!e_ext.display_menu)
817                 goto nodisplay;
818         if (ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_IN && ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_OUT)
819                 goto nodisplay;
820
821         /* if select is not given */
822         if (!(rparam = routeparam(e_action, PARAM_SELECT)))
823                 goto nodisplay;
824
825         /* scroll menu */
826         if (e_extdialing[0]=='*' || e_extdialing[0]=='1') {
827                 /* find prev entry */
828                 e_select--;
829                 if (e_select < 0)
830                         e_select = 0;
831
832         }
833         if (e_extdialing[0]=='#' || e_extdialing[0]=='3') {
834                 /* find next entry */
835                 e_select++;
836                 if (e_select >= MAX_REMEMBER) {
837                         e_select--;
838                 } else if (in) {
839                         if (e_ext.last_in[e_select][0] == '\0')
840                                 e_select--;
841                 } else
842                         if (e_ext.last_out[e_select][0] == '\0')
843                                 e_select--;
844
845         }
846
847         last = (in)?e_ext.last_in[e_select]:e_ext.last_out[e_select];
848         if (e_extdialing[0]=='0' || e_extdialing[0]=='2') {
849                 nodisplay:
850                 if (in)
851                         trace_header("ACTION reply (dialing)", DIRECTION_NONE);
852                 else
853                         trace_header("ACTION redial (dialing)", DIRECTION_NONE);
854                 add_trace("number", NULL, "%s", last);
855                 add_trace("last but", NULL, "%d", e_select);
856                 end_trace();
857                 SCPY(e_dialinginfo.id, last);
858                 e_extdialing = e_dialinginfo.id;
859                 e_action = NULL;
860                 process_dialing(0);
861                 return;
862         }
863         e_extdialing[0] = '\0';
864         
865         /* send display message to port */
866         message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
867         if (!strncmp(last, "extern:", 7))
868                 SPRINT(message->param.notifyinfo.display, "(%d) %s ext", e_select+1, last+7);
869         else
870         if (!strncmp(last, "intern:", 7))
871                 SPRINT(message->param.notifyinfo.display, "(%d) %s int", e_select+1, last+7);
872         else
873         if (!strncmp(last, "chan:", 4))
874                 SPRINT(message->param.notifyinfo.display, "(%d) %s chan", e_select+1, last+5);
875         else
876         if (!strncmp(last, "vbox:", 5))
877                 SPRINT(message->param.notifyinfo.display, "(%d) %s vbox", e_select+1, last+5);
878         else
879                 SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -");
880         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
881         message_put(message);
882         logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
883 }
884
885 /* process dialing redial
886 */
887 void EndpointAppPBX::action_dialing_redial(void)
888 {
889         _action_redial_reply(0);
890 }
891
892 /* process dialing reply
893 */
894 void EndpointAppPBX::action_dialing_reply(void)
895 {
896         _action_redial_reply(1);
897 }
898
899
900 /* dialing powerdialing delay
901  */
902 void EndpointAppPBX::action_dialing_powerdial(void)
903 {
904         struct port_list *portlist = ea_endpoint->ep_portlist;
905         struct lcr_msg *message;
906         struct route_param *rparam;
907
908         /* power dialing only possible if we have a last dialed number */
909         if (!e_ext.last_out[0]) {
910                 trace_header("ACTION powerdial (no last number stored)", DIRECTION_NONE);
911                 end_trace();
912                 new_state(EPOINT_STATE_OUT_DISCONNECT);
913                 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
914                 set_tone(portlist, "cause_3f");
915                 return;
916         }
917
918         /* limit */
919         if ((rparam = routeparam(e_action, PARAM_LIMIT))) {
920                 e_powerlimit = rparam->integer_value;
921         } else {
922                 e_powerlimit = 0;
923         }
924
925         /* delay */
926         if ((rparam = routeparam(e_action, PARAM_DELAY))) {
927                 e_powerdelay = rparam->integer_value;
928         } else {
929                 /* delay incomplete */
930                 if (!strchr(e_extdialing, '#'))
931                         return;
932                 *strchr(e_extdialing, '#') = '\0';
933                 e_powerdelay = e_extdialing[0]?atoi(e_extdialing): 0;
934         }
935
936         if (e_powerdelay < 1)
937                 e_powerdelay = 0.2;
938         trace_header("ACTION powerdial (dialing)", DIRECTION_NONE);
939         add_trace("number", NULL, "%s", e_ext.last_out[0]);
940         add_trace("delay", NULL, "%d", e_powerdelay);
941         end_trace();
942
943         /* send connect to avoid overlap timeout */
944 //      new_state(EPOINT_STATE_CONNECT); connect may prevent further dialing
945         if (e_ext.number[0])
946                 e_dtmf = 1;
947         memset(&e_connectinfo, 0, sizeof(e_connectinfo));
948         message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
949         message_put(message);
950         logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
951
952         /* do dialing */
953         SCPY(e_dialinginfo.id, e_ext.last_out[0]);
954         e_powerdial_on = 1; /* indicates the existence of powerdialing but no redial time given */
955         e_powercount = 0;
956         e_action = NULL;
957         process_dialing(0);
958 }
959
960
961 /* dialing callback
962  */
963 void EndpointAppPBX::action_dialing_callback(void)
964 {
965         struct port_list *portlist = ea_endpoint->ep_portlist;
966         struct route_param *rparam;
967         struct extension cbext;
968
969         portlist = ea_endpoint->ep_portlist;
970
971         /* check given extension */
972         if (!(rparam = routeparam(e_action, PARAM_EXTENSION))) {
973                 noextension:
974                 trace_header("ACTION callback (no extension defined)", DIRECTION_NONE);
975                 end_trace();
976                 disconnect:
977
978                 new_state(EPOINT_STATE_OUT_DISCONNECT);
979                 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
980                 set_tone(portlist, "cause_3f");
981                 e_action = NULL;
982                 e_cbcaller[0] = e_cbdialing[0] = '\0';
983                 return;
984         }
985
986         /* if extension is given */
987         SCPY(e_cbcaller, rparam->string_value);
988         if (e_cbcaller[0] == '\0')
989                 goto noextension;
990
991         /* read callback extension */
992         memset(&cbext, 0, sizeof(cbext));
993         if (!read_extension(&cbext, e_cbcaller)) {
994                 trace_header("ACTION callback (extension doesn't exist)", DIRECTION_NONE);
995                 add_trace("extension", NULL, "%s", e_cbcaller);
996                 end_trace();
997                 goto disconnect;
998         }
999
1000         /* if password is not given */
1001         if (cbext.password[0] == '\0') {
1002                 trace_header("ACTION callback (no password set)", DIRECTION_NONE);
1003                 add_trace("extension", NULL, "%s", e_cbcaller);
1004                 end_trace();
1005                 goto disconnect;
1006         }
1007
1008         /* callback only possible if callerid exists OR it is given */
1009         if ((rparam = routeparam(e_action, PARAM_CALLTO)))
1010                 SCPY(e_cbto, rparam->string_value);
1011         if (e_cbto[0]) {
1012                 trace_header("ACTION callback (alternative caller id)", DIRECTION_NONE);
1013                 add_trace("extension", NULL, "%s", e_cbcaller);
1014                 add_trace("callerid", NULL, "%s", e_cbto);
1015                 end_trace();
1016                 SCPY(e_callerinfo.id, e_cbto);
1017                 e_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
1018                 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1019         }
1020         if (e_callerinfo.id[0]=='\0' || e_callerinfo.present==INFO_PRESENT_NOTAVAIL) {
1021                 trace_header("ACTION callback (no caller ID available)", DIRECTION_NONE);
1022                 add_trace("extension", NULL, "%s", e_cbcaller);
1023                 end_trace();
1024                 goto disconnect;
1025         }
1026         /* present id */
1027         e_callerinfo.present = INFO_PRESENT_ALLOWED;
1028
1029 }
1030
1031 /*
1032  * process hangup 'callback'
1033  */
1034 void EndpointAppPBX::action_hangup_callback(void)
1035 {
1036         struct route_param *rparam;
1037         int delay;
1038
1039         /* set delay */
1040         delay = 2; /* default value */
1041         if ((rparam = routeparam(e_action, PARAM_DELAY)))
1042         if (rparam->integer_value>0)
1043                 delay = rparam->integer_value;
1044
1045         /* dialing after callback */
1046         if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1047                 SCPY(e_cbdialing, rparam->string_value);
1048         else
1049                 SCPY(e_cbdialing, e_extdialing);
1050
1051         trace_header("ACTION callback (dialing)", DIRECTION_NONE);
1052         add_trace("extension", NULL, "%s", e_cbcaller);
1053         add_trace("caller id", NULL, "%s", e_callerinfo.id);
1054         add_trace("delay", NULL, "%d", delay);
1055         add_trace("dialing", NULL, "%s", e_cbdialing);
1056         end_trace();
1057
1058         /* set time to callback */
1059         schedule_timer(&e_callback_timeout, delay, 0);
1060 }
1061
1062
1063 /*
1064  * dialing action abbreviation
1065  */
1066 void EndpointAppPBX::action_dialing_abbrev(void)
1067 {
1068         struct port_list *portlist = ea_endpoint->ep_portlist;
1069         char *abbrev, *phone, *name;
1070         int result;
1071
1072         portlist = ea_endpoint->ep_portlist;
1073
1074         /* abbrev dialing is only possible if we have a caller defined */
1075         if (!e_ext.number[0]) {
1076                 trace_header("ACTION abbreviation (only for extension)", DIRECTION_NONE);
1077                 end_trace();
1078                 new_state(EPOINT_STATE_OUT_DISCONNECT);
1079                 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1080                 set_tone(portlist, "cause_3f");
1081                 return;
1082         }
1083
1084         /* check abbreviation */
1085         abbrev = e_extdialing;
1086         phone = NULL;
1087         name = NULL;
1088         result = parse_phonebook(e_ext.number, &abbrev, &phone, &name);
1089         if (result == 0) {
1090                 trace_header("ACTION abbreviation (not found)", DIRECTION_NONE);
1091                 add_trace("abbrev", NULL, "%s", abbrev);
1092                 end_trace();
1093                 new_state(EPOINT_STATE_OUT_DISCONNECT);
1094                 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
1095                 set_tone(portlist, "cause_01");
1096                 return;
1097         }
1098         if (result == -1) { /* may match if more digits are dialed */
1099                 return;
1100         }
1101
1102         /* dial abbreviation */ 
1103         trace_header("ACTION abbreviation (dialing)", DIRECTION_NONE);
1104         add_trace("abbrev", NULL, "%s", abbrev);
1105         add_trace("number", NULL, "%s", phone);
1106         if (name) if (name[0])
1107                 add_trace("name", NULL, "%s", name);
1108         end_trace();
1109         SCPY(e_dialinginfo.id, phone);
1110         e_extdialing = e_dialinginfo.id;
1111         e_action = NULL;
1112         process_dialing(0);
1113 }
1114
1115
1116 /* process dialing 'test'
1117  */
1118 void EndpointAppPBX::action_dialing_test(void)
1119 {
1120         unsigned int cause;
1121         char causestr[16];
1122         struct port_list *portlist = ea_endpoint->ep_portlist;
1123         struct lcr_msg *message;
1124         class Port *port;
1125         char testcode[32] = "";
1126         struct route_param *rparam;
1127
1128         /* given testcode */
1129         if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1130                 SCPY(testcode, rparam->string_value);
1131         SCAT(testcode, e_extdialing);
1132
1133         switch(testcode[0]) {
1134                 case '1':
1135                 trace_header("ACTION test", DIRECTION_NONE);
1136                 add_trace("test", NULL, "proceeding");
1137                 end_trace();
1138                 new_state(EPOINT_STATE_IN_PROCEEDING);
1139                 set_tone(portlist, "proceeding");
1140                 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
1141                 message_put(message);
1142                 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1143                 break;
1144                 
1145                 case '2':
1146                 trace_header("ACTION test", DIRECTION_NONE);
1147                 add_trace("test", NULL, "alerting");
1148                 end_trace();
1149                 new_state(EPOINT_STATE_IN_ALERTING);
1150                 set_tone(portlist, "ringpbx");
1151                 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
1152                 message_put(message);
1153                 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1154                 break;
1155                 
1156                 case '3':
1157                 trace_header("ACTION test", DIRECTION_NONE);
1158                 add_trace("test", NULL, "echo");
1159                 end_trace();
1160                 new_state(EPOINT_STATE_CONNECT);
1161                 if (e_ext.number[0])
1162                         e_dtmf = 1;
1163                 set_tone(portlist, NULL);
1164                 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1165                 SCPY(e_connectinfo.id, e_callerinfo.id);
1166                 SCPY(e_connectinfo.extension, e_callerinfo.extension);
1167                 e_connectinfo.itype = e_callerinfo.itype;
1168                 e_connectinfo.ntype = e_callerinfo.ntype;
1169                 e_connectinfo.present = e_callerinfo.present;
1170                 e_connectinfo.screen = e_callerinfo.screen;
1171                 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1172                 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(struct connect_info));
1173                 /* handle restricted caller ids */
1174                 apply_callerid_restriction(&e_ext, message->param.connectinfo.id, &message->param.connectinfo.ntype, &message->param.connectinfo.present, &message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name);
1175                 /* display callerid if desired for extension */
1176                 SCPY(message->param.connectinfo.display, apply_callerid_display(message->param.connectinfo.id, message->param.connectinfo.itype, message->param.connectinfo.ntype, message->param.connectinfo.present, message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name));
1177                 message_put(message);
1178                 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1179
1180                 port = find_port_id(portlist->port_id);
1181                 if (port) {
1182                         port->set_echotest(1);
1183                 }
1184                 break;
1185                 
1186                 case '4':
1187                 trace_header("ACTION test", DIRECTION_NONE);
1188                 add_trace("test", NULL, "tone");
1189                 end_trace();
1190                 new_state(EPOINT_STATE_CONNECT);
1191                 if (e_ext.number[0])
1192                         e_dtmf = 1;
1193                 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1194                 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1195                 message_put(message);
1196                 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1197                 set_tone(portlist, "test");
1198                 break;
1199                 
1200                 case '5':
1201                 trace_header("ACTION test", DIRECTION_NONE);
1202                 add_trace("test", NULL, "hold music");
1203                 end_trace();
1204                 new_state(EPOINT_STATE_CONNECT);
1205                 if (e_ext.number[0])
1206                         e_dtmf = 1;
1207                 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1208                 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1209                 message_put(message);
1210                 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1211                 set_tone(portlist, "hold");
1212                 break;
1213                 
1214                 case '6':
1215                 if (strlen(testcode) < 4)
1216                         break;
1217                 testcode[4] = '\0';
1218                 cause = atoi(testcode+1);
1219                 if (cause > 255)
1220                         cause = 0;
1221                 trace_header("ACTION test", DIRECTION_NONE);
1222                 add_trace("test", NULL, "announcement");
1223                 add_trace("cause", NULL, "%d", cause);
1224                 end_trace();
1225                 new_state(EPOINT_STATE_CONNECT);
1226                 if (e_ext.number[0])
1227                         e_dtmf = 1;
1228                 SPRINT(causestr,"cause_%02x",cause);
1229                 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1230                 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1231                 message_put(message);
1232                 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1233                 set_tone(portlist, causestr);
1234                 break;
1235                 
1236                 case '7':
1237                 if (strlen(testcode) < 4)
1238                         break;
1239                 testcode[4] = '\0';
1240                 cause = atoi(testcode+1);
1241                 if (cause > 127)
1242                         cause = 0;
1243                 trace_header("ACTION test", DIRECTION_NONE);
1244                 add_trace("test", NULL, "disconnect");
1245                 add_trace("cause", NULL, "%d", cause);
1246                 end_trace();
1247                 new_state(EPOINT_STATE_OUT_DISCONNECT);
1248                 SPRINT(causestr,"cause_%02x",cause);
1249                 message_disconnect_port(portlist, cause, LOCATION_PRIVATE_LOCAL, "");
1250                 set_tone(portlist, causestr);
1251                 break;
1252
1253                 case '8': /* release */
1254                 trace_header("ACTION test", DIRECTION_NONE);
1255                 add_trace("test", NULL, "release");
1256                 add_trace("cause", NULL, "16");
1257                 end_trace();
1258                 new_state(EPOINT_STATE_OUT_DISCONNECT);
1259                 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
1260                 set_tone(portlist, "release");
1261                 break;
1262
1263                 case '9': /* text callerid test */
1264                 trace_header("ACTION test", DIRECTION_NONE);
1265                 add_trace("test", NULL, "callerid");
1266                 end_trace();
1267                 new_state(EPOINT_STATE_CONNECT);
1268                 if (e_ext.number[0])
1269                         e_dtmf = 1;
1270                 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1271                 SCPY(e_connectinfo.id, "12345678");
1272                 SCPY(e_connectinfo.name, "Welcome to LCR");
1273                 SCPY(e_connectinfo.display, "Welcome to LCR");
1274                 e_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1275                 e_connectinfo.present = INFO_PRESENT_ALLOWED;
1276                 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1277                 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(message->param.connectinfo));
1278                 message_put(message);
1279                 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1280                 set_tone(portlist, "hold");
1281                 break;
1282         }
1283 }
1284
1285
1286 /* process init play
1287  */
1288 void EndpointAppPBX::action_init_play(void)
1289 {
1290         struct route_param *rparam;
1291         struct port_list *portlist = ea_endpoint->ep_portlist;
1292
1293         /* check given sample */
1294         if (!(rparam = routeparam(e_action, PARAM_SAMPLE))) {
1295                 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1296                 end_trace();
1297
1298                 disconnect:
1299                 new_state(EPOINT_STATE_OUT_DISCONNECT);
1300                 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
1301                 set_tone(portlist, "cause_3f");
1302                 e_action = NULL;
1303                 return;
1304         }
1305
1306         /* if sample is given */
1307         if (rparam->string_value[0] == '\0') {
1308                 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1309                 end_trace();
1310                 goto disconnect;
1311         }
1312
1313         if (e_ext.number[0])
1314                 e_dtmf = 1;
1315
1316         set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1317 }
1318
1319
1320 /*
1321  * action_*_vbox_play is implemented in "action_vbox.cpp"
1322  */
1323
1324
1325 /*
1326  * process dialing of calculator
1327  */
1328 void EndpointAppPBX::action_dialing_calculator(void)
1329 {
1330         struct port_list *portlist = ea_endpoint->ep_portlist;
1331         struct lcr_msg *message;
1332         double value1, value2, v, sign1;
1333         int komma1, komma2, k, state, mode = 0, first;
1334         char *p;
1335
1336         portlist = ea_endpoint->ep_portlist;
1337
1338         /* remove error message */
1339         if (!strncmp(e_extdialing, "Error", 5)) {
1340                 UCPY(e_extdialing, e_extdialing+5);
1341         }
1342         if (!strncmp(e_extdialing, "inf", 3)) {
1343                 UCPY(e_extdialing, e_extdialing+3);
1344         }
1345         if (!strncmp(e_extdialing, "-inf", 4)) {
1346                 UCPY(e_extdialing, e_extdialing+4);
1347         }
1348
1349         /* process dialing */
1350         state = 0;
1351         value1 = 0;
1352         value2 = 0;
1353         komma1 = 0;
1354         komma2 = 0;
1355         sign1 = 1;
1356         p = e_extdialing;
1357         if (!p)
1358                 return;
1359         first = 1;
1360         while(*p) {
1361                 if (*p>='0' && *p<='9') {
1362 #if 0
1363                         if (first) {
1364                                 UCPY(p, p+1);
1365                                 continue;
1366                         }
1367                         if ((p[-1]<'0' || p[-1]>'0') && p[-1]!='.') {
1368                                 p--;
1369                                 UCPY(p, p+1);
1370                                 continue;
1371                         }
1372 #endif
1373                         switch(state) {
1374                                 case 0: /* first number */
1375                                 if (!komma1) {
1376                                         value1 = value1*10 + (*p-'0');
1377                                 } else {
1378                                         k = komma1++;
1379                                         v = *p-'0';
1380                                         while(k--)
1381                                                 v /= 10;
1382                                         value1 += v; 
1383                                 }
1384                                 break;
1385                                 case 1: /* second number */
1386                                 if (!komma2) {
1387                                         value2 = value2*10 + (*p-'0');
1388                                 } else {
1389                                         k = komma2++;
1390                                         v = *p-'0';
1391                                         while(k--)
1392                                                 v /= 10;
1393                                         value2 += v; 
1394                                 }
1395                                 break;
1396                         }
1397                 } else
1398                 switch(*p) {
1399                         case '*':
1400                         if (first) {
1401                                 UCPY(e_extdialing, "Error");
1402                                 goto done;
1403                         }
1404                         /* if there is a multiplication, we change to / */
1405                         if (p[-1] == '*') {
1406                                 mode = 1;
1407                                 p[-1] = '/';
1408                                 UCPY(p, p+1);
1409                                 p--;
1410                                 break;
1411                         }
1412                         /* if there is a division, we change to + */
1413                         if (p[-1] == '/') {
1414                                 mode = 2;
1415                                 p[-1] = '+';
1416                                 UCPY(p, p+1);
1417                                 p--;
1418                                 break;
1419                         }
1420                         /* if there is a addition, we change to - */
1421                         if (p[-1] == '+') {
1422                                 mode = 3;
1423                                 p[-1] = '-';
1424                                 UCPY(p, p+1);
1425                                 p--;
1426                                 break;
1427                         }
1428                         /* if there is a substraction and a comma, we change to * */
1429                         if (p[-1]=='-' && komma1) {
1430                                 mode = 0;
1431                                 p[-1] = '*';
1432                                 UCPY(p, p+1);
1433                                 p--;
1434                                 break;
1435                         }
1436                         /* if there is a substraction and no comma and the first or second value, we change to , */
1437                         if (p[-1]=='-') {
1438                                 p[-1] = '.';
1439                                 UCPY(p, p+1);
1440                                 p--;
1441                                 komma1 = 1;
1442                                 break;
1443                         }
1444                         /* if there is a komma and we are at the first value, we change to * */
1445                         if (p[-1]=='.' && state==0) {
1446                                 mode = 0;
1447                                 p[-1] = '*';
1448                                 UCPY(p, p+1);
1449                                 p--;
1450                                 komma1 = 0;
1451                                 break;
1452                         }
1453                         /* if there is a komma and we are at the second value, we display error */
1454                         if (komma2 && state==1) {
1455                                 UCPY(e_extdialing, "Error");
1456                                 goto done;
1457                         }
1458                         /* if we are at state 1, we write a comma */
1459                         if (state == 1) {
1460                                 *p = '.';
1461                                 komma2 = 1;
1462                                 break;
1463                         }
1464                         /* we assume multiplication */
1465                         mode = 0;
1466                         state = 1;
1467                         komma1 = 0;
1468                         break;
1469
1470                         case '#':
1471                         /* if just a number is displayed, the input is cleared */
1472                         if (state==0) {
1473                                 *e_extdialing = '\0';
1474                                 break;
1475                         }
1476                         /* calculate the result */
1477                         switch(mode) {
1478                                 case 0: /* multiply */
1479                                 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1*value2);
1480                                 break;
1481                                 case 1: /* divide */
1482                                 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1/value2);
1483                                 break;
1484                                 case 2: /* add */
1485                                 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1+value2);
1486                                 break;
1487                                 case 3: /* substract */
1488                                 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1-value2);
1489                                 break;
1490                         }
1491                         e_dialinginfo.id[sizeof(e_dialinginfo.id)-1] = '\0';
1492                         if (strchr(e_extdialing, '.')) { /* remove zeroes */
1493                                 while (e_extdialing[strlen(e_extdialing)-1] == '0')
1494                                         e_extdialing[strlen(e_extdialing)-1] = '\0';
1495                                 if (e_extdialing[strlen(e_extdialing)-1] == '.')
1496                                         e_extdialing[strlen(e_extdialing)-1] = '\0'; /* and remove dot */
1497                         }
1498                         p = strchr(e_extdialing,'\0')-1;
1499                         break;
1500
1501                         case '.':
1502                         if (state)
1503                                 komma2 = 1;
1504                         else    komma1 = 1;
1505                         break;
1506
1507                         case '/':
1508                         komma2 = 0;
1509                         state = 1;
1510                         mode = 1;
1511                         break;
1512
1513                         case '+':
1514                         komma2 = 0;
1515                         state = 1;
1516                         mode = 2;
1517                         break;
1518
1519                         case '-':
1520                         if (first) {
1521                                 sign1=-1;
1522                                 break;
1523                         }
1524                         komma2 = 0;
1525                         state = 1;
1526                         mode = 3;
1527                         break;
1528
1529                         default:
1530                         UCPY(e_extdialing, "Error");
1531                         goto done;
1532                 }
1533
1534                 p++;
1535                 first = 0;
1536         }
1537         done:
1538
1539         /* display dialing */   
1540         message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1541         SPRINT(message->param.notifyinfo.display, ">%s", e_extdialing);
1542         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s' internal values: %f %f\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing, value1, value2);
1543         message_put(message);
1544         logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1545
1546 }
1547
1548 /*
1549  * process dialing of timer
1550  */
1551 void EndpointAppPBX::action_dialing_timer(void)
1552 {
1553 }
1554
1555
1556 /*
1557  * process 'goto' or 'menu'
1558  */
1559 void EndpointAppPBX::_action_goto_menu(int mode)
1560 {
1561         struct port_list *portlist = ea_endpoint->ep_portlist;
1562         struct route_param *rparam;
1563
1564         /* check given ruleset */
1565         if (!(rparam = routeparam(e_action, PARAM_RULESET))) {
1566                 no_ruleset:
1567                 trace_header("ACTION goto/menu (no ruleset given)", DIRECTION_NONE);
1568                 end_trace();
1569
1570                 disconnect:
1571                 new_state(EPOINT_STATE_OUT_DISCONNECT);
1572                 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1573                 set_tone(portlist, "cause_3f");
1574                 e_action = NULL;
1575                 return;
1576         }
1577         if (rparam->string_value[0] == '\0')
1578                 goto no_ruleset;
1579         e_ruleset = getrulesetbyname(rparam->string_value);
1580         if (!e_ruleset) {
1581                 trace_header("ACTION goto/menu (ruleset not found)", DIRECTION_NONE);
1582                 add_trace("ruleset", NULL, "%s", rparam->string_value);
1583                 end_trace();
1584                 goto disconnect;
1585         }
1586
1587         /* if the 'menu' was selected, we will flush all digits */
1588         if (mode) {
1589                 e_dialinginfo.id[0] = 0;
1590                 e_extdialing = e_dialinginfo.id;
1591         } else {
1592                 /* remove digits that are required to match the rule */
1593                 if ((rparam = routeparam(e_action, PARAM_STRIP))) {
1594                         if (e_extdialing)
1595                                 SCPY(e_dialinginfo.id, e_extdialing);
1596                         e_extdialing = e_dialinginfo.id;
1597                 }
1598         }
1599
1600         /* play sample */
1601         trace_header("ACTION goto/menu (change to)", DIRECTION_NONE);
1602         add_trace("ruleset", NULL, "%s", e_ruleset->name);
1603         if (e_dialinginfo.id[0]) {
1604                 add_trace("dialing", NULL, "%s", e_dialinginfo.id);
1605         }
1606         if ((rparam = routeparam(e_action, PARAM_SAMPLE))) {
1607                 add_trace("sample", NULL, "%s", rparam->string_value);
1608                 end_trace();
1609                 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1610         } else {
1611                 end_trace();
1612         }
1613
1614         /* do dialing with new ruleset */
1615         e_action = NULL;
1616         process_dialing(0);
1617 }
1618
1619 /* process dialing goto
1620 */
1621 void EndpointAppPBX::action_dialing_goto(void)
1622 {
1623         _action_goto_menu(0);
1624 }
1625
1626 /* process dialing menu
1627 */
1628 void EndpointAppPBX::action_dialing_menu(void)
1629 {
1630         _action_goto_menu(1);
1631 }
1632
1633
1634 /*
1635  * process dialing disconnect
1636  */
1637 void EndpointAppPBX::action_dialing_disconnect(void)
1638 {
1639         struct route_param *rparam;
1640         struct port_list *portlist = ea_endpoint->ep_portlist;
1641         struct lcr_msg *message;
1642         int cause = CAUSE_NORMAL; /* normal call clearing */
1643         int location = LOCATION_PRIVATE_LOCAL;
1644         char cause_string[256] = "", display[84] = "";
1645
1646         /* check cause parameter */
1647         if ((rparam = routeparam(e_action, PARAM_CAUSE))) {
1648                 cause = rparam->integer_value;
1649                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1650         }
1651         if ((rparam = routeparam(e_action, PARAM_LOCATION))) {
1652                 location = rparam->integer_value;
1653                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1654         }
1655
1656
1657         /* use cause as sample, if not given later */
1658         SPRINT(cause_string, "cause_%02x", cause);
1659
1660         /* check sample parameter */
1661         if ((rparam = routeparam(e_action, PARAM_SAMPLE))) {
1662                 SCPY(cause_string, rparam->string_value);
1663                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'sample' is given: %s\n", ea_endpoint->ep_serial, cause_string);
1664         }
1665
1666         /* check display */
1667         if ((rparam = routeparam(e_action, PARAM_DISPLAY))) {
1668                 SCPY(display, rparam->string_value);
1669                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1670         }
1671
1672         /* disconnect only if connect parameter is not given */
1673         trace_header("ACTION disconnect", DIRECTION_NONE);
1674         add_trace("cause", "value", "%d", cause);
1675         add_trace("cause", "location", "%d", location);
1676         if (cause_string[0])
1677                 add_trace("sample", NULL, "%s", cause_string);
1678         if (display[0])
1679                 add_trace("display", NULL, "%s", display);
1680         end_trace();
1681         new_state(EPOINT_STATE_OUT_DISCONNECT);
1682         set_tone(portlist, cause_string);
1683         if (!(rparam = routeparam(e_action, PARAM_CONNECT))) {
1684                 message_disconnect_port(portlist, cause, location, display);
1685         } else {
1686                 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1687                 SCPY(message->param.notifyinfo.display, display);
1688                 message_put(message);
1689                 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1690         }
1691         e_action = NULL;
1692 }
1693
1694
1695 /*
1696  * process dialing release
1697  */
1698 void EndpointAppPBX::action_dialing_release(void)
1699 {
1700         struct route_param *rparam;
1701         int cause = CAUSE_NORMAL; /* normal call clearing */
1702         int location = LOCATION_PRIVATE_LOCAL;
1703         char cause_string[256] = "", display[84] = "";
1704
1705         /* check cause parameter */
1706         if ((rparam = routeparam(e_action, PARAM_CAUSE))) {
1707                 cause = rparam->integer_value;
1708                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1709         }
1710         if ((rparam = routeparam(e_action, PARAM_LOCATION))) {
1711                 location = rparam->integer_value;
1712                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1713         }
1714
1715
1716         /* use cause as sample, if not given later */
1717         SPRINT(cause_string, "cause_%02x", cause);
1718
1719         /* check display */
1720         if ((rparam = routeparam(e_action, PARAM_DISPLAY))) {
1721                 SCPY(display, rparam->string_value);
1722                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1723         }
1724
1725         /* disconnect only if connect parameter is not given */
1726         trace_header("ACTION release", DIRECTION_NONE);
1727         add_trace("cause", "value", "%d", cause);
1728         add_trace("cause", "location", "%d", location);
1729         if (display[0])
1730                 add_trace("display", NULL, "%s", display);
1731         end_trace();
1732         e_action = NULL;
1733         release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, location, cause, 1);
1734         return;
1735 }
1736
1737 /*
1738  * process dialing help
1739  */
1740 void EndpointAppPBX::action_dialing_help(void)
1741 {
1742         /* show all things that would match */
1743 #if 0
1744         struct numbering *numbering = numbering_int;
1745         char dialing[sizeof(e_dialinginfo.id)];
1746         int i;
1747         struct lcr_msg *message;
1748         struct route_param *rparam;
1749
1750         /* in case we have no menu (this should never happen) */
1751         if (!numbering)
1752                 return;
1753
1754         /* scroll menu */
1755         if (strchr(e_dialinginfo.id,'*')) {
1756                 e_menu--;
1757                 e_dialinginfo.id[0] = '\0';
1758         }
1759         if (strchr(e_dialinginfo.id,'#')) {
1760                 e_menu++;
1761                 e_dialinginfo.id[0] = '\0';
1762         }
1763         
1764         /* get position in menu */
1765         if (e_menu < 0) {
1766                 /* get last menu position */
1767                 e_menu = 0;
1768                 while(numbering->next) {
1769                         e_menu++;
1770                         numbering = numbering->next;
1771                 }
1772         } else {
1773                 /* get menu position */
1774                 i = 0;
1775                 while(i < e_menu) {
1776                         numbering = numbering->next;
1777                         if (!numbering) {
1778                                 e_menu = 0;
1779                                 numbering = numbering_int;
1780                                 break;
1781                         }
1782                         i++;
1783                 }
1784         }
1785
1786         /* if we dial something else we need to add the prefix and change the action */
1787         if (e_dialinginfo.id[0]) {
1788                 e_action = NUMB_ACTION_NONE;
1789                 SCPY(dialing, numbering->prefix);
1790                 //we ignore the first digit after selecting
1791                 //SCAT(dialing, e_dialinginfo.id);
1792                 SCPY(e_dialinginfo.id, dialing);
1793                 e_extdialing = e_dialinginfo.id+strlen(numbering->prefix);
1794                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s selected a new menu '%s' dialing: %s\n", ea_endpoint->ep_serial, e_ext.number, numb_actions[numbering->action], e_dialinginfo.id);
1795 nesting?:
1796                 process_dialing(0);
1797                 return;
1798         }
1799
1800         /* send display message to port */
1801         message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1802         SPRINT(message->param.notifyinfo.display, ">%s %s%s%s", numbering->prefix, numb_actions[numbering->action], (numbering->param[0])?" ":"", numbering->param);
1803         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s selected a new menu '%s' sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, numb_actions[numbering->action], message->param.notifyinfo.display);
1804         message_put(message);
1805         logmessage(message->type, message->paramea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1806 #endif
1807 }
1808
1809
1810 /*
1811  * process dialing deflect
1812  */
1813 void EndpointAppPBX::action_dialing_deflect(void)
1814 {
1815 }
1816
1817
1818 /*
1819  * process dialing setforward
1820  */
1821 void EndpointAppPBX::action_dialing_setforward(void)
1822 {
1823 }
1824
1825 /*
1826  * process init 'execute'
1827  */ 
1828 void EndpointAppPBX::action_init_execute(void)
1829 {
1830         struct route_param *rparam;
1831         int executeon = INFO_ON_HANGUP;  /* Use Hangup as a default for compatibility */
1832         
1833         /* Get the execute on parameter */
1834         if ((rparam = routeparam(e_action, PARAM_ON)))
1835         executeon = rparam->integer_value;
1836
1837         /* Execute this action if init was specified */
1838         if (executeon == INFO_ON_INIT) {
1839                 trace_header("ACTION execute ON init", DIRECTION_NONE);
1840                 end_trace();
1841                 action_execute();
1842         }
1843 }
1844
1845 /*
1846  * process hangup 'execute'
1847  */ 
1848 void EndpointAppPBX::action_hangup_execute(void)
1849 {
1850         struct route_param *rparam;
1851         int executeon = INFO_ON_HANGUP;  /* Use Hangup as a default for compatibility */
1852         
1853         /* Get the execute on parameter */
1854         if ((rparam = routeparam(e_action, PARAM_ON)))
1855         executeon = rparam->integer_value;
1856
1857         /* Execute this action if init was specified */
1858         if (executeon == INFO_ON_HANGUP) {
1859                 trace_header("ACTION execute ON hangup", DIRECTION_NONE);
1860                 end_trace();
1861                 action_execute();
1862         }
1863 }
1864
1865 /*
1866  * process 'execute' from action_init_execute or action_hangup_execute
1867  */
1868 void EndpointAppPBX::action_execute(void)
1869 {
1870         struct route_param *rparam;
1871         pid_t pid;
1872         pid_t pid2;
1873         int iWaitStatus;
1874         char *command = (char *)"";
1875         char isdn_port[10];
1876         char *argv[12]; /* check also number of args below */
1877         int i = 0;
1878
1879         /* get script / command */
1880         if ((rparam = routeparam(e_action, PARAM_EXECUTE)))
1881                 command = rparam->string_value;
1882         if (command[0] == '\0') {
1883                 trace_header("ACTION execute (no parameter given)", DIRECTION_NONE);
1884                 end_trace();
1885                 return;
1886         }
1887 #if 0
1888         argv[i++] = (char *)"/bin/sh";
1889         argv[i++] = (char *)"-c";
1890         argv[i++] = command;
1891 #endif
1892         argv[i++] = command;
1893         if ((rparam = routeparam(e_action, PARAM_PARAM))) {
1894                 argv[i++] = rparam->string_value;
1895         }
1896         argv[i++] = e_extdialing;
1897         argv[i++] = (char *)numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international);
1898         argv[i++] = e_callerinfo.extension;
1899         argv[i++] = e_callerinfo.name;
1900         SPRINT(isdn_port, "%d", e_callerinfo.isdn_port);
1901         argv[i++] = isdn_port;
1902         argv[i++] = e_callerinfo.imsi;
1903         argv[i++] = NULL; /* check also number of args above */
1904         switch (pid = fork ()) {
1905                 case -1:
1906                         trace_header("ACTION execute (fork failed)", DIRECTION_NONE);
1907                         end_trace();
1908                         break;
1909                 case 0:
1910                         /* To be shure there are no zombies created double fork */
1911                         if ((pid2 = fork()) == 0) {
1912                                 execve(command, argv, environ);
1913                         }
1914                         /* Exit immediately and release the waiting parent. The subprocess falls to init because the parent died */
1915                         exit(0);
1916                         break;
1917                 default:
1918                         trace_header("ACTION execute", DIRECTION_NONE);
1919                         add_trace("command", NULL, "%s", command);
1920                         end_trace();
1921
1922                         /* Wait for the pid. The forked process will exit immediately so there is no problem waiting. */
1923                         waitpid(pid, &iWaitStatus, 0);
1924                         break;
1925         }
1926 }
1927
1928
1929 /*
1930  * process hangup 'file'
1931  */
1932 void EndpointAppPBX::action_hangup_file(void)
1933 {
1934         struct route_param *rparam;
1935         const char *file, *content, *mode;
1936         FILE *fp;
1937
1938         /* get file / content */
1939         if (!(rparam = routeparam(e_action, PARAM_FILE)))
1940                 file = rparam->string_value;
1941         else
1942                 file = "";
1943         if (!(rparam = routeparam(e_action, PARAM_CONTENT)))
1944                 content = rparam->string_value;
1945         else
1946                 content = e_extdialing;
1947         if (!(rparam = routeparam(e_action, PARAM_APPEND)))
1948                 mode = "a";
1949         else
1950                 mode = "w";
1951         if (file[0] == '\0') {
1952                 trace_header("ACTION file (no filename given)", DIRECTION_NONE);
1953                 end_trace();
1954                 return;
1955         }
1956         if (!(fp = fopen(file, mode))) {
1957                 trace_header("ACTION file (failed to open)", DIRECTION_NONE);
1958                 add_trace("file", "name", "%s", file);
1959                 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
1960                 end_trace();
1961                 return;
1962         }
1963         trace_header("ACTION file", DIRECTION_NONE);
1964         add_trace("file", "name", "%s", file);
1965         add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
1966         add_trace("content", NULL, "%s", content);
1967         end_trace();
1968         fprintf(fp, "%s\n", content);
1969         fclose(fp);
1970 }
1971
1972
1973 /*
1974  * process init 'pick'
1975  */
1976 void EndpointAppPBX::action_init_pick(void)
1977 {
1978         struct route_param *rparam;
1979         char *extensions = NULL;
1980
1981         if ((rparam = routeparam(e_action, PARAM_EXTENSIONS)))
1982                 extensions = rparam->string_value;
1983         
1984         trace_header("ACTION pick", DIRECTION_NONE);
1985         if (extensions) if (extensions[0])
1986                 add_trace("extensions", NULL, "%s", extensions);
1987         end_trace();
1988         pick_join(extensions);
1989 }
1990
1991
1992 /*
1993  * process dialing 'password'
1994  */
1995 void EndpointAppPBX::action_dialing_password(void)
1996 {
1997         struct port_list *portlist = ea_endpoint->ep_portlist;
1998
1999         /* prompt for password */
2000         if (e_extdialing[0] == '\0') {
2001                 /* give password tone */
2002                 set_tone(portlist, "password");
2003         } else // ELSE!!
2004         if (e_extdialing[1] == '\0') {
2005                 /* give password tone */
2006                 set_tone(portlist, "dialing");
2007         }
2008
2009         /* wait until all digits are dialed */
2010         if (strlen(e_ext.password) != strlen(e_extdialing))
2011                 return; /* more digits needed */
2012
2013         /* check the password */
2014         if (e_ext.password[0]=='\0' || (strlen(e_ext.password)==strlen(e_extdialing) && !!strcmp(e_ext.password,e_extdialing))) {
2015                 trace_header("ACTION password_write (wrong password)", DIRECTION_NONE);
2016                 add_trace("dialed", NULL, "%s", e_extdialing);
2017                 end_trace();
2018                 e_connectedmode = 0;
2019                 e_dtmf = 0;
2020                 new_state(EPOINT_STATE_OUT_DISCONNECT);
2021                 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2022                 set_tone(portlist, "cause_10");
2023                 return;
2024         }
2025
2026         /* write caller id if ACTION_PASSWORD_WRITE was selected */
2027         if (e_action)
2028         if (e_action->index == ACTION_PASSWORD_WRITE) {
2029                 append_callbackauth(e_ext.number, &e_callbackinfo);
2030                 trace_header("ACTION password_write (written)", DIRECTION_NONE);
2031                 add_trace("dialed", NULL, "%s", e_extdialing);
2032                 end_trace();
2033         }
2034
2035         /* make call state  */
2036         new_state(EPOINT_STATE_IN_OVERLAP);
2037         e_ruleset = ruleset_main;
2038         if (e_ruleset)
2039                 e_rule = e_ruleset->rule_first;
2040         e_action = NULL;
2041         e_dialinginfo.id[0] = '\0';
2042         e_extdialing = e_dialinginfo.id;
2043         set_tone(portlist, "dialpbx");
2044 }
2045
2046 void EndpointAppPBX::action_dialing_password_wr(void)
2047 {
2048         action_dialing_password();
2049 }
2050
2051
2052 /* process pots-retrieve
2053  */
2054 void EndpointAppPBX::action_init_pots_retrieve(void)
2055 {
2056 #ifdef ISDN_P_FXS_POTS
2057         struct route_param *rparam;
2058         struct port_list *portlist = ea_endpoint->ep_portlist;
2059         class Port *port;
2060         class Pfxs *ourfxs, *fxs;
2061         int count = 0;
2062         class Endpoint *epoint;
2063
2064         /* check given call */
2065         if (!(rparam = routeparam(e_action, PARAM_POTS_CALL))) {
2066                 trace_header("ACTION pots-retrieve (no call given)", DIRECTION_NONE);
2067                 end_trace();
2068
2069                 disconnect:
2070                 new_state(EPOINT_STATE_OUT_DISCONNECT);
2071                 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2072                 set_tone(portlist, "cause_3f");
2073                 e_action = NULL;
2074                 return;
2075         }
2076
2077         /* find call */
2078         port = find_port_id(portlist->port_id);
2079         if (!port)
2080                 goto disconnect;
2081         if ((port->p_type & PORT_CLASS_POTS_MASK) != PORT_CLASS_POTS_FXS) {
2082                 trace_header("ACTION pots-retrieve (call not of FXS type)", DIRECTION_NONE);
2083                 end_trace();
2084                 goto disconnect;
2085         }
2086         ourfxs = (class Pfxs *)port;
2087
2088         port = port_first;
2089         while(port) {
2090                 if ((port->p_type & PORT_CLASS_POTS_MASK) == PORT_CLASS_POTS_FXS) {
2091                         fxs = (class Pfxs *)port;
2092                         if (fxs->p_m_mISDNport == ourfxs->p_m_mISDNport && fxs != ourfxs) {
2093                                 count++;
2094                                 if (count == rparam->integer_value)
2095                                         break;
2096                         }
2097                 }
2098                 port = port->next;
2099         }
2100         if (!port) {
2101                 trace_header("ACTION pots-retrieve (call # does not exist)", DIRECTION_NONE);
2102                 end_trace();
2103                 goto disconnect;
2104         }
2105
2106         /* release our call */
2107         ourfxs->hangup_ind(0);
2108
2109         /* retrieve selected call */
2110         fxs->retrieve_ind(0);
2111
2112         /* split if selected call is member of a 3pty */
2113         epoint = find_epoint_id(ACTIVE_EPOINT(fxs->p_epointlist));
2114         if (epoint && epoint->ep_app_type == EAPP_TYPE_PBX) {
2115                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) try spliting 3pty. this may fail because we don't have a 3pty.\n", epoint->ep_serial);
2116                 ((class EndpointAppPBX *)epoint->ep_app)->split_3pty();
2117         }
2118 #endif
2119 }
2120
2121
2122 /* process pots-release
2123  */
2124 void EndpointAppPBX::action_init_pots_release(void)
2125 {
2126 #ifdef ISDN_P_FXS_POTS
2127         struct route_param *rparam;
2128         struct port_list *portlist = ea_endpoint->ep_portlist;
2129         class Port *port;
2130         class Pfxs *ourfxs, *fxs;
2131         int count = 0;
2132
2133         /* check given call */
2134         if (!(rparam = routeparam(e_action, PARAM_POTS_CALL))) {
2135                 trace_header("ACTION pots-release (no call given)", DIRECTION_NONE);
2136                 end_trace();
2137
2138                 disconnect:
2139                 new_state(EPOINT_STATE_OUT_DISCONNECT);
2140                 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2141                 set_tone(portlist, "cause_3f");
2142                 e_action = NULL;
2143                 return;
2144         }
2145
2146         /* find call */
2147         port = find_port_id(portlist->port_id);
2148         if (!port)
2149                 goto disconnect;
2150         if ((port->p_type & PORT_CLASS_POTS_MASK) != PORT_CLASS_POTS_FXS) {
2151                 trace_header("ACTION pots-release (call not of FXS type)", DIRECTION_NONE);
2152                 end_trace();
2153                 goto disconnect;
2154         }
2155         ourfxs = (class Pfxs *)port;
2156
2157         port = port_first;
2158         while(port) {
2159                 if ((port->p_type & PORT_CLASS_POTS_MASK) == PORT_CLASS_POTS_FXS) {
2160                         fxs = (class Pfxs *)port;
2161                         if (fxs->p_m_mISDNport == ourfxs->p_m_mISDNport && fxs != ourfxs) {
2162                                 count++;
2163                                 if (count == rparam->integer_value)
2164                                         break;
2165                         }
2166                 }
2167                 port = port->next;
2168         }
2169         if (!port) {
2170                 trace_header("ACTION pots-release (call # does not exist)", DIRECTION_NONE);
2171                 end_trace();
2172                 goto disconnect;
2173         }
2174
2175 #if 0
2176         /* disconnect our call */
2177         new_state(EPOINT_STATE_OUT_DISCONNECT);
2178         message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2179         set_tone(portlist, "hangup");
2180         e_action = NULL;
2181 #endif
2182
2183         /* release selected call */
2184         fxs->hangup_ind(0);
2185
2186         /* indicate timeout, so next action will be processed */
2187         process_dialing(1);
2188 #endif
2189 }
2190
2191
2192 /* process pots-reject
2193  */
2194 void EndpointAppPBX::action_init_pots_reject(void)
2195 {
2196 #ifdef ISDN_P_FXS_POTS
2197         struct port_list *portlist = ea_endpoint->ep_portlist;
2198         class Port *port;
2199         class Pfxs *ourfxs, *fxs;
2200
2201         /* find call */
2202         port = find_port_id(portlist->port_id);
2203         if (!port)
2204                 goto disconnect;
2205         if ((port->p_type & PORT_CLASS_POTS_MASK) != PORT_CLASS_POTS_FXS) {
2206                 trace_header("ACTION pots-reject (call not of FXS type)", DIRECTION_NONE);
2207                 end_trace();
2208                 disconnect:
2209                 new_state(EPOINT_STATE_OUT_DISCONNECT);
2210                 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2211                 set_tone(portlist, "cause_3f");
2212                 e_action = NULL;
2213                 return;
2214         }
2215         ourfxs = (class Pfxs *)port;
2216
2217         port = port_first;
2218         while(port) {
2219                 if ((port->p_type & PORT_CLASS_POTS_MASK) == PORT_CLASS_POTS_FXS) {
2220                         fxs = (class Pfxs *)port;
2221                         if (fxs->p_m_mISDNport == ourfxs->p_m_mISDNport && fxs != ourfxs) {
2222                                 if (fxs->p_state == PORT_STATE_OUT_ALERTING)
2223                                         break;
2224                         }
2225                 }
2226                 port = port->next;
2227         }
2228         if (!port) {
2229                 trace_header("ACTION pots-reject (no call waiting)", DIRECTION_NONE);
2230                 end_trace();
2231                 goto disconnect;
2232         }
2233
2234         /* reject alerting call */
2235         fxs->reject_ind(0);
2236
2237         /* indicate timeout, so next action will be processed */
2238         process_dialing(1);
2239 #endif
2240 }
2241
2242
2243 /* process pots-answer
2244  */
2245 void EndpointAppPBX::action_init_pots_answer(void)
2246 {
2247 #ifdef ISDN_P_FXS_POTS
2248         struct port_list *portlist = ea_endpoint->ep_portlist;
2249         class Port *port;
2250         class Pfxs *ourfxs, *fxs;
2251
2252         /* find call */
2253         port = find_port_id(portlist->port_id);
2254         if (!port)
2255                 goto disconnect;
2256         if ((port->p_type & PORT_CLASS_POTS_MASK) != PORT_CLASS_POTS_FXS) {
2257                 trace_header("ACTION pots-answer (call not of FXS type)", DIRECTION_NONE);
2258                 end_trace();
2259                 disconnect:
2260                 new_state(EPOINT_STATE_OUT_DISCONNECT);
2261                 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2262                 set_tone(portlist, "cause_3f");
2263                 e_action = NULL;
2264                 return;
2265         }
2266         ourfxs = (class Pfxs *)port;
2267
2268         port = port_first;
2269         while(port) {
2270                 if ((port->p_type & PORT_CLASS_POTS_MASK) == PORT_CLASS_POTS_FXS) {
2271                         fxs = (class Pfxs *)port;
2272                         if (fxs->p_m_mISDNport == ourfxs->p_m_mISDNport && fxs != ourfxs) {
2273                                 if (fxs->p_state == PORT_STATE_OUT_ALERTING)
2274                                         break;
2275                         }
2276                 }
2277                 port = port->next;
2278         }
2279         if (!port) {
2280                 trace_header("ACTION pots-answer (no call waiting)", DIRECTION_NONE);
2281                 end_trace();
2282                 goto disconnect;
2283         }
2284
2285         /* release our call */
2286         ourfxs->hangup_ind(0);
2287
2288         /* answer alerting call */
2289         fxs->answer_ind(0);
2290 #endif
2291 }
2292
2293
2294 /* process pots-3pty
2295  */
2296 void EndpointAppPBX::action_init_pots_3pty(void)
2297 {
2298 #ifdef ISDN_P_FXS_POTS
2299         struct port_list *portlist = ea_endpoint->ep_portlist;
2300         class Port *port;
2301         class Pfxs *ourfxs, *fxs, *fxs1 = NULL, *fxs2 = NULL;
2302         class Endpoint *epoint;
2303         int count = 0;
2304
2305         /* find call */
2306         port = find_port_id(portlist->port_id);
2307         if (!port)
2308                 goto disconnect;
2309         if ((port->p_type & PORT_CLASS_POTS_MASK) != PORT_CLASS_POTS_FXS) {
2310                 trace_header("ACTION pots-3pty (call not of FXS type)", DIRECTION_NONE);
2311                 end_trace();
2312                 disconnect:
2313                 new_state(EPOINT_STATE_OUT_DISCONNECT);
2314                 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2315                 set_tone(portlist, "cause_3f");
2316                 e_action = NULL;
2317                 return;
2318         }
2319         ourfxs = (class Pfxs *)port;
2320
2321         port = port_first;
2322         while(port) {
2323                 if ((port->p_type & PORT_CLASS_POTS_MASK) == PORT_CLASS_POTS_FXS) {
2324                         fxs = (class Pfxs *)port;
2325                         if (fxs->p_m_mISDNport == ourfxs->p_m_mISDNport && fxs != ourfxs) {
2326                                 if (count == 0)
2327                                         fxs1 = fxs;
2328                                 if (count == 1)
2329                                         fxs2 = fxs;
2330                                 count++;
2331                         }
2332                 }
2333                 port = port->next;
2334         }
2335         if (count != 2) {
2336                 trace_header("ACTION pots-3pty (exactly two calls don't exist)", DIRECTION_NONE);
2337                 end_trace();
2338                 goto disconnect;
2339         }
2340
2341         /* release our call */
2342         ourfxs->hangup_ind(0);
2343
2344         /* retrieve latest active call */
2345         if (fxs2->p_m_fxs_age > fxs1->p_m_fxs_age) {
2346                 fxs2->retrieve_ind(0);
2347                 epoint = find_epoint_id(ACTIVE_EPOINT(fxs2->p_epointlist));
2348         } else {
2349                 fxs1->retrieve_ind(0);
2350                 epoint = find_epoint_id(ACTIVE_EPOINT(fxs2->p_epointlist));
2351         }
2352
2353         if (!epoint) {
2354                 trace_header("ACTION pots-3pty (interal error: no endpoint)", DIRECTION_NONE);
2355                 end_trace();
2356                 return;
2357         }
2358
2359         if (epoint->ep_app_type != EAPP_TYPE_PBX) {
2360                 trace_header("ACTION pots-3pty (interal error: endpoint not PBX type)", DIRECTION_NONE);
2361                 end_trace();
2362                 return;
2363         }
2364
2365         /* bridge calls */
2366         if (((class EndpointAppPBX *)epoint->ep_app)->join_3pty_fxs()) {
2367                 trace_header("ACTION pots-3pty (interal error: join_3pty_fsx failed)", DIRECTION_NONE);
2368                 end_trace();
2369                 return;
2370         }
2371 #endif
2372 }
2373
2374 /* process pots-transfer
2375  */
2376 void EndpointAppPBX::action_init_pots_transfer(void)
2377 {
2378 #ifdef ISDN_P_FXS_POTS
2379         struct route_param *rparam;
2380         struct port_list *portlist = ea_endpoint->ep_portlist;
2381         class Port *port;
2382         class Pfxs *ourfxs, *fxs, *fxs1 = NULL, *fxs2 = NULL;
2383         int count = 0;
2384
2385         /* check given call */
2386         if (!(rparam = routeparam(e_action, PARAM_POTS_CALL))) {
2387                 trace_header("ACTION pots-transfer (no call given)", DIRECTION_NONE);
2388                 end_trace();
2389
2390                 disconnect:
2391                 new_state(EPOINT_STATE_OUT_DISCONNECT);
2392                 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2393                 set_tone(portlist, "cause_3f");
2394                 e_action = NULL;
2395                 return;
2396         }
2397
2398         /* find call */
2399         port = find_port_id(portlist->port_id);
2400         if (!port)
2401                 goto disconnect;
2402         if ((port->p_type & PORT_CLASS_POTS_MASK) != PORT_CLASS_POTS_FXS) {
2403                 trace_header("ACTION pots-transfer (call not of FXS type)", DIRECTION_NONE);
2404                 end_trace();
2405                 goto disconnect;
2406         }
2407         ourfxs = (class Pfxs *)port;
2408
2409         port = port_first;
2410         while(port) {
2411                 if ((port->p_type & PORT_CLASS_POTS_MASK) == PORT_CLASS_POTS_FXS) {
2412                         fxs = (class Pfxs *)port;
2413                         if (fxs->p_m_mISDNport == ourfxs->p_m_mISDNport && fxs != ourfxs) {
2414                                 if (count == 0)
2415                                         fxs1 = fxs;
2416                                 if (count == 1)
2417                                         fxs2 = fxs;
2418                                 count++;
2419                         }
2420                 }
2421                 port = port->next;
2422         }
2423         if (count != 2) {
2424                 trace_header("ACTION pots-transfer (exactly two calls don't exist)", DIRECTION_NONE);
2425                 end_trace();
2426                 goto disconnect;
2427         }
2428
2429         /* retrieve call */
2430         if (fxs2->p_m_fxs_age > fxs1->p_m_fxs_age)
2431                 fxs2->retrieve_ind(0);
2432         else
2433                 fxs1->retrieve_ind(0);
2434         /* bridge calls */
2435         join_join_fxs();
2436 #endif
2437 }
2438
2439
2440 /* general process dialing of incoming call
2441  * depending on the detected prefix, subfunctions above (action_*) will be
2442  * calles.
2443  */
2444 void EndpointAppPBX::process_dialing(int timeout)
2445 {
2446         struct port_list *portlist = ea_endpoint->ep_portlist;
2447         struct lcr_msg *message;
2448         struct route_param *rparam;
2449         struct timeval current_time;
2450
2451         /* set if timeout is active, or if timeout value was given due to timeout action */
2452         if (e_action_timeout.active)
2453                 timeout = 1;
2454
2455 //#warning Due to HANG-BUG somewhere here, I added some HANG-BUG-DEBUGGING output that cannot be disabled. after bug has been found, this will be removed.
2456 //PDEBUG(~0, "HANG-BUG-DEBUGGING: entered porcess_dialing\n");
2457         portlist = ea_endpoint->ep_portlist;
2458         /* check if we have a port instance linked to our epoint */
2459         if (!portlist) {
2460                 portlist_error:
2461                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): note: dialing call requires exactly one port object to process dialing. this case could happen due to a parked call. we end dialing here.\n", ea_endpoint->ep_serial, e_ext.number);
2462                 unsched_timer(&e_action_timeout);
2463                 unsched_timer(&e_match_timeout);
2464                 return;
2465         }
2466         if (portlist->next) {
2467                 goto portlist_error;
2468         }
2469
2470         /* check nesting levels */
2471         if (++e_rule_nesting > RULE_NESTING) {
2472                 trace_header("ACTION (nesting too deep)", DIRECTION_NONE);
2473                 add_trace("max-levels", NULL, "%d", RULE_NESTING);
2474                 end_trace();
2475                 new_state(EPOINT_STATE_OUT_DISCONNECT);
2476                 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2477                 set_tone(portlist, "cause_3f");
2478                 unsched_timer(&e_action_timeout);
2479                 unsched_timer(&e_match_timeout);
2480                 goto end;
2481         }
2482
2483 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before action-timeout processing\n");
2484         /* process timeout */
2485         if (e_action && timeout) { /* e_action may be NULL, but e_action_timeout may still be set and must be ignored */
2486                 unsched_timer(&e_action_timeout);
2487                 if (e_state == EPOINT_STATE_CONNECT) {
2488                         PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action timed out, but we already have connected, so we stop timer and continue.\n", ea_endpoint->ep_serial);
2489                         goto end;
2490                 }
2491                 if (e_action->index == ACTION_DISCONNECT
2492                  || e_state == EPOINT_STATE_OUT_DISCONNECT) {
2493                         /* release after disconnect */
2494                         release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0);
2495                         goto end;
2496                 }
2497                 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
2498                 e_action = e_action->next;
2499                 if (!e_action) {
2500                         /* nothing more, so we release */
2501                         PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action timed out, and we have no next action, so we disconnect.\n", ea_endpoint->ep_serial);
2502                         new_state(EPOINT_STATE_OUT_DISCONNECT);
2503                         message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2504                         set_tone(portlist, "cause_3f");
2505                         goto end;
2506                 }
2507                 goto action_timeout;
2508         }
2509
2510 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before setup/overlap state checking\n");
2511         if (e_state!=EPOINT_STATE_IN_SETUP
2512          && e_state!=EPOINT_STATE_IN_OVERLAP) {
2513                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): we are not in incoming setup/overlap state, so we ignore init/dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting);
2514                 unsched_timer(&e_match_timeout);
2515                 goto end;
2516         }
2517
2518 #if 0
2519         /* check if we do menu selection */
2520         if (e_action==NUMB_ACTION_NONE && (e_dialinginfo.id[0]=='*' || e_dialinginfo.id[0]=='#'))
2521         /* do menu selection */
2522         if (e_ext.display_menu) {
2523                 if (portlist->port_type==PORT_TYPE_DSS1_NT_IN || portlist->port_type==PORT_TYPE_DSS1_NT_OUT) { /* only if the dialing terminal is an isdn telephone connected to an internal port */
2524                         e_dialinginfo.id[0] = '\0';
2525                         e_action = NUMB_ACTION_MENU;
2526                         e_menu = 0;
2527                         process_dialing(0);
2528                         unsched_timer(&e_match_timeout);
2529                         goto end;
2530                 }
2531                 /* invalid dialing */
2532                 message_disconnect_port(portlist, CAUSE_INCALID, LOCATION_PRIVATE_LOCAL, "");
2533                         message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
2534                         message->param.disconnectinfo.cause = CAUSE_INVALID;
2535                         message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2536                                 } else {
2537                                         message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2538                                         SCPY(message->param.notifyinfo.display,get_isdn_cause(LOCATION_PRIVATE_LOCAL, epoint->e_ext.display_cause, param->disconnectinfo.location, param->disconnectinfo.cause));
2539                                 }
2540                         message_put(message);
2541                         logmessage(message->type, message->param, portlist->port_id, DIRECTION_OUT);
2542                 }
2543                 new_state(EPOINT_STATE_OUT_DISCONNECT);
2544                 set_tone(portlist,"cause_1c");
2545                 unsched_timer(&e_match_timeout);
2546                 goto end;
2547         }
2548 #endif
2549
2550 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before e_action==NULL\n");
2551         /* if no action yet, we will call try to find a matching rule */
2552         if (!e_action) {
2553                 /* be sure that all selectors are initialized */
2554                 e_select = 0;
2555
2556                 /* check for external call */
2557                 if (!strncmp(e_dialinginfo.id, "extern:", 7)) {
2558                         e_extdialing = e_dialinginfo.id+7;
2559                         e_action = &action_external;
2560                         goto process_action;
2561                 }
2562                 /* check for internal call */
2563                 if (!strncmp(e_dialinginfo.id, "intern:", 7)) {
2564                         e_extdialing = e_dialinginfo.id+7;
2565                         e_action = &action_internal;
2566                         goto process_action;
2567                 }
2568                 /* check for vbox call */
2569                 if (!strncmp(e_dialinginfo.id, "vbox:", 5)) {
2570                         e_extdialing = e_dialinginfo.id+5;
2571                         e_action = &action_vbox;
2572                         goto process_action;
2573                 }
2574
2575                 gettimeofday(&current_time, NULL);
2576                 if (e_match_to_action && TIME_SMALLER(&e_match_timeout.timeout, &current_time)) {
2577                         /* return timeout rule */
2578                         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s' dialing: '%s', timeout in ruleset '%s'\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id, e_ruleset->name);
2579                         unsched_timer(&e_match_timeout);
2580                         e_action = e_match_to_action;
2581                         e_match_to_action = NULL;
2582                         e_extdialing = e_match_to_extdialing;
2583                         trace_header("ROUTING (timeout)", DIRECTION_NONE);
2584                         add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2585                         add_trace("line", NULL, "%d", e_action->line);
2586                         end_trace();
2587                 } else {
2588 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before routing\n");
2589                         /* check for matching rule */
2590                         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s' dialing: '%s', checking matching rule of ruleset '%s'\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id, e_ruleset->name);
2591                         if (e_ruleset) {
2592                                 e_action = route(e_ruleset);
2593                                 if (e_action) {
2594                                         trace_header("ACTION (match)", DIRECTION_NONE);
2595                                         add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2596                                         add_trace("line", NULL, "%d", e_action->line);
2597                                         end_trace();
2598                                 }
2599                         } else {
2600                                 e_action = &action_disconnect;
2601                                 if (e_action) {
2602                                         trace_header("ACTION (no main ruleset, disconnecting)", DIRECTION_NONE);
2603                                         end_trace();
2604                                 }
2605                         }
2606 //PDEBUG(~0, "HANG-BUG-DEBUGGING: after routing\n");
2607                 }
2608                 if (!e_action) {
2609                         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): no rule within the current ruleset matches yet.\n", ea_endpoint->ep_serial, e_ext.number);
2610                         goto display;
2611                 }
2612
2613                 /* matching */
2614                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): a rule with action '%s' matches.\n", ea_endpoint->ep_serial, action_defs[e_action->index].name);
2615
2616                 action_timeout:
2617
2618                 /* set timeout */
2619                 unsched_timer(&e_action_timeout);
2620                 if (e_action->timeout) {
2621                         schedule_timer(&e_action_timeout, e_action->timeout, 0);
2622                         PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action has a timeout of %d secods.\n", ea_endpoint->ep_serial, e_action->timeout);
2623                 }
2624
2625                 process_action:
2626                 /* check param proceeding / alerting / connect */
2627                 if ((rparam = routeparam(e_action, PARAM_CONNECT))) {
2628                         /* NOTE: we may not change our state to connect, because dialing will then not possible */
2629                         e_dtmf = 1;
2630                         memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2631                         message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
2632                         message_put(message);
2633                         logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2634                 } else
2635                 if ((rparam = routeparam(e_action, PARAM_ALERTING))) {
2636                         /* NOTE: we may not change our state to alerting, because dialing will then not possible */
2637                         memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2638                         message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
2639                         message_put(message);
2640                         logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2641                 } else
2642                 if ((rparam = routeparam(e_action, PARAM_PROCEEDING))) {
2643                         /* NOTE: we may not change our state to proceeding, because dialing will then not possible */
2644                         memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2645                         message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
2646                         message_put(message);
2647                         logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2648                 }
2649
2650                 if (action_defs[e_action->index].init_func) {
2651                         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: current action '%s' has a init function, so we call it...\n", ea_endpoint->ep_serial, e_ext.number, action_defs[e_action->index].name);
2652                         (this->*(action_defs[e_action->index].init_func))();
2653                 }
2654                 if (e_state!=EPOINT_STATE_IN_SETUP
2655                  && e_state!=EPOINT_STATE_IN_OVERLAP) {
2656                         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): AFTER init process: we are not in incoming setup/overlap state anymore, so we ignore further dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting);
2657                         goto display_action;
2658                 }
2659         }
2660
2661         /* show what we are doing */
2662         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s' action: %s (dialing '%s')\n", ea_endpoint->ep_serial, e_ext.number, action_defs[e_action->index].name, e_extdialing);
2663         /* go to action's dialing function */
2664         if (action_defs[e_action->index].dialing_func) {
2665                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: current action '%s' has a dialing function, so we call it...\n", ea_endpoint->ep_serial, e_ext.number, action_defs[e_action->index].name);
2666                 (this->*(action_defs[e_action->index].dialing_func))();
2667         }
2668
2669         /* display selected dialing action if enabled and still in setup state */
2670         display_action:
2671         if (e_action) {
2672                 if (e_action->index==ACTION_MENU
2673                  || e_action->index==ACTION_REDIAL
2674                  || e_action->index==ACTION_REPLY
2675                  || e_action->index==ACTION_TIMER
2676                  || e_action->index==ACTION_CALCULATOR
2677                  || e_action->index==ACTION_TEST)
2678                         goto end;
2679         }
2680         display:
2681         if (!e_ext.display_dialing)
2682                 goto end;
2683         if (e_state==EPOINT_STATE_IN_OVERLAP || e_state==EPOINT_STATE_IN_PROCEEDING || e_state==EPOINT_STATE_IN_ALERTING || e_state==EPOINT_STATE_CONNECT/* || e_state==EPOINT_STATE_IN_DISCONNECT || e_state==EPOINT_STATE_OUT_DISCONNECT*/)
2684         if (portlist->port_type==PORT_TYPE_DSS1_NT_IN || portlist->port_type==PORT_TYPE_DSS1_NT_OUT) { /* only if the dialing terminal is an isdn telephone connected to an internal port */
2685                 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2686
2687                 if (!e_action) {
2688                         SPRINT(message->param.notifyinfo.display, "> %s", e_dialinginfo.id);
2689                 } else {
2690                         SPRINT(message->param.notifyinfo.display, "%s%s%s", action_defs[e_action->index].name, (e_extdialing[0])?" ":"", e_extdialing);
2691                 }
2692
2693                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s'\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
2694                 message_put(message);
2695                 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2696         }
2697
2698 end:
2699         e_rule_nesting--;
2700         return;
2701 }
2702
2703
2704 /* some services store information after hangup */
2705 void EndpointAppPBX::process_hangup(int cause, int location)
2706 {
2707         char callertext[256], dialingtext[256];
2708         int writeext = 0, i;
2709
2710         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s'\n", ea_endpoint->ep_serial, e_ext.number);
2711         if (e_ext.number[0]) {
2712                 if (read_extension(&e_ext, e_ext.number))
2713                         writeext = 0x10;
2714
2715                 if (!e_start) {
2716                         time(&e_start);
2717                         e_stop = 0;
2718                 } else
2719                 if (!e_stop)
2720                         time(&e_stop);
2721                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): writing connect from %s to %s into logfile of %s\n", ea_endpoint->ep_serial, e_callerinfo.id, e_dialinginfo.id, e_ext.number);
2722                 switch(e_dialinginfo.itype) {
2723                         case INFO_ITYPE_CHAN:
2724                         SPRINT(dialingtext, "chan:%s", e_dialinginfo.id);
2725                         break;
2726                         case INFO_ITYPE_ISDN_EXTENSION:
2727                         SPRINT(dialingtext, "intern:%s", e_dialinginfo.id);
2728                         break;
2729                         case INFO_ITYPE_VBOX:
2730                         SPRINT(dialingtext, "vbox:%s", e_dialinginfo.id);
2731                         break;
2732                         default:
2733                         SPRINT(dialingtext, "%s", e_dialinginfo.id);
2734                 }
2735
2736                 if (e_callerinfo.id[0])
2737                         SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2738                 else
2739                         SPRINT(callertext, "unknown");
2740                 /* allpy restriction */
2741                 if (!e_ext.anon_ignore && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
2742                         SPRINT(callertext, "anonymous");
2743                 if (e_callerinfo.extension[0]) /* add intern if present */
2744                         UNPRINT(strchr(callertext,'\0'), sizeof(callertext)-1+strlen(callertext), " (intern %s)", e_callerinfo.extension);
2745                 write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location);
2746
2747                 /* store last received call for reply-list */
2748                 if (e_origin == 1) // outgoing to phone is incoming for user
2749                 if (e_callerinfo.id[0] || e_callerinfo.extension[0])
2750                 if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED) {
2751                         if (e_callerinfo.extension[0])
2752                                 SPRINT(callertext, "intern:%s", e_callerinfo.extension);
2753                         else
2754                                 SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2755                         if (!!strcmp(callertext, e_ext.last_in[0])) {
2756                                 i = MAX_REMEMBER-1;
2757                                 while(i) {
2758                                         UCPY(e_ext.last_in[i], e_ext.last_in[i-1]);
2759                                         i--;
2760                                 }
2761                                 SCPY(e_ext.last_in[0], callertext);
2762                                 writeext |= 1; /* store extension later */
2763                                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last received caller id '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_ext.last_in[0]);
2764                         } else
2765                                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last received id '%s' because it is identical with the last one.\n", ea_endpoint->ep_serial, e_ext.number, callertext);
2766                 }
2767
2768                 /* store last made call for reply-list */
2769                 if (e_origin == 0) // incoming from phone is outgoing for user
2770                 if (e_dialinginfo.id[0]) {
2771                         if (!!strcmp(e_dialinginfo.id, e_ext.last_out[0])) {
2772                                 i = MAX_REMEMBER-1;
2773                                 while(i) {
2774                                         UCPY(e_ext.last_out[i], e_ext.last_out[i-1]);
2775                                         i--;
2776                                 }
2777                                 SCPY(e_ext.last_out[0], e_dialinginfo.id);
2778                                 writeext |= 1; /* store extension later */
2779                                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
2780                         } else
2781                                 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last number '%s' because it is identical with the last one.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
2782                 }
2783         }
2784         /* write extension if needed */
2785         if (writeext == 0x11)
2786                 write_extension(&e_ext, e_ext.number);
2787
2788         if (e_action) {
2789                 if (action_defs[e_action->index].hangup_func) {
2790                         PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: current action '%s' has a hangup function, so we call it...\n", ea_endpoint->ep_serial, e_ext.number, action_defs[e_action->index].name);
2791                         (this->*(action_defs[e_action->index].hangup_func))();
2792                 }
2793         }
2794 }
2795