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' / 'remote' / 'vbox-record' / 'partyline'...
72 void EndpointAppPBX::_action_init_call(char *remote)
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 join instance.\n", ea_endpoint->ep_serial);
93 if (admin->remote_name[0] && !strcmp(admin->remote_name, remote))
99 /* resource not available */
100 trace_header("ACTION remote (not available)", DIRECTION_NONE);
101 add_trace("application", NULL, "%s", remote);
103 message_disconnect_port(portlist, CAUSE_RESSOURCEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
104 new_state(EPOINT_STATE_OUT_DISCONNECT);
105 set_tone(portlist,"cause_22");
108 join = new JoinRemote(ea_endpoint->ep_serial, remote, admin->sock);
111 join = new JoinPBX(ea_endpoint);
113 FATAL("No memoy for Join instance.\n");
114 ea_endpoint->ep_join_id = join->j_serial;
116 void EndpointAppPBX::action_init_call(void)
118 _action_init_call(NULL);
120 void EndpointAppPBX::action_init_remote(void)
122 struct route_param *rparam;
123 struct port_list *portlist = ea_endpoint->ep_portlist;
124 struct message *message;
125 struct capa_info capainfo;
126 struct caller_info callerinfo;
127 struct redir_info redirinfo;
128 struct dialing_info dialinginfo;
131 if (!(rparam = routeparam(e_action, PARAM_APPLICATION)))
133 trace_header("ACTION remote (no application given)", DIRECTION_NONE);
135 new_state(EPOINT_STATE_OUT_DISCONNECT);
136 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
137 set_tone(portlist, "cause_3f");
140 SCPY(remote, rparam->string_value);
141 _action_init_call(remote);
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));
149 /* send setup to remote */
150 trace_header("ACTION remote (setup)", DIRECTION_NONE);
151 add_trace("number", NULL, dialinginfo.id);
152 add_trace("remote", NULL, remote);
154 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
155 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
156 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
157 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
158 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
159 message_put(message);
163 * process dialing 'internal'
165 void EndpointAppPBX::action_dialing_internal(void)
167 struct capa_info capainfo;
168 struct caller_info callerinfo;
169 struct redir_info redirinfo;
170 struct dialing_info dialinginfo;
171 struct port_list *portlist = ea_endpoint->ep_portlist;
172 struct message *message;
173 struct extension ext;
174 struct route_param *rparam;
176 /* send proceeding, because number is complete */
177 set_tone(portlist, "proceeding");
178 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
179 message_put(message);
180 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
181 new_state(EPOINT_STATE_IN_PROCEEDING);
183 /* create bearer/caller/dialinginfo */
184 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
185 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
186 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
187 memset(&dialinginfo, 0, sizeof(dialinginfo));
188 dialinginfo.itype = INFO_ITYPE_ISDN_EXTENSION;
189 SCPY(dialinginfo.id, e_dialinginfo.id);
191 /* process extension */
192 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
193 SCPY(dialinginfo.id, rparam->string_value);
195 /* process number type */
196 if ((rparam = routeparam(e_action, PARAM_TYPE)))
197 dialinginfo.ntype = rparam->integer_value;
199 /* process service */
200 if ((rparam = routeparam(e_action, PARAM_CAPA)))
202 capainfo.bearer_capa = rparam->integer_value;
203 if (capainfo.bearer_capa != INFO_BC_SPEECH
204 && capainfo.bearer_capa != INFO_BC_AUDIO)
206 capainfo.bearer_mode = INFO_BMODE_PACKET;
208 capainfo.bearer_info1 = INFO_INFO1_NONE;
210 if ((rparam = routeparam(e_action, PARAM_BMODE)))
212 capainfo.bearer_mode = rparam->integer_value;
214 if ((rparam = routeparam(e_action, PARAM_INFO1)))
216 capainfo.bearer_info1 = rparam->integer_value;
218 if ((rparam = routeparam(e_action, PARAM_HLC)))
220 capainfo.hlc = rparam->integer_value;
222 if ((rparam = routeparam(e_action, PARAM_EXTHLC)))
224 capainfo.exthlc = rparam->integer_value;
227 /* process presentation */
228 if ((rparam = routeparam(e_action, PARAM_PRESENT)))
230 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
233 /* check if extension exists AND only if not multiple extensions */
234 if (!read_extension(&ext, dialinginfo.id) && !strchr(dialinginfo.id,','))
236 trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE);
237 add_trace("extension", NULL, dialinginfo.id);
239 new_state(EPOINT_STATE_OUT_DISCONNECT);
240 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
241 set_tone(portlist, "cause_86");
244 /* check if internal calls are denied */
245 if (e_ext.rights < 1)
247 trace_header("ACTION extension (dialing to extension denied)", DIRECTION_NONE);
248 add_trace("extension", NULL, dialinginfo.id);
250 new_state(EPOINT_STATE_OUT_DISCONNECT);
251 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
252 set_tone(portlist, "cause_81");
256 /* add or update internal call */
257 trace_header("ACTION extension (calling)", DIRECTION_NONE);
258 add_trace("extension", NULL, dialinginfo.id);
260 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
261 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
262 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
263 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
264 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
265 message_put(message);
268 /* process dialing external
270 void EndpointAppPBX::action_dialing_external(void)
272 struct capa_info capainfo;
273 struct caller_info callerinfo;
274 struct redir_info redirinfo;
275 struct dialing_info dialinginfo;
277 struct port_list *portlist = ea_endpoint->ep_portlist;
278 struct message *message;
279 struct route_param *rparam;
281 /* special processing of delete characters '*' and '#' */
282 if (e_ext.delete_ext)
284 /* dialing a # causes a clearing of complete number */
285 if (strchr(e_extdialing, '#'))
287 e_extdialing[0] = '\0';
288 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);
290 /* eliminate digits before '*', which is a delete digit
292 if (strchr(e_extdialing, '*'))
295 while((p=strchr(e_extdialing, '*')))
297 if (p > e_extdialing) /* only if there is a digit in front */
302 UCPY(p, p+1); /* remove '*' */
304 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s deleted digits and got new string: %s\n", ea_endpoint->ep_serial, e_ext.number, e_extdialing);
308 /* create bearer/caller/dialinginfo */
309 memcpy(&capainfo, &e_capainfo, sizeof(capainfo));
310 memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo));
311 memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo));
312 memset(&dialinginfo, 0, sizeof(dialinginfo));
313 dialinginfo.itype = INFO_ITYPE_ISDN;
314 dialinginfo.sending_complete = 0;
315 SCPY(dialinginfo.id, e_extdialing);
318 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
319 SPRINT(dialinginfo.id, "%s%s", rparam->string_value, e_extdialing);
321 /* process number complete */
322 if ((rparam = routeparam(e_action, PARAM_COMPLETE)))
323 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
324 SCPY(dialinginfo.id, rparam->string_value);
325 dialinginfo.sending_complete = 1;
327 /* process number type */
328 if ((rparam = routeparam(e_action, PARAM_TYPE)))
329 dialinginfo.ntype = rparam->integer_value;
331 /* process service */
332 if ((rparam = routeparam(e_action, PARAM_CAPA)))
334 capainfo.bearer_capa = rparam->integer_value;
335 if (capainfo.bearer_capa != INFO_BC_SPEECH
336 && capainfo.bearer_capa != INFO_BC_AUDIO)
338 capainfo.bearer_mode = INFO_BMODE_PACKET;
340 capainfo.bearer_info1 = INFO_INFO1_NONE;
342 if ((rparam = routeparam(e_action, PARAM_BMODE)))
344 capainfo.bearer_mode = rparam->integer_value;
346 if ((rparam = routeparam(e_action, PARAM_INFO1)))
348 capainfo.bearer_info1 = rparam->integer_value;
350 if ((rparam = routeparam(e_action, PARAM_HLC)))
352 capainfo.hlc = rparam->integer_value;
354 if ((rparam = routeparam(e_action, PARAM_EXTHLC)))
356 capainfo.exthlc = rparam->integer_value;
360 /* process callerid */
361 if ((rparam = routeparam(e_action, PARAM_CALLERID)))
363 SCPY(callerinfo.id, rparam->string_value);
365 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
367 callerinfo.ntype = rparam->integer_value;
370 /* process presentation */
371 if ((rparam = routeparam(e_action, PARAM_PRESENT)))
373 callerinfo.present = (rparam->integer_value)?INFO_PRESENT_ALLOWED:INFO_PRESENT_RESTRICTED;
376 /* process interfaces */
377 if ((rparam = routeparam(e_action, PARAM_INTERFACES)))
378 SCPY(dialinginfo.interfaces, rparam->string_value);
380 /* check if local calls are denied */
381 if (e_ext.rights < 2)
383 trace_header("ACTION extern (calling denied)", DIRECTION_NONE);
385 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0);
386 set_tone(portlist, "cause_82");
388 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
389 new_state(EPOINT_STATE_OUT_DISCONNECT);
393 if (!strncmp(dialinginfo.id, options.national, strlen(options.national))
394 || dialinginfo.ntype == INFO_NTYPE_NATIONAL
395 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL)
397 /* check if national calls are denied */
398 if (e_ext.rights < 3)
400 trace_header("ACTION extern (national calls denied)", DIRECTION_NONE);
402 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0);
403 set_tone(portlist, "cause_83");
408 if (!strncmp(dialinginfo.id, options.international, strlen(options.international))
409 || dialinginfo.ntype == INFO_NTYPE_INTERNATIONAL)
411 /* check if international calls are denied */
412 if (e_ext.rights < 4)
414 trace_header("ACTION extern (international calls denied)", DIRECTION_NONE);
416 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0);
417 set_tone(portlist, "cause_84");
422 /* add or update outgoing call */
423 trace_header("ACTION extern (calling)", DIRECTION_NONE);
424 add_trace("number", NULL, dialinginfo.id);
425 if (dialinginfo.interfaces[0])
426 add_trace("interfaces", NULL, dialinginfo.interfaces);
428 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
429 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
430 memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info));
431 memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info));
432 memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info));
433 message_put(message);
437 void EndpointAppPBX::action_dialing_remote(void)
439 struct message *message;
440 struct dialing_info dialinginfo;
441 // struct route_param *rparam;
443 /* create bearer/caller/dialinginfo */
444 memset(&dialinginfo, 0, sizeof(dialinginfo));
446 if (dialinginfo.id[0])
448 /* add or update outgoing call */
449 trace_header("ACTION remote (dialing)", DIRECTION_NONE);
450 add_trace("number", NULL, dialinginfo.id);
452 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_INFORMATION);
453 memcpy(&message->param.information, &dialinginfo, sizeof(struct dialing_info));
454 message_put(message);
460 * process dialing the "am" and record
462 void EndpointAppPBX::action_dialing_vbox_record(void)
464 struct dialing_info dialinginfo;
465 struct port_list *portlist = ea_endpoint->ep_portlist;
466 struct message *message;
467 struct extension ext;
468 struct route_param *rparam;
470 portlist = ea_endpoint->ep_portlist;
472 /* check for given extension */
473 if (!(rparam = routeparam(e_action, PARAM_EXTENSION)))
475 trace_header("ACTION vbox-record (no extension given by parameter)", DIRECTION_NONE);
478 new_state(EPOINT_STATE_OUT_DISCONNECT);
479 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
480 set_tone(portlist, "cause_3f");
484 /* check if extension exists */
485 if (!read_extension(&ext, rparam->string_value))
487 trace_header("ACTION vbox-record (given extension does not exists)", DIRECTION_NONE);
488 add_trace("extension", NULL, "%s", rparam->string_value);
490 new_state(EPOINT_STATE_OUT_DISCONNECT);
491 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
492 set_tone(portlist, "cause_86");
496 /* check if internal calls are denied */
497 if (e_ext.rights < 1)
499 trace_header("ACTION vbox-record (internal calls are denied)", DIRECTION_NONE);
501 new_state(EPOINT_STATE_OUT_DISCONNECT);
502 message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, "");
503 set_tone(portlist, "cause_81");
507 set_tone(portlist, "proceeding");
508 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
509 message_put(message);
510 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
511 new_state(EPOINT_STATE_IN_PROCEEDING);
513 memset(&dialinginfo, 0, sizeof(dialinginfo));
514 dialinginfo.itype = INFO_ITYPE_VBOX;
515 dialinginfo.sending_complete = 1;
516 SCPY(dialinginfo.id, rparam->string_value);
518 /* append special announcement (if given) */
519 if ((rparam = routeparam(e_action, PARAM_ANNOUNCEMENT)))
520 if (rparam->string_value[0])
522 SCAT(dialinginfo.id, ",");
523 SCAT(dialinginfo.id, rparam->string_value);
526 /* add or update internal call */
527 trace_header("ACTION vbox-record (calling)", DIRECTION_NONE);
528 add_trace("extension", NULL, "%s", dialinginfo.id);
530 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
531 memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info));
532 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
533 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
534 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
535 message_put(message);
542 void EndpointAppPBX::action_init_partyline(void)
545 class JoinPBX *joinpbx;
546 struct port_list *portlist = ea_endpoint->ep_portlist;
547 struct message *message;
548 struct route_param *rparam;
549 int partyline, jingle = 0;
550 struct join_relation *relation;
552 portlist = ea_endpoint->ep_portlist;
554 /* check for given extension */
555 if (!(rparam = routeparam(e_action, PARAM_ROOM)))
557 trace_header("ACTION partyline (no room parameter)", DIRECTION_NONE);
560 new_state(EPOINT_STATE_OUT_DISCONNECT);
561 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
562 set_tone(portlist, "cause_3f");
565 if (rparam->integer_value <= 0)
567 trace_header("ACTION partyline (illegal room parameter)", DIRECTION_NONE);
568 add_trace("room", NULL, "%d", rparam->integer_value);
570 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): invalid value for 'room'.\n", ea_endpoint->ep_serial);
573 partyline = rparam->integer_value;
574 if ((rparam = routeparam(e_action, PARAM_JINGLE)))
577 /* don't create join if partyline exists */
581 if (join->j_type == JOIN_TYPE_PBX)
583 joinpbx = (class JoinPBX *)join;
584 if (joinpbx->j_partyline == partyline)
592 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial);
593 if (!(join = new JoinPBX(ea_endpoint)))
594 FATAL("No memory for join object\n");
597 //NOTE: joinpbx must be set here
598 /* add relation to existing join */
599 if (!(relation=joinpbx->add_relation()))
600 FATAL("No memory for join relation\n");
601 relation->type = RELATION_TYPE_SETUP;
602 relation->channel_state = CHANNEL_STATE_CONNECT;
603 relation->rx_state = NOTIFY_STATE_ACTIVE;
604 relation->tx_state = NOTIFY_STATE_ACTIVE;
605 relation->epoint_id = ea_endpoint->ep_serial;
608 ea_endpoint->ep_join_id = join->j_serial;
610 set_tone(portlist, "proceeding");
611 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
612 message_put(message);
613 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
614 new_state(EPOINT_STATE_IN_PROCEEDING);
616 /* send setup to join */
617 trace_header("ACTION partyline (calling)", DIRECTION_NONE);
618 add_trace("room", NULL, "%d", partyline);
619 add_trace("jingle", NULL, (jingle)?"on":"off");
621 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP);
622 message->param.setup.partyline = partyline;
623 message->param.setup.partyline_jingle = jingle;
624 memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info));
625 memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info));
626 memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info));
627 memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info));
628 message_put(message);
633 * process hangup of all calls
635 void EndpointAppPBX::action_hangup_call(void)
639 trace_header("ACTION hangup", DIRECTION_NONE);
642 if (e_ext.number[0] == '\0')
644 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);
647 if (!(read_extension(&e_ext, e_ext.number)))
649 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);
652 if (e_dialinginfo.id[0] == '\0')
654 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last dialed number because nothing was dialed.\n", ea_endpoint->ep_serial, e_ext.number);
657 if (!strcmp(e_dialinginfo.id, e_ext.last_out[0]))
659 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);
664 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id);
668 UCPY(e_ext.last_out[i], e_ext.last_out[i-1]);
671 SCPY(e_ext.last_out[0], e_dialinginfo.id);
673 /* write extension */
674 write_extension(&e_ext, e_ext.number);
679 * process dialing 'login'
681 void EndpointAppPBX::action_dialing_login(void)
683 struct port_list *portlist = ea_endpoint->ep_portlist;
684 struct message *message;
686 struct route_param *rparam;
688 /* extension parameter */
689 if ((rparam = routeparam(e_action, PARAM_EXTENSION)))
691 /* extension is given by parameter */
692 extension = rparam->string_value;
693 if (extension[0] == '\0')
695 if (!read_extension(&e_ext, extension))
697 trace_header("ACTION login (extension doesn't exist)", DIRECTION_NONE);
698 add_trace("extension", NULL, "%s", extension);
700 /* extension doesn't exist */
701 new_state(EPOINT_STATE_OUT_DISCONNECT);
702 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
703 set_tone(portlist, "cause_86");
708 /* extension must be given by dialstring */
709 extension = e_extdialing;
710 if (extension[0] == '\0')
712 if (!read_extension(&e_ext, extension))
714 trace_header("ACTION login (extension incomplete or does not exist)", DIRECTION_NONE);
715 add_trace("extension", NULL, "%s", extension);
721 /* we changed our extension */
722 SCPY(e_ext.number, extension);
723 new_state(EPOINT_STATE_CONNECT);
727 /* send connect with extension's caller id (COLP) */
728 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
729 SCPY(message->param.connectinfo.id, e_ext.callerid);
730 message->param.connectinfo.ntype = e_ext.callerid_type;
731 if (e_ext.callerid_present==INFO_PRESENT_ALLOWED && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
732 message->param.connectinfo.present = INFO_PRESENT_RESTRICTED;
733 else message->param.connectinfo.present = e_ext.callerid_present;
734 /* handle restricted caller ids */
735 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);
736 /* display callerid if desired for extension */
737 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));
738 message->param.connectinfo.ntype = e_ext.callerid_type;
739 message_put(message);
740 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
742 /* set our caller id */
743 SCPY(e_callerinfo.id, e_ext.callerid);
744 e_callerinfo.ntype = e_ext.callerid_type;
745 e_callerinfo.present = e_ext.callerid_present;
747 /* enable connectedmode */
751 if (!(rparam = routeparam(e_action, PARAM_NOPASSWORD)))
753 /* make call state to enter password */
754 trace_header("ACTION login (ask for password)", DIRECTION_NONE);
755 add_trace("extension", NULL, "%s", e_ext.number);
757 new_state(EPOINT_STATE_IN_OVERLAP);
760 e_action = &action_password;
762 e_match_to_action = NULL;
763 e_dialinginfo.id[0] = '\0';
764 e_extdialing = strchr(e_dialinginfo.id, '\0');
767 e_password_timeout = now+20;
773 /* make call state */
774 new_state(EPOINT_STATE_IN_OVERLAP);
775 e_ruleset = ruleset_main;
777 e_rule = e_ruleset->rule_first;
779 e_dialinginfo.id[0] = '\0';
780 e_extdialing = e_dialinginfo.id;
781 set_tone(portlist, "dialpbx");
787 * process init 'change_callerid'
789 void EndpointAppPBX::action_init_change_callerid(void)
791 struct port_list *portlist = ea_endpoint->ep_portlist;
793 if (!e_ext.change_callerid)
795 /* service not available */
796 trace_header("ACTION change-callerid (denied for this caller)", DIRECTION_NONE);
798 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
799 new_state(EPOINT_STATE_OUT_DISCONNECT);
800 set_tone(portlist,"cause_87");
805 /* process dialing callerid
807 void EndpointAppPBX::_action_callerid_calleridnext(int next)
809 struct port_list *portlist = ea_endpoint->ep_portlist;
810 struct route_param *rparam;
811 char buffer[64], *callerid;
812 char old_id[64] = "", new_id[64] = "";
813 int old_type=0, new_type=0, old_present=0, new_present=0;
815 if ((rparam = routeparam(e_action, PARAM_CALLERID)))
817 /* the caller ID is given by parameter */
818 callerid = rparam->string_value;
821 /* caller ID is dialed */
822 if (!strchr(e_extdialing, '#'))
824 /* no complete ID yet */
827 *strchr(e_extdialing, '#') = '\0';
828 callerid = e_extdialing;
831 /* given callerid type */
832 if ((rparam = routeparam(e_action, PARAM_CALLERIDTYPE)))
833 switch(rparam->integer_value)
835 case INFO_NTYPE_SUBSCRIBER:
836 SPRINT(buffer, "s%s", callerid);
839 case INFO_NTYPE_NATIONAL:
840 SPRINT(buffer, "n%s", callerid);
843 case INFO_NTYPE_INTERNATIONAL:
844 SPRINT(buffer, "i%s", callerid);
848 SPRINT(buffer, "%s", callerid);
853 /* caller id complete, dialing with new caller id */
854 /* write new parameters */
855 if (read_extension(&e_ext, e_ext.number))
857 old_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
858 old_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
859 SCPY(old_id, (!next)?e_ext.callerid:e_ext.id_next_call);
860 if (callerid[0] == '\0')
863 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
867 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_ALLOWED;
868 if ((rparam = routeparam(e_action, PARAM_PRESENT))) if (rparam->integer_value == 0)
869 (!next)?e_ext.callerid_present:e_ext.id_next_call_present = INFO_PRESENT_RESTRICTED;
870 if (e_ext.callerid_type == INFO_NTYPE_UNKNOWN) /* if callerid is unknown, the given id is not nationalized */
872 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, callerid);
873 (!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN;
876 SCPY((!next)?e_ext.callerid:e_ext.id_next_call, nationalize_callerinfo(callerid,&((!next)?e_ext.callerid_type:e_ext.id_next_call_type)));
878 if (!next) e_ext.id_next_call_type = -1;
879 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);
881 new_present = (!next)?e_ext.callerid_present:e_ext.id_next_call_present;
882 new_type = (!next)?e_ext.callerid_type:e_ext.id_next_call_type;
883 SCPY(new_id, (!next)?e_ext.callerid:e_ext.id_next_call);
884 write_extension(&e_ext, e_ext.number);
887 /* function activated */
889 trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE);
891 trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE);
892 add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type));
893 add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
894 add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type));
895 add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed");
897 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
898 new_state(EPOINT_STATE_OUT_DISCONNECT);
899 set_tone(portlist,"activated");
902 /* process dialing callerid for all call
904 void EndpointAppPBX::action_dialing_callerid(void)
906 _action_callerid_calleridnext(0);
909 /* process dialing callerid for next call
911 void EndpointAppPBX::action_dialing_calleridnext(void)
913 _action_callerid_calleridnext(1);
918 * process init 'change_forward'
920 void EndpointAppPBX::action_init_change_forward(void)
922 struct port_list *portlist = ea_endpoint->ep_portlist;
924 if (!e_ext.change_forward)
926 trace_header("ACTION change-forward (denied for this caller)", DIRECTION_NONE);
928 /* service not available */
929 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
930 new_state(EPOINT_STATE_OUT_DISCONNECT);
931 set_tone(portlist,"cause_87");
936 /* process dialing forwarding
938 void EndpointAppPBX::action_dialing_forward(void)
940 struct port_list *portlist = ea_endpoint->ep_portlist;
941 int diversion = INFO_DIVERSION_CFU;
942 char *dest = e_extdialing;
943 struct route_param *rparam;
945 /* if diversion type is given */
946 if ((rparam = routeparam(e_action, PARAM_DIVERSION)))
947 diversion = rparam->integer_value;
949 if ((rparam = routeparam(e_action, PARAM_DEST)))
951 /* if destination is given */
952 dest = rparam->string_value;
955 if (!strchr(e_extdialing, '#'))
957 *strchr(e_extdialing, '#') = '\0';
961 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing forwarding to '%s'.\n", ea_endpoint->ep_serial, e_ext.number, dest);
962 if (read_extension(&e_ext, e_ext.number))
966 case INFO_DIVERSION_CFU:
967 trace_header("ACTION change-forward (new CFU=unconditional)", DIRECTION_NONE);
968 add_trace("destin'", NULL, "%s", dest);
970 SCPY(e_ext.cfu, dest);
972 case INFO_DIVERSION_CFB:
973 trace_header("ACTION change-forward (new CFB=busy)", DIRECTION_NONE);
974 add_trace("destin'", NULL, "%s", dest);
976 SCPY(e_ext.cfb, dest);
978 case INFO_DIVERSION_CFNR:
979 if ((rparam = routeparam(e_action, PARAM_DELAY)))
980 e_ext.cfnr_delay = rparam->integer_value;
981 trace_header("ACTION change-forward (new CFNR=no response)", DIRECTION_NONE);
982 add_trace("destin'", NULL, "%s", dest);
983 add_trace("delay", NULL, "%s", e_ext.cfnr_delay);
985 SCPY(e_ext.cfnr, dest);
987 case INFO_DIVERSION_CFP:
988 trace_header("ACTION change-forward (new CFP=parallel)", DIRECTION_NONE);
989 add_trace("destin'", NULL, "%s", dest);
991 SCPY(e_ext.cfp, dest);
994 write_extension(&e_ext, e_ext.number);
996 /* function (de)activated */
997 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
998 new_state(EPOINT_STATE_OUT_DISCONNECT);
1000 set_tone(portlist,"activated");
1002 set_tone(portlist,"deactivated");
1006 /* process dialing redial
1008 void EndpointAppPBX::action_init_redial_reply(void)
1010 struct port_list *portlist = ea_endpoint->ep_portlist;
1013 if (!e_ext.last_out[0])
1015 trace_header("ACTION redial/reply (no last number stored)", DIRECTION_NONE);
1017 new_state(EPOINT_STATE_OUT_DISCONNECT);
1018 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1019 set_tone(portlist, "cause_3f");
1024 /* process dialing redial
1026 void EndpointAppPBX::_action_redial_reply(int in)
1028 struct message *message;
1030 struct route_param *rparam;
1032 last = (in)?e_ext.last_in[0]:e_ext.last_out[0];
1034 /* if no display is available */
1035 if (!e_ext.display_menu)
1037 if (ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_IN && ea_endpoint->ep_portlist->port_type!=PORT_TYPE_DSS1_NT_OUT)
1040 /* if select is not given */
1041 if (!(rparam = routeparam(e_action, PARAM_SELECT)))
1045 if (e_extdialing[0]=='*' || e_extdialing[0]=='1')
1047 /* find prev entry */
1053 if (e_extdialing[0]=='#' || e_extdialing[0]=='3')
1055 /* find next entry */
1057 if (e_select >= MAX_REMEMBER)
1060 if (e_ext.last_in[e_select][0] == '\0')
1063 if (e_ext.last_out[e_select][0] == '\0')
1068 last = (in)?e_ext.last_in[e_select]:e_ext.last_out[e_select];
1069 if (e_extdialing[0]=='0' || e_extdialing[0]=='2')
1073 trace_header("ACTION reply (dialing)", DIRECTION_NONE);
1075 trace_header("ACTION redial (dialing)", DIRECTION_NONE);
1076 add_trace("number", NULL, "%s", last);
1077 add_trace("last but", NULL, "%d", e_select);
1079 SCPY(e_dialinginfo.id, last);
1080 e_extdialing = e_dialinginfo.id;
1085 e_extdialing[0] = '\0';
1087 /* send display message to port */
1088 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1089 if (!strncmp(last, "extern:", 7))
1090 SPRINT(message->param.notifyinfo.display, "(%d) %s ext", e_select+1, last+7);
1092 if (!strncmp(last, "intern:", 7))
1093 SPRINT(message->param.notifyinfo.display, "(%d) %s int", e_select+1, last+7);
1095 if (!strncmp(last, "chan:", 4))
1096 SPRINT(message->param.notifyinfo.display, "(%d) %s chan", e_select+1, last+5);
1098 if (!strncmp(last, "vbox:", 5))
1099 SPRINT(message->param.notifyinfo.display, "(%d) %s vbox", e_select+1, last+5);
1101 SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -");
1102 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
1103 message_put(message);
1104 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1107 /* process dialing redial
1109 void EndpointAppPBX::action_dialing_redial(void)
1111 _action_redial_reply(0);
1114 /* process dialing reply
1116 void EndpointAppPBX::action_dialing_reply(void)
1118 _action_redial_reply(1);
1122 /* dialing powerdialing delay
1124 void EndpointAppPBX::action_dialing_powerdial(void)
1126 struct port_list *portlist = ea_endpoint->ep_portlist;
1127 struct message *message;
1128 struct route_param *rparam;
1130 /* power dialing only possible if we have a last dialed number */
1131 if (!e_ext.last_out[0])
1133 trace_header("ACTION powerdial (no last number stored)", DIRECTION_NONE);
1135 new_state(EPOINT_STATE_OUT_DISCONNECT);
1136 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1137 set_tone(portlist, "cause_3f");
1142 if ((rparam = routeparam(e_action, PARAM_LIMIT)))
1144 e_powerlimit = rparam->integer_value;
1151 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1153 e_powerdelay = rparam->integer_value;
1156 /* delay incomplete */
1157 if (!strchr(e_extdialing, '#'))
1159 *strchr(e_extdialing, '#') = '\0';
1160 e_powerdelay = e_extdialing[0]?atoi(e_extdialing): 0;
1163 if (e_powerdelay < 1)
1165 trace_header("ACTION powerdial (dialing)", DIRECTION_NONE);
1166 add_trace("number", NULL, "%s", e_ext.last_out[0]);
1167 add_trace("delay", NULL, "%d", e_powerdelay);
1170 /* send connect to avoid overlap timeout */
1171 // new_state(EPOINT_STATE_CONNECT); connect may prevent further dialing
1172 if (e_ext.number[0])
1174 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1175 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1176 message_put(message);
1177 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1180 SCPY(e_dialinginfo.id, e_ext.last_out[0]);
1181 e_powerdialing = -1; /* indicates the existence of powerdialing but no redial time given */
1190 void EndpointAppPBX::action_dialing_callback(void)
1192 struct port_list *portlist = ea_endpoint->ep_portlist;
1193 struct route_param *rparam;
1194 struct extension cbext;
1196 portlist = ea_endpoint->ep_portlist;
1198 /* check given extension */
1199 if (!(rparam = routeparam(e_action, PARAM_EXTENSION)))
1202 trace_header("ACTION callback (no extension defined)", DIRECTION_NONE);
1206 new_state(EPOINT_STATE_OUT_DISCONNECT);
1207 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1208 set_tone(portlist, "cause_3f");
1210 e_cbcaller[0] = e_cbdialing[0] = '\0';
1214 /* if extension is given */
1215 SCPY(e_cbcaller, rparam->string_value);
1216 if (e_cbcaller[0] == '\0')
1219 /* read callback extension */
1220 memset(&cbext, 0, sizeof(cbext));
1221 if (!read_extension(&cbext, e_cbcaller))
1223 trace_header("ACTION callback (extension doesn't exist)", DIRECTION_NONE);
1224 add_trace("extension", NULL, "%s", e_cbcaller);
1229 /* if password is not given */
1230 if (cbext.password[0] == '\0')
1232 trace_header("ACTION callback (no password set)", DIRECTION_NONE);
1233 add_trace("extension", NULL, "%s", e_cbcaller);
1238 /* callback only possible if callerid exists OR it is given */
1239 if ((rparam = routeparam(e_action, PARAM_CALLTO)))
1240 SCPY(e_cbto, rparam->string_value);
1243 trace_header("ACTION callback (alternative caller id)", DIRECTION_NONE);
1244 add_trace("extension", NULL, "%s", e_cbcaller);
1245 add_trace("callerid", NULL, "%s", e_cbto);
1247 SCPY(e_callerinfo.id, e_cbto);
1248 e_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
1249 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1251 if (e_callerinfo.id[0]=='\0' || e_callerinfo.present==INFO_PRESENT_NOTAVAIL)
1253 trace_header("ACTION callback (no caller ID available)", DIRECTION_NONE);
1254 add_trace("extension", NULL, "%s", e_cbcaller);
1259 e_callerinfo.present = INFO_PRESENT_ALLOWED;
1264 * process hangup 'callback'
1266 void EndpointAppPBX::action_hangup_callback(void)
1268 struct route_param *rparam;
1272 delay = 2; /* default value */
1273 if ((rparam = routeparam(e_action, PARAM_DELAY)))
1274 if (rparam->integer_value>0)
1275 delay = rparam->integer_value;
1277 /* dialing after callback */
1278 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1279 SCPY(e_cbdialing, rparam->string_value);
1281 SCPY(e_cbdialing, e_extdialing);
1283 trace_header("ACTION callback (dialing)", DIRECTION_NONE);
1284 add_trace("extension", NULL, "%s", e_cbcaller);
1285 add_trace("caller id", NULL, "%s", e_callerinfo.id);
1286 add_trace("delay", NULL, "%d", delay);
1287 add_trace("dialing", NULL, "%s", e_cbdialing);
1290 /* set time to callback */
1291 e_callback = now_d + delay;
1296 * dialing action abbreviation
1298 void EndpointAppPBX::action_dialing_abbrev(void)
1300 struct port_list *portlist = ea_endpoint->ep_portlist;
1301 char *abbrev, *phone, *name;
1304 portlist = ea_endpoint->ep_portlist;
1306 /* abbrev dialing is only possible if we have a caller defined */
1307 if (!e_ext.number[0])
1309 trace_header("ACTION abbreviation (only for extension)", DIRECTION_NONE);
1311 new_state(EPOINT_STATE_OUT_DISCONNECT);
1312 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1313 set_tone(portlist, "cause_3f");
1317 /* check abbreviation */
1318 abbrev = e_extdialing;
1321 result = parse_phonebook(e_ext.number, &abbrev, &phone, &name);
1324 trace_header("ACTION abbreviation (not found)", DIRECTION_NONE);
1325 add_trace("abbrev", NULL, "%s", abbrev);
1327 new_state(EPOINT_STATE_OUT_DISCONNECT);
1328 message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, "");
1329 set_tone(portlist, "cause_01");
1332 if (result == -1) /* may match if more digits are dialed */
1337 /* dial abbreviation */
1338 trace_header("ACTION abbreviation (dialing)", DIRECTION_NONE);
1339 add_trace("abbrev", NULL, "%s", abbrev);
1340 add_trace("number", NULL, "%s", phone);
1341 if (name) if (name[0])
1342 add_trace("name", NULL, "%s", name);
1344 SCPY(e_dialinginfo.id, phone);
1345 e_extdialing = e_dialinginfo.id;
1351 /* process dialing 'test'
1353 void EndpointAppPBX::action_dialing_test(void)
1357 struct port_list *portlist = ea_endpoint->ep_portlist;
1358 struct message *message;
1360 char testcode[32] = "";
1361 struct route_param *rparam;
1363 /* given testcode */
1364 if ((rparam = routeparam(e_action, PARAM_PREFIX)))
1365 SCPY(testcode, rparam->string_value);
1366 SCAT(testcode, e_extdialing);
1371 trace_header("ACTION test", DIRECTION_NONE);
1372 add_trace("test", NULL, "proceeding");
1374 new_state(EPOINT_STATE_IN_PROCEEDING);
1375 set_tone(portlist, "proceeding");
1376 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
1377 message_put(message);
1378 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1382 trace_header("ACTION test", DIRECTION_NONE);
1383 add_trace("test", NULL, "alerting");
1385 new_state(EPOINT_STATE_IN_ALERTING);
1386 set_tone(portlist, "ringpbx");
1387 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
1388 message_put(message);
1389 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1393 trace_header("ACTION test", DIRECTION_NONE);
1394 add_trace("test", NULL, "echo");
1396 new_state(EPOINT_STATE_CONNECT);
1397 if (e_ext.number[0])
1399 set_tone(portlist, NULL);
1400 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1401 SCPY(e_connectinfo.id, e_callerinfo.id);
1402 SCPY(e_connectinfo.extension, e_callerinfo.extension);
1403 e_connectinfo.itype = e_callerinfo.itype;
1404 e_connectinfo.ntype = e_callerinfo.ntype;
1405 e_connectinfo.present = e_callerinfo.present;
1406 e_connectinfo.screen = e_callerinfo.screen;
1407 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1408 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(struct connect_info));
1409 /* handle restricted caller ids */
1410 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);
1411 /* display callerid if desired for extension */
1412 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));
1413 message_put(message);
1414 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1416 port = find_port_id(portlist->port_id);
1419 port->set_echotest(1);
1424 trace_header("ACTION test", DIRECTION_NONE);
1425 add_trace("test", NULL, "tone");
1427 new_state(EPOINT_STATE_CONNECT);
1428 if (e_ext.number[0])
1430 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1431 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1432 message_put(message);
1433 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1434 set_tone(portlist, "test");
1438 trace_header("ACTION test", DIRECTION_NONE);
1439 add_trace("test", NULL, "hold music");
1441 new_state(EPOINT_STATE_CONNECT);
1442 if (e_ext.number[0])
1444 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1445 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1446 message_put(message);
1447 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1448 set_tone(portlist, "hold");
1452 if (strlen(testcode) < 4)
1455 cause = atoi(testcode+1);
1458 trace_header("ACTION test", DIRECTION_NONE);
1459 add_trace("test", NULL, "announcement");
1460 add_trace("cause", NULL, "%d", cause);
1462 new_state(EPOINT_STATE_CONNECT);
1463 if (e_ext.number[0])
1465 SPRINT(causestr,"cause_%02x",cause);
1466 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1467 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1468 message_put(message);
1469 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1470 set_tone(portlist, causestr);
1474 if (strlen(testcode) < 4)
1477 cause = atoi(testcode+1);
1480 trace_header("ACTION test", DIRECTION_NONE);
1481 add_trace("test", NULL, "disconnect");
1482 add_trace("cause", NULL, "%d", cause);
1484 new_state(EPOINT_STATE_OUT_DISCONNECT);
1485 SPRINT(causestr,"cause_%02x",cause);
1486 message_disconnect_port(portlist, cause, LOCATION_PRIVATE_LOCAL, "");
1487 set_tone(portlist, causestr);
1490 case '8': /* release */
1491 trace_header("ACTION test", DIRECTION_NONE);
1492 add_trace("test", NULL, "release");
1493 add_trace("cause", NULL, "16");
1495 new_state(EPOINT_STATE_OUT_DISCONNECT);
1496 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
1497 set_tone(portlist, "release");
1500 case '9': /* text callerid test */
1501 trace_header("ACTION test", DIRECTION_NONE);
1502 add_trace("test", NULL, "callerid");
1504 new_state(EPOINT_STATE_CONNECT);
1505 if (e_ext.number[0])
1507 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
1508 SCPY(e_connectinfo.id, "12345678");
1509 SCPY(e_connectinfo.name, "Welcome to LCR");
1510 SCPY(e_connectinfo.display, "Welcome to LCR");
1511 e_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1512 e_connectinfo.present = INFO_PRESENT_ALLOWED;
1513 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
1514 memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(message->param.connectinfo));
1515 message_put(message);
1516 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1517 set_tone(portlist, "hold");
1523 /* process init play
1525 void EndpointAppPBX::action_init_play(void)
1527 struct route_param *rparam;
1528 struct port_list *portlist = ea_endpoint->ep_portlist;
1530 /* check given sample */
1531 if (!(rparam = routeparam(e_action, PARAM_SAMPLE)))
1533 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1537 new_state(EPOINT_STATE_OUT_DISCONNECT);
1538 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
1539 set_tone(portlist, "cause_3f");
1544 /* if sample is given */
1545 if (rparam->string_value[0] == '\0')
1547 trace_header("ACTION play (no sample given)", DIRECTION_NONE);
1552 if (e_ext.number[0])
1555 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1560 * action_*_vbox_play is implemented in "action_vbox.cpp"
1565 * process dialing of calculator
1567 void EndpointAppPBX::action_dialing_calculator(void)
1569 struct port_list *portlist = ea_endpoint->ep_portlist;
1570 struct message *message;
1571 double value1, value2, v, sign1;
1572 int komma1, komma2, k, state, mode, first;
1575 portlist = ea_endpoint->ep_portlist;
1577 /* remove error message */
1578 if (!strncmp(e_extdialing, "Error", 5))
1580 UCPY(e_extdialing, e_extdialing+5);
1582 if (!strncmp(e_extdialing, "inf", 3))
1584 UCPY(e_extdialing, e_extdialing+3);
1586 if (!strncmp(e_extdialing, "-inf", 4))
1588 UCPY(e_extdialing, e_extdialing+4);
1591 /* process dialing */
1604 if (*p>='0' && *p<='9')
1612 if ((p[-1]<'0' || p[-1]>'0') && p[-1]!='.')
1621 case 0: /* first number */
1624 value1 = value1*10 + (*p-'0');
1634 case 1: /* second number */
1637 value2 = value2*10 + (*p-'0');
1654 UCPY(e_extdialing, "Error");
1657 /* if there is a multiplication, we change to / */
1666 /* if there is a division, we change to + */
1675 /* if there is a addition, we change to - */
1684 /* if there is a substraction and a comma, we change to * */
1685 if (p[-1]=='-' && komma1)
1693 /* if there is a substraction and no comma and the first or second value, we change to , */
1702 /* if there is a komma and we are at the first value, we change to * */
1703 if (p[-1]=='.' && state==0)
1712 /* if there is a komma and we are at the second value, we display error */
1713 if (komma2 && state==1)
1715 UCPY(e_extdialing, "Error");
1718 /* if we are at state 1, we write a comma */
1725 /* we assume multiplication */
1732 /* if just a number is displayed, the input is cleared */
1735 *e_extdialing = '\0';
1738 /* calculate the result */
1741 case 0: /* multiply */
1742 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1*value2);
1744 case 1: /* divide */
1745 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1/value2);
1748 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1+value2);
1750 case 3: /* substract */
1751 UNPRINT(e_extdialing, sizeof(e_dialinginfo.id)-strlen(e_dialinginfo.id), "%.8f", sign1*value1-value2);
1754 e_dialinginfo.id[sizeof(e_dialinginfo.id)-1] = '\0';
1755 if (strchr(e_extdialing, '.')) /* remove zeroes */
1757 while (e_extdialing[strlen(e_extdialing)-1] == '0')
1758 e_extdialing[strlen(e_extdialing)-1] = '\0';
1759 if (e_extdialing[strlen(e_extdialing)-1] == '.')
1760 e_extdialing[strlen(e_extdialing)-1] = '\0'; /* and remove dot */
1762 p = strchr(e_extdialing,'\0')-1;
1795 UCPY(e_extdialing, "Error");
1804 /* display dialing */
1805 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1806 SPRINT(message->param.notifyinfo.display, ">%s", e_extdialing);
1807 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);
1808 message_put(message);
1809 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
1814 * process dialing of timer
1816 void EndpointAppPBX::action_dialing_timer(void)
1822 * process 'goto' or 'menu'
1824 void EndpointAppPBX::_action_goto_menu(int mode)
1826 struct port_list *portlist = ea_endpoint->ep_portlist;
1827 struct route_param *rparam;
1829 /* check given ruleset */
1830 if (!(rparam = routeparam(e_action, PARAM_RULESET)))
1833 trace_header("ACTION goto/menu (no ruleset given)", DIRECTION_NONE);
1837 new_state(EPOINT_STATE_OUT_DISCONNECT);
1838 message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, "");
1839 set_tone(portlist, "cause_3f");
1843 if (rparam->string_value[0] == '\0')
1845 e_ruleset = getrulesetbyname(rparam->string_value);
1848 trace_header("ACTION goto/menu (ruleset not found)", DIRECTION_NONE);
1849 add_trace("ruleset", NULL, "%s", rparam->string_value);
1854 /* if the 'menu' was selected, we will flush all digits */
1857 e_dialinginfo.id[0] = 0;
1858 e_extdialing = e_dialinginfo.id;
1861 /* remove digits that are required to match the rule */
1862 if (!(rparam = routeparam(e_action, PARAM_STRIP)))
1865 SCPY(e_dialinginfo.id, e_extdialing);
1866 e_extdialing = e_dialinginfo.id;
1871 trace_header("ACTION goto/menu (change to)", DIRECTION_NONE);
1872 add_trace("ruleset", NULL, "%s", e_ruleset->name);
1873 if (e_dialinginfo.id[0])
1874 add_trace("dialing", NULL, "%s", e_dialinginfo.id);
1875 if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
1877 add_trace("sample", NULL, "%s", rparam->string_value);
1878 set_tone(ea_endpoint->ep_portlist, rparam->string_value);
1882 /* do dialing with new ruleset */
1887 /* process dialing goto
1889 void EndpointAppPBX::action_dialing_goto(void)
1891 _action_goto_menu(0);
1894 /* process dialing menu
1896 void EndpointAppPBX::action_dialing_menu(void)
1898 _action_goto_menu(1);
1903 * process dialing disconnect
1905 void EndpointAppPBX::action_dialing_disconnect(void)
1907 struct route_param *rparam;
1908 struct port_list *portlist = ea_endpoint->ep_portlist;
1909 struct message *message;
1910 int cause = CAUSE_NORMAL; /* normal call clearing */
1911 int location = LOCATION_PRIVATE_LOCAL;
1912 char cause_string[256] = "", display[84] = "";
1914 /* check cause parameter */
1915 if ((rparam = routeparam(e_action, PARAM_CAUSE)))
1917 cause = rparam->integer_value;
1918 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'cause' is given: %d\n", ea_endpoint->ep_serial, cause);
1920 if ((rparam = routeparam(e_action, PARAM_LOCATION)))
1922 location = rparam->integer_value;
1923 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'location' is given: %d\n", ea_endpoint->ep_serial, location);
1927 /* use cause as sample, if not given later */
1928 SPRINT(cause_string, "cause_%02x", cause);
1930 /* check sample parameter */
1931 if ((rparam = routeparam(e_action, PARAM_SAMPLE)))
1933 SCPY(cause_string, rparam->string_value);
1934 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'sample' is given: %s\n", ea_endpoint->ep_serial, cause_string);
1938 if ((rparam = routeparam(e_action, PARAM_DISPLAY)))
1940 SCPY(display, rparam->string_value);
1941 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): 'display' is given: %s\n", ea_endpoint->ep_serial, display);
1944 /* disconnect only if connect parameter is not given */
1945 trace_header("ACTION disconnect", DIRECTION_NONE);
1946 add_trace("cause", "value", "%d", cause);
1947 add_trace("cause", "location", "%d", location);
1948 if (cause_string[0])
1949 add_trace("sample", NULL, "%s", cause_string);
1951 add_trace("display", NULL, "%s", display);
1953 new_state(EPOINT_STATE_OUT_DISCONNECT);
1954 set_tone(portlist, cause_string);
1955 if (!(rparam = routeparam(e_action, PARAM_CONNECT)))
1957 message_disconnect_port(portlist, cause, location, display);
1960 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
1961 SCPY(message->param.notifyinfo.display, display);
1962 message_put(message);
1963 logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
1970 * process dialing help
1972 void EndpointAppPBX::action_dialing_help(void)
1974 /* show all things that would match */
1976 struct numbering *numbering = numbering_int;
1977 char dialing[sizeof(e_dialinginfo.id)];
1979 struct message *message;
1980 struct route_param *rparam;
1982 /* in case we have no menu (this should never happen) */
1987 if (strchr(e_dialinginfo.id,'*'))
1990 e_dialinginfo.id[0] = '\0';
1992 if (strchr(e_dialinginfo.id,'#'))
1995 e_dialinginfo.id[0] = '\0';
1998 /* get position in menu */
2001 /* get last menu position */
2003 while(numbering->next)
2006 numbering = numbering->next;
2010 /* get menu position */
2014 numbering = numbering->next;
2018 numbering = numbering_int;
2025 /* if we dial something else we need to add the prefix and change the action */
2026 if (e_dialinginfo.id[0])
2028 e_action = NUMB_ACTION_NONE;
2029 SCPY(dialing, numbering->prefix);
2030 //we ignore the first digit after selecting
2031 //SCAT(dialing, e_dialinginfo.id);
2032 SCPY(e_dialinginfo.id, dialing);
2033 e_extdialing = e_dialinginfo.id+strlen(numbering->prefix);
2034 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);
2040 /* send display message to port */
2041 message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2042 SPRINT(message->param.notifyinfo.display, ">%s %s%s%s", numbering->prefix, numb_actions[numbering->action], (numbering->param[0])?" ":"", numbering->param);
2043 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);
2044 message_put(message);
2045 logmessage(message->type, message->paramea_endpoint->ep_portlist->port_id, DIRECTION_OUT);
2051 * process dialing deflect
2053 void EndpointAppPBX::action_dialing_deflect(void)
2059 * process dialing setforward
2061 void EndpointAppPBX::action_dialing_setforward(void)
2067 * process hangup 'execute'
2069 void EndpointAppPBX::action_hangup_execute(void)
2071 struct route_param *rparam;
2072 char *command = "", isdn_port[10];
2073 char *argv[7+1]; /* check also number of args below */
2076 /* get script / command */
2077 if ((rparam = routeparam(e_action, PARAM_EXECUTE)))
2078 command = rparam->string_value;
2079 if (command[0] == '\0')
2081 trace_header("ACTION execute (no parameter given)", DIRECTION_NONE);
2085 trace_header("ACTION execute", DIRECTION_NONE);
2086 add_trace("command", NULL, "%s", command);
2090 while(strchr(argv[0], '/'))
2091 argv[0] = strchr(argv[0], '/')+1;
2092 if ((rparam = routeparam(e_action, PARAM_PARAM)))
2094 argv[1] = rparam->string_value;
2097 argv[1+i] = e_extdialing;
2098 argv[2+i] = numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype);
2099 argv[3+i] = e_callerinfo.extension;
2100 argv[4+i] = e_callerinfo.name;
2101 SPRINT(isdn_port, "%d", e_callerinfo.isdn_port);
2102 argv[5+i] = isdn_port;
2103 argv[6+i] = NULL; /* check also number of args above */
2104 execve("/bin/sh", argv, environ);
2109 * process hangup 'file'
2111 void EndpointAppPBX::action_hangup_file(void)
2113 struct route_param *rparam;
2114 char *file, *content, *mode;
2117 /* get file / content */
2118 if (!(rparam = routeparam(e_action, PARAM_FILE)))
2119 file = rparam->string_value;
2122 if (!(rparam = routeparam(e_action, PARAM_CONTENT)))
2123 content = rparam->string_value;
2125 content = e_extdialing;
2126 if (!(rparam = routeparam(e_action, PARAM_APPEND)))
2130 if (file[0] == '\0')
2132 trace_header("ACTION file (no filename given)", DIRECTION_NONE);
2136 if (!(fp = fopen(file, mode)))
2138 trace_header("ACTION file (failed to open)", DIRECTION_NONE);
2139 add_trace("file", "name", "%s", file);
2140 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2144 trace_header("ACTION file", DIRECTION_NONE);
2145 add_trace("file", "name", "%s", file);
2146 add_trace("file", "mode", "%s", (mode[0]=='w')?"write":"append");
2147 add_trace("content", NULL, "%s", content);
2149 fprintf(fp, "%s\n", content);
2155 * process init 'pick'
2157 void EndpointAppPBX::action_init_pick(void)
2159 struct route_param *rparam;
2160 char *extensions = NULL;
2162 if ((rparam = routeparam(e_action, PARAM_EXTENSIONS)))
2163 extensions = rparam->string_value;
2165 trace_header("ACTION pick", DIRECTION_NONE);
2166 if (extensions) if (extensions[0])
2167 add_trace("extensions", NULL, "%s", extensions);
2169 pick_join(extensions);
2174 * process dialing 'password'
2176 void EndpointAppPBX::action_dialing_password(void)
2178 struct port_list *portlist = ea_endpoint->ep_portlist;
2180 /* prompt for password */
2181 if (e_extdialing[0] == '\0')
2183 /* give password tone */
2184 set_tone(portlist, "password");
2186 if (e_extdialing[1] == '\0')
2188 /* give password tone */
2189 set_tone(portlist, "dialing");
2192 /* wait until all digits are dialed */
2193 if (strlen(e_ext.password) != strlen(e_extdialing))
2194 return; /* more digits needed */
2196 /* check the password */
2197 if (e_ext.password[0]=='\0' || (strlen(e_ext.password)==strlen(e_extdialing) && !!strcmp(e_ext.password,e_extdialing)))
2199 trace_header("ACTION password_write (wrong password)", DIRECTION_NONE);
2200 add_trace("dialed", NULL, "%s", e_extdialing);
2202 e_connectedmode = 0;
2204 new_state(EPOINT_STATE_OUT_DISCONNECT);
2205 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2206 set_tone(portlist, "cause_10");
2210 /* write caller id if ACTION_PASSWORD_WRITE was selected */
2212 if (e_action->index == ACTION_PASSWORD_WRITE)
2214 append_callbackauth(e_ext.number, &e_callbackinfo);
2215 trace_header("ACTION password_write (written)", DIRECTION_NONE);
2216 add_trace("dialed", NULL, "%s", e_extdialing);
2220 /* make call state */
2221 new_state(EPOINT_STATE_IN_OVERLAP);
2222 e_ruleset = ruleset_main;
2224 e_rule = e_ruleset->rule_first;
2226 e_dialinginfo.id[0] = '\0';
2227 e_extdialing = e_dialinginfo.id;
2228 set_tone(portlist, "dialpbx");
2231 void EndpointAppPBX::action_dialing_password_wr(void)
2233 action_dialing_password();
2237 /* general process dialing of incoming call
2238 * depending on the detected prefix, subfunctions above (action_*) will be
2241 void EndpointAppPBX::process_dialing(void)
2243 struct port_list *portlist = ea_endpoint->ep_portlist;
2244 struct message *message;
2245 struct route_param *rparam;
2247 //#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.
2248 //PDEBUG(~0, "HANG-BUG-DEBUGGING: entered porcess_dialing\n");
2249 portlist = ea_endpoint->ep_portlist;
2250 /* check if we have a port instance linked to our epoint */
2254 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);
2255 e_action_timeout = 0;
2256 e_match_timeout = 0;
2261 goto portlist_error;
2264 /* check nesting levels */
2265 if (++e_rule_nesting > RULE_NESTING)
2267 trace_header("ACTION (nesting too deep)", DIRECTION_NONE);
2268 add_trace("max-levels", NULL, "%d", RULE_NESTING);
2270 new_state(EPOINT_STATE_OUT_DISCONNECT);
2271 message_disconnect_port(portlist, CAUSE_UNSPECIFIED, LOCATION_PRIVATE_LOCAL, "");
2272 set_tone(portlist, "cause_3f");
2273 e_action_timeout = 0;
2274 e_match_timeout = 0;
2278 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before action-timeout processing\n");
2279 /* process timeout */
2280 if (e_action_timeout)
2282 e_action_timeout = 0;
2283 if (e_state == EPOINT_STATE_CONNECT)
2285 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);
2288 if (e_action->index == ACTION_DISCONNECT
2289 || e_state == EPOINT_STATE_OUT_DISCONNECT)
2291 /* release after disconnect */
2292 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
2295 release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, 0);
2296 e_action = e_action->next;
2299 /* nothing more, so we release */
2300 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action timed out, and we have no next action, so we disconnect.\n", ea_endpoint->ep_serial);
2301 new_state(EPOINT_STATE_OUT_DISCONNECT);
2302 message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, "");
2303 set_tone(portlist, "cause_3f");
2306 goto action_timeout;
2309 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before setup/overlap state checking\n");
2310 if (e_state!=EPOINT_STATE_IN_SETUP
2311 && e_state!=EPOINT_STATE_IN_OVERLAP)
2313 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);
2314 e_match_timeout = 0;
2319 /* check if we do menu selection */
2320 if (e_action==NUMB_ACTION_NONE && (e_dialinginfo.id[0]=='*' || e_dialinginfo.id[0]=='#'))
2321 /* do menu selection */
2322 if (e_ext.display_menu)
2324 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 */
2326 e_dialinginfo.id[0] = '\0';
2327 e_action = NUMB_ACTION_MENU;
2330 e_match_timeout = 0;
2333 /* invalid dialing */
2334 message_disconnect_port(portlist, CAUSE_INCALID, LOCATION_PRIVATE_LOCAL, "");
2335 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT);
2336 message->param.disconnectinfo.cause = CAUSE_INVALID;
2337 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2340 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2341 SCPY(message->param.notifyinfo.display,get_isdn_cause(LOCATION_PRIVATE_LOCAL, epoint->e_ext.display_cause, param->disconnectinfo.location, param->disconnectinfo.cause));
2343 message_put(message);
2344 logmessage(message->type, message->param, portlist->port_id, DIRECTION_OUT);
2346 new_state(EPOINT_STATE_OUT_DISCONNECT);
2347 set_tone(portlist,"cause_1c");
2348 e_match_timeout = 0;
2353 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before e_action==NULL\n");
2354 /* if no action yet, we will call try to find a matching rule */
2357 /* be sure that all selectors are initialized */
2360 /* check for external call */
2361 if (!strncmp(e_dialinginfo.id, "extern:", 7))
2363 e_extdialing = e_dialinginfo.id+7;
2364 e_action = &action_external;
2365 goto process_action;
2367 /* check for internal call */
2368 if (!strncmp(e_dialinginfo.id, "intern:", 7))
2370 e_extdialing = e_dialinginfo.id+7;
2371 e_action = &action_internal;
2372 goto process_action;
2374 /* check for chan call */
2375 if (!strncmp(e_dialinginfo.id, "remote:", 7))
2377 e_extdialing = e_dialinginfo.id+7;
2378 e_action = &action_remote;
2379 goto process_action;
2381 /* check for vbox call */
2382 if (!strncmp(e_dialinginfo.id, "vbox:", 5))
2384 e_extdialing = e_dialinginfo.id+5;
2385 e_action = &action_vbox;
2386 goto process_action;
2389 if (e_match_timeout && now_d>=e_match_timeout)
2391 /* return timeout rule */
2392 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);
2393 e_match_timeout = 0;
2394 e_action = e_match_to_action;
2395 e_extdialing = e_match_to_extdialing;
2396 trace_header("ROUTING (timeout)", DIRECTION_NONE);
2397 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2398 add_trace("line", NULL, "%d", e_action->line);
2402 //PDEBUG(~0, "HANG-BUG-DEBUGGING: before routing\n");
2403 /* check for matching rule */
2404 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);
2407 e_action = route(e_ruleset);
2410 trace_header("ACTION (match)", DIRECTION_NONE);
2411 add_trace("action", NULL, "%s", action_defs[e_action->index].name);
2412 add_trace("line", NULL, "%d", e_action->line);
2417 e_action = &action_disconnect;
2420 trace_header("ACTION (no main ruleset, disconnecting)", DIRECTION_NONE);
2424 //PDEBUG(~0, "HANG-BUG-DEBUGGING: after routing\n");
2428 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): no rule within the current ruleset matches yet.\n", ea_endpoint->ep_serial, e_ext.number);
2433 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): a rule with action '%s' matches.\n", ea_endpoint->ep_serial, action_defs[e_action->index].name);
2438 e_action_timeout = 0;
2439 if (e_action->timeout)
2441 e_action_timeout = now_d + e_action->timeout;
2442 PDEBUG(DEBUG_ROUTE|DEBUG_EPOINT, "EPOINT(%d): action has a timeout of %d secods.\n", ea_endpoint->ep_serial, e_action->timeout);
2446 /* check param proceeding / alerting / connect */
2447 if ((rparam = routeparam(e_action, PARAM_CONNECT)))
2449 /* NOTE: we may not change our state to connect, because dialing will then not possible */
2451 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2452 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT);
2453 message_put(message);
2454 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2456 if ((rparam = routeparam(e_action, PARAM_ALERTING)))
2458 /* NOTE: we may not change our state to alerting, because dialing will then not possible */
2459 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2460 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING);
2461 message_put(message);
2462 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2464 if ((rparam = routeparam(e_action, PARAM_PROCEEDING)))
2466 /* NOTE: we may not change our state to proceeding, because dialing will then not possible */
2467 memset(&e_connectinfo, 0, sizeof(e_connectinfo));
2468 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING);
2469 message_put(message);
2470 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2473 if (action_defs[e_action->index].init_func)
2475 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);
2476 (this->*(action_defs[e_action->index].init_func))();
2478 if (e_state!=EPOINT_STATE_IN_SETUP
2479 && e_state!=EPOINT_STATE_IN_OVERLAP)
2481 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);
2482 goto display_action;
2486 /* show what we are doing */
2487 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);
2488 /* go to action's dialing function */
2489 if (action_defs[e_action->index].dialing_func)
2491 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);
2492 (this->*(action_defs[e_action->index].dialing_func))();
2495 /* display selected dialing action if enabled and still in setup state */
2499 if (e_action->index==ACTION_MENU
2500 || e_action->index==ACTION_REDIAL
2501 || e_action->index==ACTION_REPLY
2502 || e_action->index==ACTION_TIMER
2503 || e_action->index==ACTION_CALCULATOR
2504 || e_action->index==ACTION_TEST)
2508 if (!e_ext.display_dialing)
2510 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*/)
2511 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 */
2513 message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
2517 SPRINT(message->param.notifyinfo.display, "> %s", e_dialinginfo.id);
2520 SPRINT(message->param.notifyinfo.display, "%s%s%s", action_defs[e_action->index].name, (e_extdialing[0])?" ":"", e_extdialing);
2523 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s'\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display);
2524 message_put(message);
2525 logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT);
2534 /* some services store information after hangup */
2535 void EndpointAppPBX::process_hangup(int cause, int location)
2537 char callertext[256], dialingtext[256];
2538 int writeext = 0, i;
2540 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal '%s'\n", ea_endpoint->ep_serial, e_ext.number);
2541 if (e_ext.number[0])
2543 if (read_extension(&e_ext, e_ext.number))
2553 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);
2554 switch(e_dialinginfo.itype)
2556 case INFO_ITYPE_CHAN:
2557 SPRINT(dialingtext, "chan:%s", e_dialinginfo.id);
2559 case INFO_ITYPE_ISDN_EXTENSION:
2560 SPRINT(dialingtext, "intern:%s", e_dialinginfo.id);
2562 case INFO_ITYPE_VBOX:
2563 SPRINT(dialingtext, "vbox:%s", e_dialinginfo.id);
2566 SPRINT(dialingtext, "%s", e_dialinginfo.id);
2569 if (e_callerinfo.id[0])
2570 SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype));
2572 SPRINT(callertext, "unknown");
2573 /* allpy restriction */
2574 if (!e_ext.anon_ignore && e_callerinfo.present==INFO_PRESENT_RESTRICTED)
2575 SPRINT(callertext, "anonymous");
2576 if (e_callerinfo.extension[0]) /* add intern if present */
2577 UNPRINT(strchr(callertext,'\0'), sizeof(callertext)-1+strlen(callertext), " (intern %s)", e_callerinfo.extension);
2578 write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location);
2580 /* store last received call for reply-list */
2581 if (e_callerinfo.id[0] || e_callerinfo.extension[0])
2582 if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED)
2584 if (e_callerinfo.extension[0])
2585 SPRINT(callertext, "intern:%s", e_callerinfo.extension);
2587 SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype));
2588 if (!!strcmp(callertext, e_ext.last_in[0]))
2593 UCPY(e_ext.last_in[i], e_ext.last_in[i-1]);
2596 SCPY(e_ext.last_in[0], callertext);
2597 writeext |= 1; /* store extension later */
2598 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]);
2600 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);
2604 /* write extension if needed */
2605 if (writeext == 0x11)
2606 write_extension(&e_ext, e_ext.number);
2610 if (action_defs[e_action->index].hangup_func)
2612 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);
2613 (this->*(action_defs[e_action->index].hangup_func))();