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)
24 /* a created call, this should never happen */
25 if (ea_endpoint->ep_join_id) {
26 if (options.deb & DEBUG_EPOINT)
27 PERROR("EPOINT(%d): We already have a call instance, this should never happen!\n", ea_endpoint->ep_serial);
32 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
35 struct port_list *portlist = ea_endpoint->ep_portlist;
36 struct admin_list *admin;
40 if (admin->remote_name[0] && !strcmp(admin->remote_name, remote))
45 /* resource not available */
46 trace_header("ACTION remote (not available)", DIRECTION_NONE);
47 add_trace("application", NULL, "%s", remote);
49 message_disconnect_port(portlist, CAUSE_OUTOFORDER, LOCATION_PRIVATE_LOCAL, "");
50 new_state(EPOINT_STATE_OUT_DISCONNECT);
51 set_tone(portlist,"cause_1b");
54 join = new JoinRemote(ea_endpoint->ep_serial, remote, admin->sock);
57 join = new JoinPBX(ea_endpoint);
59 FATAL("No memoy for Join instance.\n");
60 ea_endpoint->ep_join_id = join->j_serial;
63 void EndpointAppPBX::action_init_call(void)
65 _action_init_call(NULL);
67 void EndpointAppPBX::action_init_remote(void)
72 * process dialing 'internal'
74 void EndpointAppPBX::action_dialing_internal(void)
76 struct capa_info capainfo;
77 struct caller_info callerinfo;
78 struct redir_info redirinfo;
79 struct rtp_info rtpinfo;
80 struct dialing_info dialinginfo;
81 struct port_list *portlist = ea_endpoint->ep_portlist;
82 struct lcr_msg *message;
84 struct route_param *rparam;
86 /* send proceeding, because number is complete */
87 set_tone(portlist, "proceeding");
88 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
90 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
91 new_state(EPOINT_STATE_IN_PROCEEDING);
93 /* create bearer/caller/dialinginfo */
94 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
95 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
96 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
97 memcpy(&rtpinfo, &e_rtpinfo, sizeof(rtpinfo));
98 memset(&dialinginfo, 0, sizeof(dialinginfo));
99 dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
100 SCPY(dialinginfo.id, e_dialinginfo.id);
102 /* process extension */
103 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
104 SCPY(dialinginfo.id, rparam->string_value);
106 /* process number type */
107 if ((rparam = routeparam(e_action, PARAM_TYPE)))
108 dialinginfo.ntype = rparam->integer_value;
110 /* process service */
111 if ((rparam = routeparam(e_action, PARAM_CAPA))) {
112 capainfo.bearer_capa = rparam->integer_value;
113 if (capainfo.bearer_capa != INFO_BC_SPEECH
114 && capainfo.bearer_capa != INFO_BC_AUDIO) {
115 capainfo.bearer_mode = INFO_BMODE_PACKET;
117 capainfo.bearer_info1 = INFO_INFO1_NONE;
118 capainfo.hlc = INFO_HLC_NONE;
119 capainfo.exthlc = INFO_HLC_NONE;
121 if ((rparam = routeparam(e_action, PARAM_BMODE))) {
122 capainfo.bearer_mode = rparam->integer_value;
124 if ((rparam = routeparam(e_action, PARAM_INFO1))) {
125 capainfo.bearer_info1 = rparam->integer_value;
127 if ((rparam = routeparam(e_action, PARAM_HLC))) {
128 capainfo.hlc = rparam->integer_value;
130 if ((rparam = routeparam(e_action, PARAM_EXTHLC))) {
131 capainfo.exthlc = rparam->integer_value;
134 /* process presentation */
135 if ((rparam = routeparam(e_action, PARAM_PRESENT))) {
136 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
139 /* check if extension exists AND only if not multiple extensions */
140 if (!strchr(dialinginfo.id,',') && !read_extension(&ext, dialinginfo.id)) {
141 trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE);
142 add_trace("extension", NULL, dialinginfo.id);
144 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
145 new_state(EPOINT_STATE_OUT_DISCONNECT);
146 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
147 set_tone(portlist, "cause_86");
150 /* check if internal calls are denied */
151 if (e_ext.rights < 1) {
152 trace_header("ACTION extension (dialing to extension denied)", DIRECTION_NONE);
153 add_trace("extension", NULL, dialinginfo.id);
155 new_state(EPOINT_STATE_OUT_DISCONNECT);
156 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
157 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
158 set_tone(portlist, "cause_81");
162 /* add or update internal call */
163 trace_header("ACTION extension (calling)", DIRECTION_NONE);
164 add_trace("extension", NULL, dialinginfo.id);
166 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
167 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
168 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
169 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
170 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
171 memcpy(&message->param.setup.rtpinfo, &rtpinfo, sizeof(struct rtp_info));
172 message_put(message);
175 /* process dialing external
177 void EndpointAppPBX::action_dialing_external(void)
179 struct capa_info capainfo;
180 struct caller_info callerinfo;
181 struct redir_info redirinfo;
182 struct rtp_info rtpinfo;
183 struct dialing_info dialinginfo;
185 struct port_list *portlist = ea_endpoint->ep_portlist;
186 struct lcr_msg *message;
187 struct route_param *rparam;
189 /* special processing of delete characters '*' and '#' */
190 if (e_ext.delete_ext) {
191 /* dialing a # causes a clearing of complete number */
192 if (strchr(e_extdialing, '#')) {
193 e_extdialing[0] = '\0';
194 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);
196 /* eliminate digits before '*', which is a delete digit
198 if (strchr(e_extdialing, '*')) {
200 while((p=strchr(e_extdialing, '*'))) {
201 if (p > e_extdialing) { /* only if there is a digit in front */
205 UCPY(p, p+1); /* remove '*' */
207 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s deleted digits and got new string: %s\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing);
211 /* create bearer/caller/dialinginfo */
212 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
213 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
214 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
215 memcpy(&rtpinfo, &e_rtpinfo, sizeof(rtpinfo));
216 memset(&dialinginfo, 0, sizeof(dialinginfo));
217 dialinginfo.itype = INFO_ITYPE_ISDN;
218 // dialinginfo.sending_complete = 0;
219 SCPY(dialinginfo.id, e_extdialing);
222 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
223 SPRINT(dialinginfo.id, "%s%s", rparam->string_value, e_extdialing);
226 if ((rparam = routeparam(e_action, PARAM_KEYPAD))) {
227 SCPY(dialinginfo.keypad, dialinginfo.id);
228 dialinginfo.id[0] = '\0';
231 /* process number complete */
232 if ((rparam = routeparam(e_action, PARAM_COMPLETE)))
233 dialinginfo.sending_complete = 1;
235 /* process number type */
236 if ((rparam = routeparam(e_action, PARAM_TYPE)))
237 dialinginfo.ntype = rparam->integer_value;
239 /* process service */
240 if ((rparam = routeparam(e_action, PARAM_CAPA))) {
241 capainfo.bearer_capa = rparam->integer_value;
242 if (capainfo.bearer_capa != INFO_BC_SPEECH
243 && capainfo.bearer_capa != INFO_BC_AUDIO) {
244 capainfo.bearer_mode = INFO_BMODE_PACKET;
246 capainfo.bearer_info1 = INFO_INFO1_NONE;
247 capainfo.hlc = INFO_HLC_NONE;
248 capainfo.exthlc = INFO_HLC_NONE;
250 if ((rparam = routeparam(e_action, PARAM_BMODE))) {
251 capainfo.bearer_mode = rparam->integer_value;
253 if ((rparam = routeparam(e_action, PARAM_INFO1))) {
254 capainfo.bearer_info1 = rparam->integer_value;
256 if ((rparam = routeparam(e_action, PARAM_HLC))) {
257 capainfo.hlc = rparam->integer_value;
259 if ((rparam = routeparam(e_action, PARAM_EXTHLC))) {
260 capainfo.exthlc = rparam->integer_value;
264 /* process callerid */
265 if ((rparam = routeparam(e_action, PARAM_CALLERID))) {
266 SCPY(callerinfo.id, rparam->string_value);
268 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE))) {
269 callerinfo.ntype = rparam->integer_value;
272 /* process presentation */
273 if ((rparam = routeparam(e_action, PARAM_PRESENT))) {
274 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
277 /* process interfaces */
278 if ((rparam = routeparam(e_action, PARAM_INTERFACES)))
279 SCPY(dialinginfo.interfaces, rparam->string_value);
281 /* check if local calls are denied */
282 if (e_ext.rights < 2) {
283 trace_header("ACTION extern (calling denied)", DIRECTION_NONE);
285 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
286 set_tone(portlist, "cause_82");
288 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
289 new_state(EPOINT_STATE_OUT_DISCONNECT);
293 if (!strncmp(dialinginfo.id, options.national, strlen(options.national))
294 || dialinginfo.ntype == INFO_NTYPE_NATIONAL
295 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL) {
296 /* check if national calls are denied */
297 if (e_ext.rights < 3) {
298 trace_header("ACTION extern (national calls denied)", DIRECTION_NONE);
300 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
301 set_tone(portlist, "cause_83");
306 if (!strncmp(dialinginfo.id, options.international, strlen(options.international))
307 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL) {
308 /* check if international calls are denied */
309 if (e_ext.rights < 4) {
310 trace_header("ACTION extern (international calls denied)", DIRECTION_NONE);
312 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
313 set_tone(portlist, "cause_84");
318 /* add or update outgoing call */
319 trace_header("ACTION extern (calling)", DIRECTION_NONE);
320 add_trace("number", NULL, dialinginfo.id);
321 if (dialinginfo.sending_complete)
322 add_trace("number", "complete", "yes");
323 if (dialinginfo.interfaces[0])
324 add_trace("interfaces", NULL, dialinginfo.interfaces);
326 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
327 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
328 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
329 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
330 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
331 memcpy(&message->param.setup.rtpinfo, &rtpinfo, sizeof(struct rtp_info));
332 message_put(message);
336 void EndpointAppPBX::action_dialing_remote(void)
338 struct route_param *rparam;
339 struct port_list *portlist = ea_endpoint->ep_portlist;
340 struct lcr_msg *message;
341 struct capa_info capainfo;
342 struct caller_info callerinfo;
343 struct redir_info redirinfo;
344 struct dialing_info dialinginfo;
345 char context[128] = "";
348 if (!ea_endpoint->ep_join_id) {
349 /* no join yet, sending setup */
350 if (!(rparam = routeparam(e_action, PARAM_APPLICATION))) {
351 trace_header("ACTION remote (no application given)", DIRECTION_NONE);
353 new_state(EPOINT_STATE_OUT_DISCONNECT);
354 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
355 set_tone(portlist, "cause_3f");
358 SCPY(remote, rparam->string_value);
359 if (!_action_init_call(remote))
362 /* create bearer/caller/dialinginfo */
363 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
364 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
365 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
366 memset(&dialinginfo, 0, sizeof(dialinginfo));
368 if ((rparam = routeparam(e_action, PARAM_CONTEXT))) {
369 SCPY(context, rparam->string_value);
371 if ((rparam = routeparam(e_action, PARAM_EXTEN))) {
372 SCPY(dialinginfo.id, rparam->string_value);
373 dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
375 SCPY(dialinginfo.id, e_extdialing);
377 e_extdialing = e_dialinginfo.id + strlen(e_dialinginfo.id);
378 /* send setup to remote */
379 trace_header("ACTION remote (setup)", DIRECTION_NONE);
380 add_trace("number", NULL, dialinginfo.id);
381 add_trace("remote", NULL, remote);
383 add_trace("context", NULL, context);
385 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
386 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
387 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
388 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
389 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
390 SCPY(message->param.setup.context, context);
391 message_put(message);
393 /* send overlap digits */
394 trace_header("ACTION remote (dialing)", DIRECTION_NONE);
395 add_trace("number", NULL, e_extdialing);
397 if (e_extdialing[0]) {
398 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_INFORMATION);
399 memcpy(&message->param.information, &e_dialinginfo, sizeof(struct dialing_info));
400 SCPY(message->param.information.id, e_extdialing);
401 e_extdialing = e_dialinginfo.id + strlen(e_dialinginfo.id);
402 message_put(message);
409 * process dialing the "am" and record
411 void EndpointAppPBX::action_dialing_vbox_record(void)
413 struct dialing_info dialinginfo;
414 struct port_list *portlist = ea_endpoint->ep_portlist;
415 struct lcr_msg *message;
416 struct extension ext;
417 struct route_param *rparam;
419 portlist = ea_endpoint->ep_portlist;
421 /* check for given extension */
422 if (!(rparam = routeparam(e_action, PARAM_EXTENSION))) {
423 trace_header("ACTION vbox-record (no extension given by parameter)", DIRECTION_NONE);
426 new_state(EPOINT_STATE_OUT_DISCONNECT);
427 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
428 set_tone(portlist, "cause_3f");
432 /* check if extension exists */
433 if (!read_extension(&ext, rparam->string_value)) {
434 trace_header("ACTION vbox-record (given extension does not exists)", DIRECTION_NONE);
435 add_trace("extension", NULL, "%s", rparam->string_value);
437 new_state(EPOINT_STATE_OUT_DISCONNECT);
438 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
439 set_tone(portlist, "cause_86");
443 /* check if internal calls are denied */
444 if (e_ext.rights < 1) {
445 trace_header("ACTION vbox-record (internal calls are denied)", DIRECTION_NONE);
447 new_state(EPOINT_STATE_OUT_DISCONNECT);
448 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
449 set_tone(portlist, "cause_81");
453 set_tone(portlist, "proceeding");
454 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
455 message_put(message);
456 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
457 new_state(EPOINT_STATE_IN_PROCEEDING);
459 memset(&dialinginfo, 0, sizeof(dialinginfo));
460 dialinginfo.itype = INFO_ITYPE_VBOX;
461 dialinginfo.sending_complete = 1;
462 SCPY(dialinginfo.id, rparam->string_value);
464 /* append special announcement (if given) */
465 if ((rparam = routeparam(e_action, PARAM_ANNOUNCEMENT)))
466 if (rparam->string_value[0]) {
467 SCAT(dialinginfo.id, ",");
468 SCAT(dialinginfo.id, rparam->string_value);
471 /* add or update internal call */
472 trace_header("ACTION vbox-record (calling)", DIRECTION_NONE);
473 add_trace("extension", NULL, "%s", dialinginfo.id);
475 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
476 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
477 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
478 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
479 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
480 message_put(message);
487 void EndpointAppPBX::action_init_partyline(void)
490 class JoinPBX *joinpbx;
491 struct port_list *portlist = ea_endpoint->ep_portlist;
492 struct lcr_msg *message;
493 struct route_param *rparam;
494 int partyline, jingle = 0;
495 struct join_relation *relation;
497 portlist = ea_endpoint->ep_portlist;
499 /* check for given extension */
500 if (!(rparam = routeparam(e_action, PARAM_ROOM))) {
501 trace_header("ACTION partyline (no room parameter)", DIRECTION_NONE);
504 new_state(EPOINT_STATE_OUT_DISCONNECT);
505 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
506 set_tone(portlist, "cause_3f");
509 if (rparam->integer_value <= 0) {
510 trace_header("ACTION partyline (illegal room parameter)", DIRECTION_NONE);
511 add_trace("room", NULL, "%d", rparam->integer_value);
513 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): invalid value for 'room'.\n", ea_endpoint->ep_serial);
516 partyline = rparam->integer_value;
517 if ((rparam = routeparam(e_action, PARAM_JINGLE)))
520 /* don't create join if partyline exists */
523 if (join->j_type == JOIN_TYPE_PBX) {
524 joinpbx = (class JoinPBX *)join;
525 if (joinpbx->j_partyline == partyline)
532 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
533 if (!(join = new JoinPBX(ea_endpoint)))
534 FATAL("No memory for join object\n");
536 //NOTE: joinpbx must be set here
537 /* add relation to existing join */
538 if (!(relation=joinpbx->add_relation()))
539 FATAL("No memory for join relation\n");
540 relation->type = RELATION_TYPE_SETUP;
541 relation->channel_state = 1;
542 relation->rx_state = NOTIFY_STATE_ACTIVE;
543 relation->tx_state = NOTIFY_STATE_ACTIVE;
544 relation->epoint_id = ea_endpoint->ep_serial;
547 ea_endpoint->ep_join_id = join->j_serial;
549 set_tone(portlist, "proceeding");
550 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
551 message_put(message);
552 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
553 new_state(EPOINT_STATE_IN_PROCEEDING);
555 /* send setup to join */
556 trace_header("ACTION partyline (calling)", DIRECTION_NONE);
557 add_trace("room", NULL, "%d", partyline);
558 add_trace("jingle", NULL, (jingle)?"on":"off");
560 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
561 message->param.setup.partyline = partyline;
562 message->param.setup.partyline_jingle = jingle;
563 memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info));
564 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
565 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
566 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
567 message_put(message);
572 * process hangup of all calls
574 void EndpointAppPBX::action_hangup_call(void)
576 trace_header("ACTION hangup", DIRECTION_NONE);
582 * process dialing 'login'
584 void EndpointAppPBX::action_dialing_login(void)
586 struct port_list *portlist = ea_endpoint->ep_portlist;
587 struct lcr_msg *message;
589 struct route_param *rparam;
591 /* extension parameter */
592 if ((rparam = routeparam(e_action, PARAM_EXTENSION))) {
593 /* extension is given by parameter */
594 extension = rparam->string_value;
595 if (extension[0] == '\0')
597 if (!read_extension(&e_ext, extension)) {
598 trace_header("ACTION login (extension doesn't exist)", DIRECTION_NONE);
599 add_trace("extension", NULL, "%s", extension);
601 /* extension doesn't exist */
602 new_state(EPOINT_STATE_OUT_DISCONNECT);
603 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
604 set_tone(portlist, "cause_86");
608 /* extension must be given by dialstring */
609 extension = e_extdialing;
610 if (extension[0] == '\0')
612 if (!read_extension(&e_ext, extension)) {
613 trace_header("ACTION login (extension incomplete or does not exist)", DIRECTION_NONE);
614 add_trace("extension", NULL, "%s", extension);
620 /* we changed our extension */
621 SCPY(e_ext.number, extension);
622 new_state(EPOINT_STATE_CONNECT);
626 /* send connect with extension's caller id (COLP) */
627 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
628 SCPY(message->param.connectinfo.id, e_ext.callerid);
629 message->param.connectinfo.ntype = e_ext.callerid_type;
630 if (e_ext.callerid_present==INFO_PRESENT_ALLOWED && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
631 message->param.connectinfo.present = INFO_PRESENT_RESTRICTED;
632 else message->param.connectinfo.present = e_ext.callerid_present;
633 /* handle restricted caller ids */
634 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);
635 /* display callerid if desired for extension */
636 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));
637 message->param.connectinfo.ntype = e_ext.callerid_type;
638 message_put(message);
639 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
641 /* set our caller id */
642 SCPY(e_callerinfo.id, e_ext.callerid);
643 e_callerinfo.ntype = e_ext.callerid_type;
644 e_callerinfo.present = e_ext.callerid_present;
646 /* enable connectedmode */
650 if (!(rparam = routeparam(e_action, PARAM_NOPASSWORD))) {
651 /* make call state to enter password */
652 trace_header("ACTION login (ask for password)", DIRECTION_NONE);
653 add_trace("extension", NULL, "%s", e_ext.number);
655 new_state(EPOINT_STATE_IN_OVERLAP);
658 e_action = &action_password;
659 unsched_timer(&e_match_timeout);
660 e_match_to_action = NULL;
661 e_dialinginfo.id[0] = '\0';
662 e_extdialing = strchr(e_dialinginfo.id, '\0');
665 schedule_timer(&e_password_timeout, 20, 0);
670 /* make call state */
671 new_state(EPOINT_STATE_IN_OVERLAP);
672 e_ruleset = ruleset_main;
674 e_rule = e_ruleset->rule_first;
676 e_dialinginfo.id[0] = '\0';
677 e_extdialing = e_dialinginfo.id;
678 set_tone(portlist, "dialpbx");
684 * process init 'change_callerid'
686 void EndpointAppPBX::action_init_change_callerid(void)
688 struct port_list *portlist = ea_endpoint->ep_portlist;
690 if (!e_ext.change_callerid) {
691 /* service not available */
692 trace_header("ACTION change-callerid (denied for this caller)", DIRECTION_NONE);
694 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
695 new_state(EPOINT_STATE_OUT_DISCONNECT);
696 set_tone(portlist,"cause_87");
701 /* process dialing callerid
703 void EndpointAppPBX::_action_callerid_calleridnext(int next)
705 struct port_list *portlist = ea_endpoint->ep_portlist;
706 struct route_param *rparam;
707 char buffer[64], *callerid;
708 char old_id[64] = "", new_id[64] = "";
709 int old_type=0, new_type=0, old_present=0, new_present=0;
711 if ((rparam = routeparam(e_action, PARAM_CALLERID))) {
712 /* the caller ID is given by parameter */
713 callerid = rparam->string_value;
715 /* caller ID is dialed */
716 if (!strchr(e_extdialing, '#')) {
717 /* no complete ID yet */
720 *strchr(e_extdialing, '#') = '\0';
721 callerid = e_extdialing;
724 /* given callerid type */
725 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
726 switch(rparam->integer_value) {
727 case INFO_NTYPE_SUBSCRIBER:
728 SPRINT(buffer, "s%s", callerid);
731 case INFO_NTYPE_NATIONAL:
732 SPRINT(buffer, "n%s", callerid);
735 case INFO_NTYPE_INTERNATIONAL:
736 SPRINT(buffer, "i%s", callerid);
740 SPRINT(buffer, "%s", callerid);
745 /* caller id complete, dialing with new caller id */
746 /* write new parameters */
747 if (read_extension(&e_ext, e_ext.number)) {
748 old_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
749 old_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
750 SCPY(old_id, (!next)?e_ext.callerid:e_ext.id_next_call);
751 if (callerid[0] == '\0') {
753 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
756 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_ALLOWED;
757 if ((rparam = routeparam(e_action, PARAM_PRESENT))) if (rparam->integer_value == 0)
758 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
759 if (e_ext.callerid_type == INFO_NTYPE_UNKNOWN) /* if callerid is unknown, the given id is not nationalized */ {
760 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, callerid);
761 (!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN;
763 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));
765 if (!next) e_ext.id_next_call_type = -1;
766 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);
768 new_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
769 new_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
770 SCPY(new_id, (!next)?e_ext.callerid:e_ext.id_next_call);
771 write_extension(&e_ext, e_ext.number);
774 /* function activated */
776 trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE);
778 trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE);
779 add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type, options.national, options.international));
780 add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
781 add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type, options.national, options.international));
782 add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
784 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
785 new_state(EPOINT_STATE_OUT_DISCONNECT);
786 set_tone(portlist,"activated");
789 /* process dialing callerid for all call
791 void EndpointAppPBX::action_dialing_callerid(void)
793 _action_callerid_calleridnext(0);
796 /* process dialing callerid for next call
798 void EndpointAppPBX::action_dialing_calleridnext(void)
800 _action_callerid_calleridnext(1);
805 * process init 'change_forward'
807 void EndpointAppPBX::action_init_change_forward(void)
809 struct port_list *portlist = ea_endpoint->ep_portlist;
811 if (!e_ext.change_forward) {
812 trace_header("ACTION change-forward (denied for this caller)", DIRECTION_NONE);
814 /* service not available */
815 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
816 new_state(EPOINT_STATE_OUT_DISCONNECT);
817 set_tone(portlist,"cause_87");
822 /* process dialing forwarding
824 void EndpointAppPBX::action_dialing_forward(void)
826 struct port_list *portlist = ea_endpoint->ep_portlist;
827 int diversion = INFO_DIVERSION_CFU;
828 char *dest = e_extdialing;
829 struct route_param *rparam;
831 /* if diversion type is given */
832 if ((rparam = routeparam(e_action, PARAM_DIVERSION)))
833 diversion = rparam->integer_value;
835 if ((rparam = routeparam(e_action, PARAM_DEST))) {
836 /* if destination is given */
837 dest = rparam->string_value;
839 if (!strchr(e_extdialing, '#'))
841 *strchr(e_extdialing, '#') = '\0';
845 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing forwarding to '%s'.\n", ea_endpoint->ep_serial, e_ext.number, dest);
846 if (read_extension(&e_ext, e_ext.number)) {
848 case INFO_DIVERSION_CFU:
849 trace_header("ACTION change-forward (new CFU=unconditional)", DIRECTION_NONE);
850 add_trace("destin'", NULL, "%s", dest);
852 SCPY(e_ext.cfu, dest);
854 case INFO_DIVERSION_CFB:
855 trace_header("ACTION change-forward (new CFB=busy)", DIRECTION_NONE);
856 add_trace("destin'", NULL, "%s", dest);
858 SCPY(e_ext.cfb, dest);
860 case INFO_DIVERSION_CFNR:
861 if ((rparam = routeparam(e_action, PARAM_DELAY)))
862 e_ext.cfnr_delay = rparam->integer_value;
863 trace_header("ACTION change-forward (new CFNR=no response)", DIRECTION_NONE);
864 add_trace("destin'", NULL, "%s", dest);
865 add_trace("delay", NULL, "%s", e_ext.cfnr_delay);
867 SCPY(e_ext.cfnr, dest);
869 case INFO_DIVERSION_CFP:
870 trace_header("ACTION change-forward (new CFP=parallel)", DIRECTION_NONE);
871 add_trace("destin'", NULL, "%s", dest);
873 SCPY(e_ext.cfp, dest);
876 write_extension(&e_ext, e_ext.number);
878 /* function (de)activated */
879 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
880 new_state(EPOINT_STATE_OUT_DISCONNECT);
882 set_tone(portlist,"activated");
884 set_tone(portlist,"deactivated");
888 /* process dialing redial
890 void EndpointAppPBX::action_init_redial_reply(void)
892 struct port_list *portlist = ea_endpoint->ep_portlist;
895 if (!e_ext.last_out[0]) {
896 trace_header("ACTION redial/reply (no last number stored)", DIRECTION_NONE);
898 new_state(EPOINT_STATE_OUT_DISCONNECT);
899 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
900 set_tone(portlist, "cause_3f");
905 /* process dialing redial
907 void EndpointAppPBX::_action_redial_reply(int in)
909 struct lcr_msg *message;
911 struct route_param *rparam;
913 last = (in)?e_ext.last_in[0]:e_ext.last_out[0];
915 /* if no display is available */
916 if (!e_ext.display_menu)
918 if (ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_IN && ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_OUT)
921 /* if select is not given */
922 if (!(rparam = routeparam(e_action, PARAM_SELECT)))
926 if (e_extdialing[0]=='*' || e_extdialing[0]=='1') {
927 /* find prev entry */
933 if (e_extdialing[0]=='#' || e_extdialing[0]=='3') {
934 /* find next entry */
936 if (e_select >= MAX_REMEMBER) {
939 if (e_ext.last_in[e_select][0] == '\0')
942 if (e_ext.last_out[e_select][0] == '\0')
947 last = (in)?e_ext.last_in[e_select]:e_ext.last_out[e_select];
948 if (e_extdialing[0]=='0' || e_extdialing[0]=='2') {
951 trace_header("ACTION reply (dialing)", DIRECTION_NONE);
953 trace_header("ACTION redial (dialing)", DIRECTION_NONE);
954 add_trace("number", NULL, "%s", last);
955 add_trace("last but", NULL, "%d", e_select);
957 SCPY(e_dialinginfo.id, last);
958 e_extdialing = e_dialinginfo.id;
963 e_extdialing[0] = '\0';
965 /* send display message to port */
966 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
967 if (!strncmp(last, "extern:", 7))
968 SPRINT(message->param.notifyinfo.display, "(%d) %s ext", e_select+1, last+7);
970 if (!strncmp(last, "intern:", 7))
971 SPRINT(message->param.notifyinfo.display, "(%d) %s int", e_select+1, last+7);
973 if (!strncmp(last, "chan:", 4))
974 SPRINT(message->param.notifyinfo.display, "(%d) %s chan", e_select+1, last+5);
976 if (!strncmp(last, "vbox:", 5))
977 SPRINT(message->param.notifyinfo.display, "(%d) %s vbox", e_select+1, last+5);
979 SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -");
980 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
981 message_put(message);
982 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
985 /* process dialing redial
987 void EndpointAppPBX::action_dialing_redial(void)
989 _action_redial_reply(0);
992 /* process dialing reply
994 void EndpointAppPBX::action_dialing_reply(void)
996 _action_redial_reply(1);
1000 /* dialing powerdialing delay
1002 void EndpointAppPBX::action_dialing_powerdial(void)
1004 struct port_list *portlist = ea_endpoint->ep_portlist;
1005 struct lcr_msg *message;
1006 struct route_param *rparam;
1008 /* power dialing only possible if we have a last dialed number */
1009 if (!e_ext.last_out[0]) {
1010 trace_header("ACTION powerdial (no last number stored)", DIRECTION_NONE);
1012 new_state(EPOINT_STATE_OUT_DISCONNECT);
1013 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1014 set_tone(portlist, "cause_3f");
1019 if ((rparam = routeparam(e_action, PARAM_LIMIT))) {
1020 e_powerlimit = rparam->integer_value;
1026 if ((rparam = routeparam(e_action, PARAM_DELAY))) {
1027 e_powerdelay = rparam->integer_value;
1029 /* delay incomplete */
1030 if (!strchr(e_extdialing, '#'))
1032 *strchr(e_extdialing, '#') = '\0';
1033 e_powerdelay = e_extdialing[0]?atoi(e_extdialing): 0;
1036 if (e_powerdelay < 1)
1038 trace_header("ACTION powerdial (dialing)", DIRECTION_NONE);
1039 add_trace("number", NULL, "%s", e_ext.last_out[0]);
1040 add_trace("delay", NULL, "%d", e_powerdelay);
1043 /* send connect to avoid overlap timeout */
1044 // new_state(EPOINT_STATE_CONNECT); connect may prevent further dialing
1045 if (e_ext.number[0])
1047 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1048 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1049 message_put(message);
1050 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1053 SCPY(e_dialinginfo.id, e_ext.last_out[0]);
1054 e_powerdial_on = 1; /* indicates the existence of powerdialing but no redial time given */
1063 void EndpointAppPBX::action_dialing_callback(void)
1065 struct port_list *portlist = ea_endpoint->ep_portlist;
1066 struct route_param *rparam;
1067 struct extension cbext;
1069 portlist = ea_endpoint->ep_portlist;
1071 /* check given extension */
1072 if (!(rparam = routeparam(e_action, PARAM_EXTENSION))) {
1074 trace_header("ACTION callback (no extension defined)", DIRECTION_NONE);
1078 new_state(EPOINT_STATE_OUT_DISCONNECT);
1079 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1080 set_tone(portlist, "cause_3f");
1082 e_cbcaller[0] = e_cbdialing[0] = '\0';
1086 /* if extension is given */
1087 SCPY(e_cbcaller, rparam->string_value);
1088 if (e_cbcaller[0] == '\0')
1091 /* read callback extension */
1092 memset(&cbext, 0, sizeof(cbext));
1093 if (!read_extension(&cbext, e_cbcaller)) {
1094 trace_header("ACTION callback (extension doesn't exist)", DIRECTION_NONE);
1095 add_trace("extension", NULL, "%s", e_cbcaller);
1100 /* if password is not given */
1101 if (cbext.password[0] == '\0') {
1102 trace_header("ACTION callback (no password set)", DIRECTION_NONE);
1103 add_trace("extension", NULL, "%s", e_cbcaller);
1108 /* callback only possible if callerid exists OR it is given */
1109 if ((rparam = routeparam(e_action, PARAM_CALLTO)))
1110 SCPY(e_cbto, rparam->string_value);
1112 trace_header("ACTION callback (alternative caller id)", DIRECTION_NONE);
1113 add_trace("extension", NULL, "%s", e_cbcaller);
1114 add_trace("callerid", NULL, "%s", e_cbto);
1116 SCPY(e_callerinfo.id, e_cbto);
1117 e_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
1118 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1120 if (e_callerinfo.id[0]=='\0' || e_callerinfo.present==INFO_PRESENT_NOTAVAIL) {
1121 trace_header("ACTION callback (no caller ID available)", DIRECTION_NONE);
1122 add_trace("extension", NULL, "%s", e_cbcaller);
1127 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1132 * process hangup 'callback'
1134 void EndpointAppPBX::action_hangup_callback(void)
1136 struct route_param *rparam;
1140 delay = 2; /* default value */
1141 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1142 if (rparam->integer_value>0)
1143 delay = rparam->integer_value;
1145 /* dialing after callback */
1146 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1147 SCPY(e_cbdialing, rparam->string_value);
1149 SCPY(e_cbdialing, e_extdialing);
1151 trace_header("ACTION callback (dialing)", DIRECTION_NONE);
1152 add_trace("extension", NULL, "%s", e_cbcaller);
1153 add_trace("caller id", NULL, "%s", e_callerinfo.id);
1154 add_trace("delay", NULL, "%d", delay);
1155 add_trace("dialing", NULL, "%s", e_cbdialing);
1158 /* set time to callback */
1159 schedule_timer(&e_callback_timeout, delay, 0);
1164 * dialing action abbreviation
1166 void EndpointAppPBX::action_dialing_abbrev(void)
1168 struct port_list *portlist = ea_endpoint->ep_portlist;
1169 char *abbrev, *phone, *name;
1172 portlist = ea_endpoint->ep_portlist;
1174 /* abbrev dialing is only possible if we have a caller defined */
1175 if (!e_ext.number[0]) {
1176 trace_header("ACTION abbreviation (only for extension)", DIRECTION_NONE);
1178 new_state(EPOINT_STATE_OUT_DISCONNECT);
1179 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1180 set_tone(portlist, "cause_3f");
1184 /* check abbreviation */
1185 abbrev = e_extdialing;
1188 result = parse_phonebook(e_ext.number, &abbrev, &phone, &name);
1190 trace_header("ACTION abbreviation (not found)", DIRECTION_NONE);
1191 add_trace("abbrev", NULL, "%s", abbrev);
1193 new_state(EPOINT_STATE_OUT_DISCONNECT);
1194 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
1195 set_tone(portlist, "cause_01");
1198 if (result == -1) { /* may match if more digits are dialed */
1202 /* dial abbreviation */
1203 trace_header("ACTION abbreviation (dialing)", DIRECTION_NONE);
1204 add_trace("abbrev", NULL, "%s", abbrev);
1205 add_trace("number", NULL, "%s", phone);
1206 if (name) if (name[0])
1207 add_trace("name", NULL, "%s", name);
1209 SCPY(e_dialinginfo.id, phone);
1210 e_extdialing = e_dialinginfo.id;
1216 /* process dialing 'test'
1218 void EndpointAppPBX::action_dialing_test(void)
1222 struct port_list *portlist = ea_endpoint->ep_portlist;
1223 struct lcr_msg *message;
1225 char testcode[32] = "";
1226 struct route_param *rparam;
1228 /* given testcode */
1229 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1230 SCPY(testcode, rparam->string_value);
1231 SCAT(testcode, e_extdialing);
1233 switch(testcode[0]) {
1235 trace_header("ACTION test", DIRECTION_NONE);
1236 add_trace("test", NULL, "proceeding");
1238 new_state(EPOINT_STATE_IN_PROCEEDING);
1239 set_tone(portlist, "proceeding");
1240 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
1241 message_put(message);
1242 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1246 trace_header("ACTION test", DIRECTION_NONE);
1247 add_trace("test", NULL, "alerting");
1249 new_state(EPOINT_STATE_IN_ALERTING);
1250 set_tone(portlist, "ringpbx");
1251 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
1252 message_put(message);
1253 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1257 trace_header("ACTION test", DIRECTION_NONE);
1258 add_trace("test", NULL, "echo");
1260 new_state(EPOINT_STATE_CONNECT);
1261 if (e_ext.number[0])
1263 set_tone(portlist, NULL);
1264 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1265 SCPY(e_connectinfo.id, e_callerinfo.id);
1266 SCPY(e_connectinfo.extension, e_callerinfo.extension);
1267 e_connectinfo.itype = e_callerinfo.itype;
1268 e_connectinfo.ntype = e_callerinfo.ntype;
1269 e_connectinfo.present = e_callerinfo.present;
1270 e_connectinfo.screen = e_callerinfo.screen;
1271 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1272 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(struct connect_info));
1273 /* handle restricted caller ids */
1274 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);
1275 /* display callerid if desired for extension */
1276 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));
1277 message_put(message);
1278 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1280 port = find_port_id(portlist->port_id);
1282 port->set_echotest(1);
1287 trace_header("ACTION test", DIRECTION_NONE);
1288 add_trace("test", NULL, "tone");
1290 new_state(EPOINT_STATE_CONNECT);
1291 if (e_ext.number[0])
1293 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1294 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1295 message_put(message);
1296 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1297 set_tone(portlist, "test");
1301 trace_header("ACTION test", DIRECTION_NONE);
1302 add_trace("test", NULL, "hold music");
1304 new_state(EPOINT_STATE_CONNECT);
1305 if (e_ext.number[0])
1307 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1308 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1309 message_put(message);
1310 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1311 set_tone(portlist, "hold");
1315 if (strlen(testcode) < 4)
1318 cause = atoi(testcode+1);
1321 trace_header("ACTION test", DIRECTION_NONE);
1322 add_trace("test", NULL, "announcement");
1323 add_trace("cause", NULL, "%d", cause);
1325 new_state(EPOINT_STATE_CONNECT);
1326 if (e_ext.number[0])
1328 SPRINT(causestr,"cause_%02x",cause);
1329 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1330 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1331 message_put(message);
1332 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1333 set_tone(portlist, causestr);
1337 if (strlen(testcode) < 4)
1340 cause = atoi(testcode+1);
1343 trace_header("ACTION test", DIRECTION_NONE);
1344 add_trace("test", NULL, "disconnect");
1345 add_trace("cause", NULL, "%d", cause);
1347 new_state(EPOINT_STATE_OUT_DISCONNECT);
1348 SPRINT(causestr,"cause_%02x",cause);
1349 message_disconnect_port(portlist, cause, LOCATION_PRIVATE_LOCAL, "");
1350 set_tone(portlist, causestr);
1353 case '8': /* release */
1354 trace_header("ACTION test", DIRECTION_NONE);
1355 add_trace("test", NULL, "release");
1356 add_trace("cause", NULL, "16");
1358 new_state(EPOINT_STATE_OUT_DISCONNECT);
1359 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
1360 set_tone(portlist, "release");
1363 case '9': /* text callerid test */
1364 trace_header("ACTION test", DIRECTION_NONE);
1365 add_trace("test", NULL, "callerid");
1367 new_state(EPOINT_STATE_CONNECT);
1368 if (e_ext.number[0])
1370 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1371 SCPY(e_connectinfo.id, "12345678");
1372 SCPY(e_connectinfo.name, "Welcome to LCR");
1373 SCPY(e_connectinfo.display, "Welcome to LCR");
1374 e_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1375 e_connectinfo.present = INFO_PRESENT_ALLOWED;
1376 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1377 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(message->param.connectinfo));
1378 message_put(message);
1379 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1380 set_tone(portlist, "hold");
1386 /* process init play
1388 void EndpointAppPBX::action_init_play(void)
1390 struct route_param *rparam;
1391 struct port_list *portlist = ea_endpoint->ep_portlist;
1393 /* check given sample */
1394 if (!(rparam = routeparam(e_action, PARAM_SAMPLE))) {
1395 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1399 new_state(EPOINT_STATE_OUT_DISCONNECT);
1400 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
1401 set_tone(portlist, "cause_3f");
1406 /* if sample is given */
1407 if (rparam->string_value[0] == '\0') {
1408 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1413 if (e_ext.number[0])
1416 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1421 * action_*_vbox_play is implemented in "action_vbox.cpp"
1426 * process dialing of calculator
1428 void EndpointAppPBX::action_dialing_calculator(void)
1430 struct port_list *portlist = ea_endpoint->ep_portlist;
1431 struct lcr_msg *message;
1432 double value1, value2, v, sign1;
1433 int komma1, komma2, k, state, mode = 0, first;
1436 portlist = ea_endpoint->ep_portlist;
1438 /* remove error message */
1439 if (!strncmp(e_extdialing, "Error", 5)) {
1440 UCPY(e_extdialing, e_extdialing+5);
1442 if (!strncmp(e_extdialing, "inf", 3)) {
1443 UCPY(e_extdialing, e_extdialing+3);
1445 if (!strncmp(e_extdialing, "-inf", 4)) {
1446 UCPY(e_extdialing, e_extdialing+4);
1449 /* process dialing */
1461 if (*p>='0' && *p<='9') {
1467 if ((p[-1]<'0' || p[-1]>'0') && p[-1]!='.') {
1474 case 0: /* first number */
1476 value1 = value1*10 + (*p-'0');
1485 case 1: /* second number */
1487 value2 = value2*10 + (*p-'0');
1501 UCPY(e_extdialing, "Error");
1504 /* if there is a multiplication, we change to / */
1512 /* if there is a division, we change to + */
1520 /* if there is a addition, we change to - */
1528 /* if there is a substraction and a comma, we change to * */
1529 if (p[-1]=='-' && komma1) {
1536 /* if there is a substraction and no comma and the first or second value, we change to , */
1544 /* if there is a komma and we are at the first value, we change to * */
1545 if (p[-1]=='.' && state==0) {
1553 /* if there is a komma and we are at the second value, we display error */
1554 if (komma2 && state==1) {
1555 UCPY(e_extdialing, "Error");
1558 /* if we are at state 1, we write a comma */
1564 /* we assume multiplication */
1571 /* if just a number is displayed, the input is cleared */
1573 *e_extdialing = '\0';
1576 /* calculate the result */
1578 case 0: /* multiply */
1579 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1*value2);
1581 case 1: /* divide */
1582 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1/value2);
1585 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1+value2);
1587 case 3: /* substract */
1588 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1-value2);
1591 e_dialinginfo.id[sizeof(e_dialinginfo.id)-1] = '\0';
1592 if (strchr(e_extdialing, '.')) { /* remove zeroes */
1593 while (e_extdialing[strlen(e_extdialing)-1] == '0')
1594 e_extdialing[strlen(e_extdialing)-1] = '\0';
1595 if (e_extdialing[strlen(e_extdialing)-1] == '.')
1596 e_extdialing[strlen(e_extdialing)-1] = '\0'; /* and remove dot */
1598 p = strchr(e_extdialing,'\0')-1;
1630 UCPY(e_extdialing, "Error");
1639 /* display dialing */
1640 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1641 SPRINT(message->param.notifyinfo.display, ">%s", e_extdialing);
1642 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);
1643 message_put(message);
1644 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1649 * process dialing of timer
1651 void EndpointAppPBX::action_dialing_timer(void)
1657 * process 'goto' or 'menu'
1659 void EndpointAppPBX::_action_goto_menu(int mode)
1661 struct port_list *portlist = ea_endpoint->ep_portlist;
1662 struct route_param *rparam;
1664 /* check given ruleset */
1665 if (!(rparam = routeparam(e_action, PARAM_RULESET))) {
1667 trace_header("ACTION goto/menu (no ruleset given)", DIRECTION_NONE);
1671 new_state(EPOINT_STATE_OUT_DISCONNECT);
1672 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1673 set_tone(portlist, "cause_3f");
1677 if (rparam->string_value[0] == '\0')
1679 e_ruleset = getrulesetbyname(rparam->string_value);
1681 trace_header("ACTION goto/menu (ruleset not found)", DIRECTION_NONE);
1682 add_trace("ruleset", NULL, "%s", rparam->string_value);
1687 /* if the 'menu' was selected, we will flush all digits */
1689 e_dialinginfo.id[0] = 0;
1690 e_extdialing = e_dialinginfo.id;
1692 /* remove digits that are required to match the rule */
1693 if ((rparam = routeparam(e_action, PARAM_STRIP))) {
1695 SCPY(e_dialinginfo.id, e_extdialing);
1696 e_extdialing = e_dialinginfo.id;
1701 trace_header("ACTION goto/menu (change to)", DIRECTION_NONE);
1702 add_trace("ruleset", NULL, "%s", e_ruleset->name);
1703 if (e_dialinginfo.id[0]) {
1704 add_trace("dialing", NULL, "%s", e_dialinginfo.id);
1706 if ((rparam = routeparam(e_action, PARAM_SAMPLE))) {
1707 add_trace("sample", NULL, "%s", rparam->string_value);
1709 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1714 /* do dialing with new ruleset */
1719 /* process dialing goto
1721 void EndpointAppPBX::action_dialing_goto(void)
1723 _action_goto_menu(0);
1726 /* process dialing menu
1728 void EndpointAppPBX::action_dialing_menu(void)
1730 _action_goto_menu(1);
1735 * process dialing disconnect
1737 void EndpointAppPBX::action_dialing_disconnect(void)
1739 struct route_param *rparam;
1740 struct port_list *portlist = ea_endpoint->ep_portlist;
1741 struct lcr_msg *message;
1742 int cause = CAUSE_NORMAL; /* normal call clearing */
1743 int location = LOCATION_PRIVATE_LOCAL;
1744 char cause_string[256] = "", display[84] = "";
1746 /* check cause parameter */
1747 if ((rparam = routeparam(e_action, PARAM_CAUSE))) {
1748 cause = rparam->integer_value;
1749 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1751 if ((rparam = routeparam(e_action, PARAM_LOCATION))) {
1752 location = rparam->integer_value;
1753 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1757 /* use cause as sample, if not given later */
1758 SPRINT(cause_string, "cause_%02x", cause);
1760 /* check sample parameter */
1761 if ((rparam = routeparam(e_action, PARAM_SAMPLE))) {
1762 SCPY(cause_string, rparam->string_value);
1763 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'sample' is given: %s\n", ea_endpoint->ep_serial, cause_string);
1767 if ((rparam = routeparam(e_action, PARAM_DISPLAY))) {
1768 SCPY(display, rparam->string_value);
1769 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1772 /* disconnect only if connect parameter is not given */
1773 trace_header("ACTION disconnect", DIRECTION_NONE);
1774 add_trace("cause", "value", "%d", cause);
1775 add_trace("cause", "location", "%d", location);
1776 if (cause_string[0])
1777 add_trace("sample", NULL, "%s", cause_string);
1779 add_trace("display", NULL, "%s", display);
1781 new_state(EPOINT_STATE_OUT_DISCONNECT);
1782 set_tone(portlist, cause_string);
1783 if (!(rparam = routeparam(e_action, PARAM_CONNECT))) {
1784 message_disconnect_port(portlist, cause, location, display);
1786 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1787 SCPY(message->param.notifyinfo.display, display);
1788 message_put(message);
1789 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1796 * process dialing release
1798 void EndpointAppPBX::action_dialing_release(void)
1800 struct route_param *rparam;
1801 int cause = CAUSE_NORMAL; /* normal call clearing */
1802 int location = LOCATION_PRIVATE_LOCAL;
1803 char cause_string[256] = "", display[84] = "";
1805 /* check cause parameter */
1806 if ((rparam = routeparam(e_action, PARAM_CAUSE))) {
1807 cause = rparam->integer_value;
1808 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1810 if ((rparam = routeparam(e_action, PARAM_LOCATION))) {
1811 location = rparam->integer_value;
1812 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1816 /* use cause as sample, if not given later */
1817 SPRINT(cause_string, "cause_%02x", cause);
1820 if ((rparam = routeparam(e_action, PARAM_DISPLAY))) {
1821 SCPY(display, rparam->string_value);
1822 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1825 /* disconnect only if connect parameter is not given */
1826 trace_header("ACTION release", DIRECTION_NONE);
1827 add_trace("cause", "value", "%d", cause);
1828 add_trace("cause", "location", "%d", location);
1830 add_trace("display", NULL, "%s", display);
1833 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, location, cause, 1);
1838 * process dialing help
1840 void EndpointAppPBX::action_dialing_help(void)
1842 /* show all things that would match */
1844 struct numbering *numbering = numbering_int;
1845 char dialing[sizeof(e_dialinginfo.id)];
1847 struct lcr_msg *message;
1848 struct route_param *rparam;
1850 /* in case we have no menu (this should never happen) */
1855 if (strchr(e_dialinginfo.id,'*')) {
1857 e_dialinginfo.id[0] = '\0';
1859 if (strchr(e_dialinginfo.id,'#')) {
1861 e_dialinginfo.id[0] = '\0';
1864 /* get position in menu */
1866 /* get last menu position */
1868 while(numbering->next) {
1870 numbering = numbering->next;
1873 /* get menu position */
1876 numbering = numbering->next;
1879 numbering = numbering_int;
1886 /* if we dial something else we need to add the prefix and change the action */
1887 if (e_dialinginfo.id[0]) {
1888 e_action = NUMB_ACTION_NONE;
1889 SCPY(dialing, numbering->prefix);
1890 //we ignore the first digit after selecting
1891 //SCAT(dialing, e_dialinginfo.id);
1892 SCPY(e_dialinginfo.id, dialing);
1893 e_extdialing = e_dialinginfo.id+strlen(numbering->prefix);
1894 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);
1900 /* send display message to port */
1901 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1902 SPRINT(message->param.notifyinfo.display, ">%s %s%s%s", numbering->prefix, numb_actions[numbering->action], (numbering->param[0])?" ":"", numbering->param);
1903 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);
1904 message_put(message);
1905 logmessage(message->type, message->paramea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1911 * process dialing deflect
1913 void EndpointAppPBX::action_dialing_deflect(void)
1919 * process dialing setforward
1921 void EndpointAppPBX::action_dialing_setforward(void)
1926 * process init 'execute'
1928 void EndpointAppPBX::action_init_execute(void)
1930 struct route_param *rparam;
1931 int executeon = INFO_ON_HANGUP; /* Use Hangup as a default for compatibility */
1933 /* Get the execute on parameter */
1934 if ((rparam = routeparam(e_action, PARAM_ON)))
1935 executeon = rparam->integer_value;
1937 /* Execute this action if init was specified */
1938 if (executeon == INFO_ON_INIT) {
1939 trace_header("ACTION execute ON init", DIRECTION_NONE);
1946 * process hangup 'execute'
1948 void EndpointAppPBX::action_hangup_execute(void)
1950 struct route_param *rparam;
1951 int executeon = INFO_ON_HANGUP; /* Use Hangup as a default for compatibility */
1953 /* Get the execute on parameter */
1954 if ((rparam = routeparam(e_action, PARAM_ON)))
1955 executeon = rparam->integer_value;
1957 /* Execute this action if init was specified */
1958 if (executeon == INFO_ON_HANGUP) {
1959 trace_header("ACTION execute ON hangup", DIRECTION_NONE);
1966 * process 'execute' from action_init_execute or action_hangup_execute
1968 void EndpointAppPBX::action_execute(void)
1970 struct route_param *rparam;
1974 char *command = (char *)"";
1976 char *argv[12]; /* check also number of args below */
1979 /* get script / command */
1980 if ((rparam = routeparam(e_action, PARAM_EXECUTE)))
1981 command = rparam->string_value;
1982 if (command[0] == '\0') {
1983 trace_header("ACTION execute (no parameter given)", DIRECTION_NONE);
1988 argv[i++] = (char *)"/bin/sh";
1989 argv[i++] = (char *)"-c";
1990 argv[i++] = command;
1992 argv[i++] = command;
1993 if ((rparam = routeparam(e_action, PARAM_PARAM))) {
1994 argv[i++] = rparam->string_value;
1996 argv[i++] = e_extdialing;
1997 argv[i++] = (char *)numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international);
1998 argv[i++] = e_callerinfo.extension;
1999 argv[i++] = e_callerinfo.name;
2000 SPRINT(isdn_port, "%d", e_callerinfo.isdn_port);
2001 argv[i++] = isdn_port;
2002 argv[i++] = e_callerinfo.imsi;
2003 argv[i++] = NULL; /* check also number of args above */
2004 switch (pid = fork ()) {
2006 trace_header("ACTION execute (fork failed)", DIRECTION_NONE);
2010 /* To be shure there are no zombies created double fork */
2011 if ((pid2 = fork()) == 0) {
2012 execve(command, argv, environ);
2014 /* Exit immediately and release the waiting parent. The subprocess falls to init because the parent died */
2018 trace_header("ACTION execute", DIRECTION_NONE);
2019 add_trace("command", NULL, "%s", command);
2022 /* Wait for the pid. The forked process will exit immediately so there is no problem waiting. */
2023 waitpid(pid, &iWaitStatus, 0);
2030 * process hangup 'file'
2032 void EndpointAppPBX::action_hangup_file(void)
2034 struct route_param *rparam;
2035 const char *file, *content, *mode;
2038 /* get file / content */
2039 if (!(rparam = routeparam(e_action, PARAM_FILE)))
2040 file = rparam->string_value;
2043 if (!(rparam = routeparam(e_action, PARAM_CONTENT)))
2044 content = rparam->string_value;
2046 content = e_extdialing;
2047 if (!(rparam = routeparam(e_action, PARAM_APPEND)))
2051 if (file[0] == '\0') {
2052 trace_header("ACTION file (no filename given)", DIRECTION_NONE);
2056 if (!(fp = fopen(file, mode))) {
2057 trace_header("ACTION file (failed to open)", DIRECTION_NONE);
2058 add_trace("file", "name", "%s", file);
2059 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2063 trace_header("ACTION file", DIRECTION_NONE);
2064 add_trace("file", "name", "%s", file);
2065 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2066 add_trace("content", NULL, "%s", content);
2068 fprintf(fp, "%s\n", content);
2074 * process init 'pick'
2076 void EndpointAppPBX::action_init_pick(void)
2078 struct route_param *rparam;
2079 char *extensions = NULL;
2081 if ((rparam = routeparam(e_action, PARAM_EXTENSIONS)))
2082 extensions = rparam->string_value;
2084 trace_header("ACTION pick", DIRECTION_NONE);
2085 if (extensions) if (extensions[0])
2086 add_trace("extensions", NULL, "%s", extensions);
2088 pick_join(extensions);
2093 * process dialing 'password'
2095 void EndpointAppPBX::action_dialing_password(void)
2097 struct port_list *portlist = ea_endpoint->ep_portlist;
2099 /* prompt for password */
2100 if (e_extdialing[0] == '\0') {
2101 /* give password tone */
2102 set_tone(portlist, "password");
2104 if (e_extdialing[1] == '\0') {
2105 /* give password tone */
2106 set_tone(portlist, "dialing");
2109 /* wait until all digits are dialed */
2110 if (strlen(e_ext.password) != strlen(e_extdialing))
2111 return; /* more digits needed */
2113 /* check the password */
2114 if (e_ext.password[0]=='\0' || (strlen(e_ext.password)==strlen(e_extdialing) && !!strcmp(e_ext.password,e_extdialing))) {
2115 trace_header("ACTION password_write (wrong password)", DIRECTION_NONE);
2116 add_trace("dialed", NULL, "%s", e_extdialing);
2118 e_connectedmode = 0;
2120 new_state(EPOINT_STATE_OUT_DISCONNECT);
2121 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2122 set_tone(portlist, "cause_10");
2126 /* write caller id if ACTION_PASSWORD_WRITE was selected */
2128 if (e_action->index == ACTION_PASSWORD_WRITE) {
2129 append_callbackauth(e_ext.number, &e_callbackinfo);
2130 trace_header("ACTION password_write (written)", DIRECTION_NONE);
2131 add_trace("dialed", NULL, "%s", e_extdialing);
2135 /* make call state */
2136 new_state(EPOINT_STATE_IN_OVERLAP);
2137 e_ruleset = ruleset_main;
2139 e_rule = e_ruleset->rule_first;
2141 e_dialinginfo.id[0] = '\0';
2142 e_extdialing = e_dialinginfo.id;
2143 set_tone(portlist, "dialpbx");
2146 void EndpointAppPBX::action_dialing_password_wr(void)
2148 action_dialing_password();
2152 /* general process dialing of incoming call
2153 * depending on the detected prefix, subfunctions above (action_*) will be
2156 void EndpointAppPBX::process_dialing(int timeout)
2158 struct port_list *portlist = ea_endpoint->ep_portlist;
2159 struct lcr_msg *message;
2160 struct route_param *rparam;
2161 struct timeval current_time;
2163 /* set if timeout is active, or if timeout value was given due to timeout action */
2164 if (e_action_timeout.active)
2167 //#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.
2168 //PDEBUG(~0, "HANG-BUG-DEBUGGING: entered porcess_dialing\n");
2169 portlist = ea_endpoint->ep_portlist;
2170 /* check if we have a port instance linked to our epoint */
2173 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);
2174 unsched_timer(&e_action_timeout);
2175 unsched_timer(&e_match_timeout);
2178 if (portlist->next) {
2179 goto portlist_error;
2182 /* check nesting levels */
2183 if (++e_rule_nesting > RULE_NESTING) {
2184 trace_header("ACTION (nesting too deep)", DIRECTION_NONE);
2185 add_trace("max-levels", NULL, "%d", RULE_NESTING);
2187 new_state(EPOINT_STATE_OUT_DISCONNECT);
2188 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2189 set_tone(portlist, "cause_3f");
2190 unsched_timer(&e_action_timeout);
2191 unsched_timer(&e_match_timeout);
2195 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before action-timeout processing\n");
2196 /* process timeout */
2197 if (e_action && timeout) { /* e_action may be NULL, but e_action_timeout may still be set and must be ignored */
2198 unsched_timer(&e_action_timeout);
2199 if (e_state == EPOINT_STATE_CONNECT) {
2200 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);
2203 if (e_action->index == ACTION_DISCONNECT
2204 || e_state == EPOINT_STATE_OUT_DISCONNECT) {
2205 /* release after disconnect */
2206 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0);
2209 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
2210 e_action = e_action->next;
2212 /* nothing more, so we release */
2213 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action timed out, and we have no next action, so we disconnect.\n", ea_endpoint->ep_serial);
2214 new_state(EPOINT_STATE_OUT_DISCONNECT);
2215 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2216 set_tone(portlist, "cause_3f");
2219 goto action_timeout;
2222 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before setup/overlap state checking\n");
2223 if (e_state!=EPOINT_STATE_IN_SETUP
2224 && e_state!=EPOINT_STATE_IN_OVERLAP) {
2225 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);
2226 unsched_timer(&e_match_timeout);
2231 /* check if we do menu selection */
2232 if (e_action==NUMB_ACTION_NONE && (e_dialinginfo.id[0]=='*' || e_dialinginfo.id[0]=='#'))
2233 /* do menu selection */
2234 if (e_ext.display_menu) {
2235 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 */
2236 e_dialinginfo.id[0] = '\0';
2237 e_action = NUMB_ACTION_MENU;
2240 unsched_timer(&e_match_timeout);
2243 /* invalid dialing */
2244 message_disconnect_port(portlist, CAUSE_INCALID, LOCATION_PRIVATE_LOCAL, "");
2245 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
2246 message->param.disconnectinfo.cause = CAUSE_INVALID;
2247 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2249 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2250 SCPY(message->param.notifyinfo.display,get_isdn_cause(LOCATION_PRIVATE_LOCAL, epoint->e_ext.display_cause, param->disconnectinfo.location, param->disconnectinfo.cause));
2252 message_put(message);
2253 logmessage(message->type, message->param, portlist->port_id, DIRECTION_OUT);
2255 new_state(EPOINT_STATE_OUT_DISCONNECT);
2256 set_tone(portlist,"cause_1c");
2257 unsched_timer(&e_match_timeout);
2262 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before e_action==NULL\n");
2263 /* if no action yet, we will call try to find a matching rule */
2265 /* be sure that all selectors are initialized */
2268 /* check for external call */
2269 if (!strncmp(e_dialinginfo.id, "extern:", 7)) {
2270 e_extdialing = e_dialinginfo.id+7;
2271 e_action = &action_external;
2272 goto process_action;
2274 /* check for internal call */
2275 if (!strncmp(e_dialinginfo.id, "intern:", 7)) {
2276 e_extdialing = e_dialinginfo.id+7;
2277 e_action = &action_internal;
2278 goto process_action;
2280 /* check for chan call */
2281 if (!strncmp(e_dialinginfo.id, "remote:", 7)) {
2282 e_extdialing = e_dialinginfo.id+7;
2283 e_action = &action_remote;
2284 goto process_action;
2286 /* check for vbox call */
2287 if (!strncmp(e_dialinginfo.id, "vbox:", 5)) {
2288 e_extdialing = e_dialinginfo.id+5;
2289 e_action = &action_vbox;
2290 goto process_action;
2293 gettimeofday(¤t_time, NULL);
2294 if (e_match_to_action && TIME_SMALLER(&e_match_timeout.timeout, ¤t_time)) {
2295 /* return timeout rule */
2296 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);
2297 unsched_timer(&e_match_timeout);
2298 e_action = e_match_to_action;
2299 e_match_to_action = NULL;
2300 e_extdialing = e_match_to_extdialing;
2301 trace_header("ROUTING (timeout)", DIRECTION_NONE);
2302 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2303 add_trace("line", NULL, "%d", e_action->line);
2306 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before routing\n");
2307 /* check for matching rule */
2308 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);
2310 e_action = route(e_ruleset);
2312 trace_header("ACTION (match)", DIRECTION_NONE);
2313 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2314 add_trace("line", NULL, "%d", e_action->line);
2318 e_action = &action_disconnect;
2320 trace_header("ACTION (no main ruleset, disconnecting)", DIRECTION_NONE);
2324 //PDEBUG(~0, "HANG-BUG-DEBUGGING: after routing\n");
2327 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): no rule within the current ruleset matches yet.\n", ea_endpoint->ep_serial, e_ext.number);
2332 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): a rule with action '%s' matches.\n", ea_endpoint->ep_serial, action_defs[e_action->index].name);
2337 unsched_timer(&e_action_timeout);
2338 if (e_action->timeout) {
2339 schedule_timer(&e_action_timeout, e_action->timeout, 0);
2340 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action has a timeout of %d secods.\n", ea_endpoint->ep_serial, e_action->timeout);
2344 /* check param proceeding / alerting / connect */
2345 if ((rparam = routeparam(e_action, PARAM_CONNECT))) {
2346 /* NOTE: we may not change our state to connect, because dialing will then not possible */
2348 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2349 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
2350 message_put(message);
2351 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2353 if ((rparam = routeparam(e_action, PARAM_ALERTING))) {
2354 /* NOTE: we may not change our state to alerting, because dialing will then not possible */
2355 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2356 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
2357 message_put(message);
2358 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2360 if ((rparam = routeparam(e_action, PARAM_PROCEEDING))) {
2361 /* NOTE: we may not change our state to proceeding, because dialing will then not possible */
2362 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2363 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
2364 message_put(message);
2365 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2368 if (action_defs[e_action->index].init_func) {
2369 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);
2370 (this->*(action_defs[e_action->index].init_func))();
2372 if (e_state!=EPOINT_STATE_IN_SETUP
2373 && e_state!=EPOINT_STATE_IN_OVERLAP) {
2374 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);
2375 goto display_action;
2379 /* show what we are doing */
2380 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);
2381 /* go to action's dialing function */
2382 if (action_defs[e_action->index].dialing_func) {
2383 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);
2384 (this->*(action_defs[e_action->index].dialing_func))();
2387 /* display selected dialing action if enabled and still in setup state */
2390 if (e_action->index==ACTION_MENU
2391 || e_action->index==ACTION_REDIAL
2392 || e_action->index==ACTION_REPLY
2393 || e_action->index==ACTION_TIMER
2394 || e_action->index==ACTION_CALCULATOR
2395 || e_action->index==ACTION_TEST)
2399 if (!e_ext.display_dialing)
2401 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*/)
2402 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 */
2403 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2406 SPRINT(message->param.notifyinfo.display, "> %s", e_dialinginfo.id);
2408 SPRINT(message->param.notifyinfo.display, "%s%s%s", action_defs[e_action->index].name, (e_extdialing[0])?" ":"", e_extdialing);
2411 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s'\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
2412 message_put(message);
2413 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2422 /* some services store information after hangup */
2423 void EndpointAppPBX::process_hangup(int cause, int location)
2425 char callertext[256], dialingtext[256];
2426 int writeext = 0, i;
2428 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s'\n", ea_endpoint->ep_serial, e_ext.number);
2429 if (e_ext.number[0]) {
2430 if (read_extension(&e_ext, e_ext.number))
2439 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);
2440 switch(e_dialinginfo.itype) {
2441 case INFO_ITYPE_CHAN:
2442 SPRINT(dialingtext, "chan:%s", e_dialinginfo.id);
2444 case INFO_ITYPE_ISDN_EXTENSION:
2445 SPRINT(dialingtext, "intern:%s", e_dialinginfo.id);
2447 case INFO_ITYPE_VBOX:
2448 SPRINT(dialingtext, "vbox:%s", e_dialinginfo.id);
2451 SPRINT(dialingtext, "%s", e_dialinginfo.id);
2454 if (e_callerinfo.id[0])
2455 SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2457 SPRINT(callertext, "unknown");
2458 /* allpy restriction */
2459 if (!e_ext.anon_ignore && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
2460 SPRINT(callertext, "anonymous");
2461 if (e_callerinfo.extension[0]) /* add intern if present */
2462 UNPRINT(strchr(callertext,'\0'), sizeof(callertext)-1+strlen(callertext), " (intern %s)", e_callerinfo.extension);
2463 write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location);
2465 /* store last received call for reply-list */
2466 if (e_origin == 1) // outgoing to phone is incoming for user
2467 if (e_callerinfo.id[0] || e_callerinfo.extension[0])
2468 if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED) {
2469 if (e_callerinfo.extension[0])
2470 SPRINT(callertext, "intern:%s", e_callerinfo.extension);
2472 SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2473 if (!!strcmp(callertext, e_ext.last_in[0])) {
2476 UCPY(e_ext.last_in[i], e_ext.last_in[i-1]);
2479 SCPY(e_ext.last_in[0], callertext);
2480 writeext |= 1; /* store extension later */
2481 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]);
2483 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);
2486 /* store last made call for reply-list */
2487 if (e_origin == 0) // incoming from phone is outgoing for user
2488 if (e_dialinginfo.id[0]) {
2489 if (!!strcmp(e_dialinginfo.id, e_ext.last_out[0])) {
2492 UCPY(e_ext.last_out[i], e_ext.last_out[i-1]);
2495 SCPY(e_ext.last_out[0], e_dialinginfo.id);
2496 writeext |= 1; /* store extension later */
2497 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
2499 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);
2502 /* write extension if needed */
2503 if (writeext == 0x11)
2504 write_extension(&e_ext, e_ext.number);
2507 if (action_defs[e_action->index].hangup_func) {
2508 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);
2509 (this->*(action_defs[e_action->index].hangup_func))();