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) {
28 if (options.deb & DEBUG_EPOINT)
29 PERROR("EPOINT(%d): We already have a call instance, this should never happen!\n", ea_endpoint->ep_serial);
34 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
38 if (admin->remote_name[0] && !strcmp(admin->remote_name, remote))
43 /* resource not available */
44 trace_header("ACTION remote (not available)", DIRECTION_NONE);
45 add_trace("application", NULL, "%s", remote);
47 message_disconnect_port(portlist, CAUSE_OUTOFORDER, LOCATION_PRIVATE_LOCAL, "");
48 new_state(EPOINT_STATE_OUT_DISCONNECT);
49 set_tone(portlist,"cause_1b");
52 join = new JoinRemote(ea_endpoint->ep_serial, remote, admin->sock);
55 join = new JoinPBX(ea_endpoint);
57 FATAL("No memoy for Join instance.\n");
58 ea_endpoint->ep_join_id = join->j_serial;
61 void EndpointAppPBX::action_init_call(void)
63 _action_init_call(NULL);
65 void EndpointAppPBX::action_init_remote(void)
70 * process dialing 'internal'
72 void EndpointAppPBX::action_dialing_internal(void)
74 struct capa_info capainfo;
75 struct caller_info callerinfo;
76 struct redir_info redirinfo;
77 struct dialing_info dialinginfo;
78 struct port_list *portlist = ea_endpoint->ep_portlist;
79 struct lcr_msg *message;
81 struct route_param *rparam;
83 /* send proceeding, because number is complete */
84 set_tone(portlist, "proceeding");
85 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
87 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
88 new_state(EPOINT_STATE_IN_PROCEEDING);
90 /* create bearer/caller/dialinginfo */
91 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
92 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
93 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
94 memset(&dialinginfo, 0, sizeof(dialinginfo));
95 dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
96 SCPY(dialinginfo.id, e_dialinginfo.id);
98 /* process extension */
99 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
100 SCPY(dialinginfo.id, rparam->string_value);
102 /* process number type */
103 if ((rparam = routeparam(e_action, PARAM_TYPE)))
104 dialinginfo.ntype = rparam->integer_value;
106 /* process service */
107 if ((rparam = routeparam(e_action, PARAM_CAPA))) {
108 capainfo.bearer_capa = rparam->integer_value;
109 if (capainfo.bearer_capa != INFO_BC_SPEECH
110 && capainfo.bearer_capa != INFO_BC_AUDIO) {
111 capainfo.bearer_mode = INFO_BMODE_PACKET;
113 capainfo.bearer_info1 = INFO_INFO1_NONE;
114 capainfo.hlc = INFO_HLC_NONE;
115 capainfo.exthlc = INFO_HLC_NONE;
117 if ((rparam = routeparam(e_action, PARAM_BMODE))) {
118 capainfo.bearer_mode = rparam->integer_value;
120 if ((rparam = routeparam(e_action, PARAM_INFO1))) {
121 capainfo.bearer_info1 = rparam->integer_value;
123 if ((rparam = routeparam(e_action, PARAM_HLC))) {
124 capainfo.hlc = rparam->integer_value;
126 if ((rparam = routeparam(e_action, PARAM_EXTHLC))) {
127 capainfo.exthlc = rparam->integer_value;
130 /* process presentation */
131 if ((rparam = routeparam(e_action, PARAM_PRESENT))) {
132 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
135 /* check if extension exists AND only if not multiple extensions */
136 if (!strchr(dialinginfo.id,',') && !read_extension(&ext, dialinginfo.id)) {
137 trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE);
138 add_trace("extension", NULL, dialinginfo.id);
140 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
141 new_state(EPOINT_STATE_OUT_DISCONNECT);
142 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
143 set_tone(portlist, "cause_86");
146 /* check if internal calls are denied */
147 if (e_ext.rights < 1) {
148 trace_header("ACTION extension (dialing to extension denied)", DIRECTION_NONE);
149 add_trace("extension", NULL, dialinginfo.id);
151 new_state(EPOINT_STATE_OUT_DISCONNECT);
152 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
153 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
154 set_tone(portlist, "cause_81");
158 /* add or update internal call */
159 trace_header("ACTION extension (calling)", DIRECTION_NONE);
160 add_trace("extension", NULL, dialinginfo.id);
162 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
163 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
164 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
165 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
166 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
167 message_put(message);
170 /* process dialing external
172 void EndpointAppPBX::action_dialing_external(void)
174 struct capa_info capainfo;
175 struct caller_info callerinfo;
176 struct redir_info redirinfo;
177 struct dialing_info dialinginfo;
179 struct port_list *portlist = ea_endpoint->ep_portlist;
180 struct lcr_msg *message;
181 struct route_param *rparam;
183 /* special processing of delete characters '*' and '#' */
184 if (e_ext.delete_ext) {
185 /* dialing a # causes a clearing of complete number */
186 if (strchr(e_extdialing, '#')) {
187 e_extdialing[0] = '\0';
188 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);
190 /* eliminate digits before '*', which is a delete digit
192 if (strchr(e_extdialing, '*')) {
194 while((p=strchr(e_extdialing, '*'))) {
195 if (p > e_extdialing) { /* only if there is a digit in front */
199 UCPY(p, p+1); /* remove '*' */
201 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s deleted digits and got new string: %s\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing);
205 /* create bearer/caller/dialinginfo */
206 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
207 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
208 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
209 memset(&dialinginfo, 0, sizeof(dialinginfo));
210 dialinginfo.itype = INFO_ITYPE_ISDN;
211 // dialinginfo.sending_complete = 0;
212 SCPY(dialinginfo.id, e_extdialing);
215 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
216 SPRINT(dialinginfo.id, "%s%s", rparam->string_value, e_extdialing);
219 if ((rparam = routeparam(e_action, PARAM_KEYPAD))) {
220 SCPY(dialinginfo.keypad, dialinginfo.id);
221 dialinginfo.id[0] = '\0';
224 /* process number complete */
225 if ((rparam = routeparam(e_action, PARAM_COMPLETE)))
226 dialinginfo.sending_complete = 1;
228 /* process number type */
229 if ((rparam = routeparam(e_action, PARAM_TYPE)))
230 dialinginfo.ntype = rparam->integer_value;
232 /* process service */
233 if ((rparam = routeparam(e_action, PARAM_CAPA))) {
234 capainfo.bearer_capa = rparam->integer_value;
235 if (capainfo.bearer_capa != INFO_BC_SPEECH
236 && capainfo.bearer_capa != INFO_BC_AUDIO) {
237 capainfo.bearer_mode = INFO_BMODE_PACKET;
239 capainfo.bearer_info1 = INFO_INFO1_NONE;
240 capainfo.hlc = INFO_HLC_NONE;
241 capainfo.exthlc = INFO_HLC_NONE;
243 if ((rparam = routeparam(e_action, PARAM_BMODE))) {
244 capainfo.bearer_mode = rparam->integer_value;
246 if ((rparam = routeparam(e_action, PARAM_INFO1))) {
247 capainfo.bearer_info1 = rparam->integer_value;
249 if ((rparam = routeparam(e_action, PARAM_HLC))) {
250 capainfo.hlc = rparam->integer_value;
252 if ((rparam = routeparam(e_action, PARAM_EXTHLC))) {
253 capainfo.exthlc = rparam->integer_value;
257 /* process callerid */
258 if ((rparam = routeparam(e_action, PARAM_CALLERID))) {
259 SCPY(callerinfo.id, rparam->string_value);
261 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE))) {
262 callerinfo.ntype = rparam->integer_value;
265 /* process presentation */
266 if ((rparam = routeparam(e_action, PARAM_PRESENT))) {
267 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
270 /* process interfaces */
271 if ((rparam = routeparam(e_action, PARAM_INTERFACES)))
272 SCPY(dialinginfo.interfaces, rparam->string_value);
274 /* check if local calls are denied */
275 if (e_ext.rights < 2) {
276 trace_header("ACTION extern (calling denied)", DIRECTION_NONE);
278 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
279 set_tone(portlist, "cause_82");
281 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
282 new_state(EPOINT_STATE_OUT_DISCONNECT);
286 if (!strncmp(dialinginfo.id, options.national, strlen(options.national))
287 || dialinginfo.ntype == INFO_NTYPE_NATIONAL
288 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL) {
289 /* check if national calls are denied */
290 if (e_ext.rights < 3) {
291 trace_header("ACTION extern (national calls denied)", DIRECTION_NONE);
293 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
294 set_tone(portlist, "cause_83");
299 if (!strncmp(dialinginfo.id, options.international, strlen(options.international))
300 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL) {
301 /* check if international calls are denied */
302 if (e_ext.rights < 4) {
303 trace_header("ACTION extern (international calls denied)", DIRECTION_NONE);
305 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
306 set_tone(portlist, "cause_84");
311 /* add or update outgoing call */
312 trace_header("ACTION extern (calling)", DIRECTION_NONE);
313 add_trace("number", NULL, dialinginfo.id);
314 if (dialinginfo.sending_complete)
315 add_trace("number", "complete", "yes");
316 if (dialinginfo.interfaces[0])
317 add_trace("interfaces", NULL, dialinginfo.interfaces);
319 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
320 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
321 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
322 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
323 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
324 message_put(message);
328 void EndpointAppPBX::action_dialing_remote(void)
330 struct route_param *rparam;
331 struct port_list *portlist = ea_endpoint->ep_portlist;
332 struct lcr_msg *message;
333 struct capa_info capainfo;
334 struct caller_info callerinfo;
335 struct redir_info redirinfo;
336 struct dialing_info dialinginfo;
337 char context[128] = "";
340 if (!ea_endpoint->ep_join_id) {
341 /* no join yet, sending setup */
342 if (!(rparam = routeparam(e_action, PARAM_APPLICATION))) {
343 trace_header("ACTION remote (no application given)", DIRECTION_NONE);
345 new_state(EPOINT_STATE_OUT_DISCONNECT);
346 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
347 set_tone(portlist, "cause_3f");
350 SCPY(remote, rparam->string_value);
351 if (!_action_init_call(remote))
354 /* create bearer/caller/dialinginfo */
355 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
356 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
357 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
358 memset(&dialinginfo, 0, sizeof(dialinginfo));
360 if ((rparam = routeparam(e_action, PARAM_CONTEXT))) {
361 SCPY(context, rparam->string_value);
363 if ((rparam = routeparam(e_action, PARAM_EXTEN))) {
364 SCPY(dialinginfo.id, rparam->string_value);
365 dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
367 SCPY(dialinginfo.id, e_extdialing);
369 e_extdialing = e_dialinginfo.id + strlen(e_dialinginfo.id);
370 /* send setup to remote */
371 trace_header("ACTION remote (setup)", DIRECTION_NONE);
372 add_trace("number", NULL, dialinginfo.id);
373 add_trace("remote", NULL, remote);
375 add_trace("context", NULL, context);
377 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
378 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
379 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
380 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
381 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
382 SCPY(message->param.setup.context, context);
383 message_put(message);
385 /* send overlap digits */
386 trace_header("ACTION remote (dialing)", DIRECTION_NONE);
387 add_trace("number", NULL, e_extdialing);
389 if (e_extdialing[0]) {
390 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_INFORMATION);
391 memcpy(&message->param.information, &e_dialinginfo, sizeof(struct dialing_info));
392 SCPY(message->param.information.id, e_extdialing);
393 e_extdialing = e_dialinginfo.id + strlen(e_dialinginfo.id);
394 message_put(message);
401 * process dialing the "am" and record
403 void EndpointAppPBX::action_dialing_vbox_record(void)
405 struct dialing_info dialinginfo;
406 struct port_list *portlist = ea_endpoint->ep_portlist;
407 struct lcr_msg *message;
408 struct extension ext;
409 struct route_param *rparam;
411 portlist = ea_endpoint->ep_portlist;
413 /* check for given extension */
414 if (!(rparam = routeparam(e_action, PARAM_EXTENSION))) {
415 trace_header("ACTION vbox-record (no extension given by parameter)", DIRECTION_NONE);
418 new_state(EPOINT_STATE_OUT_DISCONNECT);
419 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
420 set_tone(portlist, "cause_3f");
424 /* check if extension exists */
425 if (!read_extension(&ext, rparam->string_value)) {
426 trace_header("ACTION vbox-record (given extension does not exists)", DIRECTION_NONE);
427 add_trace("extension", NULL, "%s", rparam->string_value);
429 new_state(EPOINT_STATE_OUT_DISCONNECT);
430 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
431 set_tone(portlist, "cause_86");
435 /* check if internal calls are denied */
436 if (e_ext.rights < 1) {
437 trace_header("ACTION vbox-record (internal calls are denied)", DIRECTION_NONE);
439 new_state(EPOINT_STATE_OUT_DISCONNECT);
440 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
441 set_tone(portlist, "cause_81");
445 set_tone(portlist, "proceeding");
446 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
447 message_put(message);
448 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
449 new_state(EPOINT_STATE_IN_PROCEEDING);
451 memset(&dialinginfo, 0, sizeof(dialinginfo));
452 dialinginfo.itype = INFO_ITYPE_VBOX;
453 dialinginfo.sending_complete = 1;
454 SCPY(dialinginfo.id, rparam->string_value);
456 /* append special announcement (if given) */
457 if ((rparam = routeparam(e_action, PARAM_ANNOUNCEMENT)))
458 if (rparam->string_value[0]) {
459 SCAT(dialinginfo.id, ",");
460 SCAT(dialinginfo.id, rparam->string_value);
463 /* add or update internal call */
464 trace_header("ACTION vbox-record (calling)", DIRECTION_NONE);
465 add_trace("extension", NULL, "%s", dialinginfo.id);
467 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
468 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
469 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
470 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
471 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
472 message_put(message);
479 void EndpointAppPBX::action_init_partyline(void)
482 class JoinPBX *joinpbx;
483 struct port_list *portlist = ea_endpoint->ep_portlist;
484 struct lcr_msg *message;
485 struct route_param *rparam;
486 int partyline, jingle = 0;
487 struct join_relation *relation;
489 portlist = ea_endpoint->ep_portlist;
491 /* check for given extension */
492 if (!(rparam = routeparam(e_action, PARAM_ROOM))) {
493 trace_header("ACTION partyline (no room parameter)", DIRECTION_NONE);
496 new_state(EPOINT_STATE_OUT_DISCONNECT);
497 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
498 set_tone(portlist, "cause_3f");
501 if (rparam->integer_value <= 0) {
502 trace_header("ACTION partyline (illegal room parameter)", DIRECTION_NONE);
503 add_trace("room", NULL, "%d", rparam->integer_value);
505 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): invalid value for 'room'.\n", ea_endpoint->ep_serial);
508 partyline = rparam->integer_value;
509 if ((rparam = routeparam(e_action, PARAM_JINGLE)))
512 /* don't create join if partyline exists */
515 if (join->j_type == JOIN_TYPE_PBX) {
516 joinpbx = (class JoinPBX *)join;
517 if (joinpbx->j_partyline == partyline)
524 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
525 if (!(join = new JoinPBX(ea_endpoint)))
526 FATAL("No memory for join object\n");
528 //NOTE: joinpbx must be set here
529 /* add relation to existing join */
530 if (!(relation=joinpbx->add_relation()))
531 FATAL("No memory for join relation\n");
532 relation->type = RELATION_TYPE_SETUP;
533 relation->channel_state = 1;
534 relation->rx_state = NOTIFY_STATE_ACTIVE;
535 relation->tx_state = NOTIFY_STATE_ACTIVE;
536 relation->epoint_id = ea_endpoint->ep_serial;
539 ea_endpoint->ep_join_id = join->j_serial;
541 set_tone(portlist, "proceeding");
542 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
543 message_put(message);
544 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
545 new_state(EPOINT_STATE_IN_PROCEEDING);
547 /* send setup to join */
548 trace_header("ACTION partyline (calling)", DIRECTION_NONE);
549 add_trace("room", NULL, "%d", partyline);
550 add_trace("jingle", NULL, (jingle)?"on":"off");
552 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
553 message->param.setup.partyline = partyline;
554 message->param.setup.partyline_jingle = jingle;
555 memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info));
556 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
557 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
558 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
559 message_put(message);
564 * process hangup of all calls
566 void EndpointAppPBX::action_hangup_call(void)
568 trace_header("ACTION hangup", DIRECTION_NONE);
574 * process dialing 'login'
576 void EndpointAppPBX::action_dialing_login(void)
578 struct port_list *portlist = ea_endpoint->ep_portlist;
579 struct lcr_msg *message;
581 struct route_param *rparam;
583 /* extension parameter */
584 if ((rparam = routeparam(e_action, PARAM_EXTENSION))) {
585 /* extension is given by parameter */
586 extension = rparam->string_value;
587 if (extension[0] == '\0')
589 if (!read_extension(&e_ext, extension)) {
590 trace_header("ACTION login (extension doesn't exist)", DIRECTION_NONE);
591 add_trace("extension", NULL, "%s", extension);
593 /* extension doesn't exist */
594 new_state(EPOINT_STATE_OUT_DISCONNECT);
595 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
596 set_tone(portlist, "cause_86");
600 /* extension must be given by dialstring */
601 extension = e_extdialing;
602 if (extension[0] == '\0')
604 if (!read_extension(&e_ext, extension)) {
605 trace_header("ACTION login (extension incomplete or does not exist)", DIRECTION_NONE);
606 add_trace("extension", NULL, "%s", extension);
612 /* we changed our extension */
613 SCPY(e_ext.number, extension);
614 new_state(EPOINT_STATE_CONNECT);
618 /* send connect with extension's caller id (COLP) */
619 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
620 SCPY(message->param.connectinfo.id, e_ext.callerid);
621 message->param.connectinfo.ntype = e_ext.callerid_type;
622 if (e_ext.callerid_present==INFO_PRESENT_ALLOWED && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
623 message->param.connectinfo.present = INFO_PRESENT_RESTRICTED;
624 else message->param.connectinfo.present = e_ext.callerid_present;
625 /* handle restricted caller ids */
626 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);
627 /* display callerid if desired for extension */
628 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));
629 message->param.connectinfo.ntype = e_ext.callerid_type;
630 message_put(message);
631 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
633 /* set our caller id */
634 SCPY(e_callerinfo.id, e_ext.callerid);
635 e_callerinfo.ntype = e_ext.callerid_type;
636 e_callerinfo.present = e_ext.callerid_present;
638 /* enable connectedmode */
642 if (!(rparam = routeparam(e_action, PARAM_NOPASSWORD))) {
643 /* make call state to enter password */
644 trace_header("ACTION login (ask for password)", DIRECTION_NONE);
645 add_trace("extension", NULL, "%s", e_ext.number);
647 new_state(EPOINT_STATE_IN_OVERLAP);
650 e_action = &action_password;
651 unsched_timer(&e_match_timeout);
652 e_match_to_action = NULL;
653 e_dialinginfo.id[0] = '\0';
654 e_extdialing = strchr(e_dialinginfo.id, '\0');
657 schedule_timer(&e_password_timeout, 20, 0);
662 /* make call state */
663 new_state(EPOINT_STATE_IN_OVERLAP);
664 e_ruleset = ruleset_main;
666 e_rule = e_ruleset->rule_first;
668 e_dialinginfo.id[0] = '\0';
669 e_extdialing = e_dialinginfo.id;
670 set_tone(portlist, "dialpbx");
676 * process init 'change_callerid'
678 void EndpointAppPBX::action_init_change_callerid(void)
680 struct port_list *portlist = ea_endpoint->ep_portlist;
682 if (!e_ext.change_callerid) {
683 /* service not available */
684 trace_header("ACTION change-callerid (denied for this caller)", DIRECTION_NONE);
686 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
687 new_state(EPOINT_STATE_OUT_DISCONNECT);
688 set_tone(portlist,"cause_87");
693 /* process dialing callerid
695 void EndpointAppPBX::_action_callerid_calleridnext(int next)
697 struct port_list *portlist = ea_endpoint->ep_portlist;
698 struct route_param *rparam;
699 char buffer[64], *callerid;
700 char old_id[64] = "", new_id[64] = "";
701 int old_type=0, new_type=0, old_present=0, new_present=0;
703 if ((rparam = routeparam(e_action, PARAM_CALLERID))) {
704 /* the caller ID is given by parameter */
705 callerid = rparam->string_value;
707 /* caller ID is dialed */
708 if (!strchr(e_extdialing, '#')) {
709 /* no complete ID yet */
712 *strchr(e_extdialing, '#') = '\0';
713 callerid = e_extdialing;
716 /* given callerid type */
717 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
718 switch(rparam->integer_value) {
719 case INFO_NTYPE_SUBSCRIBER:
720 SPRINT(buffer, "s%s", callerid);
723 case INFO_NTYPE_NATIONAL:
724 SPRINT(buffer, "n%s", callerid);
727 case INFO_NTYPE_INTERNATIONAL:
728 SPRINT(buffer, "i%s", callerid);
732 SPRINT(buffer, "%s", callerid);
737 /* caller id complete, dialing with new caller id */
738 /* write new parameters */
739 if (read_extension(&e_ext, e_ext.number)) {
740 old_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
741 old_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
742 SCPY(old_id, (!next)?e_ext.callerid:e_ext.id_next_call);
743 if (callerid[0] == '\0') {
745 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
748 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_ALLOWED;
749 if ((rparam = routeparam(e_action, PARAM_PRESENT))) if (rparam->integer_value == 0)
750 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
751 if (e_ext.callerid_type == INFO_NTYPE_UNKNOWN) /* if callerid is unknown, the given id is not nationalized */ {
752 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, callerid);
753 (!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN;
755 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));
757 if (!next) e_ext.id_next_call_type = -1;
758 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);
760 new_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
761 new_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
762 SCPY(new_id, (!next)?e_ext.callerid:e_ext.id_next_call);
763 write_extension(&e_ext, e_ext.number);
766 /* function activated */
768 trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE);
770 trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE);
771 add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type, options.national, options.international));
772 add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
773 add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type, options.national, options.international));
774 add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
776 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
777 new_state(EPOINT_STATE_OUT_DISCONNECT);
778 set_tone(portlist,"activated");
781 /* process dialing callerid for all call
783 void EndpointAppPBX::action_dialing_callerid(void)
785 _action_callerid_calleridnext(0);
788 /* process dialing callerid for next call
790 void EndpointAppPBX::action_dialing_calleridnext(void)
792 _action_callerid_calleridnext(1);
797 * process init 'change_forward'
799 void EndpointAppPBX::action_init_change_forward(void)
801 struct port_list *portlist = ea_endpoint->ep_portlist;
803 if (!e_ext.change_forward) {
804 trace_header("ACTION change-forward (denied for this caller)", DIRECTION_NONE);
806 /* service not available */
807 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
808 new_state(EPOINT_STATE_OUT_DISCONNECT);
809 set_tone(portlist,"cause_87");
814 /* process dialing forwarding
816 void EndpointAppPBX::action_dialing_forward(void)
818 struct port_list *portlist = ea_endpoint->ep_portlist;
819 int diversion = INFO_DIVERSION_CFU;
820 char *dest = e_extdialing;
821 struct route_param *rparam;
823 /* if diversion type is given */
824 if ((rparam = routeparam(e_action, PARAM_DIVERSION)))
825 diversion = rparam->integer_value;
827 if ((rparam = routeparam(e_action, PARAM_DEST))) {
828 /* if destination is given */
829 dest = rparam->string_value;
831 if (!strchr(e_extdialing, '#'))
833 *strchr(e_extdialing, '#') = '\0';
837 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing forwarding to '%s'.\n", ea_endpoint->ep_serial, e_ext.number, dest);
838 if (read_extension(&e_ext, e_ext.number)) {
840 case INFO_DIVERSION_CFU:
841 trace_header("ACTION change-forward (new CFU=unconditional)", DIRECTION_NONE);
842 add_trace("destin'", NULL, "%s", dest);
844 SCPY(e_ext.cfu, dest);
846 case INFO_DIVERSION_CFB:
847 trace_header("ACTION change-forward (new CFB=busy)", DIRECTION_NONE);
848 add_trace("destin'", NULL, "%s", dest);
850 SCPY(e_ext.cfb, dest);
852 case INFO_DIVERSION_CFNR:
853 if ((rparam = routeparam(e_action, PARAM_DELAY)))
854 e_ext.cfnr_delay = rparam->integer_value;
855 trace_header("ACTION change-forward (new CFNR=no response)", DIRECTION_NONE);
856 add_trace("destin'", NULL, "%s", dest);
857 add_trace("delay", NULL, "%s", e_ext.cfnr_delay);
859 SCPY(e_ext.cfnr, dest);
861 case INFO_DIVERSION_CFP:
862 trace_header("ACTION change-forward (new CFP=parallel)", DIRECTION_NONE);
863 add_trace("destin'", NULL, "%s", dest);
865 SCPY(e_ext.cfp, dest);
868 write_extension(&e_ext, e_ext.number);
870 /* function (de)activated */
871 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
872 new_state(EPOINT_STATE_OUT_DISCONNECT);
874 set_tone(portlist,"activated");
876 set_tone(portlist,"deactivated");
880 /* process dialing redial
882 void EndpointAppPBX::action_init_redial_reply(void)
884 struct port_list *portlist = ea_endpoint->ep_portlist;
887 if (!e_ext.last_out[0]) {
888 trace_header("ACTION redial/reply (no last number stored)", DIRECTION_NONE);
890 new_state(EPOINT_STATE_OUT_DISCONNECT);
891 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
892 set_tone(portlist, "cause_3f");
897 /* process dialing redial
899 void EndpointAppPBX::_action_redial_reply(int in)
901 struct lcr_msg *message;
903 struct route_param *rparam;
905 last = (in)?e_ext.last_in[0]:e_ext.last_out[0];
907 /* if no display is available */
908 if (!e_ext.display_menu)
910 if (ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_IN && ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_OUT)
913 /* if select is not given */
914 if (!(rparam = routeparam(e_action, PARAM_SELECT)))
918 if (e_extdialing[0]=='*' || e_extdialing[0]=='1') {
919 /* find prev entry */
925 if (e_extdialing[0]=='#' || e_extdialing[0]=='3') {
926 /* find next entry */
928 if (e_select >= MAX_REMEMBER) {
931 if (e_ext.last_in[e_select][0] == '\0')
934 if (e_ext.last_out[e_select][0] == '\0')
939 last = (in)?e_ext.last_in[e_select]:e_ext.last_out[e_select];
940 if (e_extdialing[0]=='0' || e_extdialing[0]=='2') {
943 trace_header("ACTION reply (dialing)", DIRECTION_NONE);
945 trace_header("ACTION redial (dialing)", DIRECTION_NONE);
946 add_trace("number", NULL, "%s", last);
947 add_trace("last but", NULL, "%d", e_select);
949 SCPY(e_dialinginfo.id, last);
950 e_extdialing = e_dialinginfo.id;
955 e_extdialing[0] = '\0';
957 /* send display message to port */
958 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
959 if (!strncmp(last, "extern:", 7))
960 SPRINT(message->param.notifyinfo.display, "(%d) %s ext", e_select+1, last+7);
962 if (!strncmp(last, "intern:", 7))
963 SPRINT(message->param.notifyinfo.display, "(%d) %s int", e_select+1, last+7);
965 if (!strncmp(last, "chan:", 4))
966 SPRINT(message->param.notifyinfo.display, "(%d) %s chan", e_select+1, last+5);
968 if (!strncmp(last, "vbox:", 5))
969 SPRINT(message->param.notifyinfo.display, "(%d) %s vbox", e_select+1, last+5);
971 SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -");
972 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
973 message_put(message);
974 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
977 /* process dialing redial
979 void EndpointAppPBX::action_dialing_redial(void)
981 _action_redial_reply(0);
984 /* process dialing reply
986 void EndpointAppPBX::action_dialing_reply(void)
988 _action_redial_reply(1);
992 /* dialing powerdialing delay
994 void EndpointAppPBX::action_dialing_powerdial(void)
996 struct port_list *portlist = ea_endpoint->ep_portlist;
997 struct lcr_msg *message;
998 struct route_param *rparam;
1000 /* power dialing only possible if we have a last dialed number */
1001 if (!e_ext.last_out[0]) {
1002 trace_header("ACTION powerdial (no last number stored)", DIRECTION_NONE);
1004 new_state(EPOINT_STATE_OUT_DISCONNECT);
1005 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1006 set_tone(portlist, "cause_3f");
1011 if ((rparam = routeparam(e_action, PARAM_LIMIT))) {
1012 e_powerlimit = rparam->integer_value;
1018 if ((rparam = routeparam(e_action, PARAM_DELAY))) {
1019 e_powerdelay = rparam->integer_value;
1021 /* delay incomplete */
1022 if (!strchr(e_extdialing, '#'))
1024 *strchr(e_extdialing, '#') = '\0';
1025 e_powerdelay = e_extdialing[0]?atoi(e_extdialing): 0;
1028 if (e_powerdelay < 1)
1030 trace_header("ACTION powerdial (dialing)", DIRECTION_NONE);
1031 add_trace("number", NULL, "%s", e_ext.last_out[0]);
1032 add_trace("delay", NULL, "%d", e_powerdelay);
1035 /* send connect to avoid overlap timeout */
1036 // new_state(EPOINT_STATE_CONNECT); connect may prevent further dialing
1037 if (e_ext.number[0])
1039 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1040 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1041 message_put(message);
1042 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1045 SCPY(e_dialinginfo.id, e_ext.last_out[0]);
1046 e_powerdial_on = 1; /* indicates the existence of powerdialing but no redial time given */
1055 void EndpointAppPBX::action_dialing_callback(void)
1057 struct port_list *portlist = ea_endpoint->ep_portlist;
1058 struct route_param *rparam;
1059 struct extension cbext;
1061 portlist = ea_endpoint->ep_portlist;
1063 /* check given extension */
1064 if (!(rparam = routeparam(e_action, PARAM_EXTENSION))) {
1066 trace_header("ACTION callback (no extension defined)", DIRECTION_NONE);
1070 new_state(EPOINT_STATE_OUT_DISCONNECT);
1071 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1072 set_tone(portlist, "cause_3f");
1074 e_cbcaller[0] = e_cbdialing[0] = '\0';
1078 /* if extension is given */
1079 SCPY(e_cbcaller, rparam->string_value);
1080 if (e_cbcaller[0] == '\0')
1083 /* read callback extension */
1084 memset(&cbext, 0, sizeof(cbext));
1085 if (!read_extension(&cbext, e_cbcaller)) {
1086 trace_header("ACTION callback (extension doesn't exist)", DIRECTION_NONE);
1087 add_trace("extension", NULL, "%s", e_cbcaller);
1092 /* if password is not given */
1093 if (cbext.password[0] == '\0') {
1094 trace_header("ACTION callback (no password set)", DIRECTION_NONE);
1095 add_trace("extension", NULL, "%s", e_cbcaller);
1100 /* callback only possible if callerid exists OR it is given */
1101 if ((rparam = routeparam(e_action, PARAM_CALLTO)))
1102 SCPY(e_cbto, rparam->string_value);
1104 trace_header("ACTION callback (alternative caller id)", DIRECTION_NONE);
1105 add_trace("extension", NULL, "%s", e_cbcaller);
1106 add_trace("callerid", NULL, "%s", e_cbto);
1108 SCPY(e_callerinfo.id, e_cbto);
1109 e_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
1110 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1112 if (e_callerinfo.id[0]=='\0' || e_callerinfo.present==INFO_PRESENT_NOTAVAIL) {
1113 trace_header("ACTION callback (no caller ID available)", DIRECTION_NONE);
1114 add_trace("extension", NULL, "%s", e_cbcaller);
1119 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1124 * process hangup 'callback'
1126 void EndpointAppPBX::action_hangup_callback(void)
1128 struct route_param *rparam;
1132 delay = 2; /* default value */
1133 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1134 if (rparam->integer_value>0)
1135 delay = rparam->integer_value;
1137 /* dialing after callback */
1138 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1139 SCPY(e_cbdialing, rparam->string_value);
1141 SCPY(e_cbdialing, e_extdialing);
1143 trace_header("ACTION callback (dialing)", DIRECTION_NONE);
1144 add_trace("extension", NULL, "%s", e_cbcaller);
1145 add_trace("caller id", NULL, "%s", e_callerinfo.id);
1146 add_trace("delay", NULL, "%d", delay);
1147 add_trace("dialing", NULL, "%s", e_cbdialing);
1150 /* set time to callback */
1151 schedule_timer(&e_callback_timeout, delay, 0);
1156 * dialing action abbreviation
1158 void EndpointAppPBX::action_dialing_abbrev(void)
1160 struct port_list *portlist = ea_endpoint->ep_portlist;
1161 char *abbrev, *phone, *name;
1164 portlist = ea_endpoint->ep_portlist;
1166 /* abbrev dialing is only possible if we have a caller defined */
1167 if (!e_ext.number[0]) {
1168 trace_header("ACTION abbreviation (only for extension)", DIRECTION_NONE);
1170 new_state(EPOINT_STATE_OUT_DISCONNECT);
1171 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1172 set_tone(portlist, "cause_3f");
1176 /* check abbreviation */
1177 abbrev = e_extdialing;
1180 result = parse_phonebook(e_ext.number, &abbrev, &phone, &name);
1182 trace_header("ACTION abbreviation (not found)", DIRECTION_NONE);
1183 add_trace("abbrev", NULL, "%s", abbrev);
1185 new_state(EPOINT_STATE_OUT_DISCONNECT);
1186 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
1187 set_tone(portlist, "cause_01");
1190 if (result == -1) { /* may match if more digits are dialed */
1194 /* dial abbreviation */
1195 trace_header("ACTION abbreviation (dialing)", DIRECTION_NONE);
1196 add_trace("abbrev", NULL, "%s", abbrev);
1197 add_trace("number", NULL, "%s", phone);
1198 if (name) if (name[0])
1199 add_trace("name", NULL, "%s", name);
1201 SCPY(e_dialinginfo.id, phone);
1202 e_extdialing = e_dialinginfo.id;
1208 /* process dialing 'test'
1210 void EndpointAppPBX::action_dialing_test(void)
1214 struct port_list *portlist = ea_endpoint->ep_portlist;
1215 struct lcr_msg *message;
1217 char testcode[32] = "";
1218 struct route_param *rparam;
1220 /* given testcode */
1221 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1222 SCPY(testcode, rparam->string_value);
1223 SCAT(testcode, e_extdialing);
1225 switch(testcode[0]) {
1227 trace_header("ACTION test", DIRECTION_NONE);
1228 add_trace("test", NULL, "proceeding");
1230 new_state(EPOINT_STATE_IN_PROCEEDING);
1231 set_tone(portlist, "proceeding");
1232 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
1233 message_put(message);
1234 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1238 trace_header("ACTION test", DIRECTION_NONE);
1239 add_trace("test", NULL, "alerting");
1241 new_state(EPOINT_STATE_IN_ALERTING);
1242 set_tone(portlist, "ringpbx");
1243 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
1244 message_put(message);
1245 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1249 trace_header("ACTION test", DIRECTION_NONE);
1250 add_trace("test", NULL, "echo");
1252 new_state(EPOINT_STATE_CONNECT);
1253 if (e_ext.number[0])
1255 set_tone(portlist, NULL);
1256 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1257 SCPY(e_connectinfo.id, e_callerinfo.id);
1258 SCPY(e_connectinfo.extension, e_callerinfo.extension);
1259 e_connectinfo.itype = e_callerinfo.itype;
1260 e_connectinfo.ntype = e_callerinfo.ntype;
1261 e_connectinfo.present = e_callerinfo.present;
1262 e_connectinfo.screen = e_callerinfo.screen;
1263 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1264 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(struct connect_info));
1265 /* handle restricted caller ids */
1266 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);
1267 /* display callerid if desired for extension */
1268 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));
1269 message_put(message);
1270 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1272 port = find_port_id(portlist->port_id);
1274 port->set_echotest(1);
1279 trace_header("ACTION test", DIRECTION_NONE);
1280 add_trace("test", NULL, "tone");
1282 new_state(EPOINT_STATE_CONNECT);
1283 if (e_ext.number[0])
1285 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1286 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1287 message_put(message);
1288 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1289 set_tone(portlist, "test");
1293 trace_header("ACTION test", DIRECTION_NONE);
1294 add_trace("test", NULL, "hold music");
1296 new_state(EPOINT_STATE_CONNECT);
1297 if (e_ext.number[0])
1299 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1300 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1301 message_put(message);
1302 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1303 set_tone(portlist, "hold");
1307 if (strlen(testcode) < 4)
1310 cause = atoi(testcode+1);
1313 trace_header("ACTION test", DIRECTION_NONE);
1314 add_trace("test", NULL, "announcement");
1315 add_trace("cause", NULL, "%d", cause);
1317 new_state(EPOINT_STATE_CONNECT);
1318 if (e_ext.number[0])
1320 SPRINT(causestr,"cause_%02x",cause);
1321 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1322 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1323 message_put(message);
1324 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1325 set_tone(portlist, causestr);
1329 if (strlen(testcode) < 4)
1332 cause = atoi(testcode+1);
1335 trace_header("ACTION test", DIRECTION_NONE);
1336 add_trace("test", NULL, "disconnect");
1337 add_trace("cause", NULL, "%d", cause);
1339 new_state(EPOINT_STATE_OUT_DISCONNECT);
1340 SPRINT(causestr,"cause_%02x",cause);
1341 message_disconnect_port(portlist, cause, LOCATION_PRIVATE_LOCAL, "");
1342 set_tone(portlist, causestr);
1345 case '8': /* release */
1346 trace_header("ACTION test", DIRECTION_NONE);
1347 add_trace("test", NULL, "release");
1348 add_trace("cause", NULL, "16");
1350 new_state(EPOINT_STATE_OUT_DISCONNECT);
1351 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
1352 set_tone(portlist, "release");
1355 case '9': /* text callerid test */
1356 trace_header("ACTION test", DIRECTION_NONE);
1357 add_trace("test", NULL, "callerid");
1359 new_state(EPOINT_STATE_CONNECT);
1360 if (e_ext.number[0])
1362 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1363 SCPY(e_connectinfo.id, "12345678");
1364 SCPY(e_connectinfo.name, "Welcome to LCR");
1365 SCPY(e_connectinfo.display, "Welcome to LCR");
1366 e_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1367 e_connectinfo.present = INFO_PRESENT_ALLOWED;
1368 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1369 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(message->param.connectinfo));
1370 message_put(message);
1371 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1372 set_tone(portlist, "hold");
1378 /* process init play
1380 void EndpointAppPBX::action_init_play(void)
1382 struct route_param *rparam;
1383 struct port_list *portlist = ea_endpoint->ep_portlist;
1385 /* check given sample */
1386 if (!(rparam = routeparam(e_action, PARAM_SAMPLE))) {
1387 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1391 new_state(EPOINT_STATE_OUT_DISCONNECT);
1392 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
1393 set_tone(portlist, "cause_3f");
1398 /* if sample is given */
1399 if (rparam->string_value[0] == '\0') {
1400 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1405 if (e_ext.number[0])
1408 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1413 * action_*_vbox_play is implemented in "action_vbox.cpp"
1418 * process dialing of calculator
1420 void EndpointAppPBX::action_dialing_calculator(void)
1422 struct port_list *portlist = ea_endpoint->ep_portlist;
1423 struct lcr_msg *message;
1424 double value1, value2, v, sign1;
1425 int komma1, komma2, k, state, mode = 0, first;
1428 portlist = ea_endpoint->ep_portlist;
1430 /* remove error message */
1431 if (!strncmp(e_extdialing, "Error", 5)) {
1432 UCPY(e_extdialing, e_extdialing+5);
1434 if (!strncmp(e_extdialing, "inf", 3)) {
1435 UCPY(e_extdialing, e_extdialing+3);
1437 if (!strncmp(e_extdialing, "-inf", 4)) {
1438 UCPY(e_extdialing, e_extdialing+4);
1441 /* process dialing */
1453 if (*p>='0' && *p<='9') {
1459 if ((p[-1]<'0' || p[-1]>'0') && p[-1]!='.') {
1466 case 0: /* first number */
1468 value1 = value1*10 + (*p-'0');
1477 case 1: /* second number */
1479 value2 = value2*10 + (*p-'0');
1493 UCPY(e_extdialing, "Error");
1496 /* if there is a multiplication, we change to / */
1504 /* if there is a division, we change to + */
1512 /* if there is a addition, we change to - */
1520 /* if there is a substraction and a comma, we change to * */
1521 if (p[-1]=='-' && komma1) {
1528 /* if there is a substraction and no comma and the first or second value, we change to , */
1536 /* if there is a komma and we are at the first value, we change to * */
1537 if (p[-1]=='.' && state==0) {
1545 /* if there is a komma and we are at the second value, we display error */
1546 if (komma2 && state==1) {
1547 UCPY(e_extdialing, "Error");
1550 /* if we are at state 1, we write a comma */
1556 /* we assume multiplication */
1563 /* if just a number is displayed, the input is cleared */
1565 *e_extdialing = '\0';
1568 /* calculate the result */
1570 case 0: /* multiply */
1571 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1*value2);
1573 case 1: /* divide */
1574 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1/value2);
1577 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1+value2);
1579 case 3: /* substract */
1580 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1-value2);
1583 e_dialinginfo.id[sizeof(e_dialinginfo.id)-1] = '\0';
1584 if (strchr(e_extdialing, '.')) { /* remove zeroes */
1585 while (e_extdialing[strlen(e_extdialing)-1] == '0')
1586 e_extdialing[strlen(e_extdialing)-1] = '\0';
1587 if (e_extdialing[strlen(e_extdialing)-1] == '.')
1588 e_extdialing[strlen(e_extdialing)-1] = '\0'; /* and remove dot */
1590 p = strchr(e_extdialing,'\0')-1;
1622 UCPY(e_extdialing, "Error");
1631 /* display dialing */
1632 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1633 SPRINT(message->param.notifyinfo.display, ">%s", e_extdialing);
1634 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);
1635 message_put(message);
1636 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1641 * process dialing of timer
1643 void EndpointAppPBX::action_dialing_timer(void)
1649 * process 'goto' or 'menu'
1651 void EndpointAppPBX::_action_goto_menu(int mode)
1653 struct port_list *portlist = ea_endpoint->ep_portlist;
1654 struct route_param *rparam;
1656 /* check given ruleset */
1657 if (!(rparam = routeparam(e_action, PARAM_RULESET))) {
1659 trace_header("ACTION goto/menu (no ruleset given)", DIRECTION_NONE);
1663 new_state(EPOINT_STATE_OUT_DISCONNECT);
1664 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1665 set_tone(portlist, "cause_3f");
1669 if (rparam->string_value[0] == '\0')
1671 e_ruleset = getrulesetbyname(rparam->string_value);
1673 trace_header("ACTION goto/menu (ruleset not found)", DIRECTION_NONE);
1674 add_trace("ruleset", NULL, "%s", rparam->string_value);
1679 /* if the 'menu' was selected, we will flush all digits */
1681 e_dialinginfo.id[0] = 0;
1682 e_extdialing = e_dialinginfo.id;
1684 /* remove digits that are required to match the rule */
1685 if ((rparam = routeparam(e_action, PARAM_STRIP))) {
1687 SCPY(e_dialinginfo.id, e_extdialing);
1688 e_extdialing = e_dialinginfo.id;
1693 trace_header("ACTION goto/menu (change to)", DIRECTION_NONE);
1694 add_trace("ruleset", NULL, "%s", e_ruleset->name);
1695 if (e_dialinginfo.id[0]) {
1696 add_trace("dialing", NULL, "%s", e_dialinginfo.id);
1698 if ((rparam = routeparam(e_action, PARAM_SAMPLE))) {
1699 add_trace("sample", NULL, "%s", rparam->string_value);
1701 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1706 /* do dialing with new ruleset */
1711 /* process dialing goto
1713 void EndpointAppPBX::action_dialing_goto(void)
1715 _action_goto_menu(0);
1718 /* process dialing menu
1720 void EndpointAppPBX::action_dialing_menu(void)
1722 _action_goto_menu(1);
1727 * process dialing disconnect
1729 void EndpointAppPBX::action_dialing_disconnect(void)
1731 struct route_param *rparam;
1732 struct port_list *portlist = ea_endpoint->ep_portlist;
1733 struct lcr_msg *message;
1734 int cause = CAUSE_NORMAL; /* normal call clearing */
1735 int location = LOCATION_PRIVATE_LOCAL;
1736 char cause_string[256] = "", display[84] = "";
1738 /* check cause parameter */
1739 if ((rparam = routeparam(e_action, PARAM_CAUSE))) {
1740 cause = rparam->integer_value;
1741 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1743 if ((rparam = routeparam(e_action, PARAM_LOCATION))) {
1744 location = rparam->integer_value;
1745 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1749 /* use cause as sample, if not given later */
1750 SPRINT(cause_string, "cause_%02x", cause);
1752 /* check sample parameter */
1753 if ((rparam = routeparam(e_action, PARAM_SAMPLE))) {
1754 SCPY(cause_string, rparam->string_value);
1755 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'sample' is given: %s\n", ea_endpoint->ep_serial, cause_string);
1759 if ((rparam = routeparam(e_action, PARAM_DISPLAY))) {
1760 SCPY(display, rparam->string_value);
1761 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1764 /* disconnect only if connect parameter is not given */
1765 trace_header("ACTION disconnect", DIRECTION_NONE);
1766 add_trace("cause", "value", "%d", cause);
1767 add_trace("cause", "location", "%d", location);
1768 if (cause_string[0])
1769 add_trace("sample", NULL, "%s", cause_string);
1771 add_trace("display", NULL, "%s", display);
1773 new_state(EPOINT_STATE_OUT_DISCONNECT);
1774 set_tone(portlist, cause_string);
1775 if (!(rparam = routeparam(e_action, PARAM_CONNECT))) {
1776 message_disconnect_port(portlist, cause, location, display);
1778 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1779 SCPY(message->param.notifyinfo.display, display);
1780 message_put(message);
1781 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1788 * process dialing release
1790 void EndpointAppPBX::action_dialing_release(void)
1792 struct route_param *rparam;
1793 int cause = CAUSE_NORMAL; /* normal call clearing */
1794 int location = LOCATION_PRIVATE_LOCAL;
1795 char cause_string[256] = "", display[84] = "";
1797 /* check cause parameter */
1798 if ((rparam = routeparam(e_action, PARAM_CAUSE))) {
1799 cause = rparam->integer_value;
1800 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1802 if ((rparam = routeparam(e_action, PARAM_LOCATION))) {
1803 location = rparam->integer_value;
1804 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1808 /* use cause as sample, if not given later */
1809 SPRINT(cause_string, "cause_%02x", cause);
1812 if ((rparam = routeparam(e_action, PARAM_DISPLAY))) {
1813 SCPY(display, rparam->string_value);
1814 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1817 /* disconnect only if connect parameter is not given */
1818 trace_header("ACTION release", DIRECTION_NONE);
1819 add_trace("cause", "value", "%d", cause);
1820 add_trace("cause", "location", "%d", location);
1822 add_trace("display", NULL, "%s", display);
1825 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, location, cause, 1);
1830 * process dialing help
1832 void EndpointAppPBX::action_dialing_help(void)
1834 /* show all things that would match */
1836 struct numbering *numbering = numbering_int;
1837 char dialing[sizeof(e_dialinginfo.id)];
1839 struct lcr_msg *message;
1840 struct route_param *rparam;
1842 /* in case we have no menu (this should never happen) */
1847 if (strchr(e_dialinginfo.id,'*')) {
1849 e_dialinginfo.id[0] = '\0';
1851 if (strchr(e_dialinginfo.id,'#')) {
1853 e_dialinginfo.id[0] = '\0';
1856 /* get position in menu */
1858 /* get last menu position */
1860 while(numbering->next) {
1862 numbering = numbering->next;
1865 /* get menu position */
1868 numbering = numbering->next;
1871 numbering = numbering_int;
1878 /* if we dial something else we need to add the prefix and change the action */
1879 if (e_dialinginfo.id[0]) {
1880 e_action = NUMB_ACTION_NONE;
1881 SCPY(dialing, numbering->prefix);
1882 //we ignore the first digit after selecting
1883 //SCAT(dialing, e_dialinginfo.id);
1884 SCPY(e_dialinginfo.id, dialing);
1885 e_extdialing = e_dialinginfo.id+strlen(numbering->prefix);
1886 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);
1892 /* send display message to port */
1893 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1894 SPRINT(message->param.notifyinfo.display, ">%s %s%s%s", numbering->prefix, numb_actions[numbering->action], (numbering->param[0])?" ":"", numbering->param);
1895 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);
1896 message_put(message);
1897 logmessage(message->type, message->paramea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1903 * process dialing deflect
1905 void EndpointAppPBX::action_dialing_deflect(void)
1911 * process dialing setforward
1913 void EndpointAppPBX::action_dialing_setforward(void)
1918 * process init 'execute'
1920 void EndpointAppPBX::action_init_execute(void)
1922 struct route_param *rparam;
1923 int executeon = INFO_ON_HANGUP; /* Use Hangup as a default for compatibility */
1925 /* Get the execute on parameter */
1926 if ((rparam = routeparam(e_action, PARAM_ON)))
1927 executeon = rparam->integer_value;
1929 /* Execute this action if init was specified */
1930 if (executeon == INFO_ON_INIT) {
1931 trace_header("ACTION execute ON init", DIRECTION_NONE);
1938 * process hangup 'execute'
1940 void EndpointAppPBX::action_hangup_execute(void)
1942 struct route_param *rparam;
1943 int executeon = INFO_ON_HANGUP; /* Use Hangup as a default for compatibility */
1945 /* Get the execute on parameter */
1946 if ((rparam = routeparam(e_action, PARAM_ON)))
1947 executeon = rparam->integer_value;
1949 /* Execute this action if init was specified */
1950 if (executeon == INFO_ON_HANGUP) {
1951 trace_header("ACTION execute ON hangup", DIRECTION_NONE);
1958 * process 'execute' from action_init_execute or action_hangup_execute
1960 void EndpointAppPBX::action_execute(void)
1962 struct route_param *rparam;
1966 char *command = (char *)"";
1968 char *argv[12]; /* check also number of args below */
1971 /* get script / command */
1972 if ((rparam = routeparam(e_action, PARAM_EXECUTE)))
1973 command = rparam->string_value;
1974 if (command[0] == '\0') {
1975 trace_header("ACTION execute (no parameter given)", DIRECTION_NONE);
1980 argv[i++] = (char *)"/bin/sh";
1981 argv[i++] = (char *)"-c";
1982 argv[i++] = command;
1984 argv[i++] = command;
1985 if ((rparam = routeparam(e_action, PARAM_PARAM))) {
1986 argv[i++] = rparam->string_value;
1988 argv[i++] = e_extdialing;
1989 argv[i++] = (char *)numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international);
1990 argv[i++] = e_callerinfo.extension;
1991 argv[i++] = e_callerinfo.name;
1992 SPRINT(isdn_port, "%d", e_callerinfo.isdn_port);
1993 argv[i++] = isdn_port;
1994 argv[i++] = e_callerinfo.imsi;
1995 argv[i++] = NULL; /* check also number of args above */
1996 switch (pid = fork ()) {
1998 trace_header("ACTION execute (fork failed)", DIRECTION_NONE);
2002 /* To be shure there are no zombies created double fork */
2003 if ((pid2 = fork()) == 0) {
2004 execve(command, argv, environ);
2006 /* Exit immediately and release the waiting parent. The subprocess falls to init because the parent died */
2010 trace_header("ACTION execute", DIRECTION_NONE);
2011 add_trace("command", NULL, "%s", command);
2014 /* Wait for the pid. The forked process will exit immediately so there is no problem waiting. */
2015 waitpid(pid, &iWaitStatus, 0);
2022 * process hangup 'file'
2024 void EndpointAppPBX::action_hangup_file(void)
2026 struct route_param *rparam;
2027 const char *file, *content, *mode;
2030 /* get file / content */
2031 if (!(rparam = routeparam(e_action, PARAM_FILE)))
2032 file = rparam->string_value;
2035 if (!(rparam = routeparam(e_action, PARAM_CONTENT)))
2036 content = rparam->string_value;
2038 content = e_extdialing;
2039 if (!(rparam = routeparam(e_action, PARAM_APPEND)))
2043 if (file[0] == '\0') {
2044 trace_header("ACTION file (no filename given)", DIRECTION_NONE);
2048 if (!(fp = fopen(file, mode))) {
2049 trace_header("ACTION file (failed to open)", DIRECTION_NONE);
2050 add_trace("file", "name", "%s", file);
2051 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2055 trace_header("ACTION file", DIRECTION_NONE);
2056 add_trace("file", "name", "%s", file);
2057 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2058 add_trace("content", NULL, "%s", content);
2060 fprintf(fp, "%s\n", content);
2066 * process init 'pick'
2068 void EndpointAppPBX::action_init_pick(void)
2070 struct route_param *rparam;
2071 char *extensions = NULL;
2073 if ((rparam = routeparam(e_action, PARAM_EXTENSIONS)))
2074 extensions = rparam->string_value;
2076 trace_header("ACTION pick", DIRECTION_NONE);
2077 if (extensions) if (extensions[0])
2078 add_trace("extensions", NULL, "%s", extensions);
2080 pick_join(extensions);
2085 * process dialing 'password'
2087 void EndpointAppPBX::action_dialing_password(void)
2089 struct port_list *portlist = ea_endpoint->ep_portlist;
2091 /* prompt for password */
2092 if (e_extdialing[0] == '\0') {
2093 /* give password tone */
2094 set_tone(portlist, "password");
2096 if (e_extdialing[1] == '\0') {
2097 /* give password tone */
2098 set_tone(portlist, "dialing");
2101 /* wait until all digits are dialed */
2102 if (strlen(e_ext.password) != strlen(e_extdialing))
2103 return; /* more digits needed */
2105 /* check the password */
2106 if (e_ext.password[0]=='\0' || (strlen(e_ext.password)==strlen(e_extdialing) && !!strcmp(e_ext.password,e_extdialing))) {
2107 trace_header("ACTION password_write (wrong password)", DIRECTION_NONE);
2108 add_trace("dialed", NULL, "%s", e_extdialing);
2110 e_connectedmode = 0;
2112 new_state(EPOINT_STATE_OUT_DISCONNECT);
2113 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2114 set_tone(portlist, "cause_10");
2118 /* write caller id if ACTION_PASSWORD_WRITE was selected */
2120 if (e_action->index == ACTION_PASSWORD_WRITE) {
2121 append_callbackauth(e_ext.number, &e_callbackinfo);
2122 trace_header("ACTION password_write (written)", DIRECTION_NONE);
2123 add_trace("dialed", NULL, "%s", e_extdialing);
2127 /* make call state */
2128 new_state(EPOINT_STATE_IN_OVERLAP);
2129 e_ruleset = ruleset_main;
2131 e_rule = e_ruleset->rule_first;
2133 e_dialinginfo.id[0] = '\0';
2134 e_extdialing = e_dialinginfo.id;
2135 set_tone(portlist, "dialpbx");
2138 void EndpointAppPBX::action_dialing_password_wr(void)
2140 action_dialing_password();
2144 /* general process dialing of incoming call
2145 * depending on the detected prefix, subfunctions above (action_*) will be
2148 void EndpointAppPBX::process_dialing(int timeout)
2150 struct port_list *portlist = ea_endpoint->ep_portlist;
2151 struct lcr_msg *message;
2152 struct route_param *rparam;
2153 struct timeval current_time;
2155 /* set if timeout is active, or if timeout value was given due to timeout action */
2156 if (e_action_timeout.active)
2159 //#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.
2160 //PDEBUG(~0, "HANG-BUG-DEBUGGING: entered porcess_dialing\n");
2161 portlist = ea_endpoint->ep_portlist;
2162 /* check if we have a port instance linked to our epoint */
2165 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);
2166 unsched_timer(&e_action_timeout);
2167 unsched_timer(&e_match_timeout);
2170 if (portlist->next) {
2171 goto portlist_error;
2174 /* check nesting levels */
2175 if (++e_rule_nesting > RULE_NESTING) {
2176 trace_header("ACTION (nesting too deep)", DIRECTION_NONE);
2177 add_trace("max-levels", NULL, "%d", RULE_NESTING);
2179 new_state(EPOINT_STATE_OUT_DISCONNECT);
2180 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2181 set_tone(portlist, "cause_3f");
2182 unsched_timer(&e_action_timeout);
2183 unsched_timer(&e_match_timeout);
2187 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before action-timeout processing\n");
2188 /* process timeout */
2189 if (e_action && timeout) { /* e_action may be NULL, but e_action_timeout may still be set and must be ignored */
2190 unsched_timer(&e_action_timeout);
2191 if (e_state == EPOINT_STATE_CONNECT) {
2192 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);
2195 if (e_action->index == ACTION_DISCONNECT
2196 || e_state == EPOINT_STATE_OUT_DISCONNECT) {
2197 /* release after disconnect */
2198 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0);
2201 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
2202 e_action = e_action->next;
2204 /* nothing more, so we release */
2205 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action timed out, and we have no next action, so we disconnect.\n", ea_endpoint->ep_serial);
2206 new_state(EPOINT_STATE_OUT_DISCONNECT);
2207 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2208 set_tone(portlist, "cause_3f");
2211 goto action_timeout;
2214 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before setup/overlap state checking\n");
2215 if (e_state!=EPOINT_STATE_IN_SETUP
2216 && e_state!=EPOINT_STATE_IN_OVERLAP) {
2217 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);
2218 unsched_timer(&e_match_timeout);
2223 /* check if we do menu selection */
2224 if (e_action==NUMB_ACTION_NONE && (e_dialinginfo.id[0]=='*' || e_dialinginfo.id[0]=='#'))
2225 /* do menu selection */
2226 if (e_ext.display_menu) {
2227 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 */
2228 e_dialinginfo.id[0] = '\0';
2229 e_action = NUMB_ACTION_MENU;
2232 unsched_timer(&e_match_timeout);
2235 /* invalid dialing */
2236 message_disconnect_port(portlist, CAUSE_INCALID, LOCATION_PRIVATE_LOCAL, "");
2237 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
2238 message->param.disconnectinfo.cause = CAUSE_INVALID;
2239 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2241 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2242 SCPY(message->param.notifyinfo.display,get_isdn_cause(LOCATION_PRIVATE_LOCAL, epoint->e_ext.display_cause, param->disconnectinfo.location, param->disconnectinfo.cause));
2244 message_put(message);
2245 logmessage(message->type, message->param, portlist->port_id, DIRECTION_OUT);
2247 new_state(EPOINT_STATE_OUT_DISCONNECT);
2248 set_tone(portlist,"cause_1c");
2249 unsched_timer(&e_match_timeout);
2254 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before e_action==NULL\n");
2255 /* if no action yet, we will call try to find a matching rule */
2257 /* be sure that all selectors are initialized */
2260 /* check for external call */
2261 if (!strncmp(e_dialinginfo.id, "extern:", 7)) {
2262 e_extdialing = e_dialinginfo.id+7;
2263 e_action = &action_external;
2264 goto process_action;
2266 /* check for internal call */
2267 if (!strncmp(e_dialinginfo.id, "intern:", 7)) {
2268 e_extdialing = e_dialinginfo.id+7;
2269 e_action = &action_internal;
2270 goto process_action;
2272 /* check for chan call */
2273 if (!strncmp(e_dialinginfo.id, "remote:", 7)) {
2274 e_extdialing = e_dialinginfo.id+7;
2275 e_action = &action_remote;
2276 goto process_action;
2278 /* check for vbox call */
2279 if (!strncmp(e_dialinginfo.id, "vbox:", 5)) {
2280 e_extdialing = e_dialinginfo.id+5;
2281 e_action = &action_vbox;
2282 goto process_action;
2285 gettimeofday(¤t_time, NULL);
2286 if (e_match_to_action && TIME_SMALLER(&e_match_timeout.timeout, ¤t_time)) {
2287 /* return timeout rule */
2288 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);
2289 unsched_timer(&e_match_timeout);
2290 e_action = e_match_to_action;
2291 e_match_to_action = NULL;
2292 e_extdialing = e_match_to_extdialing;
2293 trace_header("ROUTING (timeout)", DIRECTION_NONE);
2294 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2295 add_trace("line", NULL, "%d", e_action->line);
2298 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before routing\n");
2299 /* check for matching rule */
2300 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);
2302 e_action = route(e_ruleset);
2304 trace_header("ACTION (match)", DIRECTION_NONE);
2305 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2306 add_trace("line", NULL, "%d", e_action->line);
2310 e_action = &action_disconnect;
2312 trace_header("ACTION (no main ruleset, disconnecting)", DIRECTION_NONE);
2316 //PDEBUG(~0, "HANG-BUG-DEBUGGING: after routing\n");
2319 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): no rule within the current ruleset matches yet.\n", ea_endpoint->ep_serial, e_ext.number);
2324 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): a rule with action '%s' matches.\n", ea_endpoint->ep_serial, action_defs[e_action->index].name);
2329 unsched_timer(&e_action_timeout);
2330 if (e_action->timeout) {
2331 schedule_timer(&e_action_timeout, e_action->timeout, 0);
2332 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action has a timeout of %d secods.\n", ea_endpoint->ep_serial, e_action->timeout);
2336 /* check param proceeding / alerting / connect */
2337 if ((rparam = routeparam(e_action, PARAM_CONNECT))) {
2338 /* NOTE: we may not change our state to connect, because dialing will then not possible */
2340 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2341 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
2342 message_put(message);
2343 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2345 if ((rparam = routeparam(e_action, PARAM_ALERTING))) {
2346 /* NOTE: we may not change our state to alerting, because dialing will then not possible */
2347 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2348 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
2349 message_put(message);
2350 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2352 if ((rparam = routeparam(e_action, PARAM_PROCEEDING))) {
2353 /* NOTE: we may not change our state to proceeding, because dialing will then not possible */
2354 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2355 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
2356 message_put(message);
2357 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2360 if (action_defs[e_action->index].init_func) {
2361 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);
2362 (this->*(action_defs[e_action->index].init_func))();
2364 if (e_state!=EPOINT_STATE_IN_SETUP
2365 && e_state!=EPOINT_STATE_IN_OVERLAP) {
2366 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);
2367 goto display_action;
2371 /* show what we are doing */
2372 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);
2373 /* go to action's dialing function */
2374 if (action_defs[e_action->index].dialing_func) {
2375 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);
2376 (this->*(action_defs[e_action->index].dialing_func))();
2379 /* display selected dialing action if enabled and still in setup state */
2382 if (e_action->index==ACTION_MENU
2383 || e_action->index==ACTION_REDIAL
2384 || e_action->index==ACTION_REPLY
2385 || e_action->index==ACTION_TIMER
2386 || e_action->index==ACTION_CALCULATOR
2387 || e_action->index==ACTION_TEST)
2391 if (!e_ext.display_dialing)
2393 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*/)
2394 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 */
2395 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2398 SPRINT(message->param.notifyinfo.display, "> %s", e_dialinginfo.id);
2400 SPRINT(message->param.notifyinfo.display, "%s%s%s", action_defs[e_action->index].name, (e_extdialing[0])?" ":"", e_extdialing);
2403 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s'\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
2404 message_put(message);
2405 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2414 /* some services store information after hangup */
2415 void EndpointAppPBX::process_hangup(int cause, int location)
2417 char callertext[256], dialingtext[256];
2418 int writeext = 0, i;
2420 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s'\n", ea_endpoint->ep_serial, e_ext.number);
2421 if (e_ext.number[0]) {
2422 if (read_extension(&e_ext, e_ext.number))
2431 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);
2432 switch(e_dialinginfo.itype) {
2433 case INFO_ITYPE_CHAN:
2434 SPRINT(dialingtext, "chan:%s", e_dialinginfo.id);
2436 case INFO_ITYPE_ISDN_EXTENSION:
2437 SPRINT(dialingtext, "intern:%s", e_dialinginfo.id);
2439 case INFO_ITYPE_VBOX:
2440 SPRINT(dialingtext, "vbox:%s", e_dialinginfo.id);
2443 SPRINT(dialingtext, "%s", e_dialinginfo.id);
2446 if (e_callerinfo.id[0])
2447 SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2449 SPRINT(callertext, "unknown");
2450 /* allpy restriction */
2451 if (!e_ext.anon_ignore && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
2452 SPRINT(callertext, "anonymous");
2453 if (e_callerinfo.extension[0]) /* add intern if present */
2454 UNPRINT(strchr(callertext,'\0'), sizeof(callertext)-1+strlen(callertext), " (intern %s)", e_callerinfo.extension);
2455 write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location);
2457 /* store last received call for reply-list */
2458 if (e_origin == 1) // outgoing to phone is incoming for user
2459 if (e_callerinfo.id[0] || e_callerinfo.extension[0])
2460 if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED) {
2461 if (e_callerinfo.extension[0])
2462 SPRINT(callertext, "intern:%s", e_callerinfo.extension);
2464 SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2465 if (!!strcmp(callertext, e_ext.last_in[0])) {
2468 UCPY(e_ext.last_in[i], e_ext.last_in[i-1]);
2471 SCPY(e_ext.last_in[0], callertext);
2472 writeext |= 1; /* store extension later */
2473 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]);
2475 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);
2478 /* store last made call for reply-list */
2479 if (e_origin == 0) // incoming from phone is outgoing for user
2480 if (e_dialinginfo.id[0]) {
2481 if (!!strcmp(e_dialinginfo.id, e_ext.last_out[0])) {
2484 UCPY(e_ext.last_out[i], e_ext.last_out[i-1]);
2487 SCPY(e_ext.last_out[0], e_dialinginfo.id);
2488 writeext |= 1; /* store extension later */
2489 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
2491 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);
2494 /* write extension if needed */
2495 if (writeext == 0x11)
2496 write_extension(&e_ext, e_ext.number);
2499 if (action_defs[e_action->index].hangup_func) {
2500 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);
2501 (this->*(action_defs[e_action->index].hangup_func))();