X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=vbox.cpp;h=238a1daf9d399645c7dc7373e6998c796d2b184b;hp=2a9696236b2b9f83de380ef28faad858341c050c;hb=a0beafd25e37f01f404ee0020d076d0ecc01ada8;hpb=2ed0fee489c37a6e2d4473f6185ebbe3e746ac11 diff --git a/vbox.cpp b/vbox.cpp index 2a96962..238a1da 100644 --- a/vbox.cpp +++ b/vbox.cpp @@ -1,6 +1,6 @@ /*****************************************************************************\ ** ** -** PBX4Linux ** +** Linux Call Router ** ** ** **---------------------------------------------------------------------------** ** Copyright: Andreas Eversberg ** @@ -55,6 +55,20 @@ VBoxPort::~VBoxPort() } +static void vbox_trace_header(class VBoxPort *vbox, char *message, int direction) +{ + /* init trace with given values */ + start_trace(0, + NULL, + vbox?numberrize_callerinfo(vbox->p_callerinfo.id, vbox->p_callerinfo.ntype):NULL, + vbox?vbox->p_dialinginfo.id:NULL, + direction, + CATEGORY_CH, + vbox?vbox->p_serial:0, + message); +} + + /* * handler of vbox */ @@ -62,9 +76,13 @@ int VBoxPort::handler(void) { struct message *message; unsigned long tosend; - signed short buffer[128<<1]; + unsigned char buffer[ISDN_TRANSMIT]; time_t currenttime; class Endpoint *epoint; + int ret; + + if ((ret = Port::handler())) + return(ret); if (p_vbox_record_start && p_vbox_record_limit) { @@ -78,6 +96,10 @@ int VBoxPort::handler(void) message->param.disconnectinfo.cause = 16; message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; message_put(message); + vbox_trace_header(this, "RELEASE from VBox (recoding limit reached)", DIRECTION_IN); + add_trace("cause", "value", "%d", message->param.disconnectinfo.cause); + add_trace("cause", "location", "%d", message->param.disconnectinfo.location); + end_trace(); /* remove epoint */ free_epointlist(p_epointlist); } @@ -87,126 +109,89 @@ int VBoxPort::handler(void) } } + /* set time the first time */ if (p_vbox_audio_start < 1) { - /* set time the first time */ p_vbox_audio_start = now_d; - } else - { - /* calculate the number of bytes */ - tosend = (unsigned long)((now_d-p_vbox_audio_start)*8000) - p_vbox_audio_transferred; - - /* wait for more */ - if (tosend < 32) - return(0); - - /* too many samples, so we just process 128 bytes until the next call of handler() */ - if (tosend > 128) - tosend = 128; + return(0); + } + + /* calculate the number of bytes */ + tosend = (unsigned long)((now_d-p_vbox_audio_start)*8000) - p_vbox_audio_transferred; - /* dummy read, to clock record buffer */ - read_audio((unsigned char *)buffer, tosend, 0); + /* wait for more */ + if (tosend < sizeof(buffer)) + return(0); + tosend = sizeof(buffer); - /* add the number of samples elapsed */ - p_vbox_audio_transferred += tosend; + /* add the number of samples elapsed */ + p_vbox_audio_transferred += tosend; - /* if announcement is currently played, send audio data */ - if (p_vbox_announce_fh >=0) + /* if announcement is currently played, send audio data */ + if (p_vbox_announce_fh >=0) + { + tosend = read_tone(p_vbox_announce_fh, buffer, p_vbox_announce_codec, tosend, p_vbox_announce_size, &p_vbox_announce_left, 1); + if (tosend <= 0) { - /* read from announcement file */ - switch(p_vbox_announce_codec) - { - case CODEC_LAW: - tosend = read_tone(p_vbox_announce_fh, buffer, p_vbox_announce_codec, tosend, p_vbox_announce_size, &p_vbox_announce_left, 1); - break; - - case CODEC_MONO: - case CODEC_STEREO: - case CODEC_8BIT: - tosend = read_tone(p_vbox_announce_fh, buffer, p_vbox_announce_codec, tosend, p_vbox_announce_size, &p_vbox_announce_left, 1); - break; - - default: - PERROR("correct codec not given.\n"); - exit(-1); - } - if (tosend <= 0) - { - /* end of file */ - close(p_vbox_announce_fh); - p_vbox_announce_fh = -1; - fhuse--; - - time(¤ttime); - p_vbox_record_start = currenttime; + /* end of file */ + close(p_vbox_announce_fh); + p_vbox_announce_fh = -1; + fhuse--; - /* connect if not already */ - epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist)); - if (epoint) - { - /* if we sent our announcement during ringing, we must now connect */ - if (p_vbox_apppbx->e_ext.vbox_free) - { - /* send connect message */ - message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT); - memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info)); - message_put(message); - new_state(PORT_STATE_CONNECT); - } - } + time(¤ttime); + p_vbox_record_start = currenttime; - /* start recording, if not already */ - if (p_vbox_mode == VBOX_MODE_NORMAL) - { - /* send recording start message */ - message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_VBOX_RECORD); - message_put(message); - } else // else!! - if (p_vbox_mode == VBOX_MODE_ANNOUNCEMENT) - { - /* send release */ - message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE); - message->param.disconnectinfo.cause = 16; - message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; - message_put(message); - /* recording is close during destruction */ - delete this; - return(-1); /* must return because port is gone */ - } - } else + /* connect if not already */ + epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist)); + if (epoint) { - switch(p_vbox_announce_codec) + /* if we sent our announcement during ringing, we must now connect */ + if (p_vbox_ext.vbox_free) { - case CODEC_LAW: - message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DATA); - message->param.data.compressed = 1; - message->param.data.port_type = p_type; - message->param.data.port_id = p_serial; - message->param.data.len = tosend; - memcpy(message->param.data.data, buffer, tosend); + /* send connect message */ + message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT); + memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info)); message_put(message); - break; - - case CODEC_MONO: - case CODEC_STEREO: - case CODEC_8BIT: - message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DATA); - message->param.data.compressed = 0; - message->param.data.port_type = p_type; - message->param.data.port_id = p_serial; - message->param.data.len = tosend<<1; - memcpy(message->param.data.data, buffer, tosend<<1); - message_put(message); - break; - - default: - PERROR("correct announce_codec not given.\n"); - exit(-1); + vbox_trace_header(this, "CONNECT from VBox (announcement is over)", DIRECTION_IN); + end_trace(); + new_state(PORT_STATE_CONNECT); } } - } + /* start recording, if not already */ + if (p_vbox_mode == VBOX_MODE_NORMAL) + { + /* recording start */ + open_record(p_vbox_ext.vbox_codec, 2, 0, p_vbox_ext.number, p_vbox_ext.anon_ignore, p_vbox_ext.vbox_email, p_vbox_ext.vbox_email_file); + vbox_trace_header(this, "RECORDING (announcement is over)", DIRECTION_IN); + end_trace(); + } else // else!! + if (p_vbox_mode == VBOX_MODE_ANNOUNCEMENT) + { + /* send release */ + message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE); + message->param.disconnectinfo.cause = 16; + message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; + message_put(message); + vbox_trace_header(this, "RELEASE from VBox (after annoucement)", DIRECTION_IN); + add_trace("cause", "value", "%d", message->param.disconnectinfo.cause); + add_trace("cause", "location", "%d", message->param.disconnectinfo.location); + end_trace(); + /* recording is close during destruction */ + delete this; + return(-1); /* must return because port is gone */ + } + } else + { + if (p_record) + record(buffer, tosend, 0); // from down + message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DATA); + message->param.data.len = tosend; + memcpy(message->param.data.data, buffer, tosend); + message_put(message); + } } + return(1); } @@ -219,7 +204,9 @@ int VBoxPort::message_epoint(unsigned long epoint_id, int message_id, union para struct message *message; class Endpoint *epoint; char filename[256], *c; - class EndpointAppPBX *eapp; + + if (Port::message_epoint(epoint_id, message_id, param)) + return(1); epoint = find_epoint_id(epoint_id); if (!epoint) @@ -228,15 +215,18 @@ int VBoxPort::message_epoint(unsigned long epoint_id, int message_id, union para return(0); } - if (Port::message_epoint(epoint_id, message_id, param)) - return(1); - switch(message_id) { - case MESSAGE_DISCONNECT: /* call has been disconnected */ - PDEBUG(DEBUG_VBOX, "PORT(%s) vbox port with (caller id %s) received disconnect cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause); + case MESSAGE_DATA: + record(param->data.data, param->data.len, 1); // from up + return(1); + case MESSAGE_DISCONNECT: /* call has been disconnected */ new_state(PORT_STATE_OUT_DISCONNECT); + vbox_trace_header(this, "DISCONNECT to VBox", DIRECTION_OUT); + add_trace("cause", "value", "%d", param->disconnectinfo.cause); + add_trace("cause", "location", "%d", param->disconnectinfo.location); + end_trace(); while(p_epointlist) { @@ -244,6 +234,10 @@ int VBoxPort::message_epoint(unsigned long epoint_id, int message_id, union para message->param.disconnectinfo.cause = CAUSE_NORMAL; message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; message_put(message); + vbox_trace_header(this, "RELEASE from VBox (after disconnect)", DIRECTION_IN); + add_trace("cause", "value", "%d", message->param.disconnectinfo.cause); + add_trace("cause", "location", "%d", message->param.disconnectinfo.location); + end_trace(); /* remove epoint */ free_epointlist(p_epointlist); } @@ -253,7 +247,10 @@ int VBoxPort::message_epoint(unsigned long epoint_id, int message_id, union para break; case MESSAGE_RELEASE: /* release vbox port */ - PDEBUG(DEBUG_VBOX, "PORT(%s) vbox port with (caller id %s) received release\n", p_name, p_callerinfo.id); + vbox_trace_header(this, "RELEASE to VBox", DIRECTION_OUT); + add_trace("cause", "value", "%d", param->disconnectinfo.cause); + add_trace("cause", "location", "%d", param->disconnectinfo.location); + end_trace(); /* we are done */ /* recording is close during destruction */ @@ -263,37 +260,33 @@ int VBoxPort::message_epoint(unsigned long epoint_id, int message_id, union para case MESSAGE_SETUP: /* dial-out command received from epoint, answer with connect */ /* get apppbx */ - eapp = (class EndpointAppPBX *)(epoint->ep_app); - p_vbox_apppbx = eapp; + memcpy(&p_vbox_ext, &((class EndpointAppPBX *)(epoint->ep_app))->e_ext, sizeof(p_vbox_ext)); /* extract optional announcement file */ - if ((c = strchr(param->setup.dialinginfo.number, ','))) + if ((c = strchr(param->setup.dialinginfo.id, ','))) { if (c[1] == '/') SPRINT(filename, c+1); else - SPRINT(filename, "%s/%s/%s/vbox/%s", INSTALL_DATA, options.extensions_dir, p_vbox_apppbx->e_terminal); + SPRINT(filename, "%s/%s/%s/vbox/%s", INSTALL_DATA, options.extensions_dir, p_vbox_ext.number); *c = '\0'; } else { - SPRINT(filename, "%s/%s/%s/vbox/announcement", INSTALL_DATA, options.extensions_dir, p_vbox_apppbx->e_terminal); + SPRINT(filename, "%s/%s/%s/vbox/announcement", INSTALL_DATA, options.extensions_dir, p_vbox_ext.number); } - PDEBUG(DEBUG_VBOX, "PORT(%s) vbox port received setup from '%s' to '%s'\n", p_name, param->setup.callerinfo.id, param->setup.dialinginfo.number); + vbox_trace_header(this, "SETUP to VBox", DIRECTION_OUT); + add_trace("from", "id", "%s", param->setup.callerinfo.id); + add_trace("to", "box", "%s", param->setup.dialinginfo.id); + end_trace(); + memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo)); memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo)); memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo)); /* link relation */ if (p_epointlist) - { - PERROR("PORT(%s) software error: epoint pointer is set in idle state, how bad!! exitting.\n", p_name); - exit(-1); - } - if (!(epointlist_new(epoint_id))) - { - PERROR("no memory for epointlist\n"); - exit(-1); - } + FATAL("PORT(%s) Epoint pointer is set in idle state, how bad!!\n", p_name); + epointlist_new(epoint_id); /* copy setup infos to port */ - SCPY(p_vbox_extension, param->setup.dialinginfo.number); + SCPY(p_vbox_extension, param->setup.dialinginfo.id); /* create connect info */ SCPY(p_connectinfo.id, p_vbox_extension); @@ -302,41 +295,43 @@ int VBoxPort::message_epoint(unsigned long epoint_id, int message_id, union para p_connectinfo.screen = INFO_SCREEN_NETWORK; /* connect unless we can send announcement while ringing */ - if (!p_vbox_apppbx->e_ext.vbox_free) + if (!p_vbox_ext.vbox_free) { /* send connect message */ message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_CONNECT); memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info)); message_put(message); + vbox_trace_header(this, "CONNECT from VBox (after setup)", DIRECTION_IN); + end_trace(); new_state(PORT_STATE_CONNECT); } else { /* send alerting message */ message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_ALERTING); message_put(message); + vbox_trace_header(this, "ALERTING from VBox (play announcement before connect)", DIRECTION_IN); + end_trace(); new_state(PORT_STATE_IN_ALERTING); } - /* start recording during announcement */ - /* start parallel recording if desired */ - p_vbox_mode = p_vbox_apppbx->e_ext.vbox_mode; - p_vbox_record_limit = p_vbox_apppbx->e_ext.vbox_time; - if (p_vbox_mode == VBOX_MODE_PARALLEL) - { - /* send recording start message */ - message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_VBOX_RECORD); - message_put(message); - } /* play the announcement */ if ((p_vbox_announce_fh = open_tone(filename, &p_vbox_announce_codec, &p_vbox_announce_size, &p_vbox_announce_left)) >= 0) { fhuse++; - } else + } + vbox_trace_header(this, "ANNOUNCEMENT", DIRECTION_OUT); + add_trace("file", "name", "%s", filename); + add_trace("file", "exists", "%s", (p_vbox_announce_fh>=0)?"yes":"no"); + end_trace(); + /* start recording if desired */ + p_vbox_mode = p_vbox_ext.vbox_mode; + p_vbox_record_limit = p_vbox_ext.vbox_time; + if (p_vbox_announce_fh<0 || p_vbox_mode==VBOX_MODE_PARALLEL) { - PDEBUG(DEBUG_VBOX, "PORT(%s) no announcement found at: '%s' so we start recording now.\n", p_name, filename); - /* send recording start message */ - message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_VBOX_RECORD); - message_put(message); + /* recording start */ + open_record(p_vbox_ext.vbox_codec, 2, 0, p_vbox_ext.number, p_vbox_ext.anon_ignore, p_vbox_ext.vbox_email, p_vbox_ext.vbox_email_file); + vbox_trace_header(this, "RECORDING", DIRECTION_IN); + end_trace(); } break;