1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** all actions (and hangup) are processed here **
10 \*****************************************************************************/
18 #include "linux/isdnif.h"
20 extern char **environ;
23 /* create caller id from digits by comparing with national and international
26 char *nationalize_callerinfo(char *string, int *ntype)
28 if (!strncmp(options.international, string, strlen(options.international)))
30 *ntype = INFO_NTYPE_INTERNATIONAL;
31 return(string+strlen(options.international));
33 if (!strncmp(options.national, string, strlen(options.national)))
35 *ntype = INFO_NTYPE_NATIONAL;
36 return(string+strlen(options.national));
38 *ntype = INFO_NTYPE_SUBSCRIBER;
42 /* create number (including access codes) from caller id
45 char *numberrize_callerinfo(char *string, int ntype)
47 static char result[256];
51 case INFO_NTYPE_INTERNATIONAL:
52 UCPY(result, options.international);
57 case INFO_NTYPE_NATIONAL:
58 UCPY(result, options.national);
70 * process init 'internal' / 'external' / 'chan' / 'vbox-record' / 'partyline'...
72 void EndpointAppPBX::_action_init_call(int chan)
75 struct port_list *portlist = ea_endpoint->ep_portlist;
77 /* a created call, this should never happen */
78 if (ea_endpoint->ep_call_id)
80 if (options.deb & DEBUG_EPOINT)
81 PERROR("EPOINT(%d): We already have a call instance, this should never happen!\n", ea_endpoint->ep_serial);
86 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new call instance.\n", ea_endpoint->ep_serial);
88 call = new CallChan(ea_endpoint);
90 call = new CallPBX(ea_endpoint);
93 /* resource not available */
94 message_disconnect_port(portlist, CAUSE_RESSOURCEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
95 new_state(EPOINT_STATE_OUT_DISCONNECT);
96 set_tone(portlist,"cause_22");
99 ea_endpoint->ep_call_id = call->c_serial;
101 void EndpointAppPBX::action_init_call(void)
103 _action_init_call(0);
105 void EndpointAppPBX::action_init_chan(void)
107 _action_init_call(1);
111 * process dialing 'internal'
113 void EndpointAppPBX::action_dialing_internal(void)
115 struct capa_info capainfo;
116 struct caller_info callerinfo;
117 struct redir_info redirinfo;
118 struct dialing_info dialinginfo;
119 struct port_list *portlist = ea_endpoint->ep_portlist;
120 struct message *message;
121 struct extension ext;
122 struct route_param *rparam;
124 /* send proceeding, because number is complete */
125 set_tone(portlist, "proceeding");
126 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
127 message_put(message);
129 new_state(EPOINT_STATE_IN_PROCEEDING);
131 /* create bearer/caller/dialinginfo */
132 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
133 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
134 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
135 memset(&dialinginfo, 0, sizeof(dialinginfo));
136 dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
137 SCPY(dialinginfo.id, e_dialinginfo.id);
139 /* process extension */
140 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
141 SCPY(dialinginfo.id, rparam->string_value);
143 /* process number type */
144 if ((rparam = routeparam(e_action, PARAM_TYPE)))
145 dialinginfo.ntype = rparam->integer_value;
147 /* process service */
148 if ((rparam = routeparam(e_action, PARAM_CAPA)))
150 capainfo.bearer_capa = rparam->integer_value;
151 if (capainfo.bearer_capa != INFO_BC_SPEECH
152 && capainfo.bearer_capa != INFO_BC_AUDIO)
154 capainfo.bearer_mode = INFO_BMODE_PACKET;
156 capainfo.bearer_info1 = INFO_INFO1_NONE;
158 if ((rparam = routeparam(e_action, PARAM_BMODE)))
160 capainfo.bearer_mode = rparam->integer_value;
162 if ((rparam = routeparam(e_action, PARAM_INFO1)))
164 capainfo.bearer_info1 = rparam->integer_value;
166 if ((rparam = routeparam(e_action, PARAM_HLC)))
168 capainfo.hlc = rparam->integer_value;
170 if ((rparam = routeparam(e_action, PARAM_EXTHLC)))
172 capainfo.exthlc = rparam->integer_value;
175 /* process presentation */
176 if ((rparam = routeparam(e_action, PARAM_PRESENT)))
178 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
181 /* check if extension exists AND only if not multiple extensions */
182 if (!read_extension(&ext, dialinginfo.id) && !strchr(dialinginfo.id,','))
184 trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE);
185 add_trace("extension", NULL, dialinginfo.id);
187 new_state(EPOINT_STATE_OUT_DISCONNECT);
188 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
189 set_tone(portlist, "cause_86");
192 /* check if internal calls are denied */
193 if (e_ext.rights < 1)
195 trace_header("ACTION extension (dialing to extension denied)", DIRECTION_NONE);
196 add_trace("extension", NULL, dialinginfo.id);
198 new_state(EPOINT_STATE_OUT_DISCONNECT);
199 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
200 set_tone(portlist, "cause_81");
204 /* add or update internal call */
205 trace_header("ACTION extension (calling)", DIRECTION_NONE);
206 add_trace("extension", NULL, dialinginfo.id);
208 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_call_id, EPOINT_TO_CALL, MESSAGE_SETUP);
209 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
210 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
211 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
212 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
213 message_put(message);
216 /* process dialing external
218 void EndpointAppPBX::action_dialing_external(void)
220 struct capa_info capainfo;
221 struct caller_info callerinfo;
222 struct redir_info redirinfo;
223 struct dialing_info dialinginfo;
225 struct port_list *portlist = ea_endpoint->ep_portlist;
226 struct message *message;
227 struct route_param *rparam;
229 /* special processing of delete characters '*' and '#' */
230 if (e_ext.delete_ext)
232 /* dialing a # causes a clearing of complete number */
233 if (strchr(e_extdialing, '#'))
235 e_extdialing[0] = '\0';
236 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);
238 /* eliminate digits before '*', which is a delete digit
240 if (strchr(e_extdialing, '*'))
243 while((p=strchr(e_extdialing, '*')))
245 if (p > e_extdialing) /* only if there is a digit in front */
250 UCPY(p, p+1); /* remove '*' */
252 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s deleted digits and got new string: %s\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing);
256 /* create bearer/caller/dialinginfo */
257 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
258 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
259 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
260 memset(&dialinginfo, 0, sizeof(dialinginfo));
261 dialinginfo.itype = INFO_ITYPE_ISDN;
262 dialinginfo.sending_complete = 0;
263 SCPY(dialinginfo.id, e_extdialing);
266 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
267 SPRINT(dialinginfo.id, "%s%s", rparam->string_value, e_extdialing);
269 /* process number complete */
270 if ((rparam = routeparam(e_action, PARAM_COMPLETE)))
271 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
272 SCPY(dialinginfo.id, rparam->string_value);
273 dialinginfo.sending_complete = 1;
275 /* process number type */
276 if ((rparam = routeparam(e_action, PARAM_TYPE)))
277 dialinginfo.ntype = rparam->integer_value;
279 /* process service */
280 if ((rparam = routeparam(e_action, PARAM_CAPA)))
282 capainfo.bearer_capa = rparam->integer_value;
283 if (capainfo.bearer_capa != INFO_BC_SPEECH
284 && capainfo.bearer_capa != INFO_BC_AUDIO)
286 capainfo.bearer_mode = INFO_BMODE_PACKET;
288 capainfo.bearer_info1 = INFO_INFO1_NONE;
290 if ((rparam = routeparam(e_action, PARAM_BMODE)))
292 capainfo.bearer_mode = rparam->integer_value;
294 if ((rparam = routeparam(e_action, PARAM_INFO1)))
296 capainfo.bearer_info1 = rparam->integer_value;
298 if ((rparam = routeparam(e_action, PARAM_HLC)))
300 capainfo.hlc = rparam->integer_value;
302 if ((rparam = routeparam(e_action, PARAM_EXTHLC)))
304 capainfo.exthlc = rparam->integer_value;
308 /* process callerid */
309 if ((rparam = routeparam(e_action, PARAM_CALLERID)))
311 SCPY(callerinfo.id, rparam->string_value);
313 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
315 callerinfo.ntype = rparam->integer_value;
318 /* process presentation */
319 if ((rparam = routeparam(e_action, PARAM_PRESENT)))
321 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
324 /* process interfaces */
325 if ((rparam = routeparam(e_action, PARAM_INTERFACES)))
326 SCPY(dialinginfo.interfaces, rparam->string_value);
328 /* check if local calls are denied */
329 if (e_ext.rights < 2)
331 trace_header("ACTION extern (calling denied)", DIRECTION_NONE);
333 release(RELEASE_CALL, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0);
334 set_tone(portlist, "cause_82");
336 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
337 new_state(EPOINT_STATE_OUT_DISCONNECT);
341 if (!strncmp(dialinginfo.id, options.national, strlen(options.national))
342 || dialinginfo.ntype == INFO_NTYPE_NATIONAL
343 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL)
345 /* check if national calls are denied */
346 if (e_ext.rights < 3)
348 trace_header("ACTION extern (national calls denied)", DIRECTION_NONE);
350 release(RELEASE_CALL, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0);
351 set_tone(portlist, "cause_83");
356 if (!strncmp(dialinginfo.id, options.international, strlen(options.international))
357 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL)
359 /* check if international calls are denied */
360 if (e_ext.rights < 4)
362 trace_header("ACTION extern (international calls denied)", DIRECTION_NONE);
364 release(RELEASE_CALL, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0);
365 set_tone(portlist, "cause_84");
370 /* add or update outgoing call */
371 trace_header("ACTION extern (calling)", DIRECTION_NONE);
372 add_trace("number", NULL, dialinginfo.id);
373 if (dialinginfo.interfaces[0])
374 add_trace("interfaces", NULL, dialinginfo.interfaces);
376 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_call_id, EPOINT_TO_CALL, MESSAGE_SETUP);
377 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
378 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
379 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
380 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
381 message_put(message);
385 void EndpointAppPBX::action_dialing_chan(void)
387 struct port_list *portlist = ea_endpoint->ep_portlist;
389 trace_header("ACTION channel (not implemented)", DIRECTION_NONE);
391 message_disconnect_port(portlist, CAUSE_UNIMPLEMENTED, LOCATION_PRIVATE_LOCAL, "");
392 new_state(EPOINT_STATE_OUT_DISCONNECT);
393 set_tone(portlist,"cause_4f");
398 * process dialing the "am" and record
400 void EndpointAppPBX::action_dialing_vbox_record(void)
402 struct dialing_info dialinginfo;
403 struct port_list *portlist = ea_endpoint->ep_portlist;
404 struct message *message;
405 struct extension ext;
406 struct route_param *rparam;
408 portlist = ea_endpoint->ep_portlist;
410 /* check for given extension */
411 if (!(rparam = routeparam(e_action, PARAM_EXTENSION)))
413 trace_header("ACTION vbox-record (no extension given by parameter)", DIRECTION_NONE);
416 new_state(EPOINT_STATE_OUT_DISCONNECT);
417 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
418 set_tone(portlist, "cause_3f");
422 /* check if extension exists */
423 if (!read_extension(&ext, rparam->string_value))
425 trace_header("ACTION vbox-record (given extension does not exists)", DIRECTION_NONE);
426 add_trace("extension", NULL, "%s", rparam->string_value);
428 new_state(EPOINT_STATE_OUT_DISCONNECT);
429 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
430 set_tone(portlist, "cause_86");
434 /* check if internal calls are denied */
435 if (e_ext.rights < 1)
437 trace_header("ACTION vbox-record (internal calls are denied)", DIRECTION_NONE);
439 new_state(EPOINT_STATE_OUT_DISCONNECT);
440 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
441 set_tone(portlist, "cause_81");
445 set_tone(portlist, "proceeding");
446 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
447 message_put(message);
449 new_state(EPOINT_STATE_IN_PROCEEDING);
451 memset(&dialinginfo, 0, sizeof(dialinginfo));
452 dialinginfo.itype = INFO_ITYPE_VBOX;
453 dialinginfo.sending_complete = 1;
454 SCPY(dialinginfo.id, rparam->string_value);
456 /* append special announcement (if given) */
457 if ((rparam = routeparam(e_action, PARAM_ANNOUNCEMENT)))
458 if (rparam->string_value[0])
460 SCAT(dialinginfo.id, ",");
461 SCAT(dialinginfo.id, rparam->string_value);
464 /* add or update internal call */
465 trace_header("ACTION vbox-record (calling)", DIRECTION_NONE);
466 add_trace("extension", NULL, "%s", dialinginfo.id);
468 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_call_id, EPOINT_TO_CALL, MESSAGE_SETUP);
469 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
470 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
471 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
472 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
473 message_put(message);
480 void EndpointAppPBX::action_init_partyline(void)
483 class CallPBX *callpbx;
484 struct port_list *portlist = ea_endpoint->ep_portlist;
485 struct message *message;
486 struct route_param *rparam;
488 struct call_relation *relation;
490 portlist = ea_endpoint->ep_portlist;
492 /* check for given extension */
493 if (!(rparam = routeparam(e_action, PARAM_ROOM)))
495 trace_header("ACTION partyline (no room parameter)", DIRECTION_NONE);
498 new_state(EPOINT_STATE_OUT_DISCONNECT);
499 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
500 set_tone(portlist, "cause_3f");
503 if (rparam->integer_value <= 0)
505 trace_header("ACTION partyline (illegal room parameter)", DIRECTION_NONE);
506 add_trace("room", NULL, "%d", rparam->integer_value);
508 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): invalid value for 'room'.\n", ea_endpoint->ep_serial);
511 partyline = rparam->integer_value;
513 /* don't create call if partyline exists */
517 if (call->c_type == CALL_TYPE_PBX)
519 callpbx = (class CallPBX *)call;
520 if (callpbx->c_partyline == rparam->integer_value)
528 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new call instance.\n", ea_endpoint->ep_serial);
529 if (!(call = new CallPBX(ea_endpoint)))
531 PERROR("no memory for call, exitting");
536 //NOTE: callpbx must be set here
537 /* add relation to existing call */
538 if (!(relation=callpbx->add_relation()))
540 PERROR("no memory for call relation, exitting");
543 relation->type = RELATION_TYPE_SETUP;
544 relation->channel_state = CHANNEL_STATE_CONNECT;
545 relation->rx_state = NOTIFY_STATE_ACTIVE;
546 relation->tx_state = NOTIFY_STATE_ACTIVE;
547 relation->epoint_id = ea_endpoint->ep_serial;
550 ea_endpoint->ep_call_id = call->c_serial;
552 set_tone(portlist, "proceeding");
553 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
554 message_put(message);
556 new_state(EPOINT_STATE_IN_PROCEEDING);
558 /* send setup to call */
559 trace_header("ACTION partyline (calling)", DIRECTION_NONE);
560 add_trace("room", NULL, "%d", partyline);
562 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_call_id, EPOINT_TO_CALL, MESSAGE_SETUP);
563 message->param.setup.partyline = partyline;
564 memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info));
565 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
566 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
567 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
568 message_put(message);
573 * process hangup of all calls
575 void EndpointAppPBX::action_hangup_call(void)
579 trace_header("ACTION hangup", DIRECTION_NONE);
582 if (e_ext.number[0] == '\0')
584 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last dialed number '%s' because caller is unknown (not internal).\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
587 if (!(read_extension(&e_ext, e_ext.number)))
589 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last dialed number '%s' because cannot read settings.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
592 if (e_dialinginfo.id[0] == '\0')
594 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last dialed number because nothing was dialed.\n", ea_endpoint->ep_serial, e_ext.number);
597 if (!strcmp(e_dialinginfo.id, e_ext.last_out[0]))
599 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last dialed number '%s' because it is identical with the last one.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
604 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
608 UCPY(e_ext.last_out[i], e_ext.last_out[i-1]);
611 SCPY(e_ext.last_out[0], e_dialinginfo.id);
613 /* write extension */
614 write_extension(&e_ext, e_ext.number);
619 * process dialing 'login'
621 void EndpointAppPBX::action_dialing_login(void)
623 struct port_list *portlist = ea_endpoint->ep_portlist;
624 struct message *message;
626 struct route_param *rparam;
628 /* extension parameter */
629 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
631 /* extension is given by parameter */
632 extension = rparam->string_value;
633 if (extension[0] == '\0')
635 if (!read_extension(&e_ext, extension))
637 trace_header("ACTION login (extension doesn't exist)", DIRECTION_NONE);
638 add_trace("extension", NULL, "%s", extension);
640 /* extension doesn't exist */
641 new_state(EPOINT_STATE_OUT_DISCONNECT);
642 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
643 set_tone(portlist, "cause_86");
648 /* extension must be given by dialstring */
649 extension = e_extdialing;
650 if (extension[0] == '\0')
652 if (!read_extension(&e_ext, extension))
654 trace_header("ACTION login (extension incomplete or does not exist)", DIRECTION_NONE);
655 add_trace("extension", NULL, "%s", extension);
661 /* we changed our extension */
662 SCPY(e_ext.number, extension);
663 new_state(EPOINT_STATE_CONNECT);
667 /* send connect with extension's caller id (COLP) */
668 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
669 SCPY(message->param.connectinfo.id, e_ext.callerid);
670 message->param.connectinfo.ntype = e_ext.callerid_type;
671 if (e_ext.callerid_present==INFO_PRESENT_ALLOWED && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
672 message->param.connectinfo.present = INFO_PRESENT_RESTRICTED;
673 else message->param.connectinfo.present = e_ext.callerid_present;
674 /* handle restricted caller ids */
675 apply_callerid_restriction(e_ext.anon_ignore, message->param.connectinfo.id, &message->param.connectinfo.ntype, &message->param.connectinfo.present, &message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name);
676 /* display callerid if desired for extension */
677 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));
678 message->param.connectinfo.ntype = e_ext.callerid_type;
679 message_put(message);
682 /* set our caller id */
683 SCPY(e_callerinfo.id, e_ext.callerid);
684 e_callerinfo.ntype = e_ext.callerid_type;
685 e_callerinfo.present = e_ext.callerid_present;
687 /* enable connectedmode */
691 if (!(rparam = routeparam(e_action, PARAM_NOPASSWORD)))
693 /* make call state to enter password */
694 trace_header("ACTION login (ask for password)", DIRECTION_NONE);
695 add_trace("extension", NULL, "%s", e_ext.number);
697 new_state(EPOINT_STATE_IN_OVERLAP);
700 e_action = &action_password;
702 e_match_to_action = NULL;
703 e_dialinginfo.id[0] = '\0';
704 e_extdialing = strchr(e_dialinginfo.id, '\0');
707 e_password_timeout = now+20;
713 /* make call state */
714 new_state(EPOINT_STATE_IN_OVERLAP);
715 e_ruleset = ruleset_main;
717 e_rule = e_ruleset->rule_first;
719 e_dialinginfo.id[0] = '\0';
720 e_extdialing = e_dialinginfo.id;
721 set_tone(portlist, "dialpbx");
727 * process init 'change_callerid'
729 void EndpointAppPBX::action_init_change_callerid(void)
731 struct port_list *portlist = ea_endpoint->ep_portlist;
733 if (!e_ext.change_callerid)
735 /* service not available */
736 trace_header("ACTION change-callerid (denied for this caller)", DIRECTION_NONE);
738 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
739 new_state(EPOINT_STATE_OUT_DISCONNECT);
740 set_tone(portlist,"cause_87");
745 /* process dialing callerid
747 void EndpointAppPBX::_action_callerid_calleridnext(int next)
749 struct port_list *portlist = ea_endpoint->ep_portlist;
750 struct route_param *rparam;
751 char buffer[64], *callerid;
752 char old_id[64] = "", new_id[64] = "";
753 int old_type=0, new_type=0, old_present=0, new_present=0;
755 if ((rparam = routeparam(e_action, PARAM_CALLERID)))
757 /* the caller ID is given by parameter */
758 callerid = rparam->string_value;
761 /* caller ID is dialed */
762 if (!strchr(e_extdialing, '#'))
764 /* no complete ID yet */
767 *strchr(e_extdialing, '#') = '\0';
768 callerid = e_extdialing;
771 /* given callerid type */
772 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
773 switch(rparam->integer_value)
775 case INFO_NTYPE_SUBSCRIBER:
776 SPRINT(buffer, "s%s", callerid);
779 case INFO_NTYPE_NATIONAL:
780 SPRINT(buffer, "n%s", callerid);
783 case INFO_NTYPE_INTERNATIONAL:
784 SPRINT(buffer, "i%s", callerid);
788 SPRINT(buffer, "%s", callerid);
793 /* caller id complete, dialing with new caller id */
794 /* write new parameters */
795 if (read_extension(&e_ext, e_ext.number))
797 old_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
798 old_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
799 SCPY(old_id, (!next)?e_ext.callerid:e_ext.id_next_call);
800 if (callerid[0] == '\0')
803 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
807 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_ALLOWED;
808 if ((rparam = routeparam(e_action, PARAM_PRESENT))) if (rparam->integer_value == 0)
809 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
810 if (e_ext.callerid_type == INFO_NTYPE_UNKNOWN) /* if callerid is unknown, the given id is not nationalized */
812 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, callerid);
813 (!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN;
816 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, nationalize_callerinfo(callerid,&((!next)?e_ext.callerid_type:e_ext.id_next_call_type)));
818 if (!next) e_ext.id_next_call_type = -1;
819 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);
821 new_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
822 new_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
823 SCPY(new_id, (!next)?e_ext.callerid:e_ext.id_next_call);
824 write_extension(&e_ext, e_ext.number);
827 /* function activated */
829 trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE);
831 trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE);
832 add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type));
833 add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
834 add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type));
835 add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
837 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
838 new_state(EPOINT_STATE_OUT_DISCONNECT);
839 set_tone(portlist,"activated");
842 /* process dialing callerid for all call
844 void EndpointAppPBX::action_dialing_callerid(void)
846 _action_callerid_calleridnext(0);
849 /* process dialing callerid for next call
851 void EndpointAppPBX::action_dialing_calleridnext(void)
853 _action_callerid_calleridnext(1);
858 * process init 'change_forward'
860 void EndpointAppPBX::action_init_change_forward(void)
862 struct port_list *portlist = ea_endpoint->ep_portlist;
864 if (!e_ext.change_forward)
866 trace_header("ACTION change-forward (denied for this caller)", DIRECTION_NONE);
868 /* service not available */
869 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
870 new_state(EPOINT_STATE_OUT_DISCONNECT);
871 set_tone(portlist,"cause_87");
876 /* process dialing forwarding
878 void EndpointAppPBX::action_dialing_forward(void)
880 struct port_list *portlist = ea_endpoint->ep_portlist;
881 int diversion = INFO_DIVERSION_CFU;
882 char *dest = e_extdialing;
883 struct route_param *rparam;
885 /* if diversion type is given */
886 if ((rparam = routeparam(e_action, PARAM_DIVERSION)))
887 diversion = rparam->integer_value;
889 if ((rparam = routeparam(e_action, PARAM_DEST)))
891 /* if destination is given */
892 dest = rparam->string_value;
895 if (!strchr(e_extdialing, '#'))
897 *strchr(e_extdialing, '#') = '\0';
901 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing forwarding to '%s'.\n", ea_endpoint->ep_serial, e_ext.number, dest);
902 if (read_extension(&e_ext, e_ext.number))
906 case INFO_DIVERSION_CFU:
907 trace_header("ACTION change-forward (new CFU=unconditional)", DIRECTION_NONE);
908 add_trace("destin'", NULL, "%s", dest);
910 SCPY(e_ext.cfu, dest);
912 case INFO_DIVERSION_CFB:
913 trace_header("ACTION change-forward (new CFB=busy)", DIRECTION_NONE);
914 add_trace("destin'", NULL, "%s", dest);
916 SCPY(e_ext.cfb, dest);
918 case INFO_DIVERSION_CFNR:
919 if ((rparam = routeparam(e_action, PARAM_DELAY)))
920 e_ext.cfnr_delay = rparam->integer_value;
921 trace_header("ACTION change-forward (new CFNR=no response)", DIRECTION_NONE);
922 add_trace("destin'", NULL, "%s", dest);
923 add_trace("delay", NULL, "%s", e_ext.cfnr_delay);
925 SCPY(e_ext.cfnr, dest);
927 case INFO_DIVERSION_CFP:
928 trace_header("ACTION change-forward (new CFP=parallel)", DIRECTION_NONE);
929 add_trace("destin'", NULL, "%s", dest);
931 SCPY(e_ext.cfp, dest);
934 write_extension(&e_ext, e_ext.number);
936 /* function (de)activated */
937 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
938 new_state(EPOINT_STATE_OUT_DISCONNECT);
940 set_tone(portlist,"activated");
942 set_tone(portlist,"deactivated");
946 /* process dialing redial
948 void EndpointAppPBX::action_init_redial_reply(void)
950 struct port_list *portlist = ea_endpoint->ep_portlist;
953 if (!e_ext.last_out[0])
955 trace_header("ACTION redial/reply (no last number stored)", DIRECTION_NONE);
957 new_state(EPOINT_STATE_OUT_DISCONNECT);
958 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
959 set_tone(portlist, "cause_3f");
964 /* process dialing redial
966 void EndpointAppPBX::_action_redial_reply(int in)
968 struct message *message;
970 struct route_param *rparam;
972 last = (in)?e_ext.last_in[0]:e_ext.last_out[0];
974 /* if no display is available */
975 if (!e_ext.display_menu)
977 if (ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_IN && ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_OUT)
980 /* if select is not given */
981 if (!(rparam = routeparam(e_action, PARAM_SELECT)))
985 if (e_extdialing[0]=='*' || e_extdialing[0]=='1')
987 /* find prev entry */
993 if (e_extdialing[0]=='#' || e_extdialing[0]=='3')
995 /* find next entry */
997 if (e_select >= MAX_REMEMBER)
1000 if (e_ext.last_in[e_select][0] == '\0')
1003 if (e_ext.last_out[e_select][0] == '\0')
1008 last = (in)?e_ext.last_in[e_select]:e_ext.last_out[e_select];
1009 if (e_extdialing[0]=='0' || e_extdialing[0]=='2')
1013 trace_header("ACTION reply (dialing)", DIRECTION_NONE);
1015 trace_header("ACTION redial (dialing)", DIRECTION_NONE);
1016 add_trace("number", NULL, "%s", last);
1017 add_trace("last but", NULL, "%d", e_select);
1019 SCPY(e_dialinginfo.id, last);
1020 e_extdialing = e_dialinginfo.id;
1025 e_extdialing[0] = '\0';
1027 /* send display message to port */
1028 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1029 if (!strncmp(last, "extern:", 7))
1030 SPRINT(message->param.notifyinfo.display, "(%d) %s ext", e_select+1, last+7);
1032 if (!strncmp(last, "intern:", 7))
1033 SPRINT(message->param.notifyinfo.display, "(%d) %s int", e_select+1, last+7);
1035 if (!strncmp(last, "chan:", 4))
1036 SPRINT(message->param.notifyinfo.display, "(%d) %s chan", e_select+1, last+5);
1038 if (!strncmp(last, "vbox:", 5))
1039 SPRINT(message->param.notifyinfo.display, "(%d) %s vbox", e_select+1, last+5);
1041 SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -");
1042 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
1043 message_put(message);
1044 logmessage(message);
1047 /* process dialing redial
1049 void EndpointAppPBX::action_dialing_redial(void)
1051 _action_redial_reply(0);
1054 /* process dialing reply
1056 void EndpointAppPBX::action_dialing_reply(void)
1058 _action_redial_reply(1);
1062 /* dialing powerdialing delay
1064 void EndpointAppPBX::action_dialing_powerdial(void)
1066 struct port_list *portlist = ea_endpoint->ep_portlist;
1067 struct message *message;
1068 struct route_param *rparam;
1070 /* power dialing only possible if we have a last dialed number */
1071 if (!e_ext.last_out[0])
1073 trace_header("ACTION powerdial (no last number stored)", DIRECTION_NONE);
1075 new_state(EPOINT_STATE_OUT_DISCONNECT);
1076 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1077 set_tone(portlist, "cause_3f");
1082 if ((rparam = routeparam(e_action, PARAM_LIMIT)))
1084 e_powerlimit = rparam->integer_value;
1091 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1093 e_powerdelay = rparam->integer_value;
1096 /* delay incomplete */
1097 if (!strchr(e_extdialing, '#'))
1099 *strchr(e_extdialing, '#') = '\0';
1100 e_powerdelay = e_extdialing[0]?atoi(e_extdialing): 0;
1103 if (e_powerdelay < 1)
1105 trace_header("ACTION powerdial (dialing)", DIRECTION_NONE);
1106 add_trace("number", NULL, "%s", e_ext.last_out[0]);
1107 add_trace("delay", NULL, "%d", e_powerdelay);
1110 /* send connect to avoid overlap timeout */
1111 // new_state(EPOINT_STATE_CONNECT); connect may prevent further dialing
1112 if (e_ext.number[0])
1114 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1115 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1116 message_put(message);
1117 logmessage(message);
1120 SCPY(e_dialinginfo.id, e_ext.last_out[0]);
1121 e_powerdialing = -1; /* indicates the existence of powerdialing but no redial time given */
1130 void EndpointAppPBX::action_dialing_callback(void)
1132 struct port_list *portlist = ea_endpoint->ep_portlist;
1133 struct route_param *rparam;
1134 struct extension cbext;
1136 portlist = ea_endpoint->ep_portlist;
1138 /* check given extension */
1139 if (!(rparam = routeparam(e_action, PARAM_EXTENSION)))
1142 trace_header("ACTION callback (no extension defined)", DIRECTION_NONE);
1146 new_state(EPOINT_STATE_OUT_DISCONNECT);
1147 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1148 set_tone(portlist, "cause_3f");
1150 e_cbcaller[0] = e_cbdialing[0] = '\0';
1154 /* if extension is given */
1155 SCPY(e_cbcaller, rparam->string_value);
1156 if (e_cbcaller[0] == '\0')
1159 /* read callback extension */
1160 memset(&cbext, 0, sizeof(cbext));
1161 if (!read_extension(&cbext, e_cbcaller))
1163 trace_header("ACTION callback (extension doesn't exist)", DIRECTION_NONE);
1164 add_trace("extension", NULL, "%s", e_cbcaller);
1169 /* if password is not given */
1170 if (cbext.password[0] == '\0')
1172 trace_header("ACTION callback (no password set)", DIRECTION_NONE);
1173 add_trace("extension", NULL, "%s", e_cbcaller);
1178 /* callback only possible if callerid exists OR it is given */
1179 if ((rparam = routeparam(e_action, PARAM_CALLTO)))
1180 SCPY(e_cbto, rparam->string_value);
1183 trace_header("ACTION callback (alternative caller id)", DIRECTION_NONE);
1184 add_trace("extension", NULL, "%s", e_cbcaller);
1185 add_trace("callerid", NULL, "%s", e_cbto);
1187 SCPY(e_callerinfo.id, e_cbto);
1188 e_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
1189 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1191 if (e_callerinfo.id[0]=='\0' || e_callerinfo.present==INFO_PRESENT_NOTAVAIL)
1193 trace_header("ACTION callback (no caller ID available)", DIRECTION_NONE);
1194 add_trace("extension", NULL, "%s", e_cbcaller);
1199 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1204 * process hangup 'callback'
1206 void EndpointAppPBX::action_hangup_callback(void)
1208 struct route_param *rparam;
1212 delay = 2; /* default value */
1213 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1214 if (rparam->integer_value>0)
1215 delay = rparam->integer_value;
1217 /* dialing after callback */
1218 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1219 SCPY(e_cbdialing, rparam->string_value);
1221 SCPY(e_cbdialing, e_extdialing);
1223 trace_header("ACTION callback (dialing)", DIRECTION_NONE);
1224 add_trace("extension", NULL, "%s", e_cbcaller);
1225 add_trace("caller id", NULL, "%s", e_callerinfo.id);
1226 add_trace("delay", NULL, "%d", delay);
1227 add_trace("dialing", NULL, "%s", e_cbdialing);
1230 /* set time to callback */
1231 e_callback = now_d + delay;
1236 * dialing action abbreviation
1238 void EndpointAppPBX::action_dialing_abbrev(void)
1240 struct port_list *portlist = ea_endpoint->ep_portlist;
1241 char *abbrev, *phone, *name;
1244 portlist = ea_endpoint->ep_portlist;
1246 /* abbrev dialing is only possible if we have a caller defined */
1247 if (!e_ext.number[0])
1249 trace_header("ACTION abbreviation (only for extension)", DIRECTION_NONE);
1251 new_state(EPOINT_STATE_OUT_DISCONNECT);
1252 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1253 set_tone(portlist, "cause_3f");
1257 /* check abbreviation */
1258 abbrev = e_extdialing;
1261 result = parse_phonebook(e_ext.number, &abbrev, &phone, &name);
1264 trace_header("ACTION abbreviation (not found)", DIRECTION_NONE);
1265 add_trace("abbrev", NULL, "%s", abbrev);
1267 new_state(EPOINT_STATE_OUT_DISCONNECT);
1268 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
1269 set_tone(portlist, "cause_01");
1272 if (result == -1) /* may match if more digits are dialed */
1277 /* dial abbreviation */
1278 trace_header("ACTION abbreviation (dialing)", DIRECTION_NONE);
1279 add_trace("abbrev", NULL, "%s", abbrev);
1280 add_trace("number", NULL, "%s", phone);
1281 if (name) if (name[0])
1282 add_trace("name", NULL, "%s", name);
1284 SCPY(e_dialinginfo.id, phone);
1285 e_extdialing = e_dialinginfo.id;
1291 /* process dialing 'test'
1293 void EndpointAppPBX::action_dialing_test(void)
1297 struct port_list *portlist = ea_endpoint->ep_portlist;
1298 struct message *message;
1300 char testcode[32] = "";
1301 struct route_param *rparam;
1303 /* given testcode */
1304 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1305 SCPY(testcode, rparam->string_value);
1306 SCAT(testcode, e_extdialing);
1311 trace_header("ACTION test", DIRECTION_NONE);
1312 add_trace("test", NULL, "proceeding");
1314 new_state(EPOINT_STATE_IN_PROCEEDING);
1315 set_tone(portlist, "proceeding");
1316 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
1317 message_put(message);
1318 logmessage(message);
1322 trace_header("ACTION test", DIRECTION_NONE);
1323 add_trace("test", NULL, "alerting");
1325 new_state(EPOINT_STATE_IN_ALERTING);
1326 set_tone(portlist, "ringpbx");
1327 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
1328 message_put(message);
1329 logmessage(message);
1333 trace_header("ACTION test", DIRECTION_NONE);
1334 add_trace("test", NULL, "echo");
1336 new_state(EPOINT_STATE_CONNECT);
1337 if (e_ext.number[0])
1339 set_tone(portlist, NULL);
1340 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1341 SCPY(e_connectinfo.id, e_callerinfo.id);
1342 SCPY(e_connectinfo.extension, e_callerinfo.extension);
1343 e_connectinfo.itype = e_callerinfo.itype;
1344 e_connectinfo.ntype = e_callerinfo.ntype;
1345 e_connectinfo.present = e_callerinfo.present;
1346 e_connectinfo.screen = e_callerinfo.screen;
1347 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1348 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(struct connect_info));
1349 /* handle restricted caller ids */
1350 apply_callerid_restriction(e_ext.anon_ignore, message->param.connectinfo.id, &message->param.connectinfo.ntype, &message->param.connectinfo.present, &message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name);
1351 /* display callerid if desired for extension */
1352 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));
1353 message_put(message);
1354 logmessage(message);
1356 port = find_port_id(portlist->port_id);
1359 port->set_echotest(1);
1364 trace_header("ACTION test", DIRECTION_NONE);
1365 add_trace("test", NULL, "tone");
1367 new_state(EPOINT_STATE_CONNECT);
1368 if (e_ext.number[0])
1370 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1371 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1372 message_put(message);
1373 logmessage(message);
1374 set_tone(portlist, "test");
1378 trace_header("ACTION test", DIRECTION_NONE);
1379 add_trace("test", NULL, "hold music");
1381 new_state(EPOINT_STATE_CONNECT);
1382 if (e_ext.number[0])
1384 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1385 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1386 message_put(message);
1387 logmessage(message);
1388 set_tone(portlist, "hold");
1392 if (strlen(testcode) < 4)
1395 cause = atoi(testcode+1);
1398 trace_header("ACTION test", DIRECTION_NONE);
1399 add_trace("test", NULL, "announcement");
1400 add_trace("cause", NULL, "%d", cause);
1402 new_state(EPOINT_STATE_CONNECT);
1403 if (e_ext.number[0])
1405 SPRINT(causestr,"cause_%02x",cause);
1406 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1407 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1408 message_put(message);
1409 logmessage(message);
1410 set_tone(portlist, causestr);
1414 if (strlen(testcode) < 4)
1417 cause = atoi(testcode+1);
1420 trace_header("ACTION test", DIRECTION_NONE);
1421 add_trace("test", NULL, "disconnect");
1422 add_trace("cause", NULL, "%d", cause);
1424 new_state(EPOINT_STATE_OUT_DISCONNECT);
1425 SPRINT(causestr,"cause_%02x",cause);
1426 message_disconnect_port(portlist, cause, LOCATION_PRIVATE_LOCAL, "");
1427 set_tone(portlist, causestr);
1430 case '8': /* release */
1431 trace_header("ACTION test", DIRECTION_NONE);
1432 add_trace("test", NULL, "release");
1433 add_trace("cause", NULL, "16");
1435 new_state(EPOINT_STATE_OUT_DISCONNECT);
1436 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
1437 set_tone(portlist, "release");
1440 case '9': /* text callerid test */
1441 trace_header("ACTION test", DIRECTION_NONE);
1442 add_trace("test", NULL, "callerid");
1444 new_state(EPOINT_STATE_CONNECT);
1445 if (e_ext.number[0])
1447 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1448 SCPY(e_connectinfo.id, "12345678");
1449 SCPY(e_connectinfo.name, "Welcome to LCR");
1450 SCPY(e_connectinfo.display, "Welcome to LCR");
1451 e_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1452 e_connectinfo.present = INFO_PRESENT_ALLOWED;
1453 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1454 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(message->param.connectinfo));
1455 message_put(message);
1456 logmessage(message);
1457 set_tone(portlist, "hold");
1463 /* process init play
1465 void EndpointAppPBX::action_init_play(void)
1467 struct route_param *rparam;
1468 struct port_list *portlist = ea_endpoint->ep_portlist;
1470 /* check given sample */
1471 if (!(rparam = routeparam(e_action, PARAM_SAMPLE)))
1473 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1477 new_state(EPOINT_STATE_OUT_DISCONNECT);
1478 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
1479 set_tone(portlist, "cause_3f");
1484 /* if sample is given */
1485 if (rparam->string_value[0] == '\0')
1487 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1492 if (e_ext.number[0])
1495 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1500 * action_*_vbox_play is implemented in "action_vbox.cpp"
1505 * process dialing of calculator
1507 void EndpointAppPBX::action_dialing_calculator(void)
1509 struct port_list *portlist = ea_endpoint->ep_portlist;
1510 struct message *message;
1511 double value1, value2, v, sign1;
1512 int komma1, komma2, k, state, mode, first;
1515 portlist = ea_endpoint->ep_portlist;
1517 /* remove error message */
1518 if (!strncmp(e_extdialing, "Error", 5))
1520 UCPY(e_extdialing, e_extdialing+5);
1522 if (!strncmp(e_extdialing, "inf", 3))
1524 UCPY(e_extdialing, e_extdialing+3);
1526 if (!strncmp(e_extdialing, "-inf", 4))
1528 UCPY(e_extdialing, e_extdialing+4);
1531 /* process dialing */
1544 if (*p>='0' && *p<='9')
1552 if ((p[-1]<'0' || p[-1]>'0') && p[-1]!='.')
1561 case 0: /* first number */
1564 value1 = value1*10 + (*p-'0');
1574 case 1: /* second number */
1577 value2 = value2*10 + (*p-'0');
1594 UCPY(e_extdialing, "Error");
1597 /* if there is a multiplication, we change to / */
1606 /* if there is a division, we change to + */
1615 /* if there is a addition, we change to - */
1624 /* if there is a substraction and a comma, we change to * */
1625 if (p[-1]=='-' && komma1)
1633 /* if there is a substraction and no comma and the first or second value, we change to , */
1642 /* if there is a komma and we are at the first value, we change to * */
1643 if (p[-1]=='.' && state==0)
1652 /* if there is a komma and we are at the second value, we display error */
1653 if (komma2 && state==1)
1655 UCPY(e_extdialing, "Error");
1658 /* if we are at state 1, we write a comma */
1665 /* we assume multiplication */
1672 /* if just a number is displayed, the input is cleared */
1675 *e_extdialing = '\0';
1678 /* calculate the result */
1681 case 0: /* multiply */
1682 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1*value2);
1684 case 1: /* divide */
1685 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1/value2);
1688 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1+value2);
1690 case 3: /* substract */
1691 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1-value2);
1694 e_dialinginfo.id[sizeof(e_dialinginfo.id)-1] = '\0';
1695 if (strchr(e_extdialing, '.')) /* remove zeroes */
1697 while (e_extdialing[strlen(e_extdialing)-1] == '0')
1698 e_extdialing[strlen(e_extdialing)-1] = '\0';
1699 if (e_extdialing[strlen(e_extdialing)-1] == '.')
1700 e_extdialing[strlen(e_extdialing)-1] = '\0'; /* and remove dot */
1702 p = strchr(e_extdialing,'\0')-1;
1735 UCPY(e_extdialing, "Error");
1744 /* display dialing */
1745 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1746 SPRINT(message->param.notifyinfo.display, ">%s", e_extdialing);
1747 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);
1748 message_put(message);
1749 logmessage(message);
1754 * process dialing of timer
1756 void EndpointAppPBX::action_dialing_timer(void)
1762 * process 'goto' or 'menu'
1764 void EndpointAppPBX::_action_goto_menu(int mode)
1766 struct port_list *portlist = ea_endpoint->ep_portlist;
1767 struct route_param *rparam;
1769 /* check given ruleset */
1770 if (!(rparam = routeparam(e_action, PARAM_RULESET)))
1773 trace_header("ACTION goto/menu (no ruleset given)", DIRECTION_NONE);
1777 new_state(EPOINT_STATE_OUT_DISCONNECT);
1778 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1779 set_tone(portlist, "cause_3f");
1783 if (rparam->string_value[0] == '\0')
1785 e_ruleset = getrulesetbyname(rparam->string_value);
1788 trace_header("ACTION goto/menu (ruleset not found)", DIRECTION_NONE);
1789 add_trace("ruleset", NULL, "%s", rparam->string_value);
1794 /* if the 'menu' was selected, we will flush all digits */
1797 e_dialinginfo.id[0] = 0;
1798 e_extdialing = e_dialinginfo.id;
1801 /* remove digits that are required to match the rule */
1802 if (!(rparam = routeparam(e_action, PARAM_STRIP)))
1805 SCPY(e_dialinginfo.id, e_extdialing);
1806 e_extdialing = e_dialinginfo.id;
1811 trace_header("ACTION goto/menu (change to)", DIRECTION_NONE);
1812 add_trace("ruleset", NULL, "%s", e_ruleset->name);
1813 if (e_dialinginfo.id[0])
1814 add_trace("dialing", NULL, "%s", e_dialinginfo.id);
1815 if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
1817 add_trace("sample", NULL, "%s", rparam->string_value);
1818 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1822 /* do dialing with new ruleset */
1827 /* process dialing goto
1829 void EndpointAppPBX::action_dialing_goto(void)
1831 _action_goto_menu(0);
1834 /* process dialing menu
1836 void EndpointAppPBX::action_dialing_menu(void)
1838 _action_goto_menu(1);
1843 * process dialing disconnect
1845 void EndpointAppPBX::action_dialing_disconnect(void)
1847 struct route_param *rparam;
1848 struct port_list *portlist = ea_endpoint->ep_portlist;
1849 struct message *message;
1850 int cause = CAUSE_NORMAL; /* normal call clearing */
1851 int location = LOCATION_PRIVATE_LOCAL;
1852 char cause_string[256] = "", display[84] = "";
1854 /* check cause parameter */
1855 if ((rparam = routeparam(e_action, PARAM_CAUSE)))
1857 cause = rparam->integer_value;
1858 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1860 if ((rparam = routeparam(e_action, PARAM_LOCATION)))
1862 location = rparam->integer_value;
1863 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1867 /* use cause as sample, if not given later */
1868 SPRINT(cause_string, "cause_%02x", cause);
1870 /* check sample parameter */
1871 if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
1873 SCPY(cause_string, rparam->string_value);
1874 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'sample' is given: %s\n", ea_endpoint->ep_serial, cause_string);
1878 if ((rparam = routeparam(e_action, PARAM_DISPLAY)))
1880 SCPY(display, rparam->string_value);
1881 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1884 /* disconnect only if connect parameter is not given */
1885 trace_header("ACTION disconnect", DIRECTION_NONE);
1886 add_trace("cause", "value", "%d", cause);
1887 add_trace("cause", "location", "%d", location);
1888 if (cause_string[0])
1889 add_trace("sample", NULL, "%s", cause_string);
1891 add_trace("display", NULL, "%s", display);
1893 new_state(EPOINT_STATE_OUT_DISCONNECT);
1894 set_tone(portlist, cause_string);
1895 if (!(rparam = routeparam(e_action, PARAM_CONNECT)))
1897 message_disconnect_port(portlist, cause, location, display);
1900 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1901 SCPY(message->param.notifyinfo.display, display);
1902 message_put(message);
1903 logmessage(message);
1910 * process dialing help
1912 void EndpointAppPBX::action_dialing_help(void)
1914 /* show all things that would match */
1916 struct numbering *numbering = numbering_int;
1917 char dialing[sizeof(e_dialinginfo.id)];
1919 struct message *message;
1920 struct route_param *rparam;
1922 /* in case we have no menu (this should never happen) */
1927 if (strchr(e_dialinginfo.id,'*'))
1930 e_dialinginfo.id[0] = '\0';
1932 if (strchr(e_dialinginfo.id,'#'))
1935 e_dialinginfo.id[0] = '\0';
1938 /* get position in menu */
1941 /* get last menu position */
1943 while(numbering->next)
1946 numbering = numbering->next;
1950 /* get menu position */
1954 numbering = numbering->next;
1958 numbering = numbering_int;
1965 /* if we dial something else we need to add the prefix and change the action */
1966 if (e_dialinginfo.id[0])
1968 e_action = NUMB_ACTION_NONE;
1969 SCPY(dialing, numbering->prefix);
1970 //we ignore the first digit after selecting
1971 //SCAT(dialing, e_dialinginfo.id);
1972 SCPY(e_dialinginfo.id, dialing);
1973 e_extdialing = e_dialinginfo.id+strlen(numbering->prefix);
1974 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);
1980 /* send display message to port */
1981 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1982 SPRINT(message->param.notifyinfo.display, ">%s %s%s%s", numbering->prefix, numb_actions[numbering->action], (numbering->param[0])?" ":"", numbering->param);
1983 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);
1984 message_put(message);
1985 logmessage(message);
1991 * process dialing deflect
1993 void EndpointAppPBX::action_dialing_deflect(void)
1999 * process dialing setforward
2001 void EndpointAppPBX::action_dialing_setforward(void)
2007 * process hangup 'execute'
2009 void EndpointAppPBX::action_hangup_execute(void)
2011 struct route_param *rparam;
2012 char *command = "", isdn_port[10];
2013 char *argv[7+1]; /* check also number of args below */
2016 /* get script / command */
2017 if ((rparam = routeparam(e_action, PARAM_EXECUTE)))
2018 command = rparam->string_value;
2019 if (command[0] == '\0')
2021 trace_header("ACTION execute (no parameter given)", DIRECTION_NONE);
2025 trace_header("ACTION execute", DIRECTION_NONE);
2026 add_trace("command", NULL, "%s", command);
2030 while(strchr(argv[0], '/'))
2031 argv[0] = strchr(argv[0], '/')+1;
2032 if ((rparam = routeparam(e_action, PARAM_PARAM)))
2034 argv[1] = rparam->string_value;
2037 argv[1+i] = e_extdialing;
2038 argv[2+i] = numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype);
2039 argv[3+i] = e_callerinfo.extension;
2040 argv[4+i] = e_callerinfo.name;
2041 SPRINT(isdn_port, "%d", e_callerinfo.isdn_port);
2042 argv[5+i] = isdn_port;
2043 argv[6+i] = NULL; /* check also number of args above */
2044 execve("/bin/sh", argv, environ);
2049 * process hangup 'file'
2051 void EndpointAppPBX::action_hangup_file(void)
2053 struct route_param *rparam;
2054 char *file, *content, *mode;
2057 /* get file / content */
2058 if (!(rparam = routeparam(e_action, PARAM_FILE)))
2059 file = rparam->string_value;
2062 if (!(rparam = routeparam(e_action, PARAM_CONTENT)))
2063 content = rparam->string_value;
2065 content = e_extdialing;
2066 if (!(rparam = routeparam(e_action, PARAM_APPEND)))
2070 if (file[0] == '\0')
2072 trace_header("ACTION file (no filename given)", DIRECTION_NONE);
2076 if (!(fp = fopen(file, mode)))
2078 trace_header("ACTION file (failed to open)", DIRECTION_NONE);
2079 add_trace("file", "name", "%s", file);
2080 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2084 trace_header("ACTION file", DIRECTION_NONE);
2085 add_trace("file", "name", "%s", file);
2086 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2087 add_trace("content", NULL, "%s", content);
2089 fprintf(fp, "%s\n", content);
2095 * process init 'pick'
2097 void EndpointAppPBX::action_init_pick(void)
2099 struct route_param *rparam;
2100 char *extensions = NULL;
2102 if ((rparam = routeparam(e_action, PARAM_EXTENSIONS)))
2103 extensions = rparam->string_value;
2105 trace_header("ACTION pick", DIRECTION_NONE);
2106 if (extensions) if (extensions[0])
2107 add_trace("extensions", NULL, "%s", extensions);
2109 pick_call(extensions);
2114 * process dialing 'password'
2116 void EndpointAppPBX::action_dialing_password(void)
2118 struct port_list *portlist = ea_endpoint->ep_portlist;
2120 /* prompt for password */
2121 if (e_extdialing[0] == '\0')
2123 /* give password tone */
2124 set_tone(portlist, "password");
2126 if (e_extdialing[1] == '\0')
2128 /* give password tone */
2129 set_tone(portlist, "dialing");
2132 /* wait until all digits are dialed */
2133 if (strlen(e_ext.password) != strlen(e_extdialing))
2134 return; /* more digits needed */
2136 /* check the password */
2137 if (e_ext.password[0]=='\0' || (strlen(e_ext.password)==strlen(e_extdialing) && !!strcmp(e_ext.password,e_extdialing)))
2139 trace_header("ACTION password_write (wrong password)", DIRECTION_NONE);
2140 add_trace("dialed", NULL, "%s", e_extdialing);
2142 e_connectedmode = 0;
2144 new_state(EPOINT_STATE_OUT_DISCONNECT);
2145 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2146 set_tone(portlist, "cause_10");
2150 /* write caller id if ACTION_PASSWORD_WRITE was selected */
2152 if (e_action->index == ACTION_PASSWORD_WRITE)
2154 append_callbackauth(e_ext.number, &e_callbackinfo);
2155 trace_header("ACTION password_write (written)", DIRECTION_NONE);
2156 add_trace("dialed", NULL, "%s", e_extdialing);
2160 /* make call state */
2161 new_state(EPOINT_STATE_IN_OVERLAP);
2162 e_ruleset = ruleset_main;
2164 e_rule = e_ruleset->rule_first;
2166 e_dialinginfo.id[0] = '\0';
2167 e_extdialing = e_dialinginfo.id;
2168 set_tone(portlist, "dialpbx");
2171 void EndpointAppPBX::action_dialing_password_wr(void)
2173 action_dialing_password();
2177 /* general process dialing of incoming call
2178 * depending on the detected prefix, subfunctions above (action_*) will be
2181 void EndpointAppPBX::process_dialing(void)
2183 struct port_list *portlist = ea_endpoint->ep_portlist;
2184 struct message *message;
2185 struct route_param *rparam;
2187 //#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.
2188 //PDEBUG(~0, "HANG-BUG-DEBUGGING: entered porcess_dialing\n");
2189 portlist = ea_endpoint->ep_portlist;
2190 /* check if we have a port instance linked to our epoint */
2194 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);
2195 e_action_timeout = 0;
2196 e_match_timeout = 0;
2201 goto portlist_error;
2204 /* check nesting levels */
2205 if (++e_rule_nesting > RULE_NESTING)
2207 trace_header("ACTION (nesting too deep)", DIRECTION_NONE);
2208 add_trace("max-levels", NULL, "%d", RULE_NESTING);
2210 new_state(EPOINT_STATE_OUT_DISCONNECT);
2211 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2212 set_tone(portlist, "cause_3f");
2213 e_action_timeout = 0;
2214 e_match_timeout = 0;
2218 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before action-timeout processing\n");
2219 /* process timeout */
2220 if (e_action_timeout)
2222 e_action_timeout = 0;
2223 if (e_state == EPOINT_STATE_CONNECT)
2225 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);
2228 if (e_action->index == ACTION_DISCONNECT
2229 || e_state == EPOINT_STATE_OUT_DISCONNECT)
2231 /* release after disconnect */
2232 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
2235 release(RELEASE_CALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, 0);
2236 e_action = e_action->next;
2239 /* nothing more, so we release */
2240 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action timed out, and we have no next action, so we disconnect.\n", ea_endpoint->ep_serial);
2241 new_state(EPOINT_STATE_OUT_DISCONNECT);
2242 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2243 set_tone(portlist, "cause_3f");
2246 goto action_timeout;
2249 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before setup/overlap state checking\n");
2250 if (e_state!=EPOINT_STATE_IN_SETUP
2251 && e_state!=EPOINT_STATE_IN_OVERLAP)
2253 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): we are not in incomming setup/overlap state, so we ignore init/dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting);
2254 e_match_timeout = 0;
2259 /* check if we do menu selection */
2260 if (e_action==NUMB_ACTION_NONE && (e_dialinginfo.id[0]=='*' || e_dialinginfo.id[0]=='#'))
2261 /* do menu selection */
2262 if (e_ext.display_menu)
2264 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 */
2266 e_dialinginfo.id[0] = '\0';
2267 e_action = NUMB_ACTION_MENU;
2270 e_match_timeout = 0;
2273 /* invalid dialing */
2274 message_disconnect_port(portlist, CAUSE_INCALID, LOCATION_PRIVATE_LOCAL, "");
2275 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
2276 message->param.disconnectinfo.cause = CAUSE_INVALID;
2277 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2280 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2281 SCPY(message->param.notifyinfo.display,get_isdn_cause(LOCATION_PRIVATE_LOCAL, epoint->e_ext.display_cause, param->disconnectinfo.location, param->disconnectinfo.cause));
2283 message_put(message);
2284 logmessage(message);
2286 new_state(EPOINT_STATE_OUT_DISCONNECT);
2287 set_tone(portlist,"cause_1c");
2288 e_match_timeout = 0;
2293 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before e_action==NULL\n");
2294 /* if no action yet, we will call try to find a matching rule */
2297 /* be sure that all selectors are initialized */
2300 /* check for external call */
2301 if (!strncmp(e_dialinginfo.id, "extern:", 7))
2303 e_extdialing = e_dialinginfo.id+7;
2304 e_action = &action_external;
2305 goto process_action;
2307 /* check for internal call */
2308 if (!strncmp(e_dialinginfo.id, "intern:", 7))
2310 e_extdialing = e_dialinginfo.id+7;
2311 e_action = &action_internal;
2312 goto process_action;
2314 /* check for chan call */
2315 if (!strncmp(e_dialinginfo.id, "chan:", 5))
2317 e_extdialing = e_dialinginfo.id+4;
2318 e_action = &action_chan;
2319 goto process_action;
2321 /* check for vbox call */
2322 if (!strncmp(e_dialinginfo.id, "vbox:", 5))
2324 e_extdialing = e_dialinginfo.id+5;
2325 e_action = &action_vbox;
2326 goto process_action;
2329 if (e_match_timeout && now_d>=e_match_timeout)
2331 /* return timeout rule */
2332 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);
2333 e_match_timeout = 0;
2334 e_action = e_match_to_action;
2335 e_extdialing = e_match_to_extdialing;
2336 trace_header("ROUTING (timeout)", DIRECTION_NONE);
2337 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2338 add_trace("line", NULL, "%d", e_action->line);
2342 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before routing\n");
2343 /* check for matching rule */
2344 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);
2347 e_action = route(e_ruleset);
2350 trace_header("ACTION (match)", DIRECTION_NONE);
2351 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2352 add_trace("line", NULL, "%d", e_action->line);
2357 e_action = &action_disconnect;
2360 trace_header("ACTION (no main ruleset, disconnecting)", DIRECTION_NONE);
2364 //PDEBUG(~0, "HANG-BUG-DEBUGGING: after routing\n");
2368 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): no rule within the current ruleset matches yet.\n", ea_endpoint->ep_serial, e_ext.number);
2373 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): a rule with action '%s' matches.\n", ea_endpoint->ep_serial, action_defs[e_action->index].name);
2378 e_action_timeout = 0;
2379 if (e_action->timeout)
2381 e_action_timeout = now_d + e_action->timeout;
2382 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action has a timeout of %d secods.\n", ea_endpoint->ep_serial, e_action->timeout);
2386 /* check param proceeding / alerting / connect */
2387 if ((rparam = routeparam(e_action, PARAM_CONNECT)))
2389 /* NOTE: we may not change our state to connect, because dialing will then not possible */
2391 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2392 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
2393 message_put(message);
2394 logmessage(message);
2396 if ((rparam = routeparam(e_action, PARAM_ALERTING)))
2398 /* NOTE: we may not change our state to alerting, because dialing will then not possible */
2399 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2400 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
2401 message_put(message);
2402 logmessage(message);
2404 if ((rparam = routeparam(e_action, PARAM_PROCEEDING)))
2406 /* NOTE: we may not change our state to proceeding, because dialing will then not possible */
2407 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2408 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
2409 message_put(message);
2410 logmessage(message);
2413 if (action_defs[e_action->index].init_func)
2415 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);
2416 (this->*(action_defs[e_action->index].init_func))();
2418 if (e_state!=EPOINT_STATE_IN_SETUP
2419 && e_state!=EPOINT_STATE_IN_OVERLAP)
2421 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): AFTER init process: we are not in incomming setup/overlap state anymore, so we ignore further dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting);
2422 goto display_action;
2426 /* show what we are doing */
2427 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);
2428 /* go to action's dialing function */
2429 if (action_defs[e_action->index].dialing_func)
2431 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);
2432 (this->*(action_defs[e_action->index].dialing_func))();
2435 /* display selected dialing action if enabled and still in setup state */
2439 if (e_action->index==ACTION_MENU
2440 || e_action->index==ACTION_REDIAL
2441 || e_action->index==ACTION_REPLY
2442 || e_action->index==ACTION_TIMER
2443 || e_action->index==ACTION_CALCULATOR
2444 || e_action->index==ACTION_TEST)
2448 if (!e_ext.display_dialing)
2450 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*/)
2451 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 */
2453 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2457 SPRINT(message->param.notifyinfo.display, "> %s", e_dialinginfo.id);
2460 SPRINT(message->param.notifyinfo.display, "%s%s%s", action_defs[e_action->index].name, (e_extdialing[0])?" ":"", e_extdialing);
2463 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s'\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
2464 message_put(message);
2465 logmessage(message);
2474 /* some services store information after hangup */
2475 void EndpointAppPBX::process_hangup(int cause, int location)
2477 char callertext[256], dialingtext[256];
2478 int writeext = 0, i;
2480 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s'\n", ea_endpoint->ep_serial, e_ext.number);
2481 if (e_ext.number[0])
2483 if (read_extension(&e_ext, e_ext.number))
2493 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);
2494 switch(e_dialinginfo.itype)
2496 case INFO_ITYPE_CHAN:
2497 SPRINT(dialingtext, "chan:%s", e_dialinginfo.id);
2499 case INFO_ITYPE_ISDN_EXTENSION:
2500 SPRINT(dialingtext, "intern:%s", e_dialinginfo.id);
2502 case INFO_ITYPE_VBOX:
2503 SPRINT(dialingtext, "vbox:%s", e_dialinginfo.id);
2506 SPRINT(dialingtext, "%s", e_dialinginfo.id);
2509 if (e_callerinfo.id[0])
2510 SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype));
2512 SPRINT(callertext, "unknown");
2513 /* allpy restriction */
2514 if (!e_ext.anon_ignore && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
2515 SPRINT(callertext, "anonymous");
2516 if (e_callerinfo.extension[0]) /* add intern if present */
2517 UNPRINT(strchr(callertext,'\0'), sizeof(callertext)-1+strlen(callertext), " (intern %s)", e_callerinfo.extension);
2518 write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location);
2520 /* store last received call for reply-list */
2521 if (e_callerinfo.id[0] || e_callerinfo.extension[0])
2522 if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED)
2524 if (e_callerinfo.extension[0])
2525 SPRINT(callertext, "intern:%s", e_callerinfo.extension);
2527 SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype));
2528 if (!!strcmp(callertext, e_ext.last_in[0]))
2533 UCPY(e_ext.last_in[i], e_ext.last_in[i-1]);
2536 SCPY(e_ext.last_in[0], callertext);
2537 writeext |= 1; /* store extension later */
2538 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]);
2540 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);
2544 /* write extension if needed */
2545 if (writeext == 0x11)
2546 write_extension(&e_ext, e_ext.number);
2550 if (action_defs[e_action->index].hangup_func)
2552 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);
2553 (this->*(action_defs[e_action->index].hangup_func))();