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 void 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_RESSOURCEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
52 new_state(EPOINT_STATE_OUT_DISCONNECT);
53 set_tone(portlist,"cause_22");
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;
64 void EndpointAppPBX::action_init_call(void)
66 _action_init_call(NULL);
68 void EndpointAppPBX::action_init_remote(void)
70 struct route_param *rparam;
71 struct port_list *portlist = ea_endpoint->ep_portlist;
72 struct lcr_msg *message;
73 struct capa_info capainfo;
74 struct caller_info callerinfo;
75 struct redir_info redirinfo;
76 struct dialing_info dialinginfo;
80 if (!(rparam = routeparam(e_action, PARAM_APPLICATION)))
82 trace_header("ACTION remote (no application given)", DIRECTION_NONE);
84 new_state(EPOINT_STATE_OUT_DISCONNECT);
85 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
86 set_tone(portlist, "cause_3f");
89 SCPY(remote, rparam->string_value);
90 _action_init_call(remote);
92 /* create bearer/caller/dialinginfo */
93 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
94 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
95 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
96 memset(&dialinginfo, 0, sizeof(dialinginfo));
98 if ((rparam = routeparam(e_action, PARAM_EXTEN)))
100 SCPY(exten, rparam->string_value);
102 /* send setup to remote */
103 trace_header("ACTION remote (setup)", DIRECTION_NONE);
104 add_trace("number", NULL, dialinginfo.id);
105 add_trace("remote", NULL, remote);
107 add_trace("exten", NULL, remote);
109 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
110 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
111 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
112 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
113 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
114 SCPY(message->param.setup.exten, exten);
115 message_put(message);
119 * process dialing 'internal'
121 void EndpointAppPBX::action_dialing_internal(void)
123 struct capa_info capainfo;
124 struct caller_info callerinfo;
125 struct redir_info redirinfo;
126 struct dialing_info dialinginfo;
127 struct port_list *portlist = ea_endpoint->ep_portlist;
128 struct lcr_msg *message;
129 struct extension ext;
130 struct route_param *rparam;
132 /* send proceeding, because number is complete */
133 set_tone(portlist, "proceeding");
134 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
135 message_put(message);
136 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
137 new_state(EPOINT_STATE_IN_PROCEEDING);
139 /* create bearer/caller/dialinginfo */
140 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
141 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
142 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
143 memset(&dialinginfo, 0, sizeof(dialinginfo));
144 dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
145 SCPY(dialinginfo.id, e_dialinginfo.id);
147 /* process extension */
148 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
149 SCPY(dialinginfo.id, rparam->string_value);
151 /* process number type */
152 if ((rparam = routeparam(e_action, PARAM_TYPE)))
153 dialinginfo.ntype = rparam->integer_value;
155 /* process service */
156 if ((rparam = routeparam(e_action, PARAM_CAPA)))
158 capainfo.bearer_capa = rparam->integer_value;
159 if (capainfo.bearer_capa != INFO_BC_SPEECH
160 && capainfo.bearer_capa != INFO_BC_AUDIO)
162 capainfo.bearer_mode = INFO_BMODE_PACKET;
164 capainfo.bearer_info1 = INFO_INFO1_NONE;
166 if ((rparam = routeparam(e_action, PARAM_BMODE)))
168 capainfo.bearer_mode = rparam->integer_value;
170 if ((rparam = routeparam(e_action, PARAM_INFO1)))
172 capainfo.bearer_info1 = rparam->integer_value;
174 if ((rparam = routeparam(e_action, PARAM_HLC)))
176 capainfo.hlc = rparam->integer_value;
178 if ((rparam = routeparam(e_action, PARAM_EXTHLC)))
180 capainfo.exthlc = rparam->integer_value;
183 /* process presentation */
184 if ((rparam = routeparam(e_action, PARAM_PRESENT)))
186 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
189 /* check if extension exists AND only if not multiple extensions */
190 if (!read_extension(&ext, dialinginfo.id) && !strchr(dialinginfo.id,','))
192 trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE);
193 add_trace("extension", NULL, dialinginfo.id);
195 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0);
196 new_state(EPOINT_STATE_OUT_DISCONNECT);
197 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
198 set_tone(portlist, "cause_86");
201 /* check if internal calls are denied */
202 if (e_ext.rights < 1)
204 trace_header("ACTION extension (dialing to extension denied)", DIRECTION_NONE);
205 add_trace("extension", NULL, dialinginfo.id);
207 new_state(EPOINT_STATE_OUT_DISCONNECT);
208 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0);
209 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
210 set_tone(portlist, "cause_81");
214 /* add or update internal call */
215 trace_header("ACTION extension (calling)", DIRECTION_NONE);
216 add_trace("extension", NULL, dialinginfo.id);
218 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
219 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
220 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
221 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
222 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
223 message_put(message);
226 /* process dialing external
228 void EndpointAppPBX::action_dialing_external(void)
230 struct capa_info capainfo;
231 struct caller_info callerinfo;
232 struct redir_info redirinfo;
233 struct dialing_info dialinginfo;
235 struct port_list *portlist = ea_endpoint->ep_portlist;
236 struct lcr_msg *message;
237 struct route_param *rparam;
239 /* special processing of delete characters '*' and '#' */
240 if (e_ext.delete_ext)
242 /* dialing a # causes a clearing of complete number */
243 if (strchr(e_extdialing, '#'))
245 e_extdialing[0] = '\0';
246 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);
248 /* eliminate digits before '*', which is a delete digit
250 if (strchr(e_extdialing, '*'))
253 while((p=strchr(e_extdialing, '*')))
255 if (p > e_extdialing) /* only if there is a digit in front */
260 UCPY(p, p+1); /* remove '*' */
262 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s deleted digits and got new string: %s\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing);
266 /* create bearer/caller/dialinginfo */
267 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
268 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
269 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
270 memset(&dialinginfo, 0, sizeof(dialinginfo));
271 dialinginfo.itype = INFO_ITYPE_ISDN;
272 dialinginfo.sending_complete = 0;
273 SCPY(dialinginfo.id, e_extdialing);
276 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
277 SPRINT(dialinginfo.id, "%s%s", rparam->string_value, e_extdialing);
279 /* process number complete */
280 if ((rparam = routeparam(e_action, PARAM_COMPLETE)))
281 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
282 SCPY(dialinginfo.id, rparam->string_value);
283 dialinginfo.sending_complete = 1;
285 /* process number type */
286 if ((rparam = routeparam(e_action, PARAM_TYPE)))
287 dialinginfo.ntype = rparam->integer_value;
289 /* process service */
290 if ((rparam = routeparam(e_action, PARAM_CAPA)))
292 capainfo.bearer_capa = rparam->integer_value;
293 if (capainfo.bearer_capa != INFO_BC_SPEECH
294 && capainfo.bearer_capa != INFO_BC_AUDIO)
296 capainfo.bearer_mode = INFO_BMODE_PACKET;
298 capainfo.bearer_info1 = INFO_INFO1_NONE;
300 if ((rparam = routeparam(e_action, PARAM_BMODE)))
302 capainfo.bearer_mode = rparam->integer_value;
304 if ((rparam = routeparam(e_action, PARAM_INFO1)))
306 capainfo.bearer_info1 = rparam->integer_value;
308 if ((rparam = routeparam(e_action, PARAM_HLC)))
310 capainfo.hlc = rparam->integer_value;
312 if ((rparam = routeparam(e_action, PARAM_EXTHLC)))
314 capainfo.exthlc = rparam->integer_value;
318 /* process callerid */
319 if ((rparam = routeparam(e_action, PARAM_CALLERID)))
321 SCPY(callerinfo.id, rparam->string_value);
323 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
325 callerinfo.ntype = rparam->integer_value;
328 /* process presentation */
329 if ((rparam = routeparam(e_action, PARAM_PRESENT)))
331 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
334 /* process interfaces */
335 if ((rparam = routeparam(e_action, PARAM_INTERFACES)))
336 SCPY(dialinginfo.interfaces, rparam->string_value);
338 /* check if local calls are denied */
339 if (e_ext.rights < 2)
341 trace_header("ACTION extern (calling denied)", DIRECTION_NONE);
343 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0);
344 set_tone(portlist, "cause_82");
346 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
347 new_state(EPOINT_STATE_OUT_DISCONNECT);
351 if (!strncmp(dialinginfo.id, options.national, strlen(options.national))
352 || dialinginfo.ntype == INFO_NTYPE_NATIONAL
353 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL)
355 /* check if national calls are denied */
356 if (e_ext.rights < 3)
358 trace_header("ACTION extern (national calls denied)", DIRECTION_NONE);
360 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0);
361 set_tone(portlist, "cause_83");
366 if (!strncmp(dialinginfo.id, options.international, strlen(options.international))
367 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL)
369 /* check if international calls are denied */
370 if (e_ext.rights < 4)
372 trace_header("ACTION extern (international calls denied)", DIRECTION_NONE);
374 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0);
375 set_tone(portlist, "cause_84");
380 /* add or update outgoing call */
381 trace_header("ACTION extern (calling)", DIRECTION_NONE);
382 add_trace("number", NULL, dialinginfo.id);
383 if (dialinginfo.interfaces[0])
384 add_trace("interfaces", NULL, dialinginfo.interfaces);
386 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
387 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
388 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
389 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
390 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
391 message_put(message);
395 void EndpointAppPBX::action_dialing_remote(void)
397 struct lcr_msg *message;
398 struct dialing_info dialinginfo;
399 // struct route_param *rparam;
401 /* create bearer/caller/dialinginfo */
402 memset(&dialinginfo, 0, sizeof(dialinginfo));
404 if (dialinginfo.id[0])
406 /* add or update outgoing call */
407 trace_header("ACTION remote (dialing)", DIRECTION_NONE);
408 add_trace("number", NULL, dialinginfo.id);
410 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_INFORMATION);
411 memcpy(&message->param.information, &dialinginfo, sizeof(struct dialing_info));
412 message_put(message);
418 * process dialing the "am" and record
420 void EndpointAppPBX::action_dialing_vbox_record(void)
422 struct dialing_info dialinginfo;
423 struct port_list *portlist = ea_endpoint->ep_portlist;
424 struct lcr_msg *message;
425 struct extension ext;
426 struct route_param *rparam;
428 portlist = ea_endpoint->ep_portlist;
430 /* check for given extension */
431 if (!(rparam = routeparam(e_action, PARAM_EXTENSION)))
433 trace_header("ACTION vbox-record (no extension given by parameter)", DIRECTION_NONE);
436 new_state(EPOINT_STATE_OUT_DISCONNECT);
437 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
438 set_tone(portlist, "cause_3f");
442 /* check if extension exists */
443 if (!read_extension(&ext, rparam->string_value))
445 trace_header("ACTION vbox-record (given extension does not exists)", DIRECTION_NONE);
446 add_trace("extension", NULL, "%s", rparam->string_value);
448 new_state(EPOINT_STATE_OUT_DISCONNECT);
449 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
450 set_tone(portlist, "cause_86");
454 /* check if internal calls are denied */
455 if (e_ext.rights < 1)
457 trace_header("ACTION vbox-record (internal calls are denied)", DIRECTION_NONE);
459 new_state(EPOINT_STATE_OUT_DISCONNECT);
460 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
461 set_tone(portlist, "cause_81");
465 set_tone(portlist, "proceeding");
466 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
467 message_put(message);
468 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
469 new_state(EPOINT_STATE_IN_PROCEEDING);
471 memset(&dialinginfo, 0, sizeof(dialinginfo));
472 dialinginfo.itype = INFO_ITYPE_VBOX;
473 dialinginfo.sending_complete = 1;
474 SCPY(dialinginfo.id, rparam->string_value);
476 /* append special announcement (if given) */
477 if ((rparam = routeparam(e_action, PARAM_ANNOUNCEMENT)))
478 if (rparam->string_value[0])
480 SCAT(dialinginfo.id, ",");
481 SCAT(dialinginfo.id, rparam->string_value);
484 /* add or update internal call */
485 trace_header("ACTION vbox-record (calling)", DIRECTION_NONE);
486 add_trace("extension", NULL, "%s", dialinginfo.id);
488 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
489 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
490 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
491 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
492 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
493 message_put(message);
500 void EndpointAppPBX::action_init_partyline(void)
503 class JoinPBX *joinpbx;
504 struct port_list *portlist = ea_endpoint->ep_portlist;
505 struct lcr_msg *message;
506 struct route_param *rparam;
507 int partyline, jingle = 0;
508 struct join_relation *relation;
510 portlist = ea_endpoint->ep_portlist;
512 /* check for given extension */
513 if (!(rparam = routeparam(e_action, PARAM_ROOM)))
515 trace_header("ACTION partyline (no room parameter)", DIRECTION_NONE);
518 new_state(EPOINT_STATE_OUT_DISCONNECT);
519 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
520 set_tone(portlist, "cause_3f");
523 if (rparam->integer_value <= 0)
525 trace_header("ACTION partyline (illegal room parameter)", DIRECTION_NONE);
526 add_trace("room", NULL, "%d", rparam->integer_value);
528 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): invalid value for 'room'.\n", ea_endpoint->ep_serial);
531 partyline = rparam->integer_value;
532 if ((rparam = routeparam(e_action, PARAM_JINGLE)))
535 /* don't create join if partyline exists */
539 if (join->j_type == JOIN_TYPE_PBX)
541 joinpbx = (class JoinPBX *)join;
542 if (joinpbx->j_partyline == partyline)
550 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
551 if (!(join = new JoinPBX(ea_endpoint)))
552 FATAL("No memory for join object\n");
555 //NOTE: joinpbx must be set here
556 /* add relation to existing join */
557 if (!(relation=joinpbx->add_relation()))
558 FATAL("No memory for join relation\n");
559 relation->type = RELATION_TYPE_SETUP;
560 relation->channel_state = CHANNEL_STATE_CONNECT;
561 relation->rx_state = NOTIFY_STATE_ACTIVE;
562 relation->tx_state = NOTIFY_STATE_ACTIVE;
563 relation->epoint_id = ea_endpoint->ep_serial;
566 ea_endpoint->ep_join_id = join->j_serial;
568 set_tone(portlist, "proceeding");
569 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
570 message_put(message);
571 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
572 new_state(EPOINT_STATE_IN_PROCEEDING);
574 /* send setup to join */
575 trace_header("ACTION partyline (calling)", DIRECTION_NONE);
576 add_trace("room", NULL, "%d", partyline);
577 add_trace("jingle", NULL, (jingle)?"on":"off");
579 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
580 message->param.setup.partyline = partyline;
581 message->param.setup.partyline_jingle = jingle;
582 memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info));
583 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
584 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
585 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
586 message_put(message);
591 * process hangup of all calls
593 void EndpointAppPBX::action_hangup_call(void)
595 trace_header("ACTION hangup", DIRECTION_NONE);
601 * process dialing 'login'
603 void EndpointAppPBX::action_dialing_login(void)
605 struct port_list *portlist = ea_endpoint->ep_portlist;
606 struct lcr_msg *message;
608 struct route_param *rparam;
610 /* extension parameter */
611 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
613 /* extension is given by parameter */
614 extension = rparam->string_value;
615 if (extension[0] == '\0')
617 if (!read_extension(&e_ext, extension))
619 trace_header("ACTION login (extension doesn't exist)", DIRECTION_NONE);
620 add_trace("extension", NULL, "%s", extension);
622 /* extension doesn't exist */
623 new_state(EPOINT_STATE_OUT_DISCONNECT);
624 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
625 set_tone(portlist, "cause_86");
630 /* extension must be given by dialstring */
631 extension = e_extdialing;
632 if (extension[0] == '\0')
634 if (!read_extension(&e_ext, extension))
636 trace_header("ACTION login (extension incomplete or does not exist)", DIRECTION_NONE);
637 add_trace("extension", NULL, "%s", extension);
643 /* we changed our extension */
644 SCPY(e_ext.number, extension);
645 new_state(EPOINT_STATE_CONNECT);
649 /* send connect with extension's caller id (COLP) */
650 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
651 SCPY(message->param.connectinfo.id, e_ext.callerid);
652 message->param.connectinfo.ntype = e_ext.callerid_type;
653 if (e_ext.callerid_present==INFO_PRESENT_ALLOWED && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
654 message->param.connectinfo.present = INFO_PRESENT_RESTRICTED;
655 else message->param.connectinfo.present = e_ext.callerid_present;
656 /* handle restricted caller ids */
657 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);
658 /* display callerid if desired for extension */
659 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));
660 message->param.connectinfo.ntype = e_ext.callerid_type;
661 message_put(message);
662 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
664 /* set our caller id */
665 SCPY(e_callerinfo.id, e_ext.callerid);
666 e_callerinfo.ntype = e_ext.callerid_type;
667 e_callerinfo.present = e_ext.callerid_present;
669 /* enable connectedmode */
673 if (!(rparam = routeparam(e_action, PARAM_NOPASSWORD)))
675 /* make call state to enter password */
676 trace_header("ACTION login (ask for password)", DIRECTION_NONE);
677 add_trace("extension", NULL, "%s", e_ext.number);
679 new_state(EPOINT_STATE_IN_OVERLAP);
682 e_action = &action_password;
684 e_match_to_action = NULL;
685 e_dialinginfo.id[0] = '\0';
686 e_extdialing = strchr(e_dialinginfo.id, '\0');
689 e_password_timeout = now+20;
695 /* make call state */
696 new_state(EPOINT_STATE_IN_OVERLAP);
697 e_ruleset = ruleset_main;
699 e_rule = e_ruleset->rule_first;
701 e_dialinginfo.id[0] = '\0';
702 e_extdialing = e_dialinginfo.id;
703 set_tone(portlist, "dialpbx");
709 * process init 'change_callerid'
711 void EndpointAppPBX::action_init_change_callerid(void)
713 struct port_list *portlist = ea_endpoint->ep_portlist;
715 if (!e_ext.change_callerid)
717 /* service not available */
718 trace_header("ACTION change-callerid (denied for this caller)", DIRECTION_NONE);
720 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
721 new_state(EPOINT_STATE_OUT_DISCONNECT);
722 set_tone(portlist,"cause_87");
727 /* process dialing callerid
729 void EndpointAppPBX::_action_callerid_calleridnext(int next)
731 struct port_list *portlist = ea_endpoint->ep_portlist;
732 struct route_param *rparam;
733 char buffer[64], *callerid;
734 char old_id[64] = "", new_id[64] = "";
735 int old_type=0, new_type=0, old_present=0, new_present=0;
737 if ((rparam = routeparam(e_action, PARAM_CALLERID)))
739 /* the caller ID is given by parameter */
740 callerid = rparam->string_value;
743 /* caller ID is dialed */
744 if (!strchr(e_extdialing, '#'))
746 /* no complete ID yet */
749 *strchr(e_extdialing, '#') = '\0';
750 callerid = e_extdialing;
753 /* given callerid type */
754 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
755 switch(rparam->integer_value)
757 case INFO_NTYPE_SUBSCRIBER:
758 SPRINT(buffer, "s%s", callerid);
761 case INFO_NTYPE_NATIONAL:
762 SPRINT(buffer, "n%s", callerid);
765 case INFO_NTYPE_INTERNATIONAL:
766 SPRINT(buffer, "i%s", callerid);
770 SPRINT(buffer, "%s", callerid);
775 /* caller id complete, dialing with new caller id */
776 /* write new parameters */
777 if (read_extension(&e_ext, e_ext.number))
779 old_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
780 old_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
781 SCPY(old_id, (!next)?e_ext.callerid:e_ext.id_next_call);
782 if (callerid[0] == '\0')
785 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
789 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_ALLOWED;
790 if ((rparam = routeparam(e_action, PARAM_PRESENT))) if (rparam->integer_value == 0)
791 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
792 if (e_ext.callerid_type == INFO_NTYPE_UNKNOWN) /* if callerid is unknown, the given id is not nationalized */
794 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, callerid);
795 (!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN;
798 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));
800 if (!next) e_ext.id_next_call_type = -1;
801 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);
803 new_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
804 new_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
805 SCPY(new_id, (!next)?e_ext.callerid:e_ext.id_next_call);
806 write_extension(&e_ext, e_ext.number);
809 /* function activated */
811 trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE);
813 trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE);
814 add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type, options.national, options.international));
815 add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
816 add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type, options.national, options.international));
817 add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
819 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
820 new_state(EPOINT_STATE_OUT_DISCONNECT);
821 set_tone(portlist,"activated");
824 /* process dialing callerid for all call
826 void EndpointAppPBX::action_dialing_callerid(void)
828 _action_callerid_calleridnext(0);
831 /* process dialing callerid for next call
833 void EndpointAppPBX::action_dialing_calleridnext(void)
835 _action_callerid_calleridnext(1);
840 * process init 'change_forward'
842 void EndpointAppPBX::action_init_change_forward(void)
844 struct port_list *portlist = ea_endpoint->ep_portlist;
846 if (!e_ext.change_forward)
848 trace_header("ACTION change-forward (denied for this caller)", DIRECTION_NONE);
850 /* service not available */
851 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
852 new_state(EPOINT_STATE_OUT_DISCONNECT);
853 set_tone(portlist,"cause_87");
858 /* process dialing forwarding
860 void EndpointAppPBX::action_dialing_forward(void)
862 struct port_list *portlist = ea_endpoint->ep_portlist;
863 int diversion = INFO_DIVERSION_CFU;
864 char *dest = e_extdialing;
865 struct route_param *rparam;
867 /* if diversion type is given */
868 if ((rparam = routeparam(e_action, PARAM_DIVERSION)))
869 diversion = rparam->integer_value;
871 if ((rparam = routeparam(e_action, PARAM_DEST)))
873 /* if destination is given */
874 dest = rparam->string_value;
877 if (!strchr(e_extdialing, '#'))
879 *strchr(e_extdialing, '#') = '\0';
883 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing forwarding to '%s'.\n", ea_endpoint->ep_serial, e_ext.number, dest);
884 if (read_extension(&e_ext, e_ext.number))
888 case INFO_DIVERSION_CFU:
889 trace_header("ACTION change-forward (new CFU=unconditional)", DIRECTION_NONE);
890 add_trace("destin'", NULL, "%s", dest);
892 SCPY(e_ext.cfu, dest);
894 case INFO_DIVERSION_CFB:
895 trace_header("ACTION change-forward (new CFB=busy)", DIRECTION_NONE);
896 add_trace("destin'", NULL, "%s", dest);
898 SCPY(e_ext.cfb, dest);
900 case INFO_DIVERSION_CFNR:
901 if ((rparam = routeparam(e_action, PARAM_DELAY)))
902 e_ext.cfnr_delay = rparam->integer_value;
903 trace_header("ACTION change-forward (new CFNR=no response)", DIRECTION_NONE);
904 add_trace("destin'", NULL, "%s", dest);
905 add_trace("delay", NULL, "%s", e_ext.cfnr_delay);
907 SCPY(e_ext.cfnr, dest);
909 case INFO_DIVERSION_CFP:
910 trace_header("ACTION change-forward (new CFP=parallel)", DIRECTION_NONE);
911 add_trace("destin'", NULL, "%s", dest);
913 SCPY(e_ext.cfp, dest);
916 write_extension(&e_ext, e_ext.number);
918 /* function (de)activated */
919 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
920 new_state(EPOINT_STATE_OUT_DISCONNECT);
922 set_tone(portlist,"activated");
924 set_tone(portlist,"deactivated");
928 /* process dialing redial
930 void EndpointAppPBX::action_init_redial_reply(void)
932 struct port_list *portlist = ea_endpoint->ep_portlist;
935 if (!e_ext.last_out[0])
937 trace_header("ACTION redial/reply (no last number stored)", DIRECTION_NONE);
939 new_state(EPOINT_STATE_OUT_DISCONNECT);
940 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
941 set_tone(portlist, "cause_3f");
946 /* process dialing redial
948 void EndpointAppPBX::_action_redial_reply(int in)
950 struct lcr_msg *message;
952 struct route_param *rparam;
954 last = (in)?e_ext.last_in[0]:e_ext.last_out[0];
956 /* if no display is available */
957 if (!e_ext.display_menu)
959 if (ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_IN && ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_OUT)
962 /* if select is not given */
963 if (!(rparam = routeparam(e_action, PARAM_SELECT)))
967 if (e_extdialing[0]=='*' || e_extdialing[0]=='1')
969 /* find prev entry */
975 if (e_extdialing[0]=='#' || e_extdialing[0]=='3')
977 /* find next entry */
979 if (e_select >= MAX_REMEMBER)
982 if (e_ext.last_in[e_select][0] == '\0')
985 if (e_ext.last_out[e_select][0] == '\0')
990 last = (in)?e_ext.last_in[e_select]:e_ext.last_out[e_select];
991 if (e_extdialing[0]=='0' || e_extdialing[0]=='2')
995 trace_header("ACTION reply (dialing)", DIRECTION_NONE);
997 trace_header("ACTION redial (dialing)", DIRECTION_NONE);
998 add_trace("number", NULL, "%s", last);
999 add_trace("last but", NULL, "%d", e_select);
1001 SCPY(e_dialinginfo.id, last);
1002 e_extdialing = e_dialinginfo.id;
1007 e_extdialing[0] = '\0';
1009 /* send display message to port */
1010 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1011 if (!strncmp(last, "extern:", 7))
1012 SPRINT(message->param.notifyinfo.display, "(%d) %s ext", e_select+1, last+7);
1014 if (!strncmp(last, "intern:", 7))
1015 SPRINT(message->param.notifyinfo.display, "(%d) %s int", e_select+1, last+7);
1017 if (!strncmp(last, "chan:", 4))
1018 SPRINT(message->param.notifyinfo.display, "(%d) %s chan", e_select+1, last+5);
1020 if (!strncmp(last, "vbox:", 5))
1021 SPRINT(message->param.notifyinfo.display, "(%d) %s vbox", e_select+1, last+5);
1023 SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -");
1024 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
1025 message_put(message);
1026 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1029 /* process dialing redial
1031 void EndpointAppPBX::action_dialing_redial(void)
1033 _action_redial_reply(0);
1036 /* process dialing reply
1038 void EndpointAppPBX::action_dialing_reply(void)
1040 _action_redial_reply(1);
1044 /* dialing powerdialing delay
1046 void EndpointAppPBX::action_dialing_powerdial(void)
1048 struct port_list *portlist = ea_endpoint->ep_portlist;
1049 struct lcr_msg *message;
1050 struct route_param *rparam;
1052 /* power dialing only possible if we have a last dialed number */
1053 if (!e_ext.last_out[0])
1055 trace_header("ACTION powerdial (no last number stored)", DIRECTION_NONE);
1057 new_state(EPOINT_STATE_OUT_DISCONNECT);
1058 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1059 set_tone(portlist, "cause_3f");
1064 if ((rparam = routeparam(e_action, PARAM_LIMIT)))
1066 e_powerlimit = rparam->integer_value;
1073 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1075 e_powerdelay = rparam->integer_value;
1078 /* delay incomplete */
1079 if (!strchr(e_extdialing, '#'))
1081 *strchr(e_extdialing, '#') = '\0';
1082 e_powerdelay = e_extdialing[0]?atoi(e_extdialing): 0;
1085 if (e_powerdelay < 1)
1087 trace_header("ACTION powerdial (dialing)", DIRECTION_NONE);
1088 add_trace("number", NULL, "%s", e_ext.last_out[0]);
1089 add_trace("delay", NULL, "%d", e_powerdelay);
1092 /* send connect to avoid overlap timeout */
1093 // new_state(EPOINT_STATE_CONNECT); connect may prevent further dialing
1094 if (e_ext.number[0])
1096 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1097 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1098 message_put(message);
1099 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1102 SCPY(e_dialinginfo.id, e_ext.last_out[0]);
1103 e_powerdialing = -1; /* indicates the existence of powerdialing but no redial time given */
1112 void EndpointAppPBX::action_dialing_callback(void)
1114 struct port_list *portlist = ea_endpoint->ep_portlist;
1115 struct route_param *rparam;
1116 struct extension cbext;
1118 portlist = ea_endpoint->ep_portlist;
1120 /* check given extension */
1121 if (!(rparam = routeparam(e_action, PARAM_EXTENSION)))
1124 trace_header("ACTION callback (no extension defined)", DIRECTION_NONE);
1128 new_state(EPOINT_STATE_OUT_DISCONNECT);
1129 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1130 set_tone(portlist, "cause_3f");
1132 e_cbcaller[0] = e_cbdialing[0] = '\0';
1136 /* if extension is given */
1137 SCPY(e_cbcaller, rparam->string_value);
1138 if (e_cbcaller[0] == '\0')
1141 /* read callback extension */
1142 memset(&cbext, 0, sizeof(cbext));
1143 if (!read_extension(&cbext, e_cbcaller))
1145 trace_header("ACTION callback (extension doesn't exist)", DIRECTION_NONE);
1146 add_trace("extension", NULL, "%s", e_cbcaller);
1151 /* if password is not given */
1152 if (cbext.password[0] == '\0')
1154 trace_header("ACTION callback (no password set)", DIRECTION_NONE);
1155 add_trace("extension", NULL, "%s", e_cbcaller);
1160 /* callback only possible if callerid exists OR it is given */
1161 if ((rparam = routeparam(e_action, PARAM_CALLTO)))
1162 SCPY(e_cbto, rparam->string_value);
1165 trace_header("ACTION callback (alternative caller id)", DIRECTION_NONE);
1166 add_trace("extension", NULL, "%s", e_cbcaller);
1167 add_trace("callerid", NULL, "%s", e_cbto);
1169 SCPY(e_callerinfo.id, e_cbto);
1170 e_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
1171 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1173 if (e_callerinfo.id[0]=='\0' || e_callerinfo.present==INFO_PRESENT_NOTAVAIL)
1175 trace_header("ACTION callback (no caller ID available)", DIRECTION_NONE);
1176 add_trace("extension", NULL, "%s", e_cbcaller);
1181 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1186 * process hangup 'callback'
1188 void EndpointAppPBX::action_hangup_callback(void)
1190 struct route_param *rparam;
1194 delay = 2; /* default value */
1195 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1196 if (rparam->integer_value>0)
1197 delay = rparam->integer_value;
1199 /* dialing after callback */
1200 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1201 SCPY(e_cbdialing, rparam->string_value);
1203 SCPY(e_cbdialing, e_extdialing);
1205 trace_header("ACTION callback (dialing)", DIRECTION_NONE);
1206 add_trace("extension", NULL, "%s", e_cbcaller);
1207 add_trace("caller id", NULL, "%s", e_callerinfo.id);
1208 add_trace("delay", NULL, "%d", delay);
1209 add_trace("dialing", NULL, "%s", e_cbdialing);
1212 /* set time to callback */
1213 e_callback = now_d + delay;
1218 * dialing action abbreviation
1220 void EndpointAppPBX::action_dialing_abbrev(void)
1222 struct port_list *portlist = ea_endpoint->ep_portlist;
1223 char *abbrev, *phone, *name;
1226 portlist = ea_endpoint->ep_portlist;
1228 /* abbrev dialing is only possible if we have a caller defined */
1229 if (!e_ext.number[0])
1231 trace_header("ACTION abbreviation (only for extension)", DIRECTION_NONE);
1233 new_state(EPOINT_STATE_OUT_DISCONNECT);
1234 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1235 set_tone(portlist, "cause_3f");
1239 /* check abbreviation */
1240 abbrev = e_extdialing;
1243 result = parse_phonebook(e_ext.number, &abbrev, &phone, &name);
1246 trace_header("ACTION abbreviation (not found)", DIRECTION_NONE);
1247 add_trace("abbrev", NULL, "%s", abbrev);
1249 new_state(EPOINT_STATE_OUT_DISCONNECT);
1250 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
1251 set_tone(portlist, "cause_01");
1254 if (result == -1) /* may match if more digits are dialed */
1259 /* dial abbreviation */
1260 trace_header("ACTION abbreviation (dialing)", DIRECTION_NONE);
1261 add_trace("abbrev", NULL, "%s", abbrev);
1262 add_trace("number", NULL, "%s", phone);
1263 if (name) if (name[0])
1264 add_trace("name", NULL, "%s", name);
1266 SCPY(e_dialinginfo.id, phone);
1267 e_extdialing = e_dialinginfo.id;
1273 /* process dialing 'test'
1275 void EndpointAppPBX::action_dialing_test(void)
1279 struct port_list *portlist = ea_endpoint->ep_portlist;
1280 struct lcr_msg *message;
1282 char testcode[32] = "";
1283 struct route_param *rparam;
1285 /* given testcode */
1286 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1287 SCPY(testcode, rparam->string_value);
1288 SCAT(testcode, e_extdialing);
1293 trace_header("ACTION test", DIRECTION_NONE);
1294 add_trace("test", NULL, "proceeding");
1296 new_state(EPOINT_STATE_IN_PROCEEDING);
1297 set_tone(portlist, "proceeding");
1298 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
1299 message_put(message);
1300 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1304 trace_header("ACTION test", DIRECTION_NONE);
1305 add_trace("test", NULL, "alerting");
1307 new_state(EPOINT_STATE_IN_ALERTING);
1308 set_tone(portlist, "ringpbx");
1309 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
1310 message_put(message);
1311 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1315 trace_header("ACTION test", DIRECTION_NONE);
1316 add_trace("test", NULL, "echo");
1318 new_state(EPOINT_STATE_CONNECT);
1319 if (e_ext.number[0])
1321 set_tone(portlist, NULL);
1322 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1323 SCPY(e_connectinfo.id, e_callerinfo.id);
1324 SCPY(e_connectinfo.extension, e_callerinfo.extension);
1325 e_connectinfo.itype = e_callerinfo.itype;
1326 e_connectinfo.ntype = e_callerinfo.ntype;
1327 e_connectinfo.present = e_callerinfo.present;
1328 e_connectinfo.screen = e_callerinfo.screen;
1329 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1330 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(struct connect_info));
1331 /* handle restricted caller ids */
1332 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);
1333 /* display callerid if desired for extension */
1334 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));
1335 message_put(message);
1336 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1338 port = find_port_id(portlist->port_id);
1341 port->set_echotest(1);
1346 trace_header("ACTION test", DIRECTION_NONE);
1347 add_trace("test", NULL, "tone");
1349 new_state(EPOINT_STATE_CONNECT);
1350 if (e_ext.number[0])
1352 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1353 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1354 message_put(message);
1355 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1356 set_tone(portlist, "test");
1360 trace_header("ACTION test", DIRECTION_NONE);
1361 add_trace("test", NULL, "hold music");
1363 new_state(EPOINT_STATE_CONNECT);
1364 if (e_ext.number[0])
1366 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1367 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1368 message_put(message);
1369 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1370 set_tone(portlist, "hold");
1374 if (strlen(testcode) < 4)
1377 cause = atoi(testcode+1);
1380 trace_header("ACTION test", DIRECTION_NONE);
1381 add_trace("test", NULL, "announcement");
1382 add_trace("cause", NULL, "%d", cause);
1384 new_state(EPOINT_STATE_CONNECT);
1385 if (e_ext.number[0])
1387 SPRINT(causestr,"cause_%02x",cause);
1388 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1389 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1390 message_put(message);
1391 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1392 set_tone(portlist, causestr);
1396 if (strlen(testcode) < 4)
1399 cause = atoi(testcode+1);
1402 trace_header("ACTION test", DIRECTION_NONE);
1403 add_trace("test", NULL, "disconnect");
1404 add_trace("cause", NULL, "%d", cause);
1406 new_state(EPOINT_STATE_OUT_DISCONNECT);
1407 SPRINT(causestr,"cause_%02x",cause);
1408 message_disconnect_port(portlist, cause, LOCATION_PRIVATE_LOCAL, "");
1409 set_tone(portlist, causestr);
1412 case '8': /* release */
1413 trace_header("ACTION test", DIRECTION_NONE);
1414 add_trace("test", NULL, "release");
1415 add_trace("cause", NULL, "16");
1417 new_state(EPOINT_STATE_OUT_DISCONNECT);
1418 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
1419 set_tone(portlist, "release");
1422 case '9': /* text callerid test */
1423 trace_header("ACTION test", DIRECTION_NONE);
1424 add_trace("test", NULL, "callerid");
1426 new_state(EPOINT_STATE_CONNECT);
1427 if (e_ext.number[0])
1429 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1430 SCPY(e_connectinfo.id, "12345678");
1431 SCPY(e_connectinfo.name, "Welcome to LCR");
1432 SCPY(e_connectinfo.display, "Welcome to LCR");
1433 e_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1434 e_connectinfo.present = INFO_PRESENT_ALLOWED;
1435 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1436 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(message->param.connectinfo));
1437 message_put(message);
1438 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1439 set_tone(portlist, "hold");
1445 /* process init play
1447 void EndpointAppPBX::action_init_play(void)
1449 struct route_param *rparam;
1450 struct port_list *portlist = ea_endpoint->ep_portlist;
1452 /* check given sample */
1453 if (!(rparam = routeparam(e_action, PARAM_SAMPLE)))
1455 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1459 new_state(EPOINT_STATE_OUT_DISCONNECT);
1460 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
1461 set_tone(portlist, "cause_3f");
1466 /* if sample is given */
1467 if (rparam->string_value[0] == '\0')
1469 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1474 if (e_ext.number[0])
1477 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1482 * action_*_vbox_play is implemented in "action_vbox.cpp"
1487 * process dialing of calculator
1489 void EndpointAppPBX::action_dialing_calculator(void)
1491 struct port_list *portlist = ea_endpoint->ep_portlist;
1492 struct lcr_msg *message;
1493 double value1, value2, v, sign1;
1494 int komma1, komma2, k, state, mode, first;
1497 portlist = ea_endpoint->ep_portlist;
1499 /* remove error message */
1500 if (!strncmp(e_extdialing, "Error", 5))
1502 UCPY(e_extdialing, e_extdialing+5);
1504 if (!strncmp(e_extdialing, "inf", 3))
1506 UCPY(e_extdialing, e_extdialing+3);
1508 if (!strncmp(e_extdialing, "-inf", 4))
1510 UCPY(e_extdialing, e_extdialing+4);
1513 /* process dialing */
1526 if (*p>='0' && *p<='9')
1534 if ((p[-1]<'0' || p[-1]>'0') && p[-1]!='.')
1543 case 0: /* first number */
1546 value1 = value1*10 + (*p-'0');
1556 case 1: /* second number */
1559 value2 = value2*10 + (*p-'0');
1576 UCPY(e_extdialing, "Error");
1579 /* if there is a multiplication, we change to / */
1588 /* if there is a division, we change to + */
1597 /* if there is a addition, we change to - */
1606 /* if there is a substraction and a comma, we change to * */
1607 if (p[-1]=='-' && komma1)
1615 /* if there is a substraction and no comma and the first or second value, we change to , */
1624 /* if there is a komma and we are at the first value, we change to * */
1625 if (p[-1]=='.' && state==0)
1634 /* if there is a komma and we are at the second value, we display error */
1635 if (komma2 && state==1)
1637 UCPY(e_extdialing, "Error");
1640 /* if we are at state 1, we write a comma */
1647 /* we assume multiplication */
1654 /* if just a number is displayed, the input is cleared */
1657 *e_extdialing = '\0';
1660 /* calculate the result */
1663 case 0: /* multiply */
1664 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1*value2);
1666 case 1: /* divide */
1667 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1/value2);
1670 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1+value2);
1672 case 3: /* substract */
1673 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1-value2);
1676 e_dialinginfo.id[sizeof(e_dialinginfo.id)-1] = '\0';
1677 if (strchr(e_extdialing, '.')) /* remove zeroes */
1679 while (e_extdialing[strlen(e_extdialing)-1] == '0')
1680 e_extdialing[strlen(e_extdialing)-1] = '\0';
1681 if (e_extdialing[strlen(e_extdialing)-1] == '.')
1682 e_extdialing[strlen(e_extdialing)-1] = '\0'; /* and remove dot */
1684 p = strchr(e_extdialing,'\0')-1;
1717 UCPY(e_extdialing, "Error");
1726 /* display dialing */
1727 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1728 SPRINT(message->param.notifyinfo.display, ">%s", e_extdialing);
1729 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);
1730 message_put(message);
1731 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1736 * process dialing of timer
1738 void EndpointAppPBX::action_dialing_timer(void)
1744 * process 'goto' or 'menu'
1746 void EndpointAppPBX::_action_goto_menu(int mode)
1748 struct port_list *portlist = ea_endpoint->ep_portlist;
1749 struct route_param *rparam;
1751 /* check given ruleset */
1752 if (!(rparam = routeparam(e_action, PARAM_RULESET)))
1755 trace_header("ACTION goto/menu (no ruleset given)", DIRECTION_NONE);
1759 new_state(EPOINT_STATE_OUT_DISCONNECT);
1760 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1761 set_tone(portlist, "cause_3f");
1765 if (rparam->string_value[0] == '\0')
1767 e_ruleset = getrulesetbyname(rparam->string_value);
1770 trace_header("ACTION goto/menu (ruleset not found)", DIRECTION_NONE);
1771 add_trace("ruleset", NULL, "%s", rparam->string_value);
1776 /* if the 'menu' was selected, we will flush all digits */
1779 e_dialinginfo.id[0] = 0;
1780 e_extdialing = e_dialinginfo.id;
1783 /* remove digits that are required to match the rule */
1784 if ((rparam = routeparam(e_action, PARAM_STRIP)))
1787 SCPY(e_dialinginfo.id, e_extdialing);
1788 e_extdialing = e_dialinginfo.id;
1793 trace_header("ACTION goto/menu (change to)", DIRECTION_NONE);
1794 add_trace("ruleset", NULL, "%s", e_ruleset->name);
1795 if (e_dialinginfo.id[0])
1797 add_trace("dialing", NULL, "%s", e_dialinginfo.id);
1799 if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
1801 add_trace("sample", NULL, "%s", rparam->string_value);
1803 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1809 /* do dialing with new ruleset */
1814 /* process dialing goto
1816 void EndpointAppPBX::action_dialing_goto(void)
1818 _action_goto_menu(0);
1821 /* process dialing menu
1823 void EndpointAppPBX::action_dialing_menu(void)
1825 _action_goto_menu(1);
1830 * process dialing disconnect
1832 void EndpointAppPBX::action_dialing_disconnect(void)
1834 struct route_param *rparam;
1835 struct port_list *portlist = ea_endpoint->ep_portlist;
1836 struct lcr_msg *message;
1837 int cause = CAUSE_NORMAL; /* normal call clearing */
1838 int location = LOCATION_PRIVATE_LOCAL;
1839 char cause_string[256] = "", display[84] = "";
1841 /* check cause parameter */
1842 if ((rparam = routeparam(e_action, PARAM_CAUSE)))
1844 cause = rparam->integer_value;
1845 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1847 if ((rparam = routeparam(e_action, PARAM_LOCATION)))
1849 location = rparam->integer_value;
1850 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1854 /* use cause as sample, if not given later */
1855 SPRINT(cause_string, "cause_%02x", cause);
1857 /* check sample parameter */
1858 if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
1860 SCPY(cause_string, rparam->string_value);
1861 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'sample' is given: %s\n", ea_endpoint->ep_serial, cause_string);
1865 if ((rparam = routeparam(e_action, PARAM_DISPLAY)))
1867 SCPY(display, rparam->string_value);
1868 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1871 /* disconnect only if connect parameter is not given */
1872 trace_header("ACTION disconnect", DIRECTION_NONE);
1873 add_trace("cause", "value", "%d", cause);
1874 add_trace("cause", "location", "%d", location);
1875 if (cause_string[0])
1876 add_trace("sample", NULL, "%s", cause_string);
1878 add_trace("display", NULL, "%s", display);
1880 new_state(EPOINT_STATE_OUT_DISCONNECT);
1881 set_tone(portlist, cause_string);
1882 if (!(rparam = routeparam(e_action, PARAM_CONNECT)))
1884 message_disconnect_port(portlist, cause, location, display);
1887 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1888 SCPY(message->param.notifyinfo.display, display);
1889 message_put(message);
1890 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1897 * process dialing help
1899 void EndpointAppPBX::action_dialing_help(void)
1901 /* show all things that would match */
1903 struct numbering *numbering = numbering_int;
1904 char dialing[sizeof(e_dialinginfo.id)];
1906 struct lcr_msg *message;
1907 struct route_param *rparam;
1909 /* in case we have no menu (this should never happen) */
1914 if (strchr(e_dialinginfo.id,'*'))
1917 e_dialinginfo.id[0] = '\0';
1919 if (strchr(e_dialinginfo.id,'#'))
1922 e_dialinginfo.id[0] = '\0';
1925 /* get position in menu */
1928 /* get last menu position */
1930 while(numbering->next)
1933 numbering = numbering->next;
1937 /* get menu position */
1941 numbering = numbering->next;
1945 numbering = numbering_int;
1952 /* if we dial something else we need to add the prefix and change the action */
1953 if (e_dialinginfo.id[0])
1955 e_action = NUMB_ACTION_NONE;
1956 SCPY(dialing, numbering->prefix);
1957 //we ignore the first digit after selecting
1958 //SCAT(dialing, e_dialinginfo.id);
1959 SCPY(e_dialinginfo.id, dialing);
1960 e_extdialing = e_dialinginfo.id+strlen(numbering->prefix);
1961 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);
1967 /* send display message to port */
1968 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1969 SPRINT(message->param.notifyinfo.display, ">%s %s%s%s", numbering->prefix, numb_actions[numbering->action], (numbering->param[0])?" ":"", numbering->param);
1970 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);
1971 message_put(message);
1972 logmessage(message->type, message->paramea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1978 * process dialing deflect
1980 void EndpointAppPBX::action_dialing_deflect(void)
1986 * process dialing setforward
1988 void EndpointAppPBX::action_dialing_setforward(void)
1994 * process hangup 'execute'
1996 void EndpointAppPBX::action_hangup_execute(void)
1998 struct route_param *rparam;
2000 char *command = "", isdn_port[10];
2001 char *argv[11]; /* check also number of args below */
2004 /* get script / command */
2005 if ((rparam = routeparam(e_action, PARAM_EXECUTE)))
2006 command = rparam->string_value;
2007 if (command[0] == '\0')
2009 trace_header("ACTION execute (no parameter given)", DIRECTION_NONE);
2013 argv[i++] = "/bin/sh";
2015 argv[i++] = command;
2016 argv[i++] = command;
2017 if ((rparam = routeparam(e_action, PARAM_PARAM)))
2019 argv[i++] = rparam->string_value;
2021 argv[i++] = e_extdialing;
2022 argv[i++] = numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international);
2023 argv[i++] = e_callerinfo.extension;
2024 argv[i++] = e_callerinfo.name;
2025 SPRINT(isdn_port, "%d", e_callerinfo.isdn_port);
2026 argv[i++] = isdn_port;
2027 argv[i++] = NULL; /* check also number of args above */
2028 switch (pid = fork ()) {
2030 trace_header("ACTION execute (fork failed)", DIRECTION_NONE);
2034 execve("/bin/sh", argv, environ);
2037 trace_header("ACTION execute", DIRECTION_NONE);
2038 add_trace("command", NULL, "%s", command);
2046 * process hangup 'file'
2048 void EndpointAppPBX::action_hangup_file(void)
2050 struct route_param *rparam;
2051 char *file, *content, *mode;
2054 /* get file / content */
2055 if (!(rparam = routeparam(e_action, PARAM_FILE)))
2056 file = rparam->string_value;
2059 if (!(rparam = routeparam(e_action, PARAM_CONTENT)))
2060 content = rparam->string_value;
2062 content = e_extdialing;
2063 if (!(rparam = routeparam(e_action, PARAM_APPEND)))
2067 if (file[0] == '\0')
2069 trace_header("ACTION file (no filename given)", DIRECTION_NONE);
2073 if (!(fp = fopen(file, mode)))
2075 trace_header("ACTION file (failed to open)", DIRECTION_NONE);
2076 add_trace("file", "name", "%s", file);
2077 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2081 trace_header("ACTION file", DIRECTION_NONE);
2082 add_trace("file", "name", "%s", file);
2083 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2084 add_trace("content", NULL, "%s", content);
2086 fprintf(fp, "%s\n", content);
2092 * process init 'pick'
2094 void EndpointAppPBX::action_init_pick(void)
2096 struct route_param *rparam;
2097 char *extensions = NULL;
2099 if ((rparam = routeparam(e_action, PARAM_EXTENSIONS)))
2100 extensions = rparam->string_value;
2102 trace_header("ACTION pick", DIRECTION_NONE);
2103 if (extensions) if (extensions[0])
2104 add_trace("extensions", NULL, "%s", extensions);
2106 pick_join(extensions);
2111 * process dialing 'password'
2113 void EndpointAppPBX::action_dialing_password(void)
2115 struct port_list *portlist = ea_endpoint->ep_portlist;
2117 /* prompt for password */
2118 if (e_extdialing[0] == '\0')
2120 /* give password tone */
2121 set_tone(portlist, "password");
2123 if (e_extdialing[1] == '\0')
2125 /* give password tone */
2126 set_tone(portlist, "dialing");
2129 /* wait until all digits are dialed */
2130 if (strlen(e_ext.password) != strlen(e_extdialing))
2131 return; /* more digits needed */
2133 /* check the password */
2134 if (e_ext.password[0]=='\0' || (strlen(e_ext.password)==strlen(e_extdialing) && !!strcmp(e_ext.password,e_extdialing)))
2136 trace_header("ACTION password_write (wrong password)", DIRECTION_NONE);
2137 add_trace("dialed", NULL, "%s", e_extdialing);
2139 e_connectedmode = 0;
2141 new_state(EPOINT_STATE_OUT_DISCONNECT);
2142 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2143 set_tone(portlist, "cause_10");
2147 /* write caller id if ACTION_PASSWORD_WRITE was selected */
2149 if (e_action->index == ACTION_PASSWORD_WRITE)
2151 append_callbackauth(e_ext.number, &e_callbackinfo);
2152 trace_header("ACTION password_write (written)", DIRECTION_NONE);
2153 add_trace("dialed", NULL, "%s", e_extdialing);
2157 /* make call state */
2158 new_state(EPOINT_STATE_IN_OVERLAP);
2159 e_ruleset = ruleset_main;
2161 e_rule = e_ruleset->rule_first;
2163 e_dialinginfo.id[0] = '\0';
2164 e_extdialing = e_dialinginfo.id;
2165 set_tone(portlist, "dialpbx");
2168 void EndpointAppPBX::action_dialing_password_wr(void)
2170 action_dialing_password();
2174 /* general process dialing of incoming call
2175 * depending on the detected prefix, subfunctions above (action_*) will be
2178 void EndpointAppPBX::process_dialing(void)
2180 struct port_list *portlist = ea_endpoint->ep_portlist;
2181 struct lcr_msg *message;
2182 struct route_param *rparam;
2184 //#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.
2185 //PDEBUG(~0, "HANG-BUG-DEBUGGING: entered porcess_dialing\n");
2186 portlist = ea_endpoint->ep_portlist;
2187 /* check if we have a port instance linked to our epoint */
2191 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);
2192 e_action_timeout = 0;
2193 e_match_timeout = 0;
2198 goto portlist_error;
2201 /* check nesting levels */
2202 if (++e_rule_nesting > RULE_NESTING)
2204 trace_header("ACTION (nesting too deep)", DIRECTION_NONE);
2205 add_trace("max-levels", NULL, "%d", RULE_NESTING);
2207 new_state(EPOINT_STATE_OUT_DISCONNECT);
2208 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2209 set_tone(portlist, "cause_3f");
2210 e_action_timeout = 0;
2211 e_match_timeout = 0;
2215 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before action-timeout processing\n");
2216 /* process timeout */
2217 if (e_action_timeout)
2219 e_action_timeout = 0;
2220 if (e_state == EPOINT_STATE_CONNECT)
2222 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);
2225 if (e_action->index == ACTION_DISCONNECT
2226 || e_state == EPOINT_STATE_OUT_DISCONNECT)
2228 /* release after disconnect */
2229 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
2232 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0);
2233 e_action = e_action->next;
2236 /* nothing more, so we release */
2237 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action timed out, and we have no next action, so we disconnect.\n", ea_endpoint->ep_serial);
2238 new_state(EPOINT_STATE_OUT_DISCONNECT);
2239 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2240 set_tone(portlist, "cause_3f");
2243 goto action_timeout;
2246 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before setup/overlap state checking\n");
2247 if (e_state!=EPOINT_STATE_IN_SETUP
2248 && e_state!=EPOINT_STATE_IN_OVERLAP)
2250 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);
2251 e_match_timeout = 0;
2256 /* check if we do menu selection */
2257 if (e_action==NUMB_ACTION_NONE && (e_dialinginfo.id[0]=='*' || e_dialinginfo.id[0]=='#'))
2258 /* do menu selection */
2259 if (e_ext.display_menu)
2261 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 */
2263 e_dialinginfo.id[0] = '\0';
2264 e_action = NUMB_ACTION_MENU;
2267 e_match_timeout = 0;
2270 /* invalid dialing */
2271 message_disconnect_port(portlist, CAUSE_INCALID, LOCATION_PRIVATE_LOCAL, "");
2272 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
2273 message->param.disconnectinfo.cause = CAUSE_INVALID;
2274 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2277 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2278 SCPY(message->param.notifyinfo.display,get_isdn_cause(LOCATION_PRIVATE_LOCAL, epoint->e_ext.display_cause, param->disconnectinfo.location, param->disconnectinfo.cause));
2280 message_put(message);
2281 logmessage(message->type, message->param, portlist->port_id, DIRECTION_OUT);
2283 new_state(EPOINT_STATE_OUT_DISCONNECT);
2284 set_tone(portlist,"cause_1c");
2285 e_match_timeout = 0;
2290 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before e_action==NULL\n");
2291 /* if no action yet, we will call try to find a matching rule */
2294 /* be sure that all selectors are initialized */
2297 /* check for external call */
2298 if (!strncmp(e_dialinginfo.id, "extern:", 7))
2300 e_extdialing = e_dialinginfo.id+7;
2301 e_action = &action_external;
2302 goto process_action;
2304 /* check for internal call */
2305 if (!strncmp(e_dialinginfo.id, "intern:", 7))
2307 e_extdialing = e_dialinginfo.id+7;
2308 e_action = &action_internal;
2309 goto process_action;
2311 /* check for chan call */
2312 if (!strncmp(e_dialinginfo.id, "remote:", 7))
2314 e_extdialing = e_dialinginfo.id+7;
2315 e_action = &action_remote;
2316 goto process_action;
2318 /* check for vbox call */
2319 if (!strncmp(e_dialinginfo.id, "vbox:", 5))
2321 e_extdialing = e_dialinginfo.id+5;
2322 e_action = &action_vbox;
2323 goto process_action;
2326 if (e_match_timeout && now_d>=e_match_timeout)
2328 /* return timeout rule */
2329 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);
2330 e_match_timeout = 0;
2331 e_action = e_match_to_action;
2332 e_extdialing = e_match_to_extdialing;
2333 trace_header("ROUTING (timeout)", DIRECTION_NONE);
2334 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2335 add_trace("line", NULL, "%d", e_action->line);
2339 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before routing\n");
2340 /* check for matching rule */
2341 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);
2344 e_action = route(e_ruleset);
2347 trace_header("ACTION (match)", DIRECTION_NONE);
2348 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2349 add_trace("line", NULL, "%d", e_action->line);
2354 e_action = &action_disconnect;
2357 trace_header("ACTION (no main ruleset, disconnecting)", DIRECTION_NONE);
2361 //PDEBUG(~0, "HANG-BUG-DEBUGGING: after routing\n");
2365 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): no rule within the current ruleset matches yet.\n", ea_endpoint->ep_serial, e_ext.number);
2370 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): a rule with action '%s' matches.\n", ea_endpoint->ep_serial, action_defs[e_action->index].name);
2375 e_action_timeout = 0;
2376 if (e_action->timeout)
2378 e_action_timeout = now_d + e_action->timeout;
2379 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action has a timeout of %d secods.\n", ea_endpoint->ep_serial, e_action->timeout);
2383 /* check param proceeding / alerting / connect */
2384 if ((rparam = routeparam(e_action, PARAM_CONNECT)))
2386 /* NOTE: we may not change our state to connect, because dialing will then not possible */
2388 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2389 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
2390 message_put(message);
2391 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2393 if ((rparam = routeparam(e_action, PARAM_ALERTING)))
2395 /* NOTE: we may not change our state to alerting, because dialing will then not possible */
2396 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2397 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
2398 message_put(message);
2399 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2401 if ((rparam = routeparam(e_action, PARAM_PROCEEDING)))
2403 /* NOTE: we may not change our state to proceeding, because dialing will then not possible */
2404 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2405 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
2406 message_put(message);
2407 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2410 if (action_defs[e_action->index].init_func)
2412 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);
2413 (this->*(action_defs[e_action->index].init_func))();
2415 if (e_state!=EPOINT_STATE_IN_SETUP
2416 && e_state!=EPOINT_STATE_IN_OVERLAP)
2418 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);
2419 goto display_action;
2423 /* show what we are doing */
2424 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);
2425 /* go to action's dialing function */
2426 if (action_defs[e_action->index].dialing_func)
2428 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);
2429 (this->*(action_defs[e_action->index].dialing_func))();
2432 /* display selected dialing action if enabled and still in setup state */
2436 if (e_action->index==ACTION_MENU
2437 || e_action->index==ACTION_REDIAL
2438 || e_action->index==ACTION_REPLY
2439 || e_action->index==ACTION_TIMER
2440 || e_action->index==ACTION_CALCULATOR
2441 || e_action->index==ACTION_TEST)
2445 if (!e_ext.display_dialing)
2447 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*/)
2448 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 */
2450 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2454 SPRINT(message->param.notifyinfo.display, "> %s", e_dialinginfo.id);
2457 SPRINT(message->param.notifyinfo.display, "%s%s%s", action_defs[e_action->index].name, (e_extdialing[0])?" ":"", e_extdialing);
2460 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s'\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
2461 message_put(message);
2462 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2471 /* some services store information after hangup */
2472 void EndpointAppPBX::process_hangup(int cause, int location)
2474 char callertext[256], dialingtext[256];
2475 int writeext = 0, i;
2477 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s'\n", ea_endpoint->ep_serial, e_ext.number);
2478 if (e_ext.number[0])
2480 if (read_extension(&e_ext, e_ext.number))
2490 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);
2491 switch(e_dialinginfo.itype)
2493 case INFO_ITYPE_CHAN:
2494 SPRINT(dialingtext, "chan:%s", e_dialinginfo.id);
2496 case INFO_ITYPE_ISDN_EXTENSION:
2497 SPRINT(dialingtext, "intern:%s", e_dialinginfo.id);
2499 case INFO_ITYPE_VBOX:
2500 SPRINT(dialingtext, "vbox:%s", e_dialinginfo.id);
2503 SPRINT(dialingtext, "%s", e_dialinginfo.id);
2506 if (e_callerinfo.id[0])
2507 SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2509 SPRINT(callertext, "unknown");
2510 /* allpy restriction */
2511 if (!e_ext.anon_ignore && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
2512 SPRINT(callertext, "anonymous");
2513 if (e_callerinfo.extension[0]) /* add intern if present */
2514 UNPRINT(strchr(callertext,'\0'), sizeof(callertext)-1+strlen(callertext), " (intern %s)", e_callerinfo.extension);
2515 write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location);
2517 /* store last received call for reply-list */
2518 if (e_origin == 1) // outgoing to phone is incoming for user
2519 if (e_callerinfo.id[0] || e_callerinfo.extension[0])
2520 if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED)
2522 if (e_callerinfo.extension[0])
2523 SPRINT(callertext, "intern:%s", e_callerinfo.extension);
2525 SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2526 if (!!strcmp(callertext, e_ext.last_in[0]))
2531 UCPY(e_ext.last_in[i], e_ext.last_in[i-1]);
2534 SCPY(e_ext.last_in[0], callertext);
2535 writeext |= 1; /* store extension later */
2536 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]);
2538 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);
2541 /* store last made call for reply-list */
2542 if (e_origin == 0) // incoming from phone is outgoing for user
2543 if (e_dialinginfo.id[0])
2545 if (!!strcmp(e_dialinginfo.id, e_ext.last_out[0]))
2550 UCPY(e_ext.last_out[i], e_ext.last_out[i-1]);
2553 SCPY(e_ext.last_out[0], e_dialinginfo.id);
2554 writeext |= 1; /* store extension later */
2555 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
2557 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);
2560 /* write extension if needed */
2561 if (writeext == 0x11)
2562 write_extension(&e_ext, e_ext.number);
2566 if (action_defs[e_action->index].hangup_func)
2568 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);
2569 (this->*(action_defs[e_action->index].hangup_func))();