X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=action.cpp;h=d0a1c9f81391fffb74ef0bde62e8dac226392fa9;hp=3e8ba8b03a49c8e838560fe68e16bd8d68d958a0;hb=08aad9a8c5ad279759e0a870b1dd0d8159ce3444;hpb=ef3fc1931a2fa82f482d21fb1296735206463d3a diff --git a/action.cpp b/action.cpp index 3e8ba8b..d0a1c9f 100644 --- a/action.cpp +++ b/action.cpp @@ -9,114 +9,65 @@ ** ** \*****************************************************************************/ -#include -#include -#include -#include -#include #include "main.h" -#include "linux/isdnif.h" extern char **environ; -/* create caller id from digits by comparing with national and international - * prefixes. - */ -char *nationalize_callerinfo(char *string, int *ntype) -{ - if (!strncmp(options.international, string, strlen(options.international))) - { - *ntype = INFO_NTYPE_INTERNATIONAL; - return(string+strlen(options.international)); - } - if (!strncmp(options.national, string, strlen(options.national))) - { - *ntype = INFO_NTYPE_NATIONAL; - return(string+strlen(options.national)); - } - *ntype = INFO_NTYPE_SUBSCRIBER; - return(string); -} - -/* create number (including access codes) from caller id - * prefixes. - */ -char *numberrize_callerinfo(char *string, int ntype) -{ - static char result[256]; - - switch(ntype) - { - case INFO_NTYPE_INTERNATIONAL: - UCPY(result, options.international); - SCAT(result, string); - return(result); - break; - - case INFO_NTYPE_NATIONAL: - UCPY(result, options.national); - SCAT(result, string); - return(result); - break; - - default: - return(string); - } -} - - /* - * process init 'internal' / 'external' / 'asterisk' / 'vbox-record' / 'partyline'... + * process init 'internal' / 'external' / 'remote' / 'vbox-record' / 'partyline'... */ -void EndpointAppPBX::_action_init_call(int asterisk) +int EndpointAppPBX::_action_init_call(char *remote) { - class Call *call; + class Join *join; struct port_list *portlist = ea_endpoint->ep_portlist; struct admin_list *admin; /* a created call, this should never happen */ - if (ea_endpoint->ep_call_id) + if (ea_endpoint->ep_join_id) { if (options.deb & DEBUG_EPOINT) PERROR("EPOINT(%d): We already have a call instance, this should never happen!\n", ea_endpoint->ep_serial); - return; + return(0); } - /* create call */ - PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new call instance.\n", ea_endpoint->ep_serial); - if (asterisk) + /* create join */ + PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial); + if (remote) { - admin = admin_list; + admin = admin_first; while(admin) { - if (admin->asterisk) + if (admin->remote_name[0] && !strcmp(admin->remote_name, remote)) break; admin = admin->next; } if (!admin) { /* resource not available */ - message_disconnect_port(portlist, CAUSE_RESSOURCEUNAVAIL, LOCATION_PRIVATE_LOCAL, ""); + trace_header("ACTION remote (not available)", DIRECTION_NONE); + add_trace("application", NULL, "%s", remote); + end_trace(); + message_disconnect_port(portlist, CAUSE_OUTOFORDER, LOCATION_PRIVATE_LOCAL, ""); new_state(EPOINT_STATE_OUT_DISCONNECT); - set_tone(portlist,"cause_22"); - return; + set_tone(portlist,"cause_1b"); + return(0); } - call = new CallAsterisk(ea_endpoint->ep_serial); + join = new JoinRemote(ea_endpoint->ep_serial, remote, admin->sock); } else - call = new CallPBX(ea_endpoint); - if (!call) - FATAL("No memoy for Call instance.\n"); - ea_endpoint->ep_call_id = call->c_serial; + join = new JoinPBX(ea_endpoint); + if (!join) + FATAL("No memoy for Join instance.\n"); + ea_endpoint->ep_join_id = join->j_serial; + return(1); } void EndpointAppPBX::action_init_call(void) { - _action_init_call(0); + _action_init_call(NULL); } -void EndpointAppPBX::action_init_chan(void) +void EndpointAppPBX::action_init_remote(void) { - _action_init_call(1); } /* @@ -129,7 +80,7 @@ void EndpointAppPBX::action_dialing_internal(void) struct redir_info redirinfo; struct dialing_info dialinginfo; struct port_list *portlist = ea_endpoint->ep_portlist; - struct message *message; + struct lcr_msg *message; struct extension ext; struct route_param *rparam; @@ -137,7 +88,7 @@ void EndpointAppPBX::action_dialing_internal(void) set_tone(portlist, "proceeding"); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); new_state(EPOINT_STATE_IN_PROCEEDING); /* create bearer/caller/dialinginfo */ @@ -196,6 +147,7 @@ void EndpointAppPBX::action_dialing_internal(void) trace_header("ACTION extension (extension doesn't exist)", DIRECTION_NONE); add_trace("extension", NULL, dialinginfo.id); end_trace(); + release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0); new_state(EPOINT_STATE_OUT_DISCONNECT); message_disconnect_port(portlist, CAUSE_UNALLOCATED, LOCATION_PRIVATE_LOCAL, ""); set_tone(portlist, "cause_86"); @@ -208,6 +160,7 @@ void EndpointAppPBX::action_dialing_internal(void) add_trace("extension", NULL, dialinginfo.id); end_trace(); new_state(EPOINT_STATE_OUT_DISCONNECT); + release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0); message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, ""); set_tone(portlist, "cause_81"); return; @@ -217,7 +170,7 @@ void EndpointAppPBX::action_dialing_internal(void) trace_header("ACTION extension (calling)", DIRECTION_NONE); add_trace("extension", NULL, dialinginfo.id); end_trace(); - message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_call_id, EPOINT_TO_CALL, MESSAGE_SETUP); + message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP); memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info)); memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info)); memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info)); @@ -235,7 +188,7 @@ void EndpointAppPBX::action_dialing_external(void) struct dialing_info dialinginfo; char *p; struct port_list *portlist = ea_endpoint->ep_portlist; - struct message *message; + struct lcr_msg *message; struct route_param *rparam; /* special processing of delete characters '*' and '#' */ @@ -342,7 +295,7 @@ void EndpointAppPBX::action_dialing_external(void) { trace_header("ACTION extern (calling denied)", DIRECTION_NONE); end_trace(); - release(RELEASE_CALL, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0); + release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0); set_tone(portlist, "cause_82"); denied: message_disconnect_port(portlist, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, ""); @@ -359,7 +312,7 @@ void EndpointAppPBX::action_dialing_external(void) { trace_header("ACTION extern (national calls denied)", DIRECTION_NONE); end_trace(); - release(RELEASE_CALL, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0); + release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0); set_tone(portlist, "cause_83"); goto denied; } @@ -373,7 +326,7 @@ void EndpointAppPBX::action_dialing_external(void) { trace_header("ACTION extern (international calls denied)", DIRECTION_NONE); end_trace(); - release(RELEASE_CALL, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, LOCATION_PRIVATE_LOCAL, 0); + release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_REJECTED, 0, 0); set_tone(portlist, "cause_84"); goto denied; } @@ -385,7 +338,7 @@ void EndpointAppPBX::action_dialing_external(void) if (dialinginfo.interfaces[0]) add_trace("interfaces", NULL, dialinginfo.interfaces); end_trace(); - message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_call_id, EPOINT_TO_CALL, MESSAGE_SETUP); + message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP); memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info)); memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info)); memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info)); @@ -394,15 +347,82 @@ void EndpointAppPBX::action_dialing_external(void) } -void EndpointAppPBX::action_dialing_chan(void) +void EndpointAppPBX::action_dialing_remote(void) { - struct port_list *portlist = ea_endpoint->ep_portlist; + struct route_param *rparam; + struct port_list *portlist = ea_endpoint->ep_portlist; + struct lcr_msg *message; + struct capa_info capainfo; + struct caller_info callerinfo; + struct redir_info redirinfo; + struct dialing_info dialinginfo; + char context[128] = ""; + char remote[32]; - trace_header("ACTION channel (not implemented)", DIRECTION_NONE); - end_trace(); - message_disconnect_port(portlist, CAUSE_UNIMPLEMENTED, LOCATION_PRIVATE_LOCAL, ""); - new_state(EPOINT_STATE_OUT_DISCONNECT); - set_tone(portlist,"cause_4f"); + if (!ea_endpoint->ep_join_id) + { + /* no join yet, sending setup */ + if (!(rparam = routeparam(e_action, PARAM_APPLICATION))) + { + trace_header("ACTION remote (no application given)", DIRECTION_NONE); + end_trace(); + new_state(EPOINT_STATE_OUT_DISCONNECT); + message_disconnect_port(portlist, CAUSE_SERVICEUNAVAIL, LOCATION_PRIVATE_LOCAL, ""); + set_tone(portlist, "cause_3f"); + return; + } + SCPY(remote, rparam->string_value); + if (!_action_init_call(remote)) + return; + + /* create bearer/caller/dialinginfo */ + memcpy(&capainfo, &e_capainfo, sizeof(capainfo)); + memcpy(&callerinfo, &e_callerinfo, sizeof(callerinfo)); + memcpy(&redirinfo, &e_redirinfo, sizeof(redirinfo)); + memset(&dialinginfo, 0, sizeof(dialinginfo)); + + if ((rparam = routeparam(e_action, PARAM_CONTEXT))) + { + SCPY(context, rparam->string_value); + } + if ((rparam = routeparam(e_action, PARAM_EXTEN))) + { + SCPY(dialinginfo.id, rparam->string_value); + dialinginfo.ntype = INFO_NTYPE_UNKNOWN; + } else + { + SCPY(dialinginfo.id, e_extdialing); + } + e_extdialing = e_dialinginfo.id + strlen(e_dialinginfo.id); + /* send setup to remote */ + trace_header("ACTION remote (setup)", DIRECTION_NONE); + add_trace("number", NULL, dialinginfo.id); + add_trace("remote", NULL, remote); + if (context[0]) + add_trace("context", NULL, context); + end_trace(); + message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP); + memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info)); + memcpy(&message->param.setup.redirinfo, &redirinfo, sizeof(struct redir_info)); + memcpy(&message->param.setup.callerinfo, &callerinfo, sizeof(struct caller_info)); + memcpy(&message->param.setup.capainfo, &capainfo, sizeof(struct capa_info)); + SCPY(message->param.setup.context, context); + message_put(message); + } else + { + /* send overlap digits */ + trace_header("ACTION remote (dialing)", DIRECTION_NONE); + add_trace("number", NULL, e_extdialing); + end_trace(); + if (e_extdialing[0]) + { + message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_INFORMATION); + memcpy(&message->param.information, &e_dialinginfo, sizeof(struct dialing_info)); + SCPY(message->param.information.id, e_extdialing); + e_extdialing = e_dialinginfo.id + strlen(e_dialinginfo.id); + message_put(message); + } + } } @@ -413,7 +433,7 @@ void EndpointAppPBX::action_dialing_vbox_record(void) { struct dialing_info dialinginfo; struct port_list *portlist = ea_endpoint->ep_portlist; - struct message *message; + struct lcr_msg *message; struct extension ext; struct route_param *rparam; @@ -457,7 +477,7 @@ void EndpointAppPBX::action_dialing_vbox_record(void) set_tone(portlist, "proceeding"); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); new_state(EPOINT_STATE_IN_PROCEEDING); memset(&dialinginfo, 0, sizeof(dialinginfo)); @@ -477,7 +497,7 @@ void EndpointAppPBX::action_dialing_vbox_record(void) trace_header("ACTION vbox-record (calling)", DIRECTION_NONE); add_trace("extension", NULL, "%s", dialinginfo.id); end_trace(); - message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_call_id, EPOINT_TO_CALL, MESSAGE_SETUP); + message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP); memcpy(&message->param.setup.dialinginfo, &dialinginfo, sizeof(struct dialing_info)); memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info)); memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info)); @@ -491,13 +511,13 @@ void EndpointAppPBX::action_dialing_vbox_record(void) */ void EndpointAppPBX::action_init_partyline(void) { - class Call *call; - class CallPBX *callpbx; + class Join *join; + class JoinPBX *joinpbx; struct port_list *portlist = ea_endpoint->ep_portlist; - struct message *message; + struct lcr_msg *message; struct route_param *rparam; - int partyline; - struct call_relation *relation; + int partyline, jingle = 0; + struct join_relation *relation; portlist = ea_endpoint->ep_portlist; @@ -521,52 +541,56 @@ void EndpointAppPBX::action_init_partyline(void) goto noroom; } partyline = rparam->integer_value; + if ((rparam = routeparam(e_action, PARAM_JINGLE))) + jingle = 1; - /* don't create call if partyline exists */ - call = call_first; - while(call) + /* don't create join if partyline exists */ + join = join_first; + while(join) { - if (call->c_type == CALL_TYPE_PBX) + if (join->j_type == JOIN_TYPE_PBX) { - callpbx = (class CallPBX *)call; - if (callpbx->c_partyline == rparam->integer_value) + joinpbx = (class JoinPBX *)join; + if (joinpbx->j_partyline == partyline) break; } - call = call->next; + join = join->next; } - if (!call) + if (!join) { - /* create call */ - PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new call instance.\n", ea_endpoint->ep_serial); - if (!(call = new CallPBX(ea_endpoint))) - FATAL("No memory for Call object\n"); + /* create join */ + PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Creating new join instance.\n", ea_endpoint->ep_serial); + if (!(join = new JoinPBX(ea_endpoint))) + FATAL("No memory for join object\n"); } else { -//NOTE: callpbx must be set here - /* add relation to existing call */ - if (!(relation=callpbx->add_relation())) - FATAL("No memory for Call relation\n"); +//NOTE: joinpbx must be set here + /* add relation to existing join */ + if (!(relation=joinpbx->add_relation())) + FATAL("No memory for join relation\n"); relation->type = RELATION_TYPE_SETUP; - relation->channel_state = CHANNEL_STATE_CONNECT; + relation->channel_state = 1; relation->rx_state = NOTIFY_STATE_ACTIVE; relation->tx_state = NOTIFY_STATE_ACTIVE; relation->epoint_id = ea_endpoint->ep_serial; } - ea_endpoint->ep_call_id = call->c_serial; + ea_endpoint->ep_join_id = join->j_serial; set_tone(portlist, "proceeding"); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); new_state(EPOINT_STATE_IN_PROCEEDING); - /* send setup to call */ + /* send setup to join */ trace_header("ACTION partyline (calling)", DIRECTION_NONE); add_trace("room", NULL, "%d", partyline); + add_trace("jingle", NULL, (jingle)?"on":"off"); end_trace(); - message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_call_id, EPOINT_TO_CALL, MESSAGE_SETUP); + message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_SETUP); message->param.setup.partyline = partyline; + message->param.setup.partyline_jingle = jingle; memcpy(&message->param.setup.dialinginfo, &e_dialinginfo, sizeof(struct dialing_info)); memcpy(&message->param.setup.redirinfo, &e_redirinfo, sizeof(struct redir_info)); memcpy(&message->param.setup.callerinfo, &e_callerinfo, sizeof(struct caller_info)); @@ -580,44 +604,8 @@ void EndpointAppPBX::action_init_partyline(void) */ void EndpointAppPBX::action_hangup_call(void) { - int i; - trace_header("ACTION hangup", DIRECTION_NONE); end_trace(); - /* check */ - if (e_ext.number[0] == '\0') - { - 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); - return; - } - if (!(read_extension(&e_ext, e_ext.number))) - { - 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); - return; - } - if (e_dialinginfo.id[0] == '\0') - { - PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last dialed number because nothing was dialed.\n", ea_endpoint->ep_serial, e_ext.number); - return; - } - if (!strcmp(e_dialinginfo.id, e_ext.last_out[0])) - { - 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); - return; - } - - /* insert */ - PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id); - i = MAX_REMEMBER-1; - while(i) - { - UCPY(e_ext.last_out[i], e_ext.last_out[i-1]); - i--; - } - SCPY(e_ext.last_out[0], e_dialinginfo.id); - - /* write extension */ - write_extension(&e_ext, e_ext.number); } @@ -627,7 +615,7 @@ void EndpointAppPBX::action_hangup_call(void) void EndpointAppPBX::action_dialing_login(void) { struct port_list *portlist = ea_endpoint->ep_portlist; - struct message *message; + struct lcr_msg *message; char *extension; struct route_param *rparam; @@ -678,12 +666,12 @@ void EndpointAppPBX::action_dialing_login(void) message->param.connectinfo.present = INFO_PRESENT_RESTRICTED; else message->param.connectinfo.present = e_ext.callerid_present; /* handle restricted caller ids */ - 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); + apply_callerid_restriction(&e_ext, message->param.connectinfo.id, &message->param.connectinfo.ntype, &message->param.connectinfo.present, &message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name); /* display callerid if desired for extension */ 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)); message->param.connectinfo.ntype = e_ext.callerid_type; message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); /* set our caller id */ SCPY(e_callerinfo.id, e_ext.callerid); @@ -819,7 +807,7 @@ void EndpointAppPBX::_action_callerid_calleridnext(int next) (!next)?e_ext.callerid_type:e_ext.id_next_call_type = INFO_NTYPE_UNKNOWN; } else { - SCPY((!next)?e_ext.callerid:e_ext.id_next_call, nationalize_callerinfo(callerid,&((!next)?e_ext.callerid_type:e_ext.id_next_call_type))); + SCPY((!next)?e_ext.callerid:e_ext.id_next_call, nationalize_callerinfo(callerid,&((!next)?e_ext.callerid_type:e_ext.id_next_call_type), options.national, options.international)); } if (!next) e_ext.id_next_call_type = -1; 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); @@ -835,9 +823,9 @@ void EndpointAppPBX::_action_callerid_calleridnext(int next) trace_header("ACTION change-callerid (only next call)", DIRECTION_NONE); else trace_header("ACTION change-callerid (all future calls)", DIRECTION_NONE); - add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type)); + add_trace("old", "caller id", "%s", numberrize_callerinfo(old_id, old_type, options.national, options.international)); add_trace("old", "present", "%s", (old_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed"); - add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type)); + add_trace("new", "caller id", "%s", numberrize_callerinfo(new_id, new_type, options.national, options.international)); add_trace("new", "present", "%s", (new_present==INFO_PRESENT_RESTRICTED)?"restricted":"allowed"); end_trace(); message_disconnect_port(portlist, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, ""); @@ -971,7 +959,7 @@ void EndpointAppPBX::action_init_redial_reply(void) */ void EndpointAppPBX::_action_redial_reply(int in) { - struct message *message; + struct lcr_msg *message; char *last; struct route_param *rparam; @@ -1000,12 +988,12 @@ void EndpointAppPBX::_action_redial_reply(int in) { /* find next entry */ e_select++; - if (e_select >= MAX_REMEMBER) + if (e_select >= MAX_REMEMBER) { e_select--; - else if (in) + } else if (in) { if (e_ext.last_in[e_select][0] == '\0') e_select--; - else + } else if (e_ext.last_out[e_select][0] == '\0') e_select--; @@ -1047,7 +1035,7 @@ void EndpointAppPBX::_action_redial_reply(int in) SPRINT(message->param.notifyinfo.display, "(%d) %s", e_select+1, (last[0])?last:"- empty -"); PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s sending display:%s\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT); } /* process dialing redial @@ -1070,7 +1058,7 @@ void EndpointAppPBX::action_dialing_reply(void) void EndpointAppPBX::action_dialing_powerdial(void) { struct port_list *portlist = ea_endpoint->ep_portlist; - struct message *message; + struct lcr_msg *message; struct route_param *rparam; /* power dialing only possible if we have a last dialed number */ @@ -1120,7 +1108,7 @@ void EndpointAppPBX::action_dialing_powerdial(void) memset(&e_connectinfo, 0, sizeof(e_connectinfo)); message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT); /* do dialing */ SCPY(e_dialinginfo.id, e_ext.last_out[0]); @@ -1301,7 +1289,7 @@ void EndpointAppPBX::action_dialing_test(void) unsigned int cause; char causestr[16]; struct port_list *portlist = ea_endpoint->ep_portlist; - struct message *message; + struct lcr_msg *message; class Port *port; char testcode[32] = ""; struct route_param *rparam; @@ -1321,7 +1309,7 @@ void EndpointAppPBX::action_dialing_test(void) set_tone(portlist, "proceeding"); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); break; case '2': @@ -1332,7 +1320,7 @@ void EndpointAppPBX::action_dialing_test(void) set_tone(portlist, "ringpbx"); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); break; case '3': @@ -1353,11 +1341,11 @@ void EndpointAppPBX::action_dialing_test(void) message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT); memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(struct connect_info)); /* handle restricted caller ids */ - 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); + apply_callerid_restriction(&e_ext, message->param.connectinfo.id, &message->param.connectinfo.ntype, &message->param.connectinfo.present, &message->param.connectinfo.screen, message->param.connectinfo.extension, message->param.connectinfo.name); /* display callerid if desired for extension */ 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)); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); port = find_port_id(portlist->port_id); if (port) @@ -1376,7 +1364,7 @@ void EndpointAppPBX::action_dialing_test(void) memset(&e_connectinfo, 0, sizeof(e_connectinfo)); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); set_tone(portlist, "test"); break; @@ -1390,7 +1378,7 @@ void EndpointAppPBX::action_dialing_test(void) memset(&e_connectinfo, 0, sizeof(e_connectinfo)); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); set_tone(portlist, "hold"); break; @@ -1412,7 +1400,7 @@ void EndpointAppPBX::action_dialing_test(void) memset(&e_connectinfo, 0, sizeof(e_connectinfo)); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); set_tone(portlist, causestr); break; @@ -1459,7 +1447,7 @@ void EndpointAppPBX::action_dialing_test(void) message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT); memcpy(&message->param.connectinfo, &e_connectinfo, sizeof(message->param.connectinfo)); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); set_tone(portlist, "hold"); break; } @@ -1513,7 +1501,7 @@ void EndpointAppPBX::action_init_play(void) void EndpointAppPBX::action_dialing_calculator(void) { struct port_list *portlist = ea_endpoint->ep_portlist; - struct message *message; + struct lcr_msg *message; double value1, value2, v, sign1; int komma1, komma2, k, state, mode, first; char *p; @@ -1752,7 +1740,7 @@ void EndpointAppPBX::action_dialing_calculator(void) SPRINT(message->param.notifyinfo.display, ">%s", e_extdialing); 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); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); } @@ -1805,7 +1793,7 @@ void EndpointAppPBX::_action_goto_menu(int mode) } else { /* remove digits that are required to match the rule */ - if (!(rparam = routeparam(e_action, PARAM_STRIP))) + if ((rparam = routeparam(e_action, PARAM_STRIP))) { if (e_extdialing) SCPY(e_dialinginfo.id, e_extdialing); @@ -1817,13 +1805,18 @@ void EndpointAppPBX::_action_goto_menu(int mode) trace_header("ACTION goto/menu (change to)", DIRECTION_NONE); add_trace("ruleset", NULL, "%s", e_ruleset->name); if (e_dialinginfo.id[0]) + { add_trace("dialing", NULL, "%s", e_dialinginfo.id); + } if ((rparam = routeparam(e_action, PARAM_SAMPLE))) { add_trace("sample", NULL, "%s", rparam->string_value); + end_trace(); set_tone(ea_endpoint->ep_portlist, rparam->string_value); + } else + { + end_trace(); } - end_trace(); /* do dialing with new ruleset */ e_action = NULL; @@ -1852,7 +1845,7 @@ void EndpointAppPBX::action_dialing_disconnect(void) { struct route_param *rparam; struct port_list *portlist = ea_endpoint->ep_portlist; - struct message *message; + struct lcr_msg *message; int cause = CAUSE_NORMAL; /* normal call clearing */ int location = LOCATION_PRIVATE_LOCAL; char cause_string[256] = "", display[84] = ""; @@ -1906,7 +1899,7 @@ void EndpointAppPBX::action_dialing_disconnect(void) message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY); SCPY(message->param.notifyinfo.display, display); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, ea_endpoint->ep_portlist->port_id, DIRECTION_OUT); } e_action = NULL; } @@ -1922,7 +1915,7 @@ void EndpointAppPBX::action_dialing_help(void) struct numbering *numbering = numbering_int; char dialing[sizeof(e_dialinginfo.id)]; int i; - struct message *message; + struct lcr_msg *message; struct route_param *rparam; /* in case we have no menu (this should never happen) */ @@ -1988,7 +1981,7 @@ nesting?: SPRINT(message->param.notifyinfo.display, ">%s %s%s%s", numbering->prefix, numb_actions[numbering->action], (numbering->param[0])?" ":"", numbering->param); 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); message_put(message); - logmessage(message); + logmessage(message->type, message->paramea_endpoint->ep_portlist->port_id, DIRECTION_OUT); #endif } @@ -2015,8 +2008,10 @@ void EndpointAppPBX::action_dialing_setforward(void) void EndpointAppPBX::action_hangup_execute(void) { struct route_param *rparam; - char *command = "", isdn_port[10]; - char *argv[7+1]; /* check also number of args below */ + pid_t pid; + char *command = (char *)""; + char isdn_port[10]; + char *argv[11]; /* check also number of args below */ int i = 0; /* get script / command */ @@ -2028,26 +2023,35 @@ void EndpointAppPBX::action_hangup_execute(void) end_trace(); return; } - trace_header("ACTION execute", DIRECTION_NONE); - add_trace("command", NULL, "%s", command); - end_trace(); - - argv[0] = command; - while(strchr(argv[0], '/')) - argv[0] = strchr(argv[0], '/')+1; + argv[i++] = (char *)"/bin/sh"; + argv[i++] = (char *)"-c"; + argv[i++] = command; + argv[i++] = command; if ((rparam = routeparam(e_action, PARAM_PARAM))) { - argv[1] = rparam->string_value; - i++; + argv[i++] = rparam->string_value; } - argv[1+i] = e_extdialing; - argv[2+i] = numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype); - argv[3+i] = e_callerinfo.extension; - argv[4+i] = e_callerinfo.name; + argv[i++] = e_extdialing; + argv[i++] = (char *)numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international); + argv[i++] = e_callerinfo.extension; + argv[i++] = e_callerinfo.name; SPRINT(isdn_port, "%d", e_callerinfo.isdn_port); - argv[5+i] = isdn_port; - argv[6+i] = NULL; /* check also number of args above */ - execve("/bin/sh", argv, environ); + argv[i++] = isdn_port; + argv[i++] = NULL; /* check also number of args above */ + switch (pid = fork ()) { + case -1: + trace_header("ACTION execute (fork failed)", DIRECTION_NONE); + end_trace(); + break; + case 0: + execve("/bin/sh", argv, environ); + break; + default: + trace_header("ACTION execute", DIRECTION_NONE); + add_trace("command", NULL, "%s", command); + end_trace(); + break; + } } @@ -2057,7 +2061,7 @@ void EndpointAppPBX::action_hangup_execute(void) void EndpointAppPBX::action_hangup_file(void) { struct route_param *rparam; - char *file, *content, *mode; + const char *file, *content, *mode; FILE *fp; /* get file / content */ @@ -2112,7 +2116,7 @@ void EndpointAppPBX::action_init_pick(void) if (extensions) if (extensions[0]) add_trace("extensions", NULL, "%s", extensions); end_trace(); - pick_call(extensions); + pick_join(extensions); } @@ -2187,7 +2191,7 @@ void EndpointAppPBX::action_dialing_password_wr(void) void EndpointAppPBX::process_dialing(void) { struct port_list *portlist = ea_endpoint->ep_portlist; - struct message *message; + struct lcr_msg *message; struct route_param *rparam; //#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. @@ -2238,7 +2242,7 @@ void EndpointAppPBX::process_dialing(void) release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL); goto end; } - release(RELEASE_CALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, 0); + release(RELEASE_JOIN, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, 0, 0); e_action = e_action->next; if (!e_action) { @@ -2256,7 +2260,7 @@ void EndpointAppPBX::process_dialing(void) if (e_state!=EPOINT_STATE_IN_SETUP && e_state!=EPOINT_STATE_IN_OVERLAP) { - 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); + PDEBUG(DEBUG_EPOINT, "EPOINT(%d): we are not in incoming setup/overlap state, so we ignore init/dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting); e_match_timeout = 0; goto end; } @@ -2287,7 +2291,7 @@ void EndpointAppPBX::process_dialing(void) SCPY(message->param.notifyinfo.display,get_isdn_cause(LOCATION_PRIVATE_LOCAL, epoint->e_ext.display_cause, param->disconnectinfo.location, param->disconnectinfo.cause)); } message_put(message); - logmessage(message); + logmessage(message->type, message->param, portlist->port_id, DIRECTION_OUT); } new_state(EPOINT_STATE_OUT_DISCONNECT); set_tone(portlist,"cause_1c"); @@ -2318,10 +2322,10 @@ void EndpointAppPBX::process_dialing(void) goto process_action; } /* check for chan call */ - if (!strncmp(e_dialinginfo.id, "chan:", 5)) + if (!strncmp(e_dialinginfo.id, "remote:", 7)) { - e_extdialing = e_dialinginfo.id+4; - e_action = &action_chan; + e_extdialing = e_dialinginfo.id+7; + e_action = &action_remote; goto process_action; } /* check for vbox call */ @@ -2397,7 +2401,7 @@ void EndpointAppPBX::process_dialing(void) memset(&e_connectinfo, 0, sizeof(e_connectinfo)); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_CONNECT); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); } else if ((rparam = routeparam(e_action, PARAM_ALERTING))) { @@ -2405,7 +2409,7 @@ void EndpointAppPBX::process_dialing(void) memset(&e_connectinfo, 0, sizeof(e_connectinfo)); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_ALERTING); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); } else if ((rparam = routeparam(e_action, PARAM_PROCEEDING))) { @@ -2413,7 +2417,7 @@ void EndpointAppPBX::process_dialing(void) memset(&e_connectinfo, 0, sizeof(e_connectinfo)); message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_PROCEEDING); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); } if (action_defs[e_action->index].init_func) @@ -2424,7 +2428,7 @@ void EndpointAppPBX::process_dialing(void) if (e_state!=EPOINT_STATE_IN_SETUP && e_state!=EPOINT_STATE_IN_OVERLAP) { - 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); + PDEBUG(DEBUG_EPOINT, "EPOINT(%d): AFTER init process: we are not in incoming setup/overlap state anymore, so we ignore further dialing process.\n", ea_endpoint->ep_serial, e_rule_nesting); goto display_action; } } @@ -2468,7 +2472,7 @@ void EndpointAppPBX::process_dialing(void) PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s displaying interpreted dialing '%s'\n", ea_endpoint->ep_serial, e_ext.number, message->param.notifyinfo.display); message_put(message); - logmessage(message); + logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); } end: @@ -2513,7 +2517,7 @@ void EndpointAppPBX::process_hangup(int cause, int location) } if (e_callerinfo.id[0]) - SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype)); + SPRINT(callertext, "%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international)); else SPRINT(callertext, "unknown"); /* allpy restriction */ @@ -2524,13 +2528,14 @@ void EndpointAppPBX::process_hangup(int cause, int location) write_log(e_ext.number, callertext, dialingtext, e_start, e_stop, 0, cause, location); /* store last received call for reply-list */ + if (e_origin == 1) // outgoing to phone is incoming for user if (e_callerinfo.id[0] || e_callerinfo.extension[0]) if (e_ext.anon_ignore || e_callerinfo.present!=INFO_PRESENT_RESTRICTED) { if (e_callerinfo.extension[0]) SPRINT(callertext, "intern:%s", e_callerinfo.extension); else - SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype)); + SPRINT(callertext, "extern:%s", numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international)); if (!!strcmp(callertext, e_ext.last_in[0])) { i = MAX_REMEMBER-1; @@ -2545,8 +2550,26 @@ void EndpointAppPBX::process_hangup(int cause, int location) } else 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); } - } + /* store last made call for reply-list */ + if (e_origin == 0) // incoming from phone is outgoing for user + if (e_dialinginfo.id[0]) + { + if (!!strcmp(e_dialinginfo.id, e_ext.last_out[0])) + { + i = MAX_REMEMBER-1; + while(i) + { + UCPY(e_ext.last_out[i], e_ext.last_out[i-1]); + i--; + } + SCPY(e_ext.last_out[0], e_dialinginfo.id); + writeext |= 1; /* store extension later */ + PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: storing last number '%s'.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id); + } else + PDEBUG(DEBUG_EPOINT, "EPOINT(%d): terminal %s: cannot store last number '%s' because it is identical with the last one.\n", ea_endpoint->ep_serial, e_ext.number, e_dialinginfo.id); + } + } /* write extension if needed */ if (writeext == 0x11) write_extension(&e_ext, e_ext.number);