add dtmf based hangup (OPENZAP-3)

git-svn-id: http://svn.openzap.org/svn/openzap/trunk@571 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Michael Jerris 2008-09-26 20:04:22 +00:00
parent c7cbbc6f4e
commit 21d796b63e
2 changed files with 25 additions and 0 deletions

View File

@ -426,6 +426,7 @@ struct zap_channel {
zap_buffer_t *fsk_buffer;
uint32_t dtmf_on;
uint32_t dtmf_off;
char *dtmf_hangup_buf;
teletone_generation_session_t tone_session;
zap_time_t last_event_time;
zap_time_t ring_time;
@ -489,6 +490,8 @@ struct zap_span {
zap_span_start_t start;
void *mod_data;
char *type;
char *dtmf_hangup;
size_t dtmf_hangup_len;
int suggest_chan_id;
zap_state_map_t *state_map;
};

View File

@ -222,6 +222,7 @@ static zap_status_t zap_span_destroy(zap_span_t *span)
zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type);
status = span->zio->span_destroy(span);
zap_safe_free(span->type);
zap_safe_free(span->dtmf_hangup);
}
return status;
@ -241,6 +242,8 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan)
zap_buffer_destroy(&zchan->dtmf_buffer);
zap_buffer_destroy(&zchan->fsk_buffer);
zap_safe_free(zchan->dtmf_hangup_buf);
if (zchan->tone_session.buffer) {
teletone_destroy_session(&zchan->tone_session);
memset(&zchan->tone_session, 0, sizeof(zchan->tone_session));
@ -453,6 +456,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha
zap_mutex_create(&new_chan->mutex);
zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0);
new_chan->dtmf_hangup_buf = calloc (span->dtmf_hangup_len + 1, sizeof (char));
zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY);
*chan = new_chan;
return ZAP_SUCCESS;
@ -965,6 +970,8 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan)
zchan->dtmf_off = ZAP_DEFAULT_DTMF_OFF;
}
memset(zchan->dtmf_hangup_buf, '\0', zchan->span->dtmf_hangup_len);
if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE)) {
zchan->effective_codec = zchan->native_codec;
zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8);
@ -1656,6 +1663,18 @@ zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf)
zap_buffer_toss(zchan->digit_buffer, strlen(dtmf));
}
if (zchan->span->dtmf_hangup_len) {
for (p = dtmf; zap_is_dtmf(*p); p++) {
memmove (zchan->dtmf_hangup_buf, zchan->dtmf_hangup_buf + 1, zchan->span->dtmf_hangup_len - 1);
zchan->dtmf_hangup_buf[zchan->span->dtmf_hangup_len - 1] = *p;
if (!strcmp(zchan->dtmf_hangup_buf, zchan->span->dtmf_hangup)) {
zap_log(ZAP_LOG_DEBUG, "DTMF hangup detected.\n");
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP);
break;
}
}
}
p = dtmf;
while (wr < len && p) {
if (zap_is_dtmf(*p)) {
@ -2127,6 +2146,9 @@ static zap_status_t load_config(void)
configured += zio->configure_span(span, val, qtype, name, number);
d++;
}
} else if (!strcasecmp(var, "dtmf_hangup")) {
span->dtmf_hangup = strdup(val);
span->dtmf_hangup_len = strlen(val);
}
} else {
zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val);