1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** all actions (and hangup) are processed here **
10 \*****************************************************************************/
14 extern char **environ;
18 * process init 'internal' / 'external' / 'remote' / 'vbox-record' / 'partyline'...
20 int EndpointAppPBX::_action_init_call(char *remote)
23 struct port_list *portlist = ea_endpoint->ep_portlist;
24 struct admin_list *admin;
26 /* a created call, this should never happen */
27 if (ea_endpoint->ep_join_id)
29 if (options.deb & DEBUG_EPOINT)
30 PERROR("EPOINT(%d): We already have a call instance, this should never happen!\n", ea_endpoint->ep_serial);
35 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
41 if (admin->remote_name[0] && !strcmp(admin->remote_name, remote))
47 /* resource not available */
48 trace_header("ACTION remote (not available)", DIRECTION_NONE);
49 add_trace("application", NULL, "%s", remote);
51 message_disconnect_port(portlist, CAUSE_OUTOFORDER, LOCATION_PRIVATE_LOCAL, "");
52 new_state(EPOINT_STATE_OUT_DISCONNECT);
53 set_tone(portlist,"cause_1b");
56 join = new JoinRemote(ea_endpoint->ep_serial, remote, admin->sock);
59 join = new JoinPBX(ea_endpoint);
61 FATAL("No memoy for Join instance.\n");
62 ea_endpoint->ep_join_id = join->j_serial;
65 void EndpointAppPBX::action_init_call(void)
67 _action_init_call(NULL);
69 void EndpointAppPBX::action_init_remote(void)
74 * process dialing 'internal'
76 void EndpointAppPBX::action_dialing_internal(void)
78 struct capa_info capainfo;
79 struct caller_info callerinfo;
80 struct redir_info redirinfo;
81 struct dialing_info dialinginfo;
82 struct port_list *portlist = ea_endpoint->ep_portlist;
83 struct lcr_msg *message;
85 struct route_param *rparam;
87 /* send proceeding, because number is complete */
88 set_tone(portlist, "proceeding");
89 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
91 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
92 new_state(EPOINT_STATE_IN_PROCEEDING);
94 /* create bearer/caller/dialinginfo */
95 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
96 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
97 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
98 memset(&dialinginfo, 0, sizeof(dialinginfo));
99 dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
100 SCPY(dialinginfo.id, e_dialinginfo.id);
102 /* process extension */
103 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
104 SCPY(dialinginfo.id, rparam->string_value);
106 /* process number type */
107 if ((rparam = routeparam(e_action, PARAM_TYPE)))
108 dialinginfo.ntype = rparam->integer_value;
110 /* process service */
111 if ((rparam = routeparam(e_action, PARAM_CAPA)))
113 capainfo.bearer_capa = rparam->integer_value;
114 if (capainfo.bearer_capa != INFO_BC_SPEECH
115 && capainfo.bearer_capa != INFO_BC_AUDIO)
117 capainfo.bearer_mode = INFO_BMODE_PACKET;
119 capainfo.bearer_info1 = INFO_INFO1_NONE;
121 if ((rparam = routeparam(e_action, PARAM_BMODE)))
123 capainfo.bearer_mode = rparam->integer_value;
125 if ((rparam = routeparam(e_action, PARAM_INFO1)))
127 capainfo.bearer_info1 = rparam->integer_value;
129 if ((rparam = routeparam(e_action, PARAM_HLC)))
131 capainfo.hlc = rparam->integer_value;
133 if ((rparam = routeparam(e_action, PARAM_EXTHLC)))
135 capainfo.exthlc = rparam->integer_value;
138 /* process presentation */
139 if ((rparam = routeparam(e_action, PARAM_PRESENT)))
141 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
144 /* check if extension exists AND only if not multiple extensions */
145 if (!read_extension(&ext, dialinginfo.id) && !strchr(dialinginfo.id,','))
147 trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE);
148 add_trace("extension", NULL, dialinginfo.id);
150 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0);
151 new_state(EPOINT_STATE_OUT_DISCONNECT);
152 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
153 set_tone(portlist, "cause_86");
156 /* check if internal calls are denied */
157 if (e_ext.rights < 1)
159 trace_header("ACTION extension (dialing to extension denied)", DIRECTION_NONE);
160 add_trace("extension", NULL, dialinginfo.id);
162 new_state(EPOINT_STATE_OUT_DISCONNECT);
163 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0);
164 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
165 set_tone(portlist, "cause_81");
169 /* add or update internal call */
170 trace_header("ACTION extension (calling)", DIRECTION_NONE);
171 add_trace("extension", NULL, dialinginfo.id);
173 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
174 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
175 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
176 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
177 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
178 message_put(message);
181 /* process dialing external
183 void EndpointAppPBX::action_dialing_external(void)
185 struct capa_info capainfo;
186 struct caller_info callerinfo;
187 struct redir_info redirinfo;
188 struct dialing_info dialinginfo;
190 struct port_list *portlist = ea_endpoint->ep_portlist;
191 struct lcr_msg *message;
192 struct route_param *rparam;
194 /* special processing of delete characters '*' and '#' */
195 if (e_ext.delete_ext)
197 /* dialing a # causes a clearing of complete number */
198 if (strchr(e_extdialing, '#'))
200 e_extdialing[0] = '\0';
201 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);
203 /* eliminate digits before '*', which is a delete digit
205 if (strchr(e_extdialing, '*'))
208 while((p=strchr(e_extdialing, '*')))
210 if (p > e_extdialing) /* only if there is a digit in front */
215 UCPY(p, p+1); /* remove '*' */
217 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s deleted digits and got new string: %s\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing);
221 /* create bearer/caller/dialinginfo */
222 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
223 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
224 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
225 memset(&dialinginfo, 0, sizeof(dialinginfo));
226 dialinginfo.itype = INFO_ITYPE_ISDN;
227 dialinginfo.sending_complete = 0;
228 SCPY(dialinginfo.id, e_extdialing);
231 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
232 SPRINT(dialinginfo.id, "%s%s", rparam->string_value, e_extdialing);
234 /* process number complete */
235 if ((rparam = routeparam(e_action, PARAM_COMPLETE)))
236 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
237 SCPY(dialinginfo.id, rparam->string_value);
238 dialinginfo.sending_complete = 1;
240 /* process number type */
241 if ((rparam = routeparam(e_action, PARAM_TYPE)))
242 dialinginfo.ntype = rparam->integer_value;
244 /* process service */
245 if ((rparam = routeparam(e_action, PARAM_CAPA)))
247 capainfo.bearer_capa = rparam->integer_value;
248 if (capainfo.bearer_capa != INFO_BC_SPEECH
249 && capainfo.bearer_capa != INFO_BC_AUDIO)
251 capainfo.bearer_mode = INFO_BMODE_PACKET;
253 capainfo.bearer_info1 = INFO_INFO1_NONE;
255 if ((rparam = routeparam(e_action, PARAM_BMODE)))
257 capainfo.bearer_mode = rparam->integer_value;
259 if ((rparam = routeparam(e_action, PARAM_INFO1)))
261 capainfo.bearer_info1 = rparam->integer_value;
263 if ((rparam = routeparam(e_action, PARAM_HLC)))
265 capainfo.hlc = rparam->integer_value;
267 if ((rparam = routeparam(e_action, PARAM_EXTHLC)))
269 capainfo.exthlc = rparam->integer_value;
273 /* process callerid */
274 if ((rparam = routeparam(e_action, PARAM_CALLERID)))
276 SCPY(callerinfo.id, rparam->string_value);
278 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
280 callerinfo.ntype = rparam->integer_value;
283 /* process presentation */
284 if ((rparam = routeparam(e_action, PARAM_PRESENT)))
286 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
289 /* process interfaces */
290 if ((rparam = routeparam(e_action, PARAM_INTERFACES)))
291 SCPY(dialinginfo.interfaces, rparam->string_value);
293 /* check if local calls are denied */
294 if (e_ext.rights < 2)
296 trace_header("ACTION extern (calling denied)", DIRECTION_NONE);
298 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0);
299 set_tone(portlist, "cause_82");
301 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
302 new_state(EPOINT_STATE_OUT_DISCONNECT);
306 if (!strncmp(dialinginfo.id, options.national, strlen(options.national))
307 || dialinginfo.ntype == INFO_NTYPE_NATIONAL
308 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL)
310 /* check if national calls are denied */
311 if (e_ext.rights < 3)
313 trace_header("ACTION extern (national calls denied)", DIRECTION_NONE);
315 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0);
316 set_tone(portlist, "cause_83");
321 if (!strncmp(dialinginfo.id, options.international, strlen(options.international))
322 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL)
324 /* check if international calls are denied */
325 if (e_ext.rights < 4)
327 trace_header("ACTION extern (international calls denied)", DIRECTION_NONE);
329 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0);
330 set_tone(portlist, "cause_84");
335 /* add or update outgoing call */
336 trace_header("ACTION extern (calling)", DIRECTION_NONE);
337 add_trace("number", NULL, dialinginfo.id);
338 if (dialinginfo.interfaces[0])
339 add_trace("interfaces", NULL, dialinginfo.interfaces);
341 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
342 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
343 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
344 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
345 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
346 message_put(message);
350 void EndpointAppPBX::action_dialing_remote(void)
352 struct route_param *rparam;
353 struct port_list *portlist = ea_endpoint->ep_portlist;
354 struct lcr_msg *message;
355 struct capa_info capainfo;
356 struct caller_info callerinfo;
357 struct redir_info redirinfo;
358 struct dialing_info dialinginfo;
359 char context[128] = "";
362 if (!ea_endpoint->ep_join_id)
364 /* no join yet, sending setup */
365 if (!(rparam = routeparam(e_action, PARAM_APPLICATION)))
367 trace_header("ACTION remote (no application given)", DIRECTION_NONE);
369 new_state(EPOINT_STATE_OUT_DISCONNECT);
370 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
371 set_tone(portlist, "cause_3f");
374 SCPY(remote, rparam->string_value);
375 if (!_action_init_call(remote))
378 /* create bearer/caller/dialinginfo */
379 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
380 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
381 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
382 memset(&dialinginfo, 0, sizeof(dialinginfo));
384 if ((rparam = routeparam(e_action, PARAM_CONTEXT)))
386 SCPY(context, rparam->string_value);
388 if ((rparam = routeparam(e_action, PARAM_EXTEN)))
390 SCPY(dialinginfo.id, rparam->string_value);
391 dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
394 SCPY(dialinginfo.id, e_extdialing);
396 e_extdialing = e_dialinginfo.id + strlen(e_dialinginfo.id);
397 /* send setup to remote */
398 trace_header("ACTION remote (setup)", DIRECTION_NONE);
399 add_trace("number", NULL, dialinginfo.id);
400 add_trace("remote", NULL, remote);
402 add_trace("context", NULL, context);
404 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
405 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
406 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
407 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
408 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
409 SCPY(message->param.setup.context, context);
410 message_put(message);
413 /* send overlap digits */
414 trace_header("ACTION remote (dialing)", DIRECTION_NONE);
415 add_trace("number", NULL, e_extdialing);
419 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_INFORMATION);
420 memcpy(&message->param.information, &e_dialinginfo, sizeof(struct dialing_info));
421 SCPY(message->param.information.id, e_extdialing);
422 e_extdialing = e_dialinginfo.id + strlen(e_dialinginfo.id);
423 message_put(message);
430 * process dialing the "am" and record
432 void EndpointAppPBX::action_dialing_vbox_record(void)
434 struct dialing_info dialinginfo;
435 struct port_list *portlist = ea_endpoint->ep_portlist;
436 struct lcr_msg *message;
437 struct extension ext;
438 struct route_param *rparam;
440 portlist = ea_endpoint->ep_portlist;
442 /* check for given extension */
443 if (!(rparam = routeparam(e_action, PARAM_EXTENSION)))
445 trace_header("ACTION vbox-record (no extension given by parameter)", DIRECTION_NONE);
448 new_state(EPOINT_STATE_OUT_DISCONNECT);
449 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
450 set_tone(portlist, "cause_3f");
454 /* check if extension exists */
455 if (!read_extension(&ext, rparam->string_value))
457 trace_header("ACTION vbox-record (given extension does not exists)", DIRECTION_NONE);
458 add_trace("extension", NULL, "%s", rparam->string_value);
460 new_state(EPOINT_STATE_OUT_DISCONNECT);
461 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
462 set_tone(portlist, "cause_86");
466 /* check if internal calls are denied */
467 if (e_ext.rights < 1)
469 trace_header("ACTION vbox-record (internal calls are denied)", DIRECTION_NONE);
471 new_state(EPOINT_STATE_OUT_DISCONNECT);
472 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
473 set_tone(portlist, "cause_81");
477 set_tone(portlist, "proceeding");
478 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
479 message_put(message);
480 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
481 new_state(EPOINT_STATE_IN_PROCEEDING);
483 memset(&dialinginfo, 0, sizeof(dialinginfo));
484 dialinginfo.itype = INFO_ITYPE_VBOX;
485 dialinginfo.sending_complete = 1;
486 SCPY(dialinginfo.id, rparam->string_value);
488 /* append special announcement (if given) */
489 if ((rparam = routeparam(e_action, PARAM_ANNOUNCEMENT)))
490 if (rparam->string_value[0])
492 SCAT(dialinginfo.id, ",");
493 SCAT(dialinginfo.id, rparam->string_value);
496 /* add or update internal call */
497 trace_header("ACTION vbox-record (calling)", DIRECTION_NONE);
498 add_trace("extension", NULL, "%s", dialinginfo.id);
500 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
501 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
502 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
503 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
504 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
505 message_put(message);
512 void EndpointAppPBX::action_init_partyline(void)
515 class JoinPBX *joinpbx;
516 struct port_list *portlist = ea_endpoint->ep_portlist;
517 struct lcr_msg *message;
518 struct route_param *rparam;
519 int partyline, jingle = 0;
520 struct join_relation *relation;
522 portlist = ea_endpoint->ep_portlist;
524 /* check for given extension */
525 if (!(rparam = routeparam(e_action, PARAM_ROOM)))
527 trace_header("ACTION partyline (no room parameter)", DIRECTION_NONE);
530 new_state(EPOINT_STATE_OUT_DISCONNECT);
531 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
532 set_tone(portlist, "cause_3f");
535 if (rparam->integer_value <= 0)
537 trace_header("ACTION partyline (illegal room parameter)", DIRECTION_NONE);
538 add_trace("room", NULL, "%d", rparam->integer_value);
540 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): invalid value for 'room'.\n", ea_endpoint->ep_serial);
543 partyline = rparam->integer_value;
544 if ((rparam = routeparam(e_action, PARAM_JINGLE)))
547 /* don't create join if partyline exists */
551 if (join->j_type == JOIN_TYPE_PBX)
553 joinpbx = (class JoinPBX *)join;
554 if (joinpbx->j_partyline == partyline)
562 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
563 if (!(join = new JoinPBX(ea_endpoint)))
564 FATAL("No memory for join object\n");
567 //NOTE: joinpbx must be set here
568 /* add relation to existing join */
569 if (!(relation=joinpbx->add_relation()))
570 FATAL("No memory for join relation\n");
571 relation->type = RELATION_TYPE_SETUP;
572 relation->channel_state = 1;
573 relation->rx_state = NOTIFY_STATE_ACTIVE;
574 relation->tx_state = NOTIFY_STATE_ACTIVE;
575 relation->epoint_id = ea_endpoint->ep_serial;
578 ea_endpoint->ep_join_id = join->j_serial;
580 set_tone(portlist, "proceeding");
581 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
582 message_put(message);
583 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
584 new_state(EPOINT_STATE_IN_PROCEEDING);
586 /* send setup to join */
587 trace_header("ACTION partyline (calling)", DIRECTION_NONE);
588 add_trace("room", NULL, "%d", partyline);
589 add_trace("jingle", NULL, (jingle)?"on":"off");
591 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
592 message->param.setup.partyline = partyline;
593 message->param.setup.partyline_jingle = jingle;
594 memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info));
595 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
596 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
597 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
598 message_put(message);
603 * process hangup of all calls
605 void EndpointAppPBX::action_hangup_call(void)
607 trace_header("ACTION hangup", DIRECTION_NONE);
613 * process dialing 'login'
615 void EndpointAppPBX::action_dialing_login(void)
617 struct port_list *portlist = ea_endpoint->ep_portlist;
618 struct lcr_msg *message;
620 struct route_param *rparam;
622 /* extension parameter */
623 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
625 /* extension is given by parameter */
626 extension = rparam->string_value;
627 if (extension[0] == '\0')
629 if (!read_extension(&e_ext, extension))
631 trace_header("ACTION login (extension doesn't exist)", DIRECTION_NONE);
632 add_trace("extension", NULL, "%s", extension);
634 /* extension doesn't exist */
635 new_state(EPOINT_STATE_OUT_DISCONNECT);
636 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
637 set_tone(portlist, "cause_86");
642 /* extension must be given by dialstring */
643 extension = e_extdialing;
644 if (extension[0] == '\0')
646 if (!read_extension(&e_ext, extension))
648 trace_header("ACTION login (extension incomplete or does not exist)", DIRECTION_NONE);
649 add_trace("extension", NULL, "%s", extension);
655 /* we changed our extension */
656 SCPY(e_ext.number, extension);
657 new_state(EPOINT_STATE_CONNECT);
661 /* send connect with extension's caller id (COLP) */
662 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
663 SCPY(message->param.connectinfo.id, e_ext.callerid);
664 message->param.connectinfo.ntype = e_ext.callerid_type;
665 if (e_ext.callerid_present==INFO_PRESENT_ALLOWED && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
666 message->param.connectinfo.present = INFO_PRESENT_RESTRICTED;
667 else message->param.connectinfo.present = e_ext.callerid_present;
668 /* handle restricted caller ids */
669 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);
670 /* display callerid if desired for extension */
671 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));
672 message->param.connectinfo.ntype = e_ext.callerid_type;
673 message_put(message);
674 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
676 /* set our caller id */
677 SCPY(e_callerinfo.id, e_ext.callerid);
678 e_callerinfo.ntype = e_ext.callerid_type;
679 e_callerinfo.present = e_ext.callerid_present;
681 /* enable connectedmode */
685 if (!(rparam = routeparam(e_action, PARAM_NOPASSWORD)))
687 /* make call state to enter password */
688 trace_header("ACTION login (ask for password)", DIRECTION_NONE);
689 add_trace("extension", NULL, "%s", e_ext.number);
691 new_state(EPOINT_STATE_IN_OVERLAP);
694 e_action = &action_password;
696 e_match_to_action = NULL;
697 e_dialinginfo.id[0] = '\0';
698 e_extdialing = strchr(e_dialinginfo.id, '\0');
701 e_password_timeout = now+20;
707 /* make call state */
708 new_state(EPOINT_STATE_IN_OVERLAP);
709 e_ruleset = ruleset_main;
711 e_rule = e_ruleset->rule_first;
713 e_dialinginfo.id[0] = '\0';
714 e_extdialing = e_dialinginfo.id;
715 set_tone(portlist, "dialpbx");
721 * process init 'change_callerid'
723 void EndpointAppPBX::action_init_change_callerid(void)
725 struct port_list *portlist = ea_endpoint->ep_portlist;
727 if (!e_ext.change_callerid)
729 /* service not available */
730 trace_header("ACTION change-callerid (denied for this caller)", DIRECTION_NONE);
732 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
733 new_state(EPOINT_STATE_OUT_DISCONNECT);
734 set_tone(portlist,"cause_87");
739 /* process dialing callerid
741 void EndpointAppPBX::_action_callerid_calleridnext(int next)
743 struct port_list *portlist = ea_endpoint->ep_portlist;
744 struct route_param *rparam;
745 char buffer[64], *callerid;
746 char old_id[64] = "", new_id[64] = "";
747 int old_type=0, new_type=0, old_present=0, new_present=0;
749 if ((rparam = routeparam(e_action, PARAM_CALLERID)))
751 /* the caller ID is given by parameter */
752 callerid = rparam->string_value;
755 /* caller ID is dialed */
756 if (!strchr(e_extdialing, '#'))
758 /* no complete ID yet */
761 *strchr(e_extdialing, '#') = '\0';
762 callerid = e_extdialing;
765 /* given callerid type */
766 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
767 switch(rparam->integer_value)
769 case INFO_NTYPE_SUBSCRIBER:
770 SPRINT(buffer, "s%s", callerid);
773 case INFO_NTYPE_NATIONAL:
774 SPRINT(buffer, "n%s", callerid);
777 case INFO_NTYPE_INTERNATIONAL:
778 SPRINT(buffer, "i%s", callerid);
782 SPRINT(buffer, "%s", callerid);
787 /* caller id complete, dialing with new caller id */
788 /* write new parameters */
789 if (read_extension(&e_ext, e_ext.number))
791 old_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
792 old_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
793 SCPY(old_id, (!next)?e_ext.callerid:e_ext.id_next_call);
794 if (callerid[0] == '\0')
797 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
801 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_ALLOWED;
802 if ((rparam = routeparam(e_action, PARAM_PRESENT))) if (rparam->integer_value == 0)
803 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
804 if (e_ext.callerid_type == INFO_NTYPE_UNKNOWN) /* if callerid is unknown, the given id is not nationalized */
806 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, callerid);
807 (!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN;
810 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));
812 if (!next) e_ext.id_next_call_type = -1;
813 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);
815 new_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
816 new_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
817 SCPY(new_id, (!next)?e_ext.callerid:e_ext.id_next_call);
818 write_extension(&e_ext, e_ext.number);
821 /* function activated */
823 trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE);
825 trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE);
826 add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type, options.national, options.international));
827 add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
828 add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type, options.national, options.international));
829 add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
831 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
832 new_state(EPOINT_STATE_OUT_DISCONNECT);
833 set_tone(portlist,"activated");
836 /* process dialing callerid for all call
838 void EndpointAppPBX::action_dialing_callerid(void)
840 _action_callerid_calleridnext(0);
843 /* process dialing callerid for next call
845 void EndpointAppPBX::action_dialing_calleridnext(void)
847 _action_callerid_calleridnext(1);
852 * process init 'change_forward'
854 void EndpointAppPBX::action_init_change_forward(void)
856 struct port_list *portlist = ea_endpoint->ep_portlist;
858 if (!e_ext.change_forward)
860 trace_header("ACTION change-forward (denied for this caller)", DIRECTION_NONE);
862 /* service not available */
863 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
864 new_state(EPOINT_STATE_OUT_DISCONNECT);
865 set_tone(portlist,"cause_87");
870 /* process dialing forwarding
872 void EndpointAppPBX::action_dialing_forward(void)
874 struct port_list *portlist = ea_endpoint->ep_portlist;
875 int diversion = INFO_DIVERSION_CFU;
876 char *dest = e_extdialing;
877 struct route_param *rparam;
879 /* if diversion type is given */
880 if ((rparam = routeparam(e_action, PARAM_DIVERSION)))
881 diversion = rparam->integer_value;
883 if ((rparam = routeparam(e_action, PARAM_DEST)))
885 /* if destination is given */
886 dest = rparam->string_value;
889 if (!strchr(e_extdialing, '#'))
891 *strchr(e_extdialing, '#') = '\0';
895 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing forwarding to '%s'.\n", ea_endpoint->ep_serial, e_ext.number, dest);
896 if (read_extension(&e_ext, e_ext.number))
900 case INFO_DIVERSION_CFU:
901 trace_header("ACTION change-forward (new CFU=unconditional)", DIRECTION_NONE);
902 add_trace("destin'", NULL, "%s", dest);
904 SCPY(e_ext.cfu, dest);
906 case INFO_DIVERSION_CFB:
907 trace_header("ACTION change-forward (new CFB=busy)", DIRECTION_NONE);
908 add_trace("destin'", NULL, "%s", dest);
910 SCPY(e_ext.cfb, dest);
912 case INFO_DIVERSION_CFNR:
913 if ((rparam = routeparam(e_action, PARAM_DELAY)))
914 e_ext.cfnr_delay = rparam->integer_value;
915 trace_header("ACTION change-forward (new CFNR=no response)", DIRECTION_NONE);
916 add_trace("destin'", NULL, "%s", dest);
917 add_trace("delay", NULL, "%s", e_ext.cfnr_delay);
919 SCPY(e_ext.cfnr, dest);
921 case INFO_DIVERSION_CFP:
922 trace_header("ACTION change-forward (new CFP=parallel)", DIRECTION_NONE);
923 add_trace("destin'", NULL, "%s", dest);
925 SCPY(e_ext.cfp, dest);
928 write_extension(&e_ext, e_ext.number);
930 /* function (de)activated */
931 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
932 new_state(EPOINT_STATE_OUT_DISCONNECT);
934 set_tone(portlist,"activated");
936 set_tone(portlist,"deactivated");
940 /* process dialing redial
942 void EndpointAppPBX::action_init_redial_reply(void)
944 struct port_list *portlist = ea_endpoint->ep_portlist;
947 if (!e_ext.last_out[0])
949 trace_header("ACTION redial/reply (no last number stored)", DIRECTION_NONE);
951 new_state(EPOINT_STATE_OUT_DISCONNECT);
952 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
953 set_tone(portlist, "cause_3f");
958 /* process dialing redial
960 void EndpointAppPBX::_action_redial_reply(int in)
962 struct lcr_msg *message;
964 struct route_param *rparam;
966 last = (in)?e_ext.last_in[0]:e_ext.last_out[0];
968 /* if no display is available */
969 if (!e_ext.display_menu)
971 if (ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_IN && ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_OUT)
974 /* if select is not given */
975 if (!(rparam = routeparam(e_action, PARAM_SELECT)))
979 if (e_extdialing[0]=='*' || e_extdialing[0]=='1')
981 /* find prev entry */
987 if (e_extdialing[0]=='#' || e_extdialing[0]=='3')
989 /* find next entry */
991 if (e_select >= MAX_REMEMBER) {
994 if (e_ext.last_in[e_select][0] == '\0')
997 if (e_ext.last_out[e_select][0] == '\0')
1002 last = (in)?e_ext.last_in[e_select]:e_ext.last_out[e_select];
1003 if (e_extdialing[0]=='0' || e_extdialing[0]=='2')
1007 trace_header("ACTION reply (dialing)", DIRECTION_NONE);
1009 trace_header("ACTION redial (dialing)", DIRECTION_NONE);
1010 add_trace("number", NULL, "%s", last);
1011 add_trace("last but", NULL, "%d", e_select);
1013 SCPY(e_dialinginfo.id, last);
1014 e_extdialing = e_dialinginfo.id;
1019 e_extdialing[0] = '\0';
1021 /* send display message to port */
1022 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1023 if (!strncmp(last, "extern:", 7))
1024 SPRINT(message->param.notifyinfo.display, "(%d) %s ext", e_select+1, last+7);
1026 if (!strncmp(last, "intern:", 7))
1027 SPRINT(message->param.notifyinfo.display, "(%d) %s int", e_select+1, last+7);
1029 if (!strncmp(last, "chan:", 4))
1030 SPRINT(message->param.notifyinfo.display, "(%d) %s chan", e_select+1, last+5);
1032 if (!strncmp(last, "vbox:", 5))
1033 SPRINT(message->param.notifyinfo.display, "(%d) %s vbox", e_select+1, last+5);
1035 SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -");
1036 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
1037 message_put(message);
1038 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1041 /* process dialing redial
1043 void EndpointAppPBX::action_dialing_redial(void)
1045 _action_redial_reply(0);
1048 /* process dialing reply
1050 void EndpointAppPBX::action_dialing_reply(void)
1052 _action_redial_reply(1);
1056 /* dialing powerdialing delay
1058 void EndpointAppPBX::action_dialing_powerdial(void)
1060 struct port_list *portlist = ea_endpoint->ep_portlist;
1061 struct lcr_msg *message;
1062 struct route_param *rparam;
1064 /* power dialing only possible if we have a last dialed number */
1065 if (!e_ext.last_out[0])
1067 trace_header("ACTION powerdial (no last number stored)", DIRECTION_NONE);
1069 new_state(EPOINT_STATE_OUT_DISCONNECT);
1070 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1071 set_tone(portlist, "cause_3f");
1076 if ((rparam = routeparam(e_action, PARAM_LIMIT)))
1078 e_powerlimit = rparam->integer_value;
1085 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1087 e_powerdelay = rparam->integer_value;
1090 /* delay incomplete */
1091 if (!strchr(e_extdialing, '#'))
1093 *strchr(e_extdialing, '#') = '\0';
1094 e_powerdelay = e_extdialing[0]?atoi(e_extdialing): 0;
1097 if (e_powerdelay < 1)
1099 trace_header("ACTION powerdial (dialing)", DIRECTION_NONE);
1100 add_trace("number", NULL, "%s", e_ext.last_out[0]);
1101 add_trace("delay", NULL, "%d", e_powerdelay);
1104 /* send connect to avoid overlap timeout */
1105 // new_state(EPOINT_STATE_CONNECT); connect may prevent further dialing
1106 if (e_ext.number[0])
1108 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1109 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1110 message_put(message);
1111 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1114 SCPY(e_dialinginfo.id, e_ext.last_out[0]);
1115 e_powerdialing = -1; /* indicates the existence of powerdialing but no redial time given */
1124 void EndpointAppPBX::action_dialing_callback(void)
1126 struct port_list *portlist = ea_endpoint->ep_portlist;
1127 struct route_param *rparam;
1128 struct extension cbext;
1130 portlist = ea_endpoint->ep_portlist;
1132 /* check given extension */
1133 if (!(rparam = routeparam(e_action, PARAM_EXTENSION)))
1136 trace_header("ACTION callback (no extension defined)", DIRECTION_NONE);
1140 new_state(EPOINT_STATE_OUT_DISCONNECT);
1141 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1142 set_tone(portlist, "cause_3f");
1144 e_cbcaller[0] = e_cbdialing[0] = '\0';
1148 /* if extension is given */
1149 SCPY(e_cbcaller, rparam->string_value);
1150 if (e_cbcaller[0] == '\0')
1153 /* read callback extension */
1154 memset(&cbext, 0, sizeof(cbext));
1155 if (!read_extension(&cbext, e_cbcaller))
1157 trace_header("ACTION callback (extension doesn't exist)", DIRECTION_NONE);
1158 add_trace("extension", NULL, "%s", e_cbcaller);
1163 /* if password is not given */
1164 if (cbext.password[0] == '\0')
1166 trace_header("ACTION callback (no password set)", DIRECTION_NONE);
1167 add_trace("extension", NULL, "%s", e_cbcaller);
1172 /* callback only possible if callerid exists OR it is given */
1173 if ((rparam = routeparam(e_action, PARAM_CALLTO)))
1174 SCPY(e_cbto, rparam->string_value);
1177 trace_header("ACTION callback (alternative caller id)", DIRECTION_NONE);
1178 add_trace("extension", NULL, "%s", e_cbcaller);
1179 add_trace("callerid", NULL, "%s", e_cbto);
1181 SCPY(e_callerinfo.id, e_cbto);
1182 e_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
1183 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1185 if (e_callerinfo.id[0]=='\0' || e_callerinfo.present==INFO_PRESENT_NOTAVAIL)
1187 trace_header("ACTION callback (no caller ID available)", DIRECTION_NONE);
1188 add_trace("extension", NULL, "%s", e_cbcaller);
1193 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1198 * process hangup 'callback'
1200 void EndpointAppPBX::action_hangup_callback(void)
1202 struct route_param *rparam;
1206 delay = 2; /* default value */
1207 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1208 if (rparam->integer_value>0)
1209 delay = rparam->integer_value;
1211 /* dialing after callback */
1212 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1213 SCPY(e_cbdialing, rparam->string_value);
1215 SCPY(e_cbdialing, e_extdialing);
1217 trace_header("ACTION callback (dialing)", DIRECTION_NONE);
1218 add_trace("extension", NULL, "%s", e_cbcaller);
1219 add_trace("caller id", NULL, "%s", e_callerinfo.id);
1220 add_trace("delay", NULL, "%d", delay);
1221 add_trace("dialing", NULL, "%s", e_cbdialing);
1224 /* set time to callback */
1225 e_callback = now_d + delay;
1230 * dialing action abbreviation
1232 void EndpointAppPBX::action_dialing_abbrev(void)
1234 struct port_list *portlist = ea_endpoint->ep_portlist;
1235 char *abbrev, *phone, *name;
1238 portlist = ea_endpoint->ep_portlist;
1240 /* abbrev dialing is only possible if we have a caller defined */
1241 if (!e_ext.number[0])
1243 trace_header("ACTION abbreviation (only for extension)", DIRECTION_NONE);
1245 new_state(EPOINT_STATE_OUT_DISCONNECT);
1246 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1247 set_tone(portlist, "cause_3f");
1251 /* check abbreviation */
1252 abbrev = e_extdialing;
1255 result = parse_phonebook(e_ext.number, &abbrev, &phone, &name);
1258 trace_header("ACTION abbreviation (not found)", DIRECTION_NONE);
1259 add_trace("abbrev", NULL, "%s", abbrev);
1261 new_state(EPOINT_STATE_OUT_DISCONNECT);
1262 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
1263 set_tone(portlist, "cause_01");
1266 if (result == -1) /* may match if more digits are dialed */
1271 /* dial abbreviation */
1272 trace_header("ACTION abbreviation (dialing)", DIRECTION_NONE);
1273 add_trace("abbrev", NULL, "%s", abbrev);
1274 add_trace("number", NULL, "%s", phone);
1275 if (name) if (name[0])
1276 add_trace("name", NULL, "%s", name);
1278 SCPY(e_dialinginfo.id, phone);
1279 e_extdialing = e_dialinginfo.id;
1285 /* process dialing 'test'
1287 void EndpointAppPBX::action_dialing_test(void)
1291 struct port_list *portlist = ea_endpoint->ep_portlist;
1292 struct lcr_msg *message;
1294 char testcode[32] = "";
1295 struct route_param *rparam;
1297 /* given testcode */
1298 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1299 SCPY(testcode, rparam->string_value);
1300 SCAT(testcode, e_extdialing);
1305 trace_header("ACTION test", DIRECTION_NONE);
1306 add_trace("test", NULL, "proceeding");
1308 new_state(EPOINT_STATE_IN_PROCEEDING);
1309 set_tone(portlist, "proceeding");
1310 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
1311 message_put(message);
1312 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1316 trace_header("ACTION test", DIRECTION_NONE);
1317 add_trace("test", NULL, "alerting");
1319 new_state(EPOINT_STATE_IN_ALERTING);
1320 set_tone(portlist, "ringpbx");
1321 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
1322 message_put(message);
1323 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1327 trace_header("ACTION test", DIRECTION_NONE);
1328 add_trace("test", NULL, "echo");
1330 new_state(EPOINT_STATE_CONNECT);
1331 if (e_ext.number[0])
1333 set_tone(portlist, NULL);
1334 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1335 SCPY(e_connectinfo.id, e_callerinfo.id);
1336 SCPY(e_connectinfo.extension, e_callerinfo.extension);
1337 e_connectinfo.itype = e_callerinfo.itype;
1338 e_connectinfo.ntype = e_callerinfo.ntype;
1339 e_connectinfo.present = e_callerinfo.present;
1340 e_connectinfo.screen = e_callerinfo.screen;
1341 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1342 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(struct connect_info));
1343 /* handle restricted caller ids */
1344 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);
1345 /* display callerid if desired for extension */
1346 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));
1347 message_put(message);
1348 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1350 port = find_port_id(portlist->port_id);
1353 port->set_echotest(1);
1358 trace_header("ACTION test", DIRECTION_NONE);
1359 add_trace("test", NULL, "tone");
1361 new_state(EPOINT_STATE_CONNECT);
1362 if (e_ext.number[0])
1364 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1365 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1366 message_put(message);
1367 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1368 set_tone(portlist, "test");
1372 trace_header("ACTION test", DIRECTION_NONE);
1373 add_trace("test", NULL, "hold music");
1375 new_state(EPOINT_STATE_CONNECT);
1376 if (e_ext.number[0])
1378 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1379 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1380 message_put(message);
1381 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1382 set_tone(portlist, "hold");
1386 if (strlen(testcode) < 4)
1389 cause = atoi(testcode+1);
1392 trace_header("ACTION test", DIRECTION_NONE);
1393 add_trace("test", NULL, "announcement");
1394 add_trace("cause", NULL, "%d", cause);
1396 new_state(EPOINT_STATE_CONNECT);
1397 if (e_ext.number[0])
1399 SPRINT(causestr,"cause_%02x",cause);
1400 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1401 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1402 message_put(message);
1403 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1404 set_tone(portlist, causestr);
1408 if (strlen(testcode) < 4)
1411 cause = atoi(testcode+1);
1414 trace_header("ACTION test", DIRECTION_NONE);
1415 add_trace("test", NULL, "disconnect");
1416 add_trace("cause", NULL, "%d", cause);
1418 new_state(EPOINT_STATE_OUT_DISCONNECT);
1419 SPRINT(causestr,"cause_%02x",cause);
1420 message_disconnect_port(portlist, cause, LOCATION_PRIVATE_LOCAL, "");
1421 set_tone(portlist, causestr);
1424 case '8': /* release */
1425 trace_header("ACTION test", DIRECTION_NONE);
1426 add_trace("test", NULL, "release");
1427 add_trace("cause", NULL, "16");
1429 new_state(EPOINT_STATE_OUT_DISCONNECT);
1430 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
1431 set_tone(portlist, "release");
1434 case '9': /* text callerid test */
1435 trace_header("ACTION test", DIRECTION_NONE);
1436 add_trace("test", NULL, "callerid");
1438 new_state(EPOINT_STATE_CONNECT);
1439 if (e_ext.number[0])
1441 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1442 SCPY(e_connectinfo.id, "12345678");
1443 SCPY(e_connectinfo.name, "Welcome to LCR");
1444 SCPY(e_connectinfo.display, "Welcome to LCR");
1445 e_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1446 e_connectinfo.present = INFO_PRESENT_ALLOWED;
1447 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1448 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(message->param.connectinfo));
1449 message_put(message);
1450 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1451 set_tone(portlist, "hold");
1457 /* process init play
1459 void EndpointAppPBX::action_init_play(void)
1461 struct route_param *rparam;
1462 struct port_list *portlist = ea_endpoint->ep_portlist;
1464 /* check given sample */
1465 if (!(rparam = routeparam(e_action, PARAM_SAMPLE)))
1467 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1471 new_state(EPOINT_STATE_OUT_DISCONNECT);
1472 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
1473 set_tone(portlist, "cause_3f");
1478 /* if sample is given */
1479 if (rparam->string_value[0] == '\0')
1481 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1486 if (e_ext.number[0])
1489 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1494 * action_*_vbox_play is implemented in "action_vbox.cpp"
1499 * process dialing of calculator
1501 void EndpointAppPBX::action_dialing_calculator(void)
1503 struct port_list *portlist = ea_endpoint->ep_portlist;
1504 struct lcr_msg *message;
1505 double value1, value2, v, sign1;
1506 int komma1, komma2, k, state, mode = 0, first;
1509 portlist = ea_endpoint->ep_portlist;
1511 /* remove error message */
1512 if (!strncmp(e_extdialing, "Error", 5))
1514 UCPY(e_extdialing, e_extdialing+5);
1516 if (!strncmp(e_extdialing, "inf", 3))
1518 UCPY(e_extdialing, e_extdialing+3);
1520 if (!strncmp(e_extdialing, "-inf", 4))
1522 UCPY(e_extdialing, e_extdialing+4);
1525 /* process dialing */
1538 if (*p>='0' && *p<='9')
1546 if ((p[-1]<'0' || p[-1]>'0') && p[-1]!='.')
1555 case 0: /* first number */
1558 value1 = value1*10 + (*p-'0');
1568 case 1: /* second number */
1571 value2 = value2*10 + (*p-'0');
1588 UCPY(e_extdialing, "Error");
1591 /* if there is a multiplication, we change to / */
1600 /* if there is a division, we change to + */
1609 /* if there is a addition, we change to - */
1618 /* if there is a substraction and a comma, we change to * */
1619 if (p[-1]=='-' && komma1)
1627 /* if there is a substraction and no comma and the first or second value, we change to , */
1636 /* if there is a komma and we are at the first value, we change to * */
1637 if (p[-1]=='.' && state==0)
1646 /* if there is a komma and we are at the second value, we display error */
1647 if (komma2 && state==1)
1649 UCPY(e_extdialing, "Error");
1652 /* if we are at state 1, we write a comma */
1659 /* we assume multiplication */
1666 /* if just a number is displayed, the input is cleared */
1669 *e_extdialing = '\0';
1672 /* calculate the result */
1675 case 0: /* multiply */
1676 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1*value2);
1678 case 1: /* divide */
1679 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1/value2);
1682 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1+value2);
1684 case 3: /* substract */
1685 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1-value2);
1688 e_dialinginfo.id[sizeof(e_dialinginfo.id)-1] = '\0';
1689 if (strchr(e_extdialing, '.')) /* remove zeroes */
1691 while (e_extdialing[strlen(e_extdialing)-1] == '0')
1692 e_extdialing[strlen(e_extdialing)-1] = '\0';
1693 if (e_extdialing[strlen(e_extdialing)-1] == '.')
1694 e_extdialing[strlen(e_extdialing)-1] = '\0'; /* and remove dot */
1696 p = strchr(e_extdialing,'\0')-1;
1729 UCPY(e_extdialing, "Error");
1738 /* display dialing */
1739 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1740 SPRINT(message->param.notifyinfo.display, ">%s", e_extdialing);
1741 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);
1742 message_put(message);
1743 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1748 * process dialing of timer
1750 void EndpointAppPBX::action_dialing_timer(void)
1756 * process 'goto' or 'menu'
1758 void EndpointAppPBX::_action_goto_menu(int mode)
1760 struct port_list *portlist = ea_endpoint->ep_portlist;
1761 struct route_param *rparam;
1763 /* check given ruleset */
1764 if (!(rparam = routeparam(e_action, PARAM_RULESET)))
1767 trace_header("ACTION goto/menu (no ruleset given)", DIRECTION_NONE);
1771 new_state(EPOINT_STATE_OUT_DISCONNECT);
1772 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1773 set_tone(portlist, "cause_3f");
1777 if (rparam->string_value[0] == '\0')
1779 e_ruleset = getrulesetbyname(rparam->string_value);
1782 trace_header("ACTION goto/menu (ruleset not found)", DIRECTION_NONE);
1783 add_trace("ruleset", NULL, "%s", rparam->string_value);
1788 /* if the 'menu' was selected, we will flush all digits */
1791 e_dialinginfo.id[0] = 0;
1792 e_extdialing = e_dialinginfo.id;
1795 /* remove digits that are required to match the rule */
1796 if ((rparam = routeparam(e_action, PARAM_STRIP)))
1799 SCPY(e_dialinginfo.id, e_extdialing);
1800 e_extdialing = e_dialinginfo.id;
1805 trace_header("ACTION goto/menu (change to)", DIRECTION_NONE);
1806 add_trace("ruleset", NULL, "%s", e_ruleset->name);
1807 if (e_dialinginfo.id[0])
1809 add_trace("dialing", NULL, "%s", e_dialinginfo.id);
1811 if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
1813 add_trace("sample", NULL, "%s", rparam->string_value);
1815 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1821 /* do dialing with new ruleset */
1826 /* process dialing goto
1828 void EndpointAppPBX::action_dialing_goto(void)
1830 _action_goto_menu(0);
1833 /* process dialing menu
1835 void EndpointAppPBX::action_dialing_menu(void)
1837 _action_goto_menu(1);
1842 * process dialing disconnect
1844 void EndpointAppPBX::action_dialing_disconnect(void)
1846 struct route_param *rparam;
1847 struct port_list *portlist = ea_endpoint->ep_portlist;
1848 struct lcr_msg *message;
1849 int cause = CAUSE_NORMAL; /* normal call clearing */
1850 int location = LOCATION_PRIVATE_LOCAL;
1851 char cause_string[256] = "", display[84] = "";
1853 /* check cause parameter */
1854 if ((rparam = routeparam(e_action, PARAM_CAUSE)))
1856 cause = rparam->integer_value;
1857 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1859 if ((rparam = routeparam(e_action, PARAM_LOCATION)))
1861 location = rparam->integer_value;
1862 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1866 /* use cause as sample, if not given later */
1867 SPRINT(cause_string, "cause_%02x", cause);
1869 /* check sample parameter */
1870 if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
1872 SCPY(cause_string, rparam->string_value);
1873 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'sample' is given: %s\n", ea_endpoint->ep_serial, cause_string);
1877 if ((rparam = routeparam(e_action, PARAM_DISPLAY)))
1879 SCPY(display, rparam->string_value);
1880 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1883 /* disconnect only if connect parameter is not given */
1884 trace_header("ACTION disconnect", DIRECTION_NONE);
1885 add_trace("cause", "value", "%d", cause);
1886 add_trace("cause", "location", "%d", location);
1887 if (cause_string[0])
1888 add_trace("sample", NULL, "%s", cause_string);
1890 add_trace("display", NULL, "%s", display);
1892 new_state(EPOINT_STATE_OUT_DISCONNECT);
1893 set_tone(portlist, cause_string);
1894 if (!(rparam = routeparam(e_action, PARAM_CONNECT)))
1896 message_disconnect_port(portlist, cause, location, display);
1899 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1900 SCPY(message->param.notifyinfo.display, display);
1901 message_put(message);
1902 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1909 * process dialing help
1911 void EndpointAppPBX::action_dialing_help(void)
1913 /* show all things that would match */
1915 struct numbering *numbering = numbering_int;
1916 char dialing[sizeof(e_dialinginfo.id)];
1918 struct lcr_msg *message;
1919 struct route_param *rparam;
1921 /* in case we have no menu (this should never happen) */
1926 if (strchr(e_dialinginfo.id,'*'))
1929 e_dialinginfo.id[0] = '\0';
1931 if (strchr(e_dialinginfo.id,'#'))
1934 e_dialinginfo.id[0] = '\0';
1937 /* get position in menu */
1940 /* get last menu position */
1942 while(numbering->next)
1945 numbering = numbering->next;
1949 /* get menu position */
1953 numbering = numbering->next;
1957 numbering = numbering_int;
1964 /* if we dial something else we need to add the prefix and change the action */
1965 if (e_dialinginfo.id[0])
1967 e_action = NUMB_ACTION_NONE;
1968 SCPY(dialing, numbering->prefix);
1969 //we ignore the first digit after selecting
1970 //SCAT(dialing, e_dialinginfo.id);
1971 SCPY(e_dialinginfo.id, dialing);
1972 e_extdialing = e_dialinginfo.id+strlen(numbering->prefix);
1973 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);
1979 /* send display message to port */
1980 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1981 SPRINT(message->param.notifyinfo.display, ">%s %s%s%s", numbering->prefix, numb_actions[numbering->action], (numbering->param[0])?" ":"", numbering->param);
1982 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);
1983 message_put(message);
1984 logmessage(message->type, message->paramea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1990 * process dialing deflect
1992 void EndpointAppPBX::action_dialing_deflect(void)
1998 * process dialing setforward
2000 void EndpointAppPBX::action_dialing_setforward(void)
2006 * process hangup 'execute'
2008 void EndpointAppPBX::action_hangup_execute(void)
2010 struct route_param *rparam;
2012 char *command = (char *)"";
2014 char *argv[11]; /* check also number of args below */
2017 /* get script / command */
2018 if ((rparam = routeparam(e_action, PARAM_EXECUTE)))
2019 command = rparam->string_value;
2020 if (command[0] == '\0')
2022 trace_header("ACTION execute (no parameter given)", DIRECTION_NONE);
2026 argv[i++] = (char *)"/bin/sh";
2027 argv[i++] = (char *)"-c";
2028 argv[i++] = command;
2029 argv[i++] = command;
2030 if ((rparam = routeparam(e_action, PARAM_PARAM)))
2032 argv[i++] = rparam->string_value;
2034 argv[i++] = e_extdialing;
2035 argv[i++] = (char *)numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international);
2036 argv[i++] = e_callerinfo.extension;
2037 argv[i++] = e_callerinfo.name;
2038 SPRINT(isdn_port, "%d", e_callerinfo.isdn_port);
2039 argv[i++] = isdn_port;
2040 argv[i++] = NULL; /* check also number of args above */
2041 switch (pid = fork ()) {
2043 trace_header("ACTION execute (fork failed)", DIRECTION_NONE);
2047 execve("/bin/sh", argv, environ);
2050 trace_header("ACTION execute", DIRECTION_NONE);
2051 add_trace("command", NULL, "%s", command);
2059 * process hangup 'file'
2061 void EndpointAppPBX::action_hangup_file(void)
2063 struct route_param *rparam;
2064 const char *file, *content, *mode;
2067 /* get file / content */
2068 if (!(rparam = routeparam(e_action, PARAM_FILE)))
2069 file = rparam->string_value;
2072 if (!(rparam = routeparam(e_action, PARAM_CONTENT)))
2073 content = rparam->string_value;
2075 content = e_extdialing;
2076 if (!(rparam = routeparam(e_action, PARAM_APPEND)))
2080 if (file[0] == '\0')
2082 trace_header("ACTION file (no filename given)", DIRECTION_NONE);
2086 if (!(fp = fopen(file, mode)))
2088 trace_header("ACTION file (failed to open)", DIRECTION_NONE);
2089 add_trace("file", "name", "%s", file);
2090 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2094 trace_header("ACTION file", DIRECTION_NONE);
2095 add_trace("file", "name", "%s", file);
2096 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2097 add_trace("content", NULL, "%s", content);
2099 fprintf(fp, "%s\n", content);
2105 * process init 'pick'
2107 void EndpointAppPBX::action_init_pick(void)
2109 struct route_param *rparam;
2110 char *extensions = NULL;
2112 if ((rparam = routeparam(e_action, PARAM_EXTENSIONS)))
2113 extensions = rparam->string_value;
2115 trace_header("ACTION pick", DIRECTION_NONE);
2116 if (extensions) if (extensions[0])
2117 add_trace("extensions", NULL, "%s", extensions);
2119 pick_join(extensions);
2124 * process dialing 'password'
2126 void EndpointAppPBX::action_dialing_password(void)
2128 struct port_list *portlist = ea_endpoint->ep_portlist;
2130 /* prompt for password */
2131 if (e_extdialing[0] == '\0')
2133 /* give password tone */
2134 set_tone(portlist, "password");
2136 if (e_extdialing[1] == '\0')
2138 /* give password tone */
2139 set_tone(portlist, "dialing");
2142 /* wait until all digits are dialed */
2143 if (strlen(e_ext.password) != strlen(e_extdialing))
2144 return; /* more digits needed */
2146 /* check the password */
2147 if (e_ext.password[0]=='\0' || (strlen(e_ext.password)==strlen(e_extdialing) && !!strcmp(e_ext.password,e_extdialing)))
2149 trace_header("ACTION password_write (wrong password)", DIRECTION_NONE);
2150 add_trace("dialed", NULL, "%s", e_extdialing);
2152 e_connectedmode = 0;
2154 new_state(EPOINT_STATE_OUT_DISCONNECT);
2155 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2156 set_tone(portlist, "cause_10");
2160 /* write caller id if ACTION_PASSWORD_WRITE was selected */
2162 if (e_action->index == ACTION_PASSWORD_WRITE)
2164 append_callbackauth(e_ext.number, &e_callbackinfo);
2165 trace_header("ACTION password_write (written)", DIRECTION_NONE);
2166 add_trace("dialed", NULL, "%s", e_extdialing);
2170 /* make call state */
2171 new_state(EPOINT_STATE_IN_OVERLAP);
2172 e_ruleset = ruleset_main;
2174 e_rule = e_ruleset->rule_first;
2176 e_dialinginfo.id[0] = '\0';
2177 e_extdialing = e_dialinginfo.id;
2178 set_tone(portlist, "dialpbx");
2181 void EndpointAppPBX::action_dialing_password_wr(void)
2183 action_dialing_password();
2187 /* general process dialing of incoming call
2188 * depending on the detected prefix, subfunctions above (action_*) will be
2191 void EndpointAppPBX::process_dialing(void)
2193 struct port_list *portlist = ea_endpoint->ep_portlist;
2194 struct lcr_msg *message;
2195 struct route_param *rparam;
2197 //#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.
2198 //PDEBUG(~0, "HANG-BUG-DEBUGGING: entered porcess_dialing\n");
2199 portlist = ea_endpoint->ep_portlist;
2200 /* check if we have a port instance linked to our epoint */
2204 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);
2205 e_action_timeout = 0;
2206 e_match_timeout = 0;
2211 goto portlist_error;
2214 /* check nesting levels */
2215 if (++e_rule_nesting > RULE_NESTING)
2217 trace_header("ACTION (nesting too deep)", DIRECTION_NONE);
2218 add_trace("max-levels", NULL, "%d", RULE_NESTING);
2220 new_state(EPOINT_STATE_OUT_DISCONNECT);
2221 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2222 set_tone(portlist, "cause_3f");
2223 e_action_timeout = 0;
2224 e_match_timeout = 0;
2228 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before action-timeout processing\n");
2229 /* process timeout */
2230 if (e_action && e_action_timeout) /* e_action may be NULL, but e_action_timeout may still be set and must be ignored */
2232 e_action_timeout = 0;
2233 if (e_state == EPOINT_STATE_CONNECT)
2235 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);
2238 if (e_action->index == ACTION_DISCONNECT
2239 || e_state == EPOINT_STATE_OUT_DISCONNECT)
2241 /* release after disconnect */
2242 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
2245 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0);
2246 e_action = e_action->next;
2249 /* nothing more, so we release */
2250 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action timed out, and we have no next action, so we disconnect.\n", ea_endpoint->ep_serial);
2251 new_state(EPOINT_STATE_OUT_DISCONNECT);
2252 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2253 set_tone(portlist, "cause_3f");
2256 goto action_timeout;
2259 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before setup/overlap state checking\n");
2260 if (e_state!=EPOINT_STATE_IN_SETUP
2261 && e_state!=EPOINT_STATE_IN_OVERLAP)
2263 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);
2264 e_match_timeout = 0;
2269 /* check if we do menu selection */
2270 if (e_action==NUMB_ACTION_NONE && (e_dialinginfo.id[0]=='*' || e_dialinginfo.id[0]=='#'))
2271 /* do menu selection */
2272 if (e_ext.display_menu)
2274 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 */
2276 e_dialinginfo.id[0] = '\0';
2277 e_action = NUMB_ACTION_MENU;
2280 e_match_timeout = 0;
2283 /* invalid dialing */
2284 message_disconnect_port(portlist, CAUSE_INCALID, LOCATION_PRIVATE_LOCAL, "");
2285 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
2286 message->param.disconnectinfo.cause = CAUSE_INVALID;
2287 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2290 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2291 SCPY(message->param.notifyinfo.display,get_isdn_cause(LOCATION_PRIVATE_LOCAL, epoint->e_ext.display_cause, param->disconnectinfo.location, param->disconnectinfo.cause));
2293 message_put(message);
2294 logmessage(message->type, message->param, portlist->port_id, DIRECTION_OUT);
2296 new_state(EPOINT_STATE_OUT_DISCONNECT);
2297 set_tone(portlist,"cause_1c");
2298 e_match_timeout = 0;
2303 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before e_action==NULL\n");
2304 /* if no action yet, we will call try to find a matching rule */
2307 /* be sure that all selectors are initialized */
2310 /* check for external call */
2311 if (!strncmp(e_dialinginfo.id, "extern:", 7))
2313 e_extdialing = e_dialinginfo.id+7;
2314 e_action = &action_external;
2315 goto process_action;
2317 /* check for internal call */
2318 if (!strncmp(e_dialinginfo.id, "intern:", 7))
2320 e_extdialing = e_dialinginfo.id+7;
2321 e_action = &action_internal;
2322 goto process_action;
2324 /* check for chan call */
2325 if (!strncmp(e_dialinginfo.id, "remote:", 7))
2327 e_extdialing = e_dialinginfo.id+7;
2328 e_action = &action_remote;
2329 goto process_action;
2331 /* check for vbox call */
2332 if (!strncmp(e_dialinginfo.id, "vbox:", 5))
2334 e_extdialing = e_dialinginfo.id+5;
2335 e_action = &action_vbox;
2336 goto process_action;
2339 if (e_match_timeout && now_d>=e_match_timeout)
2341 /* return timeout rule */
2342 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);
2343 e_match_timeout = 0;
2344 e_action = e_match_to_action;
2345 e_extdialing = e_match_to_extdialing;
2346 trace_header("ROUTING (timeout)", DIRECTION_NONE);
2347 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2348 add_trace("line", NULL, "%d", e_action->line);
2352 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before routing\n");
2353 /* check for matching rule */
2354 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);
2357 e_action = route(e_ruleset);
2360 trace_header("ACTION (match)", DIRECTION_NONE);
2361 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2362 add_trace("line", NULL, "%d", e_action->line);
2367 e_action = &action_disconnect;
2370 trace_header("ACTION (no main ruleset, disconnecting)", DIRECTION_NONE);
2374 //PDEBUG(~0, "HANG-BUG-DEBUGGING: after routing\n");
2378 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): no rule within the current ruleset matches yet.\n", ea_endpoint->ep_serial, e_ext.number);
2383 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): a rule with action '%s' matches.\n", ea_endpoint->ep_serial, action_defs[e_action->index].name);
2388 e_action_timeout = 0;
2389 if (e_action->timeout)
2391 e_action_timeout = now_d + e_action->timeout;
2392 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action has a timeout of %d secods.\n", ea_endpoint->ep_serial, e_action->timeout);
2396 /* check param proceeding / alerting / connect */
2397 if ((rparam = routeparam(e_action, PARAM_CONNECT)))
2399 /* NOTE: we may not change our state to connect, because dialing will then not possible */
2401 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2402 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
2403 message_put(message);
2404 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2406 if ((rparam = routeparam(e_action, PARAM_ALERTING)))
2408 /* NOTE: we may not change our state to alerting, because dialing will then not possible */
2409 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2410 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
2411 message_put(message);
2412 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2414 if ((rparam = routeparam(e_action, PARAM_PROCEEDING)))
2416 /* NOTE: we may not change our state to proceeding, because dialing will then not possible */
2417 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2418 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
2419 message_put(message);
2420 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2423 if (action_defs[e_action->index].init_func)
2425 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);
2426 (this->*(action_defs[e_action->index].init_func))();
2428 if (e_state!=EPOINT_STATE_IN_SETUP
2429 && e_state!=EPOINT_STATE_IN_OVERLAP)
2431 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);
2432 goto display_action;
2436 /* show what we are doing */
2437 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);
2438 /* go to action's dialing function */
2439 if (action_defs[e_action->index].dialing_func)
2441 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);
2442 (this->*(action_defs[e_action->index].dialing_func))();
2445 /* display selected dialing action if enabled and still in setup state */
2449 if (e_action->index==ACTION_MENU
2450 || e_action->index==ACTION_REDIAL
2451 || e_action->index==ACTION_REPLY
2452 || e_action->index==ACTION_TIMER
2453 || e_action->index==ACTION_CALCULATOR
2454 || e_action->index==ACTION_TEST)
2458 if (!e_ext.display_dialing)
2460 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*/)
2461 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 */
2463 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2467 SPRINT(message->param.notifyinfo.display, "> %s", e_dialinginfo.id);
2470 SPRINT(message->param.notifyinfo.display, "%s%s%s", action_defs[e_action->index].name, (e_extdialing[0])?" ":"", e_extdialing);
2473 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s'\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
2474 message_put(message);
2475 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2484 /* some services store information after hangup */
2485 void EndpointAppPBX::process_hangup(int cause, int location)
2487 char callertext[256], dialingtext[256];
2488 int writeext = 0, i;
2490 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s'\n", ea_endpoint->ep_serial, e_ext.number);
2491 if (e_ext.number[0])
2493 if (read_extension(&e_ext, e_ext.number))
2503 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);
2504 switch(e_dialinginfo.itype)
2506 case INFO_ITYPE_CHAN:
2507 SPRINT(dialingtext, "chan:%s", e_dialinginfo.id);
2509 case INFO_ITYPE_ISDN_EXTENSION:
2510 SPRINT(dialingtext, "intern:%s", e_dialinginfo.id);
2512 case INFO_ITYPE_VBOX:
2513 SPRINT(dialingtext, "vbox:%s", e_dialinginfo.id);
2516 SPRINT(dialingtext, "%s", e_dialinginfo.id);
2519 if (e_callerinfo.id[0])
2520 SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2522 SPRINT(callertext, "unknown");
2523 /* allpy restriction */
2524 if (!e_ext.anon_ignore && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
2525 SPRINT(callertext, "anonymous");
2526 if (e_callerinfo.extension[0]) /* add intern if present */
2527 UNPRINT(strchr(callertext,'\0'), sizeof(callertext)-1+strlen(callertext), " (intern %s)", e_callerinfo.extension);
2528 write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location);
2530 /* store last received call for reply-list */
2531 if (e_origin == 1) // outgoing to phone is incoming for user
2532 if (e_callerinfo.id[0] || e_callerinfo.extension[0])
2533 if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED)
2535 if (e_callerinfo.extension[0])
2536 SPRINT(callertext, "intern:%s", e_callerinfo.extension);
2538 SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2539 if (!!strcmp(callertext, e_ext.last_in[0]))
2544 UCPY(e_ext.last_in[i], e_ext.last_in[i-1]);
2547 SCPY(e_ext.last_in[0], callertext);
2548 writeext |= 1; /* store extension later */
2549 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]);
2551 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);
2554 /* store last made call for reply-list */
2555 if (e_origin == 0) // incoming from phone is outgoing for user
2556 if (e_dialinginfo.id[0])
2558 if (!!strcmp(e_dialinginfo.id, e_ext.last_out[0]))
2563 UCPY(e_ext.last_out[i], e_ext.last_out[i-1]);
2566 SCPY(e_ext.last_out[0], e_dialinginfo.id);
2567 writeext |= 1; /* store extension later */
2568 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
2570 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);
2573 /* write extension if needed */
2574 if (writeext == 0x11)
2575 write_extension(&e_ext, e_ext.number);
2579 if (action_defs[e_action->index].hangup_func)
2581 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);
2582 (this->*(action_defs[e_action->index].hangup_func))();