1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** all actions (and hangup) are processed here **
10 \*****************************************************************************/
18 #include "linux/isdnif.h"
20 extern char **environ;
23 /* create caller id from digits by comparing with national and international
26 char *nationalize_callerinfo(char *string, int *ntype)
28 if (!strncmp(options.international, string, strlen(options.international)))
30 *ntype = INFO_NTYPE_INTERNATIONAL;
31 return(string+strlen(options.international));
33 if (!strncmp(options.national, string, strlen(options.national)))
35 *ntype = INFO_NTYPE_NATIONAL;
36 return(string+strlen(options.national));
38 *ntype = INFO_NTYPE_SUBSCRIBER;
42 /* create number (including access codes) from caller id
45 char *numberrize_callerinfo(char *string, int ntype)
47 static char result[256];
51 case INFO_NTYPE_INTERNATIONAL:
52 UCPY(result, options.international);
57 case INFO_NTYPE_NATIONAL:
58 UCPY(result, options.national);
70 * process init 'internal' / 'external' / 'asterisk' / 'vbox-record' / 'partyline'...
72 void EndpointAppPBX::_action_init_call(int asterisk)
75 struct port_list *portlist = ea_endpoint->ep_portlist;
76 struct admin_list *admin;
78 /* a created call, this should never happen */
79 if (ea_endpoint->ep_join_id)
81 if (options.deb & DEBUG_EPOINT)
82 PERROR("EPOINT(%d): We already have a call instance, this should never happen!\n", ea_endpoint->ep_serial);
87 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new call instance.\n", ea_endpoint->ep_serial);
99 /* resource not available */
100 message_disconnect_port(portlist, CAUSE_RESSOURCEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
101 new_state(EPOINT_STATE_OUT_DISCONNECT);
102 set_tone(portlist,"cause_22");
105 join = new JoinAsterisk(ea_endpoint->ep_serial);
108 join = new JoinPBX(ea_endpoint);
110 FATAL("No memoy for Call instance.\n");
111 ea_endpoint->ep_join_id = join->c_serial;
113 void EndpointAppPBX::action_init_call(void)
115 _action_init_call(0);
117 void EndpointAppPBX::action_init_chan(void)
119 _action_init_call(1);
123 * process dialing 'internal'
125 void EndpointAppPBX::action_dialing_internal(void)
127 struct capa_info capainfo;
128 struct caller_info callerinfo;
129 struct redir_info redirinfo;
130 struct dialing_info dialinginfo;
131 struct port_list *portlist = ea_endpoint->ep_portlist;
132 struct message *message;
133 struct extension ext;
134 struct route_param *rparam;
136 /* send proceeding, because number is complete */
137 set_tone(portlist, "proceeding");
138 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
139 message_put(message);
140 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
141 new_state(EPOINT_STATE_IN_PROCEEDING);
143 /* create bearer/caller/dialinginfo */
144 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
145 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
146 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
147 memset(&dialinginfo, 0, sizeof(dialinginfo));
148 dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
149 SCPY(dialinginfo.id, e_dialinginfo.id);
151 /* process extension */
152 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
153 SCPY(dialinginfo.id, rparam->string_value);
155 /* process number type */
156 if ((rparam = routeparam(e_action, PARAM_TYPE)))
157 dialinginfo.ntype = rparam->integer_value;
159 /* process service */
160 if ((rparam = routeparam(e_action, PARAM_CAPA)))
162 capainfo.bearer_capa = rparam->integer_value;
163 if (capainfo.bearer_capa != INFO_BC_SPEECH
164 && capainfo.bearer_capa != INFO_BC_AUDIO)
166 capainfo.bearer_mode = INFO_BMODE_PACKET;
168 capainfo.bearer_info1 = INFO_INFO1_NONE;
170 if ((rparam = routeparam(e_action, PARAM_BMODE)))
172 capainfo.bearer_mode = rparam->integer_value;
174 if ((rparam = routeparam(e_action, PARAM_INFO1)))
176 capainfo.bearer_info1 = rparam->integer_value;
178 if ((rparam = routeparam(e_action, PARAM_HLC)))
180 capainfo.hlc = rparam->integer_value;
182 if ((rparam = routeparam(e_action, PARAM_EXTHLC)))
184 capainfo.exthlc = rparam->integer_value;
187 /* process presentation */
188 if ((rparam = routeparam(e_action, PARAM_PRESENT)))
190 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
193 /* check if extension exists AND only if not multiple extensions */
194 if (!read_extension(&ext, dialinginfo.id) && !strchr(dialinginfo.id,','))
196 trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE);
197 add_trace("extension", NULL, dialinginfo.id);
199 new_state(EPOINT_STATE_OUT_DISCONNECT);
200 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
201 set_tone(portlist, "cause_86");
204 /* check if internal calls are denied */
205 if (e_ext.rights < 1)
207 trace_header("ACTION extension (dialing to extension denied)", DIRECTION_NONE);
208 add_trace("extension", NULL, dialinginfo.id);
210 new_state(EPOINT_STATE_OUT_DISCONNECT);
211 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
212 set_tone(portlist, "cause_81");
216 /* add or update internal call */
217 trace_header("ACTION extension (calling)", DIRECTION_NONE);
218 add_trace("extension", NULL, dialinginfo.id);
220 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
221 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
222 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
223 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
224 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
225 message_put(message);
228 /* process dialing external
230 void EndpointAppPBX::action_dialing_external(void)
232 struct capa_info capainfo;
233 struct caller_info callerinfo;
234 struct redir_info redirinfo;
235 struct dialing_info dialinginfo;
237 struct port_list *portlist = ea_endpoint->ep_portlist;
238 struct message *message;
239 struct route_param *rparam;
241 /* special processing of delete characters '*' and '#' */
242 if (e_ext.delete_ext)
244 /* dialing a # causes a clearing of complete number */
245 if (strchr(e_extdialing, '#'))
247 e_extdialing[0] = '\0';
248 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);
250 /* eliminate digits before '*', which is a delete digit
252 if (strchr(e_extdialing, '*'))
255 while((p=strchr(e_extdialing, '*')))
257 if (p > e_extdialing) /* only if there is a digit in front */
262 UCPY(p, p+1); /* remove '*' */
264 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s deleted digits and got new string: %s\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing);
268 /* create bearer/caller/dialinginfo */
269 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
270 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
271 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
272 memset(&dialinginfo, 0, sizeof(dialinginfo));
273 dialinginfo.itype = INFO_ITYPE_ISDN;
274 dialinginfo.sending_complete = 0;
275 SCPY(dialinginfo.id, e_extdialing);
278 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
279 SPRINT(dialinginfo.id, "%s%s", rparam->string_value, e_extdialing);
281 /* process number complete */
282 if ((rparam = routeparam(e_action, PARAM_COMPLETE)))
283 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
284 SCPY(dialinginfo.id, rparam->string_value);
285 dialinginfo.sending_complete = 1;
287 /* process number type */
288 if ((rparam = routeparam(e_action, PARAM_TYPE)))
289 dialinginfo.ntype = rparam->integer_value;
291 /* process service */
292 if ((rparam = routeparam(e_action, PARAM_CAPA)))
294 capainfo.bearer_capa = rparam->integer_value;
295 if (capainfo.bearer_capa != INFO_BC_SPEECH
296 && capainfo.bearer_capa != INFO_BC_AUDIO)
298 capainfo.bearer_mode = INFO_BMODE_PACKET;
300 capainfo.bearer_info1 = INFO_INFO1_NONE;
302 if ((rparam = routeparam(e_action, PARAM_BMODE)))
304 capainfo.bearer_mode = rparam->integer_value;
306 if ((rparam = routeparam(e_action, PARAM_INFO1)))
308 capainfo.bearer_info1 = rparam->integer_value;
310 if ((rparam = routeparam(e_action, PARAM_HLC)))
312 capainfo.hlc = rparam->integer_value;
314 if ((rparam = routeparam(e_action, PARAM_EXTHLC)))
316 capainfo.exthlc = rparam->integer_value;
320 /* process callerid */
321 if ((rparam = routeparam(e_action, PARAM_CALLERID)))
323 SCPY(callerinfo.id, rparam->string_value);
325 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
327 callerinfo.ntype = rparam->integer_value;
330 /* process presentation */
331 if ((rparam = routeparam(e_action, PARAM_PRESENT)))
333 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
336 /* process interfaces */
337 if ((rparam = routeparam(e_action, PARAM_INTERFACES)))
338 SCPY(dialinginfo.interfaces, rparam->string_value);
340 /* check if local calls are denied */
341 if (e_ext.rights < 2)
343 trace_header("ACTION extern (calling denied)", DIRECTION_NONE);
345 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0);
346 set_tone(portlist, "cause_82");
348 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
349 new_state(EPOINT_STATE_OUT_DISCONNECT);
353 if (!strncmp(dialinginfo.id, options.national, strlen(options.national))
354 || dialinginfo.ntype == INFO_NTYPE_NATIONAL
355 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL)
357 /* check if national calls are denied */
358 if (e_ext.rights < 3)
360 trace_header("ACTION extern (national calls denied)", DIRECTION_NONE);
362 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0);
363 set_tone(portlist, "cause_83");
368 if (!strncmp(dialinginfo.id, options.international, strlen(options.international))
369 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL)
371 /* check if international calls are denied */
372 if (e_ext.rights < 4)
374 trace_header("ACTION extern (international calls denied)", DIRECTION_NONE);
376 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0);
377 set_tone(portlist, "cause_84");
382 /* add or update outgoing call */
383 trace_header("ACTION extern (calling)", DIRECTION_NONE);
384 add_trace("number", NULL, dialinginfo.id);
385 if (dialinginfo.interfaces[0])
386 add_trace("interfaces", NULL, dialinginfo.interfaces);
388 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
389 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
390 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
391 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
392 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
393 message_put(message);
397 void EndpointAppPBX::action_dialing_chan(void)
399 struct port_list *portlist = ea_endpoint->ep_portlist;
401 trace_header("ACTION channel (not implemented)", DIRECTION_NONE);
403 message_disconnect_port(portlist, CAUSE_UNIMPLEMENTED, LOCATION_PRIVATE_LOCAL, "");
404 new_state(EPOINT_STATE_OUT_DISCONNECT);
405 set_tone(portlist,"cause_4f");
410 * process dialing the "am" and record
412 void EndpointAppPBX::action_dialing_vbox_record(void)
414 struct dialing_info dialinginfo;
415 struct port_list *portlist = ea_endpoint->ep_portlist;
416 struct message *message;
417 struct extension ext;
418 struct route_param *rparam;
420 portlist = ea_endpoint->ep_portlist;
422 /* check for given extension */
423 if (!(rparam = routeparam(e_action, PARAM_EXTENSION)))
425 trace_header("ACTION vbox-record (no extension given by parameter)", DIRECTION_NONE);
428 new_state(EPOINT_STATE_OUT_DISCONNECT);
429 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
430 set_tone(portlist, "cause_3f");
434 /* check if extension exists */
435 if (!read_extension(&ext, rparam->string_value))
437 trace_header("ACTION vbox-record (given extension does not exists)", DIRECTION_NONE);
438 add_trace("extension", NULL, "%s", rparam->string_value);
440 new_state(EPOINT_STATE_OUT_DISCONNECT);
441 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
442 set_tone(portlist, "cause_86");
446 /* check if internal calls are denied */
447 if (e_ext.rights < 1)
449 trace_header("ACTION vbox-record (internal calls are denied)", DIRECTION_NONE);
451 new_state(EPOINT_STATE_OUT_DISCONNECT);
452 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
453 set_tone(portlist, "cause_81");
457 set_tone(portlist, "proceeding");
458 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
459 message_put(message);
460 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
461 new_state(EPOINT_STATE_IN_PROCEEDING);
463 memset(&dialinginfo, 0, sizeof(dialinginfo));
464 dialinginfo.itype = INFO_ITYPE_VBOX;
465 dialinginfo.sending_complete = 1;
466 SCPY(dialinginfo.id, rparam->string_value);
468 /* append special announcement (if given) */
469 if ((rparam = routeparam(e_action, PARAM_ANNOUNCEMENT)))
470 if (rparam->string_value[0])
472 SCAT(dialinginfo.id, ",");
473 SCAT(dialinginfo.id, rparam->string_value);
476 /* add or update internal call */
477 trace_header("ACTION vbox-record (calling)", DIRECTION_NONE);
478 add_trace("extension", NULL, "%s", dialinginfo.id);
480 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
481 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
482 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
483 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
484 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
485 message_put(message);
492 void EndpointAppPBX::action_init_partyline(void)
495 class JoinPBX *joinpbx;
496 struct port_list *portlist = ea_endpoint->ep_portlist;
497 struct message *message;
498 struct route_param *rparam;
500 struct join_relation *relation;
502 portlist = ea_endpoint->ep_portlist;
504 /* check for given extension */
505 if (!(rparam = routeparam(e_action, PARAM_ROOM)))
507 trace_header("ACTION partyline (no room parameter)", DIRECTION_NONE);
510 new_state(EPOINT_STATE_OUT_DISCONNECT);
511 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
512 set_tone(portlist, "cause_3f");
515 if (rparam->integer_value <= 0)
517 trace_header("ACTION partyline (illegal room parameter)", DIRECTION_NONE);
518 add_trace("room", NULL, "%d", rparam->integer_value);
520 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): invalid value for 'room'.\n", ea_endpoint->ep_serial);
523 partyline = rparam->integer_value;
525 /* don't create join if partyline exists */
529 if (join->c_type == JOIN_TYPE_PBX)
531 joinpbx = (class JoinPBX *)join;
532 if (joinpbx->c_partyline == rparam->integer_value)
540 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
541 if (!(join = new JoinPBX(ea_endpoint)))
542 FATAL("No memory for join object\n");
545 //NOTE: joinpbx must be set here
546 /* add relation to existing join */
547 if (!(relation=joinpbx->add_relation()))
548 FATAL("No memory for join relation\n");
549 relation->type = RELATION_TYPE_SETUP;
550 relation->channel_state = CHANNEL_STATE_CONNECT;
551 relation->rx_state = NOTIFY_STATE_ACTIVE;
552 relation->tx_state = NOTIFY_STATE_ACTIVE;
553 relation->epoint_id = ea_endpoint->ep_serial;
556 ea_endpoint->ep_join_id = join->c_serial;
558 set_tone(portlist, "proceeding");
559 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
560 message_put(message);
561 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
562 new_state(EPOINT_STATE_IN_PROCEEDING);
564 /* send setup to join */
565 trace_header("ACTION partyline (calling)", DIRECTION_NONE);
566 add_trace("room", NULL, "%d", partyline);
568 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
569 message->param.setup.partyline = partyline;
570 memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info));
571 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
572 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
573 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
574 message_put(message);
579 * process hangup of all calls
581 void EndpointAppPBX::action_hangup_call(void)
585 trace_header("ACTION hangup", DIRECTION_NONE);
588 if (e_ext.number[0] == '\0')
590 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last dialed number '%s' because caller is unknown (not internal).\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
593 if (!(read_extension(&e_ext, e_ext.number)))
595 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last dialed number '%s' because cannot read settings.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
598 if (e_dialinginfo.id[0] == '\0')
600 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last dialed number because nothing was dialed.\n", ea_endpoint->ep_serial, e_ext.number);
603 if (!strcmp(e_dialinginfo.id, e_ext.last_out[0]))
605 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last dialed number '%s' because it is identical with the last one.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
610 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
614 UCPY(e_ext.last_out[i], e_ext.last_out[i-1]);
617 SCPY(e_ext.last_out[0], e_dialinginfo.id);
619 /* write extension */
620 write_extension(&e_ext, e_ext.number);
625 * process dialing 'login'
627 void EndpointAppPBX::action_dialing_login(void)
629 struct port_list *portlist = ea_endpoint->ep_portlist;
630 struct message *message;
632 struct route_param *rparam;
634 /* extension parameter */
635 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
637 /* extension is given by parameter */
638 extension = rparam->string_value;
639 if (extension[0] == '\0')
641 if (!read_extension(&e_ext, extension))
643 trace_header("ACTION login (extension doesn't exist)", DIRECTION_NONE);
644 add_trace("extension", NULL, "%s", extension);
646 /* extension doesn't exist */
647 new_state(EPOINT_STATE_OUT_DISCONNECT);
648 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
649 set_tone(portlist, "cause_86");
654 /* extension must be given by dialstring */
655 extension = e_extdialing;
656 if (extension[0] == '\0')
658 if (!read_extension(&e_ext, extension))
660 trace_header("ACTION login (extension incomplete or does not exist)", DIRECTION_NONE);
661 add_trace("extension", NULL, "%s", extension);
667 /* we changed our extension */
668 SCPY(e_ext.number, extension);
669 new_state(EPOINT_STATE_CONNECT);
673 /* send connect with extension's caller id (COLP) */
674 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
675 SCPY(message->param.connectinfo.id, e_ext.callerid);
676 message->param.connectinfo.ntype = e_ext.callerid_type;
677 if (e_ext.callerid_present==INFO_PRESENT_ALLOWED && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
678 message->param.connectinfo.present = INFO_PRESENT_RESTRICTED;
679 else message->param.connectinfo.present = e_ext.callerid_present;
680 /* handle restricted caller ids */
681 apply_callerid_restriction(e_ext.anon_ignore, message->param.connectinfo.id, &message->param.connectinfo.ntype, &message->param.connectinfo.present, &message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name);
682 /* display callerid if desired for extension */
683 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));
684 message->param.connectinfo.ntype = e_ext.callerid_type;
685 message_put(message);
686 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
688 /* set our caller id */
689 SCPY(e_callerinfo.id, e_ext.callerid);
690 e_callerinfo.ntype = e_ext.callerid_type;
691 e_callerinfo.present = e_ext.callerid_present;
693 /* enable connectedmode */
697 if (!(rparam = routeparam(e_action, PARAM_NOPASSWORD)))
699 /* make call state to enter password */
700 trace_header("ACTION login (ask for password)", DIRECTION_NONE);
701 add_trace("extension", NULL, "%s", e_ext.number);
703 new_state(EPOINT_STATE_IN_OVERLAP);
706 e_action = &action_password;
708 e_match_to_action = NULL;
709 e_dialinginfo.id[0] = '\0';
710 e_extdialing = strchr(e_dialinginfo.id, '\0');
713 e_password_timeout = now+20;
719 /* make call state */
720 new_state(EPOINT_STATE_IN_OVERLAP);
721 e_ruleset = ruleset_main;
723 e_rule = e_ruleset->rule_first;
725 e_dialinginfo.id[0] = '\0';
726 e_extdialing = e_dialinginfo.id;
727 set_tone(portlist, "dialpbx");
733 * process init 'change_callerid'
735 void EndpointAppPBX::action_init_change_callerid(void)
737 struct port_list *portlist = ea_endpoint->ep_portlist;
739 if (!e_ext.change_callerid)
741 /* service not available */
742 trace_header("ACTION change-callerid (denied for this caller)", DIRECTION_NONE);
744 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
745 new_state(EPOINT_STATE_OUT_DISCONNECT);
746 set_tone(portlist,"cause_87");
751 /* process dialing callerid
753 void EndpointAppPBX::_action_callerid_calleridnext(int next)
755 struct port_list *portlist = ea_endpoint->ep_portlist;
756 struct route_param *rparam;
757 char buffer[64], *callerid;
758 char old_id[64] = "", new_id[64] = "";
759 int old_type=0, new_type=0, old_present=0, new_present=0;
761 if ((rparam = routeparam(e_action, PARAM_CALLERID)))
763 /* the caller ID is given by parameter */
764 callerid = rparam->string_value;
767 /* caller ID is dialed */
768 if (!strchr(e_extdialing, '#'))
770 /* no complete ID yet */
773 *strchr(e_extdialing, '#') = '\0';
774 callerid = e_extdialing;
777 /* given callerid type */
778 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
779 switch(rparam->integer_value)
781 case INFO_NTYPE_SUBSCRIBER:
782 SPRINT(buffer, "s%s", callerid);
785 case INFO_NTYPE_NATIONAL:
786 SPRINT(buffer, "n%s", callerid);
789 case INFO_NTYPE_INTERNATIONAL:
790 SPRINT(buffer, "i%s", callerid);
794 SPRINT(buffer, "%s", callerid);
799 /* caller id complete, dialing with new caller id */
800 /* write new parameters */
801 if (read_extension(&e_ext, e_ext.number))
803 old_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
804 old_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
805 SCPY(old_id, (!next)?e_ext.callerid:e_ext.id_next_call);
806 if (callerid[0] == '\0')
809 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
813 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_ALLOWED;
814 if ((rparam = routeparam(e_action, PARAM_PRESENT))) if (rparam->integer_value == 0)
815 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
816 if (e_ext.callerid_type == INFO_NTYPE_UNKNOWN) /* if callerid is unknown, the given id is not nationalized */
818 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, callerid);
819 (!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN;
822 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, nationalize_callerinfo(callerid,&((!next)?e_ext.callerid_type:e_ext.id_next_call_type)));
824 if (!next) e_ext.id_next_call_type = -1;
825 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);
827 new_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
828 new_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
829 SCPY(new_id, (!next)?e_ext.callerid:e_ext.id_next_call);
830 write_extension(&e_ext, e_ext.number);
833 /* function activated */
835 trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE);
837 trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE);
838 add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type));
839 add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
840 add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type));
841 add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
843 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
844 new_state(EPOINT_STATE_OUT_DISCONNECT);
845 set_tone(portlist,"activated");
848 /* process dialing callerid for all call
850 void EndpointAppPBX::action_dialing_callerid(void)
852 _action_callerid_calleridnext(0);
855 /* process dialing callerid for next call
857 void EndpointAppPBX::action_dialing_calleridnext(void)
859 _action_callerid_calleridnext(1);
864 * process init 'change_forward'
866 void EndpointAppPBX::action_init_change_forward(void)
868 struct port_list *portlist = ea_endpoint->ep_portlist;
870 if (!e_ext.change_forward)
872 trace_header("ACTION change-forward (denied for this caller)", DIRECTION_NONE);
874 /* service not available */
875 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
876 new_state(EPOINT_STATE_OUT_DISCONNECT);
877 set_tone(portlist,"cause_87");
882 /* process dialing forwarding
884 void EndpointAppPBX::action_dialing_forward(void)
886 struct port_list *portlist = ea_endpoint->ep_portlist;
887 int diversion = INFO_DIVERSION_CFU;
888 char *dest = e_extdialing;
889 struct route_param *rparam;
891 /* if diversion type is given */
892 if ((rparam = routeparam(e_action, PARAM_DIVERSION)))
893 diversion = rparam->integer_value;
895 if ((rparam = routeparam(e_action, PARAM_DEST)))
897 /* if destination is given */
898 dest = rparam->string_value;
901 if (!strchr(e_extdialing, '#'))
903 *strchr(e_extdialing, '#') = '\0';
907 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing forwarding to '%s'.\n", ea_endpoint->ep_serial, e_ext.number, dest);
908 if (read_extension(&e_ext, e_ext.number))
912 case INFO_DIVERSION_CFU:
913 trace_header("ACTION change-forward (new CFU=unconditional)", DIRECTION_NONE);
914 add_trace("destin'", NULL, "%s", dest);
916 SCPY(e_ext.cfu, dest);
918 case INFO_DIVERSION_CFB:
919 trace_header("ACTION change-forward (new CFB=busy)", DIRECTION_NONE);
920 add_trace("destin'", NULL, "%s", dest);
922 SCPY(e_ext.cfb, dest);
924 case INFO_DIVERSION_CFNR:
925 if ((rparam = routeparam(e_action, PARAM_DELAY)))
926 e_ext.cfnr_delay = rparam->integer_value;
927 trace_header("ACTION change-forward (new CFNR=no response)", DIRECTION_NONE);
928 add_trace("destin'", NULL, "%s", dest);
929 add_trace("delay", NULL, "%s", e_ext.cfnr_delay);
931 SCPY(e_ext.cfnr, dest);
933 case INFO_DIVERSION_CFP:
934 trace_header("ACTION change-forward (new CFP=parallel)", DIRECTION_NONE);
935 add_trace("destin'", NULL, "%s", dest);
937 SCPY(e_ext.cfp, dest);
940 write_extension(&e_ext, e_ext.number);
942 /* function (de)activated */
943 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
944 new_state(EPOINT_STATE_OUT_DISCONNECT);
946 set_tone(portlist,"activated");
948 set_tone(portlist,"deactivated");
952 /* process dialing redial
954 void EndpointAppPBX::action_init_redial_reply(void)
956 struct port_list *portlist = ea_endpoint->ep_portlist;
959 if (!e_ext.last_out[0])
961 trace_header("ACTION redial/reply (no last number stored)", DIRECTION_NONE);
963 new_state(EPOINT_STATE_OUT_DISCONNECT);
964 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
965 set_tone(portlist, "cause_3f");
970 /* process dialing redial
972 void EndpointAppPBX::_action_redial_reply(int in)
974 struct message *message;
976 struct route_param *rparam;
978 last = (in)?e_ext.last_in[0]:e_ext.last_out[0];
980 /* if no display is available */
981 if (!e_ext.display_menu)
983 if (ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_IN && ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_OUT)
986 /* if select is not given */
987 if (!(rparam = routeparam(e_action, PARAM_SELECT)))
991 if (e_extdialing[0]=='*' || e_extdialing[0]=='1')
993 /* find prev entry */
999 if (e_extdialing[0]=='#' || e_extdialing[0]=='3')
1001 /* find next entry */
1003 if (e_select >= MAX_REMEMBER)
1006 if (e_ext.last_in[e_select][0] == '\0')
1009 if (e_ext.last_out[e_select][0] == '\0')
1014 last = (in)?e_ext.last_in[e_select]:e_ext.last_out[e_select];
1015 if (e_extdialing[0]=='0' || e_extdialing[0]=='2')
1019 trace_header("ACTION reply (dialing)", DIRECTION_NONE);
1021 trace_header("ACTION redial (dialing)", DIRECTION_NONE);
1022 add_trace("number", NULL, "%s", last);
1023 add_trace("last but", NULL, "%d", e_select);
1025 SCPY(e_dialinginfo.id, last);
1026 e_extdialing = e_dialinginfo.id;
1031 e_extdialing[0] = '\0';
1033 /* send display message to port */
1034 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1035 if (!strncmp(last, "extern:", 7))
1036 SPRINT(message->param.notifyinfo.display, "(%d) %s ext", e_select+1, last+7);
1038 if (!strncmp(last, "intern:", 7))
1039 SPRINT(message->param.notifyinfo.display, "(%d) %s int", e_select+1, last+7);
1041 if (!strncmp(last, "chan:", 4))
1042 SPRINT(message->param.notifyinfo.display, "(%d) %s chan", e_select+1, last+5);
1044 if (!strncmp(last, "vbox:", 5))
1045 SPRINT(message->param.notifyinfo.display, "(%d) %s vbox", e_select+1, last+5);
1047 SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -");
1048 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
1049 message_put(message);
1050 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1053 /* process dialing redial
1055 void EndpointAppPBX::action_dialing_redial(void)
1057 _action_redial_reply(0);
1060 /* process dialing reply
1062 void EndpointAppPBX::action_dialing_reply(void)
1064 _action_redial_reply(1);
1068 /* dialing powerdialing delay
1070 void EndpointAppPBX::action_dialing_powerdial(void)
1072 struct port_list *portlist = ea_endpoint->ep_portlist;
1073 struct message *message;
1074 struct route_param *rparam;
1076 /* power dialing only possible if we have a last dialed number */
1077 if (!e_ext.last_out[0])
1079 trace_header("ACTION powerdial (no last number stored)", DIRECTION_NONE);
1081 new_state(EPOINT_STATE_OUT_DISCONNECT);
1082 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1083 set_tone(portlist, "cause_3f");
1088 if ((rparam = routeparam(e_action, PARAM_LIMIT)))
1090 e_powerlimit = rparam->integer_value;
1097 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1099 e_powerdelay = rparam->integer_value;
1102 /* delay incomplete */
1103 if (!strchr(e_extdialing, '#'))
1105 *strchr(e_extdialing, '#') = '\0';
1106 e_powerdelay = e_extdialing[0]?atoi(e_extdialing): 0;
1109 if (e_powerdelay < 1)
1111 trace_header("ACTION powerdial (dialing)", DIRECTION_NONE);
1112 add_trace("number", NULL, "%s", e_ext.last_out[0]);
1113 add_trace("delay", NULL, "%d", e_powerdelay);
1116 /* send connect to avoid overlap timeout */
1117 // new_state(EPOINT_STATE_CONNECT); connect may prevent further dialing
1118 if (e_ext.number[0])
1120 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1121 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1122 message_put(message);
1123 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1126 SCPY(e_dialinginfo.id, e_ext.last_out[0]);
1127 e_powerdialing = -1; /* indicates the existence of powerdialing but no redial time given */
1136 void EndpointAppPBX::action_dialing_callback(void)
1138 struct port_list *portlist = ea_endpoint->ep_portlist;
1139 struct route_param *rparam;
1140 struct extension cbext;
1142 portlist = ea_endpoint->ep_portlist;
1144 /* check given extension */
1145 if (!(rparam = routeparam(e_action, PARAM_EXTENSION)))
1148 trace_header("ACTION callback (no extension defined)", DIRECTION_NONE);
1152 new_state(EPOINT_STATE_OUT_DISCONNECT);
1153 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1154 set_tone(portlist, "cause_3f");
1156 e_cbcaller[0] = e_cbdialing[0] = '\0';
1160 /* if extension is given */
1161 SCPY(e_cbcaller, rparam->string_value);
1162 if (e_cbcaller[0] == '\0')
1165 /* read callback extension */
1166 memset(&cbext, 0, sizeof(cbext));
1167 if (!read_extension(&cbext, e_cbcaller))
1169 trace_header("ACTION callback (extension doesn't exist)", DIRECTION_NONE);
1170 add_trace("extension", NULL, "%s", e_cbcaller);
1175 /* if password is not given */
1176 if (cbext.password[0] == '\0')
1178 trace_header("ACTION callback (no password set)", DIRECTION_NONE);
1179 add_trace("extension", NULL, "%s", e_cbcaller);
1184 /* callback only possible if callerid exists OR it is given */
1185 if ((rparam = routeparam(e_action, PARAM_CALLTO)))
1186 SCPY(e_cbto, rparam->string_value);
1189 trace_header("ACTION callback (alternative caller id)", DIRECTION_NONE);
1190 add_trace("extension", NULL, "%s", e_cbcaller);
1191 add_trace("callerid", NULL, "%s", e_cbto);
1193 SCPY(e_callerinfo.id, e_cbto);
1194 e_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
1195 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1197 if (e_callerinfo.id[0]=='\0' || e_callerinfo.present==INFO_PRESENT_NOTAVAIL)
1199 trace_header("ACTION callback (no caller ID available)", DIRECTION_NONE);
1200 add_trace("extension", NULL, "%s", e_cbcaller);
1205 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1210 * process hangup 'callback'
1212 void EndpointAppPBX::action_hangup_callback(void)
1214 struct route_param *rparam;
1218 delay = 2; /* default value */
1219 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1220 if (rparam->integer_value>0)
1221 delay = rparam->integer_value;
1223 /* dialing after callback */
1224 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1225 SCPY(e_cbdialing, rparam->string_value);
1227 SCPY(e_cbdialing, e_extdialing);
1229 trace_header("ACTION callback (dialing)", DIRECTION_NONE);
1230 add_trace("extension", NULL, "%s", e_cbcaller);
1231 add_trace("caller id", NULL, "%s", e_callerinfo.id);
1232 add_trace("delay", NULL, "%d", delay);
1233 add_trace("dialing", NULL, "%s", e_cbdialing);
1236 /* set time to callback */
1237 e_callback = now_d + delay;
1242 * dialing action abbreviation
1244 void EndpointAppPBX::action_dialing_abbrev(void)
1246 struct port_list *portlist = ea_endpoint->ep_portlist;
1247 char *abbrev, *phone, *name;
1250 portlist = ea_endpoint->ep_portlist;
1252 /* abbrev dialing is only possible if we have a caller defined */
1253 if (!e_ext.number[0])
1255 trace_header("ACTION abbreviation (only for extension)", DIRECTION_NONE);
1257 new_state(EPOINT_STATE_OUT_DISCONNECT);
1258 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1259 set_tone(portlist, "cause_3f");
1263 /* check abbreviation */
1264 abbrev = e_extdialing;
1267 result = parse_phonebook(e_ext.number, &abbrev, &phone, &name);
1270 trace_header("ACTION abbreviation (not found)", DIRECTION_NONE);
1271 add_trace("abbrev", NULL, "%s", abbrev);
1273 new_state(EPOINT_STATE_OUT_DISCONNECT);
1274 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
1275 set_tone(portlist, "cause_01");
1278 if (result == -1) /* may match if more digits are dialed */
1283 /* dial abbreviation */
1284 trace_header("ACTION abbreviation (dialing)", DIRECTION_NONE);
1285 add_trace("abbrev", NULL, "%s", abbrev);
1286 add_trace("number", NULL, "%s", phone);
1287 if (name) if (name[0])
1288 add_trace("name", NULL, "%s", name);
1290 SCPY(e_dialinginfo.id, phone);
1291 e_extdialing = e_dialinginfo.id;
1297 /* process dialing 'test'
1299 void EndpointAppPBX::action_dialing_test(void)
1303 struct port_list *portlist = ea_endpoint->ep_portlist;
1304 struct message *message;
1306 char testcode[32] = "";
1307 struct route_param *rparam;
1309 /* given testcode */
1310 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1311 SCPY(testcode, rparam->string_value);
1312 SCAT(testcode, e_extdialing);
1317 trace_header("ACTION test", DIRECTION_NONE);
1318 add_trace("test", NULL, "proceeding");
1320 new_state(EPOINT_STATE_IN_PROCEEDING);
1321 set_tone(portlist, "proceeding");
1322 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
1323 message_put(message);
1324 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1328 trace_header("ACTION test", DIRECTION_NONE);
1329 add_trace("test", NULL, "alerting");
1331 new_state(EPOINT_STATE_IN_ALERTING);
1332 set_tone(portlist, "ringpbx");
1333 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
1334 message_put(message);
1335 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1339 trace_header("ACTION test", DIRECTION_NONE);
1340 add_trace("test", NULL, "echo");
1342 new_state(EPOINT_STATE_CONNECT);
1343 if (e_ext.number[0])
1345 set_tone(portlist, NULL);
1346 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1347 SCPY(e_connectinfo.id, e_callerinfo.id);
1348 SCPY(e_connectinfo.extension, e_callerinfo.extension);
1349 e_connectinfo.itype = e_callerinfo.itype;
1350 e_connectinfo.ntype = e_callerinfo.ntype;
1351 e_connectinfo.present = e_callerinfo.present;
1352 e_connectinfo.screen = e_callerinfo.screen;
1353 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1354 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(struct connect_info));
1355 /* handle restricted caller ids */
1356 apply_callerid_restriction(e_ext.anon_ignore, message->param.connectinfo.id, &message->param.connectinfo.ntype, &message->param.connectinfo.present, &message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name);
1357 /* display callerid if desired for extension */
1358 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));
1359 message_put(message);
1360 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1362 port = find_port_id(portlist->port_id);
1365 port->set_echotest(1);
1370 trace_header("ACTION test", DIRECTION_NONE);
1371 add_trace("test", NULL, "tone");
1373 new_state(EPOINT_STATE_CONNECT);
1374 if (e_ext.number[0])
1376 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1377 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1378 message_put(message);
1379 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1380 set_tone(portlist, "test");
1384 trace_header("ACTION test", DIRECTION_NONE);
1385 add_trace("test", NULL, "hold music");
1387 new_state(EPOINT_STATE_CONNECT);
1388 if (e_ext.number[0])
1390 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1391 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1392 message_put(message);
1393 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1394 set_tone(portlist, "hold");
1398 if (strlen(testcode) < 4)
1401 cause = atoi(testcode+1);
1404 trace_header("ACTION test", DIRECTION_NONE);
1405 add_trace("test", NULL, "announcement");
1406 add_trace("cause", NULL, "%d", cause);
1408 new_state(EPOINT_STATE_CONNECT);
1409 if (e_ext.number[0])
1411 SPRINT(causestr,"cause_%02x",cause);
1412 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1413 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1414 message_put(message);
1415 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1416 set_tone(portlist, causestr);
1420 if (strlen(testcode) < 4)
1423 cause = atoi(testcode+1);
1426 trace_header("ACTION test", DIRECTION_NONE);
1427 add_trace("test", NULL, "disconnect");
1428 add_trace("cause", NULL, "%d", cause);
1430 new_state(EPOINT_STATE_OUT_DISCONNECT);
1431 SPRINT(causestr,"cause_%02x",cause);
1432 message_disconnect_port(portlist, cause, LOCATION_PRIVATE_LOCAL, "");
1433 set_tone(portlist, causestr);
1436 case '8': /* release */
1437 trace_header("ACTION test", DIRECTION_NONE);
1438 add_trace("test", NULL, "release");
1439 add_trace("cause", NULL, "16");
1441 new_state(EPOINT_STATE_OUT_DISCONNECT);
1442 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
1443 set_tone(portlist, "release");
1446 case '9': /* text callerid test */
1447 trace_header("ACTION test", DIRECTION_NONE);
1448 add_trace("test", NULL, "callerid");
1450 new_state(EPOINT_STATE_CONNECT);
1451 if (e_ext.number[0])
1453 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1454 SCPY(e_connectinfo.id, "12345678");
1455 SCPY(e_connectinfo.name, "Welcome to LCR");
1456 SCPY(e_connectinfo.display, "Welcome to LCR");
1457 e_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1458 e_connectinfo.present = INFO_PRESENT_ALLOWED;
1459 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1460 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(message->param.connectinfo));
1461 message_put(message);
1462 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1463 set_tone(portlist, "hold");
1469 /* process init play
1471 void EndpointAppPBX::action_init_play(void)
1473 struct route_param *rparam;
1474 struct port_list *portlist = ea_endpoint->ep_portlist;
1476 /* check given sample */
1477 if (!(rparam = routeparam(e_action, PARAM_SAMPLE)))
1479 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1483 new_state(EPOINT_STATE_OUT_DISCONNECT);
1484 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
1485 set_tone(portlist, "cause_3f");
1490 /* if sample is given */
1491 if (rparam->string_value[0] == '\0')
1493 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1498 if (e_ext.number[0])
1501 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1506 * action_*_vbox_play is implemented in "action_vbox.cpp"
1511 * process dialing of calculator
1513 void EndpointAppPBX::action_dialing_calculator(void)
1515 struct port_list *portlist = ea_endpoint->ep_portlist;
1516 struct message *message;
1517 double value1, value2, v, sign1;
1518 int komma1, komma2, k, state, mode, first;
1521 portlist = ea_endpoint->ep_portlist;
1523 /* remove error message */
1524 if (!strncmp(e_extdialing, "Error", 5))
1526 UCPY(e_extdialing, e_extdialing+5);
1528 if (!strncmp(e_extdialing, "inf", 3))
1530 UCPY(e_extdialing, e_extdialing+3);
1532 if (!strncmp(e_extdialing, "-inf", 4))
1534 UCPY(e_extdialing, e_extdialing+4);
1537 /* process dialing */
1550 if (*p>='0' && *p<='9')
1558 if ((p[-1]<'0' || p[-1]>'0') && p[-1]!='.')
1567 case 0: /* first number */
1570 value1 = value1*10 + (*p-'0');
1580 case 1: /* second number */
1583 value2 = value2*10 + (*p-'0');
1600 UCPY(e_extdialing, "Error");
1603 /* if there is a multiplication, we change to / */
1612 /* if there is a division, we change to + */
1621 /* if there is a addition, we change to - */
1630 /* if there is a substraction and a comma, we change to * */
1631 if (p[-1]=='-' && komma1)
1639 /* if there is a substraction and no comma and the first or second value, we change to , */
1648 /* if there is a komma and we are at the first value, we change to * */
1649 if (p[-1]=='.' && state==0)
1658 /* if there is a komma and we are at the second value, we display error */
1659 if (komma2 && state==1)
1661 UCPY(e_extdialing, "Error");
1664 /* if we are at state 1, we write a comma */
1671 /* we assume multiplication */
1678 /* if just a number is displayed, the input is cleared */
1681 *e_extdialing = '\0';
1684 /* calculate the result */
1687 case 0: /* multiply */
1688 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1*value2);
1690 case 1: /* divide */
1691 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1/value2);
1694 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1+value2);
1696 case 3: /* substract */
1697 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1-value2);
1700 e_dialinginfo.id[sizeof(e_dialinginfo.id)-1] = '\0';
1701 if (strchr(e_extdialing, '.')) /* remove zeroes */
1703 while (e_extdialing[strlen(e_extdialing)-1] == '0')
1704 e_extdialing[strlen(e_extdialing)-1] = '\0';
1705 if (e_extdialing[strlen(e_extdialing)-1] == '.')
1706 e_extdialing[strlen(e_extdialing)-1] = '\0'; /* and remove dot */
1708 p = strchr(e_extdialing,'\0')-1;
1741 UCPY(e_extdialing, "Error");
1750 /* display dialing */
1751 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1752 SPRINT(message->param.notifyinfo.display, ">%s", e_extdialing);
1753 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);
1754 message_put(message);
1755 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1760 * process dialing of timer
1762 void EndpointAppPBX::action_dialing_timer(void)
1768 * process 'goto' or 'menu'
1770 void EndpointAppPBX::_action_goto_menu(int mode)
1772 struct port_list *portlist = ea_endpoint->ep_portlist;
1773 struct route_param *rparam;
1775 /* check given ruleset */
1776 if (!(rparam = routeparam(e_action, PARAM_RULESET)))
1779 trace_header("ACTION goto/menu (no ruleset given)", DIRECTION_NONE);
1783 new_state(EPOINT_STATE_OUT_DISCONNECT);
1784 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1785 set_tone(portlist, "cause_3f");
1789 if (rparam->string_value[0] == '\0')
1791 e_ruleset = getrulesetbyname(rparam->string_value);
1794 trace_header("ACTION goto/menu (ruleset not found)", DIRECTION_NONE);
1795 add_trace("ruleset", NULL, "%s", rparam->string_value);
1800 /* if the 'menu' was selected, we will flush all digits */
1803 e_dialinginfo.id[0] = 0;
1804 e_extdialing = e_dialinginfo.id;
1807 /* remove digits that are required to match the rule */
1808 if (!(rparam = routeparam(e_action, PARAM_STRIP)))
1811 SCPY(e_dialinginfo.id, e_extdialing);
1812 e_extdialing = e_dialinginfo.id;
1817 trace_header("ACTION goto/menu (change to)", DIRECTION_NONE);
1818 add_trace("ruleset", NULL, "%s", e_ruleset->name);
1819 if (e_dialinginfo.id[0])
1820 add_trace("dialing", NULL, "%s", e_dialinginfo.id);
1821 if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
1823 add_trace("sample", NULL, "%s", rparam->string_value);
1824 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1828 /* do dialing with new ruleset */
1833 /* process dialing goto
1835 void EndpointAppPBX::action_dialing_goto(void)
1837 _action_goto_menu(0);
1840 /* process dialing menu
1842 void EndpointAppPBX::action_dialing_menu(void)
1844 _action_goto_menu(1);
1849 * process dialing disconnect
1851 void EndpointAppPBX::action_dialing_disconnect(void)
1853 struct route_param *rparam;
1854 struct port_list *portlist = ea_endpoint->ep_portlist;
1855 struct message *message;
1856 int cause = CAUSE_NORMAL; /* normal call clearing */
1857 int location = LOCATION_PRIVATE_LOCAL;
1858 char cause_string[256] = "", display[84] = "";
1860 /* check cause parameter */
1861 if ((rparam = routeparam(e_action, PARAM_CAUSE)))
1863 cause = rparam->integer_value;
1864 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1866 if ((rparam = routeparam(e_action, PARAM_LOCATION)))
1868 location = rparam->integer_value;
1869 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1873 /* use cause as sample, if not given later */
1874 SPRINT(cause_string, "cause_%02x", cause);
1876 /* check sample parameter */
1877 if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
1879 SCPY(cause_string, rparam->string_value);
1880 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'sample' is given: %s\n", ea_endpoint->ep_serial, cause_string);
1884 if ((rparam = routeparam(e_action, PARAM_DISPLAY)))
1886 SCPY(display, rparam->string_value);
1887 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1890 /* disconnect only if connect parameter is not given */
1891 trace_header("ACTION disconnect", DIRECTION_NONE);
1892 add_trace("cause", "value", "%d", cause);
1893 add_trace("cause", "location", "%d", location);
1894 if (cause_string[0])
1895 add_trace("sample", NULL, "%s", cause_string);
1897 add_trace("display", NULL, "%s", display);
1899 new_state(EPOINT_STATE_OUT_DISCONNECT);
1900 set_tone(portlist, cause_string);
1901 if (!(rparam = routeparam(e_action, PARAM_CONNECT)))
1903 message_disconnect_port(portlist, cause, location, display);
1906 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1907 SCPY(message->param.notifyinfo.display, display);
1908 message_put(message);
1909 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1916 * process dialing help
1918 void EndpointAppPBX::action_dialing_help(void)
1920 /* show all things that would match */
1922 struct numbering *numbering = numbering_int;
1923 char dialing[sizeof(e_dialinginfo.id)];
1925 struct message *message;
1926 struct route_param *rparam;
1928 /* in case we have no menu (this should never happen) */
1933 if (strchr(e_dialinginfo.id,'*'))
1936 e_dialinginfo.id[0] = '\0';
1938 if (strchr(e_dialinginfo.id,'#'))
1941 e_dialinginfo.id[0] = '\0';
1944 /* get position in menu */
1947 /* get last menu position */
1949 while(numbering->next)
1952 numbering = numbering->next;
1956 /* get menu position */
1960 numbering = numbering->next;
1964 numbering = numbering_int;
1971 /* if we dial something else we need to add the prefix and change the action */
1972 if (e_dialinginfo.id[0])
1974 e_action = NUMB_ACTION_NONE;
1975 SCPY(dialing, numbering->prefix);
1976 //we ignore the first digit after selecting
1977 //SCAT(dialing, e_dialinginfo.id);
1978 SCPY(e_dialinginfo.id, dialing);
1979 e_extdialing = e_dialinginfo.id+strlen(numbering->prefix);
1980 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);
1986 /* send display message to port */
1987 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1988 SPRINT(message->param.notifyinfo.display, ">%s %s%s%s", numbering->prefix, numb_actions[numbering->action], (numbering->param[0])?" ":"", numbering->param);
1989 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);
1990 message_put(message);
1991 logmessage(message->type, message->paramea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1997 * process dialing deflect
1999 void EndpointAppPBX::action_dialing_deflect(void)
2005 * process dialing setforward
2007 void EndpointAppPBX::action_dialing_setforward(void)
2013 * process hangup 'execute'
2015 void EndpointAppPBX::action_hangup_execute(void)
2017 struct route_param *rparam;
2018 char *command = "", isdn_port[10];
2019 char *argv[7+1]; /* check also number of args below */
2022 /* get script / command */
2023 if ((rparam = routeparam(e_action, PARAM_EXECUTE)))
2024 command = rparam->string_value;
2025 if (command[0] == '\0')
2027 trace_header("ACTION execute (no parameter given)", DIRECTION_NONE);
2031 trace_header("ACTION execute", DIRECTION_NONE);
2032 add_trace("command", NULL, "%s", command);
2036 while(strchr(argv[0], '/'))
2037 argv[0] = strchr(argv[0], '/')+1;
2038 if ((rparam = routeparam(e_action, PARAM_PARAM)))
2040 argv[1] = rparam->string_value;
2043 argv[1+i] = e_extdialing;
2044 argv[2+i] = numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype);
2045 argv[3+i] = e_callerinfo.extension;
2046 argv[4+i] = e_callerinfo.name;
2047 SPRINT(isdn_port, "%d", e_callerinfo.isdn_port);
2048 argv[5+i] = isdn_port;
2049 argv[6+i] = NULL; /* check also number of args above */
2050 execve("/bin/sh", argv, environ);
2055 * process hangup 'file'
2057 void EndpointAppPBX::action_hangup_file(void)
2059 struct route_param *rparam;
2060 char *file, *content, *mode;
2063 /* get file / content */
2064 if (!(rparam = routeparam(e_action, PARAM_FILE)))
2065 file = rparam->string_value;
2068 if (!(rparam = routeparam(e_action, PARAM_CONTENT)))
2069 content = rparam->string_value;
2071 content = e_extdialing;
2072 if (!(rparam = routeparam(e_action, PARAM_APPEND)))
2076 if (file[0] == '\0')
2078 trace_header("ACTION file (no filename given)", DIRECTION_NONE);
2082 if (!(fp = fopen(file, mode)))
2084 trace_header("ACTION file (failed to open)", DIRECTION_NONE);
2085 add_trace("file", "name", "%s", file);
2086 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2090 trace_header("ACTION file", DIRECTION_NONE);
2091 add_trace("file", "name", "%s", file);
2092 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2093 add_trace("content", NULL, "%s", content);
2095 fprintf(fp, "%s\n", content);
2101 * process init 'pick'
2103 void EndpointAppPBX::action_init_pick(void)
2105 struct route_param *rparam;
2106 char *extensions = NULL;
2108 if ((rparam = routeparam(e_action, PARAM_EXTENSIONS)))
2109 extensions = rparam->string_value;
2111 trace_header("ACTION pick", DIRECTION_NONE);
2112 if (extensions) if (extensions[0])
2113 add_trace("extensions", NULL, "%s", extensions);
2115 pick_join(extensions);
2120 * process dialing 'password'
2122 void EndpointAppPBX::action_dialing_password(void)
2124 struct port_list *portlist = ea_endpoint->ep_portlist;
2126 /* prompt for password */
2127 if (e_extdialing[0] == '\0')
2129 /* give password tone */
2130 set_tone(portlist, "password");
2132 if (e_extdialing[1] == '\0')
2134 /* give password tone */
2135 set_tone(portlist, "dialing");
2138 /* wait until all digits are dialed */
2139 if (strlen(e_ext.password) != strlen(e_extdialing))
2140 return; /* more digits needed */
2142 /* check the password */
2143 if (e_ext.password[0]=='\0' || (strlen(e_ext.password)==strlen(e_extdialing) && !!strcmp(e_ext.password,e_extdialing)))
2145 trace_header("ACTION password_write (wrong password)", DIRECTION_NONE);
2146 add_trace("dialed", NULL, "%s", e_extdialing);
2148 e_connectedmode = 0;
2150 new_state(EPOINT_STATE_OUT_DISCONNECT);
2151 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2152 set_tone(portlist, "cause_10");
2156 /* write caller id if ACTION_PASSWORD_WRITE was selected */
2158 if (e_action->index == ACTION_PASSWORD_WRITE)
2160 append_callbackauth(e_ext.number, &e_callbackinfo);
2161 trace_header("ACTION password_write (written)", DIRECTION_NONE);
2162 add_trace("dialed", NULL, "%s", e_extdialing);
2166 /* make call state */
2167 new_state(EPOINT_STATE_IN_OVERLAP);
2168 e_ruleset = ruleset_main;
2170 e_rule = e_ruleset->rule_first;
2172 e_dialinginfo.id[0] = '\0';
2173 e_extdialing = e_dialinginfo.id;
2174 set_tone(portlist, "dialpbx");
2177 void EndpointAppPBX::action_dialing_password_wr(void)
2179 action_dialing_password();
2183 /* general process dialing of incoming call
2184 * depending on the detected prefix, subfunctions above (action_*) will be
2187 void EndpointAppPBX::process_dialing(void)
2189 struct port_list *portlist = ea_endpoint->ep_portlist;
2190 struct message *message;
2191 struct route_param *rparam;
2193 //#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.
2194 //PDEBUG(~0, "HANG-BUG-DEBUGGING: entered porcess_dialing\n");
2195 portlist = ea_endpoint->ep_portlist;
2196 /* check if we have a port instance linked to our epoint */
2200 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);
2201 e_action_timeout = 0;
2202 e_match_timeout = 0;
2207 goto portlist_error;
2210 /* check nesting levels */
2211 if (++e_rule_nesting > RULE_NESTING)
2213 trace_header("ACTION (nesting too deep)", DIRECTION_NONE);
2214 add_trace("max-levels", NULL, "%d", RULE_NESTING);
2216 new_state(EPOINT_STATE_OUT_DISCONNECT);
2217 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2218 set_tone(portlist, "cause_3f");
2219 e_action_timeout = 0;
2220 e_match_timeout = 0;
2224 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before action-timeout processing\n");
2225 /* process timeout */
2226 if (e_action_timeout)
2228 e_action_timeout = 0;
2229 if (e_state == EPOINT_STATE_CONNECT)
2231 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);
2234 if (e_action->index == ACTION_DISCONNECT
2235 || e_state == EPOINT_STATE_OUT_DISCONNECT)
2237 /* release after disconnect */
2238 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
2241 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, 0);
2242 e_action = e_action->next;
2245 /* nothing more, so we release */
2246 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action timed out, and we have no next action, so we disconnect.\n", ea_endpoint->ep_serial);
2247 new_state(EPOINT_STATE_OUT_DISCONNECT);
2248 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2249 set_tone(portlist, "cause_3f");
2252 goto action_timeout;
2255 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before setup/overlap state checking\n");
2256 if (e_state!=EPOINT_STATE_IN_SETUP
2257 && e_state!=EPOINT_STATE_IN_OVERLAP)
2259 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): we are not in incomming setup/overlap state, so we ignore init/dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting);
2260 e_match_timeout = 0;
2265 /* check if we do menu selection */
2266 if (e_action==NUMB_ACTION_NONE && (e_dialinginfo.id[0]=='*' || e_dialinginfo.id[0]=='#'))
2267 /* do menu selection */
2268 if (e_ext.display_menu)
2270 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 */
2272 e_dialinginfo.id[0] = '\0';
2273 e_action = NUMB_ACTION_MENU;
2276 e_match_timeout = 0;
2279 /* invalid dialing */
2280 message_disconnect_port(portlist, CAUSE_INCALID, LOCATION_PRIVATE_LOCAL, "");
2281 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
2282 message->param.disconnectinfo.cause = CAUSE_INVALID;
2283 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2286 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2287 SCPY(message->param.notifyinfo.display,get_isdn_cause(LOCATION_PRIVATE_LOCAL, epoint->e_ext.display_cause, param->disconnectinfo.location, param->disconnectinfo.cause));
2289 message_put(message);
2290 logmessage(message->type, message->param, portlist->port_id, DIRECTION_OUT);
2292 new_state(EPOINT_STATE_OUT_DISCONNECT);
2293 set_tone(portlist,"cause_1c");
2294 e_match_timeout = 0;
2299 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before e_action==NULL\n");
2300 /* if no action yet, we will call try to find a matching rule */
2303 /* be sure that all selectors are initialized */
2306 /* check for external call */
2307 if (!strncmp(e_dialinginfo.id, "extern:", 7))
2309 e_extdialing = e_dialinginfo.id+7;
2310 e_action = &action_external;
2311 goto process_action;
2313 /* check for internal call */
2314 if (!strncmp(e_dialinginfo.id, "intern:", 7))
2316 e_extdialing = e_dialinginfo.id+7;
2317 e_action = &action_internal;
2318 goto process_action;
2320 /* check for chan call */
2321 if (!strncmp(e_dialinginfo.id, "chan:", 5))
2323 e_extdialing = e_dialinginfo.id+4;
2324 e_action = &action_chan;
2325 goto process_action;
2327 /* check for vbox call */
2328 if (!strncmp(e_dialinginfo.id, "vbox:", 5))
2330 e_extdialing = e_dialinginfo.id+5;
2331 e_action = &action_vbox;
2332 goto process_action;
2335 if (e_match_timeout && now_d>=e_match_timeout)
2337 /* return timeout rule */
2338 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);
2339 e_match_timeout = 0;
2340 e_action = e_match_to_action;
2341 e_extdialing = e_match_to_extdialing;
2342 trace_header("ROUTING (timeout)", DIRECTION_NONE);
2343 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2344 add_trace("line", NULL, "%d", e_action->line);
2348 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before routing\n");
2349 /* check for matching rule */
2350 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);
2353 e_action = route(e_ruleset);
2356 trace_header("ACTION (match)", DIRECTION_NONE);
2357 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2358 add_trace("line", NULL, "%d", e_action->line);
2363 e_action = &action_disconnect;
2366 trace_header("ACTION (no main ruleset, disconnecting)", DIRECTION_NONE);
2370 //PDEBUG(~0, "HANG-BUG-DEBUGGING: after routing\n");
2374 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): no rule within the current ruleset matches yet.\n", ea_endpoint->ep_serial, e_ext.number);
2379 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): a rule with action '%s' matches.\n", ea_endpoint->ep_serial, action_defs[e_action->index].name);
2384 e_action_timeout = 0;
2385 if (e_action->timeout)
2387 e_action_timeout = now_d + e_action->timeout;
2388 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action has a timeout of %d secods.\n", ea_endpoint->ep_serial, e_action->timeout);
2392 /* check param proceeding / alerting / connect */
2393 if ((rparam = routeparam(e_action, PARAM_CONNECT)))
2395 /* NOTE: we may not change our state to connect, because dialing will then not possible */
2397 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2398 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
2399 message_put(message);
2400 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2402 if ((rparam = routeparam(e_action, PARAM_ALERTING)))
2404 /* NOTE: we may not change our state to alerting, because dialing will then not possible */
2405 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2406 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
2407 message_put(message);
2408 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2410 if ((rparam = routeparam(e_action, PARAM_PROCEEDING)))
2412 /* NOTE: we may not change our state to proceeding, because dialing will then not possible */
2413 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2414 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
2415 message_put(message);
2416 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2419 if (action_defs[e_action->index].init_func)
2421 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);
2422 (this->*(action_defs[e_action->index].init_func))();
2424 if (e_state!=EPOINT_STATE_IN_SETUP
2425 && e_state!=EPOINT_STATE_IN_OVERLAP)
2427 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): AFTER init process: we are not in incomming setup/overlap state anymore, so we ignore further dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting);
2428 goto display_action;
2432 /* show what we are doing */
2433 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);
2434 /* go to action's dialing function */
2435 if (action_defs[e_action->index].dialing_func)
2437 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);
2438 (this->*(action_defs[e_action->index].dialing_func))();
2441 /* display selected dialing action if enabled and still in setup state */
2445 if (e_action->index==ACTION_MENU
2446 || e_action->index==ACTION_REDIAL
2447 || e_action->index==ACTION_REPLY
2448 || e_action->index==ACTION_TIMER
2449 || e_action->index==ACTION_CALCULATOR
2450 || e_action->index==ACTION_TEST)
2454 if (!e_ext.display_dialing)
2456 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*/)
2457 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 */
2459 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2463 SPRINT(message->param.notifyinfo.display, "> %s", e_dialinginfo.id);
2466 SPRINT(message->param.notifyinfo.display, "%s%s%s", action_defs[e_action->index].name, (e_extdialing[0])?" ":"", e_extdialing);
2469 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s'\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
2470 message_put(message);
2471 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2480 /* some services store information after hangup */
2481 void EndpointAppPBX::process_hangup(int cause, int location)
2483 char callertext[256], dialingtext[256];
2484 int writeext = 0, i;
2486 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s'\n", ea_endpoint->ep_serial, e_ext.number);
2487 if (e_ext.number[0])
2489 if (read_extension(&e_ext, e_ext.number))
2499 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);
2500 switch(e_dialinginfo.itype)
2502 case INFO_ITYPE_CHAN:
2503 SPRINT(dialingtext, "chan:%s", e_dialinginfo.id);
2505 case INFO_ITYPE_ISDN_EXTENSION:
2506 SPRINT(dialingtext, "intern:%s", e_dialinginfo.id);
2508 case INFO_ITYPE_VBOX:
2509 SPRINT(dialingtext, "vbox:%s", e_dialinginfo.id);
2512 SPRINT(dialingtext, "%s", e_dialinginfo.id);
2515 if (e_callerinfo.id[0])
2516 SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype));
2518 SPRINT(callertext, "unknown");
2519 /* allpy restriction */
2520 if (!e_ext.anon_ignore && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
2521 SPRINT(callertext, "anonymous");
2522 if (e_callerinfo.extension[0]) /* add intern if present */
2523 UNPRINT(strchr(callertext,'\0'), sizeof(callertext)-1+strlen(callertext), " (intern %s)", e_callerinfo.extension);
2524 write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location);
2526 /* store last received call for reply-list */
2527 if (e_callerinfo.id[0] || e_callerinfo.extension[0])
2528 if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED)
2530 if (e_callerinfo.extension[0])
2531 SPRINT(callertext, "intern:%s", e_callerinfo.extension);
2533 SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype));
2534 if (!!strcmp(callertext, e_ext.last_in[0]))
2539 UCPY(e_ext.last_in[i], e_ext.last_in[i-1]);
2542 SCPY(e_ext.last_in[0], callertext);
2543 writeext |= 1; /* store extension later */
2544 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]);
2546 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);
2550 /* write extension if needed */
2551 if (writeext == 0x11)
2552 write_extension(&e_ext, e_ext.number);
2556 if (action_defs[e_action->index].hangup_func)
2558 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);
2559 (this->*(action_defs[e_action->index].hangup_func))();