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 rtp_info rtpinfo;
78 struct dialing_info dialinginfo;
79 struct port_list *portlist = ea_endpoint->ep_portlist;
80 struct lcr_msg *message;
82 struct route_param *rparam;
84 /* send proceeding, because number is complete */
85 set_tone(portlist, "proceeding");
86 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
88 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
89 new_state(EPOINT_STATE_IN_PROCEEDING);
91 /* create bearer/caller/dialinginfo */
92 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
93 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
94 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
95 memcpy(&rtpinfo, &e_rtpinfo, sizeof(rtpinfo));
96 memset(&dialinginfo, 0, sizeof(dialinginfo));
97 dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
98 SCPY(dialinginfo.id, e_dialinginfo.id);
100 /* process extension */
101 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
102 SCPY(dialinginfo.id, rparam->string_value);
104 /* process number type */
105 if ((rparam = routeparam(e_action, PARAM_TYPE)))
106 dialinginfo.ntype = rparam->integer_value;
108 /* process service */
109 if ((rparam = routeparam(e_action, PARAM_CAPA))) {
110 capainfo.bearer_capa = rparam->integer_value;
111 if (capainfo.bearer_capa != INFO_BC_SPEECH
112 && capainfo.bearer_capa != INFO_BC_AUDIO) {
113 capainfo.bearer_mode = INFO_BMODE_PACKET;
115 capainfo.bearer_info1 = INFO_INFO1_NONE;
116 capainfo.hlc = INFO_HLC_NONE;
117 capainfo.exthlc = INFO_HLC_NONE;
119 if ((rparam = routeparam(e_action, PARAM_BMODE))) {
120 capainfo.bearer_mode = rparam->integer_value;
122 if ((rparam = routeparam(e_action, PARAM_INFO1))) {
123 capainfo.bearer_info1 = rparam->integer_value;
125 if ((rparam = routeparam(e_action, PARAM_HLC))) {
126 capainfo.hlc = rparam->integer_value;
128 if ((rparam = routeparam(e_action, PARAM_EXTHLC))) {
129 capainfo.exthlc = rparam->integer_value;
132 /* process presentation */
133 if ((rparam = routeparam(e_action, PARAM_PRESENT))) {
134 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
137 /* check if extension exists AND only if not multiple extensions */
138 if (!strchr(dialinginfo.id,',') && !read_extension(&ext, dialinginfo.id)) {
139 trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE);
140 add_trace("extension", NULL, dialinginfo.id);
142 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
143 new_state(EPOINT_STATE_OUT_DISCONNECT);
144 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
145 set_tone(portlist, "cause_86");
148 /* check if internal calls are denied */
149 if (e_ext.rights < 1) {
150 trace_header("ACTION extension (dialing to extension denied)", DIRECTION_NONE);
151 add_trace("extension", NULL, dialinginfo.id);
153 new_state(EPOINT_STATE_OUT_DISCONNECT);
154 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
155 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
156 set_tone(portlist, "cause_81");
160 /* add or update internal call */
161 trace_header("ACTION extension (calling)", DIRECTION_NONE);
162 add_trace("extension", NULL, dialinginfo.id);
164 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
165 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
166 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
167 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
168 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
169 memcpy(&message->param.setup.rtpinfo, &rtpinfo, sizeof(struct rtp_info));
170 message_put(message);
173 /* process dialing external
175 void EndpointAppPBX::action_dialing_external(void)
177 struct capa_info capainfo;
178 struct caller_info callerinfo;
179 struct redir_info redirinfo;
180 struct rtp_info rtpinfo;
181 struct dialing_info dialinginfo;
183 struct port_list *portlist = ea_endpoint->ep_portlist;
184 struct lcr_msg *message;
185 struct route_param *rparam;
187 /* special processing of delete characters '*' and '#' */
188 if (e_ext.delete_ext) {
189 /* dialing a # causes a clearing of complete number */
190 if (strchr(e_extdialing, '#')) {
191 e_extdialing[0] = '\0';
192 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);
194 /* eliminate digits before '*', which is a delete digit
196 if (strchr(e_extdialing, '*')) {
198 while((p=strchr(e_extdialing, '*'))) {
199 if (p > e_extdialing) { /* only if there is a digit in front */
203 UCPY(p, p+1); /* remove '*' */
205 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s deleted digits and got new string: %s\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing);
209 /* create bearer/caller/dialinginfo */
210 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
211 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
212 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
213 memcpy(&rtpinfo, &e_rtpinfo, sizeof(rtpinfo));
214 memset(&dialinginfo, 0, sizeof(dialinginfo));
215 dialinginfo.itype = INFO_ITYPE_ISDN;
216 // dialinginfo.sending_complete = 0;
217 SCPY(dialinginfo.id, e_extdialing);
220 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
221 SPRINT(dialinginfo.id, "%s%s", rparam->string_value, e_extdialing);
224 if ((rparam = routeparam(e_action, PARAM_KEYPAD))) {
225 SCPY(dialinginfo.keypad, dialinginfo.id);
226 dialinginfo.id[0] = '\0';
229 /* process number complete */
230 if ((rparam = routeparam(e_action, PARAM_COMPLETE)))
231 dialinginfo.sending_complete = 1;
233 /* process number type */
234 if ((rparam = routeparam(e_action, PARAM_TYPE)))
235 dialinginfo.ntype = rparam->integer_value;
237 /* process service */
238 if ((rparam = routeparam(e_action, PARAM_CAPA))) {
239 capainfo.bearer_capa = rparam->integer_value;
240 if (capainfo.bearer_capa != INFO_BC_SPEECH
241 && capainfo.bearer_capa != INFO_BC_AUDIO) {
242 capainfo.bearer_mode = INFO_BMODE_PACKET;
244 capainfo.bearer_info1 = INFO_INFO1_NONE;
245 capainfo.hlc = INFO_HLC_NONE;
246 capainfo.exthlc = INFO_HLC_NONE;
248 if ((rparam = routeparam(e_action, PARAM_BMODE))) {
249 capainfo.bearer_mode = rparam->integer_value;
251 if ((rparam = routeparam(e_action, PARAM_INFO1))) {
252 capainfo.bearer_info1 = rparam->integer_value;
254 if ((rparam = routeparam(e_action, PARAM_HLC))) {
255 capainfo.hlc = rparam->integer_value;
257 if ((rparam = routeparam(e_action, PARAM_EXTHLC))) {
258 capainfo.exthlc = rparam->integer_value;
262 /* process callerid */
263 if ((rparam = routeparam(e_action, PARAM_CALLERID))) {
264 SCPY(callerinfo.id, rparam->string_value);
266 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE))) {
267 callerinfo.ntype = rparam->integer_value;
270 /* process presentation */
271 if ((rparam = routeparam(e_action, PARAM_PRESENT))) {
272 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
275 /* process interfaces */
276 if ((rparam = routeparam(e_action, PARAM_INTERFACES)))
277 SCPY(dialinginfo.interfaces, rparam->string_value);
279 /* check if local calls are denied */
280 if (e_ext.rights < 2) {
281 trace_header("ACTION extern (calling denied)", DIRECTION_NONE);
283 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
284 set_tone(portlist, "cause_82");
286 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
287 new_state(EPOINT_STATE_OUT_DISCONNECT);
291 if (!strncmp(dialinginfo.id, options.national, strlen(options.national))
292 || dialinginfo.ntype == INFO_NTYPE_NATIONAL
293 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL) {
294 /* check if national calls are denied */
295 if (e_ext.rights < 3) {
296 trace_header("ACTION extern (national calls denied)", DIRECTION_NONE);
298 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
299 set_tone(portlist, "cause_83");
304 if (!strncmp(dialinginfo.id, options.international, strlen(options.international))
305 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL) {
306 /* check if international calls are denied */
307 if (e_ext.rights < 4) {
308 trace_header("ACTION extern (international calls denied)", DIRECTION_NONE);
310 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0, 0);
311 set_tone(portlist, "cause_84");
316 /* add or update outgoing call */
317 trace_header("ACTION extern (calling)", DIRECTION_NONE);
318 add_trace("number", NULL, dialinginfo.id);
319 if (dialinginfo.sending_complete)
320 add_trace("number", "complete", "yes");
321 if (dialinginfo.interfaces[0])
322 add_trace("interfaces", NULL, dialinginfo.interfaces);
324 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
325 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
326 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
327 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
328 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
329 memcpy(&message->param.setup.rtpinfo, &rtpinfo, sizeof(struct rtp_info));
330 message_put(message);
334 void EndpointAppPBX::action_dialing_remote(void)
336 struct route_param *rparam;
337 struct port_list *portlist = ea_endpoint->ep_portlist;
338 struct lcr_msg *message;
339 struct capa_info capainfo;
340 struct caller_info callerinfo;
341 struct redir_info redirinfo;
342 struct dialing_info dialinginfo;
343 char context[128] = "";
346 if (!ea_endpoint->ep_join_id) {
347 /* no join yet, sending setup */
348 if (!(rparam = routeparam(e_action, PARAM_APPLICATION))) {
349 trace_header("ACTION remote (no application given)", DIRECTION_NONE);
351 new_state(EPOINT_STATE_OUT_DISCONNECT);
352 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
353 set_tone(portlist, "cause_3f");
356 SCPY(remote, rparam->string_value);
357 if (!_action_init_call(remote))
360 /* create bearer/caller/dialinginfo */
361 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
362 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
363 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
364 memset(&dialinginfo, 0, sizeof(dialinginfo));
366 if ((rparam = routeparam(e_action, PARAM_CONTEXT))) {
367 SCPY(context, rparam->string_value);
369 if ((rparam = routeparam(e_action, PARAM_EXTEN))) {
370 SCPY(dialinginfo.id, rparam->string_value);
371 dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
373 SCPY(dialinginfo.id, e_extdialing);
375 e_extdialing = e_dialinginfo.id + strlen(e_dialinginfo.id);
376 /* send setup to remote */
377 trace_header("ACTION remote (setup)", DIRECTION_NONE);
378 add_trace("number", NULL, dialinginfo.id);
379 add_trace("remote", NULL, remote);
381 add_trace("context", NULL, context);
383 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
384 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
385 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
386 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
387 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
388 SCPY(message->param.setup.context, context);
389 message_put(message);
391 /* send overlap digits */
392 trace_header("ACTION remote (dialing)", DIRECTION_NONE);
393 add_trace("number", NULL, e_extdialing);
395 if (e_extdialing[0]) {
396 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_INFORMATION);
397 memcpy(&message->param.information, &e_dialinginfo, sizeof(struct dialing_info));
398 SCPY(message->param.information.id, e_extdialing);
399 e_extdialing = e_dialinginfo.id + strlen(e_dialinginfo.id);
400 message_put(message);
407 * process dialing the "am" and record
409 void EndpointAppPBX::action_dialing_vbox_record(void)
411 struct dialing_info dialinginfo;
412 struct port_list *portlist = ea_endpoint->ep_portlist;
413 struct lcr_msg *message;
414 struct extension ext;
415 struct route_param *rparam;
417 portlist = ea_endpoint->ep_portlist;
419 /* check for given extension */
420 if (!(rparam = routeparam(e_action, PARAM_EXTENSION))) {
421 trace_header("ACTION vbox-record (no extension given by parameter)", DIRECTION_NONE);
424 new_state(EPOINT_STATE_OUT_DISCONNECT);
425 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
426 set_tone(portlist, "cause_3f");
430 /* check if extension exists */
431 if (!read_extension(&ext, rparam->string_value)) {
432 trace_header("ACTION vbox-record (given extension does not exists)", DIRECTION_NONE);
433 add_trace("extension", NULL, "%s", rparam->string_value);
435 new_state(EPOINT_STATE_OUT_DISCONNECT);
436 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
437 set_tone(portlist, "cause_86");
441 /* check if internal calls are denied */
442 if (e_ext.rights < 1) {
443 trace_header("ACTION vbox-record (internal calls are denied)", DIRECTION_NONE);
445 new_state(EPOINT_STATE_OUT_DISCONNECT);
446 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
447 set_tone(portlist, "cause_81");
451 set_tone(portlist, "proceeding");
452 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
453 message_put(message);
454 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
455 new_state(EPOINT_STATE_IN_PROCEEDING);
457 memset(&dialinginfo, 0, sizeof(dialinginfo));
458 dialinginfo.itype = INFO_ITYPE_VBOX;
459 dialinginfo.sending_complete = 1;
460 SCPY(dialinginfo.id, rparam->string_value);
462 /* append special announcement (if given) */
463 if ((rparam = routeparam(e_action, PARAM_ANNOUNCEMENT)))
464 if (rparam->string_value[0]) {
465 SCAT(dialinginfo.id, ",");
466 SCAT(dialinginfo.id, rparam->string_value);
469 /* add or update internal call */
470 trace_header("ACTION vbox-record (calling)", DIRECTION_NONE);
471 add_trace("extension", NULL, "%s", dialinginfo.id);
473 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
474 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
475 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
476 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
477 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
478 message_put(message);
485 void EndpointAppPBX::action_init_partyline(void)
488 class JoinPBX *joinpbx;
489 struct port_list *portlist = ea_endpoint->ep_portlist;
490 struct lcr_msg *message;
491 struct route_param *rparam;
492 int partyline, jingle = 0;
493 struct join_relation *relation;
495 portlist = ea_endpoint->ep_portlist;
497 /* check for given extension */
498 if (!(rparam = routeparam(e_action, PARAM_ROOM))) {
499 trace_header("ACTION partyline (no room parameter)", DIRECTION_NONE);
502 new_state(EPOINT_STATE_OUT_DISCONNECT);
503 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
504 set_tone(portlist, "cause_3f");
507 if (rparam->integer_value <= 0) {
508 trace_header("ACTION partyline (illegal room parameter)", DIRECTION_NONE);
509 add_trace("room", NULL, "%d", rparam->integer_value);
511 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): invalid value for 'room'.\n", ea_endpoint->ep_serial);
514 partyline = rparam->integer_value;
515 if ((rparam = routeparam(e_action, PARAM_JINGLE)))
518 /* don't create join if partyline exists */
521 if (join->j_type == JOIN_TYPE_PBX) {
522 joinpbx = (class JoinPBX *)join;
523 if (joinpbx->j_partyline == partyline)
530 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
531 if (!(join = new JoinPBX(ea_endpoint)))
532 FATAL("No memory for join object\n");
534 //NOTE: joinpbx must be set here
535 /* add relation to existing join */
536 if (!(relation=joinpbx->add_relation()))
537 FATAL("No memory for join relation\n");
538 relation->type = RELATION_TYPE_SETUP;
539 relation->channel_state = 1;
540 relation->rx_state = NOTIFY_STATE_ACTIVE;
541 relation->tx_state = NOTIFY_STATE_ACTIVE;
542 relation->epoint_id = ea_endpoint->ep_serial;
545 ea_endpoint->ep_join_id = join->j_serial;
547 set_tone(portlist, "proceeding");
548 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
549 message_put(message);
550 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
551 new_state(EPOINT_STATE_IN_PROCEEDING);
553 /* send setup to join */
554 trace_header("ACTION partyline (calling)", DIRECTION_NONE);
555 add_trace("room", NULL, "%d", partyline);
556 add_trace("jingle", NULL, (jingle)?"on":"off");
558 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
559 message->param.setup.partyline = partyline;
560 message->param.setup.partyline_jingle = jingle;
561 memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info));
562 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
563 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
564 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
565 message_put(message);
570 * process hangup of all calls
572 void EndpointAppPBX::action_hangup_call(void)
574 trace_header("ACTION hangup", DIRECTION_NONE);
580 * process dialing 'login'
582 void EndpointAppPBX::action_dialing_login(void)
584 struct port_list *portlist = ea_endpoint->ep_portlist;
585 struct lcr_msg *message;
587 struct route_param *rparam;
589 /* extension parameter */
590 if ((rparam = routeparam(e_action, PARAM_EXTENSION))) {
591 /* extension is given by parameter */
592 extension = rparam->string_value;
593 if (extension[0] == '\0')
595 if (!read_extension(&e_ext, extension)) {
596 trace_header("ACTION login (extension doesn't exist)", DIRECTION_NONE);
597 add_trace("extension", NULL, "%s", extension);
599 /* extension doesn't exist */
600 new_state(EPOINT_STATE_OUT_DISCONNECT);
601 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
602 set_tone(portlist, "cause_86");
606 /* extension must be given by dialstring */
607 extension = e_extdialing;
608 if (extension[0] == '\0')
610 if (!read_extension(&e_ext, extension)) {
611 trace_header("ACTION login (extension incomplete or does not exist)", DIRECTION_NONE);
612 add_trace("extension", NULL, "%s", extension);
618 /* we changed our extension */
619 SCPY(e_ext.number, extension);
620 new_state(EPOINT_STATE_CONNECT);
624 /* send connect with extension's caller id (COLP) */
625 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
626 SCPY(message->param.connectinfo.id, e_ext.callerid);
627 message->param.connectinfo.ntype = e_ext.callerid_type;
628 if (e_ext.callerid_present==INFO_PRESENT_ALLOWED && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
629 message->param.connectinfo.present = INFO_PRESENT_RESTRICTED;
630 else message->param.connectinfo.present = e_ext.callerid_present;
631 /* handle restricted caller ids */
632 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);
633 /* display callerid if desired for extension */
634 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));
635 message->param.connectinfo.ntype = e_ext.callerid_type;
636 message_put(message);
637 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
639 /* set our caller id */
640 SCPY(e_callerinfo.id, e_ext.callerid);
641 e_callerinfo.ntype = e_ext.callerid_type;
642 e_callerinfo.present = e_ext.callerid_present;
644 /* enable connectedmode */
648 if (!(rparam = routeparam(e_action, PARAM_NOPASSWORD))) {
649 /* make call state to enter password */
650 trace_header("ACTION login (ask for password)", DIRECTION_NONE);
651 add_trace("extension", NULL, "%s", e_ext.number);
653 new_state(EPOINT_STATE_IN_OVERLAP);
656 e_action = &action_password;
657 unsched_timer(&e_match_timeout);
658 e_match_to_action = NULL;
659 e_dialinginfo.id[0] = '\0';
660 e_extdialing = strchr(e_dialinginfo.id, '\0');
663 schedule_timer(&e_password_timeout, 20, 0);
668 /* make call state */
669 new_state(EPOINT_STATE_IN_OVERLAP);
670 e_ruleset = ruleset_main;
672 e_rule = e_ruleset->rule_first;
674 e_dialinginfo.id[0] = '\0';
675 e_extdialing = e_dialinginfo.id;
676 set_tone(portlist, "dialpbx");
682 * process init 'change_callerid'
684 void EndpointAppPBX::action_init_change_callerid(void)
686 struct port_list *portlist = ea_endpoint->ep_portlist;
688 if (!e_ext.change_callerid) {
689 /* service not available */
690 trace_header("ACTION change-callerid (denied for this caller)", DIRECTION_NONE);
692 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
693 new_state(EPOINT_STATE_OUT_DISCONNECT);
694 set_tone(portlist,"cause_87");
699 /* process dialing callerid
701 void EndpointAppPBX::_action_callerid_calleridnext(int next)
703 struct port_list *portlist = ea_endpoint->ep_portlist;
704 struct route_param *rparam;
705 char buffer[64], *callerid;
706 char old_id[64] = "", new_id[64] = "";
707 int old_type=0, new_type=0, old_present=0, new_present=0;
709 if ((rparam = routeparam(e_action, PARAM_CALLERID))) {
710 /* the caller ID is given by parameter */
711 callerid = rparam->string_value;
713 /* caller ID is dialed */
714 if (!strchr(e_extdialing, '#')) {
715 /* no complete ID yet */
718 *strchr(e_extdialing, '#') = '\0';
719 callerid = e_extdialing;
722 /* given callerid type */
723 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
724 switch(rparam->integer_value) {
725 case INFO_NTYPE_SUBSCRIBER:
726 SPRINT(buffer, "s%s", callerid);
729 case INFO_NTYPE_NATIONAL:
730 SPRINT(buffer, "n%s", callerid);
733 case INFO_NTYPE_INTERNATIONAL:
734 SPRINT(buffer, "i%s", callerid);
738 SPRINT(buffer, "%s", callerid);
743 /* caller id complete, dialing with new caller id */
744 /* write new parameters */
745 if (read_extension(&e_ext, e_ext.number)) {
746 old_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
747 old_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
748 SCPY(old_id, (!next)?e_ext.callerid:e_ext.id_next_call);
749 if (callerid[0] == '\0') {
751 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
754 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_ALLOWED;
755 if ((rparam = routeparam(e_action, PARAM_PRESENT))) if (rparam->integer_value == 0)
756 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
757 if (e_ext.callerid_type == INFO_NTYPE_UNKNOWN) /* if callerid is unknown, the given id is not nationalized */ {
758 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, callerid);
759 (!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN;
761 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));
763 if (!next) e_ext.id_next_call_type = -1;
764 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);
766 new_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
767 new_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
768 SCPY(new_id, (!next)?e_ext.callerid:e_ext.id_next_call);
769 write_extension(&e_ext, e_ext.number);
772 /* function activated */
774 trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE);
776 trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE);
777 add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type, options.national, options.international));
778 add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
779 add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type, options.national, options.international));
780 add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
782 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
783 new_state(EPOINT_STATE_OUT_DISCONNECT);
784 set_tone(portlist,"activated");
787 /* process dialing callerid for all call
789 void EndpointAppPBX::action_dialing_callerid(void)
791 _action_callerid_calleridnext(0);
794 /* process dialing callerid for next call
796 void EndpointAppPBX::action_dialing_calleridnext(void)
798 _action_callerid_calleridnext(1);
803 * process init 'change_forward'
805 void EndpointAppPBX::action_init_change_forward(void)
807 struct port_list *portlist = ea_endpoint->ep_portlist;
809 if (!e_ext.change_forward) {
810 trace_header("ACTION change-forward (denied for this caller)", DIRECTION_NONE);
812 /* service not available */
813 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
814 new_state(EPOINT_STATE_OUT_DISCONNECT);
815 set_tone(portlist,"cause_87");
820 /* process dialing forwarding
822 void EndpointAppPBX::action_dialing_forward(void)
824 struct port_list *portlist = ea_endpoint->ep_portlist;
825 int diversion = INFO_DIVERSION_CFU;
826 char *dest = e_extdialing;
827 struct route_param *rparam;
829 /* if diversion type is given */
830 if ((rparam = routeparam(e_action, PARAM_DIVERSION)))
831 diversion = rparam->integer_value;
833 if ((rparam = routeparam(e_action, PARAM_DEST))) {
834 /* if destination is given */
835 dest = rparam->string_value;
837 if (!strchr(e_extdialing, '#'))
839 *strchr(e_extdialing, '#') = '\0';
843 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing forwarding to '%s'.\n", ea_endpoint->ep_serial, e_ext.number, dest);
844 if (read_extension(&e_ext, e_ext.number)) {
846 case INFO_DIVERSION_CFU:
847 trace_header("ACTION change-forward (new CFU=unconditional)", DIRECTION_NONE);
848 add_trace("destin'", NULL, "%s", dest);
850 SCPY(e_ext.cfu, dest);
852 case INFO_DIVERSION_CFB:
853 trace_header("ACTION change-forward (new CFB=busy)", DIRECTION_NONE);
854 add_trace("destin'", NULL, "%s", dest);
856 SCPY(e_ext.cfb, dest);
858 case INFO_DIVERSION_CFNR:
859 if ((rparam = routeparam(e_action, PARAM_DELAY)))
860 e_ext.cfnr_delay = rparam->integer_value;
861 trace_header("ACTION change-forward (new CFNR=no response)", DIRECTION_NONE);
862 add_trace("destin'", NULL, "%s", dest);
863 add_trace("delay", NULL, "%s", e_ext.cfnr_delay);
865 SCPY(e_ext.cfnr, dest);
867 case INFO_DIVERSION_CFP:
868 trace_header("ACTION change-forward (new CFP=parallel)", DIRECTION_NONE);
869 add_trace("destin'", NULL, "%s", dest);
871 SCPY(e_ext.cfp, dest);
874 write_extension(&e_ext, e_ext.number);
876 /* function (de)activated */
877 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
878 new_state(EPOINT_STATE_OUT_DISCONNECT);
880 set_tone(portlist,"activated");
882 set_tone(portlist,"deactivated");
886 /* process dialing redial
888 void EndpointAppPBX::action_init_redial_reply(void)
890 struct port_list *portlist = ea_endpoint->ep_portlist;
893 if (!e_ext.last_out[0]) {
894 trace_header("ACTION redial/reply (no last number stored)", DIRECTION_NONE);
896 new_state(EPOINT_STATE_OUT_DISCONNECT);
897 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
898 set_tone(portlist, "cause_3f");
903 /* process dialing redial
905 void EndpointAppPBX::_action_redial_reply(int in)
907 struct lcr_msg *message;
909 struct route_param *rparam;
911 last = (in)?e_ext.last_in[0]:e_ext.last_out[0];
913 /* if no display is available */
914 if (!e_ext.display_menu)
916 if (ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_IN && ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_OUT)
919 /* if select is not given */
920 if (!(rparam = routeparam(e_action, PARAM_SELECT)))
924 if (e_extdialing[0]=='*' || e_extdialing[0]=='1') {
925 /* find prev entry */
931 if (e_extdialing[0]=='#' || e_extdialing[0]=='3') {
932 /* find next entry */
934 if (e_select >= MAX_REMEMBER) {
937 if (e_ext.last_in[e_select][0] == '\0')
940 if (e_ext.last_out[e_select][0] == '\0')
945 last = (in)?e_ext.last_in[e_select]:e_ext.last_out[e_select];
946 if (e_extdialing[0]=='0' || e_extdialing[0]=='2') {
949 trace_header("ACTION reply (dialing)", DIRECTION_NONE);
951 trace_header("ACTION redial (dialing)", DIRECTION_NONE);
952 add_trace("number", NULL, "%s", last);
953 add_trace("last but", NULL, "%d", e_select);
955 SCPY(e_dialinginfo.id, last);
956 e_extdialing = e_dialinginfo.id;
961 e_extdialing[0] = '\0';
963 /* send display message to port */
964 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
965 if (!strncmp(last, "extern:", 7))
966 SPRINT(message->param.notifyinfo.display, "(%d) %s ext", e_select+1, last+7);
968 if (!strncmp(last, "intern:", 7))
969 SPRINT(message->param.notifyinfo.display, "(%d) %s int", e_select+1, last+7);
971 if (!strncmp(last, "chan:", 4))
972 SPRINT(message->param.notifyinfo.display, "(%d) %s chan", e_select+1, last+5);
974 if (!strncmp(last, "vbox:", 5))
975 SPRINT(message->param.notifyinfo.display, "(%d) %s vbox", e_select+1, last+5);
977 SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -");
978 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
979 message_put(message);
980 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
983 /* process dialing redial
985 void EndpointAppPBX::action_dialing_redial(void)
987 _action_redial_reply(0);
990 /* process dialing reply
992 void EndpointAppPBX::action_dialing_reply(void)
994 _action_redial_reply(1);
998 /* dialing powerdialing delay
1000 void EndpointAppPBX::action_dialing_powerdial(void)
1002 struct port_list *portlist = ea_endpoint->ep_portlist;
1003 struct lcr_msg *message;
1004 struct route_param *rparam;
1006 /* power dialing only possible if we have a last dialed number */
1007 if (!e_ext.last_out[0]) {
1008 trace_header("ACTION powerdial (no last number stored)", DIRECTION_NONE);
1010 new_state(EPOINT_STATE_OUT_DISCONNECT);
1011 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1012 set_tone(portlist, "cause_3f");
1017 if ((rparam = routeparam(e_action, PARAM_LIMIT))) {
1018 e_powerlimit = rparam->integer_value;
1024 if ((rparam = routeparam(e_action, PARAM_DELAY))) {
1025 e_powerdelay = rparam->integer_value;
1027 /* delay incomplete */
1028 if (!strchr(e_extdialing, '#'))
1030 *strchr(e_extdialing, '#') = '\0';
1031 e_powerdelay = e_extdialing[0]?atoi(e_extdialing): 0;
1034 if (e_powerdelay < 1)
1036 trace_header("ACTION powerdial (dialing)", DIRECTION_NONE);
1037 add_trace("number", NULL, "%s", e_ext.last_out[0]);
1038 add_trace("delay", NULL, "%d", e_powerdelay);
1041 /* send connect to avoid overlap timeout */
1042 // new_state(EPOINT_STATE_CONNECT); connect may prevent further dialing
1043 if (e_ext.number[0])
1045 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1046 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1047 message_put(message);
1048 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1051 SCPY(e_dialinginfo.id, e_ext.last_out[0]);
1052 e_powerdial_on = 1; /* indicates the existence of powerdialing but no redial time given */
1061 void EndpointAppPBX::action_dialing_callback(void)
1063 struct port_list *portlist = ea_endpoint->ep_portlist;
1064 struct route_param *rparam;
1065 struct extension cbext;
1067 portlist = ea_endpoint->ep_portlist;
1069 /* check given extension */
1070 if (!(rparam = routeparam(e_action, PARAM_EXTENSION))) {
1072 trace_header("ACTION callback (no extension defined)", DIRECTION_NONE);
1076 new_state(EPOINT_STATE_OUT_DISCONNECT);
1077 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1078 set_tone(portlist, "cause_3f");
1080 e_cbcaller[0] = e_cbdialing[0] = '\0';
1084 /* if extension is given */
1085 SCPY(e_cbcaller, rparam->string_value);
1086 if (e_cbcaller[0] == '\0')
1089 /* read callback extension */
1090 memset(&cbext, 0, sizeof(cbext));
1091 if (!read_extension(&cbext, e_cbcaller)) {
1092 trace_header("ACTION callback (extension doesn't exist)", DIRECTION_NONE);
1093 add_trace("extension", NULL, "%s", e_cbcaller);
1098 /* if password is not given */
1099 if (cbext.password[0] == '\0') {
1100 trace_header("ACTION callback (no password set)", DIRECTION_NONE);
1101 add_trace("extension", NULL, "%s", e_cbcaller);
1106 /* callback only possible if callerid exists OR it is given */
1107 if ((rparam = routeparam(e_action, PARAM_CALLTO)))
1108 SCPY(e_cbto, rparam->string_value);
1110 trace_header("ACTION callback (alternative caller id)", DIRECTION_NONE);
1111 add_trace("extension", NULL, "%s", e_cbcaller);
1112 add_trace("callerid", NULL, "%s", e_cbto);
1114 SCPY(e_callerinfo.id, e_cbto);
1115 e_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
1116 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1118 if (e_callerinfo.id[0]=='\0' || e_callerinfo.present==INFO_PRESENT_NOTAVAIL) {
1119 trace_header("ACTION callback (no caller ID available)", DIRECTION_NONE);
1120 add_trace("extension", NULL, "%s", e_cbcaller);
1125 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1130 * process hangup 'callback'
1132 void EndpointAppPBX::action_hangup_callback(void)
1134 struct route_param *rparam;
1138 delay = 2; /* default value */
1139 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1140 if (rparam->integer_value>0)
1141 delay = rparam->integer_value;
1143 /* dialing after callback */
1144 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1145 SCPY(e_cbdialing, rparam->string_value);
1147 SCPY(e_cbdialing, e_extdialing);
1149 trace_header("ACTION callback (dialing)", DIRECTION_NONE);
1150 add_trace("extension", NULL, "%s", e_cbcaller);
1151 add_trace("caller id", NULL, "%s", e_callerinfo.id);
1152 add_trace("delay", NULL, "%d", delay);
1153 add_trace("dialing", NULL, "%s", e_cbdialing);
1156 /* set time to callback */
1157 schedule_timer(&e_callback_timeout, delay, 0);
1162 * dialing action abbreviation
1164 void EndpointAppPBX::action_dialing_abbrev(void)
1166 struct port_list *portlist = ea_endpoint->ep_portlist;
1167 char *abbrev, *phone, *name;
1170 portlist = ea_endpoint->ep_portlist;
1172 /* abbrev dialing is only possible if we have a caller defined */
1173 if (!e_ext.number[0]) {
1174 trace_header("ACTION abbreviation (only for extension)", DIRECTION_NONE);
1176 new_state(EPOINT_STATE_OUT_DISCONNECT);
1177 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1178 set_tone(portlist, "cause_3f");
1182 /* check abbreviation */
1183 abbrev = e_extdialing;
1186 result = parse_phonebook(e_ext.number, &abbrev, &phone, &name);
1188 trace_header("ACTION abbreviation (not found)", DIRECTION_NONE);
1189 add_trace("abbrev", NULL, "%s", abbrev);
1191 new_state(EPOINT_STATE_OUT_DISCONNECT);
1192 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
1193 set_tone(portlist, "cause_01");
1196 if (result == -1) { /* may match if more digits are dialed */
1200 /* dial abbreviation */
1201 trace_header("ACTION abbreviation (dialing)", DIRECTION_NONE);
1202 add_trace("abbrev", NULL, "%s", abbrev);
1203 add_trace("number", NULL, "%s", phone);
1204 if (name) if (name[0])
1205 add_trace("name", NULL, "%s", name);
1207 SCPY(e_dialinginfo.id, phone);
1208 e_extdialing = e_dialinginfo.id;
1214 /* process dialing 'test'
1216 void EndpointAppPBX::action_dialing_test(void)
1220 struct port_list *portlist = ea_endpoint->ep_portlist;
1221 struct lcr_msg *message;
1223 char testcode[32] = "";
1224 struct route_param *rparam;
1226 /* given testcode */
1227 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1228 SCPY(testcode, rparam->string_value);
1229 SCAT(testcode, e_extdialing);
1231 switch(testcode[0]) {
1233 trace_header("ACTION test", DIRECTION_NONE);
1234 add_trace("test", NULL, "proceeding");
1236 new_state(EPOINT_STATE_IN_PROCEEDING);
1237 set_tone(portlist, "proceeding");
1238 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
1239 message_put(message);
1240 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1244 trace_header("ACTION test", DIRECTION_NONE);
1245 add_trace("test", NULL, "alerting");
1247 new_state(EPOINT_STATE_IN_ALERTING);
1248 set_tone(portlist, "ringpbx");
1249 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
1250 message_put(message);
1251 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1255 trace_header("ACTION test", DIRECTION_NONE);
1256 add_trace("test", NULL, "echo");
1258 new_state(EPOINT_STATE_CONNECT);
1259 if (e_ext.number[0])
1261 set_tone(portlist, NULL);
1262 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1263 SCPY(e_connectinfo.id, e_callerinfo.id);
1264 SCPY(e_connectinfo.extension, e_callerinfo.extension);
1265 e_connectinfo.itype = e_callerinfo.itype;
1266 e_connectinfo.ntype = e_callerinfo.ntype;
1267 e_connectinfo.present = e_callerinfo.present;
1268 e_connectinfo.screen = e_callerinfo.screen;
1269 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1270 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(struct connect_info));
1271 /* handle restricted caller ids */
1272 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);
1273 /* display callerid if desired for extension */
1274 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));
1275 message_put(message);
1276 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1278 port = find_port_id(portlist->port_id);
1280 port->set_echotest(1);
1285 trace_header("ACTION test", DIRECTION_NONE);
1286 add_trace("test", NULL, "tone");
1288 new_state(EPOINT_STATE_CONNECT);
1289 if (e_ext.number[0])
1291 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1292 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1293 message_put(message);
1294 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1295 set_tone(portlist, "test");
1299 trace_header("ACTION test", DIRECTION_NONE);
1300 add_trace("test", NULL, "hold music");
1302 new_state(EPOINT_STATE_CONNECT);
1303 if (e_ext.number[0])
1305 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1306 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1307 message_put(message);
1308 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1309 set_tone(portlist, "hold");
1313 if (strlen(testcode) < 4)
1316 cause = atoi(testcode+1);
1319 trace_header("ACTION test", DIRECTION_NONE);
1320 add_trace("test", NULL, "announcement");
1321 add_trace("cause", NULL, "%d", cause);
1323 new_state(EPOINT_STATE_CONNECT);
1324 if (e_ext.number[0])
1326 SPRINT(causestr,"cause_%02x",cause);
1327 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1328 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1329 message_put(message);
1330 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1331 set_tone(portlist, causestr);
1335 if (strlen(testcode) < 4)
1338 cause = atoi(testcode+1);
1341 trace_header("ACTION test", DIRECTION_NONE);
1342 add_trace("test", NULL, "disconnect");
1343 add_trace("cause", NULL, "%d", cause);
1345 new_state(EPOINT_STATE_OUT_DISCONNECT);
1346 SPRINT(causestr,"cause_%02x",cause);
1347 message_disconnect_port(portlist, cause, LOCATION_PRIVATE_LOCAL, "");
1348 set_tone(portlist, causestr);
1351 case '8': /* release */
1352 trace_header("ACTION test", DIRECTION_NONE);
1353 add_trace("test", NULL, "release");
1354 add_trace("cause", NULL, "16");
1356 new_state(EPOINT_STATE_OUT_DISCONNECT);
1357 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
1358 set_tone(portlist, "release");
1361 case '9': /* text callerid test */
1362 trace_header("ACTION test", DIRECTION_NONE);
1363 add_trace("test", NULL, "callerid");
1365 new_state(EPOINT_STATE_CONNECT);
1366 if (e_ext.number[0])
1368 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1369 SCPY(e_connectinfo.id, "12345678");
1370 SCPY(e_connectinfo.name, "Welcome to LCR");
1371 SCPY(e_connectinfo.display, "Welcome to LCR");
1372 e_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1373 e_connectinfo.present = INFO_PRESENT_ALLOWED;
1374 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1375 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(message->param.connectinfo));
1376 message_put(message);
1377 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1378 set_tone(portlist, "hold");
1384 /* process init play
1386 void EndpointAppPBX::action_init_play(void)
1388 struct route_param *rparam;
1389 struct port_list *portlist = ea_endpoint->ep_portlist;
1391 /* check given sample */
1392 if (!(rparam = routeparam(e_action, PARAM_SAMPLE))) {
1393 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1397 new_state(EPOINT_STATE_OUT_DISCONNECT);
1398 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
1399 set_tone(portlist, "cause_3f");
1404 /* if sample is given */
1405 if (rparam->string_value[0] == '\0') {
1406 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1411 if (e_ext.number[0])
1414 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1419 * action_*_vbox_play is implemented in "action_vbox.cpp"
1424 * process dialing of calculator
1426 void EndpointAppPBX::action_dialing_calculator(void)
1428 struct port_list *portlist = ea_endpoint->ep_portlist;
1429 struct lcr_msg *message;
1430 double value1, value2, v, sign1;
1431 int komma1, komma2, k, state, mode = 0, first;
1434 portlist = ea_endpoint->ep_portlist;
1436 /* remove error message */
1437 if (!strncmp(e_extdialing, "Error", 5)) {
1438 UCPY(e_extdialing, e_extdialing+5);
1440 if (!strncmp(e_extdialing, "inf", 3)) {
1441 UCPY(e_extdialing, e_extdialing+3);
1443 if (!strncmp(e_extdialing, "-inf", 4)) {
1444 UCPY(e_extdialing, e_extdialing+4);
1447 /* process dialing */
1459 if (*p>='0' && *p<='9') {
1465 if ((p[-1]<'0' || p[-1]>'0') && p[-1]!='.') {
1472 case 0: /* first number */
1474 value1 = value1*10 + (*p-'0');
1483 case 1: /* second number */
1485 value2 = value2*10 + (*p-'0');
1499 UCPY(e_extdialing, "Error");
1502 /* if there is a multiplication, we change to / */
1510 /* if there is a division, we change to + */
1518 /* if there is a addition, we change to - */
1526 /* if there is a substraction and a comma, we change to * */
1527 if (p[-1]=='-' && komma1) {
1534 /* if there is a substraction and no comma and the first or second value, we change to , */
1542 /* if there is a komma and we are at the first value, we change to * */
1543 if (p[-1]=='.' && state==0) {
1551 /* if there is a komma and we are at the second value, we display error */
1552 if (komma2 && state==1) {
1553 UCPY(e_extdialing, "Error");
1556 /* if we are at state 1, we write a comma */
1562 /* we assume multiplication */
1569 /* if just a number is displayed, the input is cleared */
1571 *e_extdialing = '\0';
1574 /* calculate the result */
1576 case 0: /* multiply */
1577 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1*value2);
1579 case 1: /* divide */
1580 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1/value2);
1583 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1+value2);
1585 case 3: /* substract */
1586 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1-value2);
1589 e_dialinginfo.id[sizeof(e_dialinginfo.id)-1] = '\0';
1590 if (strchr(e_extdialing, '.')) { /* remove zeroes */
1591 while (e_extdialing[strlen(e_extdialing)-1] == '0')
1592 e_extdialing[strlen(e_extdialing)-1] = '\0';
1593 if (e_extdialing[strlen(e_extdialing)-1] == '.')
1594 e_extdialing[strlen(e_extdialing)-1] = '\0'; /* and remove dot */
1596 p = strchr(e_extdialing,'\0')-1;
1628 UCPY(e_extdialing, "Error");
1637 /* display dialing */
1638 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1639 SPRINT(message->param.notifyinfo.display, ">%s", e_extdialing);
1640 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);
1641 message_put(message);
1642 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1647 * process dialing of timer
1649 void EndpointAppPBX::action_dialing_timer(void)
1655 * process 'goto' or 'menu'
1657 void EndpointAppPBX::_action_goto_menu(int mode)
1659 struct port_list *portlist = ea_endpoint->ep_portlist;
1660 struct route_param *rparam;
1662 /* check given ruleset */
1663 if (!(rparam = routeparam(e_action, PARAM_RULESET))) {
1665 trace_header("ACTION goto/menu (no ruleset given)", DIRECTION_NONE);
1669 new_state(EPOINT_STATE_OUT_DISCONNECT);
1670 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1671 set_tone(portlist, "cause_3f");
1675 if (rparam->string_value[0] == '\0')
1677 e_ruleset = getrulesetbyname(rparam->string_value);
1679 trace_header("ACTION goto/menu (ruleset not found)", DIRECTION_NONE);
1680 add_trace("ruleset", NULL, "%s", rparam->string_value);
1685 /* if the 'menu' was selected, we will flush all digits */
1687 e_dialinginfo.id[0] = 0;
1688 e_extdialing = e_dialinginfo.id;
1690 /* remove digits that are required to match the rule */
1691 if ((rparam = routeparam(e_action, PARAM_STRIP))) {
1693 SCPY(e_dialinginfo.id, e_extdialing);
1694 e_extdialing = e_dialinginfo.id;
1699 trace_header("ACTION goto/menu (change to)", DIRECTION_NONE);
1700 add_trace("ruleset", NULL, "%s", e_ruleset->name);
1701 if (e_dialinginfo.id[0]) {
1702 add_trace("dialing", NULL, "%s", e_dialinginfo.id);
1704 if ((rparam = routeparam(e_action, PARAM_SAMPLE))) {
1705 add_trace("sample", NULL, "%s", rparam->string_value);
1707 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1712 /* do dialing with new ruleset */
1717 /* process dialing goto
1719 void EndpointAppPBX::action_dialing_goto(void)
1721 _action_goto_menu(0);
1724 /* process dialing menu
1726 void EndpointAppPBX::action_dialing_menu(void)
1728 _action_goto_menu(1);
1733 * process dialing disconnect
1735 void EndpointAppPBX::action_dialing_disconnect(void)
1737 struct route_param *rparam;
1738 struct port_list *portlist = ea_endpoint->ep_portlist;
1739 struct lcr_msg *message;
1740 int cause = CAUSE_NORMAL; /* normal call clearing */
1741 int location = LOCATION_PRIVATE_LOCAL;
1742 char cause_string[256] = "", display[84] = "";
1744 /* check cause parameter */
1745 if ((rparam = routeparam(e_action, PARAM_CAUSE))) {
1746 cause = rparam->integer_value;
1747 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1749 if ((rparam = routeparam(e_action, PARAM_LOCATION))) {
1750 location = rparam->integer_value;
1751 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1755 /* use cause as sample, if not given later */
1756 SPRINT(cause_string, "cause_%02x", cause);
1758 /* check sample parameter */
1759 if ((rparam = routeparam(e_action, PARAM_SAMPLE))) {
1760 SCPY(cause_string, rparam->string_value);
1761 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'sample' is given: %s\n", ea_endpoint->ep_serial, cause_string);
1765 if ((rparam = routeparam(e_action, PARAM_DISPLAY))) {
1766 SCPY(display, rparam->string_value);
1767 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1770 /* disconnect only if connect parameter is not given */
1771 trace_header("ACTION disconnect", DIRECTION_NONE);
1772 add_trace("cause", "value", "%d", cause);
1773 add_trace("cause", "location", "%d", location);
1774 if (cause_string[0])
1775 add_trace("sample", NULL, "%s", cause_string);
1777 add_trace("display", NULL, "%s", display);
1779 new_state(EPOINT_STATE_OUT_DISCONNECT);
1780 set_tone(portlist, cause_string);
1781 if (!(rparam = routeparam(e_action, PARAM_CONNECT))) {
1782 message_disconnect_port(portlist, cause, location, display);
1784 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1785 SCPY(message->param.notifyinfo.display, display);
1786 message_put(message);
1787 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1794 * process dialing release
1796 void EndpointAppPBX::action_dialing_release(void)
1798 struct route_param *rparam;
1799 int cause = CAUSE_NORMAL; /* normal call clearing */
1800 int location = LOCATION_PRIVATE_LOCAL;
1801 char cause_string[256] = "", display[84] = "";
1803 /* check cause parameter */
1804 if ((rparam = routeparam(e_action, PARAM_CAUSE))) {
1805 cause = rparam->integer_value;
1806 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1808 if ((rparam = routeparam(e_action, PARAM_LOCATION))) {
1809 location = rparam->integer_value;
1810 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1814 /* use cause as sample, if not given later */
1815 SPRINT(cause_string, "cause_%02x", cause);
1818 if ((rparam = routeparam(e_action, PARAM_DISPLAY))) {
1819 SCPY(display, rparam->string_value);
1820 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1823 /* disconnect only if connect parameter is not given */
1824 trace_header("ACTION release", DIRECTION_NONE);
1825 add_trace("cause", "value", "%d", cause);
1826 add_trace("cause", "location", "%d", location);
1828 add_trace("display", NULL, "%s", display);
1831 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, location, cause, 1);
1836 * process dialing help
1838 void EndpointAppPBX::action_dialing_help(void)
1840 /* show all things that would match */
1842 struct numbering *numbering = numbering_int;
1843 char dialing[sizeof(e_dialinginfo.id)];
1845 struct lcr_msg *message;
1846 struct route_param *rparam;
1848 /* in case we have no menu (this should never happen) */
1853 if (strchr(e_dialinginfo.id,'*')) {
1855 e_dialinginfo.id[0] = '\0';
1857 if (strchr(e_dialinginfo.id,'#')) {
1859 e_dialinginfo.id[0] = '\0';
1862 /* get position in menu */
1864 /* get last menu position */
1866 while(numbering->next) {
1868 numbering = numbering->next;
1871 /* get menu position */
1874 numbering = numbering->next;
1877 numbering = numbering_int;
1884 /* if we dial something else we need to add the prefix and change the action */
1885 if (e_dialinginfo.id[0]) {
1886 e_action = NUMB_ACTION_NONE;
1887 SCPY(dialing, numbering->prefix);
1888 //we ignore the first digit after selecting
1889 //SCAT(dialing, e_dialinginfo.id);
1890 SCPY(e_dialinginfo.id, dialing);
1891 e_extdialing = e_dialinginfo.id+strlen(numbering->prefix);
1892 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);
1898 /* send display message to port */
1899 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1900 SPRINT(message->param.notifyinfo.display, ">%s %s%s%s", numbering->prefix, numb_actions[numbering->action], (numbering->param[0])?" ":"", numbering->param);
1901 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);
1902 message_put(message);
1903 logmessage(message->type, message->paramea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1909 * process dialing deflect
1911 void EndpointAppPBX::action_dialing_deflect(void)
1917 * process dialing setforward
1919 void EndpointAppPBX::action_dialing_setforward(void)
1924 * process init 'execute'
1926 void EndpointAppPBX::action_init_execute(void)
1928 struct route_param *rparam;
1929 int executeon = INFO_ON_HANGUP; /* Use Hangup as a default for compatibility */
1931 /* Get the execute on parameter */
1932 if ((rparam = routeparam(e_action, PARAM_ON)))
1933 executeon = rparam->integer_value;
1935 /* Execute this action if init was specified */
1936 if (executeon == INFO_ON_INIT) {
1937 trace_header("ACTION execute ON init", DIRECTION_NONE);
1944 * process hangup 'execute'
1946 void EndpointAppPBX::action_hangup_execute(void)
1948 struct route_param *rparam;
1949 int executeon = INFO_ON_HANGUP; /* Use Hangup as a default for compatibility */
1951 /* Get the execute on parameter */
1952 if ((rparam = routeparam(e_action, PARAM_ON)))
1953 executeon = rparam->integer_value;
1955 /* Execute this action if init was specified */
1956 if (executeon == INFO_ON_HANGUP) {
1957 trace_header("ACTION execute ON hangup", DIRECTION_NONE);
1964 * process 'execute' from action_init_execute or action_hangup_execute
1966 void EndpointAppPBX::action_execute(void)
1968 struct route_param *rparam;
1972 char *command = (char *)"";
1974 char *argv[12]; /* check also number of args below */
1977 /* get script / command */
1978 if ((rparam = routeparam(e_action, PARAM_EXECUTE)))
1979 command = rparam->string_value;
1980 if (command[0] == '\0') {
1981 trace_header("ACTION execute (no parameter given)", DIRECTION_NONE);
1986 argv[i++] = (char *)"/bin/sh";
1987 argv[i++] = (char *)"-c";
1988 argv[i++] = command;
1990 argv[i++] = command;
1991 if ((rparam = routeparam(e_action, PARAM_PARAM))) {
1992 argv[i++] = rparam->string_value;
1994 argv[i++] = e_extdialing;
1995 argv[i++] = (char *)numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international);
1996 argv[i++] = e_callerinfo.extension;
1997 argv[i++] = e_callerinfo.name;
1998 SPRINT(isdn_port, "%d", e_callerinfo.isdn_port);
1999 argv[i++] = isdn_port;
2000 argv[i++] = e_callerinfo.imsi;
2001 argv[i++] = NULL; /* check also number of args above */
2002 switch (pid = fork ()) {
2004 trace_header("ACTION execute (fork failed)", DIRECTION_NONE);
2008 /* To be shure there are no zombies created double fork */
2009 if ((pid2 = fork()) == 0) {
2010 execve(command, argv, environ);
2012 /* Exit immediately and release the waiting parent. The subprocess falls to init because the parent died */
2016 trace_header("ACTION execute", DIRECTION_NONE);
2017 add_trace("command", NULL, "%s", command);
2020 /* Wait for the pid. The forked process will exit immediately so there is no problem waiting. */
2021 waitpid(pid, &iWaitStatus, 0);
2028 * process hangup 'file'
2030 void EndpointAppPBX::action_hangup_file(void)
2032 struct route_param *rparam;
2033 const char *file, *content, *mode;
2036 /* get file / content */
2037 if (!(rparam = routeparam(e_action, PARAM_FILE)))
2038 file = rparam->string_value;
2041 if (!(rparam = routeparam(e_action, PARAM_CONTENT)))
2042 content = rparam->string_value;
2044 content = e_extdialing;
2045 if (!(rparam = routeparam(e_action, PARAM_APPEND)))
2049 if (file[0] == '\0') {
2050 trace_header("ACTION file (no filename given)", DIRECTION_NONE);
2054 if (!(fp = fopen(file, mode))) {
2055 trace_header("ACTION file (failed to open)", DIRECTION_NONE);
2056 add_trace("file", "name", "%s", file);
2057 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2061 trace_header("ACTION file", DIRECTION_NONE);
2062 add_trace("file", "name", "%s", file);
2063 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2064 add_trace("content", NULL, "%s", content);
2066 fprintf(fp, "%s\n", content);
2072 * process init 'pick'
2074 void EndpointAppPBX::action_init_pick(void)
2076 struct route_param *rparam;
2077 char *extensions = NULL;
2079 if ((rparam = routeparam(e_action, PARAM_EXTENSIONS)))
2080 extensions = rparam->string_value;
2082 trace_header("ACTION pick", DIRECTION_NONE);
2083 if (extensions) if (extensions[0])
2084 add_trace("extensions", NULL, "%s", extensions);
2086 pick_join(extensions);
2091 * process dialing 'password'
2093 void EndpointAppPBX::action_dialing_password(void)
2095 struct port_list *portlist = ea_endpoint->ep_portlist;
2097 /* prompt for password */
2098 if (e_extdialing[0] == '\0') {
2099 /* give password tone */
2100 set_tone(portlist, "password");
2102 if (e_extdialing[1] == '\0') {
2103 /* give password tone */
2104 set_tone(portlist, "dialing");
2107 /* wait until all digits are dialed */
2108 if (strlen(e_ext.password) != strlen(e_extdialing))
2109 return; /* more digits needed */
2111 /* check the password */
2112 if (e_ext.password[0]=='\0' || (strlen(e_ext.password)==strlen(e_extdialing) && !!strcmp(e_ext.password,e_extdialing))) {
2113 trace_header("ACTION password_write (wrong password)", DIRECTION_NONE);
2114 add_trace("dialed", NULL, "%s", e_extdialing);
2116 e_connectedmode = 0;
2118 new_state(EPOINT_STATE_OUT_DISCONNECT);
2119 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2120 set_tone(portlist, "cause_10");
2124 /* write caller id if ACTION_PASSWORD_WRITE was selected */
2126 if (e_action->index == ACTION_PASSWORD_WRITE) {
2127 append_callbackauth(e_ext.number, &e_callbackinfo);
2128 trace_header("ACTION password_write (written)", DIRECTION_NONE);
2129 add_trace("dialed", NULL, "%s", e_extdialing);
2133 /* make call state */
2134 new_state(EPOINT_STATE_IN_OVERLAP);
2135 e_ruleset = ruleset_main;
2137 e_rule = e_ruleset->rule_first;
2139 e_dialinginfo.id[0] = '\0';
2140 e_extdialing = e_dialinginfo.id;
2141 set_tone(portlist, "dialpbx");
2144 void EndpointAppPBX::action_dialing_password_wr(void)
2146 action_dialing_password();
2150 /* general process dialing of incoming call
2151 * depending on the detected prefix, subfunctions above (action_*) will be
2154 void EndpointAppPBX::process_dialing(int timeout)
2156 struct port_list *portlist = ea_endpoint->ep_portlist;
2157 struct lcr_msg *message;
2158 struct route_param *rparam;
2159 struct timeval current_time;
2161 /* set if timeout is active, or if timeout value was given due to timeout action */
2162 if (e_action_timeout.active)
2165 //#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.
2166 //PDEBUG(~0, "HANG-BUG-DEBUGGING: entered porcess_dialing\n");
2167 portlist = ea_endpoint->ep_portlist;
2168 /* check if we have a port instance linked to our epoint */
2171 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);
2172 unsched_timer(&e_action_timeout);
2173 unsched_timer(&e_match_timeout);
2176 if (portlist->next) {
2177 goto portlist_error;
2180 /* check nesting levels */
2181 if (++e_rule_nesting > RULE_NESTING) {
2182 trace_header("ACTION (nesting too deep)", DIRECTION_NONE);
2183 add_trace("max-levels", NULL, "%d", RULE_NESTING);
2185 new_state(EPOINT_STATE_OUT_DISCONNECT);
2186 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2187 set_tone(portlist, "cause_3f");
2188 unsched_timer(&e_action_timeout);
2189 unsched_timer(&e_match_timeout);
2193 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before action-timeout processing\n");
2194 /* process timeout */
2195 if (e_action && timeout) { /* e_action may be NULL, but e_action_timeout may still be set and must be ignored */
2196 unsched_timer(&e_action_timeout);
2197 if (e_state == EPOINT_STATE_CONNECT) {
2198 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);
2201 if (e_action->index == ACTION_DISCONNECT
2202 || e_state == EPOINT_STATE_OUT_DISCONNECT) {
2203 /* release after disconnect */
2204 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0);
2207 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0, 0);
2208 e_action = e_action->next;
2210 /* nothing more, so we release */
2211 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action timed out, and we have no next action, so we disconnect.\n", ea_endpoint->ep_serial);
2212 new_state(EPOINT_STATE_OUT_DISCONNECT);
2213 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2214 set_tone(portlist, "cause_3f");
2217 goto action_timeout;
2220 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before setup/overlap state checking\n");
2221 if (e_state!=EPOINT_STATE_IN_SETUP
2222 && e_state!=EPOINT_STATE_IN_OVERLAP) {
2223 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);
2224 unsched_timer(&e_match_timeout);
2229 /* check if we do menu selection */
2230 if (e_action==NUMB_ACTION_NONE && (e_dialinginfo.id[0]=='*' || e_dialinginfo.id[0]=='#'))
2231 /* do menu selection */
2232 if (e_ext.display_menu) {
2233 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 */
2234 e_dialinginfo.id[0] = '\0';
2235 e_action = NUMB_ACTION_MENU;
2238 unsched_timer(&e_match_timeout);
2241 /* invalid dialing */
2242 message_disconnect_port(portlist, CAUSE_INCALID, LOCATION_PRIVATE_LOCAL, "");
2243 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
2244 message->param.disconnectinfo.cause = CAUSE_INVALID;
2245 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2247 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2248 SCPY(message->param.notifyinfo.display,get_isdn_cause(LOCATION_PRIVATE_LOCAL, epoint->e_ext.display_cause, param->disconnectinfo.location, param->disconnectinfo.cause));
2250 message_put(message);
2251 logmessage(message->type, message->param, portlist->port_id, DIRECTION_OUT);
2253 new_state(EPOINT_STATE_OUT_DISCONNECT);
2254 set_tone(portlist,"cause_1c");
2255 unsched_timer(&e_match_timeout);
2260 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before e_action==NULL\n");
2261 /* if no action yet, we will call try to find a matching rule */
2263 /* be sure that all selectors are initialized */
2266 /* check for external call */
2267 if (!strncmp(e_dialinginfo.id, "extern:", 7)) {
2268 e_extdialing = e_dialinginfo.id+7;
2269 e_action = &action_external;
2270 goto process_action;
2272 /* check for internal call */
2273 if (!strncmp(e_dialinginfo.id, "intern:", 7)) {
2274 e_extdialing = e_dialinginfo.id+7;
2275 e_action = &action_internal;
2276 goto process_action;
2278 /* check for chan call */
2279 if (!strncmp(e_dialinginfo.id, "remote:", 7)) {
2280 e_extdialing = e_dialinginfo.id+7;
2281 e_action = &action_remote;
2282 goto process_action;
2284 /* check for vbox call */
2285 if (!strncmp(e_dialinginfo.id, "vbox:", 5)) {
2286 e_extdialing = e_dialinginfo.id+5;
2287 e_action = &action_vbox;
2288 goto process_action;
2291 gettimeofday(¤t_time, NULL);
2292 if (e_match_to_action && TIME_SMALLER(&e_match_timeout.timeout, ¤t_time)) {
2293 /* return timeout rule */
2294 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);
2295 unsched_timer(&e_match_timeout);
2296 e_action = e_match_to_action;
2297 e_match_to_action = NULL;
2298 e_extdialing = e_match_to_extdialing;
2299 trace_header("ROUTING (timeout)", DIRECTION_NONE);
2300 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2301 add_trace("line", NULL, "%d", e_action->line);
2304 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before routing\n");
2305 /* check for matching rule */
2306 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);
2308 e_action = route(e_ruleset);
2310 trace_header("ACTION (match)", DIRECTION_NONE);
2311 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2312 add_trace("line", NULL, "%d", e_action->line);
2316 e_action = &action_disconnect;
2318 trace_header("ACTION (no main ruleset, disconnecting)", DIRECTION_NONE);
2322 //PDEBUG(~0, "HANG-BUG-DEBUGGING: after routing\n");
2325 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): no rule within the current ruleset matches yet.\n", ea_endpoint->ep_serial, e_ext.number);
2330 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): a rule with action '%s' matches.\n", ea_endpoint->ep_serial, action_defs[e_action->index].name);
2335 unsched_timer(&e_action_timeout);
2336 if (e_action->timeout) {
2337 schedule_timer(&e_action_timeout, e_action->timeout, 0);
2338 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action has a timeout of %d secods.\n", ea_endpoint->ep_serial, e_action->timeout);
2342 /* check param proceeding / alerting / connect */
2343 if ((rparam = routeparam(e_action, PARAM_CONNECT))) {
2344 /* NOTE: we may not change our state to connect, because dialing will then not possible */
2346 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2347 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
2348 message_put(message);
2349 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2351 if ((rparam = routeparam(e_action, PARAM_ALERTING))) {
2352 /* NOTE: we may not change our state to alerting, because dialing will then not possible */
2353 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2354 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
2355 message_put(message);
2356 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2358 if ((rparam = routeparam(e_action, PARAM_PROCEEDING))) {
2359 /* NOTE: we may not change our state to proceeding, because dialing will then not possible */
2360 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2361 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
2362 message_put(message);
2363 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2366 if (action_defs[e_action->index].init_func) {
2367 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);
2368 (this->*(action_defs[e_action->index].init_func))();
2370 if (e_state!=EPOINT_STATE_IN_SETUP
2371 && e_state!=EPOINT_STATE_IN_OVERLAP) {
2372 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);
2373 goto display_action;
2377 /* show what we are doing */
2378 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);
2379 /* go to action's dialing function */
2380 if (action_defs[e_action->index].dialing_func) {
2381 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);
2382 (this->*(action_defs[e_action->index].dialing_func))();
2385 /* display selected dialing action if enabled and still in setup state */
2388 if (e_action->index==ACTION_MENU
2389 || e_action->index==ACTION_REDIAL
2390 || e_action->index==ACTION_REPLY
2391 || e_action->index==ACTION_TIMER
2392 || e_action->index==ACTION_CALCULATOR
2393 || e_action->index==ACTION_TEST)
2397 if (!e_ext.display_dialing)
2399 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*/)
2400 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 */
2401 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2404 SPRINT(message->param.notifyinfo.display, "> %s", e_dialinginfo.id);
2406 SPRINT(message->param.notifyinfo.display, "%s%s%s", action_defs[e_action->index].name, (e_extdialing[0])?" ":"", e_extdialing);
2409 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s'\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
2410 message_put(message);
2411 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2420 /* some services store information after hangup */
2421 void EndpointAppPBX::process_hangup(int cause, int location)
2423 char callertext[256], dialingtext[256];
2424 int writeext = 0, i;
2426 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s'\n", ea_endpoint->ep_serial, e_ext.number);
2427 if (e_ext.number[0]) {
2428 if (read_extension(&e_ext, e_ext.number))
2437 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);
2438 switch(e_dialinginfo.itype) {
2439 case INFO_ITYPE_CHAN:
2440 SPRINT(dialingtext, "chan:%s", e_dialinginfo.id);
2442 case INFO_ITYPE_ISDN_EXTENSION:
2443 SPRINT(dialingtext, "intern:%s", e_dialinginfo.id);
2445 case INFO_ITYPE_VBOX:
2446 SPRINT(dialingtext, "vbox:%s", e_dialinginfo.id);
2449 SPRINT(dialingtext, "%s", e_dialinginfo.id);
2452 if (e_callerinfo.id[0])
2453 SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2455 SPRINT(callertext, "unknown");
2456 /* allpy restriction */
2457 if (!e_ext.anon_ignore && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
2458 SPRINT(callertext, "anonymous");
2459 if (e_callerinfo.extension[0]) /* add intern if present */
2460 UNPRINT(strchr(callertext,'\0'), sizeof(callertext)-1+strlen(callertext), " (intern %s)", e_callerinfo.extension);
2461 write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location);
2463 /* store last received call for reply-list */
2464 if (e_origin == 1) // outgoing to phone is incoming for user
2465 if (e_callerinfo.id[0] || e_callerinfo.extension[0])
2466 if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED) {
2467 if (e_callerinfo.extension[0])
2468 SPRINT(callertext, "intern:%s", e_callerinfo.extension);
2470 SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
2471 if (!!strcmp(callertext, e_ext.last_in[0])) {
2474 UCPY(e_ext.last_in[i], e_ext.last_in[i-1]);
2477 SCPY(e_ext.last_in[0], callertext);
2478 writeext |= 1; /* store extension later */
2479 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]);
2481 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);
2484 /* store last made call for reply-list */
2485 if (e_origin == 0) // incoming from phone is outgoing for user
2486 if (e_dialinginfo.id[0]) {
2487 if (!!strcmp(e_dialinginfo.id, e_ext.last_out[0])) {
2490 UCPY(e_ext.last_out[i], e_ext.last_out[i-1]);
2493 SCPY(e_ext.last_out[0], e_dialinginfo.id);
2494 writeext |= 1; /* store extension later */
2495 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
2497 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);
2500 /* write extension if needed */
2501 if (writeext == 0x11)
2502 write_extension(&e_ext, e_ext.number);
2505 if (action_defs[e_action->index].hangup_func) {
2506 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);
2507 (this->*(action_defs[e_action->index].hangup_func))();