add patch OPENZAP-15 with minor mods

git-svn-id: http://svn.openzap.org/svn/openzap/trunk@586 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Michael Jerris 2008-10-06 19:21:27 +00:00
parent 1ded021796
commit 8cdc323ca5
5 changed files with 82 additions and 20 deletions

View File

@ -1586,6 +1586,7 @@ static switch_status_t load_config(void)
char *tonegroup = NULL;
char *digit_timeout = NULL;
char *max_digits = NULL;
char *hotline = NULL;
char *dial_regex = NULL;
char *hold_music = NULL;
char *fail_dial_regex = NULL;
@ -1617,6 +1618,8 @@ static switch_status_t load_config(void)
hold_music = val;
} else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) {
max_digits = val;
} else if (!strcasecmp(var, "hotline")) {
hotline = val;
} else if (!strcasecmp(var, "enable-analog-option")) {
analog_options = enable_analog_option(val, analog_options);
}
@ -1667,6 +1670,7 @@ static switch_status_t load_config(void)
"tonemap", tonegroup,
"digit_timeout", &to,
"max_dialstr", &max,
"hotline", hotline,
"enable_callerid", enable_callerid,
TAG_END) != ZAP_SUCCESS) {
zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id);

View File

@ -298,7 +298,8 @@ typedef enum {
ZAP_CHANNEL_FEATURE_DTMF_GENERATE = (1 << 1),
ZAP_CHANNEL_FEATURE_CODECS = (1 << 2),
ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 3),
ZAP_CHANNEL_FEATURE_CALLERID = (1 << 4)
ZAP_CHANNEL_FEATURE_CALLERID = (1 << 4),
ZAP_CHANNEL_FEATURE_PROGRESS = (1 << 5)
} zap_channel_feature_t;
typedef enum {

View File

@ -83,6 +83,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span)
{
zap_analog_data_t *analog_data;
const char *tonemap = "us";
const char *hotline = "";
uint32_t digit_timeout = 10;
uint32_t max_dialstr = 11;
const char *var, *val;
@ -126,7 +127,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span)
break;
}
max_dialstr = *intval;
}
} else if (!strcasecmp(var, "hotline")) {
if (!(val = va_arg(ap, char *))) {
break;
}
hotline = val;
}
}
@ -134,7 +140,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span)
digit_timeout = 2000;
}
if (max_dialstr < 2 || max_dialstr > 20) {
if ((max_dialstr < 2 && !strlen(hotline)) || max_dialstr > 20) {
max_dialstr = 11;
}
@ -143,6 +149,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span)
analog_data->digit_timeout = digit_timeout;
analog_data->max_dialstr = max_dialstr;
analog_data->sig_cb = sig_cb;
strncpy(analog_data->hotline, hotline, sizeof(analog_data->hotline));
span->signal_type = ZAP_SIGTYPE_ANALOG;
span->signal_data = analog_data;
span->outgoing_call = span->trunk_type == ZAP_TRUNK_FXS ? analog_fxs_outgoing_call : analog_fxo_outgoing_call;
@ -562,10 +569,16 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
collecting = 0;
}
}
else if(!analog_data->max_dialstr)
{
last_digit = elapsed;
collecting = 0;
strcpy(dtmf, analog_data->hotline);
}
}
if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) > analog_data->max_dialstr))) {
if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) >= analog_data->max_dialstr))) {
zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf);
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE);
last_digit = 0;
@ -794,7 +807,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even
}
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP);
} else {
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE);
if(!analog_data->max_dialstr) {
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_COLLECT);
} else {
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE);
}
zap_mutex_unlock(event->channel->mutex);
locked = 0;
zap_thread_create_detached(zap_analog_channel_run, event->channel);
@ -808,6 +825,35 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
}
}
case ZAP_OOB_DTMF:
{
const char * digit_str = (const char *)event->data;
if(digit_str) {
if (event->channel->state == ZAP_CHANNEL_STATE_CALLWAITING && (*digit_str == 'D' || *digit_str == 'A')) {
event->channel->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++;
} else {
zio_event_cb_t event_callback = NULL;
zap_channel_queue_dtmf(event->channel, digit_str);
if (span->event_callback) {
event_callback = span->event_callback;
} else if (event->channel->event_callback) {
event_callback = event->channel->event_callback;
}
if (event_callback) {
event->channel->event_header.channel = event->channel;
event->channel->event_header.e_type = ZAP_EVENT_DTMF;
event->channel->event_header.data = (void *)digit_str;
event_callback(event->channel, &event->channel->event_header);
event->channel->event_header.e_type = ZAP_EVENT_NONE;
event->channel->event_header.data = NULL;
}
}
zap_safe_free(event->data);
}
}
}
end:
@ -826,7 +872,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj)
zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n");
while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) {
int waitms = 10;
int waitms = 1000;
zap_status_t status;
status = zap_span_poll_event(span, waitms);

View File

@ -40,11 +40,13 @@ typedef enum {
ZAP_ANALOG_CALLERID = (1 << 1)
} zap_analog_flag_t;
#define ZAP_MAX_HOTLINE_STR 20
struct zap_analog_data {
uint32_t flags;
uint32_t max_dialstr;
uint32_t digit_timeout;
char hotline[ZAP_MAX_HOTLINE_STR];
zio_signal_cb_t sig_cb;
};

View File

@ -553,7 +553,10 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_
if (!zchan->fsk_buffer) {
zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0);
} else {
zap_buffer_zero(zchan->fsk_buffer);
}
if (zchan->token_count > 1) {
zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 80, 5, 0, zchan_fsk_write_sample, zchan);
zap_fsk_modulator_send_all((&fsk_trans));
@ -562,6 +565,7 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_
zap_fsk_modulator_send_all((&fsk_trans));
zchan->buffer_delay = 3500 / zchan->effective_interval;
}
return ZAP_SUCCESS;
}
@ -756,6 +760,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta
switch(state) {
case ZAP_CHANNEL_STATE_DIALTONE:
case ZAP_CHANNEL_STATE_COLLECT:
case ZAP_CHANNEL_STATE_DIALING:
case ZAP_CHANNEL_STATE_RING:
case ZAP_CHANNEL_STATE_PROGRESS_MEDIA:
@ -1321,22 +1326,26 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo
break;
case ZAP_COMMAND_ENABLE_PROGRESS_DETECT:
{
/* if they don't have thier own, use ours */
zap_channel_clear_detected_tones(zchan);
zap_channel_clear_needed_tones(zchan);
teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]);
teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]);
teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]);
zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT);
GOTO_STATUS(done, ZAP_SUCCESS);
if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) {
/* if they don't have thier own, use ours */
zap_channel_clear_detected_tones(zchan);
zap_channel_clear_needed_tones(zchan);
teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]);
teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]);
teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]);
zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT);
GOTO_STATUS(done, ZAP_SUCCESS);
}
}
break;
case ZAP_COMMAND_DISABLE_PROGRESS_DETECT:
{
zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT);
zap_channel_clear_detected_tones(zchan);
zap_channel_clear_needed_tones(zchan);
GOTO_STATUS(done, ZAP_SUCCESS);
if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) {
zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT);
zap_channel_clear_detected_tones(zchan);
zap_channel_clear_needed_tones(zchan);
GOTO_STATUS(done, ZAP_SUCCESS);
}
}
break;
case ZAP_COMMAND_ENABLE_DTMF_DETECT:
@ -1901,7 +1910,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data
}
}
if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) {
if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT) && !zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) {
uint32_t i;
for (i = 1; i < ZAP_TONEMAP_INVALID; i++) {
@ -1916,7 +1925,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data
}
}
if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) {
if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) && !zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) {
teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen);
teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str));