mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 13:12:03 +00:00
dtmf overhaul testers wanted
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6952 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -1648,7 +1648,7 @@ static void conference_loop_output(conference_member_t * member)
|
||||
|
||||
/* if we have caller digits, feed them to the parser to find an action */
|
||||
if (switch_channel_has_dtmf(channel)) {
|
||||
switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
|
||||
switch_channel_dequeue_dtmf_string(channel, dtmf, sizeof(dtmf));
|
||||
|
||||
if (member->conference->dtmf_parser != NULL) {
|
||||
|
||||
@@ -2637,6 +2637,8 @@ static switch_status_t conf_api_sub_dtmf(conference_member_t * member, switch_st
|
||||
{
|
||||
switch_event_t *event;
|
||||
char *dtmf = (char *) data;
|
||||
char *p = dtmf;
|
||||
switch_dtmf_t _dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION };
|
||||
|
||||
if (member == NULL) {
|
||||
stream->write_function(stream, "Invalid member!\n");
|
||||
@@ -2651,9 +2653,15 @@ static switch_status_t conf_api_sub_dtmf(conference_member_t * member, switch_st
|
||||
|
||||
switch_mutex_lock(member->flag_mutex);
|
||||
switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
|
||||
switch_core_session_send_dtmf(member->session, dtmf);
|
||||
switch_mutex_unlock(member->flag_mutex);
|
||||
|
||||
while(p && *p) {
|
||||
_dtmf.digit = *p;
|
||||
switch_core_session_send_dtmf(member->session, &_dtmf);
|
||||
p++;
|
||||
}
|
||||
|
||||
switch_mutex_unlock(member->flag_mutex);
|
||||
|
||||
|
||||
if (stream != NULL) {
|
||||
stream->write_function(stream, "OK sent %s to %u\n", (char *) data, member->id);
|
||||
|
||||
@@ -193,10 +193,17 @@ SWITCH_STANDARD_APP(break_function)
|
||||
SWITCH_STANDARD_APP(queue_dtmf_function)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
char *p;
|
||||
switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
|
||||
|
||||
if (!switch_strlen_zero(data)) {
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
switch_channel_queue_dtmf(channel, data);
|
||||
for (p = (char *)data; p && *p; p++) {
|
||||
dtmf.digit = *p;
|
||||
switch_channel_queue_dtmf(channel, &dtmf);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1048,7 +1055,7 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF:
|
||||
{
|
||||
char *dtmf = (char *) input;
|
||||
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
|
||||
const char *terminators;
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
const char *p;
|
||||
@@ -1061,14 +1068,11 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit
|
||||
if (!strcasecmp(terminators, "none")) {
|
||||
terminators = NULL;
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digit %c\n", dtmf->digit);
|
||||
|
||||
for (p = terminators; p && *p; p++) {
|
||||
char *d;
|
||||
for (d = dtmf; d && *d; d++) {
|
||||
if (*p == *d) {
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
if (*p == dtmf->digit) {
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,9 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF:
|
||||
{
|
||||
char *dtmf = (char *) input;
|
||||
if (*dtmf == '*') {
|
||||
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
|
||||
|
||||
if (dtmf->digit == '*') {
|
||||
channel = switch_core_session_get_channel(session);
|
||||
if (switch_channel_test_flag(channel, CF_ORIGINATOR)) {
|
||||
channel = switch_core_session_get_channel(bleg);
|
||||
|
||||
@@ -91,11 +91,11 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit
|
||||
{
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF:{
|
||||
char *dtmf = (char *) input;
|
||||
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
|
||||
struct dtmf_buffer *dtb;
|
||||
dtb = (struct dtmf_buffer *) buf;
|
||||
|
||||
switch (*dtmf) {
|
||||
switch (dtmf->digit) {
|
||||
case '#':
|
||||
switch_set_flag(dtb, SFLAG_MAIN);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
|
||||
@@ -615,9 +615,11 @@ static switch_status_t cancel_on_dtmf(switch_core_session_t *session, void *inpu
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF:
|
||||
{
|
||||
char *dtmf = (char *) input;
|
||||
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
|
||||
if (buf && buflen) {
|
||||
switch_copy_string(buf, dtmf, buflen);
|
||||
char *bp = (char *) buf;
|
||||
bp[0] = dtmf->digit;
|
||||
bp[1] = '\0';
|
||||
}
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
@@ -643,13 +645,13 @@ static switch_status_t control_playback(switch_core_session_t *session, void *in
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF:
|
||||
{
|
||||
char *dtmf = (char *) input;
|
||||
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
|
||||
cc_t *cc = (cc_t *) buf;
|
||||
switch_file_handle_t *fh = cc->fh;
|
||||
uint32_t pos = 0;
|
||||
|
||||
if (!cc->noexit && (*dtmf == *cc->profile->delete_file_key || *dtmf == *cc->profile->save_file_key || *dtmf == *cc->profile->terminator_key)) {
|
||||
*cc->buf = *dtmf;
|
||||
if (!cc->noexit && (dtmf->digit == *cc->profile->delete_file_key || dtmf->digit == *cc->profile->save_file_key || dtmf->digit == *cc->profile->terminator_key)) {
|
||||
*cc->buf = dtmf->digit;
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
|
||||
@@ -657,7 +659,7 @@ static switch_status_t control_playback(switch_core_session_t *session, void *in
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (*dtmf == *cc->profile->pause_key) {
|
||||
if (dtmf->digit == *cc->profile->pause_key) {
|
||||
if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
|
||||
switch_clear_flag(fh, SWITCH_FILE_PAUSE);
|
||||
} else {
|
||||
@@ -666,20 +668,20 @@ static switch_status_t control_playback(switch_core_session_t *session, void *in
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (*dtmf == *cc->profile->restart_key) {
|
||||
if (dtmf->digit == *cc->profile->restart_key) {
|
||||
unsigned int seekpos = 0;
|
||||
fh->speed = 0;
|
||||
switch_core_file_seek(fh, &seekpos, 0, SEEK_SET);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (*dtmf == *cc->profile->ff_key) {
|
||||
if (dtmf->digit == *cc->profile->ff_key) {
|
||||
int samps = 24000;
|
||||
switch_core_file_seek(fh, &pos, samps, SEEK_CUR);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (*dtmf == *cc->profile->rew_key) {
|
||||
if (dtmf->digit == *cc->profile->rew_key) {
|
||||
int samps = 24000;
|
||||
switch_core_file_seek(fh, &pos, fh->pos - samps, SEEK_SET);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
@@ -522,14 +522,14 @@ static switch_status_t channel_waitfor_write(switch_core_session_t *session, int
|
||||
|
||||
}
|
||||
|
||||
static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *dtmf)
|
||||
static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
|
||||
{
|
||||
private_t *tech_pvt = NULL;
|
||||
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
assert(tech_pvt != NULL);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF ON CALL %s [%s]\n", tech_pvt->call_id, dtmf);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF ON CALL %s [%c]\n", tech_pvt->call_id, dtmf->digit);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -1205,15 +1205,21 @@ static switch_status_t engage_device(unsigned int sample_rate, int codec_ms)
|
||||
|
||||
static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream)
|
||||
{
|
||||
char *dtmf = argv[0];
|
||||
|
||||
if (switch_strlen_zero(dtmf)) {
|
||||
char *dtmf_str = argv[0];
|
||||
switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
|
||||
|
||||
if (switch_strlen_zero(dtmf_str)) {
|
||||
stream->write_function(stream, "No DTMF Supplied!\n");
|
||||
} else {
|
||||
switch_mutex_lock(globals.pvt_lock);
|
||||
if (globals.call_list) {
|
||||
switch_channel_t *channel = switch_core_session_get_channel(globals.call_list->session);
|
||||
switch_channel_queue_dtmf(channel, dtmf);
|
||||
char *p = dtmf_str;
|
||||
while(p && *p) {
|
||||
dtmf.digit = *p;
|
||||
switch_channel_queue_dtmf(channel, &dtmf);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
switch_mutex_unlock(globals.pvt_lock);
|
||||
}
|
||||
|
||||
@@ -1344,7 +1344,7 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *d
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF [%s]\n", dtmf);
|
||||
|
||||
return switch_rtp_queue_rfc2833(tech_pvt->rtp_session, dtmf, 100 * (tech_pvt->read_codec.implementation->samples_per_second / 1000));
|
||||
return switch_rtp_queue_rfc2833(tech_pvt->rtp_session, dtmf);
|
||||
|
||||
}
|
||||
|
||||
@@ -1416,9 +1416,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
|
||||
}
|
||||
#endif
|
||||
if (switch_rtp_has_dtmf(tech_pvt->rtp_session)) {
|
||||
char dtmf[128];
|
||||
switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, dtmf, sizeof(dtmf));
|
||||
switch_channel_queue_dtmf(channel, dtmf);
|
||||
switch_dtmf_t dtmf = { 0 };
|
||||
switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, &dtmf);
|
||||
switch_channel_queue_dtmf(channel, &dtmf);
|
||||
}
|
||||
|
||||
|
||||
@@ -2722,7 +2722,13 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
|
||||
case LDL_SIGNAL_MSG:
|
||||
if (msg) {
|
||||
if (*msg == '+') {
|
||||
switch_channel_queue_dtmf(channel, msg + 1);
|
||||
char *p = msg + 1;
|
||||
switch_dtmf_t dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION };
|
||||
while (p && *p) {
|
||||
dtmf.digit = *p;
|
||||
switch_channel_queue_dtmf(channel, &dtmf);
|
||||
p++;
|
||||
}
|
||||
switch_set_flag_locked(tech_pvt, TFLAG_DTMF);
|
||||
if (switch_rtp_ready(tech_pvt->rtp_session)) {
|
||||
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_BREAK);
|
||||
|
||||
@@ -620,17 +620,14 @@ static switch_status_t channel_waitfor_write(switch_core_session_t *session, int
|
||||
|
||||
}
|
||||
|
||||
static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *dtmf)
|
||||
static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
|
||||
{
|
||||
private_t *tech_pvt = NULL;
|
||||
char *digit;
|
||||
|
||||
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
switch_assert(tech_pvt != NULL);
|
||||
if (tech_pvt->iax_session) {
|
||||
for (digit = dtmf; *digit; digit++) {
|
||||
iax_send_dtmf(tech_pvt->iax_session, *digit);
|
||||
}
|
||||
iax_send_dtmf(tech_pvt->iax_session, dtmf->digit);
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
@@ -1206,11 +1203,12 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
|
||||
break;
|
||||
case IAX_EVENT_DTMF:
|
||||
if (channel) {
|
||||
char str[2] = { (char) iaxevent->subclass };
|
||||
switch_dtmf_t dtmf = { (char) iaxevent->subclass , SWITCH_DEFAULT_DTMF_DURATION };
|
||||
if (globals.debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s DTMF %s\n", str, switch_channel_get_name(channel));
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%c DTMF %s\n", dtmf.digit, switch_channel_get_name(channel));
|
||||
}
|
||||
switch_channel_queue_dtmf(channel, str);
|
||||
|
||||
switch_channel_queue_dtmf(channel, &dtmf);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -524,14 +524,14 @@ static switch_status_t channel_waitfor_write(switch_core_session_t *session, int
|
||||
|
||||
}
|
||||
|
||||
static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *dtmf)
|
||||
static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
|
||||
{
|
||||
private_t *tech_pvt = NULL;
|
||||
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
switch_assert(tech_pvt != NULL);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF ON CALL %s [%s]\n", tech_pvt->call_id, dtmf);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF ON CALL %s [%c]\n", tech_pvt->call_id, dtmf->digit);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -1314,18 +1314,23 @@ static switch_status_t engage_ring_device(int sample_rate, int channels)
|
||||
|
||||
|
||||
|
||||
|
||||
static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream)
|
||||
{
|
||||
char *dtmf = argv[0];
|
||||
|
||||
if (switch_strlen_zero(dtmf)) {
|
||||
char *dtmf_str = argv[0];
|
||||
switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
|
||||
|
||||
if (switch_strlen_zero(dtmf_str)) {
|
||||
stream->write_function(stream, "No DTMF Supplied!\n");
|
||||
} else {
|
||||
switch_mutex_lock(globals.pvt_lock);
|
||||
if (globals.call_list) {
|
||||
switch_channel_t *channel = switch_core_session_get_channel(globals.call_list->session);
|
||||
switch_channel_queue_dtmf(channel, dtmf);
|
||||
char *p = dtmf_str;
|
||||
while(p && *p) {
|
||||
dtmf.digit = *p;
|
||||
switch_channel_queue_dtmf(channel, &dtmf);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
switch_mutex_unlock(globals.pvt_lock);
|
||||
}
|
||||
|
||||
@@ -540,9 +540,9 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
|
||||
payload = tech_pvt->read_frame.payload;
|
||||
|
||||
if (switch_rtp_has_dtmf(tech_pvt->rtp_session)) {
|
||||
char dtmf[128];
|
||||
switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, dtmf, sizeof(dtmf));
|
||||
switch_channel_queue_dtmf(channel, dtmf);
|
||||
switch_dtmf_t dtmf = {0};
|
||||
switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, &dtmf);
|
||||
switch_channel_queue_dtmf(channel, &dtmf);
|
||||
}
|
||||
|
||||
|
||||
@@ -696,15 +696,31 @@ static switch_status_t sofia_waitfor_write(switch_core_session_t *session, int m
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t sofia_send_dtmf(switch_core_session_t *session, char *digits)
|
||||
static switch_status_t sofia_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
|
||||
{
|
||||
private_object_t *tech_pvt;
|
||||
char message[128] = "";
|
||||
|
||||
tech_pvt = (private_object_t *) switch_core_session_get_private(session);
|
||||
switch_assert(tech_pvt != NULL);
|
||||
|
||||
return switch_rtp_queue_rfc2833(tech_pvt->rtp_session,
|
||||
digits, tech_pvt->profile->dtmf_duration * (tech_pvt->read_codec.implementation->samples_per_second / 1000));
|
||||
switch (tech_pvt->dtmf_type) {
|
||||
case DTMF_2833:
|
||||
return switch_rtp_queue_rfc2833(tech_pvt->rtp_session, dtmf);
|
||||
|
||||
case DTMF_INFO:
|
||||
snprintf(message, sizeof(message), "Signal=%c\r\nDuration=%d\r\n", dtmf->digit, dtmf->duration);
|
||||
nua_info(tech_pvt->nh,
|
||||
//NUTAG_WITH_THIS(tech_pvt->profile->nua),
|
||||
SIPTAG_CONTENT_TYPE_STR("application/dtmf-relay"),
|
||||
SIPTAG_PAYLOAD_STR(message),
|
||||
TAG_END());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t sofia_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
|
||||
|
||||
@@ -83,6 +83,13 @@ typedef struct private_object private_object_t;
|
||||
#include <sofia-sip/nea.h>
|
||||
#include <sofia-sip/msg_addr.h>
|
||||
|
||||
|
||||
typedef enum {
|
||||
DTMF_2833,
|
||||
DTMF_INFO,
|
||||
DTMF_NONE
|
||||
} sofia_dtmf_t;
|
||||
|
||||
struct sofia_private {
|
||||
char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
||||
sofia_gateway_t *gateway;
|
||||
@@ -232,6 +239,8 @@ struct sofia_profile {
|
||||
char *tls_cert_dir;
|
||||
char *reg_domain;
|
||||
char *user_agent;
|
||||
char *record_template;
|
||||
sofia_dtmf_t dtmf_type;
|
||||
int sip_port;
|
||||
int tls_sip_port;
|
||||
char *codec_string;
|
||||
@@ -357,6 +366,7 @@ struct private_object {
|
||||
switch_payload_t video_agreed_pt;
|
||||
char *video_fmtp_out;
|
||||
uint32_t video_count;
|
||||
sofia_dtmf_t dtmf_type;
|
||||
};
|
||||
|
||||
struct callback_t {
|
||||
@@ -547,3 +557,4 @@ sofia_transport_t sofia_glue_url2transport(const url_t *url);
|
||||
const char *sofia_glue_transport2str(const sofia_transport_t tp);
|
||||
|
||||
int sofia_glue_transport_has_tls(const sofia_transport_t tp);
|
||||
const char *sofia_glue_get_unknown_header(sip_t const *sip, const char *name);
|
||||
|
||||
@@ -884,6 +884,16 @@ switch_status_t config_sofia(int reload, char *profile_name)
|
||||
|
||||
} else if (!strcasecmp(var, "user-agent-string")) {
|
||||
profile->user_agent = switch_core_strdup(profile->pool, val);;
|
||||
} else if (!strcasecmp(var, "dtmf-type")) {
|
||||
if (!strcasecmp(val, "rfc2833")) {
|
||||
profile->dtmf_type = DTMF_2833;
|
||||
} else if (!strcasecmp(val, "info")) {
|
||||
profile->dtmf_type = DTMF_INFO;
|
||||
} else {
|
||||
profile->dtmf_type = DTMF_NONE;
|
||||
}
|
||||
} else if (!strcasecmp(var, "record-template")) {
|
||||
profile->record_template = switch_core_strdup(profile->pool, val);;
|
||||
} else if (!strcasecmp(var, "inbound-no-media") && switch_true(val)) {
|
||||
switch_set_flag(profile, TFLAG_INB_NOMEDIA);
|
||||
} else if (!strcasecmp(var, "inbound-late-negotiation") && switch_true(val)) {
|
||||
@@ -1916,57 +1926,108 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
|
||||
{
|
||||
struct private_object *tech_pvt = NULL;
|
||||
switch_channel_t *channel = NULL;
|
||||
char dtmf_digit[2] = { 0, 0 };
|
||||
|
||||
/* placeholder for string searching */
|
||||
char *signal_ptr;
|
||||
const char *rec_header;
|
||||
|
||||
/* Try and find signal information in the payload */
|
||||
signal_ptr = strstr(sip->sip_payload->pl_data, "Signal=");
|
||||
if (session) {
|
||||
/* Get the channel */
|
||||
channel = switch_core_session_get_channel(session);
|
||||
|
||||
/* unknown info type */
|
||||
if (!signal_ptr) {
|
||||
sip_from_t const *from = sip->sip_from;
|
||||
/* Barf if we didn't get it */
|
||||
switch_assert(channel != NULL);
|
||||
|
||||
/* make sure we have our privates */
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
|
||||
/* Barf if we didn't get it */
|
||||
switch_assert(tech_pvt != NULL);
|
||||
|
||||
/* print in the logs if something comes through we don't understand */
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown INFO Recieved: %s%s" URL_PRINT_FORMAT "[%s]\n",
|
||||
from->a_display ? from->a_display : "",
|
||||
from->a_display ? " " : "",
|
||||
URL_PRINT_ARGS(from->a_url),
|
||||
sip->sip_payload->pl_data);
|
||||
/* Send 415 Unsupported Media response */
|
||||
nua_respond(nh, SIP_415_UNSUPPORTED_MEDIA, NUTAG_WITH_THIS(nua), TAG_END());
|
||||
return;
|
||||
|
||||
if (sip && sip->sip_payload && sip->sip_payload->pl_data) {
|
||||
switch_dtmf_t dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION };
|
||||
|
||||
/* Try and find signal information in the payload */
|
||||
if ((signal_ptr = strstr(sip->sip_payload->pl_data, "Signal="))) {
|
||||
/* move signal_ptr where we need it (right past Signal=) */
|
||||
signal_ptr = signal_ptr + 7;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Bad signal\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* unknown info type */
|
||||
if (!signal_ptr) {
|
||||
sip_from_t const *from = sip->sip_from;
|
||||
|
||||
/* print in the logs if something comes through we don't understand */
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown INFO Recieved: %s%s" URL_PRINT_FORMAT "[%s]\n",
|
||||
from->a_display ? from->a_display : "",
|
||||
from->a_display ? " " : "",
|
||||
URL_PRINT_ARGS(from->a_url),
|
||||
sip->sip_payload->pl_data);
|
||||
/* Send 415 Unsupported Media response */
|
||||
nua_respond(nh, SIP_415_UNSUPPORTED_MEDIA, NUTAG_WITH_THIS(nua), TAG_END());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
dtmf.digit = *signal_ptr;
|
||||
if ((signal_ptr = strstr(sip->sip_payload->pl_data, "Duration="))) {
|
||||
int tmp;
|
||||
signal_ptr += 8;
|
||||
if ((tmp = atoi(signal_ptr)) < 0) {
|
||||
tmp = SWITCH_DEFAULT_DTMF_DURATION;
|
||||
}
|
||||
dtmf.duration = tmp;
|
||||
}
|
||||
|
||||
/* queue it up */
|
||||
switch_channel_queue_dtmf(channel, &dtmf);
|
||||
|
||||
/* print debug info */
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INFO DTMF(%c)\n", dtmf.digit);
|
||||
|
||||
/* Send 200 OK response */
|
||||
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ((rec_header = sofia_glue_get_unknown_header(sip, "record"))) {
|
||||
if (switch_strlen_zero(profile->record_template)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Record attempted but no template defined.\n");
|
||||
nua_respond(nh, 488, "Recording not enabled", NUTAG_WITH_THIS(nua), TAG_END());
|
||||
} else {
|
||||
if (!strcasecmp(rec_header, "on")) {
|
||||
char *file;
|
||||
|
||||
file = switch_channel_expand_variables(channel, profile->record_template);
|
||||
switch_ivr_record_session(session, file, 0, NULL);
|
||||
switch_channel_set_variable(channel, "sofia_record_file", file);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Recording %s to %s\n", switch_channel_get_name(channel), file);
|
||||
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
|
||||
if (file != profile->record_template) {
|
||||
free(file);
|
||||
file = NULL;
|
||||
}
|
||||
} else {
|
||||
const char *file;
|
||||
|
||||
if ((file = switch_channel_get_variable(channel, "sofia_record_file"))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Done recording %s to %s\n", switch_channel_get_name(channel), file);
|
||||
switch_ivr_stop_record_session(session, file);
|
||||
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
|
||||
} else {
|
||||
nua_respond(nh, 488, "Nothing to stop", NUTAG_WITH_THIS(nua), TAG_END());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the channel */
|
||||
channel = switch_core_session_get_channel(session);
|
||||
|
||||
/* Barf if we didn't get it */
|
||||
switch_assert(channel != NULL);
|
||||
|
||||
/* make sure we have our privates */
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
|
||||
/* Barf if we didn't get it */
|
||||
switch_assert(tech_pvt != NULL);
|
||||
|
||||
/* move signal_ptr where we need it (right past Signal=) */
|
||||
signal_ptr = signal_ptr + 7;
|
||||
|
||||
/* put the digit somewhere we can muck with */
|
||||
strncpy(dtmf_digit, signal_ptr, 1);
|
||||
|
||||
/* queue it up */
|
||||
switch_channel_queue_dtmf(channel, dtmf_digit);
|
||||
|
||||
/* print debug info */
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INFO DTMF(%s)\n", dtmf_digit);
|
||||
|
||||
/* Send 200 OK response */
|
||||
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -347,6 +347,10 @@ void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *
|
||||
tech_pvt->te = profile->te;
|
||||
}
|
||||
|
||||
|
||||
tech_pvt->dtmf_type = profile->dtmf_type;
|
||||
|
||||
|
||||
if (tech_pvt->bcng_pt) {
|
||||
tech_pvt->cng_pt = tech_pvt->bcng_pt;
|
||||
} else if (!tech_pvt->cng_pt) {
|
||||
@@ -387,6 +391,20 @@ switch_status_t sofia_glue_ext_address_lookup(char **ip, switch_port_t *port, ch
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
const char *sofia_glue_get_unknown_header(sip_t const *sip, const char *name)
|
||||
{
|
||||
sip_unknown_t *un;
|
||||
for (un = sip->sip_unknown; un; un = un->un_next) {
|
||||
if (!strcasecmp(un->un_name, name)) {
|
||||
if (!switch_strlen_zero(un->un_value)) {
|
||||
return un->un_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt)
|
||||
{
|
||||
char *ip = tech_pvt->profile->rtpip;
|
||||
@@ -1097,6 +1115,16 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
|
||||
flags |= SWITCH_RTP_FLAG_BUGGY_2833;
|
||||
}
|
||||
|
||||
if ((val = switch_channel_get_variable(tech_pvt->channel, "dtmf_type"))) {
|
||||
if (!strcasecmp(val, "rfc2833")) {
|
||||
tech_pvt->dtmf_type = DTMF_2833;
|
||||
} else if (!strcasecmp(val, "info")) {
|
||||
tech_pvt->dtmf_type = DTMF_INFO;
|
||||
} else {
|
||||
tech_pvt->dtmf_type = tech_pvt->profile->dtmf_type;
|
||||
}
|
||||
}
|
||||
|
||||
if ((tech_pvt->profile->pflags & PFLAG_PASS_RFC2833)
|
||||
|| ((val = switch_channel_get_variable(tech_pvt->channel, "pass_rfc2833")) && switch_true(val))) {
|
||||
flags |= SWITCH_RTP_FLAG_PASS_RFC2833;
|
||||
|
||||
@@ -810,7 +810,13 @@ static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch
|
||||
teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str));
|
||||
|
||||
if(digit_str[0]) {
|
||||
switch_channel_queue_dtmf(channel, digit_str);
|
||||
char *p = digit_str;
|
||||
switch_dtmf_t dtmf = {0, globals.dtmf_on};
|
||||
while(p && *p) {
|
||||
dtmf.digit = *p;
|
||||
switch_channel_queue_dtmf(channel, &dtmf);
|
||||
p++;
|
||||
}
|
||||
if (globals.debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str);
|
||||
}
|
||||
@@ -876,13 +882,12 @@ static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switc
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t wanpipe_send_dtmf(switch_core_session_t *session, char *digits)
|
||||
static switch_status_t wanpipe_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
|
||||
{
|
||||
private_object_t *tech_pvt;
|
||||
switch_channel_t *channel = NULL;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
int wrote = 0;
|
||||
char *cur = NULL;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
@@ -903,12 +908,13 @@ static switch_status_t wanpipe_send_dtmf(switch_core_session_t *session, char *d
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, "SUCCESS!\n");
|
||||
}
|
||||
}
|
||||
for (cur = digits; *cur; cur++) {
|
||||
if ((wrote = teletone_mux_tones(&tech_pvt->tone_session, &tech_pvt->tone_session.TONES[(int)*cur]))) {
|
||||
switch_buffer_write(tech_pvt->dtmf_buffer, tech_pvt->tone_session.buffer, wrote * 2);
|
||||
}
|
||||
|
||||
tech_pvt->tone_session.duration = dtmf.duration * (tech_pvt->tone_session.rate / 1000);
|
||||
if ((wrote = teletone_mux_tones(&tech_pvt->tone_session, &tech_pvt->tone_session.TONES[(int)dtmf->digit]))) {
|
||||
switch_buffer_write(tech_pvt->dtmf_buffer, tech_pvt->tone_session.buffer, wrote * 2);
|
||||
}
|
||||
|
||||
|
||||
tech_pvt->skip_read_frames = 200;
|
||||
|
||||
return status;
|
||||
|
||||
@@ -1010,10 +1010,14 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
break;
|
||||
case SWITCH_INPUT_TYPE_DTMF:
|
||||
dtmf = (char *) input;
|
||||
argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cb_state->cx, "dtmf"));
|
||||
argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cb_state->cx, dtmf));
|
||||
case SWITCH_INPUT_TYPE_DTMF:
|
||||
{
|
||||
switch_dtmf_t *_dtmf = (switch_dtmf_t *) input;
|
||||
dtmf[0] = _dtmf->digit;
|
||||
dtmf[1] = '\0';
|
||||
argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cb_state->cx, "dtmf"));
|
||||
argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cb_state->cx, dtmf));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1208,8 +1212,6 @@ static switch_status_t js_collect_input_callback(switch_core_session_t *session,
|
||||
static JSBool session_flush_digits(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
|
||||
{
|
||||
struct js_session *jss = JS_GetPrivate(cx, obj);
|
||||
char buf[256];
|
||||
switch_size_t has;
|
||||
switch_channel_t *channel;
|
||||
|
||||
METHOD_SANITY_CHECK();
|
||||
@@ -1217,9 +1219,7 @@ static JSBool session_flush_digits(JSContext * cx, JSObject * obj, uintN argc, j
|
||||
channel = switch_core_session_get_channel(jss->session);
|
||||
switch_assert(channel != NULL);
|
||||
|
||||
while ((has = switch_channel_has_dtmf(channel))) {
|
||||
switch_channel_dequeue_dtmf(channel, buf, sizeof(buf));
|
||||
}
|
||||
switch_channel_flush_dtmf(channel);
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
|
||||
return JS_TRUE;
|
||||
|
||||
@@ -257,7 +257,7 @@ static JSBool teletone_generate(JSContext * cx, JSObject * obj, uintN argc, jsva
|
||||
uintN aargc = 0;
|
||||
jsval aargv[4];
|
||||
|
||||
switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
|
||||
switch_channel_dequeue_dtmf_string(channel, dtmf, sizeof(dtmf));
|
||||
aargv[aargc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, dtmf));
|
||||
JS_CallFunction(cx, obj, tto->function, aargc, aargv, &tto->ret);
|
||||
ret = JS_GetStringBytes(JS_ValueToString(cx, tto->ret));
|
||||
|
||||
Reference in New Issue
Block a user